SELECT
hou.name operating_unit,
hou.organization_id org_id,
ooha.order_number sales_order_number,
ooha.cust_po_number po_number,
ohdff.subscription_id subscription_id,
trunc(ooha.ordered_date) sales_order_date,
trunc(ooha.booked_date) booked_date,
hca1.account_number bill_to_customer_number,
hp1.party_name bill_to_customer_name,
hca2.account_number ship_to_customer_number,
hp2.party_name ship_to_customer_name,
nvl(oe_totals_grp.get_order_total(ooha.header_id, NULL, 'LINES'), 0) order_amount,
okhb.contract_number,
okhb.contract_number_modifier,
trunc(okhb.start_date) contract_start_date,
trunc(okhb.end_date) contract_end_date,
round(okhb.estimated_amount, 2) contract_amount,
okhb.sts_code,
okhb.id,
rcta.trx_number invoice_number,
trunc(rcta.trx_date) invoice_date,
rcta.invoice_currency_code invoice_currency,
SUM(rctla.extended_amount) invoice_amount,
decode(apsa.status, 'OP', 'Open', 'CL', 'Close') invoice_status,
rcta.customer_trx_id,
ooha.header_id,
ottt.name order_type,
ooha.context
FROM
hr_operating_units hou,
oe_order_headers_all ooha,
oe_transaction_types_tl ottt,
hz_cust_site_uses_all hcsua1,
hz_cust_acct_sites_all hcasa1,
hz_cust_accounts hca1,
hz_parties hp1,
hz_cust_site_uses_all hcsua2,
hz_cust_acct_sites_all hcasa2,
hz_cust_accounts hca2,
hz_parties hp2,
okc_k_rel_objs rel,
okc_k_headers_all_b okhb,
ra_customer_trx_all rcta,
ar_payment_schedules_all apsa,
ra_customer_trx_lines_all rctla,
oe_order_headers_all_dfv ohdff
WHERE
1 = 1
AND hou.organization_id = ooha.org_id
AND ooha.order_type_id = ottt.transaction_type_id
AND ottt.language = userenv('LANG')
AND hcsua1.site_use_id = ooha.invoice_to_org_id
AND hcasa1.cust_acct_site_id = hcsua1.cust_acct_site_id
AND hca1.cust_account_id = hcasa1.cust_account_id
AND hp1.party_id = hca1.party_id
AND hcsua2.site_use_id = ooha.ship_to_org_id
AND hcasa2.cust_acct_site_id = hcsua2.cust_acct_site_id
AND hca2.cust_account_id = hcasa2.cust_account_id
AND hp2.party_id = hca2.party_id
AND to_number(rel.chr_id) = okhb.id
AND rel.object1_id1 = ooha.header_id
AND ooha.org_id = okhb.org_id
AND rel.jtot_object1_code = 'OKX_ORDERHEAD'
AND okhb.contract_number = rctla.interface_line_attribute1
AND okhb.contract_number_modifier = rctla.interface_line_attribute2
AND rctla.interface_line_context = 'OKS CONTRACTS'
AND rctla.line_type = 'LINE'
AND rcta.customer_trx_id = rctla.customer_trx_id
AND rcta.org_id = rctla.org_id
AND apsa.customer_trx_id = rctla.customer_trx_id
AND apsa.org_id = rctla.org_id
AND ohdff.rowid = ooha.rowid
AND ohdff.amp_order = 'Y'
AND hou.organization_id IN ( 101 )
-- AND OKHB.CONTRACT_NUMBER in ('11413838','11397088','IR5134831')
GROUP BY
hou.name,
hou.organization_id,
ooha.order_number,
ooha.cust_po_number,
ohdff.subscription_id,
trunc(ooha.ordered_date),
trunc(ooha.booked_date),
hca1.account_number,
hp1.party_name,
hca2.account_number,
hp2.party_name,
okhb.contract_number,
okhb.contract_number_modifier,
okhb.start_date,
okhb.end_date,
round(okhb.estimated_amount, 2),
okhb.sts_code,
okhb.id,
rcta.trx_number,
trunc(rcta.trx_date),
rcta.invoice_currency_code,
apsa.status,
rcta.customer_trx_id,
ooha.header_id,
ottt.name,
ooha.context
No comments:
Post a Comment