Skip to main content

AP Trail Balances SQL Query for R12

AP Trail Balances SQL Query for R12

SELECT  aia.invoice_num, aia.description inv_description,aia.attribute2 "Dept", aps.segment1 vendor#,
       aps.vendor_name, aia.invoice_currency_code, aia.invoice_amount,tb.diff "Amount Remain",
          gcc.segment1
       || '.'
       || gcc.segment2
       || '.'
       || gcc.segment3
       || '.'
       || gcc.segment4
       || '.'
       || gcc.segment5
       || '.'
       || gcc.segment6
       || '.'
       || gcc.segment7 ACCOUNT,
       aia.invoice_type_lookup_code,
       aia.invoice_date, aia.attribute5 status,
       ap.NAME terms
  FROM xla.xla_transaction_entities xte,
       (SELECT   tb.code_combination_id,
                 NVL (tb.applied_to_entity_id, tb.source_entity_id) entity_id,
                 SUM (NVL (tb.acctd_rounded_cr, 0)),
                 SUM (NVL (tb.acctd_rounded_dr, 0)),
                   SUM (NVL (tb.acctd_rounded_cr, 0))
                 - SUM (NVL (tb.acctd_rounded_dr, 0)) diff,
                 party_id
            FROM xla_trial_balances tb
           WHERE tb.definition_code =:definition_code  -- Ex :  'AP_200_1001'
               and trunc(tb.gl_date) <=TO_DATE ('1-NOV-2011')
                       GROUP BY tb.code_combination_id,
                 NVL (tb.applied_to_entity_id, tb.source_entity_id),
                 tb.party_id
          HAVING SUM (NVL (tb.acctd_rounded_cr, 0)) <>
                                            SUM (NVL (tb.acctd_rounded_dr, 0))) tb,
       ap_invoices_all aia,
       ap_suppliers aps,
       gl_code_combinations gcc,
       ap_terms ap
 WHERE tb.entity_id = xte.entity_id
   AND xte.application_id =:application_id   --Ex :  200
   AND xte.source_id_int_1 = aia.invoice_id
   AND aia.vendor_id = aps.vendor_id
   AND tb.code_combination_id = gcc.code_combination_id
   AND ap.term_id = aia.terms_id




-----------------------

AP Invoice liability (Trial Balance) Query: R12 AP GL PO RCV XLA

SELECT   NVL (f.currency_code, d.invoice_currency_code) currency_code,
         d.invoice_amount, d.wfapproval_status, d.invoice_num, d.invoice_id,
         i.segment1 v_code, i.vendor_name,
         NVL (d.invoice_amount, 0) - NVL (d.amount_paid, 0) amt,
         SUM (a.acctd_rounded_cr) - SUM (a.acctd_rounded_dr) amount,
         b.accounting_date, f.segment1 po_num, f.comments descr,
         h.receipt_num rct_num, c.segment6 loc, c.segment2 cost_centre,
         d.doc_sequence_value ap_voucher, j.employee_number, j.full_name
    FROM xla_transaction_entities xte,
         ap.ap_invoice_distributions_all b,
         ap.ap_invoice_lines_all k,
         gl.gl_code_combinations c,
         ap.ap_invoices_all d,
         po.po_distributions_all e,
         po.po_headers_all f,
         apps.rcv_transactions g,
         apps.rcv_shipment_headers h,
         apps.po_vendors i,
         apps.per_all_people_f j,
         (SELECT   /*+ index(tb XLA_TRIAL_BALANCES_N2) */
                   tb.code_combination_id, tb.ledger_id, tb.party_id party_id,
                   tb.gl_date, tb.ae_header_id,
                   NVL (tb.applied_to_entity_id,
                        tb.source_entity_id
                       ) entity_id,
                   tb.definition_code, tb.record_type_code,
                   SUM (NVL (tb.acctd_rounded_cr, 0)) acctd_rounded_cr,
                   SUM (NVL (tb.acctd_rounded_dr, 0)) acctd_rounded_dr,
                     SUM (NVL (tb.acctd_rounded_cr, 0))
                   - SUM (NVL (tb.acctd_rounded_dr, 0)) diff,
                   party_id
              FROM xla_trial_balances tb
             WHERE tb.definition_code = 'AP_200_1001'
               AND tb.gl_date <= :acc_date --GL Date Value               

               AND tb.code_combination_id IN (SELECT code_combination_id
                                              FROM gl_code_combinations a
                                              WHERE a.segment3 = :acc_code)--GL CC Value
          GROUP BY tb.code_combination_id,
                   tb.ledger_id,
                   tb.party_id,
                   tb.party_id,
                   NVL(tb.applied_to_entity_id,tb.source_entity_id),
                   tb.record_type_code,
                   tb.party_id,
                   tb.gl_date,
                   tb.definition_code,
                   tb.ae_header_id) a
   WHERE a.code_combination_id = c.code_combination_id
     AND d.INVOICE_NUM = :invoice_num   --Invoice Num    

     AND a.definition_code = 'AP_200_1001'
     AND a.entity_id = xte.entity_id
     AND xte.application_id = 200
     AND xte.ledger_id = a.ledger_id
     AND NVL (source_id_int_1, (-99)) = d.invoice_id
     AND d.invoice_id = k.invoice_id
     AND k.line_number = b.invoice_line_number
     AND c.segment3 = :acc_code               --GL CC Code     

     AND a.gl_date <= :acc_date               --Gl Date 
     AND k.invoice_id = b.invoice_id
     AND b.distribution_line_number = '1'
     AND k.line_number = '1'
     AND b.po_distribution_id = e.po_distribution_id(+)
     AND e.po_header_id = f.po_header_id(+)
     AND b.rcv_transaction_id = g.transaction_id(+)
     AND g.shipment_header_id = h.shipment_header_id(+)
     AND f.agent_id = j.person_id(+)
     AND i.vendor_id = d.vendor_id
     AND d.set_of_books_id = a.ledger_id
     AND d.org_id = :l_org_id           --Invoice Org Id   

     AND TRUNC (SYSDATE) BETWEEN j.effective_start_date(+) 
     AND j.effective_end_date(+)
  HAVING SUM (a.acctd_rounded_cr) - SUM (a.acctd_rounded_dr) <> 0
  GROUP BY f.currency_code,
         d.invoice_amount,
         b.project_id,
         d.wfapproval_status,
         d.invoice_num,
         d.invoice_id,
         b.accounting_date,
         f.segment1,
         h.receipt_num,
         i.segment1,
         i.vendor_name,
         c.segment6,
         d.doc_sequence_value,
         c.segment2,
         j.employee_number,
         j.full_name,
         f.agent_id,
         f.comments,
         d.invoice_currency_code,
         b.posted_flag,
         d.amount_paid,
         d.invoice_id

Comments

  1. Hi Nasiruddin

    I am having a report Supplier due for inactivation and attached is the sql .I need to add Ap Current Balance column to the report . Is this possible , Can I add it to the report using the existing tables in the query .

    ReplyDelete
  2. SSELECT
    Table__46.COMPANY_NAME,
    Table__46.ORG_ID,
    Table__46.PAY_GROUP_LOOKUP_CODE,
    Table__46.VENDOR_ID,
    Table__46.VENDOR_NAME,
    Table__46.VENDOR_NUMBER,
    Table__46.VENDOR_CREATION_DATE,
    Table__46.VENDOR_SITE_ID,
    Table__46.VENDOR_SITE_CODE,
    Table__46.SITE_CREATION_DATE,
    Table__46.LAST_AP_DOC
    FROM
    (
    SELECT hou.name company_name, vs.org_id, vs.pay_group_lookup_code, v.vendor_id, v.vendor_name, v.segment1 vendor_number, v.creation_date vendor_creation_date, vs.vendor_site_id, vs.vendor_site_code
    , vs.creation_date site_creation_date,
    GREATEST((select MAX(api.invoice_date)
    from ap_invoices_all api
    , ap_supplier_sites_all s
    where api.org_id = vs.org_id
    and s.vendor_site_id = api.vendor_site_id
    and s.inactive_date is null
    --and api.invoice_date >= trunc(add_months(sysdate,-6))
    and s.vendor_site_id = vs.vendor_site_id),
    (select MAX(aca.check_date)
    from ap_checks_all aca
    , ap_supplier_sites_all s
    where aca.status_lookup_code = 'NEGOTIABLE'
    and aca.org_id = vs.org_id
    and s.vendor_site_id = aca.vendor_site_id
    and s.inactive_date is null
    --and aca.check_date >= trunc(add_months(sysdate,-6))
    and aca.vendor_site_id = vs.vendor_site_id)) LAST_AP_DOC
    from apps.hr_all_organization_units hou
    , apps.ap_supplier_sites_all vs
    , apps.ap_suppliers v
    where v.vendor_id = vs.vendor_id
    and NVL(v.end_date_active, sysdate+1) > sysdate
    AND NVL(v.start_date_active, sysdate-1) < sysdate
    and vs.inactive_date is null
    and trunc(vs.creation_date) < add_months(trunc(sysdate),-3)
    and hou.organization_id = vs.org_id

    ReplyDelete
  3. and not exists
    (select api.invoice_date
    from apps.ap_invoices_all api
    , apps.ap_supplier_sites_all s
    , apps.ap_payment_schedules_all aps
    where api.org_id = vs.org_id
    and api.invoice_id = aps.invoice_id
    and s.vendor_site_id = api.vendor_site_id
    and s.inactive_date is null
    and (trunc(api.invoice_date) >= trunc(add_months(sysdate,-12))
    or aps.amount_remaining <> 0)
    and s.vendor_site_id = vs.vendor_site_id
    union
    select aca.check_date
    from apps.ap_checks_all aca
    , apps.ap_supplier_sites_all s
    where aca.status_lookup_code = 'NEGOTIABLE'
    and aca.org_id = vs.org_id
    and s.vendor_site_id = aca.vendor_site_id
    and s.inactive_date is null
    and trunc(aca.check_date) >= trunc(add_months(sysdate,-12))
    and aca.vendor_site_id = vs.vendor_site_id)
    and vs.vendor_site_code||vs.org_id not in
    (

    ReplyDelete
  4. select hcu.location||hcu.org_id
    from apps.ar_payment_schedules_all ps
    , apps.hz_cust_accounts hca
    , apps.hz_cust_acct_sites_all hcs
    , apps.hz_cust_site_uses_all hcu
    , apps.hz_parties hp
    , apps.hz_party_sites hps
    , apps.hz_locations hloc
    , apps.ar_receivable_applications_all arapp
    where arapp.org_id = vs.org_id --KB TO M= add_months(trunc(sysdate),-12)
    UNION
    select hcu.location||hcu.org_id
    from apps.ar_payment_schedules_all ps
    , apps.ra_customer_trx_all rct
    , apps.hz_cust_accounts hca
    , apps.hz_cust_acct_sites_all hcs
    , apps.hz_cust_site_uses_all hcu
    , apps.hz_parties hp
    , apps.hz_party_sites hps
    , apps.hz_locations hloc
    , apps.ra_cust_trx_types_all rctt
    , apps.ra_cust_trx_line_gl_dist_all gld
    , apps.gl_code_combinations cc
    where gld.org_id = vs.org_id

    ReplyDelete
  5. AND rctt.org_id = ps.org_id
    and rct.customer_trx_id = ps.customer_trx_id
    and ps.customer_id = hca.cust_account_id
    and ps.customer_site_use_id = hcu.site_use_id
    and hca.cust_account_id = hcs.cust_account_id
    and hcs.cust_acct_site_id = hcu.cust_acct_site_id
    and hca.party_id = hp.party_id
    and hp.party_id = hps.party_id(+)
    and hps.location_id = hloc.location_id(+)
    and hcs.party_site_id = hps.party_site_id
    and rctt.cust_trx_type_id = ps.cust_trx_type_id
    and ps.customer_trx_id = gld.customer_trx_id
    and gld.account_class = 'REC'
    and gld.latest_rec_flag = 'Y'
    and gld.code_combination_id = cc.code_combination_id
    and trunc(ps.trx_date) >= add_months(trunc(sysdate),-12)
    )
    ORDER BY VENDOR_NAME ASC , VENDOR_SITE_CODE ASC


    ) Table__46
    WHERE
    (
    (
    Table__46.LAST_AP_DOC Is Null
    OR
    Table__46.LAST_AP_DOC <= @prompt('Date of Last Transaction','D','Inactive Suppliers\Last Ap Doc',Mono,Free,Not_Persistent,,User:0)
    )
    AND
    Table__46.SITE_CREATION_DATE <= @prompt('Date of Last Transaction','D','Inactive Suppliers\Site Creation Date',Mono,Free,Not_Persistent,,User:1)
    AND
    Table__46.COMPANY_NAME IN @prompt('Enter value(s) for Company Name','A','Inactive Suppliers\Company Name',Multi,Free,Persistent,,User:2,optional)
    )

    ReplyDelete

Post a Comment

Popular posts from this blog

Oracle Subledger Accounting (SLA) Tables, Views

Oracle Subledger Accounting (SLA) Tables, Views Oracle Subledger Accounting Tables: TABLE NAME DESCRIPTION XLA_AAD_GROUPS The XLA_AAD_GROUPS table stores the merge dependencies analyzed during the merge analysis.  All application accounting definitions with the same GROUP_NUM must be merged together. XLA_AAD_HDR_ACCT_ATTRS The XLA_AAD_HDR_ACCT_ATTRS stores standard, system and custom sources assigned to an accounting attribute at the AAD level. XLA_AAD_HEADER_AC_ASSGNS Store the analytical criteria for the application accounting definitions. XLA_AAD_LINE_DEFN_ASSGNS This table stores the journal lines definitions for the application accounting definitions. XLA_AAD_LOADER_DEFNS_T The XLA_AAD_LOADER_DEFNS_T table is the interface table that facilitates the data transfer from data files and the database. XLA_AAD_LOADER_LOGS The XLA_AAD_LOADER_LOGS table stores the errors and logs generated by the application accounting definitions loader. XLA_AAD_SOURCES XLA_AAD_SOURCES table stores a...

R12 Oracle E-Business Tax Configuration Guide

Applies to: Oracle E-Business Tax - Version: 12.0 to 12.2 Information in this document applies to any platform. Abstract R12 Oracle E-Business Tax Configuration Guide Document History R12 Oracle E-Business Tax Configuration 1. Tax Basic Tax Configuration Tax Definition: comprises the tax data that you set up for each tax regime and tax that your company or institution is subject to. The Tax Authority designates the regulations and rates that apply to the tax regime. Required Task List a) External Dependencies Create First Party: Legal Entity and Establishments Create Reporting and Collecting Tax Authorities b) Tax Configuration Create Tax Authorities Party Tax Profiles Create Tax Regimes Create First Party Legal Entity Party Tax Profile Create Tax Create Tax Status Create Tax Jurisdictions Tax Rate Responsibility: Tax Manager Path: Tax Managers -> Tax Managers -> Home Complete the following setup tasks: -Legal Entities and Establishments -Reporting and Collecting Tax Authorities ...

O2C Cycle with Accounting Entries

  ORDER    TO  CASH  PARTICULARS  DR  CR SPL NOTES ACCOUNT IS PULLED FROM Sales order entry No Accounting Sales Order Pick From Sub Inventory A/c 100 At Standard Cost Sub-inventory Material A/c Setup To Sub Inventory A/c 100 At Standard Cost(Staging) Sub-inventory Material A/c Setup Sales Order Issue COGS 100 It can be fetched from five places Master Item/Org/Order Type/Line Type/Shipping Params To Sub Inventory A/c 100 At Standard Cost Sub-inventory Material A/c Setup Transaction level Receivable A/c 120 Auto Accounting Tax A/c 10 Auto Accounting Freight A/c 10 Auto Accounting Revenue A/c 100 Auto Accounting Receipts Receipts with no remittance method Cash 100 Before application of the receipt Receipt class Unapplied A/c 100 Receipt class Unapplied A/c 100 After application of the receipt to the transaction Receipt class Receivables A/c 100 Receipt class Cash A/c 100 Receipt class Unidentified A/c 100 In case of receipt without customer...