From 9585af8e77a2d8566078fb171276be1f047ddd9a Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 23 May 2024 12:39:30 +0200 Subject: [PATCH 01/60] feat: refs #6822 create entryTransfer --- db/routines/vn/procedures/entryTransfer.sql | 113 ++++++++++++++++++++ db/routines/vn/procedures/entry_clone.sql | 9 +- 2 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 db/routines/vn/procedures/entryTransfer.sql diff --git a/db/routines/vn/procedures/entryTransfer.sql b/db/routines/vn/procedures/entryTransfer.sql new file mode 100644 index 000000000..b0d3c98e3 --- /dev/null +++ b/db/routines/vn/procedures/entryTransfer.sql @@ -0,0 +1,113 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entryTransfer`(vOriginalEntry INT) +BEGIN +/** +* If the bic length is Incorrect throw exception +* +* @param vBic bic code +*/ + + DECLARE vNewEntryFk INT; + DECLARE vTravelFk INT; + DECLARE vWarehouseFk INT; + + -- Clonar la entrada + CALL entry_clone(vOriginalEntry); + + SELECT id INTO vNewEntryFk + FROM entry + WHERE clonedFrom = vOriginalEntry + ORDER BY dated DESC + LIMIT 1; + + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. + INSERT INTO travel( + shipped, + landed, + warehouseInFk, + warehouseOutFk, + `ref`, + isReceived, + agencyModeFk) + SELECT util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY, + t.warehouseInFk, + t.warehouseOutFk, + t.`ref`, + t.isReceived, + t.agencyModeFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + SET vTravelFk = LAST_INSERT_ID(); + + UPDATE entry + SET travelFk = vTravelFk + WHERE id = vNewEntryFk; + + -- Poner a 0 las cantidades + UPDATE buy b + SET b.quantity = 0, b.stickers = 0 + WHERE b.entryFk = vNewEntryFk; + + -- Eliminar duplicados + DELETE b.* + FROM buy b + LEFT JOIN (SELECT b.id, b.itemFk + FROM buy b + WHERE b.entryFk = vNewEntryFk + GROUP BY b.itemFk) tBuy ON tBuy.id = b.id + WHERE b.entryFk = vNewEntryFk + AND tBuy.id IS NULL; + + SELECT t.warehouseInFk INTO vWarehouseFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones + UPDATE buy b + JOIN ( + SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold + FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity + FROM buy b + WHERE b.entryFk = vOriginalEntry + GROUP BY b.itemFk + ) tBuy + LEFT JOIN ( + SELECT ish.itemFk, SUM(visible) visible + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND sh.parked = util.VN_CURDATE() + GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk + LEFT JOIN ( + SELECT s.itemFk, SUM(s.quantity) sold + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN shelving s2 ON s2.code = is2.shelvingFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s2.parked = util.VN_CURDATE() + GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk + WHERE visible = tBuy.totalQuantity + OR iss.itemFk IS NULL + ) sub ON sub.itemFk = b.itemFk + SET b.quantity = sub.totalQuantity - sub.visible - sub.sold + WHERE b.entryFk = vNewEntryFk; + + -- Limpia la nueva entrada + DELETE b.* + FROM buy b + WHERE b.entryFk = vNewEntryFk + AND b.quantity = 0; + + CALL cache.visible_refresh(@c,TRUE,7); + CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index 4f38447c8..b970ac0ff 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_clone`(IN vSelf INT, OUT vNewEntryFk INT) BEGIN /** * clones an entry. @@ -8,6 +8,12 @@ BEGIN */ DECLARE vNewEntryFk INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + START TRANSACTION; CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL); @@ -15,6 +21,5 @@ BEGIN COMMIT; - SELECT vNewEntryFk; END$$ DELIMITER ; From bac07fe265c0393bbbe329bea42e63b6ae5d270f Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 23 May 2024 12:41:59 +0200 Subject: [PATCH 02/60] feat: refs #6822 --- db/routines/vn/procedures/entryTransfer.sql | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/db/routines/vn/procedures/entryTransfer.sql b/db/routines/vn/procedures/entryTransfer.sql index b0d3c98e3..64c9b7680 100644 --- a/db/routines/vn/procedures/entryTransfer.sql +++ b/db/routines/vn/procedures/entryTransfer.sql @@ -12,13 +12,7 @@ BEGIN DECLARE vWarehouseFk INT; -- Clonar la entrada - CALL entry_clone(vOriginalEntry); - - SELECT id INTO vNewEntryFk - FROM entry - WHERE clonedFrom = vOriginalEntry - ORDER BY dated DESC - LIMIT 1; + CALL entry_clone(vOriginalEntry,vNewEntryFk); -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. INSERT INTO travel( From 04f6059d6f67978947f7f385bded3c2c90640839 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 3 Jul 2024 12:03:28 +0200 Subject: [PATCH 03/60] feat: refs #6822 --- modules/entry/back/methods/entry/transfer.js | 38 ++++++++++++++++++++ modules/entry/back/models/entry.js | 1 + 2 files changed, 39 insertions(+) create mode 100644 modules/entry/back/methods/entry/transfer.js diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js new file mode 100644 index 000000000..977832694 --- /dev/null +++ b/modules/entry/back/methods/entry/transfer.js @@ -0,0 +1,38 @@ +module.exports = Self => { + Self.remoteMethodCtx('transfer', { + description: 'Trasladar la mercancia de una entrada al dia siguiente', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + http: {source: 'path'} + } + ], + http: { + path: '/:id/transfer', + verb: 'POST' + } + }); + + Self.transfer = async(ctx, id, options) => { + const myOptions = {userId: ctx.req.accessToken.userId}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + await Self.rawSql('CALL vn.entryTransfer(?)', [id], myOptions); + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js index 6e27e1ece..5f47d718e 100644 --- a/modules/entry/back/models/entry.js +++ b/modules/entry/back/models/entry.js @@ -10,6 +10,7 @@ module.exports = Self => { require('../methods/entry/addFromPackaging')(Self); require('../methods/entry/addFromBuy')(Self); require('../methods/entry/buyLabel')(Self); + require('../methods/entry/transfer')(Self); Self.observe('before save', async function(ctx, options) { if (ctx.isNewInstance) return; From a34376f4d2bf998042920dadc33d3d09711d1452 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 10 Jul 2024 07:31:49 +0200 Subject: [PATCH 04/60] feat: refs #6822 --- .../vn/procedures/{entryTransfer.sql => entry_transfer.sql} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/routines/vn/procedures/{entryTransfer.sql => entry_transfer.sql} (98%) diff --git a/db/routines/vn/procedures/entryTransfer.sql b/db/routines/vn/procedures/entry_transfer.sql similarity index 98% rename from db/routines/vn/procedures/entryTransfer.sql rename to db/routines/vn/procedures/entry_transfer.sql index 64c9b7680..c0f111c34 100644 --- a/db/routines/vn/procedures/entryTransfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entryTransfer`(vOriginalEntry INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT) BEGIN /** * If the bic length is Incorrect throw exception From 5a7d5787f725e15fd86d0e737ab50aed37d1733d Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 11 Jul 2024 07:38:13 +0200 Subject: [PATCH 05/60] feat: refs #6822 clonar travel con warehouseInFk --- db/routines/vn/procedures/entry_transfer.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index c0f111c34..aedfdb7d6 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -2,9 +2,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT) BEGIN /** -* If the bic length is Incorrect throw exception +* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén * -* @param vBic bic code +* @param vOriginalEntry entrada que se quiera adelantar */ DECLARE vNewEntryFk INT; @@ -14,7 +14,7 @@ BEGIN -- Clonar la entrada CALL entry_clone(vOriginalEntry,vNewEntryFk); - -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. INSERT INTO travel( shipped, landed, @@ -26,7 +26,7 @@ BEGIN SELECT util.VN_CURDATE(), util.VN_CURDATE() + INTERVAL 1 DAY, t.warehouseInFk, - t.warehouseOutFk, + t.warehouseInFk, t.`ref`, t.isReceived, t.agencyModeFk From d60a1a3424a19c0ead18976bf53a74d24bb3109b Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 11 Jul 2024 09:39:06 +0200 Subject: [PATCH 06/60] feat: refs #6822 entry_clone --- db/routines/vn/procedures/entry_clone.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index b970ac0ff..679af5f47 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_clone`(IN vSelf INT, OUT vNewEntryFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_clone`(IN vSelf INT, OUT newEntryFk INT) BEGIN /** * clones an entry. @@ -20,6 +20,7 @@ BEGIN CALL entry_copyBuys(vSelf, vNewEntryFk); COMMIT; + SET newEntryFk = vNewEntryFk; END$$ DELIMITER ; From 109770b0a37059b9a53bf626b5adf230ea29cf42 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 17 Jul 2024 10:28:22 +0200 Subject: [PATCH 07/60] feat: refs #6822 return newEntry --- db/routines/vn/procedures/entry_transfer.sql | 14 +++++++++++++- modules/entry/back/methods/entry/transfer.js | 9 ++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index aedfdb7d6..64cafe043 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) BEGIN /** * Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén @@ -11,6 +11,16 @@ BEGIN DECLARE vTravelFk INT; DECLARE vWarehouseFk INT; + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; -- Clonar la entrada CALL entry_clone(vOriginalEntry,vNewEntryFk); @@ -100,6 +110,8 @@ BEGIN WHERE b.entryFk = vNewEntryFk AND b.quantity = 0; + SET vNewEntry = vNewEntryFk; + COMMIT; CALL cache.visible_refresh(@c,TRUE,7); CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index 977832694..53ae4b48c 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -12,6 +12,10 @@ module.exports = Self => { http: { path: '/:id/transfer', verb: 'POST' + }, + returns: { + arg: 'newEntryFk', + type: 'number' } }); @@ -28,8 +32,11 @@ module.exports = Self => { } try { - await Self.rawSql('CALL vn.entryTransfer(?)', [id], myOptions); + await Self.rawSql('CALL vn.entry_transfer(?, @vNewEntry)', [id], myOptions); + const newEntryFk = await Self.rawSql('SELECT @vNewEntry AS newEntryFk', [], myOptions); + if (tx) await tx.commit(); + return newEntryFk; } catch (e) { if (tx) await tx.rollback(); throw e; From 2cb8d07aef43e1021a86e8ebdfbb316ec47116ab Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 17 Jul 2024 10:30:23 +0200 Subject: [PATCH 08/60] feat: refs #6822 --- db/routines/vn/procedures/entry_transfer.sql | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 64cafe043..efe630e36 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -11,9 +11,6 @@ BEGIN DECLARE vTravelFk INT; DECLARE vWarehouseFk INT; - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; @@ -111,9 +108,9 @@ BEGIN AND b.quantity = 0; SET vNewEntry = vNewEntryFk; - COMMIT; + CALL cache.visible_refresh(@c,TRUE,7); CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); - + COMMIT; END$$ DELIMITER ; From 5f63017853f5838ca570ac95dd9f9553d2533f26 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 6 Aug 2024 07:20:30 +0200 Subject: [PATCH 09/60] feat: refs #6822 changes transaction --- .../bs/procedures/ventas_contables_add.sql | 2 +- .../vn/procedures/entry_splitByShelving.sql | 4 +- db/routines/vn/procedures/entry_transfer.sql | 67 ++++++++++--------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index 72b0c0fee..c82cb96d9 100644 --- a/db/routines/bs/procedures/ventas_contables_add.sql +++ b/db/routines/bs/procedures/ventas_contables_add.sql @@ -15,7 +15,7 @@ BEGIN DELETE FROM bs.ventas_contables WHERE year = vYear - AND month = vMonth; + AND month = vMonth; DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; CREATE TEMPORARY TABLE tmp.ticket_list diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index f46278e5a..a8df482fa 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -34,14 +34,14 @@ BEGIN read_loop: LOOP SET vDone = FALSE; - + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; IF vDone THEN LEAVE read_loop; END IF; - IF vIshStickers = vBuyStickers THEN + IF vIshStickers = vBuyStickers THEN UPDATE buy SET entryFk = vToEntryFk WHERE id = vBuyFk; diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index efe630e36..6d7da2b37 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -17,10 +17,11 @@ BEGIN RESIGNAL; END; - START TRANSACTION; -- Clonar la entrada CALL entry_clone(vOriginalEntry,vNewEntryFk); + START TRANSACTION; + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. INSERT INTO travel( shipped, @@ -68,36 +69,38 @@ BEGIN WHERE e.id = vOriginalEntry; -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones + CREATE OR REPLACE TEMPORARY TABLE tBuy + ENGINE = MEMORY + SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold + FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity + FROM buy b + WHERE b.entryFk = vOriginalEntry + GROUP BY b.itemFk + ) tBuy + LEFT JOIN ( + SELECT ish.itemFk, SUM(visible) visible + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND sh.parked = util.VN_CURDATE() + GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk + LEFT JOIN ( + SELECT s.itemFk, SUM(s.quantity) sold + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN shelving s2 ON s2.code = is2.shelvingFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s2.parked = util.VN_CURDATE() + GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk + WHERE visible = tBuy.totalQuantity + OR iss.itemFk IS NULL; + UPDATE buy b - JOIN ( - SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold - FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity - FROM buy b - WHERE b.entryFk = vOriginalEntry - GROUP BY b.itemFk - ) tBuy - LEFT JOIN ( - SELECT ish.itemFk, SUM(visible) visible - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND sh.parked = util.VN_CURDATE() - GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk - LEFT JOIN ( - SELECT s.itemFk, SUM(s.quantity) sold - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemShelvingSale iss ON iss.saleFk = s.id - JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN shelving s2 ON s2.code = is2.shelvingFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked = util.VN_CURDATE() - GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk - WHERE visible = tBuy.totalQuantity - OR iss.itemFk IS NULL - ) sub ON sub.itemFk = b.itemFk + JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk SET b.quantity = sub.totalQuantity - sub.visible - sub.sold WHERE b.entryFk = vNewEntryFk; @@ -107,10 +110,12 @@ BEGIN WHERE b.entryFk = vNewEntryFk AND b.quantity = 0; + COMMIT; + SET vNewEntry = vNewEntryFk; CALL cache.visible_refresh(@c,TRUE,7); CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); - COMMIT; + END$$ DELIMITER ; From e99920196918815c4b7c32da2a47dea48c5f764b Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 11 Sep 2024 09:59:01 +0200 Subject: [PATCH 10/60] feat: refs #6822 entry_clone --- db/routines/vn/procedures/entry_clone.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index 1f436e230..122d521cb 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT, OUT newEntryFk INT) BEGIN /** * clones an entry. From 9a01ae5ccc5f1e07ab36a31dc2f3bf6377cf9d4a Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 23 Oct 2024 12:32:48 +0200 Subject: [PATCH 11/60] feat: refs #6822 tabulaciones --- db/routines/vn/procedures/entry_transfer.sql | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 6d7da2b37..9fbf561b2 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -2,11 +2,10 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) BEGIN /** -* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén -* -* @param vOriginalEntry entrada que se quiera adelantar -*/ - + * Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén + * + * @param vOriginalEntry entrada que se quiera adelantar + */ DECLARE vNewEntryFk INT; DECLARE vTravelFk INT; DECLARE vWarehouseFk INT; @@ -40,7 +39,7 @@ BEGIN t.agencyModeFk FROM travel t JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; + WHERE e.id = vOriginalEntry; SET vTravelFk = LAST_INSERT_ID(); @@ -116,6 +115,5 @@ BEGIN CALL cache.visible_refresh(@c,TRUE,7); CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); - END$$ DELIMITER ; From 01537d410ccda58d453b722f9e6b3f780dd852df Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 27 Nov 2024 13:08:14 +0100 Subject: [PATCH 12/60] feat: refs #6629 refs # 6629 updateAddress --- .../client/back/methods/client/updateAddress.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index 7342b28f1..190ebbc63 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -72,6 +72,10 @@ module.exports = function(Self) { { arg: 'isLogifloraAllowed', type: 'boolean' + }, + { + arg: 'updateObservations', + type: 'boolean' } ], returns: { @@ -127,6 +131,17 @@ module.exports = function(Self) { delete args.ctx; // Remove unwanted properties const updatedAddress = await address.updateAttributes(ctx.args, myOptions); + if (args.updateObservations) { + const ticket = await Self.rawSql(` + UPDATE ticketObservation to2 + JOIN ticket t ON t.id = to2.ticketFk + JOIN address a ON a.id = t.addressFk + JOIN addressObservation ao ON ao.addressFk = a.id + SET to2.description = ao.description + WHERE ao.observationTypeFk = to2.observationTypeFk + AND a.id = ? + AND t.shipped >= util.VN_CURDATE()`, [addressId]); + } return updatedAddress; }; From 4b474834cfd5b15586dfb1e3159eafc8faa5aa05 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 28 Nov 2024 08:13:53 +0100 Subject: [PATCH 13/60] feat: refs #6822 change request --- db/routines/vn/procedures/entry_clone.sql | 6 +- db/routines/vn/procedures/entry_transfer.sql | 96 +++++++++++--------- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index 122d521cb..12738af54 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -1,10 +1,14 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT, OUT newEntryFk INT) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`( + vSelf INT, + OUT newEntryFk INT +) BEGIN /** * clones an entry. * * @param vSelf The entry id + * @param newEntryFk Output parameter of the new created input */ DECLARE vNewEntryFk INT; diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 9fbf561b2..a5a127738 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -1,10 +1,14 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`( + vOriginalEntry INT, + OUT vNewEntry INT + ) BEGIN /** * Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén - * + * * @param vOriginalEntry entrada que se quiera adelantar + * @param vNewEntry nueva entrada creada */ DECLARE vNewEntryFk INT; DECLARE vTravelFk INT; @@ -15,9 +19,9 @@ BEGIN ROLLBACK; RESIGNAL; END; - + -- Clonar la entrada - CALL entry_clone(vOriginalEntry,vNewEntryFk); + CALL entry_clone(vOriginalEntry, vNewEntryFk); START TRANSACTION; @@ -33,7 +37,7 @@ BEGIN SELECT util.VN_CURDATE(), util.VN_CURDATE() + INTERVAL 1 DAY, t.warehouseInFk, - t.warehouseInFk, + t.warehouseOutFk, t.`ref`, t.isReceived, t.agencyModeFk @@ -53,15 +57,15 @@ BEGIN WHERE b.entryFk = vNewEntryFk; -- Eliminar duplicados - DELETE b.* + DELETE b FROM buy b - LEFT JOIN (SELECT b.id, b.itemFk - FROM buy b + LEFT JOIN (SELECT b.id, b.itemFk + FROM buy b WHERE b.entryFk = vNewEntryFk GROUP BY b.itemFk) tBuy ON tBuy.id = b.id WHERE b.entryFk = vNewEntryFk AND tBuy.id IS NULL; - + SELECT t.warehouseInFk INTO vWarehouseFk FROM travel t JOIN entry e ON e.travelFk = t.id @@ -69,42 +73,50 @@ BEGIN -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones CREATE OR REPLACE TEMPORARY TABLE tBuy - ENGINE = MEMORY - SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold - FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity - FROM buy b - WHERE b.entryFk = vOriginalEntry - GROUP BY b.itemFk - ) tBuy - LEFT JOIN ( - SELECT ish.itemFk, SUM(visible) visible - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND sh.parked = util.VN_CURDATE() - GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk - LEFT JOIN ( - SELECT s.itemFk, SUM(s.quantity) sold - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemShelvingSale iss ON iss.saleFk = s.id - JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN shelving s2 ON s2.code = is2.shelvingFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked = util.VN_CURDATE() - GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk - WHERE visible = tBuy.totalQuantity + WITH tBuy AS ( + SELECT b.itemFk, SUM(b.quantity) totalQuantity + FROM buy b + WHERE b.entryFk = vOriginalEntry + GROUP BY b.itemFk + ), + itemShelvings AS ( + SELECT ish.itemFk, SUM(visible) visible + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND sh.parked = util.VN_CURDATE() + GROUP BY ish.itemFk + ), + sales AS ( + SELECT s.itemFk, SUM(s.quantity) sold + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN shelving s2 ON s2.code = is2.shelvingFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s2.parked = util.VN_CURDATE() + GROUP BY s.itemFk + ) + SELECT tmp.itemFk, + IFNULL(iss.visible, 0) visible, + tmp.totalQuantity, + IFNULL(s.sold, 0) sold + FROM tBuy tmp + LEFT JOIN itemShelvings iss ON tmp.itemFk = iss.itemFk + LEFT JOIN sales s ON s.itemFk = tmp.itemFk + WHERE visible = tmp.totalQuantity OR iss.itemFk IS NULL; UPDATE buy b - JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk - SET b.quantity = sub.totalQuantity - sub.visible - sub.sold + JOIN tBuy tmp ON tmp.itemFk = b.itemFk + SET b.quantity = tmp.totalQuantity - tmp.visible - tmp.sold WHERE b.entryFk = vNewEntryFk; - + -- Limpia la nueva entrada - DELETE b.* + DELETE b FROM buy b WHERE b.entryFk = vNewEntryFk AND b.quantity = 0; @@ -113,7 +125,7 @@ BEGIN SET vNewEntry = vNewEntryFk; - CALL cache.visible_refresh(@c,TRUE,7); - CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); + CALL cache.visible_refresh(@c,TRUE,vWarehouseFk); + CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE()); END$$ DELIMITER ; From be394cec283ee2f8dd5e0d694dbe82867e3a188b Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 28 Nov 2024 08:17:32 +0100 Subject: [PATCH 14/60] feat: refs #6822 change request --- modules/entry/back/methods/entry/transfer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index 53ae4b48c..425fc6af1 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -33,7 +33,7 @@ module.exports = Self => { try { await Self.rawSql('CALL vn.entry_transfer(?, @vNewEntry)', [id], myOptions); - const newEntryFk = await Self.rawSql('SELECT @vNewEntry AS newEntryFk', [], myOptions); + const newEntryFk = await Self.rawSql('SELECT @vNewEntry newEntryFk', [], myOptions); if (tx) await tx.commit(); return newEntryFk; From 3f4aa60cd2fcc4a4ae612aa0dd48c7b2e17c04b9 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 28 Nov 2024 08:22:30 +0100 Subject: [PATCH 15/60] feat: refs #6822 poner esquemas en el with --- db/routines/vn/procedures/entry_transfer.sql | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index a5a127738..bd14c4f62 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -75,27 +75,27 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tBuy WITH tBuy AS ( SELECT b.itemFk, SUM(b.quantity) totalQuantity - FROM buy b + FROM vn.buy b WHERE b.entryFk = vOriginalEntry GROUP BY b.itemFk ), itemShelvings AS ( SELECT ish.itemFk, SUM(visible) visible - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk + FROM vn.itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk WHERE s.warehouseFk = vWarehouseFk AND sh.parked = util.VN_CURDATE() GROUP BY ish.itemFk ), sales AS ( SELECT s.itemFk, SUM(s.quantity) sold - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemShelvingSale iss ON iss.saleFk = s.id - JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN shelving s2 ON s2.code = is2.shelvingFk + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN vn.shelving s2 ON s2.code = is2.shelvingFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND s2.parked = util.VN_CURDATE() GROUP BY s.itemFk From c518352bf7118d87c87eda2b5df783f8410bb96c Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 4 Dec 2024 08:12:47 +0100 Subject: [PATCH 16/60] feat: refs #6822 changes required --- db/routines/vn/procedures/entry_clone.sql | 6 ++-- db/routines/vn/procedures/entry_transfer.sql | 35 +++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index 12738af54..c7cbf1f7b 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -1,14 +1,14 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`( vSelf INT, - OUT newEntryFk INT + OUT vOutputEntryFk INT ) BEGIN /** * clones an entry. * * @param vSelf The entry id - * @param newEntryFk Output parameter of the new created input + * @param vOutputEntryFk The new entry id */ DECLARE vNewEntryFk INT; @@ -24,7 +24,7 @@ BEGIN CALL entry_copyBuys(vSelf, vNewEntryFk); COMMIT; - SET newEntryFk = vNewEntryFk; + SET vOutputEntryFk = vNewEntryFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index bd14c4f62..7943f738f 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -13,6 +13,12 @@ BEGIN DECLARE vNewEntryFk INT; DECLARE vTravelFk INT; DECLARE vWarehouseFk INT; + DECLARE vWarehouseInFk INT; + DECLARE vWarehouseOutFk INT; + DECLARE vRef INT; + DECLARE vIsReceived INT; + DECLARE vAgencyModeFk INT; + DECLARE vNewTravelFk INT; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -26,7 +32,25 @@ BEGIN START TRANSACTION; -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. - INSERT INTO travel( + SELECT warehouseInFk,warehouseOutFk,`ref`,isReceived ,agencyModeFk + INTO vWarehouseInFk,vWarehouseOutFk, vRef,vIsReceived, vAgencyModeFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = 1; + + SELECT t.di INTO vNewTravelFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE t.shipped = util.VN_CURDATE() + AND t.landed = util.VN_CURDATE() + INTERVAL 1 DAY + AND warehouseInFk = vWarehouseInFk + AND warehouseOutFk = vWarehouseOutFk + AND `ref` = vRef + AND isReceived =vIsReceived + AND agencyModeFk = vAgencyModeFk; + + IF NOT vNewTravelFk THEN + INSERT INTO travel( shipped, landed, warehouseInFk, @@ -45,7 +69,10 @@ BEGIN JOIN entry e ON e.travelFk = t.id WHERE e.id = vOriginalEntry; - SET vTravelFk = LAST_INSERT_ID(); + SET vTravelFk = LAST_INSERT_ID(); + ELSE + SET vTravelFk = vNewTravelFk; + END IF; UPDATE entry SET travelFk = vTravelFk @@ -82,7 +109,7 @@ BEGIN itemShelvings AS ( SELECT ish.itemFk, SUM(visible) visible FROM vn.itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.shelving sh ON sh.id = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.warehouseFk = vWarehouseFk @@ -95,7 +122,7 @@ BEGIN JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN vn.shelving s2 ON s2.code = is2.shelvingFk + JOIN vn.shelving s2 ON s2.id = is2.shelvingFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND s2.parked = util.VN_CURDATE() GROUP BY s.itemFk From b97b61c7dd8304193e5af7a279c9d62270ed9de5 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 4 Dec 2024 09:40:28 +0100 Subject: [PATCH 17/60] feat: refs #6822 fix --- db/routines/vn/procedures/entry_transfer.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 7943f738f..1aa2841ce 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -36,9 +36,9 @@ BEGIN INTO vWarehouseInFk,vWarehouseOutFk, vRef,vIsReceived, vAgencyModeFk FROM travel t JOIN entry e ON e.travelFk = t.id - WHERE e.id = 1; + WHERE e.id = vOriginalEntry; - SELECT t.di INTO vNewTravelFk + SELECT t.id INTO vNewTravelFk FROM travel t JOIN entry e ON e.travelFk = t.id WHERE t.shipped = util.VN_CURDATE() @@ -49,7 +49,7 @@ BEGIN AND isReceived =vIsReceived AND agencyModeFk = vAgencyModeFk; - IF NOT vNewTravelFk THEN + IF vNewTravelFk IS NULL THEN INSERT INTO travel( shipped, landed, @@ -113,7 +113,7 @@ BEGIN JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.warehouseFk = vWarehouseFk - AND sh.parked = util.VN_CURDATE() + AND sh.parked BETWEEN CURDATE() AND util.dayend(CURDATE()) GROUP BY ish.itemFk ), sales AS ( @@ -124,7 +124,7 @@ BEGIN JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk JOIN vn.shelving s2 ON s2.id = is2.shelvingFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked = util.VN_CURDATE() + AND s2.parked BETWEEN CURDATE() AND util.dayend(CURDATE()) GROUP BY s.itemFk ) SELECT tmp.itemFk, @@ -134,7 +134,7 @@ BEGIN FROM tBuy tmp LEFT JOIN itemShelvings iss ON tmp.itemFk = iss.itemFk LEFT JOIN sales s ON s.itemFk = tmp.itemFk - WHERE visible = tmp.totalQuantity + WHERE visible < tmp.totalQuantity OR iss.itemFk IS NULL; UPDATE buy b From 6ac30dcb0c11bf1e9289460c875569a8cb4dcde2 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 4 Dec 2024 13:32:10 +0100 Subject: [PATCH 18/60] feat: refs #6822 fix conflict --- db/routines/vn/procedures/entry_transfer.sql | 7 ++++--- modules/entry/back/models/entry.js | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 1aa2841ce..6e9607691 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -75,7 +75,8 @@ BEGIN END IF; UPDATE entry - SET travelFk = vTravelFk + SET travelFk = vTravelFk, + evaNotes = vOriginalEntry WHERE id = vNewEntryFk; -- Poner a 0 las cantidades @@ -113,7 +114,7 @@ BEGIN JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.warehouseFk = vWarehouseFk - AND sh.parked BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND sh.parked >= util.VN_CURDATE() GROUP BY ish.itemFk ), sales AS ( @@ -124,7 +125,7 @@ BEGIN JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk JOIN vn.shelving s2 ON s2.id = is2.shelvingFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND s2.parked >= util.VN_CURDATE() GROUP BY s.itemFk ) SELECT tmp.itemFk, diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js index 56ff69bf5..03cbd6e7f 100644 --- a/modules/entry/back/models/entry.js +++ b/modules/entry/back/models/entry.js @@ -13,7 +13,6 @@ module.exports = Self => { require('../methods/entry/addFromBuy')(Self); require('../methods/entry/buyLabel')(Self); require('../methods/entry/transfer')(Self); - require('../methods/entry/print')(Self); require('../methods/entry/labelSupplier')(Self); require('../methods/entry/buyLabelSupplier')(Self); From 43bbdfd4215a308e4f41fc1815ae403d1b2f48a2 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 11 Dec 2024 11:54:40 +0100 Subject: [PATCH 19/60] feat: refs #6822 --- db/routines/vn/procedures/entry_transfer.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 6e9607691..98ddf3ef5 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -113,6 +113,8 @@ BEGIN JOIN vn.shelving sh ON sh.id = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.buy b ON b.id = ish.buyFk + JOIN vn.entry e ON e.id = b.entryFk WHERE s.warehouseFk = vWarehouseFk AND sh.parked >= util.VN_CURDATE() GROUP BY ish.itemFk From ab1eed66df04760db013af5f2f4fc832a8dcd647 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 13 Dec 2024 12:29:03 +0100 Subject: [PATCH 20/60] feat: refs #6822 changes required --- db/routines/vn/procedures/entry_transfer.sql | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 98ddf3ef5..c368e1e55 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -18,7 +18,7 @@ BEGIN DECLARE vRef INT; DECLARE vIsReceived INT; DECLARE vAgencyModeFk INT; - DECLARE vNewTravelFk INT; + DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -32,24 +32,23 @@ BEGIN START TRANSACTION; -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. - SELECT warehouseInFk,warehouseOutFk,`ref`,isReceived ,agencyModeFk - INTO vWarehouseInFk,vWarehouseOutFk, vRef,vIsReceived, vAgencyModeFk + SELECT t.warehouseInFk, t.warehouseOutFk, t.`ref`, t.isReceived, t.agencyModeFk + INTO vWarehouseInFk, vWarehouseOutFk, vRef, vIsReceived, vAgencyModeFk FROM travel t JOIN entry e ON e.travelFk = t.id WHERE e.id = vOriginalEntry; - SELECT t.id INTO vNewTravelFk + SELECT id INTO vTravelFk FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE t.shipped = util.VN_CURDATE() - AND t.landed = util.VN_CURDATE() + INTERVAL 1 DAY + WHERE shipped = util.VN_CURDATE() + AND landed = vTomorrow AND warehouseInFk = vWarehouseInFk AND warehouseOutFk = vWarehouseOutFk AND `ref` = vRef AND isReceived =vIsReceived AND agencyModeFk = vAgencyModeFk; - IF vNewTravelFk IS NULL THEN + IF vTravelFk IS NULL THEN INSERT INTO travel( shipped, landed, @@ -59,7 +58,7 @@ BEGIN isReceived, agencyModeFk) SELECT util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY, + vTomorrow, t.warehouseInFk, t.warehouseOutFk, t.`ref`, @@ -70,8 +69,6 @@ BEGIN WHERE e.id = vOriginalEntry; SET vTravelFk = LAST_INSERT_ID(); - ELSE - SET vTravelFk = vNewTravelFk; END IF; UPDATE entry @@ -115,6 +112,7 @@ BEGIN JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.buy b ON b.id = ish.buyFk JOIN vn.entry e ON e.id = b.entryFk + JOIN tBuy t ON t.itemFk = ish.itemFk WHERE s.warehouseFk = vWarehouseFk AND sh.parked >= util.VN_CURDATE() GROUP BY ish.itemFk @@ -126,6 +124,7 @@ BEGIN JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk JOIN vn.shelving s2 ON s2.id = is2.shelvingFk + JOIN tBuy t ON t.itemFk = s.itemFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND s2.parked >= util.VN_CURDATE() GROUP BY s.itemFk From 781a8a4d105c88edfd5b5395f4a169b189add6d6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 13 Dec 2024 13:49:35 +0100 Subject: [PATCH 21/60] refactor: refs #8205 Added geoFk Fk --- db/versions/11383-maroonChico/00-town.sql | 10 ++++++++++ db/versions/11383-maroonChico/01-postCode.sql | 10 ++++++++++ db/versions/11383-maroonChico/02-province.sql | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 db/versions/11383-maroonChico/00-town.sql create mode 100644 db/versions/11383-maroonChico/01-postCode.sql create mode 100644 db/versions/11383-maroonChico/02-province.sql diff --git a/db/versions/11383-maroonChico/00-town.sql b/db/versions/11383-maroonChico/00-town.sql new file mode 100644 index 000000000..8fdd8c7b0 --- /dev/null +++ b/db/versions/11383-maroonChico/00-town.sql @@ -0,0 +1,10 @@ +UPDATE vn.town t + LEFT JOIN vn.zoneGeo zg ON zg.id = t.geoFk + SET t.geoFk = NULL + WHERE zg.id IS NULL; + +ALTER TABLE vn.town + ADD CONSTRAINT town_zoneGeo_FK FOREIGN KEY (geoFk) + REFERENCES vn.zoneGeo(id) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/db/versions/11383-maroonChico/01-postCode.sql b/db/versions/11383-maroonChico/01-postCode.sql new file mode 100644 index 000000000..668cf69cb --- /dev/null +++ b/db/versions/11383-maroonChico/01-postCode.sql @@ -0,0 +1,10 @@ +UPDATE vn.postCode pc + LEFT JOIN vn.zoneGeo zg ON zg.id = pc.geoFk + SET pc.geoFk = NULL + WHERE zg.id IS NULL; + +ALTER TABLE vn.postCode + ADD CONSTRAINT postCode_zoneGeo_FK FOREIGN KEY (geoFk) + REFERENCES vn.zoneGeo(id) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/db/versions/11383-maroonChico/02-province.sql b/db/versions/11383-maroonChico/02-province.sql new file mode 100644 index 000000000..c16d33cd8 --- /dev/null +++ b/db/versions/11383-maroonChico/02-province.sql @@ -0,0 +1,10 @@ +UPDATE vn.province p + LEFT JOIN vn.zoneGeo zg ON zg.id = p.geoFk + SET p.geoFk = NULL + WHERE zg.id IS NULL; + +ALTER TABLE vn.province + ADD CONSTRAINT province_zoneGeo_FK FOREIGN KEY (geoFk) + REFERENCES vn.zoneGeo(id) + ON DELETE RESTRICT + ON UPDATE CASCADE; From 02d77324b170271d88231a57334eadd6a7eebd26 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 3 Jan 2025 08:27:34 +0100 Subject: [PATCH 22/60] feat: refs #6822 crear test --- db/routines/vn/procedures/entry_transfer.sql | 16 ++++------ .../back/methods/entry/specs/transfer.spec.js | 30 +++++++++++++++++++ modules/entry/back/methods/entry/transfer.js | 2 +- 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 modules/entry/back/methods/entry/specs/transfer.spec.js diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index c368e1e55..63f3f14ab 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`( vOriginalEntry INT, - OUT vNewEntry INT + OUT vNewEntryFk INT ) BEGIN /** @@ -10,7 +10,6 @@ BEGIN * @param vOriginalEntry entrada que se quiera adelantar * @param vNewEntry nueva entrada creada */ - DECLARE vNewEntryFk INT; DECLARE vTravelFk INT; DECLARE vWarehouseFk INT; DECLARE vWarehouseInFk INT; @@ -97,7 +96,7 @@ BEGIN WHERE e.id = vOriginalEntry; -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones - CREATE OR REPLACE TEMPORARY TABLE tBuy + CREATE OR REPLACE TEMPORARY TABLE buys WITH tBuy AS ( SELECT b.itemFk, SUM(b.quantity) totalQuantity FROM vn.buy b @@ -105,7 +104,7 @@ BEGIN GROUP BY b.itemFk ), itemShelvings AS ( - SELECT ish.itemFk, SUM(visible) visible + SELECT ish.itemFk, SUM(ish.visible) visible FROM vn.itemShelving ish JOIN vn.shelving sh ON sh.id = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk @@ -140,20 +139,15 @@ BEGIN OR iss.itemFk IS NULL; UPDATE buy b - JOIN tBuy tmp ON tmp.itemFk = b.itemFk + JOIN buys tmp ON tmp.itemFk = b.itemFk SET b.quantity = tmp.totalQuantity - tmp.visible - tmp.sold WHERE b.entryFk = vNewEntryFk; -- Limpia la nueva entrada - DELETE b - FROM buy b - WHERE b.entryFk = vNewEntryFk - AND b.quantity = 0; + DELETE FROM buy WHERE entryFk = vNewEntryFk AND quantity = 0; COMMIT; - SET vNewEntry = vNewEntryFk; - CALL cache.visible_refresh(@c,TRUE,vWarehouseFk); CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE()); END$$ diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js new file mode 100644 index 000000000..3a223a335 --- /dev/null +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -0,0 +1,30 @@ +const transfer = require('../transfer'); + +const models = require('vn-loopback/server/server').models; + +describe('Transfer merchandise from one entry to the next day()', () => { + const ctx = {req: {accessToken: {userId: 18}}}; + + it('should Transfer buys not located', async() => { + const id = 3; + const item = 8; + const buy = 6; + const originalEntry = 4; + + const tx = await models.ItemShelving.beginTransaction({}); + const options = {transaction: tx}; + try { + const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options); + await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options); + const result = await models.Entry.transfer(ctx, originalEntry, options); + const buys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options); + + expect(buys.length).toEqual(3); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index 425fc6af1..1c5f38c21 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('transfer', { - description: 'Trasladar la mercancia de una entrada al dia siguiente', + description: 'Transfer merchandise from one entry to the next day', accepts: [ { arg: 'id', From 04734ac55c5bf0bef6481ea3448b0609fd51fb11 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 7 Jan 2025 08:59:47 +0100 Subject: [PATCH 23/60] feat: refs #6822 test transfer --- .../back/methods/entry/specs/transfer.spec.js | 40 +++++++++++++------ modules/entry/back/models/buy.json | 7 +++- modules/item/back/models/item-shelving.json | 9 ++++- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index 3a223a335..3efd081d7 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -1,25 +1,41 @@ -const transfer = require('../transfer'); +// const transfer = require('../transfer'); const models = require('vn-loopback/server/server').models; describe('Transfer merchandise from one entry to the next day()', () => { - const ctx = {req: {accessToken: {userId: 18}}}; - - it('should Transfer buys not located', async() => { - const id = 3; - const item = 8; - const buy = 6; - const originalEntry = 4; - + fit('should Transfer buys not located', async() => { const tx = await models.ItemShelving.beginTransaction({}); const options = {transaction: tx}; + try { + const id = 3; + const item = 8; + const buy = 6; + const originalEntry = 4; + const ctx = {req: {accessToken: {userId: 48}}}; + const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options); await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options); - const result = await models.Entry.transfer(ctx, originalEntry, options); - const buys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options); - expect(buys.length).toEqual(3); + const result = await models.Entry.transfer(ctx, originalEntry, options); + + const originalEntrybuys = await models.Buy.find({where: {entryFk: originalEntry}}, options); + + const newEntrybuys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options); + + const itemShelvingsWithBuys = await models.Buy.find({ + include: { + relation: 'itemShelving', + scope: { + fields: ['id'], + }, + }, + where: {entryFk: originalEntry}, + }, options); + + const hasItemShelving = await itemShelvingsWithBuys.filter(buy => buy.itemShelving().length); + + expect(newEntrybuys.length).toEqual(originalEntrybuys.length - hasItemShelving.length); await tx.rollback(); } catch (e) { diff --git a/modules/entry/back/models/buy.json b/modules/entry/back/models/buy.json index 14cafde06..cd1e54de7 100644 --- a/modules/entry/back/models/buy.json +++ b/modules/entry/back/models/buy.json @@ -114,6 +114,11 @@ "type": "belongsTo", "model": "Delivery", "foreignKey": "deliveryFk" - } + }, + "itemShelving": { + "type": "hasMany", + "model": "ItemShelving", + "foreignKey": "buyFk" + } } } diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 483d6bf3d..5c31e9e4e 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -61,6 +61,11 @@ "type": "belongsTo", "model": "Shelving", "foreignKey": "shelvingFk" - } + }, + "buy": { + "type": "belongsTo", + "model": "Buy", + "foreignKey": "buyFk" + } } -} \ No newline at end of file +} From b7658f5814a98ba5aa06ca6ed50ac18c9741074e Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 7 Jan 2025 09:28:17 +0100 Subject: [PATCH 24/60] feat: refs #6822 fix test --- modules/entry/back/methods/entry/specs/transfer.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index 3efd081d7..e4f4747c6 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -3,7 +3,7 @@ const models = require('vn-loopback/server/server').models; describe('Transfer merchandise from one entry to the next day()', () => { - fit('should Transfer buys not located', async() => { + it('should Transfer buys not located', async() => { const tx = await models.ItemShelving.beginTransaction({}); const options = {transaction: tx}; From ebf234dd4fbeca5c484bf2653ae6ab96e2213053 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 7 Jan 2025 09:49:55 +0100 Subject: [PATCH 25/60] feat: refs #6822 delete fixtures to test --- modules/entry/back/methods/entry/specs/transfer.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index e4f4747c6..0ab35e4a3 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -23,6 +23,8 @@ describe('Transfer merchandise from one entry to the next day()', () => { const newEntrybuys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options); + const newTravel = await models.Entry.find({where: {id: result[0].newEntryFk}}, options); + const itemShelvingsWithBuys = await models.Buy.find({ include: { relation: 'itemShelving', @@ -37,6 +39,9 @@ describe('Transfer merchandise from one entry to the next day()', () => { expect(newEntrybuys.length).toEqual(originalEntrybuys.length - hasItemShelving.length); + await models.Travel.destroyById(newTravel, options); + await models.Entry.destroyById(result[0].newEntryFk, options); + await tx.rollback(); } catch (e) { await tx.rollback(); From c4c9b5640ec50496af87decbcf56bbe14dfd4f50 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 7 Jan 2025 12:02:32 +0100 Subject: [PATCH 26/60] feat: refs #6822 modify transaction --- db/routines/vn/procedures/entry_clone.sql | 7 ++++--- db/routines/vn/procedures/entry_transfer.sql | 8 +++++--- .../entry/back/methods/entry/specs/transfer.spec.js | 10 +++------- modules/entry/back/methods/entry/transfer.js | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index c7cbf1f7b..511ff4837 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -12,18 +12,19 @@ BEGIN */ DECLARE vNewEntryFk INT; + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; - START TRANSACTION; + CALL util.tx_start(vIsRequiredTx); CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL); CALL entry_copyBuys(vSelf, vNewEntryFk); - COMMIT; + CALL util.tx_commit(vIsRequiredTx); SET vOutputEntryFk = vNewEntryFk; END$$ diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 63f3f14ab..123470038 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -19,16 +19,18 @@ BEGIN DECLARE vAgencyModeFk INT; DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; -- Clonar la entrada CALL entry_clone(vOriginalEntry, vNewEntryFk); - START TRANSACTION; + CALL util.tx_start(vIsRequiredTx); + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. SELECT t.warehouseInFk, t.warehouseOutFk, t.`ref`, t.isReceived, t.agencyModeFk @@ -146,7 +148,7 @@ BEGIN -- Limpia la nueva entrada DELETE FROM buy WHERE entryFk = vNewEntryFk AND quantity = 0; - COMMIT; + CALL util.tx_commit(vIsRequiredTx); CALL cache.visible_refresh(@c,TRUE,vWarehouseFk); CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE()); diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index 0ab35e4a3..74e89df46 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -17,13 +17,12 @@ describe('Transfer merchandise from one entry to the next day()', () => { const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options); await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options); - const result = await models.Entry.transfer(ctx, originalEntry, options); - + const [{newEntryFk}] = await models.Entry.transfer(ctx, originalEntry, options); const originalEntrybuys = await models.Buy.find({where: {entryFk: originalEntry}}, options); - const newEntrybuys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options); + const newEntrybuys = await models.Buy.find({where: {entryFk: newEntryFk}}, options); - const newTravel = await models.Entry.find({where: {id: result[0].newEntryFk}}, options); + await models.Entry.find({where: {id: newEntryFk}}, options); const itemShelvingsWithBuys = await models.Buy.find({ include: { @@ -39,9 +38,6 @@ describe('Transfer merchandise from one entry to the next day()', () => { expect(newEntrybuys.length).toEqual(originalEntrybuys.length - hasItemShelving.length); - await models.Travel.destroyById(newTravel, options); - await models.Entry.destroyById(result[0].newEntryFk, options); - await tx.rollback(); } catch (e) { await tx.rollback(); diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index 1c5f38c21..aa4b4c819 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -33,7 +33,7 @@ module.exports = Self => { try { await Self.rawSql('CALL vn.entry_transfer(?, @vNewEntry)', [id], myOptions); - const newEntryFk = await Self.rawSql('SELECT @vNewEntry newEntryFk', [], myOptions); + const newEntryFk = await Self.rawSql('SELECT @vNewEntry newEntryFk', null, myOptions); if (tx) await tx.commit(); return newEntryFk; From 115756aaf3b71300ebd604588478f9f2266597e3 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 8 Jan 2025 07:44:49 +0100 Subject: [PATCH 27/60] feat: refs #6822 fix transfer test --- modules/entry/back/methods/entry/specs/transfer.spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index 74e89df46..cc712b994 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -1,5 +1,3 @@ -// const transfer = require('../transfer'); - const models = require('vn-loopback/server/server').models; describe('Transfer merchandise from one entry to the next day()', () => { @@ -22,8 +20,6 @@ describe('Transfer merchandise from one entry to the next day()', () => { const newEntrybuys = await models.Buy.find({where: {entryFk: newEntryFk}}, options); - await models.Entry.find({where: {id: newEntryFk}}, options); - const itemShelvingsWithBuys = await models.Buy.find({ include: { relation: 'itemShelving', From 050c338ffb67283ae303f06e786a492bd88262b8 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 13 Jan 2025 14:29:13 +0100 Subject: [PATCH 28/60] feat: refs #8387 crudModel --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 5 +++-- modules/item/back/models/item-tag.js | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 80da13ae5..e6b7b98c1 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -250,5 +250,6 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fcee0e111..93ba0d59a 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,5 +398,6 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" -} + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 5b7163913..338ef64cf 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -10,4 +10,27 @@ module.exports = Self => { return new UserError(`Tag value cannot be blank`); return err; }); + + Self.observe('before save', async ctx => { + const validValue = new RegExp('^\\d{1,3}(-\\d{1,3})?$'); + let tagFk; + let value; + + if (ctx.isNewInstance) { + tagFk = ctx.instance.tagFk; + value = ctx.instance.value; + } + const newData = ctx.data.value || null; + const currentData = ctx.currentInstance.value || null; + const models = Self.app.models; + const validTag = await models.Tag.findOne({where: {name: 'Longitud(cm)'}}); + + if (tagFk === validTag.id || (currentData && currentData === validTag.id)) { + if ( + (value && !validValue.test(value)) || + (newData && !validValue.test(newData)) + ) + throw new UserError('The value must be a number or a range of numbers'); + } + }); }; From 6fd8c5ded6816c4437bd833af98de12d7ddc837b Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 13 Jan 2025 14:33:32 +0100 Subject: [PATCH 29/60] feat: refs #8387 fix --- loopback/locale/en.json | 5 ++--- loopback/locale/es.json | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index e6b7b98c1..2e25408c6 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -250,6 +250,5 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 93ba0d59a..57aa2845a 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,6 +398,5 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "There are tickets to be invoiced": "La zona tiene tickets por facturar" +} From 849bcd1ff55633de28469dfd812b21a6cb9805b6 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 14 Jan 2025 13:39:43 +0100 Subject: [PATCH 30/60] feat: refs #6629 test back updateObservations --- .../client/specs/updateAddress.spec.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index 0453332d7..e8d6bb8d8 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -157,4 +157,57 @@ describe('Address updateAddress', () => { throw e; } }); + + fit('should update ticket observations when updateObservations is true', async() => { + const tx = await models.Client.beginTransaction({}); + const client = 1103; + const address = 123; + const ticket = 31; + const observationType = 3; + + const salesAssistantId = 21; + const addressObservation = 'nuevo texto'; + const ticketObservation = 'texto a modificar'; + + try { + const options = {transaction: tx}; + ctx.req.accessToken.userId = salesAssistantId; + ctx.args = { + updateObservations: true, + incotermsFk: incotermsId, + provinceFk: provinceId, + customsAgentFk: customAgentOneId + }; + + await models.AddressObservation.create({ + addressFk: address, + observationTypeFk: observationType, + description: addressObservation + }, options); + + await models.TicketObservation.create({ + ticketFk: ticket, + observationTypeFk: observationType, + description: ticketObservation + }, options); + + await models.Client.updateAddress(ctx, client, address, options); + + const updatedObservation = await models.TicketObservation.findOne({ + where: {ticketFk: ticket, observationTypeFk: observationType} + }, options); + + // const address = await models.Address.findById(addressId, null, options); + + // const addressObservation = await models.addressObservation.findById(addressId, null, options); + + expect(updatedObservation).toEqual(addressObservation); + // expect(1).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 807ddf07ad33b8fd77aa81b0ddb5d31b3190ecfb Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 15 Jan 2025 07:31:49 +0100 Subject: [PATCH 31/60] feat: refs #6629 test back --- .../back/methods/client/specs/updateAddress.spec.js | 9 ++------- modules/client/back/methods/client/updateAddress.js | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index e8d6bb8d8..233ab9ccb 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -158,7 +158,7 @@ describe('Address updateAddress', () => { } }); - fit('should update ticket observations when updateObservations is true', async() => { + it('should update ticket observations when updateObservations is true', async() => { const tx = await models.Client.beginTransaction({}); const client = 1103; const address = 123; @@ -197,12 +197,7 @@ describe('Address updateAddress', () => { where: {ticketFk: ticket, observationTypeFk: observationType} }, options); - // const address = await models.Address.findById(addressId, null, options); - - // const addressObservation = await models.addressObservation.findById(addressId, null, options); - - expect(updatedObservation).toEqual(addressObservation); - // expect(1).toEqual(1); + expect(updatedObservation.description).toEqual(addressObservation); await tx.rollback(); } catch (e) { diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index 69e288db3..e6e5adb45 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -148,7 +148,7 @@ module.exports = function(Self) { SET to2.description = ao.description WHERE ao.observationTypeFk = to2.observationTypeFk AND a.id = ? - AND t.shipped >= util.VN_CURDATE()`, [addressId]); + AND t.shipped >= util.VN_CURDATE()`, [addressId], myOptions); } return updatedAddress; From 93c9ef6f4cbb3e4b2d752019e4b374fefe09eb23 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 15 Jan 2025 10:25:21 +0100 Subject: [PATCH 32/60] feat: refs #8387 changes --- loopback/locale/en.json | 7 ++++--- loopback/locale/es.json | 5 +++-- modules/item/back/models/item-tag.js | 14 ++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 8d5eab4bc..4fe11c2b6 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -211,7 +211,7 @@ "Name should be uppercase": "Name should be uppercase", "You cannot update these fields": "You cannot update these fields", "CountryFK cannot be empty": "Country cannot be empty", - "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", + "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", "You are not allowed to modify the alias": "You are not allowed to modify the alias", "You already have the mailAlias": "You already have the mailAlias", "This machine is already in use.": "This machine is already in use.", @@ -251,5 +251,6 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" -} + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5558c0964..9a24f84ba 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,5 +398,6 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" -} + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 338ef64cf..4c1ef4d4a 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -19,17 +19,15 @@ module.exports = Self => { if (ctx.isNewInstance) { tagFk = ctx.instance.tagFk; value = ctx.instance.value; + } else { + tagFk = ctx.currentInstance.tagFk; + value = ctx.data.value; } - const newData = ctx.data.value || null; - const currentData = ctx.currentInstance.value || null; const models = Self.app.models; - const validTag = await models.Tag.findOne({where: {name: 'Longitud(cm)'}}); + const validTag = await models.Tag.findOne({where: {name: 'Longitud(m)'}}); - if (tagFk === validTag.id || (currentData && currentData === validTag.id)) { - if ( - (value && !validValue.test(value)) || - (newData && !validValue.test(newData)) - ) + if (tagFk === validTag.id) { + if ((value && !validValue.test(value))) throw new UserError('The value must be a number or a range of numbers'); } }); From ec14281a820d86bfa03155c50e587b5159ff0d99 Mon Sep 17 00:00:00 2001 From: jtubau Date: Wed, 15 Jan 2025 13:37:57 +0100 Subject: [PATCH 33/60] feat: refs #7322 add optional addressFk parameter to transferClient method --- modules/ticket/back/methods/ticket/transferClient.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 95bee008d..99e89da99 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -12,6 +12,10 @@ module.exports = Self => { arg: 'clientFk', type: 'number', required: true, + }, { + arg: 'addressFk', + type: 'number', + required: false, }], http: { path: `/:id/transferClient`, @@ -19,7 +23,7 @@ module.exports = Self => { } }); - Self.transferClient = async(ctx, id, clientFk, options) => { + Self.transferClient = async(ctx, id, clientFk, addressFk, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -43,10 +47,10 @@ module.exports = Self => { const client = await models.Client.findById(clientFk, {fields: ['id', 'defaultAddressFk']}, myOptions); - const address = await models.Address.findById(client.defaultAddressFk, + const address = await models.Address.findById(addressFk ? addressFk : client.defaultAddressFk, {fields: ['id', 'nickname']}, myOptions); - const attributes = {clientFk, addressFk: client.defaultAddressFk, nickname: address.nickname}; + const attributes = {clientFk, addressFk: address.id, nickname: address.nickname}; const tickets = []; const ticketIds = []; From b78603275fceb1e53898294b66839a2b7f752286 Mon Sep 17 00:00:00 2001 From: jtubau Date: Wed, 15 Jan 2025 14:13:00 +0100 Subject: [PATCH 34/60] fix: refs #7322 reorder parameters in transferClient method for consistency --- modules/ticket/back/methods/ticket/transferClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 99e89da99..9bf2a861e 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -23,7 +23,7 @@ module.exports = Self => { } }); - Self.transferClient = async(ctx, id, clientFk, addressFk, options) => { + Self.transferClient = async(ctx, id, clientFk, options, addressFk) => { const models = Self.app.models; const myOptions = {}; let tx; From 0bfd0895d7a418382545b41cd623af86e80df1c1 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 17 Jan 2025 12:11:18 +0100 Subject: [PATCH 35/60] feat: refs #8077 sumDefaulter --- .../client/back/methods/defaulter/filter.js | 58 +++++++++++-------- .../methods/defaulter/specs/filter.spec.js | 29 ++++++++-- 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 5359ce4a7..e00048cf5 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -21,7 +21,7 @@ module.exports = Self => { } ], returns: { - type: ['object'], + type: 'object', root: true }, http: { @@ -41,23 +41,28 @@ module.exports = Self => { switch (param) { case 'search': return {or: [ - {'d.clientFk': value}, - {'d.clientName': {like: `%${value}%`}} + {'c.id': value}, + {'c.name': {like: `%${value}%`}} ]}; } }); - filter = mergeFilters(ctx.args.filter, {where}); + const date = Date.vnNew(); + date.setHours(0, 0, 0, 0); + + filter = mergeFilters({where: {'d.created': date, 'd.amount': {gt: 0}}}, ctx.args.filter); + filter = mergeFilters(filter, {where}); const stmts = []; - const date = Date.vnNew(); - date.setHours(0, 0, 0, 0); - const stmt = new ParameterizedSQL( - `SELECT * - FROM ( - SELECT - DISTINCT c.id clientFk, + let stmt = new ParameterizedSQL( + `CREATE OR REPLACE TEMPORARY TABLE tmp.defaulters + WITH clientObservations AS + (SELECT clientFk,text, created, workerFk + FROM vn.clientObservation + GROUP BY clientFk + ORDER BY created DESC + )SELECT c.id clientFk, c.name clientName, c.salesPersonFk, c.businessTypeFk = 'worker' isWorker, @@ -80,36 +85,43 @@ module.exports = Self => { JOIN client c ON c.id = d.clientFk JOIN country cn ON cn.id = c.countryFk JOIN payMethod pm ON pm.id = c.payMethodFk - LEFT JOIN clientObservation co ON co.clientFk = c.id + LEFT JOIN clientObservations co ON co.clientFk = c.id LEFT JOIN account.user u ON u.id = c.salesPersonFk LEFT JOIN account.user uw ON uw.id = co.workerFk LEFT JOIN ( - SELECT r1.started, r1.clientFk, r1.finished + SELECT r1.started, r1.clientFk, r1.finished FROM recovery r1 JOIN ( - SELECT MAX(started) AS maxStarted, clientFk + SELECT MAX(started) maxStarted, clientFk FROM recovery GROUP BY clientFk ) r2 ON r1.clientFk = r2.clientFk AND r1.started = r2.maxStarted + WHERE r1.finished + GROUP BY r1.clientFk ) r ON r.clientFk = c.id LEFT JOIN workerDepartment wd ON wd.workerFk = u.id - JOIN department dp ON dp.id = wd.departmentFk - WHERE - d.created = ? - AND d.amount > 0 - ORDER BY co.created DESC) d` - , [date]); + LEFT JOIN department dp ON dp.id = wd.departmentFk`); stmt.merge(conn.makeWhere(filter.where)); - stmt.merge(`GROUP BY d.clientFk`); + stmts.push(stmt); + + stmt = new ParameterizedSQL(` + SELECT SUM(amount) amount + FROM tmp.defaulters + `); + stmts.push(stmt); + + stmt = new ParameterizedSQL(` + SELECT * + FROM tmp.defaulters + `); stmt.merge(conn.makeOrderBy(filter.order)); - stmt.merge(conn.makeLimit(filter)); const itemsIndex = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); - return itemsIndex === 0 ? result : result[itemsIndex]; + return {defaulters: result[itemsIndex], amount: result[itemsIndex - 1][0].amount}; }; }; diff --git a/modules/client/back/methods/defaulter/specs/filter.spec.js b/modules/client/back/methods/defaulter/specs/filter.spec.js index 0a970823e..e7f58c575 100644 --- a/modules/client/back/methods/defaulter/specs/filter.spec.js +++ b/modules/client/back/methods/defaulter/specs/filter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('defaulter filter()', () => { +fdescribe('defaulter filter()', () => { const authUserId = 9; it('should all return the tickets matching the filter', async() => { const tx = await models.Defaulter.beginTransaction({}); @@ -11,10 +11,10 @@ describe('defaulter filter()', () => { const ctx = {req: {accessToken: {userId: authUserId}}, args: {filter: filter}}; const result = await models.Defaulter.filter(ctx, null, options); - const firstRow = result[0]; + const firstRow = result.defaulters[0]; expect(firstRow.clientFk).toEqual(1101); - expect(result.length).toEqual(5); + expect(result.defaulters.length).toEqual(5); await tx.rollback(); } catch (e) { @@ -31,7 +31,7 @@ describe('defaulter filter()', () => { const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 1101}}; const result = await models.Defaulter.filter(ctx, null, options); - const firstRow = result[0]; + const firstRow = result.defaulters[0]; expect(firstRow.clientFk).toEqual(1101); @@ -50,7 +50,7 @@ describe('defaulter filter()', () => { const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 'Petter Parker'}}; const result = await models.Defaulter.filter(ctx, null, options); - const firstRow = result[0]; + const firstRow = result.defaulters[0]; expect(firstRow.clientName).toEqual('Petter Parker'); @@ -60,4 +60,23 @@ describe('defaulter filter()', () => { throw e; } }); + + it('should return the defaulter the sum of every defaulters', async() => { + const tx = await models.Defaulter.beginTransaction({}); + + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: authUserId}}, args: {search: 1101}}; + const {defaulters, amount} = await models.Defaulter.filter(ctx, null, options); + + const total = defaulters.reduce((total, row) => total + row.amount, 0); + + expect(total).toEqual(amount); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 9cd8dfaf9de3db785d72496a114c806ecbd68a32 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 17 Jan 2025 13:03:28 +0100 Subject: [PATCH 36/60] feat: refs #8077 fix spec --- modules/client/back/methods/defaulter/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/methods/defaulter/specs/filter.spec.js b/modules/client/back/methods/defaulter/specs/filter.spec.js index e7f58c575..ca7a6b4ff 100644 --- a/modules/client/back/methods/defaulter/specs/filter.spec.js +++ b/modules/client/back/methods/defaulter/specs/filter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('defaulter filter()', () => { +describe('defaulter filter()', () => { const authUserId = 9; it('should all return the tickets matching the filter', async() => { const tx = await models.Defaulter.beginTransaction({}); From 4f68a7d2625287668db4f493343d6426ac725a5d Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 17 Jan 2025 15:36:11 +0100 Subject: [PATCH 37/60] feat: refs #8381 add agencyModeFk to travel thermograph and create AgencyModeIncoming model --- db/routines/vn/views/agencyModeIncoming.sql | 9 +++++++ .../00-agencyIncomingForeign.sql | 6 +++++ .../01-travelThermographAlter.sql | 7 +++++ .../back/methods/travel/saveThermograph.js | 6 +++++ modules/travel/back/model-config.json | 5 +++- .../back/models/agency-mode-incoming.json | 27 +++++++++++++++++++ .../back/models/travel-thermograph.json | 5 ++++ 7 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/views/agencyModeIncoming.sql create mode 100644 db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql create mode 100644 db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql create mode 100644 modules/travel/back/models/agency-mode-incoming.json diff --git a/db/routines/vn/views/agencyModeIncoming.sql b/db/routines/vn/views/agencyModeIncoming.sql new file mode 100644 index 000000000..f7f6e595d --- /dev/null +++ b/db/routines/vn/views/agencyModeIncoming.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`vn`@`localhost` +SQL SECURITY DEFINER +VIEW `vn`.`agencyModeIncoming` AS + SELECT + am.id, + am.name + FROM `vn`.`agencyMode` AS am + JOIN `vn`.`agencyIncoming` AS ai + ON am.id = ai.agencyModeFk; diff --git a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql new file mode 100644 index 000000000..bf2c75f2b --- /dev/null +++ b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`agencyIncoming` + ADD CONSTRAINT `fk_agencyIncoming_agencyMode` + FOREIGN KEY (`agencyModeFk`) + REFERENCES `agencyMode`(`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; diff --git a/db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql b/db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql new file mode 100644 index 000000000..3838f59d7 --- /dev/null +++ b/db/versions/11411-turquoiseEucalyptus/01-travelThermographAlter.sql @@ -0,0 +1,7 @@ +ALTER TABLE `vn`.`travelThermograph` + ADD COLUMN `agencyModeFk` INT(11) NULL AFTER `editorFk`, + ADD CONSTRAINT `travelThermograph_agencyIncoming_fk` + FOREIGN KEY (`agencyModeFk`) + REFERENCES `agencyIncoming`(`agencyModeFk`) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/modules/travel/back/methods/travel/saveThermograph.js b/modules/travel/back/methods/travel/saveThermograph.js index 6f7e1c8bf..2517b0b8c 100644 --- a/modules/travel/back/methods/travel/saveThermograph.js +++ b/modules/travel/back/methods/travel/saveThermograph.js @@ -57,6 +57,10 @@ module.exports = Self => { arg: 'hasFileAttached', type: 'Boolean', description: 'True if has an attached file' + }, { + arg: 'agencyModeFk', + type: 'Number', + description: 'Carrier' }], returns: {type: 'object', root: true}, http: {path: `/:id/saveThermograph`, verb: 'POST'} @@ -76,6 +80,7 @@ module.exports = Self => { reference, description, hasFileAttached, + agencyModeFk, options ) => { const models = Self.app.models; @@ -119,6 +124,7 @@ module.exports = Self => { minTemperature, temperatureFk, warehouseFk: warehouseId, + agencyModeFk, }, myOptions); if (tx) await tx.commit(); diff --git a/modules/travel/back/model-config.json b/modules/travel/back/model-config.json index 952ce0d20..e7a644180 100644 --- a/modules/travel/back/model-config.json +++ b/modules/travel/back/model-config.json @@ -22,5 +22,8 @@ }, "Temperature": { "dataSource": "vn" + }, + "AgencyModeIncoming": { + "dataSource": "vn" } -} \ No newline at end of file +} diff --git a/modules/travel/back/models/agency-mode-incoming.json b/modules/travel/back/models/agency-mode-incoming.json new file mode 100644 index 000000000..efefaf872 --- /dev/null +++ b/modules/travel/back/models/agency-mode-incoming.json @@ -0,0 +1,27 @@ +{ + "name": "AgencyModeIncoming", + "base": "VnModel", + "options": { + "mysql": { + "table": "agencyModeIncoming" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json index cb0a9b4f8..79b692507 100644 --- a/modules/travel/back/models/travel-thermograph.json +++ b/modules/travel/back/models/travel-thermograph.json @@ -58,6 +58,11 @@ "type": "belongsTo", "model": "Thermograph", "foreignKey": "thermographFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" } } } From a46ec1bc8d34150a19ff02568ad78db6b6c73773 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 21 Jan 2025 08:13:56 +0100 Subject: [PATCH 39/60] feat: refs #8381 add agencyModeFk to thermograph and insert agencyIncoming records --- db/dump/fixtures.before.sql | 5 +++++ .../back/methods/travel/specs/saveThermograph.spec.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 590fe34b6..30c49aafc 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -321,6 +321,11 @@ UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com' UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; +INSERT INTO `vn`.`agencyIncoming`(`agencyModeFk`) + VALUES + (1), + (2); + INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`, `hasVerified`) VALUES (1, NULL, 'PayMethod one', 0, 001, 0, 0, 0), diff --git a/modules/travel/back/methods/travel/specs/saveThermograph.spec.js b/modules/travel/back/methods/travel/specs/saveThermograph.spec.js index c2da4234e..0f5f248bf 100644 --- a/modules/travel/back/methods/travel/specs/saveThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/saveThermograph.spec.js @@ -9,6 +9,7 @@ describe('Thermograph saveThermograph()', () => { const maxTemperature = 30; const minTemperature = 10; const temperatureFk = 'COOL'; + const agencyModeFk = 1; let tx; let options; @@ -46,13 +47,16 @@ describe('Thermograph saveThermograph()', () => { null, null, null, - null, options + null, + agencyModeFk, + options ); expect(updatedThermograph.result).toEqual(state); expect(updatedThermograph.maxTemperature).toEqual(maxTemperature); expect(updatedThermograph.minTemperature).toEqual(minTemperature); expect(updatedThermograph.temperatureFk).toEqual(temperatureFk); + expect(updatedThermograph.agencyModeFk).toEqual(agencyModeFk); expect(updatedThermograph.dmsFk).toEqual(dmsFk); }); From c72758685584378a28e2fdd9de127fc8968cbeb6 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 11:25:03 +0100 Subject: [PATCH 40/60] feat: refs #8387 add column validationRegex --- db/versions/11419-orangeSalal/00-firstScript.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 db/versions/11419-orangeSalal/00-firstScript.sql diff --git a/db/versions/11419-orangeSalal/00-firstScript.sql b/db/versions/11419-orangeSalal/00-firstScript.sql new file mode 100644 index 000000000..432ed70aa --- /dev/null +++ b/db/versions/11419-orangeSalal/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`tag` +ADD COLUMN IF NOT EXISTS `validationRegex` varchar(50) DEFAULT NULL; From 3d5bfb81da18c83910213eedf63af1a3bbdbeb4a Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:12:03 +0100 Subject: [PATCH 41/60] feat: refs #8387 regular expression all tags --- loopback/locale/es.json | 4 ++-- modules/item/back/models/item-tag.js | 10 ++++++---- modules/item/back/models/tag.json | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9a24f84ba..6199bb106 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -399,5 +399,5 @@ "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "The value must be a number or a range of numbers": "El valor debe ser un número o un rango de números" +} diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 4c1ef4d4a..5a81f427f 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -12,7 +12,6 @@ module.exports = Self => { }); Self.observe('before save', async ctx => { - const validValue = new RegExp('^\\d{1,3}(-\\d{1,3})?$'); let tagFk; let value; @@ -24,10 +23,13 @@ module.exports = Self => { value = ctx.data.value; } const models = Self.app.models; - const validTag = await models.Tag.findOne({where: {name: 'Longitud(m)'}}); + const validTag = await models.Tag.findOne({where: {id: tagFk}}); - if (tagFk === validTag.id) { - if ((value && !validValue.test(value))) + if (validTag.validationRegex) { + const regexString = validTag.validationRegex.replace(/\\\\/g, '\\'); + const validExpresion = new RegExp(regexString); + + if (value && !validExpresion.test(value)) throw new UserError('The value must be a number or a range of numbers'); } }); diff --git a/modules/item/back/models/tag.json b/modules/item/back/models/tag.json index 6c5f5c0ba..5269b849f 100644 --- a/modules/item/back/models/tag.json +++ b/modules/item/back/models/tag.json @@ -30,6 +30,9 @@ "mysql": { "columnName": "isQuantitatif" } + }, + "validationRegex": { + "type": "string" } }, "acls": [ From b4ac80615b7422b9f829ab92d913886f5f984b81 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:13:30 +0100 Subject: [PATCH 42/60] feat: refs #8387 fix traductions --- loopback/locale/en.json | 5 ++--- loopback/locale/es.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 4fe11c2b6..818772e40 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -251,6 +251,5 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" -} \ No newline at end of file + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 6199bb106..b8a43285d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -399,5 +399,5 @@ "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "El valor debe ser un número o un rango de números" + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" } From a40e9a547b7d96fc047ad0dd6321ec1438768082 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:40:24 +0100 Subject: [PATCH 43/60] feat: refs #8387 --- loopback/locale/es.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b8a43285d..5558c0964 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,6 +398,5 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" + "There are tickets to be invoiced": "La zona tiene tickets por facturar" } From 5ff27de72c20ee2e7b9800c75c9117599ca59f9e Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 13:42:12 +0100 Subject: [PATCH 44/60] feat: refs #8387 --- loopback/locale/es.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5558c0964..fc2b89caa 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -397,6 +397,5 @@ "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", - "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" + "Price cannot be blank": "Price cannot be blank" } From 3c89ea0df8e225bdbf4a9ec065114d4c66ec73b7 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 21 Jan 2025 14:12:14 +0100 Subject: [PATCH 45/60] fix: refs #8387 local/es.json --- loopback/locale/es.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fc2b89caa..23a40a9fb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -397,5 +397,8 @@ "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", - "Price cannot be blank": "Price cannot be blank" + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", + "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", + "Price cannot be blank": "El precio no puede estar en blanco" } From e92e1d3a46162a24a6464c9a3a429b36c9070176 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 22 Jan 2025 13:20:24 +0100 Subject: [PATCH 46/60] feat: refs #6822 refs #688 change request --- db/routines/vn/procedures/entry_transfer.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 123470038..bb1ef97be 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -31,8 +31,7 @@ BEGIN CALL util.tx_start(vIsRequiredTx); - - -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. + -- Nuevo travel, salida hoy y llegada mañana, asignar la entrada nueva al nuevo travel. SELECT t.warehouseInFk, t.warehouseOutFk, t.`ref`, t.isReceived, t.agencyModeFk INTO vWarehouseInFk, vWarehouseOutFk, vRef, vIsReceived, vAgencyModeFk FROM travel t From 0f531d4b745671287067c9f32d006486b64fa3f1 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 22 Jan 2025 13:24:06 +0100 Subject: [PATCH 47/60] feat: refs #6822 change request --- db/routines/vn/procedures/entry_transfer.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index bb1ef97be..7e38e5095 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -31,7 +31,8 @@ BEGIN CALL util.tx_start(vIsRequiredTx); - -- Nuevo travel, salida hoy y llegada mañana, asignar la entrada nueva al nuevo travel. + /* Hay que crear un nuevo travel, con salida hoy y llegada mañana y + asignar la entrada nueva al nuevo travel.*/ SELECT t.warehouseInFk, t.warehouseOutFk, t.`ref`, t.isReceived, t.agencyModeFk INTO vWarehouseInFk, vWarehouseOutFk, vRef, vIsReceived, vAgencyModeFk FROM travel t @@ -96,7 +97,8 @@ BEGIN JOIN entry e ON e.travelFk = t.id WHERE e.id = vOriginalEntry; - -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones + /* Actualizar nueva entrada con lo que no está ubicado HOY, + descontando lo vendido HOY de esas ubicaciones*/ CREATE OR REPLACE TEMPORARY TABLE buys WITH tBuy AS ( SELECT b.itemFk, SUM(b.quantity) totalQuantity From d8847d3d09822ea377cc315156031ebf05a62de3 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 23 Jan 2025 12:59:32 +0100 Subject: [PATCH 48/60] feat: refs #6822 change request --- db/routines/vn/procedures/entry_transfer.sql | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 7e38e5095..5b83ae532 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -18,6 +18,7 @@ BEGIN DECLARE vIsReceived INT; DECLARE vAgencyModeFk INT; DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); + DECLARE vCurDate DATE DEFAULT util.VN_CURDATE(); DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION @@ -41,7 +42,7 @@ BEGIN SELECT id INTO vTravelFk FROM travel t - WHERE shipped = util.VN_CURDATE() + WHERE shipped = vCurDate AND landed = vTomorrow AND warehouseInFk = vWarehouseInFk AND warehouseOutFk = vWarehouseOutFk @@ -58,7 +59,7 @@ BEGIN `ref`, isReceived, agencyModeFk) - SELECT util.VN_CURDATE(), + SELECT vCurDate, vTomorrow, t.warehouseInFk, t.warehouseOutFk, @@ -116,7 +117,7 @@ BEGIN JOIN vn.entry e ON e.id = b.entryFk JOIN tBuy t ON t.itemFk = ish.itemFk WHERE s.warehouseFk = vWarehouseFk - AND sh.parked >= util.VN_CURDATE() + AND sh.parked >= vCurDate GROUP BY ish.itemFk ), sales AS ( @@ -127,8 +128,8 @@ BEGIN JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk JOIN vn.shelving s2 ON s2.id = is2.shelvingFk JOIN tBuy t ON t.itemFk = s.itemFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked >= util.VN_CURDATE() + WHERE t.shipped BETWEEN vCurDate AND util.dayend(vCurDate) + AND s2.parked >= vCurDate GROUP BY s.itemFk ) SELECT tmp.itemFk, @@ -152,6 +153,6 @@ BEGIN CALL util.tx_commit(vIsRequiredTx); CALL cache.visible_refresh(@c,TRUE,vWarehouseFk); - CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE()); + CALL cache.available_refresh(@c, TRUE, vWarehouseFk, vCurDate); END$$ DELIMITER ; From 518a91cff206d87adf054d6035d6704ce6c1cf3a Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 23 Jan 2025 13:56:36 +0100 Subject: [PATCH 49/60] fix: address isEqualizated can be null for trigger --- db/versions/11423-maroonMonstera/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11423-maroonMonstera/00-firstScript.sql diff --git a/db/versions/11423-maroonMonstera/00-firstScript.sql b/db/versions/11423-maroonMonstera/00-firstScript.sql new file mode 100644 index 000000000..cf21473d8 --- /dev/null +++ b/db/versions/11423-maroonMonstera/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.address MODIFY COLUMN isEqualizated tinyint(1) NULL; From f165d178695a0218e11fa11e3f035ca98dbdf2af Mon Sep 17 00:00:00 2001 From: jtubau Date: Thu, 23 Jan 2025 14:26:02 +0100 Subject: [PATCH 50/60] feat: refs #7322 add addressFk parameter to transferClient method and update tests --- .../ticket/specs/transferClient.spec.js | 43 +++++++++++++++++-- .../back/methods/ticket/transferClient.js | 6 ++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index d3ac3c6aa..327a099d8 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -22,14 +22,16 @@ describe('Ticket transferClient()', () => { it('should throw an error as the ticket is not editable', async() => { try { const ticketId = 4; - await models.Ticket.transferClient(ctx, ticketId, clientId, options); + const addressFk = null; + await models.Ticket.transferClient(ctx, ticketId, clientId, addressFk, options); } catch (e) { expect(e.message).toEqual('This ticket is locked'); } }); it('should be assigned a different clientFk and nickname in the original ticket', async() => { - await models.Ticket.transferClient(ctx, 2, clientId, options); + const addressFk = null; + await models.Ticket.transferClient(ctx, 2, clientId, addressFk, options); const afterTransfer = await models.Ticket.findById(2, null, options); const client = await models.Client.findById(clientId, {fields: ['defaultAddressFk']}, options); const address = await models.Address.findById(client.defaultAddressFk, {fields: ['nickname']}, options); @@ -39,7 +41,8 @@ describe('Ticket transferClient()', () => { }); it('should be assigned a different clientFk and nickname in the original and refund ticket and claim', async() => { - await models.Ticket.transferClient(ctx, originalTicketId, clientId, options); + const addressFk = null; + await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options); const [originalTicket, refundTicket] = await models.Ticket.find({ where: {id: {inq: [originalTicketId, refundTicketId]}} @@ -59,4 +62,38 @@ describe('Ticket transferClient()', () => { expect(originalTicket.nickname).toEqual(address.nickname); expect(refundTicket.nickname).toEqual(address.nickname); }); + + it('should be assigned a different addressFk and nickname in the original and refund ticket', async() => { + const addressFk = 131; + await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options); + + const [originalTicket, refundTicket] = await models.Ticket.find({ + where: {id: {inq: [originalTicketId, refundTicketId]}} + }, options); + + const claim = await models.Claim.findOne({ + where: {ticketFk: originalTicketId} + }, options); + + const address = await models.Address.findById(addressFk, {fields: ['id', 'nickname', 'clientFk']}, options); + + expect(originalTicket.clientFk).toEqual(clientId); + expect(originalTicket.clientFk).toEqual(address.clientFk); + expect(refundTicket.clientFk).toEqual(clientId); + expect(refundTicket.clientFk).toEqual(address.clientFk); + expect(claim.clientFk).toEqual(clientId); + expect(claim.clientFk).toEqual(address.clientFk); + + expect(originalTicket.nickname).toEqual(address.nickname); + expect(refundTicket.nickname).toEqual(address.nickname); + }); + + it('should be thrown an error if the new address is not belong to the client', async() => { + const addressFk = 1; + try { + await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options); + } catch (e) { + expect(e.message).toEqual('The address does not belong to the client'); + } + }); }); diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 9bf2a861e..76a66c528 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -23,7 +23,7 @@ module.exports = Self => { } }); - Self.transferClient = async(ctx, id, clientFk, options, addressFk) => { + Self.transferClient = async(ctx, id, clientFk, addressFk, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -48,7 +48,9 @@ module.exports = Self => { {fields: ['id', 'defaultAddressFk']}, myOptions); const address = await models.Address.findById(addressFk ? addressFk : client.defaultAddressFk, - {fields: ['id', 'nickname']}, myOptions); + {fields: ['id', 'nickname', 'clientFk']}, myOptions); + + if (address.clientFk !== clientFk) throw new UserError('The address does not belong to the client'); const attributes = {clientFk, addressFk: address.id, nickname: address.nickname}; From df97534882ddbd86ef55c6f8360f77fdbeb9a5f3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 24 Jan 2025 08:25:44 +0100 Subject: [PATCH 51/60] fix: refs #6861 refs#6861 showUsername --- back/methods/collection/getTickets.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 85d1111df..f7ec4867b 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -65,7 +65,8 @@ module.exports = Self => { iss.id itemShelvingSaleFk, iss.isPicked, iss.itemShelvingFk, - st.code stateCode + st.code stateCode, + ac.username FROM ticketCollection tc LEFT JOIN collection c ON c.id = tc.collectionFk JOIN sale s ON s.ticketFk = tc.ticketFk @@ -79,7 +80,8 @@ module.exports = Self => { LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN state st ON st.id = sg.stateFk + LEFT JOIN state st ON st.id = sg.stateFk, + LEFT JOIN account.user ac ON ac.id = iss.userFk WHERE tc.collectionFk = ? GROUP BY s.id, ish.id, p.code, p2.code UNION ALL @@ -109,7 +111,8 @@ module.exports = Self => { iss.id itemShelvingSaleFk, iss.isPicked, iss.itemShelvingFk, - st.code stateCode + st.code stateCode, + ac.username FROM sectorCollection sc JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id JOIN saleGroup sg ON sg.id = ss.saleGroupFk @@ -124,6 +127,7 @@ module.exports = Self => { LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN origin o ON o.id = i.originFk LEFT JOIN state st ON st.id = sg.stateFk + LEFT JOIN account.user ac ON ac.id = sg.userFk WHERE sc.id = ? AND sgd.saleGroupFk GROUP BY s.id, ish.id, p.code, p2.code`, [id, id], myOptions); From 5dd60bd912e147e3fc6ce46701e3f4f221c11584 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 24 Jan 2025 08:28:15 +0100 Subject: [PATCH 52/60] fix: refs #6861 refs#6861 showUsername --- back/methods/collection/getTickets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index f7ec4867b..dfe86c94c 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -80,7 +80,7 @@ module.exports = Self => { LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN state st ON st.id = sg.stateFk, + LEFT JOIN state st ON st.id = sg.stateFk LEFT JOIN account.user ac ON ac.id = iss.userFk WHERE tc.collectionFk = ? GROUP BY s.id, ish.id, p.code, p2.code From 2ee5ba908a518e957312bd5b3c0044f25ef8d38c Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 24 Jan 2025 13:16:36 +0100 Subject: [PATCH 53/60] feat: refs #6822 change request --- modules/entry/back/methods/entry/transfer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index aa4b4c819..db6873663 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -33,7 +33,7 @@ module.exports = Self => { try { await Self.rawSql('CALL vn.entry_transfer(?, @vNewEntry)', [id], myOptions); - const newEntryFk = await Self.rawSql('SELECT @vNewEntry newEntryFk', null, myOptions); + const [newEntryFk] = await Self.rawSql('SELECT @vNewEntry newEntryFk', null, myOptions); if (tx) await tx.commit(); return newEntryFk; From 163302c770ca66b7d4838406f93f976c116bec6a Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 24 Jan 2025 13:26:36 +0100 Subject: [PATCH 54/60] feat: refs #6822 fix test --- modules/entry/back/methods/entry/specs/transfer.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index cc712b994..bf0b2b974 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -15,7 +15,7 @@ describe('Transfer merchandise from one entry to the next day()', () => { const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options); await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options); - const [{newEntryFk}] = await models.Entry.transfer(ctx, originalEntry, options); + const {newEntryFk} = await models.Entry.transfer(ctx, originalEntry, options); const originalEntrybuys = await models.Buy.find({where: {entryFk: originalEntry}}, options); const newEntrybuys = await models.Buy.find({where: {entryFk: newEntryFk}}, options); From 29af7cfcbcf8af057cd0c5a1ed9c6263d34fc56c Mon Sep 17 00:00:00 2001 From: jtubau Date: Mon, 27 Jan 2025 08:23:30 +0100 Subject: [PATCH 55/60] test: refs #7322 added test error for case when expected error is not thrown --- modules/ticket/back/methods/ticket/specs/transferClient.spec.js | 1 + modules/ticket/back/methods/ticket/transferClient.js | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 327a099d8..063433680 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -92,6 +92,7 @@ describe('Ticket transferClient()', () => { const addressFk = 1; try { await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options); + fail('Expected an error to be thrown, but none was thrown.'); } catch (e) { expect(e.message).toEqual('The address does not belong to the client'); } diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 76a66c528..2e845144e 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -1,3 +1,4 @@ +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('transferClient', { description: 'Transferring ticket to another client', From 1f6779d86b2837e22f1165b4935eb92ac4b23720 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 27 Jan 2025 08:59:33 +0100 Subject: [PATCH 56/60] feat: refs #8387 change request --- modules/item/back/models/item-tag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 5a81f427f..2cd2e5f9b 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -23,7 +23,7 @@ module.exports = Self => { value = ctx.data.value; } const models = Self.app.models; - const validTag = await models.Tag.findOne({where: {id: tagFk}}); + const validTag = await models.Tag.findById(tagFk); if (validTag.validationRegex) { const regexString = validTag.validationRegex.replace(/\\\\/g, '\\'); From cd8e04d6485a8f3a33f4ed630ac932ff70284376 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 27 Jan 2025 11:22:21 +0100 Subject: [PATCH 57/60] refactor: refs #7568 ticket_doCmr ignore alertLevel --- db/routines/vn/procedures/ticket_doCmr.sql | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/ticket_doCmr.sql b/db/routines/vn/procedures/ticket_doCmr.sql index ba64944f8..59bb3e070 100644 --- a/db/routines/vn/procedures/ticket_doCmr.sql +++ b/db/routines/vn/procedures/ticket_doCmr.sql @@ -21,9 +21,6 @@ BEGIN IFNULL(sat.supplierFk, su.id) supplierFk, t.landed FROM ticket t - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN `state` s ON s.id = ts.stateFk - JOIN alertLevel al ON al.id = s.alertLevel JOIN client c ON c.id = t.clientFk JOIN `address` a ON a.id = t.addressFk JOIN province p ON p.id = a.provinceFk @@ -40,8 +37,7 @@ BEGIN LEFT JOIN agency ag ON ag.id = am.agencyFk LEFT JOIN supplierAgencyTerm sat ON sat.agencyFk = ag.id AND wo.isFreelance - WHERE al.code IN ('PACKED', 'DELIVERED') - AND co.code <> 'ES' + WHERE co.code <> 'ES' AND am.name <> 'ABONO' AND w.code = 'ALG' AND t.id = vSelf From bbebff7ea93dc0a34f9b9b807cad883d585f56b2 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 27 Jan 2025 14:37:39 +0100 Subject: [PATCH 58/60] fix: prevent slow update --- db/versions/11269-wheatBirch/00-firstScript.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/versions/11269-wheatBirch/00-firstScript.sql b/db/versions/11269-wheatBirch/00-firstScript.sql index 9432d131b..9552fe6cd 100644 --- a/db/versions/11269-wheatBirch/00-firstScript.sql +++ b/db/versions/11269-wheatBirch/00-firstScript.sql @@ -7,9 +7,9 @@ ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_customsAgentFk FOREIGN KEY ( ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_incotermsFk FOREIGN KEY (incotermsFk) REFERENCES vn.incoterms (`code`) ON DELETE RESTRICT ON UPDATE CASCADE; -UPDATE vn.invoiceOut io - JOIN vn.client c ON c.id = io.clientFk - JOIN vn.ticket t ON t.clientFk = c.id - JOIN vn.address a ON a.id = t.addressFk - SET io.customsAgentFk = a.customsAgentFk, - io.incotermsFk = a.incotermsFk; \ No newline at end of file +-- UPDATE vn.invoiceOut io +-- JOIN vn.client c ON c.id = io.clientFk +-- JOIN vn.ticket t ON t.clientFk = c.id +-- JOIN vn.address a ON a.id = t.addressFk +-- SET io.customsAgentFk = a.customsAgentFk, +-- io.incotermsFk = a.incotermsFk; From 8cbe64eedd9dc87659061476ea18a15a85817785 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 27 Jan 2025 16:34:28 +0100 Subject: [PATCH 59/60] fix: remove orphaned agencyIncoming records with null agencyModeFk --- .../11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql index bf2c75f2b..e470282b7 100644 --- a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql +++ b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql @@ -1,3 +1,9 @@ +DELETE ai from + `vn`.`agencyIncoming` ai +LEFT JOIN `vn`.`agencyMode` am ON + am.id = ai.agencyModeFk +WHERE am.id IS null + ALTER TABLE `vn`.`agencyIncoming` ADD CONSTRAINT `fk_agencyIncoming_agencyMode` FOREIGN KEY (`agencyModeFk`) From b8f9dc7ad7b2e3bf81fa617e9347f03fb46ad51f Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 27 Jan 2025 16:37:17 +0100 Subject: [PATCH 60/60] fix: correct SQL syntax for deleting orphaned agencyIncoming records --- .../00-agencyIncomingForeign.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql index e470282b7..829236a2a 100644 --- a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql +++ b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql @@ -1,8 +1,8 @@ DELETE ai from - `vn`.`agencyIncoming` ai -LEFT JOIN `vn`.`agencyMode` am ON - am.id = ai.agencyModeFk -WHERE am.id IS null + `vn`.`agencyIncoming` ai + LEFT JOIN `vn`.`agencyMode` am ON + am.id = ai.agencyModeFk + WHERE am.id IS null; ALTER TABLE `vn`.`agencyIncoming` ADD CONSTRAINT `fk_agencyIncoming_agencyMode`