fix: refs #7400 ledger_next
gitea/salix/pipeline/pr-test There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2024-05-15 14:57:17 +02:00
parent f6c84065f0
commit 383f2f85cc
4 changed files with 10 additions and 51 deletions

View File

@ -57,7 +57,7 @@ BEGIN
LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva
WHERE ii.id = vSelf; WHERE ii.id = vSelf;
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn; SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
CALL ledger_next(vFiscalYear, vBookNumber); CALL ledger_next(vFiscalYear, vBookNumber);
-- Apunte del proveedor -- Apunte del proveedor

View File

@ -60,7 +60,7 @@ BEGIN
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
WHERE io.id = vInvoice; WHERE io.id = vInvoice;
SELECT YEAR(FECHA) INTO vFiscalYear FROM rs; SELECT YEAR(FECHA) INTO vFiscalYear FROM rs LIMIT 1;
CALL ledger_next(vFiscalYear, vBookNumber); CALL ledger_next(vFiscalYear, vBookNumber);
-- Linea del cliente -- Linea del cliente
INSERT INTO XDiario( INSERT INTO XDiario(

View File

@ -4,54 +4,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
OUT vNewBookEntry INT OUT vNewBookEntry INT
) )
BEGIN BEGIN
DECLARE vLastBookEntry INT; UPDATE ledgerCompany
DECLARE vHasStartTransaction BOOLEAN; SET bookEntry = LAST_INSERT_ID(bookEntry + 1)
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;
SELECT @@in_transaction INTO vHasStartTransaction;
IF NOT vHasStartTransaction THEN
START TRANSACTION;
ELSE
SAVEPOINT sp;
END IF;
SELECT bookEntry INTO vLastBookEntry
FROM ledgerCompany
WHERE fiscalYear = vFiscalYear
FOR UPDATE;
IF vLastBookEntry IS NULL THEN
INSERT INTO ledgerCompany
SET fiscalYear = vFiscalYear,
bookEntry = 1;
END IF;
SET vNewBookEntry = IFNULL(vLastBookEntry, 0) + 1;
UPDATE ledgerCompany
SET bookEntry = vNewBookEntry
WHERE fiscalYear = vFiscalYear; WHERE fiscalYear = vFiscalYear;
IF vHasStartTransaction THEN SET vNewBookEntry = LAST_INSERT_ID();
RELEASE SAVEPOINT sp;
ELSE
COMMIT;
END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,8 +1,10 @@
CREATE OR REPLACE TABLE vn.ledgerCompany (
CREATE TABLE OR REPLACE `ledgerCompany` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`fiscalYear` int(10) unsigned NOT NULL COMMENT 'Año del ejercicio contable', `fiscalYear` int(10) unsigned NOT NULL COMMENT 'Año del ejercicio contable',
`bookEntry` int(10) unsigned NOT NULL DEFAULT 1 COMMENT 'Contador asiento contable', `bookEntry` int(10) unsigned NOT NULL DEFAULT 1 COMMENT 'Contador asiento contable',
PRIMARY KEY (`id`) PRIMARY KEY (`id`),
UNIQUE KEY `ledgerCompany_unique` (`fiscalYear`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci
COMMENT='Contador para asientos contables'; COMMENT='Contador para asientos contables';