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

27 lines
732 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`.`newBornSales`
AS SELECT `v`.`importe` AS `amount`,
`v`.`Id_Cliente` AS `clientFk`,
`c`.`salesPersonFk` AS `userFk`,
`v`.`fecha` AS `dated`,
`cn`.`firstShipped` AS `firstShipped`
FROM (
(
(
(
`bs`.`clientNewBorn` `cn`
JOIN `bs`.`ventas` `v` ON(
`cn`.`firstShipped` + INTERVAL 1 year > `v`.`fecha`
AND `v`.`Id_Cliente` = `cn`.`clientFk`
)
)
JOIN `vn`.`client` `c` ON(`c`.`id` = `v`.`Id_Cliente`)
)
JOIN `account`.`user` `u` ON(`u`.`id` = `c`.`salesPersonFk`)
)
JOIN `account`.`role` `r` ON(`r`.`id` = `u`.`role`)
)
WHERE `r`.`name` = 'salesPerson'
AND `u`.`name` NOT IN ('ismaelalcolea', 'ruben')