26 lines
822 B
SQL
26 lines
822 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_zoneClosure`()
|
|
BEGIN
|
|
|
|
/* Devuelve una tabla temporal con la hora minima de un ticket sino tiene el de la zoneClosure y
|
|
* si tampoco hay el de la zona , para todos los artículos con salida hoy.
|
|
*
|
|
* @return tmp.itemZoneClosure(itemFk, timed)
|
|
*/
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemZoneClosure
|
|
(INDEX (itemFk))
|
|
ENGINE = MEMORY
|
|
SELECT s.itemFk,
|
|
MIN(DATE_FORMAT(IF(HOUR(t.shipped),t.shipped,
|
|
IFNULL(zc.hour, z.HOUR)), '%H:%i')
|
|
)timed
|
|
FROM ticket t
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
|
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
|
|
WHERE t.shipped BETWEEN util.VN_CURDATE() AND CONCAT(util.VN_CURDATE(), ' 23:59:59')
|
|
GROUP BY s.itemFk;
|
|
END$$
|
|
DELIMITER ;
|