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

62 lines
1.6 KiB
SQL

CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`expeditionSticker`
AS SELECT `e`.`id` AS `expeditionFk`,
`e`.`ticketFk` AS `ticketFk`,
`t`.`addressFk` AS `addressFk`,
`t`.`clientFk` AS `clientFk`,
`a`.`street` AS `street`,
`a`.`postalCode` AS `postalCode`,
`a`.`city` AS `city`,
`a`.`nickname` AS `nickname`,
concat('R(', right(`t`.`routeFk`, 3), ')') AS `routeFk`,
`rm`.`beachFk` AS `beachFk`,
IF(
`t`.`routeFk`,
IFNULL(
`rs`.`description`,
REPLACE(`am`.`name`, 'ZONA ', 'Z')
),
`z`.`name`
) AS `zona`,
`p`.`name` AS `province`,
IFNULL(
`c`.`mobile`,
IFNULL(`a`.`mobile`, IFNULL(`c`.`phone`, `a`.`phone`))
) AS `phone`,
`w`.`code` AS `workerCode`
FROM (
(
(
(
(
(
(
(
(
(
(
`vn`.`expedition` `e`
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `e`.`ticketFk`)
)
JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`)
)
JOIN `vn`.`province` `p` ON(`p`.`id` = `a`.`provinceFk`)
)
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`)
)
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`roadmapStopFk`)
)
LEFT JOIN `vn`.`beach` `b` ON(`b`.`code` = `rm`.`beachFk`)
)
LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
)
LEFT JOIN `vn`.`route` `r` ON(`r`.`id` = `t`.`routeFk`)
)
LEFT JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `r`.`agencyModeFk`)
)
JOIN `vn`.`client` `c` ON(`c`.`id` = `a`.`clientFk`)
)
JOIN `vn`.`worker` `w` ON(`w`.`id` = `e`.`workerFk`)
)