2023-03-16 09:33:24 +00:00
|
|
|
DROP PROCEDURE IF EXISTS `vn`.`ticket_getWarnings`;
|
|
|
|
|
|
|
|
DELIMITER $$
|
|
|
|
$$
|
|
|
|
CREATE PROCEDURE `vn`.`ticket_getWarnings`()
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Calcula las adventencias para un conjunto de tickets.
|
|
|
|
* Agrupados por ticket
|
|
|
|
*
|
|
|
|
* @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular
|
|
|
|
* @return tmp.ticket_warnings
|
|
|
|
*/
|
2023-03-22 09:57:18 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings;
|
|
|
|
CREATE TEMPORARY TABLE tmp.sale_warnings (
|
|
|
|
ticketFk INT(11),
|
|
|
|
saleFk INT(11),
|
|
|
|
isFragile INTEGER(1) DEFAULT 0,
|
|
|
|
PRIMARY KEY (ticketFk, saleFk)
|
|
|
|
) ENGINE = MEMORY;
|
|
|
|
|
|
|
|
-- Frágil
|
|
|
|
INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile)
|
|
|
|
SELECT tt.ticketFk, s.id, TRUE
|
|
|
|
FROM tmp.sale_getWarnings tt
|
|
|
|
LEFT JOIN sale s ON s.ticketFk = tt.ticketFk
|
|
|
|
LEFT JOIN item i ON i.id = s.itemFk
|
|
|
|
LEFT JOIN itemType it ON it.id = i.typeFk
|
|
|
|
LEFT JOIN agencyMode am ON am.id = tt.agencyModeFk
|
|
|
|
LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
|
|
|
WHERE dm.code IN ('AGENCY')
|
2023-03-23 08:25:56 +00:00
|
|
|
AND it.isFragile;
|
2023-03-16 09:33:24 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_warnings;
|
|
|
|
CREATE TEMPORARY TABLE tmp.ticket_warnings
|
|
|
|
(PRIMARY KEY (ticketFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT
|
|
|
|
sw.ticketFk,
|
2023-03-22 09:57:18 +00:00
|
|
|
MAX(sw.isFragile) AS isFragile
|
2023-03-16 09:33:24 +00:00
|
|
|
FROM tmp.sale_warnings sw
|
|
|
|
GROUP BY sw.ticketFk;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE
|
|
|
|
tmp.sale_warnings;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|