fix: collection_new
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Carlos Andrés 2024-09-18 10:25:21 +02:00
parent dcd7237d67
commit d5f18b9187
1 changed files with 34 additions and 58 deletions

View File

@ -5,23 +5,21 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_splitItemPacki
) )
proc: BEGIN proc: BEGIN
/** /**
* Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado. * Clona y reparte las líneas de ventas de un ticket en funcion del tipo de empaquetado.
* Respeta el id inicial para el tipo propuesto. * Respeta el id de ticket inicial para el tipo de empaquetado propuesto.
* *
* @param vSelf Id ticket * @param vSelf Id ticket
* @param vOriginalItemPackingTypeFk Tipo para el que se reserva el número de ticket original * @param vOriginalItemPackingTypeFk Tipo empaquetado al que se mantiene el ticket original
* @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk) * @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk)
*/ */
DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H';
DECLARE vNewTicketFk INT;
DECLARE vPackingTypesToSplit INT;
DECLARE vDone INT DEFAULT FALSE; DECLARE vDone INT DEFAULT FALSE;
DECLARE vHasItemPackingType BOOL;
DECLARE vItemPackingTypeFk INT;
DECLARE vNewTicketFk INT;
DECLARE vSaleGroup CURSOR FOR DECLARE vItemPackingTypes CURSOR FOR
SELECT itemPackingTypeFk SELECT DISTINCT itemPackingTypeFk
FROM tSaleGroup FROM tSalesToMove;
WHERE itemPackingTypeFk IS NOT NULL
ORDER BY (itemPackingTypeFk = vOriginalItemPackingTypeFk) DESC;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
@ -36,59 +34,39 @@ proc: BEGIN
LEAVE proc; LEAVE proc;
END IF; END IF;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT( CREATE OR REPLACE TEMPORARY TABLE tSalesToMove (
ticketFk INT, ticketFk INT,
itemPackingTypeFk VARCHAR(1) saleFk INT,
) ENGINE = MEMORY; itemPackingTypeFk INT
) ENGINE=MEMORY;
CASE vPackingTypesToSplit INSERT INTO tSalesToMove (saleFk, itemPackingTypeFk)
WHEN 0 THEN SELECT s.id, i.itemPackingTypeFk
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) FROM ticket t
VALUES(vSelf, vItemPackingTypeFk); JOIN sale s ON s.ticketFk = t.id
WHEN 1 THEN JOIN item i ON i.id = s.itemFk
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) WHERE t.id = vSelf
SELECT vSelf, itemPackingTypeFk AND i.itemPackingTypeFk <> vOriginalItemPackingTypeFk;
FROM tSaleGroup
WHERE itemPackingTypeFk IS NOT NULL;
ELSE
OPEN vSaleGroup;
FETCH vSaleGroup INTO vItemPackingTypeFk;
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) OPEN vItemPackingTypes;
VALUES(vSelf, vItemPackingTypeFk);
l: LOOP l: LOOP
SET vDone = FALSE; SET vDone = FALSE;
FETCH vSaleGroup INTO vItemPackingTypeFk; FETCH vItemPackingTypes INTO vItemPackingTypeFk;
IF vDone THEN IF vDone THEN
LEAVE l; LEAVE l;
END IF; END IF;
CALL ticket_Clone(vSelf, vNewTicketFk); CALL ticket_Clone(vSelf, vNewTicketFk);
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) UPDATE tSalesToMove
VALUES(vNewTicketFk, vItemPackingTypeFk); SET ticketFk = vNewTicketFk
END LOOP; WHERE itemPackingTypeFk = vItemPackingTypeFk;
CLOSE vSaleGroup; END LOOP;
SELECT s.id CLOSE vItemPackingTypes;
FROM sale s
JOIN tSale ts ON ts.id = s.id
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
FOR UPDATE;
UPDATE sale s
JOIN tSale ts ON ts.id = s.id
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
SET s.ticketFk = t.ticketFk;
SELECT itemPackingTypeFk INTO vItemPackingTypeFk
FROM tSaleGroup sg
WHERE sg.itemPackingTypeFk IS NOT NULL
ORDER BY sg.itemPackingTypeFk
LIMIT 1;
UPDATE sale s UPDATE sale s
JOIN tSalesToMove stm ON stm.saleFk = s.id JOIN tSalesToMove stm ON stm.saleFk = s.id
@ -105,8 +83,6 @@ proc: BEGIN
UNION UNION
SELECT vSelf, vOriginalItemPackingTypeFk; SELECT vSelf, vOriginalItemPackingTypeFk;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE tSalesToMove;
tSale,
tSaleGroup;
END$$ END$$
DELIMITER ; DELIMITER ;