231801_test_to_master #1519

Merged
alexm merged 490 commits from 231801_test_to_master into master 2023-05-12 06:29:59 +00:00
2 changed files with 61 additions and 125 deletions
Showing only changes of commit cebab42b47 - Show all commits

View File

@ -1,12 +1,5 @@
DROP TABLE IF EXISTS `vn`.`dmsRecover`; DROP TABLE IF EXISTS `vn`.`dmsRecover`;
DROP PROCEDURE IF EXISTS `vn`.`route_getTickets`;
ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk;
ALTER TABLE `vn`.`delivery` DROP CONSTRAINT delivery_ticketFk_FK;
ALTER TABLE `vn`.`delivery` DROP COLUMN ticketFk;
ALTER TABLE `vn`.`delivery` ADD ticketFk INT DEFAULT NULL;
ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`);
DROP PROCEDURE IF EXISTS vn.route_getTickets;
DELIMITER $$ DELIMITER $$
$$ $$
@ -17,54 +10,67 @@ BEGIN
* de sus tickets. * de sus tickets.
* *
* @param vRouteFk * @param vRouteFk
*
* @select Información de los tickets * @select Información de los tickets
*/ */
SELECT *
SELECT FROM (
t.id Id, SELECT t.id Id,
t.clientFk Client, t.clientFk Client,
a.id Address, a.id Address,
t.packages Packages, a.nickname ClientName,
a.street AddressName, t.packages Packages,
a.postalCode PostalCode, a.street AddressName,
a.city City, a.postalCode PostalCode,
sub2.itemPackingTypeFk PackingType, a.city City,
c.phone ClientPhone, sub2.itemPackingTypeFk PackingType,
c.mobile ClientMobile, c.phone ClientPhone,
a.phone AddressPhone, c.mobile ClientMobile,
a.mobile AddressMobile, a.phone AddressPhone,
d.longitude Longitude, a.mobile AddressMobile,
d.latitude Latitude, d.longitude Longitude,
wm.mediaValue SalePersonPhone, d.latitude Latitude,
tob.Note Note, wm.mediaValue SalePersonPhone,
t.isSigned Signed tob.description Note,
FROM ticket t t.isSigned Signed,
JOIN client c ON t.clientFk = c.id t.priority
JOIN address a ON t.addressFk = a.id FROM ticket t
LEFT JOIN delivery d ON t.id = d.ticketFk JOIN client c ON t.clientFk = c.id
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk JOIN address a ON t.addressFk = a.id
LEFT JOIN LEFT JOIN delivery d ON d.ticketFk = t.id
(SELECT tob.description Note, t.id LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
FROM ticketObservation tob LEFT JOIN(
JOIN ticket t ON tob.ticketFk = t.id SELECT tob.description, t.id
JOIN observationType ot ON ot.id = tob.observationTypeFk FROM ticketObservation tob
WHERE t.routeFk = vRouteFk JOIN ticket t ON tob.ticketFk = t.id
AND ot.code = 'delivery' JOIN observationType ot ON ot.id = tob.observationTypeFk
)tob ON tob.id = t.id WHERE t.routeFk = vRouteFk
LEFT JOIN AND ot.code = 'delivery'
(SELECT sub.ticketFk, )tob ON tob.id = t.id
CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk LEFT JOIN(
FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items SELECT sub.ticketFk,
FROM ticket t CONCAT('(',
JOIN sale s ON s.ticketFk = t.id GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk
JOIN item i ON i.id = s.itemFk ORDER BY sub.items DESC SEPARATOR ','),
WHERE t.routeFk = vRouteFk ') ') itemPackingTypeFk
GROUP BY t.id,i.itemPackingTypeFk)sub FROM (
GROUP BY sub.ticketFk SELECT s.ticketFk, i.itemPackingTypeFk, COUNT(*) items
) sub2 ON sub2.ticketFk = t.id FROM ticket t
WHERE t.routeFk = vRouteFk JOIN sale s ON s.ticketFk = t.id
GROUP BY t.id JOIN item i ON i.id = s.itemFk
ORDER BY t.priority; 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$$ END$$
DELIMITER ; DELIMITER ;
ALTER TABLE `vn`.`delivery` DROP COLUMN ticketFk;
ALTER TABLE `vn`.`delivery` ADD ticketFk INT DEFAULT NULL;
ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`);

View File

@ -1,70 +0,0 @@
DROP TABLE IF EXISTS `vn`.`dmsRecover`;
ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk;
ALTER TABLE `vn`.`delivery` DROP CONSTRAINT delivery_ticketFk_FK;
ALTER TABLE `vn`.`delivery` DROP COLUMN ticketFk;
ALTER TABLE `vn`.`delivery` ADD ticketFk INT DEFAULT NULL;
ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`);
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 ;