From 0e5a15dd4e1b9fc5ac5738280090663a6cf1f4b1 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 24 May 2024 15:14:20 +0200 Subject: [PATCH 01/22] con addressFk --- db/dump/.dump/data.sql | 4 +-- db/dump/fixtures.before.sql | 19 +++++++++----- .../vn/procedures/expeditionTruck_Add.sql | 9 ------- .../vn/procedures/expeditionTruck_List.sql | 12 --------- .../vn/views/expeditionTruck_Control.sql | 19 -------------- .../views/expeditionTruck_Control_Detail.sql | 18 ------------- .../expeditionTruck_Control_Detail_Pallet.sql | 22 ---------------- .../00-roadmapAddress.sql | 8 ++++++ .../11063-purpleAnthurium/01-roadmapStop.sql | 7 +++++ .../02-roadmapStopGrants.sql | 11 ++++++++ .../route/back/locale/routesMonitor/en.yml | 4 +-- .../route/back/locale/routesMonitor/es.yml | 4 +-- modules/route/back/methods/roadmap/clone.js | 11 +++----- modules/route/back/model-config.json | 3 +++ modules/route/back/models/roadmapAddress.json | 26 +++++++++++++++++++ modules/route/back/models/roadmapStop.json | 8 +++--- 16 files changed, 81 insertions(+), 104 deletions(-) delete mode 100644 db/routines/vn/procedures/expeditionTruck_Add.sql delete mode 100644 db/routines/vn/procedures/expeditionTruck_List.sql delete mode 100644 db/routines/vn/views/expeditionTruck_Control.sql delete mode 100644 db/routines/vn/views/expeditionTruck_Control_Detail.sql delete mode 100644 db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql create mode 100644 db/versions/11063-purpleAnthurium/00-roadmapAddress.sql create mode 100644 db/versions/11063-purpleAnthurium/01-roadmapStop.sql create mode 100644 db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql create mode 100644 modules/route/back/models/roadmapAddress.json diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index f49e3f0f9..b1a69dee9 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -1747,8 +1747,8 @@ INSERT INTO `ACL` VALUES (688,'ClientSms','create','WRITE','ALLOW','ROLE','emplo INSERT INTO `ACL` VALUES (689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'); INSERT INTO `ACL` VALUES (691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'); -INSERT INTO `ACL` VALUES (692,'ExpeditionTruck','*','*','ALLOW','ROLE','production'); -INSERT INTO `ACL` VALUES (693,'ExpeditionTruck','*','*','ALLOW','ROLE','productionBoss'); +INSERT INTO `ACL` VALUES (692,'roadmapStop','*','*','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (693,'roadmapStop','*','*','ALLOW','ROLE','productionBoss'); INSERT INTO `ACL` VALUES (695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'); diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 3e6edf07d..ccd6ef1d5 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2670,13 +2670,20 @@ INSERT INTO `vn`.`zoneAgencyMode`(`id`, `agencyModeFk`, `zoneFk`) (3, 6, 5), (4, 7, 1); +INSERT INTO `vn`.`roadmapAddress` (`addressFk`) + VALUES + (1), + (2), + (3), + (4); + INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `userFk`, `price`, `driverName`) VALUES - (1, 'val-algemesi', 'RE-001', 'PO-001', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'), - (2, 'alg-valencia', 'RE-002', 'PO-002', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'), - (3, 'alz-algemesi', 'RE-003', 'PO-003', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman'); + (1, 'val-algemesi', '1234-BCD', '9876-BCD', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'), + (2, 'alg-valencia', '2345-CDF', '8765-BCD', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'), + (3, 'alz-algemesi', '3456-DFG', '7654-BCD', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman'); -INSERT INTO `vn`.`expeditionTruck` (`id`, `roadmapFk`, `warehouseFk`, `eta`, `description`, `userFk`) +INSERT INTO `vn`.`roadmapStop` (`id`, `roadmapFk`, `addressFk`, `eta`, `description`, `userFk`) VALUES (1, 1, 1, DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY), 'Best truck in fleet', 1), (2, 1, 2, DATE_ADD(util.VN_NOW(), INTERVAL '1 2' DAY_HOUR), 'Second truck in fleet', 1), @@ -3788,7 +3795,7 @@ INSERT INTO vn.workerTeam(id, team, workerFk) VALUES (8, 1, 19); -INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) +INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL); -UPDATE vn.locker SET workerFk = 1110 WHERE id = 147; \ No newline at end of file +UPDATE vn.locker SET workerFk = 1110 WHERE id = 147; diff --git a/db/routines/vn/procedures/expeditionTruck_Add.sql b/db/routines/vn/procedures/expeditionTruck_Add.sql deleted file mode 100644 index eabfa452c..000000000 --- a/db/routines/vn/procedures/expeditionTruck_Add.sql +++ /dev/null @@ -1,9 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionTruck_Add`(vHour VARCHAR(5), vDescription VARCHAR(45)) -BEGIN - - INSERT INTO vn.roadmapStop(eta,description) - VALUES(CONCAT(util.VN_CURDATE(), ' ', vHour), vDescription); - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionTruck_List.sql b/db/routines/vn/procedures/expeditionTruck_List.sql deleted file mode 100644 index c358df5e3..000000000 --- a/db/routines/vn/procedures/expeditionTruck_List.sql +++ /dev/null @@ -1,12 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionTruck_List`() -BEGIN - - SELECT id truckFk, - eta, - description Destino - FROM roadmapStop - WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - ORDER BY eta; -END$$ -DELIMITER ; diff --git a/db/routines/vn/views/expeditionTruck_Control.sql b/db/routines/vn/views/expeditionTruck_Control.sql deleted file mode 100644 index 838e1f89e..000000000 --- a/db/routines/vn/views/expeditionTruck_Control.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`expeditionTruck_Control` -AS SELECT `e`.`truckFk` AS `id`, - `e`.`eta` AS `ETD`, - `e`.`description` AS `description`, - COUNT( - DISTINCT IF(`e`.`expeditionFk` IS NULL, `e`.`ticketFk`, NULL) - ) AS `ticketsSinBultos`, - COUNT(DISTINCT `e`.`palletFk`) AS `pallets`, - COUNT(DISTINCT `e`.`routeFk`) AS `routes`, - COUNT(DISTINCT `e`.`scanFk`) AS `scans`, - COUNT(DISTINCT `e`.`expeditionFk`) AS `expeditions`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, - max(`e`.`lastPacked`) AS `lastPacked` -FROM `vn`.`expeditionCommon` `e` -GROUP BY `e`.`truckFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, - `e`.`eta` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail.sql b/db/routines/vn/views/expeditionTruck_Control_Detail.sql deleted file mode 100644 index 96a5b78e6..000000000 --- a/db/routines/vn/views/expeditionTruck_Control_Detail.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`expeditionTruck_Control_Detail` -AS SELECT `e`.`truckFk` AS `id`, - `e`.`eta` AS `eta`, - `e`.`description` AS `destino`, - `e`.`palletFk` AS `pallet`, - COUNT(DISTINCT `e`.`routeFk`) AS `routes`, - COUNT(DISTINCT `e`.`scanFk`) AS `scans`, - COUNT(DISTINCT `e`.`expeditionTruckFk`) AS `destinos`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, - max(`e`.`lastPacked`) AS `lastPacked` -FROM `vn`.`expeditionCommon` `e` -GROUP BY `e`.`truckFk`, - `e`.`palletFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, - `e`.`eta`, - `e`.`truckFk` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql deleted file mode 100644 index 3f239432d..000000000 --- a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql +++ /dev/null @@ -1,22 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`expeditionTruck_Control_Detail_Pallet` -AS SELECT `e`.`truckFk` AS `id`, - `e`.`eta` AS `eta`, - `e`.`description` AS `destino`, - `e`.`palletFk` AS `pallet`, - `e`.`routeFk` AS `route`, - COUNT(DISTINCT `e`.`scanFk`) AS `scans`, - `rs`.`description` AS `destinos`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, - `e`.`expeditionTruckFk` AS `expeditionTruckFk`, - max(`e`.`lastPacked`) AS `lastPacked` -FROM ( - `vn`.`expeditionCommon` `e` - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`expeditionTruckFk`) - ) -GROUP BY `e`.`truckFk`, - `e`.`palletFk`, - `e`.`routeFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, - `e`.`palletFk` diff --git a/db/versions/11063-purpleAnthurium/00-roadmapAddress.sql b/db/versions/11063-purpleAnthurium/00-roadmapAddress.sql new file mode 100644 index 000000000..6435da1c9 --- /dev/null +++ b/db/versions/11063-purpleAnthurium/00-roadmapAddress.sql @@ -0,0 +1,8 @@ +CREATE TABLE `vn`.`roadmapAddress` ( + addressFk int(11) NULL, + isActive TINYINT DEFAULT 1 NULL, + PRIMARY KEY (addressFk) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Direcciones de los troncales'; + +ALTER TABLE vn.roadmapAddress + ADD CONSTRAINT roadmapAddress_address_FK FOREIGN KEY (addressFk) REFERENCES vn.address(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/11063-purpleAnthurium/01-roadmapStop.sql b/db/versions/11063-purpleAnthurium/01-roadmapStop.sql new file mode 100644 index 000000000..844abf45f --- /dev/null +++ b/db/versions/11063-purpleAnthurium/01-roadmapStop.sql @@ -0,0 +1,7 @@ +ALTER TABLE vn.roadmapStop DROP FOREIGN KEY expeditionTruck_FK_1; +ALTER TABLE vn.roadmapStop DROP COLUMN warehouseFk; +ALTER TABLE vn.roadmapStop ADD addressFk int(11) NULL; +ALTER TABLE vn.roadmapStop CHANGE addressFk addressFk int(11) DEFAULT NULL NULL AFTER roadmapFk; + +ALTER TABLE vn.roadmapStop + ADD CONSTRAINT roadmapStop_roadmapAddress_FK FOREIGN KEY (addressFk) REFERENCES vn.roadmapAddress(addressFk) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql b/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql new file mode 100644 index 000000000..d2c8354c0 --- /dev/null +++ b/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql @@ -0,0 +1,11 @@ +DELETE FROM salix.ACL + WHERE model in ('expeditionTruck', 'Roadmap', 'roadmapStop', 'roadmapAddress'); + +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES + ('roadmapAddress', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), + ('roadmapAddress', '*', 'READ', 'ALLOW', 'ROLE', 'production'), + ('Roadmap', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), + ('Roadmap', '*', 'READ', 'ALLOW', 'ROLE', 'production'), + ('RoadmapStop', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), + ('RoadmapStop', '*', 'READ', 'ALLOW', 'ROLE', 'production'); diff --git a/modules/route/back/locale/routesMonitor/en.yml b/modules/route/back/locale/routesMonitor/en.yml index 8908ee636..0542ced54 100644 --- a/modules/route/back/locale/routesMonitor/en.yml +++ b/modules/route/back/locale/routesMonitor/en.yml @@ -13,7 +13,7 @@ columns: m3: m3 priority: priority etd: etd - expeditionTruckFk: truck + roadmapStopFk: truck m3boxes: m3 boxes bufferFk: buffer - isPickingAllowed: is picking allowed \ No newline at end of file + isPickingAllowed: is picking allowed diff --git a/modules/route/back/locale/routesMonitor/es.yml b/modules/route/back/locale/routesMonitor/es.yml index 9ded8983d..1ea0532c6 100644 --- a/modules/route/back/locale/routesMonitor/es.yml +++ b/modules/route/back/locale/routesMonitor/es.yml @@ -13,7 +13,7 @@ columns: m3: m3 priority: prioridad etd: etd - expeditionTruckFk: camión + roadmapStopFk: camión m3boxes: m3 cajas bufferFk: buffer - isPickingAllowed: está permitido recoger \ No newline at end of file + isPickingAllowed: está permitido recoger diff --git a/modules/route/back/methods/roadmap/clone.js b/modules/route/back/methods/roadmap/clone.js index b74cf803c..5f1ab9229 100644 --- a/modules/route/back/methods/roadmap/clone.js +++ b/modules/route/back/methods/roadmap/clone.js @@ -37,17 +37,12 @@ module.exports = Self => { fields: [ 'id', 'name', - 'tractorPlate', - 'trailerPlate', - 'phone', 'supplierFk', - 'etd', - 'observations', - 'price'], + 'etd'], include: [{ - relation: 'expeditionTruck', + relation: 'roadmapStop', scope: { - fields: ['roadmapFk', 'warehouseFk', 'eta', 'description'] + fields: ['roadmapFk', 'addressFk', 'eta', 'description'] } }] diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index 09cda6b2d..ccae87bd9 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -8,6 +8,9 @@ "DeliveryPoint": { "dataSource": "vn" }, + "RoadmapAddress": { + "dataSource": "vn" + }, "RoadmapStop": { "dataSource": "vn" }, diff --git a/modules/route/back/models/roadmapAddress.json b/modules/route/back/models/roadmapAddress.json new file mode 100644 index 000000000..0241ce0d8 --- /dev/null +++ b/modules/route/back/models/roadmapAddress.json @@ -0,0 +1,26 @@ +{ + "name": "RoadmapAddress", + "base": "VnModel", + "options": { + "mysql": { + "table": "roadmapAddress" + } + }, + "properties": { + "addressFk": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "isActive": { + "type": "number" + } + }, + "relations": { + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" + } + } +} diff --git a/modules/route/back/models/roadmapStop.json b/modules/route/back/models/roadmapStop.json index 51aa3a6db..527bbae98 100644 --- a/modules/route/back/models/roadmapStop.json +++ b/modules/route/back/models/roadmapStop.json @@ -15,7 +15,7 @@ "roadmapFk": { "type": "number" }, - "warehouseFk": { + "addressFk": { "type": "number" }, "eta": { @@ -34,10 +34,10 @@ "model": "Roadmap", "foreignKey": "roadmapFk" }, - "warehouse": { + "address": { "type": "belongsTo", - "model": "Warehouse", - "foreignKey": "warehouseFk" + "model": "RoadmapAddress", + "foreignKey": "addressFk" } } } From bd82bb011a2283ccbf5aa175be7518637c1224b2 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 31 May 2024 08:44:30 +0200 Subject: [PATCH 02/22] fix(transferInvoice): separate invoice functionality from generating PDF and adapt tests --- loopback/locale/en.json | 5 +- loopback/locale/es.json | 5 +- loopback/locale/fr.json | 5 +- loopback/locale/pt.json | 5 +- .../invoiceOut/specs/transferinvoice.spec.js | 90 ++++++++++--------- .../methods/invoiceOut/transferInvoice.js | 28 ++++-- .../invoiceOut/front/descriptor-menu/index.js | 2 +- modules/ticket/back/methods/sale/clone.js | 1 + 8 files changed, 81 insertions(+), 60 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 551b544b6..48ec17535 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -227,5 +227,6 @@ "They're not your subordinate": "They're not your subordinate", "InvoiceIn is already booked": "InvoiceIn is already booked", "This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency", - "You can only have one PDA": "You can only have one PDA" -} \ No newline at end of file + "You can only have one PDA": "You can only have one PDA", + "It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4a7e1505c..169b4bc01 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -359,5 +359,6 @@ "It was not able to create the invoice": "No se pudo crear la factura", "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", "This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario", - "You can only have one PDA": "Solo puedes tener un PDA" -} \ No newline at end of file + "You can only have one PDA": "Solo puedes tener un PDA", + "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF" +} diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 44f5e35d3..2bb23c3fc 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -356,5 +356,6 @@ "InvoiceIn is already booked": "La facture reçue est déjà comptabilisée", "This workCenter is already assigned to this agency": "Ce centre de travail est déjà assigné à cette agence", "Select ticket or client": "Choisissez un ticket ou un client", - "It was not able to create the invoice": "Il n'a pas été possible de créer la facture" -} \ No newline at end of file + "It was not able to create the invoice": "Il n'a pas été possible de créer la facture", + "It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré" +} diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index b11eeefc6..1ebcfa3de 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -356,5 +356,6 @@ "InvoiceIn is already booked": "InvoiceIn já está reservado", "This workCenter is already assigned to this agency": "Este centro de trabalho já está atribuído a esta agência", "Select ticket or client": "Selecione um ticket ou cliente", - "It was not able to create the invoice": "Não foi possível criar a fatura" -} \ No newline at end of file + "It was not able to create the invoice": "Não foi possível criar a fatura", + "It has been invoiced but the PDF could not be generated": "Foi faturado, mas o PDF não pôde ser gerado" +} diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js index eaaef3e26..cf656f6da 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js @@ -1,4 +1,4 @@ - +/* eslint max-len: ["error", { "code": 150 }]*/ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); @@ -17,27 +17,19 @@ describe('InvoiceOut transferInvoice()', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); - spyOn(models.InvoiceOut, 'makePdfAndNotify'); }); it('should return the id of the created issued invoice', async() => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; - const args = { - id: '4', - refFk: 'T4444444', - newClientFk: 1, - cplusRectificationTypeFk: 1, - siiTypeInvoiceOutFk: 1, - invoiceCorrectionTypeFk: 1 - }; - ctx.args = args; + const id = 4; + const newClient = 1; + spyOn(models.InvoiceOut, 'makePdfList'); + try { - const {clientFk: oldClient} = await models.InvoiceOut.findById(args.id, {fields: ['clientFk']}); + const {clientFk: oldClient} = await models.InvoiceOut.findById(id, {fields: ['clientFk']}); const invoicesBefore = await models.InvoiceOut.find({}, options); - const result = await models.InvoiceOut.transferInvoice( - ctx, - options); + const result = await models.InvoiceOut.transferInvoice(ctx, id, 'T4444444', newClient, 1, 1, 1, true, options); const invoicesAfter = await models.InvoiceOut.find({}, options); const rectificativeInvoice = invoicesAfter[invoicesAfter.length - 2]; const newInvoice = invoicesAfter[invoicesAfter.length - 1]; @@ -45,7 +37,7 @@ describe('InvoiceOut transferInvoice()', () => { expect(result).toBeDefined(); expect(invoicesAfter.length - invoicesBefore.length).toEqual(2); expect(rectificativeInvoice.clientFk).toEqual(oldClient); - expect(newInvoice.clientFk).toEqual(args.newClientFk); + expect(newInvoice.clientFk).toEqual(newClient); await tx.rollback(); } catch (e) { @@ -54,22 +46,13 @@ describe('InvoiceOut transferInvoice()', () => { } }); - it('should throw an UserError when it is the same client', async() => { + it('should throw an error when it is the same client', async() => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; - const args = { - id: '1', - refFk: 'T1111111', - newClientFk: 1101, - cplusRectificationTypeFk: 1, - siiTypeInvoiceOutFk: 1, - invoiceCorrectionTypeFk: 1 - }; - ctx.args = args; + spyOn(models.InvoiceOut, 'makePdfList'); + try { - await models.InvoiceOut.transferInvoice( - ctx, - options); + await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1101, 1, 1, 1, true, options); await tx.rollback(); } catch (e) { expect(e.message).toBe(`Select a different client`); @@ -77,26 +60,49 @@ describe('InvoiceOut transferInvoice()', () => { } }); - it('should throw an UserError when it is refund', async() => { + it('should throw an error when it is refund', async() => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; - const args = { - id: '1', - refFk: 'T1111111', - newClientFk: 1102, - cplusRectificationTypeFk: 1, - siiTypeInvoiceOutFk: 1, - invoiceCorrectionTypeFk: 1 - }; - ctx.args = args; + spyOn(models.InvoiceOut, 'makePdfList'); try { - await models.InvoiceOut.transferInvoice( - ctx, - options); + await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1102, 1, 1, 1, true, options); await tx.rollback(); } catch (e) { expect(e.message).toContain(`This ticket is already a refund`); await tx.rollback(); } }); + + it('should throw an error when pdf failed', async() => { + const tx = await models.InvoiceOut.beginTransaction({}); + const options = {transaction: tx}; + spyOn(models.InvoiceOut, 'makePdfList').and.returnValue(() => { + throw new Error('test'); + }); + + try { + await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1102, 1, 1, 1, true, options); + await tx.rollback(); + } catch (e) { + expect(e.message).toContain(`It has been invoiced but the PDF could not be generated`); + await tx.rollback(); + } + }); + + it('should not generate an invoice', async() => { + const tx = await models.InvoiceOut.beginTransaction({}); + const options = {transaction: tx}; + spyOn(models.InvoiceOut, 'makePdfList'); + + let response; + try { + response = await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1102, 1, 1, 1, false, options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(response).not.toBeDefined(); + }); }); diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index b5eb9bed5..72e647efe 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -1,3 +1,4 @@ +/* eslint max-len: ["error", { "code": 160 }]*/ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { @@ -37,13 +38,13 @@ module.exports = Self => { required: true }, { - arg: 'checked', + arg: 'makeInvoice', type: 'boolean', required: true }, ], returns: { - type: 'boolean', + type: 'object', root: true }, http: { @@ -52,11 +53,11 @@ module.exports = Self => { } }); - Self.transferInvoice = async(ctx, options) => { + Self.transferInvoice = async(ctx, id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk, makeInvoice, options) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; - const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args; - const checked = ctx.args.checked; + let invoiceId; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -102,13 +103,22 @@ module.exports = Self => { await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); - if (!checked) { - const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions); - return invoiceId; - } + if (makeInvoice) + invoiceId = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions); + + tx && await tx.commit(); } catch (e) { if (tx) await tx.rollback(); throw e; } + + if (tx && makeInvoice) { + try { + await models.InvoiceOut.makePdfList(ctx, invoiceId, null); + } catch (e) { + throw new UserError('It has been invoiced but the PDF could not be generated'); + } + } + return invoiceId; }; }; diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 0d7fb32dd..8ea4507ec 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -158,7 +158,7 @@ class Controller extends Section { cplusRectificationTypeFk: this.cplusRectificationType, siiTypeInvoiceOutFk: this.siiTypeInvoiceOut, invoiceCorrectionTypeFk: this.invoiceCorrectionType, - checked: this.checked + makeInvoice: this.checked }; this.$http.get(`Clients/${this.clientId}`).then(response => { diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index 77c40d8a0..fa1079fbe 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -135,6 +135,7 @@ module.exports = Self => { const now = Date.vnNew(); const ticket = await models.Ticket.findById(ticketId, null, myOptions); + if (!ctx.args) ctx.args = {}; ctx.args.clientId = ticket.clientFk; ctx.args.shipped = now; ctx.args.landed = now; From 788f334e704a1347af0eb4dc3fa92e6a9592c539 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 31 May 2024 09:29:47 +0200 Subject: [PATCH 03/22] intros --- .../invoiceOut/specs/transferinvoice.spec.js | 12 ++++++++++-- .../back/methods/invoiceOut/transferInvoice.js | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js index cf656f6da..22787e730 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js @@ -1,4 +1,3 @@ -/* eslint max-len: ["error", { "code": 150 }]*/ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); @@ -29,7 +28,16 @@ describe('InvoiceOut transferInvoice()', () => { try { const {clientFk: oldClient} = await models.InvoiceOut.findById(id, {fields: ['clientFk']}); const invoicesBefore = await models.InvoiceOut.find({}, options); - const result = await models.InvoiceOut.transferInvoice(ctx, id, 'T4444444', newClient, 1, 1, 1, true, options); + const result = await models.InvoiceOut.transferInvoice( + ctx, + id, + 'T4444444', + newClient, + 1, + 1, + 1, + true, + options); const invoicesAfter = await models.InvoiceOut.find({}, options); const rectificativeInvoice = invoicesAfter[invoicesAfter.length - 2]; const newInvoice = invoicesAfter[invoicesAfter.length - 1]; diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index 72e647efe..f5530d772 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -1,4 +1,3 @@ -/* eslint max-len: ["error", { "code": 160 }]*/ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { @@ -53,7 +52,17 @@ module.exports = Self => { } }); - Self.transferInvoice = async(ctx, id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk, makeInvoice, options) => { + Self.transferInvoice = async( + ctx, + id, + refFk, + newClientFk, + cplusRectificationTypeFk, + siiTypeInvoiceOutFk, + invoiceCorrectionTypeFk, + makeInvoice, + options + ) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; let invoiceId; From 340a8c119ecb48cd8eeac87f76975405a2b71e42 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 3 Jun 2024 09:35:44 +0200 Subject: [PATCH 04/22] refactor: refs #6753 fix saveSign --- modules/ticket/back/methods/ticket/saveSign.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index 490b05320..b5c662089 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -140,14 +140,7 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - const deliveryState = await models.State.findOne({ - where: {code: 'DELIVERED'} - }, myOptions); - - await models.Ticket.state(ctx, { - ticketFk: ticketId, - stateFk: deliveryState.id - }, myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions); if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); From da1b4649bb59414c6bde7be4511e73e6504754e6 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 4 Jun 2024 11:58:39 +0200 Subject: [PATCH 05/22] feat: refs #4560 sin expeditionTruck --- .../11063-purpleAnthurium/02-roadmapStopGrants.sql | 4 ++-- modules/route/back/model-config.json | 3 --- modules/route/back/models/expedition-truck.json | 9 --------- modules/route/back/models/roadmapStop.json | 2 +- modules/route/back/models/routesMonitor.json | 3 --- 5 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 modules/route/back/models/expedition-truck.json diff --git a/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql b/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql index d2c8354c0..bba1c019c 100644 --- a/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql +++ b/db/versions/11063-purpleAnthurium/02-roadmapStopGrants.sql @@ -3,8 +3,8 @@ DELETE FROM salix.ACL INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES - ('roadmapAddress', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), - ('roadmapAddress', '*', 'READ', 'ALLOW', 'ROLE', 'production'), + ('RoadmapAddress', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), + ('RoadmapAddress', '*', 'READ', 'ALLOW', 'ROLE', 'production'), ('Roadmap', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), ('Roadmap', '*', 'READ', 'ALLOW', 'ROLE', 'production'), ('RoadmapStop', '*', 'WRITE', 'ALLOW', 'ROLE', 'palletizerBoss'), diff --git a/modules/route/back/model-config.json b/modules/route/back/model-config.json index c315891fd..ccae87bd9 100644 --- a/modules/route/back/model-config.json +++ b/modules/route/back/model-config.json @@ -28,8 +28,5 @@ }, "RoutesMonitor": { "dataSource": "vn" - }, - "ExpeditionTruck": { - "dataSource": "vn" } } diff --git a/modules/route/back/models/expedition-truck.json b/modules/route/back/models/expedition-truck.json deleted file mode 100644 index fc9cd90f0..000000000 --- a/modules/route/back/models/expedition-truck.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "ExpeditionTruck", - "base": "RoadmapStop", - "options": { - "mysql": { - "table": "expeditionTruck" - } - } -} diff --git a/modules/route/back/models/roadmapStop.json b/modules/route/back/models/roadmapStop.json index 527bbae98..74b02cd7a 100644 --- a/modules/route/back/models/roadmapStop.json +++ b/modules/route/back/models/roadmapStop.json @@ -36,7 +36,7 @@ }, "address": { "type": "belongsTo", - "model": "RoadmapAddress", + "model": "Address", "foreignKey": "addressFk" } } diff --git a/modules/route/back/models/routesMonitor.json b/modules/route/back/models/routesMonitor.json index 122026336..a14680b5c 100644 --- a/modules/route/back/models/routesMonitor.json +++ b/modules/route/back/models/routesMonitor.json @@ -48,9 +48,6 @@ "priority": { "type": "number" }, - "expeditionTruckFk": { - "type": "number" - }, "m3boxes": { "type": "number" }, From 4089c7deb3fbdd424ff3f8d4624673aca3f638ea Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 4 Jun 2024 12:23:28 +0200 Subject: [PATCH 06/22] feat: refs #4560 minorChanges --- db/dump/.dump/data.sql | 4 ++-- modules/route/back/locale/routesMonitor/en.yml | 1 - modules/route/back/locale/routesMonitor/es.yml | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 8bc94e76f..3f2d8e22e 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -1772,8 +1772,8 @@ INSERT INTO `ACL` VALUES (688,'ClientSms','create','WRITE','ALLOW','ROLE','emplo INSERT INTO `ACL` VALUES (689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'); INSERT INTO `ACL` VALUES (691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'); -INSERT INTO `ACL` VALUES (692,'roadmapStop','*','*','ALLOW','ROLE','production'); -INSERT INTO `ACL` VALUES (693,'roadmapStop','*','*','ALLOW','ROLE','productionBoss'); +INSERT INTO `ACL` VALUES (692,'RoadmapStop','*','*','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (693,'RoadmapStop','*','*','ALLOW','ROLE','productionBoss'); INSERT INTO `ACL` VALUES (695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'); diff --git a/modules/route/back/locale/routesMonitor/en.yml b/modules/route/back/locale/routesMonitor/en.yml index 0542ced54..c28c5cb4d 100644 --- a/modules/route/back/locale/routesMonitor/en.yml +++ b/modules/route/back/locale/routesMonitor/en.yml @@ -13,7 +13,6 @@ columns: m3: m3 priority: priority etd: etd - roadmapStopFk: truck m3boxes: m3 boxes bufferFk: buffer isPickingAllowed: is picking allowed diff --git a/modules/route/back/locale/routesMonitor/es.yml b/modules/route/back/locale/routesMonitor/es.yml index 1ea0532c6..a8e807626 100644 --- a/modules/route/back/locale/routesMonitor/es.yml +++ b/modules/route/back/locale/routesMonitor/es.yml @@ -13,7 +13,6 @@ columns: m3: m3 priority: prioridad etd: etd - roadmapStopFk: camión m3boxes: m3 cajas bufferFk: buffer isPickingAllowed: está permitido recoger From 130d2b6b47d254f6294eaf694d3e90b592431c92 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 5 Jun 2024 08:05:46 +0200 Subject: [PATCH 07/22] feat: refs #7203 remove numbres alertLevel --- db/.pullinfo.json | 2 +- .../bi/procedures/claim_ratio_routine.sql | 3 +- .../hedera/procedures/item_getVisible.sql | 19 +++---- .../procedures/order_confirmWithUser.sql | 5 +- .../stock/procedures/log_refreshSale.sql | 3 +- db/routines/vn/procedures/invoiceOut_new.sql | 8 +-- .../vn/procedures/prepareTicketList.sql | 10 ++-- .../vn/procedures/productionControl.sql | 11 +++-- .../procedures/ticketGetVisibleAvailable.sql | 7 ++- .../vn/procedures/ticketMissed_List.sql | 49 ------------------- .../procedures/ticketParking_findSkipped.sql | 30 ++++++------ .../procedures/ticketStateToday_setState.sql | 27 +++++----- .../vn/procedures/ticketStateUpdate.sql | 26 ---------- .../vn/procedures/ticket_DelayTruck.sql | 3 +- .../vn/triggers/expedition_beforeInsert.sql | 14 +++--- 15 files changed, 80 insertions(+), 137 deletions(-) delete mode 100644 db/routines/vn/procedures/ticketMissed_List.sql delete mode 100644 db/routines/vn/procedures/ticketStateUpdate.sql diff --git a/db/.pullinfo.json b/db/.pullinfo.json index 0defed845..27d2c7535 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54" + "expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345" } } } diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql index 40b879483..3cf4bf8dc 100644 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -65,11 +65,12 @@ BEGIN JOIN vn.ticketLastState ts ON ts.ticketFk = t.id JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk JOIN vn.state st ON st.id = tt.stateFk + JOIN vn.alertLevel al ON al.code = 'DELIVERED' WHERE sc.componentFk = 17 AND sc.isGreuge = 0 AND t.shipped >= '2016-10-01' AND t.shipped < util.VN_CURDATE() - AND st.alertLevel >= 3; + AND st.alertLevel >= al.id; DELETE g.* FROM vn.greuge g diff --git a/db/routines/hedera/procedures/item_getVisible.sql b/db/routines/hedera/procedures/item_getVisible.sql index 8e25eaab3..2f4ef32ab 100644 --- a/db/routines/hedera/procedures/item_getVisible.sql +++ b/db/routines/hedera/procedures/item_getVisible.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_getVisible vType INT, vPrefix VARCHAR(255)) BEGIN - + /** * Gets visible items of the specified type at specified date. * @@ -14,7 +14,7 @@ BEGIN * @param vType The type id * @param vPrefix The article prefix to filter or %NULL for all * @return tmp.itemVisible Visible items - */ + */ DECLARE vPrefixLen SMALLINT; DECLARE vFilter VARCHAR(255) DEFAULT NULL; DECLARE vDateInv DATE DEFAULT vn.getInventoryDate(); @@ -23,13 +23,13 @@ BEGIN GET DIAGNOSTICS CONDITION 1 @message = MESSAGE_TEXT; CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, + 'cau@verdnatura.es', + NULL, CONCAT('hedera.item_getVisible error: ', @message), CONCAT( - 'warehouse: ', IFNULL(vWarehouse, ''), - ', Fecha:', IFNULL(vDate, ''), - ', tipo: ', IFNULL(vType,''), + 'warehouse: ', IFNULL(vWarehouse, ''), + ', Fecha:', IFNULL(vDate, ''), + ', tipo: ', IFNULL(vType,''), ', prefijo: ', IFNULL(vPrefix,''))); RESIGNAL; END; @@ -74,9 +74,10 @@ BEGIN FROM vn.sale m JOIN vn.ticket t ON t.id = m.ticketFk JOIN vn.ticketState s ON s.ticketFk = t.id + JOIN vn.alertLevel al ON al.code = 'DELIVERED' WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() AND t.warehouseFk = vWarehouse - AND s.alertLevel = 3 + AND s.alertLevel = al.id ) t GROUP BY itemFk HAVING quantity > 0; @@ -108,7 +109,7 @@ BEGIN IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, CEIL(s.quantity / t.packing) etiquetas FROM vn.item i - JOIN `filter` f ON f.itemFk = i.id + JOIN `filter` f ON f.itemFk = i.id JOIN currentStock s ON s.itemFk = i.id LEFT JOIN tmp t ON t.itemFk = i.id LEFT JOIN vn.packaging p ON p.id = t.packagingFk diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql index 0aeaaf65b..9c932aaa1 100644 --- a/db/routines/hedera/procedures/order_confirmWithUser.sql +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -62,7 +62,7 @@ BEGIN END; -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, + SELECT o.date_send, o.address_id, o.note, a.clientFk, o.company_id, o.agency_id, c.isTaxDataChecked INTO vDelivery, vAddress, vNotes, vClientId, vCompanyId, vAgencyModeId, vIsTaxDataChecked @@ -121,6 +121,7 @@ BEGIN ) SELECT t.id INTO vTicket FROM vn.ticket t + JOIN vn.alertLevel al ON al.code = 'FREE' LEFT JOIN tPrevia tp ON tp.ticketFk = t.id LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id JOIN hedera.`order` o @@ -131,7 +132,7 @@ BEGIN WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL - AND IFNULL(tls.alertLevel,0) = 0 + AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) LIMIT 1; -- Crea el ticket en el caso de no existir uno adecuado diff --git a/db/routines/stock/procedures/log_refreshSale.sql b/db/routines/stock/procedures/log_refreshSale.sql index 983616dca..3054f8ecb 100644 --- a/db/routines/stock/procedures/log_refreshSale.sql +++ b/db/routines/stock/procedures/log_refreshSale.sql @@ -16,12 +16,13 @@ BEGIN m.created, TIMESTAMPADD(DAY, tp.life, t.shipped) expired, m.quantity < 0 isIn, - m.isPicked OR s.alertLevel > 1 isPicked + m.isPicked OR s.alertLevel > al.id isPicked FROM vn.sale m JOIN vn.ticket t ON t.id = m.ticketFk JOIN vn.ticketState s ON s.ticketFk = t.id JOIN vn.item i ON i.id = m.itemFk JOIN vn.itemType tp ON tp.id = i.typeFk + JOIN vn.alertLevel al ON al.code = 'ON_PREPARATION' WHERE ( vTableId IS NULL OR (vTableName = 'ticket' AND t.id = vTableId) diff --git a/db/routines/vn/procedures/invoiceOut_new.sql b/db/routines/vn/procedures/invoiceOut_new.sql index 1b486df86..42c3f99da 100644 --- a/db/routines/vn/procedures/invoiceOut_new.sql +++ b/db/routines/vn/procedures/invoiceOut_new.sql @@ -80,8 +80,8 @@ BEGIN OR t.isDeleted OR c.hasToInvoice = FALSE OR itc.id IS NULL - OR a.id IS NULL - OR (vTaxArea = 'WORLD' + OR a.id IS NULL + OR (vTaxArea = 'WORLD' AND (a.customsAgentFk IS NULL OR a.incotermsFk IS NULL)); SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 @@ -153,7 +153,9 @@ BEGIN FROM tmp.ticketToInvoice ti LEFT JOIN ticketState ts ON ti.id = ts.ticketFk JOIN state s - WHERE IFNULL(ts.alertLevel, 0) < 3 and s.`code` = getAlert3State(ti.id); + JOIN alertLevel al ON al.code = 'DELIVERED' + WHERE (ts.alertLevel IS NULL OR ts.alertLevel < al.id) + AND s.`code` = getAlert3State(ti.id); INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT * FROM tmp.updateInter; diff --git a/db/routines/vn/procedures/prepareTicketList.sql b/db/routines/vn/procedures/prepareTicketList.sql index f0f47f9a2..29c95cc9f 100644 --- a/db/routines/vn/procedures/prepareTicketList.sql +++ b/db/routines/vn/procedures/prepareTicketList.sql @@ -6,14 +6,16 @@ BEGIN (PRIMARY KEY (ticketFk)) ENGINE = MEMORY SELECT t.id ticketFk, t.clientFk - FROM vn.ticket t - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.client c ON c.id = t.clientFk + FROM ticket t + JOIN alertLevel al ON al.code = 'DELIVERED' + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + JOIN client c ON c.id = t.clientFk + WHERE c.typeFk IN ('normal','handMaking','internalUse') AND ( t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate OR ( - ts.alertLevel < 3 + ts.alertLevel < al.id AND t.shipped >= vStartingDate AND t.shipped < util.VN_CURDATE() ) diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index b42645d1e..6505473fa 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionControl`( - vWarehouseFk INT, + vWarehouseFk INT, vScopeDays INT ) proc: BEGIN @@ -67,7 +67,7 @@ proc: BEGIN wk.code salesPersonCode, p.id provinceFk, tls.productionOrder, - IFNULL(tls.alertLevel, 0) alertLevel, + IFNULL(tls.alertLevel, al.id) alertLevel, t.isBoxed palletized, IF(rm.isPickingAllowed, rm.bufferFk, NULL) ubicacion, tlu.lastUpdated, @@ -81,6 +81,7 @@ proc: BEGIN rm.bufferFk FROM tmp.productionTicket tt JOIN ticket t ON tt.ticketFk = t.id + JOIN alertLevel al ON al.code = 'FREE' LEFT JOIN ticketStateToday tst ON tst.ticketFk = t.id LEFT JOIN `state` st ON st.id = tst.state LEFT JOIN client c ON c.id = t.clientFk @@ -101,7 +102,7 @@ proc: BEGIN LEFT JOIN parking pk ON pk.id = tp.parkingFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); - + UPDATE tmp.productionBuffer pb JOIN ( SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking @@ -109,12 +110,12 @@ proc: BEGIN JOIN sale s ON s.ticketFk = pb.ticketFk JOIN saleGroupDetail sgd ON sgd.saleFk = s.id JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - JOIN parking p ON p.id = sg.parkingFk + JOIN parking p ON p.id = sg.parkingFk GROUP BY pb.ticketFk ) t ON t.ticketFk = pb.ticketFk SET pb.previaParking = t.previaParking; - -- Problemas por ticket + -- Problemas por ticket ALTER TABLE tmp.productionBuffer CHANGE COLUMN `problem` `problem` VARCHAR(255), ADD COLUMN `collectionH` INT, diff --git a/db/routines/vn/procedures/ticketGetVisibleAvailable.sql b/db/routines/vn/procedures/ticketGetVisibleAvailable.sql index 07dfa69e5..3717d57e3 100644 --- a/db/routines/vn/procedures/ticketGetVisibleAvailable.sql +++ b/db/routines/vn/procedures/ticketGetVisibleAvailable.sql @@ -7,13 +7,16 @@ BEGIN DECLARE vShipped DATE; DECLARE vWarehouse TINYINT; DECLARE vAlertLevel INT; + DECLARE vAlertLevelFree INT; - SELECT t.warehouseFk, t.shipped, ts.alertLevel INTO vWarehouse, vShipped, vAlertLevel + SELECT t.warehouseFk, t.shipped, ts.alertLevel, al.id + INTO vWarehouse, vShipped, vAlertLevel, vAlertLevelFree FROM ticket t + JOIN alertLevel al ON al.code = 'FREE' LEFT JOIN ticketState ts ON ts.ticketFk = vTicket WHERE t.id = vTicket; - IF vAlertLevel IS NULL OR vAlertLevel = 0 THEN + IF vAlertLevel IS NULL OR vAlertLevel = vAlertLevelFree THEN IF vShipped >= util.VN_CURDATE() THEN CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped); END IF; diff --git a/db/routines/vn/procedures/ticketMissed_List.sql b/db/routines/vn/procedures/ticketMissed_List.sql deleted file mode 100644 index 6b0f66e6a..000000000 --- a/db/routines/vn/procedures/ticketMissed_List.sql +++ /dev/null @@ -1,49 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketMissed_List`(vTicketFk INT) -BEGIN - - DECLARE vParkingFk INT; - DECLARE vParked DATETIME; - DECLARE vLevel INT; - DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) - INTO vLevel, vCollectionFk - FROM vn.ticketCollection - WHERE ticketFk = vTicketFk - LIMIT 1; - - SELECT created, parkingFk - INTO vParked, vParkingFk - FROM vn.ticketParking - WHERE ticketFk = vTicketFk; - - SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia - FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector sc ON sc.id = p.sectorFk - LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.zone z ON z.id = t.zoneFk - JOIN vn.agencyMode am ON am.id = z.agencyModeFk - JOIN vn.state s ON s.id = tst.state - WHERE (s.alertLevel < 2 - AND tp.parkingFk = vParkingFk - AND sc.isPackagingArea - AND ( - ( - ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) - OR - ( tc.collectionFk = vCollectionFk AND LEFT(tc.level,1) < LEFT(vLevel,1) ) - ) - )) -- Etiquetas que no se han escaneado y ya estamos con una posterior - OR - (s.alertLevel > 1 - AND tp.parkingFk = vParkingFk - AND sc.isPackagingArea - AND tp.created < vParked - AND t.packages <=> 0); - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/ticketParking_findSkipped.sql b/db/routines/vn/procedures/ticketParking_findSkipped.sql index b00006ffe..ff72110c7 100644 --- a/db/routines/vn/procedures/ticketParking_findSkipped.sql +++ b/db/routines/vn/procedures/ticketParking_findSkipped.sql @@ -1,37 +1,37 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1)) BEGIN - + /** * Averigua los tickets que se han saltado por un error en el proceso encajado * @param vTicketFk Ticket * @param vItemPackingTypeFk Modo de encajado * @return un select con los tickets afectados - */ + */ DECLARE vParkingFk INT; DECLARE vParked DATETIME; DECLARE vLevel INT; DECLARE vWagon INT; DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) + + SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) INTO vLevel, vWagon, vCollectionFk FROM vn.ticketCollection tc JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk WHERE ticketFk = vTicketFk ORDER BY c.id DESC LIMIT 1; - - SELECT created, parkingFk + + SELECT created, parkingFk INTO vParked, vParkingFk FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk WHERE ticketFk = vTicketFk AND s.itemPackingTypeFk = vItemPackingTypeFk AND s.isPackagingArea ; - + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp JOIN vn.parking p ON p.id = tp.parkingFk @@ -42,23 +42,25 @@ BEGIN JOIN vn.zone z ON z.id = t.zoneFk JOIN vn.agencyMode am ON am.id = z.agencyModeFk JOIN vn.state s ON s.id = tst.state - WHERE (s.alertLevel < 2 + JOIN vn.alertLevel alPacked ON alPacked.code = 'PACKED' + JOIN vn.alertLevel alOnPreparation ON alOnPreparation.code = 'ON_PREPARATION' + WHERE (s.alertLevel < alPacked.id AND tp.parkingFk = vParkingFk AND sc.isPackagingArea AND ( ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) OR - ( tc.collectionFk = vCollectionFk + ( tc.collectionFk = vCollectionFk AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) - OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) + OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) ) ) ) -- Etiquetas que no se han escaneado y ya estamos con una posterior OR - (s.alertLevel > 1 + (s.alertLevel > alOnPreparation.id AND tp.parkingFk = vParkingFk AND sc.isPackagingArea - AND tp.created < vParked + AND tp.created < vParked AND t.packages <=> 0); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticketStateToday_setState.sql b/db/routines/vn/procedures/ticketStateToday_setState.sql index 73a92bbb5..bd79043b4 100644 --- a/db/routines/vn/procedures/ticketStateToday_setState.sql +++ b/db/routines/vn/procedures/ticketStateToday_setState.sql @@ -1,26 +1,29 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN - + /* Modifica el estado de un ticket de hoy - * + * * @param vTicketFk el id del ticket * @param vStateCode estado a modificar del ticket - * + * */ - + DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM state s - JOIN ticketStateToday tst ON tst.state = s.id + DECLARE vAlertLevelPacked INT; + + SELECT s.alertLevel, al.id + INTO vAlertLevel, vAlertLevelPacked + FROM state s + JOIN ticketStateToday tst ON tst.state = s.id + JOIN alertLevel al ON al.code = 'PACKED' WHERE tst.ticketFk = vTicketFk LIMIT 1; - - IF vAlertLevel < 2 THEN - + + IF vAlertLevel < vAlertLevelPacked THEN + CALL vn.ticket_setState(vTicketFk, vStateCode); - + END IF; END$$ diff --git a/db/routines/vn/procedures/ticketStateUpdate.sql b/db/routines/vn/procedures/ticketStateUpdate.sql deleted file mode 100644 index 4e19b7eb4..000000000 --- a/db/routines/vn/procedures/ticketStateUpdate.sql +++ /dev/null @@ -1,26 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) -BEGIN - - /* - * @deprecated:utilizar ticket_setState - */ - - DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM vn.state s - JOIN vn.ticketState ts ON ts.stateFk = s.id - WHERE ts.ticketFk = vTicketFk; - - IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN - - INSERT INTO ticketTracking(stateFk, ticketFk, userFk) - SELECT id, vTicketFk, account.myUser_getId() - FROM vn.state - WHERE `code` = vStateCode collate utf8_unicode_ci; - - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruck.sql b/db/routines/vn/procedures/ticket_DelayTruck.sql index 7a3170d68..20601ee49 100644 --- a/db/routines/vn/procedures/ticket_DelayTruck.sql +++ b/db/routines/vn/procedures/ticket_DelayTruck.sql @@ -13,10 +13,11 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticket SELECT ticketFk FROM tmp.productionBuffer + JOIN alertLevel al ON al.code = 'FREE' WHERE shipped = util.VN_CURDATE() AND problem LIKE '%I:%' AND (HH <= vHour OR HH = vHour AND mm < vMinute) - AND alertLevel = 0; + AND alertLevel = al.id; OPEN cur1; diff --git a/db/routines/vn/triggers/expedition_beforeInsert.sql b/db/routines/vn/triggers/expedition_beforeInsert.sql index 685de72cb..2e5644a19 100644 --- a/db/routines/vn/triggers/expedition_beforeInsert.sql +++ b/db/routines/vn/triggers/expedition_beforeInsert.sql @@ -4,21 +4,21 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeInse FOR EACH ROW BEGIN DECLARE intcounter INT; - DECLARE vShipFk INT; SET NEW.editorFk = account.myUser_getId(); - IF NEW.freightItemFk IS NOT NULL THEN + IF NEW.freightItemFk IS NOT NULL THEN UPDATE ticket SET packages = IFNULL(packages, 0) + 1 WHERE id = NEW.ticketFk; - SELECT IFNULL(MAX(counter),0) +1 INTO intcounter - FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id + SELECT IFNULL(MAX(counter),0) + 1 INTO intcounter + FROM expedition e + JOIN alertLevel al ON al.code = 'DELIVERED' + JOIN ticket t1 ON e.ticketFk = t1.id LEFT JOIN ticketState ts ON ts.ticketFk = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) AND t1.warehouseFk = t2.warehouseFk - WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk + WHERE t2.id = NEW.ticketFk AND ts.alertLevel < al.id AND t1.companyFk = t2.companyFk AND t1.agencyModeFk = t2.agencyModeFk; SET NEW.`counter` = intcounter; From a0e79a778df7e229eaa17da67217c3ac86b20b38 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 5 Jun 2024 09:57:15 +0200 Subject: [PATCH 08/22] feat: refs #7496 deprecated ticket.isLabeled --- db/routines/vn2008/views/Saldos_Prevision.sql | 10 ---------- db/routines/vn2008/views/Tickets.sql | 1 - db/versions/11087-aquaDendro/00-firstScript.sql | 4 ++++ 3 files changed, 4 insertions(+), 11 deletions(-) delete mode 100644 db/routines/vn2008/views/Saldos_Prevision.sql create mode 100644 db/versions/11087-aquaDendro/00-firstScript.sql diff --git a/db/routines/vn2008/views/Saldos_Prevision.sql b/db/routines/vn2008/views/Saldos_Prevision.sql deleted file mode 100644 index f4749d30f..000000000 --- a/db/routines/vn2008/views/Saldos_Prevision.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`Saldos_Prevision` -AS SELECT `fb`.`id` AS `Saldos_Prevision_id`, - `fb`.`description` AS `Descripcion`, - `fb`.`amount` AS `Importe`, - `fb`.`dated` AS `Fecha`, - `fb`.`accountingFk` AS `Id_Banco`, - `fb`.`companyFk` AS `empresa_id` -FROM `vn`.`forecastedBalance` `fb` \ No newline at end of file diff --git a/db/routines/vn2008/views/Tickets.sql b/db/routines/vn2008/views/Tickets.sql index c24b87b72..59dcb9100 100644 --- a/db/routines/vn2008/views/Tickets.sql +++ b/db/routines/vn2008/views/Tickets.sql @@ -21,7 +21,6 @@ AS SELECT `t`.`id` AS `Id_Ticket`, `t`.`workerFk` AS `Id_Trabajador`, `t`.`observations` AS `Observaciones`, `t`.`isSigned` AS `Firmado`, - `t`.`isLabeled` AS `Etiquetasemitidas`, `t`.`isPrinted` AS `PedidoImpreso`, `t`.`hour` AS `Hora`, `t`.`isBlocked` AS `blocked`, diff --git a/db/versions/11087-aquaDendro/00-firstScript.sql b/db/versions/11087-aquaDendro/00-firstScript.sql new file mode 100644 index 000000000..e53c231c3 --- /dev/null +++ b/db/versions/11087-aquaDendro/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.ticket MODIFY COLUMN IF EXISTS isLabeled__ tinyint(1) DEFAULT 0 NOT NULL COMMENT 'refs #7496 deprecated 2024-06-20'; + +ALTER TABLE IF EXISTS vn.forecastedBalance RENAME vn2008.call_information__; +ALTER TABLE IF EXISTS vn.forecastedBalance COMMENT='@deprecated 2024-05-21'; \ No newline at end of file From 1fa22e71a980afc8f1ebed895b58e6ce4b22401f Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 5 Jun 2024 12:42:55 +0200 Subject: [PATCH 09/22] feat: refs #7203 nombre variables --- .../procedures/ticketParking_findSkipped.sql | 20 +++++++++---------- .../vn/triggers/expedition_beforeInsert.sql | 6 +++--- modules/account/back/models/role-inherit.json | 3 +++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/procedures/ticketParking_findSkipped.sql b/db/routines/vn/procedures/ticketParking_findSkipped.sql index ff72110c7..7713d5b50 100644 --- a/db/routines/vn/procedures/ticketParking_findSkipped.sql +++ b/db/routines/vn/procedures/ticketParking_findSkipped.sql @@ -34,16 +34,16 @@ BEGIN SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector sc ON sc.id = p.sectorFk - LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.zone z ON z.id = t.zoneFk - JOIN vn.agencyMode am ON am.id = z.agencyModeFk - JOIN vn.state s ON s.id = tst.state - JOIN vn.alertLevel alPacked ON alPacked.code = 'PACKED' - JOIN vn.alertLevel alOnPreparation ON alOnPreparation.code = 'ON_PREPARATION' + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.zone z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + JOIN vn.state s ON s.id = tst.state + JOIN vn.alertLevel alPacked ON alPacked.code = 'PACKED' + JOIN vn.alertLevel alOnPreparation ON alOnPreparation.code = 'ON_PREPARATION' WHERE (s.alertLevel < alPacked.id AND tp.parkingFk = vParkingFk AND sc.isPackagingArea diff --git a/db/routines/vn/triggers/expedition_beforeInsert.sql b/db/routines/vn/triggers/expedition_beforeInsert.sql index 2e5644a19..e73ed9e49 100644 --- a/db/routines/vn/triggers/expedition_beforeInsert.sql +++ b/db/routines/vn/triggers/expedition_beforeInsert.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeInse BEFORE INSERT ON `expedition` FOR EACH ROW BEGIN - DECLARE intcounter INT; + DECLARE vMaxCounter INT; SET NEW.editorFk = account.myUser_getId(); @@ -11,7 +11,7 @@ BEGIN UPDATE ticket SET packages = IFNULL(packages, 0) + 1 WHERE id = NEW.ticketFk; - SELECT IFNULL(MAX(counter),0) + 1 INTO intcounter + SELECT IFNULL(MAX(counter),0) + 1 INTO vMaxCounter FROM expedition e JOIN alertLevel al ON al.code = 'DELIVERED' JOIN ticket t1 ON e.ticketFk = t1.id @@ -21,7 +21,7 @@ BEGIN WHERE t2.id = NEW.ticketFk AND ts.alertLevel < al.id AND t1.companyFk = t2.companyFk AND t1.agencyModeFk = t2.agencyModeFk; - SET NEW.`counter` = intcounter; + SET NEW.`counter` = vMaxCounter; END IF; END$$ DELIMITER ; diff --git a/modules/account/back/models/role-inherit.json b/modules/account/back/models/role-inherit.json index a89f47b77..30d526471 100644 --- a/modules/account/back/models/role-inherit.json +++ b/modules/account/back/models/role-inherit.json @@ -1,6 +1,9 @@ { "name": "RoleInherit", "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "account.roleInherit" From a33f14ffa57e8416205eae2aefce2ef253983a18 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 5 Jun 2024 12:44:28 +0200 Subject: [PATCH 10/22] feat(transferInvoice): makePdf of refund --- loopback/locale/en.json | 4 +++- loopback/locale/es.json | 3 ++- loopback/locale/fr.json | 3 ++- loopback/locale/pt.json | 3 ++- .../back/methods/invoiceOut/transferInvoice.js | 10 ++++++++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 48ec17535..a9b91a509 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -228,5 +228,7 @@ "InvoiceIn is already booked": "InvoiceIn is already booked", "This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency", "You can only have one PDA": "You can only have one PDA", - "It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated" + "It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated", + "It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated" + } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 169b4bc01..80261afc7 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -360,5 +360,6 @@ "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)", "This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario", "You can only have one PDA": "Solo puedes tener un PDA", - "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF" + "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", + "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono" } diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 2bb23c3fc..d3b69169f 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -357,5 +357,6 @@ "This workCenter is already assigned to this agency": "Ce centre de travail est déjà assigné à cette agence", "Select ticket or client": "Choisissez un ticket ou un client", "It was not able to create the invoice": "Il n'a pas été possible de créer la facture", - "It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré" + "It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", + "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré" } diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index 1ebcfa3de..9b5cf61bb 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -357,5 +357,6 @@ "This workCenter is already assigned to this agency": "Este centro de trabalho já está atribuído a esta agência", "Select ticket or client": "Selecione um ticket ou cliente", "It was not able to create the invoice": "Não foi possível criar a fatura", - "It has been invoiced but the PDF could not be generated": "Foi faturado, mas o PDF não pôde ser gerado" + "It has been invoiced but the PDF could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", + "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso" } diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index f5530d772..0c86e5810 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -66,6 +66,7 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; let invoiceId; + let refundId; let tx; if (typeof options == 'object') @@ -110,7 +111,7 @@ module.exports = Self => { }; const refundTicketIds = refundTickets.map(ticket => ticket.id); - await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); + refundId = await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); if (makeInvoice) invoiceId = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions); @@ -123,10 +124,15 @@ module.exports = Self => { if (tx && makeInvoice) { try { - await models.InvoiceOut.makePdfList(ctx, invoiceId, null); + await models.InvoiceOut.makePdfList(ctx, invoiceId); } catch (e) { throw new UserError('It has been invoiced but the PDF could not be generated'); } + try { + await models.InvoiceOut.makePdfList(ctx, refundId); + } catch (e) { + throw new UserError('It has been invoiced but the PDF of refund not be generated'); + } } return invoiceId; }; From 40d40bd0bb9ef171ddd8b4e5633964938bbef314 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 5 Jun 2024 13:42:21 +0200 Subject: [PATCH 11/22] fix: refs #7335 hotFix cmrTicket --- db/routines/vn/triggers/ticket_afterUpdate.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/ticket_afterUpdate.sql b/db/routines/vn/triggers/ticket_afterUpdate.sql index 0ce13e0a5..1c0a8be67 100644 --- a/db/routines/vn/triggers/ticket_afterUpdate.sql +++ b/db/routines/vn/triggers/ticket_afterUpdate.sql @@ -8,7 +8,9 @@ BEGIN SET hasNewRoute = TRUE WHERE ticketFk = NEW.id; - CALL ticket_doCmr(NEW.id); + IF NEW.cmrFk THEN + CALL ticket_doCmr(NEW.id); + END IF; END IF; END$$ DELIMITER ; From 71ea1d1467af533a0d987908a90c88dfa79baa9d Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 5 Jun 2024 14:53:59 +0200 Subject: [PATCH 12/22] refs #7536 modify itemShelvingRadar --- db/routines/vn/procedures/itemShelvingRadar.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelvingRadar.sql b/db/routines/vn/procedures/itemShelvingRadar.sql index 7875c4791..aa95d0503 100644 --- a/db/routines/vn/procedures/itemShelvingRadar.sql +++ b/db/routines/vn/procedures/itemShelvingRadar.sql @@ -49,7 +49,7 @@ BEGIN ish.isChecked, sub.isAllChecked FROM itemShelvingStock iss - JOIN itemShelving ish ON ish.shelvingFk = iss.shelvingFk + JOIN itemShelving ish ON ish.id = iss.itemShelvingFk LEFT JOIN ( SELECT itemFk, IF( From 638a5e9a1e6b379638ed55484b03b2e3f936d439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 5 Jun 2024 15:44:11 +0200 Subject: [PATCH 13/22] Hotfix modificar entradas contabilizadas Ticket 191417 --- .../vn/procedures/entry_checkBooked.sql | 22 ----------------- .../vn/procedures/entry_isEditable.sql | 24 +++++++++++++++++++ db/routines/vn/triggers/buy_beforeDelete.sql | 2 +- db/routines/vn/triggers/buy_beforeInsert.sql | 2 +- db/routines/vn/triggers/buy_beforeUpdate.sql | 2 +- .../vn/triggers/entry_beforeDelete.sql | 2 +- .../vn/triggers/entry_beforeUpdate.sql | 2 +- 7 files changed, 29 insertions(+), 27 deletions(-) delete mode 100644 db/routines/vn/procedures/entry_checkBooked.sql create mode 100644 db/routines/vn/procedures/entry_isEditable.sql diff --git a/db/routines/vn/procedures/entry_checkBooked.sql b/db/routines/vn/procedures/entry_checkBooked.sql deleted file mode 100644 index 7ee1fee22..000000000 --- a/db/routines/vn/procedures/entry_checkBooked.sql +++ /dev/null @@ -1,22 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkBooked`( - vSelf INT -) -BEGIN -/** - * Comprueba si una entrada está contabilizada, - * y si lo está retorna un throw. - * - * @param vSelf Id de entrada - */ - DECLARE vIsBooked BOOL; - - SELECT isBooked INTO vIsBooked - FROM `entry` - WHERE id = vSelf; - - IF vIsBooked AND NOT IFNULL(@isModeInventory, FALSE) THEN - CALL util.throw('Entry is already booked'); - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/entry_isEditable.sql b/db/routines/vn/procedures/entry_isEditable.sql new file mode 100644 index 000000000..75e7d9c13 --- /dev/null +++ b/db/routines/vn/procedures/entry_isEditable.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_isEditable`( + vSelf INT +) +BEGIN +/** + * Comprueba si una entrada se puede actualizar + * si no se puede retorna un throw. + * + * @param vSelf Id de entrada + */ + DECLARE vIsEditable BOOL; + + SELECT e.isBooked INTO vIsEditable + FROM `entry` e + JOIN entryType et ON et.code = e.typeFk + WHERE NOT et.isInformal + AND id = vSelf; + + IF vIsEditable AND NOT IFNULL(@isModeInventory, FALSE) THEN + CALL util.throw('Entry is not editable'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_beforeDelete.sql b/db/routines/vn/triggers/buy_beforeDelete.sql index 85f1cf298..1bbeadec9 100644 --- a/db/routines/vn/triggers/buy_beforeDelete.sql +++ b/db/routines/vn/triggers/buy_beforeDelete.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeDelete` BEFORE DELETE ON `buy` FOR EACH ROW BEGIN - CALL entry_checkBooked(OLD.entryFk); + CALL entry_isEditable(OLD.entryFk); IF OLD.printedStickers <> 0 THEN CALL util.throw("it is not possible to delete buys with printed labels "); END IF; diff --git a/db/routines/vn/triggers/buy_beforeInsert.sql b/db/routines/vn/triggers/buy_beforeInsert.sql index 6ad72916b..39befcaf1 100644 --- a/db/routines/vn/triggers/buy_beforeInsert.sql +++ b/db/routines/vn/triggers/buy_beforeInsert.sql @@ -15,7 +15,7 @@ trig: BEGIN LEAVE trig; END IF; - CALL entry_checkBooked(NEW.entryFk); + CALL entry_isEditable(NEW.entryFk); IF NEW.printedStickers <> 0 THEN CALL util.throw('it is not possible to create buy lines with printedstickers other than 0'); END IF; diff --git a/db/routines/vn/triggers/buy_beforeUpdate.sql b/db/routines/vn/triggers/buy_beforeUpdate.sql index 2403091c6..dc999095b 100644 --- a/db/routines/vn/triggers/buy_beforeUpdate.sql +++ b/db/routines/vn/triggers/buy_beforeUpdate.sql @@ -13,7 +13,7 @@ trig:BEGIN LEAVE trig; END IF; - CALL entry_checkBooked(OLD.entryFk); + CALL entry_isEditable(OLD.entryFk); SET NEW.editorFk = account.myUser_getId(); SELECT defaultEntry INTO vDefaultEntry diff --git a/db/routines/vn/triggers/entry_beforeDelete.sql b/db/routines/vn/triggers/entry_beforeDelete.sql index 1d2c84b9e..5b83daf77 100644 --- a/db/routines/vn/triggers/entry_beforeDelete.sql +++ b/db/routines/vn/triggers/entry_beforeDelete.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeDelete` BEFORE DELETE ON `entry` FOR EACH ROW BEGIN - CALL entry_checkBooked(OLD.id); + CALL entry_isEditable(OLD.id); DELETE FROM buy WHERE entryFk = OLD.id; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index d56db5e01..9b0d8f083 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -9,7 +9,7 @@ BEGIN DECLARE vTotalBuy INT; IF NEW.isBooked = OLD.isBooked THEN - CALL entry_checkBooked(OLD.id); + CALL entry_isEditable(OLD.id); ELSE IF NEW.isBooked THEN SELECT COUNT(*) INTO vTotalBuy From b78ef97813591c29cdbf925da2370fb7312d2c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 5 Jun 2024 15:50:16 +0200 Subject: [PATCH 14/22] Hotfix modificar entradas contabilizadas Ticket 191417 --- db/routines/vn/procedures/entry_isEditable.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_isEditable.sql b/db/routines/vn/procedures/entry_isEditable.sql index 75e7d9c13..a05a1fd92 100644 --- a/db/routines/vn/procedures/entry_isEditable.sql +++ b/db/routines/vn/procedures/entry_isEditable.sql @@ -15,7 +15,7 @@ BEGIN FROM `entry` e JOIN entryType et ON et.code = e.typeFk WHERE NOT et.isInformal - AND id = vSelf; + AND e.id = vSelf; IF vIsEditable AND NOT IFNULL(@isModeInventory, FALSE) THEN CALL util.throw('Entry is not editable'); From 268c0a984cfb9e4b0b2b1b8c0db12fe51bd34480 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 6 Jun 2024 12:28:34 +0200 Subject: [PATCH 15/22] feat isScanned refs #7276 --- db/.pullinfo.json | 2 +- db/versions/11089-blueMastic/00-firstScript.sql | 5 +++++ .../expedition-state/addExpeditionState.js | 2 ++ .../ticket/back/models/expedition-state.json | 17 ++++++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 db/versions/11089-blueMastic/00-firstScript.sql diff --git a/db/.pullinfo.json b/db/.pullinfo.json index 0defed845..27d2c7535 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54" + "expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345" } } } diff --git a/db/versions/11089-blueMastic/00-firstScript.sql b/db/versions/11089-blueMastic/00-firstScript.sql new file mode 100644 index 000000000..a3a92c56c --- /dev/null +++ b/db/versions/11089-blueMastic/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.expeditionState ADD isScanned tinyint(1) DEFAULT false NOT NULL; diff --git a/modules/ticket/back/methods/expedition-state/addExpeditionState.js b/modules/ticket/back/methods/expedition-state/addExpeditionState.js index 8eab1a838..80d74ee92 100644 --- a/modules/ticket/back/methods/expedition-state/addExpeditionState.js +++ b/modules/ticket/back/methods/expedition-state/addExpeditionState.js @@ -44,11 +44,13 @@ module.exports = Self => { const typeFk = expeditionStateType.id; expeditionId = expedition.expeditionFk; + const isScannedExpedition = expedition.isScanned ?? false; await models.ExpeditionState.create({ expeditionFk: expedition.expeditionFk, typeFk, userFk: userId, + isScanned: isScannedExpedition, }, myOptions); } diff --git a/modules/ticket/back/models/expedition-state.json b/modules/ticket/back/models/expedition-state.json index eda0f79fd..159a9275e 100644 --- a/modules/ticket/back/models/expedition-state.json +++ b/modules/ticket/back/models/expedition-state.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "expeditionState" + "table": "expeditionState" } }, "properties": { @@ -23,13 +23,16 @@ }, "userFk": { "type": "number" + }, + "isScanned": { + "type": "boolean" } }, "relations": { - "expeditionStateType": { - "type": "belongsTo", - "model": "ExpeditionStateType", - "foreignKey": "typeFk" - } + "expeditionStateType": { + "type": "belongsTo", + "model": "ExpeditionStateType", + "foreignKey": "typeFk" + } } -} +} \ No newline at end of file From 5a6e2a2b31a1a5a52ac952787f0607d851ca94bc Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 6 Jun 2024 15:45:39 +0200 Subject: [PATCH 16/22] fix: refs #6942 create invoiceIn acl --- db/versions/11090-silverErica/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/11090-silverErica/00-firstScript.sql diff --git a/db/versions/11090-silverErica/00-firstScript.sql b/db/versions/11090-silverErica/00-firstScript.sql new file mode 100644 index 000000000..ec4959de9 --- /dev/null +++ b/db/versions/11090-silverErica/00-firstScript.sql @@ -0,0 +1,3 @@ +INSERT INTO salix.ACL(model,property,accessType,permission,principalType,principalId) + VALUES('InvoiceIn', 'create', 'WRITE', 'ALLOW', 'ROLE', 'administrative'), + ('InvoiceIn', 'create', 'WRITE', 'ALLOW', 'ROLE', 'buyer'); \ No newline at end of file From f7c2fd824f529fe40826c249894fe7f515e8ddf7 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 7 Jun 2024 07:05:22 +0200 Subject: [PATCH 17/22] feat: refs #7496 changesRequested --- db/versions/11087-aquaDendro/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11087-aquaDendro/00-firstScript.sql b/db/versions/11087-aquaDendro/00-firstScript.sql index e53c231c3..3490919a9 100644 --- a/db/versions/11087-aquaDendro/00-firstScript.sql +++ b/db/versions/11087-aquaDendro/00-firstScript.sql @@ -1,4 +1,4 @@ ALTER TABLE vn.ticket MODIFY COLUMN IF EXISTS isLabeled__ tinyint(1) DEFAULT 0 NOT NULL COMMENT 'refs #7496 deprecated 2024-06-20'; -ALTER TABLE IF EXISTS vn.forecastedBalance RENAME vn2008.call_information__; -ALTER TABLE IF EXISTS vn.forecastedBalance COMMENT='@deprecated 2024-05-21'; \ No newline at end of file +ALTER TABLE IF EXISTS vn.forecastedBalance RENAME vn.forecastedBalance__ ; +ALTER TABLE IF EXISTS vn.forecastedBalance__ COMMENT='@deprecated 2024-05-21'; \ No newline at end of file From 70eddb6ce2308450d3c72dd1f4a250972ee287bd Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 7 Jun 2024 08:18:07 +0200 Subject: [PATCH 18/22] refactor: refs #7419 Added index ticketLog --- db/versions/11092-azureBirch/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11092-azureBirch/00-firstScript.sql diff --git a/db/versions/11092-azureBirch/00-firstScript.sql b/db/versions/11092-azureBirch/00-firstScript.sql new file mode 100644 index 000000000..12b9d7a20 --- /dev/null +++ b/db/versions/11092-azureBirch/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX ticketLog_creationDate_IDX USING BTREE ON vn.ticketLog (creationDate,changedModel,`action`); From 7c0fa6dbb9f27bbabbd78a08612f6f6e0b1e9c14 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 7 Jun 2024 09:18:52 +0200 Subject: [PATCH 19/22] feat isScannedExpedition refs #7276 --- db/routines/vn/procedures/expedition_getFromRoute.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/expedition_getFromRoute.sql b/db/routines/vn/procedures/expedition_getFromRoute.sql index 2b4de5662..3742ef4fb 100644 --- a/db/routines/vn/procedures/expedition_getFromRoute.sql +++ b/db/routines/vn/procedures/expedition_getFromRoute.sql @@ -15,7 +15,8 @@ BEGIN t.addressFk, a.nickname, sub2.itemPackingTypeConcat, - est.code + est.code, + sub5.isScanned FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = e.ticketFk @@ -33,6 +34,11 @@ BEGIN GROUP BY sub.ticketFk ) sub2 ON sub2.ticketFk = t.id LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk + LEFT JOIN (SELECT es.expeditionFk, isScanned + FROM expeditionState es + JOIN (SELECT expeditionFk, MAX(id) maxId + FROM expeditionState es + GROUP BY expeditionFk)sub4 ON sub4.maxId = es.id)sub5 ON sub5.expeditionFk = e.id WHERE t.routeFk = vRouteFk AND e.freightItemFk <> FALSE ORDER BY r.created, t.priority DESC; END$$ From 4cf5c0775c672439c9584391cbfe2d3e04e6962e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 10 Jun 2024 07:30:33 +0200 Subject: [PATCH 20/22] feat isScannedExpedition refs #7276 --- db/routines/vn/procedures/expedition_getFromRoute.sql | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/expedition_getFromRoute.sql b/db/routines/vn/procedures/expedition_getFromRoute.sql index 3742ef4fb..2b726fa7d 100644 --- a/db/routines/vn/procedures/expedition_getFromRoute.sql +++ b/db/routines/vn/procedures/expedition_getFromRoute.sql @@ -16,7 +16,7 @@ BEGIN a.nickname, sub2.itemPackingTypeConcat, est.code, - sub5.isScanned + es.isScanned FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = e.ticketFk @@ -34,11 +34,10 @@ BEGIN GROUP BY sub.ticketFk ) sub2 ON sub2.ticketFk = t.id LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk - LEFT JOIN (SELECT es.expeditionFk, isScanned - FROM expeditionState es - JOIN (SELECT expeditionFk, MAX(id) maxId - FROM expeditionState es - GROUP BY expeditionFk)sub4 ON sub4.maxId = es.id)sub5 ON sub5.expeditionFk = e.id + LEFT JOIN expeditionState es ON es.id = ( + SELECT MAX(id) + FROM expeditionState es + WHERE expeditionFk = e.id) WHERE t.routeFk = vRouteFk AND e.freightItemFk <> FALSE ORDER BY r.created, t.priority DESC; END$$ From 2e8d28d7959d0bdab9386813812700f36964e4d5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 09:08:26 +0200 Subject: [PATCH 21/22] refactor: refs #7517 Added throw --- db/routines/vn/procedures/buy_afterUpsert.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/routines/vn/procedures/buy_afterUpsert.sql b/db/routines/vn/procedures/buy_afterUpsert.sql index 17e84177c..8af53ddfb 100644 --- a/db/routines/vn/procedures/buy_afterUpsert.sql +++ b/db/routines/vn/procedures/buy_afterUpsert.sql @@ -47,6 +47,9 @@ BEGIN WHERE e.id = vEntryFk; IF vIsMerchandise THEN + IF vWarehouse IS NULL THEN + CALL util.throw('The entry does not have travel'); + END IF; REPLACE itemCost SET itemFk = vItemFk, From ca7d67451b23bc95a586103e0e6f9b5310c5e97d Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 10 Jun 2024 09:09:11 +0200 Subject: [PATCH 22/22] refactor: refs #7517 Minor changes --- db/routines/vn/procedures/buy_afterUpsert.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/buy_afterUpsert.sql b/db/routines/vn/procedures/buy_afterUpsert.sql index 8af53ddfb..76f60d1e5 100644 --- a/db/routines/vn/procedures/buy_afterUpsert.sql +++ b/db/routines/vn/procedures/buy_afterUpsert.sql @@ -1,5 +1,7 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_afterUpsert`(vSelf INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_afterUpsert`( + vSelf INT +) BEGIN /** * Triggered actions when a buy is updated or inserted. @@ -16,7 +18,7 @@ BEGIN DECLARE vIsFeedStock BOOL; DECLARE vWeight DECIMAL(10,2); DECLARE vPacking INT; - + SELECT b.entryFk, b.itemFk, i.packingOut, @@ -51,7 +53,7 @@ BEGIN CALL util.throw('The entry does not have travel'); END IF; - REPLACE itemCost SET + REPLACE itemCost SET itemFk = vItemFk, warehouseFk = vWarehouse, cm3 = buy_getUnitVolume(vSelf), @@ -77,7 +79,7 @@ BEGIN WHERE b.id = vSelf; END IF; - CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck + CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck SELECT vSelf id; CALL buy_checkItem(); END$$