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

25 lines
846 B
MySQL
Raw Normal View History

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`zoneEstimatedDelivery`
AS SELECT t.zoneFk,
zc.`hour` zoneClosureHour,
z.`hour` zoneHour,
sv.volume volume,
al.hasToRecalcPrice,
lhp.m3,
dl.minSpeed
FROM ticket t
2024-02-05 06:30:04 +00:00
JOIN ticketStateToday tst ON tst.ticketFk = t.id
JOIN state s ON s.id = tst.state
JOIN saleVolume sv ON sv.ticketFk = t.id
LEFT JOIN lastHourProduction lhp ON lhp.warehouseFk = t.warehouseFk
JOIN warehouse w ON w.id = t.warehouseFk
STRAIGHT_JOIN `zone` z ON z.id = t.zoneFk
LEFT JOIN 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 alertLevel al ON al.id = s.alertLevel
WHERE w.hasProduction
AND DATE(t.shipped) = util.VN_CURDATE()