salix/db/routines/srt/functions/expedition_getDayMinute.sql

32 lines
915 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`expedition_getDayMinute`(vExpeditionFk INT)
RETURNS int(11)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
/**
* Devuelve el minuto absoluto ( un dia tiene 24 x 60 minutos ) de salida del camión
*
* @param vExpeditionFk Identificador de srt.expedition
*
* @return vDayMinute Minuto absoluto diario
*/
DECLARE vDayMinute INT;
SELECT HOUR(IFNULL(rs.ETD, z.`hour`)) * 60 + MINUTE(IFNULL(rs.ETD, z.`hour`)) INTO vDayMinute
FROM vn.expedition e
JOIN vn.ticket t ON e.ticketFk = t.id
JOIN vn.`zone` z ON z.id = t.zoneFk
LEFT JOIN vn.route r ON r.id = t.routeFk
LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk
LEFT JOIN vn.routesMonitor rm ON t.routeFk = rm.routeFk
LEFT JOIN vn.roadmapStop rs ON rm.expeditionTruckFk = rs.id
WHERE e.id = vExpeditionFk;
RETURN vDayMinute;
END$$
DELIMITER ;