2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT)
|
|
|
|
BEGIN
|
2024-02-15 09:04:15 +00:00
|
|
|
/**
|
|
|
|
* Genera el asiento de un DUA y marca las entradas como confirmadas
|
2024-02-15 09:14:19 +00:00
|
|
|
*
|
2024-02-15 09:04:15 +00:00
|
|
|
* @param vDuaFk Id del dua a recalcular
|
|
|
|
*/
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE done BOOL DEFAULT FALSE;
|
|
|
|
DECLARE vInvoiceFk INT;
|
2024-02-15 09:04:15 +00:00
|
|
|
DECLARE vASIEN BIGINT DEFAULT 0;
|
|
|
|
DECLARE vCounter INT DEFAULT 0;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE rs CURSOR FOR
|
2024-02-15 09:04:15 +00:00
|
|
|
SELECT DISTINCT e.invoiceInFk
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM entry e
|
|
|
|
JOIN duaEntry de ON de.entryFk = e.id
|
2024-02-15 09:04:15 +00:00
|
|
|
JOIN invoiceIn ii ON ii.id = e.invoiceInFk
|
|
|
|
WHERE de.duaFk = vDuaFk
|
2024-01-15 11:31:03 +00:00
|
|
|
AND de.customsValue
|
|
|
|
AND ii.isBooked = FALSE;
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
|
|
|
|
|
|
|
OPEN rs;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
UPDATE invoiceIn ii
|
|
|
|
JOIN entry e ON e.invoiceInFk = ii.id
|
2024-02-15 09:04:15 +00:00
|
|
|
JOIN duaEntry de ON de.entryFk = e.id
|
|
|
|
JOIN dua d ON d.id = de.duaFk
|
2024-01-15 11:31:03 +00:00
|
|
|
SET ii.isBooked = TRUE,
|
|
|
|
ii.booked = IFNULL(ii.booked,d.booked),
|
|
|
|
ii.operated = IFNULL(ii.operated,d.operated),
|
2024-02-15 09:04:15 +00:00
|
|
|
ii.issued = IFNULL(ii.issued,d.issued),
|
|
|
|
ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried),
|
|
|
|
e.isConfirmed = TRUE
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE d.id = vDuaFk;
|
2024-02-15 09:04:15 +00:00
|
|
|
|
|
|
|
SELECT IFNULL(ASIEN,0) INTO vASIEN
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM dua
|
|
|
|
WHERE id = vDuaFk;
|
2024-02-15 09:04:15 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
FETCH rs INTO vInvoiceFk;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
WHILE NOT done DO
|
|
|
|
|
|
|
|
CALL invoiceIn_booking(vInvoiceFk);
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
IF vCounter > 0 OR vASIEN > 0 THEN
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-02-23 07:14:58 +00:00
|
|
|
UPDATE XDiario x
|
2024-02-15 09:04:15 +00:00
|
|
|
JOIN ledgerConfig lc ON lc.lastBookEntry = x.ASIEN
|
|
|
|
SET x.ASIEN = vASIEN;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
ELSE
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
SELECT lastBookEntry INTO vASIEN FROM ledgerConfig;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
END IF;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-02-15 09:04:15 +00:00
|
|
|
SET vCounter = vCounter + 1;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
FETCH rs INTO vInvoiceFk;
|
|
|
|
|
|
|
|
END WHILE;
|
2024-02-15 09:04:15 +00:00
|
|
|
|
|
|
|
CLOSE rs;
|
|
|
|
|
2024-02-15 09:14:19 +00:00
|
|
|
UPDATE dua
|
2024-02-15 09:04:15 +00:00
|
|
|
SET ASIEN = vASIEN
|
|
|
|
WHERE id = vDuaFk;
|
2024-02-15 09:14:19 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|