35 lines
892 B
SQL
35 lines
892 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`ledger_next`(
|
|
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
|
|
* No inicia transacción, para transaccionar usar vn.ledger_nextTx
|
|
*
|
|
* @param vFiscalYear Id del año contable
|
|
* @return vLastBookEntry Id del asiento
|
|
*/
|
|
BEGIN
|
|
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
|
|
WHERE fiscalYear = vFiscalYear;
|
|
END$$
|
|
DELIMITER ; |