refactor: refs #7490 Deleted update duaInvoiceInBooking #2561

Merged
guillermo merged 6 commits from 7490-duaInvoiceInBooking into dev 2024-06-21 05:04:33 +00:00
1 changed files with 28 additions and 5 deletions
Showing only changes of commit fb4be69cf1 - Show all commits

View File

@ -4,10 +4,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking
)
BEGIN
/**
* Genera el asiento de un DUA y marca las entradas como confirmadas
*
* @param vDuaFk Id del dua a recalcular
*/
* Genera el asiento de un DUA y marca las entradas como confirmadas
*
* @param vDuaFk Id del dua a recalcular
*/
DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vInvoiceFk INT;
DECLARE vBookEntry INT;
@ -29,7 +29,7 @@ BEGIN
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 `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
@ -60,5 +60,28 @@ l: LOOP
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
SET ii.isBooked = TRUE
WHERE dii.duaFk = vDuaFk;
UPDATE `entry` e
JOIN (
WITH entries AS (
SELECT e.id, de.duaFk
FROM `entry` e
JOIN duaEntry de ON de.entryFk = e.id
WHERE de.duaFk = vDuaFk
AND (NOT e.isBooked OR NOT e.isConfirmed)
),
notBookedEntries AS (
SELECT e.id
FROM entries e
JOIN duaEntry de ON de.entryFk = e.id
JOIN dua d ON d.id = de.duaFk
WHERE d.ASIEN IS NULL)
SELECT e.id
FROM entries e
LEFT JOIN notBookedEntries nbe ON nbe.id = e.id
WHERE nbe.id IS NULL
) sub ON sub.id = e.id
SET e.isBooked = TRUE,
e.isConfirmed = TRUE;
END$$
DELIMITER ;