SELECT
DISTINCT cust_acct.ACCOUNT_NUMBER customer_number,
SUBSTRB (HP.party_name, 1, 50) customer_name,
ps.trx_number Invoice_No,
ps.trx_date,
(SELECT DESCRIPTION
FROM RA_CUSTOMER_TRX_LINES_ALL
WHERE CUSTOMER_TRX_ID = ps.CUSTOMER_TRX_ID
AND DESCRIPTION IS NOT NULL
AND ROWNUM = 1)
PRODUCT_CATEGORY,
ps.due_date,
NVL (ps.amount_due_original, 0) Invoice_amt,
NVL (ps.AMOUNT_DUE_REMAINING, 0) DUEAMOUNT,
-- NVL (SUM (ps.amount_due_remaining), 0) invoice_balance
NVL ( (ps.amount_due_REMAINING * NVL (ps.EXCHANGE_RATE, 1)), 0)
NET_OUTSTANDING,
PS.CLASS TYPE,
(SELECT DISTINCT name
FROM JTF_RS_SALESREPS
WHERE salesrep_id(+) = rta.primary_salesrep_id)
SALESREP_NAME,
HP.STATE REGION,
HP.COUNTY Continent,
TERMS.NAME CREDIT_PERIOD,
TRUNC (SYSDATE) RUN_DATE,
:P_AS_ON_DATE AS_ON_DATE
FROM ra_cust_trx_types_all rtt,
ra_customer_trx_all rta,
ra_cust_trx_line_gl_dist_all rgld,
gl_code_combinations cc,
hz_cust_accounts_all cust_acct,
--ra_customer_trx_lines_all rctla,
hz_parties hp,
--JTF_RS_SALESREPS REP,
ra_terms terms,
ar_payment_schedules_all ps,
hz_cust_acct_sites_all acct_site,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses_all site_uses
WHERE --cust_acct.account_number = :p_account_number
ps.customer_id = cust_acct.cust_account_id
AND ps.cust_trx_type_id = rtt.cust_trx_type_id
AND cust_acct.party_id = hp.party_id
--and rta.customer_trx_id = rctla.customer_trx_id
AND rta.term_id = terms.term_id
-- AND ps.trx_date <= :p_as_of_date
AND ps.CLASS NOT IN ('CM', 'PMT')
AND site_uses.site_use_code = 'BILL_TO'
AND acct_site.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
AND NVL (site_uses.status, 'A') = 'A'
AND cust_acct.cust_account_id = acct_site.cust_account_id
AND acct_site.cust_acct_site_id = site_uses.cust_acct_site_id
AND ps.customer_id = acct_site.cust_account_id
AND ps.customer_site_use_id = site_uses.site_use_id
AND rta.customer_trx_id = ps.customer_trx_id
AND rta.customer_trx_id = rgld.customer_trx_id
AND rgld.code_combination_id = cc.code_combination_id
AND rgld.account_class = 'REV'
-- AND RTA.ORG_ID = 102
AND RTA.SET_OF_BOOKS_ID = '2021'
AND rta.previous_customer_trx_id IS NULL
AND cust_acct.account_number =
NVL (:P_CUST_NUMBER, cust_acct.account_number)
AND ps.ORG_ID = :P_ORG_ID
AND HP.party_name = NVL (:P_CUST_NAME, HP.party_name)
AND ps.TRX_NUMBER <= NVL (:P_FROM_INVOICE_NO, ps.trx_number)
AND ps.TRX_NUMBER >= NVL (:P_TO_INVOICE_NO, ps.trx_number)
and TRUNC (ps.gl_date) <= :P_AS_ON_DATE
AND PS.AMOUNT_DUE_REMAINING <> 0
ORDER BY TRX_DATE
DISTINCT cust_acct.ACCOUNT_NUMBER customer_number,
SUBSTRB (HP.party_name, 1, 50) customer_name,
ps.trx_number Invoice_No,
ps.trx_date,
(SELECT DESCRIPTION
FROM RA_CUSTOMER_TRX_LINES_ALL
WHERE CUSTOMER_TRX_ID = ps.CUSTOMER_TRX_ID
AND DESCRIPTION IS NOT NULL
AND ROWNUM = 1)
PRODUCT_CATEGORY,
ps.due_date,
NVL (ps.amount_due_original, 0) Invoice_amt,
NVL (ps.AMOUNT_DUE_REMAINING, 0) DUEAMOUNT,
-- NVL (SUM (ps.amount_due_remaining), 0) invoice_balance
NVL ( (ps.amount_due_REMAINING * NVL (ps.EXCHANGE_RATE, 1)), 0)
NET_OUTSTANDING,
PS.CLASS TYPE,
(SELECT DISTINCT name
FROM JTF_RS_SALESREPS
WHERE salesrep_id(+) = rta.primary_salesrep_id)
SALESREP_NAME,
HP.STATE REGION,
HP.COUNTY Continent,
TERMS.NAME CREDIT_PERIOD,
TRUNC (SYSDATE) RUN_DATE,
:P_AS_ON_DATE AS_ON_DATE
FROM ra_cust_trx_types_all rtt,
ra_customer_trx_all rta,
ra_cust_trx_line_gl_dist_all rgld,
gl_code_combinations cc,
hz_cust_accounts_all cust_acct,
--ra_customer_trx_lines_all rctla,
hz_parties hp,
--JTF_RS_SALESREPS REP,
ra_terms terms,
ar_payment_schedules_all ps,
hz_cust_acct_sites_all acct_site,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses_all site_uses
WHERE --cust_acct.account_number = :p_account_number
ps.customer_id = cust_acct.cust_account_id
AND ps.cust_trx_type_id = rtt.cust_trx_type_id
AND cust_acct.party_id = hp.party_id
--and rta.customer_trx_id = rctla.customer_trx_id
AND rta.term_id = terms.term_id
-- AND ps.trx_date <= :p_as_of_date
AND ps.CLASS NOT IN ('CM', 'PMT')
AND site_uses.site_use_code = 'BILL_TO'
AND acct_site.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
AND NVL (site_uses.status, 'A') = 'A'
AND cust_acct.cust_account_id = acct_site.cust_account_id
AND acct_site.cust_acct_site_id = site_uses.cust_acct_site_id
AND ps.customer_id = acct_site.cust_account_id
AND ps.customer_site_use_id = site_uses.site_use_id
AND rta.customer_trx_id = ps.customer_trx_id
AND rta.customer_trx_id = rgld.customer_trx_id
AND rgld.code_combination_id = cc.code_combination_id
AND rgld.account_class = 'REV'
-- AND RTA.ORG_ID = 102
AND RTA.SET_OF_BOOKS_ID = '2021'
AND rta.previous_customer_trx_id IS NULL
AND cust_acct.account_number =
NVL (:P_CUST_NUMBER, cust_acct.account_number)
AND ps.ORG_ID = :P_ORG_ID
AND HP.party_name = NVL (:P_CUST_NAME, HP.party_name)
AND ps.TRX_NUMBER <= NVL (:P_FROM_INVOICE_NO, ps.trx_number)
AND ps.TRX_NUMBER >= NVL (:P_TO_INVOICE_NO, ps.trx_number)
and TRUNC (ps.gl_date) <= :P_AS_ON_DATE
AND PS.AMOUNT_DUE_REMAINING <> 0
ORDER BY TRX_DATE
No comments:
Post a Comment