Fix Script
Fix Script
CURSOR c1
IS
SELECT (SELECT DISTINCT inv.invoice_num
FROM ap_invoices_all inv,
jai_tax_det_factors det
WHERE inv.invoice_id = det.trx_id
AND jagl.tax_det_factor_id = det.det_factor_id)
inv_number,
jagl.*
FROM jai_tax_journal_entries jagl
WHERE (tax_det_factor_id, tax_line_id) IN (
SELECT det_factor_id, tax_line_id
FROM (SELECT SUM (NVL (entered_dr, 0)) enter_dr,
SUM (NVL (entered_cr, 0)) enter_cr,
reference23 det_factor_id,
reference24 tax_line_id, currency_code
FROM gl_interface
WHERE 1 = 1
-- AND currency_code <> 'INR'
-- AND status = 'EU02,EP01'
AND reference23 IS NOT NULL
AND reference24 IS NOT NULL
AND user_je_source_name = 'Financials India'
AND user_je_category_name = 'AP Validate'
GROUP BY reference23, reference24, currency_code)
WHERE enter_dr <> enter_cr);
CURSOR c2
IS
SELECT *
FROM (SELECT SUM (NVL (entered_dr, 0)) enter_dr,
SUM (NVL (entered_cr, 0)) enter_cr,
reference23 det_factor_id, reference24 tax_line_id,
currency_code
FROM gl_interface
WHERE 1 = 1
-- AND currency_code <> 'INR'
-- AND status = 'EU02,EP01'
AND reference23 IS NOT NULL
AND reference24 IS NOT NULL
AND user_je_source_name = 'Financials India'
AND user_je_category_name = 'AP Validate'
GROUP BY reference23, reference24, currency_code)
WHERE enter_dr <> enter_cr;
BEGIN
FOR i IN c1
LOOP
DELETE jai_tax_journal_entries jagl
WHERE journal_entry_id = i.journal_entry_id;
END LOOP;
FOR j IN c2
LOOP
DELETE gl_interface
WHERE reference23 = j.det_factor_id
AND reference24 = j.tax_line_id
AND user_je_source_name = 'Financials India'
AND user_je_category_name = 'AP Validate';
END LOOP;
END;
COMMIT ;