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

55 lines
1.5 KiB
MySQL
Raw Normal View History

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `srt`.`bufferStock`
AS SELECT `e`.`id` AS `expeditionFk`,
`e`.`bufferFk` AS `bufferFk`,
`e`.`position` AS `position`,
`srt`.`dayMinute`(IFNULL(`rs`.`eta`, `z`.`hour`)) AS `dayMinute`,
IFNULL(
`rs`.`eta`,
`util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) + 120 MINUTE
) AS `eta`,
`ve`.`ticketFk` AS `ticketFk`,
IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`) AS `routeFk`,
`z`.`name` AS `zonaTicket`,
`rs`.`description` AS `truck`,
`es`.`description` AS `expeditionState`,
`b`.`hasWorkerWaiting` AS `hasWorkerWaiting`,
`b`.`isActive` AS `isActive`,
IF(
`rs`.`id` IS NULL,
`c`.`bufferDefault`,
`rs`.`bufferFk`
) AS `bufferTruck`,
`bt`.`typeName` AS `typeName`,
`rm`.`bufferFk` AS `routeBuffer`
FROM (
(
(
(
(
(
(
(
(
`srt`.`expedition` `e`
LEFT JOIN `vn`.`expedition` `ve` ON(`ve`.`id` = `e`.`id`)
)
JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e`.`stateFk`)
)
JOIN `srt`.`buffer` `b` ON(`b`.`id` = `e`.`bufferFk`)
)
LEFT JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ve`.`ticketFk`)
)
LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
)
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`)
)
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`)
)
JOIN `srt`.`config` `c`
)
JOIN `srt`.`bufferType` `bt` ON(`bt`.`id` = `b`.`typeFk`)
)
WHERE `bt`.`typeName` <> 'DISABLED'