salix/db/routines/srt/views/routeVolume.sql

21 lines
641 B
SQL

CREATE OR REPLACE DEFINER=`juan`@`%`
SQL SECURITY DEFINER
VIEW `srt`.`routeVolume`
AS SELECT `bs`.`dayMinute` AS `dayMinute`,
`bs`.`eta` AS `ETD`,
COUNT(0) AS `cajas`,
`bs`.`eta` + INTERVAL - `c`.`minutesBeforeTruckDeparture` MINUTE < `util`.`VN_NOW`()
OR COUNT(0) >= `c`.`minBoxesToUnloading` AS `isReady`,
`bs`.`routeFk` AS `routeFk`,
`bs`.`zonaTicket` AS `zonaTicket`,
`bs`.`bufferTruck` AS `bufferTruck`,
`bs`.`routeBuffer` AS `routeBuffer`
FROM (
`srt`.`bufferStock` `bs`
JOIN `srt`.`config` `c`
)
WHERE `bs`.`expeditionState` = 'STORED'
AND `bs`.`isActive` <> 0
AND `bs`.`hasWorkerWaiting` = 0
GROUP BY `bs`.`routeFk`