From cbd46330b31d8efcbab8ce2b116dd8f048cd8eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 27 Jun 2024 13:01:42 +0200 Subject: [PATCH 01/30] feat: Turn issues into calculated columns refs#7213 --- .../functions/ticket_isProblemCalcNeeded.sql | 27 +++ db/routines/vn/procedures/buyUltimate.sql | 34 +-- .../vn/procedures/buyUltimateFromInterval.sql | 195 ++++++++++-------- db/routines/vn/procedures/sale_setProblem.sql | 9 +- .../sale_setProblemComponentLack.sql | 8 +- ...ale_setProblemComponentLackByComponent.sql | 8 +- .../vn/procedures/sale_setProblemRounding.sql | 9 +- .../vn/procedures/ticket_setProblem.sql | 12 +- .../vn/procedures/ticket_setProblemFreeze.sql | 8 +- .../procedures/ticket_setProblemRequest.sql | 6 +- .../vn/procedures/ticket_setProblemRisk.sql | 17 +- .../procedures/ticket_setProblemRounding.sql | 7 +- .../ticket_setProblemTaxDataChecked.sql | 6 +- .../procedures/ticket_setProblemTooLittle.sql | 8 +- .../ticket_setProblemTooLittleItemCost.sql | 6 +- 15 files changed, 234 insertions(+), 126 deletions(-) create mode 100644 db/routines/vn/functions/ticket_isProblemCalcNeeded.sql diff --git a/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql b/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql new file mode 100644 index 000000000..4974a8c76 --- /dev/null +++ b/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isProblemCalcNeeded`( + vSelf INT +) + RETURNS BOOL + DETERMINISTIC +BEGIN +/** + * Check if the ticket requires to update column vn.ticket.problem + * + * @param vSelf Id ticket + * @return BOOL + */ + DECLARE vIsProblemCalcNeeded BOOL; + + SELECT COUNT(*) INTO vIsProblemCalcNeeded + FROM ticket t + JOIN client c ON c.id = t.clientFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE t.id = vSelf + AND dm.code IN ('AGENCY','DELIVERY','PICKUP') + AND c.typeFk = 'normal'; + + RETURN vIsProblemCalcNeeded; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql index 4346ef640..98b16cbc0 100644 --- a/db/routines/vn/procedures/buyUltimate.sql +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -1,5 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(vWarehouseFk SMALLINT, vDated DATE) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`( + vWarehouseFk SMALLINT, + vDated DATE +) BEGIN /** * Calcula las últimas compras realizadas hasta una fecha @@ -19,21 +22,22 @@ BEGIN FROM cache.last_buy WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); + IF vDated >= util.VN_CURDATE() THEN + CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); - REPLACE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed <= vDated - AND NOT isIgnored; - - INSERT IGNORE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed > vDated - ORDER BY isIgnored = FALSE DESC; + REPLACE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed <= vDated + AND NOT isIgnored; + INSERT IGNORE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed > vDated + ORDER BY isIgnored = FALSE DESC; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index e264b500d..5879b58e1 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -1,5 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`( + vWarehouseFk SMALLINT, + vStarted DATE, + vEnded DATE +) BEGIN /** * Calcula las últimas compras realizadas @@ -21,12 +25,13 @@ BEGIN -- Item DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval - (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) + (PRIMARY KEY (itemFk, warehouseFk), + INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) ENGINE = MEMORY SELECT itemFk, warehouseFk, buyFk, - MAX(landed) landed, + landed, isIgnored FROM (SELECT b.itemFk, t.warehouseInFk warehouseFk, @@ -45,93 +50,117 @@ BEGIN INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - GROUP BY itemFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - GROUP BY itemFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; -- ItemOriginal INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT itemFk, - warehouseFk, - buyFk, - MAX(landed) landed, - isIgnored - FROM (SELECT b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - itemOriginalFk, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND b.quantity > 0 - AND itemOriginalFk - ORDER BY t.landed DESC, b.id DESC - LIMIT 10000000000000000000) sub - GROUP BY itemOriginalFk, warehouseFk; + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + itemOriginalFk, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND b.quantity > 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM + (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql index 20319cc3f..1ba7a1353 100644 --- a/db/routines/vn/procedures/sale_setProblem.sql +++ b/db/routines/vn/procedures/sale_setProblem.sql @@ -6,8 +6,15 @@ BEGIN /** * Update column sale.problem with a problem code * @param vProblemCode Code to set or unset - * @table tmp.sale(saleFk, hasProblem) + * @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded) */ + UPDATE tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + SET s.problem = NULL + WHERE NOT ts.isProblemCalcNeeded; + + DELETE FROM tmp.sale WHERE NOT isProblemCalcNeeded; + UPDATE sale s JOIN tmp.sale ts ON ts.saleFk = s.id SET s.problem = CONCAT( diff --git a/db/routines/vn/procedures/sale_setProblemComponentLack.sql b/db/routines/vn/procedures/sale_setProblemComponentLack.sql index 363663a00..aa5f5f1be 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLack.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLack.sql @@ -10,9 +10,13 @@ BEGIN * @param vSelf Id del sale */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) + (INDEX(saleFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem; + SELECT vSelf saleFk, + sale_hasComponentLack(vSelf) hasProblem, + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + FROM sale + WHERE id = vSelf; CALL sale_setProblem('hasComponentLack'); diff --git a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql index b911327dd..2ee49b656 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql @@ -10,11 +10,13 @@ BEGIN * @param vComponentFk Id component */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) + (INDEX(saleFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem + SELECT saleFk, + sale_hasComponentLack(saleFk) hasProblem, + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded FROM ( - SELECT s.id saleFk + SELECT s.id saleFk, s.ticketFk FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id diff --git a/db/routines/vn/procedures/sale_setProblemRounding.sql b/db/routines/vn/procedures/sale_setProblemRounding.sql index f14cd408f..f58d00799 100644 --- a/db/routines/vn/procedures/sale_setProblemRounding.sql +++ b/db/routines/vn/procedures/sale_setProblemRounding.sql @@ -11,9 +11,10 @@ BEGIN DECLARE vWarehouseFk INT; DECLARE vShipped DATE; DECLARE vQuantity INT; + DECLARE vIsProblemCalcNeeded BOOL; - SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity - INTO vItemFk, vWarehouseFk, vShipped, vQuantity + SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity, ticket_isProblemCalcNeeded(t.id) + INTO vItemFk, vWarehouseFk, vShipped, vQuantity, vIsProblemCalcNeeded FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE s.id = vSelf; @@ -21,7 +22,9 @@ BEGIN CALL buyUltimate(vWarehouseFk, vShipped); CREATE OR REPLACE TEMPORARY TABLE tmp.sale - SELECT vSelf saleFk, MOD(vQuantity, b.`grouping`) hasProblem + SELECT vSelf saleFk, + MOD(vQuantity, b.`grouping`) hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded FROM tmp.buyUltimate bu JOIN buy b ON b.id = bu.buyFk WHERE bu.itemFk = vItemFk; diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql index bab8f1f52..a75cb91ed 100644 --- a/db/routines/vn/procedures/ticket_setProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblem.sql @@ -4,11 +4,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( ) BEGIN /** - * Update column ticket.problem with a problem code + * Update column ticket.problem with a problem code and SET NULL when + * the problem is not requiered * * @param vProblemCode Code to set or unset - * @table tmp.ticket(ticketFk, hasProblem) + * @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded) */ + UPDATE ticket t + JOIN tmp.ticket tt ON tt.ticketFk = t.id + SET t.problem = NULL + WHERE NOT tt.isProblemCalcNeeded; + + DELETE FROM tmp.ticket WHERE NOT isProblemCalcNeeded; + UPDATE ticket t JOIN tmp.ticket tt ON tt.ticketFk = t.id SET t.problem = CONCAT( diff --git a/db/routines/vn/procedures/ticket_setProblemFreeze.sql b/db/routines/vn/procedures/ticket_setProblemFreeze.sql index 560bce612..1de939ba7 100644 --- a/db/routines/vn/procedures/ticket_setProblemFreeze.sql +++ b/db/routines/vn/procedures/ticket_setProblemFreeze.sql @@ -9,9 +9,11 @@ BEGIN * @param vClientFk Id Cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem + SELECT t.id ticketFk, + FALSE hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vClientFk IS NULL OR t.clientFk = vClientFk); @@ -21,7 +23,7 @@ BEGIN JOIN client c ON c.id = ti.clientFk SET t.hasProblem = TRUE WHERE c.isFreezed; - + CALL ticket_setProblem('isFreezed'); DROP TEMPORARY TABLE tmp.ticket; diff --git a/db/routines/vn/procedures/ticket_setProblemRequest.sql b/db/routines/vn/procedures/ticket_setProblemRequest.sql index 19bba5b76..687facfc7 100644 --- a/db/routines/vn/procedures/ticket_setProblemRequest.sql +++ b/db/routines/vn/procedures/ticket_setProblemRequest.sql @@ -9,9 +9,11 @@ BEGIN * @param vSelf Id ticket, if NULL ALL tickets */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem + SELECT t.id ticketFk, + FALSE hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vSelf IS NULL OR t.id = vSelf); diff --git a/db/routines/vn/procedures/ticket_setProblemRisk.sql b/db/routines/vn/procedures/ticket_setProblemRisk.sql index 5f73ee838..efa5b10e2 100644 --- a/db/routines/vn/procedures/ticket_setProblemRisk.sql +++ b/db/routines/vn/procedures/ticket_setProblemRisk.sql @@ -10,21 +10,30 @@ BEGIN */ DECLARE vHasRisk BOOL; DECLARE vHasHighRisk BOOL; + DECLARE vIsProblemCalcNeeded BOOL; - SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10)) - INTO vHasRisk, vHasHighRisk + SELECT t.risk > (c.credit + 10), + (t.risk - cc.riskTolerance) > (c.credit + 10), + ticket_isProblemCalcNeeded(t.id) + INTO vHasRisk, vHasHighRisk, vIsProblemCalcNeeded FROM client c JOIN ticket t ON t.clientFk = c.id JOIN clientConfig cc WHERE t.id = vSelf; CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf ticketFk, vHasRisk hasProblem; + ENGINE = MEMORY + SELECT vSelf ticketFk, + vHasRisk hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded; CALL ticket_setProblem('hasRisk'); CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf ticketFk, vHasHighRisk hasProblem; + ENGINE = MEMORY + SELECT vSelf ticketFk, + vHasHighRisk hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded; CALL ticket_setProblem('hasHighRisk'); diff --git a/db/routines/vn/procedures/ticket_setProblemRounding.sql b/db/routines/vn/procedures/ticket_setProblemRounding.sql index 81294325c..fb580eacf 100644 --- a/db/routines/vn/procedures/ticket_setProblemRounding.sql +++ b/db/routines/vn/procedures/ticket_setProblemRounding.sql @@ -18,8 +18,11 @@ BEGIN CALL buyUltimate(vWarehouseFk, vDated); - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk, isProblemCalcNeeded)) + SELECT s.id saleFk , + MOD(s.quantity, b.`grouping`) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql index 00918426b..9877b5acc 100644 --- a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql @@ -9,9 +9,11 @@ BEGIN * @param vClientFk Id cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem + SELECT t.id ticketFk, + IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t JOIN client c ON c.id = t.clientFk WHERE t.shipped >= util.VN_CURDATE() diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittle.sql b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql index 98a0787af..48cc47809 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittle.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql @@ -8,13 +8,17 @@ BEGIN * * @param vSelf Id del ticket */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem; + SELECT vSelf ticketFk, + ticket_isTooLittle(vSelf) hasProblem, + ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded; CALL ticket_setProblem('isTooLittle'); DROP TEMPORARY TABLE tmp.ticket; + END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index cd1f42783..1f41c0716 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -10,7 +10,7 @@ BEGIN * @param vItemFk Id del item, NULL ALL items */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY WITH tickets AS( SELECT t.id ticketFk @@ -19,7 +19,9 @@ BEGIN WHERE t.shipped >= util.VN_CURDATE() AND (s.itemFk = vItemFk OR vItemFk IS NULL) GROUP BY t.id - )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem + )SELECT ticketFk, + ticket_isTooLittle(ticketFk) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM tickets; CALL ticket_setProblem('isTooLittle'); From a8d663bee46d62da682a56f5fed24bce5714c029 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 3 Jul 2024 10:49:51 +0200 Subject: [PATCH 02/30] feat: refs #7348 hasDailyInvoice field --- db/routines/vn/procedures/client_create.sql | 24 ++++++++++++------- .../11126-blueCamellia/00-firstScript.sql | 2 ++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 db/versions/11126-blueCamellia/00-firstScript.sql diff --git a/db/routines/vn/procedures/client_create.sql b/db/routines/vn/procedures/client_create.sql index d5d7258a1..f2321e129 100644 --- a/db/routines/vn/procedures/client_create.sql +++ b/db/routines/vn/procedures/client_create.sql @@ -34,20 +34,25 @@ BEGIN DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vHasCoreVnl BOOLEAN; DECLARE vMandateTypeFk INT; + DECLARE vHasDailyInvoice BOOLEAN; - SELECT defaultPayMethodFk, - defaultDueDay, - defaultCredit, - defaultIsTaxDataChecked, - defaultHasCoreVnl, - defaultMandateTypeFk + SELECT cc.defaultPayMethodFk, + cc.defaultDueDay, + cc.defaultCredit, + cc.defaultIsTaxDataChecked, + cc.defaultHasCoreVnl, + cc.defaultMandateTypeFk, + c.hasDailyInvoice INTO vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked, vHasCoreVnl, - vMandateTypeFk - FROM clientConfig; + vMandateTypeFk, + vHasDailyInvoice + FROM clientConfig cc + LEFT JOIN province p ON p.id = vProvinceFk + LEFT JOIN country c ON c.id = p.countryFk; INSERT INTO `client` SET id = vUserFk, @@ -65,7 +70,8 @@ BEGIN credit = vDefaultCredit, isTaxDataChecked = vIsTaxDataChecked, hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE + isEqualizated = FALSE, + hasDailyInvoice = vHasDailyInvoice ON duplicate KEY UPDATE payMethodFk = vPayMethodFk, dueDay = vDueDay, diff --git a/db/versions/11126-blueCamellia/00-firstScript.sql b/db/versions/11126-blueCamellia/00-firstScript.sql new file mode 100644 index 000000000..45c2ed2dc --- /dev/null +++ b/db/versions/11126-blueCamellia/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `client` +ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'; From e3db143b443c7ecdc1412b7627c120a05d534207 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 5 Jul 2024 08:55:24 +0200 Subject: [PATCH 03/30] feat: refs #7348 campo en json --- modules/client/back/models/client.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index f3eb9919b..f24f69ae7 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -144,6 +144,9 @@ }, "recommendedCredit": { "type": "number" + }, + "hasDailyInvoice": { + "type": "boolean" } }, From d4b4c0fafe9397d8389586dbecebbae8d8d73ec2 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 5 Jul 2024 09:04:38 +0200 Subject: [PATCH 04/30] feat: refs #7348 campos a modificar --- modules/client/back/methods/client/updateFiscalData.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index 851648658..8ed55b856 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -99,6 +99,10 @@ module.exports = Self => { { arg: 'hasElectronicInvoice', type: 'boolean' + }, + { + arg: 'hasDailyInvoice', + type: 'boolean' } ], returns: { @@ -117,8 +121,6 @@ module.exports = Self => { const myOptions = {}; const models = Self.app.models; const args = ctx.args; - const userId = ctx.req.accessToken.userId; - const $t = ctx.req.__; if (typeof options == 'object') Object.assign(myOptions, options); From 64bddd4f63273063b7d35f63c993a0c491f62836 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 10 Jul 2024 10:41:52 +0200 Subject: [PATCH 05/30] feat: refs #6403 add dynamic clientType --- back/methods/mrw-config/cancelShipment.ejs | 2 +- back/methods/mrw-config/cancelShipment.js | 4 +-- back/methods/mrw-config/createShipment.ejs | 2 +- back/methods/mrw-config/createShipment.js | 11 +++---- back/methods/mrw-config/getLabel.ejs | 2 +- back/methods/mrw-config/getLabel.js | 16 +++++++-- .../mrw-config/specs/createShipment.spec.js | 18 +++++----- back/methods/viaexpress-config/renderer.js | 4 +-- back/model-config.json | 3 ++ back/models/mrw-config.js | 25 ++++++++++++++ back/models/mrw-config.json | 3 ++ back/models/mrw-service.json | 33 +++++++++++++++++++ modules/zone/back/models/agency-mode.json | 5 +++ 13 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 back/models/mrw-service.json diff --git a/back/methods/mrw-config/cancelShipment.ejs b/back/methods/mrw-config/cancelShipment.ejs index 9ef401bc8..bc0662981 100644 --- a/back/methods/mrw-config/cancelShipment.ejs +++ b/back/methods/mrw-config/cancelShipment.ejs @@ -2,7 +2,7 @@ <%= mrw.franchiseCode %> - <%= mrw.subscriberCode %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 86bbb7410..10d556575 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -27,9 +27,9 @@ module.exports = Self => { const mrw = await models.MrwConfig.findOne(); const {externalId} = await models.Expedition.findById(expeditionFk); - + const clientType = await models.MrwConfig.getClientType(expeditionFk); const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8'); - const renderedXml = ejs.render(template, {mrw, externalId}); + const renderedXml = ejs.render(template, {mrw, externalId, clientType}); const response = await axios.post(mrw.url, renderedXml, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' diff --git a/back/methods/mrw-config/createShipment.ejs b/back/methods/mrw-config/createShipment.ejs index 8e123ddd9..65326112b 100644 --- a/back/methods/mrw-config/createShipment.ejs +++ b/back/methods/mrw-config/createShipment.ejs @@ -3,7 +3,7 @@ <%= mrw.franchiseCode %> - <%= expeditionData.clientType %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 9b23cc370..ab25113dc 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -22,6 +22,7 @@ module.exports = Self => { Self.createShipment = async expeditionFk => { const models = Self.app.models; const mrw = await Self.getConfig(); + const clientType = await models.MrwConfig.getClientType(expeditionFk); const today = Date.vnNew(); const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0]; @@ -52,8 +53,7 @@ module.exports = Self => { CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, IF(mw.weekdays, 'S', 'N') weekDays, - oa.description deliveryObservation, - LPAD(ms.clientType, mc.clientTypeWidth, '0') clientType + oa.description deliveryObservation FROM expedition e JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk @@ -73,22 +73,19 @@ module.exports = Self => { const [expeditionData] = await Self.rawSql(query, [expeditionFk]); - if (!expeditionData) - throw new UserError(`This expedition is not a MRW shipment`); - if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0)) throw new UserError(`This ticket has a shipped date earlier than today`); const shipmentResponse = await Self.sendXmlDoc( __dirname + `/createShipment.ejs`, - {mrw, expeditionData}, + {mrw, expeditionData, clientType}, 'application/soap+xml' ); const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio'); if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje')); - const file = await models.MrwConfig.getLabel(shipmentId); + const file = await models.MrwConfig.getLabel(shipmentId, clientType); return {shipmentId, file}; }; diff --git a/back/methods/mrw-config/getLabel.ejs b/back/methods/mrw-config/getLabel.ejs index 09bdb3f6c..b0dae17c8 100644 --- a/back/methods/mrw-config/getLabel.ejs +++ b/back/methods/mrw-config/getLabel.ejs @@ -2,7 +2,7 @@ <%= mrw.franchiseCode %> - <%= mrw.subscriberCode %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/getLabel.js b/back/methods/mrw-config/getLabel.js index aa9b87af1..4af3276bb 100644 --- a/back/methods/mrw-config/getLabel.js +++ b/back/methods/mrw-config/getLabel.js @@ -6,7 +6,13 @@ module.exports = Self => { arg: 'shipmentId', type: 'string', required: true - }], + }, + { + arg: 'clientType', + type: 'string', + required: true + }, + ], returns: { type: 'string', root: true @@ -17,10 +23,14 @@ module.exports = Self => { } }); - Self.getLabel = async shipmentId => { + Self.getLabel = async(shipmentId, clientType) => { const mrw = await Self.getConfig(); - const getLabelResponse = await Self.sendXmlDoc(__dirname + `/getLabel.ejs`, {mrw, shipmentId}, 'text/xml'); + const getLabelResponse = await Self.sendXmlDoc( + __dirname + `/getLabel.ejs`, + {mrw, shipmentId, clientType}, + 'text/xml' + ); return Self.getTextByTag(getLabelResponse, 'EtiquetaFile'); }; diff --git a/back/methods/mrw-config/specs/createShipment.spec.js b/back/methods/mrw-config/specs/createShipment.spec.js index 883dd8f6f..1ab77f608 100644 --- a/back/methods/mrw-config/specs/createShipment.spec.js +++ b/back/methods/mrw-config/specs/createShipment.spec.js @@ -40,15 +40,12 @@ describe('MRWConfig createShipment()', () => { ); + await models.MrwService.create( + {'agencyModeCodeFk': 'mrw', 'clientType': '000001', 'serviceType': 105, 'kg': 10} + ); + await createMrwConfig(); - await models.Application.rawSql( - `INSERT INTO vn.mrwService - SET agencyModeCodeFk = 'mrw', - clientType = 1, - serviceType = 1, - kg = 1`, null - ); await models.Ticket.create(ticket1); await models.Expedition.create(expedition1); }); @@ -82,7 +79,8 @@ describe('MRWConfig createShipment()', () => { 'user': 'user', 'password': 'password', 'franchiseCode': 'franchiseCode', - 'subscriberCode': 'subscriberCode' + 'subscriberCode': 'subscriberCode', + 'clientTypeWidth': 6 } ); } @@ -115,10 +113,10 @@ describe('MRWConfig createShipment()', () => { it('should fail if expeditionFk is not a MrwExpedition', async() => { let error; - await models.MrwConfig.createShipment(undefined).catch(e => { + await models.MrwConfig.createShipment(15).catch(e => { error = e; }).finally(async() => { - expect(error.message).toEqual(`This expedition is not a MRW shipment`); + expect(error.message).toEqual(`ClientType not available`); }); }); diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index c8533ea6b..5d83b5870 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -20,7 +20,7 @@ module.exports = Self => { } }); - Self.renderer = async (expeditionFk) => { + Self.renderer = async expeditionFk => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ @@ -109,7 +109,7 @@ module.exports = Self => { const ticket = expedition.ticket(); const sender = ticket.company().client(); const shipped = ticket.shipped.toISOString(); - const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk) + const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk); const data = { viaexpressConfig, sender, diff --git a/back/model-config.json b/back/model-config.json index 58fa86797..a16fe4e8a 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -192,5 +192,8 @@ }, "RouteConfig": { "dataSource": "vn" + }, + "MrwService": { + "dataSource": "vn" } } \ No newline at end of file diff --git a/back/models/mrw-config.js b/back/models/mrw-config.js index c738c9c0e..8bb24dbe5 100644 --- a/back/models/mrw-config.js +++ b/back/models/mrw-config.js @@ -31,5 +31,30 @@ module.exports = Self => { }); return parser.parseFromString(data.data, 'text/xml'); }; + + Self.getClientType = async function(expeditionFk) { + if (!expeditionFk) throw new UserError(`No expeditionFk defined`); + + const {clientTypeWidth} = await Self.getConfig(); + const result = await Self.app.models.Expedition.findById(expeditionFk, + {include: [{ + relation: 'ticket', + scope: { + include: { + relation: 'agencyMode', + scope: { + include: { + relation: 'mrwService', + } + } + } + } + }]} + ); + const clientType = result?.ticket()?.agencyMode()?.mrwService()?.clientType; + if (!clientType || !clientTypeWidth) throw new UserError(`ClientType not available`); + + return clientType.toString().padStart(clientTypeWidth, '0'); + }; }; diff --git a/back/models/mrw-config.json b/back/models/mrw-config.json index c96b68cf3..60c0ca2a2 100644 --- a/back/models/mrw-config.json +++ b/back/models/mrw-config.json @@ -45,6 +45,9 @@ }, "notified":{ "type": "date" + }, + "clientTypeWidth": { + "type": "number" } } } diff --git a/back/models/mrw-service.json b/back/models/mrw-service.json new file mode 100644 index 000000000..1ad72d060 --- /dev/null +++ b/back/models/mrw-service.json @@ -0,0 +1,33 @@ +{ + "name": "MrwService", + "base": "VnModel", + "options": { + "mysql": { + "table": "mrwService" + } + }, + "properties": { + "agencyModeCodeFk": { + "id": true, + "type": "string", + "required": true + }, + "clientType": { + "type": "number", + "required": true + }, + "serviceType": { + "type": "number" + }, + "kg": { + "type": "number" + } + }, + "relations": { + "agency": { + "type": "hasOne", + "model": "AgencyMode", + "foreignKey": "code" + } + } +} diff --git a/modules/zone/back/models/agency-mode.json b/modules/zone/back/models/agency-mode.json index 99ed43b97..6033e26c6 100644 --- a/modules/zone/back/models/agency-mode.json +++ b/modules/zone/back/models/agency-mode.json @@ -60,6 +60,11 @@ "type": "hasMany", "model": "Zone", "foreignKey": "agencyModeFk" + }, + "mrwService": { + "type": "belongsTo", + "model": "MrwService", + "foreignKey": "code" } }, "acls": [ From 5304929f57593a9d477bf5238172f54aff8b11a3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 11 Jul 2024 08:52:07 +0200 Subject: [PATCH 06/30] feat: #refs 7348 schema --- db/versions/11126-blueCamellia/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11126-blueCamellia/00-firstScript.sql b/db/versions/11126-blueCamellia/00-firstScript.sql index 45c2ed2dc..40c5e2b37 100644 --- a/db/versions/11126-blueCamellia/00-firstScript.sql +++ b/db/versions/11126-blueCamellia/00-firstScript.sql @@ -1,2 +1,2 @@ -ALTER TABLE `client` +ALTER TABLE `vn`.`client` ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'; From 0579e7dbbff60c8e3e1c7410b17e184b7329683c Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 11 Jul 2024 09:14:14 +0200 Subject: [PATCH 07/30] hotfix routeSummary --- modules/route/front/summary/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/front/summary/index.html b/modules/route/front/summary/index.html index 8269bf118..764312d16 100644 --- a/modules/route/front/summary/index.html +++ b/modules/route/front/summary/index.html @@ -35,10 +35,10 @@ + value="{{$ctrl.summary.route.started | date: 'HH:mm'}}"> + value="{{$ctrl.summary.route.finished | date: 'HH:mm'}}"> From 69bcad9ce006687604c8ecfdbebcc543e31cfcc0 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 11 Jul 2024 18:09:00 +0200 Subject: [PATCH 08/30] feat itemShelvingSale refs #6861 --- .../vn/procedures/itemShelvingSale_setQuantity.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 42f915ead..93927d417 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -21,6 +21,7 @@ BEGIN DECLARE vRemainingQuantity INT; DECLARE vItemFk INT; DECLARE vTotalQuantity INT; + DECLARE vStateCode VARCHAR(45); DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -32,10 +33,11 @@ BEGIN CALL util.throw('Reservation completed'); END IF; - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)) - INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity + SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)), IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED') vStateCode + INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity, vStateCode FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = iss.saleFk WHERE iss.id = vItemShelvingSaleFk AND NOT iss.isPicked; @@ -74,7 +76,7 @@ BEGIN vTotalQuantity, `account`.`myUser_getId`(), NULL, - 'PREPARED', + vStateCode, TRUE); UPDATE sale s From ca48ad9777f6043300c237017d5267e1db72cb92 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 11 Jul 2024 19:55:19 +0200 Subject: [PATCH 09/30] feat(salix): refs #7648 #7648 add new entries and travels --- db/dump/fixtures.after.sql | 29 +++++++++++++++++++ .../item/specs/lastEntriesFilter.spec.js | 2 +- .../travel/specs/extraCommunityFilter.spec.js | 2 +- .../back/methods/travel/specs/filter.spec.js | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 562ea02d8..dd07b24c0 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -315,4 +315,33 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`) FROM mysql.roles_mapping WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost; +UPDATE account.`user` + SET `role`=131 + WHERE id=1102; + +UPDATE vn.travel + SET shipped='2001-01-02',landed='2001-01-05' + WHERE id=4; +UPDATE vn.travel + SET shipped='2001-01-01',landed='2001-01-05' + WHERE id=5; +UPDATE vn.travel + SET landed='2001-01-05',shipped='2001-01-03' + WHERE id=6; +UPDATE vn.travel + SET shipped='2001-01-04',landed='2001-01-05' + WHERE id=7; + +UPDATE vn.travel + SET shipped='2001-01-05',landed='2001-01-05' + WHERE id=8; + +INSERT INTO vn.entry (supplierFk,invoiceNumber,isBooked,isExcludedFromAvailable,isConfirmed,isOrdered,isRaid,commission,created,evaNotes,travelFk,currencyFk,companyFk,isBlocked__,reference,editorFk,locked) + VALUES + (2,'IN2008',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), + (2,'IN2008',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), + (2,'IN2008',0,1,0,0,1,0.0,'2000-12-04 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), + (2,'IN2008',0,1,0,0,1,0.0,'2000-12-02 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), + (2,'IN2008',0,1,0,0,1,0.0,'2000-12-03 00:00:00.000','',8,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'); + FLUSH PRIVILEGES; diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index 00488e534..a99402266 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -37,7 +37,7 @@ describe('item lastEntriesFilter()', () => { const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; const result = await models.Item.lastEntriesFilter(filter, options); - expect(result.length).toEqual(5); + expect(result.length).toEqual(3); await tx.rollback(); } catch (e) { diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 599851b55..0553aa58a 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -110,6 +110,6 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(1); + expect(result.length).toEqual(6); }); }); diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index 1a6ee895c..3f8179c30 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -68,7 +68,7 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(3); }); it('should return the travel matching "continent"', async() => { From b28a8a34dc6445e12d5c2f46fac6c78b31c5d520 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 11 Jul 2024 19:55:36 +0200 Subject: [PATCH 10/30] feat(salix): refs #7648 #7648 add new filter --- modules/entry/back/methods/entry/filter.js | 21 +++++++++++++++++-- .../back/methods/entry/specs/filter.spec.js | 10 ++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index f21d9dbc4..0981247ee 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -2,6 +2,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; +const DEFAULT_INTERVAL_DAYS = 3; module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -95,6 +96,11 @@ module.exports = Self => { arg: 'to', type: 'date', description: `The to date filter` + }, + { + arg: 'days', + type: 'number', + description: `N days interval` } ], returns: { @@ -183,15 +189,26 @@ module.exports = Self => { t.landed, t.ref AS travelRef, t.warehouseInFk, - w.name warehouseInName + w.name warehouseInName, + util.VN_CURDATE() FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.company co ON co.id = e.companyFk - JOIN vn.currency cu ON cu.id = e.currencyFk` + JOIN vn.currency cu ON cu.id = e.currencyFk + ` ); + if (supplier) { + stmt.merge({ + sql: ` + AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY + AND t.shipped >= util.VN_CURDATE() + `, + params: Array(1).fill(ctx.args.days ?? DEFAULT_INTERVAL_DAYS) + }); + } stmt.merge(conn.makeSuffix(filter)); const itemsIndex = stmts.push(stmt) - 1; diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index c8a5bd94f..d08400184 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(9); + expect(result.length).toEqual(14); await tx.rollback(); } catch (e) { @@ -61,7 +61,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(8); await tx.rollback(); } catch (e) { @@ -84,7 +84,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(8); await tx.rollback(); } catch (e) { @@ -107,7 +107,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(8); + expect(result.length).toEqual(13); await tx.rollback(); } catch (e) { From 47cff3f8946d29d7b714da549fde55eee7a23612 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 12 Jul 2024 08:52:03 +0200 Subject: [PATCH 11/30] feat(ssalix): refs #7648 remove select field --- modules/entry/back/methods/entry/filter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 0981247ee..77e5f2e67 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -189,8 +189,7 @@ module.exports = Self => { t.landed, t.ref AS travelRef, t.warehouseInFk, - w.name warehouseInName, - util.VN_CURDATE() + w.name warehouseInName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk @@ -201,12 +200,13 @@ module.exports = Self => { ); if (supplier) { + const days = ctx.args.days ?? DEFAULT_INTERVAL_DAYS; stmt.merge({ sql: ` AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY AND t.shipped >= util.VN_CURDATE() `, - params: Array(1).fill(ctx.args.days ?? DEFAULT_INTERVAL_DAYS) + params: [days] }); } stmt.merge(conn.makeSuffix(filter)); From 21987011b6392f4277c4ba1da3719e1533dfee38 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 12 Jul 2024 09:06:05 +0200 Subject: [PATCH 12/30] feat itemShelvingSale refs #6861 --- .../vn/procedures/itemShelvingSale_setQuantity.sql | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 93927d417..85f56ee68 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -33,8 +33,16 @@ BEGIN CALL util.throw('Reservation completed'); END IF; - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)), IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED') vStateCode - INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity, vStateCode + SELECT s.itemFk, + iss.saleFk, + iss.itemShelvingFk, + SUM(IFNULL(iss.quantity,0)), + IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED') + INTO vItemFk, + vSaleFk, + vItemShelvingFk, + vReservedQuantity, + vStateCode FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = iss.saleFk From b93601d6d868e042ec739725a5b832383e94d83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 08:27:24 +0000 Subject: [PATCH 13/30] Actualizar db/routines/vn/procedures/itemShelvingSale_addBySale.sql --- .../procedures/itemShelvingSale_addBySale.sql | 214 +++++++++--------- 1 file changed, 113 insertions(+), 101 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 7e836859a..2aae37353 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -1,102 +1,114 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( - vSaleFk INT -) -proc: BEGIN -/** - * Reserva una línea de venta en la ubicación más óptima - * - * @param vSaleFk Id de sale - * @param vItemShelvingSaleFk Id de reserva - */ - DECLARE vLastPickingOrder INT; - DECLARE vDone INT DEFAULT FALSE; - DECLARE vItemShelvingFk INT; - DECLARE vAvailable INT; - DECLARE vReservedQuantity INT; - DECLARE vOutStanding INT; - DECLARE vUserFk INT; - - DECLARE vItemShelvingAvailable CURSOR FOR - SELECT ish.id itemShelvingFk, - ish.available - FROM sale s - JOIN itemShelving ish ON ish.itemFk = s.itemFk - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector sc ON sc.id = p.sectorFk - JOIN productionConfig pc - WHERE s.id = vSaleFk - AND NOT sc.isHideForPickers - ORDER BY s.id, - p.pickingOrder >= vLastPickingOrder, - sh.priority DESC, - ish.available >= s.quantity DESC, - s.quantity MOD ish.grouping = 0 DESC, - ish.grouping DESC, - IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)) - INTO vLastPickingOrder, vOutStanding - FROM sale s - LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id - LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - LEFT JOIN shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = sh.parkingFk - WHERE s.id = vSaleFk; - - IF vOutStanding <= 0 THEN - LEAVE proc; - END IF; - - SELECT getUser() INTO vUserFk; - - OPEN vItemShelvingAvailable; - l: LOOP - SET vDone = FALSE; - FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable; - - IF vOutStanding <= 0 OR vDone THEN - LEAVE l; - END IF; - - START TRANSACTION; - - SELECT id INTO vItemShelvingFk - FROM itemShelving - WHERE id = vItemShelvingFk - FOR UPDATE; - - SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity; - SET vOutStanding = vOutStanding - vReservedQuantity; - - IF vReservedQuantity > 0 THEN - - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk) - SELECT vItemShelvingFk, - vSaleFk, - vReservedQuantity, - vUserFk; - - UPDATE itemShelving - SET available = available - vReservedQuantity - WHERE id = vItemShelvingFk; - - END IF; - - COMMIT; - END LOOP; - CLOSE vItemShelvingAvailable; -END$$ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( + vSaleFk INT +) +proc: BEGIN +/** + * Reserva una línea de venta en la ubicación más óptima + * + * @param vSaleFk Id de sale + * @param vItemShelvingSaleFk Id de reserva + */ + DECLARE vLastPickingOrder INT; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vItemShelvingFk INT; + DECLARE vAvailable INT; + DECLARE vReservedQuantity INT; + DECLARE vOutStanding INT; + DECLARE vUserFk INT; + DECLARE vTotalReservedQuantity INT; + DECLARE vSaleQuantity INT; + + DECLARE vItemShelvingAvailable CURSOR FOR + SELECT ish.id itemShelvingFk, + ish.available + FROM sale s + JOIN itemShelving ish ON ish.itemFk = s.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector sc ON sc.id = p.sectorFk + JOIN productionConfig pc + WHERE s.id = vSaleFk + AND NOT sc.isHideForPickers + ORDER BY s.id, + p.pickingOrder >= vLastPickingOrder, + sh.priority DESC, + ish.available >= s.quantity DESC, + s.quantity MOD ish.grouping = 0 DESC, + ish.grouping DESC, + IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity + INTO vLastPickingOrder, vOutStanding, vSaleQuantity + FROM sale s + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + LEFT JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = sh.parkingFk + WHERE s.id = vSaleFk; + + IF vOutStanding <= 0 THEN + LEAVE proc; + END IF; + + SELECT getUser() INTO vUserFk; + + OPEN vItemShelvingAvailable; + l: LOOP + SET vDone = FALSE; + FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable; + + IF vOutStanding <= 0 OR vDone THEN + SELECT SUM(IFNULL(quantity, 0)) + INTO vTotalReservedQuantity + FROM itemShelvingSale + WHERE saleFk = vSaleFk; + + IF vTotalReservedQuantity <> vSaleQuantity THEN + UPDATE sale + SET quantity = vTotalReservedQuantity + WHERE id = vSaleFk; + END IF + LEAVE l; + END IF; + + START TRANSACTION; + + SELECT id INTO vItemShelvingFk + FROM itemShelving + WHERE id = vItemShelvingFk + FOR UPDATE; + + SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity; + SET vOutStanding = vOutStanding - vReservedQuantity; + + IF vReservedQuantity > 0 THEN + + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk; + + UPDATE itemShelving + SET available = available - vReservedQuantity + WHERE id = vItemShelvingFk; + + END IF; + + COMMIT; + END LOOP; + CLOSE vItemShelvingAvailable; +END$$ DELIMITER ; \ No newline at end of file From 323d26f226482a72cb34f7c8c05d9ef773368862 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 12 Jul 2024 10:37:39 +0200 Subject: [PATCH 14/30] Fix --- db/routines/vn/procedures/itemShelvingSale_addBySale.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 2aae37353..909ce5155 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -75,7 +75,7 @@ proc: BEGIN UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; - END IF + END IF; LEAVE l; END IF; From 896d273da81d0eb99331f759d5f26f72c24accd6 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 12 Jul 2024 12:06:37 +0200 Subject: [PATCH 15/30] fix(worker_new): fix countryFk --- modules/client/front/postcode/index.html | 2 +- modules/worker/back/methods/worker/new.js | 12 ++++++------ modules/worker/back/models/worker.js | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/client/front/postcode/index.html b/modules/client/front/postcode/index.html index b3dbb74d8..fa0b7870f 100644 --- a/modules/client/front/postcode/index.html +++ b/modules/client/front/postcode/index.html @@ -53,7 +53,7 @@ diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index ba9dc3853..fad464ae1 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -171,8 +171,8 @@ module.exports = Self => { const address = await models.Address.create({ clientFk: user.id, street: street, - city: city, - provinceFk: provinceFk, + city, + provinceFk, postalCode: postcode, mobile: phone, nickname: nickname, @@ -193,7 +193,9 @@ module.exports = Self => { } await user.updateAttribute('email', email, myOptions); - + const {countryFk} = await Self.app.models.Province.findById(provinceFk, { + fields: ['countryFk'] + }); await models.Worker.create({ id: user.id, firstName, @@ -202,6 +204,7 @@ module.exports = Self => { bossFk, fi, birth, + originCountryFk: countryFk }, myOptions); @@ -212,11 +215,8 @@ module.exports = Self => { const message = e.sqlMessage; if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`); - if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`); - if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`); - throw e; } diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 0b0e043f2..3351c348c 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -27,11 +27,10 @@ module.exports = Self => { }); async function tinIsValid(err, done) { - const filter = { + const country = await Self.app.models.Country.findOne({ fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); + where: {id: this.originCountryFk} + }); const code = country ? country.code.toLowerCase() : null; if (!this.fi || !validateTin(this.fi, code)) From 66959dd3885bf94372139d0818c05161273bb4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 12:10:43 +0200 Subject: [PATCH 16/30] hotfix: packaging ticket 199070 --- .../vn/procedures/sale_getBoxPickingList.sql | 25 ++++++++++--------- db/routines/vn/procedures/ticket_close.sql | 8 ++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 7466eb9be..8d16d556b 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -19,21 +19,20 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale (saleFk INT PRIMARY KEY) - SELECT - s.ticketFk, - s.id saleFk, - s.itemFk, - s.concept, - s.quantity, - MAKETIME(pb.HH,pb.mm,0) etd, - pb.routeFk, - FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, - IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, - b.packagingFk + SELECT s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, + IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, + IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk - LEFT JOIN ( SELECT iss.itemShelvingFk, + LEFT JOIN ( SELECT iss.itemShelvingFk, s.itemFk, SUM(iss.quantity) reserve FROM itemShelvingSale iss @@ -52,6 +51,8 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN packaging pa ON pa.id = b.packagingFk + JOIN packagingConfig pc WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut) <= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0)) AND NOT pb.problem diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 47d748ddf..16173719a 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -44,14 +44,14 @@ BEGIN t.shipped, IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), w.isManaged, - c.hasToInvoice + c.hasToInvoice INTO vClientFk, vIsTaxDataChecked, vCompanyFk, vShipped, vHasDailyInvoice, vWithPackage, - vHasToInvoice + vHasToInvoice FROM ticket t JOIN `client` c ON c.id = t.clientFk JOIN province p ON p.id = c.provinceFk @@ -64,8 +64,12 @@ BEGIN (SELECT vCurTicketFk, p.id, COUNT(*) FROM expedition e JOIN packaging p ON p.id = e.packagingFk + JOIN ticket t ON t.id = e.ticketFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage + AND NOT dm.`code`= 'PICKUP' GROUP BY p.itemFk); -- No retornables o no catalogados From d2e482d7cd01d29b39035f7fc5f14fc7dbe6508c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 12:13:21 +0200 Subject: [PATCH 17/30] hotfix: packaging ticket 199070 --- db/routines/vn/procedures/ticket_close.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 16173719a..7f52e81a7 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -65,8 +65,8 @@ BEGIN FROM expedition e JOIN packaging p ON p.id = e.packagingFk JOIN ticket t ON t.id = e.ticketFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage AND NOT dm.`code`= 'PICKUP' From cb107215b609ef12822d00263f9135e3c7652234 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 12 Jul 2024 13:14:00 +0200 Subject: [PATCH 18/30] feat itemShelvingSale refs #6861 --- back/methods/collection/getTickets.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 663b70e94..b79dbc93a 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -63,8 +63,7 @@ module.exports = Self => { iss.isPicked FROM ticketCollection tc LEFT JOIN collection c ON c.id = tc.collectionFk - JOIN ticket t ON t.id = tc.ticketFk - JOIN sale s ON s.ticketFk = t.id + JOIN sale s ON s.ticketFk = tc.ticketFk LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk @@ -103,9 +102,8 @@ module.exports = Self => { FROM sectorCollection sc JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id JOIN saleGroup sg ON sg.id = ss.saleGroupFk - JOIN ticket t ON t.id = sg.ticketFk - JOIN sale s ON s.ticketFk = t.id - LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id + JOIN sale s ON s.id = sgd.saleFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk JOIN item i ON i.id = s.itemFk JOIN itemShelvingSale iss ON iss.saleFk = s.id From 1e264c21026fbee6d3bc2b060388daebce8fd1ec Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 12 Jul 2024 14:04:49 +0200 Subject: [PATCH 19/30] fix: refs #7704 Warehouse priority --- db/dump/fixtures.before.sql | 6 +++--- .../hedera/procedures/order_addItem.sql | 12 +++++++++-- .../vn/procedures/catalog_calculate.sql | 21 +++++++++++++------ .../11150-bronzeEucalyptus/00-firstScript.sql | 2 ++ modules/ticket/back/models/sale.js | 11 +++++++--- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 db/versions/11150-bronzeEucalyptus/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index d918007e7..7446342c0 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -995,11 +995,11 @@ INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3` INSERT INTO `vn`.`itemMinimumQuantity`(`itemFk`, `quantity`, `started`, `ended`, `warehouseFk`) VALUES - (1, 5, util.VN_CURDATE() - INTERVAL 2 MONTH, util.VN_CURDATE() + INTERVAL 1 MONTH, 1), - (2, 10, util.VN_CURDATE() - INTERVAL 2 DAY, NULL, 2), + (1, 5, util.VN_CURDATE() - INTERVAL 2 MONTH, util.VN_CURDATE() + INTERVAL 1 MONTH, 1), + (2, 10, util.VN_CURDATE() - INTERVAL 2 DAY, util.VN_CURDATE() - INTERVAL 1 DAY, 2), (3, 15, util.VN_CURDATE() + INTERVAL 3 DAY, util.VN_CURDATE() + INTERVAL 2 WEEK, 3), (2, 10, util.VN_CURDATE() + INTERVAL 2 MONTH, NULL, 5), - (4, 8, util.VN_CURDATE() - INTERVAL 3 MONTH, NULL, NULL); + (4, 8, util.VN_CURDATE() - INTERVAL 3 MONTH, NULL, NULL); INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`) VALUES diff --git a/db/routines/hedera/procedures/order_addItem.sql b/db/routines/hedera/procedures/order_addItem.sql index 50c2f3489..f690f9aa6 100644 --- a/db/routines/hedera/procedures/order_addItem.sql +++ b/db/routines/hedera/procedures/order_addItem.sql @@ -56,13 +56,21 @@ BEGIN CALL util.throw ('ORDER_ROW_UNAVAILABLE'); END IF; - SELECT quantity INTO vMinQuantity + WITH itemMinQuantityPriority AS ( + SELECT quantity, + ROW_NUMBER() OVER ( + PARTITION BY itemFk + ORDER BY warehouseFk IS NULL + ) priority FROM vn.itemMinimumQuantity WHERE itemFk = vItem AND `started` <= vShipment AND (`ended` >= vShipment OR `ended` IS NULL) AND (warehouseFk = vWarehouse OR warehouseFk IS NULL) - LIMIT 1; + ) + SELECT quantity INTO vMinQuantity + FROM itemMinQuantityPriority + WHERE priority = 1; IF vAmount < LEAST(IFNULL(vMinQuantity, 0), vAvailable) THEN CALL util.throw ('quantityLessThanMin'); diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql index e79f2da0b..963e33507 100644 --- a/db/routines/vn/procedures/catalog_calculate.sql +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -180,15 +180,24 @@ BEGIN GROUP BY itemFk ) bl ON bl.itemFk = tl.itemFk LEFT JOIN ( - SELECT itemFk, quantity, warehouseFk - FROM itemMinimumQuantity + WITH itemMinQuantityPriority AS ( + SELECT itemFk, + quantity, + ROW_NUMBER() OVER ( + PARTITION BY itemFk + ORDER BY warehouseFk IS NULL + ) priority + FROM vn.itemMinimumQuantity WHERE `started` <= vShipped AND (`ended` >= vShipped OR `ended` IS NULL) - GROUP BY itemFk, warehouseFk - ORDER BY warehouseFk DESC + AND (warehouseFk = vWarehouseFk OR warehouseFk IS NULL) + ) + SELECT itemFk, quantity + FROM itemMinQuantityPriority + WHERE priority = 1 ) mq ON mq.itemFk = tl.itemFk - AND (mq.warehouseFk = tl.warehouseFk OR mq.warehouseFk IS NULL) - WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk + WHERE tl.zoneFk = vZoneFk + AND tl.warehouseFk = vWarehouseFk GROUP BY tl.itemFk ON DUPLICATE KEY UPDATE available = available + VALUES(available); END LOOP; diff --git a/db/versions/11150-bronzeEucalyptus/00-firstScript.sql b/db/versions/11150-bronzeEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..c9a619618 --- /dev/null +++ b/db/versions/11150-bronzeEucalyptus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.itemMinimumQuantity + ADD CONSTRAINT itemMinimumQuantity_check CHECK (quantity > 0); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 12cb08c16..3aa4cbf2a 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -88,8 +88,8 @@ module.exports = Self => { if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return; - const minQuantity = await models.ItemMinimumQuantity.findOne({ - fields: ['quantity'], + const itemMinimalQuantity = await models.ItemMinimumQuantity.find({ + fields: ['quantity', 'warehouseFk'], where: { itemFk: itemId, started: {lte: ticket.shipped}, @@ -103,9 +103,14 @@ module.exports = Self => { {warehouseFk: null} ] }, - limit: 1 }, ctx.options); + const minQuantity = itemMinimalQuantity.reduce((selected, item) => { + if (item.warehouseFk === ticket.warehouseFk) return item; + if (item.warehouseFk === null && !selected) return item; + return selected; + }, null); + if (newQuantity < minQuantity?.quantity && newQuantity != available) throw new UserError('The amount cannot be less than the minimum'); From 49183c79f10faced2a42c5f701afa9c90de748af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 16:47:24 +0200 Subject: [PATCH 20/30] feat: Turn issues into calculated columns refs#7213 --- db/routines/vn/procedures/ticket_setRisk.sql | 43 ++++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index f5e6cb5a0..32f3647b7 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -8,6 +8,7 @@ BEGIN * @param vClientFk Id cliente */ DECLARE vHasDebt BOOL; + DECLARE vStarted DATETIME; SELECT COUNT(*) INTO vHasDebt FROM `client` @@ -16,22 +17,24 @@ BEGIN IF vHasDebt THEN + SELECT util.VN_CURDATE() - INTERVAL riskScope MONTH INTO vStarted + FROM clientConfig; + CREATE OR REPLACE TEMPORARY TABLE tTicketRisk (KEY (ticketFk)) ENGINE = MEMORY WITH ticket AS( - SELECT id ticketFk, companyFk, DATE(shipped) dated - FROM vn.ticket t + SELECT id ticketFk, + companyFk, + DATE(shipped) dated, + totalWithVat, + ticket_isProblemCalcNeeded(id) isProblemCalcNeeded + FROM vn.ticket WHERE clientFk = vClientFk AND refFk IS NULL AND NOT isDeleted - AND totalWithoutVat <> 0 - ), dated AS( - SELECT t.companyFk, MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started, - MAX(DATE(t.dated)) ended - FROM ticket t - JOIN vn.clientConfig cc - GROUP BY t.companyFk + AND IFNULL(totalWithVat, 0) <> 0 + AND shipped > vStarted ), balance AS( SELECT SUM(amount)amount, companyFk FROM ( @@ -49,15 +52,11 @@ BEGIN WHERE companyFk GROUP BY companyFk ), uninvoiced AS( - SELECT t.companyFk, DATE(t.shipped) dated, SUM(IFNULL(t.totalWithVat, 0)) amount - FROM vn.ticket t - JOIN dated d - WHERE t.clientFk = vClientFk - AND t.refFk IS NULL - AND t.shipped BETWEEN d.started AND d.ended - GROUP BY t.companyFk, DATE(t.shipped) + SELECT companyFk, dated, SUM(totalWithVat) amount + FROM ticket + GROUP BY companyFk, dated ), receipt AS( - SELECT companyFk,DATE(payed) dated, SUM(amountPaid) amount + SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount FROM vn.receipt WHERE clientFk = vClientFk AND payed > util.VN_CURDATE() @@ -79,7 +78,15 @@ BEGIN UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id - SET t.risk = tr.amount; + SET t.risk = tr.amount + WHERE tr.isProblemCalcNeeded + ORDER BY t.id; + + UPDATE ticket t + JOIN tTicketRisk tr ON tr.ticketFk = t.id + SET t.risk = NULL + WHERE tr.isProblemCalcNeeded + ORDER BY t.id; DROP TEMPORARY TABLE tTicketRisk; END IF; From c70824535a347a334dc62470ba79629aaeba9fd4 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 12 Jul 2024 20:52:00 +0200 Subject: [PATCH 21/30] feat(ssalix): refs #7648 clean fixtures --- db/dump/fixtures.after.sql | 26 -------------------------- db/dump/fixtures.before.sql | 7 +++++-- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index dd07b24c0..bc2c86b95 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -318,30 +318,4 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`) UPDATE account.`user` SET `role`=131 WHERE id=1102; - -UPDATE vn.travel - SET shipped='2001-01-02',landed='2001-01-05' - WHERE id=4; -UPDATE vn.travel - SET shipped='2001-01-01',landed='2001-01-05' - WHERE id=5; -UPDATE vn.travel - SET landed='2001-01-05',shipped='2001-01-03' - WHERE id=6; -UPDATE vn.travel - SET shipped='2001-01-04',landed='2001-01-05' - WHERE id=7; - -UPDATE vn.travel - SET shipped='2001-01-05',landed='2001-01-05' - WHERE id=8; - -INSERT INTO vn.entry (supplierFk,invoiceNumber,isBooked,isExcludedFromAvailable,isConfirmed,isOrdered,isRaid,commission,created,evaNotes,travelFk,currencyFk,companyFk,isBlocked__,reference,editorFk,locked) - VALUES - (2,'IN2008',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), - (2,'IN2008',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), - (2,'IN2008',0,1,0,0,1,0.0,'2000-12-04 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), - (2,'IN2008',0,1,0,0,1,0.0,'2000-12-02 00:00:00.000','',7,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'), - (2,'IN2008',0,1,0,0,1,0.0,'2000-12-03 00:00:00.000','',8,1,442,0,'Movement 8',100,'2024-07-11 09:24:48.000'); - FLUSH PRIVILEGES; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 7446342c0..16c785bc6 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1500,7 +1500,8 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10); + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), + (10, DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) VALUES @@ -1511,7 +1512,9 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 0, 'observation five'), (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 0, 'observation six'), (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'), - (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''); + (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''), + (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''), + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''); INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWaste`, `rate`) VALUES From 5dcabd687e1eb3a68231193cec90b9e60311733c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 12 Jul 2024 20:52:26 +0200 Subject: [PATCH 22/30] feat(ssalix): refs #7648 clean test !entry.filter --- .../item/back/methods/item/specs/lastEntriesFilter.spec.js | 2 +- .../back/methods/travel/specs/extraCommunityFilter.spec.js | 4 ++-- modules/travel/back/methods/travel/specs/filter.spec.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index a99402266..00488e534 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -37,7 +37,7 @@ describe('item lastEntriesFilter()', () => { const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; const result = await models.Item.lastEntriesFilter(filter, options); - expect(result.length).toEqual(3); + expect(result.length).toEqual(5); await tx.rollback(); } catch (e) { diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 0553aa58a..7e90c7681 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(8); + expect(result.length).toEqual(9); }); it('should return the travel matching "cargoSupplierFk"', async() => { @@ -110,6 +110,6 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(6); + expect(result.length).toEqual(2); }); }); diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index 3f8179c30..a608a980e 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -50,7 +50,7 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(5); + expect(result.length).toEqual(6); }); it('should return the routes matching "shipped from" and "shipped to"', async() => { @@ -68,7 +68,7 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(3); + expect(result.length).toEqual(1); }); it('should return the travel matching "continent"', async() => { @@ -80,6 +80,6 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(5); + expect(result.length).toEqual(6); }); }); From 1d23554508e2d58539a56d5c8059f1f794b974a8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 12 Jul 2024 20:52:52 +0200 Subject: [PATCH 23/30] perf(ssalix): refs #7648 remove default value --- modules/entry/back/methods/entry/filter.js | 9 +++------ modules/entry/back/methods/entry/specs/filter.spec.js | 10 +++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 77e5f2e67..2e2b8e467 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -2,7 +2,6 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; -const DEFAULT_INTERVAL_DAYS = 3; module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -195,18 +194,16 @@ module.exports = Self => { JOIN vn.travel t ON t.id = e.travelFk JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.company co ON co.id = e.companyFk - JOIN vn.currency cu ON cu.id = e.currencyFk - ` + JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (supplier) { - const days = ctx.args.days ?? DEFAULT_INTERVAL_DAYS; + if (supplier && ctx.args.days) { stmt.merge({ sql: ` AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY AND t.shipped >= util.VN_CURDATE() `, - params: [days] + params: [ctx.args.days] }); } stmt.merge(conn.makeSuffix(filter)); diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index d08400184..c7156062a 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(14); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { @@ -55,13 +55,13 @@ describe('Entry filter()', () => { try { const ctx = { - args: {}, + args: {days: 6}, req: {accessToken: {userId: 1102}} }; const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(8); + expect(result.length).toEqual(2); await tx.rollback(); } catch (e) { @@ -107,7 +107,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(11); + expect(result.length).toEqual(8); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(13); + expect(result.length).toEqual(10); await tx.rollback(); } catch (e) { From 0ca4bffaf0e0541ab18a96d3bc99bb54c29320d1 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sat, 13 Jul 2024 18:07:46 +0000 Subject: [PATCH 24/30] Perf: improve condition days filter --- modules/entry/back/methods/entry/filter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 2e2b8e467..4b47c625e 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -1,4 +1,3 @@ - const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; @@ -197,7 +196,7 @@ module.exports = Self => { JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (supplier && ctx.args.days) { + if (ctx.args.days) { stmt.merge({ sql: ` AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY From 67b19ee4ca10e99e68c1937bb0f1eca3daa92e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Sun, 14 Jul 2024 09:08:14 +0200 Subject: [PATCH 25/30] hotfix: packaging ticket 199070 --- db/routines/vn/procedures/sale_getBoxPickingList.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 8d16d556b..a95ed5b0c 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -28,7 +28,7 @@ BEGIN pb.routeFk, FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, - IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) + IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) packagingFk FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk From fb8b31b397292c737b5e5980a2ab4aa08ae0ec4f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 15 Jul 2024 09:59:52 +0200 Subject: [PATCH 26/30] perf: refs #7648 #7648 clean fixtures and SQL filter --- db/dump/fixtures.after.sql | 4 ---- db/dump/fixtures.before.sql | 2 +- modules/entry/back/methods/entry/filter.js | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index bc2c86b95..84ce0d940 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -314,8 +314,4 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`) SELECT SUBSTR(`User`, @prefixLen + 1), `Host`, `Role`, `Admin_option` FROM mysql.roles_mapping WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost; - -UPDATE account.`user` - SET `role`=131 - WHERE id=1102; FLUSH PRIVILEGES; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 16c785bc6..db0fab77f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -121,7 +121,7 @@ INSERT INTO hedera.orderConfig (`id`, `employeeFk`, `defaultAgencyFk`, `guestMet INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`) VALUES (1101, 'brucewayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es','1101'), - (1102, 'petterparker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'PetterParker@mydomain.com', 'en','1102'), + (1102, 'petterparker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 131, 1, 'PetterParker@mydomain.com', 'en','1102'), (1103, 'clarkkent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'ClarkKent@mydomain.com', 'fr','1103'), (1104, 'tonystark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'TonyStark@mydomain.com', 'es','1104'), (1105, 'maxeisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt','1105'), diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 2e2b8e467..5fbfd2d0f 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -197,10 +197,10 @@ module.exports = Self => { JOIN vn.currency cu ON cu.id = e.currencyFk` ); - if (supplier && ctx.args.days) { + if (ctx.args.days) { stmt.merge({ sql: ` - AND t.shipped < util.VN_CURDATE() + INTERVAL ? + 1 DAY + AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY AND t.shipped >= util.VN_CURDATE() `, params: [ctx.args.days] From 08ba1acc3cf3825455b8559ce3597a03b27b90ff Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 15 Jul 2024 13:35:24 +0200 Subject: [PATCH 27/30] fix: refs #6403 fix delivery observation --- back/methods/mrw-config/createShipment.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index ab25113dc..900e1fc0f 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -63,8 +63,7 @@ module.exports = Self => { JOIN client c ON t.clientFk = c.id JOIN address a ON t.addressFk = a.id LEFT JOIN addressObservation oa ON oa.addressFk = a.id - LEFT JOIN observationType ot ON ot.id = oa.observationTypeFk - AND ot.code = 'delivery' + AND oa.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'delivery') JOIN province p ON a.provinceFk = p.id JOIN country co ON co.id = p.countryFk JOIN mrwConfig mc From ddd6c799dc2e1f949757562e3930ff6e116ec653 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 15 Jul 2024 17:32:14 +0000 Subject: [PATCH 28/30] feat(salix): #7648 Add field for endpoint as buyLabel report --- modules/entry/back/methods/entry/getBuys.js | 35 ++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index 0cb71653e..6635c8038 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -51,6 +51,7 @@ module.exports = Self => { 'stickers', 'packing', 'grouping', + 'packing', 'groupingMode', 'quantity', 'packagingFk', @@ -59,7 +60,8 @@ module.exports = Self => { 'price2', 'price3', 'printedStickers', - 'entryFk' + 'entryFk', + ], include: [{ relation: 'entry', @@ -80,7 +82,9 @@ module.exports = Self => { fields: [ 'id', 'typeFk', + 'stems', 'name', + 'category', 'subName', 'size', 'minPrice', @@ -96,14 +100,31 @@ module.exports = Self => { 'value9', 'tag10', 'value10', - 'groupingMode' + 'groupingMode', + 'inkFk', + 'originFk', + 'producerFk' ], - include: { - relation: 'itemType', - scope: { - fields: ['code', 'description'] + include: [ + { + relation: 'itemType', + scope: { + fields: ['code', 'description'] + } + }, + { + relation: 'origin', + scope: { + fields: ['code'] + } + }, + { + relation: 'producer', + scope: { + fields: ['name'] + } } - } + ] } }] }; From a0be2edc415ecda3e6101e0c7d598c6a19f70359 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 15 Jul 2024 17:33:21 +0000 Subject: [PATCH 29/30] feat(salix): #7648 remove white line --- modules/entry/back/methods/entry/getBuys.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index 6635c8038..b6809c8c5 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -60,8 +60,7 @@ module.exports = Self => { 'price2', 'price3', 'printedStickers', - 'entryFk', - + 'entryFk' ], include: [{ relation: 'entry', From aa1db03224da1754d5a88a4e6f7e369f0d309880 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 16 Jul 2024 09:18:52 +0200 Subject: [PATCH 30/30] build: init version 24.32 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea126bce3..9016f74a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.30.0", + "version": "24.32.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0",