#2687 - Travel CloneWithEntries #1887
|
@ -0,0 +1,88 @@
|
|||
DROP PROCEDURE IF EXISTS vn.travel_cloneWithEntries;
|
||||
jsegarra marked this conversation as resolved
Outdated
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`(
|
||||
IN vTravelFk INT,
|
||||
IN vDateStart DATE,
|
||||
IN vDateEnd DATE,
|
||||
IN vWarehouseOutFk INT,
|
||||
IN vWarehouseInFk INT,
|
||||
IN vRef VARCHAR(255),
|
||||
IN vAgencyModeFk INT,
|
||||
IN vTx BOOL,
|
||||
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
|
||||
* @param vWarehouseOutFk fecha del salida del nuevo travel
|
||||
* @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;
|
||||
jsegarra
commented
He añadido esta variable He añadido esta variable
|
||||
DECLARE vTx BOOLEAN DEFAULT !@@in_transaction;
|
||||
DECLARE vRsEntry CURSOR FOR
|
||||
SELECT e.id
|
||||
FROM entry e
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
WHERE e.travelFk = vTravelFk;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
jsegarra
commented
He modificado ROLLBACK por esto He modificado ROLLBACK por esto
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
jsegarra
commented
He modificado START TRANSACTION por esto He modificado START TRANSACTION por esto
|
||||
START TRANSACTION;
|
||||
|
||||
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;
|
||||
|
||||
SET vNewTravelFk = LAST_INSERT_ID();
|
||||
|
||||
SET vDone = FALSE;
|
||||
SET @isModeInventory = TRUE;
|
||||
|
||||
OPEN vRsEntry;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vRsEntry INTO vAuxEntryFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
CALL util.tx_start(vTx);
|
||||
CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk);
|
||||
CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk);
|
||||
CALL util.tx_commit(vTx);
|
||||
|
||||
SELECT evaNotes INTO vEvaNotes
|
||||
FROM entry
|
||||
WHERE id = vAuxEntryFk;
|
||||
|
||||
UPDATE entry
|
||||
SET evaNotes = vEvaNotes
|
||||
WHERE id = vNewEntryFk;
|
||||
|
||||
END LOOP;
|
||||
|
||||
SET @isModeInventory = FALSE;
|
||||
jsegarra
commented
He modificado COMMIT por esto He modificado COMMIT por esto
|
||||
CLOSE vRsEntry;
|
||||
|
||||
COMMIT;
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue
Cambiar version
La versión correcta, sería la 240001 o la 240101?