2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-09-05 07:40:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getProblems`(
|
2024-08-07 08:32:47 +00:00
|
|
|
vIsTodayRelative tinyint(1)
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Calcula los problemas para un conjunto de tickets.
|
|
|
|
* Agrupados por ticket
|
|
|
|
*
|
|
|
|
* @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular
|
|
|
|
* @return tmp.ticket_problems
|
|
|
|
*/
|
|
|
|
CALL sale_getProblems(vIsTodayRelative);
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems
|
|
|
|
(PRIMARY KEY (ticketFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT ticketFk,
|
|
|
|
MAX(isFreezed) isFreezed,
|
|
|
|
MAX(risk) risk,
|
2024-09-03 10:06:31 +00:00
|
|
|
MAX(hasRisk) hasRisk,
|
2024-01-15 11:31:03 +00:00
|
|
|
MAX(hasHighRisk) hasHighRisk,
|
|
|
|
MAX(hasTicketRequest) hasTicketRequest,
|
|
|
|
MAX(itemShortage) itemShortage,
|
|
|
|
MIN(isTaxDataChecked) isTaxDataChecked,
|
|
|
|
MAX(hasComponentLack) hasComponentLack,
|
|
|
|
MAX(isTooLittle) isTooLittle,
|
|
|
|
MAX(itemDelay) itemDelay,
|
|
|
|
MAX(hasRounding) hasRounding,
|
|
|
|
MAX(itemLost) itemLost,
|
2024-05-14 07:07:43 +00:00
|
|
|
MAX(isVip) isVip,
|
2024-01-15 11:31:03 +00:00
|
|
|
0 totalProblems
|
|
|
|
FROM tmp.sale_problems
|
|
|
|
GROUP BY ticketFk;
|
|
|
|
|
2024-09-03 10:06:31 +00:00
|
|
|
UPDATE tmp.ticket_problems
|
|
|
|
SET totalProblems = (
|
|
|
|
(isFreezed) +
|
|
|
|
(hasRisk) +
|
|
|
|
(hasTicketRequest) +
|
2024-09-03 11:29:01 +00:00
|
|
|
(!isTaxDataChecked) +
|
2024-09-03 10:06:31 +00:00
|
|
|
(hasComponentLack) +
|
|
|
|
(itemDelay IS NOT NULL) +
|
|
|
|
(isTooLittle) +
|
|
|
|
(itemLost IS NOT NULL) +
|
|
|
|
(hasRounding IS NOT NULL) +
|
|
|
|
(itemShortage IS NOT NULL) +
|
|
|
|
(isVip)
|
2024-01-15 11:31:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.sale_problems;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|