CREATE DEFINER=`admin`@`localhost` FUNCTION `generate_trip_diagnosis`(start_datetime DATETIME, start_eta DATETIME, end_datetime DATETIME, end_eta DATETIME) RETURNS varchar(40) CHARSET utf8mb4
    DETERMINISTIC
BEGIN
	DECLARE result VARCHAR(40) DEFAULT NULL;
    DECLARE start_diff INT DEFAULT TIMESTAMPDIFF( MINUTE, start_eta, start_datetime);
	DECLARE end_diff INT DEFAULT TIMESTAMPDIFF( MINUTE, end_datetime, end_eta);
    DECLARE ini_status VARCHAR(20) DEFAULT IF(start_diff > 0, 'A tiempo','Retrasado');
    DECLARE end_status VARCHAR(20) DEFAULT IF(end_diff <= 0, 'A tiempo','Retrasado');
	
    SET result = IF( ini_status = end_status , ini_status, CONCAT(ini_status, ",",end_status));
    
RETURN result;
END