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

35 lines
1.1 KiB
MySQL
Raw Permalink Normal View History

2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`itemPlacementSupplyList`
AS SELECT `ips`.`id` AS `id`,
`ips`.`itemFk` AS `itemFk`,
`ips`.`quantity` AS `quantity`,
`ips`.`priority` AS `priority`,
IFNULL(`isps`.`created`, `ips`.`created`) AS `created`,
`ips`.`userFk` AS `userFk`,
`ips`.`repoUserFk` AS `repoUserFk`,
`ips`.`quantity` - sum(IFNULL(`isps`.`quantity`, 0)) AS `saldo`,
concat(`i`.`longName`, ' ', `i`.`size`) AS `longName`,
`i`.`subName` AS `subName`,
`i`.`size` AS `size`,
`w`.`code` AS `workerCode`,
`rw`.`code` AS `repoCode`,
`ips`.`sectorFk` AS `sectorFk`
FROM (
(
(
(
`vn`.`itemPlacementSupply` `ips`
JOIN `vn`.`item` `i` ON(`i`.`id` = `ips`.`itemFk`)
)
LEFT JOIN `vn`.`worker` `w` ON(`w`.`id` = `ips`.`userFk`)
)
LEFT JOIN `vn`.`worker` `rw` ON(`rw`.`id` = `ips`.`repoUserFk`)
)
LEFT JOIN `vn`.`itemShelvingPlacementSupply` `isps` ON(`isps`.`itemPlacementSupplyFk` = `ips`.`id`)
)
WHERE `ips`.`created` >= `util`.`VN_CURDATE`()
GROUP BY `ips`.`priority`,
`ips`.`id`,
`ips`.`sectorFk`