2024-06-25 17:30:59 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_DelayTruckSplit`(
|
2024-06-25 17:47:22 +00:00
|
|
|
vTicketFk INT
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Splita las lineas de ticket que no estan ubicadas
|
|
|
|
*
|
|
|
|
* @param vTicketFk Id ticket
|
|
|
|
*/
|
|
|
|
DECLARE vNewTicketFk INT;
|
|
|
|
DECLARE vTotalLines INT;
|
|
|
|
DECLARE vLinesToSplit INT;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vTotalLines
|
|
|
|
FROM sale
|
|
|
|
WHERE ticketFk = vTicketFk;
|
|
|
|
|
|
|
|
CREATE TEMPORARY TABLE tmp.SalesToSplit
|
|
|
|
SELECT s.id saleFk
|
|
|
|
FROM ticket t
|
|
|
|
JOIN sale s ON t.id = s.ticketFk
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT ish.itemFk itemFk,
|
|
|
|
SUM(ish.visible) visible,
|
|
|
|
s.warehouseFk warehouseFk
|
|
|
|
FROM itemShelving ish
|
2024-11-13 08:56:38 +00:00
|
|
|
JOIN shelving sh ON sh.id = ish.shelvingFk
|
2024-01-15 11:31:03 +00:00
|
|
|
JOIN parking p ON p.id = sh.parkingFk
|
|
|
|
JOIN sector s ON s.id = p.sectorFk
|
|
|
|
GROUP BY ish.itemFk,
|
|
|
|
s.warehouseFk
|
|
|
|
) issw ON issw.itemFk = s.itemFk
|
|
|
|
AND issw.warehouseFk = t.warehouseFk
|
|
|
|
WHERE s.quantity > IFNULL(issw.visible, 0)
|
|
|
|
AND s.quantity > 0
|
|
|
|
AND NOT s.isPicked
|
|
|
|
AND NOT s.reserved
|
|
|
|
AND t.id = vTicketFk;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vLinesToSplit
|
|
|
|
FROM tmp.SalesToSplit;
|
|
|
|
|
|
|
|
IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN
|
|
|
|
SET vNewTicketFk = vTicketFk;
|
|
|
|
ELSE
|
|
|
|
CALL ticket_Clone(vTicketFk, vNewTicketFk);
|
|
|
|
UPDATE sale s
|
|
|
|
JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id
|
|
|
|
SET s.ticketFk = vNewTicketFk;
|
|
|
|
END IF;
|
|
|
|
|
2024-06-25 17:30:59 +00:00
|
|
|
CALL ticket_setState(vNewTicketFk, 'FIXING');
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.SalesToSplit;
|
2024-06-25 17:30:59 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|