From 3146f4f5b611a57d371ad3456049f1300d7deb45 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 2 May 2024 14:59:30 +0200 Subject: [PATCH 01/30] refactor: refs #6701 Refactor claim_ratio_routine --- .../bi/procedures/claim_ratio_routine.sql | 166 ------------------ db/routines/vn/procedures/claimRatio_add.sql | 154 ++++++++++++++++ .../11028-silverCarnation/00-firstScript.sql | 4 + 3 files changed, 158 insertions(+), 166 deletions(-) delete mode 100644 db/routines/bi/procedures/claim_ratio_routine.sql create mode 100644 db/routines/vn/procedures/claimRatio_add.sql create mode 100644 db/versions/11028-silverCarnation/00-firstScript.sql diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql deleted file mode 100644 index ae87e15a2..000000000 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ /dev/null @@ -1,166 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`claim_ratio_routine`() -BEGIN - DECLARE vMonthToRefund INT DEFAULT 4; - - /* - * PAK 2015-11-20 - * Se trata de añadir a la tabla Greuges todos los - * cargos que luego vamos a utilizar para calcular el recobro - */ - - -- Reclamaciones demasiado sensibles - - INSERT INTO vn.greuge(shipped, clientFk, description, - amount, greugeTypeFk, ticketFk) - SELECT c.ticketCreated - , c.clientFk - , concat('Claim ', c.id,' : ', s.concept) - ,round( -1 * ((c.responsibility -1)/4) * s.quantity * - s.price * (100 - s.discount) / 100, 2) - , 4 - , s.ticketFk - FROM vn.sale s - JOIN vn.claimEnd ce ON ce.saleFk = s.id - JOIN vn.claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3; - - -- Reclamaciones que pasan a Maná - - INSERT INTO vn.greuge(shipped, clientFk, description, - amount, greugeTypeFk, ticketFk) - SELECT c.ticketCreated - , c.clientFk - , concat('Claim_mana ',c.id,' : ', s.concept) - ,round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2) - ,3 - ,s.ticketFk - FROM vn.sale s - JOIN vn.claimEnd ce ON ce.saleFk = s.id - JOIN vn.claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3 - AND c.isChargedToMana; - - -- Marcamos para no repetir - UPDATE vn.claimEnd ce - JOIN vn.claim c ON c.id = ce.claimFk - SET c.isChargedToMana = TRUE - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3; - - -- Recobros - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - CREATE TEMPORARY TABLE tmp.ticket_list - (PRIMARY KEY (Id_Ticket)) - SELECT DISTINCT t.id Id_Ticket - FROM vn.saleComponent sc - JOIN vn.sale s ON sc.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.ticketLastState ts ON ts.ticketFk = t.id - JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk - JOIN vn.state st ON st.id = tt.stateFk - WHERE sc.componentFk = 17 - AND sc.isGreuge = 0 - AND t.shipped >= '2016-10-01' - AND t.shipped < util.VN_CURDATE() - AND st.alertLevel >= 3; - - DELETE g.* - FROM vn.greuge g - JOIN tmp.ticket_list t ON g.ticketFk = t.Id_Ticket - WHERE g.greugeTypeFk = 2; - - INSERT INTO vn.greuge(clientFk, description, amount,shipped, - greugeTypeFk, ticketFk) - SELECT t.clientFk - ,concat('recobro ', s.ticketFk), - round(SUM(sc.value*s.quantity),2) - AS dif, - date(t.shipped) - , 2 - ,tt.Id_Ticket - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id - JOIN vn.saleComponent sc - ON sc.saleFk = s.id AND sc.componentFk = 17 - GROUP BY t.id - HAVING ABS(dif) > 1; - - UPDATE vn.saleComponent sc - JOIN vn.sale s ON s.id = sc.saleFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = s.ticketFk - SET sc.isGreuge = 1 - WHERE sc.componentFk = 17; - - /* - * Recalculamos la ratio de las reclamaciones, que luego - * se va a utilizar en el recobro - */ - - REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT id, 0,0,0,0 - FROM vn.client; - - REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones, - round(Reclamaciones / (12*fm.Consumo),4), 0 - FROM bi.facturacion_media_anual fm - LEFT JOIN( - SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) * - s.quantity * s.price * (100 - s.discount) / 100)) - AS Reclamaciones - FROM vn.sale s - JOIN vn.claimEnd ce ON ce.saleFk = s.id - JOIN vn.claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND c.claimStateFk = 3 - AND c.ticketCreated >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) - GROUP BY c.clientFk - ) claims ON claims.clientFk = fm.Id_Cliente; - - - -- Calculamos el porcentaje del recobro para añadirlo al precio de venta - UPDATE bi.claims_ratio cr - JOIN ( - SELECT clientFk Id_Cliente, IFNULL(SUM(amount), 0) AS Greuge - FROM vn.greuge - WHERE shipped <= util.VN_CURDATE() - GROUP BY clientFk - ) g ON g.Id_Cliente = cr.Id_Cliente - SET recobro = GREATEST(0,round(IFNULL(Greuge, 0) / - (IFNULL(Consumo, 0) * vMonthToRefund / 12 ) ,3)); - - -- Protección neonatos - UPDATE bi.claims_ratio cr - JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente - SET recobro = 0, Ratio = 0 - WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); - - -- CLIENTE 7983, JULIAN SUAU - UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; - - -- CLIENTE 4358 - UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 4358; - - -- CLIENTE 5523, VERDECORA - UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; - - -- CLIENTE 15979, SERVEIS VETERINARIS - UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 15979; - - -- CLIENTE 5189 i 8942, son de CSR i son el mateix client - UPDATE bi.claims_ratio cr - JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro - FROM bi.claims_ratio - WHERE Id_Cliente IN ( 5189,8942) - ) sub - SET cr.recobro = sub.recobro - WHERE Id_Cliente IN ( 5189,8942); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql new file mode 100644 index 000000000..2f64f8c7e --- /dev/null +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -0,0 +1,154 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`() +BEGIN +/* +* PAK 2015-11-20 +* Se trata de añadir a la tabla Greuges todos los +* cargos que luego vamos a utilizar para calcular el recobro +*/ + DECLARE vMonthToRefund INT DEFAULT 4; + DECLARE vRecoveryGreugeType INT; + + SELECT id INTO vRecoveryGreugeType + FROM greugeType + WHERE code = 'recovery'; + + -- Reclamaciones demasiado sensibles + INSERT INTO greuge(shipped, clientFk, description, + amount, greugeTypeFk, ticketFk) + SELECT c.ticketCreated + , c.clientFk + , concat('Claim ', c.id,' : ', s.concept) + ,round( -1 * ((c.responsibility -1)/4) * s.quantity * + s.price * (100 - s.discount) / 100, 2) + , 4 + , s.ticketFk + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claim c ON c.id = ce.claimFk + WHERE ce.claimDestinationFk NOT IN (1,5) + AND NOT ce.isGreuge + AND c.claimStateFk = 3; + + -- Reclamaciones que pasan a Maná + INSERT INTO greuge(shipped, + clientFk, + `description`, + amount, + greugeTypeFk, + ticketFk) + SELECT c.ticketCreated, + c.clientFk, + concat('Claim_mana ',c.id,' : ', s.concept), + round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), + 3, + s.ticketFk + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claim c ON c.id = ce.claimFk + WHERE ce.claimDestinationFk NOT IN (1,5) + AND NOT ce.isGreuge + AND c.claimStateFk = 3 + AND c.isChargedToMana; + + -- Marcamos para no repetir + UPDATE claimEnd ce + JOIN claim c ON c.id = ce.claimFk + SET c.isChargedToMana = TRUE + WHERE ce.claimDestinationFk NOT IN (1,5) + AND NOT ce.isGreuge + AND c.claimStateFk = 3; + + -- Recobros + CREATE OR REPLACE TEMPORARY TABLE tTicketList + (PRIMARY KEY (ticketFk)) + SELECT DISTINCT s.ticketFk + FROM saleComponent sc + JOIN sale s ON sc.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN ticketLastState ts ON ts.ticketFk = t.id + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state st ON st.id = tt.stateFk + WHERE sc.componentFk = 17 + AND sc.isGreuge = 0 + AND t.shipped >= '2016-10-01' + AND t.shipped < util.VN_CURDATE() + AND st.alertLevel >= 3; + + DELETE g.* + FROM greuge g + JOIN tTicketList t ON t.ticketFk = g.ticketFk + WHERE g.greugeTypeFk = vRecoveryGreugeType; + + INSERT INTO greuge(clientFk, + `description`, + amount, + shipped, + greugeTypeFk, + ticketFk) + SELECT t.clientFk, + 'Recobro', + - ROUND(SUM(sc.value * s.quantity), 2) dif, + DATE(t.shipped), + vRecoveryGreugeType, + tl.ticketFk + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN tTicketList tl ON tl.ticketFk = t.id + JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = 17 + GROUP BY t.id + HAVING ABS(dif) > 1; + + UPDATE saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN tTicketList tl ON tl.ticketFk = s.ticketFk + SET sc.isGreuge = TRUE + WHERE sc.componentFk = 17; + + /* + * Recalculamos la ratio de las reclamaciones, que luego + * se va a utilizar en el recobro + */ + REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) + SELECT id, 0, 0, 0, 0 + FROM client; + + REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) + SELECT cac.clientFk, 12 * cac.invoiced, totalClaims, + ROUND(totalClaims / (12 * cac.invoiced), 4), 0 + FROM bs.clientAnnualConsumption cac + LEFT JOIN( + SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) * + s.quantity * s.price * (100 - s.discount) / 100)) + totalClaims + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claim c ON c.id = ce.claimFk + WHERE ce.claimDestinationFk NOT IN (1,5) + AND c.claimStateFk = 3 + AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR + GROUP BY c.clientFk + ) claims ON claims.clientFk = fm.Id_Cliente; + + -- Calculamos el porcentaje del recobro para añadirlo al precio de venta + UPDATE claimRatio cr + JOIN ( + SELECT clientFk, IFNULL(SUM(amount), 0) AS Greuge + FROM greuge + WHERE shipped <= util.VN_CURDATE() + GROUP BY clientFk + ) g ON g.clientFk = cr.clientFk + SET cr.priceIncreasing = GREATEST(0, round(IFNULL(Greuge, 0) / + (IFNULL(Consumo, 0) * vMonthToRefund / 12 ), 3)); + + -- Protección neonatos + UPDATE claimRatio cr + JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk + SET cr.priceIncreasing = 0, + cr.claimingRate = 0 + WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH; + + DROP TEMPORARY TABLE tTicketList; +END$$ +DELIMITER ; diff --git a/db/versions/11028-silverCarnation/00-firstScript.sql b/db/versions/11028-silverCarnation/00-firstScript.sql new file mode 100644 index 000000000..f865b0caf --- /dev/null +++ b/db/versions/11028-silverCarnation/00-firstScript.sql @@ -0,0 +1,4 @@ +UPDATE IGNORE bs.nightTask + SET `procedure` = 'claimRatio_add', + `schema` = 'vn' + WHERE `procedure` = 'claim_ratio_routine'; From 883f6f18a3b48560e82446251453057f5ef4a894 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 3 May 2024 13:47:55 +0200 Subject: [PATCH 02/30] refactor: refs #6701 Refactor claim_ratio_routine --- db/routines/vn/procedures/claimRatio_add.sql | 171 ++++++++++++------- 1 file changed, 108 insertions(+), 63 deletions(-) diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 2f64f8c7e..deb5cc068 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -7,57 +7,82 @@ BEGIN * cargos que luego vamos a utilizar para calcular el recobro */ DECLARE vMonthToRefund INT DEFAULT 4; - DECLARE vRecoveryGreugeType INT; + DECLARE vRecoveryGreugeType INT + DEFAULT (SELECT id FROM greugeType WHERE code = 'recovery'); + DECLARE vManaGreugeType INT + DEFAULT (SELECT id FROM greugeType WHERE code = 'mana'); + DECLARE vClaimGreugeType INT + DEFAULT (SELECT id FROM greugeType WHERE code = 'claim'); + DECLARE vDebtComponentType INT + DEFAULT (SELECT id FROM component WHERE code = 'debtCollection'); - SELECT id INTO vRecoveryGreugeType - FROM greugeType - WHERE code = 'recovery'; + IF vRecoveryGreugeType IS NULL + OR vManaGreugeType IS NULL + OR vClaimGreugeType IS NULL + OR vDebtComponentType IS NULL THEN + + CALL util.throw('Required variables not found'); + END IF; -- Reclamaciones demasiado sensibles - INSERT INTO greuge(shipped, clientFk, description, - amount, greugeTypeFk, ticketFk) - SELECT c.ticketCreated - , c.clientFk - , concat('Claim ', c.id,' : ', s.concept) - ,round( -1 * ((c.responsibility -1)/4) * s.quantity * - s.price * (100 - s.discount) / 100, 2) - , 4 - , s.ticketFk - FROM sale s - JOIN claimEnd ce ON ce.saleFk = s.id - JOIN claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND NOT ce.isGreuge - AND c.claimStateFk = 3; - - -- Reclamaciones que pasan a Maná - INSERT INTO greuge(shipped, - clientFk, - `description`, - amount, - greugeTypeFk, - ticketFk) + INSERT INTO greuge( + shipped, + clientFk, + `description`, + amount, + greugeTypeFk, + ticketFk + ) SELECT c.ticketCreated, c.clientFk, - concat('Claim_mana ',c.id,' : ', s.concept), - round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), - 3, + CONCAT('Claim ', c.id,' : ', s.concept), + ROUND(-1 * ((c.responsibility - 1) / 4) * s.quantity * + s.price * (100 - s.discount) / 100, 2), + vClaimGreugeType, s.ticketFk FROM sale s JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) + JOIN claimState cs ON cs.id = c.claimStateFk + WHERE ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge - AND c.claimStateFk = 3 + AND cs.code = 'resolved'; + + -- Reclamaciones que pasan a Maná + INSERT INTO greuge( + shipped, + clientFk, + `description`, + amount, + greugeTypeFk, + ticketFk + ) + SELECT c.ticketCreated, + c.clientFk, + CONCAT('Claim_mana ', c.id,' : ', s.concept), + ROUND( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), + vManaGreugeType, + s.ticketFk + FROM sale s + JOIN claimEnd ce ON ce.saleFk = s.id + 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') + AND NOT ce.isGreuge + AND cs.code = 'resolved' AND c.isChargedToMana; -- Marcamos para no repetir UPDATE claimEnd ce + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk + JOIN claimState cs ON cs.id = c.claimStateFk SET c.isChargedToMana = TRUE - WHERE ce.claimDestinationFk NOT IN (1,5) + WHERE cd.description NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge - AND c.claimStateFk = 3; + AND cs.code = 'resolved'; -- Recobros CREATE OR REPLACE TEMPORARY TABLE tTicketList @@ -69,23 +94,26 @@ BEGIN JOIN ticketLastState ts ON ts.ticketFk = t.id JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk JOIN state st ON st.id = tt.stateFk - WHERE sc.componentFk = 17 - AND sc.isGreuge = 0 + JOIN alertLevel al ON al.id = st.alertLevel + WHERE sc.componentFk = vDebtComponentType + AND NOT sc.isGreuge AND t.shipped >= '2016-10-01' AND t.shipped < util.VN_CURDATE() - AND st.alertLevel >= 3; + AND al.code = 'DELIVERED'; DELETE g.* FROM greuge g JOIN tTicketList t ON t.ticketFk = g.ticketFk WHERE g.greugeTypeFk = vRecoveryGreugeType; - INSERT INTO greuge(clientFk, - `description`, - amount, - shipped, - greugeTypeFk, - ticketFk) + INSERT INTO greuge( + clientFk, + `description`, + amount, + shipped, + greugeTypeFk, + ticketFk + ) SELECT t.clientFk, 'Recobro', - ROUND(SUM(sc.value * s.quantity), 2) dif, @@ -96,51 +124,68 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk JOIN tTicketList tl ON tl.ticketFk = t.id JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = 17 + AND sc.componentFk = vDebtComponentType GROUP BY t.id - HAVING ABS(dif) > 1; + HAVING ABS(dif) > 1; UPDATE saleComponent sc JOIN sale s ON s.id = sc.saleFk JOIN tTicketList tl ON tl.ticketFk = s.ticketFk SET sc.isGreuge = TRUE - WHERE sc.componentFk = 17; + WHERE sc.componentFk = vDebtComponentType; /* * Recalculamos la ratio de las reclamaciones, que luego * se va a utilizar en el recobro */ - REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) - SELECT id, 0, 0, 0, 0 - FROM client; + REPLACE claimRatio( + clientFk, + yearSale, + claimAmount, + claimingRate, + priceIncreasing + ) + SELECT id, 0, 0, 0, 0 FROM client; - REPLACE claimRatio(clientFk, yearSale, claimAmount, claimingRate, priceIncreasing) - SELECT cac.clientFk, 12 * cac.invoiced, totalClaims, - ROUND(totalClaims / (12 * cac.invoiced), 4), 0 + REPLACE claimRatio( + clientFk, + yearSale, + claimAmount, + claimingRate, + priceIncreasing + ) + SELECT cac.clientFk, + 12 * cac.invoiced, + totalClaims, + ROUND(totalClaims / (12 * cac.invoiced), 4), + 0 FROM bs.clientAnnualConsumption cac - LEFT JOIN( - SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) * - s.quantity * s.price * (100 - s.discount) / 100)) - totalClaims + LEFT JOIN ( + SELECT c.clientFk, + ROUND(SUM(-1 * ((c.responsibility - 1) / 4) * + s.quantity * s.price * (100 - s.discount) + / 100)) totalClaims FROM sale s JOIN claimEnd ce ON ce.saleFk = s.id + JOIN claimDestination cd ON cd.id = ce.claimDestinationFk JOIN claim c ON c.id = ce.claimFk - WHERE ce.claimDestinationFk NOT IN (1,5) - AND c.claimStateFk = 3 + JOIN claimState cs ON cs.id = c.claimStateFk + WHERE ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') + AND cs.code = 'resolved' AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR GROUP BY c.clientFk - ) claims ON claims.clientFk = fm.Id_Cliente; + ) sub ON sub.clientFk = cac.clientFk; -- Calculamos el porcentaje del recobro para añadirlo al precio de venta UPDATE claimRatio cr JOIN ( - SELECT clientFk, IFNULL(SUM(amount), 0) AS Greuge + SELECT clientFk, IFNULL(SUM(amount), 0) greuge FROM greuge WHERE shipped <= util.VN_CURDATE() GROUP BY clientFk - ) g ON g.clientFk = cr.clientFk - SET cr.priceIncreasing = GREATEST(0, round(IFNULL(Greuge, 0) / - (IFNULL(Consumo, 0) * vMonthToRefund / 12 ), 3)); + ) sub ON subg.clientFk = cr.clientFk + SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) / + (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)); -- Protección neonatos UPDATE claimRatio cr From f0b814c79b895ee4ac6487a6a4494c35feaf8c64 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 3 May 2024 14:15:55 +0200 Subject: [PATCH 03/30] refactor: refs #6701 Refactor claim_ratio_routine --- db/dump/fixtures.before.sql | 6 +-- db/routines/vn/procedures/claimRatio_add.sql | 37 +++++++------------ .../11028-silverCarnation/00-firstScript.sql | 6 +++ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 06e94c99e..6b8166caa 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -831,9 +831,9 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) VALUES (1, 'Diff', 'diff'), - (2, 'Recover', 'recover'), - (3, 'Mana', 'mana'), - (4, 'Reclaim', 'reclaim'), + (2, 'Recobro', 'recovery'), + (3, 'Maná', 'mana'), + (4, 'Reclamación', 'claim'), (5, 'Heritage', 'heritage'), (6, 'Miscellaneous', 'miscellaneous'), (7, 'Freight Pickup', 'freightPickUp'); diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index deb5cc068..36b9023da 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -2,9 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`() BEGIN /* -* PAK 2015-11-20 -* Se trata de añadir a la tabla Greuges todos los -* cargos que luego vamos a utilizar para calcular el recobro +* Añade a la tabla greuges todos los cargos necesario y +* que luego lo utilizamos para calcular el recobro. */ DECLARE vMonthToRefund INT DEFAULT 4; DECLARE vRecoveryGreugeType INT @@ -61,7 +60,8 @@ BEGIN SELECT c.ticketCreated, c.clientFk, CONCAT('Claim_mana ', c.id,' : ', s.concept), - ROUND( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2), + ROUND(((c.responsibility - 1) / 4) * s.quantity * + s.price * (100 - s.discount) / 100, 2), vManaGreugeType, s.ticketFk FROM sale s @@ -134,20 +134,7 @@ BEGIN SET sc.isGreuge = TRUE WHERE sc.componentFk = vDebtComponentType; - /* - * Recalculamos la ratio de las reclamaciones, que luego - * se va a utilizar en el recobro - */ - REPLACE claimRatio( - clientFk, - yearSale, - claimAmount, - claimingRate, - priceIncreasing - ) - SELECT id, 0, 0, 0, 0 FROM client; - - REPLACE claimRatio( + INSERT INTO claimRatio( clientFk, yearSale, claimAmount, @@ -163,8 +150,8 @@ BEGIN LEFT JOIN ( SELECT c.clientFk, ROUND(SUM(-1 * ((c.responsibility - 1) / 4) * - s.quantity * s.price * (100 - s.discount) - / 100)) totalClaims + s.quantity * s.price * (100 - s.discount) + / 100)) totalClaims FROM sale s JOIN claimEnd ce ON ce.saleFk = s.id JOIN claimDestination cd ON cd.id = ce.claimDestinationFk @@ -183,17 +170,19 @@ BEGIN FROM greuge WHERE shipped <= util.VN_CURDATE() GROUP BY clientFk - ) sub ON subg.clientFk = cr.clientFk + ) sub ON sub.clientFk = cr.clientFk SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) / - (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)); + (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)) + WHERE cr.dated = util.VN_CURDATE(); -- Protección neonatos UPDATE claimRatio cr JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk SET cr.priceIncreasing = 0, cr.claimingRate = 0 - WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH; - + WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH + AND cr.dated = util.VN_CURDATE(); + DROP TEMPORARY TABLE tTicketList; END$$ DELIMITER ; diff --git a/db/versions/11028-silverCarnation/00-firstScript.sql b/db/versions/11028-silverCarnation/00-firstScript.sql index f865b0caf..9d291f451 100644 --- a/db/versions/11028-silverCarnation/00-firstScript.sql +++ b/db/versions/11028-silverCarnation/00-firstScript.sql @@ -2,3 +2,9 @@ UPDATE IGNORE bs.nightTask SET `procedure` = 'claimRatio_add', `schema` = 'vn' WHERE `procedure` = 'claim_ratio_routine'; + +ALTER TABLE vn.claimRatio ADD dated DATE DEFAULT current_timestamp() NOT NULL; +ALTER TABLE vn.claimRatio CHANGE dated dated DATE DEFAULT current_timestamp() NOT NULL FIRST; +ALTER TABLE vn.claimRatio DROP FOREIGN KEY claimRatio_ibfk_1; +ALTER TABLE vn.claimRatio DROP PRIMARY KEY; +ALTER TABLE vn.claimRatio ADD CONSTRAINT claimRatio_pk PRIMARY KEY (dated,clientFk); From 49fed4e51e45f1d203ca43f13ed3c4cb02cd5cb2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 22 May 2024 12:23:33 +0200 Subject: [PATCH 04/30] refs #6964 feat: hasItemOlder --- db/versions/11064-grayMedeola/00-firstScript.sql | 6 ++++++ .../back/methods/item-shelving/hasItemOlder.js | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 db/versions/11064-grayMedeola/00-firstScript.sql diff --git a/db/versions/11064-grayMedeola/00-firstScript.sql b/db/versions/11064-grayMedeola/00-firstScript.sql new file mode 100644 index 000000000..301c0fef1 --- /dev/null +++ b/db/versions/11064-grayMedeola/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.sector ADD hasItemOlderReview BIGINT DEFAULT false NULL COMMENT 'Indica si el sector se revisa para comprobar si tiene ítems más viejos'; +ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js index ee4cdc829..02cd14bb8 100644 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ b/modules/item/back/methods/item-shelving/hasItemOlder.js @@ -46,17 +46,22 @@ module.exports = Self => { SELECT COUNT(ish.id) countItemOlder FROM vn.itemShelving ish JOIN ( - SELECT ish.itemFk, created,shelvingFk + SELECT ish.itemFk, created, shelvingFk FROM vn.itemShelving ish JOIN vn.shelving s ON ish.shelvingFk = s.code + LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk WHERE ish.shelvingFk = ? )sub ON sub.itemFK = ish.itemFk JOIN vn.shelving s ON s.code = ish.shelvingFk JOIN vn.parking p ON p.id = s.parkingFk - WHERE sub.created > ish.created - AND (p.code <> ? OR ? IS NULL) - AND (ish.shelvingFk <> ? OR ? IS NULL) - AND (ish.itemFk <> ? OR ? IS NULL)`, + JOIN vn.sector s2 ON s2.id = p.sectorFk + JOIN vn.productionConfig pc ON pc.itemOlderReviewHours + WHERE ish.created + INTERVAL pc.itemOlderReviewHours HOUR < sub.created + AND (p.code <> ? OR ? IS NULL) + AND (ish.shelvingFk <> ? OR ? IS NULL) + AND (ish.itemFk = ? OR ? IS NULL) + AND (p.pickingOrder < sub.pickingOrder OR sub.pickingOrder IS NULL) + AND (s2.hasItemOlderReview)`, [shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions); return result[0]['countItemOlder'] > 0; }; From 0914925a860d6978f848c9315a38456307e1cc3f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 23 May 2024 13:43:00 +0200 Subject: [PATCH 05/30] refs #6964 feat: hasItemOlder --- modules/item/back/methods/item-shelving/hasItemOlder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js index 02cd14bb8..9bea6fbe9 100644 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ b/modules/item/back/methods/item-shelving/hasItemOlder.js @@ -46,7 +46,7 @@ module.exports = Self => { SELECT COUNT(ish.id) countItemOlder FROM vn.itemShelving ish JOIN ( - SELECT ish.itemFk, created, shelvingFk + SELECT ish.itemFk, created, shelvingFk, pickingOrder FROM vn.itemShelving ish JOIN vn.shelving s ON ish.shelvingFk = s.code LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk From 4703ebbdf3ce7922f16a52d852d90ee3abd94cbe Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 11:38:09 +0200 Subject: [PATCH 06/30] refactor: refs #7519 Minor change --- db/dump/fixtures.before.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6b8166caa..8bcedeb8d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -831,9 +831,9 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) VALUES (1, 'Diff', 'diff'), - (2, 'Recobro', 'recovery'), - (3, 'Maná', 'mana'), - (4, 'Reclamación', 'claim'), + (2, 'Recovery', 'recovery'), + (3, 'Mana', 'mana'), + (4, 'Claim', 'claim'), (5, 'Heritage', 'heritage'), (6, 'Miscellaneous', 'miscellaneous'), (7, 'Freight Pickup', 'freightPickUp'); From 8cef8eace7a92a8fb96fd124dd720fd07a455304 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 11:41:09 +0200 Subject: [PATCH 07/30] refactor: refs #7519 Minor change --- db/routines/vn/procedures/claimRatio_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 36b9023da..2e999f738 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -79,7 +79,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 - SET c.isChargedToMana = TRUE + SET ce.isGreuge = TRUE WHERE cd.description NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge AND cs.code = 'resolved'; From b8e95c02840358fb279008df97e0b4fed160bc0f Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 11:46:52 +0200 Subject: [PATCH 08/30] refactor: refs #7519 Minor change --- db/routines/vn/procedures/claimRatio_add.sql | 6 ++---- db/versions/11028-silverCarnation/00-firstScript.sql | 10 ---------- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 db/versions/11028-silverCarnation/00-firstScript.sql diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 2e999f738..7def0837f 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -172,16 +172,14 @@ BEGIN GROUP BY clientFk ) sub ON sub.clientFk = cr.clientFk SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) / - (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)) - WHERE cr.dated = util.VN_CURDATE(); + (IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3)); -- Protección neonatos UPDATE claimRatio cr JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk SET cr.priceIncreasing = 0, cr.claimingRate = 0 - WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH - AND cr.dated = util.VN_CURDATE(); + WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH; DROP TEMPORARY TABLE tTicketList; END$$ diff --git a/db/versions/11028-silverCarnation/00-firstScript.sql b/db/versions/11028-silverCarnation/00-firstScript.sql deleted file mode 100644 index 9d291f451..000000000 --- a/db/versions/11028-silverCarnation/00-firstScript.sql +++ /dev/null @@ -1,10 +0,0 @@ -UPDATE IGNORE bs.nightTask - SET `procedure` = 'claimRatio_add', - `schema` = 'vn' - WHERE `procedure` = 'claim_ratio_routine'; - -ALTER TABLE vn.claimRatio ADD dated DATE DEFAULT current_timestamp() NOT NULL; -ALTER TABLE vn.claimRatio CHANGE dated dated DATE DEFAULT current_timestamp() NOT NULL FIRST; -ALTER TABLE vn.claimRatio DROP FOREIGN KEY claimRatio_ibfk_1; -ALTER TABLE vn.claimRatio DROP PRIMARY KEY; -ALTER TABLE vn.claimRatio ADD CONSTRAINT claimRatio_pk PRIMARY KEY (dated,clientFk); From cac1278c080451d9760d4f48f7dadd0a9e066945 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 7 Jun 2024 16:29:51 +0200 Subject: [PATCH 09/30] feat hsItemOlder refs $6964 --- .../11064-grayMedeola/00-firstScript.sql | 3 +- loopback/locale/es.json | 3 +- .../methods/item-shelving/getListItemNewer.js | 68 +++++++++++++++++++ .../methods/item-shelving/hasItemOlder.js | 68 ------------------- .../specs/getListItemNewer.spec.js | 40 +++++++++++ .../item-shelving/specs/hasItemOlder.spec.js | 45 ------------ modules/item/back/models/item-shelving.js | 2 +- 7 files changed, 112 insertions(+), 117 deletions(-) create mode 100644 modules/item/back/methods/item-shelving/getListItemNewer.js delete mode 100644 modules/item/back/methods/item-shelving/hasItemOlder.js create mode 100644 modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js delete mode 100644 modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js diff --git a/db/versions/11064-grayMedeola/00-firstScript.sql b/db/versions/11064-grayMedeola/00-firstScript.sql index 301c0fef1..b5af3599b 100644 --- a/db/versions/11064-grayMedeola/00-firstScript.sql +++ b/db/versions/11064-grayMedeola/00-firstScript.sql @@ -2,5 +2,4 @@ USE vn; -ALTER TABLE vn.sector ADD hasItemOlderReview BIGINT DEFAULT false NULL COMMENT 'Indica si el sector se revisa para comprobar si tiene ítems más viejos'; -ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; +ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) DEFAULT 0 NOT NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.'; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 77e707590..8244deb8a 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -358,5 +358,6 @@ "Select ticket or client": "Elija un ticket o un client", "It was not able to create the invoice": "No se pudo crear la factura", "This PDA is already assigned to another user": "This PDA is already assigned to another user", - "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)" + "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", + "parkingNotExist": "parkingNotExist" } \ No newline at end of file diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js new file mode 100644 index 000000000..a6ab0e5f1 --- /dev/null +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -0,0 +1,68 @@ +module.exports = Self => { + Self.remoteMethod('getListItemNewer', { + description: + 'Get boolean if any or specific item of the shelving has older created in another shelving or parking', + accessType: 'READ', + accepts: [{ + arg: 'shelvingFk', + type: 'string', + required: true, + description: 'Shelving code' + }, + { + arg: 'parking', + type: 'string', + required: true, + description: 'Parking code' + }, + ], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/getListItemNewer`, + verb: 'GET' + } + }); + + Self.getListItemNewer = async(shelvingFk, parking, options) => { + const myOptions = {}; + if (typeof options == 'object') + Object.assign(myOptions, options); + + const isParkingToReview = await Self.rawSql(` + SELECT COUNT(p.id) parkingToReview + FROM vn.parking p + JOIN vn.sector s ON s.id = p.sectorFk + WHERE p.code = ? AND s.code = "CAMARA SECTOR D";`, + [parking], myOptions); + + if (isParkingToReview[0]['parkingToReview'] > 0) { + const result = await Self.rawSql(` + WITH tItemShelving AS( + SELECT is2.itemFk, is2.created, p.sectorFK, is2.id + FROM vn.itemShelving is2 + JOIN vn.shelving sh ON sh.code = is2.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE is2.shelvingFk = ? AND s.code = "NAVE ALGEMESI" + ), tItemInSector AS ( + SELECT is2.itemFk, is2.created, is2.shelvingFk + FROM vn.itemShelving is2 + JOIN vn.shelving sh ON sh.code = is2.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE is2.shelvingFk <> ? + AND s.code = "NAVE ALGEMESI") + SELECT ti.itemFK, tis.shelvingFk + FROM tItemShelving ti + JOIN tItemInSector tis ON tis.itemFk = ti.itemFk + JOIN vn.productionConfig pc + WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`, + [shelvingFk, shelvingFk], myOptions); + return result; + } else + return []; + }; +}; diff --git a/modules/item/back/methods/item-shelving/hasItemOlder.js b/modules/item/back/methods/item-shelving/hasItemOlder.js deleted file mode 100644 index 9bea6fbe9..000000000 --- a/modules/item/back/methods/item-shelving/hasItemOlder.js +++ /dev/null @@ -1,68 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); -module.exports = Self => { - Self.remoteMethod('hasItemOlder', { - description: - 'Get boolean if any or specific item of the shelving has older created in another shelving or parking', - accessType: 'READ', - accepts: [{ - arg: 'shelvingFkIn', - type: 'string', - required: true, - description: 'Shelving code' - }, - { - arg: 'parking', - type: 'string', - description: 'Parking code' - }, - { - arg: 'shelvingFkOut', - type: 'string', - description: 'Shelving code' - }, - { - arg: 'itemFk', - type: 'integer', - description: 'Item id' - }], - returns: { - type: 'boolean', - root: true - }, - http: { - path: `/hasItemOlder`, - verb: 'GET' - } - }); - - Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => { - if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving'); - - const myOptions = {}; - if (typeof options == 'object') - Object.assign(myOptions, options); - - const result = await Self.rawSql(` - SELECT COUNT(ish.id) countItemOlder - FROM vn.itemShelving ish - JOIN ( - SELECT ish.itemFk, created, shelvingFk, pickingOrder - FROM vn.itemShelving ish - JOIN vn.shelving s ON ish.shelvingFk = s.code - LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk - WHERE ish.shelvingFk = ? - )sub ON sub.itemFK = ish.itemFk - JOIN vn.shelving s ON s.code = ish.shelvingFk - JOIN vn.parking p ON p.id = s.parkingFk - JOIN vn.sector s2 ON s2.id = p.sectorFk - JOIN vn.productionConfig pc ON pc.itemOlderReviewHours - WHERE ish.created + INTERVAL pc.itemOlderReviewHours HOUR < sub.created - AND (p.code <> ? OR ? IS NULL) - AND (ish.shelvingFk <> ? OR ? IS NULL) - AND (ish.itemFk = ? OR ? IS NULL) - AND (p.pickingOrder < sub.pickingOrder OR sub.pickingOrder IS NULL) - AND (s2.hasItemOlderReview)`, - [shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions); - return result[0]['countItemOlder'] > 0; - }; -}; diff --git a/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js new file mode 100644 index 000000000..5f0f7d826 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js @@ -0,0 +1,40 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('itemShelving getListItemNewer()', () => { + fit('should return true because there is an older item', async() => { + const shelving = 'NCC'; + const parking = 'A-47-1'; + const sectorCam = 1; + const sectorCamCode = 'CAMARA SECTOR D'; + const sectorCamHigh = 9991; + const sectorCamHighCode = 'NAVE ALGEMESI'; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + const filter = {where: {id: sectorCam}}; + const filterHigh = {where: {id: sectorCamHigh}}; + + try { + const sectorCamBefore = await models.Sector.findOne(filter, myOptions); + + await sectorCamBefore.updateAttributes({ + code: sectorCamCode + }, myOptions); + + const sectorCamHighBefore = await models.Sector.findOne(filterHigh, myOptions); + await sectorCamHighBefore.updateAttributes({ + code: sectorCamHighCode + }, myOptions); + + const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions); + + expect(result.length).toEqual(2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js b/modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js deleted file mode 100644 index abffead53..000000000 --- a/modules/item/back/methods/item-shelving/specs/hasItemOlder.spec.js +++ /dev/null @@ -1,45 +0,0 @@ - -const {models} = require('vn-loopback/server/server'); - -describe('itemShelving hasOlder()', () => { - it('should return false because there are not older items', async() => { - const shelvingFkIn = 'GVC'; - const shelvingFkOut = 'HEJ'; - const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut); - - expect(result).toBe(false); - }); - - it('should return false because there are not older items in parking', async() => { - const shelvingFkIn = 'HEJ'; - const parking = '700-01'; - const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking); - - expect(result).toBe(false); - }); - - it('should return true because there is an older item', async() => { - const shelvingFkIn = 'UXN'; - const shelvingFkOut = 'PCC'; - const parking = 'A-01-1'; - const itemFk = 1; - - const tx = await models.ItemShelving.beginTransaction({}); - const myOptions = {transaction: tx}; - const filter = {where: {shelvingFk: shelvingFkOut} - }; - try { - const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions); - await itemShelvingBefore.updateAttributes({ - itemFk: itemFk - }, myOptions); - const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions); - - expect(result).toBe(true); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index d48ee10d5..be72dac37 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -4,5 +4,5 @@ module.exports = Self => { require('../methods/item-shelving/getInventory')(Self); require('../methods/item-shelving/getAlternative')(Self); require('../methods/item-shelving/updateFromSale')(Self); - require('../methods/item-shelving/hasItemOlder')(Self); + require('../methods/item-shelving/getListItemNewer')(Self); }; From 9b21cd5eb1e52712e34d0a7ae3941ff3c8dad612 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 08:38:58 +0200 Subject: [PATCH 10/30] refactor: refs #7490 Deleted update duaInvoiceInBooking --- .../vn/procedures/duaInvoiceInBooking.sql | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 8b4df6a73..018c72e0e 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -1,5 +1,7 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`( + vDuaFk INT +) BEGIN /** * Genera el asiento de un DUA y marca las entradas como confirmadas @@ -22,18 +24,6 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - UPDATE invoiceIn ii - JOIN entry e ON e.invoiceInFk = ii.id - JOIN duaEntry de ON de.entryFk = e.id - JOIN dua d ON d.id = de.duaFk - SET ii.booked = IFNULL(ii.booked, d.booked), - ii.operated = IFNULL(ii.operated, d.operated), - ii.issued = IFNULL(ii.issued, d.issued), - ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried), - e.isBooked = TRUE, - e.isConfirmed = TRUE - WHERE d.id = vDuaFk; - SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk; IF vBookEntry IS NULL THEN From fb4be69cf12737ef71bc29a2ee24a20f9e3b32ee Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 08:47:02 +0200 Subject: [PATCH 11/30] refactor: refs #7490 Added final update --- .../vn/procedures/duaInvoiceInBooking.sql | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 018c72e0e..9cbf54b4a 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -4,10 +4,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking ) BEGIN /** - * Genera el asiento de un DUA y marca las entradas como confirmadas - * - * @param vDuaFk Id del dua a recalcular - */ +* Genera el asiento de un DUA y marca las entradas como confirmadas +* +* @param vDuaFk Id del dua a recalcular +*/ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; DECLARE vBookEntry INT; @@ -29,7 +29,7 @@ BEGIN IF vBookEntry IS NULL THEN SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear FROM invoiceIn ii - JOIN entry e ON e.invoiceInFk = ii.id + JOIN `entry` e ON e.invoiceInFk = ii.id JOIN duaEntry de ON de.entryFk = e.id JOIN dua d ON d.id = de.duaFk WHERE d.id = vDuaFk @@ -60,5 +60,28 @@ l: LOOP JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id SET ii.isBooked = TRUE WHERE dii.duaFk = vDuaFk; + + UPDATE `entry` e + JOIN ( + WITH entries AS ( + SELECT e.id, de.duaFk + FROM `entry` e + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk + AND (NOT e.isBooked OR NOT e.isConfirmed) + ), + notBookedEntries AS ( + SELECT e.id + FROM entries e + JOIN duaEntry de ON de.entryFk = e.id + JOIN dua d ON d.id = de.duaFk + WHERE d.ASIEN IS NULL) + SELECT e.id + FROM entries e + LEFT JOIN notBookedEntries nbe ON nbe.id = e.id + WHERE nbe.id IS NULL + ) sub ON sub.id = e.id + SET e.isBooked = TRUE, + e.isConfirmed = TRUE; END$$ DELIMITER ; From 317f898c2eb1a63fea6bd0f024c1b136251b92ca Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 08:48:56 +0200 Subject: [PATCH 12/30] refactor: refs #7490 Minor changes --- db/routines/vn/procedures/duaInvoiceInBooking.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 9cbf54b4a..efaf29b41 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -4,10 +4,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking ) BEGIN /** -* Genera el asiento de un DUA y marca las entradas como confirmadas -* -* @param vDuaFk Id del dua a recalcular -*/ + * Genera el asiento de un DUA y marca las entradas como confirmadas + * + * @param vDuaFk Id del dua a recalcular + */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; DECLARE vBookEntry INT; @@ -39,7 +39,7 @@ BEGIN OPEN vInvoicesIn; -l: LOOP + l: LOOP SET vDone = FALSE; FETCH vInvoicesIn INTO vInvoiceFk; From d0b926b2c5176685324836649ba1ed4ed3936f38 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 12 Jun 2024 14:26:26 +0200 Subject: [PATCH 13/30] feat: refs #7490 Changes --- .../vn/procedures/duaInvoiceInBooking.sql | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index efaf29b41..1f026e96b 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -24,6 +24,16 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + UPDATE invoiceIn ii + JOIN entry e ON e.invoiceInFk = ii.id + JOIN duaEntry de ON de.entryFk = e.id + JOIN dua d ON d.id = de.duaFk + SET ii.booked = IFNULL(ii.booked, d.booked), + ii.operated = IFNULL(ii.operated, d.operated), + ii.issued = IFNULL(ii.issued, d.issued), + ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried) + WHERE d.id = vDuaFk; + SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk; IF vBookEntry IS NULL THEN @@ -65,21 +75,21 @@ BEGIN JOIN ( WITH entries AS ( SELECT e.id, de.duaFk - FROM `entry` e + FROM `entry` e JOIN duaEntry de ON de.entryFk = e.id WHERE de.duaFk = vDuaFk AND (NOT e.isBooked OR NOT e.isConfirmed) ), notBookedEntries AS ( SELECT e.id - FROM entries e - JOIN duaEntry de ON de.entryFk = e.id - JOIN dua d ON d.id = de.duaFk - WHERE d.ASIEN IS NULL) - SELECT e.id + FROM duaEntry + WHERE duaFk = vDuaFk + AND NOT customsValue + ) + SELECT e.id FROM entries e - LEFT JOIN notBookedEntries nbe ON nbe.id = e.id - WHERE nbe.id IS NULL + LEFT JOIN notBookedEntries nbe ON nbe.entryFk = e.id + WHERE nbe.entryFk IS NULL ) sub ON sub.id = e.id SET e.isBooked = TRUE, e.isConfirmed = TRUE; From cfc5e327154fdc7e5a680395c7ccfce22bde4199 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 13 Jun 2024 13:11:50 +0200 Subject: [PATCH 14/30] feat: refs #6701 Fix error --- db/routines/vn/procedures/claimRatio_add.sql | 43 ++++++++++--------- .../11101-limeCordyline/00-firstScript.sql | 4 ++ 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 db/versions/11101-limeCordyline/00-firstScript.sql diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 7def0837f..8d94805db 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -44,7 +44,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 ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') + WHERE cd.description NOT IN ('Bueno', 'Corregido') AND NOT ce.isGreuge AND cs.code = 'resolved'; @@ -86,20 +86,20 @@ BEGIN -- Recobros CREATE OR REPLACE TEMPORARY TABLE tTicketList - (PRIMARY KEY (ticketFk)) - SELECT DISTINCT s.ticketFk - FROM saleComponent sc - JOIN sale s ON sc.saleFk = s.id - JOIN ticket t ON t.id = s.ticketFk - JOIN ticketLastState ts ON ts.ticketFk = t.id - JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk - JOIN state st ON st.id = tt.stateFk - JOIN alertLevel al ON al.id = st.alertLevel - WHERE sc.componentFk = vDebtComponentType - AND NOT sc.isGreuge - AND t.shipped >= '2016-10-01' - AND t.shipped < util.VN_CURDATE() - AND al.code = 'DELIVERED'; + (PRIMARY KEY (ticketFk)) + SELECT DISTINCT s.ticketFk + FROM saleComponent sc + JOIN sale s ON sc.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN ticketLastState ts ON ts.ticketFk = t.id + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state st ON st.id = tt.stateFk + JOIN alertLevel al ON al.id = st.alertLevel + WHERE sc.componentFk = vDebtComponentType + AND NOT sc.isGreuge + AND t.shipped >= '2016-10-01' + AND t.shipped < util.VN_CURDATE() + AND al.code = 'DELIVERED'; DELETE g.* FROM greuge g @@ -133,20 +133,21 @@ BEGIN JOIN tTicketList tl ON tl.ticketFk = s.ticketFk SET sc.isGreuge = TRUE WHERE sc.componentFk = vDebtComponentType; - - INSERT INTO claimRatio( + + REPLACE claimRatio( clientFk, yearSale, claimAmount, claimingRate, priceIncreasing ) - SELECT cac.clientFk, + SELECT c.id, 12 * cac.invoiced, totalClaims, ROUND(totalClaims / (12 * cac.invoiced), 4), 0 - FROM bs.clientAnnualConsumption cac + FROM client c + LEFT JOIN bs.clientAnnualConsumption cac ON cac.clientFk = c.id LEFT JOIN ( SELECT c.clientFk, ROUND(SUM(-1 * ((c.responsibility - 1) / 4) * @@ -157,11 +158,11 @@ 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 ce.claimDestinationFk NOT IN ('Bueno', 'Corregido') + WHERE cd.description NOT IN ('Bueno', 'Corregido') AND cs.code = 'resolved' AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR GROUP BY c.clientFk - ) sub ON sub.clientFk = cac.clientFk; + ) sub ON sub.clientFk = c.id; -- Calculamos el porcentaje del recobro para añadirlo al precio de venta UPDATE claimRatio cr diff --git a/db/versions/11101-limeCordyline/00-firstScript.sql b/db/versions/11101-limeCordyline/00-firstScript.sql new file mode 100644 index 000000000..e9ffa1b12 --- /dev/null +++ b/db/versions/11101-limeCordyline/00-firstScript.sql @@ -0,0 +1,4 @@ +UPDATE IGNORE bs.nightTask + SET `schema` = 'vn', + `procedure` = 'claimRatio_add' + WHERE `procedure` = 'claim_ratio_routine'; From 9b118f83e5d952c0e029e2eef2b831f270f6c238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 14 Jun 2024 17:56:24 +0200 Subject: [PATCH 15/30] fix: asociar ticketRefund refs #7586 --- modules/ticket/back/methods/sale/clone.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index fa1079fbe..9185a6e75 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -145,15 +145,10 @@ module.exports = Self => { const newTicket = await models.Ticket.new(ctx, myOptions); - const ticketRefund = await models.TicketRefund.findOne({ - where: {refundTicketFk: ticketId} + await models.TicketRefund.create({ + originalTicketFk: ticketId, + refundTicketFk: newTicket.id }, myOptions); - if (negative && (withWarehouse || !ticketRefund?.id)) { - await models.TicketRefund.create({ - originalTicketFk: ticketId, - refundTicketFk: newTicket.id - }, myOptions); - } return newTicket; } From 1d0b89ed526b03bf5f40b85705dcb0550b848b21 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 17 Jun 2024 09:42:16 +0200 Subject: [PATCH 16/30] refs #7519 Requested changes --- db/dump/fixtures.before.sql | 4 ++-- db/routines/vn/procedures/claimRatio_add.sql | 9 ++++++--- db/versions/11101-limeCordyline/00-firstScript.sql | 8 ++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 60ef58861..eb165aeec 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1885,9 +1885,9 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina (1, 31, 4, 21, 2), (2, 32, 3, 21, 3); -INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`) +INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`) VALUES - (1, 50); + (1, 5, 4, '2016-10-01'); INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`) VALUES diff --git a/db/routines/vn/procedures/claimRatio_add.sql b/db/routines/vn/procedures/claimRatio_add.sql index 8d94805db..c375f8736 100644 --- a/db/routines/vn/procedures/claimRatio_add.sql +++ b/db/routines/vn/procedures/claimRatio_add.sql @@ -5,7 +5,8 @@ BEGIN * Añade a la tabla greuges todos los cargos necesario y * que luego lo utilizamos para calcular el recobro. */ - DECLARE vMonthToRefund INT DEFAULT 4; + DECLARE vMonthToRefund INT + DEFAULT (SELECT monthsToRefund FROM claimConfig); DECLARE vRecoveryGreugeType INT DEFAULT (SELECT id FROM greugeType WHERE code = 'recovery'); DECLARE vManaGreugeType INT @@ -15,7 +16,8 @@ BEGIN DECLARE vDebtComponentType INT DEFAULT (SELECT id FROM component WHERE code = 'debtCollection'); - IF vRecoveryGreugeType IS NULL + IF vMonthToRefund IS NULL + OR vRecoveryGreugeType IS NULL OR vManaGreugeType IS NULL OR vClaimGreugeType IS NULL OR vDebtComponentType IS NULL THEN @@ -87,6 +89,7 @@ BEGIN -- Recobros CREATE OR REPLACE TEMPORARY TABLE tTicketList (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY SELECT DISTINCT s.ticketFk FROM saleComponent sc JOIN sale s ON sc.saleFk = s.id @@ -97,7 +100,7 @@ BEGIN JOIN alertLevel al ON al.id = st.alertLevel WHERE sc.componentFk = vDebtComponentType AND NOT sc.isGreuge - AND t.shipped >= '2016-10-01' + AND t.shipped >= (SELECT minShipped FROM claimConfig) AND t.shipped < util.VN_CURDATE() AND al.code = 'DELIVERED'; diff --git a/db/versions/11101-limeCordyline/00-firstScript.sql b/db/versions/11101-limeCordyline/00-firstScript.sql index e9ffa1b12..d6f30ce3f 100644 --- a/db/versions/11101-limeCordyline/00-firstScript.sql +++ b/db/versions/11101-limeCordyline/00-firstScript.sql @@ -2,3 +2,11 @@ UPDATE IGNORE bs.nightTask SET `schema` = 'vn', `procedure` = 'claimRatio_add' WHERE `procedure` = 'claim_ratio_routine'; + +ALTER TABLE vn.claimConfig + ADD monthsToRefund int(11) DEFAULT NULL NULL, + ADD minShipped date DEFAULT NULL NULL; + +UPDATE IGNORE vn.claimConfig + SET monthsToRefund = 4, + minShipped = '2016-10-01'; From 89ea931d9c964e553d332c4b67e8891dd5baf515 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 17 Jun 2024 12:19:59 +0200 Subject: [PATCH 17/30] feat: refs #6744 add locale & drop verification --- loopback/locale/es.json | 6 +++--- modules/account/back/models/account.js | 6 +++++- modules/worker/front/descriptor/index.html | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e876c1bbb..188f33631 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -351,7 +351,7 @@ "You are not allowed to modify the alias": "No estás autorizado a modificar el alias", "The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas", "The line could not be marked": "La linea no puede ser marcada", - "This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario", + "Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado", "They're not your subordinate": "No es tu subordinado/a.", "No results found": "No se han encontrado resultados", "InvoiceIn is already booked": "La factura recibida está contabilizada", @@ -359,10 +359,10 @@ "Select ticket or client": "Elija un ticket o un client", "It was not able to create the invoice": "No se pudo crear la factura", "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", - "Incoterms and Customs agent are required for a non UEE member": "Se requieren Incoterms y agente de aduanas para un no miembro de la UEE", + "Incoterms and Customs agent are required for a non UEE member": "Se requieren Incoterms y agente de aduanas para un no miembro de la UEE", "You can not use the same password": "No puedes usar la misma contraseña", "This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario", "You can only have one PDA": "Solo puedes tener un PDA", "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono" -} +} \ No newline at end of file diff --git a/modules/account/back/models/account.js b/modules/account/back/models/account.js index ceb26053c..7800d3e44 100644 --- a/modules/account/back/models/account.js +++ b/modules/account/back/models/account.js @@ -13,7 +13,11 @@ module.exports = Self => { Self.setUnverifiedPassword = async(id, pass, options) => { const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options); - if (emailVerified) throw new ForbiddenError('This password can only be changed by the user themselves'); + if (emailVerified) { + throw new ForbiddenError( + 'Through this procedure, it is not possible to modify the password of users with verified email' + ); + } await models.VnUser.setPassword(id, pass, options); }; diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index 73332efac..a77f986ed 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -11,7 +11,7 @@ ? 'Click to allow the user to be disabled' : 'Click to exclude the user from getting disabled'}} - + Change password From 4bc62a30bdb8a2e3e530de88cabea13918e77d53 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 17 Jun 2024 12:23:01 +0200 Subject: [PATCH 18/30] fix: refs #6744 back test --- modules/worker/back/methods/worker/specs/setPassword.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker/specs/setPassword.spec.js b/modules/worker/back/methods/worker/specs/setPassword.spec.js index 8d152bdd1..b9b20ce94 100644 --- a/modules/worker/back/methods/worker/specs/setPassword.spec.js +++ b/modules/worker/back/methods/worker/specs/setPassword.spec.js @@ -42,7 +42,9 @@ describe('worker setPassword()', () => { await tx.rollback(); } catch (e) { - expect(e.message).toEqual(`This password can only be changed by the user themselves`); + expect(e.message).toEqual( + 'Through this procedure, it is not possible to modify the password of users with verified email' + ); await tx.rollback(); } }); From eedcdb54fad2773fba8d4e3f5e985a327a894a6e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 17 Jun 2024 19:50:51 +0200 Subject: [PATCH 19/30] feat hasItemOlder refs#6964 --- db/versions/11106-salmonPhormium/00-firstScript.sql | 9 +++++++++ .../item/back/methods/item-shelving/getListItemNewer.js | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/versions/11106-salmonPhormium/00-firstScript.sql diff --git a/db/versions/11106-salmonPhormium/00-firstScript.sql b/db/versions/11106-salmonPhormium/00-firstScript.sql new file mode 100644 index 000000000..b7cd5de4c --- /dev/null +++ b/db/versions/11106-salmonPhormium/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(11) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear'; +ALTER TABLE vn.productionConfig ADD sectorToCode varchar(11) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear'; + +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js index a6ab0e5f1..3978fa26e 100644 --- a/modules/item/back/methods/item-shelving/getListItemNewer.js +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -35,7 +35,8 @@ module.exports = Self => { SELECT COUNT(p.id) parkingToReview FROM vn.parking p JOIN vn.sector s ON s.id = p.sectorFk - WHERE p.code = ? AND s.code = "CAMARA SECTOR D";`, + JOIN vn.productionConfig pc + WHERE p.code = ? AND s.code = pc.sectorToCode;`, [parking], myOptions); if (isParkingToReview[0]['parkingToReview'] > 0) { @@ -46,15 +47,17 @@ module.exports = Self => { JOIN vn.shelving sh ON sh.code = is2.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk - WHERE is2.shelvingFk = ? AND s.code = "NAVE ALGEMESI" + JOIN vn.productionConfig pc + WHERE is2.shelvingFk = ? AND s.code = c.sectorFromCode ), tItemInSector AS ( SELECT is2.itemFk, is2.created, is2.shelvingFk FROM vn.itemShelving is2 JOIN vn.shelving sh ON sh.code = is2.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.productionConfig pc WHERE is2.shelvingFk <> ? - AND s.code = "NAVE ALGEMESI") + AND s.code = c.sectorFromCode) SELECT ti.itemFK, tis.shelvingFk FROM tItemShelving ti JOIN tItemInSector tis ON tis.itemFk = ti.itemFk From 46cd20a1fde5601fd9aa1642d5f1bfa79008d591 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jun 2024 08:24:15 +0200 Subject: [PATCH 20/30] feat hasItemOlder refs#6964 --- .../methods/item-shelving/getListItemNewer.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js index 3978fa26e..708b81108 100644 --- a/modules/item/back/methods/item-shelving/getListItemNewer.js +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -17,7 +17,7 @@ module.exports = Self => { }, ], returns: { - type: 'Object', + type: 'Array', root: true }, http: { @@ -31,7 +31,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isParkingToReview = await Self.rawSql(` + const [isParkingToReview] = await Self.rawSql(` SELECT COUNT(p.id) parkingToReview FROM vn.parking p JOIN vn.sector s ON s.id = p.sectorFk @@ -39,8 +39,9 @@ module.exports = Self => { WHERE p.code = ? AND s.code = pc.sectorToCode;`, [parking], myOptions); - if (isParkingToReview[0]['parkingToReview'] > 0) { - const result = await Self.rawSql(` + if (isParkingToReview['parkingToReview'] < 1) return []; + + const result = await Self.rawSql(` WITH tItemShelving AS( SELECT is2.itemFk, is2.created, p.sectorFK, is2.id FROM vn.itemShelving is2 @@ -63,9 +64,7 @@ module.exports = Self => { JOIN tItemInSector tis ON tis.itemFk = ti.itemFk JOIN vn.productionConfig pc WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`, - [shelvingFk, shelvingFk], myOptions); - return result; - } else - return []; + [shelvingFk, shelvingFk], myOptions); + return result; }; }; From 239814e6b4315009f404a96457a41bd71766ddb3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jun 2024 10:08:40 +0200 Subject: [PATCH 21/30] feat hasItemOlder refs#6964 --- back/models/production-config.json | 12 ++++-- .../11106-salmonPhormium/00-firstScript.sql | 8 ++-- .../methods/item-shelving/getListItemNewer.js | 4 +- .../specs/getListItemNewer.spec.js | 39 +++++++++++-------- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/back/models/production-config.json b/back/models/production-config.json index 3800dbbf2..2fc6d71ff 100644 --- a/back/models/production-config.json +++ b/back/models/production-config.json @@ -3,17 +3,23 @@ "base": "VnModel", "options": { "mysql": { - "table": "productionConfig" + "table": "productionConfig" } - }, + }, "properties": { "id": { "type": "number", "required": true, "id": true }, + "sectorFromCode": { + "type": "string" + }, + "sectorToCode": { + "type": "string" + }, "backupPrinterNotificationDelay": { "type": "string" } } -} +} \ No newline at end of file diff --git a/db/versions/11106-salmonPhormium/00-firstScript.sql b/db/versions/11106-salmonPhormium/00-firstScript.sql index b7cd5de4c..9f63e6075 100644 --- a/db/versions/11106-salmonPhormium/00-firstScript.sql +++ b/db/versions/11106-salmonPhormium/00-firstScript.sql @@ -2,8 +2,8 @@ USE vn; -ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(11) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear'; -ALTER TABLE vn.productionConfig ADD sectorToCode varchar(11) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear'; +ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(15) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear'; +ALTER TABLE vn.productionConfig ADD sectorToCode varchar(15) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear'; -ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/modules/item/back/methods/item-shelving/getListItemNewer.js b/modules/item/back/methods/item-shelving/getListItemNewer.js index 708b81108..1702bb05b 100644 --- a/modules/item/back/methods/item-shelving/getListItemNewer.js +++ b/modules/item/back/methods/item-shelving/getListItemNewer.js @@ -49,7 +49,7 @@ module.exports = Self => { JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.productionConfig pc - WHERE is2.shelvingFk = ? AND s.code = c.sectorFromCode + WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode ), tItemInSector AS ( SELECT is2.itemFk, is2.created, is2.shelvingFk FROM vn.itemShelving is2 @@ -58,7 +58,7 @@ module.exports = Self => { JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.productionConfig pc WHERE is2.shelvingFk <> ? - AND s.code = c.sectorFromCode) + AND s.code = pc.sectorFromCode) SELECT ti.itemFK, tis.shelvingFk FROM tItemShelving ti JOIN tItemInSector tis ON tis.itemFk = ti.itemFk diff --git a/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js index 5f0f7d826..15c480992 100644 --- a/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getListItemNewer.spec.js @@ -2,31 +2,36 @@ const {models} = require('vn-loopback/server/server'); describe('itemShelving getListItemNewer()', () => { - fit('should return true because there is an older item', async() => { + it('should return true because there is an older item', async() => { const shelving = 'NCC'; const parking = 'A-47-1'; - const sectorCam = 1; - const sectorCamCode = 'CAMARA SECTOR D'; - const sectorCamHigh = 9991; - const sectorCamHighCode = 'NAVE ALGEMESI'; + + const sectorCamHighCode = 'CAMARA SECTOR D'; + const sectorCamCode = 'NAVE ALGEMESI'; + + const sectorCamCodeHighId = 1; + const sectorCamCodeId = 9991; const tx = await models.Sector.beginTransaction({}); const myOptions = {transaction: tx}; - const filter = {where: {id: sectorCam}}; - const filterHigh = {where: {id: sectorCamHigh}}; - try { - const sectorCamBefore = await models.Sector.findOne(filter, myOptions); - - await sectorCamBefore.updateAttributes({ - code: sectorCamCode - }, myOptions); - - const sectorCamHighBefore = await models.Sector.findOne(filterHigh, myOptions); - await sectorCamHighBefore.updateAttributes({ + const sectorHighCam = await models.Sector.findById(sectorCamCodeHighId, null, myOptions); + await sectorHighCam.updateAttributes({ code: sectorCamHighCode - }, myOptions); + }); + + const sectorCam = await models.Sector.findById(sectorCamCodeId, null, myOptions); + await sectorCam.updateAttributes({ + code: sectorCamCode + }); + + const config = await models.ProductionConfig.findOne(); + + await config.updateAttributes({ + sectorToCode: sectorCamHighCode, + sectorFromCode: sectorCamCode + }); const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions); From ae01fb6440f987a442c5d511362722b57cfe267f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 18 Jun 2024 17:00:15 +0200 Subject: [PATCH 22/30] hotFix delete unique refs #6281 --- .../11109-whiteCarnation/00-firstScript.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 db/versions/11109-whiteCarnation/00-firstScript.sql diff --git a/db/versions/11109-whiteCarnation/00-firstScript.sql b/db/versions/11109-whiteCarnation/00-firstScript.sql new file mode 100644 index 000000000..a1ff19815 --- /dev/null +++ b/db/versions/11109-whiteCarnation/00-firstScript.sql @@ -0,0 +1,14 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelvingBuy_FK; +ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2; +ALTER TABLE vn.itemShelving DROP INDEX itemShelving_UN; + +ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_fk2 FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelvingBuy_FK FOREIGN KEY (buyFk) REFERENCES vn.buy(id) ON DELETE RESTRICT ON UPDATE RESTRICT; + + + + From df4b3add8ddcea3596d66915d708cea5500754ca Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 19 Jun 2024 07:59:45 +0200 Subject: [PATCH 23/30] fix: refs #6408 quito state.js --- .../back/methods/ticket/specs/state.spec.js | 36 ++++++++++- modules/ticket/back/methods/ticket/state.js | 64 +------------------ 2 files changed, 38 insertions(+), 62 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/state.spec.js b/modules/ticket/back/methods/ticket/specs/state.spec.js index d908aa2ef..58a407c4e 100644 --- a/modules/ticket/back/methods/ticket/specs/state.spec.js +++ b/modules/ticket/back/methods/ticket/specs/state.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -describe('ticket state()', () => { +xdescribe('ticket state()', () => { const salesPersonId = 18; const employeeId = 1; const productionId = 49; @@ -113,6 +113,7 @@ describe('ticket state()', () => { try { const options = {transaction: tx}; + spyOn(models.Chat, 'sendCheckingPresence').and.callThrough(); const ticket = await models.Ticket.create(sampleTicket, options); activeCtx.accessToken.userId = salesPersonId; const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options); @@ -124,6 +125,7 @@ describe('ticket state()', () => { expect(resAssigned.userFk).toBe(paramsAssigned.userFk); expect(resAssigned.userFk).toBe(1); expect(resAssigned.id).toBeDefined(); + expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled(); activeCtx.accessToken.userId = productionId; const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); @@ -183,5 +185,37 @@ describe('ticket state()', () => { throw e; } }); + + it('should not call sendCheckingPresence if sales.length is 0 because quantities are equal', async() => { + const tx = await models.TicketTracking.beginTransaction({}); + spyOn(models.Chat, 'sendCheckingPresence').and.callThrough(); + + try { + const options = {transaction: tx}; + const ticket = await models.Ticket.create(sampleTicket, options); + activeCtx.accessToken.userId = productionId; + + const sampleSale = { + ticketFk: ticket.id, + itemFk: 1, + concept: 'Test', + quantity: 10, + originalQuantity: 10 + }; + await models.Sale.create(sampleSale, options); + + const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); + const params = {ticketFk: ticket.id, stateFk: packedState.id}; + + await models.Ticket.state(ctx, params, options); + + expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 1e6069b79..fea9475f8 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -26,7 +26,6 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {}; let tx; - let newStateOrder; if (typeof options == 'object') Object.assign(myOptions, options); @@ -41,16 +40,11 @@ module.exports = Self => { throw new UserError('State cannot be blank'); if (params.stateFk) { - const {code, order} = await models.State.findById( - params.stateFk, - {fields: ['code', 'order']}, - myOptions); + const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions); params.code = code; - newStateOrder = order; } else { - const {id, order} = await models.State.findOne({where: {code: params.code}}, myOptions); + const {id} = await models.State.findOne({where: {code: params.code}}, myOptions); params.stateFk = id; - newStateOrder = order; } if (!params.userFk) { @@ -70,59 +64,7 @@ module.exports = Self => { if ((ticketState && !oldStateAllowed) || !newStateAllowed) throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); - const ticket = await models.Ticket.findById(params.ticketFk, { - include: [{ - relation: 'client', - scope: { - fields: ['salesPersonFk'] - } - }], - fields: ['id', 'clientFk'] - }, myOptions); - - const salesPersonFk = ticket.client().salesPersonFk; - const stateChecked = await models.State.findOne({fields: ['order'], where: {code: 'CHECKED'}}); - - if (salesPersonFk && newStateOrder >= stateChecked.order) { - const sales = await Self.rawSql(` - SELECT DISTINCT s.id, - s.itemFk, - s.concept, - s.originalQuantity AS oldQuantity, - s.quantity AS newQuantity - FROM vn.sale s - WHERE s.ticketFk = ? - AND s.originalQuantity IS NOT NULL - AND s.originalQuantity <> s.quantity - `, [params.ticketFk], myOptions); - - if (sales.length) { - let changes = ''; - const url = await models.Url.getUrl(); - const $t = ctx.req.__; - for (let sale of sales) { - changes += `\r\n-` + $t('Changes in sales', { - itemId: sale.itemFk, - concept: sale.concept, - oldQuantity: sale.oldQuantity, - newQuantity: sale.newQuantity, - itemUrl: `${url}item/${sale.itemFk}/summary` - }); - const currentSale = await models.Sale.findById(sale.id, null, myOptions); - await currentSale.updateAttributes({ - originalQuantity: currentSale.quantity - }, myOptions); - } - - const message = $t('Changed sale quantity', { - ticketId: ticket.id, - changes: changes, - ticketUrl: `${url}ticket/${ticket.id}/sale` - }); - await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions); - } - } - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions); const ticketTracking = await models.TicketTracking.findOne({ where: {ticketFk: params.ticketFk}, From 637c6a9035e0b37907c5fc71e9cf239ae461a80e Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 19 Jun 2024 09:40:24 +0200 Subject: [PATCH 24/30] feat: refs #7216 logUnpaid --- modules/client/back/locale/client-unpaid/en.yml | 5 +++++ modules/client/back/locale/client-unpaid/es.yml | 5 +++++ modules/client/back/models/client-unpaid.json | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 modules/client/back/locale/client-unpaid/en.yml create mode 100644 modules/client/back/locale/client-unpaid/es.yml diff --git a/modules/client/back/locale/client-unpaid/en.yml b/modules/client/back/locale/client-unpaid/en.yml new file mode 100644 index 000000000..77a993671 --- /dev/null +++ b/modules/client/back/locale/client-unpaid/en.yml @@ -0,0 +1,5 @@ +name: uppaid +columns: + clientFk: client + dated: date + amount: amount diff --git a/modules/client/back/locale/client-unpaid/es.yml b/modules/client/back/locale/client-unpaid/es.yml new file mode 100644 index 000000000..e24236109 --- /dev/null +++ b/modules/client/back/locale/client-unpaid/es.yml @@ -0,0 +1,5 @@ +name: impagado +columns: + clientFk: cliente + dated: fecha + amount: cantidad diff --git a/modules/client/back/models/client-unpaid.json b/modules/client/back/models/client-unpaid.json index 0fc3a9195..6637c3940 100644 --- a/modules/client/back/models/client-unpaid.json +++ b/modules/client/back/models/client-unpaid.json @@ -1,6 +1,9 @@ { "name": "ClientUnpaid", "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "clientUnpaid" @@ -25,4 +28,4 @@ "foreignKey": "clientFk" } } -} \ No newline at end of file +} From 1a8df4d87c0a554bde7b55ac54dffdadc73c6555 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 19 Jun 2024 13:41:37 +0200 Subject: [PATCH 25/30] feat: refs #7216 triggers --- db/routines/vn/triggers/clientUnpaid_beforeInsert.sql | 8 ++++++++ db/routines/vn/triggers/clientUnpaid_beforeUpdate.sql | 8 ++++++++ db/versions/11110-grayGerbera/00-clientUnpaid.sql | 4 ++++ modules/client/back/locale/client-unpaid/en.yml | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/triggers/clientUnpaid_beforeInsert.sql create mode 100644 db/routines/vn/triggers/clientUnpaid_beforeUpdate.sql create mode 100644 db/versions/11110-grayGerbera/00-clientUnpaid.sql diff --git a/db/routines/vn/triggers/clientUnpaid_beforeInsert.sql b/db/routines/vn/triggers/clientUnpaid_beforeInsert.sql new file mode 100644 index 000000000..279a81b73 --- /dev/null +++ b/db/routines/vn/triggers/clientUnpaid_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientUnpaid_beforeInsert` + BEFORE INSERT ON `clientUnpaid` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientUnpaid_beforeUpdate.sql b/db/routines/vn/triggers/clientUnpaid_beforeUpdate.sql new file mode 100644 index 000000000..13cac3fa7 --- /dev/null +++ b/db/routines/vn/triggers/clientUnpaid_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientUnpaid_beforeUpdate` + BEFORE UPDATE ON `clientUnpaid` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/versions/11110-grayGerbera/00-clientUnpaid.sql b/db/versions/11110-grayGerbera/00-clientUnpaid.sql new file mode 100644 index 000000000..06fd51555 --- /dev/null +++ b/db/versions/11110-grayGerbera/00-clientUnpaid.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.clientUnpaid + ADD editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ClientUnpaid_editorFk FOREIGN KEY (editorFk) + REFERENCES account.`user`(id); diff --git a/modules/client/back/locale/client-unpaid/en.yml b/modules/client/back/locale/client-unpaid/en.yml index 77a993671..10f797c97 100644 --- a/modules/client/back/locale/client-unpaid/en.yml +++ b/modules/client/back/locale/client-unpaid/en.yml @@ -1,4 +1,4 @@ -name: uppaid +name: unpaid columns: clientFk: client dated: date From b2ad44980909fd2ecd7d3bc29cb2a0a25755b869 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 19 Jun 2024 14:38:56 +0200 Subject: [PATCH 26/30] feat: refs #7027 mailError managed --- loopback/locale/en.json | 5 +++-- loopback/locale/es.json | 5 +++-- loopback/locale/fr.json | 3 ++- print/core/email.js | 8 ++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a2332fdca..1e5733442 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -232,5 +232,6 @@ "Incoterms and Customs agent are required for a non UEE member": "Incoterms and Customs agent are required for a non UEE member", "It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated", "It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated", - "Cannot add holidays on this day": "Cannot add holidays on this day" -} \ No newline at end of file + "Cannot add holidays on this day": "Cannot add holidays on this day", + "Cannot send mail": "Cannot send mail" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 714475374..cf8133759 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -365,5 +365,6 @@ "You can only have one PDA": "Solo puedes tener un PDA", "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", - "Payment method is required": "El método de pago es obligatorio" -} \ No newline at end of file + "Payment method is required": "El método de pago es obligatorio", + "Cannot send mail": "Não é possível enviar o email" +} diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 1dbd162d8..49584ef0e 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -359,5 +359,6 @@ "Select ticket or client": "Choisissez un ticket ou un client", "It was not able to create the invoice": "Il n'a pas été possible de créer la facture", "It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", - "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré" + "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", + "Cannot send mail": "Impossible d'envoyer le mail" } diff --git a/print/core/email.js b/print/core/email.js index 5de13099a..a0bcf9122 100644 --- a/print/core/email.js +++ b/print/core/email.js @@ -2,6 +2,7 @@ const path = require('path'); const smtp = require('./smtp'); const Component = require('./component'); const Report = require('./report'); +const UserError = require('vn-loopback/util/user-error'); if (!process.env.OPENSSL_CONF) process.env.OPENSSL_CONF = '/etc/ssl/'; @@ -9,7 +10,6 @@ if (!process.env.OPENSSL_CONF) class Email extends Component { constructor(name, args) { super(name); - this.args = args; } @@ -88,7 +88,11 @@ class Email extends Component { force: options.force }; - return await smtp.send(mailOptions); + try { + return await smtp.send(mailOptions); + } catch (error) { + throw new UserError('Cannot send mail'); + } } } From 7d3c07aaaecc61fd1caa83221af430185b235b42 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Thu, 20 Jun 2024 10:44:31 +0000 Subject: [PATCH 27/30] Actualizar README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b052bd8bf..2ad83c2e4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Pull from repository. Run this commands on project root directory to install Node dependencies. ``` -$ npm install +$ pnpm install $ gulp install ``` From 9a4ec460733faf283b6a31789bca1d7e5ebdc0de Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 20 Jun 2024 13:09:40 +0200 Subject: [PATCH 28/30] hotfix: refs #6820 Deleted km validation --- modules/route/back/models/route.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index bf1f26e74..0fde335b3 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -20,21 +20,4 @@ module.exports = Self => { require('../methods/route/cmrEmail')(Self); require('../methods/route/getExpeditionSummary')(Self); require('../methods/route/getByWorker')(Self); - - Self.validate('kmStart', validateDistance, { - message: 'Distance must be lesser than 4000' - }); - - Self.validate('kmEnd', validateDistance, { - message: 'Distance must be lesser than 4000' - }); - - function validateDistance(err) { - if (this.kmEnd) { - const routeTotalKm = this.kmEnd - this.kmStart; - const routeMaxKm = 4000; - if (routeTotalKm > routeMaxKm || this.kmStart > this.kmEnd) - err(); - } - } }; From e0d105313d4d34b2fb2b768efd8a601f86d1e095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 20 Jun 2024 14:27:11 +0200 Subject: [PATCH 29/30] feat: sincro client supplier sage refs #7595 --- .../procedures/accountingMovements_add.sql | 73 ++++++++++++------- .../sage/procedures/clientSupplier_add.sql | 34 +++++---- .../vn/triggers/client_afterUpdate.sql | 25 ++++++- .../vn/triggers/client_beforeUpdate.sql | 4 +- .../vn/triggers/supplier_afterUpdate.sql | 26 +++++++ .../00-firstScript.sql | 9 +++ 6 files changed, 128 insertions(+), 43 deletions(-) create mode 100644 db/routines/vn/triggers/supplier_afterUpdate.sql create mode 100644 db/versions/11105-bronzeChrysanthemum/00-firstScript.sql diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index 575c63f6c..88c599b09 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -21,7 +21,8 @@ BEGIN DECLARE vTransactionExportTaxFreeFk INT; DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; DECLARE vInvoiceTypeInformativeCode VARCHAR(1); - DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2) ; + DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); + DECLARE vCompanyCode INT; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -31,9 +32,6 @@ BEGIN FROM Naciones WHERE Nacion ='CEUTA Y MELILLA'; - SELECT pendingServiceTransactionTypeFk INTO vDuaTransactionFk - FROM config; - SELECT id INTO vTaxImportFk FROM taxType WHERE code = 'import21'; @@ -46,10 +44,14 @@ BEGIN FROM taxType WHERE code = 'import4'; - SELECT definitiveExportTransactionTypeFk INTO vTransactionExportFk - FROM config; - - SELECT shipmentTransactionTypeFk INTO vTransactionExportTaxFreeFk + SELECT shipmentTransactionTypeFk, + definitiveExportTransactionTypeFk, + pendingServiceTransactionTypeFk, + company_getCode(vCompanyFk) + INTO vTransactionExportTaxFreeFk, + vTransactionExportFk, + vDuaTransactionFk, + vCompanyCode FROM config; SELECT codeSage INTO vInvoiceTypeInformativeCode @@ -64,8 +66,6 @@ BEGIN WHERE enlazadoSage = FALSE AND Asiento <> 1 ; - CALL clientSupplier_add(vCompanyFk); - CALL pgc_add(vCompanyFk); CALL invoiceOut_manager(vYear, vCompanyFk); CALL invoiceIn_manager(vYear, vCompanyFk); @@ -158,7 +158,7 @@ BEGIN ) SELECT 'EN' TipoEntrada, YEAR(x.FECHA) Ejercicio, - company_getCode(vCompanyFk) AS CodigoEmpresa, + vCompanyCode CodigoEmpresa, x.ASIEN Asiento, IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL), 'D', 'H') CargoAbono, @@ -291,20 +291,6 @@ BEGIN WHERE m.CargoAbono = 'D' AND m.enlazadoSage = FALSE; --- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación - DELETE cp - FROM clientesProveedores cp - LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - --- Elimina cuentas contables que no se utilizarán en la importación - DELETE pc - FROM planCuentasPGC pc - LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - -- DUAS UPDATE movConta mci JOIN vn.XDiario x ON x.ASIEN = mci.Asiento @@ -411,5 +397,42 @@ BEGIN AND importeDivisa > 0 AND ImporteAsiento < 0; + CREATE OR REPLACE TEMPORARY TABLE tmp.clientSupplier + (INDEX(idClientSupplier, `type`)) + ENGINE = MEMORY + WITH client AS( + SELECT DISTINCT c.id + FROM sage.movConta mc + JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta + WHERE NOT enlazadoSage + ),supplier AS( + SELECT DISTINCT s.id + FROM sage.movConta mc + JOIN vn.supplier s ON s.account = mc.CodigoCuenta + WHERE NOT enlazadoSage + )SELECT idClientSupplier, `type` + FROM sage.clientSupplier cs + WHERE NOT isSync + UNION + SELECT id, 'C' + FROM client + UNION + SELECT id, 'P' + FROM supplier; + + CALL clientSupplier_add(vCompanyFk); + + INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) + SELECT vCompanyCode, `type`, idClientSupplier, FALSE + FROM tmp.clientSupplier; + + CALL pgc_add(vCompanyFk); +-- Elimina cuentas contables que no se utilizarán en la importación + DELETE pc + FROM planCuentasPGC pc + LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta + AND mc.enlazadoSage = FALSE + WHERE mc.codigoCuenta IS NULL; + END$$ DELIMITER ; diff --git a/db/routines/sage/procedures/clientSupplier_add.sql b/db/routines/sage/procedures/clientSupplier_add.sql index 70f3ef3d0..2c4b4db9d 100644 --- a/db/routines/sage/procedures/clientSupplier_add.sql +++ b/db/routines/sage/procedures/clientSupplier_add.sql @@ -1,11 +1,16 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`( + vCompanyFk INT +) BEGIN /** - * Prepara los datos de clientes y proveedores para exportarlos a Sage - * @vCompanyFk Empresa dela que se quiere trasladar datos + * Inserta en la tabla sage.clientesProveedores los datos de clientes y proveedores + * que se actualizaran o se daran de alta en Sage + * @vCompanyFk Id de empresa + * @table tmp.clientSupplier(idClientSupplier, `type`) */ DECLARE vCountryCeutaMelillaFk INT; + DECLARE vCompanyCode INT DEFAULT company_getCode(vCompanyFk); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); SELECT SiglaNacion INTO vCountryCanariasCode @@ -45,7 +50,7 @@ BEGIN Email1, iban) SELECT - company_getCode(vCompanyFk), + vCompanyCode, 'C', c.id, c.socialName, @@ -53,7 +58,7 @@ BEGIN IFNULL(c.street, ''), c.accountingAccount, @fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)), - IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)), + IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)), IFNULL(c.postcode, ''), IFNULL(c.city, ''), IFNULL(pr.CodigoProvincia, ''), @@ -75,15 +80,14 @@ BEGIN IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''), IFNULL(c.iban, '') FROM vn.`client` c - JOIN clientLastTwoMonths clm ON clm.clientFk = c.id + JOIN tmp.clientSupplier cs ON cs.idClientSupplier = c.id LEFT JOIN vn.country cu ON cu.id = c.countryFk LEFT JOIN Naciones n ON n.countryFk = cu.id LEFT JOIN vn.province p ON p.id = c.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id - WHERE c.isRelevant - AND clm.companyFk = vCompanyFk + WHERE cs.type = 'C' UNION ALL - SELECT company_getCode(vCompanyFk), + SELECT vCompanyCode, 'P', s.id, s.name, @@ -107,18 +111,18 @@ BEGIN IFNULL(s.transactionTypeSageFk, 0), IFNULL(s.withholdingSageFk, '0'), IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''), - IFNULL(iban, '') + IFNULL(sa.iban, '') FROM vn.supplier s - JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id + JOIN tmp.clientSupplier cs ON cs.idClientSupplier = s.id LEFT JOIN vn.country co ON co.id = s.countryFk LEFT JOIN Naciones n ON n.countryFk = co.id LEFT JOIN vn.province p ON p.id = s.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - WHERE pl.companyFk = vCompanyFk AND - s.isActive AND - s.nif <> '' - GROUP BY pl.supplierFk, pl.companyFk; + WHERE cs.type = 'P' + GROUP BY s.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientSupplier; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/client_afterUpdate.sql b/db/routines/vn/triggers/client_afterUpdate.sql index e316fb08a..a2a3e48e3 100644 --- a/db/routines/vn/triggers/client_afterUpdate.sql +++ b/db/routines/vn/triggers/client_afterUpdate.sql @@ -3,12 +3,35 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterUpdate` AFTER UPDATE ON `client` FOR EACH ROW BEGIN - IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN + IF NOT (NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN UPDATE `address` SET isDefaultAddress = FALSE WHERE clientFk = NEW.id; UPDATE `address` SET isDefaultAddress = TRUE WHERE id = NEW.defaultAddressFk; END IF; + + IF NEW.id <> OLD.id + OR NOT (NEW.provinceFk <=> OLD.provinceFk) + OR NOT (NEW.socialName <=> OLD.socialName) + OR NOT (NEW.street <=> OLD.street) + OR NOT (NEW.accountingAccount <=> OLD.accountingAccount) + OR NOT (NEW.isVies <=> OLD.isVies) + OR NOT (NEW.fi <=> OLD.fi) + OR NOT (NEW.postcode <=> OLD.postcode) + OR NOT (NEW.city <=> OLD.city) + OR NOT (NEW.countryFk <=> OLD.countryFk) + OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk) + OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk) + OR NOT (NEW.email <=> OLD.email) + OR NOT (NEW.iban <=> OLD.iban) + OR NOT (NEW.phone <=> OLD.phone) + OR NOT (NEW.mobile <=> OLD.mobile) THEN + + UPDATE sage.clientSupplier + SET isSync = FALSE + WHERE idClientSupplier IN (NEW.id, OLD.id) + AND `type` = 'C'; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/client_beforeUpdate.sql b/db/routines/vn/triggers/client_beforeUpdate.sql index 2f384c535..914ae5b8a 100644 --- a/db/routines/vn/triggers/client_beforeUpdate.sql +++ b/db/routines/vn/triggers/client_beforeUpdate.sql @@ -65,11 +65,11 @@ BEGIN END IF; END IF; - IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN + IF NOT (NEW.salesPersonFk <=> OLD.salesPersonFk) THEN SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); END IF; - IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN + IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN SET NEW.isTaxDataChecked = 0; END IF; END$$ diff --git a/db/routines/vn/triggers/supplier_afterUpdate.sql b/db/routines/vn/triggers/supplier_afterUpdate.sql new file mode 100644 index 000000000..e89df037f --- /dev/null +++ b/db/routines/vn/triggers/supplier_afterUpdate.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_afterUpdate` + BEFORE UPDATE ON `supplier` + FOR EACH ROW +BEGIN + IF NEW.id <> OLD.id + OR NOT (NEW.name <=> OLD.name) + OR NOT (NEW.street <=> OLD.street) + OR NOT (NEW.account <=> OLD.account) + OR NOT (NEW.nif <=> OLD.nif) + OR NOT (NEW.isVies <=> OLD.isVies) + OR NOT (NEW.provinceFk <=> OLD.provinceFk) + OR NOT (NEW.countryFk <=> OLD.countryFk) + OR NOT (NEW.postCode <=> OLD.postCode) + OR NOT (NEW.city <=> OLD.city) + OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk) + OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk) + OR NOT (NEW.withholdingSageFk <=> OLD.withholdingSageFk) THEN + + UPDATE sage.clientSupplier + SET isSync = FALSE + WHERE idClientSupplier IN (NEW.id, OLD.id) + AND `type` = 'P'; + END IF; +END$$ +DELIMITER ; diff --git a/db/versions/11105-bronzeChrysanthemum/00-firstScript.sql b/db/versions/11105-bronzeChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..685cd8f75 --- /dev/null +++ b/db/versions/11105-bronzeChrysanthemum/00-firstScript.sql @@ -0,0 +1,9 @@ + +CREATE OR REPLACE TABLE sage.clientSupplier ( + `companyFk` smallint(6) NOT NULL, + `type` ENUM('C','P') NOT NULL, + `idClientSupplier` INT NOT NULL, + `isSync` TINYINT(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`companyFk`,`idClientSupplier`,`type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci + COMMENT='Clients and suppliers present in Sage and their synchronization status'; \ No newline at end of file From 414bf9eb03a72329ffe7f5ef296b7a28d30214c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 20 Jun 2024 14:48:32 +0200 Subject: [PATCH 30/30] feat: sincro client supplier sage refs #7595 --- db/routines/sage/procedures/accountingMovements_add.sql | 2 ++ db/routines/sage/procedures/clientSupplier_add.sql | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index 88c599b09..ada954334 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -425,6 +425,8 @@ BEGIN INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) SELECT vCompanyCode, `type`, idClientSupplier, FALSE FROM tmp.clientSupplier; + + DROP TEMPORARY TABLE tmp.clientSupplier; CALL pgc_add(vCompanyFk); -- Elimina cuentas contables que no se utilizarán en la importación diff --git a/db/routines/sage/procedures/clientSupplier_add.sql b/db/routines/sage/procedures/clientSupplier_add.sql index 2c4b4db9d..2d1a51882 100644 --- a/db/routines/sage/procedures/clientSupplier_add.sql +++ b/db/routines/sage/procedures/clientSupplier_add.sql @@ -122,7 +122,5 @@ BEGIN LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id WHERE cs.type = 'P' GROUP BY s.id; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientSupplier; END$$ DELIMITER ;