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: 140

                              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: 184

		     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

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: 227

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: 312

          DELETE  JAI_AP_MATCH_ERS_T
          WHERE   invoice_id = v_prev_invoice_id;
Line: 317

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

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

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

    DELETE  JAI_AP_MATCH_ERS_T
    WHERE   invoice_id = v_prev_invoice_id;
Line: 428

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

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

    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: 501

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

    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: 515

	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: 523

     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: 555

     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: 562

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

    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: 599

    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
    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 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
    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
      ---------------------------------------------------------------------
    ORDER BY  tax_line_no; -- added bug#3038566
Line: 669

     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
     FROM   JAI_CMN_TAXES_ALL
     WHERE  tax_id = t_id;
Line: 679

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

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

     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: 694

    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 */
     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: 734

    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
    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: 758

   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
  , 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 */
					     )
    order by  tax_line_no; -- added
Line: 797

    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
    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'

    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
    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
    -- GROUP BY jrl.tax_id,jrl.currency,jrl.tax_type, jrl.modvat_flag; commented by bug#3038566
Line: 870

  select ap_invoice_distributions_s.nextval
  from   dual;
Line: 876

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

 select NVL(rounding_factor,-1)
 from jai_cmn_taxes_all
 where tax_id = cp_tax_id  ;
Line: 916

  v_update_payment_schedule           boolean; -- bug#3218978
Line: 927

  for_dist_insertion_rec              for_dist_insertion%ROWTYPE;
Line: 954

  ln_lines_to_insert                  number;
Line: 972

    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: 988

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

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

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

    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: 1038

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

  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: 1061

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

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

    v_total_tax_in_payment  number;
Line: 1088

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

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

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

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

      v_tax_installment := -1 ;--Modified by kunkumar for  5593895
Line: 1125

      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: 1143

      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: 1155

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

  end update_payment_schedule; -- bug # 3218978
Line: 1161

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

      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: 1184

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

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

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

      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: 1215

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

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

    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: 1239

  select  sum(tax_amount) tax_amount-- project costing fwd porting
  from    JAI_AP_MATCH_INV_TAXES
  where   p_orig_invoice_id = p_orig_invoice_id
  and   parent_invoice_distribution_id = p_orig_invoice_dist_id
  and   tax_id = p_tax_id;
Line: 1258

      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: 1317

                        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: 1672

                    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

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: 1859

      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: 1873

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

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

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

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

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

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

  FETCH for_dist_insertion INTO for_dist_insertion_rec;
Line: 1912

  CLOSE for_dist_insertion;
Line: 1947

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

                    (for_dist_insertion_rec.dist_code_combination_id);
Line: 2030

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

      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: 2061

        v_price_var_accnt := for_dist_insertion_rec.price_var_code_combination_id;
Line: 2071

      v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 2176

        lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 2177

        lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 2185

        v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 2235

      ln_lines_to_insert := 1;
Line: 2251

      	ln_lines_to_insert := 1;
Line: 2257

      	ln_lines_to_insert := 2;
Line: 2273

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

      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: 2292

      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: 2307

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

          lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 2324

          lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 2327

          v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 2441

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

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 2458

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 2462

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 2506

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 2522

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 2523

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 2526

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 2548

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 2561

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 2562

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 2563

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 2576

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

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

        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(v_tax_amount,ln_precision)
        , 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: 2679

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

        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
        )
        VALUES
        (
        rec_max_ap_lines_all.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,
        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), -- replaced 2 with ln_precision - ssumaith - bug# 3127834
        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,
        -1, --Modified by kunkumar for bug# 5593895
        po_dist_id ,
        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
        /* End 5763527 */
        -- Bug 7249100. Added by Lakshmi Gopalsami
        ,lv_dist_class
        );
Line: 2812

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

        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(lv_tax_line_amount, ln_precision),  --added by eric for compatibility of inclusvice tax on 20-dec-2007
        nvl(ln_base_amount, ROUND(ROUND(i.tax_amount, ln_precision), ln_precision)),
        caid,
        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 , 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
        ---------------------------------------------------------------
        , 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 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: 2921

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

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

      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: 2967

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

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

  ELSIF p_rematch = 'PAY_ON_RECEIPT' THEN

    Fnd_File.put_line(Fnd_File.LOG, 'inside  p_rematch = PAY_ON_RECEIPT ');
Line: 3030

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

        v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 3102

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 3119

		        lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3120

		        lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3130

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 3164

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3165

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3167

            v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 3177

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

        	ln_lines_to_insert := 1;
Line: 3197

        	ln_lines_to_insert := 2;
Line: 3213

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

        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: 3230

        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: 3243

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

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3260

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 3263

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 3289

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

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3306

                lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 3310

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 3354

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 3370

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3371

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3374

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 3396

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 3409

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3410

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3411

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 3424

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

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

            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(v_tax_amount,ln_precision)
            , 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: 3533

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

            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
            )
            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(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,
            -- '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,
	          0,
	          po_dist_id,
            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
            );
Line: 3663

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

        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(lv_tax_line_amount,ln_precision), --added by eric for inclusive tax
        ROUND(tax_lines1_rec.tax_amount, 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 , 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: 3767

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

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

        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: 3813

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

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

      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: 3833

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

     update_mrc_data; -- bug#3332988
Line: 3894

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

        v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 3965

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 3980

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 3981

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 3990

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 4006

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4007

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4009

		        v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 4035

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

        	ln_lines_to_insert := 1;
Line: 4055

        	ln_lines_to_insert := 2;
Line: 4072

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

      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: 4092

      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: 4106

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

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4124

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4126

          v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 4154

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

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4171

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 4175

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 4219

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 4235

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4236

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4239

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 4261

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 4274

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4275

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4276

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 4289

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

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

          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(v_tax_amount,ln_precision)
          , 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: 4387

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

          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
          )
          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(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,
          -- '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,
	        0,
          po_dist_id ,
          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
          );
Line: 4519

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

          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(lv_tax_line_amount,ln_precision), --added by eric for inclusive tax
          ROUND(tax_lines1_rec.tax_amount, 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: 4639

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

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

        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: 4685

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

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

      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: 4705

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

      update_mrc_data; -- bug#3332988
Line: 4790

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

        v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 4857

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 4874

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4875

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4887

          v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 4915

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 4916

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 4918

            v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 4923

        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: 4935

          v_price_var_accnt := for_dist_insertion_rec.price_var_code_combination_id;
Line: 4952

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

      	  ln_lines_to_insert := 1;
Line: 4972

      	  ln_lines_to_insert := 2;
Line: 4993

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

        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: 5012

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

      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: 5027

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

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5044

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5046

          v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 5087

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

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5104

              lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 5108

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 5154

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 5170

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5171

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5174

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 5197

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 5210

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 5211

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 5212

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 5225

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

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

          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(v_tax_amount,ln_precision)
          , 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: 5323

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

          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
            )

          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(v_tax_amount, ln_precision),
          ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_precision),
          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,
          0,
          po_dist_id ,
          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

          );
Line: 5466

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

          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(lv_tax_line_amount,ln_precision), --added by eric for inclusive tax
          ROUND(r_tax_lines_rec.tax_amount, 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
          --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
                   )
          , 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: 5580

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

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

        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: 5629

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

    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: 5685

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

    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: 5698

     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: 5731

     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: 5739

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

      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: 5774

     SELECT tax_name, tax_account_id, mod_cr_percentage, tax_type
     -- 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: 5780

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

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

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

    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 */
     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: 5830

   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: 5868

  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: 5896

	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: 5919

      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: 5926

    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: 5936

    select ap_invoice_distributions_s.nextval
    from   dual;
Line: 5942

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

  for_dist_insertion_rec              for_dist_insertion%ROWTYPE;
Line: 5986

  v_update_payment_schedule           boolean; -- bug#3206083
Line: 6003

  ln_lines_to_insert                  number;
Line: 6022

    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: 6033

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

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

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

    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: 6063

	select NVL(rounding_factor,-1)
	from jai_cmn_taxes_all
	where tax_id = cp_tax_id  ;
Line: 6086

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

    v_total_tax_in_payment            number;
Line: 6095

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

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

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

    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: 6132

      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: 6152

      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: 6166

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

  end update_payment_schedule; -- bug # 3218978
Line: 6173

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

      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: 6196

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

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

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

      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: 6227

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

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

                       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: 6550

                    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: 6702

      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: 6718

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

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

    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: 6748

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

  FETCH for_dist_insertion INTO for_dist_insertion_rec;
Line: 6750

  CLOSE for_dist_insertion;
Line: 6779

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

                    (for_dist_insertion_rec.dist_code_combination_id);
Line: 6862

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

            v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 6934

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 6950

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6951

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6960

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 6975

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 6976

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 6978

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 6999

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

            	ln_lines_to_insert := 1;
Line: 7019

            	ln_lines_to_insert := 2;
Line: 7035

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

            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: 7054

            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: 7078

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7079

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 7082

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 7110

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

                    lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7127

                    lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 7131

                  v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 7175

                    v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 7191

                    lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7192

                    lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 7195

                    v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 7217

                    v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 7230

                    lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7231

                    lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 7232

                    v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 7245

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

                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(v_tax_amount,ln_precision)
                , 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: 7342

                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
                )
                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(v_tax_amount,ln_precision), -- ROUND(v_tax_amount, 2), by Aparajita bug#2567799
                ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_precision), --
                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,
	              0,
                for_dist_insertion_rec.org_id, -- Bug 4863208
                po_dist_id ,
                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
                );
Line: 7469

                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(lv_tax_line_amount,ln_precision), --added by eric for inclusive tax
                nvl(ln_base_amount,ROUND(ROUND(tax_lines1_rec.tax_amount,ln_tax_precision), ln_precision)), --Modified by 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

                --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: 7579

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

              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: 7627

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

        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: 7641

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

        update_mrc_data; -- bug#3332988
Line: 7694

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

          v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 7764

               v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 7780

              lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7781

              lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 7790

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 7805

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7806

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 7808

              v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id;
Line: 7829

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

          	ln_lines_to_insert := 1;
Line: 7849

          	ln_lines_to_insert := 2;
Line: 7867

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

          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: 7885

          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: 7911

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7912

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 7915

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 7946

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

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 7963

                  lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 7967

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 8011

                  v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 8027

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8028

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8031

                  v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 8053

                  v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 8066

                  lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8067

                  lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8068

                  v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 8081

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

            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(v_tax_amount,ln_precision)
              , 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: 8189

            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
            )
            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,
	          0,
            for_dist_insertion_rec.org_id,  -- bug 4863208
            po_dist_id ,
            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
            );
Line: 8320

            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(lv_tax_line_amount,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: 8425

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

            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: 8480

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

        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: 8493

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

        update_mrc_data; -- bug#3332988
Line: 8519

	  (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: 8577

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

          v_assets_tracking_flag := for_dist_insertion_rec.assets_tracking_flag;
Line: 8645

              v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 8660

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8661

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8670

            v_dist_code_combination_id := for_dist_insertion_rec.dist_code_combination_id;
Line: 8680

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

          	ln_lines_to_insert := 1;
Line: 8700

          	ln_lines_to_insert := 2;
Line: 8717

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

          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: 8736

          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: 8761

            lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8762

            lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8765

            v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 8798

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

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8815

                lv_pa_addition_flag         := for_dist_insertion_rec.pa_addition_flag;
Line: 8819

              v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id;
Line: 8863

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 8879

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8880

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8883

                v_dist_code_combination_id  :=  for_dist_insertion_rec.dist_code_combination_id ;
Line: 8905

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 8918

                lv_project_accounting_context := for_dist_insertion_rec.project_accounting_context;
Line: 8919

                lv_pa_addition_flag           := for_dist_insertion_rec.pa_addition_flag;
Line: 8920

                v_dist_code_combination_id    := for_dist_insertion_rec.dist_code_combination_id ;
Line: 8933

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

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

            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(v_tax_amount,ln_precision)
              , 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: 9029

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

            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
            )
            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(v_tax_amount,ln_precision),
            ROUND(v_tax_amount * for_dist_insertion_rec.exchange_rate, ln_precision), --ROUND(for_dist_insertion_rec.base_amount,2),
            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,
	          0,
            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

            );
Line: 9158

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

            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(lv_tax_line_amount,ln_precision), --added by eric for inclusive tax
            ROUND(i.tax_amount, ln_precision),
            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: 9267

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

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

            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: 9329

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

        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: 9343

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

        update_mrc_data; -- bug#3332988