Select gjl. je_header_id,
Gjl. je_line_num,
Gjh. je_source,
Gjh. name,
Gjh.doc _ sequence_value,
Xag. third_party_id vendor_id,
Xag. third_party_name vendor_name,
Xag. third_party_sub_id vendor_site_id,
Xag. third_party_sub_name vendor_address,
Null gl_desc,
Xag. trx_type_name invoice_desc, -- invoice description (Abstract)
Gjh. default_1_tive_date, -- GL date
Gcc. segment4, -- Subject
Xag. entered_dr,
Xag. entered_cr
From gl_je_headers_v gjh,
Gl_je_lines_v gjl,
(Select jeh. je_header_id,
R. je_line_num,
222 application_id,
Adj.org _ id org_id,
Trxact. name trx_type_name,
Ard. amount_dr entered_dr,
Ard. amount_cr entered_cr,
Ard. third_party_id,
Cust_acct.account_number third_party_number,
Substrb (party. party_name, 1, 50) third_party_name,
Ard. third_party_sub_id,
Su. location third_party_sub_name
From gl_je_headers jeh,
Gl_import_references r,
Ar_distributions_all ard,
Ar_adjustments_all adj,
Ra_customer_trx_all ct,
Ra_customer_trx_all ct_chg,
Ar_receivables_trx_all trxact,
Hz_cust_site_uses_all su,
Hz_cust_accounts cust_acct,
Hz_parties party,
Ra_cust_trx_types_all ctt,
Fnd_document_sequences seq,
Gl_daily_conversion_types glct
Where ard. source_table = 'help'
And ard. source_id = adj. adjustment_id
And nvl (ard.org _ id,-99) = nvl (adj.org _ id,-99)
And glct. conversion_type (+) = ard. currency_conversion_type
And seq.doc _ sequence_id (+) = adj.doc _ sequence_id
And ct. customer_trx_id = adj. customer_trx_id
And nvl (ct.org _ id,-99) = nvl (adj.org _ id,-99)
And nvl (ctt.org _ id,-99) = nvl (ct.org _ id,-99)
And ctt. cust_trx_type_id = ct. cust_trx_type_id
And su. site_use_id = ard. third_party_sub_id
And nvl (su.org _ id,-99) = nvl (ard.org _ id,-99)
And cust_acct.cust_account_id = ard. third_party_id
And cust_acct.party_id = party. party_id
And ct_chg.customer_trx_id (+) = adj. chargeback_customer_trx_id
And nvl (ct_chg.org_id (+),-99) = nvl (adj.org _ id,-99)
And trxact. receivables_trx_id (+) = adj. receivables_trx_id
And nvl (trxact.org _ id (+),-99) = nvl (adj.org _ id,-99)
And ard. line_id = to_number (r. reference_3)
And r. je_header_id = jeh. je_header_id
And jeh. je_category = 'adjustment') xag,
Gl_code_combinations_kfv gcc
Where xag. application_id = 222
And gjh. je_source = 'receivables '-- Receivables management system
And gjl. je_header_id = gjh. je_header_id
And gjh. status = 'P'
And gjl. code_combination_id = gcc. code_combination_id
And gcc. segment2 = nvl ('02', gcc. segment2) -- business department section, 02 indicates the liquid milk Department
And gcc. segment4 = '000000' -- Customer Protection deposit Normal 0 22410302 LB 0 2 false MicrosoftInternetExplorer4
And xag. je_header_id = gjl. je_header_id
And xag. je_line_num = gjl. je_line_num
And xag. third_party_id = nvl (p_vendor_name, xag. third_party_id) -- supplier
And xag. third_party_sub_id = nvl (p_vendor_site, xag. third_party_sub_id) -- location
And gjh. period_name = '2017-01'