salix/db/routines/bs/views/s21_saleDetail.sql

43 lines
1.2 KiB
MySQL
Raw Normal View History

CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `bs`.`s21_saleDetail`
AS SELECT dayofmonth(`t`.`shipped`) AS `dia`,
year(`t`.`shipped`) AS `año`,
MONTH(`t`.`shipped`) AS `mes`,
`s`.`concept` AS `concepto`,
`s`.`quantity` AS `unidades`,
`s`.`price` AS `precio`,
`s`.`quantity` * `s`.`price` AS `venta`,
`it`.`name` AS `familia`,
`w`.`code` AS `comprador`,
`s`.`itemFk` AS `itemFk`,
`s`.`ticketFk` AS `ticketFk`,
`sv`.`volume` AS `volume`
FROM (
(
(
(
(
(
`vn`.`sale` `s`
JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`)
)
JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`)
)
JOIN `vn`.`worker` `w` ON(`w`.`id` = `it`.`workerFk`)
)
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`)
)
JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`)
)
JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`)
)
WHERE (
`t`.`shipped` BETWEEN '2020-10-21' AND '2020-10-28'
OR `t`.`shipped` BETWEEN '2019-10-21' AND '2019-10-28'
OR `t`.`shipped` BETWEEN '2021-09-1' AND '2021-10-28'
)
AND `t`.`warehouseFk` IN (1, 60)
AND `c`.`isRelevant` <> 0
AND `s`.`quantity` > 0