DBA Data[Home] [Help]

APPS.AP_ETAX_UTILITY_PKG SQL Statements

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

Line: 5

  l_login_id		ap_invoices_all.last_update_login%TYPE 	:= FND_GLOBAL.login_id;
Line: 130

  PROCEDURE insert_tax_distributions
  			(p_invoice_header_rec        IN ap_invoices_all%ROWTYPE,
			 p_inv_dist_rec              IN r_ins_tax_dist_info,
			 p_dist_code_combination_id  IN NUMBER,
			 p_user_id	             IN NUMBER,
			 p_sysdate	             IN DATE,
			 p_login_id	             IN	NUMBER,
			 p_calling_sequence          IN VARCHAR2);
Line: 321

        l_action_section := 'UPDATED';
Line: 363

              IN ('MARK TAX LINES DELETED', 'FREEZE DISTRIBUTIONS')) THEN
      l_action_section := 'UPDATED';
Line: 370

    ELSIF ( p_calling_mode = 'DELETE INVOICE' ) THEN
      l_action_section := 'PURGED';
Line: 441

    SELECT invoice_num, invoice_date, invoice_type_lookup_code
      FROM ap_invoices_all
     WHERE invoice_id = c_corrected_inv_id;
Line: 539

    SELECT invoice_num, invoice_date, invoice_type_lookup_code
      FROM ap_invoices_all
     WHERE invoice_id = c_prepay_inv_id;
Line: 637

    SELECT transaction_date, transaction_type
      FROM rcv_transactions
     WHERE transaction_id = c_rcv_transaction;
Line: 749

    SELECT pll.org_id, pll.quantity, pll.po_header_id, nvl(ph.rate ,1), pll.po_release_id, mum.uom_code
      FROM po_line_locations_all pll, po_headers_all ph, mtl_units_of_measure mum
     WHERE pll.line_location_id = c_po_line_location_Id
       AND pll.po_header_id = ph.po_header_id
       AND pll.unit_meas_lookup_code = mum.unit_of_measure (+);
Line: 756

    SELECT pll.org_id, pll.quantity, pll.line_location_id,
           pll.po_header_id, nvl(ph.rate,1), pll.po_release_id, mum.uom_code,
	   pd.quantity_ordered, pll.price_override
      FROM po_line_locations_all pll, po_distributions_all pd,
           po_headers_all ph, mtl_units_of_measure mum
     WHERE pd.po_distribution_id = c_po_dist_Id
       AND pd.line_location_id = pll.line_location_id
       AND pll.po_header_id = ph.po_header_id
       AND pll.unit_meas_lookup_code = mum.unit_of_measure (+);
Line: 794

       SELECT inventory_organization_id
         INTO AP_ETAX_SERVICES_PKG.g_fsp_attributes(l_org_id).inventory_organization_id
         FROM financials_system_params_all
        WHERE org_id = l_org_id;
Line: 874

    SELECT ail.awt_group_id
      FROM ap_invoice_distributions_all aid,
           ap_invoice_lines_all ail
     WHERE aid.invoice_distribution_id = c_prepay_dist_id
       AND aid.invoice_id = ail.invoice_id
       AND aid.invoice_line_number = ail.line_number;
Line: 922

 |      update, or delete of existing exclusive tax lines in AP if required.
 |      It also handles the update of the total tax amounts. (Inclusive and
 |      self-assessed.
 |
 |  PARAMETERS
 |      P_Invoice_Header_Rec - Header info
 |      P_error_code - Error code to be returned
 |      P_calling_sequence -  Calling sequence
 |
 |  MODIFICATION HISTORY
 |    DATE          Author         Action
 |    15-OCT-2003   SYIDNER        Created
 |
 *============================================================================*/
  FUNCTION Return_Tax_Lines(
             P_Invoice_Header_Rec        IN ap_invoices_all%ROWTYPE,
             P_Error_Code                OUT NOCOPY VARCHAR2,
             P_Calling_Sequence          IN VARCHAR2) RETURN BOOLEAN
  IS

    l_debug_info                 VARCHAR2(240);
Line: 963

	Select ail.line_number
	From   ap_invoice_lines_all ail
	Where  ail.invoice_id = c_invoice_id
        And    ail.line_type_lookup_code = 'TAX'
        And    ail.prepay_invoice_id IS NULL;
Line: 971

		(Select chrg_invoice_line_number
		 From ap_allocation_rule_lines arl
          	 Where arl.invoice_id = ail.invoice_id
            	 And arl.chrg_invoice_line_number = ail.line_number);
Line: 1000

     SELECT ail.line_number, ail.summary_tax_line_id
       INTO l_invoice_line_number, l_ap_summary_tax_line_id
       FROM AP_INVOICE_LINES_ALL ail
      WHERE ail.invoice_id            = P_Invoice_Header_Rec.invoice_id
        AND ail.line_type_lookup_code = 'TAX'
        AND NOT EXISTS
            (SELECT ls.summary_tax_line_id
               FROM zx_lines_summary ls
              WHERE ls.summary_tax_line_id             = ail.summary_tax_line_id
                AND ls.trx_id                          = ail.invoice_id
                AND NVL(ls.tax_amt_included_flag, 'N') = 'N'
                AND NVL(ls.self_assessed_flag, 'N')    = 'N'
                AND NVL(ls.reporting_only_flag, 'N')   = 'N'
            )
        AND EXISTS
            (SELECT 'Invoice Distributions Exist'
               FROM ap_invoice_distributions_all aid
              WHERE aid.invoice_id          = ail.invoice_id
                AND aid.invoice_line_number = ail.line_number
                AND (aid.accounting_event_id IS NOT NULL
                     OR NVL(aid.match_status_flag,'N') IN ('A','T')
                     OR aid.bc_event_id IS NOT NULL
                     OR NVL(aid.encumbered_flag, 'N') IN ('Y','D','W','X')
                    ) --This is done for Mexicana Bug7623255 to avoid such Data Fix Condition
            )
        AND EXISTS
            (SELECT zl.summary_tax_line_id
               FROM zx_lines_summary zl
              WHERE zl.application_id                = 200
                AND zl.entity_code                   = 'AP_INVOICES'
                AND zl.event_class_code             IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                AND zl.trx_id                        = ail.invoice_id
                AND zl.tax_regime_code               = ail.tax_regime_code
                AND zl.tax                           = ail.tax
                AND zl.tax_status_code               = ail.tax_status_code
                AND (zl.tax_rate_code                = ail.tax_rate_code
                     OR zl.tax_rate_id               = ail.tax_rate_id)
                AND (zl.tax_jurisdiction_code        = ail.tax_jurisdiction_code
                     OR zl.tax_jurisdiction_code    IS NULL)
                AND zl.tax_rate                      = ail.tax_rate
                AND zl.tax_amt			 = ail.amount
                AND NVL(zl.reporting_only_flag, 'N') = 'N'
                AND NVL(zl.self_assessed_flag, 'N')  = 'N'
                AND NVL(zl.cancel_flag, 'N')         = NVL(ail.cancelled_flag,'N')
                AND zl.summary_tax_line_id          <> ail.summary_tax_line_id
           )
       AND rownum = 1;
Line: 1073

	       FND_MESSAGE.SET_TOKEN('ERROR', 'Summary Tax Line Deleted by EBTax. This would cause orphan distributions.');
Line: 1094

      SELECT
          approval_workflow_flag,
          awt_include_tax_amt,
          disc_is_inv_less_tax_flag,
          base_currency_code,
          combined_filing_flag,
          income_tax_region_flag,
          income_tax_region
        INTO
          l_wfapproval_flag,
          l_awt_include_tax_amt,
          l_disc_is_inv_less_tax_flag,
          l_base_currency_code,
          l_combined_filing_flag,
          l_income_tax_region_flag,
          l_income_tax_region
        FROM ap_system_parameters_all
       WHERE org_id = P_Invoice_Header_Rec.org_id;
Line: 1115

    l_debug_info := 'Update existing exclusive tax lines';
Line: 1121

      UPDATE ap_invoice_lines_all ail
         SET
       (ail.description,
        ail.amount,
        ail.base_amount,
        ail.cancelled_flag,
        ail.last_updated_by,
        ail.last_update_login,
        ail.last_update_date,
        ail.tax_regime_code,
        ail.tax,
        ail.tax_jurisdiction_code,
        ail.tax_status_code,
        ail.tax_rate_id,
        ail.tax_rate_code,
        ail.tax_rate,
	ail.generate_dists) =
	(
      SELECT
        zls.tax_regime_code||' - '||zls.tax,			-- description
        zls.tax_amt, 						-- amount
        zls.tax_amt_funcl_curr,					-- base_amount
        zls.cancel_flag,					-- cancelled_flag
        l_user_id,						-- last_updated_by
        l_login_id,						-- last_update_login
        l_sysdate, 						-- last_update_date
        zls.tax_regime_code,	    				-- tax_regime_code
        zls.tax,		    				-- tax
        zls.tax_jurisdiction_code,  				-- tax_jurisdiction_code
        zls.tax_status_code,	    				-- tax_status_code
        zls.tax_rate_id,	    				-- tax_rate_id
        zls.tax_rate_code,	    				-- tax_rate_code
        zls.tax_rate, 		    				-- tax_rate
	DECODE(ail.generate_dists,'D','D','Y')		        -- generate_dists  bug 5460342
        FROM zx_lines_summary zls
       WHERE zls.summary_tax_line_id		= ail.summary_tax_line_id
         AND nvl(zls.reporting_only_flag, 'N')	= 'N'
       )
       WHERE ail.invoice_id = P_Invoice_Header_Rec.invoice_id
	 AND ail.line_type_lookup_code	= 'TAX'
         AND EXISTS
	       	    (SELECT ls.summary_tax_line_id
                       FROM zx_lines_summary ls
                      WHERE ls.summary_tax_line_id		= ail.summary_tax_line_id
                        AND ls.trx_id				= ail.invoice_id
                        AND NVL(ls.tax_amt_included_flag, 'N')	= 'N'
                        AND NVL(ls.self_assessed_flag, 'N')	= 'N'
                        AND NVL(ls.reporting_only_flag, 'N')	= 'N');
Line: 1190

       for manual tax lines and tax only lines so that we do not delete and regenerate the tax lines . */
    -------------------------------------------------------------------
    l_debug_info := 'Update summary tax line id for manual tax lines';
Line: 1199

      UPDATE ap_invoice_lines_all ail
      SET ail.summary_tax_line_id = (SELECT  zl.summary_tax_line_id
                                            FROM zx_lines zl
                                            WHERE zl.application_id 	 =  200
                                            AND zl.entity_code 	 =  'AP_INVOICES'
                                            AND zl.event_class_code IN
					        ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                                            AND zl.trx_id 	= ail.invoice_id
                                            AND zl.tax_regime_code = ail.tax_regime_code
                                            AND zl.tax = ail.tax
                                            AND zl.tax_status_code = ail.tax_status_code
                                            AND (zl.tax_rate_code = ail.tax_rate_code OR zl.tax_rate_id = ail.tax_rate_id)
					    AND (zl.tax_jurisdiction_code = ail.tax_jurisdiction_code OR zl.tax_jurisdiction_code IS NULL)
                                            AND zl.tax_rate = ail.tax_rate
                                            AND zl.manually_entered_flag = 'Y'
                                            AND nvl(zl.reporting_only_flag, 'N') = 'N'
					    AND nvl(zl.self_assessed_flag, 'N') = 'N'
					    AND nvl(zl.cancel_flag, 'N') = nvl(ail.cancelled_flag,'N')
                                            AND rownum = 1       )
      WHERE ail.invoice_id = P_Invoice_Header_Rec.invoice_id
      AND ail.line_type_lookup_code	= 'TAX'
      AND ail.line_source in ('MANUAL LINE ENTRY','IMPORTED')
      AND ail.summary_tax_line_id IS NULL
      AND NOT EXISTS
           (SELECT 1
              FROM ap_invoice_lines_all ail2
             WHERE ail2.invoice_id = ail.invoice_id
               AND ail2.line_number <> ail.line_number
               AND ail2.tax_regime_code = ail.tax_regime_code
               AND ail2.tax = ail.tax
               AND ail2.tax_status_code = ail.tax_status_code
               AND (ail2.tax_rate_code = ail.tax_rate_code OR ail2.tax_rate_id = ail.tax_rate_id)
	       AND (ail2.tax_jurisdiction_code = ail.tax_jurisdiction_code OR ail2.tax_jurisdiction_code IS NULL)
               AND ail2.tax_rate = ail.tax_rate
               AND ail2.line_type_lookup_code = 'TAX'
               AND ail2.line_source in ('MANUAL LINE ENTRY','IMPORTED')
               AND ail2.line_group_number IS NOT NULL
               AND ail2.prorate_across_all_items='Y');    --Bug7331216
Line: 1257

    l_debug_info := 'Delete exclusive tax lines if required';
Line: 1263

      DELETE ap_invoice_lines_all ail
       WHERE ail.invoice_id = P_Invoice_Header_Rec.invoice_id
         AND ail.line_type_lookup_code = 'TAX'
         AND NOT EXISTS (SELECT ls.summary_tax_line_id
                           FROM zx_lines_summary ls
                          WHERE ls.summary_tax_line_id  = ail.summary_tax_line_id
                            AND ls.trx_id               = ail.invoice_id
                            AND NVL(ls.tax_amt_included_flag, 'N') = 'N'
                            AND NVL(ls.self_assessed_flag,    'N') = 'N'
                            AND NVL(ls.reporting_only_flag,   'N') = 'N');
Line: 1276

      DELETE FROM ap_allocation_rules ar
       WHERE ar.invoice_id = p_invoice_header_rec.invoice_id
         AND NOT EXISTS
                 (SELECT 'y'
                  FROM ap_invoice_lines_all l
                  WHERE l.invoice_id = ar.invoice_id
                  AND l.line_number = ar.chrg_invoice_line_number);
Line: 1284

       DELETE FROM ap_allocation_rule_lines arl
        WHERE arl.invoice_id = p_invoice_header_rec.invoice_id
          AND NOT EXISTS
                  (SELECT 'y'
                   FROM ap_invoice_lines_all l
                   WHERE l.invoice_id = arl.invoice_id
                   AND l.line_number = arl.chrg_invoice_line_number);
Line: 1338

    l_debug_info := 'Insert exclusive tax lines';
Line: 1344

      INSERT INTO ap_invoice_lines_all (
        invoice_id,
        line_number,
        line_type_lookup_code,
        requester_id,
        description,
        line_source,
        org_id,
        line_group_number,
        inventory_item_id,
        item_description,
        serial_number,
        manufacturer,
        model_number,
        warranty_number,
        generate_dists,
        match_type,
        distribution_set_id,
        account_segment,
        balancing_segment,
        cost_center_segment,
        overlay_dist_code_concat,
        default_dist_ccid,
        prorate_across_all_items,
        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,
        base_amount,
        rounding_amt,
        quantity_invoiced,
        unit_meas_lookup_code,
        unit_price,
        wfapproval_status,
        discarded_flag,
        original_amount,
        original_base_amount,
        original_rounding_amt,
        cancelled_flag,
        income_tax_region,
        type_1099,
        stat_amount,
        prepay_invoice_id,
        prepay_line_number,
        invoice_includes_prepay_flag,
        corrected_inv_id,
        corrected_line_number,
        po_header_id,
        po_line_id,
        po_release_id,
        po_line_location_id,
        po_distribution_id,
        rcv_transaction_id,
        final_match_flag,
        assets_tracking_flag,
        asset_book_type_code,
        asset_category_id,
        project_id,
        task_id,
        expenditure_type,
        expenditure_item_date,
        expenditure_organization_id,
        pa_quantity,
        pa_cc_ar_invoice_id,
        pa_cc_ar_invoice_line_num,
        pa_cc_processed_code,
        award_id,
        awt_group_id,
        reference_1,
        reference_2,
        receipt_verified_flag,
        receipt_required_flag,
        receipt_missing_flag,
        justification,
        expense_group,
        start_expense_date,
        end_expense_date,
        receipt_currency_code,
        receipt_conversion_rate,
        receipt_currency_amount,
        daily_amount,
        web_parameter_id,
        adjustment_reason,
        merchant_document_number,
        merchant_name,
        merchant_reference,
        merchant_tax_reg_number,
        merchant_taxpayer_id,
        country_of_supply,
        credit_card_trx_id,
        company_prepaid_invoice_id,
        cc_reversal_flag,
        creation_date,
        created_by,
        last_updated_by,
        last_update_date,
        last_update_login,
        program_application_id,
        program_id,
        program_update_date,
        request_id,
        attribute_category,
        attribute1,
        attribute2,
        attribute3,
        attribute4,
        attribute5,
        attribute6,
        attribute7,
        attribute8,
        attribute9,
        attribute10,
        attribute11,
        attribute12,
        attribute13,
        attribute14,
        attribute15,
        global_attribute_category,
        global_attribute1,
        global_attribute2,
        global_attribute3,
        global_attribute4,
        global_attribute5,
        global_attribute6,
        global_attribute7,
        global_attribute8,
        global_attribute9,
        global_attribute10,
        global_attribute11,
        global_attribute12,
        global_attribute13,
        global_attribute14,
        global_attribute15,
        global_attribute16,
        global_attribute17,
        global_attribute18,
        global_attribute19,
        global_attribute20,
        control_amount,
        assessable_value,
        total_rec_tax_amount,
        total_nrec_tax_amount,
        total_rec_tax_amt_funcl_curr,
        total_nrec_tax_amt_funcl_curr,
        included_tax_amount,
        primary_intended_use,
        ship_to_location_id,
        product_type,
        product_category,
        product_fisc_classification,
        user_defined_fisc_class,
        trx_business_category,
        summary_tax_line_id,
        tax_regime_code,
        tax,
        tax_jurisdiction_code,
        tax_status_code,
        tax_rate_id,
        tax_rate_code,
        tax_rate,
        tax_code_id)
      SELECT
        P_Invoice_Header_Rec.Invoice_Id,				-- invoice_id
        (SELECT NVL(MAX(ail2.line_number),0)
           FROM ap_invoice_lines_all ail2
          WHERE ail2.invoice_id =  zls.trx_id) + ROWNUM,  		-- line_number
        'TAX',								-- line_type_lookup_code
        null,								-- requester_id
        zls.tax_regime_code||' - '||zls.tax,				-- description
        'ETAX',								-- line_source
        P_Invoice_Header_Rec.org_id,   					-- org_id
        null,   							-- line_group_number
        null,   							-- inventory_item_id
        null,   							-- item_description
        null,   							-- serial_number
        null,   							-- manufacturer
        null,   							-- model_number
        null,   							-- warranty_number
        DECODE(NVL(zls.tax_only_line_flag, 'N'),
               'Y', 'D',
               'Y'),   							-- generate_dists
        DECODE(zls.applied_to_trx_id,
               null, 'NOT_MATCHED',
               'OTHER_TO_RECEIPT'),   					-- match_type
        null,   							-- distribution_set_id
        null,   							-- account_segment
        null,   							-- balancing_segment
        null,   							-- cost_center_segment
        null,   							-- overlay_dist_code_concat
        null,   							-- default_dist_ccid
        'N',   								-- prorate_across_all_items
        l_gl_date,   							-- accounting_date
        DECODE(NVL(zls.tax_only_line_flag, 'N'),
               'N', DECODE(zls.applied_to_trx_id,
                           null, null, l_period_name),
                l_period_name),   					-- period_name
        'N',   								-- deferred_acctg_flag
        null,   							-- def_acctg_start_date
        null,   							-- def_acctg_end_date
        null,   							-- def_acctg_number_of_periods
        null,   							-- def_acctg_period_type
        P_Invoice_Header_Rec.set_of_books_id,   			-- set_of_books_id
        zls.tax_amt,   							-- amount
        DECODE(P_Invoice_Header_Rec.invoice_currency_code,
               l_base_currency_code, NULL,
               zls.tax_amt_funcl_curr),    				-- base_amount
        null,   							-- rounding_amt
        null,   							-- quantity_invoiced
        null,   							-- unit_meas_lookup_code
        null,   							-- unit_price
        l_wfapproval_status,   						-- wfapproval_status
        'N',   								-- discarded_flag
        null,   							-- original_amount
        null,   							-- original_base_amount
        null,   							-- original_rounding_amt
        'N',   								-- cancelled_flag
        DECODE(ap.type_1099,
               '','',
               DECODE(l_combined_filing_flag,
                      'N', '',
                      DECODE(l_income_tax_region_flag,
                             'Y', aps.state,
                             l_income_tax_region))),  			-- income_tax_region
        ap.type_1099,   						-- type_1099
        null,   							-- stat_amount
        zls.applied_from_trx_id,   					-- prepay_invoice_id
        zls.applied_from_line_id,   					-- prepay_line_number
        prepay.invoice_includes_prepay_flag,   				-- invoice_includes_prepay_flag
        zls.adjusted_doc_trx_id,   					-- corrected_inv_id
        -- zls.adjusted_doc_line_id,   					-- corrected_line_number
        null,								-- corrected_line_number
        null,   							-- po_header_id
        null,   							-- po_line_id
        null,   							-- po_release_id
        null,   							-- po_line_location_id
        null,   							-- po_distribution_id
        zls.applied_to_trx_id,						-- rcv_transaction_id
        'N',   								-- final_match_flag
        null,   							-- assets_tracking_flag
        null,   							-- asset_book_type_code
        null,   							-- asset_category_id
        null,   							-- project_id
        null,   							-- task_id
        null,   							-- expenditure_type
        null,   							-- expenditure_item_date
        null,   							-- expenditure_organization_id
        null,   							-- pa_quantity
        null,   							-- pa_cc_ar_invoice_id
        null,   							-- pa_cc_ar_invoice_line_num
        null,   							-- pa_cc_processed_code
        null,   							-- award_id
        DECODE(l_awt_include_tax_amt,
               'N', null,
               DECODE(zls.applied_from_trx_id,
                      null, P_Invoice_Header_Rec.awt_group_id,
                      prepay.awt_group_id)),   				-- awt_group_id
        null,   							-- reference_1
        null,   							-- reference_2
        null,   							-- receipt_verified_flag
        null,   							-- receipt_required_flag
        null,   							-- receipt_missing_flag
        null,   							-- justification
        null,   							-- expense_group
        null,   							-- start_expense_date
        null,   							-- end_expense_date
        null,   							-- receipt_currency_code
        null,   							-- receipt_conversion_rate
        null,   							-- receipt_currency_amount
        null,   							-- daily_amount
        null,   							-- web_parameter_id
        null,   							-- adjustment_reason
        null,   							-- merchant_document_number
        null,   							-- merchant_name
        null,   							-- merchant_reference
        null,   							-- merchant_tax_reg_number
        null,								-- merchant_taxpayer_id
        null,								-- country_of_supply
        null,								-- credit_card_trx_id
        null,								-- company_prepaid_invoice_id
        null,								-- cc_reversal_flag
        l_sysdate,							-- creation_date
        l_user_id,   							-- created_by
        l_user_id,   							-- last_updated_by
        l_sysdate,   							-- last_update_date
        l_login_id,   							-- last_update_login
        null,   							-- program_application_id
        null,   							-- program_id
        null,   							-- program_update_date
        null,   							-- request_id
        zls.attribute_category,   					-- attribute_category
        zls.attribute1,   						-- attribute1
        zls.attribute2,   						-- attribute2
        zls.attribute3,   						-- attribute3
        zls.attribute4,   						-- attribute4
        zls.attribute5,   						-- attribute5
        zls.attribute6,   						-- attribute6
        zls.attribute7,   						-- attribute7
        zls.attribute8,   						-- attribute8
        zls.attribute9,   						-- attribute9
        zls.attribute10,   						-- attribute10
        zls.attribute11,   						-- attribute11
        zls.attribute12,   						-- attribute12
        zls.attribute13,   						-- attribute13
        zls.attribute14,   						-- attribute14
        zls.attribute15,   						-- attribute15
        zls.global_attribute_category,   				-- global_attribute_category
        zls.global_attribute1,   					-- global_attribute1
        zls.global_attribute2,   					-- global_attribute2
        zls.global_attribute3,   					-- global_attribute3
        zls.global_attribute4,   					-- global_attribute4
        zls.global_attribute5,   					-- global_attribute5
        zls.global_attribute6,   					-- global_attribute6
        zls.global_attribute7,   					-- global_attribute7
        zls.global_attribute8,   					-- global_attribute8
        zls.global_attribute9,   					-- global_attribute9
        zls.global_attribute10,   					-- global_attribute10
        zls.global_attribute11,   					-- global_attribute11
        zls.global_attribute12,   					-- global_attribute12
        zls.global_attribute13,   					-- global_attribute13
        zls.global_attribute14,   					-- global_attribute14
        zls.global_attribute15,   					-- global_attribute15
        zls.global_attribute16,   					-- global_attribute16
        zls.global_attribute17,   					-- global_attribute17
        zls.global_attribute18,   					-- global_attribute18
        zls.global_attribute19,   					-- global_attribute19
        zls.global_attribute20,   					-- global_attribute20
        null,   							-- control_amount
        null,   							-- assessable_value
        null,   							-- total_rec_tax_amount
        null,   							-- total_nrec_tax_amount
        null,   							-- total_rec_tax_amt_funcl_curr
        null,   							-- total_nrec_tax_amt_funcl_curr
        null,   							-- included_tax_amount
        null,   							-- primary_intended_use
        null,   							-- ship_to_location_id
        null,   							-- product_type
        null,   							-- product_category
        null,   							-- product_fisc_classification
        null,   							-- user_defined_fisc_class
        null,   							-- trx_business_category
        zls.summary_tax_line_id,   					-- summary_tax_line_id
        zls.tax_regime_code,   						-- tax_regime_code
        zls.tax,   							-- tax
        zls.tax_jurisdiction_code,   					-- tax_jurisdiction_code
        zls.tax_status_code,   						-- tax_status_code
        zls.tax_rate_id,   						-- tax_rate_id
        zls.tax_rate_code,   						-- tax_rate_code
        zls.tax_rate,   						-- tax_rate
        null   								-- tax_code_id
     FROM ap_invoices_all       ai,
          ap_suppliers          ap,
          ap_supplier_sites_all aps,
          zx_lines_summary      zls,
          ap_invoice_lines_all  prepay
    WHERE ai.invoice_id				= p_invoice_header_rec.invoice_id
      AND ai.vendor_id                          = ap.vendor_id
      AND ai.vendor_site_id                     = aps.vendor_site_id
      AND zls.application_id 			= 200
      AND zls.entity_code 			= 'AP_INVOICES'
      AND zls.event_class_code			IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
      AND zls.trx_id 				= ai.invoice_id
      AND NVL(zls.tax_amt_included_flag, 'N') 	= 'N'
      AND NVL(zls.self_assessed_flag, 'N') 	= 'N'
      AND NVL(zls.reporting_only_flag, 'N') 	= 'N'
      AND zls.applied_from_trx_id  		= prepay.invoice_id(+)
      AND zls.applied_from_line_id 		= prepay.line_number(+)
      AND NOT EXISTS (SELECT il.summary_tax_line_id
                        FROM ap_invoice_lines_all il
                       WHERE il.invoice_id = ai.invoice_id
                         AND il.summary_tax_line_id = zls.summary_tax_line_id)
      AND EXISTS
          (SELECT 'Recoupment Exists'
           FROM    ZX_LINES ZL
           WHERE   ZL.application_id      = ZLS.application_id
           AND     ZL.entity_code         = ZLS.entity_code
           AND     ZL.event_class_code    = ZLS.event_class_code
           AND     ZL.trx_id              = ZLS.trx_id
           AND     ((nvl(ZL.tax_only_line_flag,'N') <> 'Y'
                     and sign(ZL.TRX_LINE_ID)       <> -1)
                    OR nvl(ZL.tax_only_line_flag,'N') = 'Y')
           AND     ZL.SUMMARY_TAX_LINE_ID = ZLS.SUMMARY_TAX_LINE_ID);
Line: 1751

    l_debug_info := 'Update Inclusive tax amount';
Line: 1758

      UPDATE ap_invoice_lines_all ail
         SET ail.included_tax_amount =
             (SELECT /*+ index(ZL ZX_LINES_U1) */SUM(NVL(zl.tax_amt, 0))
                FROM zx_lines zl
               WHERE zl.application_id 	 =  200
                 AND zl.entity_code 	 =  'AP_INVOICES'
		 AND zl.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                 AND zl.trx_id 		= ail.invoice_id
                 AND zl.trx_line_id 	= ail.line_number
                 AND NVL(zl.self_assessed_flag,    'N')	= 'N'
                 AND NVL(zl.reporting_only_flag,   'N') = 'N'
                 AND NVL(zl.tax_amt_included_flag, 'N') = 'Y')
       WHERE ail.invoice_id = P_Invoice_Header_Rec.invoice_id
         AND ail.line_type_lookup_code NOT IN ('TAX', 'AWT');
Line: 1805

	   IF NOT AP_ALLOCATION_RULES_PKG.insert_tax_allocations (
				          P_Invoice_Header_Rec.invoice_id,
				          L_Item_Line.line_number,
				          P_error_code ) THEN
	      NULL;
Line: 1838

    l_debug_info := 'Update total_tax_amount and self_assessed tax';
Line: 1844

      UPDATE ap_invoices_all ai
         SET (ai.total_tax_amount,
              ai.self_assessed_tax_amount) =
             (SELECT SUM(DECODE(NVL(zls.self_assessed_flag, 'N'),
                                'N', NVL(zls.tax_amt, 0),
                                0)),
                     SUM(DECODE(NVL(zls.self_assessed_flag, 'N'),
                                'Y', NVL(zls.tax_amt, 0),
                                 0))
                FROM zx_lines_summary zls
	       WHERE zls.application_id   = 200
		 AND zls.entity_code      = 'AP_INVOICES'
		 AND zls.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                 AND zls.trx_id 	= ai.invoice_id
                 AND NVL(zls.reporting_only_flag, 'N') = 'N')
       WHERE ai.invoice_id = P_Invoice_Header_Rec.invoice_id
       RETURNING ai.total_tax_amount, ai.self_assessed_tax_amount
            INTO l_total_tax_amount, l_self_assessed_tax_amt;
Line: 1883

    l_debug_info := 'Update tax_already_calculated_flag';
Line: 1889

      UPDATE ap_invoice_lines_all ail
         SET ail.tax_already_calculated_flag = 'Y'
       WHERE ail.invoice_id = P_invoice_header_rec.invoice_id
         AND ail.line_type_lookup_code NOT IN ('TAX', 'AWT')
         AND NVL(ail.tax_already_calculated_flag, 'N') = 'N';
Line: 1898

		      we would need to pass event_type as UPDATED.
         AND EXISTS
             ( SELECT zl.tax_line_id
                 FROM zx_lines zl
                WHERE zl.trx_id = ail.invoice_id
                  AND zl.trx_line_id = ail.line_number
                  AND zl.application_id = 200
                  AND zl.entity_code = 'AP_INVOICES'
                  AND nvl(zl.reporting_only_flag, 'N') = 'N');
Line: 1915

    l_debug_info := 'Update Invoice Includes Prepay Flag';
Line: 1921

    UPDATE ap_invoice_lines_all tax
       SET tax.invoice_includes_prepay_flag = 'Y'
     WHERE tax.invoice_id		=  P_Invoice_Header_Rec.Invoice_Id
       AND tax.line_type_lookup_code	= 'TAX'
       AND EXISTS
           (SELECT 'Prepay App Exists'
            FROM   ap_invoice_lines_all prepay
            WHERE  prepay.invoice_id 		= tax.invoice_id
            AND    prepay.line_type_lookup_code = 'PREPAY'
            AND    prepay.prepay_invoice_id 	= tax.prepay_invoice_id
            AND    prepay.prepay_line_number 	= tax.prepay_line_number
            AND    prepay.invoice_includes_prepay_flag = 'Y');
Line: 1959

 |      creation, update, or delete of existing distributions and TIPV and
 |      TERV distributions if required.
 |      It also handles the creation, update or delete of self-assessed
 |      distributions.
 |
 |  PARAMETERS
 |      P_Invoice_Header_Rec - Header info
 |      P_All_Error_Messages - Should API return 1 error message or allow
 |                             calling point to get them from message stack
 |      P_error_code - Error code to be returned
 |      P_calling_sequence -  Calling sequence
 |
 |  MODIFICATION HISTORY
 |    DATE          Author         Action
 |    23-OCT-2003   SYIDNER        Created
 |    05-MAR-2004   SYIDNER        Included changes for returning of tax
 |                                 distributions related to prepayment
 |                                 application distributions (PREPAY)
 |                                 In this case only the primary distribution
 |                                 should be created for the total value of
 |                                 the distribution (same as eTax.) No tax
 |                                 variances will be created for PREPAY type
 |                                 distributions
 *============================================================================*/

  FUNCTION Return_Tax_Distributions(
             P_Invoice_Header_Rec        IN  ap_invoices_all%ROWTYPE,
             P_All_Error_Messages        IN  VARCHAR2,
             P_Error_Code                OUT NOCOPY VARCHAR2,
             P_Calling_Sequence          IN  VARCHAR2) RETURN BOOLEAN
  IS

    l_debug_info		VARCHAR2(240);
Line: 2096

    CURSOR insert_tax_dist IS
      SELECT /*+ leading(gt,zd) cardinality(gt,1) */
         zd.gl_date accounting_date , --Bug6809792
         /*For tax distributions accounting date will be stamped from zx_rec_nrec_dist
           Ebtax will now store accounting date of opne period in their table*/
         decode(NVL(zl.tax_only_line_flag,'N'),
                               'Y',parent_tax_line.default_dist_ccid,
                                parent_taxable_dist.dist_code_combination_id) 			dist_code_combination_id, ---for 6010950
        -- this ccid is a temporary value that will be used if other
        -- conditions are met before inserting the tax distribution.
        DECODE(NVL(zd.recoverable_flag, 'N'),
               'Y', 'REC_TAX',
               'N', 'NONREC_TAX') 					line_type_lookup_code,
        ap_utilities_pkg.get_gl_period_name(zd.gl_date,ai.org_id)	period_name,
        -- included the decode as part of the prepayment changes.
        -- since for prepayment tax variances will not be created,
        -- the dist amount should be the total including variances
        DECODE(parent_item_line.line_type_lookup_code,
               'PREPAY', zd.rec_nrec_tax_amt,
               decode(parent_taxable_dist.line_type_lookup_code, 'PREPAY', zd.rec_nrec_tax_amt,
               decode(nvl(zd.recoverable_flag,'N'),
			  'Y', zd.rec_nrec_tax_amt,
				(NVL(zd.rec_nrec_tax_amt, 0) -
					 get_tv(zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
						nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
						zd.ref_per_trx_curr_unit_nr_amt, zd.price_diff, parent_tax_line.corrected_inv_id,
						parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, ai.invoice_currency_code,
						parent_item_line.match_type, zd.unit_price)))))
										amount,
	ap_utilities_pkg.ap_round_currency(
        DECODE(parent_item_line.line_type_lookup_code,
		'PREPAY', zd.rec_nrec_tax_amt_funcl_curr,
                decode(parent_taxable_dist.line_type_lookup_code, 'PREPAY', zd.rec_nrec_tax_amt_funcl_curr,
                decode(nvl(zd.recoverable_flag,'N'),
		       'Y', zd.rec_nrec_tax_amt_funcl_curr,
			     (NVL(zd.rec_nrec_tax_amt_funcl_curr, 0) -
				    (get_tv_base
					(zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt, nvl(zd.ref_doc_per_unit_nrec_tax_amt,0),
					 zd.per_trx_curr_unit_nr_amt, zd.ref_per_trx_curr_unit_nr_amt, nvl(zd.currency_conversion_rate, 1),
					 zd.ref_doc_curr_conv_rate, zd.price_diff, parent_tax_line.corrected_inv_id,
					 parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, asp.base_currency_code,
					 parent_item_line.match_type, zd.unit_price) +
				     get_terv
					(zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate, zd.applied_to_doc_curr_conv_rate,
					 NULL, zd.per_unit_nrec_tax_amt, nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
					 parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code, parent_tax_line.line_source,
					 asp.base_currency_code)))))),
					 asp.base_currency_code)		base_amount,
        -- included the decode as part of the prepayment changes.
        -- since for prepayments tax variances will not be created,
        -- the base_amount should be the total including variances
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', parent_item_line.description,
		'N', parent_tax_line.description) 				description,
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', DECODE(parent_item_line.type_1099,
			    NULL, NULL,
			    parent_item_line.income_tax_region),
         	'N', DECODE(parent_tax_line.type_1099,
                	    NULL, NULL,
			    parent_tax_line.income_tax_region))			income_tax_region,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.po_distribution_id) 			po_distribution_id,
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', parent_item_line.type_1099,
		'N', parent_tax_line.type_1099) 				type_1099,
        zd.attribute1 								attribute1,
        zd.attribute10 								attribute10,
        zd.attribute11 								attribute11,
        zd.attribute12 								attribute12,
        zd.attribute13 								attribute13,
        zd.attribute14 								attribute14,
        zd.attribute15 								attribute15,
        zd.attribute2 								attribute2,
        zd.attribute3 								attribute3,
        zd.attribute4 								attribute4,
        zd.attribute5 								attribute5,
        zd.attribute6 								attribute6,
        zd.attribute7 								attribute7,
        zd.attribute8 								attribute8,
        zd.attribute9 								attribute9,
        zd.attribute_category 							attribute_category,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.expenditure_item_date)			expenditure_item_date,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.expenditure_organization_id)		expenditure_organization_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.expenditure_type) 			expenditure_type,
        parent_taxable_dist.parent_invoice_id 					parent_invoice_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', 'E',
         	'N', parent_taxable_dist.pa_addition_flag) 			pa_addition_flag,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.pa_quantity) pa_quantity,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.project_accounting_context)		project_accounting_context,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.project_id)				project_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.task_id) 				task_id,
        DECODE(NVL(asp.allow_awt_flag, 'N'),
               'Y', DECODE(NVL(pvs.allow_awt_flag, 'N'),
                      'Y', DECODE(NVL(asp.awt_include_tax_amt, 'N'),
                             'Y', DECODE(NVL(zd.inclusive_flag, 'N'),
                                    'Y', DECODE(zd.applied_from_tax_dist_id,
                                           null, parent_item_line.awt_group_id,
                                           ap_etax_utility_pkg.Get_Prepay_Awt_Group_Id(
                                             parent_taxable_dist.prepay_distribution_id,
                                             P_Calling_Sequence)),
                                    'N',parent_tax_line.awt_group_id), --Bug6648050
                             NULL),
                      NULL),
               NULL) 								awt_group_id,
              --Bug6505640 Populating DFF's from Invoice distributions instead of Tax dists
		parent_taxable_dist.global_attribute_category 						global_attribute_category,
		parent_taxable_dist.global_attribute1 							global_attribute1,
		parent_taxable_dist.global_attribute2 							global_attribute2,
		parent_taxable_dist.global_attribute3 							global_attribute3,
		parent_taxable_dist.global_attribute4 							global_attribute4,
		parent_taxable_dist.global_attribute5 							global_attribute5,
		parent_taxable_dist.global_attribute6 							global_attribute6,
		parent_taxable_dist.global_attribute7 							global_attribute7,
		parent_taxable_dist.global_attribute8 							global_attribute8,
		parent_taxable_dist.global_attribute9 							global_attribute9,
		parent_taxable_dist.global_attribute10 							global_attribute10,
		parent_taxable_dist.global_attribute11 							global_attribute11,
		parent_taxable_dist.global_attribute12 							global_attribute12,
		parent_taxable_dist.global_attribute13 							global_attribute13,
		parent_taxable_dist.global_attribute14 							global_attribute14,
		parent_taxable_dist.global_attribute15 							global_attribute15,
		parent_taxable_dist.global_attribute16 							global_attribute16,
		parent_taxable_dist.global_attribute17 							global_attribute17,
		parent_taxable_dist.global_attribute18 							global_attribute18,
		parent_taxable_dist.global_attribute19 							global_attribute19,
		parent_taxable_dist.global_attribute20 							global_attribute20,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.award_id) 				award_id,
        DECODE(zd.ref_doc_dist_id,
		NULL, DECODE(zl.applied_to_trx_id,
              			NULL, 'NOT_MATCHED',
              			'OTHER_TO_RECEIPT'),
		'NOT_MATCHED') 							dist_match_type,
         DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
         	'N', parent_tax_line.rcv_transaction_id) 			rcv_transaction_id,
        zd.recoverable_flag 							tax_recoverable_flag,
        parent_taxable_dist.cancellation_flag 					cancellation_flag,
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', zd.trx_line_id,
		'N', nvl(parent_tax_line.line_number,
                         parent_taxable_dist.invoice_line_number)) 		invoice_line_number,
        parent_taxable_dist.corrected_invoice_dist_id 				corrected_invoice_dist_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		zd.func_curr_rounding_adjustment) 				rounding_amt,
        -- the rounding amount in the non-recoverable case will be populated
        -- to the primary distribution later in the cycle.
        decode(NVL(zl.tax_only_line_flag,'N'),
                     'Y', NULL, zd.trx_line_dist_id)				charge_applicable_to_dist_id,
        DECODE(zl.ref_doc_trx_id,
          	NULL, 'CANDIDATE', 'PERMANENT') 				distribution_class,
        zd.tax_rate_id 								tax_code_id,
        zd.rec_nrec_tax_dist_id 						detail_tax_dist_id,
        zd.rec_nrec_rate 							rec_nrec_rate,
        zd.recovery_rate_id 							recovery_rate_id,
        zd.recovery_rate_code 							recovery_rate_name,
        zd.recovery_type_code 							recovery_type_code,
        zd.summary_tax_line_id 							summary_tax_line_id,
        null									extra_po_erv,
        zd.taxable_amt								taxable_amount,
        zd.taxable_amt_funcl_curr 						taxable_base_amount,
        pd.accrue_on_receipt_flag 						accrue_on_receipt_flag,
        asp.allow_flex_override_flag 						allow_flex_override_flag,
        fsp.purch_encumbrance_flag 						purch_encumbrance_flag,
        asp.org_id 								org_id,
        zd.tax_regime_id 							tax_regime_id,
        zd.tax_id 								tax_id,
        zd.tax_status_id 							tax_status_id,
        zl.tax_jurisdiction_id 							tax_jurisdiction_id,
        parent_taxable_dist.cancellation_flag 					parent_dist_cancellation_flag,
        parent_taxable_dist.reversal_flag 					parent_dist_reversal_flag,
        parent_taxable_dist.parent_reversal_id 					parent_dist_parent_reversal_id,
        zd.reversed_tax_dist_id 						reversed_tax_dist_id,
        zd.adjusted_doc_tax_dist_id 						adjusted_doc_tax_dist_id,
        zd.applied_from_tax_dist_id 						applied_from_tax_dist_id,
        -- the prepay_distribution_id will be populated with
        -- invoice_distribution_id for the associated rec or
        -- nonrec tax distributions
        DECODE(parent_item_line.line_type_lookup_code,
               'PREPAY', AP_ETAX_UTILITY_PKG.get_dist_id_for_tax_dist_id
               			(zd.applied_from_tax_dist_id),
               decode(parent_taxable_dist.line_type_lookup_code,
		      'PREPAY', AP_ETAX_UTILITY_PKG.get_dist_id_for_tax_dist_id
                                       (zd.applied_from_tax_dist_id), NULL))	prepay_distribution_id,
        DECODE(parent_item_line.line_type_lookup_code,
               'PREPAY', DECODE(NVL(zd.recoverable_flag, 'N'),
				'N', (zd.prd_tax_amt - zd.rec_nrec_tax_amt), NULL),
               NULL) 								prepay_tax_diff_amount,
       ai.invoice_id								invoice_id,
       ai.batch_id								batch_id,
       ai.set_of_books_id							set_of_books_id,
       zd.account_source_tax_rate_id						account_source_tax_rate_id
  FROM zx_trx_headers_gt                gt,
       zx_rec_nrec_dist                 zd,
       zx_lines                         zl,
       ap_invoices_all                  ai,
       ap_supplier_sites_all            pvs,
       ap_system_parameters_all         asp,
       financials_system_params_all     fsp,
       po_distributions_all             pd,
       ap_invoice_lines_all             parent_tax_line,
       ap_invoice_lines_all             parent_item_line,
       ap_invoice_distributions_all     parent_taxable_dist
 WHERE gt.APPLICATION_ID                        = zd.APPLICATION_ID
   AND gt.ENTITY_CODE                           = zd.ENTITY_CODE
   AND gt.EVENT_CLASS_CODE                      = zd.EVENT_CLASS_CODE
   AND gt.TRX_ID                                = zd.TRX_ID
   AND zd.tax_line_id                           = zl.tax_line_id
   AND gt.trx_id                                = ai.invoice_id
   AND ai.vendor_site_id                        = pvs.vendor_site_id
   AND ai.set_of_books_id                       = asp.set_of_books_id
   AND ai.org_id                                = asp.org_id
   AND asp.set_of_books_id                      = fsp.set_of_books_id
   AND asp.org_id                               = fsp.org_id
   AND NVL(zd.self_assessed_flag, 'N')          = 'N'
   AND NVL(zl.reporting_only_flag, 'N')         = 'N'
   AND parent_taxable_dist.po_distribution_id   = pd.po_distribution_id (+)
   AND zd.trx_id                                = parent_tax_line.invoice_id (+)
   AND zd.summary_tax_line_id                   = parent_tax_line.summary_tax_line_id (+)
   AND zd.trx_id                                = parent_item_line.invoice_id (+)
   AND zd.trx_line_id                           = parent_item_line.line_number (+)
   AND zd.trx_id                                = parent_taxable_dist.invoice_id (+)
   AND zd.trx_line_dist_id                      = parent_taxable_dist.invoice_distribution_id (+)
   AND (zd.ref_doc_application_id IS NULL
        or (zd.ref_doc_application_id IS NOT NULL
            and (nvl(zd.recoverable_flag, 'N') = 'Y'
                 or (parent_taxable_dist.prepay_distribution_id IS NOT NULL
                     and (parent_item_line.line_type_lookup_code IS NULL
			  or parent_item_line.line_type_lookup_code <> 'PREPAY'))
		 or ( zd.rec_nrec_tax_amt = 0
		    and nvl(zd.recoverable_flag, 'N') = 'N'
	/* Commented for Bug 6906867*/	/*    and zd.rec_nrec_rate = 100*/  )  -- added the condition for bug fix 6695517
                 or zd.rec_nrec_tax_amt <> ap_etax_utility_pkg.get_tv
                                            (zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
                                             nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
                                             zd.ref_per_trx_curr_unit_nr_amt, zd.price_diff, parent_tax_line.corrected_inv_id,
                                             parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, ai.invoice_currency_code,
					     parent_item_line.match_type, zd.unit_price))))
--   AND ((zd.recoverable_flag = 'N'  AND zd.rec_nrec_rate<>0) OR zd.recoverable_flag = 'Y') --bug 6350100   -- commented out the condition for bug fix 6695517
   AND NOT EXISTS
      (SELECT aid.detail_tax_dist_id
         FROM ap_invoice_distributions_all aid
        WHERE aid.invoice_id            = zd.trx_id
          AND aid.detail_tax_dist_id    = zd.rec_nrec_tax_dist_id
          AND aid.line_type_lookup_code IN ('REC_TAX','NONREC_TAX'))
   AND (parent_taxable_dist.dist_match_type is null
        or nvl(zd.recoverable_flag, 'N') = 'Y'
        or parent_taxable_dist.dist_match_type <> 'PRICE_CORRECTION')
   AND (parent_taxable_dist.prepay_distribution_id IS NULL
        or (parent_taxable_dist.prepay_distribution_id IS NOT NULL
            and (parent_item_line.line_number IS NOT NULL
                 or zd.trx_line_id = (select -1 * (aid.invoice_id || aid.invoice_line_number || parent_taxable_dist.invoice_line_number)
                                        from ap_invoice_distributions_all aid
                                       where aid.invoice_distribution_id = parent_taxable_dist.prepay_distribution_id))))
   -- Bug 7462582
   -- Reverting the fixes done in bugs 6805527 and 7389822 as Etax bug 7515711 will take care of these fixes.
   /* Added by schitlap, epajaril to fix the issue in Bug 6805527 */
   /*AND (nvl(parent_taxable_dist.reversal_flag, 'N') <> 'Y'
        OR zd.reversed_tax_dist_id IS NULL) -- 7389822*/
  ORDER BY detail_tax_dist_id;
Line: 2377

  CURSOR insert_tax_variances IS
	SELECT /*+ leading(gt,zd) cardinality(gt,1) */
                zd.gl_date accounting_date , --Bug6809792
                /*For tax distributions accounting date will be stamped from zx_rec_nrec_dist
                  Ebtax will now store accounting date of opne period in their table*/
		(CASE dist.line_type
			WHEN 'TERV' THEN
			    DECODE(pd.destination_type_code, 'EXPENSE', pd.code_combination_id,
				   parent_taxable_dist.dist_code_combination_id)
			ELSE
			    DECODE(pd.destination_type_code, 'EXPENSE',
				      DECODE(pd.accrue_on_receipt_flag, 'Y', pd.code_combination_id,
				             parent_taxable_dist.dist_code_combination_id),
				   pd.variance_account_id)
		END)												dist_code_combination_id,
	        (CASE dist.line_type
			WHEN 'TIPV' THEN 'TIPV'
			WHEN 'TERV' THEN 'TERV'
			WHEN 'TRV'  THEN 'TRV'
	        END)												line_type_lookup_code,
        	ap_utilities_pkg.get_gl_period_name(zd.gl_date,ai.org_id)					period_name,
	        (CASE dist.line_type
                 WHEN 'TIPV' THEN
		        decode(parent_taxable_dist.dist_match_type,
				'PRICE_CORRECTION', zd.rec_nrec_tax_amt,
				ap_etax_utility_pkg.get_tipv(
					zd.rate_tax_factor, zd.trx_line_dist_qty,
			                nvl2(parent_taxable_dist.rcv_transaction_id,
						ap_etax_utility_pkg.get_converted_price
						(parent_taxable_dist.invoice_distribution_id), zd.unit_price),
					zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
					zd.price_diff, parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
					parent_tax_line.line_source, ai.invoice_currency_code,
					parent_item_line.match_type))
		 WHEN 'TRV' THEN
		        (ap_etax_utility_pkg.get_tv(
				zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
				nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
				zd.ref_per_trx_curr_unit_nr_amt, zd.price_diff, parent_tax_line.corrected_inv_id,
				parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, ai.invoice_currency_code,
				parent_item_line.match_type, zd.unit_price) -
		         ap_etax_utility_pkg.get_tipv(
				zd.rate_tax_factor, zd.trx_line_dist_qty,
		                nvl2(parent_taxable_dist.rcv_transaction_id,
					ap_etax_utility_pkg.get_converted_price
					(parent_taxable_dist.invoice_distribution_id), zd.unit_price),
				zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,per_trx_curr_unit_nr_amt),
				zd.price_diff, parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
				parent_tax_line.line_source, ai.invoice_currency_code, parent_item_line.match_type))
		 WHEN 'TERV' THEN 0
	         END)														amount,
	        (CASE dist.line_type
		 WHEN 'TIPV' THEN
		        ap_utilities_pkg.ap_round_currency(
	                        decode(parent_taxable_dist.dist_match_type,
	                                'PRICE_CORRECTION', zd.rec_nrec_tax_amt,
					ap_etax_utility_pkg.get_tipv_base(
						zd.rate_tax_factor, zd.trx_line_dist_qty,
				                nvl2(parent_taxable_dist.rcv_transaction_id,
							ap_etax_utility_pkg.get_converted_price
							(parent_taxable_dist.invoice_distribution_id), zd.unit_price),
						zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
						zd.price_diff, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate, NULL,
						parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
						parent_tax_line.line_source, ai.invoice_currency_code, asp.base_currency_code,
						parent_item_line.match_type)),
				asp.base_currency_code)
		 WHEN 'TRV' THEN
			ap_utilities_pkg.ap_round_currency(
			(ap_etax_utility_pkg.get_tv_base(
				zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
				nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
				zd.ref_per_trx_curr_unit_nr_amt, nvl(zd.currency_conversion_rate,1),
				zd.ref_doc_curr_conv_rate, zd.price_diff, parent_tax_line.corrected_inv_id,
				parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, asp.base_currency_code,
				parent_item_line.match_type, zd.unit_price) -
			ap_etax_utility_pkg.get_tipv_base(
				zd.rate_tax_factor, zd.trx_line_dist_qty,
		                nvl2(parent_taxable_dist.rcv_transaction_id,
					ap_etax_utility_pkg.get_converted_price
					(parent_taxable_dist.invoice_distribution_id), zd.unit_price),
				zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
				zd.price_diff, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate, NULL,
				parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
				parent_tax_line.line_source, ai.invoice_currency_code, asp.base_currency_code,
				parent_item_line.match_type) -
			decode (parent_tax_line.match_type, 'PRICE_CORRECTION', 0,
				ap_etax_utility_pkg.get_terv(
					zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate,
					zd.applied_to_doc_curr_conv_rate, NULL, zd.per_unit_nrec_tax_amt,
					nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
					parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
					parent_tax_line.line_source, asp.base_currency_code))), asp.base_currency_code)
		 WHEN 'TERV' THEN
			ap_utilities_pkg.ap_round_currency
			(ap_etax_utility_pkg.get_terv(
					zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate,
					zd.applied_to_doc_curr_conv_rate, NULL, zd.per_unit_nrec_tax_amt,
					nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
					parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
					parent_tax_line.line_source, asp.base_currency_code), asp.base_currency_code)
	        END)														base_amount,
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', parent_item_line.description,
		'N', parent_tax_line.description)							description,
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', DECODE(parent_item_line.type_1099,
			    NULL, NULL, parent_item_line.income_tax_region),
		'N', DECODE(parent_tax_line.type_1099,
			    NULL, NULL, parent_tax_line.income_tax_region))				income_tax_region,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.po_distribution_id)						po_distribution_id,
        DECODE(NVL(zd.inclusive_flag, 'N'),
		'Y', parent_item_line.type_1099,
		'N', parent_tax_line.type_1099) 							type_1099,
        zd.attribute1											attribute1,
        zd.attribute10 											attribute10,
        zd.attribute11 											attribute11,
        zd.attribute12 											attribute12,
        zd.attribute13 											attribute13,
        zd.attribute14 											attribute14,
        zd.attribute15 											attribute15,
        zd.attribute2 											attribute2,
        zd.attribute3 											attribute3,
        zd.attribute4 											attribute4,
        zd.attribute5 											attribute5,
        zd.attribute6 											attribute6,
        zd.attribute7 											attribute7,
        zd.attribute8 											attribute8,
        zd.attribute9 											attribute9,
        zd.attribute_category 										attribute_category,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.expenditure_item_date) 					expenditure_item_date,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.expenditure_organization_id)					expenditure_organization_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.expenditure_type)						expenditure_type,
        parent_taxable_dist.parent_invoice_id								parent_invoice_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', 'E',
		'N', parent_taxable_dist.pa_addition_flag)						pa_addition_flag,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.pa_quantity) 							pa_quantity,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.project_accounting_context)					project_accounting_context,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.project_id)							project_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_taxable_dist.task_id) 							task_id,
        DECODE(NVL(asp.allow_awt_flag, 'N'),
               'Y', DECODE(NVL(pvs.allow_awt_flag, 'N'),
                      'Y', DECODE(NVL(asp.awt_include_tax_amt, 'N'),
                             'Y', DECODE(NVL(zd.inclusive_flag, 'N'),
                                    'Y', DECODE(zd.applied_from_tax_dist_id,
                                           null, parent_item_line.awt_group_id,
                                           ap_etax_utility_pkg.Get_Prepay_Awt_Group_Id(
                                             parent_taxable_dist.prepay_distribution_id,
                                             P_Calling_Sequence)),
                             'N', parent_tax_line.awt_group_id),
                          NULL),
                      NULL),
               NULL) 											awt_group_id,
        zd.global_attribute_category									global_attribute_category,
        zd.global_attribute1										global_attribute1,
        zd.global_attribute2										global_attribute2,
        zd.global_attribute3										global_attribute3,
        zd.global_attribute4										global_attribute4,
        zd.global_attribute5										global_attribute5,
        zd.global_attribute6										global_attribute6,
        zd.global_attribute7										global_attribute7,
        zd.global_attribute8										global_attribute8,
        zd.global_attribute9										global_attribute9,
        zd.global_attribute10										global_attribute10,
        zd.global_attribute11										global_attribute11,
        zd.global_attribute12										global_attribute12,
        zd.global_attribute13										global_attribute13,
        zd.global_attribute14										global_attribute14,
        zd.global_attribute15										global_attribute15,
        zd.global_attribute16										global_attribute16,
        zd.global_attribute17										global_attribute17,
        zd.global_attribute18										global_attribute18,
        zd.global_attribute19										global_attribute19,
        zd.global_attribute20										global_attribute20,
        DECODE(NVL(zd.recoverable_flag, 'N'),
		'Y', NULL,
		'N', parent_taxable_dist.award_id) 							award_id,
        DECODE(zd.ref_doc_dist_id,
          	NULL, DECODE(zl.applied_to_trx_id,
				NULL, 'NOT_MATCHED',
				'OTHER_TO_RECEIPT'),
		'NOT_MATCHED')										dist_match_type,
         DECODE(NVL(zd.recoverable_flag, 'N'),
         	'Y', NULL,
         	'N', parent_tax_line.rcv_transaction_id) 						rcv_transaction_id,
        zd.recoverable_flag 										tax_recoverable_flag,
        parent_taxable_dist.cancellation_flag 								cancellation_flag,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         	'Y', zd.trx_line_id,
         	'N', parent_tax_line.line_number) 							invoice_line_number,
        parent_taxable_dist.corrected_invoice_dist_id 							corrected_invoice_dist_id,
        NULL rounding_amt,
        decode(NVL(zl.tax_only_line_flag,'N'),
                     'Y', NULL, zd.trx_line_dist_id)							charge_applicable_to_dist_id,
        DECODE(zl.ref_doc_trx_id,
          	NULL, 'CANDIDATE', 'PERMANENT') 							distribution_class,
        zd.tax_rate_id 											tax_code_id,
        zd.rec_nrec_tax_dist_id 									detail_tax_dist_id,
        zd.rec_nrec_rate 										rec_nrec_rate,
        zd.recovery_rate_id 										recovery_rate_id,
        zd.recovery_rate_code 										recovery_rate_name,
        zd.recovery_type_code 										recovery_type_code,
        zd.summary_tax_line_id 										summary_tax_line_id,
        NULL 												extra_po_erv,
        NULL 												taxable_amount,
        NULL 												taxable_base_amount,
        pd.accrue_on_receipt_flag 									accrue_on_receipt_flag,
        asp.allow_flex_override_flag 									allow_flex_override_flag,
        fsp.purch_encumbrance_flag 									purch_encumbrance_flag,
        asp.org_id 											org_id,
        zd.tax_regime_id 										tax_regime_id,
        zd.tax_id 											tax_id,
        zd.tax_status_id 										tax_status_id,
        zl.tax_jurisdiction_id 										tax_jurisdiction_id,
        parent_taxable_dist.cancellation_flag 								parent_dist_cancellation_flag,
        parent_taxable_dist.reversal_flag 								parent_dist_reversal_flag,
        parent_taxable_dist.parent_reversal_id 								parent_dist_parent_reversal_id,
        zd.reversed_tax_dist_id 									reversed_tax_dist_id,
        zd.adjusted_doc_tax_dist_id 									adjusted_doc_tax_dist_id,
        zd.applied_from_tax_dist_id  									applied_from_tax_dist_id,
        NULL 												prepay_distribution_id,
        NULL 												prepay_tax_diff_amount,
        ai.invoice_id                                                            			invoice_id,
        ai.batch_id                                                              			batch_id,
        ai.set_of_books_id                                                       			set_of_books_id,
        zd.account_source_tax_rate_id									account_source_tax_rate_id
  FROM zx_trx_headers_gt		gt,
       zx_rec_nrec_dist                 zd,
       zx_lines                         zl,
       ap_invoices_all                  ai,
       ap_supplier_sites_all            pvs,
       ap_system_parameters_all         asp,
       financials_system_params_all     fsp,
       po_distributions_all             pd,
       ap_invoice_lines_all             parent_tax_line,
       ap_invoice_lines_all             parent_item_line,
       ap_invoice_distributions_all     parent_taxable_dist,
       ap_line_temp_gt			dist
 WHERE gt.APPLICATION_ID                        = zd.APPLICATION_ID
   AND gt.ENTITY_CODE                           = zd.ENTITY_CODE
   AND gt.EVENT_CLASS_CODE                      = zd.EVENT_CLASS_CODE
   AND gt.TRX_ID                                = zd.TRX_ID
   AND zd.tax_line_id                           = zl.tax_line_id
   AND gt.trx_id                                = ai.invoice_id
   AND ai.vendor_site_id                        = pvs.vendor_site_id
   AND ai.set_of_books_id                       = asp.set_of_books_id
   AND ai.org_id                                = asp.org_id
   AND asp.set_of_books_id                      = fsp.set_of_books_id
   AND asp.org_id                               = fsp.org_id
   AND NVL(zd.recoverable_flag, 'N')    	= 'N'
   AND NVL(zd.self_assessed_flag, 'N')          = 'N'
   AND NVL(zl.reporting_only_flag, 'N')         = 'N'
   AND parent_taxable_dist.po_distribution_id   = pd.po_distribution_id(+)
   AND zd.trx_id                                = parent_tax_line.invoice_id (+)
   AND zd.summary_tax_line_id                   = parent_tax_line.summary_tax_line_id(+)
   AND zd.trx_id                                = parent_item_line.invoice_id(+)
   AND zd.trx_line_id                           = parent_item_line.line_number(+)
   AND zd.trx_id                                = parent_taxable_dist.invoice_id
   AND zd.trx_line_dist_id                      = parent_taxable_dist.invoice_distribution_id
   AND parent_item_line.line_type_lookup_code(+) <> 'PREPAY'
   AND parent_taxable_dist.line_type_lookup_code <> 'PREPAY'
   AND NOT EXISTS
      (SELECT aid.detail_tax_dist_id
         FROM ap_invoice_distributions_all aid
        WHERE aid.invoice_id            = zd.trx_id
          AND aid.detail_tax_dist_id    = zd.rec_nrec_tax_dist_id
          AND aid.line_type_lookup_code IN ('TIPV', 'TERV', 'TRV'))
   AND ((dist.line_type =  'TIPV'
	 and (ap_etax_utility_pkg.get_tipv
		(zd.rate_tax_factor, zd.trx_line_dist_qty,
		 nvl2(parent_taxable_dist.rcv_transaction_id,
			ap_etax_utility_pkg.get_converted_price
			(parent_taxable_dist.invoice_distribution_id), zd.unit_price),
		 zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
                 zd.price_diff, parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
		 parent_tax_line.line_source, ai.invoice_currency_code, parent_item_line.match_type) <> 0
	      or parent_taxable_dist.dist_match_type = 'PRICE_CORRECTION'
	     ))
	OR
	(dist.line_type =  'TRV'
	 and (ap_etax_utility_pkg.get_tv(
			zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
			nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
			zd.ref_per_trx_curr_unit_nr_amt, zd.price_diff, parent_tax_line.corrected_inv_id,
			parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, ai.invoice_currency_code,
			parent_item_line.match_type, zd.unit_price) -
	        ap_etax_utility_pkg.get_tipv(
			zd.rate_tax_factor, zd.trx_line_dist_qty,
                        nvl2(parent_taxable_dist.rcv_transaction_id,
                                ap_etax_utility_pkg.get_converted_price
                                (parent_taxable_dist.invoice_distribution_id), zd.unit_price),
			zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,per_trx_curr_unit_nr_amt),
			zd.price_diff, parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
			parent_tax_line.line_source, ai.invoice_currency_code, parent_item_line.match_type)) <> 0)
	OR
	(dist.line_type =  'TERV'
	 and (ap_etax_utility_pkg.get_terv(
			zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate,
			zd.applied_to_doc_curr_conv_rate, NULL, zd.per_unit_nrec_tax_amt,
			nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
			parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
			parent_tax_line.line_source, asp.base_currency_code)) <> 0))
    -- Bug 7462582
    -- Reverting the fixes done in bugs 6805527 and 7389822 as Etax bug 7515711 will take care of these fixes.
    /* Added by schitlap, epajaril to fix the issue in Bug 6805527 */
    /*AND (nvl(parent_taxable_dist.reversal_flag, 'N') <> 'Y'
        OR zd.reversed_tax_dist_id IS NULL) -- 7389822*/
  ORDER BY detail_tax_dist_id;
Line: 2704

  CURSOR update_tax_dist IS
      SELECT /*+ leading(gt,zd) cardinality(gt,1) */
        zd.gl_date accounting_date , --Bug6809792
         /*For tax distributions accounting date will be stamped from zx_rec_nrec_dist
           Ebtax will now store accounting date of opne period in their table*/
        parent_taxable_dist.dist_code_combination_id dist_code_combination_id,
        -- this ccid is a temporary value that will be used if other conditions
        -- are met before inserting the tax distribution
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', 'REC_TAX',
         'N', 'NONREC_TAX') line_type_lookup_code,
        ap_utilities_pkg.get_gl_period_name(zd.gl_date,ai.org_id)	period_name,
        DECODE(parent_item_line.line_type_lookup_code,
               'PREPAY', zd.rec_nrec_tax_amt,
               decode(parent_taxable_dist.line_type_lookup_code, 'PREPAY', zd.rec_nrec_tax_amt,
               decode(nvl(zd.recoverable_flag,'N'),
                          'Y', zd.rec_nrec_tax_amt,
                                (NVL(zd.rec_nrec_tax_amt, 0) -
                                         get_tv(zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
                                                nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
                                                zd.ref_per_trx_curr_unit_nr_amt, zd.price_diff, parent_tax_line.corrected_inv_id,
                                                parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, ai.invoice_currency_code,
						parent_item_line.match_type, zd.unit_price)))))
														amount,
        ap_utilities_pkg.ap_round_currency(
        DECODE(parent_item_line.line_type_lookup_code,
                'PREPAY', zd.rec_nrec_tax_amt_funcl_curr,
                decode(parent_taxable_dist.line_type_lookup_code, 'PREPAY', zd.rec_nrec_tax_amt_funcl_curr,
                decode(nvl(zd.recoverable_flag,'N'),
                       'Y', zd.rec_nrec_tax_amt_funcl_curr,
                             (NVL(zd.rec_nrec_tax_amt_funcl_curr, 0) -
                                    (get_tv_base
                                        (zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt, nvl(zd.ref_doc_per_unit_nrec_tax_amt,0),
                                         zd.per_trx_curr_unit_nr_amt, zd.ref_per_trx_curr_unit_nr_amt, nvl(zd.currency_conversion_rate, 1),
                                         zd.ref_doc_curr_conv_rate, zd.price_diff, parent_tax_line.corrected_inv_id,
                                         parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, asp.base_currency_code,
					 parent_item_line.match_type, zd.unit_price) +
                                     get_terv
                                        (zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate, zd.applied_to_doc_curr_conv_rate,
                                         NULL, zd.per_unit_nrec_tax_amt, nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
                                         parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code, parent_tax_line.line_source,
					 asp.base_currency_code)))))),
                                         asp.base_currency_code)                                                base_amount,
        -- included the decode as part of the prepayment changes.
        -- since for prepayment applic tax variances will not be created,
        -- the base_amount should be the total including variances
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', parent_item_line.description,
         'N', parent_tax_line.description) description,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', DECODE(parent_item_line.type_1099,
                NULL, NULL,
                parent_item_line.income_tax_region),
         'N', DECODE(parent_tax_line.type_1099,
                NULL, NULL,
                parent_tax_line.income_tax_region)) income_tax_region,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', parent_item_line.type_1099,
         'N', parent_tax_line.type_1099) type_1099,
-- bug 6914575: modify start
-- Populating DFF's from Invoice distributions instead of Tax dists
        aid.attribute1 attribute1,
        aid.attribute10 attribute10,
        aid.attribute11 attribute11,
        aid.attribute12 attribute12,
        aid.attribute13 attribute13,
        aid.attribute14 attribute14,
        aid.attribute15 attribute15,
        aid.attribute2 attribute2,
        aid.attribute3 attribute3,
        aid.attribute4 attribute4,
        aid.attribute5 attribute5,
        aid.attribute6 attribute6,
        aid.attribute7 attribute7,
        aid.attribute8 attribute8,
        aid.attribute9 attribute9,
        aid.attribute_category attribute_category,
-- bug 6914575: modify end
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_item_date) expenditure_item_date,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_organization_id)
           expenditure_organization_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_type) expenditure_type,
        parent_taxable_dist.parent_invoice_id parent_invoice_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', 'E',
         'N', parent_taxable_dist.pa_addition_flag) pa_addition_flag,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.pa_quantity) pa_quantity,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.project_accounting_context)
           project_accounting_context,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.project_id) project_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.task_id) task_id,
        aid.awt_group_id awt_group_id,
	--Bug6505640 Populating DFF's from Invoice distributions instead of Tax dists
        aid.global_attribute_category global_attribute_category,
        aid.global_attribute1 global_attribute1,
        aid.global_attribute2 global_attribute2,
        aid.global_attribute3 global_attribute3,
        aid.global_attribute4 global_attribute4,
        aid.global_attribute5 global_attribute5,
        aid.global_attribute6 global_attribute6,
        aid.global_attribute7 global_attribute7,
        aid.global_attribute8 global_attribute8,
        aid.global_attribute9 global_attribute9,
        aid.global_attribute10 global_attribute10,
        aid.global_attribute11 global_attribute11,
        aid.global_attribute12 global_attribute12,
        aid.global_attribute13 global_attribute13,
        aid.global_attribute14 global_attribute14,
        aid.global_attribute15 global_attribute15,
        aid.global_attribute16 global_attribute16,
        aid.global_attribute17 global_attribute17,
        aid.global_attribute18 global_attribute18,
        aid.global_attribute19 global_attribute19,
        aid.global_attribute20 global_attribute20,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.award_id) award_id,
        DECODE(zd.ref_doc_dist_id,
          NULL, DECODE(zl.applied_to_trx_id,
              NULL, 'NOT_MATCHED',
              'OTHER_TO_RECEIPT'),
          'NOT_MATCHED') dist_match_type,
         DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_tax_line.rcv_transaction_id) rcv_transaction_id,
        zd.recoverable_flag tax_recoverable_flag,
        parent_taxable_dist.cancellation_flag cancellation_flag,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', zd.trx_line_id,
         'N', nvl(parent_tax_line.line_number,
                  parent_taxable_dist.invoice_line_number)) invoice_line_number,
        parent_taxable_dist.corrected_invoice_dist_id corrected_invoice_dist_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
          'Y', NULL,
          zd.func_curr_rounding_adjustment) rounding_amt,
        -- This will update the rounding_amt in the recoverable dist
        -- for the non-recoverable the primary distribution will be
        -- updated later on
        decode(NVL(zl.tax_only_line_flag,'N'),
                     'Y', NULL, zd.trx_line_dist_id)	charge_applicable_to_dist_id,
        DECODE(zl.ref_doc_trx_id,
          NULL, 'CANDIDATE',
          'PERMANENT') distribution_class,
        zd.tax_rate_id tax_code_id,
        zd.rec_nrec_tax_dist_id detail_tax_dist_id,
        zd.rec_nrec_rate rec_nrec_rate,
        zd.recovery_rate_id recovery_rate_id,
        zd.recovery_rate_code recovery_rate_name,
        zd.recovery_type_code recovery_type_code,
        zd.taxable_amt taxable_amount,
        zd.taxable_amt_funcl_curr taxable_base_amount,
        zd.summary_tax_line_id summary_tax_line_id,
        null extra_po_erv,
        -- (zd.applied_to_doc_erv - zx.reference_doc_erv) null extra_po_erv,
        DECODE(parent_item_line.line_type_lookup_code,
          'PREPAY', DECODE(NVL(zd.recoverable_flag, 'N'),
                      'N', (zd.prd_tax_amt - zd.rec_nrec_tax_amt), NULL),
          NULL) prepay_tax_diff_amount,
        aid.invoice_distribution_id invoice_distribution_id,
        zd.account_source_tax_rate_id
  FROM  zx_trx_headers_gt		gt,
	zx_rec_nrec_dist                zd,
        zx_lines                        zl,
	ap_invoices_all                 ai,
        ap_invoice_distributions_all    aid,
        ap_supplier_sites_all           pvs,
        ap_system_parameters_all        asp,
        financials_system_params_all    fsp,
        po_distributions_all            pd,
        ap_invoice_lines_all            parent_tax_line,
        ap_invoice_lines_all            parent_item_line,
        ap_invoice_distributions_all    parent_taxable_dist
 WHERE  gt.APPLICATION_ID                        = zd.APPLICATION_ID
   AND  gt.ENTITY_CODE                           = zd.ENTITY_CODE
   AND  gt.EVENT_CLASS_CODE                      = zd.EVENT_CLASS_CODE
   AND  gt.TRX_ID                                = zd.TRX_ID
   AND  zd.tax_line_id                           = zl.tax_line_id
   AND  gt.trx_id                                = ai.invoice_id
   AND  ai.invoice_id                            = aid.invoice_id
   AND  aid.detail_tax_dist_id                   = zd.rec_nrec_tax_dist_id
   AND  aid.line_type_lookup_code                IN ('REC_TAX','NONREC_TAX')
   AND  nvl(aid.reversal_flag,'N')               <> 'Y'
   AND  ai.vendor_site_id                        = pvs.vendor_site_id
   AND  ai.set_of_books_id                       = asp.set_of_books_id
   AND  ai.org_id                                = asp.org_id
   AND  asp.set_of_books_id                      = fsp.set_of_books_id
   AND  asp.org_id                               = fsp.org_id
   AND  parent_taxable_dist.po_distribution_id   = pd.po_distribution_id(+)
   AND  zd.trx_id                                = parent_tax_line.invoice_id (+)
   AND  zd.summary_tax_line_id                   = parent_tax_line.summary_tax_line_id(+)
   AND  zd.trx_id                                = parent_item_line.invoice_id(+)
   AND  zd.trx_line_id                           = parent_item_line.line_number(+)
   AND  zd.trx_id                                = parent_taxable_dist.invoice_id(+)
   AND  zd.trx_line_dist_id                      = parent_taxable_dist.invoice_distribution_id(+);
Line: 2914

  CURSOR update_tax_variances IS
	SELECT /*+ leading(gt,zd) cardinality(gt,1) */
	         zd.gl_date accounting_date , --Bug6809792
                 /*For tax distributions accounting date will be stamped from zx_rec_nrec_dist
                   Ebtax will now store accounting date of opne period in their table*/
                (CASE aid.line_type_lookup_code
                        WHEN 'TERV' THEN
                            DECODE(pd.destination_type_code, 'EXPENSE', pd.code_combination_id,
                                   parent_taxable_dist.dist_code_combination_id)
                        ELSE
                            DECODE(pd.destination_type_code, 'EXPENSE',
                                      DECODE(pd.accrue_on_receipt_flag, 'Y', pd.code_combination_id,
                                             parent_taxable_dist.dist_code_combination_id),
                                   pd.variance_account_id)
                END)                                                                                            dist_code_combination_id,
	        (CASE aid.line_type_lookup_code
			WHEN 'TIPV' THEN 'TIPV'
			WHEN 'TERV' THEN 'TERV'
			WHEN 'TRV'  THEN 'TRV'
	        END)												line_type_lookup_code,
        	ap_utilities_pkg.get_gl_period_name(zd.gl_date,ai.org_id)					period_name,
               (CASE aid.line_type_lookup_code
                 WHEN 'TIPV' THEN
                       decode(parent_taxable_dist.dist_match_type,     -- Bug 5639076
                              'PRICE_CORRECTION', zd.rec_nrec_tax_amt,
		                        ap_etax_utility_pkg.get_tipv(
   		                          zd.rate_tax_factor, zd.trx_line_dist_qty,
		                          nvl2(parent_taxable_dist.rcv_transaction_id,
		                                ap_etax_utility_pkg.get_converted_price
		                                  (parent_taxable_dist.invoice_distribution_id), zd.unit_price),
                                                zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
			                        zd.price_diff, parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
		                                parent_tax_line.line_source, ai.invoice_currency_code, parent_item_line.match_type))
		 WHEN 'TRV' THEN
		        (ap_etax_utility_pkg.get_tv(
				zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
				nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
				zd.ref_per_trx_curr_unit_nr_amt, zd.price_diff, parent_tax_line.corrected_inv_id,
				parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, ai.invoice_currency_code,
				parent_item_line.match_type, zd.unit_price) -
		         ap_etax_utility_pkg.get_tipv(
				zd.rate_tax_factor, zd.trx_line_dist_qty,
	                        nvl2(parent_taxable_dist.rcv_transaction_id,
	                                ap_etax_utility_pkg.get_converted_price
	                                (parent_taxable_dist.invoice_distribution_id), zd.unit_price),
				zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,per_trx_curr_unit_nr_amt),
				zd.price_diff, parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
				parent_tax_line.line_source, ai.invoice_currency_code, parent_item_line.match_type))
		 WHEN 'TERV' THEN 0
	        END)												amount,
	        (CASE aid.line_type_lookup_code
		 WHEN 'TIPV' THEN
		        ap_utilities_pkg.ap_round_currency(
			ap_etax_utility_pkg.get_tipv_base(
				zd.rate_tax_factor, zd.trx_line_dist_qty,
	                        nvl2(parent_taxable_dist.rcv_transaction_id,
	                                ap_etax_utility_pkg.get_converted_price
	                                (parent_taxable_dist.invoice_distribution_id), zd.unit_price),
				zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
				zd.price_diff, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate, NULL,
				parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
				parent_tax_line.line_source, ai.invoice_currency_code, asp.base_currency_code,
				parent_item_line.match_type),
				asp.base_currency_code)
		 WHEN 'TRV' THEN
			ap_utilities_pkg.ap_round_currency(
			(ap_etax_utility_pkg.get_tv_base(
				zd.rate_tax_factor, zd.trx_line_dist_qty, zd.per_unit_nrec_tax_amt,
				nvl(zd.ref_doc_per_unit_nrec_tax_amt,0), zd.per_trx_curr_unit_nr_amt,
				zd.ref_per_trx_curr_unit_nr_amt, nvl(zd.currency_conversion_rate,1),
				zd.ref_doc_curr_conv_rate, zd.price_diff, parent_tax_line.corrected_inv_id,
				parent_tax_line.line_type_lookup_code, parent_tax_line.line_source, asp.base_currency_code,
				parent_item_line.match_type, zd.unit_price) -
			ap_etax_utility_pkg.get_tipv_base(
				zd.rate_tax_factor, zd.trx_line_dist_qty,
	                        nvl2(parent_taxable_dist.rcv_transaction_id,
	                                ap_etax_utility_pkg.get_converted_price
	                                (parent_taxable_dist.invoice_distribution_id), zd.unit_price),
				zd.ref_doc_unit_price, nvl(zd.ref_per_trx_curr_unit_nr_amt,zd.per_trx_curr_unit_nr_amt),
				zd.price_diff, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate, NULL,
				parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
				parent_tax_line.line_source, ai.invoice_currency_code, asp.base_currency_code,
				parent_item_line.match_type) -
			decode (parent_tax_line.match_type, 'PRICE_CORRECTION', 0,
				ap_etax_utility_pkg.get_terv(
					zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate,
					zd.applied_to_doc_curr_conv_rate, NULL, zd.per_unit_nrec_tax_amt,
					nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
					parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
					parent_tax_line.line_source, asp.base_currency_code))), asp.base_currency_code)
		 WHEN 'TERV' THEN
			ap_utilities_pkg.ap_round_currency
			(ap_etax_utility_pkg.get_terv(
					zd.trx_line_dist_qty, zd.currency_conversion_rate, zd.ref_doc_curr_conv_rate,
					zd.applied_to_doc_curr_conv_rate, NULL, zd.per_unit_nrec_tax_amt,
					nvl(zd.ref_doc_per_unit_nrec_tax_amt,zd.per_unit_nrec_tax_amt),
					parent_tax_line.corrected_inv_id, parent_tax_line.line_type_lookup_code,
					parent_tax_line.line_source, asp.base_currency_code), asp.base_currency_code)
	        END)												base_amount,
	        DECODE(NVL(zd.inclusive_flag, 'N'),
			'Y', parent_item_line.description,
			'N', parent_tax_line.description) 							description,
	        DECODE(NVL(zd.inclusive_flag, 'N'),
			'Y', DECODE(parent_item_line.type_1099, NULL, NULL,
					parent_item_line.income_tax_region),
			'N', DECODE(parent_tax_line.type_1099, NULL, NULL,
					parent_tax_line.income_tax_region))					income_tax_region,
	        DECODE(NVL(zd.inclusive_flag, 'N'),
			'Y', parent_item_line.type_1099,
			'N', parent_tax_line.type_1099)								type_1099,
	        zd.attribute1											attribute1,
	        zd.attribute10 											attribute10,
	        zd.attribute11 											attribute11,
	        zd.attribute12 											attribute12,
	        zd.attribute13 											attribute13,
	        zd.attribute14 											attribute14,
	        zd.attribute15 											attribute15,
	        zd.attribute2 											attribute2,
	        zd.attribute3 											attribute3,
	        zd.attribute4 											attribute4,
	        zd.attribute5 											attribute5,
	        zd.attribute6 											attribute6,
	        zd.attribute7 											attribute7,
	        zd.attribute8 											attribute8,
	        zd.attribute9 											attribute9,
	        zd.attribute_category 										attribute_category,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.expenditure_item_date) 				expenditure_item_date,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.expenditure_organization_id) 			expenditure_organization_id,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.expenditure_type) 					expenditure_type,
	        parent_taxable_dist.parent_invoice_id 								parent_invoice_id,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', 'E', 'N', parent_taxable_dist.pa_addition_flag) pa_addition_flag,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.pa_quantity) 					pa_quantity,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.project_accounting_context) 			project_accounting_context,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.project_id) 					project_id,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.task_id) 						task_id,
	        aid.awt_group_id 										awt_group_id,
	        zd.global_attribute_category									global_attribute_category,
	        zd.global_attribute1										global_attribute1,
	        zd.global_attribute2										global_attribute2,
	        zd.global_attribute3										global_attribute3,
	        zd.global_attribute4										global_attribute4,
	        zd.global_attribute5										global_attribute5,
	        zd.global_attribute6										global_attribute6,
	        zd.global_attribute7										global_attribute7,
	        zd.global_attribute8										global_attribute8,
	        zd.global_attribute9										global_attribute9,
	        zd.global_attribute10										global_attribute10,
	        zd.global_attribute11										global_attribute11,
	        zd.global_attribute12										global_attribute12,
	        zd.global_attribute13										global_attribute13,
	        zd.global_attribute14										global_attribute14,
	        zd.global_attribute15										global_attribute15,
	        zd.global_attribute16										global_attribute16,
	        zd.global_attribute17										global_attribute17,
	        zd.global_attribute18										global_attribute18,
	        zd.global_attribute19										global_attribute19,
	        zd.global_attribute20										global_attribute20,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
			'Y', NULL, 'N', parent_taxable_dist.award_id) 						award_id,
	        DECODE(zd.ref_doc_dist_id,
			NULL, DECODE(zl.applied_to_trx_id,
				NULL, 'NOT_MATCHED', 'OTHER_TO_RECEIPT'), 'NOT_MATCHED')			dist_match_type,
	        DECODE(NVL(zd.recoverable_flag, 'N'),
				'Y', NULL, 'N', parent_tax_line.rcv_transaction_id) 				rcv_transaction_id,
	        zd.recoverable_flag										tax_recoverable_flag,
	        parent_taxable_dist.cancellation_flag 								cancellation_flag,
	        DECODE(NVL(zd.inclusive_flag, 'N'),
				'Y', zd.trx_line_id, 'N', parent_tax_line.line_number)				invoice_line_number,
	        parent_taxable_dist.corrected_invoice_dist_id							corrected_invoice_dist_id,
	        NULL 												rounding_amt,
	        decode(NVL(zl.tax_only_line_flag,'N'),
                         'Y', NULL, zd.trx_line_dist_id)							charge_applicable_to_dist_id,
	        DECODE(zl.ref_doc_trx_id, NULL, 'CANDIDATE', 'PERMANENT') 					distribution_class,
	        zd.tax_rate_id 											tax_code_id,
	        zd.rec_nrec_tax_dist_id 									detail_tax_dist_id,
	        zd.rec_nrec_rate 										rec_nrec_rate,
	        zd.recovery_rate_id 										recovery_rate_id,
	        zd.recovery_rate_code 										recovery_rate_name,
	        zd.recovery_type_code 										recovery_type_code,
	        NULL 												taxable_amount,
	        NULL 												taxable_base_amount,
	        zd.summary_tax_line_id 										summary_tax_line_id,
	        NULL 												extra_po_erv,
	        NULL 												prepay_tax_diff_amount,
	        aid.invoice_distribution_id 									invoice_distribution_id,
		zd.account_source_tax_rate_id									account_source_tax_rate_id
           FROM  zx_trx_headers_gt               gt,
	        zx_rec_nrec_dist                zd,
	        zx_lines                        zl,
	        ap_invoices_all                 ai,
	        ap_invoice_distributions_all    aid,
	        ap_supplier_sites_all           pvs,
	        ap_system_parameters_all        asp,
	        financials_system_params_all    fsp,
	        po_distributions_all            pd,
	        ap_invoice_lines_all            parent_tax_line,
	        ap_invoice_lines_all            parent_item_line,
	        ap_invoice_distributions_all    parent_taxable_dist
	 WHERE  gt.APPLICATION_ID                        = zd.APPLICATION_ID
	   AND  gt.ENTITY_CODE                           = zd.ENTITY_CODE
	   AND  gt.EVENT_CLASS_CODE                      = zd.EVENT_CLASS_CODE
	   AND  gt.TRX_ID                                = zd.TRX_ID
	   AND  zd.tax_line_id                           = zl.tax_line_id
	   AND  gt.trx_id                                = ai.invoice_id
	   AND  ai.invoice_id                            = aid.invoice_id
	   AND  aid.detail_tax_dist_id                   = zd.rec_nrec_tax_dist_id
	   AND  aid.line_type_lookup_code                IN ('TIPV', 'TRV', 'TERV')
           AND  nvl(aid.reversal_flag,'N')               <> 'Y'
	   AND  ai.vendor_site_id                        = pvs.vendor_site_id
	   AND  ai.set_of_books_id                       = asp.set_of_books_id
	   AND  ai.org_id                                = asp.org_id
	   AND  asp.set_of_books_id                      = fsp.set_of_books_id
	   AND  asp.org_id                               = fsp.org_id
	   AND  parent_taxable_dist.po_distribution_id   = pd.po_distribution_id(+)
	   AND  zd.trx_id                                = parent_tax_line.invoice_id (+)
	   AND  zd.summary_tax_line_id                   = parent_tax_line.summary_tax_line_id(+)
	   AND  zd.trx_id                                = parent_item_line.invoice_id(+)
	   AND  zd.trx_line_id                           = parent_item_line.line_number(+)
	   AND  zd.trx_id                                = parent_taxable_dist.invoice_id(+)
	   AND  zd.trx_line_dist_id                      = parent_taxable_dist.invoice_distribution_id(+)
	   AND  parent_item_line.line_type_lookup_code(+) <> 'PREPAY';
Line: 3146

  CURSOR insert_tax_self IS
      SELECT /*+ leading(gt,zd) cardinality(gt,1) INDEX (ZD ZX_REC_NREC_DIST_U3) */
        zd.gl_date accounting_date , --Bug6809792
        /*For tax distributions accounting date will be stamped from zx_rec_nrec_dist
          Ebtax will now store accounting date of opne period in their table*/
        parent_taxable_dist.dist_code_combination_id dist_code_combination_id,
        -- this ccid is a temporary value that will be used if other conditions
        -- are met before inserting the tax distribution
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', 'REC_TAX',
         'N', 'NONREC_TAX') line_type_lookup_code,
        ap_utilities_pkg.get_gl_period_name(zd.gl_date,ai.org_id)	period_name,
        zd.rec_nrec_tax_amt amount,
        ap_utilities_pkg.ap_round_currency
                (zd.rec_nrec_tax_amt_funcl_curr,asp.base_currency_code) base_amount,
	parent_item_line.description description,
	DECODE(parent_item_line.type_1099,
                NULL, NULL,
                parent_item_line.income_tax_region) income_tax_region,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.po_distribution_id) po_distribution_id,
	parent_item_line.type_1099 type_1099,
        zd.attribute1 attribute1,
        zd.attribute10 attribute10,
        zd.attribute11 attribute11,
        zd.attribute12 attribute12,
        zd.attribute13 attribute13,
        zd.attribute14 attribute14,
        zd.attribute15 attribute15,
        zd.attribute2 attribute2,
        zd.attribute3 attribute3,
        zd.attribute4 attribute4,
        zd.attribute5 attribute5,
        zd.attribute6 attribute6,
        zd.attribute7 attribute7,
        zd.attribute8 attribute8,
        zd.attribute9 attribute9,
        zd.attribute_category attribute_category,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_item_date) expenditure_item_date,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_organization_id)
           expenditure_organization_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_type) expenditure_type,
        parent_taxable_dist.parent_invoice_id parent_invoice_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', 'E',
         'N', parent_taxable_dist.pa_addition_flag) pa_addition_flag,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.pa_quantity) pa_quantity,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.project_accounting_context)
           project_accounting_context,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.project_id) project_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.task_id) task_id,
        DECODE(NVL(asp.allow_awt_flag, 'N'),
               'Y', DECODE(NVL(pvs.allow_awt_flag, 'N'),
                      'Y', DECODE(NVL(asp.awt_include_tax_amt, 'N'),
                             'Y', DECODE(NVL(zd.inclusive_flag, 'N'),
                                    'Y', DECODE(zd.applied_from_tax_dist_id,
                                           null, parent_item_line.awt_group_id,
                                           ap_etax_utility_pkg.Get_Prepay_Awt_Group_Id(
                                             parent_taxable_dist.prepay_distribution_id,
                                             P_Calling_Sequence)),
                                    'N', parent_taxable_dist.awt_group_id),
                             NULL),
                      NULL),
               NULL) awt_group_id,
        zd.global_attribute_category global_attribute_category,
        zd.global_attribute1 global_attribute1,
        zd.global_attribute2 global_attribute2,
        zd.global_attribute3 global_attribute3,
        zd.global_attribute4 global_attribute4,
        zd.global_attribute5 global_attribute5,
        zd.global_attribute6 global_attribute6,
        zd.global_attribute7 global_attribute7,
        zd.global_attribute8 global_attribute8,
        zd.global_attribute9 global_attribute9,
        zd.global_attribute10 global_attribute10,
        zd.global_attribute11 global_attribute11,
        zd.global_attribute12 global_attribute12,
        zd.global_attribute13 global_attribute13,
        zd.global_attribute14 global_attribute14,
        zd.global_attribute15 global_attribute15,
        zd.global_attribute16 global_attribute16,
        zd.global_attribute17 global_attribute17,
        zd.global_attribute18 global_attribute18,
        zd.global_attribute19 global_attribute19,
        zd.global_attribute20 global_attribute20,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.award_id) award_id,
        DECODE(zd.ref_doc_dist_id,
          NULL, DECODE(zl.applied_to_trx_id,
              NULL, 'NOT_MATCHED',
              'OTHER_TO_RECEIPT'),
          'NOT_MATCHED') dist_match_type,
         DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_item_line.rcv_transaction_id) rcv_transaction_id,
        zd.recoverable_flag tax_recoverable_flag,
        parent_taxable_dist.cancellation_flag cancellation_flag,
	zd.trx_line_id invoice_line_number,
        parent_taxable_dist.corrected_invoice_dist_id corrected_invoice_dist_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
          'Y', NULL,
          zd.func_curr_rounding_adjustment) rounding_amt,
        -- the rounding amount in the non-recoverable case will be populated
        -- to the primary distribution later in the cycle.
        decode(NVL(zl.tax_only_line_flag,'N'),
                     'Y', NULL, zd.trx_line_dist_id) charge_applicable_to_dist_id,
        DECODE(zl.ref_doc_trx_id,
          NULL, 'CANDIDATE',
          'PERMANENT') distribution_class,
        zd.tax_rate_id tax_code_id,
        zd.rec_nrec_tax_dist_id detail_tax_dist_id,
        zd.rec_nrec_rate rec_nrec_rate,
        zd.recovery_rate_id recovery_rate_id,
        zd.recovery_rate_code recovery_rate_name,
        zd.recovery_type_code recovery_type_code,
        zd.summary_tax_line_id summary_tax_line_id,
        null extra_po_erv,
        zd.taxable_amt taxable_amount,
        zd.taxable_amt_funcl_curr taxable_base_amount,
        pd.accrue_on_receipt_flag accrue_on_receipt_flag,
        asp.allow_flex_override_flag allow_flex_override_flag,
        fsp.purch_encumbrance_flag purch_encumbrance_flag,
        asp.org_id org_id,
        zd.tax_regime_id tax_regime_id,
        zd.tax_id tax_id,
        zd.tax_status_id tax_status_id,
        zl.tax_jurisdiction_id tax_jurisdiction_id,
        parent_taxable_dist.cancellation_flag parent_dist_cancellation_flag,
        parent_taxable_dist.reversal_flag parent_dist_reversal_flag,
        parent_taxable_dist.parent_reversal_id parent_dist_parent_reversal_id,
        zd.reversed_tax_dist_id reversed_tax_dist_id,
        zd.adjusted_doc_tax_dist_id adjusted_doc_tax_dist_id,
        zd.applied_from_tax_dist_id applied_from_tax_dist_id,
        -- the prepay_distribution_id will be populated with
        -- invoice_distribution_id for the TAX rec or nonrec
        -- asociated
        DECODE(parent_item_line.line_type_lookup_code,
               'PREPAY',
               AP_ETAX_UTILITY_PKG.Get_Dist_Id_For_Tax_Dist_Id(
                 zd.applied_from_tax_dist_id),
               NULL) prepay_distribution_id,
        DECODE(parent_item_line.line_type_lookup_code,
               'PREPAY', DECODE(NVL(zd.recoverable_flag, 'N'),
                           'N', (zd.prd_tax_amt - zd.rec_nrec_tax_amt), NULL),
               NULL) prepay_tax_diff_amount,
       ai.invoice_id     	invoice_id,
       ai.batch_id              batch_id,
       ai.set_of_books_id       set_of_books_id,
       zd.account_source_tax_rate_id	account_source_tax_rate_id
  FROM zx_trx_headers_gt                gt,
       zx_rec_nrec_dist                 zd,
       zx_lines                         zl,
       ap_invoices_all                  ai,
       ap_supplier_sites_all            pvs,
       ap_system_parameters_all         asp,
       financials_system_params_all     fsp,
       po_distributions_all             pd,
       ap_invoice_lines_all             parent_item_line,
       ap_invoice_distributions_all     parent_taxable_dist
 WHERE gt.APPLICATION_ID                        = zd.APPLICATION_ID
   AND gt.ENTITY_CODE                           = zd.ENTITY_CODE
   AND gt.EVENT_CLASS_CODE                      = zd.EVENT_CLASS_CODE
   AND gt.TRX_ID                                = zd.TRX_ID
   AND zd.tax_line_id                           = zl.tax_line_id
   AND gt.trx_id                                = ai.invoice_id
   AND ai.vendor_site_id                        = pvs.vendor_site_id
   AND ai.set_of_books_id                       = asp.set_of_books_id
   AND ai.org_id                                = asp.org_id
   AND asp.set_of_books_id                      = fsp.set_of_books_id
   AND asp.org_id                               = fsp.org_id
   AND NVL(zd.self_assessed_flag,  'N')         = 'Y'
   AND NVL(zl.reporting_only_flag, 'N')         = 'N'
   AND parent_taxable_dist.po_distribution_id   = pd.po_distribution_id(+)
   AND zd.trx_id                                = parent_item_line.invoice_id(+)
   AND zd.trx_line_id                           = parent_item_line.line_number(+)
   AND zd.trx_id                                = parent_taxable_dist.invoice_id(+)
   AND zd.trx_line_dist_id                      = parent_taxable_dist.invoice_distribution_id(+)
   AND NOT EXISTS
      (SELECT aid.detail_tax_dist_id
         FROM ap_self_assessed_tax_dist_all aid
        WHERE aid.invoice_id            = ai.invoice_id
          AND aid.detail_tax_dist_id    = zd.rec_nrec_tax_dist_id
          AND aid.line_type_lookup_code IN ('REC_TAX','NONREC_TAX'))
   -- Bug 7462582
   -- Reverting the fixes done in bugs 6805527 and 7389822 as Etax bug 7515711 will take care of these fixes.
   /* Added by schitlap, epajaril to fix the issue in Bug 6805527 */
   /*AND (nvl(parent_taxable_dist.reversal_flag, 'N') <> 'Y'
        OR zd.reversed_tax_dist_id IS NULL) -- 7389822*/
  ORDER BY detail_tax_dist_id;
Line: 3353

  CURSOR update_tax_self IS
      SELECT /*+ leading(gt,zd) cardinality(gt,1) */
        zd.gl_date accounting_date , --Bug6809792
        /*For tax distributions accounting date will be stamped from zx_rec_nrec_dist
          Ebtax will now store accounting date of opne period in their table*/
        parent_taxable_dist.dist_code_combination_id dist_code_combination_id,
        -- this ccid is a temporary value that will be used if other conditions
        -- are met before inserting the tax distribution
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', 'REC_TAX',
         'N', 'NONREC_TAX') line_type_lookup_code,
        ap_utilities_pkg.get_gl_period_name(zd.gl_date,ai.org_id)	period_name,
	zd.rec_nrec_tax_amt amount,
        ap_utilities_pkg.ap_round_currency
		(zd.rec_nrec_tax_amt_funcl_curr,asp.base_currency_code) base_amount,
        -- included the decode as part of the prepayment changes.
        -- since for prepayment applic tax variances will not be created,
        -- the base_amount should be the total including variances
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', parent_item_line.description,
         'N', parent_tax_line.description) description,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', DECODE(parent_item_line.type_1099,
                NULL, NULL,
                parent_item_line.income_tax_region),
         'N', DECODE(parent_tax_line.type_1099,
                NULL, NULL,
                parent_tax_line.income_tax_region)) income_tax_region,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', parent_item_line.type_1099,
         'N', parent_tax_line.type_1099) type_1099,
        zd.attribute1 attribute1,
        zd.attribute10 attribute10,
        zd.attribute11 attribute11,
        zd.attribute12 attribute12,
        zd.attribute13 attribute13,
        zd.attribute14 attribute14,
        zd.attribute15 attribute15,
        zd.attribute2 attribute2,
        zd.attribute3 attribute3,
        zd.attribute4 attribute4,
        zd.attribute5 attribute5,
        zd.attribute6 attribute6,
        zd.attribute7 attribute7,
        zd.attribute8 attribute8,
        zd.attribute9 attribute9,
        zd.attribute_category attribute_category,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_item_date) expenditure_item_date,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_organization_id)
           expenditure_organization_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.expenditure_type) expenditure_type,
        parent_taxable_dist.parent_invoice_id parent_invoice_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', 'E',
         'N', parent_taxable_dist.pa_addition_flag) pa_addition_flag,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.pa_quantity) pa_quantity,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.project_accounting_context)
           project_accounting_context,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.project_id) project_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.task_id) task_id,
        DECODE(NVL(asp.allow_awt_flag, 'N'),
               'Y', DECODE(NVL(pvs.allow_awt_flag, 'N'),
                      'Y', DECODE(NVL(asp.awt_include_tax_amt, 'N'),
                             'Y', DECODE(NVL(zd.inclusive_flag, 'N'),
                                    'Y', DECODE(zd.applied_from_tax_dist_id,
                                           null, parent_item_line.awt_group_id,
                                           ap_etax_utility_pkg.Get_Prepay_Awt_Group_Id(
                                             parent_taxable_dist.prepay_distribution_id,
                                             P_Calling_Sequence)),
                                    'N', parent_taxable_dist.awt_group_id),
                             NULL),
                      NULL),
               NULL) awt_group_id,
        zd.global_attribute_category global_attribute_category,
        zd.global_attribute1 global_attribute1,
        zd.global_attribute2 global_attribute2,
        zd.global_attribute3 global_attribute3,
        zd.global_attribute4 global_attribute4,
        zd.global_attribute5 global_attribute5,
        zd.global_attribute6 global_attribute6,
        zd.global_attribute7 global_attribute7,
        zd.global_attribute8 global_attribute8,
        zd.global_attribute9 global_attribute9,
        zd.global_attribute10 global_attribute10,
        zd.global_attribute11 global_attribute11,
        zd.global_attribute12 global_attribute12,
        zd.global_attribute13 global_attribute13,
        zd.global_attribute14 global_attribute14,
        zd.global_attribute15 global_attribute15,
        zd.global_attribute16 global_attribute16,
        zd.global_attribute17 global_attribute17,
        zd.global_attribute18 global_attribute18,
        zd.global_attribute19 global_attribute19,
        zd.global_attribute20 global_attribute20,
        DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_taxable_dist.award_id) award_id,
        DECODE(zd.ref_doc_dist_id,
          NULL, DECODE(zl.applied_to_trx_id,
              NULL, 'NOT_MATCHED',
              'OTHER_TO_RECEIPT'),
          'NOT_MATCHED') dist_match_type,
         DECODE(NVL(zd.recoverable_flag, 'N'),
         'Y', NULL,
         'N', parent_tax_line.rcv_transaction_id) rcv_transaction_id,
        zd.recoverable_flag tax_recoverable_flag,
        parent_taxable_dist.cancellation_flag cancellation_flag,
        DECODE(NVL(zd.inclusive_flag, 'N'),
         'Y', zd.trx_line_id,
         'N', parent_tax_line.line_number) invoice_line_number,
        parent_taxable_dist.corrected_invoice_dist_id corrected_invoice_dist_id,
        DECODE(NVL(zd.recoverable_flag, 'N'),
          'Y', NULL,
          zd.func_curr_rounding_adjustment) rounding_amt,
        -- This will update the rounding_amt in the recoverable dist
        -- for the non-recoverable the primary distribution will be
        -- updated later on
        decode(NVL(zl.tax_only_line_flag,'N'),
                     'Y', NULL, zd.trx_line_dist_id) charge_applicable_to_dist_id,
        DECODE(zl.ref_doc_trx_id,
          NULL, 'CANDIDATE',
          'PERMANENT') distribution_class,
        zd.tax_rate_id tax_code_id,
        zd.rec_nrec_tax_dist_id detail_tax_dist_id,
        zd.rec_nrec_rate rec_nrec_rate,
        zd.recovery_rate_id recovery_rate_id,
        zd.recovery_rate_code recovery_rate_name,
        zd.recovery_type_code recovery_type_code,
        zd.taxable_amt taxable_amount,
        zd.taxable_amt_funcl_curr taxable_base_amount,
        zd.summary_tax_line_id summary_tax_line_id,
        null extra_po_erv,
        -- (zd.applied_to_doc_erv - zx.reference_doc_erv) null extra_po_erv,
        DECODE(parent_item_line.line_type_lookup_code,
          'PREPAY', DECODE(NVL(zd.recoverable_flag, 'N'),
                      'N', (zd.prd_tax_amt - zd.rec_nrec_tax_amt), NULL),
          NULL) prepay_tax_diff_amount,
        aid.invoice_distribution_id invoice_distribution_id,
        zd.account_source_tax_rate_id
  FROM  zx_trx_headers_gt               gt,
        zx_rec_nrec_dist                zd,
        zx_lines                        zl,
        ap_invoices_all                 ai,
        ap_self_assessed_tax_dist_all	aid,
        ap_supplier_sites_all           pvs,
        ap_system_parameters_all        asp,
        financials_system_params_all    fsp,
        po_distributions_all            pd,
        ap_invoice_lines_all            parent_tax_line,
        ap_invoice_lines_all            parent_item_line,
        ap_invoice_distributions_all    parent_taxable_dist
 WHERE  gt.APPLICATION_ID                        = zd.APPLICATION_ID
   AND  gt.ENTITY_CODE                           = zd.ENTITY_CODE
   AND  gt.EVENT_CLASS_CODE                      = zd.EVENT_CLASS_CODE
   AND  gt.TRX_ID                                = zd.TRX_ID
   AND  zd.tax_line_id                           = zl.tax_line_id
   AND  gt.trx_id                                = ai.invoice_id
   AND  ai.invoice_id                            = aid.invoice_id
   AND  aid.detail_tax_dist_id                   = zd.rec_nrec_tax_dist_id
   AND  aid.line_type_lookup_code                IN ('REC_TAX','NONREC_TAX')
   AND  nvl(aid.reversal_flag,'N')               <> 'Y'
   AND  ai.vendor_site_id                        = pvs.vendor_site_id
   AND  ai.set_of_books_id                       = asp.set_of_books_id
   AND  ai.org_id                                = asp.org_id
   AND  asp.set_of_books_id                      = fsp.set_of_books_id
   AND  asp.org_id                               = fsp.org_id
   AND  parent_taxable_dist.po_distribution_id   = pd.po_distribution_id(+)
   AND  zd.trx_id                                = parent_tax_line.invoice_id (+)
   AND  zd.summary_tax_line_id                   = parent_tax_line.summary_tax_line_id(+)
   AND  zd.trx_id                                = parent_item_line.invoice_id(+)
   AND  zd.trx_line_id                           = parent_item_line.line_number(+)
   AND  zd.trx_id                                = parent_taxable_dist.invoice_id(+)
   AND  zd.trx_line_dist_id                      = parent_taxable_dist.invoice_distribution_id(+);
Line: 3588

    DELETE FROM AP_Line_Temp_GT;
Line: 3591

	INSERT INTO AP_Line_Temp_GT (Line_Type)
	VALUES (linetype(i));
Line: 3600

    l_debug_info := 'Get tax distributions for update';
Line: 3602

    OPEN UPDATE_TAX_DIST;
Line: 3604

        FETCH UPDATE_TAX_DIST
         BULK COLLECT INTO L_INV_DIST_UPD
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 3608

        EXIT WHEN UPDATE_TAX_DIST%NOTFOUND
                  AND L_INV_DIST_UPD.COUNT <= 0;
Line: 3612

	l_debug_info := 'Tax distributions updated: '||l_inv_dist_upd.count;
Line: 3624

	         UPDATE ap_invoice_distributions_all
	          SET 	accounting_date 		= l_inv_dist_upd(j).accounting_date,
			last_updated_by 		= l_user_id,
	            	last_update_date 		= l_sysdate,
	            	line_type_lookup_code 		= l_inv_dist_upd(j).line_type_lookup_code,
	            	period_name 			= l_inv_dist_upd(j).period_name,
	            	amount 				= l_inv_dist_upd(j).amount,
	            	base_amount 			= decode(l_inv_dist_upd(j).base_amount,
                                                                 0, decode(l_inv_dist_upd(j).amount, 0, l_inv_dist_upd(j).base_amount, NULL),
                                                                 l_inv_dist_upd(j).base_amount),
	            	description 			= l_inv_dist_upd(j).description,
	            	income_tax_region 		= l_inv_dist_upd(j).income_tax_region,
	            	last_update_login 		= l_login_id,
	            	type_1099 			= l_inv_dist_upd(j).type_1099,
	            	attribute1 			= l_inv_dist_upd(j).attribute1,
	            	attribute10 			= l_inv_dist_upd(j).attribute10,
	            	attribute11 			= l_inv_dist_upd(j).attribute11,
	            	attribute12 			= l_inv_dist_upd(j).attribute12,
	            	attribute13 			= l_inv_dist_upd(j).attribute13,
	            	attribute14 			= l_inv_dist_upd(j).attribute14,
	            	attribute15 			= l_inv_dist_upd(j).attribute15,
	            	attribute2 			= l_inv_dist_upd(j).attribute2,
	            	attribute3 			= l_inv_dist_upd(j).attribute3,
	            	attribute4 			= l_inv_dist_upd(j).attribute4,
	            	attribute5 			= l_inv_dist_upd(j).attribute5,
	            	attribute6 			= l_inv_dist_upd(j).attribute6,
	            	attribute7 			= l_inv_dist_upd(j).attribute7,
	            	attribute8 			= l_inv_dist_upd(j).attribute8,
	            	attribute9 			= l_inv_dist_upd(j).attribute9,
	            	attribute_category 		= l_inv_dist_upd(j).attribute_category,
	            	expenditure_item_date 		= l_inv_dist_upd(j).expenditure_item_date,
	            	expenditure_organization_id 	= l_inv_dist_upd(j).expenditure_organization_id,
	            	expenditure_type 		= l_inv_dist_upd(j).expenditure_type,
	            	parent_invoice_id 		= l_inv_dist_upd(j).parent_invoice_id,
	            	pa_addition_flag 		= l_inv_dist_upd(j).pa_addition_flag,
	            	pa_quantity 			= l_inv_dist_upd(j).pa_quantity,
	            	project_accounting_context 	= l_inv_dist_upd(j).project_accounting_context,
	            	project_id 			= l_inv_dist_upd(j).project_id,
	            	task_id 			= l_inv_dist_upd(j).task_id,
	            	awt_group_id 			= l_inv_dist_upd(j).awt_group_id,
	            	global_attribute_category 	= l_inv_dist_upd(j).global_attribute_category,
	            	global_attribute1 		= l_inv_dist_upd(j).global_attribute1,
	            	global_attribute2 		= l_inv_dist_upd(j).global_attribute2,
	            	global_attribute3 		= l_inv_dist_upd(j).global_attribute3,
	            	global_attribute4 		= l_inv_dist_upd(j).global_attribute4,
	            	global_attribute5 		= l_inv_dist_upd(j).global_attribute5,
	            	global_attribute6 		= l_inv_dist_upd(j).global_attribute6,
	            	global_attribute7 		= l_inv_dist_upd(j).global_attribute7,
	            	global_attribute8 		= l_inv_dist_upd(j).global_attribute8,
	            	global_attribute9 		= l_inv_dist_upd(j).global_attribute9,
	            	global_attribute10 		= l_inv_dist_upd(j).global_attribute10,
	            	global_attribute11 		= l_inv_dist_upd(j).global_attribute11,
	            	global_attribute12 		= l_inv_dist_upd(j).global_attribute12,
	            	global_attribute13 		= l_inv_dist_upd(j).global_attribute13,
	            	global_attribute14 		= l_inv_dist_upd(j).global_attribute14,
	            	global_attribute15 		= l_inv_dist_upd(j).global_attribute15,
	            	global_attribute16 		= l_inv_dist_upd(j).global_attribute16,
	            	global_attribute17 		= l_inv_dist_upd(j).global_attribute17,
	            	global_attribute18 		= l_inv_dist_upd(j).global_attribute18,
	            	global_attribute19 		= l_inv_dist_upd(j).global_attribute19,
	            	global_attribute20 		= l_inv_dist_upd(j).global_attribute20,
	            	award_id 			= l_inv_dist_upd(j).award_id,
	            	dist_match_type 		= l_inv_dist_upd(j).dist_match_type,
	            	rcv_transaction_id 		= l_inv_dist_upd(j).rcv_transaction_id,
	            	tax_recoverable_flag 		= l_inv_dist_upd(j).tax_recoverable_flag,
	            	cancellation_flag 		= l_inv_dist_upd(j).cancellation_flag,
	            	--invoice_line_number 		= l_inv_dist_upd(j).invoice_line_number,
        	    	corrected_invoice_dist_id 	= l_inv_dist_upd(j).corrected_invoice_dist_id,
	            	rounding_amt 			= l_inv_dist_upd(j).rounding_amt,
	            	charge_applicable_to_dist_id 	= l_inv_dist_upd(j).charge_applicable_to_dist_id,
	            	--distribution_class 		= l_inv_dist_upd(j).distribution_class,    --Bug6678578
	            	tax_code_id 			= l_inv_dist_upd(j).tax_code_id,
	            	detail_tax_dist_id 		= l_inv_dist_upd(j).detail_tax_dist_id,
	            	rec_nrec_rate 			= l_inv_dist_upd(j).rec_nrec_rate,
	            	recovery_rate_id 		= l_inv_dist_upd(j).recovery_rate_id,
	            	recovery_rate_name 		= l_inv_dist_upd(j).recovery_rate_name,
	            	recovery_type_code 		= l_inv_dist_upd(j).recovery_type_code,
	            	taxable_amount 			= l_inv_dist_upd(j).taxable_amount,
	            	taxable_base_amount 		= l_inv_dist_upd(j).taxable_base_amount,
	            	summary_tax_line_id 		= l_inv_dist_upd(j).summary_tax_line_id,
	            	extra_po_erv 			= l_inv_dist_upd(j).extra_po_erv,
	            	prepay_tax_diff_amount 		= l_inv_dist_upd(j).prepay_tax_diff_amount,
			match_status_flag		= decode (amount, l_inv_dist_upd(j).amount,
									  match_status_flag, 'N')
	          WHERE invoice_distribution_id = l_inv_dist_upd(j).invoice_distribution_id;
Line: 3711

             L_INV_DIST_UPD.DELETE;
Line: 3714

    CLOSE UPDATE_TAX_DIST;
Line: 3718

    l_debug_info := 'Get tax variance distributions for update';
Line: 3720

    OPEN UPDATE_TAX_VARIANCES;
Line: 3722

        FETCH UPDATE_TAX_VARIANCES
         BULK COLLECT INTO L_INV_DIST_UPD
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 3726

        EXIT WHEN UPDATE_TAX_VARIANCES%NOTFOUND
                  AND L_INV_DIST_UPD.COUNT <= 0;
Line: 3730

	l_debug_info := 'Tax Variance distributions updated: '||l_inv_dist_upd.count;
Line: 3740

	         UPDATE ap_invoice_distributions_all
	          SET 	accounting_date 		= l_inv_dist_upd(j).accounting_date,
			last_updated_by 		= l_user_id,
	            	last_update_date 		= l_sysdate,
	            	line_type_lookup_code 		= l_inv_dist_upd(j).line_type_lookup_code,
	            	period_name 			= l_inv_dist_upd(j).period_name,
	            	amount 				= l_inv_dist_upd(j).amount,
	            	base_amount 			= decode(l_inv_dist_upd(j).base_amount,
								 0, decode(l_inv_dist_upd(j).amount, 0, l_inv_dist_upd(j).base_amount, NULL),
                                                                 l_inv_dist_upd(j).base_amount),
	            	description 			= l_inv_dist_upd(j).description,
	            	income_tax_region 		= l_inv_dist_upd(j).income_tax_region,
	            	last_update_login 		= l_login_id,
	            	type_1099 			= l_inv_dist_upd(j).type_1099,
	            	attribute1 			= l_inv_dist_upd(j).attribute1,
	            	attribute10 			= l_inv_dist_upd(j).attribute10,
	            	attribute11 			= l_inv_dist_upd(j).attribute11,
	            	attribute12 			= l_inv_dist_upd(j).attribute12,
	            	attribute13 			= l_inv_dist_upd(j).attribute13,
	            	attribute14 			= l_inv_dist_upd(j).attribute14,
	            	attribute15 			= l_inv_dist_upd(j).attribute15,
	            	attribute2 			= l_inv_dist_upd(j).attribute2,
	            	attribute3 			= l_inv_dist_upd(j).attribute3,
	            	attribute4 			= l_inv_dist_upd(j).attribute4,
	            	attribute5 			= l_inv_dist_upd(j).attribute5,
	            	attribute6 			= l_inv_dist_upd(j).attribute6,
	            	attribute7 			= l_inv_dist_upd(j).attribute7,
	            	attribute8 			= l_inv_dist_upd(j).attribute8,
	            	attribute9 			= l_inv_dist_upd(j).attribute9,
	            	attribute_category 		= l_inv_dist_upd(j).attribute_category,
	            	expenditure_item_date 		= l_inv_dist_upd(j).expenditure_item_date,
	            	expenditure_organization_id 	= l_inv_dist_upd(j).expenditure_organization_id,
	            	expenditure_type 		= l_inv_dist_upd(j).expenditure_type,
	            	parent_invoice_id 		= l_inv_dist_upd(j).parent_invoice_id,
	            	pa_addition_flag 		= l_inv_dist_upd(j).pa_addition_flag,
	            	pa_quantity 			= l_inv_dist_upd(j).pa_quantity,
	            	project_accounting_context 	= l_inv_dist_upd(j).project_accounting_context,
	            	project_id 			= l_inv_dist_upd(j).project_id,
	            	task_id 			= l_inv_dist_upd(j).task_id,
	            	awt_group_id 			= l_inv_dist_upd(j).awt_group_id,
	            	global_attribute_category 	= l_inv_dist_upd(j).global_attribute_category,
	            	global_attribute1 		= l_inv_dist_upd(j).global_attribute1,
	            	global_attribute2 		= l_inv_dist_upd(j).global_attribute2,
	            	global_attribute3 		= l_inv_dist_upd(j).global_attribute3,
	            	global_attribute4 		= l_inv_dist_upd(j).global_attribute4,
	            	global_attribute5 		= l_inv_dist_upd(j).global_attribute5,
	            	global_attribute6 		= l_inv_dist_upd(j).global_attribute6,
	            	global_attribute7 		= l_inv_dist_upd(j).global_attribute7,
	            	global_attribute8 		= l_inv_dist_upd(j).global_attribute8,
	            	global_attribute9 		= l_inv_dist_upd(j).global_attribute9,
	            	global_attribute10 		= l_inv_dist_upd(j).global_attribute10,
	            	global_attribute11 		= l_inv_dist_upd(j).global_attribute11,
	            	global_attribute12 		= l_inv_dist_upd(j).global_attribute12,
	            	global_attribute13 		= l_inv_dist_upd(j).global_attribute13,
	            	global_attribute14 		= l_inv_dist_upd(j).global_attribute14,
	            	global_attribute15 		= l_inv_dist_upd(j).global_attribute15,
	            	global_attribute16 		= l_inv_dist_upd(j).global_attribute16,
	            	global_attribute17 		= l_inv_dist_upd(j).global_attribute17,
	            	global_attribute18 		= l_inv_dist_upd(j).global_attribute18,
	            	global_attribute19 		= l_inv_dist_upd(j).global_attribute19,
	            	global_attribute20 		= l_inv_dist_upd(j).global_attribute20,
	            	award_id 			= l_inv_dist_upd(j).award_id,
	            	dist_match_type 		= l_inv_dist_upd(j).dist_match_type,
	            	rcv_transaction_id 		= l_inv_dist_upd(j).rcv_transaction_id,
	            	tax_recoverable_flag 		= l_inv_dist_upd(j).tax_recoverable_flag,
	            	cancellation_flag 		= l_inv_dist_upd(j).cancellation_flag,
	            	--invoice_line_number 		= l_inv_dist_upd(j).invoice_line_number,
        	    	corrected_invoice_dist_id 	= l_inv_dist_upd(j).corrected_invoice_dist_id,
	            	rounding_amt 			= l_inv_dist_upd(j).rounding_amt,
	            	charge_applicable_to_dist_id 	= l_inv_dist_upd(j).charge_applicable_to_dist_id,
	            	--distribution_class 		= l_inv_dist_upd(j).distribution_class, --Bug6678578
	            	tax_code_id 			= l_inv_dist_upd(j).tax_code_id,
	            	detail_tax_dist_id 		= l_inv_dist_upd(j).detail_tax_dist_id,
	            	rec_nrec_rate 			= l_inv_dist_upd(j).rec_nrec_rate,
	            	recovery_rate_id 		= l_inv_dist_upd(j).recovery_rate_id,
	            	recovery_rate_name 		= l_inv_dist_upd(j).recovery_rate_name,
	            	recovery_type_code 		= l_inv_dist_upd(j).recovery_type_code,
	            	taxable_amount 			= l_inv_dist_upd(j).taxable_amount,
	            	taxable_base_amount 		= l_inv_dist_upd(j).taxable_base_amount,
	            	summary_tax_line_id 		= l_inv_dist_upd(j).summary_tax_line_id,
	            	extra_po_erv 			= l_inv_dist_upd(j).extra_po_erv,
	            	prepay_tax_diff_amount 		= l_inv_dist_upd(j).prepay_tax_diff_amount,
                        match_status_flag               = decode (amount, l_inv_dist_upd(j).amount,
                                                                          match_status_flag, 'N')
	          WHERE invoice_distribution_id = l_inv_dist_upd(j).invoice_distribution_id;
Line: 3827

             L_INV_DIST_UPD.DELETE;
Line: 3830

    CLOSE UPDATE_TAX_VARIANCES;
Line: 3834

    l_debug_info := 'Step 5: Get tax distributions for update';
Line: 3836

    OPEN UPDATE_TAX_SELF;
Line: 3838

        FETCH UPDATE_TAX_SELF
         BULK COLLECT INTO L_INV_SELF_UPD
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 3842

        EXIT WHEN UPDATE_TAX_SELF%NOTFOUND
                  AND L_INV_DIST_UPD.COUNT <= 0;
Line: 3846

    	l_debug_info := 'Step 5: Self assessed dist updated: '||l_inv_self_upd.COUNT;
Line: 3856

	        UPDATE ap_self_assessed_tax_dist_all
	        SET accounting_date 		= l_inv_self_upd(j).accounting_date,
		    last_updated_by 		= l_user_id,
	            last_update_date 		= l_sysdate,
	            line_type_lookup_code 	= l_inv_self_upd(j).line_type_lookup_code,
	            period_name 		= l_inv_self_upd(j).period_name,
	            amount 			= l_inv_self_upd(j).amount,
	            base_amount 		= decode(l_inv_self_upd(j).base_amount,
                                                         0, decode(l_inv_self_upd(j).amount, 0, l_inv_self_upd(j).base_amount, NULL),
                                                         l_inv_self_upd(j).base_amount),
	            description 		= l_inv_self_upd(j).description,
	            income_tax_region 		= l_inv_self_upd(j).income_tax_region,
	            last_update_login 		= l_login_id,
	            type_1099 			= l_inv_self_upd(j).type_1099,
	            attribute1 			= l_inv_self_upd(j).attribute1,
	            attribute10 		= l_inv_self_upd(j).attribute10,
	            attribute11 		= l_inv_self_upd(j).attribute11,
	            attribute12 		= l_inv_self_upd(j).attribute12,
	            attribute13 		= l_inv_self_upd(j).attribute13,
	            attribute14 		= l_inv_self_upd(j).attribute14,
	            attribute15 		= l_inv_self_upd(j).attribute15,
	            attribute2 			= l_inv_self_upd(j).attribute2,
	            attribute3 			= l_inv_self_upd(j).attribute3,
	            attribute4 			= l_inv_self_upd(j).attribute4,
	            attribute5 			= l_inv_self_upd(j).attribute5,
	            attribute6 			= l_inv_self_upd(j).attribute6,
	            attribute7 			= l_inv_self_upd(j).attribute7,
	            attribute8 			= l_inv_self_upd(j).attribute8,
	            attribute9 			= l_inv_self_upd(j).attribute9,
	            attribute_category 		= l_inv_self_upd(j).attribute_category,
	            expenditure_item_date 	= l_inv_self_upd(j).expenditure_item_date,
	            expenditure_organization_id = l_inv_self_upd(j).expenditure_organization_id,
	            expenditure_type 		= l_inv_self_upd(j).expenditure_type,
	            parent_invoice_id 		= l_inv_self_upd(j).parent_invoice_id,
	            pa_addition_flag 		= l_inv_self_upd(j).pa_addition_flag,
	            pa_quantity 		= l_inv_self_upd(j).pa_quantity,
	            project_accounting_context 	= l_inv_self_upd(j).project_accounting_context,
	            project_id 			= l_inv_self_upd(j).project_id,
	            task_id 			= l_inv_self_upd(j).task_id,
	            awt_group_id 		= l_inv_self_upd(j).awt_group_id,
	            global_attribute_category 	= l_inv_self_upd(j).global_attribute_category,
	            global_attribute1 		= l_inv_self_upd(j).global_attribute1,
	            global_attribute2 		= l_inv_self_upd(j).global_attribute2,
	            global_attribute3 		= l_inv_self_upd(j).global_attribute3,
	            global_attribute4 		= l_inv_self_upd(j).global_attribute4,
	            global_attribute5 		= l_inv_self_upd(j).global_attribute5,
	            global_attribute6 		= l_inv_self_upd(j).global_attribute6,
	            global_attribute7 		= l_inv_self_upd(j).global_attribute7,
	            global_attribute8 		= l_inv_self_upd(j).global_attribute8,
	            global_attribute9 		= l_inv_self_upd(j).global_attribute9,
	            global_attribute10 		= l_inv_self_upd(j).global_attribute10,
	            global_attribute11 		= l_inv_self_upd(j).global_attribute11,
	            global_attribute12 		= l_inv_self_upd(j).global_attribute12,
	            global_attribute13 		= l_inv_self_upd(j).global_attribute13,
	            global_attribute14 		= l_inv_self_upd(j).global_attribute14,
	            global_attribute15 		= l_inv_self_upd(j).global_attribute15,
	            global_attribute16 		= l_inv_self_upd(j).global_attribute16,
	            global_attribute17 		= l_inv_self_upd(j).global_attribute17,
	            global_attribute18 		= l_inv_self_upd(j).global_attribute18,
	            global_attribute19 		= l_inv_self_upd(j).global_attribute19,
	            global_attribute20 		= l_inv_self_upd(j).global_attribute20,
	            award_id 			= l_inv_self_upd(j).award_id,
	            dist_match_type 		= l_inv_self_upd(j).dist_match_type,
	            rcv_transaction_id 		= l_inv_self_upd(j).rcv_transaction_id,
	            tax_recoverable_flag 	= l_inv_self_upd(j).tax_recoverable_flag,
	            cancellation_flag 		= l_inv_self_upd(j).cancellation_flag,
	            invoice_line_number 	= l_inv_self_upd(j).invoice_line_number,
	            corrected_invoice_dist_id 	= l_inv_self_upd(j).corrected_invoice_dist_id,
	            rounding_amt 		= l_inv_self_upd(j).rounding_amt,
	            charge_applicable_to_dist_id = l_inv_self_upd(j).charge_applicable_to_dist_id,
	            --distribution_class 		= l_inv_self_upd(j).distribution_class, --Bug6678578
	            tax_code_id 		= l_inv_self_upd(j).tax_code_id,
	            detail_tax_dist_id 		= l_inv_self_upd(j).detail_tax_dist_id,
	            rec_nrec_rate 		= l_inv_self_upd(j).rec_nrec_rate,
	            recovery_rate_id 		= l_inv_self_upd(j).recovery_rate_id,
	            recovery_rate_name 		= l_inv_self_upd(j).recovery_rate_name,
	            recovery_type_code 		= l_inv_self_upd(j).recovery_type_code,
	            taxable_amount 		= l_inv_self_upd(j).taxable_amount,
	            taxable_base_amount 	= l_inv_self_upd(j).taxable_base_amount,
	            summary_tax_line_id 	= l_inv_self_upd(j).summary_tax_line_id,
	            extra_po_erv 		= l_inv_self_upd(j).extra_po_erv,
	            prepay_tax_diff_amount 	=  l_inv_self_upd(j).prepay_tax_diff_amount
	        WHERE invoice_distribution_id = l_inv_self_upd(j).invoice_distribution_id;
Line: 3941

            L_INV_SELF_UPD.DELETE;
Line: 3944

    CLOSE UPDATE_TAX_SELF;
Line: 3947

    l_debug_info := 'Step 6: Get tax distributions for insert';
Line: 3949

    OPEN INSERT_TAX_DIST;
Line: 3951

        FETCH INSERT_TAX_DIST
         BULK COLLECT INTO L_INV_DIST_INS
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 3955

        EXIT WHEN INSERT_TAX_DIST%NOTFOUND
                  AND L_INV_DIST_INS.COUNT <= 0;
Line: 3961

            l_debug_info := 'Tax distributions to insert: '||l_inv_dist_ins.COUNT;
Line: 4022

	              SELECT dist_code_combination_id
	                INTO l_dist_code_combination_id
	                FROM ap_invoice_distributions_all
	               WHERE detail_tax_dist_id = l_inv_dist_ins(i).reversed_tax_dist_id
	                 AND line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX','TIPV', 'TRV', 'TERV')
                         AND rownum =1;--Bug7241425
Line: 4039

	              SELECT dist_code_combination_id
	                INTO l_dist_code_combination_id
	                FROM ap_invoice_distributions_all
	               WHERE detail_tax_dist_id = l_inv_dist_ins(i).adjusted_doc_tax_dist_id
	                 AND line_type_lookup_code IN ('REC_TAX','NONREC_TAX','TIPV','TRV','TERV')--Bug7241425
                         AND rownum =1;--Bug7241425
Line: 4116

	        l_debug_info := 'Insert REC/NONREC distributions';
Line: 4122

	        ap_etax_utility_pkg.insert_tax_distributions
	        			(p_invoice_header_rec        => p_invoice_header_rec,
					 p_inv_dist_rec              => l_inv_dist_ins(i),
					 p_dist_code_combination_id  => l_dist_code_combination_id,
					 p_user_id		     => l_user_id,
					 p_sysdate	     	     => l_sysdate,
					 p_login_id		     => l_login_id,
					 p_calling_sequence          => l_curr_calling_sequence);
Line: 4134

            L_INV_DIST_INS.DELETE;
Line: 4137

    CLOSE INSERT_TAX_DIST;
Line: 4142

    OPEN INSERT_TAX_VARIANCES;
Line: 4144

        FETCH INSERT_TAX_VARIANCES
         BULK COLLECT INTO L_INV_DIST_INS
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 4148

        EXIT WHEN INSERT_TAX_VARIANCES%NOTFOUND
                  AND L_INV_DIST_INS.COUNT <= 0;
Line: 4158

              SELECT 'Y'
	            INTO   l_lcm_enabled
	            FROM   RCV_TRANSACTIONS
	            WHERE  TRANSACTION_ID = L_INV_DIST_INS(i).rcv_transaction_id
	            AND    LCM_SHIPMENT_LINE_ID IS NOT NULL;
Line: 4184

                l_debug_info := 'Insert Tax Variance Distributions';
Line: 4190

                ap_etax_utility_pkg.insert_tax_distributions(
				  p_invoice_header_rec       => p_invoice_header_rec,
				  p_inv_dist_rec             => l_inv_dist_ins(i),
				  p_dist_code_combination_id => l_dist_code_combination_id,
				  p_user_id		     => l_user_id,
				  p_sysdate	     	     => l_sysdate,
				  p_login_id		     => l_login_id,
				  p_calling_sequence         => l_curr_calling_sequence);
Line: 4199

           L_INV_DIST_INS.DELETE;
Line: 4202

    CLOSE INSERT_TAX_VARIANCES;
Line: 4206

    l_debug_info := 'Get self assessed dist for insert';
Line: 4208

    OPEN INSERT_TAX_SELF;
Line: 4210

        FETCH INSERT_TAX_SELF
         BULK COLLECT INTO L_INV_SELF_INS
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 4214

        EXIT WHEN INSERT_TAX_SELF%NOTFOUND
                  AND L_INV_SELF_INS.COUNT <= 0;
Line: 4220

      	    l_debug_info := 'Insert self assessed tax distributions';
Line: 4269

	              SELECT dist_code_combination_id
	                INTO l_dist_code_combination_id
	                FROM ap_self_assessed_tax_dist_all
	               WHERE detail_tax_dist_id = l_inv_self_ins(i).reversed_tax_dist_id;
Line: 4276

	              SELECT dist_code_combination_id
	                INTO l_dist_code_combination_id
	                FROM ap_self_assessed_tax_dist_all
	               WHERE detail_tax_dist_id = l_inv_self_ins(i).adjusted_doc_tax_dist_id;
Line: 4352

	        l_debug_info := 'Insert self assessed distributions';
Line: 4359

	          INSERT INTO ap_self_assessed_tax_dist_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,
	            final_match_flag,
	            income_tax_region,
	            last_update_login,
	            match_status_flag,
	            posted_flag,
	            po_distribution_id,
	            program_application_id,
	            program_id,
	            program_update_date,
	            quantity_invoiced,
	            request_id,
	            reversal_flag,
	            type_1099,
	            unit_price,
	            encumbered_flag,
	            stat_amount,
	            attribute1,
	            attribute10,
	            attribute11,
	            attribute12,
	            attribute13,
	            attribute14,
	            attribute15,
	            attribute2,
	            attribute3,
	            attribute4,
	            attribute5,
	            attribute6,
	            attribute7,
	            attribute8,
	            attribute9,
	            attribute_category,
	            expenditure_item_date,
	            expenditure_organization_id,
	            expenditure_type,
	            parent_invoice_id,
	            pa_addition_flag,
	            pa_quantity,
	            prepay_amount_remaining,
	            project_accounting_context,
	            project_id,
	            task_id,
	            packet_id,
	            awt_flag,
	            awt_group_id,
	            awt_tax_rate_id,
	            awt_gross_amount,
	            awt_invoice_id,
	            awt_origin_group_id,
	            reference_1,
	            reference_2,
	            org_id,
	            awt_invoice_payment_id,
	            global_attribute_category,
	            global_attribute1,
	            global_attribute2,
	            global_attribute3,
	            global_attribute4,
	            global_attribute5,
	            global_attribute6,
	            global_attribute7,
	            global_attribute8,
	            global_attribute9,
	            global_attribute10,
	            global_attribute11,
	            global_attribute12,
	            global_attribute13,
	            global_attribute14,
	            global_attribute15,
	            global_attribute16,
	            global_attribute17,
	            global_attribute18,
	            global_attribute19,
	            global_attribute20,
	            receipt_verified_flag,
	            receipt_required_flag,
	            receipt_missing_flag,
	            justification,
	            expense_group,
	            start_expense_date,
	            end_expense_date,
	            receipt_currency_code,
	            receipt_conversion_rate,
	            receipt_currency_amount,
	            daily_amount,
	            web_parameter_id,
	            adjustment_reason,
	            award_id,
	            credit_card_trx_id,
	            dist_match_type,
	            rcv_transaction_id,
	            invoice_distribution_id,
	            parent_reversal_id,
	            tax_recoverable_flag,
	            merchant_document_number,
	            merchant_name,
	            merchant_reference,
	            merchant_tax_reg_number,
	            merchant_taxpayer_id,
	            country_of_supply,
	            matched_uom_lookup_code,
	            gms_burdenable_raw_cost,
	            accounting_event_id,
	            prepay_distribution_id,
	            upgrade_posted_amt,
	            upgrade_base_posted_amt,
	            inventory_transfer_status,
	            company_prepaid_invoice_id,
	            cc_reversal_flag,
	            awt_withheld_amt,
	            pa_cmt_xface_flag,
	            cancellation_flag,
	            invoice_line_number,
	            corrected_invoice_dist_id,
	            rounding_amt,
	            charge_applicable_to_dist_id,
	            corrected_quantity,
	            related_id,
	            asset_book_type_code,
	            asset_category_id,
	            distribution_class,
	            tax_code_id,
	            intended_use,
	            detail_tax_dist_id,
	            rec_nrec_rate,
	            recovery_rate_id,
	            recovery_rate_name,
	            recovery_type_code,
	            withholding_tax_code_id,
	            taxable_amount,
	            taxable_base_amount,
	            tax_already_distributed_flag,
        	    summary_tax_line_id,
	            extra_po_erv,
	            prepay_tax_diff_amount,
	            self_assessed_tax_liab_ccid,
		    rcv_charge_addition_flag,
		    self_assessed_flag
	          ) VALUES (
	            l_inv_self_ins(i).accounting_date,    -- accounting_date
	            'N',                                  -- accrual_posted_flag
	            'U',                                  -- assets_addition_flag
	            'N',                                  -- assets_tracking_flag
	            'N',                                  -- cash_posted_flag
	            AP_ETAX_UTILITY_PKG.get_max_dist_num_self(
                      --P_Invoice_Header_Rec.invoice_id,
                      l_inv_self_ins(i).invoice_id,
	              l_inv_self_ins(i).invoice_line_number)+1, --Bug7611551
	                                                  -- distribution_line_number
	            l_dist_code_combination_id,           -- dist_code_combination_id
                    l_inv_self_ins(i).invoice_id,         -- invoice_id Bug7611551
	            --P_Invoice_Header_Rec.invoice_id,      -- invoice_id
	            l_user_id,                            -- last_updated_by
	            l_sysdate,                            -- last_update_date
	            l_inv_self_ins(i).line_type_lookup_code,
	                                                  -- line_type_lookup_code
	            l_inv_self_ins(i).period_name,        -- period_name
                    l_inv_self_ins(i).set_of_books_id,         -- set_of_books_id bug7611551
	            --P_Invoice_Header_Rec.set_of_books_id, -- set_of_books_id
	            l_inv_self_ins(i).amount,             -- amount
	            decode(l_inv_self_ins(i).base_amount,
                           0, decode(l_inv_self_ins(i).amount, 0, l_inv_self_ins(i).base_amount, NULL),
                           l_inv_self_ins(i).base_amount), -- base_amount
	            l_inv_self_ins(i).batch_id,           -- batch_id  --Bug7611551
                    --P_Invoice_Header_Rec.batch_id,      -- batch_id
	            l_user_id,                            -- created_by
	            l_sysdate,                            -- creation_date
	            l_inv_self_ins(i).description,        -- description
	            NULL,                                 -- final_match_flag
	            l_inv_self_ins(i).income_tax_region,  -- income_tax_region
	            l_login_id,                           -- last_update_login
	            NULL,                                 -- match_status_flag
	            'N',                                  -- posted_flag
	            l_inv_self_ins(i).po_distribution_id, -- po_distribution_id
	            NULL,                                 -- program_application_id
	            NULL,                                 -- program_id
	            NULL,                                 -- program_update_date
	            NULL,                                 -- quantity_invoiced
	            NULL,                                 -- request_id
	            'N',                                  -- reversal_flag
	            l_inv_self_ins(i).type_1099,          -- type_1099
	            NULL,                                 -- unit_price
	            'N',                                  -- encumbered_flag
	            NULL,                                 -- stat_amount
	            l_inv_self_ins(i).attribute1,         -- attribute1
	            l_inv_self_ins(i).attribute10,        -- attribute10
	            l_inv_self_ins(i).attribute11,        -- attribute11,
	            l_inv_self_ins(i).attribute12,        -- attribute12
	            l_inv_self_ins(i).attribute13,        -- attribute13
	            l_inv_self_ins(i).attribute14,        -- attribute14
	            l_inv_self_ins(i).attribute15,        -- attribute15
	            l_inv_self_ins(i).attribute2,         -- attribute2
	            l_inv_self_ins(i).attribute3,         -- attribute3
	            l_inv_self_ins(i).attribute4,         -- attribute4
	            l_inv_self_ins(i).attribute5,         -- attribute5
	            l_inv_self_ins(i).attribute6,         -- attribute6
	            l_inv_self_ins(i).attribute7,         -- attribute7
	            l_inv_self_ins(i).attribute8,         -- attribute8
	            l_inv_self_ins(i).attribute9,         -- attribute9
	            l_inv_self_ins(i).attribute_category, -- attribute_category
	            l_inv_self_ins(i).expenditure_item_date,
	                                                  -- expenditure_item_date
	            l_inv_self_ins(i).expenditure_organization_id,
	                                                  -- expenditure_organization_id
	            l_inv_self_ins(i).expenditure_type,   -- expenditure_type
        	    l_inv_self_ins(i).parent_invoice_id,  -- parent_invoice_id
	            l_inv_self_ins(i).pa_addition_flag,   -- pa_addition_flag
	            l_inv_self_ins(i).pa_quantity,        -- pa_quantity
	            NULL,                                 -- prepay_amount_remaining
	            -- the prepay_amount_remaining will be populated for all the
	            -- prepayment distributions during the payment. And later will be
	            -- updated during the prepayment applications
	            l_inv_self_ins(i).project_accounting_context,
	                                                  -- project_accounting_context
	            l_inv_self_ins(i).project_id,         -- project_id
	            l_inv_self_ins(i).task_id,            -- task_id
	            NULL,                                 -- packet_id
	            'N',                                  -- awt_flag
	            l_inv_self_ins(i).awt_group_id,       -- awt_group_id
	            NULL,                                 -- awt_tax_rate_id
	            NULL,                                 -- awt_gross_amount
	            NULL,                                 -- awt_invoice_id
	            NULL,                                 -- awt_origin_group_id
	            NULL,                                 -- reference_1
	            NULL,                                 -- reference_2
                    l_inv_self_ins(i).org_id,             -- org_id --Bug7611551
  	            --P_Invoice_Header_Rec.org_id,        -- org_id
	            NULL,                                 -- awt_invoice_payment_id
	            l_inv_self_ins(i).global_attribute_category,
	                                                  -- global_attribute_category
	            l_inv_self_ins(i).global_attribute1,  -- global_attribute1
	            l_inv_self_ins(i).global_attribute2,  -- global_attribute2
	            l_inv_self_ins(i).global_attribute3,  -- global_attribute3
	            l_inv_self_ins(i).global_attribute4,  -- global_attribute4
	            l_inv_self_ins(i).global_attribute5,  -- global_attribute5
	            l_inv_self_ins(i).global_attribute6,  -- global_attribute6
	            l_inv_self_ins(i).global_attribute7,  -- global_attribute7
	            l_inv_self_ins(i).global_attribute8,  -- global_attribute8
	            l_inv_self_ins(i).global_attribute9,  -- global_attribute9
	            l_inv_self_ins(i).global_attribute10, -- global_attribute10
	            l_inv_self_ins(i).global_attribute11, -- global_attribute11
	            l_inv_self_ins(i).global_attribute12, -- global_attribute12
	            l_inv_self_ins(i).global_attribute13, -- global_attribute13
	            l_inv_self_ins(i).global_attribute14, -- global_attribute14
	            l_inv_self_ins(i).global_attribute15, -- global_attribute15
	            l_inv_self_ins(i).global_attribute16, -- global_attribute16
	            l_inv_self_ins(i).global_attribute17, -- global_attribute17
	            l_inv_self_ins(i).global_attribute18, -- global_attribute18
        	    l_inv_self_ins(i).global_attribute19, -- global_attribute19
	            l_inv_self_ins(i).global_attribute20, -- global_attribute20
	            NULL,                                 -- receipt_verified_flag
	            NULL,                                 -- receipt_required_flag
	            NULL,                                 -- receipt_missing_flag
	            NULL,                                 -- justification
	            NULL,                                 -- expense_group
	            NULL,                                 -- start_expense_date
	            NULL,                                 -- end_expense_date
	            NULL,                                 -- receipt_currency_code
	            NULL,                                 -- receipt_conversion_rate
	            NULL,                                 -- receipt_currency_amount
	            NULL,                                 -- daily_amount
	            NULL,                                 -- web_parameter_id
	            NULL,                                 -- adjustment_reason
	            l_inv_self_ins(i).award_id,           -- award_id
	            NULL,                                 -- credit_card_trx_id
	            l_inv_self_ins(i).dist_match_type,    -- dist_match_type
	            l_inv_self_ins(i).rcv_transaction_id, -- rcv_transaction_id
        	    ap_invoice_distributions_s.NEXTVAL,   -- invoice_distribution_id
	            NULL,                                 -- parent_reversal_id
	            l_inv_self_ins(i).tax_recoverable_flag,
	                                                  -- tax_recoverable_flag
	            NULL,                                 -- merchant_document_number
	            NULL,                                 -- merchant_name
	            NULL,                                 -- merchant_reference
	            NULL,                                 -- merchant_tax_reg_number
	            NULL,                                 -- merchant_taxpayer_id
	            NULL,                                 -- country_of_supply
	            NULL,                                 -- matched_uom_lookup_code
	            NULL,                                 -- gms_burdenable_raw_cost
	            NULL,                                 -- accounting_event_id
	            l_inv_self_ins(i).prepay_distribution_id,  -- prepay_distribution_id
	            NULL,                                 -- upgrade_posted_amt
	            NULL,                                 -- upgrade_base_posted_amt
	            'N',                                  -- inventory_transfer_status
	            NULL,                                 -- company_prepaid_invoice_id
	            NULL,                                 -- cc_reversal_flag
	            NULL,                                 -- awt_withheld_amt
	            NULL,                                 -- pa_cmt_xface_flag
	            l_inv_self_ins(i).cancellation_flag,  -- cancellation_flag
	            l_inv_self_ins(i).invoice_line_number,-- invoice_line_number
	            l_inv_self_ins(i).corrected_invoice_dist_id,
	                                                  -- corrected_invoice_dist_id
	            l_inv_self_ins(i).rounding_amt,       -- rounding_amt
	            l_inv_self_ins(i).charge_applicable_to_dist_id,
	                                                 -- charge_applicable_to_dist_id
	            NULL,                                 -- corrected_quantity
	            NULL,                                 -- related_id
	            NULL,                                 -- asset_book_type_code
	            NULL,                                 -- asset_category_id
	            l_inv_self_ins(i).distribution_class, -- distribution_class
	            l_inv_self_ins(i).tax_code_id,        -- tax_code_id
	            NULL,                                 -- intended_use,
	            l_inv_self_ins(i).detail_tax_dist_id, -- detail_tax_dist_id
	            l_inv_self_ins(i).rec_nrec_rate,      -- rec_nrec_rate
	            l_inv_self_ins(i).recovery_rate_id,   -- recovery_rate_id
	            l_inv_self_ins(i).recovery_rate_name, -- recovery_rate_name
	            l_inv_self_ins(i).recovery_type_code, -- recovery_type_code
	            NULL,                                 -- withholding_tax_code_id,
	            l_inv_self_ins(i).taxable_amount,     -- taxable_amount
	            l_inv_self_ins(i).taxable_base_amount, -- taxable_base_amount
	            NULL,                                -- tax_already_distributed_flag
	            l_inv_self_ins(i).summary_tax_line_id, -- summary_tax_line_id
	            l_inv_self_ins(i).extra_po_erv,        -- extra_po_erv
	            l_inv_self_ins(i).prepay_tax_diff_amount, -- prepay_tax_diff_amount
	            l_tax_liab_ccid,                        -- self_assessed_tax_liab_ccid
		    'N',				    -- rcv_charge_addition_flag
		    'Y'					    -- self_assessed_flag
		     );
Line: 4720

            L_INV_SELF_INS.DELETE;
Line: 4723

    CLOSE INSERT_TAX_SELF;
Line: 4727

    l_debug_info := 'Delete tax distributions';
Line: 4733

    DELETE FROM ap_invoice_distributions_all aid
     WHERE aid.invoice_distribution_id IN
		(SELECT /*+ leading(gt) cardinality(gt,1) */
                        dist.invoice_distribution_id
	           FROM zx_trx_headers_gt		gt,
			ap_invoice_distributions_all	dist
		  WHERE gt.application_id         = AP_ETAX_PKG.AP_APPLICATION_ID
	            AND gt.entity_code            = AP_ETAX_PKG.AP_ENTITY_CODE
	            AND gt.event_class_code       IN (AP_ETAX_PKG.AP_INV_EVENT_CLASS_CODE,
	                                              AP_ETAX_PKG.AP_PP_EVENT_CLASS_CODE,
	                                              AP_ETAX_PKG.AP_ER_EVENT_CLASS_CODE)
	            AND gt.trx_id                 = dist.invoice_id
		    AND dist.line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX', 'TRV', 'TIPV', 'TERV')
		    AND NOT EXISTS
				(SELECT 'Tax Distributions'
				   FROM zx_rec_nrec_dist zd
				  WHERE zd.rec_nrec_tax_dist_id = dist.detail_tax_dist_id
				   AND NVL(SELF_ASSESSED_FLAG, 'N') = 'N')-- bug 7422547
		);                                                        --Bug7634436
Line: 4755

    l_debug_info := 'Get self assessed distributions to delete';
Line: 4761

    DELETE FROM ap_self_assessed_tax_dist_all aid
     WHERE aid.invoice_distribution_id IN
                (SELECT /*+ leading(gt) cardinality(gt,1) */
			dist.invoice_distribution_id
                   FROM zx_trx_headers_gt               gt,
                        ap_self_assessed_tax_dist_all   dist
                  WHERE gt.application_id         = AP_ETAX_PKG.AP_APPLICATION_ID
                    AND gt.entity_code            = AP_ETAX_PKG.AP_ENTITY_CODE
                    AND gt.event_class_code       IN (AP_ETAX_PKG.AP_INV_EVENT_CLASS_CODE,
                                                      AP_ETAX_PKG.AP_PP_EVENT_CLASS_CODE,
                                                      AP_ETAX_PKG.AP_ER_EVENT_CLASS_CODE)
                    AND gt.trx_id                 = dist.invoice_id
                    AND dist.line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX')
                    AND NOT EXISTS
                                (SELECT 'Tax Distributions'
                                   FROM zx_rec_nrec_dist zd
                                  WHERE zd.rec_nrec_tax_dist_id = dist.detail_tax_dist_id
				                   AND NVL(SELF_ASSESSED_FLAG, 'N') = 'Y')-- bug 7422547
                );                                                                        --bug7634436
Line: 4788

    UPDATE ap_invoice_distributions_all aid
       SET invoice_line_number = (SELECT line_number
                                    FROM ap_invoice_lines_all ail
                                   WHERE ail.invoice_id          = aid.invoice_id
                                     AND ail.summary_tax_line_id = aid.summary_tax_line_id
                                     AND rownum                  = 1)
     WHERE aid.invoice_distribution_id IN
                (SELECT /*+ leading(gt) cardinality(gt,1) */
                        dist.invoice_distribution_id
                   FROM zx_trx_headers_gt               gt,
                        ap_invoice_distributions_all    dist
                  WHERE gt.application_id         = 200
                    AND gt.entity_code            = 'AP_INVOICES'
                    AND gt.event_class_code       IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                    AND gt.trx_id                 = dist.invoice_id
                    AND dist.line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX', 'TRV', 'TIPV', 'TERV')
                    AND dist.invoice_line_number NOT IN
                                                        (SELECT line_number
                                                           FROM ap_invoice_lines_all al
                                                          WHERE al.invoice_id  = dist.invoice_id)
                );
Line: 4811

        FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, 'Orphan Distributions updated: '||sql%rowcount);
Line: 4829

      IF (insert_tax_dist%ISOPEN ) THEN
        CLOSE insert_tax_dist;
Line: 4890

    SELECT *
      FROM zx_transaction_lines_gt
     WHERE trx_id = P_Invoice_Header_Rec.invoice_id
       AND trx_line_id = c_line_number;
Line: 4896

    SELECT *
      FROM zx_import_tax_lines_gt
     WHERE trx_id = P_Invoice_Header_Rec.invoice_id
       AND summary_tax_line_number = c_line_number;
Line: 4902

    SELECT ve.trx_id invoice_id,
           ve.trx_line_id line_number,
           ve.message_name rejection_code,
           ve.summary_tax_line_number summary_tax_line_number,
           ail.invoice_line_id invoice_line_id
      FROM zx_validation_errors_gt ve,
           ap_invoice_lines_interface ail
     WHERE ve.application_id = 200
       AND ve.entity_code = 'AP_INVOICES'
       AND ve.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
       AND ve.trx_id = P_Invoice_Header_Rec.invoice_id
       AND ail.invoice_id = ve.trx_id;
Line: 4948

          IF (AP_IMPORT_UTILITIES_PKG.insert_rejections(
                p_parent_table        => 'AP_INVOICES_INTERFACE',
                p_parent_id           => rej_lines(i).invoice_id,
                p_reject_code         => rej_lines(i).rejection_code,
                p_last_updated_by     => l_user_id,
                p_last_update_login   => l_login_id,
                p_calling_sequence    => l_curr_calling_sequence) <> TRUE) THEN

               RETURN FALSE;
Line: 4961

          IF (AP_IMPORT_UTILITIES_PKG.insert_rejections(
                p_parent_table        => 'AP_INVOICE_LINES_INTERFACE',
                p_parent_id           => rej_lines(i).invoice_line_id,
                p_reject_code         => rej_lines(i).rejection_code,
                p_last_updated_by     => l_user_id,
                p_last_update_login   => l_login_id,
                p_calling_sequence    => l_curr_calling_sequence) <> TRUE) THEN
		RETURN FALSE;
Line: 4976

    ELSE  -- there are no rejections for this invoice.  Update pl/sql tables
          -- with defaulted info

      -- No need to update invoice header import pl/sql record since
      -- eTax will not default any column.

      -----------------------------------------------------------------
      l_debug_info := 'Step 3: Loop through lines import pl/sql table';
Line: 4993

          l_debug_info := 'Step 4: Get trx and tax line info to update pl/sql '||
                          'table';
Line: 5009

            l_debug_info := 'Step 5: Update non-tax lines in pl/sql table';
Line: 5043

            l_debug_info := 'Step 6: Update tax lines in pl/sql table';
Line: 5070

              l_debug_info := 'Step 7: Update tax line if tax only invoice in pl/sql table';
Line: 5147

                    'update amount and base_amount for line(s)';
Line: 5150

      UPDATE ap_invoice_lines_all ail
         SET (ail.amount, ail.base_amount) =
             (SELECT NVL(ail.amount, 0) - SUM(NVL(zdl.tax_amt,0)),
                     NVL(ail.base_amount,0) - SUM(NVL(zdl.tax_amt_funcl_curr,0))
                FROM zx_detail_tax_lines_gt zdl
             WHERE zdl.application_id = 200
                 AND zdl.entity_code = 'AP_INVOICES'
		 AND zdl.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                 AND zdl.trx_id = ail.invoice_id
                 AND zdl.trx_line_id = ail.line_number
                 AND NVL(zdl.self_assessed_flag, 'N') = 'N'
                 AND NVL(zdl.tax_amt_included_flag, 'N') = 'N')
       WHERE ail.invoice_id = P_Invoice_Header_Rec.invoice_id
         AND ail.line_type_lookup_code NOT IN ('TAX', 'AWT');
Line: 5235

    SELECT message_text
      INTO p_error_code
      FROM zx_errors_gt
     WHERE rownum = 1;
Line: 5311

    SELECT 'Y'
--- Start for bug 6485124
    FROM   zx_lines_det_factors
     WHERE  trx_id = p_invoice_id
     AND application_id        =  200
     AND entity_code   =  'AP_INVOICES'
     AND event_class_code IN
         ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
     AND ROWNUM=1;
Line: 5412

     SELECT 'Y'
      INTO l_tax_already_calculated_flag
      FROM ap_invoice_lines_all
     WHERE invoice_id = p_invoice_id
       AND line_type_lookup_code <> 'AWT'
       AND (tax_already_calculated_flag = 'Y'
             OR  summary_tax_line_id IS NOT NULL)
       AND ROWNUM = 1;
Line: 5468

    SELECT 'Y'
      FROM ap_invoice_distributions_all
     WHERE invoice_id = p_invoice_id
       AND line_type_lookup_code <> 'AWT'
       AND (tax_already_distributed_flag = 'Y'
            OR detail_tax_dist_id IS NOT NULL)
       AND (related_id IS NULL
            OR related_id = invoice_distribution_id)
       AND ROWNUM = 1;
Line: 5553

    SELECT invoice_distribution_id
      FROM ap_invoice_distributions_all
     WHERE detail_tax_dist_id = P_Tax_Dist_Id;
Line: 5647

   l_debug_info := 'Select values from ap_invoice_distributions for tax distribution id';
Line: 5649

   SELECT aid1.invoice_distribution_id parent_distribution_id,
   	  ai.invoice_type_lookup_code ,
	  ail.line_type_lookup_code,
	  ail1.line_type_lookup_code parent_line_type_lookup_code,
	  ail1.line_number parent_line_number,
	  ail1.discarded_flag,
	  aid.posted_flag,
   	  aid.encumbered_flag,
	  aid.reversal_flag,
	  aid.prepay_distribution_id,
	  aid.pa_addition_flag,
	  nvl(aid.match_status_flag,'N'),
	  aid1.po_distribution_id,
	  aid1.rcv_transaction_id,
	  aid1.amount,
	  aid1.prepay_amount_remaining
   INTO l_parent_distribution_id,
    	l_invoice_type_lookup_code,
	l_line_type_lookup_code,
	l_parent_line_type_lookup_code,
	l_parent_line_number,
	l_discarded_flag,
        l_encumbered_flag,
	l_posted_flag,
	l_reversal_flag,
	l_prepay_distribution_id,
	l_pa_addition_flag,
	l_match_status_flag,
	l_po_distribution_id,
	l_rcv_transaction_id,
	l_parent_dist_amount,
	l_prepay_amount_remaining
   FROM ap_invoice_distributions aid,
   	ap_invoice_distributions aid1,
	ap_invoices ai,
	ap_invoice_lines ail,
	ap_invoice_lines ail1
   WHERE ai.invoice_id = p_invoice_id
   AND ail.invoice_id = ai.invoice_id
   AND ail.line_number = aid.invoice_line_number
   AND aid.invoice_id = ai.invoice_id
   AND aid1.invoice_id = ai.invoice_id
   AND aid.invoice_distribution_id = p_tax_dist_id
   /* Outer join is needed since charge_applicable_to_dist_id can be NULL
      for Tax-Only lines */
   AND aid.charge_applicable_to_dist_id = aid1.invoice_distribution_id(+)
   AND ail1.invoice_id = p_invoice_id
   AND aid1.invoice_line_number = ail1.line_number(+);
Line: 5714

      SELECT zl.discarded_flag
      INTO l_discarded_flag
      FROM zx_lines zl,
           zx_rec_nrec_dist zd,
           ap_invoice_distributions aid
      WHERE zl.tax_line_id = zd.tax_line_id
      AND nvl(zl.reporting_only_flag, 'N') = 'N'
      AND zd.rec_nrec_tax_dist_id = aid.detail_tax_dist_id
      AND aid.invoice_distribution_id = p_tax_dist_id; */
Line: 5876

  |  FUNCTION - Is_Tax_Line_Delete_Allowed()
  |
  |  DESCRIPTION
  |    This function will return TRUE when Detail Tax line can be deleted in ETAX,
  |    else will return FALSE.
  |
  |    When the function returns TRUE, then user can delete the TAX line else
  |      should not be allowed to delete the TAX line.
  |
  |  PARAMETERS
  |    P_Invoice_Id  - Is the invoice_id of the of the Invoice which owns this
  |                    detail tax line indirectly through the summary tax line.
  |    P_Detail_Tax_Line_Id - Is the id for a Detail Tax Line in eTax
  |
  |  USAGE: This function is called from ETAX security functions in APXINWKB.fmb
  |         from the form procedure 'IS_TAX_LINE_DELETE_ALLOWED'.
  |
  |  MODIFICATION HISTORY
  |    DATE          Author         Action
  |    04-JUL-2004   SMYADAM        Created
  |
  *============================================================================*/
  FUNCTION IS_TAX_LINE_DELETE_ALLOWED(P_Invoice_Id IN NUMBER,
                                      P_Detail_Tax_Line_Id IN NUMBER,
                                      P_Calling_Sequence IN VARCHAR2) RETURN BOOLEAN IS

     CURSOR Tax_Distributions IS
     SELECT aid.invoice_distribution_id
     FROM ap_invoice_distributions aid,
          zx_rec_nrec_dist zd
     WHERE aid.invoice_id = p_invoice_id
     AND aid.detail_tax_dist_id = zd.rec_nrec_tax_dist_id
     AND zd.tax_line_id = p_detail_tax_line_id;
Line: 5911

     l_tax_line_delete_allowed     varchar2(1) := 'Y';
Line: 5917

   l_curr_calling_sequence := p_calling_sequence ||'->AP_Etax_Utility_Pkg.Is_Tax_Line_Delete_Allowed';
Line: 5926

    EXIT WHEN tax_distributions%NOTFOUND OR l_tax_line_delete_allowed = 'N';
Line: 5931

      l_tax_line_delete_allowed := 'N';
Line: 5937

   IF (l_tax_line_delete_allowed = 'N') THEN
     RETURN(FALSE);
Line: 5957

  END IS_TAX_LINE_DELETE_ALLOWED;
Line: 6462

        SELECT territory_short_name
          FROM fnd_territories_tl
         WHERE territory_code = c_ctry_code
           AND language = userenv ('LANG');
Line: 6468

        SELECT ai.invoice_num tax_related_invoice_num
          FROM ap_invoices ai
         WHERE ai.invoice_id = c_inv_id;
Line: 6474

        SELECT classification_name
          FROM zx_fc_intended_use_v
         WHERE classification_code = c_class_code
           AND country_code        = c_ctry_code;
Line: 6584

        SELECT classification_name
        FROM   zx_fc_business_categories_v
        WHERE  classification_code = c_class_code
        AND    (country_code       = c_txn_ctry OR
                country_code IS NULL);
Line: 6592

        SELECT classification_name
        FROM   zx_fc_product_fiscal_v
        WHERE  classification_code = c_class_code
        AND    (country_code       = c_txn_ctry OR
                country_code IS NULL);
Line: 6600

        SELECT classification_name
        FROM   zx_fc_user_defined_v
        WHERE  classification_code = c_class_code
        AND    (country_code       = c_txn_ctry OR
                country_code IS NULL);
Line: 6608

        SELECT classification_name
        FROM   zx_fc_intended_use_v
        WHERE  classification_code = c_class_code
        AND    (country_code       = c_txn_ctry OR
                country_code IS NULL);
Line: 6615

        SELECT classification_name
        FROM   zx_product_types_v
	WHERE  classification_code = c_class_code;
Line: 6621

        SELECT classification_name
        FROM   zx_fc_product_categories_v
        WHERE  classification_code = c_class_code
        AND    (country_code       = c_txn_ctry OR
                country_code IS NULL);
Line: 6767

        SELECT vl.tax_regime_name
        FROM   zx_regimes_vl vl
        WHERE  vl.country_code    = c_txn_ctry
        AND    vl.tax_regime_code = c_tax_regime_code;
Line: 6774

        SELECT tax_full_name
        FROM   zx_sco_taxes
        WHERE  tax_regime_code = c_tax_regime
        AND    tax             = c_tax;
Line: 6782

        SELECT tax_jurisdiction_name
          FROM zx_jurisdictions_vl
         WHERE tax_regime_code       = c_tax_regime
           AND tax                   = c_tax
           AND tax_jurisdiction_code = c_tax_jurisdiction;
Line: 6791

        SELECT tax_status_name
        FROM   zx_sco_status
        WHERE  tax_regime_code  = c_tax_regime
        AND    tax              = c_tax
        AND    tax_status_code  = c_tax_status;
Line: 7014

PROCEDURE insert_tax_distributions(
				  p_invoice_header_rec       IN ap_invoices_all%ROWTYPE,
				  p_inv_dist_rec             IN r_ins_tax_dist_info,
				  p_dist_code_combination_id IN NUMBER,
				  p_user_id	             IN NUMBER,
				  p_sysdate	             IN DATE,
				  p_login_id	             IN	NUMBER,
				  p_calling_sequence         IN VARCHAR2) IS

 l_curr_calling_sequence VARCHAR2(2000);
Line: 7032

     l_api_name := 'Insert_Tax_Distributions';
Line: 7034

     l_curr_calling_sequence := 'Insert_Tax_Distributions <- '||p_calling_sequence;
Line: 7037

       FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME||l_api_name,'AP_ETAX_UTILITY_PKG.Insert_Tax_Distributions(+)');
Line: 7040

     l_debug_info := 'Step 11: Insert new distributions including variances';
Line: 7047

     select ap_invoice_distributions_s.NEXTVAL into l_invoice_distribution_id from dual;
Line: 7049

     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,
            final_match_flag,
            income_tax_region,
            last_update_login,
            match_status_flag,
            posted_flag,
            po_distribution_id,
            program_application_id,
            program_id,
            program_update_date,
            quantity_invoiced,
            request_id,
            reversal_flag,
            type_1099,
            unit_price,
            encumbered_flag,
            stat_amount,
            attribute1,
            attribute10,
            attribute11,
            attribute12,
            attribute13,
            attribute14,
            attribute15,
            attribute2,
            attribute3,
            attribute4,
            attribute5,
            attribute6,
            attribute7,
            attribute8,
            attribute9,
            attribute_category,
            expenditure_item_date,
            expenditure_organization_id,
            expenditure_type,
            parent_invoice_id,
            pa_addition_flag,
            pa_quantity,
            prepay_amount_remaining,
            project_accounting_context,
            project_id,
            task_id,
            packet_id,
            awt_flag,
            awt_group_id,
            awt_tax_rate_id,
            awt_gross_amount,
            awt_invoice_id,
            awt_origin_group_id,
            reference_1,
            reference_2,
            org_id,
            awt_invoice_payment_id,
            global_attribute_category,
            global_attribute1,
            global_attribute2,
            global_attribute3,
            global_attribute4,
            global_attribute5,
            global_attribute6,
            global_attribute7,
            global_attribute8,
            global_attribute9,
            global_attribute10,
            global_attribute11,
            global_attribute12,
            global_attribute13,
            global_attribute14,
            global_attribute15,
            global_attribute16,
            global_attribute17,
            global_attribute18,
            global_attribute19,
            global_attribute20,
            receipt_verified_flag,
            receipt_required_flag,
            receipt_missing_flag,
            justification,
            expense_group,
            start_expense_date,
            end_expense_date,
            receipt_currency_code,
            receipt_conversion_rate,
            receipt_currency_amount,
            daily_amount,
            web_parameter_id,
            adjustment_reason,
            award_id,
            credit_card_trx_id,
            dist_match_type,
            rcv_transaction_id,
            invoice_distribution_id,
            parent_reversal_id,
            tax_recoverable_flag,
            merchant_document_number,
            merchant_name,
            merchant_reference,
            merchant_tax_reg_number,
            merchant_taxpayer_id,
            country_of_supply,
            matched_uom_lookup_code,
            gms_burdenable_raw_cost,
            accounting_event_id,
            prepay_distribution_id,
            upgrade_posted_amt,
            upgrade_base_posted_amt,
            inventory_transfer_status,
            company_prepaid_invoice_id,
            cc_reversal_flag,
            awt_withheld_amt,
            pa_cmt_xface_flag,
            cancellation_flag,
            invoice_line_number,
            corrected_invoice_dist_id,
            rounding_amt,
            charge_applicable_to_dist_id,
            corrected_quantity,
            related_id,
            asset_book_type_code,
            asset_category_id,
            distribution_class,
            tax_code_id,
            intended_use,
            detail_tax_dist_id,
            rec_nrec_rate,
            recovery_rate_id,
            recovery_rate_name,
            recovery_type_code,
            withholding_tax_code_id,
            taxable_amount,
            taxable_base_amount,
            tax_already_distributed_flag,
            summary_tax_line_id,
            extra_po_erv,
            prepay_tax_diff_amount,
	    --Freight and Special Charges
	    rcv_charge_addition_flag )
      VALUES (
            p_inv_dist_rec.accounting_date,    -- accounting_date
            'N',                                  -- accrual_posted_flag
            'U',                                  -- assets_addition_flag
            'N',                                  -- assets_tracking_flag
            'N',                                  -- cash_posted_flag
            AP_INVOICE_LINES_PKG.get_max_dist_line_num(
              p_inv_dist_rec.invoice_id,
              p_inv_dist_rec.invoice_line_number)+1,
                                                  -- distribution_line_number
            P_dist_code_combination_id,           -- dist_code_combination_id
            p_inv_dist_rec.invoice_id,      	  -- invoice_id
            P_user_id,                            -- last_updated_by
            P_sysdate,                            -- last_update_date
            p_inv_dist_rec.line_type_lookup_code,
                                                  -- line_type_lookup_code
            p_inv_dist_rec.period_name,           -- period_name
            p_inv_dist_rec.set_of_books_id,	  -- set_of_books_id
            p_inv_dist_rec.amount,                -- amount
            decode(p_inv_dist_rec.base_amount,
                   0, decode(p_inv_dist_rec.amount, 0, p_inv_dist_rec.base_amount, NULL),
                   p_inv_dist_rec.base_amount),   -- base_amount
            p_inv_dist_rec.batch_id,        	  -- batch_id
            P_user_id,                            -- created_by
            P_sysdate,                            -- creation_date
            p_inv_dist_rec.description,        	  -- description
            NULL,                                 -- final_match_flag
            p_inv_dist_rec.income_tax_region,  -- income_tax_region
            P_login_id,                           -- last_update_login
            NULL,                                 -- match_status_flag
            'N',                                  -- posted_flag
            p_inv_dist_rec.po_distribution_id, -- po_distribution_id
            NULL,                                 -- program_application_id
            NULL,                                 -- program_id
            NULL,                                 -- program_update_date
            NULL,                                 -- quantity_invoiced
            NULL,                                 -- request_id
            'N',                                  -- reversal_flag
            p_inv_dist_rec.type_1099,          -- type_1099
            NULL,                                 -- unit_price
            'N',                                  -- encumbered_flag
            NULL,                                 -- stat_amount
            p_inv_dist_rec.attribute1,         -- attribute1
            p_inv_dist_rec.attribute10,        -- attribute10
            p_inv_dist_rec.attribute11,        -- attribute11,
            p_inv_dist_rec.attribute12,        -- attribute12
            p_inv_dist_rec.attribute13,        -- attribute13
            p_inv_dist_rec.attribute14,        -- attribute14
            p_inv_dist_rec.attribute15,        -- attribute15
            p_inv_dist_rec.attribute2,         -- attribute2
            p_inv_dist_rec.attribute3,         -- attribute3
            p_inv_dist_rec.attribute4,         -- attribute4
            p_inv_dist_rec.attribute5,         -- attribute5
            p_inv_dist_rec.attribute6,         -- attribute6
            p_inv_dist_rec.attribute7,         -- attribute7
            p_inv_dist_rec.attribute8,         -- attribute8
            p_inv_dist_rec.attribute9,         -- attribute9
            p_inv_dist_rec.attribute_category, -- attribute_category
            p_inv_dist_rec.expenditure_item_date,
                                                  -- expenditure_item_date
            p_inv_dist_rec.expenditure_organization_id,
                                                  -- expenditure_organization_id
            p_inv_dist_rec.expenditure_type,   -- expenditure_type
            p_inv_dist_rec.parent_invoice_id,  -- parent_invoice_id
            p_inv_dist_rec.pa_addition_flag,   -- pa_addition_flag
            p_inv_dist_rec.pa_quantity,        -- pa_quantity
            NULL,                                 -- prepay_amount_remaining
            -- the prepay_amount_remaining will be populated for all the
            -- prepayment distributions during the payment. And later will be
            -- updated during the prepayment applications
            p_inv_dist_rec.project_accounting_context,
                                                  -- project_accounting_context
            p_inv_dist_rec.project_id,         -- project_id
            p_inv_dist_rec.task_id,            -- task_id
            NULL,                                 -- packet_id
            'N',                                  -- awt_flag
            p_inv_dist_rec.awt_group_id,       -- awt_group_id
            NULL,                                 -- awt_tax_rate_id
            NULL,                                 -- awt_gross_amount
            NULL,                                 -- awt_invoice_id
            NULL,                                 -- awt_origin_group_id
            NULL,                                 -- reference_1
            NULL,                                 -- reference_2
            p_inv_dist_rec.org_id,		  -- org_id
            NULL,                                 -- awt_invoice_payment_id
            p_inv_dist_rec.global_attribute_category,
                                                  -- global_attribute_category
            p_inv_dist_rec.global_attribute1,  -- global_attribute1
            p_inv_dist_rec.global_attribute2,  -- global_attribute2
            p_inv_dist_rec.global_attribute3,  -- global_attribute3
            p_inv_dist_rec.global_attribute4,  -- global_attribute4
            p_inv_dist_rec.global_attribute5,  -- global_attribute5
            p_inv_dist_rec.global_attribute6,  -- global_attribute6
            p_inv_dist_rec.global_attribute7,  -- global_attribute7
            p_inv_dist_rec.global_attribute8,  -- global_attribute8
            p_inv_dist_rec.global_attribute9,  -- global_attribute9
            p_inv_dist_rec.global_attribute10, -- global_attribute10
            p_inv_dist_rec.global_attribute11, -- global_attribute11
            p_inv_dist_rec.global_attribute12, -- global_attribute12
            p_inv_dist_rec.global_attribute13, -- global_attribute13
            p_inv_dist_rec.global_attribute14, -- global_attribute14
            p_inv_dist_rec.global_attribute15, -- global_attribute15
            p_inv_dist_rec.global_attribute16, -- global_attribute16
            p_inv_dist_rec.global_attribute17, -- global_attribute17
            p_inv_dist_rec.global_attribute18, -- global_attribute18
            p_inv_dist_rec.global_attribute19, -- global_attribute19
            p_inv_dist_rec.global_attribute20, -- global_attribute20
            NULL,                                 -- receipt_verified_flag
            NULL,                                 -- receipt_required_flag
            NULL,                                 -- receipt_missing_flag
            NULL,                                 -- justification
            NULL,                                 -- expense_group
            NULL,                                 -- start_expense_date
            NULL,                                 -- end_expense_date
            NULL,                                 -- receipt_currency_code
            NULL,                                 -- receipt_conversion_rate
            NULL,                                 -- receipt_currency_amount
            NULL,                                 -- daily_amount
            NULL,                                 -- web_parameter_id
            NULL,                                 -- adjustment_reason
            p_inv_dist_rec.award_id,           -- award_id
            NULL,                                 -- credit_card_trx_id
            p_inv_dist_rec.dist_match_type,    -- dist_match_type
            p_inv_dist_rec.rcv_transaction_id, -- rcv_transaction_id
            l_invoice_distribution_id,         -- invoice_distribution_id
            NULL,                                 -- parent_reversal_id
            p_inv_dist_rec.tax_recoverable_flag,
                                                  -- tax_recoverable_flag
            NULL,                                 -- merchant_document_number
            NULL,                                 -- merchant_name
            NULL,                                 -- merchant_reference
            NULL,                                 -- merchant_tax_reg_number
            NULL,                                 -- merchant_taxpayer_id
            NULL,                                 -- country_of_supply
            NULL,                                 -- matched_uom_lookup_code
            NULL,                                 -- gms_burdenable_raw_cost
            NULL,                                 -- accounting_event_id
            p_inv_dist_rec.prepay_distribution_id,  -- prepay_distribution_id
            NULL,                                 -- upgrade_posted_amt
            NULL,                                 -- upgrade_base_posted_amt
            'N',                                  -- inventory_transfer_status
            NULL,                                 -- company_prepaid_invoice_id
            NULL,                                 -- cc_reversal_flag
            NULL,                                 -- awt_withheld_amt
            NULL,                                 -- pa_cmt_xface_flag
            p_inv_dist_rec.cancellation_flag,  -- cancellation_flag
            p_inv_dist_rec.invoice_line_number,-- invoice_line_number
            p_inv_dist_rec.corrected_invoice_dist_id,
                                                  -- corrected_invoice_dist_id
            p_inv_dist_rec.rounding_amt,       -- rounding_amt
            p_inv_dist_rec.charge_applicable_to_dist_id,
                                                 -- charge_applicable_to_dist_id
            NULL,                                 -- corrected_quantity
            NULL,                                 -- related_id
            NULL,                                 -- asset_book_type_code
            NULL,                                 -- asset_category_id
            p_inv_dist_rec.distribution_class, -- distribution_class
            p_inv_dist_rec.tax_code_id,        -- tax_code_id
            NULL,                                 -- intended_use,
            p_inv_dist_rec.detail_tax_dist_id, -- detail_tax_dist_id
            p_inv_dist_rec.rec_nrec_rate,      -- rec_nrec_rate
            p_inv_dist_rec.recovery_rate_id,   -- recovery_rate_id
            p_inv_dist_rec.recovery_rate_name, -- recovery_rate_name
            p_inv_dist_rec.recovery_type_code, -- recovery_type_code
            NULL,                                 -- withholding_tax_code_id,
            p_inv_dist_rec.taxable_amount,     -- taxable_amount
            p_inv_dist_rec.taxable_base_amount, -- taxable_base_amount
            NULL,                                -- tax_already_distributed_flag
            p_inv_dist_rec.summary_tax_line_id, -- summary_tax_line_id
            p_inv_dist_rec.extra_po_erv,        -- extra_po_erv
            p_inv_dist_rec.prepay_tax_diff_amount, -- prepay_tax_diff_amount
	    'N'					      -- rcv_charge_addition_flag
     );
Line: 7381

      FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME||l_api_name,'AP_ETAX_UTILITY_PKG.Insert_Tax_Distributions(-)');
Line: 7494

      SELECT matching_basis, payment_type, shipment_type
        INTO l_matching_basis, l_payment_type, l_shipment_type
        FROM po_line_locations_all
       WHERE line_location_id = P_Line_Location_Id;
Line: 7550

    SELECT 'Y'
      FROM ap_invoice_distributions_all
     WHERE invoice_id = p_invoice_id
       AND line_type_lookup_code <> 'AWT'
       AND (tax_already_distributed_flag = 'Y'
            OR detail_tax_dist_id IS NOT NULL)
       AND (related_id IS NULL
            OR related_id = invoice_distribution_id)
       AND ROWNUM = 1;
Line: 7607

         SELECT  D.unit_price                 unit_price,
                 pll.matching_basis           match_basis,
                 pll.match_option             match_option,
                 pl.unit_meas_lookup_code     po_uom,
                 D.matched_uom_lookup_code    rcv_uom,
                 rsl.item_id                  rcv_item_id
          FROM   ap_invoice_distributions_all D,
                 po_distributions_all         PD,
                 po_lines_all                 PL,
                 po_line_locations_all        PLL,
                 rcv_transactions             RTXN,
                 rcv_shipment_lines           RSL
          WHERE  D.invoice_distribution_id = c_inv_dist_id
            AND  D.po_distribution_id      = PD.po_distribution_id
            AND  PL.po_header_id           = PD.po_header_id
            AND  PL.po_line_id             = PD.po_line_id
            AND  PD.line_location_id       = PLL.line_location_id
            AND  D.rcv_transaction_id      = RTXN.transaction_id
            AND  RTXN.shipment_line_id     = RSL.shipment_line_id;
Line: 7669

    SELECT nvl(max(distribution_line_number),0)
      INTO l_max_dist_line_num
      FROM ap_self_assessed_tax_dist_all
     WHERE invoice_id = X_invoice_id
       AND invoice_line_number = X_line_number;