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

27 lines
669 B
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`.`ticketNotInvoiced`
AS SELECT `t`.`companyFk` AS `companyFk`,
`cm`.`code` AS `companyCode`,
`t`.`clientFk` AS `clientFk`,
`c`.`name` AS `clientName`,
`t`.`shipped` AS `shipped`,
cast(
sum(
`s`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100
) AS decimal(10, 2)
) AS `value`
FROM (
(
(
`vn`.`ticket` `t`
JOIN `vn`.`sale` `s` ON(`s`.`ticketFk` = `t`.`id`)
)
JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`)
)
JOIN `vn`.`company` `cm` ON(`cm`.`id` = `t`.`companyFk`)
)
WHERE `t`.`refFk` IS NULL
AND `t`.`shipped` > '2017-01-01'
GROUP BY `t`.`id`