R12_專題知識總結提煉-AR模塊


應收模塊簡介

應收模塊是用來為企業提供應收款管理的模塊。

當企業銷售一筆商品或者發生其他影響收入和現金的業務的時候,需要在應收模塊記賬。

本文檔以R12為例,11i可參考,只針對簡單業務情況考慮,將應收可能產生的業務流程和相應會計分錄進行整理,供參考。對於一些財務類報表,如三欄明細賬等會有所幫助。

 

R12版本的應收模塊可以從三方面取到會計分錄:

1)         應收業務,例如應收發票的分配明細、應收收款的核銷記錄、收款歷史等等,通過這里取得的數據是最為明細的。

2)         子模塊帳,R12新增的特性,將各模塊產生會計分錄的邏輯集中到xla模塊進行處理。在創建會計分錄時會產生子模塊的帳。可以關聯到發票或收款編號,但是無法具體到發票分配行等特別明細的記錄。

3)         總賬,子模塊傳至總賬的數據,無法具體到具體的業務,如需追溯只能通過gl_import_reference表來關聯xla的表,進而追溯到發票和收款。

不管是應收業務還是子模塊帳,各個帳戶的期間發生額是可以與總賬對賬的。

應收發票

不管是OM導入應收發票還是手工錄入應收發票,對企業來講,大多數應收業務都是表示企業產生一筆應收款項,同時增加一筆收入。記賬如下:

DR  應收款項-銷售商品   XXX  表示企業銷售商品而產生一筆應收款尚未收到
CR  銷項稅                         XXX 
CR  業務收入-銷售商品   XXX 表示企業因為銷售商品當期增加了一筆收入

1)         錄入應收發票;完成完成以后,我們可以通過sql查找到應收發票的分錄信息(發票分配)。此為具體到發票行的分配信息。參考ar_trx_001.sql。

SELECT ct.trx_number
      ,ctl.description
      ,fnd_flex_ext.get_segs('SQLGL'
                            ,'GL#'
                            ,gcc.chart_of_accounts_id
                            ,gcc.code_combination_id) account_number
      ,gd.gl_date
      ,to_number(decode(gd.account_class
                       ,'REC'
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,NULL
                              ,nvl(gd.amount, 0))
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,-nvl(gd.amount, 0)
                              ,NULL))) entered_dr
      ,to_number(decode(gd.account_class
                       ,'REC'
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,-nvl(gd.amount, 0)
                              ,NULL)
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,NULL
                              ,nvl(gd.amount, 0)))) entered_cr
  FROM ra_customer_trx_all          ct
      ,ra_customer_trx_lines_all    ctl
      ,ra_cust_trx_line_gl_dist_all gd
      ,gl_code_combinations         gcc
 WHERE gd.customer_trx_id = ct.customer_trx_id
   AND gd.customer_trx_line_id = ctl.customer_trx_line_id(+)
   AND gcc.code_combination_id = gd.code_combination_id
   AND ct.customer_trx_id = &customer_trx_id;
View Code

2)         創建會計分錄;第二步我們可以在應收模塊創建會計分錄,R12中,此時將匯總業務模塊的分錄(發票分配)而產生應收子模塊的分錄。取數參考ar_trx_xla_001.sql(含發票分錄和貸項通知單核銷)。

SELECT ct.trx_number
      ,l.accounting_class_code
      ,l.entered_dr
      ,l.entered_cr
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, l.code_combination_id) account_number
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id) account_description
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ra_customer_trx_all          ct
 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 te.entity_code = 'TRANSACTIONS'
   AND nvl(te.source_id_int_1, (-99)) = ct.customer_trx_id
   AND ct.customer_trx_id = 3139;
View Code

3)         傳送子模塊分錄至總賬;如果第二步沒有直接過賬至總賬,可以提交請求:將日記帳分錄傳送至 GL。

此時總賬將生成來源為je_source=’Receivables’ and je_category=’Sales Invoices’、‘Debit Memos’或’Credit Memos‘的日記賬分錄。

貸項通知單和借項通知單

1)         借項通知單:

應收的借項通知單是用來增加應收的、相當於獨立的發票。不可以核銷。

例如當我們對應收發票收款以后發現收款有誤,此時我們可以通過用借項通知單沖銷收款的方式來實現。相當於重新通過借項通知單來向客戶收款。

借項通知單分錄與發票類似,增加應收款項、增加當期收入(參考ar_trx_001.sql及ar_trx_xla_001.sql):

DR 應收   XXX
CR
收入   XXX

2)         貸項通知單:

應收的貸項通知單是用來減少應收、沖原始發票的,常用來做銷售退貨業務。可以用來核銷原始發票。

貸項通知單分錄,正好沖減因為銷售發票增加的應收和收入(參考ar_trx_001.sql及ar_trx_xla_001.sql):

DR 收入   XXX
CR
應收  XXX

3)         貸項通知單核銷

DR  貸項通知單的應收
CR 
被核銷發票的應收

可以通過sql查到核銷的分錄(分配信息)。參考ar_cmapp_001.sql。這里核銷的時候oracle按照核銷的總金額按比例分攤到被核銷發票的每一行上,可以通過ar_distributions_all進行追溯。

SELECT cm.trx_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,ra.gl_date
      ,ct.trx_number applied_trx_number
      ,ad.acctd_amount_dr
      ,ad.acctd_amount_cr
  FROM ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ar_payment_schedules_all       ps
      ,ra_customer_trx_all            cm
      ,ra_customer_trx_all            ct
 WHERE ad.source_table = 'RA'
   AND ad.source_type = 'REC'
   AND ad.source_id = ra.receivable_application_id
   AND ra.customer_trx_id = cm.customer_trx_id
      --
   AND ra.applied_payment_schedule_id = ps.payment_schedule_id
   AND ps.customer_trx_id = ct.customer_trx_id(+)
   AND ra.customer_trx_id = 51671
View Code

1)         創建會計分錄后,R12可以從xla查詢到子模塊的看會計分錄。參考附件ar_trx_xla_001.sql。

SELECT ct.trx_number
      ,l.accounting_class_code
      ,l.entered_dr
      ,l.entered_cr
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, l.code_combination_id) account_number
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id) account_description
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ra_customer_trx_all          ct
 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 te.entity_code = 'TRANSACTIONS'
   AND nvl(te.source_id_int_1, (-99)) = ct.customer_trx_id
   AND ct.customer_trx_id = 3139;
View Code

2)         傳送子模塊分錄至總賬;如果第二步沒有直接過賬至總賬,可以提交請求:將日記帳分錄傳送至 GL。

        此時總賬將生成來源為je_source=’Receivables’ and je_category=’Sales Invoices’、‘Debit Memos’或’Credit Memos‘的日記賬分錄。

貸項通知單和借項通知單

1)         借項通知單:

應收的借項通知單是用來增加應收的、相當於獨立的發票。不可以核銷。

例如當我們對應收發票收款以后發現收款有誤,此時我們可以通過用借項通知單沖銷收款的方式來實現。相當於重新通過借項通知單來向客戶收款。

借項通知單分錄與發票類似,增加應收款項、增加當期收入(參考ar_trx_001.sql及ar_trx_xla_001.sql):

DR 應收   XXX
CR
收入   XXX

2)         貸項通知單:

應收的貸項通知單是用來減少應收、沖原始發票的,常用來做銷售退貨業務。可以用來核銷原始發票。

貸項通知單分錄,正好沖減因為銷售發票增加的應收和收入(參考ar_trx_001.sql及ar_trx_xla_001.sql):

DR 收入   XXX
CR
應收  XXX

3)         貸項通知單核銷

DR  貸項通知單的應收
CR 
被核銷發票的應收

可以通過sql查到核銷的分錄(分配信息)。參考ar_cmapp_001.sql。這里核銷的時候oracle按照核銷的總金額按比例分攤到被核銷發票的每一行上,可以通過ar_distributions_all進行追溯。

SELECT cm.trx_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,ra.gl_date
      ,ct.trx_number applied_trx_number
      ,ad.acctd_amount_dr
      ,ad.acctd_amount_cr
  FROM ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ar_payment_schedules_all       ps
      ,ra_customer_trx_all            cm
      ,ra_customer_trx_all            ct
 WHERE ad.source_table = 'RA'
   AND ad.source_type = 'REC'
   AND ad.source_id = ra.receivable_application_id
   AND ra.customer_trx_id = cm.customer_trx_id
      --
   AND ra.applied_payment_schedule_id = ps.payment_schedule_id
   AND ps.customer_trx_id = ct.customer_trx_id(+)
   AND ra.customer_trx_id = 51671
View Code

1)         創建會計分錄后,R12可以從xla查詢到子模塊的看會計分錄。參考附件ar_trx_xla_001.sql。

2)         傳至總賬后將生成來源為je_source=’Receivables’ and je_category=’Credit Memos‘的日記賬分錄。、

應收發票調整

應收發票錄入完成后可以通過菜單項:活動->調整進入應收發票調整界面。

主要用來稅調整,壞賬處理之類的動作。來相應增加減少應收款項。

如因為客戶破產而無法全部追回應收款項則可以如下調整來減少應收:

DR 壞賬
CR 
應收款項

1)         錄入調整后,可以通過sql查找到調整的業務模塊的分錄(分配信息)。參考ar_adj_001.sql。

SELECT ct.trx_number
      ,adj.adjustment_number
      ,ad.amount_dr
      ,ad.amount_cr
      ,ad.source_table
      ,ad.source_type
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,ad.code_combination_id)
  FROM ar_distributions_all ad
      ,ar_adjustments_all   adj
      ,ra_customer_trx_all  ct
 WHERE ad.source_table = 'ADJ'
   AND ad.source_id = adj.adjustment_id
   AND adj.customer_trx_id = ct.customer_trx_id
   AND ct.customer_trx_id = 3958;
View Code

2)         同樣,R12版本創建分錄后可以查找到子模塊的分錄信息。參考附件ar_adj_xla_001.sql。

SELECT ct.trx_number
      ,l.accounting_class_code
      ,l.entered_dr
      ,l.entered_cr
      ,xla_oa_functions_pkg.get_ccid_description(50328,l.code_combination_id)
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ar_adjustments_all           adj
      ,ra_customer_trx_all          ct
 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 te.ledger_id=2022
   AND te.entity_code = 'ADJUSTMENTS'
   AND nvl(te.source_id_int_1,(-99))=adj.adjustment_id
   AND adj.customer_trx_id = ct.customer_trx_id
   AND ct.customer_trx_id=3958;
View Code

3)         傳至總賬后將生成來源為je_source=’Receivables’ and je_category=’ Adjustment ‘的日記賬分錄。

  

收款和核銷

1)         錄入收款

收款錄入表示企業收到客戶現金(以銀行存款為例,實際可能會有票據等其他收款方式),如果未核銷表示尚未與具體的客戶發票相關聯。現金流量表需要在此做標識。此時的會計分錄應為

DR  銀行存款
CR  應收賬款-未核銷

這里的應收賬款-未核銷科目是一個中轉科目。

2)         核銷發票時的分錄如下。

DR            應收款-未核銷
CR             應收賬款-發票

收款錄入或者核銷以后,可以通過sql查到收款的分錄信息(相當於收款分配)。參考ar_rcpt_001.sql。

-- 收款核銷,貸項通知單核銷也是通過ar_receivable_applications_all表
SELECT cr.receipt_number
      ,ad.amount_dr
      ,ad.amount_cr
      ,ad.source_table
      ,ad.source_type
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,ad.code_combination_id)
      ,ad.creation_date
  FROM ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ar_cash_receipts_all           cr
 WHERE ad.source_table = 'RA'
   AND ad.source_id = ra.receivable_application_id
   AND ra.cash_receipt_id = cr.cash_receipt_id
   AND cr.cash_receipt_id = &cash_receipt_id
-- 收款記錄
UNION ALL
SELECT cr.receipt_number
      ,ad.amount_dr
      ,ad.amount_cr
      ,ad.source_table
      ,ad.source_type
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,ad.code_combination_id)
      ,ad.creation_date
  FROM ar_distributions_all        ad
      ,ar_cash_receipt_history_all crh
      ,ar_cash_receipts_all        cr
 WHERE ad.source_table = 'CRH'
   AND ad.source_id = crh.cash_receipt_history_id
   AND crh.cash_receipt_id = cr.cash_receipt_id
   AND cr.cash_receipt_id = &cash_receipt_id
 ORDER BY creation_date;
View Code

3)         創建會計分錄以后,R12版本則可以匯總生成xla的信息,也就是子模塊的收款的會計分錄。可以通過以下sql查到。

SELECT cr.receipt_number
      ,l.accounting_class_code
      ,l.entered_dr
      ,l.entered_cr
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id)
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ar_cash_receipts_all         cr
 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 te.ledger_id = 2022
   AND te.entity_code = 'RECEIPTS'
   AND nvl(te.source_id_int_1, -99) = cr.cash_receipt_id
   AND nvl(te.source_id_int_1, -99) = &cash_receipt_id;
View Code

4)         傳至總賬后將生成來源為je_source=’Receivables’ and je_category=’ Receipts ‘的日記賬分錄。

雜項收款

雜項收款不核銷,只相當於計一筆收到現金的賬,一般常用於記錄銀行利息等影響現金類科目的業務。

以銀行利息為例,雜項收款的分錄如下:

DR   銀行存款
CR   財務費用-利息收入

表示收到一筆銀行利息收入存入銀行存款。

1)    雜項收款錄入后可以通過以下sql查找到分錄信息(分配)。參考:ar_mcd_001.sql

SELECT cr.receipt_number,cr.cash_receipt_id
      ,ad.amount_dr
      ,ad.amount_cr
      ,ad.source_table
      ,ad.source_type
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,ad.code_combination_id)
      ,ad.creation_date
  FROM ar_distributions_all           ad
      ,ar_misc_cash_distributions_all mcd
      ,ar_cash_receipts_all           cr
 WHERE ad.source_table = 'MCD'
   AND ad.source_id = mcd.misc_cash_distribution_id
   AND mcd.cash_receipt_id = cr.cash_receipt_id
   AND cr.cash_receipt_id = &cash_receipt_id
View Code

3)    創建會計分錄后,R12版本可以通過sql查詢到子模塊創建的分錄。參考上面的sql:ar_rcpt_xla_001.sql

4)    傳至總賬后將生成來源為je_source=’Receivables’ and je_category=’ Misc Receipts ‘的日記賬分錄。

應收模塊總賬追溯

將以上各種應收業務類型對應的取會計分錄的sql,union all在一起即是所有應收模塊產生的會計分錄。

R12

1)    通過發票分配等從業務角度取到的會計分錄,參考如下sql

-- 應收發票、DM、CM
SELECT ct.trx_number
      ,fnd_flex_ext.get_segs('SQLGL'
                            ,'GL#'
                            ,gcc.chart_of_accounts_id
                            ,gcc.code_combination_id) account_number
      ,gd.gl_date
      ,to_number(decode(gd.account_class
                       ,'REC'
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,NULL
                              ,nvl(gd.amount, 0))
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,-nvl(gd.amount, 0)
                              ,NULL))) entered_dr
      ,to_number(decode(gd.account_class
                       ,'REC'
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,-nvl(gd.amount, 0)
                              ,NULL)
                       ,decode(sign(nvl(gd.amount, 0))
                              ,-1
                              ,NULL
                              ,nvl(gd.amount, 0)))) entered_cr
  FROM ra_customer_trx_all          ct
      ,ra_customer_trx_lines_all    ctl
      ,ra_cust_trx_line_gl_dist_all gd
      ,gl_code_combinations         gcc
 WHERE gd.customer_trx_id = ct.customer_trx_id
   AND gd.customer_trx_line_id = ctl.customer_trx_line_id(+)
   AND gcc.code_combination_id = gd.code_combination_id
   UNION ALL
-- DM APP
SELECT cm.trx_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,ra.gl_date
      ,ad.acctd_amount_dr
      ,ad.acctd_amount_cr
  FROM ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ar_payment_schedules_all       ps
      ,ra_customer_trx_all            cm
      ,ra_customer_trx_all            ct
 WHERE ad.source_table = 'RA'
   AND ad.source_type = 'REC'
   AND ad.source_id = ra.receivable_application_id
   AND ra.customer_trx_id = cm.customer_trx_id
      --
   AND ra.applied_payment_schedule_id = ps.payment_schedule_id
   AND ps.customer_trx_id = ct.customer_trx_id(+)
   AND ra.customer_trx_id = 51671
   UNION ALL
-- Adjustment
SELECT ct.trx_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,adj.gl_date
      ,ad.amount_dr
      ,ad.amount_cr
  FROM ar_distributions_all ad
      ,ar_adjustments_all   adj
      ,ra_customer_trx_all  ct
 WHERE ad.source_table = 'ADJ'
   AND ad.source_id = adj.adjustment_id
   AND adj.customer_trx_id = ct.customer_trx_id
   AND ct.customer_trx_id = 3958
   UNION ALL
-- 收款核銷
SELECT cr.receipt_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,ra.gl_date
      ,ad.amount_dr
      ,ad.amount_cr
  FROM ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ar_cash_receipts_all           cr
 WHERE ad.source_table = 'RA'
   AND ad.source_id = ra.receivable_application_id
   AND ra.cash_receipt_id = cr.cash_receipt_id
   AND cr.cash_receipt_id = &cash_receipt_id
-- 收款記錄
UNION ALL
SELECT cr.receipt_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,crh.gl_date
      ,ad.amount_dr
      ,ad.amount_cr
  FROM ar_distributions_all        ad
      ,ar_cash_receipt_history_all crh
      ,ar_cash_receipts_all        cr
 WHERE ad.source_table = 'CRH'
   AND ad.source_id = crh.cash_receipt_history_id
   AND crh.cash_receipt_id = cr.cash_receipt_id
   AND cr.cash_receipt_id = &cash_receipt_id
-- 雜項收款
UNION ALL
SELECT cr.receipt_number
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ad.code_combination_id) account_number
      ,mcd.gl_date
      ,ad.amount_dr
      ,ad.amount_cr
  FROM ar_distributions_all           ad
      ,ar_misc_cash_distributions_all mcd
      ,ar_cash_receipts_all           cr
 WHERE ad.source_table = 'MCD'
   AND ad.source_id = mcd.misc_cash_distribution_id
   AND mcd.cash_receipt_id = cr.cash_receipt_id
   AND cr.cash_receipt_id = &cash_receipt_id
View Code

2)    通過xla取到的應收模塊會計分錄,參考如下sql

-- 發票,DM、CM、貸項通知單核銷
SELECT ct.trx_number
      ,h.accounting_date gl_date
      ,l.entered_dr
      ,l.entered_cr
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, l.code_combination_id) account_number
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id) account_description
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ra_customer_trx_all          ct
 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 te.entity_code = 'TRANSACTIONS'
   AND nvl(te.source_id_int_1, (-99)) = ct.customer_trx_id
   AND ct.customer_trx_id = 3139
UNION ALL
-- 收款、核銷、雜項收款
SELECT cr.receipt_number
      ,h.accounting_date gl_date
      ,l.entered_dr
      ,l.entered_cr
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, l.code_combination_id) account_number
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id) account_description
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ar_cash_receipts_all         cr
 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 te.ledger_id = 2022
   AND te.entity_code = 'RECEIPTS'
   AND nvl(te.source_id_int_1, -99) = cr.cash_receipt_id
   AND nvl(te.source_id_int_1, -99) = &cash_receipt_id
UNION ALL
-- ADJUSTMENTS
SELECT ct.trx_number
      ,h.accounting_date gl_date
      ,l.entered_dr
      ,l.entered_cr
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, l.code_combination_id) account_number
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id) account_description
  FROM xla_ae_headers               h
      ,xla_ae_lines                 l
      ,xla_events                   e
      ,xla.xla_transaction_entities te
      ,ar_adjustments_all           adj
      ,ra_customer_trx_all          ct
 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 te.ledger_id=2022
   AND te.entity_code = 'ADJUSTMENTS'
   AND nvl(te.source_id_int_1,(-99))=adj.adjustment_id
   AND adj.customer_trx_id = ct.customer_trx_id
   AND ct.customer_trx_id=3958;
View Code

3)    來自應收模塊的總賬日記賬分錄,參考如下sql

SELECT h.je_source
      ,h.je_category
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, l.code_combination_id) acct
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,l.code_combination_id) acct_descr
      ,l.entered_dr
      ,l.entered_cr
  FROM gl_je_headers        h
      ,gl_je_lines          l
      ,gl_code_combinations gcc
      ,gl_period_statuses   gps
 WHERE h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_source = 'Receivables'
   AND l.period_name = gps.period_name
   AND gps.application_id = 101
   AND gps.set_of_books_id = 2022
   AND h.actual_flag = 'A'
   AND h.period_name = '2009-01';
View Code

R12下總賬追溯子模塊,通過gl_import_reference表,如下sql:

SELECT h.je_source
      ,h.je_category
      ,fnd_flex_ext.get_segs('SQLGL', 'GL#', 50328, ael.code_combination_id) acct
      ,xla_oa_functions_pkg.get_ccid_description(50328
                                                ,ael.code_combination_id) acct_descr
      ,ael.entered_dr
      ,ael.entered_cr
  FROM gl_je_headers        h
      ,gl_je_lines          l
      ,gl_code_combinations gcc
      ,gl_period_statuses   gps
      ,gl_import_references ir
      ,xla_ae_lines         ael
 WHERE h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_source <> 'Receivables'
   AND l.period_name = gps.period_name
   AND gps.application_id = 101
   AND gps.set_of_books_id = 2022
   AND h.actual_flag = 'A'
   AND h.period_name = '2009-01'
   AND ir.je_header_id = l.je_header_id
   AND ir.je_line_num = l.je_line_num
   AND ael.gl_sl_link_id = ir.gl_sl_link_id
   AND ael.gl_sl_link_table = ir.gl_sl_link_table;
View Code

11i

附上以前寫的一個11i的總賬追溯子模塊的三欄明細賬的sql:11i_gl_journal_drill.sql,11i下測試通過,可以參考。

CREATE OR REPLACE VIEW CUX_GL_JOURNALS_V
(set_of_books_id, org_id, je_source, je_category, gl_date, period_name, effective_period_num, je_name, je_doc_num, sub_doc_num, code_combination_id, segment1, segment2, segment3, segment4, segment5, segment6, segment7, segment8, segment9, descr, third_party_name, party_site, currency_code, entered_dr, entered_cr, accounted_dr, accounted_cr, balance)
AS
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.name je_name
      ,h.doc_sequence_value je_doc_num
      ,to_char(ael.subledger_doc_sequence_value) ap_doc_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,decode(ae.source_table,'AP_CHECKS',ac.checkrun_name,ai.DESCRIPTION) descr
      ,pv.vendor_name
      ,pvs.vendor_site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches        b
      ,gl_je_headers        h
      ,gl_je_lines          l
      ,gl_code_combinations gcc
      ,gl_je_categories_v   jc
      ,gl_je_sources_v      js
      ,gl_period_statuses   gps
       --
      ,gl_import_references     i
      ,ap_ae_headers_all        aeh
      ,ap_ae_lines_all          ael
      ,ap_accounting_events_all ae
       --
      ,ap_invoices_all ai
      ,ap_checks_all   ac
       --
      ,po_vendors          pv
      ,po_vendor_sites_all pvs
 WHERE 1 = 1
      -- gl journal
   AND h.je_header_id = l.je_header_id
   AND h.je_batch_id = b.je_batch_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
   AND h.je_source = 'Payables'
   AND h.actual_flag = 'A'
   AND b.status='P'
      -- gl to ap
   AND l.je_header_id = i.je_header_id
   AND l.je_line_num = i.je_line_num
   AND i.gl_sl_link_id = ael.gl_sl_link_id
      -- ap journals
   AND ael.ae_header_id = aeh.ae_header_id
   AND h.period_name = aeh.period_name
   AND h.set_of_books_id = aeh.set_of_books_id
   AND aeh.accounting_event_id = ae.accounting_event_id
      --
   AND ael.third_party_id = pv.vendor_id(+)
   AND ael.third_party_sub_id = pvs.vendor_site_id(+)
   AND decode(ae.source_table, 'AP_INVOICES', ae.source_id, NULL) = ai.invoice_id(+)
   AND decode(ae.source_table, 'AP_CHECKS', ae.source_id, NULL) = ac.check_id(+)
   --AND ai.invoice_num='bz20071220lmx001'
-- Part2: AR Trade Receipts
UNION ALL
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,to_char(cr.receipt_number) ar_doc_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,csu.location descr
      ,ac.customer_name
      ,csu.location site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches                  b
      ,gl_je_lines                    l
      ,gl_code_combinations           gcc
      ,gl_je_headers                  h
      ,gl_je_categories_v             jc
      ,gl_je_sources_v                js
      ,gl_period_statuses             gps
      ,gl_import_references           i
      ,ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ar_cash_receipt_history_all    crh
      ,ar_cash_receipts_all           cr
      ,ar_receipt_methods             rm
      ,gl_sets_of_books               sob
      ,ar_customers                   ac
      ,hz_cust_site_uses_all          csu
 WHERE 1 = 1
      -- gl journals
   AND h.je_source = 'Receivables'
   AND h.je_category = 'Trade Receipts'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND l.je_header_id = h.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_batch_id = b.je_batch_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND h.set_of_books_id = sob.set_of_books_id
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
      -- gl to ar rcpt
   AND l.je_header_id = i.je_header_id
   AND l.je_line_num = i.je_line_num
   AND i.reference_3 = ad.line_id
      -- ar rcpt journals
   AND decode(ad.source_table, 'RA', ad.source_id, NULL) = ra.receivable_application_id(+)
   AND decode(ad.source_table, 'CRH', ad.source_id, NULL) = crh.cash_receipt_history_id(+)
   AND decode(ad.source_table, 'RA', ra.cash_receipt_id, 'CRH', crh.cash_receipt_id, NULL) = cr.cash_receipt_id
       -- addional info
   AND cr.receipt_method_id = rm.receipt_method_id
   AND cr.pay_from_customer = ac.customer_id(+)
   AND cr.customer_site_use_id = csu.site_use_id(+)
   --AND cr.receipt_number = 'test_ar_rcpt001'
-- Part3: AR Transactions & Credit Memos
UNION ALL
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,to_char(ct.trx_number) ar_doc_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,loc.address1 descr
      ,ac.customer_name
      ,csu.location site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches        b
      ,gl_je_headers        h
      ,gl_je_lines          l
      ,gl_code_combinations gcc
      ,gl_je_categories_v   jc
      ,gl_je_sources_v      js
      ,gl_period_statuses   gps
      ,gl_import_references i
       -- ra trx
      ,ra_customer_trx_all          ct
      ,ra_customer_trx_lines_all    ctl
      ,ra_cust_trx_line_gl_dist_all gd
       --
      ,ar_customers          ac
      ,hz_cust_site_uses_all csu
      ,hz_cust_acct_sites_all    hcas
      ,hz_party_sites        hps
      ,hz_locations          loc
 WHERE 1 = 1
      -- gl journal
   AND b.je_batch_id = h.je_batch_id
   AND h.je_header_id = l.je_header_id
   AND l.je_header_id = i.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
   AND l.je_line_num = i.je_line_num
      -- gl to ar
   AND h.je_source = 'Receivables'
   AND h.je_category IN ('Sales Invoices', 'Credit Memos')
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND i.reference_3 = gd.cust_trx_line_gl_dist_id
      -- ar journal
   AND gd.customer_trx_id = ct.customer_trx_id
   AND gd.customer_trx_line_id = ctl.customer_trx_line_id(+)
   AND ct.bill_to_customer_id = ac.customer_id
   AND ct.bill_to_site_use_id = csu.site_use_id
   and csu.cust_acct_site_id=hcas.cust_acct_site_id(+)
   and hcas.party_site_id = hps.party_site_id(+)
   and hps.location_id = loc.location_id(+)
   --AND ct.trx_number = 'test_artrx001'
UNION ALL
-- Part4: AR Credit Memos Applications
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,to_char(trx_cm.trx_number) ar_doc_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,loc.address1 descr
      ,rc.customer_name
      ,csu.location site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches                  b
      ,gl_je_lines                    l
      ,gl_code_combinations           gcc
      ,gl_je_headers                  h
      ,gl_period_statuses             gps
      ,gl_import_references           i
      ,ar_distributions_all           ad
      ,ar_receivable_applications_all ra
      ,ra_customer_trx_all            trx_cm
      ,ra_customer_trx_all            trx_inv
      ,gl_je_categories_v             jc
      ,gl_je_sources_v                js
      ,ra_customers                   rc
      ,hz_cust_site_uses_all          csu
      ,hz_cust_acct_sites_all         hcas
      ,hz_party_sites                 hps
      ,hz_locations                   loc
 WHERE 1 = 1
   AND h.je_source = 'Receivables'
   AND h.je_category = 'Credit Memo Applications'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND h.je_batch_id = b.je_batch_id
   AND h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
      -- gl to ar
   AND l.je_header_id = i.je_header_id
   AND l.je_line_num = i.je_line_num
   AND to_number(i.reference_3) = ad.line_id
      -- ar
   AND ad.source_table = 'RA'
   AND ad.source_id = ra.receivable_application_id
   AND ra.customer_trx_id = trx_cm.customer_trx_id
   AND ra.applied_customer_trx_id = trx_inv.customer_trx_id
   AND trx_cm.bill_to_customer_id = rc.customer_id
   AND trx_cm.bill_to_site_use_id = csu.site_use_id
   AND csu.cust_acct_site_id=hcas.cust_acct_site_id(+)
   AND hcas.party_site_id = hps.party_site_id(+)
   AND hps.location_id = loc.location_id(+)
   --AND trx_cm.trx_number = 'test_artrx003'
UNION ALL
-- Part5: Po Rcv & Return
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,to_char(poh.segment1) po_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,msi.concatenated_segments descr
      ,pv.vendor_name
      ,pvs.vendor_site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches        b
      ,gl_je_headers        h
      ,gl_je_lines          l
      ,gl_code_combinations gcc
      ,gl_je_categories_v   jc
      ,gl_je_sources_v      js
      ,gl_period_statuses   gps
      ,gl_import_references r
       --
      ,po_headers_all           poh
      ,po_lines_all             pol
      ,po_releases_all          pr
      ,po_line_locations_all    pll
      ,po_distributions_all     pod
      ,po_vendors          pv
      ,po_vendor_sites_all pvs
      ,rcv_receiving_sub_ledger rrs
       --
      ,rcv_transactions             rct
      ,rcv_shipment_headers         rsh
      ,rcv_shipment_lines           rsl
      ,org_organization_definitions ood
      ,mtl_system_items_kfv         msi
 WHERE 1 = 1
      -- gl journals
   AND b.je_batch_id = h.je_batch_id
   AND h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
   AND h.je_source = 'Purchasing'
   AND h.je_category  = 'Receiving'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND l.je_header_id = r.je_header_id
   AND l.je_line_num = r.je_line_num
      -- gl to po rcv
   AND r.gl_sl_link_table = 'RSL'
   AND rrs.gl_sl_link_id = r.gl_sl_link_id
   AND rrs.rcv_transaction_id = r.reference_5
      -- PO
   AND poh.po_header_id = pol.po_header_id
   AND pol.po_line_id = pll.po_line_id
   AND pll.po_release_id = pr.po_release_id(+)
   AND pll.line_location_id = pod.line_location_id
   AND poh.vendor_id = pv.vendor_id
   AND poh.vendor_site_id = pvs.vendor_site_id
      -- PO to Rcv
   AND pod.po_distribution_id = rrs.reference3
   AND rrs.rcv_transaction_id = rct.transaction_id
   AND rct.shipment_header_id = rsh.shipment_header_id
   AND rct.shipment_line_id = rsl.shipment_line_id
      --
   AND rct.organization_id = ood.organization_id
   AND ood.set_of_books_id = rrs.set_of_books_id
   AND rsl.item_id = msi.inventory_item_id
   AND rct.organization_id = msi.organization_id
   --AND poh.segment1 = '20010800157'
UNION ALL
-- Part6: INV WIP
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,msik.concatenated_segments item_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,wip_type.meaning descr
      ,NULL vendor_name
      ,NULL vendor_site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches      b
      ,gl_je_lines        l
      ,gl_code_combinations gcc
      ,gl_je_headers      h
      ,gl_je_categories_v jc
      ,gl_je_sources_v    js
      ,gl_period_statuses   gps
       --
      ,gl_import_references r
       --
      ,wip_transaction_accounts wta
      ,wip_transactions         wt
      ,mfg_lookups              wip_type
      ,wip_entities             we
      ,mtl_system_items_kfv     msik
 WHERE 1 = 1
      -- gl
   AND h.je_source = 'Inventory'
   AND h.je_category = 'WIP'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND b.je_batch_id = h.je_batch_id
   AND h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
      -- gl to inv
   AND r.je_header_id = h.je_header_id
   AND r.je_line_num = l.je_line_num
   AND r.gl_sl_link_id IS NOT NULL
   AND r.gl_sl_link_id = wta.gl_sl_link_id
   AND r.reference_3 IS NOT NULL
   AND r.reference_1 = to_char(wta.gl_batch_id)
   AND r.reference_3 = wta.transaction_id
   AND l.code_combination_id = wta.reference_account
      -- wip
   AND wta.transaction_id = wt.transaction_id
   AND wt.wip_entity_id = we.wip_entity_id
   AND wt.organization_id = we.organization_id
   AND we.primary_item_id = msik.inventory_item_id(+)
   AND we.organization_id = msik.organization_id(+)
      --
   AND wip_type.lookup_type(+) = 'WIP_TRANSACTION_TYPE'
   AND wip_type.lookup_code(+) = wt.transaction_type
   --AND h.je_header_id = 38335
   --AND l.je_line_num = 3
-- Part7: INV MTL - mmt.transaction_id = mta.transaction_id
UNION ALL
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,msi.concatenated_segments item_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,mtst.transaction_source_type_name descr
      ,NULL vendor_name
      ,NULL vendor_site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches      b
      ,gl_je_lines        l
      ,gl_code_combinations gcc
      ,gl_je_headers      h
      ,gl_je_categories_v jc
      ,gl_je_sources_v    js
       --
      ,gl_import_references      r
      ,gl_period_statuses        gps
      ,gl_sets_of_books          sob
      ,gl_daily_conversion_types glct
      ,mtl_transaction_accounts  mta
      ,mtl_material_transactions mmt
      ,mtl_transaction_types     mtt
      ,mtl_item_locations        mil
      ,mtl_parameters            mp
      ,mtl_txn_source_types      mtst
      ,mtl_system_items_vl       msi
 WHERE 1 = 1
      -- gl
   AND h.je_source = 'Inventory'
   AND h.je_category = 'MTL'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND b.je_batch_id = h.je_batch_id
   AND h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
      -- gl to inv
   AND r.je_header_id = h.je_header_id
   AND r.je_line_num = l.je_line_num
   AND l.set_of_books_id = sob.set_of_books_id
   AND r.reference_1 = mta.gl_batch_id
   AND ((r.gl_sl_link_id IS NOT NULL AND r.reference_3 IS NOT NULL AND
       mta.transaction_id = r.reference_3 AND
       mta.gl_sl_link_id = r.gl_sl_link_id) OR
       (r.gl_sl_link_id IS NULL AND r.reference_3 IS NULL AND
       mta.reference_account = l.code_combination_id AND
       nvl(mta.currency_code,
             sob.currency_code) = h.currency_code AND
       decode(mta.encumbrance_type_id,
                NULL,
                'A',
                'E') = h.actual_flag AND
       nvl(mta.encumbrance_type_id,
             -1) = nvl(h.encumbrance_type_id,
                         -1) AND
       nvl(mmt.ussgl_transaction_code,
             '#ZZZ') = nvl(h.ussgl_transaction_code,
                             '#ZZZ')))
      -- inv
   AND mmt.transaction_id = mta.transaction_id
   AND (mmt.transaction_action_id NOT IN (2, 3, 5) OR
       (mmt.transaction_action_id IN (2, 3, 5) AND
       mmt.primary_quantity < 0 AND
       mmt.primary_quantity = mta.primary_quantity))
   AND mmt.inventory_item_id = mta.inventory_item_id
   AND mmt.organization_id = mp.organization_id
   AND mmt.organization_id = mil.organization_id(+)
   AND mmt.locator_id = mil.inventory_location_id(+)
   AND mmt.currency_conversion_type = glct.conversion_type(+)
   AND mtt.transaction_type_id = mmt.transaction_type_id
   AND mtst.transaction_source_type_id = mmt.transaction_source_type_id
   AND sob.set_of_books_id = gps.set_of_books_id
   AND gps.period_name = l.period_name
   AND gps.application_id = 401
   AND msi.inventory_item_id = mmt.inventory_item_id
   AND msi.organization_id = mmt.organization_id
   --AND h.je_header_id=1665
UNION ALL
-- Part8: INV MTL Part2 - mmt.transfer_transaction_id = mta.transaction_id
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.NAME je_name
      ,h.doc_sequence_value je_doc_num
      ,msi.concatenated_segments item_num
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,mtst.transaction_source_type_name descr
      ,NULL vendor_name
      ,NULL vendor_site_code
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr, 0) - nvl(l.entered_cr, 0) balance
  FROM gl_je_batches             b
      ,gl_je_lines               l
      ,gl_code_combinations      gcc
      ,gl_je_headers             h
      ,gl_je_categories_v        jc
      ,gl_je_sources_v           js
      ,gl_import_references      r
      ,gl_period_statuses        gps
      ,gl_sets_of_books          sob
      ,gl_daily_conversion_types glct
      ,mtl_transaction_accounts  mta
      ,mtl_material_transactions mmt
      ,mtl_transaction_types     mtt
      ,mtl_item_locations        mil
      ,mtl_parameters            mp
      ,mtl_txn_source_types      mtst
      ,mtl_system_items_vl       msi
 WHERE 1 = 1
   AND h.je_source = 'Inventory'
   AND h.je_category = 'MTL'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND b.je_batch_id = h.je_batch_id
   AND h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND r.je_header_id = h.je_header_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND r.je_line_num = l.je_line_num
   AND l.set_of_books_id = sob.set_of_books_id
      -- gl to mtl
   AND r.reference_1 = mta.gl_batch_id
   AND ((r.gl_sl_link_id IS NOT NULL AND r.reference_3 IS NOT NULL AND
       mta.transaction_id = r.reference_3 AND
       mta.gl_sl_link_id = r.gl_sl_link_id) OR
       (r.gl_sl_link_id IS NULL AND r.reference_3 IS NULL AND
       mta.reference_account = l.code_combination_id AND
       nvl(mta.currency_code,
             sob.currency_code) = h.currency_code AND
       decode(mta.encumbrance_type_id,
                NULL,
                'A',
                'E') = h.actual_flag AND
       nvl(mta.encumbrance_type_id,
             -1) = nvl(h.encumbrance_type_id,
                         -1) AND
       nvl(mmt.ussgl_transaction_code,
             '#ZZZ') = nvl(h.ussgl_transaction_code,
                             '#ZZZ')))
      --mmt
   AND mmt.transfer_transaction_id = mta.transaction_id
   AND mmt.transaction_action_id IN (2, 3, 5)
   AND mmt.primary_quantity > 0
   AND mmt.primary_quantity = mta.primary_quantity
   AND mmt.inventory_item_id = mta.inventory_item_id
   AND mmt.organization_id = mp.organization_id
   AND mmt.organization_id = mil.organization_id(+)
   AND mmt.locator_id = mil.inventory_location_id(+)
   AND mmt.currency_conversion_type = glct.conversion_type(+)
   AND mtt.transaction_type_id = mmt.transaction_type_id
   AND mtst.transaction_source_type_id = mmt.transaction_source_type_id
   AND sob.set_of_books_id = gps.set_of_books_id
   AND gps.period_name = l.period_name
   AND gps.application_id = 401
   AND msi.inventory_item_id = mmt.inventory_item_id
   AND msi.organization_id = mmt.organization_id
   --AND h.je_header_id=1665
-- Part9: FA Journals
UNION ALL
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.name je_name
      ,h.doc_sequence_value je_doc_num
      ,fa.asset_number
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,fa.asset_description descr
      ,NULL
      ,NULL
      ,h.currency_code
      ,nvl(fa.entered_dr,l.entered_dr)entered_dr
      ,nvl(fa.entered_cr,l.entered_cr)entered_cr
      ,nvl(fa.accounted_dr,l.accounted_dr)accounted_dr
      ,nvl(fa.accounted_cr,l.accounted_cr)accounted_cr
      ,nvl(fa.entered_dr,0) - nvl(fa.entered_cr,0) balance
  FROM gl_je_batches      b
      ,gl_je_headers      h
      ,gl_je_lines        l
      ,gl_code_combinations gcc
      ,gl_period_statuses   gps
      ,gl_je_categories_v jc
      ,gl_je_sources_v    js
       --
      ,fa_ael_gl_v        fa
 WHERE 1=1
   AND h.je_source='Assets'
   AND h.je_category <> 'Depreciation'
   AND h.actual_flag = 'A'
   AND b.status='P'
   AND b.je_batch_id = h.je_batch_id
   AND l.code_combination_id = gcc.code_combination_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND h.je_header_id = l.je_header_id
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
   --
   AND l.je_header_id = fa.je_header_id(+)
   AND l.je_line_num = fa.je_line_num(+)
   --
   --AND l.je_header_id=481
   --AND l.je_line_num = 1
-- Part10: Other Journals
UNION ALL
SELECT h.set_of_books_id
      ,b.org_id
      ,js.user_je_source_name je_source
      ,jc.user_je_category_name je_category
      ,h.default_effective_date gl_date
      ,l.period_name
      ,gps.effective_period_num
      ,h.name je_name
      ,h.doc_sequence_value je_doc_num
      ,NULL
      ,l.code_combination_id
      ,gcc.segment1
      ,gcc.segment2
      ,gcc.segment3
      ,gcc.segment4
      ,gcc.segment5
      ,gcc.segment6
      ,gcc.segment7
      ,gcc.segment8
      ,gcc.segment9
      ,l.DESCRIPTION descr
      ,NULL
      ,NULL
      ,h.currency_code
      ,l.entered_dr
      ,l.entered_cr
      ,l.accounted_dr
      ,l.accounted_cr
      ,nvl(l.entered_dr,0) - nvl(l.entered_cr,0) balance
  FROM gl_je_batches      b
      ,gl_je_headers      h
      ,gl_je_lines        l
      ,gl_period_statuses   gps
      ,gl_code_combinations gcc
      ,gl_je_categories_v jc
      ,gl_je_sources_v    js
 WHERE b.je_batch_id = h.je_batch_id
   AND h.je_category = jc.je_category_name
   AND h.je_source = js.je_source_name
   AND h.je_header_id = l.je_header_id
   AND l.code_combination_id = gcc.code_combination_id
   AND gps.set_of_books_id = l.set_of_books_id
   AND gps.application_id = 101
   AND gps.period_name = l.period_name
   AND b.status='P'
   AND h.actual_flag = 'A'
   AND ( (h.je_source='Assets' AND h.je_category = 'Depreciation')
          OR
         (h.je_source NOT IN ('Assets','Payables','Receivables','Inventory','Purchasing'))
        )
View Code

附 :R12中子模塊的帳是如何產生的。

1) 在FORM:ARXRWMAI 的按鈕 SLACEXEC.OK_BP 觸發器中有提交創建的代碼:

arp_sla_submit.which_case;

2)包arp_sla_submit在pll文件ARSLAOLS.pll中。

3)在arp_sla_submit.which_case中執行以下過程,將FORM界面上的信息傳入過程

       submit_xla_accounting

4) submit_xla_accounting過程調用以下數據庫package創建會計科目

  XLA_ACCOUNTING_PUB_PKG.accounting_program_document

5)在XLA_ACCOUNTING_PUB_PKG中根據p_offline_flag的取值,分別調用

xla_accounting_pkg.accounting_program_document

或者調用創建會計科目的請求

6)在xla_accounting_pkg中調用下面過程

xla_accounting_pkg.accounting_program_events

7)在events_processor在調用handle_accounting_hook調根據application_id分別調用

  CASE                                                                                          

      WHEN p_application_id = 200 THEN                                                 

            xla_ap_acct_hooks_pkg.main    

      WHEN p_application_id = 222 THEN

            xla_ar_acct_hooks_pkg.main   

      WHEN p_application_id = 140 THEN                                                         

            xla_fa_acct_hooks_pkg.main

      WHEN p_application_id = 260 THEN                                                         

            xla_ce_acct_hooks_pkg.main

      WHEN p_application_id = 555 THEN                                                         

            xla_gmf_acct_hooks_pkg.main   

      WHEN p_application_id = 801 THEN                                                         

            xla_pay_acct_hooks_pkg.main     

      ELSE                                                                          

  END CASE;              

其中event_name為extract。然后調用arp_xla_extract_main_pkg.extract 來取子模塊的分配。其主要作用是將來自子模塊的分配。AR的發票、調整、收款、核銷等子模塊的帳的分配插入ar_xla_lines_extract臨時表,在這個package中可以看到xla是如何從業務模塊數據取數的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM