From 52400ab62651a38c3180b7b2eee3850986957b5c Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 20 May 2024 15:17:41 +0200 Subject: [PATCH 001/123] refs #7393 Modify night ticket closing report --- modules/ticket/back/methods/ticket/closeAll.js | 9 ++++++--- .../invoice-ticket-closure/invoice-ticket-closure.html | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index e3cbc83e2..d38cee491 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -71,7 +71,8 @@ module.exports = Self => { JSON_ARRAYAGG( JSON_OBJECT( 'ticketId', ticketFk, - 'reason', reason + 'reason', reason, + 'clientId', clientFk ) ) )errors @@ -83,7 +84,8 @@ module.exports = Self => { IF(hasErrorDeleted, 'Eliminado', NULL), IF(hasErrorItemTaxCountry, 'Impuesto no informado', NULL), IF(hasErrorAddress, 'Sin dirección', NULL), - IF(hasErrorInfoTaxAreaWorld, 'Datos exportaciones', NULL)) reason + IF(hasErrorInfoTaxAreaWorld, 'Datos exportaciones', NULL)) reason, + clientFk FROM ( SELECT t.id ticketFk, SUM(NOT c.hasToInvoice) hasErrorToInvoice, @@ -93,7 +95,8 @@ module.exports = Self => { SUM(a.id IS NULL) hasErrorAddress, SUM(ios.code IS NOT NULL AND(ad.customsAgentFk IS NULL - OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld + OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld, + t.clientFk clientFk FROM ticket t LEFT JOIN address ad ON ad.id = t.addressFk JOIN sale s ON s.ticketFk = t.id diff --git a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html index 2effa8917..f72b2177f 100644 --- a/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html +++ b/print/templates/email/invoice-ticket-closure/invoice-ticket-closure.html @@ -7,6 +7,7 @@

{{ $t('ticketId') }}: {{ticket.ticketId}}

{{ $t('reason') }}: {{ticket.reason}}

+

{{ $t('clientId')}}{{ticket.clientId}}


From 1c6e881273bb3997c572ea1f8f92fe88d033334e Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 6 Jun 2024 11:45:09 +0200 Subject: [PATCH 002/123] feat: refs #7544 crear evento claim_changeState --- db/routines/vn/events/claim_changeState.sql | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 db/routines/vn/events/claim_changeState.sql diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql new file mode 100644 index 000000000..c9e4c3cc5 --- /dev/null +++ b/db/routines/vn/events/claim_changeState.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState` + ON SCHEDULE EVERY 1 DAY + STARTS '2024-06-06 07:52:46.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + + DECLARE vClaimStete INT; + + SELECT id INTO vClaimStete + FROM claimState cs + WHERE cs.code = 'canceled' + + UPDATE claim c + JOIN claimState cs ON cs.id = c.claimStateFk + SET c.claimStateFk = vClaimStete + WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH + AND cs.code IN('incomplete','coming','waiting','out') + +END$$ +DELIMITER ; From ef50d493f18602f9c37fddf05ee2e357404f8182 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 6 Jun 2024 11:54:39 +0200 Subject: [PATCH 003/123] feat: refs #7544 --- db/routines/vn/events/claim_changeState.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql index c9e4c3cc5..790ef0c34 100644 --- a/db/routines/vn/events/claim_changeState.sql +++ b/db/routines/vn/events/claim_changeState.sql @@ -10,13 +10,13 @@ DO BEGIN SELECT id INTO vClaimStete FROM claimState cs - WHERE cs.code = 'canceled' + WHERE cs.code = 'canceled'; UPDATE claim c JOIN claimState cs ON cs.id = c.claimStateFk SET c.claimStateFk = vClaimStete WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH - AND cs.code IN('incomplete','coming','waiting','out') + AND cs.code IN('incomplete','coming','waiting','out'); END$$ DELIMITER ; From 9f9063567a957f9442ab64c23b2e0f6be39f032b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 12:40:07 +0200 Subject: [PATCH 004/123] refactor: refs #7505 item_getVisible refactor --- .../cache/procedures/visible_refresh.sql | 5 +- db/routines/vn/procedures/item_GetVisible.sql | 43 ------------- db/routines/vn/procedures/item_getVisible.sql | 49 ++++++++++++++ .../vn/procedures/multipleInventory.sql | 64 ++++++------------- 4 files changed, 70 insertions(+), 91 deletions(-) delete mode 100644 db/routines/vn/procedures/item_GetVisible.sql create mode 100644 db/routines/vn/procedures/item_getVisible.sql diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 63b42dfd9..954b8ff23 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -20,11 +20,12 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, amount stock, amount visible FROM `cache`.stock + SELECT item_id, amount stock, amount visible + FROM `cache`.stock WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_GetVisible(v_warehouse, NULL); + CALL vn.item_getVisible(v_warehouse, util.VN_CURDATE(), NULL); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_GetVisible.sql b/db/routines/vn/procedures/item_GetVisible.sql deleted file mode 100644 index ca5e43107..000000000 --- a/db/routines/vn/procedures/item_GetVisible.sql +++ /dev/null @@ -1,43 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_GetVisible`(vWarehouse SMALLINT, vItem INT) -BEGIN - DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); - - INSERT INTO tmp.itemVisible (item_id, visible) - SELECT item_id, SUM(amount) amount - FROM ( - SELECT i.itemFk AS item_id, quantity AS amount - FROM itemTicketOut i - LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk - JOIN state s ON s.id = ts.stateFk - LEFT JOIN (SELECT DISTINCT saleFk - FROM saleTracking st - JOIN state s ON s.id = st.stateFk - WHERE st.created > util.VN_CURDATE() - AND (s.isPicked OR st.isChecked) - ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk - WHERE i.warehouseFk = vWarehouse - AND (vItem IS NULL OR i.itemFk = vItem) - AND (s.isPicked OR i.reserved OR stPrevious.saleFk ) - AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow - UNION ALL - SELECT iei.itemFk, quantity - FROM itemEntryIn iei - WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/) - AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow - AND iei.warehouseInFk = vWarehouse - AND (vItem IS NULL OR iei.itemFk = vItem) - AND iei.isVirtualStock is FALSE - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE isDelivered != FALSE - AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow - AND warehouseOutFk = vWarehouse - AND (vItem IS NULL OR itemFk = vItem) - ) t - GROUP BY item_id - ON DUPLICATE KEY UPDATE - visible = IFNULL(stock,0) + VALUES(visible); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_getVisible.sql new file mode 100644 index 000000000..0516b9d06 --- /dev/null +++ b/db/routines/vn/procedures/item_getVisible.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( + vWarehouseFk INT, + vDated INT, + vItemFk INT +) +BEGIN + DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; + + INSERT INTO tmp.itemVisible (item_id, visible) + SELECT itemFk, SUM(quantity) + FROM ( + SELECT i.itemFk, i.quantity + FROM itemTicketOut i + LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk + JOIN `state` s ON s.id = ts.stateFk + LEFT JOIN ( + SELECT DISTINCT st.saleFk + FROM saleTracking st + JOIN state s ON s.id = st.stateFk + WHERE st.created > vDated + AND (s.isPicked OR st.isChecked) + ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk + WHERE i.warehouseFk = vWarehouseFk + AND (vItemFk IS NULL OR i.itemFk = vItemFk) + AND (s.isPicked OR i.reserved OR stPrevious.saleFk) + AND i.shipped >= vDated AND i.shipped < vTomorrow + UNION ALL + SELECT itemFk, quantity + FROM itemEntryIn + WHERE isReceived + AND landed >= vDated AND landed < vTomorrow + AND warehouseInFk = vWarehouseFk + AND (vItemFk IS NULL OR itemFk = vItemFk) + AND NOT isVirtualStock + UNION ALL + SELECT itemFk, quantity + FROM itemEntryOut + WHERE isDelivered + AND shipped >= vDated + AND shipped < vTomorrow + AND warehouseOutFk = vWarehouseFk + AND (vItemFk IS NULL OR itemFk = vItemFk) + ) t + GROUP BY itemFk + ON DUPLICATE KEY UPDATE + visible = IFNULL(stock, 0) + VALUES(visible); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 2a28aa9a0..4d5c5d366 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -1,9 +1,9 @@ -DELIMITER $$ +DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventory`( vDate DATE, vWarehouseFk TINYINT, vMaxDays TINYINT -) +) proc: BEGIN DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; DECLARE vDateFrom DATE DEFAULT vDate; @@ -78,47 +78,18 @@ proc: BEGIN ai.sd = sub.Subtotal; -- Cálculo del visible - UPDATE tmp.itemInventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, s.quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped >= vDate - AND t.shipped < vDateTomorrow - AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - ) sub2 - GROUP BY itemFk - ) sub ON ai.id = sub.Id_Article - SET ai.visible = ai.visible + sub.Subtotal; + CALL `cache`.stock_refresh(false); + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT item_id, amount stock, amount visible FROM `cache`.stock + WHERE warehouse_id = vWarehouseFk; + + CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + UPDATE tmp.itemInventory it + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -189,6 +160,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.itemTravel, tmp.itemCalc, - tmp.itemAtp; -END$$ -DELIMITER ; + tmp.itemAtp, + tmp.itemVisible; +END$$ +DELIMITER ; From a9aad7406aec4e0065069c2db4598a65d930bf3c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 12:51:36 +0200 Subject: [PATCH 005/123] refactor: refs #7505 Minor change --- db/routines/vn/procedures/multipleInventory.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 4d5c5d366..05f25268c 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -87,9 +87,9 @@ proc: BEGIN WHERE warehouse_id = vWarehouseFk; CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); - UPDATE tmp.itemInventory it - JOIN tmp.itemVisible iv ON iv.item_id = it.id - SET it.visible = iv.visible; + UPDATE tmp.itemInventory it + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc From 4f10a93584f309711d455d9081dfee2df9e80ae1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 13:36:46 +0200 Subject: [PATCH 006/123] refactor: refs #7505 Minor change --- db/routines/vn/procedures/multipleInventory.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 05f25268c..630301b94 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -86,7 +86,7 @@ proc: BEGIN SELECT item_id, amount stock, amount visible FROM `cache`.stock WHERE warehouse_id = vWarehouseFk; - CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = iv.visible; From 3bd596e5fd91d63a5c10f62fc45bd8805063d9ca Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 13:53:41 +0200 Subject: [PATCH 007/123] refactor: refs #7505 Added description --- db/routines/vn/procedures/item_getVisible.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_getVisible.sql index 0516b9d06..2294d8903 100644 --- a/db/routines/vn/procedures/item_getVisible.sql +++ b/db/routines/vn/procedures/item_getVisible.sql @@ -5,6 +5,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( vItemFk INT ) BEGIN +/** + * Calcula el visible de un artículo o de todos. + * + * @param vWarehouse Warehouse id + * @param vDated Max date to filter + * @param vItemFk Item id + * @param tmp.itemVisible(item_id, stock, visible) + */ DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; INSERT INTO tmp.itemVisible (item_id, visible) From aa0e06cfec4be89f54eb2828f115fc8ae800d54e Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 14:00:59 +0200 Subject: [PATCH 008/123] refactor: refs #7505 Changed name --- db/routines/cache/procedures/visible_refresh.sql | 2 +- .../vn/procedures/{item_getVisible.sql => item_calcVisible.sql} | 2 +- db/routines/vn/procedures/multipleInventory.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename db/routines/vn/procedures/{item_getVisible.sql => item_calcVisible.sql} (99%) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 954b8ff23..b200e86f2 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_getVisible(v_warehouse, util.VN_CURDATE(), NULL); + CALL vn.item_calcVisible(v_warehouse, util.VN_CURDATE(), NULL); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql similarity index 99% rename from db/routines/vn/procedures/item_getVisible.sql rename to db/routines/vn/procedures/item_calcVisible.sql index 2294d8903..f7eee661b 100644 --- a/db/routines/vn/procedures/item_getVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( vWarehouseFk INT, vDated INT, vItemFk INT diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 630301b94..b201bcaae 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -86,7 +86,7 @@ proc: BEGIN SELECT item_id, amount stock, amount visible FROM `cache`.stock WHERE warehouse_id = vWarehouseFk; - CALL item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_calcVisible(vWarehouseFk, util.VN_CURDATE(), NULL); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = iv.visible; From cbd46330b31d8efcbab8ce2b116dd8f048cd8eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 27 Jun 2024 13:01:42 +0200 Subject: [PATCH 009/123] feat: Turn issues into calculated columns refs#7213 --- .../functions/ticket_isProblemCalcNeeded.sql | 27 +++ db/routines/vn/procedures/buyUltimate.sql | 34 +-- .../vn/procedures/buyUltimateFromInterval.sql | 195 ++++++++++-------- db/routines/vn/procedures/sale_setProblem.sql | 9 +- .../sale_setProblemComponentLack.sql | 8 +- ...ale_setProblemComponentLackByComponent.sql | 8 +- .../vn/procedures/sale_setProblemRounding.sql | 9 +- .../vn/procedures/ticket_setProblem.sql | 12 +- .../vn/procedures/ticket_setProblemFreeze.sql | 8 +- .../procedures/ticket_setProblemRequest.sql | 6 +- .../vn/procedures/ticket_setProblemRisk.sql | 17 +- .../procedures/ticket_setProblemRounding.sql | 7 +- .../ticket_setProblemTaxDataChecked.sql | 6 +- .../procedures/ticket_setProblemTooLittle.sql | 8 +- .../ticket_setProblemTooLittleItemCost.sql | 6 +- 15 files changed, 234 insertions(+), 126 deletions(-) create mode 100644 db/routines/vn/functions/ticket_isProblemCalcNeeded.sql diff --git a/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql b/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql new file mode 100644 index 000000000..4974a8c76 --- /dev/null +++ b/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isProblemCalcNeeded`( + vSelf INT +) + RETURNS BOOL + DETERMINISTIC +BEGIN +/** + * Check if the ticket requires to update column vn.ticket.problem + * + * @param vSelf Id ticket + * @return BOOL + */ + DECLARE vIsProblemCalcNeeded BOOL; + + SELECT COUNT(*) INTO vIsProblemCalcNeeded + FROM ticket t + JOIN client c ON c.id = t.clientFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE t.id = vSelf + AND dm.code IN ('AGENCY','DELIVERY','PICKUP') + AND c.typeFk = 'normal'; + + RETURN vIsProblemCalcNeeded; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql index 4346ef640..98b16cbc0 100644 --- a/db/routines/vn/procedures/buyUltimate.sql +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -1,5 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(vWarehouseFk SMALLINT, vDated DATE) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`( + vWarehouseFk SMALLINT, + vDated DATE +) BEGIN /** * Calcula las últimas compras realizadas hasta una fecha @@ -19,21 +22,22 @@ BEGIN FROM cache.last_buy WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); + IF vDated >= util.VN_CURDATE() THEN + CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); - REPLACE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed <= vDated - AND NOT isIgnored; - - INSERT IGNORE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed > vDated - ORDER BY isIgnored = FALSE DESC; + REPLACE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed <= vDated + AND NOT isIgnored; + INSERT IGNORE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed > vDated + ORDER BY isIgnored = FALSE DESC; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index e264b500d..5879b58e1 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -1,5 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`( + vWarehouseFk SMALLINT, + vStarted DATE, + vEnded DATE +) BEGIN /** * Calcula las últimas compras realizadas @@ -21,12 +25,13 @@ BEGIN -- Item DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval - (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) + (PRIMARY KEY (itemFk, warehouseFk), + INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) ENGINE = MEMORY SELECT itemFk, warehouseFk, buyFk, - MAX(landed) landed, + landed, isIgnored FROM (SELECT b.itemFk, t.warehouseInFk warehouseFk, @@ -45,93 +50,117 @@ BEGIN INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - GROUP BY itemFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - GROUP BY itemFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; -- ItemOriginal INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT itemFk, - warehouseFk, - buyFk, - MAX(landed) landed, - isIgnored - FROM (SELECT b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - itemOriginalFk, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND b.quantity > 0 - AND itemOriginalFk - ORDER BY t.landed DESC, b.id DESC - LIMIT 10000000000000000000) sub - GROUP BY itemOriginalFk, warehouseFk; + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + itemOriginalFk, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND b.quantity > 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM + (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql index 20319cc3f..1ba7a1353 100644 --- a/db/routines/vn/procedures/sale_setProblem.sql +++ b/db/routines/vn/procedures/sale_setProblem.sql @@ -6,8 +6,15 @@ BEGIN /** * Update column sale.problem with a problem code * @param vProblemCode Code to set or unset - * @table tmp.sale(saleFk, hasProblem) + * @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded) */ + UPDATE tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + SET s.problem = NULL + WHERE NOT ts.isProblemCalcNeeded; + + DELETE FROM tmp.sale WHERE NOT isProblemCalcNeeded; + UPDATE sale s JOIN tmp.sale ts ON ts.saleFk = s.id SET s.problem = CONCAT( diff --git a/db/routines/vn/procedures/sale_setProblemComponentLack.sql b/db/routines/vn/procedures/sale_setProblemComponentLack.sql index 363663a00..aa5f5f1be 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLack.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLack.sql @@ -10,9 +10,13 @@ BEGIN * @param vSelf Id del sale */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) + (INDEX(saleFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem; + SELECT vSelf saleFk, + sale_hasComponentLack(vSelf) hasProblem, + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + FROM sale + WHERE id = vSelf; CALL sale_setProblem('hasComponentLack'); diff --git a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql index b911327dd..2ee49b656 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql @@ -10,11 +10,13 @@ BEGIN * @param vComponentFk Id component */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) + (INDEX(saleFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem + SELECT saleFk, + sale_hasComponentLack(saleFk) hasProblem, + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded FROM ( - SELECT s.id saleFk + SELECT s.id saleFk, s.ticketFk FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id diff --git a/db/routines/vn/procedures/sale_setProblemRounding.sql b/db/routines/vn/procedures/sale_setProblemRounding.sql index f14cd408f..f58d00799 100644 --- a/db/routines/vn/procedures/sale_setProblemRounding.sql +++ b/db/routines/vn/procedures/sale_setProblemRounding.sql @@ -11,9 +11,10 @@ BEGIN DECLARE vWarehouseFk INT; DECLARE vShipped DATE; DECLARE vQuantity INT; + DECLARE vIsProblemCalcNeeded BOOL; - SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity - INTO vItemFk, vWarehouseFk, vShipped, vQuantity + SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity, ticket_isProblemCalcNeeded(t.id) + INTO vItemFk, vWarehouseFk, vShipped, vQuantity, vIsProblemCalcNeeded FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE s.id = vSelf; @@ -21,7 +22,9 @@ BEGIN CALL buyUltimate(vWarehouseFk, vShipped); CREATE OR REPLACE TEMPORARY TABLE tmp.sale - SELECT vSelf saleFk, MOD(vQuantity, b.`grouping`) hasProblem + SELECT vSelf saleFk, + MOD(vQuantity, b.`grouping`) hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded FROM tmp.buyUltimate bu JOIN buy b ON b.id = bu.buyFk WHERE bu.itemFk = vItemFk; diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql index bab8f1f52..a75cb91ed 100644 --- a/db/routines/vn/procedures/ticket_setProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblem.sql @@ -4,11 +4,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( ) BEGIN /** - * Update column ticket.problem with a problem code + * Update column ticket.problem with a problem code and SET NULL when + * the problem is not requiered * * @param vProblemCode Code to set or unset - * @table tmp.ticket(ticketFk, hasProblem) + * @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded) */ + UPDATE ticket t + JOIN tmp.ticket tt ON tt.ticketFk = t.id + SET t.problem = NULL + WHERE NOT tt.isProblemCalcNeeded; + + DELETE FROM tmp.ticket WHERE NOT isProblemCalcNeeded; + UPDATE ticket t JOIN tmp.ticket tt ON tt.ticketFk = t.id SET t.problem = CONCAT( diff --git a/db/routines/vn/procedures/ticket_setProblemFreeze.sql b/db/routines/vn/procedures/ticket_setProblemFreeze.sql index 560bce612..1de939ba7 100644 --- a/db/routines/vn/procedures/ticket_setProblemFreeze.sql +++ b/db/routines/vn/procedures/ticket_setProblemFreeze.sql @@ -9,9 +9,11 @@ BEGIN * @param vClientFk Id Cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem + SELECT t.id ticketFk, + FALSE hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vClientFk IS NULL OR t.clientFk = vClientFk); @@ -21,7 +23,7 @@ BEGIN JOIN client c ON c.id = ti.clientFk SET t.hasProblem = TRUE WHERE c.isFreezed; - + CALL ticket_setProblem('isFreezed'); DROP TEMPORARY TABLE tmp.ticket; diff --git a/db/routines/vn/procedures/ticket_setProblemRequest.sql b/db/routines/vn/procedures/ticket_setProblemRequest.sql index 19bba5b76..687facfc7 100644 --- a/db/routines/vn/procedures/ticket_setProblemRequest.sql +++ b/db/routines/vn/procedures/ticket_setProblemRequest.sql @@ -9,9 +9,11 @@ BEGIN * @param vSelf Id ticket, if NULL ALL tickets */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem + SELECT t.id ticketFk, + FALSE hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vSelf IS NULL OR t.id = vSelf); diff --git a/db/routines/vn/procedures/ticket_setProblemRisk.sql b/db/routines/vn/procedures/ticket_setProblemRisk.sql index 5f73ee838..efa5b10e2 100644 --- a/db/routines/vn/procedures/ticket_setProblemRisk.sql +++ b/db/routines/vn/procedures/ticket_setProblemRisk.sql @@ -10,21 +10,30 @@ BEGIN */ DECLARE vHasRisk BOOL; DECLARE vHasHighRisk BOOL; + DECLARE vIsProblemCalcNeeded BOOL; - SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10)) - INTO vHasRisk, vHasHighRisk + SELECT t.risk > (c.credit + 10), + (t.risk - cc.riskTolerance) > (c.credit + 10), + ticket_isProblemCalcNeeded(t.id) + INTO vHasRisk, vHasHighRisk, vIsProblemCalcNeeded FROM client c JOIN ticket t ON t.clientFk = c.id JOIN clientConfig cc WHERE t.id = vSelf; CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf ticketFk, vHasRisk hasProblem; + ENGINE = MEMORY + SELECT vSelf ticketFk, + vHasRisk hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded; CALL ticket_setProblem('hasRisk'); CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf ticketFk, vHasHighRisk hasProblem; + ENGINE = MEMORY + SELECT vSelf ticketFk, + vHasHighRisk hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded; CALL ticket_setProblem('hasHighRisk'); diff --git a/db/routines/vn/procedures/ticket_setProblemRounding.sql b/db/routines/vn/procedures/ticket_setProblemRounding.sql index 81294325c..fb580eacf 100644 --- a/db/routines/vn/procedures/ticket_setProblemRounding.sql +++ b/db/routines/vn/procedures/ticket_setProblemRounding.sql @@ -18,8 +18,11 @@ BEGIN CALL buyUltimate(vWarehouseFk, vDated); - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk, isProblemCalcNeeded)) + SELECT s.id saleFk , + MOD(s.quantity, b.`grouping`) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql index 00918426b..9877b5acc 100644 --- a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql @@ -9,9 +9,11 @@ BEGIN * @param vClientFk Id cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem + SELECT t.id ticketFk, + IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t JOIN client c ON c.id = t.clientFk WHERE t.shipped >= util.VN_CURDATE() diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittle.sql b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql index 98a0787af..48cc47809 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittle.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql @@ -8,13 +8,17 @@ BEGIN * * @param vSelf Id del ticket */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem; + SELECT vSelf ticketFk, + ticket_isTooLittle(vSelf) hasProblem, + ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded; CALL ticket_setProblem('isTooLittle'); DROP TEMPORARY TABLE tmp.ticket; + END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index cd1f42783..1f41c0716 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -10,7 +10,7 @@ BEGIN * @param vItemFk Id del item, NULL ALL items */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY WITH tickets AS( SELECT t.id ticketFk @@ -19,7 +19,9 @@ BEGIN WHERE t.shipped >= util.VN_CURDATE() AND (s.itemFk = vItemFk OR vItemFk IS NULL) GROUP BY t.id - )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem + )SELECT ticketFk, + ticket_isTooLittle(ticketFk) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM tickets; CALL ticket_setProblem('isTooLittle'); From a8d663bee46d62da682a56f5fed24bce5714c029 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 3 Jul 2024 10:49:51 +0200 Subject: [PATCH 010/123] feat: refs #7348 hasDailyInvoice field --- db/routines/vn/procedures/client_create.sql | 24 ++++++++++++------- .../11126-blueCamellia/00-firstScript.sql | 2 ++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 db/versions/11126-blueCamellia/00-firstScript.sql diff --git a/db/routines/vn/procedures/client_create.sql b/db/routines/vn/procedures/client_create.sql index d5d7258a1..f2321e129 100644 --- a/db/routines/vn/procedures/client_create.sql +++ b/db/routines/vn/procedures/client_create.sql @@ -34,20 +34,25 @@ BEGIN DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vHasCoreVnl BOOLEAN; DECLARE vMandateTypeFk INT; + DECLARE vHasDailyInvoice BOOLEAN; - SELECT defaultPayMethodFk, - defaultDueDay, - defaultCredit, - defaultIsTaxDataChecked, - defaultHasCoreVnl, - defaultMandateTypeFk + SELECT cc.defaultPayMethodFk, + cc.defaultDueDay, + cc.defaultCredit, + cc.defaultIsTaxDataChecked, + cc.defaultHasCoreVnl, + cc.defaultMandateTypeFk, + c.hasDailyInvoice INTO vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked, vHasCoreVnl, - vMandateTypeFk - FROM clientConfig; + vMandateTypeFk, + vHasDailyInvoice + FROM clientConfig cc + LEFT JOIN province p ON p.id = vProvinceFk + LEFT JOIN country c ON c.id = p.countryFk; INSERT INTO `client` SET id = vUserFk, @@ -65,7 +70,8 @@ BEGIN credit = vDefaultCredit, isTaxDataChecked = vIsTaxDataChecked, hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE + isEqualizated = FALSE, + hasDailyInvoice = vHasDailyInvoice ON duplicate KEY UPDATE payMethodFk = vPayMethodFk, dueDay = vDueDay, diff --git a/db/versions/11126-blueCamellia/00-firstScript.sql b/db/versions/11126-blueCamellia/00-firstScript.sql new file mode 100644 index 000000000..45c2ed2dc --- /dev/null +++ b/db/versions/11126-blueCamellia/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `client` +ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'; From cf63d6e71c2d86bdb44f40f227da3ae49e02ce3e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 11:17:33 +0200 Subject: [PATCH 011/123] feat: refs #7378 Added productionConfigLog --- .../triggers/productionConfig_afterDelete.sql | 12 ++++++++++ .../productionConfig_beforeInsert.sql | 8 +++++++ .../productionConfig_beforeUpdate.sql | 8 +++++++ .../11130-crimsonIvy/00-firstScript.sql | 23 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 db/routines/vn/triggers/productionConfig_afterDelete.sql create mode 100644 db/routines/vn/triggers/productionConfig_beforeInsert.sql create mode 100644 db/routines/vn/triggers/productionConfig_beforeUpdate.sql create mode 100644 db/versions/11130-crimsonIvy/00-firstScript.sql diff --git a/db/routines/vn/triggers/productionConfig_afterDelete.sql b/db/routines/vn/triggers/productionConfig_afterDelete.sql new file mode 100644 index 000000000..384bf681e --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_afterDelete` + AFTER DELETE ON `productionConfig` + FOR EACH ROW +BEGIN + INSERT INTO productionConfig + SET `action` = 'delete', + `changedModel` = 'ProductionConfig', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/productionConfig_beforeInsert.sql b/db/routines/vn/triggers/productionConfig_beforeInsert.sql new file mode 100644 index 000000000..99b217be4 --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeInsert` + BEFORE INSERT ON `productionConfig` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/productionConfig_beforeUpdate.sql b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql new file mode 100644 index 000000000..f1ceaa471 --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeUpdate` + BEFORE UPDATE ON `productionConfig` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql new file mode 100644 index 000000000..3bde55f55 --- /dev/null +++ b/db/versions/11130-crimsonIvy/00-firstScript.sql @@ -0,0 +1,23 @@ +ALTER TABLE vn.productionConfig + ADD editorFk int(10) unsigned DEFAULT NULL NULL; +ALTER TABLE vn.productionConfig + ADD CONSTRAINT productionConfig_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id); + +CREATE OR REPLACE TABLE `vn`.`productionConfigLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('ProductionConfig') NOT NULL DEFAULT 'ProductionConfig', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `logRateuserFk` (`userFk`), + KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `productionConfigLog_originFk` (`originFk`,`creationDate`), + CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; From a7895ab0a45c56ce7a04e86258dd3ab2add482f6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 4 Jul 2024 09:17:22 +0200 Subject: [PATCH 012/123] refs #6769 First commit --- db/routines/vn/procedures/item_getBalance.sql | 224 +++++++++++------- 1 file changed, 144 insertions(+), 80 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index a4942af6f..561957452 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -2,25 +2,65 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`( vItemFk INT, vWarehouseFk INT, - vDate DATETIME + vDated DATETIME ) BEGIN /** - * @vItemFk item a buscar - * @vWarehouseFk almacen donde buscar - * @vDate Si la fecha es null, muestra el histórico desde el inventario. - * Si la fecha no es null, muestra histórico desde la fecha de vDate. + * Calcula el disponible. + * + * @vItemFk Id de artículo + * @vWarehouseFk Id de almacén + * @vDated Fecha + * Si la fecha es NULL, muestra el histórico desde el inventario. + * Si la fecha no es NULL, muestra histórico desde la fecha de vDated. */ DECLARE vDateInventory DATETIME; + DECLARE vLifeScope DATE; + DECLARE vWarehouseInventoryFk INT; + DECLARE vSupplierInventoryFk INT; - IF vDate IS NULL THEN - SELECT inventoried INTO vDateInventory - FROM config; - ELSE - SELECT mockUtcTime INTO vDateInventory - FROM util.config; + SELECT IF(vDated, uc.mockUtcTime, c.inventoried) INTO vDateInventory + FROM config c + JOIN util.config uc; + + SELECT COALESCE(vDated, vDateInventory) - INTERVAL MAX(life) DAY + INTO vLifeScope + FROM itemType; + + SELECT warehouseOutFk, supplierFk + INTO vWarehouseInventoryFk, vSupplierInventoryFk + FROM inventoryConfig; + + IF NOT vWarehouseInventoryFk OR NOT vSupplierInventoryFk THEN + CALL util.throw('Config variables are not set'); END IF; + -- Calcula el ultimo dia de vida para cada producto + CREATE OR REPLACE TEMPORARY TABLE tItemRange + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT i.id itemFk, + util.dayEnd(c.maxLanded + INTERVAL it.life DAY) ended, + it.life + FROM item i + LEFT JOIN ( + SELECT b.itemFk, MAX(t.landed) maxLanded + FROM buy b + JOIN entry e ON b.entryFk = e.id + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE t.landed BETWEEN vLifeScope AND COALESCE(vDated, vDateInventory) + AND t.warehouseInFk = vWarehouseFk + AND t.warehouseOutFk <> vWarehouseInventoryFk + AND it.life + AND NOT e.isExcludedFromAvailable + GROUP BY b.itemFk + ) c ON i.id = c.itemFk + JOIN itemType it ON it.id = i.typeFk + HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL; + CREATE OR REPLACE TEMPORARY TABLE tItemDiary( shipped DATE, `in` INT(11), @@ -37,8 +77,9 @@ BEGIN `order` TINYINT(3) UNSIGNED, clientType VARCHAR(20), claimFk INT(10) UNSIGNED, - inventorySupplierFk INT(10) - ); + inventorySupplierFk INT(10), + orderFk INT(10) UNSIGNED + ) ENGINE = MEMORY; INSERT INTO tItemDiary WITH entriesIn AS ( @@ -57,7 +98,8 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - ec.inventorySupplierFk + vSupplierInventoryFk inventorySupplierFk, + NULL orderFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk @@ -66,20 +108,20 @@ BEGIN OR (util.VN_CURDATE() AND tr.isReceived), 'DELIVERED', 'FREE') - JOIN vn.entryConfig ec WHERE tr.landed >= vDateInventory - AND vWarehouseFk = tr.warehouseInFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND tr.warehouseInFk = vWarehouseFk + AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT e.isRaid - ), entriesOut AS ( + ), + entriesOut AS ( SELECT tr.shipped, NULL, b.quantity, st.alertLevel, st.name stateName, - s.name , + s.name, e.invoiceNumber, e.id entryFk, s.id supplierFk, @@ -89,7 +131,8 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - ec.inventorySupplierFk + vSupplierInventoryFk, + NULL orderFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk @@ -102,39 +145,41 @@ BEGIN JOIN vn.entryConfig ec WHERE tr.shipped >= vDateInventory AND vWarehouseFk = tr.warehouseOutFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT w.isFeedStock AND NOT e.isRaid - ), sales AS ( - SELECT DATE(t.shipped) shipped, - s.quantity, - st2.alertLevel, - st2.name, - t.nickname, - t.refFk, - t.id ticketFk, - t.clientFk, - s.id saleFk, - st.`order`, - c.typeFk, - cb.claimFk - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - LEFT JOIN vn.state st ON st.`code` = ts.`code` - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), - 'DELIVERED', - IF (t.shipped > util.dayEnd(util.VN_CURDATE()), - 'FREE', - IFNULL(ts.code, 'FREE'))) - LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk - WHERE t.shipped >= vDateInventory - AND s.itemFk = vItemFk - AND vWarehouseFk = t.warehouseFk - ),sale AS ( + ), + sales AS ( + WITH itemSales AS ( + SELECT DATE(t.shipped) shipped, + s.quantity, + st2.alertLevel, + st2.name, + t.nickname, + t.refFk, + t.id ticketFk, + t.clientFk, + s.id saleFk, + st.`order`, + c.typeFk, + cb.claimFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id + LEFT JOIN vn.state st ON st.`code` = ts.`code` + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), + 'DELIVERED', + IF (t.shipped > util.dayEnd(util.VN_CURDATE()), + 'FREE', + IFNULL(ts.code, 'FREE'))) + LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk + WHERE t.shipped >= vDateInventory + AND s.itemFk = vItemFk + AND vWarehouseFk = t.warehouseFk + ) SELECT s.shipped, NULL `in`, s.quantity, @@ -144,39 +189,55 @@ BEGIN s.refFk, s.ticketFk, s.clientFk, - IF(stk.saleFk, TRUE, NULL), + IF(stk.saleFk, TRUE, FALSE), TRUE, s.saleFk, s.`order`, s.typeFk, s.claimFk, - NULL - FROM sales s + NULL, + NULL orderFk + FROM itemSales s LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk AND stk.stateFk = stPrep.id GROUP BY s.saleFk - ) SELECT shipped, - `in`, - `out`, - alertLevel, - stateName, - `name`, - reference, - origin, - clientFk, - isPicked, - isTicket, - lineFk, - `order`, - clientType, - claimFk, - inventorySupplierFk - FROM entriesIn + ), + orders AS ( + SELECT r.shipment, + NULL 'in', + r.amount, + NULL alertLevel, + NULL stateName, + NULL, + NULL invoiceNumber, + NULL entryFk, + NULL supplierFk, + FALSE, + FALSE isTicket, + NULL buyFk, + NULL 'order', + c.typeFk, + NULL claimFk, + NULL inventorySupplierFk, + o.id + FROM hedera.orderRow r + JOIN hedera.`order` o ON o.id = r.orderFk + JOIN tItemRange ir ON ir.itemFk = r.itemFk + JOIN vn.client c ON c.id = o.customer_id + WHERE r.shipment >= vDateInventory + AND (ir.ended IS NULL OR r.shipment <= ir.ended) + AND r.warehouseFk = vWarehouseFk + AND NOT o.confirmed + AND r.itemFk = vItemFk + ) + SELECT * FROM entriesIn UNION ALL SELECT * FROM entriesOut UNION ALL - SELECT * FROM sale + SELECT * FROM sales + UNION ALL + SELECT * FROM orders ORDER BY shipped, (inventorySupplierFk = clientFk) DESC, alertLevel DESC, @@ -186,8 +247,7 @@ BEGIN `in` DESC, `out` DESC; - IF vDate IS NULL THEN - + IF vDated IS NULL THEN SET @a := 0; SET @currentLineFk := 0; SET @shipped := ''; @@ -211,16 +271,16 @@ BEGIN t.isPicked, t.clientType, t.claimFk, - t.`order` + t.`order`, + t.orderFk FROM tItemDiary t LEFT JOIN alertLevel a ON a.id = t.alertLevel; - ELSE SELECT IFNULL(SUM(IFNULL(`in`, 0)) - SUM(IFNULL(`out`, 0)), 0) INTO @a FROM tItemDiary - WHERE shipped < vDate; + WHERE shipped < vDated; - SELECT vDate shipped, + SELECT vDated shipped, 0 alertLevel, 0 stateName, 0 origin, @@ -236,7 +296,8 @@ BEGIN 0 isPicked, 0 clientType, 0 claimFk, - NULL `order` + NULL `order`, + 0 orderFk UNION ALL SELECT shipped, alertlevel, @@ -253,11 +314,14 @@ BEGIN isPicked, clientType, claimFk, - `order` + `order`, + orderFk FROM tItemDiary - WHERE shipped >= vDate; + WHERE shipped >= vDated; END IF; - DROP TEMPORARY TABLE tItemDiary; + DROP TEMPORARY TABLE + tItemDiary, + tItemRange; END$$ DELIMITER ; From cf7de14de6e5c9babc89d70c20224aa96c665c3f Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 4 Jul 2024 11:34:55 +0200 Subject: [PATCH 013/123] refs #6769 Changes, with error no database selected --- db/routines/vn/procedures/item_getBalance.sql | 95 ++++++++----------- 1 file changed, 38 insertions(+), 57 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 561957452..dc4e16789 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -61,29 +61,11 @@ BEGIN JOIN itemType it ON it.id = i.typeFk HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL; - CREATE OR REPLACE TEMPORARY TABLE tItemDiary( - shipped DATE, - `in` INT(11), - `out` INT(11), - alertLevel INT(11), - stateName VARCHAR(20), - `name` VARCHAR(50), - reference VARCHAR(50), - origin INT(11), - clientFk INT(11), - isPicked INT(11), - isTicket TINYINT(1), - lineFk INT(11), - `order` TINYINT(3) UNSIGNED, - clientType VARCHAR(20), - claimFk INT(10) UNSIGNED, - inventorySupplierFk INT(10), - orderFk INT(10) UNSIGNED - ) ENGINE = MEMORY; - - INSERT INTO tItemDiary + CREATE OR REPLACE TEMPORARY TABLE tItemDiary + ENGINE = MEMORY WITH entriesIn AS ( - SELECT tr.landed shipped, + SELECT 'entry' `type`, + tr.landed shipped, b.quantity `in`, NULL `out`, st.alertLevel , @@ -98,13 +80,12 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - vSupplierInventoryFk inventorySupplierFk, - NULL orderFk + vSupplierInventoryFk inventorySupplierFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() + JOIN vn.state st ON st.`code` = IF(tr.landed < util.VN_CURDATE() OR (util.VN_CURDATE() AND tr.isReceived), 'DELIVERED', 'FREE') @@ -116,7 +97,8 @@ BEGIN AND NOT e.isRaid ), entriesOut AS ( - SELECT tr.shipped, + SELECT 'entry', + tr.shipped, NULL, b.quantity, st.alertLevel, @@ -131,8 +113,7 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - vSupplierInventoryFk, - NULL orderFk + vSupplierInventoryFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk @@ -180,7 +161,8 @@ BEGIN AND s.itemFk = vItemFk AND vWarehouseFk = t.warehouseFk ) - SELECT s.shipped, + SELECT 'ticket', + s.shipped, NULL `in`, s.quantity, s.alertLevel, @@ -195,8 +177,7 @@ BEGIN s.`order`, s.typeFk, s.claimFk, - NULL, - NULL orderFk + NULL FROM itemSales s LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk @@ -204,23 +185,23 @@ BEGIN GROUP BY s.saleFk ), orders AS ( - SELECT r.shipment, + SELECT 'order' `type`, + r.shipment, NULL 'in', r.amount, NULL alertLevel, NULL stateName, - NULL, + c.name, NULL invoiceNumber, - NULL entryFk, - NULL supplierFk, + o.id origin, + c.id, FALSE, FALSE isTicket, NULL buyFk, NULL 'order', c.typeFk, NULL claimFk, - NULL inventorySupplierFk, - o.id + NULL FROM hedera.orderRow r JOIN hedera.`order` o ON o.id = r.orderFk JOIN tItemRange ir ON ir.itemFk = r.itemFk @@ -252,7 +233,8 @@ BEGIN SET @currentLineFk := 0; SET @shipped := ''; - SELECT DATE(@shipped:= t.shipped) shipped, + SELECT t.type, + DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, t.origin, @@ -271,8 +253,7 @@ BEGIN t.isPicked, t.clientType, t.claimFk, - t.`order`, - t.orderFk + t.`order` FROM tItemDiary t LEFT JOIN alertLevel a ON a.id = t.alertLevel; ELSE @@ -280,26 +261,27 @@ BEGIN FROM tItemDiary WHERE shipped < vDated; - SELECT vDated shipped, - 0 alertLevel, - 0 stateName, - 0 origin, - '' reference, - 0 clientFk, + SELECT NULL `type`, + vDated shipped, + NULL alertLevel, + NULL stateName, + NULL origin, + NULL reference, + NULL clientFk, 'Inventario calculado', @a invalue, NULL `out`, @a balance, - 0 lastPreparedLineFk, - 0 isTicket, - 0 lineFk, - 0 isPicked, - 0 clientType, - 0 claimFk, - NULL `order`, - 0 orderFk + NULL lastPreparedLineFk, + NULL isTicket, + NULL lineFk, + NULL isPicked, + NULL clientType, + NULL claimFk, + NULL `order` UNION ALL - SELECT shipped, + SELECT `type`, + shipped, alertlevel, stateName, origin, @@ -314,8 +296,7 @@ BEGIN isPicked, clientType, claimFk, - `order`, - orderFk + `order` FROM tItemDiary WHERE shipped >= vDated; END IF; From 1fff3aa681acf5789975d1fad1a4ec051c9baa47 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 4 Jul 2024 12:34:56 +0200 Subject: [PATCH 014/123] feat: refs #7670 addSale --- modules/ticket/back/methods/ticket/addSale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/addSale.js b/modules/ticket/back/methods/ticket/addSale.js index 8dc7a633c..ad393fc65 100644 --- a/modules/ticket/back/methods/ticket/addSale.js +++ b/modules/ticket/back/methods/ticket/addSale.js @@ -70,7 +70,7 @@ module.exports = Self => { quantity: quantity }, myOptions); - await Self.rawSql('CALL vn.sale_calculateComponent(?, NULL)', [newSale.id], myOptions); + await Self.rawSql('CALL vn.sale_calculateComponent(?, ?)', [newSale.id, 'renewPrices'], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [id], myOptions); const sale = await models.Sale.findById(newSale.id, { From 6f0196d656fb8ffcdcfb20bc4979f9a23bc8a963 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 07:06:40 +0200 Subject: [PATCH 015/123] refs #6769 Changes --- db/routines/vn/procedures/item_getBalance.sql | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index dc4e16789..c2e0bc0c1 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -6,13 +6,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`( ) BEGIN /** - * Calcula el disponible. + * Calcula el balance de un artículo. * * @vItemFk Id de artículo * @vWarehouseFk Id de almacén - * @vDated Fecha - * Si la fecha es NULL, muestra el histórico desde el inventario. - * Si la fecha no es NULL, muestra histórico desde la fecha de vDated. + * @vDated Fecha a calcular, si es NULL muestra el histórico desde el inventario */ DECLARE vDateInventory DATETIME; DECLARE vLifeScope DATE; @@ -64,7 +62,8 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tItemDiary ENGINE = MEMORY WITH entriesIn AS ( - SELECT 'entry' `type`, + SELECT 'entry' originType, + e.id origin, tr.landed shipped, b.quantity `in`, NULL `out`, @@ -72,8 +71,8 @@ BEGIN st.name stateName, s.name `name`, e.invoiceNumber reference, - e.id origin, - s.id clientFk, + 'supplier' entityType, + s.id entity, IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, FALSE isTicket, b.id lineFk, @@ -98,6 +97,7 @@ BEGIN ), entriesOut AS ( SELECT 'entry', + e.id originType, tr.shipped, NULL, b.quantity, @@ -105,8 +105,8 @@ BEGIN st.name stateName, s.name, e.invoiceNumber, - e.id entryFk, - s.id supplierFk, + 'supplier' entityType, + s.id entity, IF(st.`code` = 'DELIVERED' , TRUE, FALSE), FALSE isTicket, b.id, @@ -123,7 +123,6 @@ BEGIN OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), 'DELIVERED', 'FREE') - JOIN vn.entryConfig ec WHERE tr.shipped >= vDateInventory AND vWarehouseFk = tr.warehouseOutFk AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) @@ -141,7 +140,8 @@ BEGIN t.nickname, t.refFk, t.id ticketFk, - t.clientFk, + 'client' entityType, + t.clientFk entity, s.id saleFk, st.`order`, c.typeFk, @@ -162,6 +162,7 @@ BEGIN AND vWarehouseFk = t.warehouseFk ) SELECT 'ticket', + s.ticketFk, s.shipped, NULL `in`, s.quantity, @@ -169,8 +170,8 @@ BEGIN s.name, s.nickname, s.refFk, - s.ticketFk, - s.clientFk, + s.entityType, + s.entity, IF(stk.saleFk, TRUE, FALSE), TRUE, s.saleFk, @@ -185,7 +186,8 @@ BEGIN GROUP BY s.saleFk ), orders AS ( - SELECT 'order' `type`, + SELECT 'order' originType, + o.id origin, r.shipment, NULL 'in', r.amount, @@ -193,7 +195,7 @@ BEGIN NULL stateName, c.name, NULL invoiceNumber, - o.id origin, + 'client' entityType, c.id, FALSE, FALSE isTicket, @@ -220,7 +222,7 @@ BEGIN UNION ALL SELECT * FROM orders ORDER BY shipped, - (inventorySupplierFk = clientFk) DESC, + (inventorySupplierFk = entity) DESC, alertLevel DESC, isTicket, `order` DESC, @@ -233,13 +235,14 @@ BEGIN SET @currentLineFk := 0; SET @shipped := ''; - SELECT t.type, + SELECT t.originType, + t.origin, DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, - t.origin, t.reference, - t.clientFk, + t.entityType, + t.entity, t.name, t.`in` invalue, t.`out`, @@ -261,13 +264,14 @@ BEGIN FROM tItemDiary WHERE shipped < vDated; - SELECT NULL `type`, + SELECT NULL originType, + NULL origin, vDated shipped, NULL alertLevel, NULL stateName, - NULL origin, NULL reference, - NULL clientFk, + NULL entityType, + NULL entity, 'Inventario calculado', @a invalue, NULL `out`, @@ -280,13 +284,14 @@ BEGIN NULL claimFk, NULL `order` UNION ALL - SELECT `type`, + SELECT originType, + origin, shipped, alertlevel, stateName, - origin, - reference, - clientFk, + reference, + entityType, + entity, name, `in`, `out`, @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), From 50c9ded103a66f7b667f6ec0f4da4ccfe71e5a86 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 08:38:40 +0200 Subject: [PATCH 016/123] refs #6769 Fix --- db/routines/vn/procedures/item_getBalance.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index c2e0bc0c1..a12397aa6 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -34,7 +34,8 @@ BEGIN END IF; -- Calcula el ultimo dia de vida para cada producto - CREATE OR REPLACE TEMPORARY TABLE tItemRange + -- Tiene tmp a propósito, porque si no falla al utilizarlo en el WITH + CREATE OR REPLACE TEMPORARY TABLE tmp.itemRange (PRIMARY KEY (itemFk)) ENGINE = MEMORY SELECT i.id itemFk, @@ -206,7 +207,7 @@ BEGIN NULL FROM hedera.orderRow r JOIN hedera.`order` o ON o.id = r.orderFk - JOIN tItemRange ir ON ir.itemFk = r.itemFk + JOIN tmp.itemRange ir ON ir.itemFk = r.itemFk JOIN vn.client c ON c.id = o.customer_id WHERE r.shipment >= vDateInventory AND (ir.ended IS NULL OR r.shipment <= ir.ended) @@ -308,6 +309,6 @@ BEGIN DROP TEMPORARY TABLE tItemDiary, - tItemRange; + tmp.itemRange; END$$ DELIMITER ; From e3db143b443c7ecdc1412b7627c120a05d534207 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 5 Jul 2024 08:55:24 +0200 Subject: [PATCH 017/123] feat: refs #7348 campo en json --- modules/client/back/models/client.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index f3eb9919b..f24f69ae7 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -144,6 +144,9 @@ }, "recommendedCredit": { "type": "number" + }, + "hasDailyInvoice": { + "type": "boolean" } }, From d4b4c0fafe9397d8389586dbecebbae8d8d73ec2 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 5 Jul 2024 09:04:38 +0200 Subject: [PATCH 018/123] feat: refs #7348 campos a modificar --- modules/client/back/methods/client/updateFiscalData.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index 851648658..8ed55b856 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -99,6 +99,10 @@ module.exports = Self => { { arg: 'hasElectronicInvoice', type: 'boolean' + }, + { + arg: 'hasDailyInvoice', + type: 'boolean' } ], returns: { @@ -117,8 +121,6 @@ module.exports = Self => { const myOptions = {}; const models = Self.app.models; const args = ctx.args; - const userId = ctx.req.accessToken.userId; - const $t = ctx.req.__; if (typeof options == 'object') Object.assign(myOptions, options); From aa46d7a53659188933d6cc4a1307f6961f74f168 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 09:46:09 +0200 Subject: [PATCH 019/123] refs #6769 item_getBalance optimization --- db/routines/vn/procedures/item_getBalance.sql | 68 +++++++++++-------- .../11135-whiteErica/00-firstScript.sql | 1 + 2 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 db/versions/11135-whiteErica/00-firstScript.sql diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index a12397aa6..15be8c926 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -21,14 +21,14 @@ BEGIN FROM config c JOIN util.config uc; - SELECT COALESCE(vDated, vDateInventory) - INTERVAL MAX(life) DAY + SELECT vDateInventory - INTERVAL MAX(life) DAY INTO vLifeScope FROM itemType; SELECT warehouseOutFk, supplierFk INTO vWarehouseInventoryFk, vSupplierInventoryFk FROM inventoryConfig; - + IF NOT vWarehouseInventoryFk OR NOT vSupplierInventoryFk THEN CALL util.throw('Config variables are not set'); END IF; @@ -50,30 +50,32 @@ BEGIN JOIN warehouse w ON w.id = t.warehouseInFk JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk - WHERE t.landed BETWEEN vLifeScope AND COALESCE(vDated, vDateInventory) + WHERE t.landed BETWEEN vLifeScope AND vDateInventory AND t.warehouseInFk = vWarehouseFk AND t.warehouseOutFk <> vWarehouseInventoryFk AND it.life + AND i.id = vItemFk AND NOT e.isExcludedFromAvailable GROUP BY b.itemFk ) c ON i.id = c.itemFk JOIN itemType it ON it.id = i.typeFk - HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL; + WHERE i.id = vItemFk + HAVING ended >= vDateInventory OR life IS NULL; CREATE OR REPLACE TEMPORARY TABLE tItemDiary ENGINE = MEMORY WITH entriesIn AS ( SELECT 'entry' originType, - e.id origin, + e.id originId, tr.landed shipped, b.quantity `in`, NULL `out`, st.alertLevel , st.name stateName, - s.name `name`, e.invoiceNumber reference, 'supplier' entityType, - s.id entity, + s.id entityId, + s.name entityName, IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, FALSE isTicket, b.id lineFk, @@ -104,10 +106,10 @@ BEGIN b.quantity, st.alertLevel, st.name stateName, - s.name, e.invoiceNumber, 'supplier' entityType, - s.id entity, + s.id entityId, + s.name, IF(st.`code` = 'DELIVERED' , TRUE, FALSE), FALSE isTicket, b.id, @@ -125,7 +127,7 @@ BEGIN 'DELIVERED', 'FREE') WHERE tr.shipped >= vDateInventory - AND vWarehouseFk = tr.warehouseOutFk + AND tr.warehouseOutFk = vWarehouseFk AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable @@ -138,29 +140,30 @@ BEGIN s.quantity, st2.alertLevel, st2.name, - t.nickname, t.refFk, t.id ticketFk, 'client' entityType, - t.clientFk entity, + t.clientFk entityId, + t.nickname, s.id saleFk, st.`order`, c.typeFk, cb.claimFk FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - LEFT JOIN vn.state st ON st.`code` = ts.`code` + LEFT JOIN vn.ticketLastState tls ON tls.ticketFk = t.id + LEFT JOIN vn.ticketTracking tt ON tt.id = tls.ticketTrackingFk + LEFT JOIN vn.state st ON st.id = tt.stateFk JOIN vn.client c ON c.id = t.clientFk JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), 'DELIVERED', IF (t.shipped > util.dayEnd(util.VN_CURDATE()), 'FREE', - IFNULL(ts.code, 'FREE'))) - LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk + IFNULL(st.code, 'FREE'))) + LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id WHERE t.shipped >= vDateInventory AND s.itemFk = vItemFk - AND vWarehouseFk = t.warehouseFk + AND t.warehouseFk = vWarehouseFk ) SELECT 'ticket', s.ticketFk, @@ -169,10 +172,10 @@ BEGIN s.quantity, s.alertLevel, s.name, - s.nickname, s.refFk, s.entityType, - s.entity, + s.entityId, + s.nickname, IF(stk.saleFk, TRUE, FALSE), TRUE, s.saleFk, @@ -188,16 +191,16 @@ BEGIN ), orders AS ( SELECT 'order' originType, - o.id origin, + o.id originId, r.shipment, NULL 'in', r.amount, NULL alertLevel, NULL stateName, - c.name, NULL invoiceNumber, 'client' entityType, c.id, + c.name, FALSE, FALSE isTicket, NULL buyFk, @@ -212,6 +215,10 @@ BEGIN WHERE r.shipment >= vDateInventory AND (ir.ended IS NULL OR r.shipment <= ir.ended) AND r.warehouseFk = vWarehouseFk + AND r.created >= ( + SELECT SUBTIME(util.VN_NOW(), reserveTime) + FROM hedera.orderConfig + ) AND NOT o.confirmed AND r.itemFk = vItemFk ) @@ -223,7 +230,7 @@ BEGIN UNION ALL SELECT * FROM orders ORDER BY shipped, - (inventorySupplierFk = entity) DESC, + (inventorySupplierFk = entityId) DESC, alertLevel DESC, isTicket, `order` DESC, @@ -237,14 +244,14 @@ BEGIN SET @shipped := ''; SELECT t.originType, - t.origin, + t.originId, DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, t.reference, t.entityType, - t.entity, - t.name, + t.entityId, + t.entityName, t.`in` invalue, t.`out`, @a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance, @@ -266,13 +273,13 @@ BEGIN WHERE shipped < vDated; SELECT NULL originType, - NULL origin, + NULL originId, vDated shipped, NULL alertLevel, NULL stateName, NULL reference, NULL entityType, - NULL entity, + NULL entityId, 'Inventario calculado', @a invalue, NULL `out`, @@ -286,14 +293,15 @@ BEGIN NULL `order` UNION ALL SELECT originType, - origin, + originId, shipped, alertlevel, stateName, reference, entityType, - entity, - name, `in`, + entityId, + entityName, + `in`, `out`, @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), 0, diff --git a/db/versions/11135-whiteErica/00-firstScript.sql b/db/versions/11135-whiteErica/00-firstScript.sql new file mode 100644 index 000000000..902608a3e --- /dev/null +++ b/db/versions/11135-whiteErica/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX travel_landed_IDX USING BTREE ON vn.travel (landed DESC,warehouseInFk,warehouseOutFk); From 4b0a08d9653f1383666e53eb1eb1b268baf33c0b Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 10:57:46 +0200 Subject: [PATCH 020/123] refactor: refs #7684 vehicle warehouseFk fix --- db/versions/11140-azurePhormium/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/11140-azurePhormium/00-firstScript.sql diff --git a/db/versions/11140-azurePhormium/00-firstScript.sql b/db/versions/11140-azurePhormium/00-firstScript.sql new file mode 100644 index 000000000..7c89110bb --- /dev/null +++ b/db/versions/11140-azurePhormium/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.vehicle DROP FOREIGN KEY provinceFk; +ALTER TABLE vn.vehicle + ADD CONSTRAINT vehicle_warehouse_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE; From d0e4decf1e5dcf28011adb313d96fb674fd3db6e Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 8 Jul 2024 11:05:11 +0200 Subject: [PATCH 021/123] refs #6952 add producer sql trad --- print/templates/reports/invoice/invoice.html | 2 +- print/templates/reports/invoice/locale/en.yml | 2 +- print/templates/reports/invoice/locale/es.yml | 3 ++- print/templates/reports/invoice/sql/sales.sql | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index af1aaa423..c4e0b818a 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -104,7 +104,7 @@ {{sale.itemFk}} {{sale.quantity}} - {{sale.concept}} + {{sale.concept}} {{sale.subName}} {{sale.price | currency('EUR', $i18n.locale)}} {{(sale.discount / 100) | percentage}} {{sale.vatType}} diff --git a/print/templates/reports/invoice/locale/en.yml b/print/templates/reports/invoice/locale/en.yml index 336592f0c..336384457 100644 --- a/print/templates/reports/invoice/locale/en.yml +++ b/print/templates/reports/invoice/locale/en.yml @@ -34,4 +34,4 @@ plantPassport: Plant passport observations: Observations wireTransfer: "Pay method: Transferencia" accountNumber: "Account number: {0}" -services: Services \ No newline at end of file +services: Services diff --git a/print/templates/reports/invoice/locale/es.yml b/print/templates/reports/invoice/locale/es.yml index 32f6fc708..879977e39 100644 --- a/print/templates/reports/invoice/locale/es.yml +++ b/print/templates/reports/invoice/locale/es.yml @@ -34,4 +34,5 @@ plantPassport: Pasaporte fitosanitario observations: Observaciones wireTransfer: "Forma de pago: Transferencia" accountNumber: "Número de cuenta: {0}" -services: Servicios \ No newline at end of file +services: Servicios + diff --git a/print/templates/reports/invoice/sql/sales.sql b/print/templates/reports/invoice/sql/sales.sql index 8e5ad1102..2d29cc520 100644 --- a/print/templates/reports/invoice/sql/sales.sql +++ b/print/templates/reports/invoice/sql/sales.sql @@ -8,7 +8,8 @@ SELECT s.itemFk, s.concept, tc.code vatType, - it.isPackaging + it.isPackaging, + i.subName FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.supplier su ON su.id = io.companyFk @@ -38,6 +39,7 @@ SELECT NULL, ts.description, tc.code, + NULL, NULL FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref From f57ab7248233b260fac97baaad5c18005ce5e340 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 13:17:29 +0200 Subject: [PATCH 022/123] refactor: refs #7580 Fix and improvement --- .../vn/procedures/collection_setParking.sql | 17 +++-- .../vn/procedures/saleGroup_setParking.sql | 20 ++++-- db/routines/vn/procedures/setParking.sql | 65 ++++++++----------- .../vn/procedures/ticket_setNextState.sql | 17 ++++- .../vn/procedures/ticket_setParking.sql | 22 +++++-- 5 files changed, 79 insertions(+), 62 deletions(-) diff --git a/db/routines/vn/procedures/collection_setParking.sql b/db/routines/vn/procedures/collection_setParking.sql index 73aa87bfb..5f6ca75da 100644 --- a/db/routines/vn/procedures/collection_setParking.sql +++ b/db/routines/vn/procedures/collection_setParking.sql @@ -1,15 +1,18 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`( + vSelf INT, + vParkingFk INT +) +BEGIN /** * Aparca una colección en un parking. * - * @param vCollectionFk Id de la colección - * @param vParkingFk Id del parking + * @param vSelf Id colección + * @param vParkingFk Id parking */ - REPLACE vn.ticketParking(ticketFk, parkingFk) + REPLACE ticketParking(ticketFk, parkingFk) SELECT tc.ticketFk, vParkingFk - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vCollectionFk; + FROM ticketCollection tc + WHERE tc.collectionFk = vSelf; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/saleGroup_setParking.sql b/db/routines/vn/procedures/saleGroup_setParking.sql index 4872f74c6..551ca6386 100644 --- a/db/routines/vn/procedures/saleGroup_setParking.sql +++ b/db/routines/vn/procedures/saleGroup_setParking.sql @@ -1,17 +1,25 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`( + vSaleGroupFk VARCHAR(8), + vParkingFk INT +) +BEGIN /** - * Aparca una preparación previa en un parking + * Aparca una preparación previa en un parking. * * @param vSaleGroupFk id de la preparación previa * @param vParkingFk id del parking */ - UPDATE vn.saleGroup sg + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + RESIGNAL; + END; + + UPDATE saleGroup sg SET sg.parkingFk = vParkingFk WHERE sg.id = vSaleGroupFk - AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND sg.created >= util.VN_CURDATE() - INTERVAL 1 WEEK; - CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk)); + CALL ticket_setNextState(ticket_get(vSaleGroupFk)); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql index d6def07de..c4e1fd19f 100644 --- a/db/routines/vn/procedures/setParking.sql +++ b/db/routines/vn/procedures/setParking.sql @@ -1,6 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`( + vParam VARCHAR(8), + vParkingCode VARCHAR(8) +) +BEGIN /** * Aparca una colección, un ticket, un saleGroup o un shelving en un parking * @@ -8,56 +11,40 @@ proc: BEGIN * @param vParkingCode código del parking */ DECLARE vParkingFk INT; - DECLARE vIsSaleGroup BOOL; - DECLARE vIsTicket BOOL; - DECLARE vIsCollection BOOL; + DECLARE vLastWeek DATE; - SET vParkingCode = replace(vParkingCode,' ',''); + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SET vParkingCode = REPLACE(vParkingCode, ' ', ''); SELECT id INTO vParkingFk - FROM vn.parking + FROM parking WHERE code = vParkingCode COLLATE utf8_unicode_ci; IF vParkingFk IS NULL THEN CALL util.throw('parkingNotExist'); - LEAVE proc; END IF; - IF vParam REGEXP '^[0-9]+$' THEN - -- Se comprueba si es una preparación previa - SELECT COUNT(*) INTO vIsSaleGroup - FROM vn.saleGroup sg - WHERE sg.id = vParam; + IF vParam REGEXP '^[0-9]+$' THEN + SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK; - IF vIsSaleGroup THEN - CALL vn.saleGroup_setParking(vParam, vParkingFk); - LEAVE proc; - END IF; - - -- Se comprueba si es un ticket - SELECT COUNT(*) INTO vIsTicket - FROM vn.ticket t - WHERE t.id = vParam - AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - IF vIsTicket THEN - CALL vn.ticket_setParking(vParam, vParkingFk); - LEAVE proc; - END IF; - - -- Se comprueba si es una coleccion de tickets - SELECT COUNT(*) INTO vIsCollection - FROM vn.collection c - WHERE c.id = vParam - AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - IF vIsCollection THEN - CALL vn.collection_setParking(vParam, vParkingFk); - LEAVE proc; + -- Comprobamos si es una prep. previa, ticket o colección + IF (SELECT TRUE FROM saleGroup sg WHERE sg.id = vParam) THEN + CALL saleGroup_setParking(vParam, vParkingFk); + ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam shipped >= vLastWeek) THEN + CALL ticket_setParking(vParam, vParkingFk); + ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN + CALL collection_setParking(vParam, vParkingFk); END IF; ELSE -- Por descarte, se considera una matrícula - CALL vn.shelving_setParking(vParam, vParkingFk); + CALL shelving_setParking(vParam, vParkingFk); END IF; + + COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_setNextState.sql b/db/routines/vn/procedures/ticket_setNextState.sql index d13cd53f0..b09309a47 100644 --- a/db/routines/vn/procedures/ticket_setNextState.sql +++ b/db/routines/vn/procedures/ticket_setNextState.sql @@ -1,14 +1,21 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`( + vSelf INT +) BEGIN /** - * Cambia el estado del ticket al siguiente estado según la tabla state + * Cambia el estado del ticket al siguiente estado según la tabla state. * - * @param vSelf id dle ticket + * @param vSelf Id ticket */ DECLARE vStateFk INT; DECLARE vNewStateFk INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + RESIGNAL; + END; + SELECT stateFk INTO vStateFk FROM ticketState WHERE ticketFk = vSelf; @@ -17,6 +24,10 @@ BEGIN FROM state WHERE id = vStateFk; + IF vNewStateFk IS NULL THEN + CALL util.throw('The ticket not have next state'); + END IF; + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) VALUES (vNewStateFk, vSelf, account.myUser_getId()); END$$ diff --git a/db/routines/vn/procedures/ticket_setParking.sql b/db/routines/vn/procedures/ticket_setParking.sql index 54c64daea..7935e0d60 100644 --- a/db/routines/vn/procedures/ticket_setParking.sql +++ b/db/routines/vn/procedures/ticket_setParking.sql @@ -1,11 +1,14 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`( + vSelf INT, + vParkingFk INT +) +BEGIN /** - * Aparca un ticket en un parking + * Aparca un ticket en un parking. * - * @param vTicketFk id del ticket - * @param vParkingFk id del parking + * @param vSelf Id ticket + * @param vParkingFk Id parking */ DECLARE vDone INT DEFAULT FALSE; DECLARE vCollectionTicketFk INT; @@ -14,16 +17,21 @@ proc: BEGIN FROM ticket t LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk - WHERE t.id = vTicketFk; + WHERE t.id = vSelf; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + RESIGNAL; + END; + INSERT INTO vn.ticketParking(ticketFk, parkingFk) SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk FROM ticket t LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk - WHERE t.id = vTicketFk + WHERE t.id = vSelf ON DUPLICATE KEY UPDATE parkingFk = vParkingFk; OPEN vCursor; From 73b43aa254f4896261c1cc692fb6fd2dc5f8629e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 13:22:10 +0200 Subject: [PATCH 023/123] refactor: refs #7580 Fixes --- db/routines/vn/procedures/setParking.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql index c4e1fd19f..107ef66f4 100644 --- a/db/routines/vn/procedures/setParking.sql +++ b/db/routines/vn/procedures/setParking.sql @@ -33,9 +33,9 @@ BEGIN SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK; -- Comprobamos si es una prep. previa, ticket o colección - IF (SELECT TRUE FROM saleGroup sg WHERE sg.id = vParam) THEN + IF (SELECT TRUE FROM saleGroup WHERE id = vParam) THEN CALL saleGroup_setParking(vParam, vParkingFk); - ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam shipped >= vLastWeek) THEN + ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam AND shipped >= vLastWeek) THEN CALL ticket_setParking(vParam, vParkingFk); ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN CALL collection_setParking(vParam, vParkingFk); From 7279feab12f6050cd4aa4840c370082db48304c6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:33:31 +0200 Subject: [PATCH 024/123] feat: refs #7505 Changes --- .../cache/procedures/visible_refresh.sql | 2 +- .../vn/procedures/item_calcVisible.sql | 22 +++++++++---------- .../vn/procedures/multipleInventory.sql | 19 ++++++++-------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index b200e86f2..4feffde8e 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_calcVisible(v_warehouse, util.VN_CURDATE(), NULL); + CALL vn.item_calcVisible(NULL, util.VN_CURDATE(), v_warehouse); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index f7eee661b..728c94276 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,8 +1,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( - vWarehouseFk INT, - vDated INT, - vItemFk INT + vSelf INT, + vDated DATE, + vWarehouseFk INT ) BEGIN /** @@ -10,12 +10,12 @@ BEGIN * * @param vWarehouse Warehouse id * @param vDated Max date to filter - * @param vItemFk Item id + * @param vSelf Item id * @param tmp.itemVisible(item_id, stock, visible) */ DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; - INSERT INTO tmp.itemVisible (item_id, visible) + INSERT INTO tmp.itemVisible(item_id, visible) SELECT itemFk, SUM(quantity) FROM ( SELECT i.itemFk, i.quantity @@ -29,8 +29,8 @@ BEGIN WHERE st.created > vDated AND (s.isPicked OR st.isChecked) ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk - WHERE i.warehouseFk = vWarehouseFk - AND (vItemFk IS NULL OR i.itemFk = vItemFk) + WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk + AND (vSelf IS NULL OR i.itemFk = vSelf) AND (s.isPicked OR i.reserved OR stPrevious.saleFk) AND i.shipped >= vDated AND i.shipped < vTomorrow UNION ALL @@ -38,8 +38,8 @@ BEGIN FROM itemEntryIn WHERE isReceived AND landed >= vDated AND landed < vTomorrow - AND warehouseInFk = vWarehouseFk - AND (vItemFk IS NULL OR itemFk = vItemFk) + AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk + AND (vSelf IS NULL OR itemFk = vSelf) AND NOT isVirtualStock UNION ALL SELECT itemFk, quantity @@ -47,8 +47,8 @@ BEGIN WHERE isDelivered AND shipped >= vDated AND shipped < vTomorrow - AND warehouseOutFk = vWarehouseFk - AND (vItemFk IS NULL OR itemFk = vItemFk) + AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk + AND (vSelf IS NULL OR itemFk = vSelf) ) t GROUP BY itemFk ON DUPLICATE KEY UPDATE diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index dd3bd6f17..3e0cf72c7 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -83,19 +83,19 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.visible_refresh(vCalc, FALSE, vWarehouseFk); + CALL cache.stock_refresh(false); - CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc + CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, visible - FROM cache.visible - WHERE calc_id = vCalc; + SELECT item_id, amount stock, amount visible + FROM cache.stock + WHERE warehouse_id = vWarehouseFk; - CALL item_calcVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_calcVisible(NULL, vWarehouseFk, util.VN_CURDATE()); UPDATE tmp.itemInventory it - JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id - SET it.visible = it.visible + ivc.visible; + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = it.visible + iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -168,7 +168,6 @@ proc: BEGIN tmp.itemCalc, tmp.itemAtp, tItemInventoryCalc, - tItemVisibleCalc, - tmp.itemAtp; + tmp.itemVisible; END$$ DELIMITER ; From 86acc644fea1069e7f94ec52b76ef7a4bafaa635 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:38:07 +0200 Subject: [PATCH 025/123] feat: refs #7505 Changes --- db/routines/vn/procedures/multipleInventory.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 3e0cf72c7..33eb0b0ed 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -83,7 +83,7 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.stock_refresh(false); + CALL cache.stock_refresh(false); CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) @@ -92,7 +92,7 @@ proc: BEGIN FROM cache.stock WHERE warehouse_id = vWarehouseFk; - CALL item_calcVisible(NULL, vWarehouseFk, util.VN_CURDATE()); + CALL item_calcVisible(NULL, vWarehouseFk, vDate); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = it.visible + iv.visible; From 29f9fa0ce36d6c1b9eab9c220b48d9454451f953 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:45:55 +0200 Subject: [PATCH 026/123] feat: refs #7505 Optimization --- .../vn/procedures/multipleInventory.sql | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 33eb0b0ed..6cd584c6e 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -10,7 +10,7 @@ proc: BEGIN DECLARE vDateTo DATETIME; DECLARE vDateToTomorrow DATETIME; DECLARE vDefaultDayRange INT; - DECLARE vCalc INT; + DECLARE vCalcFk INT; IF vDate < util.VN_CURDATE() THEN LEAVE proc; @@ -83,19 +83,18 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.stock_refresh(false); + CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, amount stock, amount visible - FROM cache.stock - WHERE warehouse_id = vWarehouseFk; + SELECT item_id, visible + FROM cache.visible + WHERE calc_id = vCalcFk; - CALL item_calcVisible(NULL, vWarehouseFk, vDate); UPDATE tmp.itemInventory it - JOIN tmp.itemVisible iv ON iv.item_id = it.id - SET it.visible = it.visible + iv.visible; + JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id + SET it.visible = it.visible + ivc.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -168,6 +167,6 @@ proc: BEGIN tmp.itemCalc, tmp.itemAtp, tItemInventoryCalc, - tmp.itemVisible; + tItemVisibleCalc; END$$ DELIMITER ; From 4dcc8b02a597eb818d79029aa8a3ee6e6cbdc643 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 10:01:32 +0200 Subject: [PATCH 027/123] feat: refs #7685 delivery coordinates --- .../procedures/address_updateCorordinates.sql | 30 +++++++++++++++++++ .../vn/triggers/delivery_beforeInsert.sql | 12 ++------ .../vn/triggers/delivery_beforeUpdate.sql | 12 ++------ 3 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 db/routines/vn/procedures/address_updateCorordinates.sql diff --git a/db/routines/vn/procedures/address_updateCorordinates.sql b/db/routines/vn/procedures/address_updateCorordinates.sql new file mode 100644 index 000000000..2004cd180 --- /dev/null +++ b/db/routines/vn/procedures/address_updateCorordinates.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`address_updateCorordinates`( + vTicketFk INT, + vLongitude INT, + vLatitude INT) +BEGIN +/** + * Actualiza las coordenadas de una direccion + * + * @param vTicketFk id del ticket + * @param vLongitude longitud de la direccion + * @param vLatitude latitud de la dirrecion + */ + DECLARE vAddressFK INT; + + START TRANSACTION; + + SELECT addressFK INTO vAddressFK + FROM ticket + WHERE id = vTicketFk + FOR UPDATE; + + UPDATE address + SET longitude = vLongitude, + latitude = vLatitude + WHERE id = vAddressFK; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/delivery_beforeInsert.sql b/db/routines/vn/triggers/delivery_beforeInsert.sql index 89431c30f..c9679ed13 100644 --- a/db/routines/vn/triggers/delivery_beforeInsert.sql +++ b/db/routines/vn/triggers/delivery_beforeInsert.sql @@ -4,16 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert FOR EACH ROW BEGIN - IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) THEN + CALL address_updateCorordinates(NEW.ticketFk,NEW.longitude,NEW.latitude); END IF; END$$ diff --git a/db/routines/vn/triggers/delivery_beforeUpdate.sql b/db/routines/vn/triggers/delivery_beforeUpdate.sql index 7e6aa7d4c..dda0e9dd2 100644 --- a/db/routines/vn/triggers/delivery_beforeUpdate.sql +++ b/db/routines/vn/triggers/delivery_beforeUpdate.sql @@ -4,16 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate FOR EACH ROW BEGIN -IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) THEN + CALL address_updateCorordinates(NEW.ticketFk,NEW.longitude,NEW.latitude); END IF; END$$ From 2078bf58ff474db4d99f1fe66c4e67bea7c135da Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 10:09:00 +0200 Subject: [PATCH 028/123] feat: refs #7681 Optimization and refactor --- db/routines/vn/procedures/route_updateM3.sql | 39 +++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql index 92d26b753..a2adf5b14 100644 --- a/db/routines/vn/procedures/route_updateM3.sql +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -1,14 +1,35 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_updateM3`(vRoute INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_updateM3`( + vSelf INT +) BEGIN +/** + * Actualiza el volumen de la ruta. + * + * @param vSelf Id ruta + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; - UPDATE vn.route r - LEFT JOIN ( - SELECT routeFk, SUM(volume) AS m3 - FROM saleVolume - WHERE routeFk = vRoute - ) v ON v.routeFk = r.id - SET r.m3 = IFNULL(v.m3,0) - WHERE r.id =vRoute; + CREATE OR REPLACE TEMPORARY TABLE tRouteVolume + ENGINE = MEMORY + SELECT IFNULL(SUM(volume), 0) volume + FROM saleVolume + WHERE routeFk = vSelf; + + START TRANSACTION; + + SELECT id FROM `route` WHERE id = vSelf FOR UPDATE; + + UPDATE `route` + SET m3 = (SELECT volume FROM tRouteVolume) + WHERE id = vSelf; + + COMMIT; + + DROP TEMPORARY TABLE tRouteVolume; END$$ DELIMITER ; From 042ea840558403519b68a8ff4b09d4289be124aa Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 10:14:55 +0200 Subject: [PATCH 029/123] feat: refs #7681 Changes --- db/routines/vn/procedures/route_updateM3.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql index a2adf5b14..07ceaaf5c 100644 --- a/db/routines/vn/procedures/route_updateM3.sql +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -22,8 +22,6 @@ BEGIN START TRANSACTION; - SELECT id FROM `route` WHERE id = vSelf FOR UPDATE; - UPDATE `route` SET m3 = (SELECT volume FROM tRouteVolume) WHERE id = vSelf; From a725cd2840f4af816833b3a29277d26d3fb9721c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 10:19:04 +0200 Subject: [PATCH 030/123] feat: refs #7681 Changes --- db/routines/vn/procedures/route_updateM3.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql index 07ceaaf5c..c2049ca26 100644 --- a/db/routines/vn/procedures/route_updateM3.sql +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -22,6 +22,9 @@ BEGIN START TRANSACTION; + -- Hago el into para que no de error en los triggers + SELECT id INTO vSelf FROM `route` WHERE id = vSelf FOR UPDATE; + UPDATE `route` SET m3 = (SELECT volume FROM tRouteVolume) WHERE id = vSelf; From 376adebe9d93a7dbe7562fc47d15a94c33baa916 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 10:19:18 +0200 Subject: [PATCH 031/123] feat: refs #7681 Changes --- db/routines/vn/procedures/route_updateM3.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql index c2049ca26..c5c85544c 100644 --- a/db/routines/vn/procedures/route_updateM3.sql +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -22,7 +22,7 @@ BEGIN START TRANSACTION; - -- Hago el into para que no de error en los triggers + -- Hago el INTO para que no de error en los triggers SELECT id INTO vSelf FROM `route` WHERE id = vSelf FOR UPDATE; UPDATE `route` From 96d2bacb3dc2317e96aa679a7f82a62e9d9fa0c2 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 10:22:42 +0200 Subject: [PATCH 032/123] feat: refs #7681 Changes --- db/routines/vn/procedures/route_updateM3.sql | 9 --------- 1 file changed, 9 deletions(-) diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql index c5c85544c..6b73b3858 100644 --- a/db/routines/vn/procedures/route_updateM3.sql +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -8,11 +8,6 @@ BEGIN * * @param vSelf Id ruta */ - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; CREATE OR REPLACE TEMPORARY TABLE tRouteVolume ENGINE = MEMORY @@ -20,8 +15,6 @@ BEGIN FROM saleVolume WHERE routeFk = vSelf; - START TRANSACTION; - -- Hago el INTO para que no de error en los triggers SELECT id INTO vSelf FROM `route` WHERE id = vSelf FOR UPDATE; @@ -29,8 +22,6 @@ BEGIN SET m3 = (SELECT volume FROM tRouteVolume) WHERE id = vSelf; - COMMIT; - DROP TEMPORARY TABLE tRouteVolume; END$$ DELIMITER ; From 02c2ccd62ee3648d2341058ef6c7efa088ee41f5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 9 Jul 2024 11:00:02 +0200 Subject: [PATCH 033/123] stash filterState --- modules/ticket/back/methods/ticket/filter.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 899fe05cd..8d93fb993 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -347,6 +347,17 @@ module.exports = Self => { if (hasWhere) stmt.merge(conn.makeWhere(problems)); + if (filter.order) { + const index = filter.order.findIndex(o => o.includes('stateFk')); + if (index > -1) { + filter.order = [ + ...filter.order.slice(0, index), + 'refFk ' + filter.order[index].split(' ')[1], + ...filter.order.slice(index) + ]; + } + } + stmt.merge(conn.makeOrderBy(filter.order)); stmt.merge(conn.makeLimit(filter)); const ticketsIndex = stmts.push(stmt) - 1; From 944cf3baa3ef35b0a30c22eeea1f1bcb54bb0545 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 9 Jul 2024 11:44:43 +0200 Subject: [PATCH 034/123] refs #7694 hotfix filter --- modules/ticket/back/methods/ticket/filter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 8d93fb993..0823b38b8 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -348,6 +348,7 @@ module.exports = Self => { stmt.merge(conn.makeWhere(problems)); if (filter.order) { + if (typeof filter.order == 'string') filter.order = [filter.order]; const index = filter.order.findIndex(o => o.includes('stateFk')); if (index > -1) { filter.order = [ From d8f3a045533db4f43892c4cf2c87b99af618b75a Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 11:45:58 +0200 Subject: [PATCH 035/123] fix: refs #6738 restore column grupotarifa --- db/versions/11145-pinkLaurel/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/11145-pinkLaurel/00-firstScript.sql diff --git a/db/versions/11145-pinkLaurel/00-firstScript.sql b/db/versions/11145-pinkLaurel/00-firstScript.sql new file mode 100644 index 000000000..741a41f5b --- /dev/null +++ b/db/versions/11145-pinkLaurel/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.payrollWorker CHANGE grupotarifa__ grupotarifa int(10) NOT NULL; +ALTER TABLE vn.payrollWorker MODIFY COLUMN grupotarifa int(10) NOT NULL; \ No newline at end of file From 8f86ffbc3895bcb989c119c35992cb40842a8c91 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 11:47:02 +0200 Subject: [PATCH 036/123] fix: refs #6738 --- db/versions/11145-pinkLaurel/00-firstScript.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/versions/11145-pinkLaurel/00-firstScript.sql b/db/versions/11145-pinkLaurel/00-firstScript.sql index 741a41f5b..ba1946d3b 100644 --- a/db/versions/11145-pinkLaurel/00-firstScript.sql +++ b/db/versions/11145-pinkLaurel/00-firstScript.sql @@ -1,3 +1,2 @@ --- Place your SQL code here ALTER TABLE vn.payrollWorker CHANGE grupotarifa__ grupotarifa int(10) NOT NULL; ALTER TABLE vn.payrollWorker MODIFY COLUMN grupotarifa int(10) NOT NULL; \ No newline at end of file From f8169b3034e24ebc217c9bce76f9ce54975afbab Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 12:46:50 +0200 Subject: [PATCH 037/123] feat: refs #7544 chages required --- db/routines/vn/events/claim_changeState.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql index 790ef0c34..5d94170a0 100644 --- a/db/routines/vn/events/claim_changeState.sql +++ b/db/routines/vn/events/claim_changeState.sql @@ -6,15 +6,15 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState` ENABLE DO BEGIN - DECLARE vClaimStete INT; + DECLARE vClaimState INT; - SELECT id INTO vClaimStete + SELECT id INTO vClaimState FROM claimState cs WHERE cs.code = 'canceled'; UPDATE claim c JOIN claimState cs ON cs.id = c.claimStateFk - SET c.claimStateFk = vClaimStete + SET c.claimStateFk = vClaimState WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH AND cs.code IN('incomplete','coming','waiting','out'); From c2e9095ccdae2ac6d7b0940916c186259dc43abe Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:22:32 +0200 Subject: [PATCH 038/123] feat: refs #7505 Requested changes --- db/routines/cache/procedures/visible_refresh.sql | 2 +- db/routines/vn/procedures/item_calcVisible.sql | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 4feffde8e..a59669ff6 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_calcVisible(NULL, util.VN_CURDATE(), v_warehouse); + CALL vn.item_calcVisible(NULL, v_warehouse); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index 728c94276..820e73a7e 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,7 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( vSelf INT, - vDated DATE, vWarehouseFk INT ) BEGIN @@ -9,11 +8,11 @@ BEGIN * Calcula el visible de un artículo o de todos. * * @param vWarehouse Warehouse id - * @param vDated Max date to filter * @param vSelf Item id * @param tmp.itemVisible(item_id, stock, visible) */ - DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; + DECLARE vDated DATE DEFAULT util.VN_CURDATE(); + DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); INSERT INTO tmp.itemVisible(item_id, visible) SELECT itemFk, SUM(quantity) From 470c9bc8720dc1db1a84c47acabe00da23cb29d3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:24:17 +0200 Subject: [PATCH 039/123] feat: refs #7505 Minor changes --- db/routines/cache/procedures/visible_refresh.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index a59669ff6..d7e02ad96 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -1,13 +1,13 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -proc: BEGIN +BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (v_calc); RESIGNAL; END; - CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); + CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); IF !v_refresh THEN LEAVE proc; @@ -15,13 +15,13 @@ proc: BEGIN -- Calculamos el stock hasta ayer - CALL `cache`.stock_refresh(false); + CALL cache.stock_refresh(false); CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT item_id, amount stock, amount visible - FROM `cache`.stock + FROM cache.stock WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy @@ -31,7 +31,7 @@ proc: BEGIN INSERT INTO visible (calc_id, item_id,visible) SELECT v_calc, item_id, visible FROM tmp.itemVisible; - CALL cache_calc_end (v_calc); + CALL cache_calc_end (v_calc); DROP TEMPORARY TABLE tmp.itemVisible; END$$ From e2b6473831e2211406e8f5c35fbecb9c9c271bbb Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:24:35 +0200 Subject: [PATCH 040/123] feat: refs #7505 Minor changes --- db/routines/cache/procedures/visible_refresh.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index d7e02ad96..78d23dbfb 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -BEGIN +proc:BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (v_calc); From 64ed96c8ae3b90699cb60451193bd5be97343808 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:47:12 +0200 Subject: [PATCH 041/123] feat: refs #7486 More debug --- db/routines/vn/procedures/collection_assign.sql | 14 +++++++------- db/routines/vn/procedures/collection_new.sql | 16 ++++++++-------- .../procedures/ticket_splitItemPackingType.sql | 11 +++++++++++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index bf130b2c6..f9032a91d 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -26,16 +26,16 @@ BEGIN vErrorNumber = MYSQL_ERRNO, vErrorMsg = MESSAGE_TEXT; + CALL util.debugAdd('collection_assign', JSON_OBJECT( + 'errorNumber', vErrorNumber, + 'errorMsg', vErrorMsg, + 'lockName', vLockName, + 'userFk', vUserFk + )); -- Tmp + IF vLockName IS NOT NULL THEN DO RELEASE_LOCK(vLockName); - CALL util.debugAdd('collection_assign', JSON_OBJECT( - 'errorNumber', vErrorNumber, - 'errorMsg', vErrorMsg, - 'lockName', vLockName, - 'userFk', vUserFk - )); -- Tmp END IF; - RESIGNAL; END; diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index 029427306..0bd6e1b25 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -53,17 +53,17 @@ BEGIN vErrorNumber = MYSQL_ERRNO, vErrorMsg = MESSAGE_TEXT; + CALL util.debugAdd('collection_new', JSON_OBJECT( + 'errorNumber', vErrorNumber, + 'errorMsg', vErrorMsg, + 'lockName', vLockName, + 'userFk', vUserFk, + 'ticketFk', vTicketFk + )); -- Tmp + IF vLockName IS NOT NULL THEN DO RELEASE_LOCK(vLockName); - CALL util.debugAdd('collection_new', JSON_OBJECT( - 'errorNumber', vErrorNumber, - 'errorMsg', vErrorMsg, - 'lockName', vLockName, - 'userFk', vUserFk, - 'ticketFk', vTicketFk - )); -- Tmp END IF; - RESIGNAL; END; diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index d6e8e8a53..e2c55e28a 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -16,6 +16,8 @@ BEGIN DECLARE vNewTicketFk INT; DECLARE vPackingTypesToSplit INT; DECLARE vDone INT DEFAULT FALSE; + DECLARE vErrorNumber INT; + DECLARE vErrorMsg TEXT; DECLARE cur1 CURSOR FOR SELECT itemPackingTypeFk @@ -27,6 +29,15 @@ BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + GET DIAGNOSTICS CONDITION 1 + vErrorNumber = MYSQL_ERRNO, + vErrorMsg = MESSAGE_TEXT; + + CALL util.debugAdd('ticket_splitItemPackingType', JSON_OBJECT( + 'errorNumber', vErrorNumber, + 'errorMsg', vErrorMsg, + 'ticketFk', vTicketFk + )); -- Tmp RESIGNAL; END; From 1ca95678dfdc3eb08816c5f949e89da3146c95ae Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:53:09 +0200 Subject: [PATCH 042/123] Fix --- db/routines/vn/procedures/ticket_splitItemPackingType.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index 8eeec551a..c2ec50fd9 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -36,7 +36,7 @@ BEGIN CALL util.debugAdd('ticket_splitItemPackingType', JSON_OBJECT( 'errorNumber', vErrorNumber, 'errorMsg', vErrorMsg, - 'ticketFk', vTicketFk + 'ticketFk', vSelf )); -- Tmp ROLLBACK; RESIGNAL; From 004dcb67ff3a5486cb2ae89d1d910faae5d5a862 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 10 Jul 2024 07:13:57 +0200 Subject: [PATCH 043/123] feat: refs #7116 insert into agencyIncoming --- db/routines/vn/events/claim_changeState.sql | 22 +++++++++++++++++++ .../10960-silverRoebelini/00-firstScript.sql | 17 +++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/events/claim_changeState.sql diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql new file mode 100644 index 000000000..9197f2a56 --- /dev/null +++ b/db/routines/vn/events/claim_changeState.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState` + ON SCHEDULE EVERY 1 DAY + STARTS '2024-06-06 07:52:46.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + + DECLARE vClaimState INT; + + SELECT id INTO vClaimState + FROM claimState cs + WHERE cs.code = 'canceled'; + + UPDATE claim c + JOIN claimState cs ON cs.id = c.claimStateFk + SET c.claimStateFk = vClaimState + WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH + AND cs.code IN('incomplete','coming','waiting','out'); + +END$$ +DELIMITER ; diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql index 228e0b014..c53a09549 100644 --- a/db/versions/10960-silverRoebelini/00-firstScript.sql +++ b/db/versions/10960-silverRoebelini/00-firstScript.sql @@ -5,4 +5,19 @@ CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';; \ No newline at end of file +COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias'; + +INSERT IGNORE INTO vn.agencyIncoming (agencyModeFk) VALUES +(1343), (1002), (1282), (841), (1303), (714), (556), (1786), (1785), (1784), +(1780), (1783), (1758), (1782), (1772), (1789), (1776), (1791), (1778), (1792), +(1779), (1362), (681), (1765), (15), (1594), (1706), (1707), (907), (1260), +(1715), (1371), (1372), (53), (689), (1375), (738), (742), (1307), (1700), (608), +(1311), (1315), (1339), (1433), (1338), (1332), (1844), (842), (1382), (1466), +(1719), (1723), (1725), (1720), (1732), (1736), (1728), (1724), (1726), (1727), +(1767), (1734), (1730), (1845), (1729), (1746), (1699), (2), (671), (1379), (614), +(1718), (1697), (62), (1529), (1392), (1378), (1438), (1796), (1688), (686), +(1326), (1691), (1), (1560), (1695), (1696), (1558), (1648), (1649), (1598), +(1680), (1694), (1600), (1601), (1602), (1712), (1603), (1604), (1641), (1692), +(1693), (1650), (1683), (1682), (1681), (1713), (1826), (1768), (1769), (1770), +(1593), (1443), (1244), (1679), (1006), (1361), (1102), (1655), (1744), (1225), +(1007); From 46e8f5b8110f1bf6d11d3e3dae15b8c66174f49f Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 07:46:18 +0200 Subject: [PATCH 044/123] feat: refs #7511 Rename to multiConfig tables --- back/methods/edi/updateData.js | 6 +++--- back/model-config.json | 2 +- back/models/user-config.json | 2 +- db/dump/fixtures.before.sql | 2 +- db/routines/pbx/views/queueConf.sql | 2 +- db/routines/vn/procedures/company_getFiscaldata.sql | 2 +- db/routines/vn/procedures/invoiceOut_new.sql | 4 ++-- db/routines/vn/procedures/item_devalueA2.sql | 2 +- db/versions/11146-maroonCordyline/00-firstScript.sql | 9 +++++++++ modules/route/back/methods/route/getExpeditionSummary.js | 2 +- myt.config.yml | 4 ++-- 11 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 db/versions/11146-maroonCordyline/00-firstScript.sql diff --git a/back/methods/edi/updateData.js b/back/methods/edi/updateData.js index 6bebad1e4..c9789d2d8 100644 --- a/back/methods/edi/updateData.js +++ b/back/methods/edi/updateData.js @@ -24,7 +24,7 @@ module.exports = Self => { try { const options = {transaction: tx, userId: ctx.req.accessToken.userId}; - const files = await Self.rawSql('SELECT name, checksum, keyValue FROM edi.fileConfig', null, options); + const files = await Self.rawSql('SELECT name, checksum, keyValue FROM edi.fileMultiConfig', null, options); const updatableFiles = []; for (const file of files) { @@ -54,7 +54,7 @@ module.exports = Self => { const tables = await Self.rawSql(` SELECT fileName, toTable, file - FROM edi.tableConfig + FROM edi.tableMultiConfig WHERE file IN (?)`, [fileNames], options); for (const table of tables) { @@ -228,7 +228,7 @@ module.exports = Self => { await Self.rawSql(sqlTemplate, [filePath], options); await Self.rawSql(` - UPDATE edi.tableConfig + UPDATE edi.tableMultiConfig SET updated = ? WHERE fileName = ? `, [Date.vnNew(), baseName], options); diff --git a/back/model-config.json b/back/model-config.json index 58fa86797..ecd6ed168 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -40,7 +40,7 @@ "ChatConfig": { "dataSource": "vn" }, - "DefaultViewConfig": { + "DefaultViewMultiConfig": { "dataSource": "vn" }, "Delivery": { diff --git a/back/models/user-config.json b/back/models/user-config.json index 5c5df1b9e..f8e563dc3 100644 --- a/back/models/user-config.json +++ b/back/models/user-config.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "userConfig" + "table": "userMultiConfig" } }, "properties": { diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4f85db98a..85f689f55 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1943,7 +1943,7 @@ INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`) (21, 21), (22, 22); -INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`) +INSERT INTO `vn`.`userMultiConfig` (`userFk`, `warehouseFk`, `companyFk`) VALUES (1, 1, 69), (5, 1, 442), diff --git a/db/routines/pbx/views/queueConf.sql b/db/routines/pbx/views/queueConf.sql index 07c241589..107989801 100644 --- a/db/routines/pbx/views/queueConf.sql +++ b/db/routines/pbx/views/queueConf.sql @@ -10,5 +10,5 @@ AS SELECT `q`.`name` AS `name`, `c`.`ringInUse` AS `ringinuse` FROM ( `pbx`.`queue` `q` - JOIN `pbx`.`queueConfig` `c` ON(`q`.`config` = `c`.`id`) + JOIN `pbx`.`queueMultiConfig` `c` ON(`q`.`config` = `c`.`id`) ) diff --git a/db/routines/vn/procedures/company_getFiscaldata.sql b/db/routines/vn/procedures/company_getFiscaldata.sql index 7c56382e9..b59ae38e1 100644 --- a/db/routines/vn/procedures/company_getFiscaldata.sql +++ b/db/routines/vn/procedures/company_getFiscaldata.sql @@ -7,7 +7,7 @@ DECLARE vCompanyFk INT; SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) INTO vCompanyFk FROM vn.routeConfig rc - LEFT JOIN userConfig uc ON uc.userFk = workerFk; + LEFT JOIN userMultiConfig uc ON uc.userFk = workerFk; SELECT diff --git a/db/routines/vn/procedures/invoiceOut_new.sql b/db/routines/vn/procedures/invoiceOut_new.sql index 42c3f99da..c9b94027e 100644 --- a/db/routines/vn/procedures/invoiceOut_new.sql +++ b/db/routines/vn/procedures/invoiceOut_new.sql @@ -216,7 +216,7 @@ BEGIN i.transactionTypeSageFk, @vTaxCodeGeneral := i.taxClassCodeFk FROM tmp.ticketServiceTax tst - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code + JOIN invoiceOutTaxMultiConfig i ON i.taxClassCodeFk = tst.code WHERE i.isService HAVING taxableBase ) sub; @@ -229,7 +229,7 @@ BEGIN i.taxTypeSageFk , i.transactionTypeSageFk FROM tmp.ticketTax tt - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code + JOIN invoiceOutTaxMultiConfig i ON i.taxClassCodeFk = tt.code WHERE !i.isService GROUP BY tt.pgcFk HAVING taxableBase diff --git a/db/routines/vn/procedures/item_devalueA2.sql b/db/routines/vn/procedures/item_devalueA2.sql index c9f716d8f..5b03fc872 100644 --- a/db/routines/vn/procedures/item_devalueA2.sql +++ b/db/routines/vn/procedures/item_devalueA2.sql @@ -42,7 +42,7 @@ BEGIN END IF; SELECT warehouseFk INTO vWarehouseFk - FROM userConfig + FROM userMultiConfig WHERE userFk = account.myUser_getId(); IF NOT vWarehouseFk OR vWarehouseFk IS NULL THEN diff --git a/db/versions/11146-maroonCordyline/00-firstScript.sql b/db/versions/11146-maroonCordyline/00-firstScript.sql new file mode 100644 index 000000000..16093311e --- /dev/null +++ b/db/versions/11146-maroonCordyline/00-firstScript.sql @@ -0,0 +1,9 @@ +RENAME TABLE hedera.shelfConfig TO hedera.shelfMultiConfig ; +RENAME TABLE pbx.queueConfig TO pbx.queueMultiConfig ; +RENAME TABLE salix.defaultViewConfig TO salix.defaultViewMultiConfig; +RENAME TABLE edi.fileConfig TO edi.fileMultiConfig; +RENAME TABLE edi.imapConfig TO edi.imapMultiConfig; +RENAME TABLE edi.tableConfig TO edi.tableMultiConfig; +RENAME TABLE vn.invoiceOutTaxConfig TO vn.invoiceOutTaxMultiConfig; +RENAME TABLE vn.userConfig TO vn.userMultiConfig; +RENAME TABLE vn.conveyorConfig TO vn.conveyorMultiConfig; diff --git a/modules/route/back/methods/route/getExpeditionSummary.js b/modules/route/back/methods/route/getExpeditionSummary.js index 2bd2ca43a..afe54b030 100644 --- a/modules/route/back/methods/route/getExpeditionSummary.js +++ b/modules/route/back/methods/route/getExpeditionSummary.js @@ -48,7 +48,7 @@ module.exports = Self => { LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk JOIN vn.agencyMode am ON am.id = r.agencyModeFk JOIN vn.agency ag ON ag.id = am.agencyFk - LEFT JOIN vn.userConfig uc ON uc.userFk = account.myUser_getId() + LEFT JOIN vn.userMultiConfig uc ON uc.userFk = account.myUser_getId() WHERE t.routeFk = ? GROUP BY t.addressFk, e.itemPackingTypeFk ) sub diff --git a/myt.config.yml b/myt.config.yml index 56239ca3c..116e3668a 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -42,7 +42,7 @@ fixtures: - ACL - fieldAcl - module - - defaultViewConfig + - defaultViewMultiConfig vn: - alertLevel - bookingPlanner @@ -363,7 +363,7 @@ localFixtures: - travelConfig - travelRecalc - travelThermograph - - userConfig + - userMultiConfig - vehicle - wagonConfig - wagonType From d660043df2db6ff5bd3bd6e245c8698342c3099a Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 07:48:42 +0200 Subject: [PATCH 045/123] feat: refs #7511 Fix tests --- back/model-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/model-config.json b/back/model-config.json index ecd6ed168..58fa86797 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -40,7 +40,7 @@ "ChatConfig": { "dataSource": "vn" }, - "DefaultViewMultiConfig": { + "DefaultViewConfig": { "dataSource": "vn" }, "Delivery": { From 64bddd4f63273063b7d35f63c993a0c491f62836 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 10 Jul 2024 10:41:52 +0200 Subject: [PATCH 046/123] feat: refs #6403 add dynamic clientType --- back/methods/mrw-config/cancelShipment.ejs | 2 +- back/methods/mrw-config/cancelShipment.js | 4 +-- back/methods/mrw-config/createShipment.ejs | 2 +- back/methods/mrw-config/createShipment.js | 11 +++---- back/methods/mrw-config/getLabel.ejs | 2 +- back/methods/mrw-config/getLabel.js | 16 +++++++-- .../mrw-config/specs/createShipment.spec.js | 18 +++++----- back/methods/viaexpress-config/renderer.js | 4 +-- back/model-config.json | 3 ++ back/models/mrw-config.js | 25 ++++++++++++++ back/models/mrw-config.json | 3 ++ back/models/mrw-service.json | 33 +++++++++++++++++++ modules/zone/back/models/agency-mode.json | 5 +++ 13 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 back/models/mrw-service.json diff --git a/back/methods/mrw-config/cancelShipment.ejs b/back/methods/mrw-config/cancelShipment.ejs index 9ef401bc8..bc0662981 100644 --- a/back/methods/mrw-config/cancelShipment.ejs +++ b/back/methods/mrw-config/cancelShipment.ejs @@ -2,7 +2,7 @@ <%= mrw.franchiseCode %> - <%= mrw.subscriberCode %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 86bbb7410..10d556575 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -27,9 +27,9 @@ module.exports = Self => { const mrw = await models.MrwConfig.findOne(); const {externalId} = await models.Expedition.findById(expeditionFk); - + const clientType = await models.MrwConfig.getClientType(expeditionFk); const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8'); - const renderedXml = ejs.render(template, {mrw, externalId}); + const renderedXml = ejs.render(template, {mrw, externalId, clientType}); const response = await axios.post(mrw.url, renderedXml, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' diff --git a/back/methods/mrw-config/createShipment.ejs b/back/methods/mrw-config/createShipment.ejs index 8e123ddd9..65326112b 100644 --- a/back/methods/mrw-config/createShipment.ejs +++ b/back/methods/mrw-config/createShipment.ejs @@ -3,7 +3,7 @@ <%= mrw.franchiseCode %> - <%= expeditionData.clientType %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 9b23cc370..ab25113dc 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -22,6 +22,7 @@ module.exports = Self => { Self.createShipment = async expeditionFk => { const models = Self.app.models; const mrw = await Self.getConfig(); + const clientType = await models.MrwConfig.getClientType(expeditionFk); const today = Date.vnNew(); const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0]; @@ -52,8 +53,7 @@ module.exports = Self => { CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, IF(mw.weekdays, 'S', 'N') weekDays, - oa.description deliveryObservation, - LPAD(ms.clientType, mc.clientTypeWidth, '0') clientType + oa.description deliveryObservation FROM expedition e JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk @@ -73,22 +73,19 @@ module.exports = Self => { const [expeditionData] = await Self.rawSql(query, [expeditionFk]); - if (!expeditionData) - throw new UserError(`This expedition is not a MRW shipment`); - if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0)) throw new UserError(`This ticket has a shipped date earlier than today`); const shipmentResponse = await Self.sendXmlDoc( __dirname + `/createShipment.ejs`, - {mrw, expeditionData}, + {mrw, expeditionData, clientType}, 'application/soap+xml' ); const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio'); if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje')); - const file = await models.MrwConfig.getLabel(shipmentId); + const file = await models.MrwConfig.getLabel(shipmentId, clientType); return {shipmentId, file}; }; diff --git a/back/methods/mrw-config/getLabel.ejs b/back/methods/mrw-config/getLabel.ejs index 09bdb3f6c..b0dae17c8 100644 --- a/back/methods/mrw-config/getLabel.ejs +++ b/back/methods/mrw-config/getLabel.ejs @@ -2,7 +2,7 @@ <%= mrw.franchiseCode %> - <%= mrw.subscriberCode %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/getLabel.js b/back/methods/mrw-config/getLabel.js index aa9b87af1..4af3276bb 100644 --- a/back/methods/mrw-config/getLabel.js +++ b/back/methods/mrw-config/getLabel.js @@ -6,7 +6,13 @@ module.exports = Self => { arg: 'shipmentId', type: 'string', required: true - }], + }, + { + arg: 'clientType', + type: 'string', + required: true + }, + ], returns: { type: 'string', root: true @@ -17,10 +23,14 @@ module.exports = Self => { } }); - Self.getLabel = async shipmentId => { + Self.getLabel = async(shipmentId, clientType) => { const mrw = await Self.getConfig(); - const getLabelResponse = await Self.sendXmlDoc(__dirname + `/getLabel.ejs`, {mrw, shipmentId}, 'text/xml'); + const getLabelResponse = await Self.sendXmlDoc( + __dirname + `/getLabel.ejs`, + {mrw, shipmentId, clientType}, + 'text/xml' + ); return Self.getTextByTag(getLabelResponse, 'EtiquetaFile'); }; diff --git a/back/methods/mrw-config/specs/createShipment.spec.js b/back/methods/mrw-config/specs/createShipment.spec.js index 883dd8f6f..1ab77f608 100644 --- a/back/methods/mrw-config/specs/createShipment.spec.js +++ b/back/methods/mrw-config/specs/createShipment.spec.js @@ -40,15 +40,12 @@ describe('MRWConfig createShipment()', () => { ); + await models.MrwService.create( + {'agencyModeCodeFk': 'mrw', 'clientType': '000001', 'serviceType': 105, 'kg': 10} + ); + await createMrwConfig(); - await models.Application.rawSql( - `INSERT INTO vn.mrwService - SET agencyModeCodeFk = 'mrw', - clientType = 1, - serviceType = 1, - kg = 1`, null - ); await models.Ticket.create(ticket1); await models.Expedition.create(expedition1); }); @@ -82,7 +79,8 @@ describe('MRWConfig createShipment()', () => { 'user': 'user', 'password': 'password', 'franchiseCode': 'franchiseCode', - 'subscriberCode': 'subscriberCode' + 'subscriberCode': 'subscriberCode', + 'clientTypeWidth': 6 } ); } @@ -115,10 +113,10 @@ describe('MRWConfig createShipment()', () => { it('should fail if expeditionFk is not a MrwExpedition', async() => { let error; - await models.MrwConfig.createShipment(undefined).catch(e => { + await models.MrwConfig.createShipment(15).catch(e => { error = e; }).finally(async() => { - expect(error.message).toEqual(`This expedition is not a MRW shipment`); + expect(error.message).toEqual(`ClientType not available`); }); }); diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index c8533ea6b..5d83b5870 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -20,7 +20,7 @@ module.exports = Self => { } }); - Self.renderer = async (expeditionFk) => { + Self.renderer = async expeditionFk => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ @@ -109,7 +109,7 @@ module.exports = Self => { const ticket = expedition.ticket(); const sender = ticket.company().client(); const shipped = ticket.shipped.toISOString(); - const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk) + const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk); const data = { viaexpressConfig, sender, diff --git a/back/model-config.json b/back/model-config.json index 58fa86797..a16fe4e8a 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -192,5 +192,8 @@ }, "RouteConfig": { "dataSource": "vn" + }, + "MrwService": { + "dataSource": "vn" } } \ No newline at end of file diff --git a/back/models/mrw-config.js b/back/models/mrw-config.js index c738c9c0e..8bb24dbe5 100644 --- a/back/models/mrw-config.js +++ b/back/models/mrw-config.js @@ -31,5 +31,30 @@ module.exports = Self => { }); return parser.parseFromString(data.data, 'text/xml'); }; + + Self.getClientType = async function(expeditionFk) { + if (!expeditionFk) throw new UserError(`No expeditionFk defined`); + + const {clientTypeWidth} = await Self.getConfig(); + const result = await Self.app.models.Expedition.findById(expeditionFk, + {include: [{ + relation: 'ticket', + scope: { + include: { + relation: 'agencyMode', + scope: { + include: { + relation: 'mrwService', + } + } + } + } + }]} + ); + const clientType = result?.ticket()?.agencyMode()?.mrwService()?.clientType; + if (!clientType || !clientTypeWidth) throw new UserError(`ClientType not available`); + + return clientType.toString().padStart(clientTypeWidth, '0'); + }; }; diff --git a/back/models/mrw-config.json b/back/models/mrw-config.json index c96b68cf3..60c0ca2a2 100644 --- a/back/models/mrw-config.json +++ b/back/models/mrw-config.json @@ -45,6 +45,9 @@ }, "notified":{ "type": "date" + }, + "clientTypeWidth": { + "type": "number" } } } diff --git a/back/models/mrw-service.json b/back/models/mrw-service.json new file mode 100644 index 000000000..1ad72d060 --- /dev/null +++ b/back/models/mrw-service.json @@ -0,0 +1,33 @@ +{ + "name": "MrwService", + "base": "VnModel", + "options": { + "mysql": { + "table": "mrwService" + } + }, + "properties": { + "agencyModeCodeFk": { + "id": true, + "type": "string", + "required": true + }, + "clientType": { + "type": "number", + "required": true + }, + "serviceType": { + "type": "number" + }, + "kg": { + "type": "number" + } + }, + "relations": { + "agency": { + "type": "hasOne", + "model": "AgencyMode", + "foreignKey": "code" + } + } +} diff --git a/modules/zone/back/models/agency-mode.json b/modules/zone/back/models/agency-mode.json index 99ed43b97..6033e26c6 100644 --- a/modules/zone/back/models/agency-mode.json +++ b/modules/zone/back/models/agency-mode.json @@ -60,6 +60,11 @@ "type": "hasMany", "model": "Zone", "foreignKey": "agencyModeFk" + }, + "mrwService": { + "type": "belongsTo", + "model": "MrwService", + "foreignKey": "code" } }, "acls": [ From 3c975aa9c47bc0e6c83b3704d6af981c24bd61fb Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:32:41 +0200 Subject: [PATCH 047/123] refactor: refs #7580 Requested changes --- db/routines/vn/procedures/setParking.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql index 107ef66f4..087fb4c07 100644 --- a/db/routines/vn/procedures/setParking.sql +++ b/db/routines/vn/procedures/setParking.sql @@ -28,7 +28,9 @@ BEGIN IF vParkingFk IS NULL THEN CALL util.throw('parkingNotExist'); END IF; - + + START TRANSACTION; + IF vParam REGEXP '^[0-9]+$' THEN SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK; From 27f9001e344ca45654aa762c32564bbf44417c0f Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:35:05 +0200 Subject: [PATCH 048/123] refactor: refs #7378 Requested changes --- db/versions/11130-crimsonIvy/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql index 3bde55f55..c93f2f6b7 100644 --- a/db/versions/11130-crimsonIvy/00-firstScript.sql +++ b/db/versions/11130-crimsonIvy/00-firstScript.sql @@ -16,7 +16,7 @@ CREATE OR REPLACE TABLE `vn`.`productionConfigLog` ( `changedModelId` int(11) NOT NULL, `changedModelValue` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), - KEY `logRateuserFk` (`userFk`), + KEY `productionConfigLog_userFk` (`userFk`), KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), KEY `productionConfigLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE From 203db3ec3a34921a533a8e8a0dc61be49603899f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 10 Jul 2024 12:47:09 +0200 Subject: [PATCH 049/123] feat solvePrintLabel refs #7269 --- print/templates/reports/collection-label/collection-label.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/collection-label/collection-label.html b/print/templates/reports/collection-label/collection-label.html index 752a31185..143efc525 100644 --- a/print/templates/reports/collection-label/collection-label.html +++ b/print/templates/reports/collection-label/collection-label.html @@ -19,7 +19,7 @@ {{dashIfEmpty(labelData.workerCode)}} - {{labelData.labelCount || 0}} + {{this.labelCount || labelData.labelCount || 0}} {{labelData.code == 'V' ? (labelData.size || 0) + 'cm' : (labelData.volume || 0) + 'm³'}} From a2f2ed743d7cb516f15d47073b00378d88334aec Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 13:31:48 +0200 Subject: [PATCH 050/123] refactor: refs #7681 Changes --- db/routines/vn/procedures/route_updateM3.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql index 6b73b3858..1df37ec8e 100644 --- a/db/routines/vn/procedures/route_updateM3.sql +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -8,16 +8,12 @@ BEGIN * * @param vSelf Id ruta */ - CREATE OR REPLACE TEMPORARY TABLE tRouteVolume ENGINE = MEMORY SELECT IFNULL(SUM(volume), 0) volume FROM saleVolume WHERE routeFk = vSelf; - -- Hago el INTO para que no de error en los triggers - SELECT id INTO vSelf FROM `route` WHERE id = vSelf FOR UPDATE; - UPDATE `route` SET m3 = (SELECT volume FROM tRouteVolume) WHERE id = vSelf; From 5304929f57593a9d477bf5238172f54aff8b11a3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 11 Jul 2024 08:52:07 +0200 Subject: [PATCH 051/123] feat: #refs 7348 schema --- db/versions/11126-blueCamellia/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11126-blueCamellia/00-firstScript.sql b/db/versions/11126-blueCamellia/00-firstScript.sql index 45c2ed2dc..40c5e2b37 100644 --- a/db/versions/11126-blueCamellia/00-firstScript.sql +++ b/db/versions/11126-blueCamellia/00-firstScript.sql @@ -1,2 +1,2 @@ -ALTER TABLE `client` +ALTER TABLE `vn`.`client` ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'; From 02bcfd9be38d21199ee12defadffda57efd3d035 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 11 Jul 2024 08:57:45 +0200 Subject: [PATCH 052/123] feat: refs #7704 Major changes --- .../hedera/procedures/order_addItem.sql | 15 +++-- db/routines/vn/procedures/item_getSimilar.sql | 2 +- db/routines/vn2008/views/buySource.sql | 3 +- .../11149-silverSalal/00-firstScript.sql | 20 +++++++ modules/item/back/model-config.json | 3 + .../back/models/item-minimum-quantity.json | 57 +++++++++++++++++++ modules/item/back/models/item.json | 4 -- modules/item/front/summary/index.html | 3 - .../order/back/methods/order/catalogFilter.js | 19 +++++-- modules/order/front/catalog-view/index.html | 12 ---- .../order/front/catalog-view/locale/es.yml | 3 +- modules/ticket/back/models/sale.js | 28 ++++++++- 12 files changed, 134 insertions(+), 35 deletions(-) create mode 100644 db/versions/11149-silverSalal/00-firstScript.sql create mode 100644 modules/item/back/models/item-minimum-quantity.json diff --git a/db/routines/hedera/procedures/order_addItem.sql b/db/routines/hedera/procedures/order_addItem.sql index d9c15c0eb..d47d8b870 100644 --- a/db/routines/hedera/procedures/order_addItem.sql +++ b/db/routines/hedera/procedures/order_addItem.sql @@ -56,11 +56,18 @@ BEGIN CALL util.throw ('ORDER_ROW_UNAVAILABLE'); END IF; - SELECT IFNULL(minQuantity, 0) INTO vMinQuantity - FROM vn.item - WHERE id = vItem; + SELECT quantity + FROM vn.itemMinimalQuantity + WHERE itemFk = vItem + AND ( + util.VN_CURDATE() BETWEEN `started` AND `ended` + OR + (util.VN_CURDATE() >= `started` AND `ended` IS NULL) + ) + AND (warehouseFk = vWarehouse OR warehouseFk IS NULL) + LIMIT 1; - IF vAmount < LEAST(vMinQuantity, vAvailable) THEN + IF vAmount < LEAST(IFNULL(vMinQuantity, 0), vAvailable) THEN CALL util.throw ('quantityLessThanMin'); END IF; diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 557d77bdf..72c543b40 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -63,7 +63,7 @@ BEGIN WHEN b.groupingMode = 'grouping' THEN b.grouping WHEN b.groupingMode = 'packing' THEN b.packing ELSE 1 - END AS minQuantity, + END minQuantity, v.visible located, b.price2 FROM vn.item i diff --git a/db/routines/vn2008/views/buySource.sql b/db/routines/vn2008/views/buySource.sql index 33226a1dc..850483833 100644 --- a/db/routines/vn2008/views/buySource.sql +++ b/db/routines/vn2008/views/buySource.sql @@ -54,8 +54,7 @@ AS SELECT `b`.`entryFk` AS `Id_Entrada`, `i`.`packingOut` AS `packingOut`, `b`.`itemOriginalFk` AS `itemOriginalFk`, `io`.`longName` AS `itemOriginalName`, - `it`.`gramsMax` AS `gramsMax`, - `i`.`minQuantity` AS `minQuantity` + `it`.`gramsMax` AS `gramsMax` FROM ( ( ( diff --git a/db/versions/11149-silverSalal/00-firstScript.sql b/db/versions/11149-silverSalal/00-firstScript.sql new file mode 100644 index 000000000..3225f137f --- /dev/null +++ b/db/versions/11149-silverSalal/00-firstScript.sql @@ -0,0 +1,20 @@ +ALTER TABLE vn.item CHANGE minQuantity minQuantity__ int(10) unsigned DEFAULT + NULL NULL COMMENT '@deprecated 2024-07-11 refs #7704 Cantidad mínima para una línea de venta'; + +CREATE TABLE `vn`.`itemMinimumQuantity` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFk` int(10) NOT NULL, + `quantity` int(10) NOT NULL, + `started` date NOT NULL, + `ended` date DEFAULT NULL, + `warehouseFk` smallint(5) unsigned DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `itemMinimumQuantity_UNIQUE` (`itemFk`, `started`, `ended`, `warehouseFk`), + KEY `itemFk` (`itemFk`), + KEY `started` (`started`), + KEY `ended` (`ended`), + KEY `warehouseFk` (`warehouseFk`), + CONSTRAINT `itemMinimumQuantity_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `itemMinimumQuantity_ibfk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 2d06e1ada..5dbe4d62a 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -32,6 +32,9 @@ "ItemLog": { "dataSource": "vn" }, + "ItemMinimumQuantity": { + "dataSource": "vn" + }, "ItemPackingType": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-minimum-quantity.json b/modules/item/back/models/item-minimum-quantity.json new file mode 100644 index 000000000..848b42a3f --- /dev/null +++ b/modules/item/back/models/item-minimum-quantity.json @@ -0,0 +1,57 @@ +{ + "name": "ItemMinimumQuantity", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemMinimumQuantity" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Id" + }, + "itemFk": { + "type": "number", + "required": true + }, + "quantity": { + "type": "number", + "required": true + }, + "started": { + "type": "date", + "required": true + }, + "ended": { + "type": "date" + }, + "warehouseFk": { + "type": "number" + }, + "created": { + "type": "date" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + }, + "warehouse": { + "type": "belongsTo", + "model": "Warehouse", + "foreignKey": "warehouseFk" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "buyer", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 10cff3e04..eda56e938 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -152,10 +152,6 @@ "columnName": "doPhoto" } }, - "minQuantity": { - "type": "number", - "description": "Min quantity" - }, "photoMotivation": { "type": "string" } diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index 13c671d29..0e4cfc955 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -128,9 +128,6 @@ - -

diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index ab1d7784e..3d67e080c 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -101,6 +101,14 @@ module.exports = Self => { )); stmt = new ParameterizedSQL(` + WITH minQuantity AS ( + SELECT itemFk, quantity, warehouseFk + FROM vn.itemMinimalQuantity + WHERE (util.VN_CURDATE() BETWEEN started AND ended + OR (util.VN_CURDATE() >= started AND ended IS NULL)) + GROUP BY itemFk, warehouseFk + ORDER BY warehouseFk DESC + ) SELECT i.id, i.name, i.subName, @@ -125,6 +133,9 @@ module.exports = Self => { JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.worker w on w.id = it.workerFk LEFT JOIN vn.ink ON ink.id = i.inkFk + LEFT JOIN tmp.ticketComponentPrice tcp ON tcp.itemFk = i.id + LEFT JOIN minQuantity mq ON mq.itemFk = i.id + AND (mq.warehouseFk = tpc.warehouseFk OR mq.warehouseFk IS NULL) `); // Apply order by tag @@ -158,21 +169,19 @@ module.exports = Self => { // Apply item prices const pricesIndex = stmts.push( - `SELECT - tcp.itemFk, + `SELECT tcp.itemFk, tcp.grouping, tcp.price, tcp.rate, tcp.warehouseFk, tcp.priceKg, - w.name AS warehouse + w.name warehouse FROM tmp.ticketComponentPrice tcp JOIN vn.warehouse w ON w.id = tcp.warehouseFk`) - 1; // Get tags from all items const itemTagsIndex = stmts.push( - `SELECT - t.id, + `SELECT t.id, t.name, t.isFree, t.sourceTable, diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html index 081ce05a0..562723cf7 100644 --- a/modules/order/front/catalog-view/index.html +++ b/modules/order/front/catalog-view/index.html @@ -37,18 +37,6 @@ value="{{::item.value7}}"> - - - - - - {{::item.minQuantity}} -