2024-06-03 18:16:27 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ledger_nextTx`(
|
2024-06-03 18:16:27 +00:00
|
|
|
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 ;
|