refactor: refs #8210 ticket_splitItemPackingType #3217

Merged
carlosap merged 5 commits from 8210-RefactorTicket_splitItemPackingType into dev 2024-11-21 12:39:35 +00:00
1 changed files with 16 additions and 11 deletions
Showing only changes of commit 031c4398ae - Show all commits

View File

@ -18,7 +18,7 @@ BEGIN
DECLARE vDefaultPackingType VARCHAR(1);
DECLARE vHasOriginalPackingType BOOLEAN;
DECLARE vNewTicketFk INT;
DECLARE vThrowAway INT;
DECLARE vTicketFk INT;
DECLARE vItemPackingTypes CURSOR FOR
SELECT DISTINCT itemPackingTypeFk FROM tSalesToMove;
@ -37,15 +37,12 @@ BEGIN
itemPackingTypeFk VARCHAR(1)
) ENGINE=MEMORY;
SELECT defaultPackingTypeFk INTO vDefaultPackingType FROM itemConfig LIMIT 1;
START TRANSACTION;
SELECT t.id INTO vThrowAway
FROM ticket t
JOIN sale s ON s.id = t.id
WHERE t.id = vSelf
FOR UPDATE;
SELECT COALESCE(MAX(ic.defaultPackingTypeFk), MAX(i.itemPackingTypeFk)) INTO vDefaultPackingType
FROM vn.sale s
JOIN item i ON i.id = s.itemFk
LEFT JOIN itemConfig ic ON ic.defaultPackingTypeFk = i.itemPackingTypeFk
WHERE s.ticketFk = vSelf
GROUP BY s.ticketFk;
SELECT EXISTS (
SELECT TRUE
@ -59,6 +56,14 @@ BEGIN
SET vOriginalItemPackingTypeFk = vDefaultPackingType;
END IF;
START TRANSACTION;
SELECT t.id INTO vTicketFk
FROM ticket t
JOIN sale s ON s.id = t.id
WHERE t.id = vSelf
FOR UPDATE;
INSERT INTO tSalesToMove (saleFk, itemPackingTypeFk)
SELECT s.id, i.itemPackingTypeFk
FROM sale s
@ -77,7 +82,7 @@ BEGIN
CALL ticket_Clone(vSelf, vNewTicketFk);
SELECT id INTO vThrowAway
SELECT id INTO vTicketFk
FROM ticket t
WHERE t.id = vNewTicketFk
FOR UPDATE;