From 690d93542949ff705f4b8093dbaf06297e406f84 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 15 Mar 2024 10:00:24 +0100 Subject: [PATCH] refactor: refs #6951 cloneAll --- db/routines/vn/procedures/ticket_Clone.sql | 4 +- db/routines/vn/procedures/ticket_CloneAll.sql | 73 ++++++++++--------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/db/routines/vn/procedures/ticket_Clone.sql b/db/routines/vn/procedures/ticket_Clone.sql index cdddd6225..7670e832e 100644 --- a/db/routines/vn/procedures/ticket_Clone.sql +++ b/db/routines/vn/procedures/ticket_Clone.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT,vWithWarehouse BOOLEAN) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN /** * Clona el contenido de un ticket en otro @@ -32,7 +32,7 @@ BEGIN addressFk, agencyModeFk, nickname, - IF(vWithWarehouse, warehouseFk, NULL), + warehouseFk, companyFk, landed, zoneFk, diff --git a/db/routines/vn/procedures/ticket_CloneAll.sql b/db/routines/vn/procedures/ticket_CloneAll.sql index 4adb50a10..d56a47a33 100644 --- a/db/routines/vn/procedures/ticket_CloneAll.sql +++ b/db/routines/vn/procedures/ticket_CloneAll.sql @@ -2,53 +2,54 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_CloneAll`(vTicketFk INT, vNewShipped DATE, vWithWarehouse BOOLEAN, OUT vNewTicketFk INT) BEGIN - DECLARE done INT DEFAULT FALSE; + DECLARE done INT DEFAULT FALSE; DECLARE vOldSaleFk INT; - DECLARE vNewSaleFk INT; - - DECLARE cur1 CURSOR FOR + DECLARE vNewSaleFk INT; + + DECLARE cur1 CURSOR FOR SELECT id - FROM vn.sale - WHERE ticketFk = vTicketFk; - + FROM sale + WHERE ticketFk = vTicketFk; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); - - CALL vn.ticket_Clone(vTicketFk, vNewTicketFk, vWithWarehouse); - - UPDATE vn.ticket + + SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); + + CALL ticket_Clone(vTicketFk, vNewTicketFk, vWithWarehouse); + + UPDATE ticket SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed), - shipped = vNewShipped - WHERE id = vNewTicketFk; - + shipped = vNewShipped, + warehouseFk = IF(vWithWarehouse, warehouseFk, NULL) + WHERE id = vNewTicketFk; + OPEN cur1; - + read_loop: LOOP - FETCH cur1 INTO vOldSaleFk; - - IF done THEN - LEAVE read_loop; - END IF; - - INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed) + FETCH cur1 INTO vOldSaleFk; + + IF done THEN + LEAVE read_loop; + END IF; + + INSERT INTO sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed) SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed - FROM vn.sale - WHERE id = vOldSaleFk; - - SELECT max(id) INTO vNewSaleFk - FROM vn.sale - WHERE ticketFk = vNewTicketFk; - - INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge) + FROM sale + WHERE id = vOldSaleFk; + + SELECT max(id) INTO vNewSaleFk + FROM sale + WHERE ticketFk = vNewTicketFk; + + INSERT INTO saleComponent(saleFk, componentFk, value, isGreuge) SELECT vNewSaleFk, componentFk, value, isGreuge - FROM vn.saleComponent - WHERE saleFk = vOldSaleFk; - + FROM saleComponent + WHERE saleFk = vOldSaleFk; + END LOOP; CLOSE cur1; - + END$$ DELIMITER ;