2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entryDelivered`(vDated DATE, vEntryFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
DECLARE vTravelFk INT;
|
|
|
|
|
|
|
|
SELECT travelFk INTO vTravelFk
|
|
|
|
FROM vn.entry
|
|
|
|
WHERE id = vEntryFk;
|
|
|
|
|
|
|
|
IF (SELECT COUNT(*) FROM vn.entry WHERE travelFk = vTravelFk) = 1 THEN
|
|
|
|
|
|
|
|
UPDATE vn.travel SET shipped = LEAST(shipped, vDated), landed = vDated
|
|
|
|
WHERE id = vTravelFk;
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
|
|
|
|
INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, ref, isDelivered, isReceived)
|
|
|
|
SELECT LEAST(shipped, vDated), vDated, warehouseInFk, warehouseOutFk, agencyModeFk, CONCAT(account.myUser_getName(),' ', vEntryFk), TRUE, TRUE
|
|
|
|
FROM vn.travel WHERE id = vTravelFk;
|
|
|
|
|
|
|
|
SELECT LAST_INSERT_ID() INTO vTravelFk;
|
|
|
|
|
|
|
|
UPDATE vn.entry
|
|
|
|
SET travelFk = vTravelFk
|
|
|
|
WHERE id = vEntryFk;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|