CREATE OR REPLACE DEFINER=`root`@`localhost`
	SQL SECURITY DEFINER
	VIEW `srt`.`bufferDayMinute`
AS SELECT `b`.`id` AS `bufferFk`,
	`e`.`id` AS `expeditionFk`,
	`srt`.`dayMinute`(IFNULL(`rs`.`eta`, `z`.`hour`)) AS `dayMinute`,
	`e`.`position` AS `position`,
	IFNULL(
		`rs`.`eta`,
		`util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) MINUTE
	) AS `ETD`,
	`e2`.`ticketFk` AS `ticketFk`,
	IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`) AS `routeFk`,
	`z`.`name` AS `zonaTicket`,
	`es`.`description` AS `expeditionState`
FROM (
		(
			(
				(
					(
						(
							(
								(
									`srt`.`buffer` `b`
									LEFT JOIN `srt`.`expedition` `e` ON(`b`.`id` = `e`.`bufferFk`)
								)
								LEFT JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e`.`stateFk`)
							)
							JOIN `srt`.`bufferType` `bt` ON(`bt`.`id` = `b`.`typeFk`)
						)
						LEFT JOIN `vn`.`expedition` `e2` ON(`e2`.`id` = `e`.`id`)
					)
					LEFT JOIN `vn`.`ticket` `t` ON(`e2`.`ticketFk` = `t`.`id`)
				)
				LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`)
			)
			LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`)
		)
		LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
	)
WHERE `b`.`isActive` <> 0
