Thursday, 17 July 2014

AP invoice with Project and bank detail query

   SELECT api.invoice_id invoice_id,
          TRUNC (api.creation_date) invoice_creation_date,
          api.last_update_date invoice_last_update_date,
          hou.name operating_unit,
          pov.vendor_name supplier,
          povs.vendor_site_code supplier_site,
          NVL ( (SELECT flv.description
                 FROM po_vendors pv,
                      po_vendor_sites_all pvs,
                      fnd_lookup_values flv
                 WHERE     pvs.org_id = 1940
                       AND pv.vendor_id = pvs.vendor_id
                       AND flv.lookup_type = 'VENDOR TYPE'
                       AND flv.lookup_code = pv.vendor_type_lookup_code
                       AND pvs.org_id = api.org_id
                       AND pv.vendor_id = pov.vendor_id
                       AND pvs.vendor_site_id = povs.vendor_site_id),
               NULL
          )
             supplier_type,
          apb.batch_name invoice_batch_name,
          api.invoice_num,
          api.invoice_date,
          api.gl_date invoice_gl_date,
          api.source invoice_source,
          api.invoice_type_lookup_code invoice_type,
          REPLACE (api.description, '~', '-') invoice_description,
          api.invoice_currency_code,
          api.payment_currency_code,
          api.payment_cross_rate,
          api.invoice_amount,
          NVL (api.invoice_amount, api.base_amount) base_amount,
          api.amount_paid invoice_amount_paid,
          api.discount_amount_taken,
          api.amount_applicable_to_discount,
          api.tax_amount,
          api.pay_curr_invoice_amount,
          api.payment_cross_rate_date,
          api.terms_date,
          iby.payment_method_name invoice_pay_method,
          api.payment_method_code payment_method_code,
          api.pay_group_lookup_code invoice_pay_group,
          api.accts_pay_code_combination_id,
          gcc1.concatenated_segments liability_account,
          api.cancelled_date invoice_cancelled_date,
          api.cancelled_amount invoice_cancelled_amount,
          api.temp_cancelled_amount invoice_temp_cancelled_amount,
          apid.accounting_date dist_accounting_date,
          apid.assets_addition_flag dist_assets_addition,
          apid.distribution_line_number dist_line_number,
          apid.dist_code_combination_id,
          gcc2.concatenated_segments expense_account,
          apid.line_type_lookup_code dist_line_type,
          apid.period_name,
          apid.creation_date dist_creation_date,
          apid.last_update_date dist_last_update_date,
          apid.amount dist_amount,
          NVL (apid.amount, apid.base_amount) dist_base_amount,
          NVL (NVL (apid.amount, apid.base_amount),
               NVL (apl.amount, apl.base_amount)
          )
             original_amount,
          apid.base_invoice_price_variance dist_base_inv_price_variance,
          REPLACE (apid.description, '~', '-') dist_description,
          apid.invoice_price_variance dist_invoice_price_variance,
          apid.match_status_flag dist_match_status,
          apid.po_distribution_id,
          apid.quantity_invoiced,
          apid.unit_price,
          apid.price_var_code_combination_id,
          gcc3.concatenated_segments price_variance_account,
          apid.expenditure_item_date pa_expenditure_item_date,
          apid.expenditure_type pa_expenditure_type,
          apid.expenditure_organization_id,
          NVL (haou1.name, (NVL (haou3.name, haou2.name)))
             expenditure_organization,
          apid.pa_addition_flag,
          apid.project_accounting_context,
          apl.line_number,
          apl.line_type_lookup_code line_type,
          REPLACE (apl.description, '~', '-') line_description,
          apl.amount line_amount,
          NVL (apl.amount, apl.base_amount) line_base_amount,
          pap.project_id,
          pat.task_id,
          pap.segment1 project_number,
          pap.name project_name,
          pap.description project_description,
          pap.project_type,
          pap.project_status_code,
          pap.start_date project_start_date,
          pap.completion_date project_completion_date,
          pat.task_number,
          pat.task_name,
          pat.description task_description,
          pat.service_type_code,
          pat.start_date task_start_date,
          pat.completion_date task_completion_date,
          pov.vendor_id,
          apb.batch_id,
          apid.invoice_line_number,
          apid.distribution_line_number
   FROM ap_invoices api,
        po_vendors pov,
        po_vendor_sites povs,
        ap_batches_all apb,
        ap_invoice_distributions apid,
        ap_invoice_lines apl,
        pa_projects pap,
        pa_tasks pat,
        hr_operating_units hou,
        gl_code_combinations_kfv gcc1,
        gl_code_combinations_kfv gcc2,
        gl_code_combinations_kfv gcc3,
        iby_payment_methods_vl iby,
        hr_all_organization_units haou1,
        hr_all_organization_units haou2,
        hr_all_organization_units haou3
   WHERE     api.vendor_id = pov.vendor_id
         AND api.vendor_site_id = povs.vendor_site_id
         AND api.batch_id = apb.batch_id(+)
         AND api.invoice_id = apl.invoice_id(+)
         AND apl.invoice_id = apid.invoice_id(+)
         AND apid.invoice_line_number(+) = apl.line_number
         AND apid.project_id = pap.project_id(+)
         AND apid.task_id = pat.task_id(+)
         AND api.org_id = hou.organization_id
         AND api.accts_pay_code_combination_id = gcc1.code_combination_id(+)
         AND apid.dist_code_combination_id = gcc2.code_combination_id(+)
         AND apid.price_var_code_combination_id = gcc3.code_combination_id(+)
         AND iby.payment_method_code = api.payment_method_code
         AND api.expenditure_organization_id = haou1.organization_id(+)
         AND apl.expenditure_organization_id = haou2.organization_id(+)
         AND apid.expenditure_organization_id = haou3.organization_id(+)

2 comments:

  1. Hi Elan, Is there any way by which we can derive AP payment details (payment details and payment date) along with Project and task. Actually on the basis of project and task we need to know the payment details. Thank you

    ReplyDelete
  2. insurance pricing & billing
    Personalize products, offers, pricing and loyalty programs; prevent revenue leakage and ensure regulatory compliance with a billing solution.

    ReplyDelete