Hotfix contabilizar DUA Ticket #188682
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Carlos Andrés 2024-05-28 12:30:17 +02:00
parent 60ac8cf6fc
commit 6e5b41a886
3 changed files with 44 additions and 33 deletions

View File

@ -6,12 +6,12 @@ BEGIN
* *
* @param vDuaFk Id del dua a recalcular * @param vDuaFk Id del dua a recalcular
*/ */
DECLARE done BOOL DEFAULT FALSE; DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vInvoiceFk INT; DECLARE vInvoiceFk INT;
DECLARE vASIEN BIGINT DEFAULT 0; DECLARE vBookEntry INT;
DECLARE vCounter INT DEFAULT 0; DECLARE vFiscalYear INT;
DECLARE rs CURSOR FOR DECLARE vInvoicesIn CURSOR FOR
SELECT DISTINCT e.invoiceInFk SELECT DISTINCT e.invoiceInFk
FROM entry e FROM entry e
JOIN duaEntry de ON de.entryFk = e.id JOIN duaEntry de ON de.entryFk = e.id
@ -20,9 +20,7 @@ BEGIN
AND de.customsValue AND de.customsValue
AND ii.isBooked = FALSE; AND ii.isBooked = FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN rs;
UPDATE invoiceIn ii UPDATE invoiceIn ii
JOIN entry e ON e.invoiceInFk = ii.id JOIN entry e ON e.invoiceInFk = ii.id
@ -36,35 +34,32 @@ BEGIN
e.isConfirmed = TRUE e.isConfirmed = TRUE
WHERE d.id = vDuaFk; WHERE d.id = vDuaFk;
SELECT IFNULL(ASIEN,0) INTO vASIEN SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk;
FROM dua
WHERE id = vDuaFk;
FETCH rs INTO vInvoiceFk; IF vBookEntry IS NULL THEN
SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear
FROM invoiceIn ii
JOIN entry e ON e.invoiceInFk = ii.id
JOIN duaEntry de ON de.entryFk = e.id
JOIN dua d ON d.id = de.duaFk
WHERE d.id = vDuaFk;
CALL ledger_next(vFiscalYear, vBookEntry);
END IF;
WHILE NOT done DO OPEN vInvoicesIn;
CALL invoiceIn_booking(vInvoiceFk); l: LOOP
SET vDone = FALSE;
IF vCounter > 0 OR vASIEN > 0 THEN FETCH vInvoicesIn INTO vInvoiceFk;
UPDATE XDiario x
JOIN ledgerConfig lc ON lc.lastBookEntry = x.ASIEN
SET x.ASIEN = vASIEN;
ELSE
SELECT lastBookEntry INTO vASIEN FROM ledgerConfig;
IF vDone THEN
LEAVE l;
END IF; END IF;
SET vCounter = vCounter + 1; CALL invoiceIn_booking(vInvoiceFk, vBookEntry);
END LOOP;
FETCH rs INTO vInvoiceFk; CLOSE vInvoicesIn;
END WHILE;
CLOSE rs;
UPDATE dua UPDATE dua
SET ASIEN = vASIEN SET ASIEN = vASIEN

View File

@ -1,6 +1,17 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(vSelf INT) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(
vSelf INT,
vBookEntry INT
)
BEGIN BEGIN
/**
* Genera la contabilidad para una factura y la marca como contabilizada
* Cuadra el asiento generado en si encuentra problemas derivados
* de los calculos con decimales
*
* @param vSelf Id invoiceIn
* @param vBookEntry Id de asiento, si es NULL se genera uno nuevo
*/
DECLARE vBookNumber INT; DECLARE vBookNumber INT;
DECLARE vFiscalYear INT; DECLARE vFiscalYear INT;
@ -58,7 +69,12 @@ BEGIN
WHERE ii.id = vSelf; WHERE ii.id = vSelf;
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1; SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
CALL ledger_next(vFiscalYear, vBookNumber);
IF vBookEntry IS NULL THEN
CALL ledger_next(vFiscalYear, vBookNumber);
ELSE
SET vBookNumber = vBookEntry;
END IF;
-- Apunte del proveedor -- Apunte del proveedor
INSERT INTO XDiario( INSERT INTO XDiario(
@ -187,7 +203,7 @@ BEGIN
LEFT JOIN ( LEFT JOIN (
SELECT e.id SELECT e.id
FROM tInvoiceIn tii FROM tInvoiceIn tii
JOIN expense e ON e.id = tii.expenseFk JOIN expense e ON e.id = tii.expenseFk
WHERE e.isWithheld WHERE e.isWithheld
LIMIT 1 LIMIT 1
) eWithheld ON TRUE ) eWithheld ON TRUE

View File

@ -32,7 +32,7 @@ module.exports = Self => {
} }
try { try {
await Self.rawSql(`CALL vn.invoiceIn_booking(?)`, [id], myOptions); await Self.rawSql(`CALL vn.invoiceIn_booking(?, NULL)`, [id], myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();