From 4bef3e9107375adbe80e844f71b9c5de8526b889 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 3 Jul 2024 17:09:10 +0200 Subject: [PATCH 01/26] refs #7531 Modify zone_getAddresses --- .../vn/procedures/zone_getAddresses.sql | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index ce7b0204e..c3a21aa83 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -1,7 +1,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( vSelf INT, - vLanded DATE + vDated DATE, + vDepartment INT ) BEGIN /** @@ -12,6 +13,7 @@ BEGIN * * @param vSelf Id de zona * @param vDated Fecha de entrega + * @param vDepartment Departamento del trabajador * @return Un select */ CALL zone_getPostalCode(vSelf); @@ -22,34 +24,47 @@ BEGIN WHERE id NOT IN ( SELECT clientFk FROM vn.ticket - WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded) + WHERE landed BETWEEN vDated AND util.dayEnd(vDated) ) + ), + hasTicketShippedToday AS ( + SELECT clientFk, + IF (COUNT(*) > 0, TRUE, FALSE) hasTicketShipped + FROM vn.ticket + WHERE shipped BETWEEN vDated AND util.dayEnd(vDated) + GROUP BY clientFk ) SELECT c.id clientFk, - c.name, - c.phone, - bt.description, - c.salesPersonFk, - u.name username, - aai.invoiced, - cnb.lastShipped - FROM vn.client c - JOIN notHasTicket ON notHasTicket.id = c.id - LEFT JOIN account.`user` u ON u.id = c.salesPersonFk - JOIN vn.`address` a ON a.clientFk = c.id - JOIN vn.postCode pc ON pc.code = a.postalCode - JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk - JOIN vn.zoneGeo zg ON zg.name = a.postalCode - JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk - LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id - LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id - JOIN vn.clientType ct ON ct.code = c.typeFk - JOIN vn.businessType bt ON bt.code = c.businessTypeFk - WHERE a.isActive - AND c.isActive - AND ct.code = 'normal' - AND bt.code <> 'worker' - GROUP BY c.id; + c.name, + c.phone, + bt.description, + c.salesPersonFk, + u.name username, + aai.invoiced, + cnb.lastShipped, + ht.hasTicketShipped + FROM vn.client c + JOIN vn.worker w ON w.id = c.salesPersonFk + JOIN vn.workerDepartment wd ON wd.workerFk = w.id + JOIN vn.department d ON d.id = wd.departmentFk + JOIN notHasTicket ON notHasTicket.id = c.id + LEFT JOIN account.`user` u ON u.id = c.salesPersonFk + JOIN vn.`address` a ON a.clientFk = c.id + JOIN vn.postCode pc ON pc.code = a.postalCode + JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk + JOIN vn.zoneGeo zg ON zg.name = a.postalCode + JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk + LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id + LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id + JOIN vn.clientType ct ON ct.code = c.typeFk + JOIN vn.businessType bt ON bt.code = c.businessTypeFk + LEFT JOIN hasTicketShippedToday ht ON ht.clientFk = c.id + WHERE a.isActive + AND c.isActive + AND ct.code = 'normal' + AND bt.code <> 'worker' + AND d.id = vDepartment + GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; END$$ From 38d863aac63c76873eed12cdf8461c99786e587d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Jul 2024 18:44:24 +0200 Subject: [PATCH 02/26] feat: refactor buyUltimate refs #7736 --- .../cache/procedures/last_buy_refresh.sql | 2 +- .../vn/procedures/available_traslate.sql | 2 +- db/routines/vn/procedures/buyUltimate.sql | 31 +--- .../vn/procedures/buyUltimateFromInterval.sql | 150 +-------------- db/routines/vn/procedures/buy_getUltimate.sql | 48 +++++ .../buy_getUltimateFromInterval .sql | 174 ++++++++++++++++++ .../vn/procedures/buy_updateGrouping.sql | 2 +- .../vn/procedures/buy_updatePacking.sql | 2 +- .../vn/procedures/catalog_calculate.sql | 2 +- .../vn/procedures/entry_getTransfer.sql | 2 +- .../vn/procedures/itemShelving_addByClaim.sql | 2 +- .../itemShelving_getItemDetails.sql | 2 +- db/routines/vn/procedures/item_devalueA2.sql | 2 +- db/routines/vn/procedures/item_getInfo.sql | 6 +- .../vn/procedures/item_multipleBuy.sql | 2 +- .../vn/procedures/item_valuateInventory.sql | 2 +- .../vn/procedures/sale_getProblems.sql | 2 +- .../vn/procedures/sale_recalcComponent.sql | 2 +- .../vn/procedures/sale_replaceItem.sql | 4 +- .../vn/procedures/sale_setProblemRounding.sql | 2 +- db/routines/vn/procedures/stockTraslation.sql | 2 +- .../vn/procedures/ticket_componentPreview.sql | 7 +- .../procedures/ticket_setProblemRounding.sql | 2 +- .../entry/back/methods/entry/addFromBuy.js | 4 +- .../entry/back/methods/entry/importBuys.js | 3 +- .../entry/back/methods/entry/lastItemBuys.js | 3 +- .../methods/order/getItemTypeAvailable.js | 15 +- 27 files changed, 265 insertions(+), 212 deletions(-) create mode 100644 db/routines/vn/procedures/buy_getUltimate.sql create mode 100644 db/routines/vn/procedures/buy_getUltimateFromInterval .sql diff --git a/db/routines/cache/procedures/last_buy_refresh.sql b/db/routines/cache/procedures/last_buy_refresh.sql index 49ef4ee5e..0f80163fb 100644 --- a/db/routines/cache/procedures/last_buy_refresh.sql +++ b/db/routines/cache/procedures/last_buy_refresh.sql @@ -30,7 +30,7 @@ proc: BEGIN SELECT inventoried INTO started FROM vn.config LIMIT 1; SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE()); - CALL vn.buyUltimateFromInterval(NULL, started, ended); + CALL vn.buy_getUltimateFromInterval (NULL, NULL, started, ended); DELETE FROM last_buy; diff --git a/db/routines/vn/procedures/available_traslate.sql b/db/routines/vn/procedures/available_traslate.sql index d33a8e10e..e4ba13d79 100644 --- a/db/routines/vn/procedures/available_traslate.sql +++ b/db/routines/vn/procedures/available_traslate.sql @@ -47,7 +47,7 @@ proc: BEGIN -- Tabla con el ultimo dia de last_buy para cada producto -- que hace un replace de la anterior. - CALL buyUltimate(vWarehouseShipment, util.VN_CURDATE()); + CALL buy_getUltimate (NULL, vWarehouseShipment, util.VN_CURDATE()); INSERT INTO tItemRange SELECT t.itemFk, tr.landed diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql index 98b16cbc0..7026c8c82 100644 --- a/db/routines/vn/procedures/buyUltimate.sql +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -5,39 +5,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`( ) BEGIN /** + * DEPRECATED usar buy_getUltimate * Calcula las últimas compras realizadas hasta una fecha * + * @param vItemFk Id del artículo * @param vWarehouseFk Id del almacén * @param vDated Compras hasta fecha * @return tmp.buyUltimate */ - CALL cache.last_buy_refresh (FALSE); - - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - CREATE TEMPORARY TABLE tmp.buyUltimate - (PRIMARY KEY (itemFk, warehouseFk), - INDEX(itemFk)) - ENGINE = MEMORY - SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing - FROM cache.last_buy - WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - - 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; - END IF; + CALL buy_getUltimate(NULL, vWarehouseFk, vDated); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index 5879b58e1..75dfff489 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -6,6 +6,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInte ) BEGIN /** + * DEPRECATED usar buy_getUltimateFromInterval * Calcula las últimas compras realizadas * desde un rango de fechas. * @@ -14,153 +15,6 @@ BEGIN * @param vEnded Fecha fin * @return tmp.buyUltimateFromInterval */ - IF vEnded IS NULL THEN - SET vEnded = vStarted; - END IF; - - IF vEnded < vStarted THEN - SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); - END IF; - - -- 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)) - ENGINE = MEMORY - 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.price2 > 0 - 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 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 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, - 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 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; + CALL vn.buy_getUltimateFromInterval (NULL,vWarehouseFk,vStarted,vEnded); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getUltimate.sql b/db/routines/vn/procedures/buy_getUltimate.sql new file mode 100644 index 000000000..36ae10fd8 --- /dev/null +++ b/db/routines/vn/procedures/buy_getUltimate.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimate`( + vItemFk INT, + vWarehouseFk SMALLINT, + vDated DATE +) +BEGIN +/** + * Calcula las últimas compras realizadas hasta una fecha + * + * @param vItemFk Id del artículo + * @param vWarehouseFk Id del almacén + * @param vDated Compras hasta fecha + * @return tmp.buyUltimate + */ + CALL cache.last_buy_refresh (FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; + CREATE TEMPORARY TABLE tmp.buyUltimate + (PRIMARY KEY (itemFk, warehouseFk), + INDEX(itemFk)) + ENGINE = MEMORY + SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing + FROM cache.last_buy + WHERE (warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL) + AND (item_id = vItemFk OR vItemFk IS NULL); + + IF vDated >= util.VN_CURDATE() THEN + CALL buyUltimateFromInterval(vItemFk, 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 (itemFk = vItemFk OR vItemFk 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 (itemFk = vItemFk OR vItemFk IS NULL) + AND landed > vDated + ORDER BY isIgnored = FALSE DESC; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getUltimateFromInterval .sql b/db/routines/vn/procedures/buy_getUltimateFromInterval .sql new file mode 100644 index 000000000..4dafd105f --- /dev/null +++ b/db/routines/vn/procedures/buy_getUltimateFromInterval .sql @@ -0,0 +1,174 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval `( + vItemFk INT, + vWarehouseFk SMALLINT, + vStarted DATE, + vEnded DATE +) +BEGIN +/** + * Calcula las últimas compras realizadas + * desde un rango de fechas. + * + * @param vItemFk Id del artículo + * @param vWarehouseFk Id del almacén si es NULL se actualizan todos + * @param vStarted Fecha inicial + * @param vEnded Fecha fin + * @return tmp.buyUltimateFromInterval + */ + IF vEnded IS NULL THEN + SET vEnded = vStarted; + END IF; + + IF vEnded < vStarted THEN + SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); + END IF; + + -- 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)) + ENGINE = MEMORY + 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.itemFk = vItemFk OR vItemFk IS NULL) + AND b.price2 > 0 + 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 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.itemFk = vItemFk OR vItemFk IS NULL) + 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 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.itemFk = vItemFk OR vItemFk IS NULL) + 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, + 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.itemFk = vItemFk OR vItemFk IS NULL) + 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.itemFk = vItemFk OR vItemFk IS NULL) + 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 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.itemFk = vItemFk OR vItemFk IS NULL) + 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/buy_updateGrouping.sql b/db/routines/vn/procedures/buy_updateGrouping.sql index fb7adc0a3..45a619262 100644 --- a/db/routines/vn/procedures/buy_updateGrouping.sql +++ b/db/routines/vn/procedures/buy_updateGrouping.sql @@ -8,7 +8,7 @@ BEGIN * @param vItemFk Id del Artículo * @param vGrouping Cantidad de grouping */ - CALL vn.buyUltimate(vWarehouseFk, util.VN_CURDATE()); + CALL vn.buy_getUltimate (vItemFk, vWarehouseFk, util.VN_CURDATE()); UPDATE vn.buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk diff --git a/db/routines/vn/procedures/buy_updatePacking.sql b/db/routines/vn/procedures/buy_updatePacking.sql index d86edc98f..0ee9d4c80 100644 --- a/db/routines/vn/procedures/buy_updatePacking.sql +++ b/db/routines/vn/procedures/buy_updatePacking.sql @@ -8,7 +8,7 @@ BEGIN * @param vItemFk id del item * @param vPacking packing a actualizar */ - CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); + CALL buy_getUltimate(vItemFk, vWarehouseFk, util.VN_CURDATE()); UPDATE buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql index 963e33507..887492b35 100644 --- a/db/routines/vn/procedures/catalog_calculate.sql +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -74,7 +74,7 @@ BEGIN CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped); CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped); - CALL vn.buyUltimate(vWarehouseFk, vShipped); + CALL vn.buy_getUltimate(NULL, vWarehouseFk, vShipped); INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk) SELECT vWarehouseFk, diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 165c87dc7..5bf049b6e 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -97,7 +97,7 @@ BEGIN FROM tmp.itemList; END IF; - CALL buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded); + CALL buy_getUltimateFromInterval(NULL, vWarehouseIn,vInventoryDate, vDateLanded); CREATE OR REPLACE TEMPORARY TABLE tTransfer ENGINE = MEMORY diff --git a/db/routines/vn/procedures/itemShelving_addByClaim.sql b/db/routines/vn/procedures/itemShelving_addByClaim.sql index 851162952..4ff2955c7 100644 --- a/db/routines/vn/procedures/itemShelving_addByClaim.sql +++ b/db/routines/vn/procedures/itemShelving_addByClaim.sql @@ -15,7 +15,7 @@ BEGIN JOIN ticket t ON t.id = c.ticketFk WHERE c.id = vClaimFk; - CALL buyUltimate (vWarehouseFk, util.VN_CURDATE()); + CALL buy_getUltimate(NULL, vWarehouseFk, util.VN_CURDATE()); INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible) SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible diff --git a/db/routines/vn/procedures/itemShelving_getItemDetails.sql b/db/routines/vn/procedures/itemShelving_getItemDetails.sql index c01bc348c..b097c2d17 100644 --- a/db/routines/vn/procedures/itemShelving_getItemDetails.sql +++ b/db/routines/vn/procedures/itemShelving_getItemDetails.sql @@ -23,7 +23,7 @@ BEGIN FROM operator WHERE workerFk = account.myUser_getId(); - CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); + CALL buy_getUltimate(vBarcodeItem, vWarehouseFk, util.VN_CURDATE()); SELECT buyFk INTO vBuyFk FROM tmp.buyUltimate diff --git a/db/routines/vn/procedures/item_devalueA2.sql b/db/routines/vn/procedures/item_devalueA2.sql index c9f716d8f..0cfcfcc7e 100644 --- a/db/routines/vn/procedures/item_devalueA2.sql +++ b/db/routines/vn/procedures/item_devalueA2.sql @@ -93,7 +93,7 @@ BEGIN ORDER BY created DESC LIMIT 1; - CALL buyUltimate(vWarehouseFk, vCurdate); + CALL buy_getUltimate(vSelf, vWarehouseFk, vCurdate); SELECT b.entryFk, bu.buyFk,IFNULL(b.buyingValue, 0) INTO vLastEntryFk, vLastBuyFk, vBuyingValueOriginal FROM tmp.buyUltimate bu diff --git a/db/routines/vn/procedures/item_getInfo.sql b/db/routines/vn/procedures/item_getInfo.sql index 50ab880a0..f569d235b 100644 --- a/db/routines/vn/procedures/item_getInfo.sql +++ b/db/routines/vn/procedures/item_getInfo.sql @@ -14,9 +14,11 @@ BEGIN CALL cache.visible_refresh(vCacheVisibleFk, FALSE, vWarehouseFk); CALL cache.available_refresh(vCacheAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); - + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + CALL buy_getUltimate(vItemFk, vWarehouseFk, util.VN_CURDATE()); + SELECT SUM(visible) INTO vVisibleItemShelving FROM itemShelvingStock WHERE itemFk = vItemFk diff --git a/db/routines/vn/procedures/item_multipleBuy.sql b/db/routines/vn/procedures/item_multipleBuy.sql index ba49f8d36..0a08f5015 100644 --- a/db/routines/vn/procedures/item_multipleBuy.sql +++ b/db/routines/vn/procedures/item_multipleBuy.sql @@ -13,7 +13,7 @@ BEGIN */ ALTER TABLE tmp.itemInventory ADD IF NOT EXISTS buy_id INT; - CALL buyUltimate(vWarehouseFk, vDate); + CALL buy_getUltimate (NULL, vWarehouseFk, vDate); CREATE OR REPLACE TEMPORARY TABLE tmp (KEY (itemFk)) diff --git a/db/routines/vn/procedures/item_valuateInventory.sql b/db/routines/vn/procedures/item_valuateInventory.sql index 18aefdf7b..71f1459eb 100644 --- a/db/routines/vn/procedures/item_valuateInventory.sql +++ b/db/routines/vn/procedures/item_valuateInventory.sql @@ -181,7 +181,7 @@ BEGIN AND e.isConfirmed ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity); - CALL buyUltimate(NULL, vDateDayEnd); + CALL buy_getUltimate (NULL, NULL, vDateDayEnd); DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity; diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql index ba4ff5857..64ecb898d 100644 --- a/db/routines/vn/procedures/sale_getProblems.sql +++ b/db/routines/vn/procedures/sale_getProblems.sql @@ -276,7 +276,7 @@ BEGIN ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; -- Redondeo: Cantidad pedida incorrecta en al grouping de la última compra - CALL buyUltimate(vWarehouseFk, vDate); + CALL buy_getUltimate(NULL, vWarehouseFk, vDate); INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk) SELECT ticketFk, problem ,saleFk FROM ( diff --git a/db/routines/vn/procedures/sale_recalcComponent.sql b/db/routines/vn/procedures/sale_recalcComponent.sql index 54297571a..f3c188404 100644 --- a/db/routines/vn/procedures/sale_recalcComponent.sql +++ b/db/routines/vn/procedures/sale_recalcComponent.sql @@ -78,7 +78,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.zoneGetLanded; -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); + CALL buy_getUltimate(NULL, vWarehouseFk, vShipped); CREATE OR REPLACE TEMPORARY TABLE tmp.sale (PRIMARY KEY (saleFk)) ENGINE = MEMORY diff --git a/db/routines/vn/procedures/sale_replaceItem.sql b/db/routines/vn/procedures/sale_replaceItem.sql index a4aefc088..573d5b488 100644 --- a/db/routines/vn/procedures/sale_replaceItem.sql +++ b/db/routines/vn/procedures/sale_replaceItem.sql @@ -53,7 +53,7 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk WHERE s.id = vSaleFk; - CALL buyUltimate(vWarehouseFk, vDate); + CALL buy_getUltimate(vNewItemFk, vWarehouseFk, vDate); SELECT `grouping`, groupingMode, packing INTO vGrouping,vGroupingMode,vPacking @@ -61,6 +61,8 @@ BEGIN JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk WHERE tmp.itemFk = vNewItemFk AND tmp.WarehouseFk = vWarehouseFk; + DROP TEMPORARY TABLE tmp.buyUltimate; + IF vGroupingMode = 'packing' AND vPacking > 0 THEN SET vRoundQuantity = vPacking; END IF; diff --git a/db/routines/vn/procedures/sale_setProblemRounding.sql b/db/routines/vn/procedures/sale_setProblemRounding.sql index f58d00799..894749c7b 100644 --- a/db/routines/vn/procedures/sale_setProblemRounding.sql +++ b/db/routines/vn/procedures/sale_setProblemRounding.sql @@ -19,7 +19,7 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk WHERE s.id = vSelf; - CALL buyUltimate(vWarehouseFk, vShipped); + CALL buy_getUltimate(vItemFk, vWarehouseFk, vShipped); CREATE OR REPLACE TEMPORARY TABLE tmp.sale SELECT vSelf saleFk, diff --git a/db/routines/vn/procedures/stockTraslation.sql b/db/routines/vn/procedures/stockTraslation.sql index c681112f1..f9175dc2a 100644 --- a/db/routines/vn/procedures/stockTraslation.sql +++ b/db/routines/vn/procedures/stockTraslation.sql @@ -36,6 +36,6 @@ BEGIN WHERE warehouse_id = vAuctionWarehouseFk ON DUPLICATE KEY UPDATE quantity = tmp.item.quantity + VALUES(quantity); - CALL buyUltimate(vAuctionWarehouseFk, vDated); + CALL buy_getUltimate(NULL, vAuctionWarehouseFk, vDated); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_componentPreview.sql b/db/routines/vn/procedures/ticket_componentPreview.sql index 729e3a743..4bcd8c8ec 100644 --- a/db/routines/vn/procedures/ticket_componentPreview.sql +++ b/db/routines/vn/procedures/ticket_componentPreview.sql @@ -56,13 +56,12 @@ BEGIN FROM zone WHERE id = vZoneFk; - CALL buyUltimate(vWarehouseFk, vShipped); + CALL buy_getUltimate(NULL, vWarehouseFk, vShipped); DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( - SELECT - vWarehouseFk AS warehouseFk, - NULL AS available, + SELECT vWarehouseFk warehouseFk, + NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk diff --git a/db/routines/vn/procedures/ticket_setProblemRounding.sql b/db/routines/vn/procedures/ticket_setProblemRounding.sql index fb580eacf..551cf67d1 100644 --- a/db/routines/vn/procedures/ticket_setProblemRounding.sql +++ b/db/routines/vn/procedures/ticket_setProblemRounding.sql @@ -16,7 +16,7 @@ BEGIN FROM ticket WHERE id = vSelf; - CALL buyUltimate(vWarehouseFk, vDated); + CALL buy_getUltimate(NULL, vWarehouseFk, vDated); CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk, isProblemCalcNeeded)) diff --git a/modules/entry/back/methods/entry/addFromBuy.js b/modules/entry/back/methods/entry/addFromBuy.js index e5cc427a8..212aed7ea 100644 --- a/modules/entry/back/methods/entry/addFromBuy.js +++ b/modules/entry/back/methods/entry/addFromBuy.js @@ -52,8 +52,8 @@ module.exports = Self => { else { const userConfig = await models.UserConfig.findById(userId, {fields: ['warehouseFk']}, myOptions); await Self.rawSql( - 'CALL vn.buyUltimate(?,?)', - [userConfig.warehouseFk, null], + 'CALL vn.buy_getUltimate(?,?,?)', + [args.item, userConfig.warehouseFk, null], myOptions ); let buyUltimate = await Self.rawSql( diff --git a/modules/entry/back/methods/entry/importBuys.js b/modules/entry/back/methods/entry/importBuys.js index 812775a1b..e3fd653bb 100644 --- a/modules/entry/back/methods/entry/importBuys.js +++ b/modules/entry/back/methods/entry/importBuys.js @@ -73,7 +73,8 @@ module.exports = Self => { }, myOptions); const travel = entry.travel(); - await Self.rawSql('CALL buyUltimate(?, ?)', [ + await Self.rawSql('CALL buy_getUltimate(?, ?, ?)', [ + null, travel.warehouseInFk, travel.landed ], myOptions); diff --git a/modules/entry/back/methods/entry/lastItemBuys.js b/modules/entry/back/methods/entry/lastItemBuys.js index 63e6d38f2..012b99d17 100644 --- a/modules/entry/back/methods/entry/lastItemBuys.js +++ b/modules/entry/back/methods/entry/lastItemBuys.js @@ -50,7 +50,8 @@ module.exports = Self => { const stmts = []; let stmt; - stmt = new ParameterizedSQL(`CALL buyUltimate(?, ?)`, [ + stmt = new ParameterizedSQL(`CALL buy_getUltimate(?, ?, ?)`, [ + null, travel.warehouseInFk, travel.landed ]); diff --git a/modules/order/back/methods/order/getItemTypeAvailable.js b/modules/order/back/methods/order/getItemTypeAvailable.js index b84863953..fd7be5d57 100644 --- a/modules/order/back/methods/order/getItemTypeAvailable.js +++ b/modules/order/back/methods/order/getItemTypeAvailable.js @@ -44,16 +44,14 @@ module.exports = Self => { ]); stmts.push(stmt); - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.item'); - stmt = new ParameterizedSQL( - `CREATE TEMPORARY TABLE tmp.item + `CREATE OR REPLACE TEMPORARY TABLE tmp.item (PRIMARY KEY (itemFk)) ENGINE = MEMORY SELECT DISTINCT - i.id AS itemFk, - it.id AS typeFk, + i.id itemFk, + it.id typeFk, it.name, - ic.name AS categoryName + ic.name categoryName FROM tmp.availableCalc ac JOIN cache.available a ON a.calc_id = ac.calcFk JOIN vn.item i ON i.id = a.item_id @@ -64,7 +62,7 @@ module.exports = Self => { stmts.push(stmt); stmt = new ParameterizedSQL( - 'CALL vn.catalog_calculate(?, ?, ?,?)', [ + 'CALL vn.catalog_calculate(?, ?, ?, ?)', [ order.landed, order.addressFk, order.agencyModeFk, @@ -74,7 +72,7 @@ module.exports = Self => { stmts.push(stmt); stmt = new ParameterizedSQL(` - SELECT i.typeFk AS id, i.name, i.categoryName + SELECT i.typeFk id, i.name, i.categoryName FROM tmp.item i JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.itemFk GROUP BY i.typeFk` @@ -85,7 +83,6 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const result = await Self.rawStmt(sql, myOptions); - return result[categoriesIndex]; }; }; From d6a949a9f38f22bfd2487bf93b246e9e7527f687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Jul 2024 18:55:58 +0200 Subject: [PATCH 03/26] feat: refactor buyUltimate refs #7736 --- .../cache/procedures/last_buy_refresh.sql | 2 +- .../vn/procedures/buyUltimateFromInterval.sql | 2 +- .../buy_getUltimateFromInterval .sql | 174 ------------------ 3 files changed, 2 insertions(+), 176 deletions(-) delete mode 100644 db/routines/vn/procedures/buy_getUltimateFromInterval .sql diff --git a/db/routines/cache/procedures/last_buy_refresh.sql b/db/routines/cache/procedures/last_buy_refresh.sql index 0f80163fb..555ae0b8d 100644 --- a/db/routines/cache/procedures/last_buy_refresh.sql +++ b/db/routines/cache/procedures/last_buy_refresh.sql @@ -30,7 +30,7 @@ proc: BEGIN SELECT inventoried INTO started FROM vn.config LIMIT 1; SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE()); - CALL vn.buy_getUltimateFromInterval (NULL, NULL, started, ended); + CALL vn.buy_getUltimateFromInterval(NULL, NULL, started, ended); DELETE FROM last_buy; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index 75dfff489..8aea38ee0 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -15,6 +15,6 @@ BEGIN * @param vEnded Fecha fin * @return tmp.buyUltimateFromInterval */ - CALL vn.buy_getUltimateFromInterval (NULL,vWarehouseFk,vStarted,vEnded); + CALL vn.buy_getUltimateFromInterval(NULL,vWarehouseFk,vStarted,vEnded); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getUltimateFromInterval .sql b/db/routines/vn/procedures/buy_getUltimateFromInterval .sql deleted file mode 100644 index 4dafd105f..000000000 --- a/db/routines/vn/procedures/buy_getUltimateFromInterval .sql +++ /dev/null @@ -1,174 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval `( - vItemFk INT, - vWarehouseFk SMALLINT, - vStarted DATE, - vEnded DATE -) -BEGIN -/** - * Calcula las últimas compras realizadas - * desde un rango de fechas. - * - * @param vItemFk Id del artículo - * @param vWarehouseFk Id del almacén si es NULL se actualizan todos - * @param vStarted Fecha inicial - * @param vEnded Fecha fin - * @return tmp.buyUltimateFromInterval - */ - IF vEnded IS NULL THEN - SET vEnded = vStarted; - END IF; - - IF vEnded < vStarted THEN - SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); - END IF; - - -- 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)) - ENGINE = MEMORY - 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.itemFk = vItemFk OR vItemFk IS NULL) - AND b.price2 > 0 - 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 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.itemFk = vItemFk OR vItemFk IS NULL) - 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 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.itemFk = vItemFk OR vItemFk IS NULL) - 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, - 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.itemFk = vItemFk OR vItemFk IS NULL) - 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.itemFk = vItemFk OR vItemFk IS NULL) - 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 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.itemFk = vItemFk OR vItemFk IS NULL) - AND b.quantity = 0 - AND itemOriginalFk - ORDER BY t.landed DESC, b.id DESC - LIMIT 10000000000000000000) sub - GROUP BY itemFk, warehouseFk; -END$$ -DELIMITER ; From 50e2c03d3e1a2caac3643d49ad2cf220c5050a04 Mon Sep 17 00:00:00 2001 From: ivanm Date: Tue, 16 Jul 2024 18:56:00 +0200 Subject: [PATCH 04/26] refs #7531 Requested modifications in redmine --- .../vn/procedures/zone_getAddresses.sql | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index c3a21aa83..417b8c7a3 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -1,40 +1,28 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( vSelf INT, - vDated DATE, - vDepartment INT + vShipped DATE, + vDepartmentFk INT ) BEGIN /** * Devuelve un listado de todos los clientes activos * con consignatarios a los que se les puede - * vender producto para esa zona y no tiene un ticket - * para ese día. + * vender producto para esa zona. * * @param vSelf Id de zona - * @param vDated Fecha de entrega - * @param vDepartment Departamento del trabajador + * @param vShipped Fecha de envio + * @param vDepartmentFk Id de departamento * @return Un select */ CALL zone_getPostalCode(vSelf); - WITH notHasTicket AS ( - SELECT id - FROM vn.client - WHERE id NOT IN ( - SELECT clientFk - FROM vn.ticket - WHERE landed BETWEEN vDated AND util.dayEnd(vDated) - ) - ), - hasTicketShippedToday AS ( - SELECT clientFk, - IF (COUNT(*) > 0, TRUE, FALSE) hasTicketShipped + WITH clientWithTicket AS ( + SELECT clientFk FROM vn.ticket - WHERE shipped BETWEEN vDated AND util.dayEnd(vDated) - GROUP BY clientFk + WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped) ) - SELECT c.id clientFk, + SELECT c.id, c.name, c.phone, bt.description, @@ -42,12 +30,12 @@ BEGIN u.name username, aai.invoiced, cnb.lastShipped, - ht.hasTicketShipped + cwt.clientFk FROM vn.client c JOIN vn.worker w ON w.id = c.salesPersonFk JOIN vn.workerDepartment wd ON wd.workerFk = w.id JOIN vn.department d ON d.id = wd.departmentFk - JOIN notHasTicket ON notHasTicket.id = c.id + LEFT JOIN clientWithTicket cwt ON cwt.clientFk = c.id LEFT JOIN account.`user` u ON u.id = c.salesPersonFk JOIN vn.`address` a ON a.clientFk = c.id JOIN vn.postCode pc ON pc.code = a.postalCode @@ -58,12 +46,11 @@ BEGIN LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id JOIN vn.clientType ct ON ct.code = c.typeFk JOIN vn.businessType bt ON bt.code = c.businessTypeFk - LEFT JOIN hasTicketShippedToday ht ON ht.clientFk = c.id WHERE a.isActive AND c.isActive AND ct.code = 'normal' AND bt.code <> 'worker' - AND d.id = vDepartment + AND d.id = vDepartmentFk GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From 5ca2a432daece8d1013b7c0737a50f3c859f4472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Jul 2024 18:58:26 +0200 Subject: [PATCH 05/26] feat: refactor buyUltimate refs #7736 --- .../buy_getUltimateFromInterval.sql | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 db/routines/vn/procedures/buy_getUltimateFromInterval.sql diff --git a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql new file mode 100644 index 000000000..45d1122ae --- /dev/null +++ b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql @@ -0,0 +1,174 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval`( + vItemFk INT, + vWarehouseFk SMALLINT, + vStarted DATE, + vEnded DATE +) +BEGIN +/** + * Calcula las últimas compras realizadas + * desde un rango de fechas. + * + * @param vItemFk Id del artículo + * @param vWarehouseFk Id del almacén si es NULL se actualizan todos + * @param vStarted Fecha inicial + * @param vEnded Fecha fin + * @return tmp.buyUltimateFromInterval + */ + IF vEnded IS NULL THEN + SET vEnded = vStarted; + END IF; + + IF vEnded < vStarted THEN + SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); + END IF; + + -- 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)) + ENGINE = MEMORY + 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.itemFk = vItemFk OR vItemFk IS NULL) + AND b.price2 > 0 + 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 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.itemFk = vItemFk OR vItemFk IS NULL) + 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 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.itemFk = vItemFk OR vItemFk IS NULL) + 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, + 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.itemFk = vItemFk OR vItemFk IS NULL) + 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.itemFk = vItemFk OR vItemFk IS NULL) + 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 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.itemFk = vItemFk OR vItemFk IS NULL) + AND b.quantity = 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; +END$$ +DELIMITER ; From 4ee0bd687fb040f2cc9fae0a9594be4c268fdbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Jul 2024 19:01:02 +0200 Subject: [PATCH 06/26] feat: refactor buyUltimate refs #7736 --- db/routines/vn/procedures/buyUltimateFromInterval.sql | 2 +- db/routines/vn/procedures/buy_getUltimate.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index 8aea38ee0..9709f2edc 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -15,6 +15,6 @@ BEGIN * @param vEnded Fecha fin * @return tmp.buyUltimateFromInterval */ - CALL vn.buy_getUltimateFromInterval(NULL,vWarehouseFk,vStarted,vEnded); + CALL vn.buy_getUltimateFromInterval(NULL, vWarehouseFk, vStarted, vEnded); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getUltimate.sql b/db/routines/vn/procedures/buy_getUltimate.sql index 36ae10fd8..d16f89295 100644 --- a/db/routines/vn/procedures/buy_getUltimate.sql +++ b/db/routines/vn/procedures/buy_getUltimate.sql @@ -26,7 +26,7 @@ BEGIN AND (item_id = vItemFk OR vItemFk IS NULL); IF vDated >= util.VN_CURDATE() THEN - CALL buyUltimateFromInterval(vItemFk, vWarehouseFk, util.VN_CURDATE(), vDated); + CALL buy_getUltimateFromInterval(vItemFk, vWarehouseFk, util.VN_CURDATE(), vDated); REPLACE INTO tmp.buyUltimate SELECT itemFk, buyFk, warehouseFk, landed landing From a6e6f435f75a976cf517c5e11d7ef1a0a32d6ab2 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 18 Jul 2024 15:21:59 +0200 Subject: [PATCH 07/26] refs #7531 No assigned department --- db/routines/vn/procedures/zone_getAddresses.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 417b8c7a3..0622ece1b 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -50,7 +50,7 @@ BEGIN AND c.isActive AND ct.code = 'normal' AND bt.code <> 'worker' - AND d.id = vDepartmentFk + AND (d.id = vDepartmentFk OR NOT vDepartmentFk) GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; From b2a8326170594eca7aff3f5127516ee97cfa399a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 19 Jul 2024 12:44:45 +0200 Subject: [PATCH 08/26] feat: refactor buyUltimate refs #7736 --- db/routines/vn/procedures/buyUltimateFromInterval.sql | 2 +- db/routines/vn/procedures/buy_getUltimate.sql | 2 +- db/routines/vn/procedures/buy_getUltimateFromInterval.sql | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index 9709f2edc..acb6282de 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -6,7 +6,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInte ) BEGIN /** - * DEPRECATED usar buy_getUltimateFromInterval + * @deprecated Usar buy_getUltimateFromInterval * Calcula las últimas compras realizadas * desde un rango de fechas. * diff --git a/db/routines/vn/procedures/buy_getUltimate.sql b/db/routines/vn/procedures/buy_getUltimate.sql index d16f89295..164fb3266 100644 --- a/db/routines/vn/procedures/buy_getUltimate.sql +++ b/db/routines/vn/procedures/buy_getUltimate.sql @@ -13,7 +13,7 @@ BEGIN * @param vDated Compras hasta fecha * @return tmp.buyUltimate */ - CALL cache.last_buy_refresh (FALSE); + CALL cache.last_buy_refresh(FALSE); DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; CREATE TEMPORARY TABLE tmp.buyUltimate diff --git a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql index 45d1122ae..df0d6a20e 100644 --- a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql @@ -25,8 +25,8 @@ BEGIN END IF; -- Item - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; - CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval + + CREATE OR REPLACE TEMPORARY TABLE tmp.buyUltimateFromInterval (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) ENGINE = MEMORY @@ -97,7 +97,8 @@ BEGIN LIMIT 10000000000000000000) sub GROUP BY itemFk, warehouseFk; - -- ItemOriginal + -- ItemOriginal + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT itemFk, warehouseFk, From 55ea761af4e9f0419712a01c841f0313d466338a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 19 Jul 2024 15:11:14 +0200 Subject: [PATCH 09/26] eat: refactor buyUltimate refs #7736 --- db/routines/vn/procedures/buy_getUltimate.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/buy_getUltimate.sql b/db/routines/vn/procedures/buy_getUltimate.sql index 164fb3266..66e92c50e 100644 --- a/db/routines/vn/procedures/buy_getUltimate.sql +++ b/db/routines/vn/procedures/buy_getUltimate.sql @@ -6,7 +6,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimate`( ) BEGIN /** - * Calcula las últimas compras realizadas hasta una fecha + * Calcula las últimas compras realizadas hasta una fecha. * * @param vItemFk Id del artículo * @param vWarehouseFk Id del almacén From d7b9a3ffd02a0571d7f3a014a33425e1c0827082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 22 Jul 2024 11:58:51 +0200 Subject: [PATCH 10/26] feat: refactor buyUltimate refs #7736 --- db/routines/vn/procedures/buy_getUltimate.sql | 3 +-- .../vn/procedures/buy_getUltimateFromInterval.sql | 2 +- db/routines/vn/procedures/buy_updateGrouping.sql | 10 +++++++--- db/routines/vn/procedures/catalog_calculate.sql | 2 +- db/routines/vn/procedures/item_getInfo.sql | 15 +++++++++------ modules/entry/back/methods/entry/addFromBuy.js | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/buy_getUltimate.sql b/db/routines/vn/procedures/buy_getUltimate.sql index 66e92c50e..023e81774 100644 --- a/db/routines/vn/procedures/buy_getUltimate.sql +++ b/db/routines/vn/procedures/buy_getUltimate.sql @@ -15,8 +15,7 @@ BEGIN */ CALL cache.last_buy_refresh(FALSE); - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - CREATE TEMPORARY TABLE tmp.buyUltimate + CREATE OR REPLACE TEMPORARY TABLE tmp.buyUltimate (PRIMARY KEY (itemFk, warehouseFk), INDEX(itemFk)) ENGINE = MEMORY diff --git a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql index df0d6a20e..c340686ba 100644 --- a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql @@ -21,7 +21,7 @@ BEGIN END IF; IF vEnded < vStarted THEN - SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); + SET vStarted = vEnded - INTERVAL 1 MONTH; END IF; -- Item diff --git a/db/routines/vn/procedures/buy_updateGrouping.sql b/db/routines/vn/procedures/buy_updateGrouping.sql index 45a619262..0d97fd8bf 100644 --- a/db/routines/vn/procedures/buy_updateGrouping.sql +++ b/db/routines/vn/procedures/buy_updateGrouping.sql @@ -1,5 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_updateGrouping`(vWarehouseFk INT, vItemFk INT, vGrouping INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_updateGrouping`( + vWarehouseFk INT, + vItemFk INT, + vGrouping INT +) BEGIN /** * Actualiza el grouping de las últimas compras de un artículo @@ -8,9 +12,9 @@ BEGIN * @param vItemFk Id del Artículo * @param vGrouping Cantidad de grouping */ - CALL vn.buy_getUltimate (vItemFk, vWarehouseFk, util.VN_CURDATE()); + CALL buy_getUltimate (vItemFk, vWarehouseFk, util.VN_CURDATE()); - UPDATE vn.buy b + UPDATE buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk SET b.`grouping` = vGrouping WHERE bu.warehouseFk = vWarehouseFk diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql index 887492b35..6c4affa9d 100644 --- a/db/routines/vn/procedures/catalog_calculate.sql +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -74,7 +74,7 @@ BEGIN CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped); CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped); - CALL vn.buy_getUltimate(NULL, vWarehouseFk, vShipped); + CALL buy_getUltimate(NULL, vWarehouseFk, vShipped); INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk) SELECT vWarehouseFk, diff --git a/db/routines/vn/procedures/item_getInfo.sql b/db/routines/vn/procedures/item_getInfo.sql index f569d235b..5cd4fb31e 100644 --- a/db/routines/vn/procedures/item_getInfo.sql +++ b/db/routines/vn/procedures/item_getInfo.sql @@ -1,5 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getInfo`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getInfo`( + `vBarcode` VARCHAR(22), + `vWarehouseFk` INT +) BEGIN /** * Devuelve información relativa al item correspondiente del vBarcode pasado @@ -11,13 +14,13 @@ BEGIN DECLARE vCacheAvailableFk INT; DECLARE vVisibleItemShelving INT; DECLARE vItemFk INT; + DECLARE vDated DATE; + + SELECT barcodeToItem(vBarcode), util.VN_CURDATE() INTO vItemFk, vDated; CALL cache.visible_refresh(vCacheVisibleFk, FALSE, vWarehouseFk); - CALL cache.available_refresh(vCacheAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - - SELECT barcodeToItem(vBarcode) INTO vItemFk; - - CALL buy_getUltimate(vItemFk, vWarehouseFk, util.VN_CURDATE()); + CALL cache.available_refresh(vCacheAvailableFk, FALSE, vWarehouseFk, vDated); + CALL buy_getUltimate(vItemFk, vWarehouseFk, vDated); SELECT SUM(visible) INTO vVisibleItemShelving FROM itemShelvingStock diff --git a/modules/entry/back/methods/entry/addFromBuy.js b/modules/entry/back/methods/entry/addFromBuy.js index 212aed7ea..c75c1935a 100644 --- a/modules/entry/back/methods/entry/addFromBuy.js +++ b/modules/entry/back/methods/entry/addFromBuy.js @@ -52,7 +52,7 @@ module.exports = Self => { else { const userConfig = await models.UserConfig.findById(userId, {fields: ['warehouseFk']}, myOptions); await Self.rawSql( - 'CALL vn.buy_getUltimate(?,?,?)', + 'CALL buy_getUltimate(?, ?, ?)', [args.item, userConfig.warehouseFk, null], myOptions ); From b086cc7658772b58c4ffd6fea4d6a7935c3a92c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 22 Jul 2024 13:34:04 +0200 Subject: [PATCH 11/26] feat: refactor buyUltimate refs #7736 --- .../buy_getUltimateFromInterval.sql | 12 ++++---- .../vn/procedures/catalog_calculate.sql | 30 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql index c340686ba..2115beb95 100644 --- a/db/routines/vn/procedures/buy_getUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buy_getUltimateFromInterval.sql @@ -115,12 +115,12 @@ BEGIN 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.itemFk = vItemFk OR vItemFk IS NULL) - AND b.price2 > 0 - AND NOT b.isIgnored - AND b.quantity > 0 - AND itemOriginalFk + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND (b.itemFk = vItemFk OR vItemFk IS NULL) + 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; diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql index 6c4affa9d..8432e8dea 100644 --- a/db/routines/vn/procedures/catalog_calculate.sql +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -29,7 +29,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, vShowExpiredZones); + CALL zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, vShowExpiredZones); DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; CREATE TEMPORARY TABLE tmp.ticketLot( @@ -86,17 +86,17 @@ BEGIN LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id AND anr.calc_id = vAvailableNoRaidsCalc JOIN tmp.item i ON i.itemFk = a.item_id - JOIN vn.item it ON it.id = i.itemFk - JOIN vn.`zone` z ON z.id = vZoneFk + JOIN item it ON it.id = i.itemFk + JOIN `zone` z ON z.id = vZoneFk LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID LEFT JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed - FROM vn.addressFilter af + FROM addressFilter af JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed - FROM vn.address ad - JOIN vn.province p ON p.id = ad.provinceFk + FROM address ad + JOIN province p ON p.id = ad.provinceFk WHERE ad.id = vAddressFk ) sub2 ON sub2.provinceFk <=> IFNULL(af.provinceFk, sub2.provinceFk) AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk) @@ -108,18 +108,18 @@ BEGIN OR ISNULL(af.afterDated)) ) sub ON sub.isVNHSupplier = v.isVNHSupplier AND (sub.isEarlyBird = mp.isEarlyBird OR ISNULL(sub.isEarlyBird)) - JOIN vn.agencyMode am ON am.id = vAgencyModeFk - JOIN vn.agency ag ON ag.id = am.agencyFk - JOIN vn.itemType itt ON itt.id = it.typeFk - JOIN vn.itemCategory itc on itc.id = itt.categoryFk - JOIN vn.address ad ON ad.id = vAddressFk - LEFT JOIN vn.clientItemType cit + JOIN agencyMode am ON am.id = vAgencyModeFk + JOIN agency ag ON ag.id = am.agencyFk + JOIN itemType itt ON itt.id = it.typeFk + JOIN itemCategory itc on itc.id = itt.categoryFk + JOIN address ad ON ad.id = vAddressFk + LEFT JOIN clientItemType cit ON cit.clientFk = ad.clientFk AND cit.itemTypeFk = itt.id - LEFT JOIN vn.zoneItemType zit + LEFT JOIN zoneItemType zit ON zit.zoneFk = vZoneFk AND zit.itemTypeFk = itt.id - LEFT JOIN vn.agencyModeItemType ait + LEFT JOIN agencyModeItemType ait ON ait.agencyModeFk = vAgencyModeFk AND ait.itemTypeFk = itt.id WHERE a.calc_id = vAvailableCalc @@ -133,7 +133,7 @@ BEGIN DROP TEMPORARY TABLE tmp.buyUltimate; - CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); INSERT INTO tmp.ticketCalculateItem( itemFk, From 33a71867bda9cd58ce2297d7a73fe051391949ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 22 Jul 2024 13:39:48 +0200 Subject: [PATCH 12/26] feat: refactor buyUltimate refs #7736 --- db/routines/vn/procedures/buyUltimate.sql | 4 ++-- db/routines/vn/procedures/buy_updateGrouping.sql | 2 +- db/routines/vn/procedures/catalog_calculate.sql | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql index 7026c8c82..e743b8c90 100644 --- a/db/routines/vn/procedures/buyUltimate.sql +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -5,8 +5,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`( ) BEGIN /** - * DEPRECATED usar buy_getUltimate - * Calcula las últimas compras realizadas hasta una fecha + * @deprecated Usar buy_getUltimate + * Calcula las últimas compras realizadas hasta una fecha. * * @param vItemFk Id del artículo * @param vWarehouseFk Id del almacén diff --git a/db/routines/vn/procedures/buy_updateGrouping.sql b/db/routines/vn/procedures/buy_updateGrouping.sql index 0d97fd8bf..e589fbd2a 100644 --- a/db/routines/vn/procedures/buy_updateGrouping.sql +++ b/db/routines/vn/procedures/buy_updateGrouping.sql @@ -12,7 +12,7 @@ BEGIN * @param vItemFk Id del Artículo * @param vGrouping Cantidad de grouping */ - CALL buy_getUltimate (vItemFk, vWarehouseFk, util.VN_CURDATE()); + CALL buy_getUltimate(vItemFk, vWarehouseFk, util.VN_CURDATE()); UPDATE buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql index 8432e8dea..2a0157881 100644 --- a/db/routines/vn/procedures/catalog_calculate.sql +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -72,8 +72,8 @@ BEGIN LEAVE l; END IF; - CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped); - CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped); + CALL `cache`.available_refresh(vAvailableCalc, FALSE, vWarehouseFk, vShipped); + CALL `cache`.availableNoRaids_refresh(vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped); CALL buy_getUltimate(NULL, vWarehouseFk, vShipped); INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk) From 5264d6c9739afe1e66524ff216075f809daba008 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 Jul 2024 10:35:01 +0200 Subject: [PATCH 13/26] feat(postcode_town): refs #7679 add requireds --- back/models/postcode.json | 5 +++-- back/models/town.json | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/back/models/postcode.json b/back/models/postcode.json index eadc2c86c..bad6be5d7 100644 --- a/back/models/postcode.json +++ b/back/models/postcode.json @@ -9,7 +9,8 @@ "properties": { "code": { "id": true, - "type": "string" + "type": "string", + "required": true } }, "relations": { @@ -47,4 +48,4 @@ } } } -} \ No newline at end of file +} diff --git a/back/models/town.json b/back/models/town.json index 4ad729791..e5d39314b 100644 --- a/back/models/town.json +++ b/back/models/town.json @@ -12,7 +12,8 @@ "type": "number" }, "name": { - "type": "string" + "type": "string", + "required": true } }, "relations": { @@ -54,4 +55,4 @@ "fields": ["id", "name", "provinceFk"] } } -} \ No newline at end of file +} From 254cced550a5a417e840fe844ac46250ba319ecd Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 29 Jul 2024 13:40:30 +0200 Subject: [PATCH 14/26] chore: refs #6989 add config model --- back/model-config.json | 3 +++ back/models/config.json | 22 +++++++++++++++++++ db/routines/vn/procedures/item_getBalance.sql | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 back/models/config.json diff --git a/back/model-config.json b/back/model-config.json index a16fe4e8a..13c06ef54 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -28,6 +28,9 @@ "Company": { "dataSource": "vn" }, + "Config": { + "dataSource": "vn" + }, "Continent": { "dataSource": "vn" }, diff --git a/back/models/config.json b/back/models/config.json new file mode 100644 index 000000000..e5ba1f134 --- /dev/null +++ b/back/models/config.json @@ -0,0 +1,22 @@ +{ + "name": "Config", + "base": "VnModel", + "options": { + "mysql": { + "table": "config" + } + }, + "properties": { + "inventoried": { + "type": "date" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$authenticated", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 0de59b478..3a594c81c 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -240,7 +240,7 @@ BEGIN NULL reference, NULL entityType, NULL entityId, - 'Inventario calculado', + 'Inventario calculado' entityName, @a invalue, NULL `out`, @a balance, From 434dfe4ae45740e8d60f603eeae7941231c9632e Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 Jul 2024 15:03:40 +0200 Subject: [PATCH 15/26] fix: refs #7679 postcode filter --- back/methods/postcode/filter.js | 36 +++++++++++++++------------------ loopback/locale/en.json | 4 +++- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 8b0f64d97..fc7905215 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -11,13 +11,11 @@ module.exports = Self => { arg: 'filter', type: 'object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} }, { arg: 'search', type: 'string', description: 'Value to filter', - http: {source: 'query'} }, ], returns: { @@ -29,13 +27,11 @@ module.exports = Self => { verb: 'GET', }, }); - Self.filter = async(ctx, filter, options) => { + Self.filter = async(filter = {}, search, options) => { const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - filter = ctx?.filter ?? {}; - const conn = Self.dataSource.connector; const where = buildFilter(filter?.where, (param, value) => { switch (param) { @@ -50,27 +46,27 @@ module.exports = Self => { }; } }) ?? {}; - delete ctx.filter.where; + delete filter.where; const stmts = []; let stmt; stmt = new ParameterizedSQL(` - SELECT - pc.townFk, - t.provinceFk, - p.countryFk, - pc.code, - t.name as town, - p.name as province, - c.name country - FROM - postCode pc - JOIN town t on t.id = pc.townFk - JOIN province p on p.id = t.provinceFk - JOIN country c on c.id = p.countryFk + SELECT + pc.townFk, + t.provinceFk, + p.countryFk, + pc.code, + t.name as town, + p.name as province, + c.name country + FROM + postCode pc + JOIN town t on t.id = pc.townFk + JOIN province p on p.id = t.provinceFk + JOIN country c on c.id = p.countryFk `); - stmt.merge(conn.makeSuffix({where, ...ctx})); + stmt.merge(conn.makeSuffix({where})); const itemsIndex = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 382a2824c..06538a524 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -233,5 +233,7 @@ "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", - "Cannot send mail": "Cannot send mail" + "Cannot send mail": "Cannot send mail", + "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", + "This postcode already exists": "This postcode already exists" } \ No newline at end of file From 6c1de1d6bd85802bcd2ed273fc1a489831d6c1fe Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 30 Jul 2024 07:55:14 +0200 Subject: [PATCH 16/26] refs #7801 frenchGoLabel --- .../email/printer-setup/locale/fr.yml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 print/templates/email/printer-setup/locale/fr.yml diff --git a/print/templates/email/printer-setup/locale/fr.yml b/print/templates/email/printer-setup/locale/fr.yml new file mode 100644 index 000000000..0c9f7031a --- /dev/null +++ b/print/templates/email/printer-setup/locale/fr.yml @@ -0,0 +1,39 @@ +subject: Instalation et configuration de l'imprimante +title: "Merci pour votre confiance !" +description: + dear: Cher client + instructions: Veuillez suivre les instructions spécifiées dans cet e-mail pour procéder à l'installation de l'imprimante. + followGuide: Vous pouvez utiliser comme guide la vidéo du montage du ruban et de la bande. + https://www.youtube.com/watch?v=qhb0kgQF3o8. Vous + aurez également besoin de GoLabel, le programme pour imprimer les bandes. + downloadFrom: Vous pouvez le télécharger depuis ce lien. https://cdn.verdnatura.es/public/GoLabel.zip + downloadDriver: Vous pouvez télécharger le pilote de l'imprimante depuis ce lien. https://es.seagullscientific.com/support/downloads/drivers/godex/download/ +sections: + GoLabel: + title: Utilisation de GoLabel + description: Pour utiliser le programme d'impression des bandes, suivez ces étapes + steps: + - Ci-joint à cet e-mail, vous trouverez le fichier 'model.ezp' (le modèle de bandes de corona standard). Téléchargez-le et vous le trouverez probablement dans le dossier 'Téléchargements'. + - Ouvrez le programme GoLabel. + - Cliquez sur l'icône de la barre supérieure en forme de dossier avec une feuille. + - Sélectionnez le fichier nommé 'model.ezp' (qui se trouve probablement dans 'Téléchargements'), puis cliquez sur Ouvrir. + - Une fois le fichier ouvert, double-cliquez sur le texte. Dans la boîte qui s'ouvre, cliquez sur le texte d'exemple (dans ce cas "TUS HERMANOS") et il apparaîtra dans la même zone à gauche pour que vous puissiez l'éditer et écrire ce que vous souhaitez. + - Lorsque vous avez le texte souhaité, cliquez sur le bouton 'OK'. + - Allez dans 'Fichier' → 'Enregistrer sous' et enregistrez-le sur le bureau sous un autre nom. + - Ensuite, pour imprimer, vous devez d'abord configurer l'imprimante. + - Cliquez sur la huitième icône de la barre supérieure, qui sera ici une imprimante avec un engrenage orange. + - Une fois là, cliquez sur le menu déroulant du modèle d'imprimante et choisissez le modèle qui correspond au vôtre 'G***'. + - Cliquez sur 'Enregistrer' et notre imprimante sera configurée et prête. + - Et enfin, pour imprimer, cliquez sur la neuvième icône, qui correspond à une imprimante bleue. + help: + title: "Avez-vous besoin d'aide ?" + description: Si vous avez besoin d'aide, téléchargez notre programme de support afin que nous puissions nous connecter à distance à votre ordinateur et effectuer l'installation. Veuillez nous fournir un horaire de contact pour vous assister, et nous vous contacterons. + remoteSupport: Vous pouvez télécharger le programme depuis ce lien. http://soporte.verdnatura.es. +help: Pour toute question que vous pourriez avoir, n'hésitez pas à nous la poser. Nous sommes là pour vous aider ! +salesPersonName: Je suis votre commercial et mon nom est +salesPersonPhone: Téléphone et WhatsApp. +salesPersonEmail: Adresse e-mail. From fcd26784bfb60dae6fcbf44677beae279acad9fc Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 Jul 2024 08:37:35 +0200 Subject: [PATCH 17/26] build: init version 2434 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9016f74a6..261b877dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.32.0", + "version": "24.34.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From dbe0f4497c880fafde27066d5ba70991b59c381f Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 Jul 2024 08:59:03 +0200 Subject: [PATCH 18/26] fix(postcode_filter): add limit --- back/methods/postcode/filter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index fc7905215..37cc0c148 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -67,10 +67,12 @@ module.exports = Self => { `); stmt.merge(conn.makeSuffix({where})); + stmt.merge(conn.makeLimit(filter)); const itemsIndex = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); + return itemsIndex === 0 ? result : result[itemsIndex]; }; }; From 2ac8760061506f713e5e4fbde9e9f0bfb6e86560 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 Jul 2024 10:13:32 +0200 Subject: [PATCH 19/26] test: fix postcode filter back test --- back/methods/postcode/filter.js | 7 +-- back/methods/postcode/specs/filter.spec.js | 57 ++++++++-------------- 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 37cc0c148..f350b1ea9 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -12,11 +12,6 @@ module.exports = Self => { type: 'object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', }, - { - arg: 'search', - type: 'string', - description: 'Value to filter', - }, ], returns: { type: ['object'], @@ -27,7 +22,7 @@ module.exports = Self => { verb: 'GET', }, }); - Self.filter = async(filter = {}, search, options) => { + Self.filter = async(filter = {}, options) => { const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); diff --git a/back/methods/postcode/specs/filter.spec.js b/back/methods/postcode/specs/filter.spec.js index 60ac24809..391b1e196 100644 --- a/back/methods/postcode/specs/filter.spec.js +++ b/back/methods/postcode/specs/filter.spec.js @@ -1,17 +1,14 @@ const {models} = require('vn-loopback/server/server'); -describe('Postcode filter()', () => { +fdescribe('Postcode filter()', () => { it('should retrieve with no filter', async() => { const tx = await models.Postcode.beginTransaction({}); const options = {transaction: tx}; try { - const ctx = { - filter: { - }, + const results = await models.Postcode.filter({ limit: 1 - }; - const results = await models.Postcode.filter(ctx, options); + }, options); expect(results.length).toEqual(1); await tx.rollback(); @@ -26,14 +23,11 @@ describe('Postcode filter()', () => { const options = {transaction: tx}; try { - const ctx = { - filter: { - where: { - search: 46, - } - }, - }; - const results = await models.Postcode.filter(ctx, options); + const results = await models.Postcode.filter({ + where: { + search: 46, + } + }, options); expect(results.length).toEqual(4); await tx.rollback(); @@ -48,14 +42,9 @@ describe('Postcode filter()', () => { const options = {transaction: tx}; try { - const ctx = { - filter: { - where: { - search: 'Alz', - } - }, - }; - const results = await models.Postcode.filter(ctx, options); + const results = await models.Postcode.filter({where: { + search: 'Alz', + }}, options); expect(results.length).toEqual(1); await tx.rollback(); @@ -70,14 +59,9 @@ describe('Postcode filter()', () => { const options = {transaction: tx}; try { - const ctx = { - filter: { - where: { - search: 'one', - } - }, - }; - const results = await models.Postcode.filter(ctx, options); + const results = await models.Postcode.filter({where: { + search: 'one', + }}, options); expect(results.length).toEqual(4); await tx.rollback(); @@ -92,14 +76,11 @@ describe('Postcode filter()', () => { const options = {transaction: tx}; try { - const ctx = { - filter: { - where: { - search: 'Ec', - } - }, - }; - const results = await models.Postcode.filter(ctx, options); + const results = await models.Postcode.filter({ + where: { + search: 'Ec', + } + }, options); expect(results.length).toEqual(1); await tx.rollback(); From b17b5a1b21955ae12d517fb208f0ad094473a42f Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 Jul 2024 10:15:09 +0200 Subject: [PATCH 20/26] test: fix postcode filter back test --- back/methods/postcode/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/postcode/specs/filter.spec.js b/back/methods/postcode/specs/filter.spec.js index 391b1e196..abf450a19 100644 --- a/back/methods/postcode/specs/filter.spec.js +++ b/back/methods/postcode/specs/filter.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('Postcode filter()', () => { +describe('Postcode filter()', () => { it('should retrieve with no filter', async() => { const tx = await models.Postcode.beginTransaction({}); const options = {transaction: tx}; From 1f80117ff749021ca6ae5070986c78f122337b99 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jul 2024 10:24:50 +0200 Subject: [PATCH 21/26] fix: refs #6861 Column --- db/routines/vn/procedures/itemShelvingSale_setQuantity.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 30abefec8..9d21e6a6f 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -103,7 +103,7 @@ BEGIN COMMIT; IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN - INSERT INTO itemShelvingSaleReserve (saleFk, vSectorFk) + INSERT INTO itemShelvingSaleReserve (saleFk, sectorFk) SELECT vSaleFk, vSectorFk; CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk, vSectorFk); END IF; From 01562420d4861b6c392a7209c92cc5ab9b6d1955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 30 Jul 2024 10:14:15 +0000 Subject: [PATCH 22/26] Actualizar db/routines/vn/procedures/itemShelvingSale_reallocate.sql --- .../itemShelvingSale_reallocate.sql | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql index a60287caa..0ce4440e6 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql @@ -1,55 +1,55 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`( - vItemShelvingFk INT(10), - vItemFk INT(10), - vSectorFk INT -) -BEGIN -/** - * Elimina reservas de un itemShelving e intenta reservar en otra ubicación - * - * @param vItemShelvingFk Id itemShelving - * @param vItemFk Id del artículo - * @param vSectorFk Id del sector - */ - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - UPDATE itemShelving - SET visible = 0, - available = 0 - WHERE id = vItemShelvingFk - AND itemFk = vItemFk; - - SELECT iss.id - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND iss.itemFk = vItemFk - AND NOT iss.isPicked - FOR UPDATE; - - INSERT INTO itemShelvingSaleReserve (saleFk, vSectorFk) - SELECT DISTINCT iss.saleFk - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND ish.itemFk = vItemFk - AND NOT iss.isPicked; - - DELETE iss - FROM itemShelvingSale iss - JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - WHERE iss.itemShelvingFk = vItemShelvingFk - AND ish.itemFk = vItemFk - AND NOT iss.isPicked; - COMMIT; - - CALL itemShelvingSale_doReserve(); -END$$ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`( + vItemShelvingFk INT(10), + vItemFk INT(10), + vSectorFk INT +) +BEGIN +/** + * Elimina reservas de un itemShelving e intenta reservar en otra ubicación + * + * @param vItemShelvingFk Id itemShelving + * @param vItemFk Id del artículo + * @param vSectorFk Id del sector + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + UPDATE itemShelving + SET visible = 0, + available = 0 + WHERE id = vItemShelvingFk + AND itemFk = vItemFk; + + SELECT iss.id + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND iss.itemFk = vItemFk + AND NOT iss.isPicked + FOR UPDATE; + + INSERT INTO itemShelvingSaleReserve (saleFk, sectorFk) + SELECT DISTINCT iss.saleFk, vSectorFk + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + + DELETE iss + FROM itemShelvingSale iss + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + WHERE iss.itemShelvingFk = vItemShelvingFk + AND ish.itemFk = vItemFk + AND NOT iss.isPicked; + COMMIT; + + CALL itemShelvingSale_doReserve(); +END$$ DELIMITER ; \ No newline at end of file From 2015256f5d6a3416eb903d7e0f6b8e82af5ac5f6 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 30 Jul 2024 12:38:13 +0200 Subject: [PATCH 23/26] hotFix reallocate resfs #6861 --- db/versions/11177-crimsonPaniculata/00-firstScript.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 db/versions/11177-crimsonPaniculata/00-firstScript.sql diff --git a/db/versions/11177-crimsonPaniculata/00-firstScript.sql b/db/versions/11177-crimsonPaniculata/00-firstScript.sql new file mode 100644 index 000000000..79bcf1291 --- /dev/null +++ b/db/versions/11177-crimsonPaniculata/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here + +ALTER TABLE vn.itemShelvingSaleReserve DROP FOREIGN KEY IF EXISTS itemShelvingSaleReserve_sector_FK; + +ALTER TABLE vn.itemShelvingSaleReserve ADD CONSTRAINT itemShelvingSaleReserve_sector_FK + FOREIGN KEY IF NOT EXISTS (sectorFk) REFERENCES vn.sector(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file From 9e486e4affa8593546602921ef393a18caf7533e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 30 Jul 2024 13:04:33 +0200 Subject: [PATCH 24/26] hotFix reallocate iss refs #6861 --- db/routines/vn/procedures/itemShelvingSale_reallocate.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql index 0ce4440e6..d5b89c373 100644 --- a/db/routines/vn/procedures/itemShelvingSale_reallocate.sql +++ b/db/routines/vn/procedures/itemShelvingSale_reallocate.sql @@ -30,7 +30,7 @@ BEGIN FROM itemShelvingSale iss JOIN itemShelving ish ON ish.id = iss.itemShelvingFk WHERE iss.itemShelvingFk = vItemShelvingFk - AND iss.itemFk = vItemFk + AND ish.itemFk = vItemFk AND NOT iss.isPicked FOR UPDATE; From 80ad1f30af043ff4e20881fae72526add266d680 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jul 2024 13:50:47 +0200 Subject: [PATCH 25/26] fix: refs #7811 Variables pm2 --- back/process.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/back/process.yml b/back/process.yml index a29323240..08fee7a93 100644 --- a/back/process.yml +++ b/back/process.yml @@ -2,6 +2,5 @@ apps: - script: ./loopback/server/server.js name: salix-back instances: 1 - max_restarts: 3 - restart_delay: 15000 + max_restarts: 0 node_args: --tls-min-v1.0 --openssl-legacy-provider From d97aba8e10127c2522d30f87d1b7294e55fdf22d Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 30 Jul 2024 17:28:55 +0200 Subject: [PATCH 26/26] hotFix getTickets refs #6861 --- back/methods/collection/getTickets.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index b79dbc93a..2a2b67524 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -57,8 +57,10 @@ module.exports = Self => { ROW_NUMBER () OVER (PARTITION BY s.id ORDER BY pickingOrder) currentItemShelving, COUNT(*) OVER (PARTITION BY s.id ORDER BY s.id) totalItemShelving, sh.code, - IFNULL(p2.code, p.code) parkingCode, - IFNULL(p2.pickingOrder, p.pickingOrder) pickingOrder, + p2.code parkingCode, + p2.pickingOrder pickingOrder, + p.code parkingCodePrevia, + p.pickingOrder pickingOrderPrevia, iss.id itemShelvingSaleFk, iss.isPicked FROM ticketCollection tc @@ -95,8 +97,10 @@ module.exports = Self => { ROW_NUMBER () OVER (PARTITION BY s.id ORDER BY p.pickingOrder), COUNT(*) OVER (PARTITION BY s.id ORDER BY s.id) , sh.code, - IFNULL(p2.code, p.code), - IFNULL(p2.pickingOrder, p.pickingOrder), + p2.code, + p2.pickingOrder, + p.code, + p.pickingOrder, iss.id itemShelvingSaleFk, iss.isPicked FROM sectorCollection sc