From 0bfa4c54aac1e41c3590d1c19ed5f7cb8d3debe4 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 4 Apr 2023 09:52:46 +0200 Subject: [PATCH 1/7] fix: inserta en workerTimeControlMail --- modules/worker/back/methods/worker-time-control/sendMail.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 579a83112..4962e96f8 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -332,6 +332,12 @@ module.exports = Self => { const lastDay = days[index][days[index].length - 1]; if (day.workerFk != previousWorkerFk || day == lastDay) { + await models.WorkerTimeControlMail.create({ + workerFk: previousWorkerFk, + year: args.year, + week: args.week + }, myOptions); + const salix = await models.Url.findOne({ where: { appName: 'salix', From 0372d44415a7015d0a9bed40b8cc37146db3a6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Apr 2023 15:00:28 +0200 Subject: [PATCH 2/7] fixes #5529 Fixes: missing awaits, buffer-to-file --- .../back/methods/invoiceOut/createPdf.js | 4 +- .../front/global-invoicing/index.js | 23 ++++--- .../front/global-invoicing/locale/es.yml | 3 +- modules/ticket/back/methods/ticket/closure.js | 2 +- print/core/cluster.js | 60 +++++++++---------- print/core/report.js | 39 ++++++------ print/core/storage.js | 16 +---- 7 files changed, 72 insertions(+), 75 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js index e56516237..23b6c9e04 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js @@ -56,7 +56,7 @@ module.exports = Self => { reference: invoiceOut.ref, recipientId: invoiceOut.clientFk }); - const stream = await invoiceReport.toPdfStream(); + const buffer = await invoiceReport.toPdfStream(); const issued = invoiceOut.issued; const year = issued.getFullYear().toString(); @@ -66,7 +66,7 @@ module.exports = Self => { const fileName = `${year}${invoiceOut.ref}.pdf`; // Store invoice - print.storage.write(stream, { + await print.storage.write(buffer, { type: 'invoice', path: `${year}/${month}/${day}`, fileName: fileName diff --git a/modules/invoiceOut/front/global-invoicing/index.js b/modules/invoiceOut/front/global-invoicing/index.js index 0ac0223b4..0aa6a4a24 100644 --- a/modules/invoiceOut/front/global-invoicing/index.js +++ b/modules/invoiceOut/front/global-invoicing/index.js @@ -100,16 +100,23 @@ class Controller extends Section { }; this.$http.post(`InvoiceOuts/invoiceClient`, params) + .then(() => this.invoiceNext()) .catch(res => { - this.errors.unshift({ - address, - message: res.data.error.message - }); + const message = res.data?.error?.message || res.message; + if (res.status >= 400 && res.status < 500) { + this.errors.unshift({address, message}); + this.invoiceNext(); + } else { + this.invoicing = false; + this.status = 'done'; + throw new UserError(`Critical invoicing error, proccess stopped`); + } }) - .finally(() => { - this.addressIndex++; - this.invoiceOut(); - }); + } + + invoiceNext() { + this.addressIndex++; + this.invoiceOut(); } get nAddresses() { diff --git a/modules/invoiceOut/front/global-invoicing/locale/es.yml b/modules/invoiceOut/front/global-invoicing/locale/es.yml index 242b5a93f..5b1f7e883 100644 --- a/modules/invoiceOut/front/global-invoicing/locale/es.yml +++ b/modules/invoiceOut/front/global-invoicing/locale/es.yml @@ -17,4 +17,5 @@ Ended process: Proceso finalizado Invoice out: Facturar One client: Un solo cliente Choose a valid client: Selecciona un cliente válido -Stop: Parar \ No newline at end of file +Stop: Parar +Critical invoicing error, proccess stopped: Error crítico al facturar, proceso detenido \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index d5fa58e7b..9b3355d6c 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -46,7 +46,7 @@ module.exports = async function(Self, tickets, reqArgs = {}) { const fileName = `${year}${invoiceOut.ref}.pdf`; // Store invoice - storage.write(stream, { + await storage.write(stream, { type: 'invoice', path: `${year}/${month}/${day}`, fileName: fileName diff --git a/print/core/cluster.js b/print/core/cluster.js index 23b3d88e9..d54044fa2 100644 --- a/print/core/cluster.js +++ b/print/core/cluster.js @@ -4,40 +4,38 @@ const {cpus} = require('os'); module.exports = { init() { - if (!this.pool) { - Cluster.launch({ - concurrency: Cluster.CONCURRENCY_CONTEXT, - maxConcurrency: cpus().length, - puppeteerOptions: { - headless: true, - args: [ - '--no-sandbox', - '--disable-setuid-sandbox', - '--no-zygote' - ] - } - }) - .then(cluster => { - this.pool = cluster; + if (this.pool) return; + Cluster.launch({ + concurrency: Cluster.CONCURRENCY_CONTEXT, + maxConcurrency: cpus().length, + puppeteerOptions: { + headless: true, + args: [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--no-zygote' + ] + } + }).then(cluster => { + this.pool = cluster; - log4js.configure({ - appenders: { - out: {type: 'stdout'} - }, - categories: {default: {appenders: ['out'], level: 'info'}}, - }); + log4js.configure({ + appenders: { + out: {type: 'stdout'} + }, + categories: {default: {appenders: ['out'], level: 'info'}}, + }); - const logger = log4js.getLogger(); + const logger = log4js.getLogger(); - cluster.on('taskerror', (err, data, willRetry) => { - if (willRetry) - logger.warn(`[Print] => ${err.message}\nThis job will be retried`); - else - logger.error(`[Print] => ${err.message}`); - }); + cluster.on('taskerror', (err, data, willRetry) => { + if (willRetry) + logger.warn(`[Print] => ${err.message}\nThis job will be retried`); + else + logger.error(`[Print] => ${err.message}`); + }); - cluster.on('queue', () => logger.info('Printing task initialized by pool')); - }); - } + cluster.on('queue', () => logger.info('Printing task initialized by pool')); + }); } }; diff --git a/print/core/report.js b/print/core/report.js index c5182d1a8..23cffac2c 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -32,28 +32,31 @@ class Report extends Component { if (fs.existsSync(fullPath)) options = require(optionsPath); - return new Promise(resolve => { + return new Promise((resolve, reject) => { Cluster.pool.queue({}, async({page}) => { - await page.emulateMediaType('screen'); - await page.setContent(template); + try { + await page.emulateMediaType('screen'); + await page.setContent(template); - const element = await page.$('#pageFooter'); + const element = await page.$('#pageFooter'); - let footer = '\n'; - if (element) { - footer = await page.evaluate(el => { - const html = el.innerHTML; - el.remove(); - return html; - }, element); + let footer = '\n'; + if (element) { + footer = await page.evaluate(el => { + const html = el.innerHTML; + el.remove(); + return html; + }, element); + } + + options.headerTemplate = '\n'; + options.footerTemplate = footer; + + const buffer = await page.pdf(options); + resolve(buffer); + } catch (err) { + reject(err); } - - options.headerTemplate = '\n'; - options.footerTemplate = footer; - - const stream = await page.pdf(options); - - resolve(stream); }); }); } diff --git a/print/core/storage.js b/print/core/storage.js index 063a2fbec..66f7ce98a 100644 --- a/print/core/storage.js +++ b/print/core/storage.js @@ -3,26 +3,14 @@ const path = require('path'); const fs = require('fs-extra'); module.exports = { - async write(stream, options) { + async write(buffer, options) { const storage = config.storage[options.type]; - if (!storage) return; const src = path.join(storage.root, options.path); const fileSrc = path.join(src, options.fileName); await fs.mkdir(src, {recursive: true}); - - const writeStream = fs.createWriteStream(fileSrc); - writeStream.on('open', () => writeStream.write(stream)); - writeStream.on('finish', () => writeStream.end()); - - return new Promise(resolve => { - writeStream.on('close', () => resolve()); - }); - }, - - load(type, data) { - + await fs.writeFile(fileSrc, buffer); } }; From 6fc2867551376775dad65635ce3d1a4d39e345c8 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Apr 2023 08:05:37 +0200 Subject: [PATCH 3/7] permite decimales --- .../supplier/front/agency-term/create/index.html | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html index 29d7b9b6a..728e98146 100644 --- a/modules/supplier/front/agency-term/create/index.html +++ b/modules/supplier/front/agency-term/create/index.html @@ -22,7 +22,7 @@ value-field="id" rule> - - - - - - - \ No newline at end of file + From d5d18d537633716f6c09cc2005d89c4f0dd4f0a5 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Apr 2023 11:02:08 +0200 Subject: [PATCH 4/7] hotfix apply SQL delivery.sql --- db/changes/231202/00-delivery.sql | 74 +++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 db/changes/231202/00-delivery.sql diff --git a/db/changes/231202/00-delivery.sql b/db/changes/231202/00-delivery.sql new file mode 100644 index 000000000..3a9269183 --- /dev/null +++ b/db/changes/231202/00-delivery.sql @@ -0,0 +1,74 @@ +DROP TABLE `vn`.`dmsRecover`; + +ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; +ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; +ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; +ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); + +DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) + VALUES + ('Ticket','saveSign','WRITE','ALLOW','employee'); + +DROP PROCEDURE IF EXISTS vn.route_getTickets; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * + * @select Información de los tickets + */ + + SELECT + t.id Id, + t.clientFk Client, + a.id Address, + t.packages Packages, + a.street AddressName, + a.postalCode PostalCode, + a.city City, + sub2.itemPackingTypeFk PackingType, + c.phone ClientPhone, + c.mobile ClientMobile, + a.phone AddressPhone, + a.mobile AddressMobile, + d.longitude Longitude, + d.latitude Latitude, + wm.mediaValue SalePersonPhone, + tob.Note Note, + t.isSigned Signed + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN delivery d ON t.id = d.ticketFk + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN + (SELECT tob.description Note, t.id + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.id = t.id + LEFT JOIN + (SELECT sub.ticketFk, + CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk + FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id,i.itemPackingTypeFk)sub + GROUP BY sub.ticketFk + ) sub2 ON sub2.ticketFk = t.id + WHERE t.routeFk = vRouteFk + GROUP BY t.id + ORDER BY t.priority; +END$$ +DELIMITER ; From c6db5f1a4bba2389eff12fb54ced6f1bcbfc055e Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Apr 2023 12:29:09 +0200 Subject: [PATCH 5/7] hotfix apply changes procedure --- db/changes/231202/00-delivery.sql | 68 ------------------------------- db/changes/231202/01-delivery.sql | 67 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 68 deletions(-) create mode 100644 db/changes/231202/01-delivery.sql diff --git a/db/changes/231202/00-delivery.sql b/db/changes/231202/00-delivery.sql index 3a9269183..87e5119e3 100644 --- a/db/changes/231202/00-delivery.sql +++ b/db/changes/231202/00-delivery.sql @@ -4,71 +4,3 @@ ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); - -DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('Ticket','saveSign','WRITE','ALLOW','employee'); - -DROP PROCEDURE IF EXISTS vn.route_getTickets; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) -BEGIN -/** - * Pasado un RouteFk devuelve la información - * de sus tickets. - * - * @param vRouteFk - * - * @select Información de los tickets - */ - - SELECT - t.id Id, - t.clientFk Client, - a.id Address, - t.packages Packages, - a.street AddressName, - a.postalCode PostalCode, - a.city City, - sub2.itemPackingTypeFk PackingType, - c.phone ClientPhone, - c.mobile ClientMobile, - a.phone AddressPhone, - a.mobile AddressMobile, - d.longitude Longitude, - d.latitude Latitude, - wm.mediaValue SalePersonPhone, - tob.Note Note, - t.isSigned Signed - FROM ticket t - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN delivery d ON t.id = d.ticketFk - LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk - LEFT JOIN - (SELECT tob.description Note, t.id - FROM ticketObservation tob - JOIN ticket t ON tob.ticketFk = t.id - JOIN observationType ot ON ot.id = tob.observationTypeFk - WHERE t.routeFk = vRouteFk - AND ot.code = 'delivery' - )tob ON tob.id = t.id - LEFT JOIN - (SELECT sub.ticketFk, - CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk - FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.routeFk = vRouteFk - GROUP BY t.id,i.itemPackingTypeFk)sub - GROUP BY sub.ticketFk - ) sub2 ON sub2.ticketFk = t.id - WHERE t.routeFk = vRouteFk - GROUP BY t.id - ORDER BY t.priority; -END$$ -DELIMITER ; diff --git a/db/changes/231202/01-delivery.sql b/db/changes/231202/01-delivery.sql new file mode 100644 index 000000000..0815ec421 --- /dev/null +++ b/db/changes/231202/01-delivery.sql @@ -0,0 +1,67 @@ +DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) + VALUES + ('Ticket','saveSign','WRITE','ALLOW','employee'); + +DROP PROCEDURE IF EXISTS vn.route_getTickets; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * + * @select Información de los tickets + */ + + SELECT + t.id Id, + t.clientFk Client, + a.id Address, + t.packages Packages, + a.street AddressName, + a.postalCode PostalCode, + a.city City, + sub2.itemPackingTypeFk PackingType, + c.phone ClientPhone, + c.mobile ClientMobile, + a.phone AddressPhone, + a.mobile AddressMobile, + d.longitude Longitude, + d.latitude Latitude, + wm.mediaValue SalePersonPhone, + tob.Note Note, + t.isSigned Signed + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN delivery d ON t.id = d.ticketFk + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN + (SELECT tob.description Note, t.id + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.id = t.id + LEFT JOIN + (SELECT sub.ticketFk, + CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk + FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id,i.itemPackingTypeFk)sub + GROUP BY sub.ticketFk + ) sub2 ON sub2.ticketFk = t.id + WHERE t.routeFk = vRouteFk + GROUP BY t.id + ORDER BY t.priority; +END$$ +DELIMITER ; From 3ee08e030026ff93b8950daca874a9ad48f98352 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Apr 2023 12:34:26 +0200 Subject: [PATCH 6/7] changed folder --- db/changes/231202/00-delivery.sql | 68 +++++++++++++++++++ .../00-delivery.sql} | 0 2 files changed, 68 insertions(+) rename db/changes/{231202/01-delivery.sql => 231203/00-delivery.sql} (100%) diff --git a/db/changes/231202/00-delivery.sql b/db/changes/231202/00-delivery.sql index 87e5119e3..3a9269183 100644 --- a/db/changes/231202/00-delivery.sql +++ b/db/changes/231202/00-delivery.sql @@ -4,3 +4,71 @@ ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); + +DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) + VALUES + ('Ticket','saveSign','WRITE','ALLOW','employee'); + +DROP PROCEDURE IF EXISTS vn.route_getTickets; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * + * @select Información de los tickets + */ + + SELECT + t.id Id, + t.clientFk Client, + a.id Address, + t.packages Packages, + a.street AddressName, + a.postalCode PostalCode, + a.city City, + sub2.itemPackingTypeFk PackingType, + c.phone ClientPhone, + c.mobile ClientMobile, + a.phone AddressPhone, + a.mobile AddressMobile, + d.longitude Longitude, + d.latitude Latitude, + wm.mediaValue SalePersonPhone, + tob.Note Note, + t.isSigned Signed + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN delivery d ON t.id = d.ticketFk + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN + (SELECT tob.description Note, t.id + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.id = t.id + LEFT JOIN + (SELECT sub.ticketFk, + CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk + FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id,i.itemPackingTypeFk)sub + GROUP BY sub.ticketFk + ) sub2 ON sub2.ticketFk = t.id + WHERE t.routeFk = vRouteFk + GROUP BY t.id + ORDER BY t.priority; +END$$ +DELIMITER ; diff --git a/db/changes/231202/01-delivery.sql b/db/changes/231203/00-delivery.sql similarity index 100% rename from db/changes/231202/01-delivery.sql rename to db/changes/231203/00-delivery.sql From 245b0e70f47f3399681e2921c5d4ed9d7ccdef07 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Apr 2023 14:51:39 +0200 Subject: [PATCH 7/7] hotfix rollback delivery.sql --- db/changes/231204/00-rollbackDelivery.sql | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 db/changes/231204/00-rollbackDelivery.sql diff --git a/db/changes/231204/00-rollbackDelivery.sql b/db/changes/231204/00-rollbackDelivery.sql new file mode 100644 index 000000000..d7fa6b587 --- /dev/null +++ b/db/changes/231204/00-rollbackDelivery.sql @@ -0,0 +1,83 @@ +CREATE TABLE `vn`.`dmsRecover` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `ticketFk` int(11) DEFAULT NULL, + `sign` text DEFAULT NULL, + `created` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `ticketFk_idx` (`ticketFk`), + CONSTRAINT `ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=31917 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE `vn`.`delivery` ADD addressFk INT; + +DROP PROCEDURE IF EXISTS `vn`.`route_getTickets`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * @select Información de los tickets + */ +SELECT * + FROM ( + SELECT t.id Id, + t.clientFk Client, + a.id Address, + a.nickname ClientName, + t.packages Packages, + a.street AddressName, + a.postalCode PostalCode, + a.city City, + sub2.itemPackingTypeFk PackingType, + c.phone ClientPhone, + c.mobile ClientMobile, + a.phone AddressPhone, + a.mobile AddressMobile, + d.longitude Longitude, + d.latitude Latitude, + wm.mediaValue SalePersonPhone, + tob.description Note, + t.isSigned Signed, + t.priority + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN delivery d ON d.addressFk = a.id + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN( + SELECT tob.description, t.id + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.id = t.id + LEFT JOIN( + SELECT sub.ticketFk, + CONCAT('(', + GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk + ORDER BY sub.items DESC SEPARATOR ','), + ') ') itemPackingTypeFk + FROM ( + SELECT s.ticketFk, i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id, i.itemPackingTypeFk + )sub + GROUP BY sub.ticketFk + )sub2 ON sub2.ticketFk = t.id + WHERE t.routeFk = vRouteFk + ORDER BY d.id DESC + LIMIT 10000000000000000000 + )sub3 + GROUP BY sub3.id + ORDER BY sub3.priority; +END$$ +DELIMITER ;