From fc1e0672a4469ae56446707ecd37cc696ff9ef43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 29 Nov 2024 11:59:36 +0100 Subject: [PATCH 1/4] fix: refs #8087 refs#8087 errores travel_moveRaids --- .../vn/procedures/travel_checkRaid.sql | 17 ----- .../vn/procedures/travel_moveRaids.sql | 69 +++++++++++-------- .../vn/triggers/travel_beforeInsert.sql | 4 -- 3 files changed, 41 insertions(+), 49 deletions(-) delete mode 100644 db/routines/vn/procedures/travel_checkRaid.sql diff --git a/db/routines/vn/procedures/travel_checkRaid.sql b/db/routines/vn/procedures/travel_checkRaid.sql deleted file mode 100644 index 64f3355e2..000000000 --- a/db/routines/vn/procedures/travel_checkRaid.sql +++ /dev/null @@ -1,17 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`travel_checkRaid`( - vIsRaid BOOL, - vDaysInForward INT -) -BEGIN -/** - * Check if the values of isRaid and daysInforward are correct - * - * @param vIsRaid idRaid value - * @param vDaysInForward daysInForward value - */ - IF (NOT vIsRaid AND vDaysInForward IS NOT NULL) OR (vIsRaid AND vDaysInForward IS NULL) THEN - CALL util.throw('The raid information is not correct'); - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/travel_moveRaids.sql b/db/routines/vn/procedures/travel_moveRaids.sql index cf0fce23c..52f6707bf 100644 --- a/db/routines/vn/procedures/travel_moveRaids.sql +++ b/db/routines/vn/procedures/travel_moveRaids.sql @@ -8,22 +8,16 @@ BEGIN DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBuyerEmail VARCHAR(40); DECLARE vTravelLink TEXT; - DECLARE vMailBody TEXT DEFAULT ''; + DECLARE vMailBody TEXT; + DECLARE vIsMovible BOOL; + DECLARE vSubject VARCHAR(30); - DECLARE vCur CURSOR FOR - SELECT GROUP_CONCAT(DISTINCT - CONCAT('https://salix.verdnatura.es/#!/travel/', - ttm.travelFk, - '/summary ') - ORDER BY ttm.travelFk SEPARATOR '\n\r') travelLink, - CONCAT(u.name, '@verdnatura.es') buyerEmail - FROM tTravelToMove ttm - JOIN entry e ON e.travelFk = ttm.travelFk - JOIN buy b ON b.entryFk = e.id - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN account.user u ON u.id = it.workerFk - GROUP BY u.name; + DECLARE vTravels CURSOR FOR + SELECT GROUP_CONCAT(DISTINCT travelLink ORDER BY id SEPARATOR '\n\r'), + buyerEmail, + isMovable + FROM tTravelToMove + GROUP BY isMovable, buyerEmail; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -34,35 +28,54 @@ BEGIN END; CREATE OR REPLACE TEMPORARY TABLE tTravelToMove - SELECT id travelFk, - util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded + WITH travels AS ( + SELECT id , + CONCAT('https://salix.verdnatura.es/#!/travel/', id,'/summary') travelLink, + util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded, + shipped <= util.VN_CURDATE() + INTERVAL daysInForward DAY isMovable FROM travel WHERE isRaid - AND daysInForward; + AND daysInForward + )SELECT t.*, + CONCAT(u.name, '@verdnatura.es') buyerEmail + FROM travels t + STRAIGHT_JOIN entry e ON e.travelFk = t.id + JOIN buy b ON b.entryFk = e.id + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN account.user u ON u.id = it.workerFk + GROUP BY t.id; START TRANSACTION; UPDATE travel tr - JOIN tTravelToMove ttm ON ttm.travelFk = tr.id - SET tr.landed = ttm.newLanded; + JOIN tTravelToMove ttm ON ttm.id = tr.id + SET tr.landed = ttm.newLanded + WHERE ttm.isMovable; - OPEN vCur; + OPEN vTravels; l: LOOP SET vDone = FALSE; - FETCH vCur INTO vTravelLink, vBuyerEmail; + FETCH vTravels INTO vTravelLink, vBuyerEmail, vIsMovible; IF vDone THEN LEAVE l; END IF; - CALL `vn`.`mail_insert`( - vBuyerEmail, - 'noreply@verdnatura.es', - 'Cambio de fecha en Redadas', - CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink)); + IF vIsMovible THEN + SET vSubject = 'Cambio de fecha en Redadas'; + SET vMailBody = 'Se ha movido los siguientes travels'; + ELSE + SET vSubject = 'ERROR al cambiar la fecha en Redadas'; + SET vMailBody = 'Ha ocurrido un error con las fechas al mover los siguiente travels'; + END IF; + + SET vMailBody = CONCAT(vMailBody, ': \n\r ', vTravelLink); + + CALL mail_insert(vBuyerEmail, 'noreply@verdnatura.es', vSubject, vMailBody); END LOOP; - CLOSE vCur; + CLOSE vTravels; COMMIT; DROP TEMPORARY TABLE tTravelToMove; END$$ diff --git a/db/routines/vn/triggers/travel_beforeInsert.sql b/db/routines/vn/triggers/travel_beforeInsert.sql index 5356ed537..50331ba6a 100644 --- a/db/routines/vn/triggers/travel_beforeInsert.sql +++ b/db/routines/vn/triggers/travel_beforeInsert.sql @@ -9,10 +9,6 @@ BEGIN CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); - IF NEW.isRaid IS NOT NULL OR NEW.daysInForward IS NOT NULL THEN - CALL travel_checkRaid(NEW.isRaid, NEW.daysInForward); - END IF; - IF NEW.awbFk IS NOT NULL THEN CALL travel_throwAwb(NEW.id); END IF; From b0ee1f3e24260098d712565c1b2a83a8c1cade89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 29 Nov 2024 17:18:25 +0100 Subject: [PATCH 2/4] fix: refs #8087 refs#8087 errores travel_moveRaids --- .../vn/procedures/travel_checkRaid.sql | 17 +++++++++ .../vn/procedures/travel_moveRaids.sql | 38 ++++++++----------- .../vn/triggers/travel_beforeInsert.sql | 4 ++ .../vn/triggers/travel_beforeUpdate.sql | 4 ++ 4 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 db/routines/vn/procedures/travel_checkRaid.sql diff --git a/db/routines/vn/procedures/travel_checkRaid.sql b/db/routines/vn/procedures/travel_checkRaid.sql new file mode 100644 index 000000000..885fc718a --- /dev/null +++ b/db/routines/vn/procedures/travel_checkRaid.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`travel_checkRaid`( + vIsRaid BOOL, + vDaysInForward INT +) +BEGIN +/** + * Check if the values of isRaid and daysInforward are correct + * + * @param vIsRaid idRaid value + * @param vDaysInForward daysInForward value + */ + IF NOT vIsRaid AND vDaysInForward THEN + CALL util.throw('If daysInForward has a value, the raid cannot be unchecked'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_moveRaids.sql b/db/routines/vn/procedures/travel_moveRaids.sql index 52f6707bf..7f2593a3b 100644 --- a/db/routines/vn/procedures/travel_moveRaids.sql +++ b/db/routines/vn/procedures/travel_moveRaids.sql @@ -9,15 +9,14 @@ BEGIN DECLARE vBuyerEmail VARCHAR(40); DECLARE vTravelLink TEXT; DECLARE vMailBody TEXT; - DECLARE vIsMovible BOOL; + DECLARE vDaysBetweenDates INT; DECLARE vSubject VARCHAR(30); DECLARE vTravels CURSOR FOR SELECT GROUP_CONCAT(DISTINCT travelLink ORDER BY id SEPARATOR '\n\r'), - buyerEmail, - isMovable + buyerEmail FROM tTravelToMove - GROUP BY isMovable, buyerEmail; + GROUP BY buyerEmail; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -29,20 +28,20 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tTravelToMove WITH travels AS ( - SELECT id , + SELECT id, CONCAT('https://salix.verdnatura.es/#!/travel/', id,'/summary') travelLink, util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded, - shipped <= util.VN_CURDATE() + INTERVAL daysInForward DAY isMovable - FROM travel + util.VN_CURDATE() - INTERVAL DATEDIFF(landed, shipped) + daysInForward DAY newShipped + FROM vn.travel WHERE isRaid AND daysInForward )SELECT t.*, CONCAT(u.name, '@verdnatura.es') buyerEmail FROM travels t - STRAIGHT_JOIN entry e ON e.travelFk = t.id - JOIN buy b ON b.entryFk = e.id - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk + STRAIGHT_JOIN vn.entry e ON e.travelFk = t.id + JOIN vn.buy b ON b.entryFk = e.id + JOIN vn.item i ON i.id = b.itemFk + JOIN vn.itemType it ON it.id = i.typeFk JOIN account.user u ON u.id = it.workerFk GROUP BY t.id; @@ -50,28 +49,21 @@ BEGIN UPDATE travel tr JOIN tTravelToMove ttm ON ttm.id = tr.id - SET tr.landed = ttm.newLanded - WHERE ttm.isMovable; + SET tr.landed = ttm.newLanded, + tr.shipped = ttm.newShipped; OPEN vTravels; l: LOOP SET vDone = FALSE; - FETCH vTravels INTO vTravelLink, vBuyerEmail, vIsMovible; + FETCH vTravels INTO vTravelLink, vBuyerEmail; IF vDone THEN LEAVE l; END IF; - IF vIsMovible THEN - SET vSubject = 'Cambio de fecha en Redadas'; - SET vMailBody = 'Se ha movido los siguientes travels'; - ELSE - SET vSubject = 'ERROR al cambiar la fecha en Redadas'; - SET vMailBody = 'Ha ocurrido un error con las fechas al mover los siguiente travels'; - END IF; - - SET vMailBody = CONCAT(vMailBody, ': \n\r ', vTravelLink); + SET vSubject = 'Cambio de fecha en Redadas', + vMailBody = CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink); CALL mail_insert(vBuyerEmail, 'noreply@verdnatura.es', vSubject, vMailBody); END LOOP; diff --git a/db/routines/vn/triggers/travel_beforeInsert.sql b/db/routines/vn/triggers/travel_beforeInsert.sql index 50331ba6a..5356ed537 100644 --- a/db/routines/vn/triggers/travel_beforeInsert.sql +++ b/db/routines/vn/triggers/travel_beforeInsert.sql @@ -9,6 +9,10 @@ BEGIN CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); + IF NEW.isRaid IS NOT NULL OR NEW.daysInForward IS NOT NULL THEN + CALL travel_checkRaid(NEW.isRaid, NEW.daysInForward); + END IF; + IF NEW.awbFk IS NOT NULL THEN CALL travel_throwAwb(NEW.id); END IF; diff --git a/db/routines/vn/triggers/travel_beforeUpdate.sql b/db/routines/vn/triggers/travel_beforeUpdate.sql index 256dd35f8..5a27b43b4 100644 --- a/db/routines/vn/triggers/travel_beforeUpdate.sql +++ b/db/routines/vn/triggers/travel_beforeUpdate.sql @@ -20,6 +20,10 @@ BEGIN CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); END IF; + IF NOT (NEW.isRaid <=> OLD.isRaid) OR NOT (NEW.daysInForward <=> OLD.daysInForward) THEN + CALL travel_checkRaid(NEW.isRaid, NEW.daysInForward); + END IF; + IF NOT (NEW.awbFk <=> OLD.awbFk)THEN SELECT COUNT(*) INTO vHasAnyInvoiceBooked FROM travel t From 202ed47963dad41ed96efce4197225113feb2c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 29 Nov 2024 17:20:14 +0100 Subject: [PATCH 3/4] fix: refs #8087 refs#8087 errores travel_moveRaids --- db/routines/vn/procedures/travel_moveRaids.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/travel_moveRaids.sql b/db/routines/vn/procedures/travel_moveRaids.sql index 7f2593a3b..17d7ecc4c 100644 --- a/db/routines/vn/procedures/travel_moveRaids.sql +++ b/db/routines/vn/procedures/travel_moveRaids.sql @@ -35,7 +35,10 @@ BEGIN FROM vn.travel WHERE isRaid AND daysInForward - )SELECT t.*, + )SELECT t.id, + t.travelLink, + t.newLanded, + t.newShipped, CONCAT(u.name, '@verdnatura.es') buyerEmail FROM travels t STRAIGHT_JOIN vn.entry e ON e.travelFk = t.id From 452ec3d7319491df73c9416ea671341a80f2a695 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 13 Dec 2024 08:29:14 +0100 Subject: [PATCH 4/4] fix: refs #247552 ticket 247552 claimRatio_add --- db/routines/vn/procedures/claimRatio_add.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 8c3213644..5e2e66a8e 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -46,7 +46,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND NOT ce.isGreuge AND cs.code = 'resolved'; @@ -71,7 +71,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND NOT ce.isGreuge AND cs.code = 'resolved' AND c.isChargedToMana; @@ -82,7 +82,7 @@ BEGIN JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk SET ce.isGreuge = TRUE - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND NOT ce.isGreuge AND cs.code = 'resolved'; @@ -161,7 +161,7 @@ BEGIN JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk JOIN claimState cs ON cs.id = c.claimStateFk - WHERE cd.description NOT IN ('Bueno', 'Corregido') + WHERE cd.code NOT IN ('good', 'corrected', 'supplierClaim') AND cs.code = 'resolved' AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR GROUP BY c.clientFk