From b352fc10e7f1d4864896cb42076fe54eadcbaae6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 20 Mar 2024 14:44:06 +0100 Subject: [PATCH 01/51] refs #6532 redirect grafana, remove mermas --- modules/item/front/index.js | 1 - modules/item/front/waste/detail/index.html | 43 ---------------- modules/item/front/waste/detail/index.js | 7 --- modules/item/front/waste/detail/style.scss | 25 --------- modules/item/front/waste/index/index.html | 51 +------------------ modules/item/front/waste/index/index.js | 22 ++------ modules/item/front/waste/index/index.spec.js | 53 -------------------- 7 files changed, 5 insertions(+), 197 deletions(-) delete mode 100644 modules/item/front/waste/detail/index.html delete mode 100644 modules/item/front/waste/detail/index.js delete mode 100644 modules/item/front/waste/detail/style.scss delete mode 100644 modules/item/front/waste/index/index.spec.js diff --git a/modules/item/front/index.js b/modules/item/front/index.js index d2ffcc8fb..354477d4d 100644 --- a/modules/item/front/index.js +++ b/modules/item/front/index.js @@ -20,7 +20,6 @@ import './botanical'; import './barcode'; import './summary'; import './waste/index/'; -import './waste/detail'; import './fixed-price'; import './fixed-price-search-panel'; import './item-type'; diff --git a/modules/item/front/waste/detail/index.html b/modules/item/front/waste/detail/index.html deleted file mode 100644 index 1b44088bf..000000000 --- a/modules/item/front/waste/detail/index.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - -
- -
{{detail.family}} ({{detail.buyer}})
-
- - - - Item - Percentage - Dwindle - Total - - - - - - - {{::waste.itemFk}} - - - {{::(waste.percentage / 100) | percentage: 2}} - {{::waste.dwindle | currency: 'EUR'}} - {{::waste.total | currency: 'EUR'}} - - - -
-
-
- - \ No newline at end of file diff --git a/modules/item/front/waste/detail/index.js b/modules/item/front/waste/detail/index.js deleted file mode 100644 index 2949a493b..000000000 --- a/modules/item/front/waste/detail/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import ngModule from '../../module'; -import Section from 'salix/components/section'; - -ngModule.vnComponent('vnItemWasteDetail', { - template: require('./index.html'), - controller: Section -}); diff --git a/modules/item/front/waste/detail/style.scss b/modules/item/front/waste/detail/style.scss deleted file mode 100644 index 55a6eb2ef..000000000 --- a/modules/item/front/waste/detail/style.scss +++ /dev/null @@ -1,25 +0,0 @@ -@import "variables"; - -vn-item-waste { - .header { - margin-bottom: 16px; - text-transform: uppercase; - font-size: 1.25rem; - line-height: 1; - padding: 7px; - padding-bottom: 7px; - padding-bottom: 4px; - font-weight: lighter; - background-color: #fde6ca; - border-bottom: 1px solid #f7931e; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - - vn-table vn-th.waste-family, - vn-table vn-td.waste-family { - max-width: 64px; - width: 64px - } -} \ No newline at end of file diff --git a/modules/item/front/waste/index/index.html b/modules/item/front/waste/index/index.html index f1475c1b3..7fb3b870e 100644 --- a/modules/item/front/waste/index/index.html +++ b/modules/item/front/waste/index/index.html @@ -1,49 +1,2 @@ - - - - - - - - Buyer - Family - Percentage - Dwindle - Total - - - - - - {{::detail.buyer}} - {{::detail.family}} - {{::(detail.percentage / 100) | percentage: 2}} - {{::detail.dwindle | currency: 'EUR'}} - {{::detail.total | currency: 'EUR'}} - - - - - - - - {{::waste.family}} - {{::(waste.percentage / 100) | percentage: 2}} - {{::waste.dwindle | currency: 'EUR'}} - {{::waste.total | currency: 'EUR'}} - - - - - - + + diff --git a/modules/item/front/waste/index/index.js b/modules/item/front/waste/index/index.js index b11f54b08..86d9d3778 100644 --- a/modules/item/front/waste/index/index.js +++ b/modules/item/front/waste/index/index.js @@ -5,27 +5,11 @@ import './style.scss'; export default class Controller extends Section { constructor($element, $) { super($element, $); - - this.getWasteConfig(); } - getWasteConfig() { - return this.wasteConfig = JSON.parse(localStorage.getItem('wasteConfig')) || {}; - } - - setWasteConfig() { - localStorage.setItem('wasteConfig', JSON.stringify(this.wasteConfig)); - } - - toggleHidePanel(detail) { - if (!this.wasteConfig[detail.buyer]) { - this.wasteConfig[detail.buyer] = { - hidden: true - }; - } else - this.wasteConfig[detail.buyer].hidden = !this.wasteConfig[detail.buyer].hidden; - - this.setWasteConfig(); + async $onInit() { + this.$state.go('item.index'); + window.location.href = 'https://grafana.verdnatura.es/d/TTNXQAxVk'; } } diff --git a/modules/item/front/waste/index/index.spec.js b/modules/item/front/waste/index/index.spec.js deleted file mode 100644 index fd7332f68..000000000 --- a/modules/item/front/waste/index/index.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -import './index.js'; -import crudModel from 'core/mocks/crud-model'; - -describe('Item', () => { - describe('Component vnItemWasteIndex', () => { - let $scope; - let controller; - - beforeEach(ngModule('item')); - - beforeEach(inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - $scope.model = crudModel; - const $element = angular.element(''); - controller = $componentController('vnItemWasteIndex', {$element, $scope}); - })); - - describe('getWasteConfig / setWasteConfig', () => { - it('should return the local storage wasteConfig', () => { - const result = controller.getWasteConfig(); - - expect(result).toEqual({}); - }); - - it('should set and return the local storage wasteConfig', () => { - controller.wasteConfig = {salesPerson: {hidden: true}}; - controller.setWasteConfig(); - - const result = controller.getWasteConfig(); - - expect(result).toEqual(controller.wasteConfig); - }); - }); - - describe('toggleHidePanel()', () => { - it('should make details hidden by default', () => { - controller.wasteConfig = {}; - - controller.toggleHidePanel({buyer: 'salesPerson'}); - - expect(controller.wasteConfig.salesPerson.hidden).toEqual(true); - }); - - it('should toggle hidden false', () => { - controller.wasteConfig = {salesPerson: {hidden: true}}; - - controller.toggleHidePanel({buyer: 'salesPerson'}); - - expect(controller.wasteConfig.salesPerson.hidden).toEqual(false); - }); - }); - }); -}); From 20a338f7464b3298b992d07cd09c42b79982c77e Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 21 Mar 2024 10:25:08 +0100 Subject: [PATCH 02/51] feat: #7120 specialPrice with new fiels --- db/routines/vn/functions/getSpecialPrice.sql | 9 ++-- .../procedures/catalog_componentCalculate.sql | 53 +++++++++++-------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/db/routines/vn/functions/getSpecialPrice.sql b/db/routines/vn/functions/getSpecialPrice.sql index f3b340cfe..c2c1878eb 100644 --- a/db/routines/vn/functions/getSpecialPrice.sql +++ b/db/routines/vn/functions/getSpecialPrice.sql @@ -8,13 +8,14 @@ BEGIN SELECT rate3 INTO price FROM vn.priceFixed - WHERE itemFk = vItemFk + WHERE itemFk = vItemFk AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; - SELECT `value` INTO price + SELECT `value` INTO price FROM vn.specialPrice - WHERE itemFk = vItemFk - AND clientFk = vClientFk ; + WHERE itemFk = vItemFk + AND (clientFk = vClientFk OR clientFk IS NULL) + AND util.VN_CURDATE() BETWEEN started AND ended; RETURN price; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql index 64bb74430..76fbadd61 100644 --- a/db/routines/vn/procedures/catalog_componentCalculate.sql +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -10,7 +10,7 @@ BEGIN * Calcula los componentes de los articulos de tmp.ticketLot * * @param vZoneFk para calcular el transporte - * @param vAddressFk Consignatario + * @param vAddressFk Consignatario * @param vShipped dia de salida del pedido * @param vWarehouseFk warehouse de salida del pedido * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) @@ -24,7 +24,7 @@ BEGIN SELECT clientFk INTO vClientFK FROM address WHERE id = vAddressFk; - + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate (PRIMARY KEY (itemFk, warehouseFk)) ENGINE = MEMORY @@ -36,7 +36,7 @@ BEGIN IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing, IFNULL(pf.`grouping`, b.`grouping`) `grouping`, ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, - tl.buyFk, + tl.buyFk, i.typeFk, IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping FROM tmp.ticketLot tl @@ -44,8 +44,9 @@ BEGIN JOIN item i ON i.id = tl.itemFk JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN specialPrice sp ON sp.itemFk = i.id - AND sp.clientFk = vClientFk + LEFT JOIN specialPrice sp ON sp.itemFk = i.id + AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) + AND vShipped BETWEEN sp.started AND sp.ended LEFT JOIN ( SELECT * FROM ( SELECT pf.itemFk, @@ -63,7 +64,7 @@ BEGIN LIMIT 10000000000000000000 ) tpf GROUP BY tpf.itemFk, tpf.warehouseFk - ) pf ON pf.itemFk = tl.itemFk + ) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.merchandise @@ -95,10 +96,10 @@ BEGIN FROM tmp.ticketComponent tc JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk GROUP BY tc.itemFk, warehouseFk; - + -- RECOBRO INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcb.warehouseFk, tcb.itemFk, c2.id, + SELECT tcb.warehouseFk, tcb.itemFk, c2.id, ROUND(tcb.base * LEAST( MAX(GREATEST(IFNULL(cr.priceIncreasing,0), @@ -129,29 +130,31 @@ BEGIN ROUND(base * wm.pricesModifierRate, 3) manaAuto FROM tmp.ticketComponentBase tcb JOIN `client` c on c.id = vClientFk - JOIN workerMana wm ON c.salesPersonFk = wm.workerFk + JOIN workerMana wm ON c.salesPersonFk = wm.workerFk JOIN vn.component c2 ON c2.code = 'autoMana' WHERE wm.isPricesModifierActivated HAVING manaAuto <> 0; - + -- Precios especiales INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, c2.id, GREATEST( - IFNULL(ROUND(tcb.base * c2.tax, 4), 0), + IFNULL(ROUND(tcb.base * c2.tax, 4), 0), IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3 ) cost FROM tmp.ticketComponentBase tcb JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount' - JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk - LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk + JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk + LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk + AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) + AND vShipped BETWEEN sp.started AND sp.ended JOIN vn.item i ON i.id = tcb.itemFk WHERE sp.value IS NULL AND i.supplyResponseFk IS NULL; - -- Individual + -- Individual INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, @@ -162,14 +165,16 @@ BEGIN JOIN vn.client c ON c.id = vClientFk JOIN vn.businessType bt ON bt.code = c.businessTypeFk WHERE bt.code = 'individual'; - + -- Venta por paquetes INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 + SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 FROM tmp.ticketComponentCalculate tcc JOIN vn.component c2 ON c2.code = 'salePerPackage' JOIN buy b ON b.id = tcc.buyFk - LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk + LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk + AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) + AND vShipped BETWEEN sp.started AND sp.ended WHERE sp.value IS NULL; CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id)) @@ -177,7 +182,7 @@ BEGIN SELECT vZoneFk id; CALL zone_getOptionsForShipment(vShipped, TRUE); - + -- Reparto INSERT INTO tmp.ticketComponent SELECT tcc.warehouseFK, @@ -191,7 +196,7 @@ BEGIN JOIN agencyMode am ON am.id = z.agencyModeFk JOIN vn.volumeConfig vc JOIN vn.component c2 ON c2.code = 'delivery' - LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk + LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk AND ic.itemFk = tcc.itemFk HAVING cost <> 0; @@ -208,7 +213,9 @@ BEGIN sp.value - SUM(tcc.cost) sumCost FROM tmp.ticketComponentCopy tcc JOIN component c ON c.id = tcc.componentFk - JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk + JOIN specialPrice sp ON sp.itemFk = tcc.itemFk + AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) + AND vShipped BETWEEN sp.started AND sp.ended JOIN vn.component c2 ON c2.code = 'specialPrices' WHERE c.classRate IS NULL AND tcc.warehouseFk = vWarehouseFk @@ -244,9 +251,9 @@ BEGIN CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price, CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg FROM tmp.ticketComponentCalculate tcc - JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk AND tcs.warehouseFk = tcc.warehouseFk - WHERE IFNULL(tcs.classRate, 1) = 1 + WHERE IFNULL(tcs.classRate, 1) = 1 AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0) GROUP BY tcs.warehouseFk, tcs.itemFk; @@ -283,7 +290,7 @@ BEGIN SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 ) t GROUP BY itemFk, warehouseFk, `grouping`; - + DROP TEMPORARY TABLE tmp.ticketComponentCalculate, tmp.ticketComponentSum, From c46e7227e75f26a6c938b3bd7586bf2c0e4c1a45 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 21 Mar 2024 10:40:30 +0100 Subject: [PATCH 03/51] feat: #7013 solo muestra clientes asegurados --- .../vn/procedures/solunionRiskRequest.sql | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql index b735bea33..540f52e18 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -1,31 +1,41 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() BEGIN - - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; CREATE TEMPORARY TABLE tmp.client_list - (PRIMARY KEY (Id_Cliente)) - ENGINE = MEMORY - SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc - JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification - WHERE dateEnd IS NULL - ORDER BY ci.creationDate DESC - LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; - + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * FROM ( + SELECT cc.client, ci.grade + FROM creditClassification cc + JOIN creditInsurance ci ON cc.id = ci.creditClassification + WHERE dateEnd IS NULL + ORDER BY ci.creationDate DESC + LIMIT 10000000000000000000) t1 + GROUP BY client; + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); - - SELECT - c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, - cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, - f.Consumo consumo_anual, c.Vencimiento, ci.grade - FROM - vn2008.Clientes c - JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente - JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente - JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente - GROUP BY Id_cliente; - - DROP TEMPORARY TABLE IF EXISTS tmp.risk; + + SELECT + c.id, + c.name, + c.credit clientCredit, + c.creditInsurance solunion, + cast(r.risk as DECIMAL(10,0)) risk, + cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, + cac.invoiced billedAnnually, + c.dueDay, + ci.grade, + c2.country + FROM tmp.client_list ci + LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.client + JOIN client c ON c.id = ci.client + JOIN bs.clientAnnualConsumption cac ON c.id = cac.Id_Cliente + JOIN vn.country c2 ON c2.id = c.countryFk + GROUP BY c.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; From a24d38128b255ff8d1a178155dc3c7cc90d15e7a Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 21 Mar 2024 10:48:43 +0100 Subject: [PATCH 04/51] feat: #7013 muestra solo clientes asegurados --- .../vn/procedures/solunionRiskRequest.sql | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql index 540f52e18..6b51c4202 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -2,40 +2,39 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; - CREATE TEMPORARY TABLE tmp.client_list - (PRIMARY KEY (Id_Cliente)) - ENGINE = MEMORY - SELECT * FROM ( - SELECT cc.client, ci.grade - FROM creditClassification cc - JOIN creditInsurance ci ON cc.id = ci.creditClassification - WHERE dateEnd IS NULL - ORDER BY ci.creationDate DESC - LIMIT 10000000000000000000) t1 - GROUP BY client; + CREATE OR REPLACE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * FROM ( + SELECT cc.client Id_Cliente, ci.grade + FROM creditClassification cc + JOIN creditInsurance ci ON cc.id = ci.creditClassification + WHERE dateEnd IS NULL + ORDER BY ci.creationDate DESC + LIMIT 10000000000000000000) t1 + GROUP BY Id_Cliente; - CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); - SELECT - c.id, - c.name, - c.credit clientCredit, - c.creditInsurance solunion, - cast(r.risk as DECIMAL(10,0)) risk, - cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, - cac.invoiced billedAnnually, - c.dueDay, - ci.grade, - c2.country - FROM tmp.client_list ci - LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.client - JOIN client c ON c.id = ci.client - JOIN bs.clientAnnualConsumption cac ON c.id = cac.Id_Cliente - JOIN vn.country c2 ON c2.id = c.countryFk - GROUP BY c.id; + SELECT + c.id, + c.name, + c.credit clientCredit, + c.creditInsurance solunion, + cast(r.risk as DECIMAL(10,0)) risk, + cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, + cac.invoiced billedAnnually, + c.dueDay, + ci.grade, + c2.country + FROM tmp.client_list ci + LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.Id_Cliente + JOIN client c ON c.id = ci.Id_Cliente + JOIN bs.clientAnnualConsumption cac ON c.id = cac.clientFk + JOIN vn.country c2 ON c2.id = c.countryFk + GROUP BY c.id; - DROP TEMPORARY TABLE IF EXISTS tmp.risk; - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; From ca0d269ee289ce5d36303064c5805caf5ce89dfc Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 21 Mar 2024 15:02:09 +0100 Subject: [PATCH 05/51] refs #6074 remove isBlocked --- db/versions/10964-silverDracena/00-firstScript.sql | 2 ++ modules/entry/back/models/entry.json | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 db/versions/10964-silverDracena/00-firstScript.sql diff --git a/db/versions/10964-silverDracena/00-firstScript.sql b/db/versions/10964-silverDracena/00-firstScript.sql new file mode 100644 index 000000000..400758cb2 --- /dev/null +++ b/db/versions/10964-silverDracena/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.entry CHANGE isBlocked isBlocked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Deprecado 21/03/2024'; diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index 0f3e389b6..ab451219e 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -57,9 +57,6 @@ "columnName": "evaNotes" } }, - "isBlocked": { - "type": "boolean" - }, "loadPriority": { "type": "number" }, From 8d258254d0ada153524acdfc51d8a7afa0a3aa8d Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 25 Mar 2024 07:52:40 +0100 Subject: [PATCH 06/51] feat: #7013 change name procedure --- ...solunionRiskRequest.sql => creditInsurance_getRisk.sql} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename db/routines/vn/procedures/{solunionRiskRequest.sql => creditInsurance_getRisk.sql} (88%) diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql similarity index 88% rename from db/routines/vn/procedures/solunionRiskRequest.sql rename to db/routines/vn/procedures/creditInsurance_getRisk.sql index 6b51c4202..4a54c0f7f 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -1,7 +1,10 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`() BEGIN - + /** + * Devuelve el riesgo de los clientes que estan asegurados + * + */ CREATE OR REPLACE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY From 10a16fccd8a79d025fb4f4ea3fbc4df43a053ab1 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 25 Mar 2024 13:03:11 +0100 Subject: [PATCH 07/51] primer prototipo --- .../vn/procedures/boxPicking_print.sql | 286 ++++++++++++++++++ .../vn/procedures/sale_getBoxPickingList.sql | 2 + 2 files changed, 288 insertions(+) create mode 100644 db/routines/vn/procedures/boxPicking_print.sql diff --git a/db/routines/vn/procedures/boxPicking_print.sql b/db/routines/vn/procedures/boxPicking_print.sql new file mode 100644 index 000000000..0d34ed056 --- /dev/null +++ b/db/routines/vn/procedures/boxPicking_print.sql @@ -0,0 +1,286 @@ +DROP PROCEDURE IF EXISTS vn.boxPicking_print; + +DELIMITER $$ +$$ +CREATE PROCEDURE vn.boxPicking_print( + IN vPrinterFk INT, + IN vSaleFk INT, + IN vPacking INT, + IN vSectorFk INT, + IN vUserFk INT, + IN vPackagingFk INT, + IN vPackingSiteFk INT) +BEGIN +/** Splits a line of sale to a different ticket and prints the transport sticker + * + */ + DECLARE vAgencyModeFk INT; + DECLARE vConcept VARCHAR(20); + DECLARE vExpeditionFk INT; + DECLARE vItemFk INT; + DECLARE vItemShelvingFk INT; + DECLARE vItemShelvingSaleFk INT; + DECLARE vItemShelvingSaleFk_old INT; + DECLARE vLastExpeditionTimeStamp DATETIME; + DECLARE vMaxPhoneLength INT DEFAULT 11; + DECLARE vMaxStreetLength INT DEFAULT 36; + DECLARE vNewSaleFk INT; + DECLARE vNewTicketFk INT; + DECLARE vParkingCode VARCHAR(10); + DECLARE vQuantity INT; + DECLARE vRest INT DEFAULT 0; + DECLARE vRestSaleFk INT; + DECLARE vShelving VARCHAR(10); + DECLARE vTicketFk INT; + + SELECT s.quantity, + s.quantity MOD vPacking, + s.ticketFk, + s.itemFk, + s.concept + INTO vQuantity, + vRest, + vTicketFk, + vItemFk, + vConcept + FROM sale s + WHERE s.id = vSaleFk; + + IF vRest THEN + UPDATE sale SET quantity = quantity - vRest WHERE id = vSaleFk; + + INSERT INTO vn.sale(ticketFk, itemFk, quantity, price, discount, concept) + SELECT ticketFk, itemFk, vRest, price, discount, concept + FROM vn.sale + WHERE id = vSaleFk; + + SET vRestSaleFk = LAST_INSERT_ID(); + + INSERT INTO vn.saleComponent(saleFk, componentFk, value) + SELECT vRestSaleFk, componentFk, value + FROM vn.saleComponent + WHERE saleFk = vSaleFk; + END IF; + +w1: WHILE vQuantity >= vPacking DO + + SET vItemShelvingFk = 0; + + SELECT sub.id + INTO vItemShelvingFk + FROM vn.productionConfig pc + JOIN ( + SELECT ish.id, + ish.visible - ifnull(SUM(iss.quantity),0) available, + p.pickingOrder, + ish.created + FROM vn.itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + LEFT JOIN vn.itemShelvingSale iss + ON iss.itemShelvingFk = ish.id + AND iss.created >= CURDATE() + AND iss.isPicked = FALSE + WHERE ish.itemFk = vItemFk + AND p.sectorFk = vSectorFk + GROUP BY ish.id + HAVING available >= vPacking) sub + ORDER BY IF(pc.orderMode = 'Location',sub.pickingOrder, sub.created) + LIMIT 1; + + IF vItemShelvingFk THEN + INSERT INTO vn.itemShelvingSale + SET itemShelvingFk = vItemShelvingFk, + saleFk = vSaleFk, + quantity = vPacking, + userFk = vUserFk, + isPicked = TRUE; + + SET vItemShelvingSaleFk = LAST_INSERT_ID(); + + UPDATE vn.sale SET isPicked = FALSE WHERE id = vSaleFk; + ELSE + LEAVE w1; + END IF; + + SET vNewTicketFk = 0; + + SELECT MAX(t.id) INTO vNewTicketFk + FROM vn.ticket t + JOIN vn.ticketLastState tls ON tls.ticketFk = t.id + JOIN (SELECT addressFk, clientFk, date(shipped) shipped, warehouseFk + FROM vn.ticket + WHERE id = vTicketFk) tt + ON tt.addressFk = t.addressFk + AND tt.clientFk = t.clientFk + AND t.shipped BETWEEN tt.shipped AND util.dayend(tt.shipped) + AND t.warehouseFk = tt.warehouseFk + WHERE tls.name = 'Encajado' ; + + IF vNewTicketFk = 0 THEN + INSERT INTO vn.ticket( clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk, + priority, + hasPriority, + clonedFrom) + SELECT clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk, + priority, + hasPriority, + id + FROM vn.ticket + WHERE id = vTicketFk; + + SET vNewTicketFk = LAST_INSERT_ID(); + + INSERT INTO ticketTracking(ticketFk, stateFk, userFk) + SELECT vNewTicketFk, id, vUserFk + FROM state + WHERE code = 'PACKED'; + END IF; + + UPDATE sale SET quantity = quantity - vPacking WHERE id = vSaleFk; + + UPDATE itemShelving SET visible = visible - vPacking WHERE id = vItemShelvingFk; + + SET vNewSaleFk = 0; + + SELECT MAX(id) INTO vNewSaleFk + FROM sale + WHERE ticketFk = vNewTicketFk + AND itemFk = vItemFk; + + IF vNewSaleFk THEN + UPDATE sale + SET quantity = quantity + vPacking + WHERE id = vNewSaleFk; + + SET vItemShelvingSaleFk_old = 0; + + SELECT MAX(id) INTO vItemShelvingSaleFk_old + FROM vn.itemShelvingSale + WHERE itemShelvingFk = vItemShelvingFk + AND saleFk = vNewSaleFk; + + IF vItemShelvingSaleFk_old THEN + UPDATE vn.itemShelvingSale + SET quantity = quantity + vPacking + WHERE id = vItemShelvingSaleFk_old; + + DELETE FROM vn.itemShelvingSale + WHERE id = vItemShelvingSaleFk; + + SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; + ELSE + UPDATE itemShelvingSale + SET saleFk = vNewSaleFk + WHERE id = vItemShelvingSaleFk; + END IF; + ELSE + INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, discount, price) + SELECT vNewTicketFk, itemFk, concept, vPacking, discount, price + FROM vn.sale + WHERE id = vSaleFk; + + SET vNewSaleFk = LAST_INSERT_ID(); + + INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge) + SELECT vNewSaleFk, componentFk, value, isGreuge + FROM vn.saleComponent + WHERE saleFk = vSaleFk; + + UPDATE itemShelvingSale + SET saleFk = vNewSaleFk + WHERE id = vItemShelvingSaleFk; + END IF; + + INSERT IGNORE INTO vn.saleTracking(saleFk, isChecked, workerFk, stateFk) + SELECT vNewSaleFk, TRUE, vUserFk, id + FROM vn.state + WHERE code = 'PREPARED'; + + SELECT agencyModeFk INTO vAgencyModeFk + FROM ticket + WHERE id = vNewTicketFk; + + INSERT INTO vn.expedition( + agencyModeFk, + ticketFk, + freightItemFk, + workerFk, + packagingFk, + itemPackingTypeFk, + hostFk, + packingSiteFk, + monitorId, + started, + ended + ) + SELECT vAgencyModeFk, + vNewTicketFk, + i.id, + vUserFk, + vPackagingFk, + ps.code, + h.code, + vPackingSiteFk, + ps.monitorId, + started = IFNULL(vLastExpeditionTimeStamp, Now()), + ended = Now() + FROM packingSite ps + JOIN host h ON h.id = ps.hostFk + JOIN item i ON i.name = 'Shipping cost' + WHERE ps.id = vPackingSiteFk + LIMIT 1; + + SET vExpeditionFk = LAST_INSERT_ID(); + + SET vLastExpeditionTimeStamp = Now(); + + CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE); + + SELECT shelvingFk, p.code + INTO vShelving, vParkingCode + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + WHERE ish.id = vItemShelvingFk; + + UPDATE dipole.expedition_PrintOut SET + isPrinted = FALSE, + itemFk = vItemFk, + quantity = vPacking, + longName = vConcept, + shelvingFk = vShelving, + parkingCode = vParkingCode, + phone = RIGHT(phone,vMaxPhoneLength), + street = RIGHT(street, vMAxStreetLength) + WHERE expeditionFk = vExpeditionFk; + + DELETE FROM vn.sale + WHERE quantity = 0 + AND id = vSaleFk; + END WHILE; + +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index ff0e85259..7466eb9be 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -46,6 +46,7 @@ BEGIN JOIN parking p ON p.id = sh.parkingFk JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk JOIN agencyMode am ON am.id = pb.agencyModeFk + JOIN agency a ON a .id = am.agencyFk LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk @@ -60,6 +61,7 @@ BEGIN AND ((rm.bufferFk AND rm.isPickingAllowed) OR am.code = 'REC_ALG') AND pb.shipped = vDated + AND a.isOwn GROUP BY s.id ORDER BY etd; From eb2b0d41de4e4cdabce5587c72c292fba3c1dc04 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 25 Mar 2024 13:33:39 +0100 Subject: [PATCH 08/51] feat: refs #7002 update direction if device exists --- .../worker-time-control/updateTimeEntry.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index 7e4455447..e86834502 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -29,7 +29,7 @@ module.exports = Self => { Self.updateTimeEntry = async(ctx, timeEntryId, direction, options) => { const currentUserId = ctx.req.accessToken.userId; const models = Self.app.models; - const myOptions = {}; + const myOptions = {userId: currentUserId}; let tx; if (typeof options == 'object') @@ -41,19 +41,24 @@ module.exports = Self => { } try { - const {id, userFk, timed} = await Self.findById(timeEntryId, null, myOptions); - const isSubordinate = await models.Worker.isSubordinate(ctx, userFk, myOptions); + const timeEntry = await Self.findById(timeEntryId, null, myOptions); + const isSubordinate = await models.Worker.isSubordinate(ctx, timeEntry.userFk, myOptions); const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE'); - const isHimself = currentUserId == userFk; + const isHimself = currentUserId == timeEntry.userFk; const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss); if (notAllowed) throw new UserError(`You don't have enough privileges`); - await models.WorkerTimeControl.deleteById(id, myOptions); - const timeEntryUpdatedId = await Self.clockIn(userFk, timed, direction, null, myOptions); - - await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions); + let timeEntryUpdatedId; + if (timeEntry.device) { + timeEntry.updateAttribute('direction', direction); + timeEntryUpdatedId = timeEntry.id; + } else { + await models.WorkerTimeControl.deleteById(timeEntry.id, myOptions); + timeEntryUpdatedId = await Self.clockIn(timeEntry.userFk, timeEntry.timed, direction, null, myOptions); + } + await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, timeEntry.userFk, timeEntry.timed, myOptions); if (tx) await tx.commit(); return timeEntryUpdatedId; } catch (e) { From dd977fab831c22b45d65c31a920f536ae4d7d1e6 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 25 Mar 2024 14:56:12 +0100 Subject: [PATCH 09/51] fix: refs #7141 catalog_calculate --- .../hedera/procedures/catalog_calcFromMyAddress.sql | 2 +- db/routines/hedera/procedures/item_calcCatalog.sql | 2 +- db/routines/hedera/procedures/order_calcCatalog.sql | 2 +- db/routines/hedera/procedures/order_calcCatalogFull.sql | 2 +- db/routines/vn/procedures/catalog_calcFromItem.sql | 2 +- db/routines/vn/procedures/catalog_calculate.sql | 8 ++++++-- db/routines/vn/procedures/sale_replaceItem.sql | 3 ++- db/routines/vn/procedures/ticketCalculateFromType.sql | 2 +- modules/order/back/methods/order/catalogFilter.js | 3 ++- modules/order/back/methods/order/getItemTypeAvailable.js | 3 ++- 10 files changed, 18 insertions(+), 11 deletions(-) diff --git a/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql b/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql index c9a9db5e0..c9fa54f36 100644 --- a/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql +++ b/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql @@ -32,7 +32,7 @@ BEGIN WHERE c.available > 0 GROUP BY c.item_id; - CALL vn.catalog_calculate(vDelivery, vAddress, vAgencyMode); + CALL vn.catalog_calculate(vDelivery, vAddress, vAgencyMode, FALSE); DROP TEMPORARY TABLE tmp.item; END$$ diff --git a/db/routines/hedera/procedures/item_calcCatalog.sql b/db/routines/hedera/procedures/item_calcCatalog.sql index 81b3adf5a..e72c2fd06 100644 --- a/db/routines/hedera/procedures/item_calcCatalog.sql +++ b/db/routines/hedera/procedures/item_calcCatalog.sql @@ -16,7 +16,7 @@ BEGIN ENGINE = MEMORY SELECT vSelf itemFk; - CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); + CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, FALSE); SELECT l.warehouseFk, w.name warehouse, p.`grouping`, p.price, p.rate, l.available diff --git a/db/routines/hedera/procedures/order_calcCatalog.sql b/db/routines/hedera/procedures/order_calcCatalog.sql index 53ede1b57..239e01788 100644 --- a/db/routines/hedera/procedures/order_calcCatalog.sql +++ b/db/routines/hedera/procedures/order_calcCatalog.sql @@ -27,7 +27,7 @@ BEGIN WHERE orderFk = vSelf GROUP BY itemFk; - CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); + CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode, FALSE); DROP TEMPORARY TABLE tmp.item; END$$ diff --git a/db/routines/hedera/procedures/order_calcCatalogFull.sql b/db/routines/hedera/procedures/order_calcCatalogFull.sql index 52d22ba30..41408c5e8 100644 --- a/db/routines/hedera/procedures/order_calcCatalogFull.sql +++ b/db/routines/hedera/procedures/order_calcCatalogFull.sql @@ -22,7 +22,7 @@ BEGIN FROM `order` WHERE id = vSelf; - CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); + CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode, FALSE); IF account.myUser_getName() = 'visitor' THEN UPDATE tmp.ticketCalculateItem diff --git a/db/routines/vn/procedures/catalog_calcFromItem.sql b/db/routines/vn/procedures/catalog_calcFromItem.sql index aeeaccb08..497fd107c 100644 --- a/db/routines/vn/procedures/catalog_calcFromItem.sql +++ b/db/routines/vn/procedures/catalog_calcFromItem.sql @@ -20,7 +20,7 @@ BEGIN ENGINE = MEMORY SELECT vItemFk itemFk; - CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); + CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, TRUE); DROP TEMPORARY TABLE tmp.item; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql index 698328770..bb52020df 100644 --- a/db/routines/vn/procedures/catalog_calculate.sql +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -1,5 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_calculate`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_calculate`( + vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT, + vShowExpiredZones BOOLEAN) BEGIN /** * Calcula los articulos disponibles y sus precios @@ -25,7 +29,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, FALSE); + CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, vShowExpiredZones); DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; CREATE TEMPORARY TABLE tmp.ticketLot( diff --git a/db/routines/vn/procedures/sale_replaceItem.sql b/db/routines/vn/procedures/sale_replaceItem.sql index aff34d5e9..79997d989 100644 --- a/db/routines/vn/procedures/sale_replaceItem.sql +++ b/db/routines/vn/procedures/sale_replaceItem.sql @@ -77,7 +77,8 @@ BEGIN vNewItemFk); SELECT price INTO vNewPrice - FROM tmp.ticketCalculateItem; + FROM tmp.ticketComponentPrice + WHERE (vQuantity % `grouping` = 0); IF vNewPrice IS NULL THEN CALL util.throw('price retrieval failed'); diff --git a/db/routines/vn/procedures/ticketCalculateFromType.sql b/db/routines/vn/procedures/ticketCalculateFromType.sql index 106e0aecc..63f4b8941 100644 --- a/db/routines/vn/procedures/ticketCalculateFromType.sql +++ b/db/routines/vn/procedures/ticketCalculateFromType.sql @@ -11,7 +11,7 @@ BEGIN SELECT id itemFk FROM vn.item WHERE typeFk = vTypeFk; - CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); + CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, FALSE); DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.ticketLot; END$$ diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index dc0e2f60b..ab1d7784e 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -92,10 +92,11 @@ module.exports = Self => { // Calculate items const order = await Self.findById(orderFk, null, myOptions); stmts.push(new ParameterizedSQL( - 'CALL vn.catalog_calculate(?, ?, ?)', [ + 'CALL vn.catalog_calculate(?, ?, ?, ?)', [ order.landed, order.address_id, order.agency_id, + false ] )); diff --git a/modules/order/back/methods/order/getItemTypeAvailable.js b/modules/order/back/methods/order/getItemTypeAvailable.js index b62adebb5..b84863953 100644 --- a/modules/order/back/methods/order/getItemTypeAvailable.js +++ b/modules/order/back/methods/order/getItemTypeAvailable.js @@ -64,10 +64,11 @@ module.exports = Self => { stmts.push(stmt); stmt = new ParameterizedSQL( - 'CALL vn.catalog_calculate(?, ?, ?)', [ + 'CALL vn.catalog_calculate(?, ?, ?,?)', [ order.landed, order.addressFk, order.agencyModeFk, + false ] ); stmts.push(stmt); From 04e42cd3c842097a8fc9b9348941675c09675c45 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 26 Mar 2024 08:29:07 +0100 Subject: [PATCH 10/51] feat: #6514 created supplierDms functionality --- db/dump/fixtures.before.sql | 10 ++- .../00-aclSupplierDms.sql | 3 + loopback/server/datasources.json | 15 ++++ .../supplier/supplier-dms/downloadFile.js | 59 +++++++++++++ .../supplier/supplier-dms/removeFile.js | 53 ++++++++++++ .../supplier/supplier-dms/uploadFile.js | 86 +++++++++++++++++++ modules/supplier/back/model-config.json | 6 ++ .../back/models/supplier-container.json | 10 +++ modules/supplier/back/models/supplier-dms.js | 13 +++ .../supplier/back/models/supplier-dms.json | 37 ++++++++ 10 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 db/versions/10969-silverCataractarum/00-aclSupplierDms.sql create mode 100644 modules/supplier/back/methods/supplier/supplier-dms/downloadFile.js create mode 100644 modules/supplier/back/methods/supplier/supplier-dms/removeFile.js create mode 100644 modules/supplier/back/methods/supplier/supplier-dms/uploadFile.js create mode 100644 modules/supplier/back/models/supplier-container.json create mode 100644 modules/supplier/back/models/supplier-dms.js create mode 100644 modules/supplier/back/models/supplier-dms.json diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4af445bfa..bec4d964d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2400,7 +2400,8 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `readRoleFk`, `writeRoleFk`, `code`) (18, 'dua', NULL, NULL, 'dua'), (19, 'inmovilizado', NULL, NULL, 'fixedAssets'), (20, 'ReclamaciĆ³n', 1, 1, 'claim'), - (21, 'Entrada', 1, 1, 'entry'); + (21, 'Entrada', 1, 1, 'entry'), + (22, 'Proveedor', 1, 1, 'supplier'); INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) VALUES @@ -2412,7 +2413,8 @@ INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `wa (6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', util.VN_CURDATE()), (7, 20, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()), (8, 20, '8.mp4', 'video/mp4', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()), - (9, 21, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'ENTRADA ID 1', util.VN_CURDATE()); + (9, 21, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'ENTRADA ID 1', util.VN_CURDATE()), + (10, 21, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'ENTRADA DE PRUEBA', util.VN_CURDATE()); INSERT INTO `vn`.`claimDms`(`claimFk`, `dmsFk`) VALUES @@ -3737,3 +3739,7 @@ INSERT INTO vn.parkingLog(originFk, userFk, `action`, creationDate, description, INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,newInstance,changedModelId,changedModelValue) VALUES (18,9,'insert','2001-01-01 11:01:00.000','Ticket','{"isDeleted":true}',45,'Super Man'); + +INSERT INTO `vn`.`supplierDms`(`supplierFk`, `dmsFk`, `editorFk`) + VALUES + (1, 10, 9); \ No newline at end of file diff --git a/db/versions/10969-silverCataractarum/00-aclSupplierDms.sql b/db/versions/10969-silverCataractarum/00-aclSupplierDms.sql new file mode 100644 index 000000000..48c7438f1 --- /dev/null +++ b/db/versions/10969-silverCataractarum/00-aclSupplierDms.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('SupplierDms', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index 608479b4b..a8fc13152 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -126,5 +126,20 @@ "allowedContentTypes": [ "application/x-7z-compressed" ] + }, + "supplierStorage": { + "name": "supplierStorage", + "connector": "loopback-component-storage", + "provider": "filesystem", + "root": "./storage/dms", + "maxFileSize": "31457280", + "allowedContentTypes": [ + "image/png", + "image/jpeg", + "image/jpg", + "image/webp", + "video/mp4", + "application/pdf" + ] } } diff --git a/modules/supplier/back/methods/supplier/supplier-dms/downloadFile.js b/modules/supplier/back/methods/supplier/supplier-dms/downloadFile.js new file mode 100644 index 000000000..fa70dc554 --- /dev/null +++ b/modules/supplier/back/methods/supplier/supplier-dms/downloadFile.js @@ -0,0 +1,59 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('downloadFile', { + description: 'Get the supplier file', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'Number', + description: 'The file id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, + { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, + { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: `/:id/downloadFile`, + verb: 'GET' + } + }); + + Self.downloadFile = async function(ctx, id) { + const models = Self.app.models; + const SupplierContainer = models.SupplierContainer; + const dms = await models.Dms.findById(id); + const pathHash = SupplierContainer.getHash(dms.id); + try { + await SupplierContainer.getFile(pathHash, dms.file); + } catch (e) { + if (e.code != 'ENOENT') + throw e; + + const error = new UserError(`File doesn't exists`); + error.statusCode = 404; + + throw error; + } + + const stream = SupplierContainer.downloadStream(pathHash, dms.file); + + return [stream, dms.contentType, `filename="${dms.file}"`]; + }; +}; diff --git a/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js b/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js new file mode 100644 index 000000000..60fe4f4d5 --- /dev/null +++ b/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js @@ -0,0 +1,53 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('removeFile', { + description: 'Removes a entry document', + accessType: 'WRITE', + accepts: { + arg: 'id', + type: 'number', + description: 'The file id', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/removeFile`, + verb: 'DELETE' + } + }); + + Self.removeFile = async(ctx, id, options) => { + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const targetSupplierDms = await Self.findById(id, null, myOptions); + const targetDms = await Self.app.models.Dms.removeFile(ctx, targetSupplierDms.dmsFk, myOptions); + + if (!targetDms) + throw new UserError('Try again'); + + const supplierDmsDestroyed = await targetSupplierDms.destroy(myOptions); + + if (tx) await tx.commit(); + + return supplierDmsDestroyed; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; + diff --git a/modules/supplier/back/methods/supplier/supplier-dms/uploadFile.js b/modules/supplier/back/methods/supplier/supplier-dms/uploadFile.js new file mode 100644 index 000000000..a9ff2d125 --- /dev/null +++ b/modules/supplier/back/methods/supplier/supplier-dms/uploadFile.js @@ -0,0 +1,86 @@ + +module.exports = Self => { + Self.remoteMethodCtx('uploadFile', { + description: 'Upload and attach a file', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + description: 'The supplier id', + http: {source: 'path'} + }, + { + arg: 'warehouseId', + type: 'number', + description: 'The warehouse id', + required: true + }, + { + arg: 'companyId', + type: 'number', + description: 'The company id', + required: true + }, + { + arg: 'dmsTypeId', + type: 'number', + description: 'The dms type id', + required: true + }, + { + arg: 'reference', + type: 'string', + required: true + }, + { + arg: 'description', + type: 'string', + required: true + }, + { + arg: 'hasFile', + type: 'boolean', + description: 'True if has an attached file', + required: true + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/uploadFile`, + verb: 'POST' + } + }); + + Self.uploadFile = async(ctx, id, options) => { + const {Dms, SupplierDms} = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const uploadedFiles = await Dms.uploadFile(ctx, myOptions); + + const promises = uploadedFiles.map(dms => SupplierDms.create({ + supplierFk: id, + dmsFk: dms.id + }, myOptions)); + await Promise.all(promises); + + if (tx) await tx.commit(); + + return uploadedFiles; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index dbc387ed2..efbb4ceed 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -5,6 +5,12 @@ "Supplier": { "dataSource": "vn" }, + "SupplierDms": { + "dataSource": "vn" + }, + "SupplierContainer": { + "dataSource": "supplierStorage" + }, "SupplierAddress": { "dataSource": "vn" }, diff --git a/modules/supplier/back/models/supplier-container.json b/modules/supplier/back/models/supplier-container.json new file mode 100644 index 000000000..91b931869 --- /dev/null +++ b/modules/supplier/back/models/supplier-container.json @@ -0,0 +1,10 @@ +{ + "name": "SupplierContainer", + "base": "Container", + "acls": [{ + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} \ No newline at end of file diff --git a/modules/supplier/back/models/supplier-dms.js b/modules/supplier/back/models/supplier-dms.js new file mode 100644 index 000000000..13e492bfb --- /dev/null +++ b/modules/supplier/back/models/supplier-dms.js @@ -0,0 +1,13 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + require('../methods/supplier/supplier-dms/removeFile')(Self); + require('../methods/supplier/supplier-dms/downloadFile')(Self); + require('../methods/supplier/supplier-dms/uploadFile')(Self); + + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`The file is already attached to another entry`); + return err; + }); +}; diff --git a/modules/supplier/back/models/supplier-dms.json b/modules/supplier/back/models/supplier-dms.json new file mode 100644 index 000000000..8d32cc4e8 --- /dev/null +++ b/modules/supplier/back/models/supplier-dms.json @@ -0,0 +1,37 @@ +{ + "name": "SupplierDms", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "supplierDms" + } + }, + "allowedContentTypes": [ + "image/png", + "image/jpeg", + "image/jpg", + "application/pdf" + ], + "properties": { + "dmsFk": { + "type": "number", + "id": true, + "required": true + } + }, + "relations": { + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "supplierFk" + }, + "dms": { + "type": "belongsTo", + "model": "Dms", + "foreignKey": "dmsFk" + } + } +} \ No newline at end of file From a5082d04f9511f63815b6b2c1d5fd90b5ebb5cbc Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 26 Mar 2024 08:52:11 +0100 Subject: [PATCH 11/51] refs: #6514 fixed error --- .../supplier/back/methods/supplier/supplier-dms/removeFile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js b/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js index 60fe4f4d5..04a9011f1 100644 --- a/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js +++ b/modules/supplier/back/methods/supplier/supplier-dms/removeFile.js @@ -16,7 +16,7 @@ module.exports = Self => { }, http: { path: `/:id/removeFile`, - verb: 'DELETE' + verb: 'POST' } }); From 7f14211b80a50a1a114ad9d5f76ffd20b11a9b8e Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 09:27:30 +0100 Subject: [PATCH 12/51] feat: #7117 company_getSuppliersDebt devolver el pais del banco --- .../procedures/company_getSuppliersDebt.sql | 274 +++++++++--------- 1 file changed, 139 insertions(+), 135 deletions(-) diff --git a/db/routines/vn/procedures/company_getSuppliersDebt.sql b/db/routines/vn/procedures/company_getSuppliersDebt.sql index f6bfc229d..5354ef09d 100644 --- a/db/routines/vn/procedures/company_getSuppliersDebt.sql +++ b/db/routines/vn/procedures/company_getSuppliersDebt.sql @@ -7,81 +7,81 @@ BEGIN * @param vSelf company id * @param vMonthAgo time interval to be consulted */ - DECLARE vStartingDate DATETIME DEFAULT TIMESTAMPADD (MONTH,- vMonthsAgo,util.VN_CURDATE()); - DECLARE vCurrencyEuroFk INT; - DECLARE vStartDate DATE; - DECLARE vInvalidBalances DOUBLE; + DECLARE vStartingDate DATETIME DEFAULT TIMESTAMPADD (MONTH,- vMonthsAgo,util.VN_CURDATE()); + DECLARE vCurrencyEuroFk INT; + DECLARE vStartDate DATE; + DECLARE vInvalidBalances DOUBLE; - SELECT dated, invalidBalances INTO vStartDate, vInvalidBalances FROM supplierDebtConfig; - SELECT id INTO vCurrencyEuroFk FROM currency WHERE code = 'EUR'; + SELECT dated, invalidBalances INTO vStartDate, vInvalidBalances FROM supplierDebtConfig; + SELECT id INTO vCurrencyEuroFk FROM currency WHERE code = 'EUR'; - DROP TEMPORARY TABLE IF EXISTS tOpeningBalances; - CREATE TEMPORARY TABLE tOpeningBalances ( - supplierFk INT NOT NULL, - companyFk INT NOT NULL, - openingBalances DOUBLE NOT NULL, - closingBalances DOUBLE NOT NULL, - currencyFk INT NOT NULL, - PRIMARY KEY (supplierFk, companyFk, currencyFk) - ) ENGINE = MEMORY; + DROP TEMPORARY TABLE IF EXISTS tOpeningBalances; + CREATE TEMPORARY TABLE tOpeningBalances ( + supplierFk INT NOT NULL, + companyFk INT NOT NULL, + openingBalances DOUBLE NOT NULL, + closingBalances DOUBLE NOT NULL, + currencyFk INT NOT NULL, + PRIMARY KEY (supplierFk, companyFk, currencyFk) + ) ENGINE = MEMORY; - -- Calculates the opening and closing balance for each supplier - INSERT INTO tOpeningBalances - SELECT supplierFk, - companyFk, - SUM(amount * isBeforeStarting) AS openingBalances, - SUM(amount) closingBalances, - currencyFk - FROM ( - SELECT p.supplierFk, + -- Calculates the opening and closing balance for each supplier + INSERT INTO tOpeningBalances + SELECT supplierFk, + companyFk, + SUM(amount * isBeforeStarting) AS openingBalances, + SUM(amount) closingBalances, + currencyFk + FROM ( + SELECT p.supplierFk, p.companyFk, IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa) AS amount, p.dueDated < vStartingDate isBeforeStarting, p.currencyFk - FROM payment p - WHERE p.received > vStartDate - AND p.companyFk = vSelf - UNION ALL - SELECT r.supplierFk, + FROM payment p + WHERE p.received > vStartDate + AND p.companyFk = vSelf + UNION ALL + SELECT r.supplierFk, r.companyFk, - IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue) AS Total, rv.dueDated < vStartingDate isBeforeStarting, - r.currencyFk - FROM invoiceIn r - INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk - WHERE r.issued > vStartDate - AND r.isBooked - AND r.companyFk = vSelf - ) sub GROUP BY companyFk, supplierFk, currencyFk; + r.currencyFk + FROM invoiceIn r + INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk + WHERE r.issued > vStartDate + AND r.isBooked + AND r.companyFk = vSelf + ) sub GROUP BY companyFk, supplierFk, currencyFk; - DROP TEMPORARY TABLE IF EXISTS tPendingDuedates; - CREATE TEMPORARY TABLE tPendingDuedates ( - id INT auto_increment, + DROP TEMPORARY TABLE IF EXISTS tPendingDuedates; + CREATE TEMPORARY TABLE tPendingDuedates ( + id INT auto_increment, expirationId INT, - dated DATE, - supplierFk INT NOT NULL, - companyFk INT NOT NULL, - amount DECIMAL(10, 2) NOT NULL, - currencyFk INT NOT NULL, - pending DECIMAL(10, 2) DEFAULT 0, - balance DECIMAL(10, 2) DEFAULT 0, - endingBalance DECIMAL(10, 2) DEFAULT 0, - isPayment BOOLEAN, - isReconciled BOOLEAN, - PRIMARY KEY (id), - INDEX (supplierFk, companyFk, currencyFk) - ) ENGINE = MEMORY; + dated DATE, + supplierFk INT NOT NULL, + companyFk INT NOT NULL, + amount DECIMAL(10, 2) NOT NULL, + currencyFk INT NOT NULL, + pending DECIMAL(10, 2) DEFAULT 0, + balance DECIMAL(10, 2) DEFAULT 0, + endingBalance DECIMAL(10, 2) DEFAULT 0, + isPayment BOOLEAN, + isReconciled BOOLEAN, + PRIMARY KEY (id), + INDEX (supplierFk, companyFk, currencyFk) + ) ENGINE = MEMORY; - INSERT INTO tPendingDuedates ( - expirationId, - dated, - supplierFk, - companyFk, - amount, - currencyFk, - isPayment, - isReconciled - )SELECT p.id, + INSERT INTO tPendingDuedates ( + expirationId, + dated, + supplierFk, + companyFk, + amount, + currencyFk, + isPayment, + isReconciled + )SELECT p.id, p.dueDated, p.supplierFk, p.companyFk, @@ -100,80 +100,80 @@ BEGIN -IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue), r.currencyFk, FALSE isPayment, - TRUE - FROM invoiceIn r + TRUE + FROM invoiceIn r LEFT JOIN tOpeningBalances si ON r.companyFk = si.companyFk AND r.supplierFk = si.supplierFk - AND r.currencyFk = si.currencyFk + AND r.currencyFk = si.currencyFk JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk WHERE rv.dueDated >= vStartingDate AND (si.closingBalances IS NULL OR si.closingBalances <> 0) AND r.isBooked AND r.companyFk = vSelf ORDER BY supplierFk, companyFk, companyFk, dueDated, isPayment DESC, id; - -- Now, we calculate the outstanding amount for each receipt in descending order - SET @risk := 0.0; - SET @supplier := 0.0; - SET @company := 0.0; - SET @moneda := 0.0; - SET @pending := 0.0; - SET @day := util.VN_CURDATE(); + -- Now, we calculate the outstanding amount for each receipt in descending order + SET @risk := 0.0; + SET @supplier := 0.0; + SET @company := 0.0; + SET @moneda := 0.0; + SET @pending := 0.0; + SET @day := util.VN_CURDATE(); - UPDATE tPendingDuedates vp - LEFT JOIN tOpeningBalances si ON vp.companyFk = si.companyFk - AND vp.supplierFk = si.supplierFk - AND vp.currencyFk = si.currencyFk - SET vp.balance = @risk := ( - IF ( - @company <> vp.companyFk - OR @supplier <> vp.supplierFk - OR @moneda <> vp.currencyFk, - IFNULL(si.openingBalances, 0), - @risk - ) + - vp.amount - ), - -- if there is a change of company or supplier or currency, the balance is reset - vp.pending = @pending := IF ( - @company <> vp.companyFk - OR @supplier <> vp.supplierFk - OR @moneda <> vp.currencyFk - OR @day <> vp.dated, - vp.amount * (NOT vp.isPayment), - @pending + vp.amount - ), - vp.companyFk = @company := vp.companyFk, - vp.supplierFk = @supplier := vp.supplierFk, - vp.currencyFk = @moneda := vp.currencyFk, - vp.dated = @day := vp.dated, - vp.balance = @risk, - vp.pending = @pending; + UPDATE tPendingDuedates vp + LEFT JOIN tOpeningBalances si ON vp.companyFk = si.companyFk + AND vp.supplierFk = si.supplierFk + AND vp.currencyFk = si.currencyFk + SET vp.balance = @risk := ( + IF ( + @company <> vp.companyFk + OR @supplier <> vp.supplierFk + OR @moneda <> vp.currencyFk, + IFNULL(si.openingBalances, 0), + @risk + ) + + vp.amount + ), + -- if there is a change of company or supplier or currency, the balance is reset + vp.pending = @pending := IF ( + @company <> vp.companyFk + OR @supplier <> vp.supplierFk + OR @moneda <> vp.currencyFk + OR @day <> vp.dated, + vp.amount * (NOT vp.isPayment), + @pending + vp.amount + ), + vp.companyFk = @company := vp.companyFk, + vp.supplierFk = @supplier := vp.supplierFk, + vp.currencyFk = @moneda := vp.currencyFk, + vp.dated = @day := vp.dated, + vp.balance = @risk, + vp.pending = @pending; - CREATE OR REPLACE TEMPORARY TABLE tRowsToDelete ENGINE = MEMORY - SELECT expirationId, - dated, - supplierFk, - companyFk, - currencyFk, - balance - FROM tPendingDuedates - WHERE balance < vInvalidBalances - AND balance > - vInvalidBalances; - - DELETE vp.* - FROM tPendingDuedates vp - JOIN tRowsToDelete rd ON ( - vp.dated < rd.dated - OR (vp.dated = rd.dated AND vp.expirationId <= rd.expirationId) - ) - AND vp.supplierFk = rd.supplierFk - AND vp.companyFk = rd.companyFk - AND vp.currencyFk = rd.currencyFk - WHERE vp.isPayment = FALSE; + CREATE OR REPLACE TEMPORARY TABLE tRowsToDelete ENGINE = MEMORY + SELECT expirationId, + dated, + supplierFk, + companyFk, + currencyFk, + balance + FROM tPendingDuedates + WHERE balance < vInvalidBalances + AND balance > - vInvalidBalances; - SELECT vp.expirationId, - vp.dated, - vp.supplierFk, + DELETE vp.* + FROM tPendingDuedates vp + JOIN tRowsToDelete rd ON ( + vp.dated < rd.dated + OR (vp.dated = rd.dated AND vp.expirationId <= rd.expirationId) + ) + AND vp.supplierFk = rd.supplierFk + AND vp.companyFk = rd.companyFk + AND vp.currencyFk = rd.currencyFk + WHERE vp.isPayment = FALSE; + + SELECT vp.expirationId, + vp.dated, + vp.supplierFk, vp.companyFk, vp.currencyFk, vp.amount, @@ -183,15 +183,19 @@ BEGIN vp.isPayment, vp.isReconciled, vp.endingBalance, - cr.amount clientRiskAmount - FROM tPendingDuedates vp - LEFT JOIN supplier s ON s.id = vp.supplierFk - LEFT JOIN client c ON c.fi = s.nif - LEFT JOIN clientRisk cr ON cr.clientFk = c.id - AND cr.companyFk = vp.companyFk; - - DROP TEMPORARY TABLE tOpeningBalances; - DROP TEMPORARY TABLE tPendingDuedates; - DROP TEMPORARY TABLE tRowsToDelete; + cr.amount clientRiskAmount, + co.CEE + FROM tPendingDuedates vp + LEFT JOIN supplier s ON s.id = vp.supplierFk + LEFT JOIN client c ON c.fi = s.nif + LEFT JOIN clientRisk cr ON cr.clientFk = c.id + LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id + LEFT JOIN bankEntity be ON be.id = sa.bankEntityFk + LEFT JOIN country co ON co.id = be.countryFk + AND cr.companyFk = vp.companyFk; + + DROP TEMPORARY TABLE tOpeningBalances; + DROP TEMPORARY TABLE tPendingDuedates; + DROP TEMPORARY TABLE tRowsToDelete; END$$ DELIMITER ; From 04117d2c277fa9ac9b6fc1e59433962579d1e284 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 10:13:10 +0100 Subject: [PATCH 13/51] fix: #7013 quito vn. --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index 4a54c0f7f..60c272a02 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -34,7 +34,7 @@ BEGIN LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.Id_Cliente JOIN client c ON c.id = ci.Id_Cliente JOIN bs.clientAnnualConsumption cac ON c.id = cac.clientFk - JOIN vn.country c2 ON c2.id = c.countryFk + JOIN country c2 ON c2.id = c.countryFk GROUP BY c.id; DROP TEMPORARY TABLE IF EXISTS tmp.risk; From dc5f588c8e22799f989d088e8824f9e5336c5cd4 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 26 Mar 2024 10:13:57 +0100 Subject: [PATCH 14/51] refs #3520 feat: backWarehouse in Salix --- .../ticket-collection/getUncheckedTicket.js | 35 +++++++++++++++++++ .../ticket/back/models/ticket-collection.js | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js create mode 100644 modules/ticket/back/models/ticket-collection.js diff --git a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js new file mode 100644 index 000000000..64a4c563c --- /dev/null +++ b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js @@ -0,0 +1,35 @@ +module.exports = Self => { + Self.remoteMethod('getUncheckedTicket', { + description: + 'Get boolean if the collection of ticket has a ticket not checked', + accessType: 'READ', + accepts: [{ + arg: 'ticketFk', + type: 'int', + required: true, + description: 'Ticket id' + }], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/getUncheckedTicket`, + verb: 'GET' + } + }); + + Self.getUncheckedTicket = async ticketFk => { + const result = await Self.rawSql(` + SELECT tc2.ticketFk + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk + LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk + JOIN vn.state s ON s.id = ts.stateFk + JOIN vn.state s2 ON s2.code = 'CHECKED' + WHERE tc.ticketFk = ? AND s.order < s2.id + LIMIT 1;`, + [ticketFk]); + return result.length > 0 && result[0]['ticketFk'] > 0; + }; +}; diff --git a/modules/ticket/back/models/ticket-collection.js b/modules/ticket/back/models/ticket-collection.js new file mode 100644 index 000000000..55920f2a2 --- /dev/null +++ b/modules/ticket/back/models/ticket-collection.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/ticket-collection/getUncheckedTicket')(Self); +}; From caf99a97382a8bdfa9b8ac9044f67ddc31e91c52 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 26 Mar 2024 11:06:14 +0100 Subject: [PATCH 15/51] refs #3520 feat:uncheckedTicket --- .../back/methods/ticket-collection/getUncheckedTicket.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js index 64a4c563c..9eead967d 100644 --- a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js @@ -19,7 +19,12 @@ module.exports = Self => { } }); - Self.getUncheckedTicket = async ticketFk => { + Self.getUncheckedTicket = async(ticketFk, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + const result = await Self.rawSql(` SELECT tc2.ticketFk FROM vn.ticketCollection tc @@ -29,7 +34,7 @@ module.exports = Self => { JOIN vn.state s2 ON s2.code = 'CHECKED' WHERE tc.ticketFk = ? AND s.order < s2.id LIMIT 1;`, - [ticketFk]); + [ticketFk], myOptions); return result.length > 0 && result[0]['ticketFk'] > 0; }; }; From c99de95b3355f81d0e15e7e0b3814c83fadc02b5 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 12:07:23 +0100 Subject: [PATCH 16/51] feat: #7120 con tabla temporal --- db/routines/vn/functions/getSpecialPrice.sql | 8 +++-- .../procedures/catalog_componentCalculate.sql | 32 +++++++++++-------- .../10970-bronzeGerbera/00-specialPrice.sql | 7 ++++ 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 db/versions/10970-bronzeGerbera/00-specialPrice.sql diff --git a/db/routines/vn/functions/getSpecialPrice.sql b/db/routines/vn/functions/getSpecialPrice.sql index c2c1878eb..2cc5f2b99 100644 --- a/db/routines/vn/functions/getSpecialPrice.sql +++ b/db/routines/vn/functions/getSpecialPrice.sql @@ -13,9 +13,11 @@ BEGIN SELECT `value` INTO price FROM vn.specialPrice - WHERE itemFk = vItemFk - AND (clientFk = vClientFk OR clientFk IS NULL) - AND util.VN_CURDATE() BETWEEN started AND ended; + WHERE itemFk = vItemFk + AND (clientFk = vClientFk OR clientFk IS NULL) + AND started <= util.VN_CURDATE() + AND (ended >= util.VN_CURDATE() OR ended IS NULL) + ORDER BY id DESC LIMIT 1; RETURN price; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql index 76fbadd61..1af0ff9eb 100644 --- a/db/routines/vn/procedures/catalog_componentCalculate.sql +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -25,6 +25,19 @@ BEGIN FROM address WHERE id = vAddressFk; + 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; + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate (PRIMARY KEY (itemFk, warehouseFk)) ENGINE = MEMORY @@ -44,9 +57,7 @@ BEGIN JOIN item i ON i.id = tl.itemFk JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN specialPrice sp ON sp.itemFk = i.id - AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) - AND vShipped BETWEEN sp.started AND sp.ended + LEFT JOIN tSpecialPrice sp ON sp.itemFk = i.id LEFT JOIN ( SELECT * FROM ( SELECT pf.itemFk, @@ -147,9 +158,7 @@ BEGIN FROM tmp.ticketComponentBase tcb JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount' JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk - LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk - AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) - AND vShipped BETWEEN sp.started AND sp.ended + LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk JOIN vn.item i ON i.id = tcb.itemFk WHERE sp.value IS NULL AND i.supplyResponseFk IS NULL; @@ -172,9 +181,7 @@ BEGIN FROM tmp.ticketComponentCalculate tcc JOIN vn.component c2 ON c2.code = 'salePerPackage' JOIN buy b ON b.id = tcc.buyFk - LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk - AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) - AND vShipped BETWEEN sp.started AND sp.ended + LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk WHERE sp.value IS NULL; CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id)) @@ -213,9 +220,7 @@ BEGIN sp.value - SUM(tcc.cost) sumCost FROM tmp.ticketComponentCopy tcc JOIN component c ON c.id = tcc.componentFk - JOIN specialPrice sp ON sp.itemFk = tcc.itemFk - AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL) - AND vShipped BETWEEN sp.started AND sp.ended + JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk JOIN vn.component c2 ON c2.code = 'specialPrices' WHERE c.classRate IS NULL AND tcc.warehouseFk = vWarehouseFk @@ -296,6 +301,7 @@ BEGIN tmp.ticketComponentSum, tmp.ticketComponentBase, tmp.ticketComponentRate, - tmp.ticketComponentCopy; + tmp.ticketComponentCopy, + tSpecialPrice; END$$ DELIMITER ; diff --git a/db/versions/10970-bronzeGerbera/00-specialPrice.sql b/db/versions/10970-bronzeGerbera/00-specialPrice.sql new file mode 100644 index 000000000..db582082d --- /dev/null +++ b/db/versions/10970-bronzeGerbera/00-specialPrice.sql @@ -0,0 +1,7 @@ +ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) DEFAULT 0 NULL; +ALTER TABLE vn.specialPrice ADD started date NOT NULL; +ALTER TABLE vn.specialPrice ADD ended date NULL; + +ALTER TABLE `specialPrice` + ADD CONSTRAINT `check_date_range` + CHECK (`ended` IS NULL OR `ended` >= `started`); From 587dd8f4d9ec4156831a7493abf42d9213e8d348 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 12:12:27 +0100 Subject: [PATCH 17/51] feat: #7013 sin tabular --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index 60c272a02..16d96f577 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -1,10 +1,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`() BEGIN - /** - * Devuelve el riesgo de los clientes que estan asegurados - * - */ +/** +* Devuelve el riesgo de los clientes que estan asegurados +*/ CREATE OR REPLACE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY From 57c42b68087a4d748ebe087503899ed4c2d1f232 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 12:16:03 +0100 Subject: [PATCH 18/51] =?UTF-8?q?feat:=20#7117=20a=C3=B1ado=20NOT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/routines/vn/procedures/company_getSuppliersDebt.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/company_getSuppliersDebt.sql b/db/routines/vn/procedures/company_getSuppliersDebt.sql index 5354ef09d..f4814abcc 100644 --- a/db/routines/vn/procedures/company_getSuppliersDebt.sql +++ b/db/routines/vn/procedures/company_getSuppliersDebt.sql @@ -169,7 +169,7 @@ BEGIN AND vp.supplierFk = rd.supplierFk AND vp.companyFk = rd.companyFk AND vp.currencyFk = rd.currencyFk - WHERE vp.isPayment = FALSE; + WHERE NOT vp.isPayment; SELECT vp.expirationId, vp.dated, From 9408b82874b415b834ff6ee667195e688824bb94 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 12:18:53 +0100 Subject: [PATCH 19/51] feat: #7120 con esquema --- db/versions/10970-bronzeGerbera/00-specialPrice.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10970-bronzeGerbera/00-specialPrice.sql b/db/versions/10970-bronzeGerbera/00-specialPrice.sql index db582082d..a4439a74f 100644 --- a/db/versions/10970-bronzeGerbera/00-specialPrice.sql +++ b/db/versions/10970-bronzeGerbera/00-specialPrice.sql @@ -2,6 +2,6 @@ ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) DEFAULT 0 NULL; ALTER TABLE vn.specialPrice ADD started date NOT NULL; ALTER TABLE vn.specialPrice ADD ended date NULL; -ALTER TABLE `specialPrice` +ALTER TABLE vn.`specialPrice` ADD CONSTRAINT `check_date_range` CHECK (`ended` IS NULL OR `ended` >= `started`); From b805a5de0a0cb4d3d6a1b64fff2864d7707eb4c2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 26 Mar 2024 12:40:44 +0100 Subject: [PATCH 20/51] refs #3520 feat:uncheckedTicket --- ...checkedTicket.js => hasUncheckedTicket.js} | 4 +-- .../spec/hasUncheckedTicket.spec.js | 35 +++++++++++++++++++ .../ticket/back/models/ticket-collection.js | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) rename modules/ticket/back/methods/ticket-collection/{getUncheckedTicket.js => hasUncheckedTicket.js} (93%) create mode 100644 modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js diff --git a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js similarity index 93% rename from modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js rename to modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index 9eead967d..1c5174969 100644 --- a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('getUncheckedTicket', { + Self.remoteMethod('hasUncheckedTicket', { description: 'Get boolean if the collection of ticket has a ticket not checked', accessType: 'READ', @@ -14,7 +14,7 @@ module.exports = Self => { root: true }, http: { - path: `/getUncheckedTicket`, + path: `/hasUncheckedTicket`, verb: 'GET' } }); diff --git a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js new file mode 100644 index 000000000..02db364b2 --- /dev/null +++ b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js @@ -0,0 +1,35 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('ticketCollection hasUncheckedTicket()', () => { + fit('should return false because there are not tickets not checked', async() => { + const ticketFk = 1; + const result = await models.TicketCollection.hasUncheckedTicket(ticketFk); + + expect(result).toBe(false); + }); + + it('should return true because there is a ticket not checked', async() => { + const ticketFk = 1; + + const tx = await models.TicketTracking.beginTransaction({}); + const myOptions = {transaction: tx}; + const filter = {where: { + ticketFk: 1, + stateFk: 16} + }; + try { + const ticketTracking = await models.TicketTracking.findOne(filter, myOptions); + await ticketTracking.updateAttributes({ + stateFk: 7 + }); + const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions); + + expect(result).toBe(true); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/models/ticket-collection.js b/modules/ticket/back/models/ticket-collection.js index 55920f2a2..c5cd75a94 100644 --- a/modules/ticket/back/models/ticket-collection.js +++ b/modules/ticket/back/models/ticket-collection.js @@ -1,3 +1,3 @@ module.exports = Self => { - require('../methods/ticket-collection/getUncheckedTicket')(Self); + require('../methods/ticket-collection/hasUncheckedTicket')(Self); }; From 6ded14b593b0fa378b99b65512d022c7397f240f Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 26 Mar 2024 14:25:25 +0100 Subject: [PATCH 21/51] feat: refs #7002 update direction if it was not manual --- .../worker-time-control/updateTimeEntry.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index e86834502..bbe8fd0fe 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -41,26 +41,24 @@ module.exports = Self => { } try { - const timeEntry = await Self.findById(timeEntryId, null, myOptions); - const isSubordinate = await models.Worker.isSubordinate(ctx, timeEntry.userFk, myOptions); + const {id, userFk, timed, manual} = await Self.findById(timeEntryId, null, myOptions); + const isSubordinate = await models.Worker.isSubordinate(ctx, userFk, myOptions); const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE'); - const isHimself = currentUserId == timeEntry.userFk; + const isHimself = currentUserId == userFk; const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss); if (notAllowed) throw new UserError(`You don't have enough privileges`); - let timeEntryUpdatedId; - if (timeEntry.device) { - timeEntry.updateAttribute('direction', direction); - timeEntryUpdatedId = timeEntry.id; - } else { - await models.WorkerTimeControl.deleteById(timeEntry.id, myOptions); - timeEntryUpdatedId = await Self.clockIn(timeEntry.userFk, timeEntry.timed, direction, null, myOptions); - } + await models.WorkerTimeControl.deleteById(id, myOptions); + const {id: newTimeEntryId} = await Self.clockIn( + userFk, timed, direction, null, myOptions + ); + + if (!manual) await Self.updateAll({id: newTimeEntryId}, {manual: false}, myOptions); + await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions); - await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, timeEntry.userFk, timeEntry.timed, myOptions); if (tx) await tx.commit(); - return timeEntryUpdatedId; + return newTimeEntryId; } catch (e) { if (tx) await tx.rollback(); throw e; From 861d9b3135cf52964b5bf21d73e6bb99caa28835 Mon Sep 17 00:00:00 2001 From: Pako Date: Tue, 26 Mar 2024 14:59:06 +0100 Subject: [PATCH 22/51] javi's proposals --- .../vn/procedures/boxPicking_print.sql | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/boxPicking_print.sql b/db/routines/vn/procedures/boxPicking_print.sql index 0d34ed056..637fde2b9 100644 --- a/db/routines/vn/procedures/boxPicking_print.sql +++ b/db/routines/vn/procedures/boxPicking_print.sql @@ -1,8 +1,6 @@ -DROP PROCEDURE IF EXISTS vn.boxPicking_print; - DELIMITER $$ $$ -CREATE PROCEDURE vn.boxPicking_print( +CREATE OR REPLACE PROCEDURE vn.sale_boxPickingPrint( IN vPrinterFk INT, IN vSaleFk INT, IN vPacking INT, @@ -12,10 +10,9 @@ CREATE PROCEDURE vn.boxPicking_print( IN vPackingSiteFk INT) BEGIN /** Splits a line of sale to a different ticket and prints the transport sticker - * */ DECLARE vAgencyModeFk INT; - DECLARE vConcept VARCHAR(20); + DECLARE vConcept VARCHAR(30); DECLARE vExpeditionFk INT; DECLARE vItemFk INT; DECLARE vItemShelvingFk INT; @@ -64,7 +61,7 @@ BEGIN w1: WHILE vQuantity >= vPacking DO - SET vItemShelvingFk = 0; + SET vItemShelvingFk = NULL; SELECT sub.id INTO vItemShelvingFk @@ -103,7 +100,7 @@ w1: WHILE vQuantity >= vPacking DO LEAVE w1; END IF; - SET vNewTicketFk = 0; + SET vNewTicketFk = NULL; SELECT MAX(t.id) INTO vNewTicketFk FROM vn.ticket t @@ -117,7 +114,7 @@ w1: WHILE vQuantity >= vPacking DO AND t.warehouseFk = tt.warehouseFk WHERE tls.name = 'Encajado' ; - IF vNewTicketFk = 0 THEN + IF ISNULL(vNewTicketFk) THEN INSERT INTO vn.ticket( clientFk, shipped, addressFk, @@ -163,7 +160,7 @@ w1: WHILE vQuantity >= vPacking DO UPDATE itemShelving SET visible = visible - vPacking WHERE id = vItemShelvingFk; - SET vNewSaleFk = 0; + SET vNewSaleFk = NULL; SELECT MAX(id) INTO vNewSaleFk FROM sale @@ -175,7 +172,7 @@ w1: WHILE vQuantity >= vPacking DO SET quantity = quantity + vPacking WHERE id = vNewSaleFk; - SET vItemShelvingSaleFk_old = 0; + SET vItemShelvingSaleFk_old = NULL; SELECT MAX(id) INTO vItemShelvingSaleFk_old FROM vn.itemShelvingSale @@ -245,8 +242,8 @@ w1: WHILE vQuantity >= vPacking DO h.code, vPackingSiteFk, ps.monitorId, - started = IFNULL(vLastExpeditionTimeStamp, Now()), - ended = Now() + IFNULL(vLastExpeditionTimeStamp, Now()), + Now() FROM packingSite ps JOIN host h ON h.id = ps.hostFk JOIN item i ON i.name = 'Shipping cost' @@ -266,15 +263,15 @@ w1: WHILE vQuantity >= vPacking DO JOIN parking p ON p.id = sh.parkingFk WHERE ish.id = vItemShelvingFk; - UPDATE dipole.expedition_PrintOut SET - isPrinted = FALSE, - itemFk = vItemFk, - quantity = vPacking, - longName = vConcept, - shelvingFk = vShelving, - parkingCode = vParkingCode, - phone = RIGHT(phone,vMaxPhoneLength), - street = RIGHT(street, vMAxStreetLength) + UPDATE dipole.expedition_PrintOut + SET isPrinted = FALSE, + itemFk = vItemFk, + quantity = vPacking, + longName = vConcept, + shelvingFk = vShelving, + parkingCode = vParkingCode, + phone = RIGHT(phone,vMaxPhoneLength), + street = RIGHT(street, vMAxStreetLength) WHERE expeditionFk = vExpeditionFk; DELETE FROM vn.sale From 8e2770aa565c647c4a2720384e0f04524fcff0c5 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 26 Mar 2024 16:27:49 +0100 Subject: [PATCH 23/51] feat: refs #7141 --- db/routines/vn/procedures/sale_replaceItem.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_replaceItem.sql b/db/routines/vn/procedures/sale_replaceItem.sql index 79997d989..51c6f6c08 100644 --- a/db/routines/vn/procedures/sale_replaceItem.sql +++ b/db/routines/vn/procedures/sale_replaceItem.sql @@ -78,7 +78,8 @@ BEGIN SELECT price INTO vNewPrice FROM tmp.ticketComponentPrice - WHERE (vQuantity % `grouping` = 0); + ORDER BY (vQuantity % `grouping`) ASC + LIMIT 1; IF vNewPrice IS NULL THEN CALL util.throw('price retrieval failed'); From 2881409b1e8c2100de2f6e747365b248d2583dff Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 27 Mar 2024 07:19:51 +0100 Subject: [PATCH 24/51] feat: #7120 con fecha por defecto --- db/versions/10970-bronzeGerbera/00-specialPrice.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/versions/10970-bronzeGerbera/00-specialPrice.sql b/db/versions/10970-bronzeGerbera/00-specialPrice.sql index a4439a74f..e2e46fb1f 100644 --- a/db/versions/10970-bronzeGerbera/00-specialPrice.sql +++ b/db/versions/10970-bronzeGerbera/00-specialPrice.sql @@ -1,6 +1,9 @@ -ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) DEFAULT 0 NULL; -ALTER TABLE vn.specialPrice ADD started date NOT NULL; +ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) NULL; +ALTER TABLE vn.specialPrice ADD started date NOT NULL DEFAULT '2024-01-01'; ALTER TABLE vn.specialPrice ADD ended date NULL; +ALTER TABLE vn.specialPrice MODIFY COLUMN itemFk int(11) NOT NULL; +ALTER TABLE vn.specialPrice MODIFY COLUMN value DECIMAL(10,2) NOT NULL; + ALTER TABLE vn.`specialPrice` ADD CONSTRAINT `check_date_range` From 39b1e9ff7bc77c68f57ca957e7c9c72879fb5740 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 07:26:11 +0100 Subject: [PATCH 25/51] refs #3520 hasUncheckedTicket --- .../back/methods/ticket-collection/hasUncheckedTicket.js | 2 +- .../ticket-collection/spec/hasUncheckedTicket.spec.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index 1c5174969..dc4da2ae6 100644 --- a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -19,7 +19,7 @@ module.exports = Self => { } }); - Self.getUncheckedTicket = async(ticketFk, options) => { + Self.hasUncheckedTicket = async(ticketFk, options) => { const myOptions = {}; if (typeof options == 'object') diff --git a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js index 02db364b2..9f88b9f0b 100644 --- a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js +++ b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js @@ -2,7 +2,7 @@ const {models} = require('vn-loopback/server/server'); describe('ticketCollection hasUncheckedTicket()', () => { - fit('should return false because there are not tickets not checked', async() => { + it('should return false because there are not tickets not checked', async() => { const ticketFk = 1; const result = await models.TicketCollection.hasUncheckedTicket(ticketFk); @@ -11,17 +11,19 @@ describe('ticketCollection hasUncheckedTicket()', () => { it('should return true because there is a ticket not checked', async() => { const ticketFk = 1; + const stateFkCurrent = 16; + const stateFkUpdated = 7; const tx = await models.TicketTracking.beginTransaction({}); const myOptions = {transaction: tx}; const filter = {where: { ticketFk: 1, - stateFk: 16} + stateFk: stateFkCurrent} }; try { const ticketTracking = await models.TicketTracking.findOne(filter, myOptions); await ticketTracking.updateAttributes({ - stateFk: 7 + stateFk: stateFkUpdated }); const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions); From a983f25c57f05020e965fb597cb4f724015fa140 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 07:47:36 +0100 Subject: [PATCH 26/51] refs #3520 hasUncheckedTicket --- .../ticket/back/methods/ticket-collection/hasUncheckedTicket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index dc4da2ae6..6c8df250a 100644 --- a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -5,7 +5,7 @@ module.exports = Self => { accessType: 'READ', accepts: [{ arg: 'ticketFk', - type: 'int', + type: 'integer', required: true, description: 'Ticket id' }], From 2cf572baf874850175ace84f2c27331bfb751ac2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 07:48:16 +0100 Subject: [PATCH 27/51] refs #3520 hasUncheckedTicket --- .../ticket-collection/hasUncheckedTicket.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index 6c8df250a..1ea522de6 100644 --- a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -27,13 +27,13 @@ module.exports = Self => { const result = await Self.rawSql(` SELECT tc2.ticketFk - FROM vn.ticketCollection tc - JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk - LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk - JOIN vn.state s ON s.id = ts.stateFk - JOIN vn.state s2 ON s2.code = 'CHECKED' - WHERE tc.ticketFk = ? AND s.order < s2.id - LIMIT 1;`, + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk + LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk + JOIN vn.state s ON s.id = ts.stateFk + JOIN vn.state s2 ON s2.code = 'CHECKED' + WHERE tc.ticketFk = ? AND s.order < s2.id + LIMIT 1;`, [ticketFk], myOptions); return result.length > 0 && result[0]['ticketFk'] > 0; }; From 4b41ac68aa71ea5b39b1197ad08ae99ed19cbde4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 27 Mar 2024 08:05:33 +0100 Subject: [PATCH 28/51] feat: #7013 en mayusculas y con espacio en comentarios --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index 16d96f577..8028dc5fb 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -2,8 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`() BEGIN /** -* Devuelve el riesgo de los clientes que estan asegurados -*/ + * Devuelve el riesgo de los clientes que estan asegurados + */ CREATE OR REPLACE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY @@ -23,8 +23,8 @@ BEGIN c.name, c.credit clientCredit, c.creditInsurance solunion, - cast(r.risk as DECIMAL(10,0)) risk, - cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, + CAST(r.risk AS DECIMAL(10,0)) risk, + CAST(c.creditInsurance - r.risk AS DECIMAL(10,0)) riskAlive, cac.invoiced billedAnnually, c.dueDay, ci.grade, From fe0a1ad7be715f68de833ddd80d85e10da47ed6c Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 27 Mar 2024 08:12:05 +0100 Subject: [PATCH 29/51] feat: #7013 purge productionError --- db/routines/vn/procedures/clean.sql | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/clean.sql b/db/routines/vn/procedures/clean.sql index 5ffb03f6d..ed1569935 100644 --- a/db/routines/vn/procedures/clean.sql +++ b/db/routines/vn/procedures/clean.sql @@ -12,7 +12,7 @@ BEGIN DECLARE v1Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; DECLARE v2Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; DECLARE v4Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; - DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR; + DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR; DECLARE vTrashId VARCHAR(15); DECLARE vCompanyBlk INT; @@ -30,8 +30,9 @@ BEGIN DELETE IGNORE FROM expedition WHERE created < v26Months; DELETE FROM sms WHERE created < v18Months; DELETE FROM saleTracking WHERE created < v1Years; + DELETE FROM productionError WHERE dated < v1Years; DELETE FROM ticketTracking WHERE created < v18Months; - DELETE tobs FROM ticketObservation tobs + DELETE tobs FROM ticketObservation tobs JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < v5Years; DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < v1Years; @@ -113,12 +114,12 @@ BEGIN FROM travel t LEFT JOIN entry e ON e.travelFk = t.id WHERE t.shipped < v3Months AND e.travelFk IS NULL; - + UPDATE dms d - JOIN dmsType dt ON dt.id = d.dmsTypeFk - SET d.dmsTypeFk = vTrashId + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId WHERE created < util.VN_CURDATE() - INTERVAL dt.monthToDelete MONTH; - + -- borrar entradas sin compras CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete SELECT e.* @@ -136,7 +137,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tRouteToDelete SELECT * FROM route r - WHERE created < v4Years; + WHERE created < v4Years; UPDATE tRouteToDelete tmp JOIN dms d ON d.id = tmp.gestdocFk @@ -180,7 +181,7 @@ BEGIN DELETE FROM mail WHERE creationDate < v2Months; DELETE FROM split WHERE dated < v18Months; DELETE FROM remittance WHERE dated < v18Months; - + CREATE OR REPLACE TEMPORARY TABLE tTicketDelete SELECT DISTINCT tl.originFk ticketFk FROM ticketLog tl @@ -189,11 +190,11 @@ BEGIN FROM ticket t JOIN ticketLog tl ON tl.originFk = t.id LEFT JOIN ticketWeekly tw ON tw.ticketFk = t.id - WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' + WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' AND t.isDeleted AND tw.ticketFk IS NULL GROUP BY t.id - ) sub ON sub.ids = tl.id + ) sub ON sub.ids = tl.id WHERE tl.creationDate <= v2Months; DELETE t FROM ticket t From b532ce3f77b03b21f533035660b1abd959f68b31 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 27 Mar 2024 08:30:45 +0100 Subject: [PATCH 30/51] hotFix: recreate addressTaxArea --- db/routines/vn/functions/addressTaxArea.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/routines/vn/functions/addressTaxArea.sql b/db/routines/vn/functions/addressTaxArea.sql index 3586dd4ce..1d4e9e2f0 100644 --- a/db/routines/vn/functions/addressTaxArea.sql +++ b/db/routines/vn/functions/addressTaxArea.sql @@ -20,6 +20,7 @@ BEGIN CALL vn.addressTaxArea(); SELECT areaFk INTO vTaxArea FROM tmp.addressTaxArea; + DROP TEMPORARY TABLE tmp.addressCompany, tmp.addressTaxArea; From 483345666ed9f09d54dc836c1512a11a20d31a34 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 11:01:32 +0100 Subject: [PATCH 31/51] refs #3520 feat:back WarehouseFk --- modules/ticket/back/models/ticket-collection.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/ticket/back/models/ticket-collection.json b/modules/ticket/back/models/ticket-collection.json index 4bd34f08e..bc1c2dd18 100644 --- a/modules/ticket/back/models/ticket-collection.json +++ b/modules/ticket/back/models/ticket-collection.json @@ -13,6 +13,9 @@ }, "usedShelves": { "type": "number" + }, + "collectionFk": { + "type": "number" } }, "relations": { @@ -20,6 +23,11 @@ "type": "belongsTo", "model": "Ticket", "foreignKey": "ticketFk" + }, + "collection": { + "type": "belongsTo", + "model": "Collection", + "foreignKey": "collectionFk" } } } \ No newline at end of file From c9431e605e12898230576414a036808c78d138e6 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 27 Mar 2024 12:22:22 +0100 Subject: [PATCH 32/51] second proposals --- .../vn/procedures/boxPicking_print.sql | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/db/routines/vn/procedures/boxPicking_print.sql b/db/routines/vn/procedures/boxPicking_print.sql index 637fde2b9..6c890a3fd 100644 --- a/db/routines/vn/procedures/boxPicking_print.sql +++ b/db/routines/vn/procedures/boxPicking_print.sql @@ -25,7 +25,7 @@ BEGIN DECLARE vNewTicketFk INT; DECLARE vParkingCode VARCHAR(10); DECLARE vQuantity INT; - DECLARE vRest INT DEFAULT 0; + DECLARE vRemainder INT DEFAULT 0; DECLARE vRestSaleFk INT; DECLARE vShelving VARCHAR(10); DECLARE vTicketFk INT; @@ -43,19 +43,19 @@ BEGIN FROM sale s WHERE s.id = vSaleFk; - IF vRest THEN - UPDATE sale SET quantity = quantity - vRest WHERE id = vSaleFk; + IF vRemainder THEN + UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk; - INSERT INTO vn.sale(ticketFk, itemFk, quantity, price, discount, concept) + INSERT INTO sale(ticketFk, itemFk, quantity, price, discount, concept) SELECT ticketFk, itemFk, vRest, price, discount, concept - FROM vn.sale + FROM sale WHERE id = vSaleFk; SET vRestSaleFk = LAST_INSERT_ID(); - INSERT INTO vn.saleComponent(saleFk, componentFk, value) + INSERT INTO saleComponent(saleFk, componentFk, value) SELECT vRestSaleFk, componentFk, value - FROM vn.saleComponent + FROM saleComponent WHERE saleFk = vSaleFk; END IF; @@ -65,16 +65,16 @@ w1: WHILE vQuantity >= vPacking DO SELECT sub.id INTO vItemShelvingFk - FROM vn.productionConfig pc + FROM productionConfig pc JOIN ( SELECT ish.id, - ish.visible - ifnull(SUM(iss.quantity),0) available, + ish.visible - IFNULL(SUM(iss.quantity),0) available, p.pickingOrder, ish.created - FROM vn.itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - LEFT JOIN vn.itemShelvingSale iss + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + LEFT JOIN itemShelvingSale iss ON iss.itemShelvingFk = ish.id AND iss.created >= CURDATE() AND iss.isPicked = FALSE @@ -86,7 +86,7 @@ w1: WHILE vQuantity >= vPacking DO LIMIT 1; IF vItemShelvingFk THEN - INSERT INTO vn.itemShelvingSale + INSERT INTO itemShelvingSale SET itemShelvingFk = vItemShelvingFk, saleFk = vSaleFk, quantity = vPacking, @@ -95,7 +95,7 @@ w1: WHILE vQuantity >= vPacking DO SET vItemShelvingSaleFk = LAST_INSERT_ID(); - UPDATE vn.sale SET isPicked = FALSE WHERE id = vSaleFk; + UPDATE sale SET isPicked = FALSE WHERE id = vSaleFk; ELSE LEAVE w1; END IF; @@ -103,10 +103,10 @@ w1: WHILE vQuantity >= vPacking DO SET vNewTicketFk = NULL; SELECT MAX(t.id) INTO vNewTicketFk - FROM vn.ticket t - JOIN vn.ticketLastState tls ON tls.ticketFk = t.id + FROM ticket t + JOIN ticketLastState tls ON tls.ticketFk = t.id JOIN (SELECT addressFk, clientFk, date(shipped) shipped, warehouseFk - FROM vn.ticket + FROM ticket WHERE id = vTicketFk) tt ON tt.addressFk = t.addressFk AND tt.clientFk = t.clientFk @@ -115,7 +115,7 @@ w1: WHILE vQuantity >= vPacking DO WHERE tls.name = 'Encajado' ; IF ISNULL(vNewTicketFk) THEN - INSERT INTO vn.ticket( clientFk, + INSERT INTO ticket( clientFk, shipped, addressFk, agencyModeFk, @@ -145,7 +145,7 @@ w1: WHILE vQuantity >= vPacking DO priority, hasPriority, id - FROM vn.ticket + FROM ticket WHERE id = vTicketFk; SET vNewTicketFk = LAST_INSERT_ID(); @@ -175,16 +175,16 @@ w1: WHILE vQuantity >= vPacking DO SET vItemShelvingSaleFk_old = NULL; SELECT MAX(id) INTO vItemShelvingSaleFk_old - FROM vn.itemShelvingSale + FROM itemShelvingSale WHERE itemShelvingFk = vItemShelvingFk AND saleFk = vNewSaleFk; IF vItemShelvingSaleFk_old THEN - UPDATE vn.itemShelvingSale + UPDATE itemShelvingSale SET quantity = quantity + vPacking WHERE id = vItemShelvingSaleFk_old; - DELETE FROM vn.itemShelvingSale + DELETE FROM itemShelvingSale WHERE id = vItemShelvingSaleFk; SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; @@ -194,16 +194,16 @@ w1: WHILE vQuantity >= vPacking DO WHERE id = vItemShelvingSaleFk; END IF; ELSE - INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, discount, price) + INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) SELECT vNewTicketFk, itemFk, concept, vPacking, discount, price - FROM vn.sale + FROM sale WHERE id = vSaleFk; SET vNewSaleFk = LAST_INSERT_ID(); - INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge) + INSERT INTO saleComponent(saleFk, componentFk, value, isGreuge) SELECT vNewSaleFk, componentFk, value, isGreuge - FROM vn.saleComponent + FROM saleComponent WHERE saleFk = vSaleFk; UPDATE itemShelvingSale @@ -211,16 +211,16 @@ w1: WHILE vQuantity >= vPacking DO WHERE id = vItemShelvingSaleFk; END IF; - INSERT IGNORE INTO vn.saleTracking(saleFk, isChecked, workerFk, stateFk) + INSERT IGNORE INTO saleTracking(saleFk, isChecked, workerFk, stateFk) SELECT vNewSaleFk, TRUE, vUserFk, id - FROM vn.state + FROM state WHERE code = 'PREPARED'; SELECT agencyModeFk INTO vAgencyModeFk FROM ticket WHERE id = vNewTicketFk; - INSERT INTO vn.expedition( + INSERT INTO expedition( agencyModeFk, ticketFk, freightItemFk, @@ -242,8 +242,8 @@ w1: WHILE vQuantity >= vPacking DO h.code, vPackingSiteFk, ps.monitorId, - IFNULL(vLastExpeditionTimeStamp, Now()), - Now() + IFNULL(vLastExpeditionTimeStamp, NOW()), + NOW() FROM packingSite ps JOIN host h ON h.id = ps.hostFk JOIN item i ON i.name = 'Shipping cost' @@ -252,7 +252,7 @@ w1: WHILE vQuantity >= vPacking DO SET vExpeditionFk = LAST_INSERT_ID(); - SET vLastExpeditionTimeStamp = Now(); + SET vLastExpeditionTimeStamp = NOW(); CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE); @@ -274,7 +274,7 @@ w1: WHILE vQuantity >= vPacking DO street = RIGHT(street, vMAxStreetLength) WHERE expeditionFk = vExpeditionFk; - DELETE FROM vn.sale + DELETE FROM sale WHERE quantity = 0 AND id = vSaleFk; END WHILE; From 09c9a3d7efd9a5e23c0a33c63bf9658856f9884c Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 27 Mar 2024 12:25:57 +0100 Subject: [PATCH 33/51] vRest --- db/routines/vn/procedures/boxPicking_print.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/boxPicking_print.sql b/db/routines/vn/procedures/boxPicking_print.sql index 6c890a3fd..5eea4ee1e 100644 --- a/db/routines/vn/procedures/boxPicking_print.sql +++ b/db/routines/vn/procedures/boxPicking_print.sql @@ -26,7 +26,7 @@ BEGIN DECLARE vParkingCode VARCHAR(10); DECLARE vQuantity INT; DECLARE vRemainder INT DEFAULT 0; - DECLARE vRestSaleFk INT; + DECLARE vRemainderSaleFk INT; DECLARE vShelving VARCHAR(10); DECLARE vTicketFk INT; @@ -36,7 +36,7 @@ BEGIN s.itemFk, s.concept INTO vQuantity, - vRest, + vRemainder, vTicketFk, vItemFk, vConcept @@ -47,14 +47,14 @@ BEGIN UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk; INSERT INTO sale(ticketFk, itemFk, quantity, price, discount, concept) - SELECT ticketFk, itemFk, vRest, price, discount, concept + SELECT ticketFk, itemFk, vRemainder, price, discount, concept FROM sale WHERE id = vSaleFk; - SET vRestSaleFk = LAST_INSERT_ID(); + SET vRemainderSaleFk = LAST_INSERT_ID(); INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT vRestSaleFk, componentFk, value + SELECT vRemainderSaleFk, componentFk, value FROM saleComponent WHERE saleFk = vSaleFk; END IF; From e7a29119d0ca53d37b6b9696eaf78d0d0ddb82da Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 27 Mar 2024 13:38:04 +0100 Subject: [PATCH 34/51] feat: refs #7002 add test --- .../worker-time-control/specs/clockIn.spec.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index 0ee439941..343eb2a71 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -71,6 +71,34 @@ describe('workerTimeControl clockIn()', () => { } }); + it('should updates the time entry direction and remaining not be manual', async() => { + activeCtx.accessToken.userId = HHRRId; + const workerId = teamBossId; + + const tx = await models.WorkerTimeControl.beginTransaction({}); + try { + const options = {transaction: tx}; + + const entryTime = "2000-12-25T11:00:00.000Z"; + ctx.args = {timed: entryTime, direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const middleTime ="2000-12-25T16:00:00.000Z"; + ctx.args = {timed: middleTime, direction: 'middle'}; + const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + middleEntryTime.updateAttribute('manual', false); + + const direction = 'out'; + const outTimeEntryId = await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options); + + const outTimeEntry = await models.WorkerTimeControl.findById(outTimeEntryId, null, options); + expect(outTimeEntry.manual).toBeFalsy(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + } + }); + describe('as Role errors', () => { it('should add if the current user is team boss and the target user is himself', async() => { activeCtx.accessToken.userId = teamBossId; @@ -144,7 +172,7 @@ describe('workerTimeControl clockIn()', () => { const middleTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); const direction = 'out'; - const {id:outTimeEntryId} = await models.WorkerTimeControl.updateTimeEntry( + const outTimeEntryId = await models.WorkerTimeControl.updateTimeEntry( ctx, middleTime.id, direction, options ); From 4ac418111ba2d63b32f58baa17d56868441d50dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 27 Mar 2024 14:12:34 +0100 Subject: [PATCH 35/51] fix: TRIGGER incorrecto en travel refs #7148 --- db/routines/vn/triggers/travel_afterUpdate.sql | 4 ---- db/routines/vn/triggers/travel_beforeUpdate.sql | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/triggers/travel_afterUpdate.sql b/db/routines/vn/triggers/travel_afterUpdate.sql index 7752505e3..38cd3ba13 100644 --- a/db/routines/vn/triggers/travel_afterUpdate.sql +++ b/db/routines/vn/triggers/travel_afterUpdate.sql @@ -23,9 +23,5 @@ BEGIN CALL buy_checkItem(); END IF; END IF; - - IF (NOT(NEW.awbFk <=> OLD.awbFk)) AND NEW.awbFk IS NOT NULL AND NOT travel_hasUniqueAwb(NEW.id) THEN - CALL util.throw('The AWB is incorrect, there is a different AWB in the associated entries'); - END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/travel_beforeUpdate.sql b/db/routines/vn/triggers/travel_beforeUpdate.sql index 7cc198e3c..5e43c8761 100644 --- a/db/routines/vn/triggers/travel_beforeUpdate.sql +++ b/db/routines/vn/triggers/travel_beforeUpdate.sql @@ -32,5 +32,9 @@ BEGIN CALL util.throw('The travel has entries with booked invoices'); END IF; END IF; + + IF (NOT(NEW.awbFk <=> OLD.awbFk)) AND NEW.awbFk IS NOT NULL AND NOT travel_hasUniqueAwb(NEW.id) THEN + CALL util.throw('The AWB is incorrect, there is a different AWB in the associated entries'); + END IF; END$$ DELIMITER ; From 97b2500eeafc560cb764d176680fc1a0095c6809 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 27 Mar 2024 14:24:58 +0100 Subject: [PATCH 36/51] refs #6074 fix comment --- db/versions/10964-silverDracena/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10964-silverDracena/00-firstScript.sql b/db/versions/10964-silverDracena/00-firstScript.sql index 400758cb2..dbc4ba8a0 100644 --- a/db/versions/10964-silverDracena/00-firstScript.sql +++ b/db/versions/10964-silverDracena/00-firstScript.sql @@ -1,2 +1,2 @@ -- Place your SQL code here -ALTER TABLE vn.entry CHANGE isBlocked isBlocked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Deprecado 21/03/2024'; +ALTER TABLE vn.entry CHANGE isBlocked isBlocked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT '@deprecated 27/03/2024'; From 5d5dc9583ace8dbfd65c75d03473eb0179597b61 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 27 Mar 2024 14:44:46 +0100 Subject: [PATCH 37/51] refs #6532 change url --- .../templates/email/buyer-week-waste/buyer-week-waste.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/print/templates/email/buyer-week-waste/buyer-week-waste.html b/print/templates/email/buyer-week-waste/buyer-week-waste.html index d8b7a622b..ecec9c215 100644 --- a/print/templates/email/buyer-week-waste/buyer-week-waste.html +++ b/print/templates/email/buyer-week-waste/buyer-week-waste.html @@ -28,10 +28,10 @@

- \ No newline at end of file + From 2a8256319f685c0810b098200a3af9770e4bade1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 27 Mar 2024 16:18:21 +0100 Subject: [PATCH 38/51] fix: #6085 Old db/changes directory removed --- db/changes/240404/00-revokeMailAliasAccount.sql | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 db/changes/240404/00-revokeMailAliasAccount.sql diff --git a/db/changes/240404/00-revokeMailAliasAccount.sql b/db/changes/240404/00-revokeMailAliasAccount.sql deleted file mode 100644 index a86de1f3c..000000000 --- a/db/changes/240404/00-revokeMailAliasAccount.sql +++ /dev/null @@ -1,5 +0,0 @@ -DELETE FROM salix.ACL - WHERE model = 'MailAliasAccount' - AND property = 'canEditAlias' - AND principalType = 'ROLE' - AND principalId = 'marketingBoss'; From d30cac971ff5c7ed91dd40dd34fc43ab7cb1aaea Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 28 Mar 2024 07:22:28 +0100 Subject: [PATCH 39/51] refs #6930 updates --- modules/invoiceOut/front/index/index.js | 5 +++-- modules/route/front/index/index.js | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js index 403c51d58..f109cd5b0 100644 --- a/modules/invoiceOut/front/index/index.js +++ b/modules/invoiceOut/front/index/index.js @@ -23,15 +23,16 @@ export default class Controller extends Section { } openPdf() { + const access_token = this.vnToken.tokenMultimedia; if (this.checked.length <= 1) { const [invoiceOutId] = this.checked; - const url = `api/InvoiceOuts/${invoiceOutId}/download?access_token=${this.vnToken.tokenMultimedia}`; + const url = `api/InvoiceOuts/${invoiceOutId}/download?access_token=${access_token}`; window.open(url, '_blank'); } else { const invoiceOutIds = this.checked; const invoicesIds = invoiceOutIds.join(','); const serializedParams = this.$httpParamSerializer({ - access_token: this.vnToken.token, + access_token, ids: invoicesIds }); const url = `api/InvoiceOuts/downloadZip?${serializedParams}`; diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 0c5dfe7f3..bb32e1f13 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -35,16 +35,18 @@ export default class Controller extends Section { showRouteReport() { const routesIds = []; + const access_token = this.vnToken.tokenMultimedia; + for (let route of this.checked) routesIds.push(route.id); const stringRoutesIds = routesIds.join(','); if (this.checked.length <= 1) { - const url = `api/Routes/${stringRoutesIds}/driver-route-pdf?access_token=${this.vnToken.tokenMultimedia}`; + const url = `api/Routes/${stringRoutesIds}/driver-route-pdf?access_token=${access_token}`; window.open(url, '_blank'); } else { const serializedParams = this.$httpParamSerializer({ - access_token: this.vnToken.token, + access_token, id: stringRoutesIds }); const url = `api/Routes/downloadZip?${serializedParams}`; From 8e6416d59c2f61e24fc553187e1ae550a410e478 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 28 Mar 2024 08:08:32 +0100 Subject: [PATCH 40/51] refs #3520 feat:uncheckedTicket --- .../methods/ticket-collection/spec/hasUncheckedTicket.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js index 9f88b9f0b..ae7a8e6ee 100644 --- a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js +++ b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js @@ -24,7 +24,7 @@ describe('ticketCollection hasUncheckedTicket()', () => { const ticketTracking = await models.TicketTracking.findOne(filter, myOptions); await ticketTracking.updateAttributes({ stateFk: stateFkUpdated - }); + }, myOptions); const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions); expect(result).toBe(true); @@ -35,3 +35,4 @@ describe('ticketCollection hasUncheckedTicket()', () => { } }); }); + From c1310ada918b98887d92211655f20aaecdccdcde Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Mar 2024 09:28:42 +0100 Subject: [PATCH 41/51] refs #7152 deploy: init version 24.16 --- CHANGELOG.md | 14 ++------------ package.json | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eed71921..c031a3874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,22 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [24.16.01] - 2024-04-18 + ## [2414.01] - 2024-04-04 -### Added - -### Changed - -### Fixed - ## [2408.01] - 2024-02-22 -### Added - -### Changed - -### Fixed - ## [2406.01] - 2024-02-08 ### Added diff --git a/package.json b/package.json index be209e737..39c5e15b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.14.0", + "version": "24.16.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From ed46ad03d29d2cc013512ef6ae80e0e259d850de Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Mar 2024 09:33:57 +0100 Subject: [PATCH 42/51] refs #7152 warmFix --- loopback/server/datasources.json | 15 --------------- modules/supplier/back/model-config.json | 3 --- 2 files changed, 18 deletions(-) diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index a8fc13152..608479b4b 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -126,20 +126,5 @@ "allowedContentTypes": [ "application/x-7z-compressed" ] - }, - "supplierStorage": { - "name": "supplierStorage", - "connector": "loopback-component-storage", - "provider": "filesystem", - "root": "./storage/dms", - "maxFileSize": "31457280", - "allowedContentTypes": [ - "image/png", - "image/jpeg", - "image/jpg", - "image/webp", - "video/mp4", - "application/pdf" - ] } } diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index efbb4ceed..5a0c6b43a 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -8,9 +8,6 @@ "SupplierDms": { "dataSource": "vn" }, - "SupplierContainer": { - "dataSource": "supplierStorage" - }, "SupplierAddress": { "dataSource": "vn" }, From b445d745a534a611e77ed259f1abe4cc75500b2e Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 28 Mar 2024 11:40:18 +0100 Subject: [PATCH 43/51] cambios --- .../vn/procedures/sale_boxPickingPrint.sql | 283 ++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 db/routines/vn/procedures/sale_boxPickingPrint.sql diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql new file mode 100644 index 000000000..e979ee0b4 --- /dev/null +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -0,0 +1,283 @@ +DELIMITER $$ +$$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE vn.sale_boxPickingPrint( + IN vPrinterFk INT, + IN vSaleFk INT, + IN vPacking INT, + IN vSectorFk INT, + IN vUserFk INT, + IN vPackagingFk VARCHAR(10), + IN vPackingSiteFk INT) +BEGIN +/** Splits a line of sale to a different ticket and prints the transport sticker + */ + DECLARE vAgencyModeFk INT; + DECLARE vConcept VARCHAR(30); + DECLARE vExpeditionFk INT; + DECLARE vItemFk INT; + DECLARE vItemShelvingFk INT; + DECLARE vItemShelvingSaleFk INT; + DECLARE vItemShelvingSaleFk_old INT; + DECLARE vLastExpeditionTimeStamp DATETIME; + DECLARE vMaxPhoneLength INT DEFAULT 11; + DECLARE vMaxStreetLength INT DEFAULT 36; + DECLARE vNewSaleFk INT; + DECLARE vNewTicketFk INT; + DECLARE vParkingCode VARCHAR(10); + DECLARE vQuantity INT; + DECLARE vRemainder INT DEFAULT 0; + DECLARE vRemainderSaleFk INT; + DECLARE vShelving VARCHAR(10); + DECLARE vTicketFk INT; + + SELECT s.quantity, + s.quantity MOD vPacking, + s.ticketFk, + s.itemFk, + s.concept + INTO vQuantity, + vRemainder, + vTicketFk, + vItemFk, + vConcept + FROM sale s + WHERE s.id = vSaleFk; + + IF vRemainder THEN + UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk; + + INSERT INTO sale(ticketFk, itemFk, quantity, price, discount, concept) + SELECT ticketFk, itemFk, vRemainder, price, discount, concept + FROM sale + WHERE id = vSaleFk; + + SET vRemainderSaleFk = LAST_INSERT_ID(); + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT vRemainderSaleFk, componentFk, value + FROM saleComponent + WHERE saleFk = vSaleFk; + END IF; + +w1: WHILE vQuantity >= vPacking DO + + SET vItemShelvingFk = NULL; + + SELECT sub.id + INTO vItemShelvingFk + FROM productionConfig pc + JOIN ( + SELECT ish.id, + ish.visible - IFNULL(SUM(iss.quantity),0) available, + p.pickingOrder, + ish.created + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + LEFT JOIN itemShelvingSale iss + ON iss.itemShelvingFk = ish.id + AND iss.created >= CURDATE() + AND iss.isPicked = FALSE + WHERE ish.itemFk = vItemFk + AND p.sectorFk = vSectorFk + GROUP BY ish.id + HAVING available >= vPacking) sub + ORDER BY IF(pc.orderMode = 'Location',sub.pickingOrder, sub.created) + LIMIT 1; + + IF vItemShelvingFk THEN + INSERT INTO itemShelvingSale + SET itemShelvingFk = vItemShelvingFk, + saleFk = vSaleFk, + quantity = vPacking, + userFk = vUserFk, + isPicked = TRUE; + + SET vItemShelvingSaleFk = LAST_INSERT_ID(); + + UPDATE sale SET isPicked = FALSE WHERE id = vSaleFk; + ELSE + LEAVE w1; + END IF; + + SET vNewTicketFk = NULL; + + SELECT MAX(t.id) INTO vNewTicketFk + FROM ticket t + JOIN ticketLastState tls ON tls.ticketFk = t.id + JOIN (SELECT addressFk, clientFk, date(shipped) shipped, warehouseFk + FROM ticket + WHERE id = vTicketFk) tt + ON tt.addressFk = t.addressFk + AND tt.clientFk = t.clientFk + AND t.shipped BETWEEN tt.shipped AND util.dayend(tt.shipped) + AND t.warehouseFk = tt.warehouseFk + WHERE tls.name = 'Encajado' ; + + IF ISNULL(vNewTicketFk) THEN + INSERT INTO ticket( clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk, + priority, + hasPriority, + clonedFrom) + SELECT clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk, + priority, + hasPriority, + id + FROM ticket + WHERE id = vTicketFk; + + SET vNewTicketFk = LAST_INSERT_ID(); + + INSERT INTO ticketTracking(ticketFk, stateFk, userFk) + SELECT vNewTicketFk, id, vUserFk + FROM state + WHERE code = 'PACKED'; + END IF; + + UPDATE sale SET quantity = quantity - vPacking WHERE id = vSaleFk; + + UPDATE itemShelving SET visible = visible - vPacking WHERE id = vItemShelvingFk; + + SET vNewSaleFk = NULL; + + SELECT MAX(id) INTO vNewSaleFk + FROM sale + WHERE ticketFk = vNewTicketFk + AND itemFk = vItemFk; + + IF vNewSaleFk THEN + UPDATE sale + SET quantity = quantity + vPacking + WHERE id = vNewSaleFk; + + SET vItemShelvingSaleFk_old = NULL; + + SELECT MAX(id) INTO vItemShelvingSaleFk_old + FROM itemShelvingSale + WHERE itemShelvingFk = vItemShelvingFk + AND saleFk = vNewSaleFk; + + IF vItemShelvingSaleFk_old THEN + UPDATE itemShelvingSale + SET quantity = quantity + vPacking + WHERE id = vItemShelvingSaleFk_old; + + DELETE FROM itemShelvingSale + WHERE id = vItemShelvingSaleFk; + + SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; + ELSE + UPDATE itemShelvingSale + SET saleFk = vNewSaleFk + WHERE id = vItemShelvingSaleFk; + END IF; + ELSE + INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) + SELECT vNewTicketFk, itemFk, concept, vPacking, discount, price + FROM sale + WHERE id = vSaleFk; + + SET vNewSaleFk = LAST_INSERT_ID(); + + INSERT INTO saleComponent(saleFk, componentFk, value, isGreuge) + SELECT vNewSaleFk, componentFk, value, isGreuge + FROM saleComponent + WHERE saleFk = vSaleFk; + + UPDATE itemShelvingSale + SET saleFk = vNewSaleFk + WHERE id = vItemShelvingSaleFk; + END IF; + + INSERT IGNORE INTO saleTracking(saleFk, isChecked, workerFk, stateFk) + SELECT vNewSaleFk, TRUE, vUserFk, id + FROM state + WHERE code = 'PREPARED'; + + SELECT agencyModeFk INTO vAgencyModeFk + FROM ticket + WHERE id = vNewTicketFk; + + INSERT INTO expedition( + agencyModeFk, + ticketFk, + freightItemFk, + workerFk, + packagingFk, + itemPackingTypeFk, + hostFk, + packingSiteFk, + monitorId, + started, + ended + ) + SELECT vAgencyModeFk, + vNewTicketFk, + i.id, + vUserFk, + vPackagingFk, + ps.code, + h.code, + vPackingSiteFk, + ps.monitorId, + IFNULL(vLastExpeditionTimeStamp, NOW()), + NOW() + FROM packingSite ps + JOIN host h ON h.id = ps.hostFk + JOIN item i ON i.name = 'Shipping cost' + WHERE ps.id = vPackingSiteFk + LIMIT 1; + + SET vExpeditionFk = LAST_INSERT_ID(); + + SET vLastExpeditionTimeStamp = NOW(); + + CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE); + + SELECT shelvingFk, p.code + INTO vShelving, vParkingCode + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + WHERE ish.id = vItemShelvingFk; + + UPDATE dipole.expedition_PrintOut + SET isPrinted = FALSE, + itemFk = vItemFk, + quantity = vPacking, + longName = vConcept, + shelvingFk = vShelving, + parkingCode = vParkingCode, + phone = RIGHT(phone,vMaxPhoneLength), + street = RIGHT(street, vMAxStreetLength) + WHERE expeditionFk = vExpeditionFk; + + DELETE FROM sale + WHERE quantity = 0 + AND id = vSaleFk; + END WHILE; + +END$$ +DELIMITER ; \ No newline at end of file From 1d906c993b8b0ebff3f9e5ba455781aa75a2ea7e Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 28 Mar 2024 12:43:13 +0100 Subject: [PATCH 44/51] portes --- db/routines/vn/procedures/sale_boxPickingPrint.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index e979ee0b4..6cd8eeb20 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -246,7 +246,7 @@ w1: WHILE vQuantity >= vPacking DO NOW() FROM packingSite ps JOIN host h ON h.id = ps.hostFk - JOIN item i ON i.name = 'Shipping cost' + JOIN item i ON i.name = 'Porte Caja' WHERE ps.id = vPackingSiteFk LIMIT 1; From 76c04cb2605bf032d0be16ea9a65aa464f604dbd Mon Sep 17 00:00:00 2001 From: Juanjo Breso Date: Thu, 28 Mar 2024 13:33:21 +0000 Subject: [PATCH 45/51] Restore storage rule --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b741a2d44..895a6a8dc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ print.*.json db.json junit.xml .DS_Store +storage \ No newline at end of file From c942786783ea8bc9650e20ba690fcf095e98624b Mon Sep 17 00:00:00 2001 From: Pako Date: Thu, 28 Mar 2024 14:54:30 +0100 Subject: [PATCH 46/51] pruebas --- .../vn/procedures/boxPicking_print.sql | 22 +++++++++++++------ .../vn/procedures/sale_boxPickingPrint.sql | 14 ++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/boxPicking_print.sql b/db/routines/vn/procedures/boxPicking_print.sql index 5eea4ee1e..31485be1d 100644 --- a/db/routines/vn/procedures/boxPicking_print.sql +++ b/db/routines/vn/procedures/boxPicking_print.sql @@ -59,6 +59,8 @@ BEGIN WHERE saleFk = vSaleFk; END IF; +SELECT vQuantity , vPacking; + w1: WHILE vQuantity >= vPacking DO SET vItemShelvingFk = NULL; @@ -86,13 +88,13 @@ w1: WHILE vQuantity >= vPacking DO LIMIT 1; IF vItemShelvingFk THEN - INSERT INTO itemShelvingSale + /* INSERT INTO itemShelvingSale SET itemShelvingFk = vItemShelvingFk, saleFk = vSaleFk, quantity = vPacking, userFk = vUserFk, isPicked = TRUE; - +*/ SET vItemShelvingSaleFk = LAST_INSERT_ID(); UPDATE sale SET isPicked = FALSE WHERE id = vSaleFk; @@ -188,10 +190,12 @@ w1: WHILE vQuantity >= vPacking DO WHERE id = vItemShelvingSaleFk; SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; - ELSE - UPDATE itemShelvingSale + /*ELSE + + * UPDATE itemShelvingSale SET saleFk = vNewSaleFk WHERE id = vItemShelvingSaleFk; + */ END IF; ELSE INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) @@ -206,9 +210,11 @@ w1: WHILE vQuantity >= vPacking DO FROM saleComponent WHERE saleFk = vSaleFk; - UPDATE itemShelvingSale + /* + * UPDATE itemShelvingSale SET saleFk = vNewSaleFk WHERE id = vItemShelvingSaleFk; + */ END IF; INSERT IGNORE INTO saleTracking(saleFk, isChecked, workerFk, stateFk) @@ -231,7 +237,8 @@ w1: WHILE vQuantity >= vPacking DO packingSiteFk, monitorId, started, - ended + ended, + counter ) SELECT vAgencyModeFk, vNewTicketFk, @@ -243,7 +250,8 @@ w1: WHILE vQuantity >= vPacking DO vPackingSiteFk, ps.monitorId, IFNULL(vLastExpeditionTimeStamp, NOW()), - NOW() + NOW(), + 0 FROM packingSite ps JOIN host h ON h.id = ps.hostFk JOIN item i ON i.name = 'Shipping cost' diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index 6cd8eeb20..7872ff000 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -86,7 +86,7 @@ w1: WHILE vQuantity >= vPacking DO LIMIT 1; IF vItemShelvingFk THEN - INSERT INTO itemShelvingSale + /* INSERT INTO itemShelvingSale SET itemShelvingFk = vItemShelvingFk, saleFk = vSaleFk, quantity = vPacking, @@ -94,7 +94,7 @@ w1: WHILE vQuantity >= vPacking DO isPicked = TRUE; SET vItemShelvingSaleFk = LAST_INSERT_ID(); - +*/ UPDATE sale SET isPicked = FALSE WHERE id = vSaleFk; ELSE LEAVE w1; @@ -188,10 +188,10 @@ w1: WHILE vQuantity >= vPacking DO WHERE id = vItemShelvingSaleFk; SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; - ELSE + /* ELSE UPDATE itemShelvingSale SET saleFk = vNewSaleFk - WHERE id = vItemShelvingSaleFk; + WHERE id = vItemShelvingSaleFk; */ END IF; ELSE INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) @@ -206,9 +206,9 @@ w1: WHILE vQuantity >= vPacking DO FROM saleComponent WHERE saleFk = vSaleFk; - UPDATE itemShelvingSale - SET saleFk = vNewSaleFk - WHERE id = vItemShelvingSaleFk; + /* UPDATE itemShelvingSale + SET saleFk = vNewSaleFk */ + END IF; INSERT IGNORE INTO saleTracking(saleFk, isChecked, workerFk, stateFk) From 9aae9677e66b3208fd66b1399a578cf1974f6ef2 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 1 Apr 2024 08:43:26 +0200 Subject: [PATCH 47/51] modificaciones --- .../vn/procedures/sale_boxPickingPrint.sql | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index 7872ff000..8b7f8ecbe 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -61,6 +61,8 @@ BEGIN w1: WHILE vQuantity >= vPacking DO + SET vQuantity = vQuantity - vPacking; + SET vItemShelvingFk = NULL; SELECT sub.id @@ -86,7 +88,7 @@ w1: WHILE vQuantity >= vPacking DO LIMIT 1; IF vItemShelvingFk THEN - /* INSERT INTO itemShelvingSale + INSERT INTO itemShelvingSale SET itemShelvingFk = vItemShelvingFk, saleFk = vSaleFk, quantity = vPacking, @@ -94,7 +96,7 @@ w1: WHILE vQuantity >= vPacking DO isPicked = TRUE; SET vItemShelvingSaleFk = LAST_INSERT_ID(); -*/ + UPDATE sale SET isPicked = FALSE WHERE id = vSaleFk; ELSE LEAVE w1; @@ -188,10 +190,10 @@ w1: WHILE vQuantity >= vPacking DO WHERE id = vItemShelvingSaleFk; SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; - /* ELSE + ELSE UPDATE itemShelvingSale SET saleFk = vNewSaleFk - WHERE id = vItemShelvingSaleFk; */ + WHERE id = vItemShelvingSaleFk; END IF; ELSE INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) @@ -206,9 +208,10 @@ w1: WHILE vQuantity >= vPacking DO FROM saleComponent WHERE saleFk = vSaleFk; - /* UPDATE itemShelvingSale - SET saleFk = vNewSaleFk */ - + UPDATE itemShelvingSale + SET saleFk = vNewSaleFk + WHERE id = vItemShelvingSaleFk; + END IF; INSERT IGNORE INTO saleTracking(saleFk, isChecked, workerFk, stateFk) @@ -277,6 +280,7 @@ w1: WHILE vQuantity >= vPacking DO DELETE FROM sale WHERE quantity = 0 AND id = vSaleFk; + END WHILE; END$$ From 98b1e933f7c0c390440b04ef6f8ad0edab66f542 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 1 Apr 2024 08:46:07 +0200 Subject: [PATCH 48/51] prova --- db/routines/vn/procedures/sale_boxPickingPrint.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index 8b7f8ecbe..ae0c6451e 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -58,7 +58,7 @@ BEGIN FROM saleComponent WHERE saleFk = vSaleFk; END IF; - +/* res */ w1: WHILE vQuantity >= vPacking DO SET vQuantity = vQuantity - vPacking; From 547df4704922b475341a9ddffa33e984a619eb22 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 1 Apr 2024 08:47:16 +0200 Subject: [PATCH 49/51] delete old proc --- .../vn/procedures/boxPicking_print.sql | 291 ------------------ 1 file changed, 291 deletions(-) delete mode 100644 db/routines/vn/procedures/boxPicking_print.sql diff --git a/db/routines/vn/procedures/boxPicking_print.sql b/db/routines/vn/procedures/boxPicking_print.sql deleted file mode 100644 index 31485be1d..000000000 --- a/db/routines/vn/procedures/boxPicking_print.sql +++ /dev/null @@ -1,291 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE PROCEDURE vn.sale_boxPickingPrint( - IN vPrinterFk INT, - IN vSaleFk INT, - IN vPacking INT, - IN vSectorFk INT, - IN vUserFk INT, - IN vPackagingFk INT, - IN vPackingSiteFk INT) -BEGIN -/** Splits a line of sale to a different ticket and prints the transport sticker - */ - DECLARE vAgencyModeFk INT; - DECLARE vConcept VARCHAR(30); - DECLARE vExpeditionFk INT; - DECLARE vItemFk INT; - DECLARE vItemShelvingFk INT; - DECLARE vItemShelvingSaleFk INT; - DECLARE vItemShelvingSaleFk_old INT; - DECLARE vLastExpeditionTimeStamp DATETIME; - DECLARE vMaxPhoneLength INT DEFAULT 11; - DECLARE vMaxStreetLength INT DEFAULT 36; - DECLARE vNewSaleFk INT; - DECLARE vNewTicketFk INT; - DECLARE vParkingCode VARCHAR(10); - DECLARE vQuantity INT; - DECLARE vRemainder INT DEFAULT 0; - DECLARE vRemainderSaleFk INT; - DECLARE vShelving VARCHAR(10); - DECLARE vTicketFk INT; - - SELECT s.quantity, - s.quantity MOD vPacking, - s.ticketFk, - s.itemFk, - s.concept - INTO vQuantity, - vRemainder, - vTicketFk, - vItemFk, - vConcept - FROM sale s - WHERE s.id = vSaleFk; - - IF vRemainder THEN - UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk; - - INSERT INTO sale(ticketFk, itemFk, quantity, price, discount, concept) - SELECT ticketFk, itemFk, vRemainder, price, discount, concept - FROM sale - WHERE id = vSaleFk; - - SET vRemainderSaleFk = LAST_INSERT_ID(); - - INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT vRemainderSaleFk, componentFk, value - FROM saleComponent - WHERE saleFk = vSaleFk; - END IF; - -SELECT vQuantity , vPacking; - -w1: WHILE vQuantity >= vPacking DO - - SET vItemShelvingFk = NULL; - - SELECT sub.id - INTO vItemShelvingFk - FROM productionConfig pc - JOIN ( - SELECT ish.id, - ish.visible - IFNULL(SUM(iss.quantity),0) available, - p.pickingOrder, - ish.created - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - LEFT JOIN itemShelvingSale iss - ON iss.itemShelvingFk = ish.id - AND iss.created >= CURDATE() - AND iss.isPicked = FALSE - WHERE ish.itemFk = vItemFk - AND p.sectorFk = vSectorFk - GROUP BY ish.id - HAVING available >= vPacking) sub - ORDER BY IF(pc.orderMode = 'Location',sub.pickingOrder, sub.created) - LIMIT 1; - - IF vItemShelvingFk THEN - /* INSERT INTO itemShelvingSale - SET itemShelvingFk = vItemShelvingFk, - saleFk = vSaleFk, - quantity = vPacking, - userFk = vUserFk, - isPicked = TRUE; -*/ - SET vItemShelvingSaleFk = LAST_INSERT_ID(); - - UPDATE sale SET isPicked = FALSE WHERE id = vSaleFk; - ELSE - LEAVE w1; - END IF; - - SET vNewTicketFk = NULL; - - SELECT MAX(t.id) INTO vNewTicketFk - FROM ticket t - JOIN ticketLastState tls ON tls.ticketFk = t.id - JOIN (SELECT addressFk, clientFk, date(shipped) shipped, warehouseFk - FROM ticket - WHERE id = vTicketFk) tt - ON tt.addressFk = t.addressFk - AND tt.clientFk = t.clientFk - AND t.shipped BETWEEN tt.shipped AND util.dayend(tt.shipped) - AND t.warehouseFk = tt.warehouseFk - WHERE tls.name = 'Encajado' ; - - IF ISNULL(vNewTicketFk) THEN - INSERT INTO ticket( clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus, - routeFk, - priority, - hasPriority, - clonedFrom) - SELECT clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus, - routeFk, - priority, - hasPriority, - id - FROM ticket - WHERE id = vTicketFk; - - SET vNewTicketFk = LAST_INSERT_ID(); - - INSERT INTO ticketTracking(ticketFk, stateFk, userFk) - SELECT vNewTicketFk, id, vUserFk - FROM state - WHERE code = 'PACKED'; - END IF; - - UPDATE sale SET quantity = quantity - vPacking WHERE id = vSaleFk; - - UPDATE itemShelving SET visible = visible - vPacking WHERE id = vItemShelvingFk; - - SET vNewSaleFk = NULL; - - SELECT MAX(id) INTO vNewSaleFk - FROM sale - WHERE ticketFk = vNewTicketFk - AND itemFk = vItemFk; - - IF vNewSaleFk THEN - UPDATE sale - SET quantity = quantity + vPacking - WHERE id = vNewSaleFk; - - SET vItemShelvingSaleFk_old = NULL; - - SELECT MAX(id) INTO vItemShelvingSaleFk_old - FROM itemShelvingSale - WHERE itemShelvingFk = vItemShelvingFk - AND saleFk = vNewSaleFk; - - IF vItemShelvingSaleFk_old THEN - UPDATE itemShelvingSale - SET quantity = quantity + vPacking - WHERE id = vItemShelvingSaleFk_old; - - DELETE FROM itemShelvingSale - WHERE id = vItemShelvingSaleFk; - - SET vItemShelvingSaleFk = vItemShelvingSaleFk_old; - /*ELSE - - * UPDATE itemShelvingSale - SET saleFk = vNewSaleFk - WHERE id = vItemShelvingSaleFk; - */ - END IF; - ELSE - INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) - SELECT vNewTicketFk, itemFk, concept, vPacking, discount, price - FROM sale - WHERE id = vSaleFk; - - SET vNewSaleFk = LAST_INSERT_ID(); - - INSERT INTO saleComponent(saleFk, componentFk, value, isGreuge) - SELECT vNewSaleFk, componentFk, value, isGreuge - FROM saleComponent - WHERE saleFk = vSaleFk; - - /* - * UPDATE itemShelvingSale - SET saleFk = vNewSaleFk - WHERE id = vItemShelvingSaleFk; - */ - END IF; - - INSERT IGNORE INTO saleTracking(saleFk, isChecked, workerFk, stateFk) - SELECT vNewSaleFk, TRUE, vUserFk, id - FROM state - WHERE code = 'PREPARED'; - - SELECT agencyModeFk INTO vAgencyModeFk - FROM ticket - WHERE id = vNewTicketFk; - - INSERT INTO expedition( - agencyModeFk, - ticketFk, - freightItemFk, - workerFk, - packagingFk, - itemPackingTypeFk, - hostFk, - packingSiteFk, - monitorId, - started, - ended, - counter - ) - SELECT vAgencyModeFk, - vNewTicketFk, - i.id, - vUserFk, - vPackagingFk, - ps.code, - h.code, - vPackingSiteFk, - ps.monitorId, - IFNULL(vLastExpeditionTimeStamp, NOW()), - NOW(), - 0 - FROM packingSite ps - JOIN host h ON h.id = ps.hostFk - JOIN item i ON i.name = 'Shipping cost' - WHERE ps.id = vPackingSiteFk - LIMIT 1; - - SET vExpeditionFk = LAST_INSERT_ID(); - - SET vLastExpeditionTimeStamp = NOW(); - - CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE); - - SELECT shelvingFk, p.code - INTO vShelving, vParkingCode - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - WHERE ish.id = vItemShelvingFk; - - UPDATE dipole.expedition_PrintOut - SET isPrinted = FALSE, - itemFk = vItemFk, - quantity = vPacking, - longName = vConcept, - shelvingFk = vShelving, - parkingCode = vParkingCode, - phone = RIGHT(phone,vMaxPhoneLength), - street = RIGHT(street, vMAxStreetLength) - WHERE expeditionFk = vExpeditionFk; - - DELETE FROM sale - WHERE quantity = 0 - AND id = vSaleFk; - END WHILE; - -END$$ -DELIMITER ; \ No newline at end of file From df911b9b75e23066f0263e1fcb96379b0ef25412 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 1 Apr 2024 08:47:47 +0200 Subject: [PATCH 50/51] fora comentaris --- db/routines/vn/procedures/sale_boxPickingPrint.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index ae0c6451e..8b7f8ecbe 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -58,7 +58,7 @@ BEGIN FROM saleComponent WHERE saleFk = vSaleFk; END IF; -/* res */ + w1: WHILE vQuantity >= vPacking DO SET vQuantity = vQuantity - vPacking; From 7c4fc31b50a8ab0323a8ab510ffa70135d8cfe81 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 1 Apr 2024 08:55:21 +0200 Subject: [PATCH 51/51] version productionConfig --- db/routines/vn/procedures/sale_boxPickingPrint.sql | 7 +++---- db/versions/10973-purpleAsparagus/00-firstScript.sql | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 db/versions/10973-purpleAsparagus/00-firstScript.sql diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index 8b7f8ecbe..dbb3b6c14 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -238,7 +238,7 @@ w1: WHILE vQuantity >= vPacking DO ) SELECT vAgencyModeFk, vNewTicketFk, - i.id, + pc.defaultFreightItemFk, vUserFk, vPackagingFk, ps.code, @@ -249,9 +249,8 @@ w1: WHILE vQuantity >= vPacking DO NOW() FROM packingSite ps JOIN host h ON h.id = ps.hostFk - JOIN item i ON i.name = 'Porte Caja' - WHERE ps.id = vPackingSiteFk - LIMIT 1; + JOIN productionConfig pc + WHERE ps.id = vPackingSiteFk; SET vExpeditionFk = LAST_INSERT_ID(); diff --git a/db/versions/10973-purpleAsparagus/00-firstScript.sql b/db/versions/10973-purpleAsparagus/00-firstScript.sql new file mode 100644 index 000000000..f5b838529 --- /dev/null +++ b/db/versions/10973-purpleAsparagus/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig ADD defaultFreightItemFk INT UNSIGNED DEFAULT 71 NOT NULL COMMENT 'Default value for expedition table';