|
select distinct
aeh.accounting_event_id,
aeh.accounting_date,
aeh.org_id,
aeh.PERIOD_NAME,
aeh.gl_transfer_flag,
aeh.set_of_books_id,
aeh.accounting_error_code,
ael.accounting_error_code,
ael.ae_header_id,
ael.reference1 Supplier_Name,
decode(aea2.source_table, 'AP_INVOICES', aea2.invoice_num, null) invoice_num,
decode(aea2.source_table,'AP_CHECKS', aea2.check_number,
'AP_PAYMENT_HISTORY', aea2.check_number, null) check_number2
from ap_ae_lines ael, ap_ae_headers aeh,
(select aea.accounting_event_id, ai.invoice_num, ac.check_number, aea.source_table, ac.check_id
from ap_accounting_events aea, ap_invoices ai, ap_checks ac, ap_invoice_Payments aip
where (
(aea.source_table = 'AP_INVOICES' and aea.source_id = ai.invoice_id)
or (aea.source_table in ('AP_CHECKS', 'AP_PAYMENT_HISTORY') and aea.source_id = ac.check_id)
)
and ai.invoice_id = aip.invoice_id(+)
and aip.check_id = ac.check_id(+)
) aea2
where aeh.gl_transfer_flag <> 'Y'
and aeh.ae_header_id = ael.ae_header_id(+)
and aeh.period_name = 'May-04'
and aeh.accounting_event_id = aea2.accounting_event_id(+)
and aeh.set_of_books_id = &SOB_ID
order by ael.ae_header_id |
|