DBA Data[Home] [Help]

APPS.JAI_AP_MATCH_TAX_PKG SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 15

  SELECT account_type
    FROM gl_code_combinations
   WHERE code_combination_id = cp_code_combination_id ;
Line: 52

                        SELECT ship_to_organization_id,
                                                 ship_to_location_id
                                FROM po_line_locations_all
                         WHERE line_location_id IN ( SELECT line_location_id

                      FROM po_distributions_all
WHERE po_distribution_id = po_dist_id) ;
Line: 150

                              trigger ja_in_tds_temp_after_insert_trg on ap_invoice_distributions_all. The main concepts
                              used here are,
                              - if an error occurs while processing a particular record, the program will skip processing
                                all other distributions lines of the error invoice.
                              - the program will continue to process other invoices.
                              - the program will update the temporary table for an error record, with error flag time and error
                              - if a particular line has error flag set to 'Y', this program will not pick up that record and
                                also all other lines pertaining to such an error invoice.

2.      30-oct-2003           Aparajita. bug#3218695. Version#616.1.
                              Intrduced parameters p_org_id(current operating unit) and p_process_all_org(Y/N).

                              If p_process_all_org is Y, this program processed records of all operating units. When
                              p_process_all_org is 'N', records pertaining to org id p_org_id is only peocessed.

3.    08-Jun-2005             Version 116.2 jai_ap_match_tax -Object is Modified to refer to New DB Entity names in place of Old DB Entity Names
                               as required for CASE COMPLAINCE.

4.    22-Jun-05               rallamse bug#4448789 116.3 Pefomed LE changes by adding legal_entity_id at the required places

5.    03-Feb-2006         avallabh for bug 4926094. Version 120.4.
        Modified the cursor c_dist_reversal_cnt to check for rownum=1, to enhance performance.
        Removed the default initialization of v_dist_reversal_cnt to 0 and added it just before
        opening the cursor and assigning the value to the variable.


6.    01/11/2006    SACSETHI for bug 5228046, File version 120.8
                          Forward porting the change in 11i bug 5365523 (Additional CVD Enhancement).
                    This bug has datamodel and spec changes.

7.    13-April-2007   ssawant for bug 5989740 ,File version 120.13
                      Forward porting Budget07-08 changes of handling secondary and
                Higher Secondary Education Cess from 11.5( bug no 5907436) to R12 (bug no 5989740).
          Changes were done for following files
          ja_in_pay_on_recpt_dist_match_p.sql;
Line: 194

         UNABLE TO FIND LOV VALUES IN INDIA - TO INSERT TAXES  FOR PAY ON RECEIPT"
         Changes are done in  process_batch procedure

12. 31-oct-2007 Bug 6595773 File version 120.7.12000000.5
        Forward ported the changes done for bug 5416515 - AP ACCRUAL ACCOUNT IS NOT DEBITED FOR
        VAT TAXES IN INVOICE DISTRIBUTION

13.   20-Dec-2007   Eric modified and added code for the inclusive tax

14.   09-JAN-2008   Jason Liu
                    Modified for Retroactive Price

15. 18-Feb-2010 CSahoo for bug#9386496, File Version 120.34.12010000.13
                Issue: TAXES ARE GETTING INSERTED WITH PO EXPENSE ACCOUNT INSTEAD OF SERVICE TAX INTERI
                Fix: Added NVl condition to the parameter po_dist_id in the call to the function
                     check_service_interim_account.
16  07-jun-2011 vkaranam for bug#11936596
                Issue:  R12:POT - INCLUSIVE TAX ACCOUNTING NOT HAPPENING FOR PO MATCHED INVOICES
                Fix details:
                Following accounting entry to be passed for PO/Receipt Match Inclusive Taxes
at time of PO/Receipt Match event :

 The accounting entries for these Misc lines will be as follows:-
 Misc line :  +1364      --   Interim Recovery (Interim Recovery)
 Misc line :  -1364     --   ACC1 (AP Accrual)

 Changes are done in process_online  procedure for po_matching,rcv_matching.

18  16-mar-2012  vkaranam for bug#12434160
                Issue:Tax amount appear on the PO AP Accrual Reconcilliation report if the
  Purchase Order has multiple distribution lines.
  Issue details:
  Anything that is not linked to a po_distribution_id would be processed as
miscellaneous accrual and not as AP-PO accrual. Since po_distribution_id
for tax lines in AP is null in case of po with mulitple distributions, its  being processed as Miscellaneous reconciliation record.
Fix:
ap_invoice_distributions_all.po_distribution_id shall be populated with the po_distribution_id of
the item distribution line.
Changes are done in process_batch_records procedure.

61. 25-Jan-2013    amandali for bug 16220700
                   Issue: Discarded line has posted flag 'Y' eventhough not accounted, if the parent distribution is accounted.
                   Fix: Updated the posted flag, cash posted flag, accrual posted flag to 'N' for the discarded lines.
                        Also, added the updation of who columns

Future Dependencies For the release Of this Object:-
==================================================
(Please add a row in the section below only if your bug introduces a dependency due to spec change/
A new call to a object/A datamodel change )

------------------------------------------------------------------------------------------------------
Version       Bug       Dependencies (including other objects like files if any)
-------------------------------------------------------------------------------------------------------
616.1         3218695   This fix introduced two input parameters p_org_id and p_process_all_org.
                        The associated ldt for concurrent registration is the dependency..


------------------------------------------------------------------------------------------------------------------------ */
BEGIN


  Fnd_File.put_line(Fnd_File.LOG, 'Start procedure - jai_ap_match_tax_pkg.process_batch');
Line: 270

SELECT
    temp.ROWID,
    temp.invoice_id,
    temp.invoice_line_number,
    temp.po_distribution_id,
    temp.quantity_invoiced,
    temp.shipment_header_id,
    temp.receipt_num,
    temp.receipt_code,
    temp.rematching,
    temp.rcv_transaction_id,
    temp.amount,
    --project_id,
    --task_id,
    --expenditure_type,
    --expenditure_organization_id,
    --expenditure_item_date,
    temp.org_id
    /* 5763527 */
    ,apla.project_id
    ,apla.task_id
    ,apla.expenditure_type
    ,apla.expenditure_organization_id
    ,apla.expenditure_item_date
    /* End 5763527 */
   FROM JAI_AP_MATCH_ERS_T          temp
       ,ap_invoice_lines_all apla  -- 5763527
   WHERE  temp.invoice_id NOT IN
     (SELECT invoice_id
      FROM   JAI_AP_MATCH_ERS_T
      WHERE  error_flag = 'Y'
      )
   AND ( (v_org_id is null and mo_global.check_access(temp.org_id)='Y' )
         OR ( (v_org_id is not null) and  (temp.org_id = v_org_id) )
       ) ----added and mo_global.check_access(org_id)='Y' for bug#6457733, added by bug#3218695
   /* 5763527 */
   and  apla.invoice_id = temp.invoice_id
   and  apla.line_number = temp.invoice_line_number
   --and  aida.invoice_distribution_id = temp.invoice_distribution_id
   /* End 5763527 */
   ORDER BY  invoice_id, invoice_line_number
  )
  LOOP

   BEGIN

    v_rowid := c_rec.ROWID;
Line: 355

          DELETE  JAI_AP_MATCH_ERS_T
          WHERE   invoice_id = v_prev_invoice_id;
Line: 360

          SELECT invoice_num
          INTO   v_invoice_number
          FROM   ap_invoices_all
          WHERE  invoice_id = v_prev_invoice_id;
Line: 432

      UPDATE JAI_AP_MATCH_ERS_T
      SET    error_flag = 'Y',
             processing_time = SYSDATE,
             error_message = v_errbuf
      WHERE  ROWID = v_rowid;
Line: 441

      SELECT invoice_num
    INTO   v_invoice_number
    FROM   ap_invoices_all
    WHERE  invoice_id = c_rec.invoice_id;
Line: 466

    DELETE  JAI_AP_MATCH_ERS_T
    WHERE   invoice_id = v_prev_invoice_id;
Line: 471

    SELECT invoice_num
    INTO   v_invoice_number
    FROM   ap_invoices_all
    WHERE  invoice_id = v_prev_invoice_id;
Line: 494

    UPDATE JAI_AP_MATCH_ERS_T
    SET    error_flag = 'Y',
           processing_time = SYSDATE,
           error_message = p_errbuf
    WHERE  ROWID = v_rowid;
Line: 538

    SELECT vendor_id, vendor_site_id, org_id, cancelled_date, invoice_num, set_of_books_id,  -- added for bug#3354932
           legal_entity_id /* rallamse bug#4448789 */
    FROM   ap_invoices_all
    WHERE  invoice_id = v_invoice_id;
Line: 544

Select nvl(discarded_flag,'N') from ap_invoice_lines_all
where invoice_id = ln_invoice_id
and  line_number = pn_invoice_line_number
and  po_distribution_id = po_dist_id;
Line: 550

select invoice_id, po_distribution_id, invoice_distribution_id, rcv_transaction_id,invoice_line_number,
parent_invoice_distribution_id
from  jai_ap_match_inv_taxes
where line_type_lookup_code = 'MISCELLANEOUS'
and invoice_id = p_invoice_id
and parent_invoice_line_number = pn_invoice_line_number
and po_distribution_id = po_dist_id;
Line: 559

select accounting_date,
        accrual_posted_flag,
        assets_addition_flag,
        assets_tracking_flag,
        cash_posted_flag,
        distribution_line_number,
        dist_code_combination_id,
        invoice_id,
        line_type_lookup_code,
        period_name,
        set_of_books_id ,
        amount,
        base_amount,
        batch_id,
        description,
        exchange_rate_variance,
        last_update_login,
        match_status_flag,
        posted_flag,
        rate_var_code_combination_id ,
        reversal_flag ,
        program_application_id,
        program_id,
        program_update_date,
        accts_pay_code_combination_id,
        invoice_distribution_id,
        quantity_invoiced,
        po_distribution_id ,
        rcv_transaction_id,
        price_var_code_combination_id,
        invoice_price_variance,
        base_invoice_price_variance,
        matched_uom_lookup_code,
        invoice_line_number,
        org_id ,
        charge_applicable_to_dist_id ,
        project_id,
        task_id,
        expenditure_type,
        expenditure_item_date,
        expenditure_organization_id,
        project_accounting_context,
        pa_addition_flag,
        distribution_class,
        dist_match_type
from ap_invoice_distributions_all
where invoice_id = ln_invoice_id
and   invoice_distribution_id = ln_invoice_distribution_id;
Line: 609

select accounting_date,
        accrual_posted_flag,
        assets_addition_flag,
        assets_tracking_flag,
        cash_posted_flag,
        distribution_line_number,
        dist_code_combination_id,
        invoice_id,
        line_type_lookup_code,
        period_name,
        set_of_books_id ,
        amount,
        base_amount,
        batch_id,
        description,
        exchange_rate_variance,
        last_update_login,
        match_status_flag,
        posted_flag,
        rate_var_code_combination_id ,
        reversal_flag ,
        program_application_id,
        program_id,
        program_update_date,
        accts_pay_code_combination_id,
        invoice_distribution_id,
        quantity_invoiced,
        po_distribution_id ,
        rcv_transaction_id,
        price_var_code_combination_id,
        invoice_price_variance,
        base_invoice_price_variance,
        matched_uom_lookup_code,
        invoice_line_number,
        org_id ,
        charge_applicable_to_dist_id ,
        project_id,
        task_id,
        expenditure_type,
        expenditure_item_date,
        expenditure_organization_id,
        project_accounting_context,
        pa_addition_flag,
        distribution_class,
        dist_match_type
from ap_invoice_distributions_all
where invoice_id = ln_invoice_id
and   po_distribution_id  = ln_po_distribution_id
and   line_type_lookup_code = 'MISCELLANEOUS';
Line: 661

    SELECT currency_code
    FROM   gl_sets_of_books
    WHERE  set_of_books_id = p_sob;
Line: 666

    SELECT pay_on_code, pay_on_receipt_summary_code
    FROM   po_vendor_sites_all
    WHERE  vendor_id = ven_id
    AND    vendor_site_id = ven_site_id
    AND    NVL(org_id, -1) = NVL(v_org_id, -1);
Line: 675

  select ship_to_organization_id
     ,ship_to_location_id
  from  po_line_locations_all plla
  where plla.line_location_id = cpn_line_location_id;
Line: 683

     SELECT pod.po_header_id,
      pod.po_line_id,
      pod.line_location_id,
      pod.set_of_books_id,
      pod.org_id,
      poh.rate,
      poh.rate_type,
      pod.rate_date,
      poh.currency_code,
      api.last_update_login,
      apd.dist_code_combination_id,
      api.creation_date,
      api.created_by,
      api.last_update_date,
      api.last_updated_by,
      api.invoice_date
    FROM  ap_invoices_all api,
      ap_invoice_distributions_all apd,
      po_distributions_all pod,
      po_headers_all poh
     WHERE  apd.invoice_id               = api.invoice_id
     AND    pod.po_header_id             = poh.po_header_id
     AND    apd.po_distribution_id       = pod.po_distribution_id
     AND    apd.invoice_line_number      = line_no
     AND    api.invoice_id               = inv_id
     AND    apd.distribution_line_number = cpn_min_dist_line_no;
Line: 715

     SELECT min(distribution_line_number)
     FROM   ap_invoice_distributions_all apid
     WHERE  apid.invoice_id = cpn_invoice_id
     AND    apid.invoice_line_number = cpn_invoice_line_number;
Line: 722

    SELECT line_location_id, po_line_id
    FROM   po_distributions_all
    WHERE  po_distribution_id = po_dist_id;
Line: 732

    SELECT po_line_id, po_line_location_id
    FROM ap_invoice_lines_all
    WHERE invoice_id = inv_id
    AND line_number = pn_invoice_line_number;
Line: 738

    SELECT a.accounting_date,
           a.accrual_posted_flag,
           a.assets_addition_flag,
           a.assets_tracking_flag,
           a.cash_posted_flag,
           a.dist_code_combination_id,
           a.last_updated_by,
           a.last_update_date,
           a.line_type_lookup_code,
           a.period_name,
           a.set_of_books_id,
           a.amount,
           a.base_amount,
           a.batch_id,
           a.created_by,
           a.creation_date,
           a.description,
           a.accts_pay_code_combination_id,
           a.exchange_rate_variance,
           a.last_update_login,
           a.match_status_flag,
           a.posted_flag,
           a.rate_var_code_combination_id,
           a.reversal_flag,
           a.vat_code,
           a.exchange_date,
           a.exchange_rate,
           a.exchange_rate_type,
           a.price_adjustment_flag,
           a.program_application_id,
           a.program_id,
           a.program_update_date,
           a.global_attribute1,
           a.global_attribute2,
           a.global_attribute3,
           a.po_distribution_id,--rchandan for bug#4333488
           a.project_id,
           a.task_id,
           a.expenditure_type,
           a.expenditure_item_date,
           a.expenditure_organization_id,
           a.quantity_invoiced,
           Nvl(a.quantity_invoiced,1)/Nvl(b.quantity_invoiced,1) qty_apportion_factor,
           a.unit_price,
           price_var_code_combination_id,
           invoice_distribution_id,
           matched_uom_lookup_code,
           invoice_price_variance,
           a.distribution_line_number,
           a.org_id -- Test for Bug 4863208
           /* 5763527 */
           ,project_accounting_context
           ,pa_addition_flag
           /* End 5763527 */
      ,a.dist_match_type --Added by nprashar for bug # 12832424
     FROM   ap_invoice_distributions_all a,
            ap_invoice_lines_all b
     WHERE  a.invoice_id = cp_invoice_id
     AND    a.invoice_line_number = cp_line_num
     AND    b.invoice_id = cp_invoice_id
     AND    b.line_number = cp_line_num
     AND    a.invoice_id = b.invoice_id
     AND    a.invoice_line_number = b.line_number
     ORDER BY a.distribution_line_number;
Line: 816

    SELECT tax_id, tax_amount, currency, tax_target_amount, nvl(modvat_flag,'Y') modvat_flag,
    tax_type, tax_line_no -- added by kunkumar for bug 5593895
    FROM   JAI_PO_TAXES
    -- WHERE line_focus_id = focus_id
    WHERE line_location_id = p_line_location_id   -- 3096578
    AND    NVL(upper(tax_type), 'A') NOT IN
                              ('TDS',
             'CVD',
             jai_constants.tax_type_add_cvd ,     -- Date 31/10/2006 Bug 5228046 added by SACSETHI
             'CUSTOMS',
                    jai_constants.tax_type_cvd_edu_cess,
              jai_constants.tax_type_customs_edu_cess,
              jai_constants.tax_type_sh_cvd_edu_cess,jai_constants.tax_type_sh_customs_edu_cess --Added higher education cess by csahoo for bug#5989740
              )
    AND    NVL(vendor_id, -1) = vend_id --Modified by kunkumar for bug 5593895
    order by  tax_line_no; -- added bug#3038566
Line: 841

    SELECT
      jpt.tax_id
    , jpt.tax_amount
    , jpt.currency
    , jpt.tax_target_amount
    , nvl(jpt.modvat_flag,'Y') modvat_flag
    , jpt.tax_type
    , jpt.tax_line_no -- added by kunkumar for bug 5593895
    , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
    ,nvl(jcta.vat_flag,'N') VAT_FLAG
    ,nvl(jcta.adhoc_flag,'N') adhoc_flag
    FROM
      JAI_PO_TAXES jpt
    , JAI_CMN_TAXES_ALL  jcta              --Added by Eric for Inclusive Tax
    -- WHERE line_focus_id = focus_id
    WHERE line_location_id = p_line_location_id   -- 3096578
      AND NVL(UPPER(jpt.tax_type), 'A')
          NOT IN( 'TDS'
                , 'CVD'
                , jai_constants.tax_type_add_cvd      -- Date 31/10/2006 Bug 5228046 added by SACSETHI
                , 'CUSTOMS'
                , jai_constants.tax_type_cvd_edu_cess
                , jai_constants.tax_type_customs_edu_cess
                , jai_constants.tax_type_sh_cvd_edu_cess
                , jai_constants.tax_type_sh_customs_edu_cess --Added higher education cess by csahoo for bug#5989740
                )
      AND jcta.tax_id   = jpt.tax_id
      AND NVL(jpt.vendor_id, -1) = vend_id --Modified by kunkumar for bug 5593895
      AND p_source <> 'PPA'
      --Added by Qiong for reverse charge bug#16001407 start
      ---------------------------------------------------------------------
      AND NVL(jcta.reverse_charge_flag,'N') = 'N'
      ---------------------------------------------------------------------
      --Added by Qiong for reverse charge bug#16001407 end
    -- Added by Jason Liu for bug#6918386
    ---------------------------------------------------------------------
    UNION

    SELECT
      jrl.tax_id
    , (jrl.modified_tax_amount - jrl.original_tax_amount) tax_amount
    , jrl.currency_code currency
    , (jrl.modified_tax_amount - jrl.original_tax_amount) tax_target_amount
    , jrl.recoverable_flag modvat_flag
    , jrl.tax_type tax_type
    , jrl.tax_line_no tax_line_no
    , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag
    ,nvl(jcta.vat_flag,'N') VAT_FLAG
    ,nvl(jcta.adhoc_flag,'N') adhoc_flag
    FROM
      jai_retro_tax_changes  jrl
    , jai_retro_line_changes jrlc
    , jai_cmn_taxes_all      jcta
    WHERE jrlc.line_location_id = p_line_location_id
      AND jrlc.line_change_id = jrl.line_change_id
      AND jrlc.doc_version_number = (SELECT max(doc_version_number)
                                     FROM jai_retro_line_changes
                                     WHERE doc_type IN ('STANDARD PO', 'RELEASE')
                                       AND doc_line_id = jrlc.doc_line_id
                                     )
      AND jrlc.doc_type IN ('STANDARD PO', 'RELEASE')
      AND jrl.tax_id = jcta.tax_id
      AND NVL(jrlc.vendor_id, -1) = vend_id
      AND p_source = 'PPA'
      AND NVL(upper(jrl.tax_type),'TDS') NOT IN ( jai_constants.tax_type_tds
                                                , jai_constants.tax_type_cvd
                                                , jai_constants.tax_type_add_cvd
                                                , jai_constants.tax_type_customs
                                                , jai_constants.tax_type_sh_customs_edu_cess
                                                , jai_constants.tax_type_customs_edu_cess
                                                , jai_constants.tax_type_sh_cvd_edu_cess
                                                , jai_constants.tax_type_cvd_edu_cess
                                                )
      AND NVL(jrl.third_party_flag, 'N') = 'N' -- Added by Jason Liu for bug#6936416
      ---------------------------------------------------------------------
      --Added by Qiong for reverse charge bug#16001407 start
      ---------------------------------------------------------------------
      AND NVL(jcta.reverse_charge_flag,'N') = 'N'
      ---------------------------------------------------------------------
      --Added by Qiong for reverse charge bug#16001407 end
    ORDER BY  tax_line_no; -- added bug#3038566
Line: 925

     SELECT tax_name,
        tax_account_id,
        mod_cr_percentage, -- bug 3051828
        adhoc_flag,  -- added by aparajita on 23/01/2003 for bug # 2694011
        nvl(tax_rate,-1) tax_rate,  --Modified by kunkumar for bug 5593895
        tax_type,
    NVL(rounding_factor,0) rounding_factor /* added by vumaasha for bug 6761425 */
     FROM   JAI_CMN_TAXES_ALL
     WHERE  tax_id = t_id;
Line: 936

      SELECT batch_id,source
      FROM   ap_invoices_all
      WHERE  invoice_id = inv_id;
Line: 941

     SELECT org_id, vendor_id, NVL(exchange_rate, 1) exchange_rate, invoice_currency_code
     FROM   ap_invoices_all
     WHERE  invoice_id = inv_id;
Line: 946

     SELECT accts_pay_code_combination_id
     FROM   ap_system_parameters_all
     WHERE  NVL(org_id, -1) = NVL(orgn_id, -1);--uncommented and modified by kunkumar for bug 5593895
Line: 951

    CURSOR for_dist_insertion(cpn_invoice_id NUMBER, cpn_inv_line_num NUMBER,cpn_min_dist_line_num NUMBER) IS  /* Picks up dtls from std apps inserted line */
    SELECT a.accounting_date,a.accrual_posted_flag,
                a.assets_addition_flag,a.assets_tracking_flag,
    a.cash_posted_flag, a.dist_code_combination_id,
    a.last_updated_by,a.last_update_date,
    a.line_type_lookup_code,  a.period_name,
    a.set_of_books_id,a.amount,a.base_amount,
    a.batch_id,a.created_by,a.creation_date,
    a.description,a.accts_pay_code_combination_id,
    a.exchange_rate_variance,a.last_update_login,
    a.match_status_flag,a.posted_flag, a.rate_var_code_combination_id,
    a.reversal_flag,a.vat_code,a.exchange_date,a.exchange_rate,
    a.exchange_rate_type,a.price_adjustment_flag,
    a.program_application_id,a.program_id,
    a.program_update_date,a.global_attribute1,
    a.global_attribute2,
    a.global_attribute3, a.po_distribution_id,--rchandan for bug#4333488
                a.project_id,a.task_id,a.expenditure_type,a.expenditure_item_date,
    a.expenditure_organization_id,     quantity_invoiced,
    a.unit_price, price_var_code_combination_id,
    invoice_distribution_id, matched_uom_lookup_code, invoice_price_variance,
    org_id -- Test for Bug 4863208
     /* 5763527 */
     ,project_accounting_context
     ,pa_addition_flag
   /* End 5763527 */
        , dist_match_type --Added by nprashar for bug # 12832424
     FROM   ap_invoice_distributions_all a
     WHERE  invoice_id               = cpn_invoice_id
     AND    invoice_line_number      = cpn_inv_line_num
     AND    distribution_line_number = cpn_min_dist_line_num;
Line: 993

    SELECT jrl.tax_amount tax_amount,
    jrl.tax_id,
    jrl.currency,
    jrl.tax_type tax_type,
    jrl.modvat_flag,
    jrl.tax_line_no tax_line_no --modified by kunkumar for bug 5593895
    , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
    FROM JAI_RCV_LINE_TAXES jrl,rcv_shipment_lines rsl,rcv_transactions rt
    WHERE jrl.shipment_line_id = rsl.shipment_line_id
    AND rt.shipment_line_id = rsl.shipment_line_id
    AND rt.transaction_id = tran_id
    AND jrl.vendor_id = ven_id
    AND NVL(upper(jrl.tax_type),'TDS') NOT IN (
                                                 'TDS',
             'CVD',
             jai_constants.tax_type_add_cvd ,     -- Date 31/10/2006 Bug 5228046 added by SACSETHI
             'CUSTOMS',
                        JAI_CONSTANTS.TAX_TYPE_SH_CUSTOMS_EDU_CESS,jai_constants.tax_type_customs_edu_cess, -- added by ssawant for bug 5989740
            JAI_CONSTANTS.TAX_TYPE_SH_CVD_EDU_CESS,jai_constants.tax_type_cvd_edu_cess --added by ssawant for bug 5989740
                 )
    order by  tax_line_no -- added bug#3038566
    ;
Line: 1022

   SELECT
     jrl.tax_amount tax_amount
   , jrl.tax_id
   , jrl.currency
   , jrl.tax_type tax_type
   , jrl.modvat_flag
   , jrl.tax_line_no tax_line_no --modified by kunkumar for bug 5593895
   , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
   ,jcta.vat_flag vat_flag
   ,nvl(jcta.adhoc_flag,'N') adhoc_flag --12697697

  FROM
    JAI_RCV_LINE_TAXES jrl
  , RCV_SHIPMENT_LINES RSL
  , RCV_TRANSACTIONS RT
  , jai_cmn_taxes_all  jcta
  WHERE jrl.shipment_line_id = rsl.shipment_line_id
    AND rt.shipment_line_id  = rsl.shipment_line_id
    AND rt.transaction_id    = tran_id
    AND jrl.vendor_id        = ven_id
    AND jcta.tax_id          = jrl.tax_id  --Added by Eric for Inclusive Tax
    AND NVL(upper(jrl.tax_type),'TDS')
        NOT IN ( 'TDS'
               , 'CVD'
               , jai_constants.tax_type_add_cvd      -- Date 31/10/2006 Bug 5228046 added by SACSETHI
               , 'CUSTOMS'
               , JAI_CONSTANTS.TAX_TYPE_SH_CUSTOMS_EDU_CESS
               , jai_constants.tax_type_customs_edu_cess /* added by ssawant for bug 5989740 */
               , JAI_CONSTANTS.TAX_TYPE_SH_CVD_EDU_CESS
               , jai_constants.tax_type_cvd_edu_cess /* added by ssawant for bug 5989740 */
               )
     --Added by Qiong for reverse charge bug#16001407 start
     ---------------------------------------------------------------------
     AND NVL(jcta.reverse_charge_flag,'N') = 'N'
     ---------------------------------------------------------------------
     --Added by Qiong for reverse charge bug#16001407 end
    order by  tax_line_no; -- added
Line: 1069

    SELECT
      jrl.tax_amount tax_amount
    , jrl.tax_id
    , jrl.currency
    , jrl.tax_type tax_type
    , jrl.modvat_flag
    , jrl.tax_line_no tax_line_no --Added by kunkumar for bug 5593895
    , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
    ,jcta.vat_flag vat_flag
   ,nvl(jcta.adhoc_flag,'N') ADHOC_FLAG --12697697
    FROM
      jai_rcv_line_taxes jrl
    , rcv_shipment_lines rsl
    , rcv_transactions rt
    , jai_cmn_taxes_all jcta          --Added by Eric for Inclusive Tax
    WHERE jrl.shipment_line_id = rsl.shipment_line_id
      AND rt.shipment_line_id = rsl.shipment_line_id
      AND rt.transaction_id = tran_id
      AND jrl.vendor_id = ven_id
      AND jcta.tax_id   = jrl.tax_id  --Added by Eric for Inclusive Tax
      AND NVL(upper(jrl.tax_type),'TDS') NOT IN
                                             ('TDS',
                'CVD',
                       jai_constants.tax_type_add_cvd ,     -- Date 31/10/2006 Bug 5228046 added by SACSETHI
                'CUSTOMS',
                                              JAI_CONSTANTS.TAX_TYPE_SH_CUSTOMS_EDU_CESS,jai_constants.tax_type_customs_edu_cess, /* added by ssawant for bug 5989740 */
                JAI_CONSTANTS.TAX_TYPE_SH_CVD_EDU_CESS,jai_constants.tax_type_cvd_edu_cess /* added by ssawant for bug 5989740 */
       )
      AND p_source <> 'PPA'
      --Added by Qiong for reverse charge bug#16001407 start
      ---------------------------------------------------------------------
      AND NVL(jcta.reverse_charge_flag,'N') = 'N'
      ---------------------------------------------------------------------
      --Added by Qiong for reverse charge bug#16001407 end
    UNION

    SELECT
      (jrl.modified_tax_amount - jrl.original_tax_amount) tax_amount
    , jrl.tax_id
    , jrl.currency_code currency
    , jrl.tax_type tax_type
    , jrl.recoverable_flag modvat_flag
    , jrl.tax_line_no tax_line_no
    , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag
    ,jcta.vat_flag vat_flag
       ,nvl(jcta.adhoc_flag,'N') ADHOC_FLAG --12697697
    FROM
      jai_retro_tax_changes  jrl
    , rcv_shipment_lines     rsl
    , rcv_transactions       rt
    , jai_retro_line_changes jrlc
    , jai_cmn_taxes_all      jcta
    WHERE jrlc.doc_line_id = rsl.shipment_line_id
      AND jrlc.line_change_id = jrl.line_change_id
      AND jrlc.doc_version_number = (SELECT max(doc_version_number)
                                     FROM jai_retro_line_changes
                                     WHERE doc_type = 'RECEIPT'
                                       AND doc_line_id = jrlc.doc_line_id
                                     )
      AND jrlc.doc_type = 'RECEIPT'
      AND jrl.tax_id = jcta.tax_id
      AND rt.shipment_line_id = rsl.shipment_line_id
      AND rt.transaction_id = tran_id
      AND jrlc.vendor_id = ven_id
      AND p_source = 'PPA'
      AND NVL(upper(jrl.tax_type),'TDS') NOT IN ( jai_constants.tax_type_tds
                                                , jai_constants.tax_type_cvd
                                                , jai_constants.tax_type_add_cvd
                                                , jai_constants.tax_type_customs
                                                , jai_constants.tax_type_sh_customs_edu_cess
                                                , jai_constants.tax_type_customs_edu_cess
                                                , jai_constants.tax_type_sh_cvd_edu_cess
                                                , jai_constants.tax_type_cvd_edu_cess
                                                )
      AND NVL(jrl.third_party_flag, 'N') = 'N' -- Added by Jason Liu for bug#6936416
      --Added by Qiong for reverse charge bug#16001407 start
      ---------------------------------------------------------------------
      AND NVL(jcta.reverse_charge_flag,'N') = 'N'
      ---------------------------------------------------------------------
      --Added by Qiong for reverse charge bug#16001407 end
    -- GROUP BY jrl.tax_id,jrl.currency,jrl.tax_type, jrl.modvat_flag; commented by bug#3038566
Line: 1155

  select ap_invoice_distributions_s.nextval
  from   dual;
Line: 1161

 select precision
 from   fnd_currencies
 where  currency_code = cp_currency_code;
Line: 1169

 select NVL(rounding_factor,0) -- for bug 13954092 by anupgupt
 from jai_cmn_taxes_all
 where tax_id = cp_tax_id  ;
Line: 1176

  select source
  from ap_invoices_all
  where invoice_id = p_inv_id;
Line: 1212

  v_update_payment_schedule           boolean; -- bug#3218978
Line: 1223

  for_dist_insertion_rec              for_dist_insertion%ROWTYPE;
Line: 1251

  ln_lines_to_insert                  number;
Line: 1274

  SELECT
    NVL(ja.inclusive_tax_flag, 'N')  inclusive_tax_flag
  FROM
    jai_ap_tds_years ja
  WHERE ja.legal_entity_id = cn_org_id
  AND sysdate between ja.start_date and ja.end_date;
Line: 1289

    select attribute2 excise_costing_flag
    from   jai_rcv_transactions jrcvt
    where  jrcvt.parent_transaction_id = cp_rcv_transaction_id
  and    jrcvt.organization_id  = cp_organization_id --Added by Bgowrava for Bug#7503308
    and jrcvt.shipment_header_id = cp_shipment_header_id --Added by Bgowrava for Bug#7503308
    and    jrcvt.transaction_type = cp_txn_type  --'DELIVER'   --Modified by Bgowrava for Bug#7503308
    and    jrcvt.attribute1= cp_attribute1 ; --'CENVAT_COSTED_FLAG';  ----Modified by Bgowrava for Bug#7503308
Line: 1305

     select po_line_id, organization_id
     from   rcv_transactions
     where  transaction_id = p_transaction_id;
Line: 1311

     select item_id
     from   po_lines_all
     where  po_line_id = p_po_line_id;
Line: 1323

     select regime_id
     from   JAI_RGM_DEFINITIONS
     where  regime_code = cp_regime_code ; /* SERVICE or VAT */
Line: 1328

    select attribute_code tax_type
    from   JAI_RGM_REGISTRATIONS
    where  regime_id = cp_regime_id
    and    registration_type = jai_constants.regn_type_tax_types  /* TAX_TYPES */
    and    attribute_code = cp_tax_type;
Line: 1355

  SELECT max (line_number)
  FROM   ap_invoice_lines_all
  WHERE  invoice_id = inv_id;
Line: 1362

  SELECT   accounting_date
          ,period_name
          ,deferred_acctg_flag
          ,def_acctg_start_date
          ,def_acctg_end_date
          ,def_acctg_number_of_periods
          ,def_acctg_period_type
          ,set_of_books_id
    ,wfapproval_status -- Bug 4863208
  FROM    ap_invoice_lines_all
  WHERE   invoice_id = inv_id
  AND     line_number = cpn_max_line_num;
Line: 1378

  SELECT aia.source
  FROM ap_invoices_all aia
  WHERE aia.invoice_id = inv_id;
Line: 1396

  FUNCTION update_payment_schedule (p_total_tax NUMBER) RETURN boolean IS -- bug # 3218978

    v_total_tax_in_payment  number;
Line: 1405

    select  sum(gross_amount)
    from    ap_payment_schedules_all
    where   invoice_id = inv_id;
Line: 1411

  Fnd_File.put_line(Fnd_File.LOG, 'Start of function  update_payment_schedule');
Line: 1418

    Fnd_File.put_line(Fnd_File.LOG, 'Cannot update payment schedule, total payment amount :'
                                    || to_char(v_total_payment_amt));
Line: 1429

    select  gross_amount,
        payment_num
    from    ap_payment_schedules_all
    where   invoice_id = inv_id
    order by payment_num
    )
    loop

      v_tax_installment := 0;
Line: 1444

      update ap_payment_schedules_all
      set    gross_amount        = gross_amount          + v_tax_installment,
         amount_remaining      = amount_remaining      + v_tax_installment,
         inv_curr_gross_amount = inv_curr_gross_amount + v_tax_installment,
            payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
            -- bug#3624898
      where  invoice_id = inv_id
      and    payment_num = v_payment_num;
Line: 1462

      update ap_payment_schedules_all
      set    gross_amount        = gross_amount          + v_diff_tax_amount,
         amount_remaining      = amount_remaining      + v_diff_tax_amount,
         inv_curr_gross_amount = inv_curr_gross_amount + v_diff_tax_amount
      where  invoice_id = inv_id
      and    payment_num = v_payment_num;
Line: 1474

      Fnd_File.put_line(Fnd_File.LOG, 'exception from function  update_payment_schedule');
Line: 1477

  end update_payment_schedule; -- bug # 3218978
Line: 1480

  procedure insert_mrc_data (p_invoice_distribution_id number) is
    -- Vijay Shankar for bug#3461030
    v_mrc_string VARCHAR2(10000);
Line: 1486

      p_operation_mode    => ''INSERT'',
      p_table_name        => ''AP_INVOICE_DISTRIBUTIONS_ALL'',
      p_key_value         => :a,
      p_key_value_list    => NULL,
      p_calling_sequence  =>
      ''India Local Tax line as Miscellaneous distribution line (jai_ap_match_tax_pkg.process_online procedure)''
       ); END;';
Line: 1503

      FND_FILE.put_line(FND_FILE.log, '*** MRC API is not existing(insert)');
Line: 1505

      FND_FILE.put_line(FND_FILE.log, 'MRC API exists and different err(insert)->'||SQLERRM);
Line: 1511

  procedure update_mrc_data is
    -- Vijay Shankar for bug#3461030
    v_mrc_string VARCHAR2(10000);
Line: 1517

      p_operation_mode    => ''UPDATE'',
      p_table_name        => ''AP_INVOICES_ALL'',
      p_key_value         => :a,
      p_key_value_list    => NULL,
      p_calling_sequence  =>
      ''India Local Tax amount added to invoice header (jai_ap_match_tax_pkg.process_online procedure)''
       ); END;';
Line: 1534

      FND_FILE.put_line(FND_FILE.log, 'MRC API is not existing(update)');
Line: 1536

      FND_FILE.put_line(FND_FILE.log, 'MRC API exists and different err(update)->'||SQLERRM);
Line: 1547

    select amount, invoice_distribution_id
    from   ap_invoice_distributions_all
  WHERE  invoice_id = p_price_correct_inv_id
  and    po_distribution_id = p_po_distribution_id
  AND    line_type_lookup_code = 'ITEM';
Line: 1558

  select  sum(jam.tax_amount) tax_amount-- project costing fwd porting
  from    JAI_AP_MATCH_INV_TAXES jam,jai_cmn_taxes_all jct
  where   p_orig_invoice_id = p_orig_invoice_id
  and   parent_invoice_distribution_id = p_orig_invoice_dist_id
  and   jam.tax_id = p_tax_id
  --start additions for bug#10167393
  /*adhoc tax shall not be apportioned on PRICE CORRECTION*/
  and jam.tax_id=jct.tax_id
  and (
  nvl(jct.adhoc_flag,'N')='Y'
       or
     --( jct.adhoc_flag='Y' and jct.tax_type not in  ('Freight','Insurance','Octrai','Other','PURCHASE TAX','ENTRY TAX')));
Line: 1585

      execute immediate 'select /* price_correct_inv_id */, po_distribution_id, amount, quantity_invoiced
                         from   ap_invoice_lines_all
                         where  invoice_id = :inv_id
                         and    line_number = :inv_line_num'
                         into cur_price_correct_inv_id, cur_po_distribution_id, cur_amount, cur_quantity_invoiced
                         USING inv_id, pn_invoice_line_number;  -- Using pn_invoice_line_number instead of dist_line_no for Bug#4445989
Line: 1644

                        insert statemnt for temp table JAI_CMN_FA_INV_DIST_ALL

2.       29-mar-01      Subramanyam S.K added modifications for STForm
                        Tracking at AP level. Insert statments for JA_in_po_st_forms_hdr
                        and ja_in_po_st_forms_dtl after validating whether
                        the tax line is Sales Tax or CST and for these taxes
                        stform_type(JAI_CMN_TAXES_ALL) is not null.

3.       20-apr-01      Modifications done by Ajay Sharma for correct calculation
                        of taxes and invoice amount at the time of RCV_MATCHING

4.       17-aug-01      Code Added by Vijay for Multi-Org support of ST Form Tracking

5.       24-Aug-01      Modification done by Ajay Sharma to insert records in case of
                        running of pay on receipt for subsequent receipt against same PO

6.       08-Sep-01      Modifications done by Pavan to care of the split payment terms

7.       09-Mar-02      RPK: for BUG#2255404
                        Code modified to facilitate the invoice matching with more than
                        one receipt.When the invoice is matched to more than one receipts
                        getting the error 'Unique constraint(AP.AP_INVOICE_DITRIBUTIONS_U1) violated

8.       22-may-2002    Aparajita for bug # 2387481.
                        The calculation of tax amount for RCV_MATCHING case when there exists
                        some return to vendor for the receipt, was not correct.

                        Corrected it by using quantity_shipped in the r_for_shipment_line
                        cursor instead of quantity_received.
                        Quantity_shipped gives the original quantity of the receipt.

                        Added the Fnd_File.put_line(Fnd_File.LOG,'') statements to
                        generate the log also.

9.       09/10/2002     Aparajita for bug # 2483164 Version#615.1
                        Populate the po distribution id and rcv_transactions id for the tax
                        lines for backtracking tax to purchasing side.


10.       03/11/2002    Aparajita for bug # 2567799  Version#615.2
                       Added a function apportion_tax_pay_on_rect_f and using it to apportion
                       the tax amount. This is useful when there are multiple distributions for the PO.

                       Deleted the code for supplementary invoices as this is not being used.

11.       05/11/2002    Aparajita for bug # 2506453, Version#615.3

                       Changed the cursor definition get_tax_ln_no, to look into the receipt tax
                       instead of the po tax table for getting the line number.
                       This was running into error when no taxes exist at po and have been
                       added at receipt.

                       Added the cursor get_tax_ln_no_po, to fetch the tax line number from PO
                       if it is the case of PO matching.

                       Also Changed the cursor definition get_sales_tax_dtl to fetch on the
                       basis of tax id instead of name.

12.      02/12/2002    Aparajita for bug # 2689826 Version # 615.4

                       The distribution line numbers were getting  skipped every time the tax is
                       inserted for a 2nd item line onwards. This was happening because the
                       distribution line number is calulated by taking the max distribution
                       line number and also the no of tax lines which have a shipment line id
                       less than corresponding shipment line id for the same shipment header.

                       This logic is not required as the distribution line number should
                       always be the next number. commented the cursor count_tax_lines.

13.      14/01/2003     Aparajita for bug # 2694011. Version # 615.5

                       The taxes in case of PO matching were wrong when the price is changed
                       at PO matching. Added code to check the price at invoice to the price
                       at PO and apportioning the tax amount in case of a price change.
                       This is applicable to non-adhoc taxes only as they depend on the po amount.

                       Added unit price in cursor for_dist_insertion to get invoice price.
                       Added  price_override in cursor for_line_qty to get po price.
                       Added code to compare the above prices and apportion the calculated
                       tax in case of change.

                       Used the cursor for_line_qty in case of receipt matching with the
                       line location id from rcv_transactions to get the price.
                       Price of a receipt cannot be changed, so same as po price.
                       Logic of apportioning was also added in receipt matching cases.

14       31/01/2003    Aparajita for bug # 2775043. Version # 615.6
                       When price is changed at the time of po/receipt matching the tax amount is
                       apportioned appropriately. This should also hit the invoice price variance
                       account, but this is not happening as base apps expects the variance amount
                       and account code to be loaded into the following fields.

                        - price_var_code_combination_id
                        - invoice_price_variance
                        - base_invoice_price_variance (in functional currency)

15       21/02/2003     Aparajita for bug # 2805527. Version # 615.7
                       This procedure is run as a concurrent, this concurrent should be
                       incompatible to itself as more than 1 request may be entering tax lines for
                       the same invoice. For some reason if the incompatibility is not set or
                       does not work, this concurrent runs into error.

                       Added the concept of locking the distribution lines so that even if they
                       run concurrently there should not be any error.
                       The code was using two variables dno and dlno for distribution
                       number,

                       stream lines it to consider only v_distribution_no and changed the related logic.

16.      14/03/2003    Aparajita for bug # 2841363. Version # 615.8
                       Taxes having 0 amount were not considered, changed the cursor
                       from_line_location_taxes to consider such tax lines for propagation into AP.

17.      23/03/2003    Vijay Shankar for Bug# 2827356. Version # 615.9
                        When Receipt line Uom is different from PO shipment line Uom,
                        then Invoice Matching with Receipt is calculating taxes wrongly for distribution
                        item lines. This is resolved by incorporating Receipt Line to PO Shipment
                        line UOM converion rate to be multiplied with PO Shipment price (used to proportionate the receipt tax along with invoice distribution price).
                        This issue happens only during receipt matching.

18.      07/04/2003    Aparajita for bug # 2851123. Version # 615.10
                       The assets_tracking_flag in ap_invoice_distributions_all,
                       JAI_AP_MATCH_INV_TAXES and JAI_CMN_FA_INV_DIST_ALL should
                       be set as 'N' if the tax line against which the line is being generated
                       is excise type of tax and is modvatable. By default this flag gets the value
                       from the corresponding item line for which the tax is attached.

                       Introduced a variable v_assets_tracking_flag.
                       Modified the following cursors to fetch modvat_flag.
                       - from_line_location_taxes
                       - tax_lines1_cur
                       - r_tax_lines_cur

19      17/07/2003     Aparajita for bug#3038566. Version#616.1

                       Introduced a new function getSTformsTaxBaseAmount to calculate the
                       tax base amount to be populated into the table ja_in_po_st_forms_dtl.
                       Calculating the tax base amount from the tax amount and percentage was
                       giving problem because of rounding.

20     14/08/2003     kpvs for bug # 3051828, version # 616.2
                      OPM code merged into this version of the procedure.
                      Changes made to pull in the OPM code fixes done for bugs 2616100
                      and 2616107 Used 'v_opm_flag' to check for the process enabled flag of the
                      organization.

21.    17/08/2003     Aparajita for bug#3094025. Generic for bug#3054140. version # 616.3
                      There may be taxes at receipt without having any tax at PO.
                      For such cases, the st forms population has to cater.
                      Precedences are not available, so calculation of tax base is not possible.
                      Added the backward calcultion for such cases.

                      Changes in the function getSTformsTaxBaseAmount.
                      Introduced two new parameters tax amount and rate to calculate backward
                      in case PO tax details are not found.

                      It was observed that the function getSTformsTaxBaseAmount was always
                      considering the precedence 0 amount irrespective of the valus of the precendences.
                      This has been corrected.

22.   22/08/2003    Aparajita for bug# 2828928. Version # 616.4
                      Added the condition to consider null vendor id and modvat = 'N'taxes in the following
                      cursors. Also added the code to consider mod_cr_percentage.

                      - C_third_party_tax_recipt
                      - C_third_party_tax_po


23.     27/08/2003    Aparajita for bug#3116659. Version#616.5
                      Projects clean up.

24.   27/08/2003     Vijay Shankar for bug# 3096578. Version # 616.6
                       All taxes are not picked from PO Shipment if the taxes are selected based on
                       line_focus_id as there are different line_focus_id's for same line_location_id
                       which is wrong.Also we should use line_location_id to fetch the taxes instead of
                       line_focus_id as line_location_id refers to the PO Shipments in which taxes are
                       attached and line_focus_id is just a unique key for JAI_PO_LINE_LOCATIONS table.
                       Modified the cursor from_line_locations_taxes to fetch the taxes based on
                       line_location_id.

25      16/10/2003    Aparajita for bug#3193849. Version#616.7

                      Removed the ST forms functionality from here as ST forms population is now being
                      handled through a concurrent.

26    28/10/2003      Aparajita for bug#3206083. Version#616.7

                      If the base invoice is cancelled, there is no need to bring the tax lines.
                      Added code to check the cancelled date and if populated, returning from the proc.

27    28/10/2003    Aparajita for bug#3218978. Version#616.7

                      Tax amount is apportioned properly between the installments.
                      Differential tax amounts if any because of rounding is added to the last installment.

                      Code is not reading anything from terms master, instead based on the
                      distribution of the amount before tax, tax amount is distributed. coded in
                      in line function update_payment_schedule.


28      23/12/2003    Aparajita for bug#3306090. Version 618.1
                      Tax amount was calculated wrongly when tax currency is different from
                      invoice currency. This was not handled in the function
                      apportion_tax_pay_on_rect_f. Added code for the same.

29    07/01/2003    Aparajita for bug#3354932. Version#618.2
                    When the invoice is in foreign currency, for ERS invoice, base_amount in
                    ap_invoices_all should be updated to include the loc taxes as otherwise
                    it is creating wrong accounting entries.

                    This update needs to be done only for ERS invoices as other cases localization
                    does not update the invoice header amounts. p_rematch = 'PAY_ON_RECEIPT'.
                    Additionally this should be done only when the invoice currency is not
                    the functional currency.

30      27/01/2004   Aparajita for bug#3332988. Version#618.3

                    Call to AP_MRC_ENGINE_PKG.Maintain_MRC_Data for MRC functionality.

                    This call is made after every distribution line is inserted.
                    This has been implemented as a in line procedure insert_mrc_data.

                    The procedure is called after every insert into ap_invoice_distributions_all.

                    Procedure update_mrc_data has been created and invoked whereever invoice
                    header is being updated.

31     03/02/2004   Aparajita for bug#3015112. Version#618.4.
                    Removed the OPM costing functionality.
                    This was updating quantity invoiced and unit price for miscellaneous lines
                    and this was creating problem for subsequent transactions against the same
                    PO / Receipt.

                    The changes removed were brought in for bug#3051828.

32     24/02/2004   Vijay Shankar for bug#3461030. Version#618.5
                     Modified the MRC call to be dynamic by using EXECUTE IMMEDIATE.
                     This is done to take care of Ct.s who are on base version less than 11.5.7

33    25/02/2004   Aparajita for bug#3315162. Version#618.6

                    Base application gives problem while reversing localization tax lines.
                    This was analyzed with base and found out that the problem was because of
                    null value for matched_uom_lookup_code field of the miscellaneous tax distribution.
                    Further null value of quantity also creats problem as the billed quantity
                    on PO/receipt gets updated to null when the loc taxes does get reversed with
                    value populated for UOM.

                    Changes have been made to populate matched_uom_lookup_code same as item line
                    and quantity as 0.

34    30/03/2004   Aparajita for bug#3448803. Version#619.1.

                     track as asset flag for the distribution for tax line in payable invoice now
                     considers partially recoverable taxes. The logic is now as follows,

                     - default value of this flag is same as that of the corresponding item line.
                     - if the corresponding tax is modvatable to the extent of 100% then the value of
                     the flag is over written to 'N' irrespective of the value of the corresponding
                     base item line.

35      15/05/2004   Aparajita for bug#3624898. Version#619.2
                     Whenever the tax lines are populated, if the invoice is already fully paid
                     the paid amount is displayed wrongly to be including the tax amount.

                     Fixed the problem by updating the payment_status_flag in ap_invoices_all and
                     ap_payment_shedules_all to 'P' in case it was Y.

36      21/05/2004   Aparajita for bug#3632810. Version#115.1

                     Tax lines are apportioned when being brought over to AP for changes like
                     price, quantity etc. In cases where the UOM has been changed, it triggers a
                     change in price too. In such cases, UOM is also taken into account for changes
                     in quantity and price.

                     UOM at PO was being checked always from po_line_locations. But there are cases
                     like BPA, where the UOM is in po_lines_all in stead of po_line_locations_all.
                     Changed the code to check from po_lines_all whenever UOM does not exist in
                     Po_line_locations_all.

37     11/06/2004    Aparajita for bug#3671967. Version#115.2

                     When the tax line being brought over from PO by way of PO matching,
                     for completely recoverable taxes and a tax account has been defined for the tax
                     then tax account should be used.

                     This is applicable for PO matching only.

38    08/07/2004     Aparajita for bug#3752887. Version#115.3. Clean up.

                     Function apportion_tax_pay_on_rect_f was considering the quantity
                     from rcv_transactions and  taxes from JAI_RCV_LINE_TAXES.
                     This fails when there have been corrections as taxes are modified as
                     per the corrected quantity.

                     Cleaned the entire logic of apportioning of tax from PO to AP.
                     Used the function jai_ap_interface_pkg.get_apportion_factor which has been
                     designed new to find out the factor that needs to be applied. All Logic
                     of apportioning is now in the external function and removed a lot of code
                     from here which was trying to do the same here at more than one place.
                     Also rmoved the in line function function apportion_tax_pay_on_rect_f.

                     Function jai_ap_interface_pkg.get_apportion_factor was designed for purchase register report
                     through bug#3633078. Added the procedure here also in the patch as it is not
                     required to have the report to have the function. So no dependency.

                     Changes done via bug#2775043 earlier in this procedure for IPV for tax
                     line  was redone as it would again involve details of apportion.
                     Instead used the following logic to arrive at IPV amount.

                     tax invoice price variance :=
                     tax amount * (base item line variance amount / base item line amount).

39. 01/11/2003       ssumaith - bug# 3127834 - file version 115.4

                     currency precision was not used for rounding the tax amounts when inserting / updating
                     records into  ap_invoices_all , ap_invoices_distributions_all , ap_payment_Schedules_all
                     tables. As a result the invoice was going into automatic hold because the invoice amount
                     does not equal sum of distributions amount.

                     This has been resolved in the bug by getting the currency precision for the invoice
                     currency from FND_CURRENCIES table and using it in all the inserts and updates which
                     involve the tax amounts.

40. 30/12/2004       Aparajita - Bug#4095234. Version#115.5

                     Cursor r_cur_items_rec was getting used without being opened. There is no need to use this,
                     replaced with cur_items_rec. Removed the cursor r_cur_items.

41. 21/01/2005       Aparajita - Bug#4078546 Service Tax. Version#115.6

                     4106633  Base Bug For Education Cess on Excise, CVD and Customs.
                     4059774  Base Bug For Service Tax Regime Implementation.
                     4078546  Modification in receive and rtv accounting for service tax


                     Service Tax interim account needs to be populated as the charge account,
                     if the following condition is true.

                     Case of PO Matching or Accrue on receipt is No.

42. 11/02/2005      Aparajita - Bug#4177452. Version#115.7

                    Charge account for non-recoverable taxes were going was null.
                    This was because of the default assignment of,
                      v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 1999

                    each insertion of tax line if the tax amount is 0.


44  12/03/2005      Bug 4210102. Added by LGOPALSA Version 115.9
                    (1) Added CVD, Excise and Customs education cess
        (2) Added Check file syntax in dbdrv command
        (3) Added NOCOPY for OUT variables

45 8/05/2005        rchandan for bug#4333488. Version 116.1
                    The Invoice Distribution DFF is eliminated and a new global DFF is used to
                    maintain the functionality. From now the TDS tax, WCT tax and ESSI will not
                    be populated in the attribute columns of ap_invoice_distributions_all table
                    instead these will be populated in the global attribute columns. So the code changes are
                    made accordingly.

46 10-Jun-2005      rallamse for bug#  Version 116.2
                    All inserts into JAI_AP_MATCH_INV_TAXES table now include legal_entity_id as
                    part of R12 LE Initiative. The legal_entity_id is selected from ap_invoices_all in
                    cursor get_ven_info.

47  23-Jun-2005     Brathod for Bug# 4445989, Version 120.0
                    Issue: Impact uptake on IL Product for AP_INVOICE_LINES_ALL Uptake
                    Resolution:- Code modified to consider ap_invoice_lines_all instead of
                    ap_invoice_distributions_all.
                    Following changes done
                      -  Code refering to ap_invoice_distributions_all modified to consider
                         invoice_id and invoice_line_number as unique combination
                      -  invoice line record is created in ap_invoice_lines_all where ever previously
                         distribution was created
                      -  Obsoleted JAI_CMN_FA_INV_DIST_ALL
                      -  Modified structure of JAI_AP_MATCH_INV_TAXES to incorporate invoice lines
                         and also the fields from JAI_CMN_FA_INV_DIST_ALL
                      -  Code modfied to insert appropriate fields in JAI_AP_MATCH_INV_TAXES

48. 06-Jul-2005       Sanjikum for Bug#4474501
                      1) Commented the cursor - for_acct_id and corresponding open/fetch/close for the same.
                      2) Commented the call to function - jai_general_pkg.get_accounting_method

49. 25-Apr-2007       CSahoo for bug#5989740, File Version 120.14
                      Forward Porting of 11i bug#5907436
                      ENH: Handling of secondary and higher education cess.
                      Added the sh cess tax types.

50. 20-dec-2007      eric modified and added code for inclusive tax

51. 09-Jan-2008      Modifed by Jason Liu for retroactive price

52. 04-Feb-2008      JMEENA for bug#6780154

         Modify the insert statement of ap_invoice_lines_all to populate the po_distribution_id.


53. 21-Feb-2008      JMEENA for bug#6835548
         Changed the value of lv_match_type from NOT MATCHED to NOT_MATCHED.

54. 03-APR-2008      Jason Liu for bug#6918386
         Modified the cursor from_line_location_taxes
         1) Added the parameter p_source
         2) Added the UNION for PPA invoice
55.  03-APR-2008      Jason Liu for bug#66936416
         Added a condition to exclude the third party taxes

56. 19-May-2008     JMEENA for bug#7008161
        Modified the insert statement of ap_invoice_distributions_all to populate the charge_applicable_to_dist_id
        based on v_assets_tracking_flag and removed the condition of account_type.

 57.  12-Dec-2008  Added by Bgowrava for Bug#7503308, File Version 120.7.12000000.15, 120.34.12010000.4, 120.38
                  Issue: INDIA - TO INSERT TAXES FOR PAY ON RECEIPT REQUESTPERFORMANCE ISSUE
                  Reason: full table scan on JAI_RCV_TRANSACTIONS table in cursor c_get_excise_costing_flag
                  Fix:   Added organization_id and shipment_headder_id columns

58.  06-Apr-2010   Bgowrava For Bug#9499146, File Version 120.34.12010000.14,
                                 Issue: WRONG AP ACCRUAL ACCOUNT TAKING FOR RECOVERABLE TAXES LIKE EXCISE IN AP INVOICE
                                 Fix: Modified code so that all taxes will hit the same account as that of the  item line (except service type of taxes)

59. 07-DEC-2010  Abezgam for Bug#10375894 ,
	Issue: Fixed Assets Mass Addition report is Erroring out.
	Fix: Set the value for variable v_assets_tracking_flag to 'N'.

60. 10-Feb-2012 Qinglei for Bug#13589613, Bug#13561173, Bug#13696344

61. 16-Feb-2012 Qinglei for Bug#13561173
    Bug#13561173 is same as bug#13513039. Ported code change in 13513039.

Future Dependencies For the release Of this Object:-
==================================================
(Please add a row in the section below only if your bug introduces a dependency due to spec change/
A new call to a object/A datamodel change )

-------------------------------------------------------------------------------------------------------
Version       Bug       Dependencies (including other objects like files if any)
--------------------------------------------------------------------------------------------------------
616.1         3038566   ALTER Script  JAI_AP_MATCH_INV_TAXES Table is altered.

115.3         3752887   Dependency on function jai_ap_interface_pkg.get_apportion_factor which is also added
                        in this patch. So no pre - req.

115.6         4146708   Base Bug for Service + Cess Release.

                        Variable usage of jai_constants package.

                        Call to following,
                        jai_general_pkg.is_item_an_expense
                        jai_general_pkg.get_accounting_method
                        jai_rcv_trx_processing_pkg.get_accrue_on_receipt
                        jai_cmn_rgm_recording_pkg.get_account


------------------------------------------------------------------------------------------------------- */


  Fnd_File.put_line(Fnd_File.LOG, 'Start procedure - jai_ap_match_tax_pkg.process_online ');
Line: 2155

    select ap_invoice_distributions_s.nextval into ln_invoice_dist_id_rev from dual;
Line: 2166

        INSERT INTO ap_invoice_distributions_all
        (
        accounting_date,
        accrual_posted_flag,
        assets_addition_flag,
        assets_tracking_flag,
        cash_posted_flag,
        distribution_line_number,
        dist_code_combination_id,
        invoice_id,
        line_type_lookup_code,
        period_name,
        set_of_books_id ,
        amount,
        base_amount,
        batch_id,
        description,
        exchange_rate_variance,
        match_status_flag,
        posted_flag,
        rate_var_code_combination_id ,
        reversal_flag ,
        program_application_id,
        program_id,
        program_update_date,
        accts_pay_code_combination_id,
        invoice_distribution_id,
        quantity_invoiced,
        po_distribution_id ,
        rcv_transaction_id,
        parent_reversal_id,
        price_var_code_combination_id,
        invoice_price_variance,
        base_invoice_price_variance,
        matched_uom_lookup_code,
        invoice_line_number,
        org_id,
        charge_applicable_to_dist_id ,
        project_id,
        task_id,
        expenditure_type,
        expenditure_item_date,
        expenditure_organization_id,
        project_accounting_context,
        pa_addition_flag,
        distribution_class,
        dist_match_type,
        LAST_UPDATED_BY,
        LAST_UPDATE_DATE,
       created_by, /* Bug 16220700 */
		creation_Date /* Bug 16220700 */
        )
        VALUES
        (
        ins_reverse_dist_lines.accounting_date,
        'N', --ins_reverse_dist_lines.accrual_posted_flag, /* Bug 16220700 */
        ins_reverse_dist_lines.assets_addition_flag,
        ins_reverse_dist_lines.assets_tracking_flag,
        'N', --ins_reverse_dist_lines.cash_posted_flag, /* Bug 16220700 */
        ln_invoice_distribution_no,
        ins_reverse_dist_lines.dist_code_combination_id,
        ins_reverse_dist_lines.invoice_id,
        ins_reverse_dist_lines.line_type_lookup_code,
        ins_reverse_dist_lines.period_name,
        ins_reverse_dist_lines.set_of_books_id,
        -ins_reverse_dist_lines.amount,
        ins_reverse_dist_lines.base_amount,
        ins_reverse_dist_lines.batch_id,
        ins_reverse_dist_lines.description,
        ins_reverse_dist_lines.exchange_rate_variance,
        'N',
        'N', --ins_reverse_dist_lines.posted_flag, /* Bug 16220700 */
        ins_reverse_dist_lines.rate_var_code_combination_id,
        'Y',
        -1,
        -1,
        sysdate,
        ins_reverse_dist_lines.accts_pay_code_combination_id,
        ln_invoice_dist_id_rev,
        NULL,
        ins_reverse_dist_lines.po_distribution_id,
        ins_reverse_dist_lines.rcv_transaction_id,
        ins_reverse_dist_lines.invoice_distribution_id, --parent_reversal_id
        ins_reverse_dist_lines.price_var_code_combination_id,
        ins_reverse_dist_lines.invoice_price_variance,
        ins_reverse_dist_lines.base_invoice_price_variance,
        ins_reverse_dist_lines.matched_uom_lookup_code,
        ins_reverse_dist_lines.invoice_line_number,
        ins_reverse_dist_lines.org_id,
        ins_reverse_dist_lines.charge_applicable_to_dist_id ,
        ins_reverse_dist_lines.project_id,
        ins_reverse_dist_lines.task_id,
        ins_reverse_dist_lines.expenditure_type,
        ins_reverse_dist_lines.expenditure_item_date,
        ins_reverse_dist_lines.expenditure_organization_id,
        ins_reverse_dist_lines.project_accounting_context,
        ins_reverse_dist_lines.pa_addition_flag,
        ins_reverse_dist_lines.distribution_class,
        ins_reverse_dist_lines.dist_match_type,
        ln_user_id,
        sysdate,
        ln_user_id, /* Bug 16220700 */
		sysdate /* Bug 16220700 */);
Line: 2272

     Update ap_invoice_lines_all
     set  discarded_flag = 'Y',
          amount = 0,
          last_update_date = sysdate,
          last_updated_by = -1
    Where invoice_id =  ident_rec.invoice_id
    and line_number = ident_rec.invoice_line_number
    and line_type_lookup_code = 'MISCELLANEOUS';
Line: 2291

          select ap_invoice_distributions_s.nextval into ln_invoice_dist_id_rev from dual;
Line: 2292

 INSERT INTO ap_invoice_distributions_all
        (
        accounting_date,
        accrual_posted_flag,
        assets_addition_flag,
        assets_tracking_flag,
        cash_posted_flag,
        distribution_line_number,
        dist_code_combination_id,
        invoice_id,
        line_type_lookup_code,
        period_name,
        set_of_books_id ,
        amount,
        base_amount,
        batch_id,
        description,
        exchange_rate_variance,
        match_status_flag,
        posted_flag,
        rate_var_code_combination_id ,
        reversal_flag ,
        program_application_id,
        program_id,
        program_update_date,
        accts_pay_code_combination_id,
        invoice_distribution_id,
        quantity_invoiced,
        po_distribution_id ,
        rcv_transaction_id,
        parent_reversal_id,
        price_var_code_combination_id,
        invoice_price_variance,
        base_invoice_price_variance,
        matched_uom_lookup_code,
        invoice_line_number,
        org_id,
        charge_applicable_to_dist_id ,
        project_id,
        task_id,
        expenditure_type,
        expenditure_item_date,
        expenditure_organization_id,
        project_accounting_context,
        pa_addition_flag,
        distribution_class,
        dist_match_type,
        LAST_UPDATED_BY,
        LAST_UPDATE_DATE,
		created_by, /* Bug 16220700 */
		creation_date /* Bug 16220700 */
        )
        VALUES
        (
        ins_reverse_dist_lines_ers.accounting_date,
        'N', --ins_reverse_dist_lines_ers.accrual_posted_flag, /* Bug 16220700 */
        ins_reverse_dist_lines_ers.assets_addition_flag,
        ins_reverse_dist_lines_ers.assets_tracking_flag,
        'N', --ins_reverse_dist_lines_ers.cash_posted_flag, /* Bug 16220700 */
        ln_invoice_distribution_no,
        ins_reverse_dist_lines_ers.dist_code_combination_id,
        ins_reverse_dist_lines_ers.invoice_id,
        ins_reverse_dist_lines_ers.line_type_lookup_code,
        ins_reverse_dist_lines_ers.period_name,
        ins_reverse_dist_lines_ers.set_of_books_id,
        -ins_reverse_dist_lines_ers.amount,
        ins_reverse_dist_lines_ers.base_amount,
        ins_reverse_dist_lines_ers.batch_id,
        ins_reverse_dist_lines_ers.description,
        ins_reverse_dist_lines_ers.exchange_rate_variance,
        'N',
        'N', --ins_reverse_dist_lines_ers.posted_flag, /* Bug 16220700 */
        ins_reverse_dist_lines_ers.rate_var_code_combination_id,
        'Y',
        -1,
        -1,
        sysdate,
        ins_reverse_dist_lines_ers.accts_pay_code_combination_id,
        ln_invoice_dist_id_rev,
        NULL,
        ins_reverse_dist_lines_ers.po_distribution_id,
        ins_reverse_dist_lines_ers.rcv_transaction_id,
        ins_reverse_dist_lines_ers.invoice_distribution_id, --parent_reversal_id
        ins_reverse_dist_lines_ers.price_var_code_combination_id,
        ins_reverse_dist_lines_ers.invoice_price_variance,
        ins_reverse_dist_lines_ers.base_invoice_price_variance,
        ins_reverse_dist_lines_ers.matched_uom_lookup_code,
        ins_reverse_dist_lines_ers.invoice_line_number,
        ins_reverse_dist_lines_ers.org_id,
        ins_reverse_dist_lines_ers.charge_applicable_to_dist_id ,
        ins_reverse_dist_lines_ers.project_id,
        ins_reverse_dist_lines_ers.task_id,
        ins_reverse_dist_lines_ers.expenditure_type,
        ins_reverse_dist_lines_ers.expenditure_item_date,
        ins_reverse_dist_lines_ers.expenditure_organization_id,
        ins_reverse_dist_lines_ers.project_accounting_context,
        ins_reverse_dist_lines_ers.pa_addition_flag,
        ins_reverse_dist_lines_ers.distribution_class,
        ins_reverse_dist_lines_ers.dist_match_type,
        ln_user_id,
        sysdate,
		ln_user_id, /* Bug 16220700 */
		sysdate /* Bug 16220700 */);
Line: 2396

        Update ap_invoice_lines_all
        set  discarded_flag = 'Y',
        amount = 0,
        last_update_date = sysdate,
        last_updated_by = -1
        Where invoice_id =  ins_reverse_dist_lines_ers.invoice_id
        and line_number = ins_reverse_dist_lines_ers.invoice_line_number
        and line_type_lookup_code = 'MISCELLANEOUS';
Line: 2479

      SELECT chart_of_accounts_id INTO caid
      FROM   gl_sets_of_books
      WHERE  set_of_books_id = cur_items_rec.set_of_books_id;
Line: 2493

    update ap_invoice_distributions_all
    set    last_update_date = last_update_date
    where  invoice_id = inv_id;
Line: 2498

    update ap_invoice_lines_all
    set    last_update_date = last_update_date
    where  invoice_id = inv_id;
Line: 2502

    SELECT max(line_number)
    INTO   ln_inv_line_num
    FROM   ap_invoice_lines_all
    WHERE  invoice_id = inv_id;
Line: 2510

    select max(DISTRIBUTION_LINE_NUMBER)
    into   v_distribution_no
    from   ap_invoice_distributions_all
    where  invoice_id = inv_id;
Line: 2524

  SELECT accts_pay_code_combination_id
  INTO   apccid
  FROM   ap_invoices_all
  WHERE  invoice_id = inv_id;
Line: 2530

  OPEN  for_dist_insertion(inv_id,pn_invoice_line_number, ln_min_dist_line_num);
Line: 2531

  FETCH for_dist_insertion INTO for_dist_insertion_rec;
Line: 2532

  CLOSE for_dist_insertion;
Line: 2567

                             p_sob_id            =>    for_dist_insertion_rec.set_of_books_id,
                             p_organization_id   =>    r_rcv_transactions.organization_id
                          );*/
Line: 2578

   SELECT Min(po_distribution_id)
   INTO ln_po_dist_id
   FROM po_distributions_all
   WHERE po_line_id = ln_po_line_id
   AND line_location_id = ln_po_line_location_id;
Line: 2613

                    (for_dist_insertion_rec.dist_code_combination_id);
Line: 2706

      v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 2808

     v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;  --Added by Bgowrava for Bug#9499146
Line: 2811

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id; --Added by Bgowrava for Bug#9499146
Line: 2891

      ln_lines_to_insert := 1;
Line: 2907

        ln_lines_to_insert := 1;
Line: 2913

        ln_lines_to_insert := 2;
Line: 2929

        ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 2945

      fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                      ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                      ',ln_nrec_tax_amt='||ln_nrec_tax_amt||' ln_inclurec_tax_amt '||ln_inclurec_tax_amt
                       );
Line: 2956

      for line in 1..ln_lines_to_insert
      loop

        --Commented out the existing partially tax processing logic
        --replace it with new logic to cover inclusive tax case
        /*
        if line = 1 then

          v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 2971

          if for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES then
            v_assets_tracking_flag := jai_constants.YES;
Line: 2987

          lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 2988

          lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 2991

          v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 3105

            IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
              v_assets_tracking_flag := jai_constants.YES;
Line: 3121

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3122

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 3126

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 3150

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;--13561173
Line: 3170

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 3186

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3187

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3190

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 3212

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 3225

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3226

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3227

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 3240

          END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 3255

      'Before inserting into ap_invoice_lines_all for line no :' || ln_inv_line_num );
Line: 3282

        INSERT INTO ap_invoice_lines_all
        (
          INVOICE_ID
        , LINE_NUMBER
        , LINE_TYPE_LOOKUP_CODE
        , DESCRIPTION
        , ORG_ID
        , MATCH_TYPE
  , DEFAULT_DIST_CCID --Changes by nprashar for bug #6995437
        , ACCOUNTING_DATE
        , PERIOD_NAME
        , DEFERRED_ACCTG_FLAG
        , DEF_ACCTG_START_DATE
        , DEF_ACCTG_END_DATE
        , DEF_ACCTG_NUMBER_OF_PERIODS
        , DEF_ACCTG_PERIOD_TYPE
        , SET_OF_BOOKS_ID
        , AMOUNT
        , WFAPPROVAL_STATUS
        , CREATION_DATE
        , CREATED_BY
        , LAST_UPDATED_BY
        , LAST_UPDATE_DATE
        , LAST_UPDATE_LOGIN
        /* 5763527 */
        , project_id
        , task_id
        , expenditure_type
        , expenditure_item_date
        , expenditure_organization_id
        /* End 5763527 */
        ,po_distribution_id --Added for bug#6780154
         )
        VALUES
        (
          inv_id
        , ln_inv_line_num
        , lv_misc
        , c_tax_rec.tax_name
        , v_org_id
        , lv_match_type
  , v_dist_code_combination_id  --Changes by nprashar for bug #6995437
        , rec_max_ap_lines_all.accounting_date
        , rec_max_ap_lines_all.period_name
        , rec_max_ap_lines_all.deferred_acctg_flag
        , rec_max_ap_lines_all.def_acctg_start_date
        , rec_max_ap_lines_all.def_acctg_end_date
        , rec_max_ap_lines_all.def_acctg_number_of_periods
        , rec_max_ap_lines_all.def_acctg_period_type
        , rec_max_ap_lines_all.set_of_books_id
        , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
        , rec_max_ap_lines_all.wfapproval_status -- Bug 4863208
        , sysdate
        , ln_user_id
        , ln_user_id
        , sysdate
        , ln_login_id
        /* 5763527 */
        , ln_project_id
        , ln_task_id
        , lv_exp_type
        , ld_exp_item_date
        , ln_exp_organization_id
        /* End 5763527 */
        ,po_dist_id --Added for bug#6780154
        );
Line: 3350

     /*bug 9346307 - new LOOP added to insert multiple distributions for
     same line, if the matched PO shipment has multiple distributions*/
     v_distribution_no := 1;
Line: 3389

        'Before inserting into ap_invoice_distributions_all for distribution line no :'
        ||v_distribution_no  );
Line: 3408

               SELECT tax_account_id
               FROM jai_cmn_taxes_all
               WHERE tax_id = i.tax_id
               AND tax_type = 'Other';
Line: 3426

        INSERT INTO ap_invoice_distributions_all
        (
        accounting_date,
        accrual_posted_flag,
        assets_addition_flag,
        assets_tracking_flag,
        cash_posted_flag,
        distribution_line_number,
        dist_code_combination_id,
        invoice_id,
        last_updated_by,
        last_update_date,
        line_type_lookup_code,
        period_name,
        set_of_books_id ,
        amount,
        base_amount,
        batch_id,
        created_by,
        creation_date,
        description,
        exchange_rate_variance,
        last_update_login,
        match_status_flag,
        posted_flag,
        rate_var_code_combination_id ,
        reversal_flag ,
        program_application_id,
        program_id,
        program_update_date,
        accts_pay_code_combination_id,
        invoice_distribution_id,     /*  Added on 11-sep-00  */
        quantity_invoiced,
        po_distribution_id , -- added for bug # 2483164
        rcv_transaction_id, -- added for bug # 2483164
        price_var_code_combination_id, -- following three lines added for bug # 2775043.
        invoice_price_variance,
        base_invoice_price_variance,
        matched_uom_lookup_code  -- bug#3315162
        ,invoice_line_number -- Added by Brathod for Bug# 4445989
        ,org_id   -- Bug 4863208
        ,charge_applicable_to_dist_id -- Bug 5401111. Added by Lakshmi Gopalsami
        /* 5763527 */
        , project_id
        , task_id
        , expenditure_type
        , expenditure_item_date
        , expenditure_organization_id
        , project_accounting_context
        , pa_addition_flag
        -- Bug 7249100. Added by Lakshmi Gopalsami
          ,distribution_class
		   , dist_match_type --Added by nprashar for bug # 12832424
        )
        VALUES
        (
        rec_max_ap_lines_all.accounting_date,
        'N',
      r_ap_dist.assets_addition_flag,
        v_assets_tracking_flag,
        'N',
        v_distribution_no,
        v_dist_code_combination_id,
        inv_id,
        ln_user_id,
        sysdate,
        lv_misc,
        rec_max_ap_lines_all.period_name,
        rec_max_ap_lines_all.set_of_books_id ,
      ROUND(ROUND(v_tax_amt_dist,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
      ROUND(ROUND(v_tax_amt_dist * r_ap_dist.exchange_rate,ln_tax_precision), ln_precision), --Added by nprashar for bug # 13653889
        v_batch_id,
        ln_user_id,
        sysdate,
        c_tax_rec.tax_name,
        null,--kunkumar for forward porting to R12
        ln_login_id,
      r_ap_dist.match_status_flag , -- Bug 4863208
        'N',
        NULL,
      r_ap_dist.reversal_flag,  -- Bug 4863208
      r_ap_dist.program_application_id,
      r_ap_dist.program_id,
      r_ap_dist.program_update_date,
      r_ap_dist.accts_pay_code_combination_id,
        v_invoice_distribution_id,
        -1, --Modified by kunkumar for bug# 5593895
      r_ap_dist.po_distribution_id ,
        rcv_tran_id,
        v_price_var_accnt,
        v_tax_variance_inv_cur,
        v_tax_variance_fun_cur,
      r_ap_dist.matched_uom_lookup_code,
        ln_inv_line_num,
      r_ap_dist.org_id, -- Bug 4863208
        -- Bug 5401111. Added by Lakshmi Gopalsami
        decode(v_assets_tracking_flag,'N',
             NULL,r_ap_dist.invoice_distribution_id)
          /* 5763527 */
        , ln_project_id
        , ln_task_id
        , lv_exp_type
        , ld_exp_item_date
        , ln_exp_organization_id
        , lv_project_accounting_context
        , lv_pa_addition_flag
        /* End 5763527 */
        -- Bug 7249100. Added by Lakshmi Gopalsami
        ,lv_dist_class
        , r_ap_dist.dist_match_type  --Added by nprashar for bug # 12832424
        );
Line: 3545

      Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_AP_MATCH_INV_TAXES ');
Line: 3562

        INSERT INTO JAI_AP_MATCH_INV_TAXES
        (
        tax_distribution_id,

        assets_tracking_flag,
        invoice_id,
        po_header_id,
        po_line_id,
        line_location_id,
        set_of_books_id,
        --org_id,
        exchange_rate,
        exchange_rate_type,
        exchange_date,
        currency_code,
        code_combination_id,
        last_update_login,
        creation_date,
        created_by,
        last_update_date,
        last_updated_by,
        acct_pay_code_combination_id,
        accounting_date,
        tax_id,
        tax_amount,
        base_amount,
        chart_of_accounts_id,
        distribution_line_number,
        po_distribution_id,  -- added  by bug#3038566
        parent_invoice_distribution_id,  -- added  by bug#3038566
        legal_entity_id -- added by rallamse bug#
        ,INVOICE_LINE_NUMBER  --    Added by Brathod, Bug# 4445989
        ,INVOICE_DISTRIBUTION_ID ------------|
        ,PARENT_INVOICE_LINE_NUMBER----------|
        ,RCV_TRANSACTION_ID
        ,LINE_TYPE_LOOKUP_CODE
        /* 5763527 */
        , recoverable_flag
        , line_no            -- Bug 5553150, 5593895
        )
        -- End Bug# 4445989
        VALUES
        (
        JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,

        v_assets_tracking_flag, -- 'N', Commented by Aparajita for bug # 2851123
        inv_id,
        cur_items_rec.po_header_id,
        cur_items_rec.po_line_id,
        cur_items_rec.line_location_id,
        cur_items_rec.set_of_books_id,
        --cur_items_rec.org_id,
        cur_items_rec.rate,
        cur_items_rec.rate_type,
        cur_items_rec.rate_date,
        cur_items_rec.currency_code,
        v_dist_code_combination_id,
        cur_items_rec.last_update_login,
        cur_items_rec.creation_date,
        cur_items_rec.created_by,
        cur_items_rec.last_update_date,
        cur_items_rec.last_updated_by,
        apccid,
        cur_items_rec.invoice_date,
        i.tax_id,
        --ROUND(v_tax_amount, ln_precision), deleted by eric for inclusvice tax on 20-dec-2007
        ROUND(ROUND(lv_tax_line_amount * r_ap_dist.qty_apportion_factor, ln_tax_precision),ln_precision),
        nvl(ln_base_amount, ROUND(ROUND(i.tax_amount*r_ap_dist.qty_apportion_factor, ln_tax_precision), ln_precision)),
        caid,
        v_distribution_no,
      r_ap_dist.po_distribution_id, -- added  by bug#3038566
      r_ap_dist.invoice_distribution_id, -- added  by bug#3038566
        get_ven_info_rec.legal_entity_id -- added by rallamse bug#
        --, ln_inv_line_num , modified by eric for inclusvice tax
        --v_invoice_distribution_id,deleted by eric for inclusvice tax on 20-dec-2007

        --added by eric for inclusvice tax on 20-dec-2007,begin
        ---------------------------------------------------------------
        --Modified by Qinglei on 10-Feb-2012 for bug#13589613 begin
        /*, DECODE ( NVL(i.inc_tax_flag,'N')
                 , 'N',ln_inv_line_num
                 , 'Y',pn_invoice_line_number
                 )*/
        , DECODE ( NVL(i.inc_tax_flag,'N')
                 , 'N',ln_inv_line_num
                 , 'Y',DECODE(lv_modvat_flag,'Y',ln_inv_line_num,'N',pn_invoice_line_number)
                 )
        --For inclusive tax recoverable line, the invoice_line_number should the same as MISC line of ap_invoice_lines_all.
        --To ensure that it can generate journal entries in gl interface after invoice create accounting.
        --Modified by Qinglei on 10-Feb-2012 for bug#13589613 begin

        , NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
        ---------------------------------------------------------------
        --added by eric for inclusvice tax on 20-dec-2007,end
        , pn_invoice_line_number
        , rcv_tran_id
        , lv_misc
        , lv_modvat_flag -- 5763527
        , i.tax_line_no  -- Bug 5553150, 5593895
        );
Line: 3672

      insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 3693

      Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_CMN_FA_INV_DIST_ALL');
Line: 3694

      INSERT INTO JAI_CMN_FA_INV_DIST_ALL
      (
      invoice_id,
      invoice_distribution_id,
      set_of_books_id,
      batch_id,
      po_distribution_id,
      rcv_transaction_id,
      dist_code_combination_id,
      accounting_date,
      assets_addition_flag,
      assets_tracking_flag,
      distribution_line_number,
      line_type_lookup_code,
      amount,
      description,
      match_status_flag,
      quantity_invoiced
      )
      VALUES
      (
      inv_id,
      ap_invoice_distributions_s.CURRVAL,
      for_dist_insertion_rec.set_of_books_id,
      v_batch_id,
      for_dist_insertion_rec.po_distribution_id,
      rcv_tran_id,
      v_dist_code_combination_id,
      for_dist_insertion_rec.accounting_date,
      for_dist_insertion_rec.assets_addition_flag,
      v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
      v_distribution_no,
      'MISCELLANEOUS',
      ROUND(v_tax_amount, ln_precision),
      c_tax_rec.tax_name,
      NULL,
      NULL);
Line: 3732

      end loop ;--> for line in 1 to ln_lines_to_insert Brathod, 5763527
Line: 3744

   fnd_file.put_line(fnd_file.log ,'Start the Insertion of Inclusive Service tax lines for POT recoverable service amount is '||ln_inclurec_tax_amt);
Line: 3783

           v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 3797

                    Fnd_File.put_line(Fnd_File.LOG,'Before inserting Inclusive Service tax lines for POT into ap_invoice_lines_all for line no :'|| ln_inv_line_num ||'  tax amount =  '||lv_tax_line_amount);
Line: 3799

                           INSERT INTO ap_invoice_lines_all
                          (
                            INVOICE_ID
                          , LINE_NUMBER
                          , LINE_TYPE_LOOKUP_CODE
                          , DESCRIPTION
                          , ORG_ID
                          , MATCH_TYPE
                          , DEFAULT_DIST_CCID
                          , ACCOUNTING_DATE
                          , PERIOD_NAME
                          , DEFERRED_ACCTG_FLAG
                          , DEF_ACCTG_START_DATE
                          , DEF_ACCTG_END_DATE
                          , DEF_ACCTG_NUMBER_OF_PERIODS
                          , DEF_ACCTG_PERIOD_TYPE
                          , SET_OF_BOOKS_ID
                          , AMOUNT
                          , WFAPPROVAL_STATUS
                          , CREATION_DATE
                          , CREATED_BY
                          , LAST_UPDATED_BY
                          , LAST_UPDATE_DATE
                          , LAST_UPDATE_LOGIN
                          , project_id
                          , task_id
                          , expenditure_type
                          , expenditure_item_date
                          , expenditure_organization_id
                          ,po_distribution_id
                           )
                          VALUES
                          (
                            inv_id
                          , ln_inv_line_num
                          , lv_misc
                          , c_tax_rec.tax_name
                          , v_org_id
                          , lv_match_type
                          , v_dist_code_combination_id
                          , rec_max_ap_lines_all.accounting_date
                          , rec_max_ap_lines_all.period_name
                          , rec_max_ap_lines_all.deferred_acctg_flag
                          , rec_max_ap_lines_all.def_acctg_start_date
                          , rec_max_ap_lines_all.def_acctg_end_date
                          , rec_max_ap_lines_all.def_acctg_number_of_periods
                          , rec_max_ap_lines_all.def_acctg_period_type
                          , rec_max_ap_lines_all.set_of_books_id
                          , ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
                          , rec_max_ap_lines_all.wfapproval_status -- Bug 4863208
                          , sysdate
                          , ln_user_id
                          , ln_user_id
                          , sysdate
                          , ln_login_id
                          /* 5763527 */
                          , ln_project_id
                          , ln_task_id
                          , lv_exp_type
                          , ld_exp_item_date
                          , ln_exp_organization_id
                          /* End 5763527 */
                          ,po_dist_id --Added for bug#6780154
                          );
Line: 3865

                    'Before inserting  Inclusive Service tax lines for POT into ap_invoice_distributions_all for distribution line no :' || v_distribution_no);
Line: 3875

                 INSERT INTO ap_invoice_distributions_all
                             (accounting_date,
                              accrual_posted_flag,
                              assets_addition_flag,
                              assets_tracking_flag,
                              cash_posted_flag,
                              distribution_line_number,
                              dist_code_combination_id,
                              invoice_id,
                              last_updated_by,
                              last_update_date,
                              line_type_lookup_code,
                              period_name,
                              set_of_books_id ,
                              amount,
                              base_amount,
                              batch_id,
                              created_by,
                              creation_date,
                              description,
                              exchange_rate_variance,
                              last_update_login,
                              match_status_flag,
                              posted_flag,
                              rate_var_code_combination_id ,
                              reversal_flag ,
                              program_application_id,
                              program_id,
                              program_update_date,
                              accts_pay_code_combination_id,
                              invoice_distribution_id,
                              quantity_invoiced,
                              po_distribution_id ,
                              rcv_transaction_id,
                              price_var_code_combination_id,
                              invoice_price_variance,
                              base_invoice_price_variance,
                              matched_uom_lookup_code
                              , invoice_line_number
                              , org_id
                              , charge_applicable_to_dist_id
                              , project_id
                              , task_id
                              , expenditure_type
                              , expenditure_item_date
                              , expenditure_organization_id
                              , project_accounting_context
                              , pa_addition_flag
                              , distribution_class
                              , dist_match_type  --Added by nprashar for bug # 12832424
                              )
                              VALUES
                              (
                              rec_max_ap_lines_all.accounting_date,
                              'N',
                              --r_ap_dist.assets_addition_flag,
                              for_dist_insertion_rec.assets_addition_flag,
                              --Modified by Qinglei on 10-Feb-2012 for bug#13696344
                              v_assets_tracking_flag,
                              'N',
                              v_distribution_no,
                              v_dist_code_combination_id,
                              inv_id,
                              ln_user_id,
                              sysdate,
                              lv_misc,
                              rec_max_ap_lines_all.period_name,
                              rec_max_ap_lines_all.set_of_books_id ,
                              ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision),  --Added by nprashar for bug # 13653889
                              ROUND(ROUND(lv_tax_line_amount * r_ap_dist.exchange_rate,ln_tax_precision), ln_precision), --Added by nprashar for bug # 13653889
                              v_batch_id,
                              ln_user_id,
                              sysdate,
                              c_tax_rec.tax_name,
                              null,
                              ln_login_id,
                              --r_ap_dist.match_status_flag ,
                              for_dist_insertion_rec.match_status_flag,
                              --Modified by Qinglei on 10-Feb-2012 for bug#13696344
                              'N',
                              NULL,
                              /*r_ap_dist.reversal_flag,
                              r_ap_dist.program_application_id,
                              r_ap_dist.program_id,
                              r_ap_dist.program_update_date,
                              r_ap_dist.accts_pay_code_combination_id,*/
                              for_dist_insertion_rec.reversal_flag,
                              for_dist_insertion_rec.program_application_id,
                              for_dist_insertion_rec.program_id,
                              for_dist_insertion_rec.program_update_date,
                              for_dist_insertion_rec.accts_pay_code_combination_id,
                              --Modified by Qinglei on 10-Feb-2012 for bug#13696344
                              v_invoice_distribution_id,
                              -1,
                              --r_ap_dist.po_distribution_id ,
                              for_dist_insertion_rec.po_distribution_id,
                              rcv_tran_id,
                              v_price_var_accnt,
                              v_tax_variance_inv_cur,
                              v_tax_variance_fun_cur,
                              --r_ap_dist.matched_uom_lookup_code,
                              for_dist_insertion_rec.matched_uom_lookup_code,
                              ln_inv_line_num,
                              --r_ap_dist.org_id,
                              for_dist_insertion_rec.org_id,
                              --Modified by Qinglei on 10-Feb-2012 for bug#13696344
                              decode(v_assets_tracking_flag,'N',
                                   NULL,/*r_ap_dist.invoice_distribution_id*/for_dist_insertion_rec.invoice_distribution_id)
                                   --Modified by Qinglei on 10-Feb-2012 for bug#13696344
                              , ln_project_id
                              , ln_task_id
                              , lv_exp_type
                              , ld_exp_item_date
                              , ln_exp_organization_id
                              , lv_project_accounting_context
                              , lv_pa_addition_flag
                              , lv_dist_class
                              --, r_ap_dist.dist_match_type --Added by nprashar for bug # 12832424
                              , for_dist_insertion_rec.dist_match_type
                              --Modified by Qinglei on 10-Feb-2012 for bug#13696344
                              );
Line: 3999

           UPDATE JAI_AP_MATCH_INV_TAXES jat
           SET    jat.invoice_distribution_id = v_invoice_distribution_id
           WHERE  jat.invoice_id = inv_id
           AND    jat.po_header_id = cur_items_rec.po_header_id
           AND    jat.po_line_id = cur_items_rec.po_line_id
           AND    jat.line_location_id = cur_items_rec.line_location_id
           AND    jat.set_of_books_id = cur_items_rec.set_of_books_id
           AND    jat.line_no = i.tax_line_no
           AND    jat.tax_id = i.tax_id
           AND    jat.recoverable_flag = decode(inclu_Serv_line,1,'Y',2,'N','N');
Line: 4026

     * Removed the update which is updating ap_invoices_all
     * and ap_payment_schedules_all
     */

    /* Bug 8866084 - Start
     * Added the update which is updating ap_invoices_all
     * and ap_payment_schedules_all
     * Needs to be updated for Invoices created from iSupplier
    */

     open c_get_ap_invoice_src (inv_id);
Line: 4043

         cum_tax_amt is initialized with -1 for Bug 5593895. Bug updates are not clear as to why it was done
         This causes Tax Amount to be less by 1 when PO Matched Invoice is created from iSupplier
         Hence incrementing Tax Amount by 1 for this specific scenario as modifying initialization to 0 may cause regression
         */
         cum_tax_amt := cum_tax_amt + 1;
Line: 4049

         v_update_payment_schedule:=update_payment_schedule(cum_tax_amt);
Line: 4051

         UPDATE ap_invoices_all
         SET   invoice_amount       =  invoice_amount   + cum_tax_amt,
               approved_amount      =  approved_amount  + cum_tax_amt,
               pay_curr_invoice_amount =  pay_curr_invoice_amount + cum_tax_amt,
               amount_applicable_to_discount =  amount_applicable_to_discount + cum_tax_amt,
               payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
         WHERE  invoice_id = inv_id;
Line: 4061

            update ap_invoices_all
            set    base_amount = invoice_amount  * exchange_rate
            where  invoice_id = inv_id;
Line: 4130

                              p_parent_dist_id      =>   for_dist_insertion_rec.invoice_distribution_id ,
                              p_tax_id              =>   tax_lines1_rec.tax_id
                            ) ;
Line: 4138

        v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 4202

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 4219

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4220

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4230

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 4289

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4290

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4292

            v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 4302

        ln_lines_to_insert := 1; -- Loop controller to insert more than one lines for partially recoverable tax lines in PO
Line: 4316

          ln_lines_to_insert := 1;
Line: 4322

          ln_lines_to_insert := 2;
Line: 4338

          ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 4344

        fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                        ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                        ',ln_nrec_tax_amt='||ln_nrec_tax_amt
                         );
Line: 4356

        for line in 1..ln_lines_to_insert
        loop
          --commented out by eric for inclusive tax on 20-dec-2007,begin
          /*
          if line = 1 then

            v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 4369

            if for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES then
              v_assets_tracking_flag := jai_constants.YES;
Line: 4385

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4386

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 4389

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 4415

              IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
                v_assets_tracking_flag := jai_constants.YES;
Line: 4431

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4432

                lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 4436

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 4480

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 4496

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4497

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4500

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 4522

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 4535

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4536

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4537

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 4550

            END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 4569

          'Before inserting into ap_invoice_lines_all for line no :'|| ln_inv_line_num  );
Line: 4590

            INSERT INTO ap_invoice_lines_all
            (
              INVOICE_ID
            , LINE_NUMBER
            , LINE_TYPE_LOOKUP_CODE
            , DESCRIPTION
            , ORG_ID
            , MATCH_TYPE
      , DEFAULT_DIST_CCID --Changes by nprashar for bug #6995437
            , ACCOUNTING_DATE
            , PERIOD_NAME
            , DEFERRED_ACCTG_FLAG
            , DEF_ACCTG_START_DATE
            , DEF_ACCTG_END_DATE
            , DEF_ACCTG_NUMBER_OF_PERIODS
            , DEF_ACCTG_PERIOD_TYPE
            , SET_OF_BOOKS_ID
            , AMOUNT
            , WFAPPROVAL_STATUS
            , CREATION_DATE
            , CREATED_BY
            , LAST_UPDATED_BY
            , LAST_UPDATE_DATE
            , LAST_UPDATE_LOGIN
              /* 5763527 */
            , project_id
            , task_id
            , expenditure_type
            , expenditure_item_date
            , expenditure_organization_id
            /* End 5763527 */
            ,po_distribution_id --Added for bug#6780154

            )
            VALUES
            (
              inv_id
            , ln_inv_line_num
            , lv_misc
            , c_tax_rec.tax_name
            , v_org_id
            , NULL
      ,v_dist_code_combination_id
            , rec_max_ap_lines_all.accounting_date
            , rec_max_ap_lines_all.period_name
            , rec_max_ap_lines_all.deferred_acctg_flag
            , rec_max_ap_lines_all.def_acctg_start_date
            , rec_max_ap_lines_all.def_acctg_end_date
            , rec_max_ap_lines_all.def_acctg_number_of_periods
            , rec_max_ap_lines_all.def_acctg_period_type
            , rec_max_ap_lines_all.set_of_books_id
            , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
            , rec_max_ap_lines_all.wfapproval_status -- Bug 4863208
            , sysdate
            , ln_user_id
            , ln_user_id
            , sysdate
            , ln_login_id
              /* 5763527 */
              , ln_project_id
              , ln_task_id
              , lv_exp_type
              , ld_exp_item_date
              , ln_exp_organization_id
              /* End 5763527 */
           ,po_dist_id  --Added for bug#6780154
            );
Line: 4659

            'Before inserting into ap_invoice_distributions_all for distribution line no : '
            ||v_distribution_no);
Line: 4670

            INSERT INTO ap_invoice_distributions_all
            (
            accounting_date,
            accrual_posted_flag,
            assets_addition_flag,
            assets_tracking_flag,
            cash_posted_flag,
            distribution_line_number,
            dist_code_combination_id,
            invoice_id,
            last_updated_by,
            last_update_date,
            line_type_lookup_code,
            period_name,
            set_of_books_id,
            amount,
            base_amount,
            batch_id,
            created_by,
            creation_date,
            description,
            exchange_rate_variance,
            last_update_login,
            match_status_flag,
            posted_flag,
            rate_var_code_combination_id,
            reversal_flag,
            program_application_id,
            program_id,
            program_update_date,
            accts_pay_code_combination_id,
            invoice_distribution_id,
            quantity_invoiced,
            po_distribution_id ,
            rcv_transaction_id,
            matched_uom_lookup_code
            ,INVOICE_LINE_NUMBER
            ,org_id -- Bug 4863208
            ,charge_applicable_to_dist_id -- Bug 5401111. Added by Lakshmi Gopalsami
            /* 5763527 */
            , project_id
            , task_id
            , expenditure_type
            , expenditure_item_date
            , expenditure_organization_id
            , project_accounting_context
            , pa_addition_flag
            /* End 5763527 */
           -- Bug 7249100. Added by Lakshmi Gopalsami
            ,distribution_class
              , dist_match_type --Added by nprashar for bug # 12832424
            )
            VALUES
            (
            rec_max_ap_lines_all.accounting_date,
            'N', --for_dist_insertion_rec.accrual_posted_flag,
            for_dist_insertion_rec.assets_addition_flag,
            v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
            'N',
            v_distribution_no,
            /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
                   * for_dist_insertion_rec.dist_code_combination_id
             * and v_dist_code_combination_id
             */
            v_dist_code_combination_id,
            inv_id,
            ln_user_id,
            sysdate,
            lv_misc,
            rec_max_ap_lines_all.period_name,
            rec_max_ap_lines_all.set_of_books_id,
            ROUND(round(v_tax_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
            ROUND(ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
            v_batch_id,
            ln_user_id,
            sysdate,
            c_tax_rec.tax_name,
            null,--kunkumar for forward porting to R12
            ln_login_id,
            for_dist_insertion_rec.match_status_flag , -- Bug 4863208
            'N',
            NULL,
            -- 'N',
            for_dist_insertion_rec.reversal_flag,  -- Bug 4863208
            for_dist_insertion_rec.program_application_id,
            for_dist_insertion_rec.program_id,
            for_dist_insertion_rec.program_update_date,
            for_dist_insertion_rec.accts_pay_code_combination_id,
            v_invoice_distribution_id,
            decode(v_assets_tracking_flag, 'Y', NULL, 0), /* Modified for bug 8406404 by vumaasha */
             --po_dist_id,12434160
			for_dist_insertion_rec.po_distribution_id, --12434160
            rcv_tran_id,
            for_dist_insertion_rec.matched_uom_lookup_code
            ,ln_inv_line_num
            ,for_dist_insertion_rec.org_id -- Bug 4863208
            -- Bug 5401111. Added by Lakshmi Gopalsami
            ,decode(v_assets_tracking_flag,'N',
                    NULL,for_dist_insertion_rec.invoice_distribution_id)
/*Commented the account_type condition for bug#7008161 by JMEENA
       decode(lv_account_type, 'A',
              for_dist_insertion_rec.invoice_distribution_id,NULL)
            )
*/
            /* 5763527 */
            , ln_project_id
            , ln_task_id
            , lv_exp_type
            , ld_exp_item_date
            , ln_exp_organization_id
            , lv_project_accounting_context
            , lv_pa_addition_flag
            -- Bug 7249100. Added by Lakshmi Gopalsami
            ,lv_dist_class
            , for_dist_insertion_rec.dist_match_type --Added by nprashar for bug # 12832424
            );
Line: 4793

        Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_AP_MATCH_INV_TAXES ');
Line: 4794

        INSERT INTO JAI_AP_MATCH_INV_TAXES
        (
        tax_distribution_id,
        exchange_rate_variance,
        assets_tracking_flag,
        invoice_id,
        po_header_id,
        po_line_id,
        line_location_id,
        set_of_books_id,
        --org_id,
        exchange_rate,
        exchange_rate_type,
        exchange_date,
        currency_code,
        code_combination_id,
        last_update_login,
        creation_date,
        created_by,
        last_update_date,
        last_updated_by,
        acct_pay_code_combination_id,
        accounting_date,
        tax_id,
        tax_amount,
        base_amount,
        chart_of_accounts_id,
        distribution_line_number,
        --project_id,
        --task_id,
        po_distribution_id,  -- added  by bug#3038566
        parent_invoice_distribution_id,  -- added  by bug#3038566
        legal_entity_id -- added by rallamse bug#
        -- Added by Brathod, Bug# 4445989
        ,invoice_line_number
        ,INVOICE_DISTRIBUTION_ID
        ,PARENT_INVOICE_LINE_NUMBER
        ,RCV_TRANSACTION_ID
        ,LINE_TYPE_LOOKUP_CODE
        -- End Bug# 4445989
        ,recoverable_flag -- 5763527
        ,line_no          -- Bug 5553150, 5593895
        )
        VALUES
        (
        JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,
       null,--kunkumar for forward porting to R12
        v_assets_tracking_flag, -- 'N', bug # 2851123
        inv_id,
        cur_items_rec.po_header_id,
        cur_items_rec.po_line_id,
        cur_items_rec.line_location_id,
        cur_items_rec.set_of_books_id,
        --cur_items_rec.org_id,
        cur_items_rec.rate,
        cur_items_rec.rate_type,
        cur_items_rec.rate_date,
        cur_items_rec.currency_code,
  /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
         * c_tax_rec.tax_account_id and v_dist_code_combination_id
   */
        v_dist_code_combination_id,
        cur_items_rec.last_update_login,
        cur_items_rec.creation_date,
        cur_items_rec.created_by,
        cur_items_rec.last_update_date,
        cur_items_rec.last_updated_by,
        apccid,
        cur_items_rec.invoice_date,
        tax_lines1_rec.tax_id,
        /*commented out by eric for inclusive tax
        round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
        */
        ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision),  --Added by nprashar for bug # 13653889
        ROUND(ROUND(tax_lines1_rec.tax_amount, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
        caid,
        v_distribution_no,
        --p_project_id,
        --p_task_id ,
        po_dist_id, -- added  by bug#3038566
        for_dist_insertion_rec.invoice_distribution_id, -- added  by bug#3038566
        get_ven_info_rec.legal_entity_id, -- added by rallamse bug#
        --, ln_inv_line_num , modified by eric for inclusvice tax
        --, v_invoice_distribution_id , modified by eric for inclusvice tax
        --added by eric for inclusvice tax on 20-dec-2007,begin
        --------------------------------------------------------------------------
        DECODE ( NVL(tax_lines1_rec.inc_tax_flag,'N')
               , 'N',ln_inv_line_num
               , 'Y',pn_invoice_line_number
               )
        , NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
        --------------------------------------------------------------------------
        --added by eric for inclusvice tax on 20-dec-2007,end
        , pn_invoice_line_number
       , rcv_tran_id
       , lv_misc
       , lv_modvat_flag -- 5763527
       , tax_lines1_rec.tax_line_no  -- Bug 5553150, 5593895

        );
Line: 4897

        insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 4914

        Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_CMN_FA_INV_DIST_ALL ');
Line: 4916

        INSERT INTO JAI_CMN_FA_INV_DIST_ALL
        (
        invoice_id,
        invoice_distribution_id,
        set_of_books_id,
        batch_id,
        po_distribution_id,
        rcv_transaction_id,
        dist_code_combination_id,
        accounting_date,
        assets_addition_flag,
        assets_tracking_flag,
        distribution_line_number,
        line_type_lookup_code,
        amount,
        description,
        match_status_flag,
        quantity_invoiced
        )
        VALUES
        (
        inv_id,
        ap_invoice_distributions_s.CURRVAL,
        for_dist_insertion_rec.set_of_books_id,
        v_batch_id,
        for_dist_insertion_rec.po_distribution_id,
        rcv_tran_id,
        for_dist_insertion_rec.dist_code_combination_id,
        for_dist_insertion_rec.accounting_date,
        for_dist_insertion_rec.assets_addition_flag,
        v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
        v_distribution_no,
        'MISCELLANEOUS',
        round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799,
        c_tax_rec.tax_name,
        NULL,
        NULL
        );
Line: 4955

        end loop ;--> for line in 1 to ln_lines_to_insert Brathod, 5763527
Line: 4960

      v_update_payment_schedule:=update_payment_schedule(cum_tax_amt); -- bug#3218978
Line: 4963

      UPDATE ap_invoices_all
      SET   invoice_amount       =  invoice_amount   + cum_tax_amt,
        approved_amount      =  approved_amount  + cum_tax_amt,
        pay_curr_invoice_amount =  pay_curr_invoice_amount + cum_tax_amt,
        amount_applicable_to_discount =  amount_applicable_to_discount + cum_tax_amt,
        payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
        -- bug#3624898
      WHERE  invoice_id = inv_id;
Line: 4975

        update ap_invoices_all
        set    base_amount = invoice_amount  * exchange_rate
        where  invoice_id = inv_id;
Line: 4983

     update_mrc_data; -- bug#3332988
Line: 5042

                              p_parent_dist_id      =>   for_dist_insertion_rec.invoice_distribution_id ,
                              p_tax_id              =>   tax_lines1_rec.tax_id
                            ) ;
Line: 5050

        v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 5113

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 5128

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5129

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5138

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 5154

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5155

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5157

            v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 5183

        ln_lines_to_insert := 1; -- Loop controller to insert more than one lines for partially recoverable tax lines in PO
Line: 5197

          ln_lines_to_insert := 1;
Line: 5203

          ln_lines_to_insert := 2;
Line: 5220

        ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 5237

      fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                      ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                      ',ln_nrec_tax_amt='||ln_nrec_tax_amt ||' ln_inclurec_tax_amt '||ln_inclurec_tax_amt
                       );
Line: 5251

      for line in 1..ln_lines_to_insert
      loop

        --commented out by eric for inclusive tax
        /*
        if line = 1 then

          v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 5265

          if for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES then
            v_assets_tracking_flag := jai_constants.YES;
Line: 5282

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5283

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5285

          v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 5313

            IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
              v_assets_tracking_flag := jai_constants.YES;
Line: 5329

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5330

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 5334

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 5378

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 5394

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5395

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5398

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 5420

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 5433

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5434

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5435

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 5448

          END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 5455

      Fnd_File.put_line(Fnd_File.LOG,'Before inserting into ap_invoice_lines_all for line no :'
      || ln_inv_line_num  );
Line: 5477

          INSERT INTO ap_invoice_lines_all
          (
            INVOICE_ID
          , LINE_NUMBER
          , LINE_TYPE_LOOKUP_CODE
          , DESCRIPTION
          , ORG_ID
          , MATCH_TYPE
    , DEFAULT_DIST_CCID --Changes by nprashar for bug #6995437
          , ACCOUNTING_DATE
          , PERIOD_NAME
          , DEFERRED_ACCTG_FLAG
          , DEF_ACCTG_START_DATE
          , DEF_ACCTG_END_DATE
          , DEF_ACCTG_NUMBER_OF_PERIODS
          , DEF_ACCTG_PERIOD_TYPE
          , SET_OF_BOOKS_ID
          , AMOUNT
          , WFAPPROVAL_STATUS
          , CREATION_DATE
          , CREATED_BY
          , LAST_UPDATED_BY
          , LAST_UPDATE_DATE
          , LAST_UPDATE_LOGIN
          /* 5763527 */
          , project_id
          , task_id
          , expenditure_type
          , expenditure_item_date
          , expenditure_organization_id
          /* End 5763527 */
         ,po_distribution_id --Added for bug#6780154

          )
          VALUES
          (
            inv_id
          , ln_inv_line_num
          , lv_misc
          , c_tax_rec.tax_name
          , v_org_id
          , lv_match_type
    , v_dist_code_combination_id
          , rec_max_ap_lines_all.accounting_date
          , rec_max_ap_lines_all.period_name
          , rec_max_ap_lines_all.deferred_acctg_flag
          , rec_max_ap_lines_all.def_acctg_start_date
          , rec_max_ap_lines_all.def_acctg_end_date
          , rec_max_ap_lines_all.def_acctg_number_of_periods
          , rec_max_ap_lines_all.def_acctg_period_type
          , rec_max_ap_lines_all.set_of_books_id
          , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
          , rec_max_ap_lines_all.wfapproval_status -- Bug 4863208
          , sysdate
          , ln_user_id
          , ln_user_id
          , sysdate
          , ln_login_id
          /* 5763527 */
          , ln_project_id
          , ln_task_id
          , lv_exp_type
          , ld_exp_item_date
          , ln_exp_organization_id
          /* End 5763527 */
          ,po_dist_id --Added for bug#6780154
          );
Line: 5546

          'Before inserting into ap_invoice_distributions_all for distribution line no : ' || v_distribution_no);
Line: 5556

          INSERT INTO ap_invoice_distributions_all
          (
          accounting_date,
          accrual_posted_flag,
          assets_addition_flag,
          assets_tracking_flag,
          cash_posted_flag,
          distribution_line_number,
          dist_code_combination_id,
          invoice_id,
          last_updated_by,
          last_update_date,
          line_type_lookup_code,
          period_name,
          set_of_books_id,
          amount,
          base_amount,
          batch_id,
          created_by,
          creation_date,
          description,
          exChange_rate_variance,
          last_update_login,
          match_status_flag,
          posted_flag,
          rate_var_code_combination_id,
          reversal_flag,
          program_application_id,
          program_id,
          program_update_date,
          accts_pay_code_combination_id,
          invoice_distribution_id,
          quantity_invoiced,
          po_distribution_id ,
          rcv_transaction_id,
          matched_uom_lookup_code,
          invoice_line_number,
          org_id -- Bug 4863208
          ,charge_applicable_to_dist_id -- Bug 5401111. Added by Lakshmi Gopalsami
          /* 5763527 */
          , project_id
          , task_id
          , expenditure_type
          , expenditure_item_date
          , expenditure_organization_id
          , project_accounting_context
          , pa_addition_flag
          /* End 5763527 */
          -- Bug 7249100. Added by Lakshmi Gopalsami
          ,distribution_class
           ,dist_match_type --Added by nprashar for bug #  12832424
          )
          VALUES
          (
          rec_max_ap_lines_all.accounting_date,
          'N', --for_dist_insertion_rec.accrual_posted_flag,
          for_dist_insertion_rec.assets_addition_flag,
          v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
          'N',
          v_distribution_no,
    /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
           * for_dist_insertion_rec.dist_code_combination_id
     * and v_dist_code_combination_id
     */
          v_dist_code_combination_id,
          inv_id,
          ln_user_id,
          sysdate,
          lv_misc,
          rec_max_ap_lines_all.period_name,
          rec_max_ap_lines_all.set_of_books_id,
          ROUND(round(v_tax_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
          ROUND(ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate,ln_tax_precision), ln_precision), --Added by nprashar for bug # 13653889
          v_batch_id,
          ln_user_id,
          sysdate,
          c_tax_rec.tax_name,
          null,--kunkumar for forward porting to R12
          ln_login_id,
          for_dist_insertion_rec.match_status_flag , -- Bug 4863208
          'N',
          NULL,
          -- 'N',
          for_dist_insertion_rec.reversal_flag,  -- Bug 4863208
          for_dist_insertion_rec.program_application_id,
          for_dist_insertion_rec.program_id,
          for_dist_insertion_rec.program_update_date,
          for_dist_insertion_rec.accts_pay_code_combination_id,
          v_invoice_distribution_id,
          decode(v_assets_tracking_flag, 'Y', NULL, 0), /* Modified for bug 8406404 by vumaasha */
          --po_dist_id,12434160
			for_dist_insertion_rec.po_distribution_id, --12434160
          rcv_tran_id,
          for_dist_insertion_rec.matched_uom_lookup_code,
          ln_inv_line_num,
          for_dist_insertion_rec.org_id    -- Bug 4863208
          -- Bug 5401111. Added by Lakshmi Gopalsami
          ,decode(v_assets_tracking_flag,'N',
                  NULL,for_dist_insertion_rec.invoice_distribution_id)
/*Commented the account_type condition for bug#7008161 by JMEENA
       decode(lv_account_type, 'A',
              for_dist_insertion_rec.invoice_distribution_id,NULL)
            )
*/
          /* 5763527 */
          , ln_project_id
          , ln_task_id
          , lv_exp_type
          , ld_exp_item_date
          , ln_exp_organization_id
          , lv_project_accounting_context
          , lv_pa_addition_flag
          /* End 5763527 */
          -- Bug 7249100. Added by Lakshmi Gopalsami
          , lv_dist_class
           , for_dist_insertion_rec.dist_match_type --Added by nprashar for bug # 12832424
          );
Line: 5683

        Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_AP_MATCH_INV_TAXES ');
Line: 5692

          INSERT INTO JAI_AP_MATCH_INV_TAXES
          (
          tax_distribution_id,
          exchange_rate_variance,
          assets_tracking_flag,
          invoice_id,
          po_header_id,
          po_line_id,
          line_location_id,
          set_of_books_id,
          --org_id,
          exchange_rate,
          exchange_rate_type,
          exchange_date,
          currency_code,
          code_combination_id,
          last_update_login,
          creation_date,
          created_by,
          last_update_date,
          last_updated_by,
          acct_pay_code_combination_id,
          accounting_date,
          tax_id,
          tax_amount,
          base_amount,
          chart_of_accounts_id,
          distribution_line_number,
          --project_id,
          --task_id,
          po_distribution_id,  -- added  by bug#3038566
          parent_invoice_distribution_id,  -- added  by bug#3038566
          legal_entity_id -- added by rallamse bug#
          -- Added by Brathod, Bug# 4445989
          ,invoice_line_number
          ,INVOICE_DISTRIBUTION_ID
          ,PARENT_INVOICE_LINE_NUMBER
          ,RCV_TRANSACTION_ID
          ,LINE_TYPE_LOOKUP_CODE
          -- End Bug# 4445989
          /*5763527 */
          ,recoverable_flag
          /* End 5763527 */
          ,line_no  -- Bug 5553150, 5593895
          )
          VALUES
          (
          JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,
          null,--kunkumar for forward porting to R12
          v_assets_tracking_flag, -- 'N', bug # 2851123
          inv_id,
          cur_items_rec.po_header_id,
          cur_items_rec.po_line_id,
          cur_items_rec.line_location_id,
          cur_items_rec.set_of_books_id,
          --cur_items_rec.org_id,
          cur_items_rec.rate,
          cur_items_rec.rate_type,
          cur_items_rec.rate_date,
          cur_items_rec.currency_code,
          /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
                * c_tax_rec.tax_account_id and v_dist_code_combination_id
          */
          v_dist_code_combination_id,
          cur_items_rec.last_update_login,
          cur_items_rec.creation_date,
          cur_items_rec.created_by,
          cur_items_rec.last_update_date,
          cur_items_rec.last_updated_by,
          apccid,
          cur_items_rec.invoice_date,
          tax_lines1_rec.tax_id,
          /*commented out by eric for inclusive tax
          round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
          */
          ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision), --added by eric for inclusive tax
          ROUND(ROUND(tax_lines1_rec.tax_amount, ln_tax_precision),ln_precision),
          caid,
          v_distribution_no,
          --p_project_id,
          --p_task_id,
          po_dist_id, -- added  by bug#3038566
          for_dist_insertion_rec.invoice_distribution_id, -- added  by bug#3038566
          get_ven_info_rec.legal_entity_id,-- added by rallamse bug#
          --, ln_inv_line_num , commented out by eric for inclusvice tax
          --, v_invoice_distribution_id , commented out by eric for inclusvice tax
          --added by eric for inclusvice tax on 20-dec-2007,begin
          ---------------------------------------------------------------
          DECODE ( NVL(tax_lines1_rec.inc_tax_flag,'N')
                 , 'N',ln_inv_line_num
                 , 'Y',pn_invoice_line_number
                 )
          ,NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
          ---------------------------------------------------------------
          --added by eric for inclusvice tax on 20-dec-2007,end
          , pn_invoice_line_number
          , rcv_tran_id
          , lv_misc
          /* 5763527 */
          ,lv_modvat_flag
          /* End 5763527 */
          ,tax_lines1_rec.tax_line_no  -- --Bug 5553150, 5593895
          );
Line: 5803

        insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 5819

        Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_CMN_FA_INV_DIST_ALL ');
Line: 5820

        INSERT INTO JAI_CMN_FA_INV_DIST_ALL
        (
        invoice_id,
        invoice_distribution_id,
        set_of_books_id,
        batch_id,
        po_distribution_id,
        rcv_transaction_id,
        dist_code_combination_id,
        accounting_date,
        assets_addition_flag,
        assets_tracking_flag,
        distribution_line_number,
        line_type_lookup_code,
        amount,
        description,
        match_status_flag,
        quantity_invoiced
        )
        VALUES
        (
        inv_id,
        ap_invoice_distributions_s.CURRVAL,
        for_dist_insertion_rec.set_of_books_id,
        v_batch_id,
        for_dist_insertion_rec.po_distribution_id,
        rcv_tran_id,
        for_dist_insertion_rec.dist_code_combination_id,
        for_dist_insertion_rec.accounting_date,
        for_dist_insertion_rec.assets_addition_flag,
        v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
        v_distribution_no,
        'MISCELLANEOUS',
        round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
        c_tax_rec.tax_name,
        NULL,
        NULL
        );*/
Line: 5859

        end loop; --> for line in 1..ln_lines_to_insert; -- Brathod, 5763527
Line: 5864

      v_update_payment_schedule:=update_payment_schedule(cum_tax_amt); -- bug#3218978
Line: 5866

      UPDATE ap_invoices_all
      SET     invoice_amount       =  invoice_amount   + cum_tax_amt,
          approved_amount      =  approved_amount  + cum_tax_amt,
          pay_curr_invoice_amount =  pay_curr_invoice_amount + cum_tax_amt,
          amount_applicable_to_discount =  amount_applicable_to_discount + cum_tax_amt,
          payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
          -- bug#3624898
      WHERE  invoice_id = inv_id;
Line: 5879

        update ap_invoices_all
        set    base_amount = invoice_amount  * exchange_rate
        where  invoice_id = inv_id;
Line: 5887

      update_mrc_data; -- bug#3332988
Line: 5969

                              p_parent_dist_id      =>   for_dist_insertion_rec.invoice_distribution_id ,
                              p_tax_id              =>   r_tax_lines_rec.tax_id
                            ) ;
Line: 5975

        v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 6037

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 6055

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6056

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6068

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 6122

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6123

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6125

            v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 6130

        if nvl(for_dist_insertion_rec.invoice_price_variance, -1) <>-1 --Modified by kunkumar for bug#5593895
           and
           nvl(for_dist_insertion_rec.amount, -1) <> -1 then  --Modified by kunkumar for bug#5593895

          v_tax_variance_inv_cur :=
          v_tax_amount *
          (for_dist_insertion_rec.invoice_price_variance / for_dist_insertion_rec.amount);
Line: 6142

          v_price_var_accnt := for_dist_insertion_rec.price_var_code_combination_id;
Line: 6174

        ln_lines_to_insert := 1; -- Loop controller to insert more than one lines for partially recoverable tax lines in PO
Line: 6188

          ln_lines_to_insert := 1;
Line: 6194

          ln_lines_to_insert := 2;
Line: 6215

          ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 6229

        fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                        ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                        ',ln_nrec_tax_amt='||ln_nrec_tax_amt ||' ln_inclurec_tax_amt  '||ln_inclurec_tax_amt
                         );
Line: 6242

      Fnd_File.put_line(Fnd_File.LOG, 'ln_lines_to_insert ='|| ln_lines_to_insert);
Line: 6243

      for line in 1..ln_lines_to_insert
      loop
        --deleted by eric for inclusive tax on 04-Jan-2008,begin
        ---------------------------------------------------------------------------
        /*
        if line = 1 then

          v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 6257

          if for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES then
            v_assets_tracking_flag := jai_constants.YES;
Line: 6273

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6274

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6276

          v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 6317

            IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
              v_assets_tracking_flag := jai_constants.YES;
Line: 6333

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6334

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 6338

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 6384

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 6400

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6401

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6404

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 6427

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 6440

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6441

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6442

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 6455

          END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 6483

          Fnd_File.put_line(Fnd_File.LOG,'Before inserting into ap_invoice_lines_all for line no :'|| ln_inv_line_num );
Line: 6485

          INSERT INTO ap_invoice_lines_all
          (
            INVOICE_ID
          , LINE_NUMBER
          , LINE_TYPE_LOOKUP_CODE
          , DESCRIPTION
          , ORG_ID
          , MATCH_TYPE
    , DEFAULT_DIST_CCID ----Changes by nprashar for bug #6995437
          , ACCOUNTING_DATE
          , PERIOD_NAME
          , DEFERRED_ACCTG_FLAG
          , DEF_ACCTG_START_DATE
          , DEF_ACCTG_END_DATE
          , DEF_ACCTG_NUMBER_OF_PERIODS
          , DEF_ACCTG_PERIOD_TYPE
          , SET_OF_BOOKS_ID
          , AMOUNT
          , WFAPPROVAL_STATUS
          , CREATION_DATE
          , CREATED_BY
          , LAST_UPDATED_BY
          , LAST_UPDATE_DATE
          , LAST_UPDATE_LOGIN
          /* 5763527 */
          , project_id
          , task_id
          , expenditure_type
          , expenditure_item_date
          , expenditure_organization_id
          ,po_distribution_id --Added for bug#6780154
          )
          VALUES
          (
              inv_id
          , ln_inv_line_num
          , lv_misc
          , c_tax_rec.tax_name
          , v_org_id
          , lv_match_type
    , v_dist_code_combination_id
          , rec_max_ap_lines_all.accounting_date
          , rec_max_ap_lines_all.period_name
          , rec_max_ap_lines_all.deferred_acctg_flag
          , rec_max_ap_lines_all.def_acctg_start_date
          , rec_max_ap_lines_all.def_acctg_end_date
          , rec_max_ap_lines_all.def_acctg_number_of_periods
          , rec_max_ap_lines_all.def_acctg_period_type
          , rec_max_ap_lines_all.set_of_books_id
          , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) ----Added by nprashar for bug # 13653889
          , rec_max_ap_lines_all.wfapproval_status  -- Bug 4863208
          , sysdate
          , ln_user_id
          , ln_user_id
          , sysdate
          , ln_login_id
          /* 5763527 */
          , ln_project_id
          , ln_task_id
          , lv_exp_type
          , ld_exp_item_date
          , ln_exp_organization_id
          /* End 5763527 */
          ,po_dist_id --Added for bug#6780154
           );
Line: 6553

          'Before inserting into ap_invoice_distributions_all for distribution line no :' || v_distribution_no);
Line: 6563

          INSERT INTO ap_invoice_distributions_all
          (
          accounting_date,
          accrual_posted_flag,
          assets_addition_flag,
          assets_tracking_flag,
          cash_posted_flag,
          distribution_line_number,
          dist_code_combination_id,
          invoice_id,
          last_updated_by,
          last_update_date,
          line_type_lookup_code,
          period_name,
          set_of_books_id,
          amount,
          base_amount,
          batch_id,
          created_by,
          creation_date,
          description,
          exchange_rate_variance,
          last_update_login,
          match_status_flag,
          posted_flag,
          rate_var_code_combination_id,
          reversal_flag,
          program_application_id,
          program_id,
          program_update_date,
          accts_pay_code_combination_id,
          invoice_distribution_id,
          quantity_invoiced,
          po_distribution_id ,
          rcv_transaction_id,
          price_var_code_combination_id,
          invoice_price_variance,
          base_invoice_price_variance,
          matched_uom_lookup_code,
          INVOICE_LINE_NUMBER,
          org_id    -- Bug 4863208
          ,charge_applicable_to_dist_id -- Bug 5401111. Added by Lakshmi Gopalsami
            /* 5763527 */
            , project_id
            , task_id
            , expenditure_type
            , expenditure_item_date
            , expenditure_organization_id
            , project_accounting_context
            , pa_addition_flag
            -- Bug 7249100. Added by Lakshmi Gopalsami
            ,distribution_class
      ,dist_match_type --Added by nprashar for bug # 12832424
      )
          VALUES
          (
          for_dist_insertion_rec.accounting_date,
          'N', --for_dist_insertion_rec.accrual_posted_flag,
          for_dist_insertion_rec.assets_addition_flag,
          v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
          'N',
          v_distribution_no,
          /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
           * for_dist_insertion_rec.dist_code_combination_id
           * and v_dist_code_combination_id
           */
          v_dist_code_combination_id,
          inv_id,
          for_dist_insertion_rec.last_updated_by,
          for_dist_insertion_rec.last_update_date,
          lv_misc,
          for_dist_insertion_rec.period_name,
          for_dist_insertion_rec.set_of_books_id,
          ROUND(ROUND(v_tax_amount, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
          ROUND(ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_tax_precision),ln_precision),  --Added by nprashar for bug # 13653889
          v_batch_id,
          for_dist_insertion_rec.created_by,
          for_dist_insertion_rec.creation_date,
          c_tax_rec.tax_name,
          null,--kunkumar for forwad porting to R12
          for_dist_insertion_rec.last_update_login,
          for_dist_insertion_rec.match_status_flag , -- Bug 4863208
          'N',
          NULL,
          --'N',
          for_dist_insertion_rec.reversal_flag,  -- Bug 4863208
          for_dist_insertion_rec.program_application_id,
          for_dist_insertion_rec.program_id,
          for_dist_insertion_rec.program_update_date,
          for_dist_insertion_rec.accts_pay_code_combination_id,
          v_invoice_distribution_id,
          decode(v_assets_tracking_flag, 'Y', NULL, 0),/* Modified for bug 8406404 by vumaasha */
           --po_dist_id,12434160
			for_dist_insertion_rec.po_distribution_id, --12434160
          rcv_tran_id,
          v_price_var_accnt,
          v_tax_variance_inv_cur,
          v_tax_variance_fun_cur,
          for_dist_insertion_rec.matched_uom_lookup_code,
          ln_inv_line_num,
          for_dist_insertion_rec.org_id   -- bug 4863208
          -- Bug 5401111. Added by Lakshmi Gopalsami
          ,decode(v_assets_tracking_flag,'N',
                  NULL,for_dist_insertion_rec.invoice_distribution_id)
/*Commented the account_type condition for bug#7008161 by JMEENA
       decode(lv_account_type, 'A',
              for_dist_insertion_rec.invoice_distribution_id,NULL)
            )
*/
            /* 5763527 */
            , ln_project_id
            , ln_task_id
            , lv_exp_type
            , ld_exp_item_date
            , ln_exp_organization_id
            , lv_project_accounting_context
            , lv_pa_addition_flag
            -- Bug 7249100. Added by Lakshmi Gopalsami
            , lv_dist_class
         ,for_dist_insertion_rec.dist_match_type --Added by nprashar for bug # 12832424
);
Line: 6702

          Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_AP_MATCH_INV_TAXES ');
Line: 6703

          INSERT INTO JAI_AP_MATCH_INV_TAXES
          (
          tax_distribution_id,
          --shipment_line_id,
          exchange_rate_variance,
          assets_tracking_flag,
          invoice_id,
          po_header_id,
          po_line_id,
          line_location_id,
          set_of_books_id,
          --org_id,
          exchange_rate,
          exchange_rate_type,
          exchange_date,
          currency_code,
          code_combination_id,
          last_update_login,
          creation_date,
          created_by,
          last_update_date,
          last_updated_by,
          acct_pay_code_combination_id,
          accounting_date,
          tax_id,
          tax_amount,
          base_amount,
          chart_of_accounts_id,
          distribution_line_number,
          --project_id,
          --task_id,
          po_distribution_id,  -- added  by bug#3038566
          parent_invoice_distribution_id,  -- added  by bug#3038566
          legal_entity_id -- added by rallamse bug#
          -- Added by Brathod, Bug# 4445989
          ,invoice_line_number
          ,INVOICE_DISTRIBUTION_ID
          ,PARENT_INVOICE_LINE_NUMBER
          ,RCV_TRANSACTION_ID
          ,LINE_TYPE_LOOKUP_CODE
          -- End Bug# 4445989
          /* 5763527 */
          , recoverable_flag
          /* End 5763527 */
          ,line_no    -- Bug 5553150, 5593895
          )

          VALUES
          (
          JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,
          null,--kunkumar for forward porting to R12
          v_assets_tracking_flag, -- 'N', bug # 2851123
          inv_id,
          cur_items_rec.po_header_id, /* All references to r_cur_items_rec have been replaced by cur_items_rec */
          cur_items_rec.po_line_id,
          cur_items_rec.line_location_id,
          cur_items_rec.set_of_books_id,
          --cur_items_rec.org_id,
          cur_items_rec.rate,
          cur_items_rec.rate_type,
          cur_items_rec.rate_date,
          cur_items_rec.currency_code,
          /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
           * c_tax_rec.tax_account_id and v_dist_code_combination_id
           */
          v_dist_code_combination_id,
          cur_items_rec.last_update_login,
          cur_items_rec.creation_date,
          cur_items_rec.created_by,
          cur_items_rec.last_update_date,
          cur_items_rec.last_updated_by,
          apccid,
          cur_items_rec.invoice_date,
          r_tax_lines_rec.tax_id,
          /*commented out by eric for inclusive tax
          round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
          */
          ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
          ROUND(ROUND(r_tax_lines_rec.tax_amount, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
          caid,
          v_distribution_no,
          --p_project_id,
          --p_task_id,
          po_dist_id, -- added  by bug#3038566
          for_dist_insertion_rec.invoice_distribution_id, -- added  by bug#3038566
          get_ven_info_rec.legal_entity_id -- added by rallamse bug#
          --, ln_inv_line_num , commented out by eric for inclusvice tax
          --, v_invoice_distribution_id
          --added by Eric for inclusive tax on 20-dec-2007,begin
          --------------------------------------------------------------
          /*, DECODE ( NVL(r_tax_lines_rec.inc_tax_flag,'N')
                   , 'N',ln_inv_line_num
                   , 'Y',pn_invoice_line_number
                   )*/
          --Added by Qinglei on 10-Feb-2012 for bug#13589613 begin
          , DECODE ( NVL(r_tax_lines_rec.inc_tax_flag,'N')
                 , 'N',ln_inv_line_num
                 , 'Y',DECODE(lv_modvat_flag,'Y',ln_inv_line_num,'N',pn_invoice_line_number)
                 )
          --Added by Qinglei on 10-Feb-2012 for bug#13589613 end
          , NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
          --------------------------------------------------------------
          --added by Eric for inclusive tax on 20-dec-2007,end
          , pn_invoice_line_number
          , rcv_tran_id
          , lv_misc
          /* 5763527 */
          , lv_modvat_flag
          /* End 5763527 */
          ,r_tax_lines_rec.tax_line_no  -- Bug 5553150, 5593895
          );
Line: 6822

        insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 6840

        Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_CMN_FA_INV_DIST_ALL ');
Line: 6841

        INSERT INTO JAI_CMN_FA_INV_DIST_ALL
        (
        invoice_id,
        invoice_distribution_id,
        set_of_books_id,
        batch_id,
        po_distribution_id,
        rcv_transaction_id,
        dist_code_combination_id,
        accounting_date,
        assets_addition_flag,
        assets_tracking_flag,
        distribution_line_number,
        line_type_lookup_code,
        amount,
        description,
        match_status_flag,
        quantity_invoiced
        )
        VALUES
        (
        inv_id,
        ap_invoice_distributions_s.CURRVAL,
        for_dist_insertion_rec.set_of_books_id,
        v_batch_id,
        for_dist_insertion_rec.po_distribution_id,
        rcv_tran_id,
        for_dist_insertion_rec.dist_code_combination_id,
        for_dist_insertion_rec.accounting_date,
        for_dist_insertion_rec.assets_addition_flag,
        v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug # 2851123
        v_distribution_no,
        'MISCELLANEOUS',
        ROUND(v_tax_amount, ln_precision),
        c_tax_rec.tax_name,
        NULL,
        NULL
        );*/
Line: 6883

          end loop ;  --> for line in 1 to ln_lines_to_insert Brathod, 5763527
Line: 6892

   fnd_file.put_line(fnd_file.log ,'Start the Insertion of Inclusive Service tax lines for POT recoverable service amount is '||ln_inclurec_tax_amt);
Line: 6931

           v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 6942

                    Fnd_File.put_line(Fnd_File.LOG,'Before inserting Inclusive Service tax lines for POT into ap_invoice_lines_all for line no :'|| ln_inv_line_num ||'  tax amount =  '||lv_tax_line_amount);
Line: 6944

                    INSERT INTO ap_invoice_lines_all
                    (
                      INVOICE_ID
                    , LINE_NUMBER
                    , LINE_TYPE_LOOKUP_CODE
                    , DESCRIPTION
                    , ORG_ID
                    , MATCH_TYPE
                    , DEFAULT_DIST_CCID
                    , ACCOUNTING_DATE
                    , PERIOD_NAME
                    , DEFERRED_ACCTG_FLAG
                    , DEF_ACCTG_START_DATE
                    , DEF_ACCTG_END_DATE
                    , DEF_ACCTG_NUMBER_OF_PERIODS
                    , DEF_ACCTG_PERIOD_TYPE
                    , SET_OF_BOOKS_ID
                    , AMOUNT
                    , WFAPPROVAL_STATUS
                    , CREATION_DATE
                    , CREATED_BY
                    , LAST_UPDATED_BY
                    , LAST_UPDATE_DATE
                    , LAST_UPDATE_LOGIN
                    , project_id
                    , task_id
                    , expenditure_type
                    , expenditure_item_date
                    , expenditure_organization_id
                    ,po_distribution_id
                    )
                    VALUES
                    (
                     inv_id
                    , ln_inv_line_num
                    , lv_misc
                    , c_tax_rec.tax_name
                    , v_org_id
                    , lv_match_type
                    , v_dist_code_combination_id
                    , rec_max_ap_lines_all.accounting_date
                    , rec_max_ap_lines_all.period_name
                    , rec_max_ap_lines_all.deferred_acctg_flag
                    , rec_max_ap_lines_all.def_acctg_start_date
                    , rec_max_ap_lines_all.def_acctg_end_date
                    , rec_max_ap_lines_all.def_acctg_number_of_periods
                    , rec_max_ap_lines_all.def_acctg_period_type
                    , rec_max_ap_lines_all.set_of_books_id
                    , ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
                    , rec_max_ap_lines_all.wfapproval_status
                    , sysdate
                    , ln_user_id
                    , ln_user_id
                    , sysdate
                    , ln_login_id
                    , ln_project_id
                    , ln_task_id
                    , lv_exp_type
                    , ld_exp_item_date
                    , ln_exp_organization_id
                    ,po_dist_id
                     );
Line: 7009

                    'Before inserting  Inclusive Service tax lines for POT into ap_invoice_distributions_all for distribution line no :' || v_distribution_no);
Line: 7019

                    INSERT INTO ap_invoice_distributions_all
                    (
                    accounting_date,
                    accrual_posted_flag,
                    assets_addition_flag,
                    assets_tracking_flag,
                    cash_posted_flag,
                    distribution_line_number,
                    dist_code_combination_id,
                    invoice_id,
                    last_updated_by,
                    last_update_date,
                    line_type_lookup_code,
                    period_name,
                    set_of_books_id,
                    amount,
                    base_amount,
                    batch_id,
                    created_by,
                    creation_date,
                    description,
                    exchange_rate_variance,
                    last_update_login,
                    match_status_flag,
                    posted_flag,
                    rate_var_code_combination_id,
                    reversal_flag,
                    program_application_id,
                    program_id,
                    program_update_date,
                    accts_pay_code_combination_id,
                    invoice_distribution_id,
                    quantity_invoiced,
                    po_distribution_id ,
                    rcv_transaction_id,
                    price_var_code_combination_id,
                    invoice_price_variance,
                    base_invoice_price_variance,
                    matched_uom_lookup_code,
                    INVOICE_LINE_NUMBER,
                    org_id
                    ,charge_applicable_to_dist_id
                      , project_id
                      , task_id
                      , expenditure_type
                      , expenditure_item_date
                      , expenditure_organization_id
                      , project_accounting_context
                      , pa_addition_flag
                      ,distribution_class
                  , dist_match_type --Added by nprashar for bug # 12832424
                )
                    VALUES
                    (
                    for_dist_insertion_rec.accounting_date,
                    'N',
                    for_dist_insertion_rec.assets_addition_flag,
                    v_assets_tracking_flag,
                    'N',
                    v_distribution_no,
                    v_dist_code_combination_id,
                    inv_id,
                    for_dist_insertion_rec.last_updated_by,
                    for_dist_insertion_rec.last_update_date,
                    lv_misc,
                    for_dist_insertion_rec.period_name,
                    for_dist_insertion_rec.set_of_books_id,
                    ROUND(ROUND(lv_tax_line_amount,ln_tax_precision), ln_precision), --Added by nprashar for bug # 13653889
                    ROUND(ROUND(lv_tax_line_amount * for_dist_insertion_rec.exchange_rate, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
                    v_batch_id,
                    for_dist_insertion_rec.created_by,
                    for_dist_insertion_rec.creation_date,
                    c_tax_rec.tax_name,
                    null,
                    for_dist_insertion_rec.last_update_login,
                    for_dist_insertion_rec.match_status_flag ,
                    'N',
                    NULL,
                    for_dist_insertion_rec.reversal_flag,
                    for_dist_insertion_rec.program_application_id,
                    for_dist_insertion_rec.program_id,
                    for_dist_insertion_rec.program_update_date,
                    for_dist_insertion_rec.accts_pay_code_combination_id,
                    v_invoice_distribution_id,
                    decode(v_assets_tracking_flag, 'Y', NULL, 0),
                     --po_dist_id,12434160
			for_dist_insertion_rec.po_distribution_id, --12434160
                    rcv_tran_id,
                    v_price_var_accnt,
                    v_tax_variance_inv_cur,
                    v_tax_variance_fun_cur,
                    for_dist_insertion_rec.matched_uom_lookup_code,
                    ln_inv_line_num,
                    for_dist_insertion_rec.org_id
                    ,decode(v_assets_tracking_flag,'N',
                            NULL,for_dist_insertion_rec.invoice_distribution_id)
                      , ln_project_id
                      , ln_task_id
                      , lv_exp_type
                      , ld_exp_item_date
                      , ln_exp_organization_id
                      , lv_project_accounting_context
                      , lv_pa_addition_flag

                      , lv_dist_class
                  ,for_dist_insertion_rec.dist_match_type --Added by nprashar for bug # 12832424

                    );
Line: 7130

           UPDATE JAI_AP_MATCH_INV_TAXES jat
           SET    jat.invoice_distribution_id = v_invoice_distribution_id
           WHERE  jat.invoice_id = inv_id
           AND    jat.po_header_id = cur_items_rec.po_header_id
           AND    jat.po_line_id = cur_items_rec.po_line_id
           AND    jat.line_location_id = cur_items_rec.line_location_id
           AND    jat.set_of_books_id = cur_items_rec.set_of_books_id
           AND    jat.line_no = r_tax_lines_rec.tax_line_no
           AND    jat.tax_id = r_tax_lines_rec.tax_id
           AND    jat.recoverable_flag = decode(inclu_Serv_line,1,'Y',2,'N','N');
Line: 7226

    SELECT vendor_id, vendor_site_id, org_id, cancelled_date -- cancelled date added by bug#3206083
         ,set_of_books_id -- added for bug#3354932
         ,legal_entity_id -- added rallamse for bug#
     ,invoice_num -- added by pramasub FP
    FROM   ap_invoices_all
    WHERE  invoice_id = v_invoice_id;
Line: 7234

    SELECT currency_code
    FROM   gl_sets_of_books
    WHERE  set_of_books_id = p_sob;
Line: 7239

    SELECT pay_on_code, pay_on_receipt_summary_code
    FROM   po_vendor_sites_all
    WHERE  vendor_id = ven_id
    AND    vendor_site_id = ven_site_id
    AND    NVL(org_id, 0) = NVL(v_org_id, 0);
Line: 7247

     SELECT pod.po_header_id,
      pod.po_line_id,
      pod.line_location_id,
      pod.set_of_books_id,
      pod.org_id,
      poh.rate,
      poh.rate_type,
      pod.rate_date,
      poh.currency_code,
      api.last_update_login,
      apd.dist_code_combination_id,
      api.creation_date,
      api.created_by,
      api.last_update_date,
      api.last_updated_by,
      api.invoice_date
    FROM  ap_invoices_all api,
      ap_invoice_distributions_all apd,
      po_distributions_all pod,
      po_headers_all poh
     WHERE  api.invoice_id               = inv_id
     AND    api.invoice_id               = apd.invoice_id
     AND    pod.po_header_id             = poh.po_header_id
     AND    apd.po_distribution_id       = pod.po_distribution_id
     AND    apd.invoice_line_number      = line_no
     AND    apd.distribution_line_number = cpn_max_dist_line_num;
Line: 7280

     SELECT min(distribution_line_number)
     FROM   ap_invoice_distributions_all apid
     WHERE  apid.invoice_id = cpn_invoice_id
     AND    apid.invoice_line_number = cpn_invoice_line_number;
Line: 7288

      SELECT max (line_number)
      FROM   ap_invoice_lines_all
      WHERE  invoice_id = inv_id;
Line: 7305

      SELECT   accounting_date
              ,period_name
              ,deferred_acctg_flag
              ,def_acctg_start_date
              ,def_acctg_end_date
              ,def_acctg_number_of_periods
              ,def_acctg_period_type
              ,set_of_books_id
        , wfapproval_status
      FROM    ap_invoice_lines_all
      WHERE   invoice_id = inv_id
      AND     line_number = cpn_max_line_num;
Line: 7323

     SELECT tax_name, tax_account_id, mod_cr_percentage, tax_type,
   NVL(rounding_factor,0) rounding_factor /* added by vumaasha for bug 6761425 */
     -- bug 3051832, mod_cr_percentage added by aparajita on 10/10/2002 for bug # 2616100
     FROM   JAI_CMN_TAXES_ALL
     WHERE  tax_id = t_id;
Line: 7330

      SELECT batch_id,source
      FROM   ap_invoices_all
      WHERE  invoice_id = inv_id;
Line: 7335

     SELECT org_id, vendor_id, NVL(exchange_rate, 1) exchange_rate, invoice_currency_code
     FROM   ap_invoices_all
     WHERE  invoice_id = inv_id;
Line: 7340

     SELECT accts_pay_code_combination_id
     FROM   ap_system_parameters_all
     WHERE  NVL(org_id, 0) = NVL(orgn_id, 0);
Line: 7346

    CURSOR for_dist_insertion(inv_id NUMBER, inv_line_num NUMBER, cpn_min_dist_line_num NUMBER) IS  /* Picks up dtls from std apps inserted line */
     SELECT a.accounting_date,a.accrual_posted_flag,
                a.assets_addition_flag,a.assets_tracking_flag,
    a.cash_posted_flag,a.dist_code_combination_id,
    a.last_updated_by,a.last_update_date,
    a.line_type_lookup_code,a.period_name,
    a.set_of_books_id,a.amount,a.base_amount,a.batch_id,
    a.created_by,a.creation_date,a.description,
    a.accts_pay_code_combination_id,
    a.exchange_rate_variance,
    a.last_update_login,a.match_status_flag,
    a.posted_flag, a.rate_var_code_combination_id,
    a.reversal_flag,a.vat_code,a.exchange_date,
    a.exchange_rate, a.exchange_rate_type,
    a.price_adjustment_flag,a.program_application_id,
    a.program_id, a.program_update_date,
    a.global_attribute1, a.global_attribute2, a.global_attribute3,
    a.po_distribution_id,  a.project_id,a.task_id,a.expenditure_type,
    a.expenditure_item_date,a.expenditure_organization_id,
    quantity_invoiced,
    invoice_distribution_id,
    matched_uom_lookup_code,
    org_id -- Bug 4863208
    , project_accounting_context    /* 5763527 */
    , pa_addition_flag    /* 5763527 */
  , asset_book_type_code /* 8406404 */
     FROM   ap_invoice_distributions_all a
     WHERE  invoice_id               = inv_id
     AND    invoice_line_number      = inv_line_num
     AND    distribution_line_number = cpn_min_dist_line_num;
Line: 7381

   SELECT
     jrl.tax_amount tax_amount
   , jrl.tax_id
   , jrl.currency
   , jrl.tax_type tax_type
   , jrl.modvat_flag
   , jrl.tax_line_no --Added by kunkumar for bug#5593895
   , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
   FROM
     JAI_RCV_LINE_TAXES jrl
   , rcv_shipment_lines rsl
   , rcv_transactions   rt
   , jai_cmn_taxes_all   jcta
   WHERE jrl.shipment_line_id = rsl.shipment_line_id
     AND rt.shipment_line_id = rsl.shipment_line_id
     AND rt.transaction_id = tran_id
     AND jrl.vendor_id = ven_id
     AND jcta.tax_id   = jrl.tax_id  --Added by Eric for Inclusive Tax
     AND NVL(upper(jrl.tax_type),'TDS') NOT IN ('TDS',
                                               'CVD',
                        jai_constants.tax_type_add_cvd ,     -- Date 31/10/2006 Bug 5228046 added by SACSETHI
                 'CUSTOMS',
                                                jai_constants.tax_type_customs_edu_cess,
                                                jai_constants.tax_type_cvd_edu_cess)
    -- GROUP BY jrl.tax_id,jrl.currency,jrl.tax_type, jrl.modvat_flag  -- commented bug#3038566
    order by  tax_line_no -- added bug#3038566
    ;
Line: 7419

  SELECT * FROM( --PRAMASUB FP
      SELECT
        jpt.tax_id
      , jpt.tax_amount
      , jpt.currency
      , jpt.tax_target_amount
      , jpt.modvat_flag
      , jpt.tax_type
      , jpt.tax_line_no --Added by kunkumar for bug#5593895
      , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
      FROM
        jai_po_taxes          jpt
      , jai_cmn_taxes_all     jcta           --Added by Eric for Inclusive Tax
      -- WHERE line_focus_id = focus_id
      WHERE jpt.line_location_id = p_line_location_id   -- 3096578
        AND jcta.tax_id   = jpt.tax_id                  --Added by Eric for Inclusive Tax
        AND NVL(upper(jpt.tax_type), 'A') NOT IN ('TDS',
                                            'CVD',
               jai_constants.tax_type_add_cvd ,     -- Date 31/10/2006 Bug 5228046 added by SACSETHI
              'CUSTOMS',
                                            jai_constants.tax_type_customs_edu_cess,
                                            jai_constants.tax_type_cvd_edu_cess
             )
        AND NVL(jpt.vendor_id, 0) = vend_id
        AND cp_source <> 'ASBN'
      --ORDER BY  tax_line_no; -- added bug#3038566  --pramasub FP  | commented and order by is moved to end of the qry
Line: 7447

  SELECT
    taxes.tax_id
  , taxes.TAX_AMT       tax_amount
  , taxes.CURRENCY_CODE currency
  , taxes.TAX_AMT       tax_target_amount
  , taxes.modvat_flag
  , taxes.tax_type
  , taxes.tax_line_no -- added, Harshita for Bug 5553150
  , NVL(jcta.inclusive_tax_flag,'N') inc_tax_flag --Added by Eric for Inclusive Tax
  FROM
    jai_cmn_lines lines
  , jai_cmn_document_Taxes taxes
  , jai_cmn_taxes_all     jcta           --Added by Eric for Inclusive Tax
  WHERE lines.cmn_line_id = taxes.source_doc_line_id
    AND taxes.source_doc_type = 'ASBN'
    AND lines.po_line_location_id = p_line_location_id
    AND lines.shipment_number = cp_shipment_num
    AND NVL(taxes.vendor_id, 0) = vend_id
    AND jcta.tax_id   = taxes.tax_id   --Added by Eric for Inclusive Tax
    AND cp_source = 'ASBN')
  ORDER BY  tax_line_no; --pramasub FP end
Line: 7470

      SELECT 1
      FROM ap_invoice_distributions_all
      WHERE invoice_id = p_invoice_id
      AND reversal_flag = 'Y'
      AND rownum = 1; -- Added by avallabh for bug 4926094 on 03-Feb-2006
Line: 7477

    SELECT NVL(DISTRIBUTION_LINE_NUMBER,1) FROM
     AP_INVOICE_DISTRIBUTIONS_ALL WHERE
     INVOICE_ID = inv_id
     AND DISTRIBUTION_LINE_NUMBER =
       (SELECT MAX(DISTRIBUTION_LINE_NUMBER)
        FROM AP_INVOICE_DISTRIBUTIONS_ALL
        WHERE INVOICE_ID = inv_id)
        FOR UPDATE OF DISTRIBUTION_LINE_NUMBER;
Line: 7487

    select ap_invoice_distributions_s.nextval
    from   dual;
Line: 7493

  select precision
  from   fnd_currencies
  where  currency_code = cp_currency_code;
Line: 7508

  for_dist_insertion_rec              for_dist_insertion%ROWTYPE;
Line: 7537

  v_update_payment_schedule           boolean; -- bug#3206083
Line: 7554

  ln_lines_to_insert                  number;
Line: 7573

    select attribute2 excise_costing_flag
    from   jai_rcv_transactions jrcvt
    where  jrcvt.parent_transaction_id = cp_rcv_transaction_id
  and    jrcvt.organization_id  = cp_organization_id --Added by Bgowrava for Bug#7503308
    and    jrcvt.shipment_header_id = cp_shipment_header_id
    and    jrcvt.transaction_type = cp_txn_type --'DELIVER'     --Modified by Bgowrava for Bug#7503308
    and    jrcvt.attribute1= cp_attribute1 ; --'CENVAT_COSTED_FLAG';    --Modified by Bgowrava for Bug#7503308
Line: 7584

     select po_line_id, organization_id
     from   rcv_transactions
     where  transaction_id = p_transaction_id;
Line: 7589

     select item_id
     from   po_lines_all
     where  po_line_id = p_po_line_id;
Line: 7601

     select regime_id
     from   JAI_RGM_DEFINITIONS
     where  regime_code = cp_regime_code ; /* SERVICE or VAT */
Line: 7606

    select attribute_code tax_type
    from   JAI_RGM_REGISTRATIONS
    where  regime_id = cp_regime_id
    and    registration_type = jai_constants.regn_type_tax_types  /* TAX_TYPES */
    and    attribute_code = cp_tax_type;
Line: 7615

  select NVL(rounding_factor,0) -- for bug 13954092 by anupgupt
  from jai_cmn_taxes_all
  where tax_id = cp_tax_id  ;
Line: 7638

  FUNCTION update_payment_schedule (p_total_tax NUMBER) RETURN boolean IS -- bug # 3218978

    v_total_tax_in_payment            number;
Line: 7647

    select  sum(gross_amount)
    from    ap_payment_schedules_all
    where   invoice_id = inv_id;
Line: 7653

  Fnd_File.put_line(Fnd_File.LOG, 'Start of function  update_payment_schedule');
Line: 7660

  Fnd_File.put_line(Fnd_File.LOG, 'Cannot update payment schedule, total payment amount :'
                                    || to_char(v_total_payment_amt));
Line: 7671

    select  gross_amount,
        payment_num
    from    ap_payment_schedules_all
    where   invoice_id = inv_id
    order by payment_num
    )
    loop

      v_tax_installment := 0 ;
Line: 7686

      update ap_payment_schedules_all
      set    gross_amount        = gross_amount          + v_tax_installment,
         amount_remaining      = amount_remaining      + v_tax_installment,
         inv_curr_gross_amount = inv_curr_gross_amount + v_tax_installment,
            payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
            -- bug#3624898
      where  invoice_id = inv_id
      and    payment_num = v_payment_num;
Line: 7706

      update ap_payment_schedules_all
      set    gross_amount        = gross_amount          + v_diff_tax_amount,
         amount_remaining      = amount_remaining      + v_diff_tax_amount,
         inv_curr_gross_amount = inv_curr_gross_amount + v_diff_tax_amount,
            payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
            -- bug#3624898
      where  invoice_id = inv_id
      and    payment_num = v_payment_num;
Line: 7720

      Fnd_File.put_line(Fnd_File.LOG, 'exception from function  update_payment_schedule');
Line: 7724

  end update_payment_schedule; -- bug # 3218978
Line: 7727

  procedure insert_mrc_data (p_invoice_distribution_id number) is
    -- Vijay Shankar for bug#3461030
    v_mrc_string VARCHAR2(10000);
Line: 7733

      p_operation_mode    => ''INSERT'',
      p_table_name        => ''AP_INVOICE_DISTRIBUTIONS_ALL'',
      p_key_value         => :a,
      p_key_value_list    => NULL,
      p_calling_sequence  =>
      ''India Local Tax line as Miscellaneous distribution line (jai_ap_match_tax_pkg.process_batch_record procedure)''
       ); END;';
Line: 7750

      FND_FILE.put_line(FND_FILE.log, '*** MRC API is not existing(insert)');
Line: 7752

      FND_FILE.put_line(FND_FILE.log, 'MRC API exists and different err(insert)->'||SQLERRM);
Line: 7757

  procedure update_mrc_data is
    -- Vijay Shankar for bug#3461030
    v_mrc_string VARCHAR2(10000);
Line: 7764

      p_operation_mode    => ''UPDATE'',
      p_table_name        => ''AP_INVOICES_ALL'',
      p_key_value         => :a,
      p_key_value_list    => NULL,
      p_calling_sequence  =>
      ''India Local Tax amount added to invoice header (jai_ap_match_tax_pkg.process_batch_record procedure)''
       ); END;';
Line: 7781

      FND_FILE.put_line(FND_FILE.log, '*** MRC API is not existing(update)');
Line: 7783

      FND_FILE.put_line(FND_FILE.log, 'MRC API exists and different err(update)->'||SQLERRM);
Line: 7802

                       In the insertion to ap_invoice_distributions_all, populated the
                       org id that is supplied as a parameter to this program. Without this
                       the org id gets defaulted from the session variables and may go wrong.

3.       09/10/2002    Aparajita for bug # 2483164 Version# 615.1
                       Populate the po distribution id and rcv_transactions id for the tax
                       lines for backtracking tax to purchasing side.

                       Deleted the code for supplementary invoices as this is only for pay on
                       receipt. This code was here as this procedure was extracted from
                       distribution matching.

4.       03/11/2002    Aparajita for bug # 2567799 Version# 615.2
                       Added a function apportion_tax_pay_on_rect_f and using it to apportion the
                       tax amount. This is useful when there are multiple distributions for the PO.


5.       05/11/2002    Aparajita for bug # 2506453, Version# 615.3
                       Changed the cursor definition get_tax_ln_no, to look into the receipt tax
                       instead of the po tax table for getting the line number. This was running
                       into error when no taxes exist at po and have been added at receipt.

                       Also Changed the cursor definition get_sales_tax_dtl to fetch on the
                       basis of tax id instead of name.

6.       15/11/2002    cbabu for bug # 2665306, Version# 615.4
                       Added the code when rcv_tran_id is NULL.

                       the code that is added was copied from jai_ap_match_tax_pkg.process_online code with
                       p_rematch = 'PO_MATCHING' Now the taxes for ERS invoice will be defaulted
                       here and header amount is updated if the invoice is created for the first
                       time. If any reversal is happened for distribution lines, then invoice
                       header amount is not modified.

7.       02/12/2002    Aparajita for bug # 2689834 Version # 615.5
                       In the insertion to ap_invoice_distributions_all, populated the org id
                       that is supplied as a parameter to this program. Without this the org id
                       gets defaulted from the session variables and may go wrong.

                       Bug # 2428264 had addressed this issue before but that was only for
                       pay on receipt scenario. Bug # 2665306  added the PO setup where the
                       rcv_transaction id goes as blank. In this scenario, the org id was
                       not getting populated, have done the same changes for that scenario.

8.       16/12/2002    cbabu for bug# 2713601, FileVersion # 615.6
                       AP_PAYMENTS_SCHEDULES_ALL is not getting updated with the tax amount
                       as soon as AP_INVOICES_ALL isgetting updated. Update statement for
                       ap_payment_schedules_all is written for scenario where rcv_transaction_id
                       in ap_invoice_distributions_all is NULL. Thsi happens in PO matching
                       setup for ERS invoices.

9.      20/12/2002    Aparajita for bug # 2689826 Version # 615.7

                       The distribution line numbers were getting  skipped every time the tax
                       is inserted for a 2nd item line onwards. This was happening because the
                       distribution line number is calulated by taking the max distribution
                       line number and also the no of tax lines which have a shipment line id
                       less than corresponding shipment line id for the same shipment header.
                       This logic is not required as the distribution line number should always
                       be the next number. commented the cursor count_tax_lines.


10.      14/03/2003    Aparajita for bug # 2841363. Version # 615.8
                       Taxes having 0 amount were not considered, changed the cursor
                       from_line_location_taxes to conside such tax lines for propagation into AP.

11.      15/03/2003    Aparajita for bug # 2851123. Version # 615.9
                       The assets_tracking_flag in ap_invoice_distributions_all,
                       JAI_AP_MATCH_INV_TAXES and JAI_CMN_FA_INV_DIST_ALL should be set as 'N'
                       if the tax line against which the line is being generated is excise type of
                       tax and is modvatable. By default this flag gets the value from the
                       corresponding item line for which the tax is attached.

                       Introduced a variable v_assets_tracking_flag.
                       Modified the following cursors to fetch modvat_flag.
                       - from_line_location_taxes
                       - tax_lines1_cur

12.      13/04/2003    bug#2799217. Version # 615.10
                       line focus id from JAI_PO_TAXES instead of
                       JAI_PO_LINE_LOCATIONS, changed cursor get_focus_id.

                       This was done as in some cases data does not exist in
                       JAI_PO_LINE_LOCATIONS but exists in JAI_PO_TAXES.
                       The root cause of this will be looked into separately.

13      17/07/2003     Aparajita for bug#3038566, version # 616.1

                       Introduced a new function getSTformsTaxBaseAmount to calculate the
                       tax base amount to be populated into the table ja_in_po_st_forms_dtl.
                       Calculating the tax base amount from the tax amount and percentage was
                       giving problem because of rounding.

14     14/08/2003      kpvs for bug # 3051832, version # 616.2
                       OPM code merged into this version of the procedure.
                       Changes made to pull in the OPM code fixes done for bugs 2616100 and 2616107
                       Used 'v_opm_flag' to check for the process enabled flag of the
                       organization.


15.    17/08/2003     Aparajita for bug#3094025. Generic for bug#3054140. version # 616.3
                      There may be taxes at receipt without having any tax at PO.
                      For such cases, the st forms population has to cater.
                      Precedences are not available, so calculation of tax base is not possible.
                      Added the backward calcultion for such cases.

                      Changes in the function getSTformsTaxBaseAmount.
                      Introduced two new parameters tax amount and rate to calculate backward
                      in case PO tax details are not found. It was observed that the function
                      getSTformsTaxBaseAmount was always considering the precedence
                      0 amount irrespective of the valus of the precendences.
                      This has been corrected.

16.   22/08/2003    Aparajita for bug# 2828928. Version # 616.4 .
                      Added the condition to consider null vendor id
                      and modvat = 'N' taxes in the following
                      cursor. Also added the code to consider mod_cr_percentage.
                       - C_third_party_tax cursor definition modified.


17.     27/08/2003    Aparajita for bug#3116659. Version#616.5
                      Projects clean up.

18.   27/08/2003    Vijay Shankar for bug# 3096578. Version # 616.6
                       All taxes are not picked from PO Shipment if the taxes are selected based on
                       line_focus_id as there are different line_focus_id's for same
                       line_location_id which is wrong. Also we should use line_location_id
                       to fetch the taxes instead of line_focus_id as line_location_id
                       refers to the PO Shipments in which taxes are attached and line_focus_id
                       is just a unique key for JAI_PO_LINE_LOCATIONS table.
                       Modified the cursor from_line_locations_taxes to fetch the taxes
                       based on line_location_id

            Bug# 3114596, Version same as bug# 3096578 (616.6)
                       When DEBIT MEMO created for RTS transaction, then if Supplier setup has
                       PO Matching, then dist_match_type is coming as ITEM_TO_RECEIPT
                       but rcv_transaction_id is not getting populated because of which taxes
                       are not getting defaulted by giving an error which is written in default
                       ELSIf. Code is modified to take the route of PO matching
                       if rcv_transaction_id is not populated for DEBIT MEMO
                       i.e source = 'RTS'


19      16/10/2003    Aparajita for bug#3193849. Version#616.7

                      Removed the ST forms functionality from here as ST forms population is now being
                      handled through a concurrent.

20    28/10/2003    Aparajita for bug#3206083. Version#616.7

                      If the base invoice is cancelled, there is no need to bring the tax lines.
                      Added code to check the cancelled date and if populated, returning from the proc.

21    28/10/2003    Aparajita for bug#3218978. Version#616.7

                      Tax amount is apportioned properly between the installments.Differential
                      tax amounts if any because of rounding is added to the last installment.

                      Code is not reading anything from terms master, instead based on
                      the distribution of the amount before tax, tax amount is distributed.
                      coded in in line function update_payment_schedule.

22      23/12/2003    Aparajita for bug#3306090. Version 618.1
                      Tax amount was calculated wrongly when tax currency is different from
                      invoice currency. This was not handled in the function
                      apportion_tax_pay_on_rect_f. Added code for the same.

29    07/01/2003    Aparajita for bug#3354932. Version#618.2
                    When the invoice is in foreign currency, for ERS invoice, base_amount in
                    ap_invoices_all should be updated to include the loc taxes as otherwise
                    it is creating wrong accounting entries.

                    This update needs to be done only for ERS invoices as other cases
                    localization does not update the
                    invoice header amounts. p_rematch = 'PAY_ON_RECEIPT'.
                    Additionally this should be done only when the invoice currency
                    is not the functional currency.

30      27/01/2004   Aparajita for bug#3332988. Version#618.3

                     Call to AP_MRC_ENGINE_PKG.Maintain_MRC_Data for MRC functionality.

                     This call is made after every distribution line is inserted.
                     This has been implemented as a in line procedure insert_mrc_data.
                     The procedure is called after every insert into
                     ap_invoice_distributions_all.

                    Procedure update_mrc_data has been created and invoked whereever
                    invoice header is being updated.


31     03/02/2004   Aparajita for bug#3015112. Version#618.4
                    Removed the OPM costing functionality. This was updating quantity invoiced
                    and unit price for miscellaneous lines and this was creating problem
                    for subsequent transactions against the same PO / Receipt.

                    The changes removed were brought in for bug#3051828.

32     24/02/2004   Vijay Shankar for bug#3461030. Version#618.5
                     Modified the MRC call to be dynamic by using EXECUTE IMMEDIATE.
                     This is done to take care of Ct.s who are on base version less than 11.5.7

33    25/02/2004   Aparajita for bug#3315162. Version#618.6

                     Base application gives problem while reversing localization tax lines.
                     This was analyzed with base and found out that the problem was because of
                     null value for matched_uom_lookup_code field of the miscellaneous
                     tax distribution.  Further null value of quantity also creats problem as
                     the billed quantity on PO/receipt gets updated to null when the loc taxes
                     does get reversed with value populated for UOM.

                     Changes have been made to populate matched_uom_lookup_code same
                     as item line and quantity as 0.

34    30/03/2004   Aparajita for bug#3448803. Version#619.1.
                     track as asset flag for the distribution for tax line in payable invoice now
                     considers partially recoverable taxes. The logic is now as follows,

                     - default value of this flag is same as that of the corresponding item line.
                     - if the corresponding tax is modvatable to teh extent of 100% then the value
                     of the flag is over written to 'N' irrespective of the value of the
                     corresponding base item line.

35      15/05/2004   Aparajita for bug#3624898. Version#619.2
                     Whenever the tax lines are populated, if the invoice is already fully paid
                     the paid amount is displayed wrongly to be including the tax amount.

                     Fixed the problem by updating the payment_status_flag in ap_invoices)_all and
                     ap_payment_shedules_all to 'P' in case it was Y.

36    08/07/2004     Aparajita for bug#3752887. Version#115.1, Clean up.

                     Function apportion_tax_pay_on_rect_f was considering the quantity
                     from rcv_transactions and  taxes from JAI_RCV_LINE_TAXES.
                     This fails when there have been corrections as taxes are modified as
                     per the corrected quantity.

                     Cleaned the entire logic of apportioning of tax from PO to AP.
                     Used the function jai_ap_interface_pkg.get_apportion_factor which has been
                     designed new to find out the factor that needs to be applied. All Logic
                     of apportioning is now in the external function and removed a lot of code
                     from here which was trying to do the same here at more than one place.
                     Also rmoved the in line function function apportion_tax_pay_on_rect_f.

                     Function jai_ap_interface_pkg.get_apportion_factor was designed for purchase register report
                     through bug#3633078. Added the procedure here also in the patch as it is not
                     required to have the report to have the function. So no dependency.

                     tax invoice price variance :=
                     tax amount * (base item line variance amount / base item line amount).


37. 01/11/2003       ssumaith - bug# 3127834 - file version 115.2

                     currency precision was not used for rounding the tax amounts when inserting / updating
                     records into  ap_invoices_all , ap_invoices_distributions_all , ap_payment_Schedules_all
                     tables. As a result the invoice was going into automatic hold because the invoice amount
                     does not equal sum of distributions amount.

                     This has been resolved in the bug by getting the currency precision for the invoice
                     currency from FND_CURRENCIES table and using it in all the inserts and updates which
                     involve the tax amounts.

38. 21/01/2005       Aparajita - Bug#4078546 Service Tax. Version#115.3

                    4106633    Base Bug For Education Cess on Excise, CVD and Customs.
                    4059774    Base Bug For Service Tax Regime Implementation.
                    4078546    Modification in receive and rtv accounting for service tax


                     Service Tax interim account needs to be populated as the charge account,
                     if the following condition is true.

                     Case of PO Matching or Accrue on receipt is No.


39. 11/02/2005      Aparajita - Bug#4177452. Version#115.4

                    Charge account for non-recoverable taxes were going was null.
                    This was because of the default assignment of,
                      v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 8104

                    All inserts into JAI_AP_MATCH_INV_TAXES table now include legal_entity_id as
                    part of R12 LE Initiative. The legal_entity_id is selected from ap_invoices_all in
                    cursor get_ven_info.

44  23-Jun-2005     Brathod for Bug# 4445989, Version 120.0
                    Issue: Impact uptake on IL Product for AP_INVOICE_LINES_ALL Uptake
                    Resolution:- Code modified to consider ap_invoice_lines_all instead of
                    ap_invoice_distributions_all.
                    Following changes done
                      -  Code refering to ap_invoice_distributions_all modified to consider
                         invoice_id and invoice_line_number as unique combination
                      -  invoice line record is created in ap_invoice_lines_all where ever previously
                         distribution was created
                      -  Obsoleted JAI_CMN_FA_INV_DIST_ALL
                      -  Modified structure of JAI_AP_MATCH_INV_TAXES to incorporate invoice lines
                         and also the fields from JAI_CMN_FA_INV_DIST_ALL
                      -  Code modfied to insert appropriate fields in JAI_AP_MATCH_INV_TAXES

45. 06-Jul-2005       Sanjikum for Bug#4474501
                      1) Commented the cursor - for_acct_id and corresponding open/fetch/close for the same.
                      2) Commented the call to function - jai_general_pkg.get_accounting_method

46.  08-Dec-2005  Bug 4863208. Added by Lakshmi Gopalsami Version 120.2
                          (1) Added wfapproval_Status in insert to ap_invoice_lines_all
        (2) Derived the org_id for inserting into ap_invoice_distributions_all
             This is added in CURSOR for_dist_insertion
                          (3) Added values for match_status_flag, reversal_flag in insert

47. 04-Feb-2008   JMEENA for bug#6780154

          Modify the insert statement of ap_invoice_lines_all to populate the po_distribution_id.


48.  21-Feb-2008  JMEENA for bug#6835548
          Changed the value of lv_match_type from NOT MATCHED to NOT_MATCHED.

49.  19-May-2008    JMEENA for bug#7008161
        Modified the insert statement of ap_invoice_distributions_all to populate the charge_applicable_to_dist_id
        based on v_assets_tracking_flag and removed the condition of account_type.


Future Dependencies For the release Of this Object:-
==================================================
(Please add a row in the section below only if your bug introduces a dependency due to spec change/
A new call to a object/A datamodel change )

------------------------------------------------------------------------------------------------------
Version       Bug       Dependencies (including other objects like files if any)
-------------------------------------------------------------------------------------------------------
616.1         3038566   ALTER Script  JAI_AP_MATCH_INV_TAXES Table is altered.

115.1         3752887   Dependency on function jai_ap_interface_pkg.get_apportion_factor which is also added
                        in this patch. So no pre - req.

115.3         4146708   Base Bug for Service + Cess Release.

                        Variable usage of jai_constants package.

                        Call to following,
                        jai_general_pkg.is_item_an_expense
                        jai_general_pkg.get_accounting_method
                        jai_rcv_trx_processing_pkg.get_accrue_on_receipt
                        jai_cmn_rgm_recording_pkg.get_account

------------------------------------------------------------------------------------------------------*/


  ln_user_id := fnd_global.user_id;
Line: 8256

      SELECT chart_of_accounts_id INTO caid
      FROM   gl_sets_of_books
      WHERE  set_of_books_id = cur_items_rec.set_of_books_id;
Line: 8272

    UPDATE ap_invoice_lines_all
    SET    last_update_date = last_update_date
    WHERE invoice_id = inv_id;
Line: 8276

    SELECT max(line_number)
    INTO   ln_inv_line_num
    FROM   ap_invoice_lines_all
    WHERE  invoice_id = inv_id;
Line: 8283

    SELECT NVL(DISTRIBUTION_LINE_NUMBER,1)
    INTO v_distribution_no
    FROM   AP_INVOICE_DISTRIBUTIONS_ALL
    WHERE  INVOICE_ID = inv_id
    AND    DISTRIBUTION_LINE_NUMBER =
      (
      SELECT MAX(DISTRIBUTION_LINE_NUMBER)
      FROM   AP_INVOICE_DISTRIBUTIONS_ALL
      WHERE  INVOICE_ID = inv_id
      )
    FOR UPDATE OF DISTRIBUTION_LINE_NUMBER;
Line: 8302

  OPEN  for_dist_insertion(inv_id,pn_invoice_line_number, ln_min_dist_line_num);
Line: 8303

  FETCH for_dist_insertion INTO for_dist_insertion_rec;
Line: 8304

  CLOSE for_dist_insertion;
Line: 8333

   p_sob_id            =>    for_dist_insertion_rec.set_of_books_id
  );*/
Line: 8359

                    (for_dist_insertion_rec.dist_code_combination_id);
Line: 8416

                                  p_parent_dist_id      =>   for_dist_insertion_rec.invoice_distribution_id ,
                                  p_tax_id              =>   tax_lines1_rec.tax_id
                                ) ;
Line: 8433

            v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 8494

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 8510

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8511

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8520

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 8535

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8536

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8538

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 8559

            ln_lines_to_insert := 1; -- Loop controller to insert more than one lines for partially recoverable tax lines in PO
Line: 8573

              ln_lines_to_insert := 1;
Line: 8579

              ln_lines_to_insert := 2;
Line: 8595

              ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 8602

            fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                            ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                            ',ln_nrec_tax_amt='||ln_nrec_tax_amt
                             );
Line: 8614

            for line in 1..ln_lines_to_insert
            loop
              /* commented out by eric for inclusive tax
              if line = 1 then

                v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 8638

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8639

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8642

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 8670

                  IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
                    v_assets_tracking_flag := jai_constants.YES;
Line: 8686

                    lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8687

                    lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 8691

                  v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 8735

                    v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 8751

                    lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8752

                    lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8755

                    v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 8777

                    v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 8790

                    lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8791

                    lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8792

                    v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 8805

                END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 8828

                INSERT INTO ap_invoice_lines_all
                (
                  INVOICE_ID
                , LINE_NUMBER
                , LINE_TYPE_LOOKUP_CODE
                , DESCRIPTION
                , ORG_ID
                , MATCH_TYPE
    , DEFAULT_DIST_CCID --Changes by nprashar for bug #6995437
                , ACCOUNTING_DATE
                , PERIOD_NAME
                , DEFERRED_ACCTG_FLAG
                , DEF_ACCTG_START_DATE
                , DEF_ACCTG_END_DATE
                , DEF_ACCTG_NUMBER_OF_PERIODS
                , DEF_ACCTG_PERIOD_TYPE
                , SET_OF_BOOKS_ID
                , AMOUNT
                , WFAPPROVAL_STATUS
                , CREATION_DATE
                , CREATED_BY
                , LAST_UPDATED_BY
                , LAST_UPDATE_DATE
                , LAST_UPDATE_LOGIN
                /* 5763527 */
                , project_id
                , task_id
                , expenditure_type
                , expenditure_item_date
                , expenditure_organization_id
                /* End 5763527 */
                ,po_distribution_id --Added for bug#6780154
                )
                VALUES
                (
                  inv_id
                , ln_inv_line_num
                , lv_misc
                , c_tax_rec.tax_name
                , v_org_id
                , lv_match_type
    , v_dist_code_combination_id
                , rec_max_ap_lines_all.accounting_date
                , rec_max_ap_lines_all.period_name
                , rec_max_ap_lines_all.deferred_acctg_flag
                , rec_max_ap_lines_all.def_acctg_start_date
                , rec_max_ap_lines_all.def_acctg_end_date
                , rec_max_ap_lines_all.def_acctg_number_of_periods
                , rec_max_ap_lines_all.def_acctg_period_type
                , rec_max_ap_lines_all.set_of_books_id
                , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
                , rec_max_ap_lines_all.wfapproval_status  -- Bug 4863208
                , sysdate
                , ln_user_id
                , ln_user_id
                , sysdate
                , ln_login_id
                /* 5763527 */
                , ln_project_id
                , ln_task_id
                , lv_exp_type
                , ld_exp_item_date
                , ln_exp_organization_id
          ,po_dist_id --Added for bug#6780154
                );
Line: 8902

                INSERT INTO ap_invoice_distributions_all
                (
                accounting_date,
                accrual_posted_flag,
                assets_addition_flag,
                assets_tracking_flag,
                cash_posted_flag,
                distribution_line_number,
                dist_code_combination_id,
                invoice_id,
                last_updated_by,
                last_update_date,
                line_type_lookup_code,
                period_name,
                set_of_books_id,
                amount,
                base_amount,
                batch_id,
                created_by,
                creation_date,
                description,
                last_update_login,
                match_status_flag,
                posted_flag,
                rate_var_code_combination_id,
                reversal_flag,
                program_application_id,
                program_id,
                program_update_date,
                accts_pay_code_combination_id,
                invoice_distribution_id,
                quantity_invoiced,
                org_id,
                po_distribution_id ,
                rcv_transaction_id,
                matched_uom_lookup_code,
                invoice_line_number
                -- Bug 5401111. Added by Lakshmi Gopalsami
                ,charge_applicable_to_dist_id --5763527
                , project_id
                , task_id
                , expenditure_type
                , expenditure_item_date
                , expenditure_organization_id
                , project_accounting_context
                , pa_addition_flag
               -- Bug 7249100. Added by Lakshmi Gopalsami
                ,distribution_class
        ,asset_book_type_code /* added for bug 8406404 by vumaasha */
                )
                VALUES
                (
                rec_max_ap_lines_all.accounting_date,
                'N', --for_dist_insertion_rec.accrual_posted_flag,
                for_dist_insertion_rec.assets_addition_flag,
                v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug#2851123
                'N',
                v_distribution_no,
                v_dist_code_combination_id,
                inv_id,
                ln_user_id,
                SYSDATE,
                lv_misc,
                rec_max_ap_lines_all.period_name,
                rec_max_ap_lines_all.set_of_books_id,
                round(round(v_tax_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
                ROUND(ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate,ln_tax_precision), ln_precision), --Added by nprashar for bug # 13653889
                v_batch_id,
                ln_user_id,
                SYSDATE,
                c_tax_rec.tax_name,
                ln_login_id,
                for_dist_insertion_rec.match_status_flag , -- Bug 4863208
                'N',
                NULL,
                for_dist_insertion_rec.reversal_flag,  -- Bug 4863208
                for_dist_insertion_rec.program_application_id,
                for_dist_insertion_rec.program_id,
                for_dist_insertion_rec.program_update_date,
                for_dist_insertion_rec.accts_pay_code_combination_id,
                v_invoice_distribution_id, -- BUG#3332988 ap_invoice_distributions_s.NEXTVAL,
               decode(v_assets_tracking_flag, 'Y', NULL, 0),/* Modified for bug 8406404 by vumaasha */
                for_dist_insertion_rec.org_id, -- Bug 4863208
                 --po_dist_id,12434160
			for_dist_insertion_rec.po_distribution_id, --12434160
                rcv_tran_id,
                for_dist_insertion_rec.matched_uom_lookup_code,
                ln_inv_line_num
                /* Bug 5361931. Added by Lakshmi Gopalsami
                 * Passed ln_inv_line_num instead of
                 * pn_invoice_line_number
                 */
                 -- Bug 5401111. Added by Lakshmi Gopalsami
                 ,decode(v_assets_tracking_flag,'N',
                         NULL,for_dist_insertion_rec.invoice_distribution_id)
/*Commented the account_type condition for bug#7008161 by JMEENA
       decode(lv_account_type, 'A',
              for_dist_insertion_rec.invoice_distribution_id,NULL)
            )
*/
                /* 5763527 */
                , ln_project_id
                , ln_task_id
                , lv_exp_type
                , ld_exp_item_date
                , ln_exp_organization_id
                , lv_project_accounting_context
                , lv_pa_addition_flag
                -- Bug 7249100. Added by Lakshmi Gopalsami
               ,lv_dist_class
        , decode(v_assets_tracking_flag,'Y',for_dist_insertion_rec.asset_book_type_code,NULL) /* added for bug 8406404 by vumaasha */
                );
Line: 9029

                INSERT INTO JAI_AP_MATCH_INV_TAXES
                (
                tax_distribution_id,
                exchange_rate_variance,
                assets_tracking_flag,
                invoice_id,
                po_header_id,
                po_line_id,
                line_location_id,
                set_of_books_id,
                --org_id,
                exchange_rate,
                exchange_rate_type,
                exchange_date,
                currency_code,
                code_combination_id,
                last_update_login,
                creation_date,
                created_by,
                last_update_date,
                last_updated_by,
                acct_pay_code_combination_id,
                accounting_date,
                tax_id,
                tax_amount,
                base_amount,
                chart_of_accounts_id,
                distribution_line_number,
                --project_id,
                --task_id,
                po_distribution_id,  -- added  by bug#3038566
                parent_invoice_distribution_id,  -- added  by bug#3038566
                legal_entity_id -- added by rallamse bug#
                ,INVOICE_LINE_NUMBER  -- Added by Brathod, Bug# 4445989
                ,INVOICE_DISTRIBUTION_ID -------|
                ,PARENT_INVOICE_LINE_NUMBER-----|
                ,RCV_TRANSACTION_ID
                ,LINE_TYPE_LOOKUP_CODE
                , recoverable_flag -- 5763527
                ,line_no            -- Bug 5553150

                )
                VALUES
                (
                JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,
                null,--kunkumar for forward porting to R12
                v_assets_tracking_flag , -- 'N', bug#2851123
                inv_id,
                cur_items_rec.po_header_id,
                cur_items_rec.po_line_id,
                cur_items_rec.line_location_id,
                cur_items_rec.set_of_books_id,
                --cur_items_rec.org_id,
                cur_items_rec.rate,
                cur_items_rec.rate_type,
                cur_items_rec.rate_date,
                cur_items_rec.currency_code,
                /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
                 * c_tax_rec.tax_account_id and v_dist_code_combination_id
                */
                v_dist_code_combination_id,
                cur_items_rec.last_update_login,
                cur_items_rec.creation_date,
                cur_items_rec.created_by,
                cur_items_rec.last_update_date,
                cur_items_rec.last_updated_by,
                v_dist_code_combination_id,
                cur_items_rec.invoice_date,
                tax_lines1_rec.tax_id,
                /*commented out by eric for inclusive tax
                round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
                */
                ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
                nvl(ln_base_amount,ROUND(ROUND(tax_lines1_rec.tax_amount,ln_tax_precision), ln_precision)), --Added by nprashar for bug # 13653889
                caid,
                v_distribution_no,
                --p_project_id,
                --p_task_id,
                po_dist_id, -- added  by bug#3038566
                for_dist_insertion_rec.invoice_distribution_id, -- added  by bug#3038566
                get_ven_info_rec.legal_entity_id -- added by rallamse bug#
                --ln_inv_line_num,deleted by Eric for inclusive tax
                --, v_invoice_distribution_id,deleted by Eric for inclusive tax

                --added by Eric for inclusive tax on 20-dec-2007,begin
                ----------------------------------------------------------------
                , DECODE ( NVL(tax_lines1_rec.inc_tax_flag,'N')
                         , 'N',ln_inv_line_num
                         , 'Y',pn_invoice_line_number
                         )
               , NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
                -----------------------------------------------------------------
                --added by Eric for inclusive tax on 20-dec-2007,end

                , pn_invoice_line_number
                , rcv_tran_id
                , lv_misc
                , lv_modvat_flag -- 5763527
                , tax_lines1_rec.tax_line_no  -- added, Harshita for Bug 5553150
                );
Line: 9139

              insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 9157

              INSERT INTO JAI_CMN_FA_INV_DIST_ALL
              (
              invoice_id,
              invoice_distribution_id,
              set_of_books_id,
              batch_id,
              po_distribution_id,
              rcv_transaction_id,
              dist_code_combination_id,
              accounting_date,
              assets_addition_flag,
              assets_tracking_flag,
              distribution_line_number,
              line_type_lookup_code,
              amount,
              description,
              match_status_flag,
              quantity_invoiced
              )
              VALUES
              (
              inv_id,
              ap_invoice_distributions_s.CURRVAL,
              for_dist_insertion_rec.set_of_books_id,
              v_batch_id,
              for_dist_insertion_rec.po_distribution_id,
              rcv_tran_id,
              v_dist_code_combination_id,
              for_dist_insertion_rec.accounting_date,
              for_dist_insertion_rec.assets_addition_flag,
              v_assets_tracking_flag , -- for_dist_insertion_rec.assets_tracking_flag, bug#2851123
              v_distribution_no,
              'MISCELLANEOUS',
              round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
              c_tax_rec.tax_name,
              NULL,
              NULL
              ); */
Line: 9199

        v_update_payment_schedule:=update_payment_schedule(cum_tax_amt); -- bug#3218978
Line: 9202

        UPDATE  ap_invoices_all
        SET   invoice_amount = invoice_amount   + cum_tax_amt,
            approved_amount = approved_amount  + cum_tax_amt,
            pay_curr_invoice_amount =  pay_curr_invoice_amount + cum_tax_amt,
            amount_applicable_to_discount =  amount_applicable_to_discount + cum_tax_amt,
            payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
        WHERE  invoice_id = inv_id;
Line: 9213

          update ap_invoices_all
          set    base_amount = invoice_amount  * exchange_rate
          where  invoice_id = inv_id;
Line: 9221

        update_mrc_data; -- bug#3332988
Line: 9266

                                p_parent_dist_id      =>   for_dist_insertion_rec.invoice_distribution_id ,
                                p_tax_id              =>   tax_lines1_rec.tax_id
                              ) ;
Line: 9281

          v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 9341

               v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 9357

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 9358

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 9367

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 9382

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 9383

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 9385

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 9406

          ln_lines_to_insert := 1; -- Loop controller to insert more than one lines for partially recoverable tax lines in PO
Line: 9420

            ln_lines_to_insert := 1;
Line: 9426

            ln_lines_to_insert := 2;
Line: 9444

            ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 9451

          fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                          ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                          ',ln_nrec_tax_amt='||ln_nrec_tax_amt
                           );
Line: 9463

          for line in 1..ln_lines_to_insert
          loop

            --deleted by Eric for inclusive tax on 20-dec-2007,begin
            -------------------------------------------------------------------------------------
            /* commented out by eric for inclusive tax
            if line = 1 then

              v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 9489

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 9490

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 9493

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 9524

                IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
                  v_assets_tracking_flag := jai_constants.YES;
Line: 9540

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 9541

                  lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 9545

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 9589

                  v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 9605

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 9606

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 9609

                  v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 9631

                  v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 9644

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 9645

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 9646

                  v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 9659

              END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 9694

            INSERT INTO ap_invoice_lines_all
            (
              INVOICE_ID
            , LINE_NUMBER
            , LINE_TYPE_LOOKUP_CODE
            , DESCRIPTION
            , ORG_ID
            , MATCH_TYPE
      , DEFAULT_DIST_CCID --Changes by nprashar for bug #6995437
            , ACCOUNTING_DATE
            , PERIOD_NAME
            , DEFERRED_ACCTG_FLAG
            , DEF_ACCTG_START_DATE
            , DEF_ACCTG_END_DATE
            , DEF_ACCTG_NUMBER_OF_PERIODS
            , DEF_ACCTG_PERIOD_TYPE
            , SET_OF_BOOKS_ID
            , AMOUNT
            , WFAPPROVAL_STATUS
            , CREATION_DATE
            , CREATED_BY
            , LAST_UPDATED_BY
            , LAST_UPDATE_DATE
            , LAST_UPDATE_LOGIN
            /* 5763527 */
            , project_id
            , task_id
            , expenditure_type
            , expenditure_item_date
            , expenditure_organization_id
      ,po_distribution_id --Added for bug#6780154
            )
            VALUES
            (
                inv_id
              , ln_inv_line_num
              , lv_misc
              , c_tax_rec.tax_name
              , v_org_id
              , lv_match_type
        , v_dist_code_combination_id
              , rec_max_ap_lines_all.accounting_date
              , rec_max_ap_lines_all.period_name
              , rec_max_ap_lines_all.deferred_acctg_flag
              , rec_max_ap_lines_all.def_acctg_start_date
              , rec_max_ap_lines_all.def_acctg_end_date
              , rec_max_ap_lines_all.def_acctg_number_of_periods
              , rec_max_ap_lines_all.def_acctg_period_type
              , rec_max_ap_lines_all.set_of_books_id
              , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
              , rec_max_ap_lines_all.wfapproval_status  -- Bug 4863208
              , sysdate
              , ln_user_id
              , ln_user_id
              , sysdate
              , ln_login_id
              /* 5763527 */
              , ln_project_id
              , ln_task_id
              , lv_exp_type
              , ld_exp_item_date
              , ln_exp_organization_id
        ,po_dist_id --Added for bug#6780154
            );
Line: 9767

            INSERT INTO ap_invoice_distributions_all
            (
            accounting_date,
            accrual_posted_flag,
            assets_addition_flag,
            assets_tracking_flag,
            cash_posted_flag,
            distribution_line_number,
            dist_code_combination_id,
            invoice_id,
            last_updated_by,
            last_update_date,
            line_type_lookup_code,
            period_name,
            set_of_books_id,
            amount,
            base_amount,
            batch_id,
            created_by,
            creation_date,
            description,
             exchange_rate_variance,
            last_update_login,
            match_status_flag,
            posted_flag,
            rate_var_code_combination_id,
            reversal_flag,
            program_application_id,
            program_id,
            program_update_date,
            accts_pay_code_combination_id,
            invoice_distribution_id,
            quantity_invoiced,
            org_id,
            po_distribution_id ,
            rcv_transaction_id,
            matched_uom_lookup_code,
            invoice_line_number
            ,charge_applicable_to_dist_id -- Bug 5401111. Added by Lakshmi Gopalsami
            /* 5763527 */
            , project_id
            , task_id
            , expenditure_type
            , expenditure_item_date
            , expenditure_organization_id
            , project_accounting_context
            , pa_addition_flag
            -- Bug 7249100. Added by Lakshmi Gopalsami
            ,distribution_class
      ,asset_book_type_code /* added for bug 8406404 by vumaasha */
            )
            VALUES
            (
            rec_max_ap_lines_all.accounting_date,
            'N', --for_dist_insertion_rec.accrual_posted_flag,
            for_dist_insertion_rec.assets_addition_flag,
            v_assets_tracking_flag ,
            'N',
            v_distribution_no,
            v_dist_code_combination_id,
            inv_id,
            ln_user_id,
            sysdate,
            lv_misc,
            rec_max_ap_lines_all.period_name,
            rec_max_ap_lines_all.set_of_books_id,
            round(v_tax_amount,ln_precision),
            ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_precision),
            v_batch_id,
            ln_user_id,
            sysdate,
            c_tax_rec.tax_name,
              null,--kunkumar for forward porting to R12
            ln_login_id,
            for_dist_insertion_rec.match_status_flag , -- Bug 4863208
            'N',
            NULL,
            for_dist_insertion_rec.reversal_flag,  -- Bug 4863208
            for_dist_insertion_rec.program_application_id,
            for_dist_insertion_rec.program_id,
            for_dist_insertion_rec.program_update_date,
            for_dist_insertion_rec.accts_pay_code_combination_id,
            v_invoice_distribution_id,
            decode(v_assets_tracking_flag, 'Y', NULL, 0), /* Modified for bug 8406404 by vumaasha */
            for_dist_insertion_rec.org_id,  -- bug 4863208
             --po_dist_id,12434160
			for_dist_insertion_rec.po_distribution_id, --12434160
            rcv_tran_id,
            for_dist_insertion_rec.matched_uom_lookup_code,
            ln_inv_line_num
            /* Bug 5361931. Added by Lakshmi Gopalsami
             * Passed ln_inv_line_num instead of
             * pn_invoice_line_number
             */
            -- Bug 5401111. Added by Lakshmi Gopalsami
            ,decode(v_assets_tracking_flag,'N',
                    NULL,for_dist_insertion_rec.invoice_distribution_id)
/*Commented the account_type condition for bug#7008161 by JMEENA
       decode(lv_account_type, 'A',
              for_dist_insertion_rec.invoice_distribution_id,NULL)
            )
*/
            /* 5763527 */
            , ln_project_id
            , ln_task_id
            , lv_exp_type
            , ld_exp_item_date
            , ln_exp_organization_id
            , lv_project_accounting_context
            , lv_pa_addition_flag
            -- Bug 7249100. Added by Lakshmi Gopalsami
            , lv_dist_class
      , decode(v_assets_tracking_flag,'Y',for_dist_insertion_rec.asset_book_type_code,NULL) /* added for bug 8406404 by vumaasha */
            );
Line: 9894

            INSERT INTO JAI_AP_MATCH_INV_TAXES
            (
            tax_distribution_id,
            exchange_rate_variance,
            assets_tracking_flag,
            invoice_id,
            po_header_id,
            po_line_id,
            line_location_id,
            set_of_books_id,
            --org_id,
            exchange_rate,
            exchange_rate_type,
            exchange_date,
            currency_code,
            code_combination_id,
            last_update_login,
            creation_date,
            created_by,
            last_update_date,
            last_updated_by,
            acct_pay_code_combination_id,
            accounting_date,
            tax_id,
            tax_amount,
            base_amount,
            chart_of_accounts_id,
            distribution_line_number,
            --project_id,
            --task_id,
            po_distribution_id,  -- added  by bug#3038566
            parent_invoice_distribution_id,  -- added  by bug#3038566
            legal_entity_id -- added by rallamse bug#
            ,INVOICE_LINE_NUMBER  --    Added by Brathod, Bug# 4445989
            ,INVOICE_DISTRIBUTION_ID ------------|
            ,PARENT_INVOICE_LINE_NUMBER----------|
            ,RCV_TRANSACTION_ID
            ,LINE_TYPE_LOOKUP_CODE
            /* 5763527*/
            , recoverable_flag
            , line_no                          -- added, Harshita for Bug 5553150
            /* End 5763527 */
            )
            VALUES
            (
            JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,
            null,--kunkumar for forward porting to R12
            v_assets_tracking_flag , -- 'N', bug#2851123
            inv_id,
            cur_items_rec.po_header_id,
            cur_items_rec.po_line_id,
            cur_items_rec.line_location_id,
            cur_items_rec.set_of_books_id,
            --cur_items_rec.org_id,
            cur_items_rec.rate,
            cur_items_rec.rate_type,
            cur_items_rec.rate_date,
            cur_items_rec.currency_code,
            /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
                   * c_tax_rec.tax_account_id and v_dist_code_combination_id
             */
            v_dist_code_combination_id,
            cur_items_rec.last_update_login,
            cur_items_rec.creation_date,
            cur_items_rec.created_by,
            cur_items_rec.last_update_date,
            cur_items_rec.last_updated_by,
            v_dist_code_combination_id,
            cur_items_rec.invoice_date,
            tax_lines1_rec.tax_id,
            /*commented out by eric for inclusive tax
            round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
            */
            ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision), --added by eric for inclusive tax
            nvl(ln_base_amount,ROUND(ROUND(tax_lines1_rec.tax_amount,ln_tax_precision), ln_precision)), --Kunkumar for Bug#5593895
            caid,
            v_distribution_no,
            --p_project_id,
            --p_task_id,
            po_dist_id, -- added  by bug#3038566
            for_dist_insertion_rec.invoice_distribution_id, -- added  by bug#3038566
            get_ven_info_rec.legal_entity_id -- added by rallamse bug#
            -- ln_inv_line_num, deleted by Eric for inclusive tax
            --, v_invoice_distribution_id ,deleted by Eric for inclusive tax on 20-dec-2007
            --added by Eric for inclusive tax on 20-dec-2007,begin
            ---------------------------------------------------------------
            , DECODE ( NVL( tax_lines1_rec.inc_tax_flag,'N')
                     , 'N',ln_inv_line_num
                     , 'Y',pn_invoice_line_number
                     )
            , NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
            ---------------------------------------------------------------
            --added by Eric for inclusive tax on 20-dec-2007,end
            , pn_invoice_line_number
            , rcv_tran_id
            , lv_misc
            /* 5763527*/
            , lv_modvat_flag
            , tax_lines1_rec.tax_line_no  -- added, Harshita for Bug 5553150
            /* End of 5763527 */
            );
Line: 9999

            insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 10015

            INSERT INTO JAI_CMN_FA_INV_DIST_ALL
            (
            invoice_id,
            invoice_distribution_id,
            set_of_books_id,
            batch_id,
            po_distribution_id,
            rcv_transaction_id,
            dist_code_combination_id,
            accounting_date,
            assets_addition_flag,
            assets_tracking_flag,
            distribution_line_number,
            line_type_lookup_code,
            amount,
            description,
            match_status_flag,
            quantity_invoiced
            )
            VALUES
            (
            inv_id,
            ap_invoice_distributions_s.CURRVAL,
            for_dist_insertion_rec.set_of_books_id,
            v_batch_id,
            for_dist_insertion_rec.po_distribution_id,
            rcv_tran_id,
            v_dist_code_combination_id,
            for_dist_insertion_rec.accounting_date,
            for_dist_insertion_rec.assets_addition_flag,
            v_assets_tracking_flag, -- for_dist_insertion_rec.assets_tracking_flag, bug#2851123
            v_distribution_no,
            'MISCELLANEOUS',
            round(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
            c_tax_rec.tax_name,
            NULL,
            NULL
            );
Line: 10064

        v_update_payment_schedule:=update_payment_schedule(cum_tax_amt); -- added by bug 321978.
Line: 10067

        UPDATE  ap_invoices_all
        SET     invoice_amount = invoice_amount   + cum_tax_amt,
            approved_amount      =  approved_amount  + cum_tax_amt,
            pay_curr_invoice_amount =  pay_curr_invoice_amount + cum_tax_amt,
            amount_applicable_to_discount =  amount_applicable_to_discount + cum_tax_amt,
            payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
        WHERE  invoice_id = inv_id;
Line: 10077

          update ap_invoices_all
          set    base_amount = invoice_amount  * exchange_rate
          where  invoice_id = inv_id;
Line: 10085

        update_mrc_data; -- bug#3332988
Line: 10103

    (Select shipment_num
    From   rcv_headers_interface
    Where  invoice_num = get_ven_info_rec.invoice_num)
    Loop
      v_ship_num := rcv_hdr_intf_rec.shipment_num;
Line: 10166

                                p_parent_dist_id      =>   for_dist_insertion_rec.invoice_distribution_id ,
                                p_tax_id              =>   i.tax_id
                              ) ;
Line: 10173

          v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 10234

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 10249

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 10250

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 10259

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 10269

          ln_lines_to_insert := 1; -- Loop controller to insert more than one lines for partially recoverable tax lines in PO
Line: 10283

            ln_lines_to_insert := 1;
Line: 10289

            ln_lines_to_insert := 2;
Line: 10306

            ln_lines_to_insert := 2 *ln_lines_to_insert; --changed by eric for inclusive tax on Jan 4,2008
Line: 10314

          fnd_file.put_line(fnd_file.log, 'ln_lines_to_insert='||ln_lines_to_insert||
                                        ',ln_rec_tax_amt='||ln_rec_tax_amt          ||
                                        ',ln_nrec_tax_amt='||ln_nrec_tax_amt
                         );
Line: 10326

          for line in 1..ln_lines_to_insert
          loop
          /*commented out by eric for inclusive tax

          if line = 1 then

            v_tax_amount  := nvl(ln_rec_tax_amt, v_tax_amount);
Line: 10351

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 10352

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 10355

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 10388

              IF for_dist_insertion_rec.assets_tracking_flag = jai_constants.YES THEN
                v_assets_tracking_flag := jai_constants.YES;
Line: 10404

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 10405

                lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 10409

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 10453

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 10469

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 10470

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 10473

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 10495

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 10508

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 10509

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 10510

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 10523

            END IF;--( tax_type ='PR' and (ln_lines_to_insert =4 OR )
Line: 10530

          'Before inserting into ap_invoice_lines_all for line no :' || ln_inv_line_num );
Line: 10550

            INSERT INTO ap_invoice_lines_all
            (
                INVOICE_ID
              , LINE_NUMBER
              , LINE_TYPE_LOOKUP_CODE
              , DESCRIPTION
              , ORG_ID
              , MATCH_TYPE
        , DEFAULT_DIST_CCID --Changes by nprashar for bug #6995437
              , ACCOUNTING_DATE
              , PERIOD_NAME
              , DEFERRED_ACCTG_FLAG
              , DEF_ACCTG_START_DATE
              , DEF_ACCTG_END_DATE
              , DEF_ACCTG_NUMBER_OF_PERIODS
              , DEF_ACCTG_PERIOD_TYPE
              , SET_OF_BOOKS_ID
              , AMOUNT
              , WFAPPROVAL_STATUS
              , CREATION_DATE
              , CREATED_BY
              , LAST_UPDATED_BY
              , LAST_UPDATE_DATE
              , LAST_UPDATE_LOGIN
              /* 5763527 */
              , project_id
              , task_id
              , expenditure_type
              , expenditure_item_date
              , expenditure_organization_id
              /* End 5763527 */
        ,po_distribution_id --Added for bug#6780154

            )
            VALUES
            (
                inv_id
              , ln_inv_line_num
              , lv_misc
              , c_tax_rec.tax_name
              , v_org_id
              , lv_match_type
        , v_dist_code_combination_id
              , rec_max_ap_lines_all.accounting_date
              , rec_max_ap_lines_all.period_name
              , rec_max_ap_lines_all.deferred_acctg_flag
              , rec_max_ap_lines_all.def_acctg_start_date
              , rec_max_ap_lines_all.def_acctg_end_date
              , rec_max_ap_lines_all.def_acctg_number_of_periods
              , rec_max_ap_lines_all.def_acctg_period_type
              , rec_max_ap_lines_all.set_of_books_id
              , ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision) --Added by nprashar for bug # 13653889
              , rec_max_ap_lines_all.wfapproval_status  -- Bug 4863208
              , sysdate
              , ln_user_id
              , ln_user_id
              , sysdate
              , ln_login_id
              /* 5763527 */
              , ln_project_id
              , ln_task_id
              , lv_exp_type
              , ld_exp_item_date
              , ln_exp_organization_id
              /* End 5763527 */
          ,po_dist_id --Added for bug#6780154
             );
Line: 10619

            'Before inserting into ap_invoice_distributions_all for distribution line no :'
            || v_distribution_no);
Line: 10629

            INSERT INTO ap_invoice_distributions_all
            (
            accounting_date,
            accrual_posted_flag,
            assets_addition_flag,
            assets_tracking_flag,
            cash_posted_flag,
            distribution_line_number,
            dist_code_combination_id,
            invoice_id,
            last_updated_by,
            last_update_date,
            line_type_lookup_code,
            period_name,
            set_of_books_id ,
            amount,
            base_amount,
            batch_id,
            created_by,
            creation_date,
            description,
             exChange_rate_variance,
            last_update_login,
            match_status_flag,
            posted_flag,
            rate_var_code_combination_id ,
            reversal_flag ,
            program_application_id,
            program_id,
            program_update_date,
            accts_pay_code_combination_id,
            invoice_distribution_id,
            quantity_invoiced,
            po_distribution_id ,
            rcv_transaction_id,
            org_id,
            matched_uom_lookup_code
            ,invoice_line_number
      ,charge_applicable_to_dist_id -- Bug 5401111. Added by Lakshmi Gopalsami
            /* 5763527 */
            , project_id
            , task_id
            , expenditure_type
            , expenditure_item_date
            , expenditure_organization_id
            , project_accounting_context
            , pa_addition_flag
            /* End of 5763527 */
            -- Bug 7249100. Added by Lakshmi Gopalsami
            ,distribution_class
      ,asset_book_type_code /* added for bug 8406404 by vumaasha */
            )
            VALUES
            (
            rec_max_ap_lines_all.accounting_date,
            'N', --for_dist_insertion_rec.accrual_posted_flag,
            for_dist_insertion_rec.assets_addition_flag,
            v_assets_tracking_flag , -- for_dist_insertion_rec.assets_tracking_flag, bug#2851123
            'N',
            -- dln,
            v_distribution_no,
            v_dist_code_combination_id,
            inv_id,
            ln_user_id,
            sysdate,
            lv_misc,
            rec_max_ap_lines_all.period_name,
            rec_max_ap_lines_all.set_of_books_id ,
            ROUND(ROUND(v_tax_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
            ROUND(ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
            v_batch_id,
            ln_user_id,
            sysdate,
            c_tax_rec.tax_name,
            null,--kunkumar for forward porting to R12
            ln_login_id,
            for_dist_insertion_rec.match_status_flag , -- Bug 4863208
            'N',
            NULL,
            for_dist_insertion_rec.reversal_flag,  -- Bug 4863208
            for_dist_insertion_rec.program_application_id,
            for_dist_insertion_rec.program_id,
            for_dist_insertion_rec.program_update_date,
            for_dist_insertion_rec.accts_pay_code_combination_id,
            v_invoice_distribution_id,
            decode(v_assets_tracking_flag, 'Y', NULL, 0), /* Modified for bug 8406404 by vumaasha */
            po_dist_id ,
            rcv_tran_id,
            for_dist_insertion_rec.org_id,  -- Bug 4863208
            for_dist_insertion_rec.matched_uom_lookup_code,
            ln_inv_line_num
      -- Bug 5401111. Added by Lakshmi Gopalsami
      ,decode(v_assets_tracking_flag,'N',
              NULL,for_dist_insertion_rec.invoice_distribution_id)
/*Commented the account_type condition for bug#7008161 by JMEENA
       decode(lv_account_type, 'A',
              for_dist_insertion_rec.invoice_distribution_id,NULL)
            )
*/
            /* 5763527 */
            , ln_project_id
            , ln_task_id
            , lv_exp_type
            , ld_exp_item_date
            , ln_exp_organization_id
            , lv_project_accounting_context
            , lv_pa_addition_flag
            /* End Of 5763527 */
            -- Bug 7249100. Added by Lakshmi Gopalsami
            , lv_dist_class
      , decode(v_assets_tracking_flag,'Y',for_dist_insertion_rec.asset_book_type_code,NULL) /* added for bug 8406404 by vumaasha */
            );
Line: 10749

            'Before inserting into JAI_AP_MATCH_INV_TAXES tax id ' || i.tax_id );
Line: 10756

            INSERT INTO JAI_AP_MATCH_INV_TAXES
            (
            tax_distribution_id,
            exchange_rate_variance,
            assets_tracking_flag,
            invoice_id,
            po_header_id,
            po_line_id,
            line_location_id,
            set_of_books_id,
            --org_id,
            exchange_rate,
            exchange_rate_type,
            exchange_date,
            currency_code,
            code_combination_id,
            last_update_login,
            creation_date,
            created_by,
            last_update_date,
            last_updated_by,
            acct_pay_code_combination_id,
            accounting_date,
            tax_id,
            tax_amount,
            base_amount,
            chart_of_accounts_id,
            distribution_line_number,
            po_distribution_id,
            parent_invoice_distribution_id,
            legal_entity_id
            ,INVOICE_LINE_NUMBER
            ,INVOICE_DISTRIBUTION_ID
            ,PARENT_INVOICE_LINE_NUMBER
            ,RCV_TRANSACTION_ID
            ,LINE_TYPE_LOOKUP_CODE
            ,recoverable_flag -- 5763527
            ,line_no            -- added, Harshita for Bug 5553150
            )
            VALUES
            (
            JAI_AP_MATCH_INV_TAXES_S.NEXTVAL,
            null,--kunkumar for forward porting to R12
            v_assets_tracking_flag , -- 'N', bug#2851123
            inv_id,
            cur_items_rec.po_header_id,
            cur_items_rec.po_line_id,
            cur_items_rec.line_location_id,
            cur_items_rec.set_of_books_id,
            --cur_items_rec.org_id,
            cur_items_rec.rate,
            cur_items_rec.rate_type,
            cur_items_rec.rate_date,
            cur_items_rec.currency_code,
      /* Bug 5358788. Added by Lakshmi Gopalsami. Commented
             * c_tax_rec.tax_account_id and v_dist_code_combination_id
       */
            v_dist_code_combination_id,
            cur_items_rec.last_update_login,
            cur_items_rec.creation_date,
            cur_items_rec.created_by,
            cur_items_rec.last_update_date,
            cur_items_rec.last_updated_by,
            v_dist_code_combination_id,
            cur_items_rec.invoice_date,
            i.tax_id,
            /*commented out by eric for inclusive tax
            round(v_tax_amount,ln_precision),
            */
            ROUND(ROUND(lv_tax_line_amount,ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
            ROUND(ROUND(i.tax_amount, ln_tax_precision),ln_precision), --Added by nprashar for bug # 13653889
            caid,
            -- dln,
            v_distribution_no,
            po_dist_id, -- added  by bug#3038566
            for_dist_insertion_rec.invoice_distribution_id, -- added  by bug#3038566
            get_ven_info_rec.legal_entity_id  -- added by rallamse bug#
            --ln_inv_line_num, deletedt by eric for inclusive tax
            --, v_invoice_distribution_id, deletedt by eric for inclusive tax
            --added by Eric for inclusive tax on 20-dec-2007,begin
            --------------------------------------------------------------
            , DECODE ( NVL(i.inc_tax_flag,'N')
                     , 'N',ln_inv_line_num
                     , 'Y',pn_invoice_line_number
                     )
            ,NVL(v_invoice_distribution_id,for_dist_insertion_rec.invoice_distribution_id)
            --------------------------------------------------------------
            --added by Eric for inclusive tax on 20-dec-2007,end
            , pn_invoice_line_number
            , rcv_tran_id
            , lv_misc
            , lv_modvat_flag -- 5763527
            , i.tax_line_no  -- added, Harshita for Bug 5553150
            );
Line: 10858

            insert_mrc_data(v_invoice_distribution_id); -- bug#3332988
Line: 10879

            Fnd_File.put_line(Fnd_File.LOG, 'Before inserting into JAI_CMN_FA_INV_DIST_ALL');
Line: 10880

            INSERT INTO JAI_CMN_FA_INV_DIST_ALL
            (
            invoice_id,
            invoice_distribution_id,
            set_of_books_id,
            batch_id,
            po_distribution_id,
            rcv_transaction_id,
            dist_code_combination_id,
            accounting_date,
            assets_addition_flag,
            assets_tracking_flag,
            distribution_line_number,
            line_type_lookup_code,
            amount,
            description,
            match_status_flag,
            quantity_invoiced
            )
            VALUES
            (
            inv_id,
            ap_invoice_distributions_s.CURRVAL,
            for_dist_insertion_rec.set_of_books_id,
            v_batch_id,
            for_dist_insertion_rec.po_distribution_id,
            rcv_tran_id,
            v_dist_code_combination_id,
            for_dist_insertion_rec.accounting_date,
            for_dist_insertion_rec.assets_addition_flag,
            v_assets_tracking_flag , -- for_dist_insertion_rec.assets_tracking_flag, bug#2851123
            v_distribution_no,
            'MISCELLANEOUS',
            ROUND(v_tax_amount, ln_precision),
            c_tax_rec.tax_name,
            NULL,
            NULL);*/
Line: 10932

        v_update_payment_schedule:=update_payment_schedule(cum_tax_amt); -- bug#3218978
Line: 10934

        UPDATE ap_invoices_all
        SET invoice_amount = invoice_amount + cum_tax_amt,
        approved_amount = approved_amount + cum_tax_amt,
        pay_curr_invoice_amount = pay_curr_invoice_amount + cum_tax_amt,
        amount_applicable_to_discount = amount_applicable_to_discount + cum_tax_amt,
        payment_status_flag = decode(payment_status_flag, 'Y', 'P', payment_status_flag)
        -- bug#3624898
        WHERE invoice_id = inv_id;
Line: 10946

          update ap_invoices_all
          set    base_amount = invoice_amount  * exchange_rate
          where  invoice_id = inv_id;
Line: 10954

        update_mrc_data; -- bug#3332988