fix: rutasAnalyzeHotFix #2119

Merged
robert merged 30 commits from rutasAnalyzeHotFix into master 2024-03-07 07:21:47 +00:00
2 changed files with 10 additions and 20 deletions

View File

@ -1,7 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`rutasAnalyze`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`rutasAnalyze`(
vYear INT, vDatedFrom DATE,
vMonth INT vDatedTo DATE
) )
BEGIN BEGIN
/** /**
@ -9,8 +9,7 @@ BEGIN
* y lo almacena en la tabla bi.rutasBoard * y lo almacena en la tabla bi.rutasBoard
*/ */
DELETE FROM rutasBoard DELETE FROM rutasBoard
WHERE YEAR(Fecha) = vYear WHERE Fecha BETWEEN vDatedFrom AND vDatedTo;
AND MONTH(Fecha) = vMonth;
-- Rellenamos la tabla con los datos de las rutas VOLUMETRICAS, especialmente con los bultos "virtuales" -- Rellenamos la tabla con los datos de las rutas VOLUMETRICAS, especialmente con los bultos "virtuales"
INSERT INTO rutasBoard( INSERT INTO rutasBoard(
@ -27,7 +26,7 @@ BEGIN
LEFT JOIN vn.`zone` z ON z.id = t.zoneFk LEFT JOIN vn.`zone` z ON z.id = t.zoneFk
JOIN vn.saleVolume sv ON sv.ticketFk = t.id JOIN vn.saleVolume sv ON sv.ticketFk = t.id
JOIN vn.expeditionBoxVol ebv ON ebv.code = 'transportBox' JOIN vn.expeditionBoxVol ebv ON ebv.code = 'transportBox'
WHERE YEAR(r.created) = vYear AND MONTH(r.created) = vMonth WHERE r.created BETWEEN vDatedFrom AND vDatedTo
AND z.isVolumetric AND z.isVolumetric
GROUP BY r.id; GROUP BY r.id;
@ -44,8 +43,7 @@ BEGIN
FROM vn.route r FROM vn.route r
JOIN vn.ticket t ON t.routeFk = r.id JOIN vn.ticket t ON t.routeFk = r.id
LEFT JOIN vn.`zone` z ON z.id = t.zoneFk LEFT JOIN vn.`zone` z ON z.id = t.zoneFk
WHERE YEAR(r.created) = vYear WHERE r.created BETWEEN vDatedFrom AND vDatedTo
AND MONTH(r.created) = vMonth
AND NOT z.isVolumetric AND NOT z.isVolumetric
GROUP BY r.id GROUP BY r.id
ON DUPLICATE KEY UPDATE Bultos = Bultos + VALUES(Bultos); ON DUPLICATE KEY UPDATE Bultos = Bultos + VALUES(Bultos);
@ -56,15 +54,13 @@ BEGIN
SELECT t.routeFk, SELECT t.routeFk,
SUM(s.quantity * sc.value) totalPractice SUM(s.quantity * sc.value) totalPractice
FROM vn.route r FROM vn.route r
JOIN vn.`time` tm ON tm.dated = r.created
JOIN vn.ticket t ON t.routeFk = r.id JOIN vn.ticket t ON t.routeFk = r.id
JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.saleComponent sc ON sc.saleFk = s.id JOIN vn.saleComponent sc ON sc.saleFk = s.id
JOIN vn.component c ON c.id = sc.componentFk JOIN vn.component c ON c.id = sc.componentFk
JOIN vn.componentType ct ON ct.id = c.typeFk JOIN vn.componentType ct ON ct.id = c.typeFk
WHERE ct.code = 'FREIGHT' WHERE ct.code = 'FREIGHT'
AND tm.`year` = vYear AND r.created BETWEEN vDatedFrom AND vDatedTo
AND tm.`month` = vMonth
GROUP BY r.id GROUP BY r.id
) sub ON sub.routeFk = r.Id_Ruta ) sub ON sub.routeFk = r.Id_Ruta
SET r.practico = IFNULL(sub.totalPractice / r.Bultos, 0); SET r.practico = IFNULL(sub.totalPractice / r.Bultos, 0);
@ -76,14 +72,12 @@ BEGIN
SUM(t.zonePrice/ ebv.ratio) / COUNT(*) averageTheoreticalVolume SUM(t.zonePrice/ ebv.ratio) / COUNT(*) averageTheoreticalVolume
FROM vn.ticket t FROM vn.ticket t
JOIN vn.route r ON r.id = t.routeFk JOIN vn.route r ON r.id = t.routeFk
JOIN vn.`time` tm ON tm.dated = r.created
JOIN vn.expedition e ON e.ticketFk = t.id JOIN vn.expedition e ON e.ticketFk = t.id
JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk
JOIN vn.address ad ON ad.id = t.addressFk JOIN vn.address ad ON ad.id = t.addressFk
JOIN vn.client c ON c.id = ad.clientFk JOIN vn.client c ON c.id = ad.clientFk
LEFT JOIN vn.`zone` z ON z.id = t.zoneFk LEFT JOIN vn.`zone` z ON z.id = t.zoneFk
WHERE tm.`year` = vYear WHERE r.created BETWEEN vDatedFrom AND vDatedTo
AND tm.`month` = vMonth
AND NOT z.isVolumetric AND NOT z.isVolumetric
GROUP BY t.routeFk GROUP BY t.routeFk
) sub ON r.Id_Ruta = sub.routeFk ) sub ON r.Id_Ruta = sub.routeFk
@ -96,12 +90,10 @@ BEGIN
SUM(freight) averageTheoreticalVolume SUM(freight) averageTheoreticalVolume
FROM vn.ticket t FROM vn.ticket t
JOIN vn.route r ON r.id = t.routeFk JOIN vn.route r ON r.id = t.routeFk
JOIN vn.`time` tm ON tm.dated = r.created
JOIN vn.saleVolume sf ON sf.ticketFk = t.id JOIN vn.saleVolume sf ON sf.ticketFk = t.id
JOIN vn.client c ON c.id = t.clientFk JOIN vn.client c ON c.id = t.clientFk
JOIN vn.`zone` z ON z.id = t.zoneFk JOIN vn.`zone` z ON z.id = t.zoneFk
WHERE tm.`year` = vYear WHERE r.created BETWEEN vDatedFrom AND vDatedTo
AND tm.`month` = vMonth
AND z.isVolumetric AND z.isVolumetric
GROUP BY t.routeFk GROUP BY t.routeFk
) sub ON r.Id_Ruta = sub.routeFk ) sub ON r.Id_Ruta = sub.routeFk
@ -114,11 +106,9 @@ BEGIN
SUM(g.amount) greuge SUM(g.amount) greuge
FROM vn.ticket t FROM vn.ticket t
JOIN vn.route r ON r.id = t.routeFk JOIN vn.route r ON r.id = t.routeFk
JOIN vn.`time` tm ON tm.dated = r.created
JOIN vn.greuge g ON g.ticketFk = t.id JOIN vn.greuge g ON g.ticketFk = t.id
JOIN vn.greugeType gt ON gt.id = g.greugeTypeFk JOIN vn.greugeType gt ON gt.id = g.greugeTypeFk
WHERE tm.`year` = vYear WHERE r.created BETWEEN vDatedFrom AND vDatedTo
AND tm.`month` = vMonth
AND gt.code = 'freightDifference' AND gt.code = 'freightDifference'
GROUP BY t.routeFk GROUP BY t.routeFk
) sub ON r.Id_Ruta = sub.routeFk ) sub ON r.Id_Ruta = sub.routeFk

View File

@ -4,6 +4,6 @@ BEGIN
/** /**
* Call rutasAnalyze * Call rutasAnalyze
*/ */
CALL rutasAnalyze(YEAR(util.VN_CURDATE()), MONTH(util.VN_CURDATE())); CALL rutasAnalyze(util.VN_CURDATE() - INTERVAL 30 DAY , util.VN_CURDATE());
END$$ END$$
DELIMITER ; DELIMITER ;