SELECT aps.vendor_name,
ai.invoice_num,
NVL (
DECODE (
SIGN (SUM (amount - NVL (prepay_amount_remaining, amount))),
1,
DECODE (SUM (prepay_amount_remaining), 0, 'Y', NULL),
NULL
),
'N'
)
AS prepayment_invoice_status -- Y is Fully Applied, N is Partially or Not Applied
FROM ap_invoice_distributions_all aid
,ap_invoices_all ai
,ap_suppliers aps
WHERE aid.invoice_id = ai.invoice_id
AND aps.vendor_id = ai.vendor_id
AND aid.line_type_lookup_code = 'ITEM'
AND ai.invoice_type_lookup_code = 'PREPAYMENT'
--AND ai.invoice_id = :p_invoice_id
AND NVL (reversal_flag, 'N') <> 'Y'
GROUP BY aps.vendor_name, ai.invoice_num
ai.invoice_num,
NVL (
DECODE (
SIGN (SUM (amount - NVL (prepay_amount_remaining, amount))),
1,
DECODE (SUM (prepay_amount_remaining), 0, 'Y', NULL),
NULL
),
'N'
)
AS prepayment_invoice_status -- Y is Fully Applied, N is Partially or Not Applied
FROM ap_invoice_distributions_all aid
,ap_invoices_all ai
,ap_suppliers aps
WHERE aid.invoice_id = ai.invoice_id
AND aps.vendor_id = ai.vendor_id
AND aid.line_type_lookup_code = 'ITEM'
AND ai.invoice_type_lookup_code = 'PREPAYMENT'
--AND ai.invoice_id = :p_invoice_id
AND NVL (reversal_flag, 'N') <> 'Y'
GROUP BY aps.vendor_name, ai.invoice_num
No comments:
Post a Comment