Translate

Wednesday, August 24, 2016

Query to get GL drill down to AP

SELECT 'AP' source,
               asup.segment1 vendor_number,
               asup.vendor_name,
               h.je_category,
               h.je_source,
               h.period_name je_period_name,
               h.name journal_name,
               h.status journal_status,
               h.created_by je_created_by,
               h.creation_date je_created_date,
               glcc.concatenated_segments account,
               l.description,
               xlal.accounting_class_code,
               xlal.description xlal_description,
               xlal.accounting_date accounting_date,
               xlate.transaction_number xlate_transaction_number,
               gir.subledger_doc_sequence_value voucher_number,
               h.currency_code entered_currencey,
               (SELECT SUM (NVL (begin_balance_dr, 0))
                       - SUM (NVL (begin_balance_cr, 0))
                  FROM gl_balances gb
                 WHERE     gb.code_combination_id = glcc.code_combination_id
                       AND gb.ledger_id = 2091
                       AND gb.actual_flag = 'A'
                       AND gb.period_name = NVL (:period, h.period_name)
                       AND gb.currency_code = h.currency_code)
                  begining_balance,
               (SELECT SUM (NVL (period_net_dr, 0))
                       - SUM (NVL (period_net_cr, 0))
                       + (SUM (NVL (begin_balance_dr, 0))
                          - SUM (NVL (begin_balance_cr, 0)))
                  FROM gl_balances gb
                 WHERE     gb.code_combination_id = glcc.code_combination_id
                       AND gb.ledger_id = 2091
                       AND gb.actual_flag = 'A'
                       AND gb.period_name = NVL (:period, h.period_name)
                       AND gb.currency_code = h.currency_code)
                  ending_balance,
               l.accounted_dr,
               l.accounted_cr,
               xlal.accounted_dr trx_accounted_dr_jod,
               xlal.accounted_cr trx_accounted_cr_jod,
               NVL (l.accounted_dr, 0) - NVL (l.accounted_cr, 0) balance,
               NULL po_number,
               NULL receipt_num,
               (SELECT bank_name || ' - ' || bank_account_num_electronic
                  FROM ar_cash_receipts_v v, iby_ext_bank_accounts_v vv
                 WHERE vv.ext_bank_account_id = v.customer_bank_account_id
                       AND gir.subledger_doc_sequence_value =
                              v.document_number)
                  customer_bank,
               (SELECT BANK_ACCOUNT_NAME || ' - ' || BANK_ACCOUNT_NUM
                  FROM ce_bank_acct_uses ba,
                       ce_bank_accounts cba,
                       ce_bank_branches_v bb,
                       ar_receipt_method_accounts v
                 WHERE     bb.bank_name LIKE '%'
                       AND bb.bank_branch_name LIKE '%'
                       AND bb.bank_institution_type = 'BANK'
                       AND bb.branch_party_id = cba.bank_branch_id
                       AND cba.bank_account_id = ba.bank_account_id
                       AND cba.account_classification = 'INTERNAL'
                       AND ba.bank_acct_use_id = v.remit_bank_acct_use_id
                       AND CASH_CCID = glcc.code_combination_id
                       AND RECEIPT_METHOD_ID = 10000)
                  bank_account_name
          FROM gl_je_batches b,
               gl_je_headers h,
               gl_je_lines l,
               gl_code_combinations_kfv glcc,
               gl_import_references gir,
               xla_ae_lines xlal,
               xla_ae_headers xlah,
               xla_events xlae,
               xla.xla_transaction_entities xlate,
               ap_suppliers asup
         WHERE     1 = 1
               AND glcc.chart_of_accounts_id = 50408
               AND h.ledger_id = 2091
               AND b.je_batch_id = h.je_batch_id
               AND h.je_header_id = l.je_header_id
               AND l.je_header_id = gir.je_header_id
               AND l.je_line_num = gir.je_line_num
               AND xlal.code_combination_id = glcc.code_combination_id
               AND gir.gl_sl_link_table = xlal.gl_sl_link_table
               AND gir.gl_sl_link_id = xlal.gl_sl_link_id
               AND xlal.ae_header_id = xlah.ae_header_id
               AND xlah.event_id = xlae.event_id
               AND xlae.entity_id = xlate.entity_id
               AND xlae.application_id = xlate.application_id
               AND h.je_source = 'Payables'
               AND asup.vendor_id(+) = xlal.party_id
               AND h.period_name = NVL (:period, h.period_name)
               AND glcc.concatenated_segments BETWEEN NVL (
                                                         :p_min_flex,
                                                         glcc.concatenated_segments)
                                                  AND NVL (
                                                         :p_max_flex,
                                                         glcc.concatenated_segments)

No comments:

Post a Comment

Featured Post

To Add user Responsibility like another user

DECLARE    lc_user_name              VARCHAR2 (100) := 'ALI';    lc_resp_appl_short_name   VARCHAR2 (100) := 'SYSADMIN'; ...