2024-06-03 18:16:27 +00:00
|
|
|
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
|
2024-06-04 14:43:09 +00:00
|
|
|
DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction;
|
2024-06-03 18:16:27 +00:00
|
|
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
|
|
BEGIN
|
2024-06-04 14:43:09 +00:00
|
|
|
CALL util.tx_rollback(vIsRequiredTx);
|
2024-06-03 18:16:27 +00:00
|
|
|
RESIGNAL;
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF vFiscalYear IS NULL THEN
|
|
|
|
CALL util.throw('Fiscal year is required');
|
|
|
|
END IF;
|
|
|
|
|
2024-06-04 14:43:09 +00:00
|
|
|
CALL util.tx_start(vIsRequiredTx);
|
2024-06-03 18:16:27 +00:00
|
|
|
CALL ledger_next(vFiscalYear, vLastBookEntry);
|
2024-06-04 14:43:09 +00:00
|
|
|
CALL util.tx_commit(vIsRequiredTx);
|
2024-06-03 18:16:27 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|