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`.`item_getMinETD`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/* Devuelve una tabla temporal con la primera ETD, para todos los artículos con salida hoy.
|
|
|
|
*
|
|
|
|
* @return tmp.itemMinETD(itemFk, timed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE vMidnight DATETIME DEFAULT util.midnight();
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.itemMinETD;
|
|
|
|
|
|
|
|
CREATE TEMPORARY TABLE tmp.itemMinETD
|
|
|
|
(INDEX (itemFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT s.itemFk, MIN(TIME(IFNULL(z.`hour`,vMidnight))) timed
|
|
|
|
FROM ticket t
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
|
|
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
|
|
|
WHERE t.shipped BETWEEN util.VN_CURDATE() AND vMidnight
|
|
|
|
GROUP BY s.itemFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|