2024-03-12 11:57:34 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`agencyVolume`()
|
2024-03-12 11:57:34 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
2024-03-12 14:27:09 +00:00
|
|
|
* Calculates and presents information on shipment and packaging volumes
|
|
|
|
* for agencies that are not owned for a specific period.
|
2024-03-12 11:57:34 +00:00
|
|
|
*/
|
|
|
|
DECLARE vStarted DATETIME DEFAULT util.VN_CURDATE();
|
|
|
|
DECLARE vEnded DATETIME DEFAULT util.dayEnd(util.VN_CURDATE());
|
|
|
|
|
|
|
|
SELECT ag.id agency_id,
|
2024-04-24 07:05:29 +00:00
|
|
|
CONCAT(RPAD(c.name, 16,' _') ,' ',ag.name) Agencia,
|
2024-03-12 11:57:34 +00:00
|
|
|
COUNT(*) expediciones,
|
|
|
|
SUM(t.packages) Bultos,
|
|
|
|
SUM(tpe.boxes) Faltan
|
|
|
|
FROM ticket t
|
|
|
|
JOIN warehouse w ON w.id = t.warehouseFk
|
|
|
|
JOIN country c ON w.countryFk = c.id
|
|
|
|
JOIN address a ON a.id = t.addressFk
|
|
|
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
|
|
|
JOIN agency ag ON ag.id = am.agencyFk
|
|
|
|
JOIN (
|
|
|
|
SELECT sv.ticketFk,
|
2024-03-14 08:42:54 +00:00
|
|
|
CEIL(1000 * SUM(sv.volume) / vc.standardFlowerBox) boxes
|
2024-03-12 11:57:34 +00:00
|
|
|
FROM ticket t
|
|
|
|
JOIN saleVolume sv ON sv.ticketFk = t.id
|
|
|
|
JOIN volumeConfig vc
|
|
|
|
WHERE t.shipped BETWEEN vStarted AND vEnded
|
|
|
|
AND (t.packages IS NULL OR NOT t.packages)
|
|
|
|
GROUP BY t.id
|
|
|
|
) tpe ON tpe.ticketFk = t.id
|
|
|
|
WHERE t.shipped BETWEEN vStarted AND vEnded
|
|
|
|
AND NOT ag.isOwn
|
|
|
|
GROUP BY ag.id
|
|
|
|
ORDER BY Agencia;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|