2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`prepareTicketList`(vStartingDate DATETIME, vEndingDate DATETIME)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket;
|
|
|
|
CREATE TEMPORARY TABLE tmp.productionTicket
|
|
|
|
(PRIMARY KEY (ticketFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT t.id ticketFk, t.clientFk
|
2024-06-05 06:05:46 +00:00
|
|
|
FROM ticket t
|
|
|
|
JOIN alertLevel al ON al.code = 'DELIVERED'
|
|
|
|
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
|
|
|
JOIN client c ON c.id = t.clientFk
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE c.typeFk IN ('normal','handMaking','internalUse')
|
|
|
|
AND (
|
|
|
|
t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate
|
|
|
|
OR (
|
2024-06-05 06:05:46 +00:00
|
|
|
ts.alertLevel < al.id
|
2024-01-15 11:31:03 +00:00
|
|
|
AND t.shipped >= vStartingDate
|
|
|
|
AND t.shipped < util.VN_CURDATE()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|