Thursday, 18 February 2016

How to Check orphan Payments through SQL Query

http://aporaclepayables.blogspot.com/2016/02/how-to-check-orphan-payments-through.html

select check_id, check_number from ap_checks_all where check_id
not in
(select check_id from ap_invoice_payments_all)

-----------------------------------------------------------------------------

select aa.check_id, aa.check_number, aa.BANK_ACCOUNT_NAME, aa.AMOUNT, aa.CLEARED_DATE, aa.CHECK_DATE, aa.CREATED_BY from ap_checks_all aa where check_id
not in
(select check_id from ap_invoice_payments_all)

----------------------------------------------------------------------------

 SELECT AC.CHECK_ID,
            AC.CHECK_NUMBER,
      AC.AMOUNT
       FROM AP_CHECKS_ALL AC,
            AP_PAYMENT_HISTORY_ALL APH
      WHERE AC.PAYMENT_ID IS NULL
        AND AC.STATUS_LOOKUP_CODE NOT IN ('OVERFLOW','SET UP','SPOILED')
        AND AC.CHECK_ID=APH.CHECK_ID
        AND NVL(APH.HISTORICAL_FLAG,'N') <> 'Y'
        --AND APH.POSTED_FLAG <>'Y'
        AND NOT EXISTS (SELECT 1
                          FROM AP_INVOICE_PAYMENTS_ALL AIP
                         WHERE AIP.CHECK_ID = AC.CHECK_ID)
        AND EXISTS  (SELECT 1
                       FROM AP_INVOICE_PAYMENTS_ALL AIP1,
                AP_CHECKS_ALL AC1
                      WHERE AIP1.CHECK_ID = AC1.CHECK_ID
                        AND AC.ORG_ID = AC1.ORG_ID
                        AND ((AC.VENDOR_ID = AC1.VENDOR_ID
                        AND AC.VENDOR_SITE_ID = AC1.VENDOR_SITE_ID)
                         OR AC.PAYMENT_DOCUMENT_ID =AC1.PAYMENT_DOCUMENT_ID)
                        AND AC.CHECK_NUMBER = AC1.CHECK_NUMBER )

No comments:

Post a Comment