From 33a4061058c234ed29e55abca6c8758ec24ba29f Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 14:24:55 +0200 Subject: [PATCH 1/6] feat: refs #8069 8069-overStocking --- .../orderRow_updateOverstocking.sql | 52 +++++++++++++++++++ .../hedera/triggers/orderRow_afterInsert.sql | 10 ++++ .../11288-purpleFern/00-firstScript.sql | 3 ++ 3 files changed, 65 insertions(+) create mode 100644 db/routines/hedera/procedures/orderRow_updateOverstocking.sql create mode 100644 db/routines/hedera/triggers/orderRow_afterInsert.sql create mode 100644 db/versions/11288-purpleFern/00-firstScript.sql diff --git a/db/routines/hedera/procedures/orderRow_updateOverstocking.sql b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql new file mode 100644 index 000000000..e919ff922 --- /dev/null +++ b/db/routines/hedera/procedures/orderRow_updateOverstocking.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` +PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT) +BEGIN +/** +* Set amount = 0 to avoid overbooking sales +* +* @param vOrderFk hedera.order.id +*/ + DECLARE vCalcFk INT; + DECLARE vDone BOOL; + DECLARE vWarehouseFk INT; + + DECLARE cWarehouses CURSOR FOR + SELECT DISTINCT warehouseFk + FROM orderRow + WHERE orderFk = vOrderFk + AND shipment = util.VN_CURDATE(); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + OPEN cWarehouses; + checking: LOOP + SET vDone = FALSE; + + FETCH cWarehouses INTO vWarehouseFk; + + IF vDone THEN + LEAVE checking; + END IF; + + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + + UPDATE orderRow r + JOIN `order` o ON o.id = r.orderFk + JOIN orderConfig oc + JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk + SET r.amount = 0 + WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW() + AND a.available <= 0 + AND r.warehouseFk = vWarehouseFk + AND r.orderFk = vOrderFk; + END LOOP; + CLOSE cWarehouses; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/hedera/triggers/orderRow_afterInsert.sql b/db/routines/hedera/triggers/orderRow_afterInsert.sql new file mode 100644 index 000000000..525e5d4d2 --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_afterInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert` + AFTER INSERT ON `orderRow` + FOR EACH ROW +BEGIN + UPDATE `order` + SET rowUpdated = NOW() + WHERE id = NEW.orderFk; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11288-purpleFern/00-firstScript.sql b/db/versions/11288-purpleFern/00-firstScript.sql new file mode 100644 index 000000000..77d60eb40 --- /dev/null +++ b/db/versions/11288-purpleFern/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE hedera.`order` ADD IF NOT EXISTS rowUpdated DATETIME NULL + COMMENT 'Timestamp for last updated record in orderRow table'; \ No newline at end of file From 20836d734c6fdcdd8714e9d2f6b8fc6c4675f2b3 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 7 Oct 2024 14:25:46 +0200 Subject: [PATCH 2/6] fix: refs #8069 order_confirmWithUser --- .../hedera/procedures/order_confirmWithUser.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 2b033b704..a0c5c5667 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -13,6 +13,7 @@ BEGIN */ DECLARE vHasRows BOOL; DECLARE vDone BOOL; + DECLARE vHas0Amount BOOL; DECLARE vWarehouseFk INT; DECLARE vShipment DATE; DECLARE vShipmentDayEnd DATETIME; @@ -97,6 +98,20 @@ BEGIN SELECT employeeFk INTO vUserFk FROM orderConfig; END IF; + CALL orderRow_updateOverstocking(vSelf); + + -- Check if any product has a quantity of 0 + SELECT EXISTS ( + SELECT id + FROM orderRow + WHERE orderFk = vSelf + AND amount = 0 + ) INTO vHas0Amount; + + IF vHas0Amount THEN + CALL util.throw('Remove lines with quantity = 0 before confirming'); + END IF; + START TRANSACTION; CALL order_checkEditable(vSelf); From 679773b33eb8961ec18f7e58e49cbd553cfdbbdb Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 9 Oct 2024 07:26:22 +0200 Subject: [PATCH 3/6] feat: refs #8075 itemShelvingMoving --- db/routines/vn/triggers/itemShelving_beforeUpdate.sql | 3 +++ db/versions/11295-brownLaurel/00-firstScript.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 db/versions/11295-brownLaurel/00-firstScript.sql diff --git a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql index fabdf8efb..53f85de01 100644 --- a/db/routines/vn/triggers/itemShelving_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -9,5 +9,8 @@ BEGIN SET NEW.userFk = account.myUser_getId(); END IF; + IF NEW.shelvingFk <> OLD.shelvingFk THEN + SET NEW.movingState = NULL; + END IF; END$$ DELIMITER ; diff --git a/db/versions/11295-brownLaurel/00-firstScript.sql b/db/versions/11295-brownLaurel/00-firstScript.sql new file mode 100644 index 000000000..2d6ed3a5b --- /dev/null +++ b/db/versions/11295-brownLaurel/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.itemShelving DROP COLUMN IF EXISTS isMoving; +ALTER TABLE vn.itemShelving ADD IF NOT EXISTS movingState ENUM('selected','printed') NULL; \ No newline at end of file From 4eab12dd0453218a0298427534f3d00650797f62 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 9 Oct 2024 07:41:43 +0200 Subject: [PATCH 4/6] fix: refs #8069 throw message in spanish --- db/routines/hedera/procedures/order_confirmWithUser.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index a0c5c5667..b7ed500d7 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -109,8 +109,8 @@ BEGIN ) INTO vHas0Amount; IF vHas0Amount THEN - CALL util.throw('Remove lines with quantity = 0 before confirming'); - END IF; + CALL util.throw('Hay líneas vacías. Por favor, elimínelas'); + END IF; START TRANSACTION; From 208869bd306565cc31bb90a7b09e5c9f2596a9ea Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 10 Oct 2024 08:20:41 +0200 Subject: [PATCH 5/6] fix: refs #8069 removed obsolete variables --- db/routines/hedera/procedures/order_confirmWithUser.sql | 2 -- db/routines/hedera/triggers/orderRow_afterInsert.sql | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index b7ed500d7..44da9d071 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -22,7 +22,6 @@ BEGIN DECLARE vItemFk INT; DECLARE vConcept VARCHAR(30); DECLARE vAmount INT; - DECLARE vAvailable INT; DECLARE vPrice DECIMAL(10,2); DECLARE vSaleFk INT; DECLARE vRowFk INT; @@ -32,7 +31,6 @@ BEGIN DECLARE vClientFk INT; DECLARE vCompanyFk INT; DECLARE vAgencyModeFk INT; - DECLARE vCalcFk INT; DECLARE vIsTaxDataChecked BOOL; DECLARE vDates CURSOR FOR diff --git a/db/routines/hedera/triggers/orderRow_afterInsert.sql b/db/routines/hedera/triggers/orderRow_afterInsert.sql index 525e5d4d2..d0da043e7 100644 --- a/db/routines/hedera/triggers/orderRow_afterInsert.sql +++ b/db/routines/hedera/triggers/orderRow_afterInsert.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterIns FOR EACH ROW BEGIN UPDATE `order` - SET rowUpdated = NOW() + SET rowUpdated = util.VN_NOW() WHERE id = NEW.orderFk; END$$ DELIMITER ; \ No newline at end of file From f3b5a70b673de493a110257cd0fae9c4081160da Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 14 Oct 2024 14:41:25 +0200 Subject: [PATCH 6/6] feat: refs #7323 show right error --- modules/worker/back/methods/worker/new.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index bb43fba99..7da8a8da2 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -217,6 +217,7 @@ module.exports = Self => { const code = e.code; const message = e.sqlMessage; + if (e.message && e.message.includes('Invalid email')) throw new UserError('Invalid email'); if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`); if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`); if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`);