Merge pull request 'hotfix delivery' (!1457) from hotfix-delivery-231401 into test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1457 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
cebab42b47
|
@ -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,14 +10,14 @@ 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,
|
||||||
|
a.nickname ClientName,
|
||||||
t.packages Packages,
|
t.packages Packages,
|
||||||
a.street AddressName,
|
a.street AddressName,
|
||||||
a.postalCode PostalCode,
|
a.postalCode PostalCode,
|
||||||
|
@ -37,34 +30,47 @@ BEGIN
|
||||||
d.longitude Longitude,
|
d.longitude Longitude,
|
||||||
d.latitude Latitude,
|
d.latitude Latitude,
|
||||||
wm.mediaValue SalePersonPhone,
|
wm.mediaValue SalePersonPhone,
|
||||||
tob.Note Note,
|
tob.description Note,
|
||||||
t.isSigned Signed
|
t.isSigned Signed,
|
||||||
|
t.priority
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN client c ON t.clientFk = c.id
|
JOIN client c ON t.clientFk = c.id
|
||||||
JOIN address a ON t.addressFk = a.id
|
JOIN address a ON t.addressFk = a.id
|
||||||
LEFT JOIN delivery d ON t.id = d.ticketFk
|
LEFT JOIN delivery d ON d.ticketFk = t.id
|
||||||
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
|
LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
|
||||||
LEFT JOIN
|
LEFT JOIN(
|
||||||
(SELECT tob.description Note, t.id
|
SELECT tob.description, t.id
|
||||||
FROM ticketObservation tob
|
FROM ticketObservation tob
|
||||||
JOIN ticket t ON tob.ticketFk = t.id
|
JOIN ticket t ON tob.ticketFk = t.id
|
||||||
JOIN observationType ot ON ot.id = tob.observationTypeFk
|
JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||||
WHERE t.routeFk = vRouteFk
|
WHERE t.routeFk = vRouteFk
|
||||||
AND ot.code = 'delivery'
|
AND ot.code = 'delivery'
|
||||||
)tob ON tob.id = t.id
|
)tob ON tob.id = t.id
|
||||||
LEFT JOIN
|
LEFT JOIN(
|
||||||
(SELECT sub.ticketFk,
|
SELECT sub.ticketFk,
|
||||||
CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk
|
CONCAT('(',
|
||||||
FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items
|
GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk
|
||||||
|
ORDER BY sub.items DESC SEPARATOR ','),
|
||||||
|
') ') itemPackingTypeFk
|
||||||
|
FROM (
|
||||||
|
SELECT s.ticketFk, i.itemPackingTypeFk, COUNT(*) items
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
WHERE t.routeFk = vRouteFk
|
WHERE t.routeFk = vRouteFk
|
||||||
GROUP BY t.id,i.itemPackingTypeFk)sub
|
GROUP BY t.id, i.itemPackingTypeFk
|
||||||
|
)sub
|
||||||
GROUP BY sub.ticketFk
|
GROUP BY sub.ticketFk
|
||||||
) sub2 ON sub2.ticketFk = t.id
|
)sub2 ON sub2.ticketFk = t.id
|
||||||
WHERE t.routeFk = vRouteFk
|
WHERE t.routeFk = vRouteFk
|
||||||
GROUP BY t.id
|
ORDER BY d.id DESC
|
||||||
ORDER BY t.priority;
|
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`);
|
||||||
|
|
|
@ -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 ;
|
|
Loading…
Reference in New Issue