Aging 1

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

SELECT hca.

account_number
, hzp.party_name account_name
, term.name terms
, rctt.name trans_type
, ps.trx_number
, ps.trx_date
, ps.due_date
, ps.amount_due_original
, ps.amount_due_remaining
, CASE
WHEN CEIL(TRUNC (SYSDATE) - TRUNC (ps.due_date)) 90 THEN
ps.amount_due_remaining
ELSE NULL
END greater_than_90
FROM ar_payment_schedules_all ps
, hz_cust_accounts hca
, hz_parties hzp
, ra_customer_trx_all rct
, ra_cust_trx_types_all rctt
, ra_terms term
WHERE hca.cust_account_id = ps.customer_id
AND hca.party_id = hzp.party_id
AND ps.customer_trx_id = rct.customer_trx_id
AND rct.cust_trx_type_id = rctt.cust_trx_type_id (+)
AND ps.status = 'OP'
AND ps.class != 'PMT'
AND ps.amount_due_remaining != 0
AND ps.term_id = term.term_id (+)
ORDER BY hzp.party_name
;、、a

aaaaaaaa

--As of Date AR Aging


SELECT account_number
, account_name
, terms
, trans_type
, trx_number
, trx_date
, due_date
, amount_due_original
, amt_due_remaining
, CASE WHEN past_due_days 0
AND past_due_days 30
AND past_due_days 60
AND past_due_days 90
AND past_due_days 120 THEN amt_due_remaining ELSE NULL END
greater_than_120
FROM (SELECT hca.account_number
, hzp.party_name account_name
, term.name terms
, rctt.name trans_type
, ps.trx_number
, ps.trx_date
, ps.due_date
, ps.amount_due_original
, (ps.amount_due_original
- nvl((SELECT SUM (NVL (ara.amount_applied, 0))
FROM ar_receivable_applications_all ara
WHERE ara.applied_customer_trx_id =
ps.customer_trx_id
AND ara.display = 'Y'
AND TRUNC (ara.gl_date)
<= :p_as_of_date ),0)
+ NVL(( SELECT sum(nvl(aaa.amount,0))
FROM ar_adjustments_all aaa
WHERE aaa.payment_schedule_id =
ps.payment_schedule_id
AND aaa.gl_date <= :p_as_of_date ),0)
) amt_due_remaining
--, ps.amount_due_remaining amt_due_remaining
--, CEIL ( TRUNC ( SYSDATE ) - TRUNC ( ps.due_date ) )
past_due_days
, CEIL ( TO_DATE (TO_CHAR (:p_as_of_date, 'DD-MON-RRRR'),
'DD-MON-RRRR') - TRUNC ( ps.due_date ) ) past_due_days
FROM ar_payment_schedules_all ps
, hz_cust_accounts hca
, hz_parties hzp
, ra_customer_trx_all rct
, ra_cust_trx_types_all rctt
, ra_terms term
WHERE hca.cust_account_id = ps.customer_id
AND hca.party_id = hzp.party_id
AND ps.customer_trx_id = rct.customer_trx_id
AND rct.cust_trx_type_seq_id = rctt.cust_trx_type_seq_id(+)
--AND ps.status = 'OP'
AND ps.class != 'PMT'
AND ps.gl_date :p_as_of_date
--AND rct.invoice_currency_code = 'USD'
--AND ps.amount_due_remaining != 0
AND ps.term_id = term.term_id(+)
AND ps.org_id = :p_bu_id
AND rct.org_id = :p_bu_id)
ORDER BY account_name;

SELECT hca.account_number
, hzp.party_name account_name
, NULL terms
, ‘Payment’ trans_type
, cr.receipt_number trx_number
, ps.trx_date trx_date
, ps.trx_date due_date
, ps.amount_on_account amount_due_original
, ps.amount_on_account amt_due_remaining
, CEIL ( TO_DATE (TO_CHAR (:p_as_of_date, ‘DD-MON-RRRR’), ‘DD-MON-RRRR’) – TRUNC
( ps.trx_date ) ) past_due_days
FROM ar_payment_schedules_all ps
, ar_cash_receipts_all cr
, hz_cust_accounts hca
, hz_parties hzp
WHERE hca.cust_account_id = ps.customer_id
AND hca.party_id = hzp.party_id
–AND cr.currency_code = ‘USD’
AND cr.cash_receipt_id = ps.cash_receipt_id
AND ps.class = ‘PMT’
AND ps.amount_on_account != 0
AND ps.gl_date TO_DATE (TO_CHAR (:p_as_of_date, ‘DD-MON-RRRR’), ‘DD-MON-RRRR’);

````````
12221

You might also like