AP Accounting Entries SQL Query

select
doc_type,
doc_num,
doc_date,
doc_desc,
supplier_no,
supplier_name,
doc_sequence_value,
accounting_class_code,
account_code,
gl_date,
currency_code,
entered_dr,
entered_cr,
accounted_dr,
accounted_cr,
description

from
(select
'Invoice' doc_type,
ai.invoice_num doc_num,
ai.invoice_date doc_date,
ai.description doc_desc,
s.segment1 supplier_no,
s.vendor_name supplier_name,
ai.doc_sequence_value,
xel.accounting_class_code,
c.concatenated_segments account_code,
xeh.accounting_date gl_date,
xel.currency_code,
xel.entered_dr,
xel.entered_cr,
xel.accounted_dr,
xel.accounted_cr,
xel.description

from
xla_ae_lines xel,
xla_ae_headers xeh,
ap_invoices_all ai,
ap_suppliers s,
xla.xla_transaction_entities xte,
gl_code_combinations_kfv c


where
s.vendor_id=ai.vendor_id 
and xel.application_id = xeh.application_id 
and xte.application_id = xeh.application_id 
and c.code_combination_id=xel.code_combination_id 
and xel.ae_header_id = xeh.ae_header_id 
and xte.source_id_int_1 = ai.invoice_id 
and xte.entity_id = xeh.entity_id 
and xte.application_id = 200 
and xte.entity_code = 'AP_INVOICES'

union all
select
'Invoice' doc_type,
to_char(ac.check_number) doc_num,
ac.check_date doc_date,
ac.description doc_desc,
s.segment1 supplier_no,
s.vendor_name supplier_name,
ac.doc_sequence_value,
xel.accounting_class_code,
c.concatenated_segments account_code,
xeh.accounting_date gl_date,
xel.currency_code,
xel.entered_dr,
xel.entered_cr,
xel.accounted_dr,
xel.accounted_cr,
xel.description

from
xla_ae_lines xel,
xla_ae_headers xeh,
ap_checks_all ac,
ap_suppliers s,
xla_transaction_entities xte,
gl_code_combinations_kfv c

where
s.vendor_id=ac.vendor_id 
and xel.application_id = xeh.application_id 
and xte.application_id = xeh.application_id 
and c.code_combination_id=xel.code_combination_id 
and xel.ae_header_id = xeh.ae_header_id 
and xte.source_id_int_1 = ac.check_id 
and xte.entity_id = xeh.entity_id 
and xte.application_id = 200 
and xte.entity_code = 'AP_PAYMENTS')

order by
doc_date,
gl_date,
doc_type,
doc_num

No comments:

Post a Comment