From d0b926b2c5176685324836649ba1ed4ed3936f38 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 12 Jun 2024 14:26:26 +0200 Subject: [PATCH] feat: refs #7490 Changes --- .../vn/procedures/duaInvoiceInBooking.sql | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index efaf29b41..1f026e96b 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -24,6 +24,16 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + UPDATE 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 + SET ii.booked = IFNULL(ii.booked, d.booked), + ii.operated = IFNULL(ii.operated, d.operated), + ii.issued = IFNULL(ii.issued, d.issued), + ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried) + WHERE d.id = vDuaFk; + SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk; IF vBookEntry IS NULL THEN @@ -65,21 +75,21 @@ BEGIN JOIN ( WITH entries AS ( SELECT e.id, de.duaFk - FROM `entry` e + 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 duaEntry + WHERE duaFk = vDuaFk + AND NOT customsValue + ) + SELECT e.id FROM entries e - LEFT JOIN notBookedEntries nbe ON nbe.id = e.id - WHERE nbe.id IS NULL + LEFT JOIN notBookedEntries nbe ON nbe.entryFk = e.id + WHERE nbe.entryFk IS NULL ) sub ON sub.id = e.id SET e.isBooked = TRUE, e.isConfirmed = TRUE;