Query to Find Credit Memos Matched to an AP Invoice

When a credit memo or debit memo is matched to an invoice in Oracle Payables, the memo’s distributions point back to the original invoice. In AP_INVOICE_DISTRIBUTIONS_ALL this link is the PARENT_INVOICE_ID column, and in R12 the invoice line also stores it in AP_INVOICE_LINES_ALL.CORRECTED_INV_ID. Joining AP_INVOICES_ALL to itself through that column shows which memos belong to which invoice.

Query: number of invoices each memo is matched to

This query returns each memo number (ai1) and the count of distinct invoices (ai2) that it is matched to:

  SELECT COUNT (DISTINCT ai2.invoice_num), ai1.invoice_num
    FROM ap.ap_invoices_all            ai1,
         ap.ap_invoice_distributions_all aid1,
         ap.ap_invoices_all            ai2
   WHERE     ai1.invoice_id = aid1.invoice_id
         AND aid1.parent_invoice_id = ai2.invoice_id
         AND ai1.org_id = ai2.org_id
GROUP BY ai1.invoice_num

Query: list all credit and debit memos for one invoice

To start from the invoice instead and see every memo applied to it, with the amount, use the R12 line-level link:

SELECT inv.invoice_num             parent_invoice,
       inv.invoice_amount          invoice_amount,
       cm.invoice_num              memo_number,
       cm.invoice_type_lookup_code memo_type,
       cm.invoice_date             memo_date,
       SUM (cml.amount)            memo_amount
  FROM ap_invoices_all      inv,
       ap_invoice_lines_all cml,
       ap_invoices_all      cm
 WHERE cml.corrected_inv_id = inv.invoice_id
   AND cm.invoice_id = cml.invoice_id
   AND cm.invoice_type_lookup_code IN ('CREDIT', 'DEBIT')
   AND inv.invoice_num = :p_invoice_num
   AND inv.org_id = :p_org_id
 GROUP BY inv.invoice_num,
          inv.invoice_amount,
          cm.invoice_num,
          cm.invoice_type_lookup_code,
          cm.invoice_date
 ORDER BY cm.invoice_date;

Notes

  • Memo amounts are negative for credit memos, so invoice_amount + SUM(memo_amount) gives the net invoice value.
  • Pass :p_org_id (operating unit) because invoice numbers are unique only per supplier and operating unit.
  • Cancelled memos still appear; add AND cm.cancelled_date IS NULL to exclude them.

How is a credit memo linked to an invoice in Oracle Payables?

When the memo is matched to an invoice, its lines store the invoice ID in AP_INVOICE_LINES_ALL.CORRECTED_INV_ID and its distributions store it in AP_INVOICE_DISTRIBUTIONS_ALL.PARENT_INVOICE_ID.

What is the difference between a credit memo and a debit memo in AP?

A credit memo is a negative amount document sent by the supplier. A debit memo is a negative amount document you create to notify the supplier of a credit you are taking. Both reduce the amount you owe.

Which column identifies the invoice type in AP_INVOICES_ALL?

INVOICE_TYPE_LOOKUP_CODE, with values such as STANDARD, CREDIT, DEBIT, PREPAYMENT and MIXED.

Related queries

Related posts: Upload your own post and refer it anywhere anytime: