From d5d18d537633716f6c09cc2005d89c4f0dd4f0a5 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Apr 2023 11:02:08 +0200 Subject: [PATCH] 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 ;