AR Details Qry
AR Details Qry
o509970."Invoice",
o509970."Invoice Date",
o509970."Customer",
o509970."Customer #",
o509970."Customer Purchase Order",
o509970."Ship To Address1", o509970."Ship To Address2",
o509970."Ship To City", o509970."Ship To State",
o509970."Ship To Zip Code",
o509970."Bill To Address1", o509970."Bill To Address2",
o509970."Bill To City",o509970."Bill To State",
o509970."Bill To Zip Code",
o509970."Item Number",
o509970."Item Description",
o509970."Line Amount",
o509970."Line Type",
o509970."Tax Amount",
--o509970."Freight",
o509970."Exempt Amount",
o509970."Taxable Amount",
o509970."Invoice Total"
from (
select --tax_adjusted "Tax",
party_name "Customer",
account_number "Customer #",
purchase_order "Customer Purchase Order",
trx_number "Invoice",
trx_date "Invoice Date",
invoice_currency_code "Currency",
exchange_rate "Exchange Rate",
address1 "Ship To Address1",
address2 "Ship To Address2",
city "Ship To City",
state "Ship To State",
postal_code "Ship To Zip Code",
address1_bill_to "Bill To Address1",
address2_bill_to "Bill To Address2",
city_bill_to "Bill To City",
state_bill_to "Bill To State",
postal_code_bill_to "Bill To Zip Code",
inventory_item_id "Item Number",
description "Item Description",
extended_amount "Line Amount" ,
line_type "Line Type",
--freight_adjusted "Freight",
taxable_amount "Taxabale Amount",
(
select sum(rctl.extended_amount)
from ar.ra_customer_trx_lines_all rctl
where rctl.line_type = 'TAX'
and rctl.customer_trx_id = a.customer_trx_id
) "Tax Amount"
,nvl(extended_amount - taxable_amount,0) "Exempt Amount"
,taxable_amount "Taxable Amount",
(
select sum(nvl(rctl.extended_amount,0)) invoice_amt
from ar.ra_customer_trx_lines_all rctl
where rctl.customer_trx_id = a.customer_trx_id
) "Invoice Total"
from
(
select distinct --aa.tax_adjusted ,
hp.party_name ,
hca.account_number,
ct.purchase_order ,
ct.trx_number,
ct.trx_date ,
ct.invoice_currency_code ,
ct.exchange_rate ,
hl.address1 ,
hl.address2 ,
hl.city ,
hl.state ,
hl.postal_code ,
hba.address1 address1_bill_to ,
hba.address2 address2_bill_to ,
hba.city city_bill_to ,
hba.state state_bill_to ,
hba.postal_code postal_code_bill_to,
cta.inventory_item_id ,
cta.description,
cta.line_type,
cta.taxable_amount,
nvl(cta.extended_amount-cta.taxable_amount,0),
--freight_adjusted,
cta.extended_amount ,
cta.customer_trx_id
from
ar.ra_cust_trx_line_gl_dist_all aa, ar.ar_receivables_trx_all rt,
ar.ra_customer_trx_all ct, ar.ra_cust_trx_types_all rta,
ar.ra_customer_trx_lines_all cta
,ar.hz_parties hp
,ar.hz_cust_accounts hca
,ar.hz_party_sites hps
,ar.hz_cust_acct_sites_all hcas
,ar.hz_cust_site_uses_all hcsu
,ar.hz_locations hl
,ar.ra_cust_trx_types_all rctta
,(select hl.address1, hl.address2,hl.city, hl.state,
hl.postal_code, hcsu.site_use_id, hca.cust_account_id
from ar.hz_parties hp
,ar.hz_cust_accounts hca
,ar.hz_party_sites hps
,ar.hz_cust_acct_sites_all hcas
,ar.hz_cust_site_uses_all hcsu
,ar.hz_locations hl
where 1=1
and hcas.cust_acct_site_id = hcsu.cust_acct_site_id
and hps.party_site_id = hcas.party_site_id
and hp.party_id = hps.party_id
and hp.party_id = hca.party_id
and hcas.cust_account_id = hca.cust_account_id
and hps.location_id = hl.location_id
and hcsu.site_use_code = 'BILL_TO') hba
where 1=1
--and aa.RECEIVABLES_TRX_ID = rt.RECEIVABLES_TRX_ID
and aa.customer_trx_id = ct.customer_trx_id
and
aa.customer_trx_line_id = cta.customer_trx_line_id
and ct.customer_trx_id = cta.customer_trx_id
and ct.ship_to_site_use_id = hcsu.site_use_id
and rt.org_id = ct.org_id--sanju
and rt.org_id=118
and hcas.cust_acct_site_id = hcsu.cust_acct_site_id
and hps.party_site_id = hcas.party_site_id
and hp.party_id = hps.party_id
and hp.party_id = hca.party_id
and hcas.cust_account_id = hca.cust_account_id
and hps.location_id = hl.location_id
and ct.bill_to_customer_id = hba.cust_account_id
and ct.bill_to_site_use_id = hba.site_use_id
and ct.cust_trx_type_id = rta.cust_trx_type_id
and rta.type in ('INV','CM')
and aa.gl_date >= to_date('30-SEP-2012', 'DD-MON-YYYY')
and aa.gl_date <= to_date('29-DEC-2012', 'DD-MON-YYYY')
and aa.set_of_books_id = 1001
and hl.state='CA'
--and ct.trx_number='12969636'
group by --aa.apply_date, aa.gl_date,
--aa.adjustment_number, aa.line_adjusted,
freight_adjusted, aa.tax_adjusted,
--aa.type,
rt.name, --aa.reason_code,
hl.state ,
hp.party_name, hca.account_number,
ct.trx_number, ct.trx_date,
ct.invoice_currency_code, ct.exchange_rate,
hl.address1, hl.address2,
hl.city, hl.state,
hl.postal_code,
hba.address1, hba.address2,
hba.city, hba.state,
hba.postal_code, cta.inventory_item_id,cta.description, cta.line_type,
cta.unit_standard_price ,
cta.extended_amount, cta.quantity_invoiced,ct.purchase_order
,cta.customer_trx_id,cta.taxable_amount
UNION ALL
select distinct /*+ RULE */ --aa.tax_adjusted "Tax",
hp.party_name "Customer", hca.account_number "Customer #",ct.purchase_order
"Customer Purchase Order",
ct.trx_number "Invoice", ct.trx_date "Invoice Date",
ct.invoice_currency_code "Currency", ct.exchange_rate "Exchange Rate",
hl.address1 "Ship To Address1", hl.address2 "Ship To Address2",
hl.city "Ship To City", hl.state "Ship To State",
hl.postal_code "Ship To Zip Code",
hba.address1 "Bill To Address1", hba.address2 "Bill To Address2",
hba.city "Bill To City", hba.state "Bill To State",
hba.postal_code "Bill To Zip Code", cta.inventory_item_id "Item Number",
cta.description "Item Description",
cta.line_type "Line Type",--freight_adjusted "Freight",
cta.unit_standard_price "Line Amount" ,cta.customer_trx_id,
nvl(cta.extended_amount-cta.taxable_amount,0) "Exempt Amount"
,cta.taxable_amount "Taxable Amount"
from ar.ra_cust_trx_line_gl_dist_all aa, ar.ar_receivables_trx_all rt,
ar.ra_customer_trx_all ct,ar.ra_cust_trx_types_all rta,
ar.ra_customer_trx_lines_all cta
,ar.hz_parties hp
,ar.hz_cust_accounts hca
,ar.hz_party_sites hps
,ar.hz_cust_acct_sites_all hcas
,ar.hz_cust_site_uses_all hcsu
,ar.hz_locations hl
,ar.ra_cust_trx_types_all rctta
,(select hl.address1, hl.address2,hl.city, hl.state,
hl.postal_code, hcsu.site_use_id, hca.cust_account_id
from ar.hz_parties hp
,ar.hz_cust_accounts hca
,ar.hz_party_sites hps
,ar.hz_cust_acct_sites_all hcas
,ar.hz_cust_site_uses_all hcsu
,ar.hz_locations hl
where hcas.cust_acct_site_id = hcsu.cust_acct_site_id
and hps.party_site_id = hcas.party_site_id
and hp.party_id = hps.party_id
and hp.party_id = hca.party_id
and hcas.cust_account_id = hca.cust_account_id
and hps.location_id = hl.location_id
and hcsu.site_use_code = 'BILL_TO') hba
where --aa.RECEIVABLES_TRX_ID = rt.RECEIVABLES_TRX_ID
aa.customer_trx_id = ct.customer_trx_id
and
aa.customer_trx_line_id = cta.customer_trx_line_id
and ct.customer_trx_id = cta.customer_trx_id
and ct.bill_to_site_use_id = hcsu.site_use_id
and ct.ship_to_site_use_id is null
and hcas.cust_acct_site_id = hcsu.cust_acct_site_id
and hps.party_site_id = hcas.party_site_id
and hp.party_id = hps.party_id
and hp.party_id = hca.party_id
and hcas.cust_account_id = hca.cust_account_id
and hps.location_id = hl.location_id
and ct.bill_to_customer_id = hba.cust_account_id
and ct.bill_to_site_use_id = hba.site_use_id
and aa.gl_date >= to_date('30-SEP-2012', 'DD-MON-YYYY')
and aa.gl_date <= to_date('29-DEC-2012', 'DD-MON-YYYY')
and ct.cust_trx_type_id = rta.cust_trx_type_id
and rta.type in ('INV','CM')
and aa.set_of_books_id = 1001
and hl.state='CA'
and rt.org_id = ct.org_id--sanju
and rt.org_id=118
--and ct.trx_number='12969636'
group by --aa.apply_date, aa.gl_date, aa.adjustment_number, aa.line_adjusted,
--freight_adjusted, aa.tax_adjusted,
--aa.type,
rt.name, --aa.reason_code,
hl.state ,
hp.party_name, hca.account_number,
ct.trx_number, ct.trx_date,
ct.invoice_currency_code, ct.exchange_rate,
hl.address1, hl.address2,
hl.city, hl.state,
hl.postal_code,
hba.address1, hba.address2,
hba.city, hba.state,
hba.postal_code , cta.inventory_item_id, cta.description,
cta.unit_standard_price ,cta.extended_amount
,cta.quantity_invoiced,ct.purchase_order
,cta.customer_trx_id,cta.line_type,cta.taxable_amount
)a
)o509970
--order by o509970."Invoice"