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
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);
-- Apunte del proveedor

View File

@ -60,7 +60,7 @@ BEGIN
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
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);
-- Linea del cliente
INSERT INTO XDiario(

View File

@ -4,54 +4,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
OUT vNewBookEntry INT
)
BEGIN
DECLARE vLastBookEntry INT;
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;
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
SET bookEntry = LAST_INSERT_ID(bookEntry + 1)
WHERE fiscalYear = vFiscalYear;
IF vHasStartTransaction THEN
RELEASE SAVEPOINT sp;
ELSE
COMMIT;
END IF;
SET vNewBookEntry = LAST_INSERT_ID();
END$$
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,
`fiscalYear` int(10) unsigned NOT NULL COMMENT 'Año del ejercicio 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
COMMENT='Contador para asientos contables';