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

47 lines
1.4 KiB
SQL

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`salesPreparedLastHour`
AS SELECT `t`.`warehouseFk` AS `warehouseFk`,
`st`.`saleFk` AS `saleFk`,
`st`.`isChecked` AS `isChecked`,
`st`.`originalQuantity` AS `originalQuantity`,
`st`.`created` AS `created`,
`e`.`code` AS `code`,
`w`.`firstName` AS `firstname`,
`w`.`lastName` AS `lastName`,
`w`.`code` AS `workerCode`,
`ic`.`cm3delivery` * `s`.`quantity` / 1000 AS `litros`,
`s`.`concept` AS `concept`,
`d`.`name` AS `departmentName`
FROM (
(
(
(
(
(
(
(
`vn`.`saleTracking` `st`
LEFT JOIN `vn`.`salesPreviousPreparated` `prevPrepSales` ON(`prevPrepSales`.`saleFk` = `st`.`saleFk`)
)
JOIN `vn`.`sale` `s` ON(`s`.`id` = `st`.`saleFk`)
)
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`)
)
JOIN `vn`.`itemCost` `ic` ON(
`ic`.`warehouseFk` = `t`.`warehouseFk`
AND `ic`.`itemFk` = `s`.`itemFk`
)
)
JOIN `vn`.`worker` `w` ON(`w`.`id` = `st`.`workerFk`)
)
JOIN `vn`.`state` `e` ON(`e`.`id` = `st`.`stateFk`)
)
JOIN `vn`.`workerDepartment` `wd` ON(`wd`.`workerFk` = `st`.`workerFk`)
)
JOIN `vn`.`department` `d` ON(`d`.`id` = `wd`.`departmentFk`)
)
WHERE `st`.`created` > `util`.`VN_NOW`() + INTERVAL -1 HOUR
AND `prevPrepSales`.`saleFk` IS NULL
AND `d`.`name` NOT LIKE 'EQUIPO%'