Merge pull request 'refactor: refs #7490 Deleted update duaInvoiceInBooking' (!2561) from 7490-duaInvoiceInBooking into dev
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
Reviewed-on: #2561 Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
commit
a899ecaab7
|
@ -1,5 +1,7 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(
|
||||
vDuaFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Genera el asiento de un DUA y marca las entradas como confirmadas
|
||||
|
@ -29,9 +31,7 @@ BEGIN
|
|||
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),
|
||||
e.isBooked = TRUE,
|
||||
e.isConfirmed = TRUE
|
||||
ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried)
|
||||
WHERE d.id = vDuaFk;
|
||||
|
||||
SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk;
|
||||
|
@ -39,7 +39,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
|
||||
|
@ -49,7 +49,7 @@ BEGIN
|
|||
|
||||
OPEN vInvoicesIn;
|
||||
|
||||
l: LOOP
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vInvoicesIn INTO vInvoiceFk;
|
||||
|
||||
|
@ -70,5 +70,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 duaEntry
|
||||
WHERE duaFk = vDuaFk
|
||||
AND NOT customsValue
|
||||
)
|
||||
SELECT e.id
|
||||
FROM entries e
|
||||
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;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue