salix/db/routines/vn/views/zoneEstimatedDelivery.sql

45 lines
1.3 KiB
MySQL
Raw Permalink Normal View History

2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`zoneEstimatedDelivery`
2024-02-15 09:04:15 +00:00
AS SELECT `t`.`zoneFk` AS `zoneFk`,
`zc`.`hour` AS `zoneClosureHour`,
`z`.`hour` AS `zoneHour`,
`sv`.`volume` AS `volume`,
`al`.`hasToRecalcPrice` AS `hasToRecalcPrice`,
`lhp`.`m3` AS `m3`,
`dl`.`minSpeed` AS `minSpeed`
FROM (
(
(
(
(
(
(
(
(
2024-02-15 10:07:47 +00:00
`vn`.`ticket` `t`
JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticketFk` = `t`.`id`)
2024-02-15 09:04:15 +00:00
)
2024-02-15 10:07:47 +00:00
JOIN `vn`.`state` `s` ON(`s`.`id` = `tst`.`state`)
2024-02-15 09:04:15 +00:00
)
2024-02-15 10:07:47 +00:00
JOIN `vn`.`saleVolume` `sv` ON(`sv`.`ticketFk` = `t`.`id`)
2024-02-15 09:04:15 +00:00
)
2024-02-15 10:07:47 +00:00
LEFT JOIN `vn`.`lastHourProduction` `lhp` ON(`lhp`.`warehouseFk` = `t`.`warehouseFk`)
)
JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`)
2024-02-15 09:04:15 +00:00
)
) STRAIGHT_JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
)
LEFT JOIN `vn`.`zoneClosure` `zc` ON(
`zc`.`zoneFk` = `t`.`zoneFk`
AND `zc`.`dated` = `util`.`VN_CURDATE`()
)
)
LEFT JOIN `cache`.`departure_limit` `dl` ON(
`dl`.`warehouse_id` = `t`.`warehouseFk`
AND `dl`.`fecha` = `util`.`VN_CURDATE`()
)
)
JOIN `vn`.`alertLevel` `al` ON(`al`.`id` = `s`.`alertLevel`)
WHERE `w`.`hasProduction` <> 0
2024-02-15 10:07:47 +00:00
AND cast(`t`.`shipped` AS date) = `util`.`VN_CURDATE`()