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
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2519 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
dc3c92eef1
|
@ -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;
|
||||
SELECT ASIEN INTO vBookEntry 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);
|
||||
|
||||
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;
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vInvoicesIn INTO vInvoiceFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
SET vCounter = vCounter + 1;
|
||||
CALL invoiceIn_booking(vInvoiceFk, vBookEntry);
|
||||
END LOOP;
|
||||
|
||||
FETCH rs INTO vInvoiceFk;
|
||||
|
||||
END WHILE;
|
||||
|
||||
CLOSE rs;
|
||||
CLOSE vInvoicesIn;
|
||||
|
||||
UPDATE dua
|
||||
SET ASIEN = vASIEN
|
||||
|
|
|
@ -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;
|
||||
CALL ledger_next(vFiscalYear, vBookNumber);
|
||||
|
||||
IF vBookNumber IS NULL THEN
|
||||
CALL ledger_next(vFiscalYear, vBookNumber);
|
||||
END IF;
|
||||
|
||||
-- Apunte del proveedor
|
||||
INSERT INTO XDiario(
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue