2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`travel_clone`(vSelf INT, vDays INT, OUT vNewTravelFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Clona un travel el número de dias indicado y devuelve su id.
|
|
|
|
*
|
|
|
|
* @param vSelf Identificador de vn.travel
|
|
|
|
* @param vDays Número de dias a futuro
|
|
|
|
* @return vNewTravelFk Nuevo número de travel
|
|
|
|
*/
|
|
|
|
SELECT tr.id INTO vNewTravelFk
|
|
|
|
FROM vn.travel tr
|
|
|
|
JOIN vn.travel tr2 USING(shipped, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`)
|
|
|
|
WHERE tr2.id = vSelf
|
|
|
|
AND tr.landed = TIMESTAMPADD(DAY, vDays, tr2.landed);
|
|
|
|
|
|
|
|
IF ISNULL(vNewTravelFk) THEN
|
|
|
|
START TRANSACTION;
|
|
|
|
|
|
|
|
INSERT INTO vn.travel( shipped,
|
|
|
|
shipmentHour,
|
|
|
|
landed,
|
|
|
|
landingHour,
|
|
|
|
warehouseInFk,
|
|
|
|
warehouseOutFk,
|
|
|
|
agencyModeFk,
|
|
|
|
`ref`,
|
|
|
|
cargoSupplierFk,
|
|
|
|
clonedFrom)
|
|
|
|
SELECT shipped,
|
|
|
|
shipmentHour,
|
|
|
|
TIMESTAMPADD(DAY, vDays, landed),
|
|
|
|
landingHour,
|
|
|
|
warehouseInFk,
|
|
|
|
warehouseOutFk,
|
|
|
|
agencyModeFk,
|
|
|
|
`ref`,
|
|
|
|
cargoSupplierFk,
|
|
|
|
vSelf
|
|
|
|
FROM vn.travel
|
|
|
|
WHERE id = vSelf;
|
|
|
|
|
|
|
|
SELECT LAST_INSERT_ID() INTO vNewTravelFk;
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|