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

60 lines
1.8 KiB
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`itemShelvingAvailable`
AS SELECT `s`.`id` AS `saleFk`,
`tst`.`updated` AS `Modificado`,
`s`.`ticketFk` AS `ticketFk`,
0 AS `isPicked`,
`s`.`itemFk` AS `itemFk`,
`s`.`quantity` AS `quantity`,
`s`.`concept` AS `concept`,
`i`.`size` AS `size`,
`st`.`name` AS `Estado`,
`st`.`sectorProdPriority` AS `sectorProdPriority`,
`stock`.`visible` AS `available`,
`stock`.`sectorFk` AS `sectorFk`,
`stock`.`shelvingFk` AS `matricula`,
`stock`.`parkingFk` AS `parking`,
`stock`.`itemShelvingFk` AS `itemShelving`,
`am`.`name` AS `Agency`,
`t`.`shipped` AS `shipped`,
`stock`.`grouping` AS `grouping`,
`stock`.`packing` AS `packing`,
`z`.`hour` AS `hour`,
`st`.`isPreviousPreparable` AS `isPreviousPreparable`,
`sv`.`physicalVolume` AS `physicalVolume`,
`t`.`warehouseFk` AS `warehouseFk`
FROM (
(
(
(
(
(
(
(
(
`vn`.`sale` `s`
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`)
)
JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`)
)
JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticketFk` = `t`.`id`)
)
JOIN `vn`.`state` `st` ON(`st`.`id` = `tst`.`state`)
)
JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`)
)
JOIN `vn`.`itemShelvingStock` `stock` ON(`stock`.`itemFk` = `i`.`id`)
)
LEFT JOIN `vn`.`saleTracking` `stk` ON(`stk`.`saleFk` = `s`.`id`)
)
LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
)
LEFT JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`)
)
WHERE `t`.`shipped` BETWEEN `util`.`yesterday`() AND `util`.`dayend`(`util`.`VN_CURDATE`())
AND `stk`.`id` IS NULL
AND `stock`.`visible` > 0
AND `stk`.`saleFk` IS NULL
AND `st`.`isPreviousPreparable` <> 0