Hotfix contabilizar DUA Ticket #188682 #2519

Merged
carlosap merged 2 commits from Hotfix-contabilizar-DUA-Ticket-#188682 into master 2024-05-28 11:34:05 +00:00
3 changed files with 42 additions and 34 deletions

View File

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

View File

@ -1,7 +1,17 @@
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,
vBookNumber INT
)
BEGIN
DECLARE vBookNumber INT;
/**
* 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 vFiscalYear INT;
CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn
@ -58,7 +68,10 @@ BEGIN
WHERE ii.id = vSelf;
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
IF vBookNumber IS NULL THEN
CALL ledger_next(vFiscalYear, vBookNumber);
END IF;
-- Apunte del proveedor

quitar la variable

quitar la variable
INSERT INTO XDiario(

View File

@ -32,7 +32,7 @@ module.exports = Self => {
}
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();
} catch (e) {
if (tx) await tx.rollback();