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

41 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `srt`.`upperStickers`
AS SELECT `e`.`id` AS `expeditionFk`,
`e`.`id` MOD 10000 AS `expedition`,
IFNULL(
`rs`.`eta`,
`util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) + 120 MINUTE
) AS `ETD`,
`ve`.`ticketFk` AS `ticketFk`,
right(IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`), 3) AS `routeFk`,
`z`.`name` AS `zonaTicket`,
`rs`.`description` AS `truck`,
`epo`.`workerCode` AS `worker`,
`p`.`name` AS `labeler`,
`ve`.`counter` AS `expeditionCounter`,
`vn`.`ticketTotalVolume`(`t`.`id`) AS `m3`,
`t`.`clientFk` AS `clientFk`
FROM (
(
(
(
(
(
(
`srt`.`expedition` `e`
LEFT JOIN `vn`.`expedition` `ve` ON(`ve`.`id` = `e`.`id`)
)
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`.`roadmapStopFk` = `rs`.`id`)
)
JOIN `dipole`.`expedition_PrintOut` `epo` ON(`epo`.`expeditionFk` = `e`.`id`)
)
JOIN `vn`.`printer` `p` ON(`p`.`id` = `epo`.`printerFk`)
)