SELECT h.ae_header_id
--,ct.trx_number 事务处理编号
,h.doc_sequence_value 凭证编号
,l.currency_code 币别
,l.currency_conversion_rate 兑换率
,to_char(h.accounting_date,'yyyy-mm-dd') GL日期
,l.accounting_class_code 会计分类
,l.entered_dr 借方原币金额
,l.entered_cr 贷方原币金额
,l.accounted_dr 借方人民币金额
,l.accounted_cr 贷方方人民币金额
,fnd_flex_ext.get_segs('SQLGL',
'GL#',
50328,
l.Code_Combination_Id) 科目代码
,xla_oa_functions_pkg.get_ccid_description(50328,
l.Code_Combination_Id) 科目描述
,to_char(h.creation_date,'yyyy-mm-dd') 创建日期
,h.period_name 会计期间
,ct.org_id 组织ID
,pf.LAST_NAME 填证人
,trx_number 摘要
FROM xla.xla_ae_headers h, --子帐头
xla.xla_ae_lines l, --子帐行
xla.xla_events e, --会计事件
xla.xla_transaction_entities te, --会计事物处理实体
gl_ledgers gl,
ra_customer_trx_all ct, --应收发票头
hr_operating_units hou,
FND_USER u,
PER_PEOPLE_F pf
WHERE h.application_id = l.application_id
AND h.ae_header_id = l.ae_header_id
AND h.application_id = e.application_id
AND h.event_id = e.event_id
AND h.application_id = te.application_id
AND h.entity_id = te.entity_id
AND te.application_id = 222
AND gl.ledger_id = h.ledger_id
AND te.ledger_id = 2021
AND te.entity_code in ('TRANSACTIONS','ADJUSTMENTS')
AND nvl(te.source_id_int_1, (-99)) = ct.customer_trx_id
AND nvl(nvl(l.accounted_cr, l.accounted_dr), 0) <> 0
AND hou.organization_id = ct.org_id
AND u.employee_id = pf.PERSON_ID(+)
AND h.created_by = u.user_id(+)
ORDER BY h.doc_sequence_value ASC;
--AP INVOICES ACCOUNTING
SELECT h.ae_header_id
--,aia.invoice_num 发票编号
,h.doc_sequence_value 凭证编号
,to_char(h.accounting_date,'yyyy-mm-dd') GL日期
,fnd_flex_ext.get_segs('SQLGL',
'GL#',
50328,
l.Code_Combination_Id) 科目代码
,xla_oa_functions_pkg.get_ccid_description(50328,
l.Code_Combination_Id) 科目描述
,l.currency_code 币别
,l.currency_conversion_rate 兑换率
,l.entered_dr 借方原币金额
,l.entered_cr 贷方原币金额
,l.accounted_dr 借方人民币金额
,l.accounted_cr 贷方人民币金额
,h.period_name 会计期间
,aia.org_id 组织ID
,to_char(h.creation_date,'yyyy-mm-dd') 创建日期
,pf.LAST_NAME 填证人
,pv.VENDOR_NAME_ALT||' '||aia.invoice_num 摘要
FROM xla.xla_ae_headers h,
xla.xla_ae_lines l,
xla.xla_events e,
xla.xla_transaction_entities te,
gl_ledgers gl,
ap_invoices_all aia,
hr_operating_units hou,
FND_USER u,
PER_PEOPLE_F pf,
po_vendors pv
WHERE e.event_id = h.event_id
AND e.application_id = h.application_id
AND h.ae_header_id = l.ae_header_id
AND h.application_id = l.application_id
--AND nvl(nvl(accounted_cr, accounted_dr), 0) <> 0
AND h.application_id = 200
AND gl.ledger_id = h.ledger_id
AND te.application_id = h.application_id
AND te.entity_id = h.entity_id
AND te.entity_code = 'AP_INVOICES'
AND te.ledger_id = 2021
AND aia.invoice_id = nvl(te.source_id_int_1, -99)
AND hou.organization_id = aia.org_id
AND ap_invoices_pkg.get_posting_status(aia.invoice_id) IN ('Y', 'P')
AND h.balance_type_code = 'A'
AND u.employee_id = pf.PERSON_ID(+)
AND h.last_updated_by = u.user_id(+)
and aia.vendor_id=pv.VENDOR_ID(+)
ORDER BY h.doc_sequence_value ASC;