2023-03-16 09:33:24 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getWarnings`()
|
2023-03-16 09:33:24 +00:00
|
|
|
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
|
|
|
|
*/
|
2024-01-15 11:31:03 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tSaleWarnings (
|
2023-03-22 09:57:18 +00:00
|
|
|
ticketFk INT(11),
|
|
|
|
saleFk INT(11),
|
|
|
|
isFragile INTEGER(1) DEFAULT 0,
|
|
|
|
PRIMARY KEY (ticketFk, saleFk)
|
|
|
|
) ENGINE = MEMORY;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
-- Fragile
|
|
|
|
INSERT INTO tSaleWarnings(ticketFk, saleFk, isFragile)
|
2023-03-22 09:57:18 +00:00
|
|
|
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
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_warnings
|
|
|
|
(PRIMARY KEY (ticketFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT
|
|
|
|
sw.ticketFk,
|
|
|
|
MAX(sw.isFragile) AS isFragile
|
|
|
|
FROM tSaleWarnings sw
|
|
|
|
GROUP BY sw.ticketFk;
|
2023-03-16 09:33:24 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE
|
2024-01-15 11:31:03 +00:00
|
|
|
tSaleWarnings;
|
2023-03-16 09:33:24 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|