From 8c18bcd776ee10e5cc70c04436f5317abdb40fdf Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 25 Sep 2024 07:36:48 +0200 Subject: [PATCH 01/11] feat(components): refs #8030 new component bonus With table vn.priceDelta, buyers set a range of items to be affected for a price increasing Refs: #8030 --- .../00-firstScript.sql | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 db/versions/11262-chocolateCamellia/00-firstScript.sql diff --git a/db/versions/11262-chocolateCamellia/00-firstScript.sql b/db/versions/11262-chocolateCamellia/00-firstScript.sql new file mode 100644 index 000000000..79910fa76 --- /dev/null +++ b/db/versions/11262-chocolateCamellia/00-firstScript.sql @@ -0,0 +1,31 @@ +-- vn.priceDelta definition + +CREATE OR REPLACE TABLE vn.priceDelta ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `itemTypeFk` smallint(5) unsigned NOT NULL, + `minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size', + `maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size', + `inkFk` varchar(3) DEFAULT NULL, + `originFk` tinyint(2) unsigned DEFAULT NULL, + `producerFk` mediumint(3) unsigned DEFAULT NULL, + `fromDated` date DEFAULT NULL, + `toDated` date DEFAULT NULL, + `absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price', + `ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price', + `warehouseFk` smallint(6) unsigned NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `editorFk` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `priceDelta_itemType_FK` (`itemTypeFk`), + KEY `priceDelta_ink_FK` (`inkFk`), + KEY `priceDelta_producer_FK` (`producerFk`), + KEY `priceDelta_warehouse_FK` (`warehouseFk`), + KEY `priceDelta_worker_FK` (`editorFk`), + CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items'; + +GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer; \ No newline at end of file From 2b6c604fcdeccf8f86be2505b2d5b84e1f920f1b Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 25 Sep 2024 07:37:52 +0200 Subject: [PATCH 02/11] feat(components): refs #8030 new component bonus With table vn.priceDelta, buyers set a range of items to be affected for a price increasing Refs: #8030 --- .../procedures/catalog_componentCalculate.sql | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql index 7ac383e8f..d4ce88ca7 100644 --- a/db/routines/vn/procedures/catalog_componentCalculate.sql +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -7,7 +7,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_componentCalc ) BEGIN /** - * Calcula los componentes de los articulos de tmp.ticketLot + * Calcula los componentes de los articulos de la tabla tmp.ticketLot * * @param vZoneFk para calcular el transporte * @param vAddressFk Consignatario @@ -25,18 +25,38 @@ BEGIN FROM address WHERE id = vAddressFk; - CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice + CREATE OR REPLACE TEMPORARY TABLE tPriceDelta (INDEX (itemFk)) - ENGINE = MEMORY - SELECT * FROM ( + ENGINE = MEMORY + SELECT i.id itemFk, + SUM(IFNULL(pd.absIncreasing,0)) absIncreasing, + SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing, + pd.warehouseFk + FROM item i + JOIN priceDelta pd + ON pd.itemTypeFk = i.typeFk + AND (pd.minSize IS NULL OR pd.minSize <= i.`size`) + AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`) + AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk) + AND (pd.originFk IS NULL OR pd.originFk = i.originFk) + AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk) + AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk) + WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped) + AND (pd.toDated IS NULL OR pd.toDated >= vShipped) + GROUP BY i.id; + + CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT * FROM ( SELECT * - FROM specialPrice - WHERE (clientFk = vClientFk OR clientFk IS NULL) - AND started <= vShipped - AND (ended >= vShipped OR ended IS NULL) - ORDER BY (clientFk = vClientFk) DESC, id DESC - LIMIT 10000000000000000000) t - GROUP BY itemFk; + FROM specialPrice + WHERE (clientFk = vClientFk OR clientFk IS NULL) + AND started <= vShipped + AND (ended >= vShipped OR ended IS NULL) + ORDER BY (clientFk = vClientFk) DESC, id DESC + LIMIT 10000000000000000000) t + GROUP BY itemFk; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate (PRIMARY KEY (itemFk, warehouseFk)) @@ -108,6 +128,19 @@ BEGIN JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk GROUP BY tc.itemFk, warehouseFk; + -- Bonus del comprador a un rango de productos + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT + tcb.warehouseFk, + tcb.itemFk, + c.id, + IFNULL(tcb.base * tpd.ratIncreasing / 100,0) + IFNULL(tpd.absIncreasing,0) + FROM tmp.ticketComponentBase tcb + JOIN component c ON c.code = 'bonus' + JOIN tPriceDelta tpd + ON tpd.itemFk = tcb.itemFk + AND tpd.warehouseFk = tcb.warehouseFk; + -- RECOBRO INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, c2.id, @@ -303,6 +336,7 @@ BEGIN tmp.ticketComponentBase, tmp.ticketComponentRate, tmp.ticketComponentCopy, - tSpecialPrice; + tPriceDelta, + tSpecialPrice; END$$ DELIMITER ; From beb66cce1f6be159a0f265c364d9df31f60d045b Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 25 Sep 2024 07:43:29 +0200 Subject: [PATCH 03/11] feat(components): refs #8030 new component bonus With table vn.priceDelta, buyers set a range of items to be affected for a price increasing Refs: #8030 --- .../procedures/catalog_componentCalculate.sql | 58 +++++++++++++++---- .../11263-brownAnthurium/00-firstScript.sql | 32 ++++++++++ 2 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 db/versions/11263-brownAnthurium/00-firstScript.sql diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql index 7ac383e8f..d4ce88ca7 100644 --- a/db/routines/vn/procedures/catalog_componentCalculate.sql +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -7,7 +7,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_componentCalc ) BEGIN /** - * Calcula los componentes de los articulos de tmp.ticketLot + * Calcula los componentes de los articulos de la tabla tmp.ticketLot * * @param vZoneFk para calcular el transporte * @param vAddressFk Consignatario @@ -25,18 +25,38 @@ BEGIN FROM address WHERE id = vAddressFk; - CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice + CREATE OR REPLACE TEMPORARY TABLE tPriceDelta (INDEX (itemFk)) - ENGINE = MEMORY - SELECT * FROM ( + ENGINE = MEMORY + SELECT i.id itemFk, + SUM(IFNULL(pd.absIncreasing,0)) absIncreasing, + SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing, + pd.warehouseFk + FROM item i + JOIN priceDelta pd + ON pd.itemTypeFk = i.typeFk + AND (pd.minSize IS NULL OR pd.minSize <= i.`size`) + AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`) + AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk) + AND (pd.originFk IS NULL OR pd.originFk = i.originFk) + AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk) + AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk) + WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped) + AND (pd.toDated IS NULL OR pd.toDated >= vShipped) + GROUP BY i.id; + + CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT * FROM ( SELECT * - FROM specialPrice - WHERE (clientFk = vClientFk OR clientFk IS NULL) - AND started <= vShipped - AND (ended >= vShipped OR ended IS NULL) - ORDER BY (clientFk = vClientFk) DESC, id DESC - LIMIT 10000000000000000000) t - GROUP BY itemFk; + FROM specialPrice + WHERE (clientFk = vClientFk OR clientFk IS NULL) + AND started <= vShipped + AND (ended >= vShipped OR ended IS NULL) + ORDER BY (clientFk = vClientFk) DESC, id DESC + LIMIT 10000000000000000000) t + GROUP BY itemFk; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate (PRIMARY KEY (itemFk, warehouseFk)) @@ -108,6 +128,19 @@ BEGIN JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk GROUP BY tc.itemFk, warehouseFk; + -- Bonus del comprador a un rango de productos + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT + tcb.warehouseFk, + tcb.itemFk, + c.id, + IFNULL(tcb.base * tpd.ratIncreasing / 100,0) + IFNULL(tpd.absIncreasing,0) + FROM tmp.ticketComponentBase tcb + JOIN component c ON c.code = 'bonus' + JOIN tPriceDelta tpd + ON tpd.itemFk = tcb.itemFk + AND tpd.warehouseFk = tcb.warehouseFk; + -- RECOBRO INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, c2.id, @@ -303,6 +336,7 @@ BEGIN tmp.ticketComponentBase, tmp.ticketComponentRate, tmp.ticketComponentCopy, - tSpecialPrice; + tPriceDelta, + tSpecialPrice; END$$ DELIMITER ; diff --git a/db/versions/11263-brownAnthurium/00-firstScript.sql b/db/versions/11263-brownAnthurium/00-firstScript.sql new file mode 100644 index 000000000..0824ea5f7 --- /dev/null +++ b/db/versions/11263-brownAnthurium/00-firstScript.sql @@ -0,0 +1,32 @@ +-- Place your SQL code here +-- vn.priceDelta definition + +CREATE OR REPLACE TABLE vn.priceDelta ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `itemTypeFk` smallint(5) unsigned NOT NULL, + `minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size', + `maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size', + `inkFk` varchar(3) DEFAULT NULL, + `originFk` tinyint(2) unsigned DEFAULT NULL, + `producerFk` mediumint(3) unsigned DEFAULT NULL, + `fromDated` date DEFAULT NULL, + `toDated` date DEFAULT NULL, + `absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price', + `ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price', + `warehouseFk` smallint(6) unsigned NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `editorFk` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `priceDelta_itemType_FK` (`itemTypeFk`), + KEY `priceDelta_ink_FK` (`inkFk`), + KEY `priceDelta_producer_FK` (`producerFk`), + KEY `priceDelta_warehouse_FK` (`warehouseFk`), + KEY `priceDelta_worker_FK` (`editorFk`), + CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items'; + +GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer; \ No newline at end of file From 8f63118550998f48acd324a1d8103a29a56941db Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 25 Sep 2024 12:24:00 +0200 Subject: [PATCH 04/11] fix: refs #6861 updateAvailable --- modules/item/back/methods/item-shelving/updateFromSale.js | 6 +++++- modules/ticket/back/methods/sale-tracking/setPicked.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/item/back/methods/item-shelving/updateFromSale.js b/modules/item/back/methods/item-shelving/updateFromSale.js index 167509074..47ca2a010 100644 --- a/modules/item/back/methods/item-shelving/updateFromSale.js +++ b/modules/item/back/methods/item-shelving/updateFromSale.js @@ -38,9 +38,13 @@ module.exports = Self => { const itemShelving = itemShelvingSale.itemShelving(); const quantity = itemShelving.visible + itemShelvingSale.quantity; + const available = itemShelving.available + itemShelvingSale.quantity; await itemShelving.updateAttributes( - {visible: quantity}, + { + visible: quantity, + available: available + }, myOptions ); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/sale-tracking/setPicked.js b/modules/ticket/back/methods/sale-tracking/setPicked.js index ed3656cf4..b63a0474f 100644 --- a/modules/ticket/back/methods/sale-tracking/setPicked.js +++ b/modules/ticket/back/methods/sale-tracking/setPicked.js @@ -75,7 +75,11 @@ module.exports = Self => { const itemShelving = await models.ItemShelving.findById(itemShelvingFk, null, myOptions); - await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions); + await itemShelving.updateAttributes( + { + visible: itemShelving.visible - quantity, + available: itemShelving.available - quantity + }, myOptions); await Self.updateAll( {saleFk}, From 08cb1241bf4fb0c529dcde98ef434aec0e713b2e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 26 Sep 2024 11:53:33 +0200 Subject: [PATCH 05/11] fix: refs #5890 recovery ItemShelving_afterInsert --- .../vn/triggers/itemShelving_afterInsert.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 db/routines/vn/triggers/itemShelving_afterInsert.sql diff --git a/db/routines/vn/triggers/itemShelving_afterInsert.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql new file mode 100644 index 000000000..92243ca03 --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_afterInsert.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` + AFTER INSERT ON `itemShelving` + FOR EACH ROW +BEGIN + INSERT INTO itemShelvingLog + SET itemShelvingFk = NEW.id, + workerFk = account.myUser_getId(), + accion = 'CREA REGISTRO', + itemFk = NEW.itemFk, + shelvingFk = NEW.shelvingFk, + visible = NEW.visible, + `grouping` = NEW.`grouping`, + packing = NEW.packing, + available = NEW.available; + +END$$ +DELIMITER ; From 989589afd7e17c25d20f8851a8a812d7ab5aa554 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 26 Sep 2024 11:18:05 +0000 Subject: [PATCH 06/11] feat(salix): use params.q as table filter in lilium --- front/core/services/app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/front/core/services/app.js b/front/core/services/app.js index cec7bea7f..17381dba8 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -66,6 +66,9 @@ export default class App { ]} }; + if (this.logger.$params.q) + newRoute = newRoute.concat(`list?table=${this.logger.$params.q}`); + return this.logger.$http.get('Urls/findOne', {filter}) .then(res => { if (res && res.data) From c83f44a4553935a180692a3d5e9f2af98ae00410 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 26 Sep 2024 12:12:33 +0000 Subject: [PATCH 07/11] perf(salix): use params.q as table filter in lilium --- front/core/services/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/core/services/app.js b/front/core/services/app.js index 17381dba8..a26d6def5 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -67,7 +67,8 @@ export default class App { }; if (this.logger.$params.q) - newRoute = newRoute.concat(`list?table=${this.logger.$params.q}`); + this.logger.$params.table = this.logger.$params.q; + return this.logger.$http.get('Urls/findOne', {filter}) .then(res => { From 4f16df523e23e4c63acaadfa807eb311ac293b60 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 26 Sep 2024 12:14:02 +0000 Subject: [PATCH 08/11] perf(salix): use params.q as table filter in lilium --- front/core/services/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/core/services/app.js b/front/core/services/app.js index a26d6def5..65d70e216 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -66,8 +66,9 @@ export default class App { ]} }; + if (this.logger.$params.q) - this.logger.$params.table = this.logger.$params.q; + newRoute = newRoute.concat(`?table=${this.logger.$params.q}`); return this.logger.$http.get('Urls/findOne', {filter}) From 640d9ad9f7ab5187743679c0f0feb34db46cf9c3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 26 Sep 2024 12:38:27 +0000 Subject: [PATCH 09/11] fix(salix): use params.sq --- front/core/services/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/core/services/app.js b/front/core/services/app.js index 65d70e216..b8fcc43e1 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -57,7 +57,7 @@ export default class App { getUrl(route, appName = 'lilium') { const index = window.location.hash.indexOf(route.toLowerCase()); - const newRoute = index < 0 ? route : window.location.hash.substring(index); + let newRoute = index < 0 ? route : window.location.hash.substring(index); const env = process.env.NODE_ENV; const filter = { where: {and: [ From f858674c8a4f4f74c05ed44929154af40adeb3e4 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 27 Sep 2024 12:01:54 +0200 Subject: [PATCH 10/11] Revert "Merge pull request '7404-stockBuyed' (!2836) from 7404-stockBuyed into dev" This reverts commit f6c5f41d44adfdc16fce0dc89ac38afbf1de25a0, reversing changes made to 5ee5da24e18b4497b8835715dd7a3e8af5c3bba2. --- back/models/buyer.json | 3 - db/dump/fixtures.before.sql | 84 ++++++++++--------- .../vn/procedures/stockBought_calculate.sql | 52 ------------ db/routines/vn/views/buyer.sql | 4 +- .../11115-turquoiseRose/00-firstScript.sql | 30 ------- loopback/locale/en.json | 7 +- loopback/locale/es.json | 9 +- .../account/back/models/mail-alias-account.js | 1 - modules/entry/back/methods/entry/print.js | 2 +- .../back/methods/entry/specs/filter.spec.js | 4 +- .../methods/stock-bought/getStockBought.js | 60 ------------- .../stock-bought/getStockBoughtDetail.js | 58 ------------- modules/entry/back/model-config.json | 3 - modules/entry/back/models/stock-bought.js | 10 --- modules/entry/back/models/stock-bought.json | 34 -------- 15 files changed, 55 insertions(+), 306 deletions(-) delete mode 100644 db/routines/vn/procedures/stockBought_calculate.sql delete mode 100644 db/versions/11115-turquoiseRose/00-firstScript.sql delete mode 100644 modules/entry/back/methods/stock-bought/getStockBought.js delete mode 100644 modules/entry/back/methods/stock-bought/getStockBoughtDetail.js delete mode 100644 modules/entry/back/models/stock-bought.js delete mode 100644 modules/entry/back/models/stock-bought.json diff --git a/back/models/buyer.json b/back/models/buyer.json index a1297eda3..a17d3b538 100644 --- a/back/models/buyer.json +++ b/back/models/buyer.json @@ -15,9 +15,6 @@ "nickname": { "type": "string", "required": true - }, - "display": { - "type": "boolean" } }, "acls": [ diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 514a94506..ad1c19794 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -179,12 +179,12 @@ INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `i (30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2); INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `countryFk`, `hasProduction`, `isOrigin`, `isDestiny`) - VALUES (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), + VALUES + (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 13, 1, 1, 0), (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0), (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1), (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), - (6, 'Warehouse six', 'VNH', 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0), (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0); @@ -1497,16 +1497,16 @@ INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`) - VALUES (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), - (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150.00, 2000, 'second travel', 2, 2, 2), - (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), - (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), - (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), - (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), - (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10), - (11, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4); + VALUES + (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), + (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2, 2), + (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), + (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), + (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), + (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), + (10, DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) VALUES @@ -1519,8 +1519,7 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'), (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''), (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''), - (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''), - (99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 1, 1, ''); + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''); INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) VALUES (2, 4, 1); @@ -1543,7 +1542,7 @@ INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `sal ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '186', '0', '51', '53.12', '56.20', '56.20', '56.20'), ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '277', '0', '53.12', '56.20', '56.20', '56.20', '56.20'); -INSERT INTO vn.buy(id,entryFk,itemFk,buyingValue,quantity,packagingFk,stickers,freightValue,packageValue,comissionValue,packing,grouping,groupingMode,location,price1,price2,price3,printedStickers,isChecked,isIgnored,weight,created) +INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagingFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`, `printedStickers`,`isChecked`,`isIgnored`,`weight`, `created`) VALUES (1, 1, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH), (2, 2, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 1 MONTH), @@ -1559,8 +1558,7 @@ INSERT INTO vn.buy(id,entryFk,itemFk,buyingValue,quantity,packagingFk,stickers,f (12, 6, 4, 1.25, 0, 3, 1, 2.500, 2.500, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), (13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), - (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), - (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'); + (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()); INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) VALUES @@ -3937,37 +3935,43 @@ INSERT INTO vn.medicalReview (id, workerFk, centerFk, `date`, `time`, isFit, amount, invoice, remark) VALUES(3, 9, 2, '2000-01-01', '8:00', 1, 150.0, NULL, NULL); -INSERT INTO vn.stockBought (workerFk, bought, reserve, dated) - VALUES(35, 1.00, 1.00, '2001-01-01'); - -INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk) - VALUES (1,0.6,6); - -INSERT INTO vn.payrollComponent (id, name, isSalaryAgreed, isVariable, isException) - VALUES (1, 'Salario1', 1, 0, 0), +INSERT INTO vn.payrollComponent +(id, name, isSalaryAgreed, isVariable, isException) + VALUES + (1, 'Salario1', 1, 0, 0), (2, 'Salario2', 1, 1, 0), (3, 'Salario3', 1, 0, 1); -INSERT INTO vn.workerIncome (debit, credit, incomeTypeFk, paymentDate, workerFk, concept) - VALUES (1000.00, 900.00, 2, '2000-01-01', 1106, NULL), + +INSERT INTO vn.workerIncome +(debit, credit, incomeTypeFk, paymentDate, workerFk, concept) + VALUES + (1000.00, 900.00, 2, '2000-01-01', 1106, NULL), (1001.00, 800.00, 2, '2000-01-01', 1106, NULL); -INSERT INTO dipole.printer (id, description) VALUES(1, ''); -INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) - VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); +INSERT INTO dipole.printer (id, description) +VALUES(1, ''); -INSERT INTO vn.accountDetail (id, value, accountDetailTypeFk, supplierAccountFk) - VALUES (21, 'ES12345B12345678', 3, 241), - (35, 'ES12346B12345679', 3, 241); +INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, +truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) +VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); -INSERT INTO vn.accountDetailType (id, description, code) - VALUES (1, 'IBAN', 'iban'), - (2, 'SWIFT', 'swift'), - (3, 'Referencia Remesas', 'remRef'), - (4, 'Referencia Transferencias', 'trnRef'), - (5, 'Referencia Nominas', 'payRef'), - (6, 'ABA', 'aba'); +INSERT INTO vn.accountDetail +(id, value, accountDetailTypeFk, supplierAccountFk) +VALUES + (21, 'ES12345B12345678', 3, 241), + (35, 'ES12346B12345679', 3, 241); + +INSERT INTO vn.accountDetailType +(id, description, code) +VALUES + (1, 'IBAN', 'iban'), + (2, 'SWIFT', 'swift'), + (3, 'Referencia Remesas', 'remRef'), + (4, 'Referencia Transferencias', 'trnRef'), + (5, 'Referencia Nominas', 'payRef'), + (6, 'ABA', 'aba'); INSERT IGNORE INTO ormConfig SET id =1, diff --git a/db/routines/vn/procedures/stockBought_calculate.sql b/db/routines/vn/procedures/stockBought_calculate.sql deleted file mode 100644 index 6eabe015c..000000000 --- a/db/routines/vn/procedures/stockBought_calculate.sql +++ /dev/null @@ -1,52 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`() -BEGIN -/** - * Inserts the purchase volume per buyer - * into stockBought according to the current date. - */ - DECLARE vDated DATE; - SET vDated = util.VN_CURDATE(); - - CREATE OR REPLACE TEMPORARY TABLE tStockBought - SELECT workerFk, reserve - FROM stockBought - WHERE dated = vDated - AND reserve; - - DELETE FROM stockBought WHERE dated = vDated; - - INSERT INTO stockBought (workerFk, bought, dated) - SELECT it.workerFk, - ROUND(SUM( - (ac.conversionCoefficient * - (b.quantity / b.packing) * - buy_getVolume(b.id) - ) / (vc.trolleyM3 * 1000000) - ), 1), - vDated - FROM entry e - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - JOIN buy b ON b.entryFk = e.id - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN auctionConfig ac - JOIN volumeConfig vc - WHERE t.shipped = vDated - AND t.warehouseInFk = ac.warehouseFk - GROUP BY it.workerFk; - - UPDATE stockBought s - JOIN tStockBought ts ON ts.workerFk = s.workerFk - SET s.reserve = ts.reserve - WHERE s.dated = vDated; - - INSERT INTO stockBought (workerFk, reserve, dated) - SELECT ts.workerFk, ts.reserve, vDated - FROM tStockBought ts - WHERE ts.workerFk NOT IN (SELECT workerFk FROM stockBought WHERE dated = vDated); - - DROP TEMPORARY TABLE tStockBought; -END$$ -DELIMITER ; diff --git a/db/routines/vn/views/buyer.sql b/db/routines/vn/views/buyer.sql index e690dc16f..4f668d35d 100644 --- a/db/routines/vn/views/buyer.sql +++ b/db/routines/vn/views/buyer.sql @@ -2,12 +2,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`buyer` AS SELECT DISTINCT `u`.`id` AS `userFk`, - `u`.`nickname` AS `nickname`, - `ic`.`display` AS `display` + `u`.`nickname` AS `nickname` FROM ( `account`.`user` `u` JOIN `vn`.`itemType` `it` ON(`it`.`workerFk` = `u`.`id`) - JOIN `vn`.`itemCategory` `ic` ON(`ic`.`id` = `it`.`categoryFk`) ) WHERE `u`.`active` <> 0 ORDER BY `u`.`nickname` diff --git a/db/versions/11115-turquoiseRose/00-firstScript.sql b/db/versions/11115-turquoiseRose/00-firstScript.sql deleted file mode 100644 index 3982936fc..000000000 --- a/db/versions/11115-turquoiseRose/00-firstScript.sql +++ /dev/null @@ -1,30 +0,0 @@ --- Place your SQL code here --- vn.stockBought definition - -CREATE TABLE IF NOT EXISTS vn.stockBought ( - id INT UNSIGNED auto_increment NOT NULL, - workerFk int(10) unsigned NOT NULL, - bought decimal(10,2) NOT NULL COMMENT 'purchase volume in m3 for the day', - reserve decimal(10,2) NULL COMMENT 'reserved volume in m3 for the day', - dated DATE NOT NULL DEFAULT current_timestamp(), - CONSTRAINT stockBought_pk PRIMARY KEY (id), - CONSTRAINT stockBought_unique UNIQUE KEY (workerFk,dated), - CONSTRAINT stockBought_worker_FK FOREIGN KEY (workerFk) REFERENCES vn.worker(id) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; - - -INSERT IGNORE vn.stockBought (workerFk, bought, reserve, dated) - SELECT userFk, SUM(buyed), SUM(IFNULL(reserved,0)), dated - FROM vn.stockBuyed - WHERE userFk IS NOT NULL - AND buyed IS NOT NULL - GROUP BY userFk, dated; - -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('StockBought','*','READ','ALLOW','ROLE','buyer'), - ('StockBought','*','WRITE','ALLOW','ROLE','buyer'), - ('Buyer','*','READ','ALLOW','ROLE','buyer'); - diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 352e08826..1753d1d07 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -235,10 +235,9 @@ "Cannot add holidays on this day": "Cannot add holidays on this day", "Cannot send mail": "Cannot send mail", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", + "This postcode already exists": "This postcode already exists", "Original invoice not found": "Original invoice not found", "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", - "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "This postcode already exists": "This postcode already exists", - "This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date" -} \ No newline at end of file + "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fdd4ea095..eb48b0646 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -366,17 +366,16 @@ "The invoices have been created but the PDFs could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", "Payment method is required": "El método de pago es obligatorio", - "Cannot send mail": "No se ha podido enviar el correo", + "Cannot send mail": "Não é possível enviar o email", "CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos", "The sale not exists in the item shelving": "La venta no existe en la estantería del artículo", + "The entry not have stickers": "La entrada no tiene etiquetas", + "Too many records": "Demasiados registros", "Original invoice not found": "Factura original no encontrada", "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe", "Weight already set": "El peso ya está establecido", "This ticket is not allocated to your department": "Este ticket no está asignado a tu departamento", "There is already a tray with the same height": "Ya existe una bandeja con la misma altura", "The height must be greater than 50cm": "La altura debe ser superior a 50cm", - "The maximum height of the wagon is 200cm": "La altura máxima es 200cm", - "The entry does not have stickers": "La entrada no tiene etiquetas", - "Too many records": "Demasiados registros", - "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha" + "The maximum height of the wagon is 200cm": "La altura máxima es 200cm" } diff --git a/modules/account/back/models/mail-alias-account.js b/modules/account/back/models/mail-alias-account.js index 0eee6a123..61ca344e9 100644 --- a/modules/account/back/models/mail-alias-account.js +++ b/modules/account/back/models/mail-alias-account.js @@ -1,6 +1,5 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); -const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { diff --git a/modules/entry/back/methods/entry/print.js b/modules/entry/back/methods/entry/print.js index 11abf0788..5b9de9a69 100644 --- a/modules/entry/back/methods/entry/print.js +++ b/modules/entry/back/methods/entry/print.js @@ -52,7 +52,7 @@ module.exports = Self => { await merger.add(new Uint8Array(pdfBuffer[0])); } - if (!merger._doc) throw new UserError('The entry does not have stickers'); + if (!merger._doc) throw new UserError('The entry not have stickers'); await Self.rawSql(` UPDATE buy diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 145da170a..c7156062a 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(12); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(11); + expect(result.length).toEqual(10); await tx.rollback(); } catch (e) { diff --git a/modules/entry/back/methods/stock-bought/getStockBought.js b/modules/entry/back/methods/stock-bought/getStockBought.js deleted file mode 100644 index 94e206ece..000000000 --- a/modules/entry/back/methods/stock-bought/getStockBought.js +++ /dev/null @@ -1,60 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('getStockBought', { - description: 'Returns the stock bought for a given date', - accessType: 'READ', - accepts: [{ - arg: 'workerFk', - type: 'number', - description: 'The id for a buyer', - }, - { - arg: 'dated', - type: 'date', - description: 'The date to filter', - } - ], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/getStockBought`, - verb: 'GET' - } - }); - - Self.getStockBought = async(workerFk, dated = Date.vnNew()) => { - const models = Self.app.models; - const today = Date.vnNew(); - dated.setHours(0, 0, 0, 0); - today.setHours(0, 0, 0, 0); - - if (dated.getTime() === today.getTime()) - await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`); - - const filter = { - where: { - dated: dated - }, - include: [ - { - relation: 'worker', - scope: { - include: [ - { - relation: 'user', - scope: { - fields: ['id', 'name'] - } - } - ] - } - } - ] - }; - - if (workerFk) filter.where.workerFk = workerFk; - - return models.StockBought.find(filter); - }; -}; diff --git a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js deleted file mode 100644 index 6f09f1f67..000000000 --- a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js +++ /dev/null @@ -1,58 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('getStockBoughtDetail', { - description: 'Returns the detail of stock bought for a given date and a worker', - accessType: 'READ', - accepts: [{ - arg: 'workerFk', - type: 'number', - description: 'The worker to filter', - required: true, - }, { - arg: 'dated', - type: 'string', - description: 'The date to filter', - } - ], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/getStockBoughtDetail`, - verb: 'GET' - } - }); - - Self.getStockBoughtDetail = async(workerFk, dated) => { - if (!dated) { - dated = Date.vnNew(); - dated.setHours(0, 0, 0, 0); - } - return Self.rawSql( - `SELECT e.id entryFk, - i.id itemFk, - i.longName itemName, - b.quantity, - ROUND((ac.conversionCoefficient * - (b.quantity / b.packing) * - buy_getVolume(b.id) - ) / (vc.trolleyM3 * 1000000), - 2 - ) volume, - b.packagingFk, - b.packing - FROM entry e - JOIN travel t ON t.id = e.travelFk - JOIN buy b ON b.entryFk = e.id - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN worker w ON w.id = it.workerFk - JOIN auctionConfig ac - JOIN volumeConfig vc - WHERE t.warehouseInFk = ac.warehouseFk - AND it.workerFk = ? - AND t.shipped = util.VN_CURDATE()`, - [workerFk] - ); - }; -}; diff --git a/modules/entry/back/model-config.json b/modules/entry/back/model-config.json index 85f5e8285..dc7fd86be 100644 --- a/modules/entry/back/model-config.json +++ b/modules/entry/back/model-config.json @@ -25,8 +25,5 @@ }, "EntryType": { "dataSource": "vn" - }, - "StockBought": { - "dataSource": "vn" } } \ No newline at end of file diff --git a/modules/entry/back/models/stock-bought.js b/modules/entry/back/models/stock-bought.js deleted file mode 100644 index ae52e7654..000000000 --- a/modules/entry/back/models/stock-bought.js +++ /dev/null @@ -1,10 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); -module.exports = Self => { - require('../methods/stock-bought/getStockBought')(Self); - require('../methods/stock-bought/getStockBoughtDetail')(Self); - Self.rewriteDbError(function(err) { - if (err.code === 'ER_DUP_ENTRY') - return new UserError(`This buyer has already made a reservation for this date`); - return err; - }); -}; diff --git a/modules/entry/back/models/stock-bought.json b/modules/entry/back/models/stock-bought.json deleted file mode 100644 index 18c9f0347..000000000 --- a/modules/entry/back/models/stock-bought.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "StockBought", - "base": "VnModel", - "options": { - "mysql": { - "table": "stockBought" - } - }, - "properties": { - "id": { - "type": "number", - "id": true - }, - "workerFk": { - "type": "number" - }, - "bought": { - "type": "number" - }, - "reserve": { - "type": "number" - }, - "dated": { - "type": "date" - } - }, - "relations": { - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - } - } -} From dbbd2c7947c7e81f3e828a382972166b892354ba Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 30 Sep 2024 08:04:01 +0200 Subject: [PATCH 11/11] feat(ClaimBeginning): throw error when quantity claimed is greater than quantity of line --- loopback/locale/en.json | 4 +- loopback/locale/es.json | 3 +- loopback/locale/fr.json | 4 +- loopback/locale/pt.json | 3 +- .../specs/claim-beginning.spec.js | 55 +++++++++++++++++++ modules/claim/back/models/claim-beginning.js | 17 ++++-- 6 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 modules/claim/back/methods/claim-beginning/specs/claim-beginning.spec.js diff --git a/loopback/locale/en.json b/loopback/locale/en.json index d9d9c8511..f0b7d6eca 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -236,6 +236,6 @@ "Cannot send mail": "Cannot send mail", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", "This postcode already exists": "This postcode already exists", - "Original invoice not found": "Original invoice not found" - + "Original invoice not found": "Original invoice not found", + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b9933f596..84722ea5d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -372,5 +372,6 @@ "The entry not have stickers": "La entrada no tiene etiquetas", "Too many records": "Demasiados registros", "Original invoice not found": "Factura original no encontrada", - "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe" + "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe", + "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea" } diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 601fe35f5..a6648b186 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -361,6 +361,6 @@ "The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", - "Original invoice not found": "Facture originale introuvable" - + "Original invoice not found": "Facture originale introuvable", + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne" } diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index a6a65710f..a43f0e780 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -361,5 +361,6 @@ "The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", "Original invoice not found": "Fatura original não encontrada", - "Cannot send mail": "Não é possível enviar o email" + "Cannot send mail": "Não é possível enviar o email", + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" } diff --git a/modules/claim/back/methods/claim-beginning/specs/claim-beginning.spec.js b/modules/claim/back/methods/claim-beginning/specs/claim-beginning.spec.js new file mode 100644 index 000000000..b7974ad23 --- /dev/null +++ b/modules/claim/back/methods/claim-beginning/specs/claim-beginning.spec.js @@ -0,0 +1,55 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +describe('ClaimBeginning model()', () => { + const claimFk = 1; + const activeCtx = { + accessToken: {userId: 18}, + headers: {origin: 'localhost:5000'}, + __: () => {} + }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should change quantity claimed', async() => { + const tx = await models.ClaimBeginning.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + const claim = await models.ClaimBeginning.findOne({where: {claimFk}}, options); + const sale = await models.Sale.findById(claim.saleFk, {}, options); + await claim.updateAttribute('quantity', sale.quantity - 1, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error).toBeUndefined(); + }); + + it('should throw error when quantity claimed is greater than quantity of the sale', async() => { + const tx = await models.ClaimBeginning.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + const claim = await models.ClaimBeginning.findOne({where: {claimFk}}, options); + const sale = await models.Sale.findById(claim.saleFk, {}, options); + await claim.updateAttribute('quantity', sale.quantity + 1, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.toString()).toContain('The quantity claimed cannot be greater than the quantity of the line'); + }); +}); diff --git a/modules/claim/back/models/claim-beginning.js b/modules/claim/back/models/claim-beginning.js index d269b2285..3dc9261c3 100644 --- a/modules/claim/back/models/claim-beginning.js +++ b/modules/claim/back/models/claim-beginning.js @@ -10,16 +10,21 @@ module.exports = Self => { }); Self.observe('before save', async ctx => { + const options = ctx.options; + const models = Self.app.models; + const saleFk = ctx?.currentInstance?.saleFk || ctx?.instance?.saleFk; + const sale = await models.Sale.findById(saleFk, {fields: ['ticketFk', 'quantity']}, options); + if (ctx.isNewInstance) { - const models = Self.app.models; - const options = ctx.options; - const instance = ctx.instance; - const ticket = await models.Sale.findById(instance.saleFk, {fields: ['ticketFk']}, options); - const claim = await models.Claim.findById(instance.claimFk, {fields: ['ticketFk']}, options); - if (ticket.ticketFk != claim.ticketFk) + const claim = await models.Claim.findById(ctx.instance.claimFk, {fields: ['ticketFk']}, options); + if (sale.ticketFk != claim.ticketFk) throw new UserError(`Cannot create a new claimBeginning from a different ticket`); } + await claimIsEditable(ctx); + + if (sale?.quantity && ctx.data?.quantity && ctx.data.quantity > sale?.quantity) + throw new UserError('The quantity claimed cannot be greater than the quantity of the line'); }); Self.observe('before delete', async ctx => {