refactor: refs #7490 Deleted update duaInvoiceInBooking #2561
|
@ -1,5 +1,7 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(
|
||||||
|
vDuaFk INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Genera el asiento de un DUA y marca las entradas como confirmadas
|
* 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),
|
SET ii.booked = IFNULL(ii.booked, d.booked),
|
||||||
ii.operated = IFNULL(ii.operated, d.operated),
|
ii.operated = IFNULL(ii.operated, d.operated),
|
||||||
ii.issued = IFNULL(ii.issued, d.issued),
|
ii.issued = IFNULL(ii.issued, d.issued),
|
||||||
ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried),
|
ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried)
|
||||||
e.isBooked = TRUE,
|
|
||||||
e.isConfirmed = TRUE
|
|
||||||
WHERE d.id = vDuaFk;
|
WHERE d.id = vDuaFk;
|
||||||
|
|
||||||
SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk;
|
SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk;
|
||||||
|
@ -39,7 +39,7 @@ BEGIN
|
||||||
IF vBookEntry IS NULL THEN
|
IF vBookEntry IS NULL THEN
|
||||||
SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear
|
SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear
|
||||||
FROM invoiceIn ii
|
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 duaEntry de ON de.entryFk = e.id
|
||||||
JOIN dua d ON d.id = de.duaFk
|
JOIN dua d ON d.id = de.duaFk
|
||||||
WHERE d.id = vDuaFk
|
WHERE d.id = vDuaFk
|
||||||
|
@ -49,7 +49,7 @@ BEGIN
|
||||||
|
|
||||||
OPEN vInvoicesIn;
|
OPEN vInvoicesIn;
|
||||||
|
|
||||||
l: LOOP
|
l: LOOP
|
||||||
SET vDone = FALSE;
|
SET vDone = FALSE;
|
||||||
FETCH vInvoicesIn INTO vInvoiceFk;
|
FETCH vInvoicesIn INTO vInvoiceFk;
|
||||||
|
|
||||||
|
@ -70,5 +70,28 @@ l: LOOP
|
||||||
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
|
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
|
||||||
SET ii.isBooked = TRUE
|
SET ii.isBooked = TRUE
|
||||||
WHERE dii.duaFk = vDuaFk;
|
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$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue