DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_beforeUpdate`
	BEFORE UPDATE ON `travel`
	FOR EACH ROW
BEGIN
	SET NEW.editorFk = account.myUser_getId();
/*
	IF ((NOT NEW.shipped <=> OLD.shipped )
		OR (NOT NEW.landed <=> OLD.landed )
		OR (NOT NEW.warehouseInFk <=> OLD.warehouseInFk )
		OR (NOT NEW.warehouseOutFk <=> OLD.warehouseOutFk ))
		AND (OLD.totalEntries AND OLD.landed < CURDATE()) THEN
		CALL util.throw("Cannot past travels with entries");
	END IF;
*/
	IF NOT (NEW.landed <=> OLD.landed)
	OR NOT (NEW.shipped <=> OLD.shipped) THEN
		CALL travel_checkDates(NEW.shipped, NEW.landed);
	END IF;

	IF NOT (NEW.isReceived <=> OLD.isReceived) THEN
		CALL travel_checkPackaging(NEW.id);
	END IF;

	IF NOT (NEW.warehouseInFk <=> OLD.warehouseInFk) THEN
		CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk);
	END IF;
END$$
DELIMITER ;
