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

36 lines
943 B
SQL

CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`lastPurchases`
AS SELECT `tr`.`landed` AS `landed`,
`w`.`id` AS `warehouseFk`,
`w`.`name` AS `warehouse`,
`i`.`longName` AS `longName`,
`i`.`subName` AS `subName`,
`e`.`id` AS `entryFk`,
`b`.`stickers` AS `stickers`,
`b`.`packing` AS `packing`,
`e`.`invoiceNumber` AS `ref`,
`b`.`itemFk` AS `itemFk`,
`ek`.`pro` AS `pro`,
`ek`.`ref` AS `ektRef`,
`ek`.`agj` AS `agj`
FROM (
(
(
(
(
`vn`.`buy` `b`
JOIN `vn`.`entry` `e` ON(`e`.`id` = `b`.`entryFk`)
)
JOIN `vn`.`item` `i` ON(`i`.`id` = `b`.`itemFk`)
)
JOIN `vn`.`travel` `tr` ON(`tr`.`id` = `e`.`travelFk`)
)
JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `tr`.`warehouseInFk`)
)
LEFT JOIN `edi`.`ekt` `ek` ON(`ek`.`id` = `b`.`ektFk`)
)
WHERE `tr`.`landed` BETWEEN `util`.`yesterday`() AND `util`.`tomorrow`()
AND NOT `tr`.`isRaid`
AND `b`.`stickers` > 0