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

23 lines
624 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`invoiceFromAddress`(vMaxTicketDate DATETIME,vAddress INT,vCompany INT)
BEGIN
DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, util.VN_CURDATE());
SET vMaxTicketDate = util.dayEnd(vMaxTicketDate);
DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`;
2024-02-07 10:41:22 +00:00
CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice`
(PRIMARY KEY (`id`))
ENGINE = MEMORY
2024-02-06 13:55:20 +00:00
SELECT id
FROM ticket
WHERE (shipped BETWEEN vMinDateTicket AND vMaxTicketDate)
AND addressFk = vAddress
AND refFk IS NULL
AND companyFk = vCompany;
END$$
DELIMITER ;