salix/db/routines/vn/procedures/ticketNotInvoicedByClient.sql

31 lines
693 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketNotInvoicedByClient`(vClientFk INT)
BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
CREATE TEMPORARY TABLE tmp.ticket
SELECT id ticketFk
FROM ticket
WHERE refFk IS NULL
AND clientFk = vClientFk
AND shipped > '2001-01-01';
CALL vn.ticketGetTotal(NULL);
SELECT c.id,
c.name as Cliente,
t.shipped as Fecha,
t.id as Id_Ticket,
CAST(tt.total AS DECIMAL(10,2)) as Importe
FROM tmp.ticketTotal tt
JOIN ticket t ON t.id = tt.ticketFk
JOIN client c ON c.id = t.ClientFk;
DROP TEMPORARY TABLE
tmp.ticket,
tmp.ticketTotal;
END$$
DELIMITER ;