2835: --To handle case like prepayment application and one invoice with different period
2836: --If ae_header_id is derived from invoice,
2837: --it indicates that ae_header_id derived from invoice or prepayment application and it may be used as a condition
2838: AND ((EXISTS (SELECT Aid.Invoice_Id
2839: FROM Ap_Invoice_Distributions_All Aid
2840: WHERE Aid.Invoice_Id = ln_invoice_id --variable: ln_invoice_id
2841: AND Aid.period_name = lv_period_name) --variable: lv_period_name
2842: AND Aeh.Ae_Header_Id = ln_ae_header_id) --variable: ln_ae_header_id
2843: OR (NOT EXISTS
2841: AND Aid.period_name = lv_period_name) --variable: lv_period_name
2842: AND Aeh.Ae_Header_Id = ln_ae_header_id) --variable: ln_ae_header_id
2843: OR (NOT EXISTS
2844: (SELECT Aid.Invoice_Id
2845: FROM Ap_Invoice_Distributions_All Aid
2846: WHERE Aid.Invoice_Id = ln_invoice_id --variable: ln_invoice_id
2847: AND Aid.period_name = lv_period_name)) --variable: lv_period_name
2848: );
2849: