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_cloneWithEntries`(
|
2024-02-14 07:45:50 +00:00
|
|
|
IN vTravelFk INT,
|
|
|
|
IN vDateStart DATE,
|
2024-01-15 11:31:03 +00:00
|
|
|
IN vDateEnd DATE,
|
|
|
|
IN vWarehouseOutFk INT,
|
2024-02-14 07:45:50 +00:00
|
|
|
IN vWarehouseInFk INT,
|
|
|
|
IN vRef VARCHAR(255),
|
|
|
|
IN vAgencyModeFk INT,
|
2024-01-15 11:31:03 +00:00
|
|
|
OUT vNewTravelFk INT)
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Clona un travel junto con sus entradas y compras
|
|
|
|
* @param vTravelFk travel plantilla a clonar
|
|
|
|
* @param vDateStart fecha del shipment del nuevo travel
|
|
|
|
* @param vDateEnd fecha del landing del nuevo travel
|
2024-02-14 07:45:50 +00:00
|
|
|
* @param vWarehouseOutFk warehouse del salida del nuevo travel
|
2024-01-15 11:31:03 +00:00
|
|
|
* @param vWarehouseInFk warehouse de landing del nuevo travel
|
|
|
|
* @param vRef referencia del nuevo travel
|
|
|
|
* @param vAgencyModeFk del nuevo travel
|
|
|
|
* @param vNewTravelFk id del nuevo travel
|
|
|
|
*/
|
|
|
|
DECLARE vNewEntryFk INT;
|
|
|
|
DECLARE vEvaNotes VARCHAR(255);
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
DECLARE vAuxEntryFk INT;
|
2024-06-04 14:45:42 +00:00
|
|
|
DECLARE vIsRequiredTx BOOLEAN DEFAULT NOT @@in_transaction;
|
|
|
|
DECLARE vRsEntry CURSOR FOR
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT e.id
|
|
|
|
FROM entry e
|
|
|
|
JOIN travel t ON t.id = e.travelFk
|
|
|
|
WHERE e.travelFk = vTravelFk;
|
2024-02-14 07:45:50 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
|
|
|
|
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
2024-02-14 07:45:50 +00:00
|
|
|
BEGIN
|
2024-06-04 14:43:09 +00:00
|
|
|
CALL util.tx_rollback(vIsRequiredTx);
|
2024-01-15 11:31:03 +00:00
|
|
|
RESIGNAL;
|
|
|
|
END;
|
2024-02-14 07:45:50 +00:00
|
|
|
|
2024-06-04 14:43:09 +00:00
|
|
|
CALL util.tx_start(vIsRequiredTx);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom)
|
|
|
|
SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk
|
|
|
|
FROM travel
|
|
|
|
WHERE id = vTravelFk;
|
2024-02-14 07:45:50 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SET vNewTravelFk = LAST_INSERT_ID();
|
|
|
|
|
|
|
|
SET vDone = FALSE;
|
|
|
|
SET @isModeInventory = TRUE;
|
|
|
|
|
|
|
|
OPEN vRsEntry;
|
2024-02-14 07:45:50 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
l: LOOP
|
|
|
|
SET vDone = FALSE;
|
|
|
|
FETCH vRsEntry INTO vAuxEntryFk;
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE l;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk);
|
2024-02-14 07:45:50 +00:00
|
|
|
CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
SELECT evaNotes INTO vEvaNotes
|
|
|
|
FROM entry
|
|
|
|
WHERE id = vAuxEntryFk;
|
|
|
|
|
|
|
|
UPDATE entry
|
|
|
|
SET evaNotes = vEvaNotes
|
|
|
|
WHERE id = vNewEntryFk;
|
|
|
|
END LOOP;
|
|
|
|
|
|
|
|
SET @isModeInventory = FALSE;
|
|
|
|
CLOSE vRsEntry;
|
|
|
|
|
2024-06-04 14:43:09 +00:00
|
|
|
CALL util.tx_commit(vIsRequiredTx);
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|