2024-01-15 11:31:03 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
|
|
SQL SECURITY DEFINER
|
|
|
|
VIEW `vn`.`routesControl`
|
|
|
|
AS SELECT `t`.`routeFk` AS `routeFk`,
|
|
|
|
COUNT(`e`.`id`) AS `expeditions`,
|
|
|
|
COUNT(`es`.`id`) AS `scanned`,
|
|
|
|
COUNT(DISTINCT `es`.`palletFk`) AS `pallets`,
|
|
|
|
max(`es`.`scanned`) AS `lastScanned`,
|
2024-04-30 09:48:18 +00:00
|
|
|
max(`rs`.`description`) AS `description`,
|
|
|
|
max(`rs`.`eta`) AS `eta`
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM (
|
|
|
|
(
|
|
|
|
(
|
|
|
|
(
|
|
|
|
`vn`.`ticket` `t`
|
|
|
|
JOIN `vn`.`expedition` `e` ON(`t`.`id` = `e`.`ticketFk`)
|
|
|
|
)
|
|
|
|
LEFT JOIN `vn`.`expeditionScan` `es` ON(`es`.`expeditionFk` = `e`.`id`)
|
|
|
|
)
|
|
|
|
LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`id` = `es`.`palletFk`)
|
|
|
|
)
|
2024-04-30 09:48:18 +00:00
|
|
|
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `ep`.`truckFk`)
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
|
|
|
WHERE `t`.`shipped` >= `util`.`VN_CURDATE`()
|
|
|
|
AND `t`.`routeFk` <> 0
|
|
|
|
GROUP BY `t`.`routeFk`
|
2024-04-30 09:48:18 +00:00
|
|
|
ORDER BY max(`rs`.`eta`)
|