refactor: refs #8210 ticket_splitItemPackingType
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
a7ab8696ac
commit
43abb52efc
|
@ -18,19 +18,34 @@ BEGIN
|
||||||
DECLARE vDefaultPackingType VARCHAR(1);
|
DECLARE vDefaultPackingType VARCHAR(1);
|
||||||
DECLARE vHasOriginalPackingType BOOLEAN;
|
DECLARE vHasOriginalPackingType BOOLEAN;
|
||||||
DECLARE vNewTicketFk INT;
|
DECLARE vNewTicketFk INT;
|
||||||
|
DECLARE vThrowAway INT;
|
||||||
|
|
||||||
DECLARE vItemPackingTypes CURSOR FOR
|
DECLARE vItemPackingTypes CURSOR FOR
|
||||||
SELECT DISTINCT itemPackingTypeFk FROM tSalesToMove;
|
SELECT DISTINCT itemPackingTypeFk FROM tSalesToMove;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK;
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tSalesToMove (
|
CREATE OR REPLACE TEMPORARY TABLE tSalesToMove (
|
||||||
ticketFk INT,
|
ticketFk INT,
|
||||||
saleFk INT,
|
saleFk INT,
|
||||||
itemPackingTypeFk VARCHAR(1)
|
itemPackingTypeFk VARCHAR(1)
|
||||||
) ENGINE=MEMORY;
|
) ENGINE=MEMORY;
|
||||||
|
|
||||||
SELECT vDefaultPackingTypeFk INTO vDefaultPackingType FROM itemConfig LIMIT 1;
|
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 EXISTS (
|
SELECT EXISTS (
|
||||||
SELECT TRUE
|
SELECT TRUE
|
||||||
|
@ -48,11 +63,12 @@ BEGIN
|
||||||
SELECT s.id, i.itemPackingTypeFk
|
SELECT s.id, i.itemPackingTypeFk
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
WHERE s.ticketFk = vSelf
|
WHERE s.ticketFk = vSelf
|
||||||
AND i.itemPackingTypeFk <> vOriginalItemPackingTypeFk;
|
AND i.itemPackingTypeFk <> vOriginalItemPackingTypeFk;
|
||||||
|
|
||||||
OPEN vItemPackingTypes;
|
OPEN vItemPackingTypes;
|
||||||
l: LOOP
|
l: LOOP
|
||||||
|
SET vIsDone = FALSE;
|
||||||
FETCH vItemPackingTypes INTO vCurrentPackingType;
|
FETCH vItemPackingTypes INTO vCurrentPackingType;
|
||||||
|
|
||||||
IF vIsDone THEN
|
IF vIsDone THEN
|
||||||
|
@ -61,6 +77,11 @@ BEGIN
|
||||||
|
|
||||||
CALL ticket_Clone(vSelf, vNewTicketFk);
|
CALL ticket_Clone(vSelf, vNewTicketFk);
|
||||||
|
|
||||||
|
SELECT id INTO vThrowAway
|
||||||
|
FROM ticket t
|
||||||
|
WHERE t.id = vNewTicketFk
|
||||||
|
FOR UPDATE;
|
||||||
|
|
||||||
UPDATE tSalesToMove
|
UPDATE tSalesToMove
|
||||||
SET ticketFk = vNewTicketFk
|
SET ticketFk = vNewTicketFk
|
||||||
WHERE itemPackingTypeFk = vCurrentPackingType;
|
WHERE itemPackingTypeFk = vCurrentPackingType;
|
||||||
|
@ -73,25 +94,27 @@ BEGIN
|
||||||
WHERE s.ticketFk = vSelf
|
WHERE s.ticketFk = vSelf
|
||||||
AND i.itemPackingTypeFk IS NULL;
|
AND i.itemPackingTypeFk IS NULL;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE vItemPackingTypes;
|
CLOSE vItemPackingTypes;
|
||||||
|
|
||||||
UPDATE sale s
|
UPDATE sale s
|
||||||
JOIN tSalesToMove t ON t.saleFk = s.id
|
JOIN tSalesToMove t ON t.saleFk = s.id
|
||||||
SET s.ticketFk = t.ticketFk
|
SET s.ticketFk = t.ticketFk;
|
||||||
WHERE t.ticketFk IS NOT NULL;
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT
|
||||||
ENGINE=MEMORY
|
ENGINE=MEMORY
|
||||||
SELECT s.ticketFk, i.itemPackingTypeFk
|
SELECT s.ticketFk, MAX(i.itemPackingTypeFk) itemPackingTypeFk
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
WHERE s.ticketFk = vSelf
|
WHERE s.ticketFk = vSelf
|
||||||
GROUP BY s.ticketFk, i.itemPackingTypeFk
|
GROUP BY s.ticketFk
|
||||||
UNION
|
UNION
|
||||||
SELECT ticketFk, itemPackingTypeFk
|
SELECT ticketFk, MAX(itemPackingTypeFk)
|
||||||
FROM tSalesToMove
|
FROM tSalesToMove
|
||||||
GROUP BY ticketFk, itemPackingTypeFk;
|
GROUP BY ticketFk;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tSalesToMove;
|
DROP TEMPORARY TABLE tSalesToMove;
|
||||||
END$$
|
END$$
|
||||||
|
|
Loading…
Reference in New Issue