From 952b7a5054efff1b7ce6b34a33cbb87c3f13cda3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jul 2024 07:10:38 +0200 Subject: [PATCH 1/8] hotFix model itemShelving refs #7805 --- modules/item/back/models/item-shelving.json | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 893a1f81d..40f2a2852 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -1,9 +1,9 @@ { "name": "ItemShelving", "base": "VnModel", - "mixins": { - "Loggable": true - }, + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "itemShelving" @@ -17,27 +17,27 @@ }, "shelvingFk": { "type": "string" - }, + }, "itemFk": { "type": "number" - }, + }, "created": { "type": "date" - }, + }, "grouping": { "type": "number" - }, - "isChecked": { - "type": "boolean" + }, + "isChecked": { + "type": "number" }, "packing": { "type": "number" - }, - "visible": { - "type": "number" }, - "userFk": { - "type": "number" + "visible": { + "type": "number" + }, + "userFk": { + "type": "number" } }, "relations": { @@ -56,6 +56,6 @@ "model": "Shelving", "foreignKey": "shelvingFk", "primaryKey": "code" - } + } } -} +} \ No newline at end of file -- 2.40.1 From dca7900ab231cbb52944a77e4264b2a35adbc270 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 31 Jul 2024 11:31:02 +0200 Subject: [PATCH 2/8] fix: refs #7818 entry_splitByShelving --- db/routines/vn/procedures/entry_splitByShelving.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index eb07c12b7..f46278e5a 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -110,7 +110,7 @@ BEGIN UPDATE itemShelving SET isSplit = TRUE - WHERE shelvingFk = vShelvingFk; + WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci; END LOOP; CLOSE cur; END$$ -- 2.40.1 From 77fa4dd4979d1148cec6cb02cdeb87020685a436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 14:38:12 +0200 Subject: [PATCH 3/8] fix: refs #7213 componentLack y setRisk --- db/routines/vn/procedures/sale_setProblemComponentLack.sql | 2 +- .../vn/procedures/sale_setProblemComponentLackByComponent.sql | 4 ++-- db/routines/vn/procedures/ticket_setRisk.sql | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/sale_setProblemComponentLack.sql b/db/routines/vn/procedures/sale_setProblemComponentLack.sql index aa5f5f1be..23eb77c2e 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLack.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLack.sql @@ -14,7 +14,7 @@ BEGIN ENGINE = MEMORY SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem, - ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + (ticket_isProblemCalcNeeded(ticketFk) AND quantity > 0) isProblemCalcNeeded FROM sale WHERE id = vSelf; diff --git a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql index 2ee49b656..cdf28ac09 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql @@ -14,9 +14,9 @@ BEGIN ENGINE = MEMORY SELECT saleFk, sale_hasComponentLack(saleFk) hasProblem, - ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + (ticket_isProblemCalcNeeded(ticketFk) AND quantity > 0) isProblemCalcNeeded FROM ( - SELECT s.id saleFk, s.ticketFk + SELECT s.id saleFk, s.ticketFk, s.quantity 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/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index bd5d1e9f9..b88e60a37 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -85,7 +85,7 @@ BEGIN UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id SET t.risk = NULL - WHERE tr.isProblemCalcNeeded + WHERE NOT tr.isProblemCalcNeeded ORDER BY t.id; DROP TEMPORARY TABLE tTicketRisk; -- 2.40.1 From 6c0aae04c004d97d6fe31d4faa739ae5faf2be04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 14:59:12 +0200 Subject: [PATCH 4/8] fix: refs #7213 componentLack y setRisk --- db/routines/vn/procedures/ticket_setRisk.sql | 140 ++++++++----------- 1 file changed, 62 insertions(+), 78 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index b88e60a37..535cd0787 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -1,94 +1,78 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRisk`( - vClientFk INT) + vClientFk INT +) BEGIN /** - * Update the risk for a client with pending tickets + * Update the risk for a client with pending tickets. * * @param vClientFk Id cliente */ - DECLARE vHasDebt BOOL; - DECLARE vStarted DATETIME; - - SELECT COUNT(*) INTO vHasDebt - FROM `client` - WHERE id = vClientFk - AND typeFk = 'normal'; - - IF vHasDebt THEN - - SELECT util.VN_CURDATE() - INTERVAL riskScope MONTH INTO vStarted - FROM clientConfig; - + IF (SELECT COUNT(*) FROM client WHERE id = vClientFk AND typeFk = 'normal') THEN CREATE OR REPLACE TEMPORARY TABLE tTicketRisk - (KEY (ticketFk)) + (PRIMARY KEY (ticketFk)) ENGINE = MEMORY - WITH ticket AS( - 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 IFNULL(totalWithVat, 0) <> 0 - AND shipped > vStarted - ), balance AS( - SELECT SUM(amount)amount, companyFk - FROM ( - SELECT amount, companyFk - FROM vn.clientRisk - WHERE clientFk = vClientFk - UNION ALL - SELECT -(SUM(amount) / 100) amount, tm.companyFk - FROM hedera.tpvTransaction t - JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk - WHERE clientFk = vClientFk - AND receiptFk IS NULL - AND status = 'ok' - ) sub - WHERE companyFk - GROUP BY companyFk - ), uninvoiced AS( - SELECT companyFk, dated, SUM(totalWithVat) amount - FROM ticket - GROUP BY companyFk, dated - ), receipt AS( - SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount - FROM vn.receipt - WHERE clientFk = vClientFk - AND payed > util.VN_CURDATE() - GROUP BY companyFk, DATE(payed) - ), risk AS( - SELECT b.companyFk, - ui.dated, - SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated ) + - b.amount + - SUM(IFNULL(r.amount, 0)) amount - FROM balance b - JOIN uninvoiced ui ON ui.companyFk = b.companyFk - LEFT JOIN receipt r ON r.dated > ui.dated AND r.companyFk = ui.companyFk - GROUP BY b.companyFk, ui.dated - ) - SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded - FROM ticket ti - JOIN risk r ON r.dated = ti.dated AND r.companyFk = ti.companyFk; + WITH ticket AS ( + SELECT t.id ticketFk, + t.companyFk, + DATE(t.shipped) dated, + t.totalWithVat, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded + FROM vn.ticket t + JOIN vn.clientConfig cc + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND NOT t.isDeleted + AND IFNULL(t.totalWithVat, 0) <> 0 + AND t.shipped > (util.VN_CURDATE() - INTERVAL cc.riskScope MONTH) + ), balance AS ( + SELECT SUM(amount)amount, companyFk + FROM ( + SELECT amount, companyFk + FROM vn.clientRisk + WHERE clientFk = vClientFk + UNION ALL + SELECT -(SUM(amount) / 100) amount, tm.companyFk + FROM hedera.tpvTransaction t + JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk + WHERE clientFk = vClientFk + AND receiptFk IS NULL + AND `status` = 'ok' + ) sub + WHERE companyFk + GROUP BY companyFk + ), uninvoiced AS ( + SELECT companyFk, dated, SUM(totalWithVat) amount + FROM ticket + GROUP BY companyFk, dated + ), receipt AS ( + SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount + FROM vn.receipt + WHERE clientFk = vClientFk + AND payed > util.VN_CURDATE() + GROUP BY companyFk, DATE(payed) + ), risk AS ( + SELECT b.companyFk, + ui.dated, + SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated) + + b.amount + + SUM(IFNULL(r.amount, 0)) amount + FROM balance b + JOIN uninvoiced ui ON ui.companyFk = b.companyFk + LEFT JOIN receipt r ON r.dated > ui.dated + AND r.companyFk = ui.companyFk + GROUP BY b.companyFk, ui.dated + ) + SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded + FROM ticket ti + JOIN risk r ON r.dated = ti.dated + AND r.companyFk = ti.companyFk; UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id - 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 NOT tr.isProblemCalcNeeded - ORDER BY t.id; + SET t.risk = IF(tr.isProblemCalcNeeded, tr.amount, NULL); DROP TEMPORARY TABLE tTicketRisk; - END IF; + END IF; END$$ DELIMITER ; \ No newline at end of file -- 2.40.1 From 65e9ed301ff370f6f0e019c44ecfda47adf526f3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jul 2024 18:11:03 +0200 Subject: [PATCH 5/8] hotFix itemShelving refs #6861 --- .../itemShelvingSale_addBySaleGroup.sql | 46 +++++++++++++++++++ .../vn/procedures/itemShelving_get.sql | 3 +- .../vn/triggers/itemShelving_beforeUpdate.sql | 4 -- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql b/db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql new file mode 100644 index 000000000..285b9f93f --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_addBySaleGroup.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySaleGroup`( + vSaleGroupFk INT(11) +) +BEGIN +/** + * Reserva cantidades con ubicaciones para el contenido de una preparación previa + * a través del saleGroup + * + * @param vSaleGroupFk Identificador de saleGroup + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vSaleFk INT; + DECLARE vSectorFk INT; + DECLARE vSales CURSOR FOR + SELECT s.id + FROM saleGroupDetail sgd + JOIN sale s ON sgd.saleFk = s.id + JOIN saleTracking str ON str.saleFk = s.id + JOIN `state` st ON st.id = str.stateFk + AND st.code = 'PREVIOUS_PREPARATION' + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + WHERE sgd.saleGroupFk = vSaleGroupFk + AND str.workerFk = account.myUser_getId() + AND iss.id IS NULL; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT sectorFk INTO vSectorFk + FROM operator + WHERE workerFk = account.myUser_getId(); + + OPEN vSales; + l: LOOP + SET vDone = FALSE; + FETCH vSales INTO vSaleFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); + END LOOP; + CLOSE vSales; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelving_get.sql b/db/routines/vn/procedures/itemShelving_get.sql index 1be762f09..d42446b06 100644 --- a/db/routines/vn/procedures/itemShelving_get.sql +++ b/db/routines/vn/procedures/itemShelving_get.sql @@ -16,7 +16,8 @@ BEGIN ish.id, s.priority, ish.isChecked, - ic.url + ic.url, + ish.available FROM itemShelving ish JOIN item i ON i.id = ish.itemFk JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index 214c64b45..961d89f65 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -9,9 +9,5 @@ BEGIN SET NEW.userFk = account.myUser_getId(); END IF; - IF (NEW.visible <> OLD.visible) THEN - SET NEW.available = GREATEST(NEW.available + NEW.visible - OLD.visible, 0); - END IF; - END$$ DELIMITER ; -- 2.40.1 From 70b931553bf91c2bda7509b01023b96a34f4178f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 31 Jul 2024 18:14:09 +0200 Subject: [PATCH 6/8] hotFix itemShelving refs #6861 --- modules/item/back/models/item-shelving.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 40f2a2852..5df3b0703 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -38,6 +38,9 @@ }, "userFk": { "type": "number" + }, + "available": { + "type": "number" } }, "relations": { -- 2.40.1 From 5b0dcee62d5be611423328fe6583b11237953071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 18:41:18 +0200 Subject: [PATCH 7/8] hotfix: getBuys add field comment Ticket 207748 --- modules/entry/back/methods/entry/getBuys.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index bd9c5db7a..245dada09 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -101,7 +101,8 @@ module.exports = Self => { 'groupingMode', 'inkFk', 'originFk', - 'producerFk' + 'producerFk', + 'comment' ], include: [ { -- 2.40.1 From 77f6e80066b37174020dfd76446dbbd97cf5212b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 31 Jul 2024 17:38:50 +0000 Subject: [PATCH 8/8] Actualizar db/routines/vn/procedures/ticket_setRisk.sql --- db/routines/vn/procedures/ticket_setRisk.sql | 113 ++++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index 535cd0787..e3cbaf231 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -13,60 +13,65 @@ BEGIN (PRIMARY KEY (ticketFk)) ENGINE = MEMORY WITH ticket AS ( - SELECT t.id ticketFk, - t.companyFk, - DATE(t.shipped) dated, - t.totalWithVat, - ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded - FROM vn.ticket t - JOIN vn.clientConfig cc - WHERE t.clientFk = vClientFk - AND t.refFk IS NULL - AND NOT t.isDeleted - AND IFNULL(t.totalWithVat, 0) <> 0 - AND t.shipped > (util.VN_CURDATE() - INTERVAL cc.riskScope MONTH) - ), balance AS ( - SELECT SUM(amount)amount, companyFk - FROM ( - SELECT amount, companyFk - FROM vn.clientRisk - WHERE clientFk = vClientFk - UNION ALL - SELECT -(SUM(amount) / 100) amount, tm.companyFk - FROM hedera.tpvTransaction t - JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk - WHERE clientFk = vClientFk - AND receiptFk IS NULL - AND `status` = 'ok' - ) sub - WHERE companyFk - GROUP BY companyFk - ), uninvoiced AS ( - SELECT companyFk, dated, SUM(totalWithVat) amount - FROM ticket - GROUP BY companyFk, dated - ), receipt AS ( - SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount - FROM vn.receipt - WHERE clientFk = vClientFk - AND payed > util.VN_CURDATE() - GROUP BY companyFk, DATE(payed) - ), risk AS ( - SELECT b.companyFk, - ui.dated, - SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated) + - b.amount + - SUM(IFNULL(r.amount, 0)) amount - FROM balance b - JOIN uninvoiced ui ON ui.companyFk = b.companyFk - LEFT JOIN receipt r ON r.dated > ui.dated - AND r.companyFk = ui.companyFk - GROUP BY b.companyFk, ui.dated - ) - SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded - FROM ticket ti - JOIN risk r ON r.dated = ti.dated - AND r.companyFk = ti.companyFk; + SELECT t.id ticketFk, + t.companyFk, + DATE(t.shipped) dated, + t.totalWithVat, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded + FROM vn.ticket t + JOIN vn.clientConfig cc + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND NOT t.isDeleted + AND IFNULL(t.totalWithVat, 0) <> 0 + AND t.shipped > (util.VN_CURDATE() - INTERVAL cc.riskScope MONTH) + ), uninvoiced AS ( + SELECT companyFk, dated, SUM(totalWithVat) amount + FROM ticket + GROUP BY companyFk, dated + ), companies AS ( + SELECT DISTINCT companyFk FROM uninvoiced + ), balance AS ( + SELECT SUM(IFNULL(amount, 0))amount, companyFk + FROM ( + SELECT cr.amount, c.companyFk + FROM companies c + LEFT JOIN vn.clientRisk cr ON cr.companyFk = c.companyFk + AND cr.clientFk = vClientFk + UNION ALL + SELECT -(SUM(t.amount) / 100) amount, c.companyFk + FROM companies c + LEFT JOIN hedera.tpvMerchant tm ON tm.companyFk = c.companyFk + LEFT JOIN hedera.tpvTransaction t ON t.merchantFk = tm.id + AND t.clientFk = vClientFk + AND t.receiptFk IS NULL + AND t.`status` = 'ok' + ) sub + WHERE companyFk + GROUP BY companyFk + ), receipt AS ( + SELECT r.companyFk, DATE(r.payed) dated, SUM(r.amountPaid) amount + FROM vn.receipt r + JOIN companies c ON c.companyFk = r.companyFk + WHERE r.clientFk = vClientFk + AND r.payed > util.VN_CURDATE() + GROUP BY r.companyFk, DATE(r.payed) + ), risk AS ( + SELECT b.companyFk, + ui.dated, + SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated) + + b.amount + + SUM(IFNULL(r.amount, 0)) amount + FROM balance b + JOIN uninvoiced ui ON ui.companyFk = b.companyFk + LEFT JOIN receipt r ON r.dated > ui.dated + AND r.companyFk = ui.companyFk + GROUP BY b.companyFk, ui.dated + ) + SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded + FROM ticket ti + JOIN risk r ON r.dated = ti.dated + AND r.companyFk = ti.companyFk; UPDATE ticket t JOIN tTicketRisk tr ON tr.ticketFk = t.id -- 2.40.1