Merge pull request 'Hotfix contabilizar DUA Ticket #188682' (!2519) from Hotfix-contabilizar-DUA-Ticket-#188682 into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2519
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Carlos Andrés 2024-05-28 11:34:04 +00:00
commit dc3c92eef1
3 changed files with 42 additions and 34 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,7 +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,
vBookNumber INT
)
BEGIN 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; DECLARE vFiscalYear INT;
CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn
@ -58,7 +68,10 @@ 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 vBookNumber IS NULL THEN
CALL ledger_next(vFiscalYear, vBookNumber);
END IF;
-- Apunte del proveedor -- Apunte del proveedor
INSERT INTO XDiario( INSERT INTO XDiario(

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();