2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-05-16 17:16:25 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
|
|
|
|
IN vFiscalYear INT,
|
2024-05-21 15:31:29 +00:00
|
|
|
OUT vLastBookEntry INT
|
2024-05-16 17:16:25 +00:00
|
|
|
)
|
2024-06-03 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
2024-05-21 15:31:29 +00:00
|
|
|
IF vFiscalYear IS NULL THEN
|
|
|
|
CALL util.throw('Fiscal year is required');
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT bookEntry + 1 INTO vLastBookEntry
|
|
|
|
FROM ledgerCompany
|
|
|
|
WHERE fiscalYear = vFiscalYear
|
|
|
|
FOR UPDATE;
|
|
|
|
|
|
|
|
IF vLastBookEntry IS NULL THEN
|
|
|
|
INSERT INTO ledgerCompany
|
|
|
|
SET fiscalYear = vFiscalYear,
|
|
|
|
bookEntry = 1;
|
|
|
|
SET vLastBookEntry = 1;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
UPDATE ledgerCompany
|
|
|
|
SET bookEntry = vLastBookEntry
|
2024-05-16 16:48:59 +00:00
|
|
|
WHERE fiscalYear = vFiscalYear;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
2024-05-21 15:31:29 +00:00
|
|
|
DELIMITER ;
|