hotfix: ledger_next transacciones refs #7523
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Andrés 2024-06-03 20:04:58 +02:00
parent a73c98eebe
commit 83b8fc38bd
9 changed files with 50 additions and 40 deletions

View File

@ -44,7 +44,7 @@ BEGIN
JOIN dua d ON d.id = de.duaFk
WHERE d.id = vDuaFk
LIMIT 1;
CALL ledger_next(vFiscalYear, FALSE, vBookEntry);
CALL ledger_nextTx(vFiscalYear, FALSE, vBookEntry);
END IF;
OPEN vInvoicesIn;

View File

@ -12,7 +12,7 @@ BEGIN
WHERE id = vDuaFk;
IF vBookNumber IS NULL OR NOT vBookNumber THEN
CALL ledger_next(YEAR(vBookDated), FALSE, vBookNumber);
CALL ledger_nextTx(YEAR(vBookDated), FALSE, vBookNumber);
END IF;
-- Apunte de la aduana

View File

@ -70,7 +70,7 @@ BEGIN
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
IF vBookNumber IS NULL THEN
CALL ledger_next(vFiscalYear, FALSE, vBookNumber);
CALL ledger_nextTx(vFiscalYear, FALSE, vBookNumber);
END IF;
-- Apunte del proveedor

View File

@ -61,7 +61,7 @@ BEGIN
WHERE io.id = vInvoice;
SELECT YEAR(FECHA) INTO vFiscalYear FROM rs LIMIT 1;
CALL ledger_next(vFiscalYear, FALSE, vBookNumber);
CALL ledger_nextTx(vFiscalYear, FALSE, vBookNumber);
-- Linea del cliente
INSERT INTO XDiario(
ASIEN,

View File

@ -28,7 +28,7 @@ BEGIN
DECLARE vIsOriginalAClient BOOL;
DECLARE vPayMethodCompensation INT;
CALL ledger_next(YEAR(vDated), FALSE, vNewBookEntry);
CALL ledger_nextTx(YEAR(vDated), FALSE, vNewBookEntry);
SELECT COUNT(id) INTO vIsOriginalAClient
FROM client

View File

@ -1,38 +1,21 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
IN vFiscalYear INT,
IN vIsManageTransaction BOOLEAN,
OUT vLastBookEntry INT
)
/**
* Devuelve un número de asiento válido, según el contador de asientos
* tabla vn.ledgerConfig, si no existe lo inicializa a 1
* No inicia transacción, para transaccionar usar vn.ledger_nextTx
*
* @param vFiscalYear Id del año contable
* @return vLastBookEntry Id del asiento
*/
BEGIN
DECLARE vHasStartTransaction BOOLEAN;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
IF vHasStartTransaction THEN
ROLLBACK TO sp;
RESIGNAL;
ELSE
ROLLBACK;
CALL util.throw ('It has not been possible to generate a new ledger');
END IF;
END;
IF vFiscalYear IS NULL THEN
CALL util.throw('Fiscal year is required');
END IF;
IF NOT vIsManageTransaction THEN
SELECT @@in_transaction INTO vHasStartTransaction;
IF NOT vHasStartTransaction THEN
START TRANSACTION;
ELSE
SAVEPOINT sp;
END IF;
END IF;
SELECT bookEntry + 1 INTO vLastBookEntry
FROM ledgerCompany
WHERE fiscalYear = vFiscalYear
@ -48,13 +31,5 @@ BEGIN
UPDATE ledgerCompany
SET bookEntry = vLastBookEntry
WHERE fiscalYear = vFiscalYear;
IF NOT vIsManageTransaction THEN
IF vHasStartTransaction THEN
RELEASE SAVEPOINT sp;
ELSE
COMMIT;
END IF;
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,35 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_nextTx`(
IN vFiscalYear INT,
OUT vLastBookEntry INT
)
/**
* Devuelve un número de asiento válido, según el contador de asientos
* tabla vn.ledgerConfig, si no existe lo inicializa a 1
* Lo hace transaccionando el proceso
*
* @param vFiscalYear Id del año contable
* @return vLastBookEntry Id del asiento
*/
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
IF vFiscalYear IS NULL THEN
CALL util.throw('Fiscal year is required');
END IF;
IF @@in_transaction THEN
CALL util.throw('This procedure should not be executed within a transaction');
END IF;
START TRANSACTION;
CALL ledger_next(vFiscalYear, vLastBookEntry);
COMMIT;
END$$
DELIMITER ;

View File

@ -39,7 +39,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`xdiario_new`(
*/
BEGIN
IF vBookNumber IS NULL THEN
CALL ledger_next(YEAR(vDated), FALSE, vBookNumber);
CALL ledger_nextTx(YEAR(vDated), FALSE, vBookNumber);
END IF;
INSERT INTO XDiario

View File

@ -23,7 +23,7 @@ BEGIN
FROM supplier
WHERE id = NEW.supplierFk;
CALL ledger_next(YEAR(NEW.received), TRUE, vNewBookEntry);
CALL ledger_next(YEAR(NEW.received), vNewBookEntry);
INSERT INTO XDiario (
ASIEN,