DBA Data[Home] [Help]

APPS.AP_ETAX_SERVICES_PKG SQL Statements

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

Line: 33

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

  FUNCTION Update_Distributions
			(P_Invoice_header_rec    IN ap_invoices_all%ROWTYPE,
             		 P_Calling_Mode          IN VARCHAR2,
             		 P_All_Error_Messages    IN VARCHAR2,
             		 P_Error_Code            OUT NOCOPY VARCHAR2,
             		 P_Calling_Sequence      IN VARCHAR2) RETURN BOOLEAN;
Line: 136

	     Select fa.application_short_name
		into l_application_short_name
	       from fnd_application fa,
		    fnd_product_installations fpi
	      Where fa.application_id = fpi.application_id
		and fa.application_id = p_application_id
		and nvl(fpi.status,'U') <> 'N'
		and rownum = 1;
Line: 187

     SELECT SHIP_TO_ORGANIZATION_ID
      INTO l_po_ship_to_org_id
     FROM po_line_locations_all pll
     WHERE pll.line_location_id = p_po_line_location_Id;
Line: 275

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = c_invoice_Id;
Line: 280

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id = c_invoice_id
       AND (line_type_lookup_code NOT IN ('TAX', 'AWT','RETROTAX','RETROITEM') OR
	   (line_type_lookup_code = 'RETROITEM' AND match_type = 'PO_PRICE_ADJUSTMENT'))  --Bug10416960
       AND nvl(discarded_flag, 'N')  <> 'Y'  --Bug8811102
       AND nvl(cancelled_flag, 'N') <> 'Y';  --Bug8811102;
Line: 292

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id  = c_invoice_id
       AND line_number = c_line_number
       AND (line_type_lookup_code NOT IN ('TAX', 'AWT','RETROTAX','RETROITEM') OR
	       (line_type_lookup_code = 'RETROITEM' AND match_type = 'PO_PRICE_ADJUSTMENT'))  --Bug10416960
       AND nvl(discarded_flag, 'N')  <> 'Y'  --Bug8811102
       AND nvl(cancelled_flag, 'N') <> 'Y';  --Bug8811102
Line: 302

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id            = c_invoice_id
       AND line_type_lookup_code = 'TAX'
       AND summary_tax_line_id   IS NULL
       AND nvl(discarded_flag, 'N')  <> 'Y'  --Bug8811102
       AND nvl(cancelled_flag, 'N') <> 'Y';  --Bug8811102
Line: 312

    CURSOR c_selected_invoices IS
    SELECT trx_id, event_class_code
      FROM zx_trx_headers_gt
     WHERE application_id   =  ap_etax_pkg.ap_application_id
       AND entity_code      =  ap_etax_pkg.ap_entity_code
       AND 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);
Line: 361

       UPDATE /*+ index(ail,AP_INVOICE_LINES_U1) */ ap_invoice_lines_all ail
       SET    tax_already_calculated_flag = NULL
       WHERE  ail.invoice_id IN (SELECT /*+ cardinality(gt 10) unnest */ DISTINCT(trx_id)
                                 FROM   zx_trx_headers_gt gt
                                 WHERE  application_id = 200
                                 AND    entity_code = 'AP_INVOICES')
       AND    NVL(ail.tax_already_calculated_flag, 'N') = 'Y'
	   AND    NVL(ail.historical_flag, 'N') = 'N' --bug14671024
       AND    NOT EXISTS
                (SELECT /*+ no_unnest index(zf,ZX_LINES_DET_FACTORS_U1) */ 'Line Determining Factors Exist'
                   FROM zx_lines_det_factors zf
                  WHERE zf.application_id   = 200
                    AND zf.entity_code        = 'AP_INVOICES'
                    AND zf.event_class_code IN ('STANDARD INVOICES',
                                                'PREPAYMENT INVOICES',
                                                'EXPENSE REPORTS')
                    -- bug 7233679
                    AND ZF.TRX_LEVEL_TYPE = 'LINE'
                    AND ZF.INTERNAL_ORGANIZATION_ID = AIL.ORG_ID
                    AND ZF.lEDGER_ID=AIL.SET_OF_BOOKS_ID
                    -- bug 7233679
                    AND zf.trx_id           = ail.invoice_id
                    AND zf.trx_line_id      = ail.line_number);
Line: 387

       l_debug_info := l_count ||' rows updated in ap_invoice_lines_all.';
Line: 397

       DELETE FROM ZX_TRX_HEADERS_GT;
Line: 461

		 Insert into ap_errors_gt(invoice_id , message_text) values(l_inv_header_rec.invoice_id , 'Error in AP_ETAX_SERVICES_PKG.Populate_Headers_GT');
Line: 498

       UPDATE ap_invoice_lines_all ail
          SET tax_already_calculated_flag = NULL
        WHERE ail.invoice_id = p_invoice_id
          AND nvl(ail.tax_already_calculated_flag, 'N') = 'Y'
		  AND NVL(ail.historical_flag, 'N') = 'N' --bug14671024
          AND NOT EXISTS
		      (SELECT 'Line Determining Factors Exist'
	             from zx_lines_det_factors zf
 	            where zf.application_id   = 200
  	              and zf.entity_code	    = 'AP_INVOICES'
	              and zf.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
	              and zf.trx_id           = ail.invoice_id
  	              and zf.trx_line_id      = ail.line_number);
Line: 514

       l_debug_info := l_count ||' rows updated in ap_invoice_lines_all.';
Line: 539

    DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 540

    DELETE FROM ZX_IMPORT_TAX_LINES_GT;
Line: 541

    DELETE FROM ZX_TRX_TAX_LINK_GT;
Line: 543

    AP_ETAX_SERVICES_PKG.G_SITE_ATTRIBUTES.DELETE;
Line: 544

    AP_ETAX_SERVICES_PKG.G_ORG_ATTRIBUTES.DELETE;
Line: 547

    OPEN C_SELECTED_INVOICES;
Line: 549

        FETCH C_SELECTED_INVOICES
        BULK COLLECT INTO AP_ETAX_PKG.G_INV_ID_LIST,
                          AP_ETAX_PKG.G_EVNT_CLS_LIST
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 560

           EXIT WHEN (C_SELECTED_INVOICES%NOTFOUND
                      AND AP_ETAX_PKG.G_INV_ID_LIST.COUNT <= 0);
Line: 642

		                       Insert into ap_errors_gt(invoice_id , message_text) values(l_inv_header_rec.invoice_id , 'Error in AP_ETAX_SERVICES_PKG.Cache_Line_Defaults');
Line: 672

		                       Insert into ap_errors_gt(invoice_id , message_text) values(l_inv_header_rec.invoice_id , 'Error in AP_ETAX_SERVICES_PKG.Cache_Line_Defaults');
Line: 797

		 Insert into ap_errors_gt(invoice_id , message_text) values(l_inv_header_rec.invoice_id , 'Error in AP_ETAX_SERVICES_PKG.Freeze_itm_Distributions');
Line: 941

            DELETE FROM zx_trx_headers_gt
                WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
                  AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
                  AND 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 trx_id = l_inv_header_rec.invoice_id;
Line: 984

        AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 985

        AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 987

    CLOSE C_SELECTED_INVOICES;
Line: 989

    AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 990

    AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 1041

        OPEN C_SELECTED_INVOICES;
Line: 1043

           FETCH C_SELECTED_INVOICES
            BULK COLLECT INTO AP_ETAX_PKG.G_INV_ID_LIST,
	                      AP_ETAX_PKG.G_EVNT_CLS_LIST
	   LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 1055

              EXIT WHEN (C_SELECTED_INVOICES%NOTFOUND
                         AND AP_ETAX_PKG.G_INV_ID_LIST.COUNT <= 0);
Line: 1067

               IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
		                P_Invoice_header_rec => l_inv_header_rec,
		                P_Calling_Mode       => P_Calling_Mode,
		                P_All_Error_Messages => P_All_Error_Messages,
		                P_Error_Code         => P_error_code,
		                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

                   l_return_status := FALSE;
Line: 1077

           AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 1078

           AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 1080

        CLOSE C_SELECTED_INVOICES;
Line: 1102

    AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 1103

    AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 1174

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 1179

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id = c_invoice_id
       AND line_type_lookup_code NOT IN ('TAX', 'AWT');
Line: 1218

    DELETE FROM ZX_TRX_HEADERS_GT;
Line: 1219

    DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 1220

    DELETE FROM ZX_IMPORT_TAX_LINES_GT;
Line: 1221

    DELETE FROM ZX_TRX_TAX_LINK_GT;
Line: 1225

    l_debug_info := 'Step 2: Update trx_id in header';
Line: 1231

    UPDATE zx_trx_headers_gt
       SET trx_id = P_Invoice_Id
     WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
       AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
       AND 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 trx_id = P_Interface_Invoice_Id;
Line: 1251

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

      l_debug_info := 'Step 3: Update trx_id in Lines';
Line: 1347

      UPDATE zx_transaction_lines_gt
         SET trx_id = P_Invoice_Id
       WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
         AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
         AND 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 trx_id = P_Interface_Invoice_Id;
Line: 1425

       IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
                P_Invoice_header_rec => l_inv_header_rec,
                P_Calling_Mode       => P_Calling_Mode,
                P_All_Error_Messages => P_All_Error_Messages,
                P_Error_Code         => P_error_code,
                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

          l_return_status := FALSE;
Line: 1536

    SELECT ai.*
      FROM ap_invoices_all ai,
	   ap_system_parameters_all asp --Bug14779241
     WHERE ai.invoice_id = c_invoice_id
	   AND asp.org_id = ai.org_id /* Bug14779241: Start */
	   AND ((asp.base_currency_code = ai.invoice_currency_code) OR
               (asp.base_currency_code <> ai.invoice_currency_code AND
               ai.exchange_rate IS NOT NULL)); /* Bug14779241: End */
Line: 1546

    SELECT aid.*
      FROM ap_invoice_lines_all ail,
           ap_invoice_distributions_all aid,
           ap_invoices_all ai , --Bug14779241
	   ap_system_parameters_all asp  --Bug14779241
     WHERE ail.invoice_id  = aid.invoice_id
       AND ail.line_number = aid.invoice_line_number
       AND ail.invoice_id  = c_invoice_id
       AND ai.invoice_id = ail.invoice_id /* Bug14779241: Start */
       AND asp.org_id = ai.org_id
       AND ((asp.base_currency_code = ai.invoice_currency_code) OR
           (asp.base_currency_code <> ai.invoice_currency_code AND
           ai.exchange_rate IS NOT NULL)) /* Bug14779241: End */
       AND (aid.line_type_lookup_code NOT IN
           ('AWT', 'REC_TAX', 'NONREC_TAX', 'TRV', 'TERV', 'TIPV') OR
           (ail.line_type_lookup_code = 'TAX'
            AND aid.charge_applicable_to_dist_id IS NULL
            AND ail.summary_tax_line_id IS NOT NULL
            AND aid.detail_tax_dist_id IS NOT NULL)) --Bug9494315
       AND (aid.line_type_lookup_code <> 'RETAINAGE'
	    or (aid.line_type_lookup_code = 'RETAINAGE'
	        and ail.line_type_lookup_code = 'RETAINAGE RELEASE'))
       AND (aid.line_type_lookup_code <> 'RETROACCRUAL' OR
           (aid.line_type_lookup_code = 'RETROACCRUAL' AND dist_match_type ='PO_PRICE_ADJUSTMENT'))   --Bug10416960
       AND (related_id IS NULL
            or related_id = invoice_distribution_id)
       AND (aid.prepay_distribution_id IS NULL
            or (aid.prepay_distribution_id IS NOT NULL
                and ail.line_type_lookup_code = 'PREPAY'))
       AND ((nvl(ail.discarded_flag, 'N') <> 'Y' AND nvl(ail.cancelled_flag, 'N') <> 'Y') --Bug8811102
            OR (ail.line_type_lookup_code = 'TAX'  AND aid.reversal_flag IS NULL)) --Bug9494315
       AND p_calling_mode <> 'DISTRIBUTE RECOUP'
       AND   (NVL(aid.reversal_flag,'N') <> 'Y') -- bug 12419997 --Bug14383132
    UNION
    SELECT aid.*
      FROM ap_invoice_lines_all ail,
           ap_invoice_distributions_all aid,
           ap_invoices_all ai,  --Bug14779241
	   ap_system_parameters_all asp  --Bug14779241
     WHERE ail.invoice_id  = aid.invoice_id
       AND ail.line_number = aid.invoice_line_number
       AND ail.invoice_id  = c_invoice_id
       AND ai.invoice_id = ail.invoice_id /* Bug14779241: Start */
       AND asp.org_id = ai.org_id
       AND ((asp.base_currency_code = ai.invoice_currency_code) OR
           (asp.base_currency_code <> ai.invoice_currency_code AND
           ai.exchange_rate IS NOT NULL)) /* Bug14779241: End */
       AND ail.line_type_lookup_code  <> 'PREPAY'
       AND aid.line_type_lookup_code  =  'PREPAY'
       AND aid.prepay_distribution_id IS NOT NULL
       AND p_calling_mode = 'DISTRIBUTE RECOUP'
       AND   (NVL(aid.reversal_flag,'N') <> 'Y') -- bug 12419997  --Bug14383132
	     ;
Line: 1608

    SELECT aid.*
      FROM ap_invoice_lines_all ail,
           ap_invoice_distributions_all aid,
           ap_invoices_all ai,  --Bug14779241
	   ap_system_parameters_all asp  --Bug14779241
     WHERE ail.invoice_id  = aid.invoice_id
       AND ail.line_number = aid.invoice_line_number
       AND ail.invoice_id  = c_invoice_id
       AND ail.line_number = c_line_number
       AND ai.invoice_id = ail.invoice_id /* Bug14779241: Start */
       AND asp.org_id = ai.org_id
       AND ((asp.base_currency_code = ai.invoice_currency_code) OR
           (asp.base_currency_code <> ai.invoice_currency_code AND
           ai.exchange_rate IS NOT NULL)) /* Bug14779241: End */
       AND (aid.line_type_lookup_code NOT IN
           ('AWT', 'REC_TAX', 'NONREC_TAX', 'TRV', 'TERV', 'TIPV') OR
           (ail.line_type_lookup_code = 'TAX'
            AND aid.charge_applicable_to_dist_id IS NULL
            AND ail.summary_tax_line_id IS NOT NULL
            AND aid.detail_tax_dist_id IS NOT NULL))  --Bug9494315
       AND (aid.line_type_lookup_code <> 'RETROACCRUAL' OR
           (aid.line_type_lookup_code = 'RETROACCRUAL' AND dist_match_type ='PO_PRICE_ADJUSTMENT'))  --Bug10416960
       AND (related_id IS NULL
            or related_id = invoice_distribution_id)
       AND (aid.prepay_distribution_id IS NULL
            or (aid.prepay_distribution_id IS NOT NULL
                and ail.line_type_lookup_code = 'PREPAY'))
       AND ((nvl(ail.discarded_flag, 'N') <> 'Y' AND nvl(ail.cancelled_flag, 'N') <> 'Y') --Bug8811102
            OR (ail.line_type_lookup_code = 'TAX'  AND aid.reversal_flag IS NULL)) --Bug9494315
       AND p_calling_mode <> 'DISTRIBUTE RECOUP'
       AND   (NVL(aid.reversal_flag,'N') <> 'Y') -- bug 12419997  --Bug14383132
    UNION
    SELECT aid.*
      FROM ap_invoice_lines_all ail,
           ap_invoice_distributions_all aid,
	   ap_invoices_all ai,  --Bug14779241
	   ap_system_parameters_all asp  --Bug14779241
     WHERE ail.invoice_id  = aid.invoice_id
       AND ail.line_number = aid.invoice_line_number
       AND ail.invoice_id  = c_invoice_id
       AND ail.line_number = c_line_number
       AND ai.invoice_id = ail.invoice_id /* Bug14779241: Start */
       AND asp.org_id = ai.org_id
       AND ((asp.base_currency_code = ai.invoice_currency_code) OR
           (asp.base_currency_code <> ai.invoice_currency_code AND
           ai.exchange_rate IS NOT NULL)) /* Bug14779241: End */
       AND ail.line_type_lookup_code  <> 'PREPAY'
       AND aid.line_type_lookup_code  =  'PREPAY'
       AND aid.prepay_distribution_id IS NOT NULL
       AND p_calling_mode = 'DISTRIBUTE RECOUP'
       AND   (NVL(aid.reversal_flag,'N') <> 'Y') -- bug 12419997  --Bug14383132
	     ;
Line: 1662

    CURSOR c_selected_invoices IS
    SELECT trx_id, event_class_code
      FROM zx_trx_headers_gt
     WHERE application_id   =  ap_etax_pkg.ap_application_id
       AND entity_code      =  ap_etax_pkg.ap_entity_code
       AND 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);
Line: 1675

    SELECT amount,
	       NVL(included_tax_amount,0) included_tax_amount,
		   line_number,
           (NVL(total_rec_tax_amt_funcl_curr,0) + NVL(total_nrec_tax_amt_funcl_curr,0)) base_included_tax_amount,
	   discarded_flag
      FROM ap_invoice_lines_all
     WHERE invoice_id =  c_invoice_id
       AND line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS','PREPAY')  -- bug7338249
       AND included_tax_amount IS NOT NULL ;--Bug6874234
Line: 1686

    SELECT amount,
	       NVL(included_tax_amount,0) included_tax_amount,
		   line_number,
           (NVL(total_rec_tax_amt_funcl_curr,0) + NVL(total_nrec_tax_amt_funcl_curr,0)) base_included_tax_amount,
	   discarded_flag
      FROM ap_invoice_lines_all
     WHERE invoice_id =  c_invoice_id
       AND line_number = c_line_number
       AND line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS','PREPAY') --bug7338249
       AND included_tax_amount IS NOT NULL ;--Bug6874234
Line: 1719

       DELETE FROM ZX_TRX_HEADERS_GT;
Line: 1811

     DELETE FROM zx_itm_distributions_gt;
Line: 1817

        UPDATE ap_invoice_distributions_All aid1
        /*no_unnest hints and consolidation of query for bug 11674044 */
        SET (aid1.amount, aid1.base_amount) =
            (SELECT aid1.amount + NVL(SUM(Nvl(amount, 0)),0)
            , aid1.base_amount + NVL(SUM(Nvl(base_amount, 0)),0)
            FROM ap_invoice_distributions_all aid2
            WHERE aid2.invoice_id = aid1.invoice_id
            AND aid2.charge_applicable_to_dist_id = aid1.invoice_distribution_id
            AND aid2.line_type_lookup_code IN ( 'REC_TAX', 'NONREC_TAX', 'TRV', 'TIPV', 'TERV' )
            AND EXISTS (SELECT /*+ NO_UNNEST */ 1
                           FROM zx_rec_nrec_dist zd
                          WHERE zd.application_id = 200
                            AND zd.entity_code = 'AP_INVOICES'
                            AND zd.event_class_code IN ( 'STANDARD INVOICES', 'EXPENSE REPORTS', 'PREPAYMENT INVOICES' )
                            AND zd.trx_id = aid2.invoice_id
                            AND zd.rec_nrec_tax_dist_id = aid2.detail_tax_dist_id
                            AND Nvl(zd.inclusive_flag, 'N') = 'Y'))
         WHERE aid1.invoice_id IN (SELECT /*+ cardinality(gt 10) unnest */ DISTINCT(trx_id)
                                     FROM zx_trx_headers_gt gt
                                    WHERE application_id = 200
                                      AND entity_code = 'AP_INVOICES'
                                      AND event_class_code IN ('STANDARD INVOICES','EXPENSE REPORTS','PREPAYMENT INVOICES'))
           AND aid1.line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS')   --bug9314506
           AND NOT EXISTS (SELECT /*+  nl_aj */ 1
                             FROM ap_invoice_lines_all ail
                            WHERE ail.invoice_id = aid1.invoice_id
                              AND ail.line_number=aid1.invoice_line_number
                              AND NVL(ail.discarded_flag,'N') = 'Y');
Line: 1851

     OPEN C_SELECTED_INVOICES;
Line: 1853

     FETCH C_SELECTED_INVOICES
        BULK COLLECT INTO AP_ETAX_PKG.G_INV_ID_LIST,
			  AP_ETAX_PKG.G_EVNT_CLS_LIST
        LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 1864

           EXIT WHEN (C_SELECTED_INVOICES%NOTFOUND
                      AND AP_ETAX_PKG.G_INV_ID_LIST.COUNT <= 0);
Line: 1901

        UPDATE ap_invoice_distributions_All aid1
        /*no_unnest hints and consolidation of query for bug 11674044 */
        SET (aid1.amount, aid1.base_amount) =
            (SELECT aid1.amount + NVL(SUM(Nvl(amount, 0)),0)
            , aid1.base_amount + NVL(SUM(Nvl(base_amount, 0)),0)
            FROM ap_invoice_distributions_all aid2
            WHERE aid2.invoice_id =  p_invoice_id
	    AND aid2.invoice_line_number = p_line_number
            AND aid2.charge_applicable_to_dist_id = aid1.invoice_distribution_id
            AND aid2.line_type_lookup_code IN ( 'REC_TAX', 'NONREC_TAX', 'TRV', 'TIPV', 'TERV' )
            AND EXISTS (SELECT /*+ NO_UNNEST */ 1
                           FROM zx_rec_nrec_dist zd
                          WHERE zd.application_id = 200
                            AND zd.entity_code = 'AP_INVOICES'
                            AND zd.event_class_code IN ( 'STANDARD INVOICES', 'EXPENSE REPORTS', 'PREPAYMENT INVOICES' )
                            AND zd.trx_id = aid2.invoice_id
                            AND zd.rec_nrec_tax_dist_id = aid2.detail_tax_dist_id
                            AND Nvl(zd.inclusive_flag, 'N') = 'Y'))
		         WHERE aid1.invoice_id =  p_invoice_id
		           AND aid1.invoice_line_number = p_line_number
		           AND aid1.line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS')  --bug9314506
               AND NOT EXISTS (SELECT  /*+  nl_aj */ 1   --9325964
                                 FROM ap_invoice_lines_all ail
                                WHERE ail.invoice_id = aid1.invoice_id
                                  AND ail.line_number=aid1.invoice_line_number
                                  AND NVL(ail.discarded_flag,'N') = 'Y');
Line: 1952

             DELETE FROM zx_trx_headers_gt
              WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
                AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
                AND 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 trx_id = l_inv_header_rec.invoice_id;
Line: 1961

     	     l_debug_info := 'DELETE INV ID '||l_inv_header_rec.invoice_id||' FROM zx_trx_headers_gt';
Line: 2004

	      UPDATE /*+ ROWID (AID) */ AP_Invoice_Distributions_All AID
	      SET   (RECOVERY_RATE_CODE,
	             RECOVERY_RATE_ID,
	             RECOVERY_TYPE_CODE) =
		                       (SELECT REC.Tax_Rate_Code,
		                               REC.Tax_Rate_ID,
		                               REC.Recovery_Type_Code
		                        FROM   ZX_Rates_B RATE,
		                               ZX_Rates_B REC
		                        WHERE  RATE.Tax_Rate_ID		 = AID.Tax_Code_ID
		                        AND    RATE.Tax_Regime_Code	 = REC.Tax_Regime_Code
		                        AND    RATE.Tax			 = REC.Tax
		                        AND    RATE.Tax_Status_Code	 = REC.Tax_Status_Code
		                        AND    RATE.Content_Owner_ID	 = REC.Content_Owner_ID
		                        AND    REC.Rate_type_code	 = 'RECOVERY'
		                        AND    REC.Effective_From <= AID.Accounting_Date
		                        AND    NVL(REC.Effective_To, AID.Accounting_Date) >= AID.Accounting_Date
		                        AND    REC.Active_Flag		 = 'Y'
		                        AND    REC.Percentage_Rate	 = AID.Rec_NRec_Rate
		                        AND    REC.Tax_Rate_Code 	 = 'STANDARD-' || REC.Percentage_Rate
		                        AND    AID.Line_Type_Lookup_Code = 'REC_TAX')
             WHERE AID.invoice_id            = l_inv_header_rec.invoice_id
	       AND AID.historical_flag       = 'Y'
               AND AID.line_type_lookup_code = 'REC_TAX'
               AND AID.recovery_rate_code    Is Null
               AND AID.recovery_rate_id      Is Null
               AND AID.recovery_type_code    Is Null;
Line: 2034

       AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 2035

       AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 2038

    CLOSE C_SELECTED_INVOICES;
Line: 2076

           IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
 			P_Invoice_header_rec => l_inv_header_rec,
	                P_Calling_Mode       => P_Calling_Mode,
	                P_All_Error_Messages => P_All_Error_Messages,
	                P_Error_Code         => P_error_code,
	                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

              l_return_status := FALSE;
Line: 2109

       OPEN C_SELECTED_INVOICES;
Line: 2111

          FETCH C_SELECTED_INVOICES
          BULK COLLECT INTO AP_ETAX_PKG.G_INV_ID_LIST,
                            AP_ETAX_PKG.G_EVNT_CLS_LIST
          LIMIT AP_ETAX_PKG.G_BATCH_LIMIT;
Line: 2119

             EXIT WHEN (C_SELECTED_INVOICES%NOTFOUND
                        AND AP_ETAX_PKG.G_INV_ID_LIST.COUNT <= 0);
Line: 2137

             l_debug_info := 'Update Invoice Distributions';
Line: 2143

             IF NOT(AP_ETAX_SERVICES_PKG.Update_Distributions(
	                        P_Invoice_header_rec => l_inv_header_rec,
	                        P_Calling_Mode       => P_Calling_Mode,
	                        P_All_Error_Messages => P_All_Error_Messages,
	                        P_Error_Code         => P_error_code,
	                        P_Calling_Sequence   => l_curr_calling_sequence)) THEN

	         l_return_status := FALSE;
Line: 2153

          AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 2154

          AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 2156

      CLOSE C_SELECTED_INVOICES;
Line: 2160

      AP_ETAX_PKG.G_INV_ID_LIST.DELETE;
Line: 2161

      AP_ETAX_PKG.G_EVNT_CLS_LIST.DELETE;
Line: 2233

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 2238

    SELECT ai.invoice_id
      FROM ap_invoices_all ai,
	       ap_system_parameters_all asp
     WHERE ai.invoice_id = P_Invoice_Id
	   AND asp.org_id = ai.org_id
	   AND ((asp.base_currency_code = ai.invoice_currency_code) OR
         (asp.base_currency_code <> ai.invoice_currency_code AND
          ai.exchange_rate IS NOT NULL));
Line: 2318

       IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
                P_Invoice_header_rec => l_inv_header_rec,
                P_Calling_Mode       => P_Calling_Mode,
                P_All_Error_Messages => P_All_Error_Messages,
                P_Error_Code         => P_error_code,
                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

          l_return_status := FALSE;
Line: 2419

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 2425

    SELECT *
      FROM ap_invoice_lines_all
      WHERE invoice_id = c_invoice_id
      AND line_type_lookup_code = 'TAX'
      AND NVL(discarded_flag,'N')='N'
      AND NVL(cancelled_flag,'N')='N'
	  AND summary_tax_line_id IS NULL;
Line: 2457

    DELETE FROM ZX_TRX_HEADERS_GT;
Line: 2458

    DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 2459

    DELETE FROM ZX_IMPORT_TAX_LINES_GT;
Line: 2460

    DELETE FROM ZX_TRX_TAX_LINK_GT;
Line: 2466

    l_debug_info := 'Step 2: Update Header P_Invoice_Id '||P_Invoice_Id;
Line: 2472

      UPDATE zx_trx_headers_gt
         SET trx_id = P_Invoice_Id
       WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
         AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
         AND 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 trx_id = P_Interface_Invoice_Id;
Line: 2483

		l_debug_info := 'Header rows updated: '||SQL%ROWCOUNT;
Line: 2566

      l_debug_info := 'Step 3: Update trx_id in Lines';
Line: 2571

      UPDATE zx_transaction_lines_gt
         SET trx_id = P_Invoice_Id
       WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
         AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
         AND 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 trx_id = P_Interface_Invoice_Id;
Line: 2581

    l_debug_info := 'Step 4: Update trx_id in tax Lines';
Line: 2587

      UPDATE zx_import_tax_lines_gt
         SET trx_id = P_Invoice_Id
       WHERE trx_id = P_Interface_Invoice_Id;
Line: 2595

    l_debug_info := 'Step 5: Update trx_id in the allocation structure '||
                    'etax table';
Line: 2602

      UPDATE zx_trx_tax_link_gt
         SET trx_id = P_Invoice_Id
       WHERE trx_id = P_Interface_Invoice_Id;
Line: 2676

       IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
                P_Invoice_header_rec => l_inv_header_rec,
                P_Calling_Mode       => P_Calling_Mode,
                P_All_Error_Messages => P_All_Error_Messages,
                P_Error_Code         => P_error_code,
                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

          l_return_status := FALSE;
Line: 2772

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id
       AND quick_credit = 'Y'
       AND credited_invoice_id IS NOT NULL;
Line: 2779

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = c_credited_inv;
Line: 2861

    INSERT INTO zx_rev_trx_headers_gt(
        internal_organization_id,
        reversing_appln_id,
        reversing_entity_code,
        reversing_evnt_cls_code,
        reversing_trx_id,
        legal_entity_id,
        trx_number
    ) VALUES
	(l_inv_header_rec.org_id,
         200,
         'AP_INVOICES',
         l_event_class_code_credited,
         l_inv_header_rec.invoice_id,
         l_inv_header_rec.legal_entity_id,
         l_inv_header_rec.invoice_num);
Line: 2885

      INSERT INTO zx_reverse_trx_lines_gt(
        internal_organization_id,
        reversing_appln_id,
        reversing_entity_code,
        reversing_evnt_cls_code,
        reversing_trx_id,
        reversing_trx_level_type,
        reversing_trx_line_id,
        reversed_appln_id,
        reversed_entity_code,
        reversed_evnt_cls_code,
        reversed_trx_id,
        reversed_trx_level_type,
        reversed_trx_line_id,
        trx_line_gl_date -- bug 9880212
      )
      SELECT
        l_inv_header_rec.org_id,        -- internal_organization_id
        200,                            -- reversing_appln_id
        'AP_INVOICES',                  -- reversing_entity_code
        l_event_class_code_crediting,   -- reversing_evnt_cls_code
        ail.invoice_id,                 -- reversing_trx_id
        'LINE',                         -- reversing_trx_level_type
        ail.line_number,                -- reversing_trx_line_id
        200,                            -- reversed_appln_id
        'AP_INVOICES',                  -- reversed_entity_code
        l_event_class_code_credited,    -- reversed_evnt_cls_code
        aic.invoice_id,                 -- reversed_trx_id
        'LINE',                         -- reversed_trx_level_type
        aic.line_number,                -- reversed_trx_line_id
        ail.accounting_date             -- trx_line_gl_date -- bug 9880212
        FROM ap_invoice_lines_all ail,
             ap_invoice_lines_all aic
       WHERE ail.invoice_id = l_inv_header_rec.invoice_id
         AND ail.line_type_lookup_code NOT IN ('TAX', 'AWT')
         AND ail.corrected_inv_id = aic.invoice_id
         AND ail.corrected_line_number = aic.line_number;
Line: 2933

      INSERT INTO zx_reverse_dist_gt(
        internal_organization_id,
        reversing_appln_id,
        reversing_entity_code,
        reversing_evnt_cls_code,
        reversing_trx_id,
        reversing_trx_level_type,
        reversing_trx_line_id,
        reversing_trx_line_dist_id,
        reversing_tax_line_id,
        reversed_appln_id,
        reversed_entity_code,
        reversed_evnt_cls_code,
        reversed_trx_id,
        reversed_trx_level_type,
        reversed_trx_line_id,
        reversed_trx_line_dist_id,
        reversed_tax_line_id
      )
      SELECT
        l_inv_header_rec.org_id,        -- internal_organization_id
        200,                            -- reversing_appln_id
        'AP_INVOICES',                  -- reversing_entity_code
        l_event_class_code_crediting,   -- reversing_evnt_cls_code
        aid.invoice_id,                 -- reversing_trx_id
        'LINE',                         -- reversing_trx_level_type
        aid.invoice_line_number,        -- reversing_trx_line_id
        aid.invoice_distribution_id,    -- reversing_trx_line_dist_id
        NULL,                           -- reversing_tax_line_id
        200,                            -- reversed_appln_id
        'AP_INVOICES',                  -- reversed_entity_code
        l_event_class_code_credited,    -- reversed_evnt_cls_code
        idc.invoice_id,                 -- reversed_trx_id
        'LINE',                         -- reversed_trx_level_type
        idc.invoice_line_number,        -- reversed_trx_line_id
        idc.invoice_distribution_id,    -- reversed_trx_line_dist_id
        NULL                            -- reversed_tax_line_id
        FROM ap_invoice_distributions_all aid,
             ap_invoice_distributions_all idc
       WHERE aid.invoice_id = l_inv_header_rec.invoice_id
         AND aid.line_type_lookup_code NOT IN
             ('AWT', 'REC_TAX', 'NONREC_TAX', 'TRV', 'TERV', 'TIPV')
         AND (aid.related_id IS NULL
              OR aid.related_id = aid.invoice_distribution_id)
         AND aid.corrected_invoice_dist_id = idc.invoice_distribution_id;
Line: 3058

       IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
                P_Invoice_header_rec => l_inv_header_rec,
                P_Calling_Mode       => P_Calling_Mode,
                P_All_Error_Messages => P_All_Error_Messages,
                P_Error_Code         => P_error_code,
                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

          l_return_status := FALSE;
Line: 3163

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 3168

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id = P_Invoice_Id
       AND line_type_lookup_code NOT IN ('TAX', 'AWT');
Line: 3174

    SELECT ai.invoice_id
      FROM ap_invoices_all ai,
	       ap_system_parameters_all asp
     WHERE ai.invoice_id = P_Invoice_Id
	   AND asp.org_id = ai.org_id
	   AND ((asp.base_currency_code = ai.invoice_currency_code) OR
         (asp.base_currency_code <> ai.invoice_currency_code AND
          ai.exchange_rate IS NOT NULL));
Line: 3199

      l_debug_info := 'Step 1: Update ap_invoice_lines_all from eTax '||
                      'repository';
Line: 3206

        UPDATE ap_invoice_lines_all ail
           SET
         (-- Bug 10157751 ail.description,
          ail.cancelled_flag,
          ail.last_updated_by,
          ail.last_update_login,
          ail.last_update_date,
          ail.attribute_category,
          ail.attribute1,
          ail.attribute2,
          ail.attribute3,
          ail.attribute4,
          ail.attribute5,
          ail.attribute6,
          ail.attribute7,
          ail.attribute8,
          ail.attribute9,
          ail.attribute10,
          ail.attribute11,
          ail.attribute12,
          ail.attribute13,
          ail.attribute14,
          ail.attribute15,
          ail.global_attribute_category,
          ail.global_attribute1,
          ail.global_attribute2,
          ail.global_attribute3,
          ail.global_attribute4,
          ail.global_attribute5,
          ail.global_attribute6,
          ail.global_attribute7,
          ail.global_attribute8,
          ail.global_attribute9,
          ail.global_attribute10,
          ail.global_attribute11,
          ail.global_attribute12,
          ail.global_attribute13,
          ail.global_attribute14,
          ail.global_attribute15,
          ail.global_attribute16,
          ail.global_attribute17,
          ail.global_attribute18,
          ail.global_attribute19,
          ail.global_attribute20 ) = (
          SELECT
	  /* Bug 10157751
          DECODE( ail.line_source,
		  'MANUAL LINE ENTRY', ail.description,
		  'IMPORTED'         , ail.description,
                  zls.tax_regime_code||' - '||zls.tax ), -- description : Bug 9383712 - Added DECODE
	  */
          zls.cancel_flag,                     -- cancelled_flag
          l_user_id,                           -- last_updated_by
          l_login_id,                          -- last_update_login
          l_sysdate,                           -- last_update_date
          zls.attribute_category,
          zls.attribute1,
          zls.attribute2,
          zls.attribute3,
          zls.attribute4,
          zls.attribute5,
          zls.attribute6,
          zls.attribute7,
          zls.attribute8,
          zls.attribute9,
          zls.attribute10,
          zls.attribute11,
          zls.attribute12,
          zls.attribute13,
          zls.attribute14,
          zls.attribute15,
          zls.global_attribute_category,
          zls.global_attribute1,
          zls.global_attribute2,
          zls.global_attribute3,
          zls.global_attribute4,
          zls.global_attribute5,
          zls.global_attribute6,
          zls.global_attribute7,
          zls.global_attribute8,
          zls.global_attribute9,
          zls.global_attribute10,
          zls.global_attribute11,
          zls.global_attribute12,
          zls.global_attribute13,
          zls.global_attribute14,
          zls.global_attribute15,
          zls.global_attribute16,
          zls.global_attribute17,
          zls.global_attribute18,
          zls.global_attribute19,
          zls.global_attribute20
          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_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: 3383

      DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 3385

      AP_ETAX_SERVICES_PKG.G_SITE_ATTRIBUTES.DELETE;
Line: 3386

      AP_ETAX_SERVICES_PKG.G_ORG_ATTRIBUTES.DELETE;
Line: 3466

         IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
                  P_Invoice_header_rec => l_inv_header_rec,
                  P_Calling_Mode       => P_Calling_Mode,
                P_All_Error_Messages   => P_All_Error_Messages,
                  P_Error_Code         => P_error_code,
                  P_Calling_Sequence   => l_curr_calling_sequence)) THEN

            l_return_status := FALSE;
Line: 3547

      l_debug_info := 'Step 12: Update Total Tax Amount';
Line: 3556

       	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', case when exists (SELECT 'Prepay App Exists'
                                          FROM ap_invoice_lines_all prepay
                                         WHERE prepay.invoice_id = zls.trx_id
                                         AND prepay.line_type_lookup_code = 'PREPAY'
                                         AND prepay.prepay_invoice_id  = zls.applied_from_trx_id
                                         AND prepay.prepay_line_number = zls.applied_from_line_id
                                         AND prepay.invoice_includes_prepay_flag = 'Y'
                                         AND (prepay.discarded_flag is null
                                           or prepay.discarded_flag = 'N')) THEN
                                           0
                                        ELSE NVL(zls.tax_amt, 0) end,
                                       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 = l_inv_header_rec.invoice_id;
Line: 3587

      UPDATE ap_invoices_all ai
      SET ai.total_tax_amount = (nvl(ai.total_tax_amount,0) +
                                 (SELECT NVL(sum(NVL(ail.amount,0)),0)
                                  FROM ap_invoice_lines_all ail
                                  WHERE ail.invoice_id = ai.invoice_id
                                   AND line_type_lookup_code ='RETROTAX'))
      WHERE ai.invoice_id = l_inv_header_rec.invoice_id;
Line: 3597

        UPDATE ap_invoice_distributions_all
           SET distribution_class = 'PERMANENT'
         WHERE invoice_id = l_inv_header_rec.invoice_id
           AND distribution_class = 'CANDIDATE'
           AND line_type_lookup_code IN ('REC_TAX','NONREC_TAX','TRV','TERV','TIPV');
Line: 3607

        UPDATE ap_self_assessed_tax_dist_all
           SET distribution_class = 'PERMANENT'
         WHERE invoice_id = l_inv_header_rec.invoice_id
           AND distribution_class = 'CANDIDATE'
           AND line_type_lookup_code IN ('REC_TAX','NONREC_TAX','TRV','TERV','TIPV');
Line: 3679

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 3832

       IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
                P_Invoice_header_rec => l_inv_header_rec,
                P_Calling_Mode       => P_Calling_Mode,
                P_All_Error_Messages => P_All_Error_Messages,
                P_Error_Code         => P_error_code,
                P_Calling_Sequence   => l_curr_calling_sequence)) THEN

          l_return_status := FALSE;
Line: 3926

      SELECT encumbered_flag,
             reversal_flag,
             prepay_distribution_id,
             accrual_posted_flag,
             cash_posted_flag,
             posted_flag,
             org_id,
             pa_addition_flag,
             match_status_flag,
             corrected_invoice_dist_id,
             invoice_distribution_id,
             po_distribution_id,
             rcv_transaction_id,
             accounting_event_id,
             dist_match_type,
             amount,
             prepay_amount_remaining
        FROM ap_invoice_distributions_all
       WHERE invoice_id = p_invoice_header_rec.invoice_id
         AND line_type_lookup_code NOT IN ('REC_TAX', 'NONREC_TAX', 'TRV', 'TERV', 'TIPV');
Line: 4306

    insert into ap_errors_gt(invoice_id , message_text) values (P_Invoice_Header_Rec.Invoice_id , l_err);
Line: 4353

    (SELECT encumbered_flag,
            reversal_flag,
            charge_applicable_to_dist_id,
            prepay_distribution_id,
            accrual_posted_flag,
            cash_posted_flag,
            posted_flag,
            org_id,
            pa_addition_flag,
            match_status_flag,
            corrected_invoice_dist_id,
            invoice_distribution_id,
            detail_tax_dist_id,
            accounting_event_id
       FROM ap_invoice_distributions_all
      WHERE invoice_id = p_invoice_header_rec.invoice_id
        AND line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX', 'TRV', 'TERV', 'TIPV')
        AND (related_id IS NULL
                  OR (related_id = invoice_distribution_id
                      OR (related_id IS NOT NULL
                          AND line_type_lookup_code IN ('TRV', 'TERV', 'TIPV'))))
      UNION ALL
      SELECT encumbered_flag,
             reversal_flag,
             charge_applicable_to_dist_id,
             prepay_distribution_id,
             accrual_posted_flag,
             cash_posted_flag,
             posted_flag,
             org_id,
             pa_addition_flag,
             match_status_flag,
             corrected_invoice_dist_id,
             invoice_distribution_id,
             detail_tax_dist_id,
             accounting_event_id
        FROM ap_self_assessed_tax_dist_all
       WHERE invoice_id = p_invoice_header_rec.invoice_id
         AND line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX', 'TRV', 'TERV', 'TIPV')
         AND (related_id IS NULL
                  OR (related_id = invoice_distribution_id
                      OR (related_id IS NOT NULL
                          AND line_type_lookup_code IN ('TRV', 'TERV', 'TIPV')))));
Line: 4514

              select should not fire.I found out that value of charge_applicable_to_dist_id is
              -99 in this case.So aaded the AND condition to avoid the select.  */
            --this validation because it can be null for tax-only lines

           SELECT po_distribution_id, rcv_transaction_id
             INTO l_po_distribution_id, l_rcv_transaction_id
             FROM ap_invoice_distributions_all
            WHERE invoice_distribution_id =
                  l_tax_dist_list_local(i).charge_applicable_to_dist_id;
Line: 4661

            SELECT 'Y'
              INTO l_freeze_dist_flag
              FROM ap_invoice_distributions_all
             WHERE corrected_invoice_dist_id =
                   l_tax_dist_list_local(i).charge_applicable_to_dist_id
               AND ROWNUM = 1;
Line: 4706

    delete zx_tax_dist_id_gt;--Bug7582775
Line: 4708

    l_debug_info := 'No Of Rows Deleted From zx_tax_dist_id_gt  '||sql%rowcount;
Line: 4719

          INSERT INTO zx_tax_dist_id_gt(tax_dist_id)
          VALUES (freeze_dist_list(m).tax_dist_id);
Line: 4805

 |  FUNCTION - Global_Document_Update()
 |
 |  DESCRIPTION
 |      Public function that will call the global_document_update service to
 |      inform eTax of a cancellation of an invoice, the freeze after the
 |      invoice is validated (meaning is ready to reporting), the unfreeze
 |      of an invoice because it has to be modified after it was validated, and
 |      the release of tax holds by the user.
 |      This API assumes the calling code controls the commit cycle.
 |      This function returns TRUE if the call to the service is successful.
 |      Otherwise, FALSE.
 |
 |  PARAMETERS
 |      P_Invoice_Id - invoice id
 |      P_Calling_Mode - calling mode.  Identifies which service to call
 |      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
 |    07-OCT-2003   SYIDNER        Created
 |
 *============================================================================*/

  FUNCTION Global_Document_Update(
             P_Invoice_id              IN NUMBER,
	     P_Line_Number	       IN NUMBER DEFAULT NULL,
             P_Calling_Mode            IN VARCHAR2,
             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: 4848

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 4862

    l_api_name                  VARCHAR2(30) := 'global_document_update'; -- bug 6321366
Line: 4865

    l_curr_calling_sequence := 'AP_ETAX_SERVICES_PKG.Global_Document_Update<-' ||
                               P_calling_sequence;
Line: 4884

        UPDATE ap_invoices_all ail
           SET control_amount= NULL --Bug6887264
         WHERE ail.invoice_id = p_invoice_id
           AND P_Calling_Mode = 'CANCEL INVOICE'
           AND ail.control_amount IS NOT NULL ;
Line: 4892

        UPDATE ap_invoice_lines_all ail
          SET control_amount= NULL --Bug6887264
        WHERE ail.invoice_id = p_invoice_id
          AND P_Calling_Mode = 'CANCEL INVOICE'
          AND ail.control_amount IS NOT NULL ;
Line: 4929

  END Global_Document_Update;
Line: 4936

 |      Public function that will call the global_document_update service to
 |      inform eTax the release of tax holds by the user.
 |      This function returns TRUE if the call to the service is successful.
 |      Otherwise, FALSE.
 |
 |  PARAMETERS
 |      P_Invoice_Id - invoice id
 |      P_Calling_Mode - calling mode.  Identifies which service to call
 |      P_Tax_Hold_Code - List of tax hold codes released in AP
 |                        Posible values: TAX VARIANCE and TAX AMOUNT RANGE
 |      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
 |    05-NOV-2003   SYIDNER        Created
 |
 *============================================================================*/

  FUNCTION Release_Tax_Holds(
             P_Invoice_id              IN NUMBER,
             P_Calling_Mode            IN VARCHAR2,
             P_Tax_Hold_Code           IN Rel_Hold_Codes_Type,
             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: 4974

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 5094

    l_debug_info := 'Step 6: Call to global_document_update service';
Line: 5100

      zx_api_pub.global_document_update(
        p_api_version        => 1.0,
        p_init_msg_list      => FND_API.G_TRUE,
        p_commit             => FND_API.G_FALSE,
        p_validation_level   => FND_API.G_VALID_LEVEL_FULL,
        p_transaction_rec    => l_transaction_rec,
        p_validation_status  => l_validation_status,
        x_return_status      => l_return_status_service,
        x_msg_count          => l_msg_count,
        x_msg_data           => l_msg_data);
Line: 5160

 |  FUNCTION - Mark_Tax_Lines_Deleted()
 |
 |  DESCRIPTION
 |      Public function that will call the mark_tax_lines_deleted service.
 |      This API assumes the calling code controls the commit cycle.
 |      This function returns TRUE if the call to the service is successful.
 |      Otherwise, FALSE.
 |      This service should be called per invoice line.
 |
 |  PARAMETERS
 |      P_Invoice_Id - invoice id
 |      P_Calling_Mode - calling mode.  Identifies which service to call
 |      P_Line_Number_To_Delete - line number deleted in AP
 |      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
 |    07-OCT-2003   SYIDNER        Created
 |
 *============================================================================*/

  FUNCTION Mark_Tax_Lines_Deleted(
             P_Invoice_id              IN NUMBER,
             P_Calling_Mode            IN VARCHAR2,
             P_Line_Number_To_Delete   IN NUMBER,
             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: 5196

    l_api_name			 VARCHAR2(30) := 'Mark_Tax_Lines_Deleted';
Line: 5202

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 5216

    l_curr_calling_sequence := 'AP_ETAX_SERVICES_PKG.Mark_Tax_Lines_Deleted<-' ||
                               P_calling_sequence;
Line: 5290

    l_transaction_line_rec.trx_line_id              := P_Line_Number_To_Delete;
Line: 5326

        l_debug_info := 'Step 8: Sync up ZX and AP data after delete';
Line: 5332

        IF NOT(AP_ETAX_SERVICES_PKG.Update_AP(
	        P_Invoice_header_rec => l_inv_header_rec,
	        P_Calling_Mode       => 'DELETE TAX LINE',
	        P_All_Error_Messages => P_All_Error_Messages,
	        P_Error_Code         => P_error_code,
	        P_Calling_Sequence   => l_curr_calling_sequence)) THEN

            l_return_status := FALSE;
Line: 5374

          ' P_Line_Number_To_Delete = '||P_Line_Number_To_Delete||
          ' P_Calling_Mode ='||P_Calling_Mode||
          ' P_Error_Code = '||P_Error_Code||
          ' P_Calling_Sequence = '||P_Calling_Sequence);
Line: 5383

  END Mark_Tax_Lines_Deleted;
Line: 5387

 |  FUNCTION - Mark_Tax_Lines_Deleted()
 |
 |  DESCRIPTION
 |      Public function that will call the mark_tax_lines_deleted service.
 |      This API assumes the calling code controls the commit cycle.
 |      This function returns TRUE/FALSE as varchar2 for bug 9343533
 |
 |  PARAMETERS
 |      P_Invoice_Id - invoice id
 |      P_Calling_Mode - calling mode.  Identifies which service to call
 |      P_Line_Number_To_Delete - Tax Line to delete
 |      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
 |      P_dummy - dummy variable to differentiate from existing
 |                Mark_Tax_Lines_Deleted API
 |
 |  MODIFICATION HISTORY
 |    DATE              Author                  Action
 |    25-MAR-2010   DCSHANMU        Created
 |
 *============================================================================*/
  FUNCTION Mark_Tax_Lines_Deleted(
             P_Invoice_id              IN NUMBER,
             P_Calling_Mode            IN VARCHAR2,
             P_Line_Number_To_Delete   IN NUMBER,
             P_All_Error_Messages      IN VARCHAR2,
             P_Error_Code              OUT NOCOPY VARCHAR2,
             P_Calling_Sequence        IN VARCHAR2,
             p_dummy                   IN VARCHAR2) RETURN VARCHAR2 IS

result boolean := false;
Line: 5423

	result := Mark_Tax_Lines_Deleted(
             P_Invoice_id,
             P_Calling_Mode,
             P_Line_Number_To_Delete,
             P_All_Error_Messages,
             P_Error_Code,
             P_Calling_Sequence);
Line: 5477

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 5638

              SELECT hold_lookup_code
                BULK COLLECT INTO l_hold_lookup_code
                FROM ap_holds_all
               WHERE invoice_id = l_inv_header_rec.invoice_id
                 AND org_id = l_inv_header_rec.org_id
                 AND hold_lookup_code IN ('TAX VARIANCE', 'TAX AMOUNT RANGE')
                 AND release_lookup_code is NULL;
Line: 5715

              ap_holds_pkg.insert_single_hold(
           	   X_invoice_id          => l_inv_header_rec.invoice_id,
              	   X_hold_lookup_code    => l_hold_codes_tab(i),
                   X_hold_type           => NULL,
                   X_hold_reason         => NULL,
                   X_held_by             => l_user_id,
                   X_calling_sequence    => l_curr_calling_sequence);
Line: 5836

       p_invoice_lines_tabl.DELETE;
Line: 5841

          p_invoice_lines_tabl.delete;
Line: 6043

 |      This function returns TRUE if the insert to the temp table goes
 |      through successfully.  Otherwise, FALSE.
 |
 |  PARAMETERS
 |      P_Invoice_Header_Rec - record with invoice header information
 |      P_Calling_Mode - calling mode. it is used to
 |      P_eTax_Already_called_flag - Flag to know if this is the first time tax
 |                                   has been called
 |      P_Event_Class_Code - Event class code
 |      P_Event_Type_Code - Event type code
 |      P_error_code - Error code to be returned
 |      P_calling_sequence -  Calling sequence
 |
 |  MODIFICATION HISTORY
 |    DATE          Author         Action
 |    07-OCT-2003   SYIDNER        Created
 |
 *============================================================================*/

  FUNCTION Populate_Headers_GT(
             P_Invoice_Header_Rec        IN ap_invoices_all%ROWTYPE,
             P_Calling_Mode              IN VARCHAR2,
             P_eTax_Already_called_flag  IN VARCHAR2,
             P_Event_Class_Code          OUT NOCOPY VARCHAR2,
             P_Event_Type_Code           OUT NOCOPY VARCHAR2,
             P_Error_Code                OUT NOCOPY VARCHAR2,
             P_Calling_Sequence          IN VARCHAR2) RETURN BOOLEAN
  IS

    l_debug_info                 VARCHAR2(240);
Line: 6084

    SELECT invoice_num, invoice_type_lookup_code, invoice_date
      FROM ap_invoices_all
     WHERE invoice_id = c_tax_related_invoice_id;
Line: 6219

        SELECT NVL(precision, 0), NVL(minimum_accountable_unit,(1/power(10,precision)))
          INTO l_precision, l_minimum_accountable_unit
          FROM fnd_currencies
         WHERE currency_code = P_Invoice_Header_Rec.invoice_currency_code;
Line: 6236

        SELECT name
          INTO l_doc_seq_name
          FROM fnd_document_sequences
         WHERE doc_sequence_id = p_invoice_header_rec.doc_sequence_id;
Line: 6255

      DELETE FROM zx_trx_headers_gt
       WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
         AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
         AND 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 trx_id = p_invoice_header_rec.invoice_id;
Line: 6263

      INSERT INTO zx_trx_headers_gt(
        internal_organization_id,
        internal_org_location_id,
        application_id,
        entity_code,
        event_class_code,
        event_type_code,
        trx_id,
        hdr_trx_user_key1,
        hdr_trx_user_key2,
        hdr_trx_user_key3,
        hdr_trx_user_key4,
        hdr_trx_user_key5,
        hdr_trx_user_key6,
        trx_date,
        trx_doc_revision,
        ledger_id,
        trx_currency_code,
        currency_conversion_date,
        currency_conversion_rate,
        currency_conversion_type,
        minimum_accountable_unit,
        precision,
        legal_entity_id,
        rounding_ship_to_party_id,
        rounding_ship_from_party_id,
        rounding_bill_to_party_id,
        rounding_bill_from_party_id,
        rndg_ship_to_party_site_id,
        rndg_ship_from_party_site_id,
        rndg_bill_to_party_site_id,
        rndg_bill_from_party_site_id,
        establishment_id,
        receivables_trx_type_id,
        related_doc_application_id,
        related_doc_entity_code,
        related_doc_event_class_code,
        related_doc_trx_id,
        rel_doc_hdr_trx_user_key1,
        rel_doc_hdr_trx_user_key2,
        rel_doc_hdr_trx_user_key3,
        rel_doc_hdr_trx_user_key4,
        rel_doc_hdr_trx_user_key5,
        rel_doc_hdr_trx_user_key6,
        related_doc_number,
        related_doc_date,
        default_taxation_country,
        quote_flag,
        ctrl_total_hdr_tx_amt,
        trx_number,
        trx_description,
        trx_communicated_date,
        batch_source_id,
        batch_source_name,
        doc_seq_id,
        doc_seq_name,
        doc_seq_value,
        trx_due_date,
        trx_type_description,
        document_sub_type,
        supplier_tax_invoice_number,
        supplier_tax_invoice_date,
        supplier_exchange_rate,
        tax_invoice_date,
        tax_invoice_number,
        tax_event_class_code,
        tax_event_type_code,
        doc_event_status,
        rdng_ship_to_pty_tx_prof_id,
        rdng_ship_from_pty_tx_prof_id,
        rdng_bill_to_pty_tx_prof_id,
        rdng_bill_from_pty_tx_prof_id,
        rdng_ship_to_pty_tx_p_st_id,
        rdng_ship_from_pty_tx_p_st_id,
        rdng_bill_to_pty_tx_p_st_id,
        rdng_bill_from_pty_tx_p_st_id,
        bill_third_pty_acct_id,
        bill_third_pty_acct_site_id,
	ship_third_pty_acct_id,
	ship_third_pty_acct_site_id
        ) VALUES (
        p_invoice_header_rec.org_id,                       --internal_organization_id
        NULL,                                              --internal_org_location_id
        l_application_id,                                  --application_id
        l_entity_code,                                     --entity_code
        P_event_class_code,                                --event_class_code
        P_event_type_code,                                 --event_type_code
        p_invoice_header_rec.invoice_id,                   --trx_id
        NULL,                                              --hdr_trx_user_key1
        NULL,                                              --hdr_trx_user_key2
        NULL,                                              --hdr_trx_user_key3
        NULL,                                              --hdr_trx_user_key4
        NULL,                                              --hdr_trx_user_key5
        NULL,                                              --hdr_trx_user_key6
        p_invoice_header_rec.invoice_date,                 --trx_date
        NULL,                                              --trx_doc_revision
        p_invoice_header_rec.set_of_books_id,              --ledger_id
        p_invoice_header_rec.invoice_currency_code,        --trx_currency_code
        p_invoice_header_rec.exchange_date,                --currency_conversion_date
        p_invoice_header_rec.exchange_rate,                --currency_conversion_rate
        p_invoice_header_rec.exchange_rate_type,           --currency_conversion_type
        l_minimum_accountable_unit,                        --minimum_accountable_unit
        l_precision,                                       --precision
        p_invoice_header_rec.legal_entity_id,              --legal_entity_id
        NULL,                                              --rounding_ship_to_party_id
        p_invoice_header_rec.party_id,                     --rounding_ship_from_party_id
        NULL,                                              --rounding_bill_to_party_id
        p_invoice_header_rec.party_id,                     --rounding_bill_from_party_id
        NULL,                                              --rndg_ship_to_party_site_id
        p_invoice_header_rec.party_site_id,                --rndg_ship_from_party_site_id
        NULL,                                              --rndg_bill_to_party_site_id
        p_invoice_header_rec.party_site_id,                --rndg_bill_from_party_site_id
        NULL,                                              --establishment_id
        NULL,                                              --receivables_trx_type_id
        l_related_inv_application_id,                      --related_doc_application_id
        l_related_inv_entity_code,                         --related_doc_entity_code
        l_related_event_class_code,                        --related_doc_event_class_code
        p_invoice_header_rec.tax_related_invoice_id,       --related_doc_trx_id
        NULL,                                              --rel_doc_hdr_trx_user_key1
        NULL,                                              --rel_doc_hdr_trx_user_key2
        NULL,                                              --rel_doc_hdr_trx_user_key3
        NULL,                                              --rel_doc_hdr_trx_user_key4
        NULL,                                              --rel_doc_hdr_trx_user_key5
        NULL,                                              --rel_doc_hdr_trx_user_key6
        l_related_inv_number,                              --related_doc_number
        l_related_inv_date,                                --related_doc_date
        p_invoice_header_rec.taxation_country,             --default_taxation_country
        l_quote_flag,                                      --quote_flag
        p_invoice_header_rec.control_amount,               --ctrl_total_hdr_tx_amt
        p_invoice_header_rec.invoice_num,                  --trx_number
        p_invoice_header_rec.description,                  --trx_description
        NULL,                                              --trx_communicated_date
        NULL,                                              --batch_source_id
        NULL,                                              --batch_source_name
        p_invoice_header_rec.doc_sequence_id,              --doc_seq_id
        l_doc_seq_name,            			   --doc_seq_name
        nvl(to_char(p_invoice_header_rec.doc_sequence_value),--bug6656894
	    p_invoice_header_rec.voucher_num),             --doc_seq_value
        NULL,                                              --trx_due_date
        NULL,                                              --trx_type_description
        p_invoice_header_rec.document_sub_type,            --document_sub_type
        p_invoice_header_rec.supplier_tax_invoice_number,  --supplier_tax_invoice_number
        p_invoice_header_rec.supplier_tax_invoice_date,    --supplier_tax_invoice_date
        p_invoice_header_rec.supplier_tax_exchange_rate,   --supplier_exchange_rate
        p_invoice_header_rec.tax_invoice_recording_date,   --tax_invoice_date
        p_invoice_header_rec.tax_invoice_internal_seq,     --tax_invoice_number
        NULL,                                              --tax_event_class_code
        NULL,                                              --tax_event_type_code
        NULL,                                              --doc_event_status
        NULL,                                              --rdng_ship_to_pty_tx_prof_id
        NULL,                                              --rdng_ship_from_pty_tx_prof_id
        NULL,                                              --rdng_bill_to_pty_tx_prof_id
        NULL,                                              --rdng_bill_from_pty_tx_prof_id
        NULL,                                              --rdng_ship_to_pty_tx_p_st_id
        NULL,                                              --rdng_ship_from_pty_tx_p_st_id
        NULL,                                              --rdng_bill_to_pty_tx_p_st_id
        NULL,                                              --rdng_bill_from_pty_tx_p_st_id
	p_invoice_header_rec.vendor_id,			   --bill_third_pty_acct_id
	p_invoice_header_rec.vendor_site_id,		   --bill_third_pty_acct_site_id
        p_invoice_header_rec.vendor_id,                    --ship_third_pty_acct_id
        p_invoice_header_rec.vendor_site_id                --ship_third_pty_acct_site_id
     );
Line: 6475

 |    This function returns TRUE if the insert to the temp table goes
 |    through successfully.  Otherwise, FALSE.
 |
 |  PARAMETERS
 |    P_Invoice_Header_Rec - record with invoice header information
 |    P_Calling_Mode - calling mode. it is used to
 |    P_Event_Class_Code - Event class code
 |    P_Event_Type_Code - Event type code
 |    P_error_code - Error code to be returned
 |    P_calling_sequence -  Calling sequence
 |
 |  MODIFICATION HISTORY
 |    DATE          Author         Action
 |    20-JAN-2004   SYIDNER        Created
 |
*============================================================================*/
  FUNCTION Populate_Header_Import_GT(
             P_Invoice_Header_Rec        IN AP_IMPORT_INVOICES_PKG.r_invoice_info_rec,
             P_Calling_Mode              IN VARCHAR2,
             P_Event_Class_Code          OUT NOCOPY VARCHAR2,
             P_Event_Type_Code           OUT NOCOPY VARCHAR2,
             P_Error_Code                OUT NOCOPY VARCHAR2,
             P_Calling_Sequence          IN VARCHAR2) RETURN BOOLEAN
  IS

    l_debug_info                 VARCHAR2(240);
Line: 6513

    SELECT invoice_num, invoice_type_lookup_code, invoice_date
      FROM ap_invoices_all
     WHERE invoice_id = c_tax_related_invoice_id;
Line: 6643

        SELECT NVL(precision, 0), NVL(minimum_accountable_unit,(1/power(10,precision)))
          INTO l_precision, l_minimum_accountable_unit
          FROM fnd_currencies
         WHERE currency_code = P_Invoice_Header_Rec.invoice_currency_code;
Line: 6659

      DELETE FROM zx_trx_headers_gt
       WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
         AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
         AND 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 trx_id = p_invoice_header_rec.invoice_id;
Line: 6667

      INSERT INTO zx_trx_headers_gt(
        internal_organization_id,
        internal_org_location_id,
        application_id,
        entity_code,
        event_class_code,
        event_type_code,
        trx_id,
        hdr_trx_user_key1,
        hdr_trx_user_key2,
        hdr_trx_user_key3,
        hdr_trx_user_key4,
        hdr_trx_user_key5,
        hdr_trx_user_key6,
        trx_date,
        trx_doc_revision,
        ledger_id,
        trx_currency_code,
        currency_conversion_date,
        currency_conversion_rate,
        currency_conversion_type,
        minimum_accountable_unit,
        precision,
        legal_entity_id,
        rounding_ship_to_party_id,
        rounding_ship_from_party_id,
        rounding_bill_to_party_id,
        rounding_bill_from_party_id,
        rndg_ship_to_party_site_id,
        rndg_ship_from_party_site_id,
        rndg_bill_to_party_site_id,
        rndg_bill_from_party_site_id,
        establishment_id,
        receivables_trx_type_id,
        related_doc_application_id,
        related_doc_entity_code,
        related_doc_event_class_code,
        related_doc_trx_id,
        rel_doc_hdr_trx_user_key1,
        rel_doc_hdr_trx_user_key2,
        rel_doc_hdr_trx_user_key3,
        rel_doc_hdr_trx_user_key4,
        rel_doc_hdr_trx_user_key5,
        rel_doc_hdr_trx_user_key6,
        related_doc_number,
        related_doc_date,
        default_taxation_country,
        quote_flag,
        ctrl_total_hdr_tx_amt,
        trx_number,
        trx_description,
        trx_communicated_date,
        batch_source_id,
        batch_source_name,
        doc_seq_id,
        doc_seq_name,
        doc_seq_value,
        trx_due_date,
        trx_type_description,
        document_sub_type,
        supplier_tax_invoice_number,
        supplier_tax_invoice_date,
        supplier_exchange_rate,
        tax_invoice_date,
        tax_invoice_number,
        tax_event_class_code,
        tax_event_type_code,
        doc_event_status,
        rdng_ship_to_pty_tx_prof_id,
        rdng_ship_from_pty_tx_prof_id,
        rdng_bill_to_pty_tx_prof_id,
        rdng_bill_from_pty_tx_prof_id,
        rdng_ship_to_pty_tx_p_st_id,
        rdng_ship_from_pty_tx_p_st_id,
        rdng_bill_to_pty_tx_p_st_id,
        rdng_bill_from_pty_tx_p_st_id,
        bill_third_pty_acct_id,
        bill_third_pty_acct_site_id,
        ship_third_pty_acct_id,
	ship_third_pty_acct_site_id
        ) VALUES (
        p_invoice_header_rec.org_id,                       --internal_organization_id
        NULL,                                              --internal_org_location_id
        l_application_id,                                  --application_id
        l_entity_code,                                     --entity_code
        P_event_class_code,                                --event_class_code
        P_event_type_code,                                 --event_type_code
        p_invoice_header_rec.invoice_id,                   --trx_id
        NULL,                                              --hdr_trx_user_key1
        NULL,                                              --hdr_trx_user_key2
        NULL,                                              --hdr_trx_user_key3
        NULL,                                              --hdr_trx_user_key4
        NULL,                                              --hdr_trx_user_key5
        NULL,                                              --hdr_trx_user_key6
        p_invoice_header_rec.invoice_date,                 --trx_date
        NULL,                                              --trx_doc_revision
        p_invoice_header_rec.set_of_books_id,              --ledger_id
        p_invoice_header_rec.invoice_currency_code,        --trx_currency_code
        p_invoice_header_rec.exchange_date,                --currency_conversion_date
        p_invoice_header_rec.exchange_rate,                --currency_conversion_rate
        p_invoice_header_rec.exchange_rate_type,           --currency_conversion_type
        l_minimum_accountable_unit,                        --minimum_accountable_unit
        l_precision,                                       --precision
        p_invoice_header_rec.legal_entity_id,              --legal_entity_id
        NULL,                                              --rounding_ship_to_party_id
        p_invoice_header_rec.party_id,                     --rounding_ship_from_party_id
        NULL,                                              --rounding_bill_to_party_id
        p_invoice_header_rec.party_id,                     --rounding_bill_from_party_id
        NULL,                                              --rndg_ship_to_party_site_id
        p_invoice_header_rec.party_site_id,                --rndg_ship_from_party_site_id
        NULL,                                              --rndg_bill_to_party_site_id
        p_invoice_header_rec.party_site_id,                --rndg_bill_from_party_site_id
        NULL,                                              --establishment_id
        NULL, --receivables_trx_type_id
        l_related_inv_application_id, --related_doc_application_id
        l_related_inv_entity_code, --related_doc_entity_code
        l_related_event_class_code, --related_doc_event_class_code
        p_invoice_header_rec.tax_related_invoice_id,       --related_doc_trx_id
        NULL, --rel_doc_hdr_trx_user_key1
        NULL, --rel_doc_hdr_trx_user_key2
        NULL, --rel_doc_hdr_trx_user_key3
        NULL, --rel_doc_hdr_trx_user_key4
        NULL, --rel_doc_hdr_trx_user_key5
        NULL, --rel_doc_hdr_trx_user_key6
        l_related_inv_number,                              --related_doc_number
        l_related_inv_date,                                --related_doc_date
        p_invoice_header_rec.taxation_country, --default_taxation_country
        l_quote_flag,                                      --quote_flag
        p_invoice_header_rec.control_amount, --ctrl_total_hdr_tx_amt
        p_invoice_header_rec.invoice_num,                  --trx_number
        p_invoice_header_rec.description,                  --trx_description
        NULL, --trx_communicated_date
        NULL,                                              --batch_source_id
        NULL,                                              --batch_source_name
        NULL,                                              --doc_seq_id
        NULL,                                              --doc_seq_name
        NULL,                                              --doc_seq_value
        NULL,                                              --trx_due_date
        NULL, --trx_type_description
        p_invoice_header_rec.document_sub_type,            --document_sub_type
        p_invoice_header_rec.supplier_tax_invoice_number, --supplier_tax_invoice_number
        p_invoice_header_rec.supplier_tax_invoice_date, --supplier_tax_invoice_date
        p_invoice_header_rec.supplier_tax_exchange_rate, --supplier_exchange_rate
        p_invoice_header_rec.tax_invoice_recording_date,   --tax_invoice_date
        p_invoice_header_rec.tax_invoice_internal_seq,     --tax_invoice_number
        NULL, --tax_event_class_code
        NULL,                                              --tax_event_type_code
        NULL,                                              --doc_event_status
        NULL, --rdng_ship_to_pty_tx_prof_id
        NULL, --rdng_ship_from_pty_tx_prof_id
        NULL, --rdng_bill_to_pty_tx_prof_id
        NULL, --rdng_bill_from_pty_tx_prof_id
        NULL, --rdng_ship_to_pty_tx_p_st_id
        NULL, --rdng_ship_from_pty_tx_p_st_id
        NULL, --rdng_bill_to_pty_tx_p_st_id
        NULL, --rdng_bill_from_pty_tx_p_st_id
        p_invoice_header_rec.vendor_id,			   --bill_third_pty_acct_id
        p_invoice_header_rec.vendor_site_id,               --bill_third_pty_acct_site_id
        p_invoice_header_rec.vendor_id,                    --ship_third_pty_acct_id
        p_invoice_header_rec.vendor_site_id                --ship_third_pty_acct_site_id
     );
Line: 7148

	       --   l_line_level_action := 'UPDATE';
Line: 7176

                  l_line_level_action := 'UPDATE';
Line: 7180

              SELECT 'Y'
              INTO   l_tax_already_calculated_line
              FROM   zx_lines_det_factors
              WHERE  application_id        =  200
              AND    entity_code           =  'AP_INVOICES'
              AND    event_class_code      IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
              AND    trx_id                = l_inv_line_list(i).invoice_id
              AND    trx_line_id           = l_inv_line_list(i).line_number
              AND    ROWNUM = 1;
Line: 7191

                  l_line_level_action := 'UPDATE';
Line: 7239

	          Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in Get_po_info');
Line: 7285

	          Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in Get_Receipt_Info');
Line: 7328

	          Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in Get_Prepay_Invoice_Info');
Line: 7358

	      Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in Get_Prepay_Invoice_Info');
Line: 7412

	          Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in Get_Corrected_Invoice_Info');
Line: 7458

		 SELECT /*+ index(ZX_LINES_DET_FACTORS ZX_LINES_DET_FACTORS_U1) */  -- 9373895
		        line_amt_includes_tax_flag
		   INTO l_init_line_amt_incl_tax_fg
		   FROM zx_lines_det_factors
		  WHERE application_id = 200
		    AND entity_code    = 'AP_INVOICES'
		    AND event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
		    AND trx_id         = l_inv_line_list(i).invoice_id
		    AND trx_line_id    = l_inv_line_list(i).line_number
		    AND rownum         = 1;
Line: 7515

	      Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in Get_Line_Class');
Line: 7531

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id = l_inv_line_list(i).po_line_location_id
                 AND rownum = 1;
Line: 7565

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id =
                    (SELECT pod.line_location_id
                       FROM po_distributions_all pod
                      WHERE po_distribution_id = l_inv_line_list(i).po_distribution_id)
                 AND rownum = 1;
Line: 7602

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id =
                     (SELECT rcv.po_line_location_id
                        FROM rcv_shipment_lines rcv
                       WHERE rcv.shipment_line_id = l_inv_line_list(i).rcv_shipment_line_id)
                 AND rownum = 1;
Line: 7639

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id =
                     (SELECT rcv.po_line_location_id
                        FROM rcv_transactions rcv
                       WHERE rcv.transaction_id = l_inv_line_list(i).rcv_transaction_id)
                 AND rownum = 1;
Line: 7697

         		 SELECT aid.dist_code_combination_id
         		   INTO l_inv_line_list(i).default_dist_ccid
                         FROM ap_invoice_distributions_all aid
         		  WHERE aid.invoice_id = l_inv_line_list(i).invoice_id
         		    AND aid.invoice_line_number =  l_inv_line_list(i).line_number
					AND ROWNUM = 1;
Line: 7733

	                            Insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.invoice_id , 'Error in get_ccid_from_projects');
Line: 7753

          SELECT aerd.code_combination_id
            INTO l_inv_line_list(i).default_dist_ccid
            FROM ap_exp_report_dists_all aerd,
                 ap_expense_report_lines_all aerl,
                 ap_invoices_all ai
           WHERE aerd.report_header_id = l_inv_line_list(i).reference_key1
             AND aerd.report_line_id = l_inv_line_list(i).reference_key2
             AND aerd.report_line_id = aerl.report_line_id
             AND aerd.report_header_id = aerl.report_header_id
             AND ai.invoice_id = l_inv_line_list(i).invoice_id
             AND ai.invoice_type_lookup_code = 'EXPENSE REPORT'
             AND rownum = 1;
Line: 7899

             SELECT sum(amount)
               INTO trans_lines(i).line_amt
               FROM ap_invoice_distributions_all aids
              WHERE invoice_id            = p_invoice_header_rec.invoice_id
		AND invoice_line_number   = p_line_number
                AND line_type_lookup_code = 'PREPAY'
                AND EXISTS
                      (select 'Prepayment Invoice'
                         from ap_invoice_distributions_all aidp
                         where aidp.invoice_distribution_id = aids.prepay_distribution_id
                           and aidp.invoice_id              = l_inv_line_list(i).invoice_id
                           and aidp.invoice_line_number     = l_inv_line_list(i).line_number);
Line: 7941

                SELECT unit_price
                  INTO trans_lines(i).unit_price
                  FROM ap_invoice_lines_all ail
                 WHERE ail.invoice_id = l_inv_line_list(i).Retained_invoice_id
                   AND ail.line_number =  l_inv_line_list(i).Retained_line_number;
Line: 8106

    l_debug_info := 'Bulk Insert into global temp table';
Line: 8113

        INSERT INTO zx_transaction_lines_gt
        VALUES trans_lines(m);
Line: 8138

    insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.Invoice_id , l_err);
Line: 8261

      SELECT location_id
        INTO l_bill_to_location_id
        FROM hr_all_organization_units
       WHERE organization_id = P_Invoice_Header_Rec.org_id;
Line: 8278

      SELECT location_id, ship_to_location_id, fob_lookup_code
        INTO l_location_id, l_ship_to_location_id, l_fob_point
        FROM ap_supplier_sites_all
       WHERE vendor_site_id = P_Invoice_Header_Rec.vendor_site_id;
Line: 8536

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id = P_Inv_Line_List(i).po_line_location_id
                 AND rownum = 1;
Line: 8572

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id =
                    (SELECT pod.line_location_id
                       FROM po_distributions_all pod
                      WHERE po_distribution_id = P_Inv_Line_List(i).po_distribution_id)
                 AND rownum = 1;
Line: 8609

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id =
                     (SELECT rcv.po_line_location_id
                        FROM rcv_shipment_lines rcv
                       WHERE rcv.shipment_line_id = P_Inv_Line_List(i).rcv_shipment_line_id)
                 AND rownum = 1;
Line: 8646

              SELECT pd.code_combination_id
                INTO l_default_ccid
                FROM po_distributions_all pd
               WHERE pd.line_location_id =
                     (SELECT rcv.po_line_location_id
                        FROM rcv_transactions rcv
                       WHERE rcv.transaction_id = P_Inv_Line_List(i).rcv_transaction_id)
                 AND rownum = 1;
Line: 8699

          SELECT aerd.code_combination_id
            INTO l_default_ccid
            FROM ap_exp_report_dists_all aerd,
                 ap_expense_report_lines_all aerl,
                 ap_invoices_all ai
           WHERE aerd.report_header_id = P_Inv_Line_List(i).reference_key1
             AND aerd.report_line_id = P_Inv_Line_List(i).reference_key2
             AND aerd.report_line_id = aerl.report_line_id
             AND aerd.report_header_id = aerl.report_header_id
             AND ai.invoice_id = P_Invoice_Header_Rec.invoice_id  --9841978
             AND ai.invoice_type_lookup_code = 'EXPENSE REPORT'
             AND rownum = 1;
Line: 9061

              INSERT INTO zx_trx_tax_link_gt (
                application_id,
                entity_code,
                event_class_code,
                trx_id,
                trx_level_type,
                trx_line_id,
                summary_tax_line_number,
                line_amt
              ) SELECT
                  200,                                           -- application_id
                  'AP_INVOICES',                                 -- entity_code
                  p_event_class_code,                            -- event_class_code
                  P_Invoice_Header_Rec.invoice_id,               -- trx_id
                  'LINE',                                        -- trx_level_type
                  aili.line_number,                              -- trx_line_id
                  p_inv_line_list(i).line_number,                -- summary_tax_line_number
                  AP_UTILITIES_PKG.ap_round_currency(
                    p_inv_line_list(i).amount*aili.amount/l_prorating_total,
                    P_Invoice_Header_Rec.invoice_currency_code)  -- line_amt
                 FROM ap_invoice_lines_interface aili
                WHERE aili.invoice_id = P_Invoice_Header_Rec.invoice_id
                  AND aili.line_number <> p_inv_line_list(i).line_number
                  AND aili.line_type_lookup_code <> 'TAX'
                  AND NVL(aili.taxable_flag, 'N') = 'Y';
Line: 9099

                SELECT SUM(NVL(line_amt,0))
                  INTO l_total_prorated
                  FROM zx_trx_tax_link_gt
                 WHERE trx_id = P_Invoice_Header_Rec.invoice_id
                   AND summary_tax_line_number = p_inv_line_list(i).line_number;
Line: 9106

                  UPDATE zx_trx_tax_link_gt
                     SET line_amt = line_amt + (p_inv_line_list(i).amount - l_total_prorated)
                   WHERE trx_id = P_Invoice_Header_Rec.invoice_id
                     AND trx_line_id <> p_inv_line_list(i).line_number
                     AND trx_line_id =
                        (SELECT (MAX(aili.line_number))
                           FROM ap_invoice_lines_interface aili
                          WHERE aili.invoice_id = P_Invoice_Header_Rec.invoice_id
                            AND aili.line_number <> p_inv_line_list(i).line_number
                            AND aili.amount <> 0
                            AND aili.line_type_lookup_code <> 'TAX'
                            AND NVL(aili.taxable_flag, 'N') = 'Y'
                            AND ABS(aili.amount) >=
                              ( SELECT MAX(ABS(ail2.amount))
                                  FROM ap_invoice_lines_interface ail2
                                 WHERE ail2.invoice_id = aili.invoice_id
                                   AND ail2.line_number <> p_inv_line_list(i).line_number
                                   AND ail2.line_number <> aili.line_number
                                   AND ail2.line_type_lookup_code <> 'TAX'
                                   AND NVL(ail2.taxable_flag, 'N') = 'Y'));
Line: 9151

                   SELECT SUM(NVL(amount, 0))
                     INTO l_prorating_total
                     FROM ap_invoice_lines_interface
                    WHERE invoice_id = P_Invoice_Header_Rec.invoice_id
                      AND line_number <> p_inv_line_list(i).line_number
					  AND line_type_lookup_code <> 'TAX'     --Bug6608702**
                      AND line_group_number = p_inv_line_list(i).line_group_number;
Line: 9160

                   l_debug_info := 'Step 18: Get Insert in global temp table';
Line: 9166

                     INSERT INTO zx_trx_tax_link_gt (
                       application_id,
                       entity_code,
                       event_class_code,
                       trx_id,
                       trx_level_type,
                       trx_line_id,
                       summary_tax_line_number,
                       line_amt
                     ) SELECT
                         200,                                           -- application_id
                         'AP_INVOICES',                                 -- entity_code
                         p_event_class_code,                            -- event_class_code
                         P_Invoice_Header_Rec.invoice_id,               -- trx_id
                         'LINE',                                        -- trx_level_type
                         aili.line_number,                              -- trx_line_id
                         p_inv_line_list(i).line_number,                -- summary_tax_line_number
                         AP_UTILITIES_PKG.ap_round_currency(
                           p_inv_line_list(i).amount*aili.amount/l_prorating_total,
                           P_Invoice_Header_Rec.invoice_currency_code)  -- line_amt
                        FROM ap_invoice_lines_interface aili
                       WHERE aili.invoice_id = P_Invoice_Header_Rec.invoice_id
                         AND aili.line_number <> p_inv_line_list(i).line_number
						 AND aili.line_type_lookup_code <> 'TAX' --Bug6608702**
                         AND aili.line_group_number = p_inv_line_list(i).line_group_number;
Line: 9203

                     SELECT SUM(NVL(line_amt,0))
                       INTO l_total_prorated
                       FROM zx_trx_tax_link_gt
                      WHERE trx_id = P_Invoice_Header_Rec.invoice_id
                        AND summary_tax_line_number = p_inv_line_list(i).line_number;
Line: 9210

                       UPDATE zx_trx_tax_link_gt
                          SET line_amt = line_amt + (p_inv_line_list(i).amount - l_total_prorated)
                        WHERE trx_id = P_Invoice_Header_Rec.invoice_id
                          AND trx_line_id <> p_inv_line_list(i).line_number
                          AND trx_line_id =
                             (SELECT (MAX(aili.line_number))
                                FROM ap_invoice_lines_interface aili
                               WHERE aili.invoice_id = P_Invoice_Header_Rec.invoice_id
                                 AND aili.line_number <> p_inv_line_list(i).line_number
								 AND aili.line_type_lookup_code <> 'TAX' --Bug6608702**
                                 AND aili.amount <> 0
                                 AND aili.line_group_number = p_inv_line_list(i).line_group_number
                                 AND ABS(aili.amount) >=
                                   ( SELECT  MAX(ABS(ail2.amount))
                                       FROM  ap_invoice_lines_interface ail2
                                      WHERE  ail2.invoice_id = aili.invoice_id
                                        AND  ail2.line_number <> p_inv_line_list(i).line_number
                                        AND  ail2.line_number <> aili.line_number
										AND  ail2.line_type_lookup_code <> 'TAX' --Bug6608702**
                                        AND  ail2.line_group_number =
                                               p_inv_line_list(i).line_group_number));
Line: 9852

    l_debug_info := 'Step 12: Bulk Insert into global temp tables';
Line: 9859

      DELETE FROM zx_transaction_lines_gt
       WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
         AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
         AND 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 trx_id = p_invoice_header_rec.invoice_id;
Line: 9869

          INSERT INTO zx_transaction_lines_gt
          VALUES trans_lines(m);
Line: 9875

          INSERT INTO zx_import_tax_lines_gt
          VALUES tax_lines(m);
Line: 9888

              FOR i IN (SELECT *
                          FROM zx_import_tax_lines_gt
                         WHERE trx_id = P_Invoice_Header_Rec.invoice_id
                           AND application_id = 200
                           AND entity_code ='AP_INVOICES'
                           AND event_class_code IN ('STANDARD INVOICES','PREPAYMENT INVOICES','EXPENSE REPORTS')) LOOP

                        l_debug_info := '1 '|| i.ATTRIBUTE1;
Line: 9940

          INSERT INTO zx_trx_tax_link_gt
          VALUES link_lines(m);
Line: 10174

					  SELECT SUM(NVL(amount, 0))
                        INTO l_prorating_total
                        FROM ap_invoice_lines
                       WHERE invoice_id = l_inv_tax_list(i).invoice_id
                         AND line_number <> l_inv_tax_list(i).line_number
						 AND line_type_lookup_code <> 'TAX'   --Bug6608702
                         AND line_group_number = l_inv_tax_list(i).line_group_number;
Line: 10198

                      l_debug_info := 'Step 18: Get Insert in global temp table';
Line: 10205

                        INSERT INTO zx_trx_tax_link_gt (
                          application_id,
                          entity_code,
                          event_class_code,
                          trx_id,
                          trx_level_type,
                          trx_line_id,
                          summary_tax_line_number,
                          line_amt
                        ) SELECT
                            200,                                           -- application_id
                            'AP_INVOICES',                                 -- entity_code
                            p_event_class_code,                            -- event_class_code
                            l_inv_tax_list(i).invoice_id,               -- trx_id
                            'LINE',                                        -- trx_level_type
                            ail.line_number,                              -- trx_line_id
                            l_inv_tax_list(i).line_number,                -- summary_tax_line_number
                            AP_UTILITIES_PKG.ap_round_currency(
                              l_inv_tax_list(i).amount*ail.amount/l_prorating_total,
                              l_inv_header_rec2.invoice_currency_code)  -- line_amt
                           FROM ap_invoice_lines ail
                          WHERE ail.invoice_id = l_inv_tax_list(i).invoice_id
                            AND ail.line_number <> l_inv_tax_list(i).line_number
							AND ail.line_type_lookup_code <> 'TAX'   --Bug6608702
                            AND ail.line_group_number = l_inv_tax_list(i).line_group_number;
Line: 10242

                        SELECT SUM(NVL(line_amt,0))
                          INTO l_total_prorated
                          FROM zx_trx_tax_link_gt
                         WHERE trx_id = l_inv_tax_list(i).invoice_id
                           AND summary_tax_line_number = l_inv_tax_list(i).line_number;
Line: 10249

                          UPDATE zx_trx_tax_link_gt
                             SET line_amt = line_amt + (l_inv_tax_list(i).amount - l_total_prorated)
                           WHERE trx_id = l_inv_tax_list(i).invoice_id
                             AND trx_line_id <> l_inv_tax_list(i).line_number
                             AND trx_line_id =
                                (SELECT (MAX(ail.line_number))
                                   FROM ap_invoice_lines ail
                                  WHERE ail.invoice_id = l_inv_tax_list(i).invoice_id
                                    AND ail.line_number <> l_inv_tax_list(i).line_number
									AND ail.line_type_lookup_code <> 'TAX'   --Bug6608702
                                    AND ail.amount <> 0
                                    AND ail.line_group_number = l_inv_tax_list(i).line_group_number
                                    AND ABS(ail.amount) >=
                                      ( SELECT  MAX(ABS(ail2.amount))
                                          FROM  ap_invoice_lines ail2
                                         WHERE  ail2.invoice_id = ail.invoice_id
                                           AND  ail2.line_number <> l_inv_tax_list(i).line_number
                                           AND  ail2.line_number <> ail.line_number
										   AND  ail2.line_type_lookup_code <> 'TAX'   --Bug6608702
                                           AND  ail2.line_group_number =
                                                  l_inv_tax_list(i).line_group_number));
Line: 10519

	     insert into ap_errors_gt(invoice_id , message_text) values (P_Invoice_Header_Rec.Invoice_id , 'Error in Get_PO_Info ');
Line: 10553

	       insert into ap_errors_gt(invoice_id , message_text) values (P_Invoice_Header_Rec.Invoice_id , 'Error in Get_Receipt_Info');
Line: 10584

	     insert into ap_errors_gt(invoice_id , message_text) values (P_Invoice_Header_Rec.Invoice_id , 'Error in Get_Corrected_Invoice_Info');
Line: 10864

    l_debug_info := 'Step 14: Bulk Insert into global temp tables';
Line: 10873

          INSERT INTO zx_transaction_lines_gt
          VALUES trans_lines(m);
Line: 10887

          INSERT INTO zx_import_tax_lines_gt
          VALUES tax_lines(m);
Line: 10899

              FOR i IN (SELECT *
                          FROM zx_import_tax_lines_gt
                         WHERE trx_id = P_Invoice_Header_Rec.invoice_id
                           AND application_id = 200
                           AND entity_code ='AP_INVOICES'
                           AND event_class_code IN ('STANDARD INVOICES','PREPAYMENT INVOICES','EXPENSE REPORTS')) LOOP

                        l_debug_info := '1 '|| i.ATTRIBUTE1;
Line: 10949

          INSERT INTO zx_trx_tax_link_gt
          VALUES link_lines(m);
Line: 10976

    insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.Invoice_id , l_err);
Line: 11129

              l_dist_level_action := 'UPDATE';
Line: 11138

        l_debug_info := 'Step 3: Update the amount including IPV/ERV';
Line: 11144

           SELECT SUM(amount)
             INTO l_amount
             FROM ap_invoice_distributions_all
            WHERE invoice_id = l_inv_dist_list(i).invoice_id
	      AND (related_id = l_inv_dist_list(i).related_id
                   or related_retainage_dist_id = l_inv_dist_list(i).related_retainage_dist_id);
Line: 11154

           SELECT SUM(amount)
             INTO l_amount
             FROM ap_invoice_distributions_all
            WHERE invoice_id = l_inv_dist_list(i).invoice_id
	      AND related_id = l_inv_dist_list(i).related_id;
Line: 11172

          SELECT quantity_invoiced, po_release_id, primary_intended_use --8796484
            INTO l_line_quantity_invoiced, l_po_release_id, l_intended_use
            FROM ap_invoice_lines_all
           WHERE invoice_id = l_inv_dist_list(i).invoice_id
             AND line_number = l_inv_dist_list(i).invoice_line_number;
Line: 11238

            SELECT currency_conversion_rate
              INTO l_receipt_curr_conv_rate
              FROM rcv_transactions
             WHERE transaction_id = l_inv_dist_list(i).rcv_transaction_id;
Line: 11265

	   Select invoice_id, invoice_line_number
	     Into l_adj_doc_trx_id, l_adj_doc_line_id
	     From ap_invoice_distributions_all
	    Where invoice_distribution_id = l_inv_dist_list(i).corrected_invoice_dist_id;
Line: 11304

	  SELECT invoice_id, invoice_line_number
	    INTO l_applied_from_trx_id, l_applied_from_line_id
	    FROM ap_invoice_distributions_all
	   WHERE invoice_distribution_id = l_inv_dist_list(i).prepay_distribution_id;
Line: 11352

		 SELECT invoice_id, invoice_line_number
                   INTO l_prepay_inv_id, l_prepay_line_num
                   FROM ap_invoice_distributions_all
                  WHERE invoice_distribution_id = l_inv_dist_list(i).prepay_distribution_id;
Line: 11374

		    SELECT POL.retainage_rate INTO l_retainage_rate
              FROM po_lines_all POL , po_line_locations_all PLL
             WHERE PLL.po_header_id = POL.po_header_id
               AND PLL.po_line_id = POL.po_line_id
               AND PLL.line_location_id = l_po_line_location_id
               AND PLL.po_header_id =  l_ref_doc_trx_id;
Line: 11387

		        select amount into l_retained_amount from ap_invoice_distributions_all aid
		         where  aid.invoice_id = l_inv_dist_list(i).invoice_id
		           and aid.line_type_lookup_code = 'RETAINAGE'
		           and aid.related_retainage_dist_id is NOT NULL
		           and aid.related_retainage_dist_id = l_inv_dist_list(i).invoice_distribution_id;
Line: 11402

		        SELECT amount INTO l_retainage_rrf_amount FROM ap_invoice_distributions_all
		         WHERE line_type_lookup_code = 'RETAINAGE'
			       AND invoice_distribution_id = l_inv_dist_list(i).RETAINED_INVOICE_DIST_ID;
Line: 11406

		        SELECT aid1.quantity_invoiced  , aid1.unit_price INTO l_quantity_invoiced  , l_unit_price
                  FROM ap_invoice_distributions_all aid1 , ap_invoice_distributions_all aid2
		         WHERE aid1.line_type_lookup_code IN ('ACCRUAL' ,'ITEM')
		           AND aid1.invoice_distribution_id = aid2.related_retainage_dist_id
			       AND aid2.invoice_distribution_id = l_inv_dist_list(i).RETAINED_INVOICE_DIST_ID
			       AND aid2.line_type_lookup_code = 'RETAINAGE';
Line: 11607

      l_debug_info := 'Step 7: Bulk Insert into global temp table';
Line: 11615

          INSERT INTO zx_itm_distributions_gt
          VALUES trans_dists(m);
Line: 11641

 |  FUNCTION - Update_AP()
 |
 |  DESCRIPTION
 |      This function will handle the return of values from the eTax repository
 |      This will be called from all the functions that call the etax services
 |      in the case the call is successfull.
 |
 |  PARAMETERS
 |      P_Invoice_header_rec - Invoice header info
 |      P_Calling_Mode - calling mode.
 |      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
 |    20-OCT-2003   SYIDNER        Created
 |
 *============================================================================*/

  FUNCTION Update_AP(
             P_Invoice_header_rec    IN ap_invoices_all%ROWTYPE,
             P_Calling_Mode          IN VARCHAR2,
             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: 11673

    l_api_name                   CONSTANT VARCHAR2(30) := 'Update_AP';
Line: 11679

      'AP_ETAX_SERVICES_PKG.Update_AP<-'||P_calling_sequence;
Line: 11744

    ELSIF (P_Calling_Mode in ('REVERSE INVOICE','DELETE TAX LINE')) THEN
      -------------------------------------------------------------------
      l_debug_info := 'Step 5: Calling Return_Tax_Lines for '||
                      'REVERSE INVOICE';
Line: 11799

                insert into ap_errors_gt(invoice_id , message_text) values(P_Invoice_Header_Rec.Invoice_id , l_err);
Line: 11803

  END Update_AP;
Line: 11813

 |      based on the parameter p_invoice_header_rec. A psuedo-line is inserted
 |      into the GTT and removed after the tax amount is calculated.
 |
 |  PARAMETERS
 |      P_Invoice_Header_Rec 	- Invoice header info
 |      P_Invoice_Lines_Rec	- Invoice lines info
 |      P_Calling_Mode 		- Calling mode. (CALCULATE_QUOTE)
 |      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
 |    13-AUG-2004   Sanjay         Created
 *============================================================================*/

  FUNCTION CALCULATE_QUOTE(
             P_Invoice_Header_Rec      	IN  ap_invoices_all%ROWTYPE,
             P_Invoice_Lines_Rec	    IN  ap_invoice_lines_all%ROWTYPE,
             P_Calling_Mode            	IN  VARCHAR2,
	         P_Tax_Amount		        OUT NOCOPY NUMBER,
	         P_Tax_Amt_Included		    OUT NOCOPY VARCHAR2,
             P_Error_Code              	OUT NOCOPY VARCHAR2,
             P_Calling_Sequence         IN  VARCHAR2) RETURN BOOLEAN
  IS

    l_debug_info                 	VARCHAR2(240);
Line: 11877

    SELECT SUM(NVL(zdl.tax_amt,0))
    FROM   zx_detail_tax_lines_gt zdl
    WHERE  zdl.application_id = 200
    AND    zdl.entity_code    = 'AP_INVOICES'
    AND    zdl.trx_id         = P_Invoice_Lines_Rec.invoice_id
    AND    NVL(zdl.self_assessed_flag,  'N') = 'N'
    AND    NVL(zdl.reporting_only_flag, 'N') = 'N';
Line: 11900

      SELECT location_id, fob_lookup_code
        INTO l_location_id, l_fob_point
        FROM ap_supplier_sites_all
       WHERE vendor_site_id = P_Invoice_Header_Rec.vendor_site_id;
Line: 11958

      SELECT location_id
        INTO l_bill_to_location_id
        FROM hr_all_organization_units
       WHERE organization_id = P_Invoice_Header_Rec.org_id;
Line: 12073

    l_debug_info := 'Step 9: Insert into zx_transaction_lines_gt';
Line: 12080

	INSERT INTO zx_transaction_lines_gt
	(
	 application_id,
	 entity_code,
	 event_class_code,
	 trx_id,
	 trx_level_type,
	 trx_line_id,
	 line_level_action,
	 trx_line_type,
	 trx_line_date,
	 trx_business_category,
	 line_intended_use,
	 user_defined_fisc_class,
	 line_amt,
	 trx_line_quantity,
	 unit_price,
	 product_id,
	 product_fisc_classification,
	 product_org_id,
	 uom_code,
	 product_type,
	 product_category,
	 fob_point,
	 ship_to_party_id,
	 ship_from_party_id,
	 bill_to_party_id,
	 bill_from_party_id,
	 ship_from_party_site_id,
	 bill_from_party_site_id,
	 ship_to_location_id,
     ship_from_location_id,
	 bill_to_location_id,
	 bill_from_location_id,
	 account_ccid,
	 merchant_party_country,
	 ref_doc_application_id,
	 ref_doc_entity_code,
	 ref_doc_event_class_code,
	 ref_doc_trx_id,
	 ref_doc_line_id,
	 ref_doc_line_quantity,
     ref_doc_trx_level_type,
	 --applied_to_trx_line_id,
	 trx_line_number,
	 trx_line_description,
	 product_description,
	 trx_line_gl_date,
	 merchant_party_name,
	 merchant_party_document_number,
	 merchant_party_reference,
	 merchant_party_taxpayer_id,
	 merchant_party_tax_reg_number,
	 assessable_value,
	 line_amt_includes_tax_flag,
	 historical_flag,
	 ctrl_hdr_tx_appl_flag,
	 ctrl_total_line_tx_amt,
	 input_tax_classification_code
	)
	VALUES
	(
	 200,
	 'AP_INVOICES',
	 l_event_class_code,
	 P_Invoice_Lines_Rec.invoice_id,
	 'LINE',
	 P_Invoice_Lines_Rec.line_number,
	 l_line_level_action,
	 P_Invoice_Lines_Rec.line_type_lookup_code,
	 P_Invoice_Header_Rec.invoice_date,
	 P_Invoice_Lines_Rec.trx_business_category,
	 P_Invoice_Lines_Rec.primary_intended_use,
	 P_Invoice_Lines_Rec.user_defined_fisc_class,
	 P_Invoice_Lines_Rec.amount,
	 P_Invoice_Lines_Rec.quantity_invoiced,
	 P_Invoice_Lines_Rec.unit_price,
	 P_Invoice_Lines_Rec.inventory_item_id,
	 P_Invoice_Lines_Rec.product_fisc_classification,
	 l_product_org_id,
	 P_Invoice_Lines_Rec.unit_meas_lookup_code,
	 P_Invoice_Lines_Rec.product_type,
	 P_Invoice_Lines_Rec.product_category,
	 l_fob_point,
	 P_Invoice_Lines_Rec.org_id,
	 P_Invoice_Header_Rec.party_id,
	 P_Invoice_Lines_Rec.org_id,
	 P_Invoice_Header_Rec.party_id,
	 P_Invoice_Header_Rec.party_site_id,
	 P_Invoice_Header_Rec.party_site_id,
	 P_Invoice_Lines_Rec.ship_to_location_id,
     l_location_id,
	 l_bill_to_location_id,
     l_location_id,
	 P_Invoice_Lines_Rec.default_dist_ccid,
	 P_Invoice_Lines_Rec.country_of_supply,
	 l_ref_doc_application_id,
	 l_ref_doc_entity_code,
	 l_ref_doc_event_class_code,
	 l_ref_doc_trx_id,
         --Bug5680407 corrected the wrong ordering of below
         --3 coulmns
	 P_Invoice_Lines_Rec.po_line_location_id,
	 l_ref_doc_line_quantity,
     l_ref_doc_trx_level_type,
	 P_Invoice_Lines_Rec.line_number,
	 P_Invoice_Lines_Rec.description,
	 P_Invoice_Lines_Rec.item_description,
	 P_Invoice_Lines_Rec.accounting_date,
	 P_Invoice_Lines_Rec.merchant_name,
	 P_Invoice_Lines_Rec.merchant_document_number,
	 P_Invoice_Lines_Rec.merchant_reference,
	 P_Invoice_Lines_Rec.merchant_taxpayer_id,
	 P_Invoice_Lines_Rec.merchant_tax_reg_number,
	 P_Invoice_Lines_Rec.assessable_value,
	 l_line_amt_includes_tax_flag,
	 NVL(P_Invoice_Header_Rec.historical_flag, 'N'),
	 l_ctrl_hdr_tx_appl_flag,
	 P_Invoice_Lines_Rec.control_amount,
	 P_Invoice_Lines_Rec.tax_classification_code
	);
Line: 12240

	   SELECT distinct zdl.tax_amt_included_flag
           INTO   P_Tax_Amt_Included
           FROM   zx_detail_tax_lines_gt zdl
           WHERE  zdl.application_id	= 200
           AND    zdl.entity_code	= 'AP_INVOICES'
           AND    zdl.trx_id 		= P_Invoice_Lines_Rec.invoice_id
           AND    NVL(zdl.self_assessed_flag,  'N') = 'N'
           AND    NVL(zdl.reporting_only_flag, 'N') = 'N';
Line: 12280

    l_debug_info := 'Step 13: Delete eTax Global Temporary Tables';
Line: 12285

    BEGIN DELETE zx_trx_headers_gt;
Line: 12289

    BEGIN DELETE zx_transaction_lines_gt;
Line: 12332

        SELECT  line_intended_use,
                product_type,
                product_category,
                product_fisc_classification,
                user_defined_fisc_class,
                assessable_value,
		input_tax_classification_code
        FROM	zx_lines_det_factors
        WHERE	application_id           = p_application_id
        AND	internal_organization_id = p_org_id
        AND	entity_code              = p_entity_code
        AND 	event_class_code         = p_event_class_code
        AND	trx_level_type           = p_trx_level_type
        AND	trx_id                   = p_trx_id
        AND	trx_line_id              = p_trx_line_id;
Line: 12407

        SELECT  line_intended_use,
                product_type,
                product_category,
                product_fisc_classification,
                user_defined_fisc_class,
                assessable_value,
		input_tax_classification_code,
		default_taxation_country,
		trx_business_category
        FROM	 zx_lines_det_factors
        WHERE	application_id           = p_application_id
        AND	internal_organization_id = p_org_id
        AND	entity_code              = p_entity_code
        AND 	event_class_code         = p_event_class_code
        AND	trx_level_type           = p_trx_level_type
        AND	trx_id                   = p_trx_id
        AND	trx_line_id              = p_trx_line_id;
Line: 12488

	  select
            nvl(item_dist.accounting_date,
	        zx_dist.gl_date)                        accounting_date, --Bug 8350132
            'N'						accrual_posted_flag,
            'U'						assets_addition_flag,
            tax_dist.assets_tracking_flag		assets_tracking_flag, --Bug14772756
            'N'						cash_posted_flag,
            AP_INVOICE_LINES_PKG.get_max_dist_line_num(
		              p_invoice_id,
		              tax_dist.invoice_line_number)+1
							distribution_line_number,
            tax_dist.dist_code_combination_id		dist_code_combination_id,
            tax_dist.invoice_id				invoice_id,
            l_user_id					last_updated_by,
            l_sysdate					last_update_date,
            tax_dist.line_type_lookup_code		line_type_lookup_code,
            ap_utilities_pkg.get_gl_period_name(
                              zx_dist.gl_date,
                              tax_dist.org_id)          period_name,
            tax_dist.set_of_books_id			set_of_books_id,
            (-tax_dist.amount)				amount,
            (-tax_dist.base_amount)			base_amount,
            --P_Invoice_Header_Rec.batch_id		batch_id,
            l_user_id					created_by,
            l_sysdate					creation_date,
            tax_dist.description			description,
            NULL					final_match_flag,
            tax_dist.income_tax_region			income_tax_region,
            l_user_id					last_update_login,
            NULL					match_status_flag,
            'N'						posted_flag,
            tax_dist.po_distribution_id			po_distribution_id,
            NULL					program_application_id,
            NULL					program_id,
            NULL					program_update_date,
            NULL					quantity_invoiced,
            NULL					request_id,
            'Y'						reversal_flag,
            tax_dist.type_1099				type_1099,
            tax_dist.unit_price				unit_price,
            DECODE(tax_dist.encumbered_flag,
		   'R', 'R', 'N')   			encumbered_flag,    --Bug 8733916
            NULL					stat_amount,
            tax_dist.attribute1				attribute1,
            tax_dist.attribute10			attribute10,
            tax_dist.attribute11			attribute11,
            tax_dist.attribute12			attribute12,
            tax_dist.attribute13			attribute13,
            tax_dist.attribute14			attribute14,
            tax_dist.attribute15			attribute15,
            tax_dist.attribute2				attribute2,
            tax_dist.attribute3				attribute3,
            tax_dist.attribute4				attribute4,
            tax_dist.attribute5				attribute5,
            tax_dist.attribute6				attribute6,
            tax_dist.attribute7				attribute7,
            tax_dist.attribute8				attribute8,
            tax_dist.attribute9				attribute9,
            tax_dist.attribute_category			attribute_category,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
		   tax_dist.expenditure_item_date)	expenditure_item_date, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.expenditure_organization_id)  expenditure_organization_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
            	   tax_dist.expenditure_type)		expenditure_type, /* bug 11076722 */
            tax_dist.parent_invoice_id			parent_invoice_id,
            decode(zx_dist.recoverable_flag,
		   'Y', 'E',
		   item_dist.pa_addition_flag)		pa_addition_flag,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.pa_quantity)		pa_quantity, /* bug 11076722 */
            NULL					prepay_amount_remaining,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_accounting_context) project_accounting_context, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_id)		project_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.task_id)			task_id, /* bug 11076722 */
            NULL					packet_id,
            'N'						awt_flag,
            tax_dist.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,
            tax_dist.org_id				org_id,
            NULL					awt_invoice_payment_id,
            tax_dist.global_attribute_category		global_attribute_category,
            tax_dist.global_attribute1			global_attribute1,
            tax_dist.global_attribute2			global_attribute2,
            tax_dist.global_attribute3			global_attribute3,
            tax_dist.global_attribute4			global_attribute4,
            tax_dist.global_attribute5			global_attribute5,
            tax_dist.global_attribute6			global_attribute6,
            tax_dist.global_attribute7			global_attribute7,
            tax_dist.global_attribute8			global_attribute8,
            tax_dist.global_attribute9			global_attribute9,
            tax_dist.global_attribute10			global_attribute10,
            tax_dist.global_attribute11			global_attribute11,
            tax_dist.global_attribute12			global_attribute12,
            tax_dist.global_attribute13			global_attribute13,
            tax_dist.global_attribute14			global_attribute14,
            tax_dist.global_attribute15			global_attribute15,
            tax_dist.global_attribute16			global_attribute16,
            tax_dist.global_attribute17			global_attribute17,
            tax_dist.global_attribute18			global_attribute18,
            tax_dist.global_attribute19			global_attribute19,
            tax_dist.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,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.award_id)          		award_id,
            NULL                        		credit_card_trx_id,
            tax_dist.dist_match_type    		dist_match_type,
            tax_dist.rcv_transaction_id 		rcv_transaction_id,
            ap_invoice_distributions_s.NEXTVAL   	invoice_distribution_id,
            tax_dist.invoice_distribution_id     	parent_reversal_id,
            tax_dist.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,
            tax_dist.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,
	    -- bug9321979
            decode(p_calling_mode,'CANCEL INVOICE',
                   DECODE(tax_dist.prepay_distribution_id,NULL, 'Y',NULL),Null) cancellation_flag,   --Bug8811102
            tax_dist.invoice_line_number	  	invoice_line_number,
            tax_dist.corrected_invoice_dist_id		corrected_invoice_dist_id,
            tax_dist.rounding_amt       	  	rounding_amt,
            decode(NVL(zx_dist.tax_only_line_flag,'N'),'Y',
			        NULL,zx_dist.trx_line_dist_id)		charge_applicable_to_dist_id, --Bug14772756
            NULL					corrected_quantity,
            -- bug 5572121
            -- NULL                                  	related_id,
            DECODE( tax_dist.related_id, NULL, NULL,
                    tax_dist.invoice_distribution_id,
                     ap_invoice_distributions_s.CURRVAL, NULL) related_id,
            NULL                                  	asset_book_type_code,
            NULL                                  	asset_category_id,
            tax_dist.distribution_class 	  	distribution_class,
            tax_dist.tax_code_id        	  	tax_code_id,
            tax_dist.intended_use                 	intended_use,
            zx_dist.rec_nrec_tax_dist_id 	  	detail_tax_dist_id,
            zx_dist.rec_nrec_rate     	  	  	rec_nrec_rate,
            zx_dist.recovery_rate_id  	  	  	recovery_rate_id,
            zx_dist.recovery_type_code	  	  	recovery_type_code,
            NULL                                  	withholding_tax_code_id,
            NULL			     	  	taxable_amount,
            NULL			 	  	taxable_base_amount,
            tax_dist.tax_already_distributed_flag	tax_already_distributed_flag,
            tax_dist.summary_tax_line_id 	  	summary_tax_line_id,
	        'N'				      	  	rcv_charge_addition_flag,
            (-1)*tax_dist.prepay_tax_diff_amount  prepay_tax_diff_amount, -- BUG 7338249 bug 9040333 added (-1)* as this is reversal
            tax_dist.pay_awt_group_id     pay_awt_group_id /*BUG 10261626*/
	from	ap_invoice_distributions_all 	tax_dist,
		ap_invoice_distributions_all	item_dist,
		zx_rec_nrec_dist		zx_dist
	where	tax_dist.invoice_id		  = p_invoice_id
	/* -- Bug8575619 start */
	and     tax_dist.invoice_id               = zx_dist.trx_id
	and     zx_dist.application_id   = 200
	and     zx_dist.entity_code        = 'AP_INVOICES'
	and     zx_dist.event_class_code IN ('STANDARD INVOICES',
	                                     'PREPAYMENT INVOICES',
					     'EXPENSE REPORTS')
	/* -- Bug8575619 end */
	and	tax_dist.line_type_lookup_code    IN ('NONREC_TAX', 'REC_TAX', 'TIPV', 'TERV', 'TRV')
	and	tax_dist.detail_tax_dist_id	  = zx_dist.reversed_tax_dist_id
	and	item_dist.invoice_distribution_id(+) = zx_dist.trx_line_dist_id  --bug7394712
	and	zx_dist.reverse_flag 		  = 'Y'
        --and     (p_line_number IS NULL -- bug 6056777
         --       or zx_dist.trx_line_id = p_line_number) --bug605677
	--bugfix:5582836
        and     not exists(select detail_tax_dist_id
			   from ap_invoice_distributions aid
			   where aid.invoice_id = p_invoice_id
			   and aid.detail_tax_dist_id = zx_dist.rec_nrec_tax_dist_id);
Line: 12706

	  select /*+ INDEX (ZX_DIST, ZX_REC_NREC_DIST_N2) */ --8576175
              nvl(item_dist.accounting_date,
	        zx_dist.gl_date)                        accounting_date,  --bug 13101979
            'N'						accrual_posted_flag,
            'U'						assets_addition_flag,
            tax_dist.assets_tracking_flag		assets_tracking_flag, --Bug14772756
            'N'						cash_posted_flag,
            AP_INVOICE_LINES_PKG.get_max_dist_line_num(
		              p_invoice_id,
		              tax_dist.invoice_line_number)+1
							distribution_line_number,
            tax_dist.dist_code_combination_id		dist_code_combination_id,
            tax_dist.invoice_id				invoice_id,
            l_user_id					last_updated_by,
            l_sysdate					last_update_date,
            tax_dist.line_type_lookup_code		line_type_lookup_code,
            ap_utilities_pkg.get_gl_period_name(
                              zx_dist.gl_date,
                              tax_dist.org_id)          period_name,
            tax_dist.set_of_books_id			set_of_books_id,
            (-tax_dist.amount)				amount,
            (-tax_dist.base_amount)			base_amount,
            --P_Invoice_Header_Rec.batch_id		batch_id,
            l_user_id					created_by,
            l_sysdate					creation_date,
            tax_dist.description			description,
            NULL					final_match_flag,
            tax_dist.income_tax_region			income_tax_region,
            l_user_id					last_update_login,
            NULL					match_status_flag,
            'N'						posted_flag,
            tax_dist.po_distribution_id			po_distribution_id,
            NULL					program_application_id,
            NULL					program_id,
            NULL					program_update_date,
            NULL					quantity_invoiced,
            NULL					request_id,
            'Y'						reversal_flag,
            tax_dist.type_1099				type_1099,
            tax_dist.unit_price				unit_price,
            DECODE(tax_dist.encumbered_flag,
		   'R', 'R', 'N')   			encumbered_flag,    --Bug 8733916
            NULL					stat_amount,
            tax_dist.attribute1				attribute1,
            tax_dist.attribute10			attribute10,
            tax_dist.attribute11			attribute11,
            tax_dist.attribute12			attribute12,
            tax_dist.attribute13			attribute13,
            tax_dist.attribute14			attribute14,
            tax_dist.attribute15			attribute15,
            tax_dist.attribute2				attribute2,
            tax_dist.attribute3				attribute3,
            tax_dist.attribute4				attribute4,
            tax_dist.attribute5				attribute5,
            tax_dist.attribute6				attribute6,
            tax_dist.attribute7				attribute7,
            tax_dist.attribute8				attribute8,
            tax_dist.attribute9				attribute9,
            tax_dist.attribute_category			attribute_category,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
		   tax_dist.expenditure_item_date)	expenditure_item_date, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.expenditure_organization_id)  expenditure_organization_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
            	   tax_dist.expenditure_type)		expenditure_type, /* bug 11076722 */
            tax_dist.parent_invoice_id			parent_invoice_id,
            decode(zx_dist.recoverable_flag,
		   'Y', 'E',
		   item_dist.pa_addition_flag)		pa_addition_flag,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.pa_quantity)		pa_quantity, /* bug 11076722 */
            NULL					prepay_amount_remaining,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_accounting_context) project_accounting_context, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_id)		project_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.task_id)			task_id, /* bug 11076722 */
            NULL					packet_id,
            'N'						awt_flag,
            tax_dist.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,
            tax_dist.org_id				org_id,
            NULL					awt_invoice_payment_id,
            tax_dist.global_attribute_category		global_attribute_category,
            tax_dist.global_attribute1			global_attribute1,
            tax_dist.global_attribute2			global_attribute2,
            tax_dist.global_attribute3			global_attribute3,
            tax_dist.global_attribute4			global_attribute4,
            tax_dist.global_attribute5			global_attribute5,
            tax_dist.global_attribute6			global_attribute6,
            tax_dist.global_attribute7			global_attribute7,
            tax_dist.global_attribute8			global_attribute8,
            tax_dist.global_attribute9			global_attribute9,
            tax_dist.global_attribute10			global_attribute10,
            tax_dist.global_attribute11			global_attribute11,
            tax_dist.global_attribute12			global_attribute12,
            tax_dist.global_attribute13			global_attribute13,
            tax_dist.global_attribute14			global_attribute14,
            tax_dist.global_attribute15			global_attribute15,
            tax_dist.global_attribute16			global_attribute16,
            tax_dist.global_attribute17			global_attribute17,
            tax_dist.global_attribute18			global_attribute18,
            tax_dist.global_attribute19			global_attribute19,
            tax_dist.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,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.award_id)          		award_id,
            NULL                        		credit_card_trx_id,
            tax_dist.dist_match_type    		dist_match_type,
            tax_dist.rcv_transaction_id 		rcv_transaction_id,
            ap_invoice_distributions_s.NEXTVAL   	invoice_distribution_id,
            tax_dist.invoice_distribution_id     	parent_reversal_id,
            tax_dist.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,
            tax_dist.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,
	    -- bug9321979
            decode(p_calling_mode,'CANCEL INVOICE',
                   DECODE(tax_dist.prepay_distribution_id,NULL, 'Y',NULL),Null) cancellation_flag,   --Bug8811102
            tax_dist.invoice_line_number	  	invoice_line_number,
            tax_dist.corrected_invoice_dist_id		corrected_invoice_dist_id,
            tax_dist.rounding_amt       	  	rounding_amt,
            decode(NVL(zx_dist.tax_only_line_flag,'N'),'Y',
			        NULL,zx_dist.trx_line_dist_id)		charge_applicable_to_dist_id, --Bug14772756
            NULL					corrected_quantity,
            -- bug 5572121
            -- NULL                                  	related_id,
            DECODE( tax_dist.related_id, NULL, NULL,
                    tax_dist.invoice_distribution_id,
                     ap_invoice_distributions_s.CURRVAL, NULL) related_id,

            NULL                                  	asset_book_type_code,
            NULL                                  	asset_category_id,
            tax_dist.distribution_class 	  	distribution_class,
            tax_dist.tax_code_id        	  	tax_code_id,
            tax_dist.intended_use                 	intended_use,
            zx_dist.rec_nrec_tax_dist_id 	  	detail_tax_dist_id,
            zx_dist.rec_nrec_rate     	  	  	rec_nrec_rate,
            zx_dist.recovery_rate_id  	  	  	recovery_rate_id,
            zx_dist.recovery_type_code	  	  	recovery_type_code,
            NULL                                  	withholding_tax_code_id,
            NULL			     	  	taxable_amount,
            NULL			 	  	taxable_base_amount,
            tax_dist.tax_already_distributed_flag	tax_already_distributed_flag,
            tax_dist.summary_tax_line_id 	  	summary_tax_line_id,
	        'N'				      	  	rcv_charge_addition_flag,
            (-1)*tax_dist.prepay_tax_diff_amount prepay_tax_diff_amount, -- BUG 7338249 bug 9040333 added (-1)* as this is reversal
            tax_dist.pay_awt_group_id     pay_awt_group_id /*BUG 10261626*/
	from	ap_invoice_distributions_all 	tax_dist,
		ap_invoice_distributions_all	item_dist,
		zx_rec_nrec_dist		zx_dist
	where	tax_dist.invoice_id		  = p_invoice_id
	/* -- Bug8575619 start */
	and     tax_dist.invoice_id               = zx_dist.trx_id
	and     zx_dist.application_id   = 200
	and     zx_dist.entity_code        = 'AP_INVOICES'
	and     zx_dist.event_class_code IN ('STANDARD INVOICES',
	                                     'PREPAYMENT INVOICES',
					     'EXPENSE REPORTS')
	/* -- Bug8575619 end */
	and	tax_dist.line_type_lookup_code    IN ('NONREC_TAX', 'REC_TAX', 'TIPV', 'TERV', 'TRV')
	and	tax_dist.detail_tax_dist_id	  = zx_dist.reversed_tax_dist_id
	and	item_dist.invoice_distribution_id(+) = zx_dist.trx_line_dist_id  --bug7394712
	and	zx_dist.reverse_flag 		  = 'Y'
        and   zx_dist.trx_line_id = p_line_number --bug6056777
	--bugfix:5582836
        and     not exists(select detail_tax_dist_id
			   from ap_invoice_distributions aid
			   where aid.invoice_id = p_invoice_id
			   and aid.detail_tax_dist_id = zx_dist.rec_nrec_tax_dist_id);
Line: 12928

	  select
            nvl(item_dist.accounting_date,
	        zx_dist.gl_date)                        accounting_date, --Bug 8350132
            'N'						accrual_posted_flag,
            'U'						assets_addition_flag,
            tax_dist.assets_tracking_flag		assets_tracking_flag, --Bug14772756
            'N'						cash_posted_flag,
            AP_ETAX_UTILITY_PKG.Get_Max_Dist_Num_Self(
		              p_invoice_id,
		              tax_dist.invoice_line_number)+1
							distribution_line_number,
            tax_dist.dist_code_combination_id		dist_code_combination_id,
            tax_dist.invoice_id				invoice_id,
            l_user_id					last_updated_by,
            l_sysdate					last_update_date,
            tax_dist.line_type_lookup_code		line_type_lookup_code,
            tax_dist.period_name			period_name,
            tax_dist.set_of_books_id			set_of_books_id,
            (-tax_dist.amount)				amount,
            (-tax_dist.base_amount)			base_amount,
            --P_Invoice_Header_Rec.batch_id		batch_id,
            l_user_id					created_by,
            l_sysdate					creation_date,
            tax_dist.description			description,
            NULL					final_match_flag,
            tax_dist.income_tax_region			income_tax_region,
            l_user_id					last_update_login,
            NULL					match_status_flag,
            'N'						posted_flag,
            tax_dist.po_distribution_id			po_distribution_id,
            NULL					program_application_id,
            NULL					program_id,
            NULL					program_update_date,
            NULL					quantity_invoiced,
            NULL					request_id,
            'Y'						reversal_flag,
            tax_dist.type_1099				type_1099,
            tax_dist.unit_price				unit_price,
            DECODE(tax_dist.encumbered_flag,
 		   'R', 'R', 'N')   			encumbered_flag,    --Bug 8733916
            NULL					stat_amount,
            tax_dist.attribute1				attribute1,
            tax_dist.attribute10			attribute10,
            tax_dist.attribute11			attribute11,
            tax_dist.attribute12			attribute12,
            tax_dist.attribute13			attribute13,
            tax_dist.attribute14			attribute14,
            tax_dist.attribute15			attribute15,
            tax_dist.attribute2				attribute2,
            tax_dist.attribute3				attribute3,
            tax_dist.attribute4				attribute4,
            tax_dist.attribute5				attribute5,
            tax_dist.attribute6				attribute6,
            tax_dist.attribute7				attribute7,
            tax_dist.attribute8				attribute8,
            tax_dist.attribute9				attribute9,
            tax_dist.attribute_category			attribute_category,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
		   tax_dist.expenditure_item_date)	expenditure_item_date, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.expenditure_organization_id)  expenditure_organization_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
            	   tax_dist.expenditure_type)		expenditure_type, /* bug 11076722 */
            tax_dist.parent_invoice_id			parent_invoice_id,
            decode(zx_dist.recoverable_flag,
		   'Y', 'E',
		   item_dist.pa_addition_flag)		pa_addition_flag,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.pa_quantity)		pa_quantity, /* bug 11076722 */
            NULL					prepay_amount_remaining,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_accounting_context) project_accounting_context, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_id)		project_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.task_id)			task_id, /* bug 11076722 */
            NULL					packet_id,
            'N'						awt_flag,
            tax_dist.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,
            tax_dist.org_id				org_id,
            NULL					awt_invoice_payment_id,
            tax_dist.global_attribute_category		global_attribute_category,
            tax_dist.global_attribute1			global_attribute1,
            tax_dist.global_attribute2			global_attribute2,
            tax_dist.global_attribute3			global_attribute3,
            tax_dist.global_attribute4			global_attribute4,
            tax_dist.global_attribute5			global_attribute5,
            tax_dist.global_attribute6			global_attribute6,
            tax_dist.global_attribute7			global_attribute7,
            tax_dist.global_attribute8			global_attribute8,
            tax_dist.global_attribute9			global_attribute9,
            tax_dist.global_attribute10			global_attribute10,
            tax_dist.global_attribute11			global_attribute11,
            tax_dist.global_attribute12			global_attribute12,
            tax_dist.global_attribute13			global_attribute13,
            tax_dist.global_attribute14			global_attribute14,
            tax_dist.global_attribute15			global_attribute15,
            tax_dist.global_attribute16			global_attribute16,
            tax_dist.global_attribute17			global_attribute17,
            tax_dist.global_attribute18			global_attribute18,
            tax_dist.global_attribute19			global_attribute19,
            tax_dist.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,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.award_id)          		award_id,
            NULL                        		credit_card_trx_id,
            tax_dist.dist_match_type    		dist_match_type,
            tax_dist.rcv_transaction_id 		rcv_transaction_id,
            ap_invoice_distributions_s.NEXTVAL   	invoice_distribution_id,
            tax_dist.invoice_distribution_id     	parent_reversal_id,
            tax_dist.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,
            tax_dist.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,
	    -- bug9321979
            decode(p_calling_mode,'CANCEL INVOICE',
                   DECODE(tax_dist.prepay_distribution_id,NULL,'Y',NULL),Null) cancellation_flag,   --Bug8811102
            tax_dist.invoice_line_number	  	invoice_line_number,
            tax_dist.corrected_invoice_dist_id		corrected_invoice_dist_id,
            tax_dist.rounding_amt       	  	rounding_amt,
            decode(NVL(zx_dist.tax_only_line_flag,'N'),'Y',
			        NULL,zx_dist.trx_line_dist_id)		charge_applicable_to_dist_id, --Bug14772756
            NULL					corrected_quantity,
            -- bug 5572121
            -- NULL                                  	related_id,
            DECODE( tax_dist.related_id, NULL, NULL,
                    tax_dist.invoice_distribution_id,
                     ap_invoice_distributions_s.CURRVAL, NULL) related_id,

            NULL                                  	asset_book_type_code,
            NULL                                  	asset_category_id,
            tax_dist.distribution_class 	  	distribution_class,
            tax_dist.tax_code_id        	  	tax_code_id,
            tax_dist.intended_use                 	intended_use,
            zx_dist.rec_nrec_tax_dist_id 	  	detail_tax_dist_id,
            zx_dist.rec_nrec_rate     	  	  	rec_nrec_rate,
            zx_dist.recovery_rate_id  	  	  	recovery_rate_id,
            zx_dist.recovery_type_code	  	  	recovery_type_code,
            NULL                                  	withholding_tax_code_id,
            NULL			     	  	taxable_amount,
            NULL			 	  	taxable_base_amount,
            tax_dist.tax_already_distributed_flag	tax_already_distributed_flag,
            tax_dist.summary_tax_line_id 	  	summary_tax_line_id,
	        'N'				      	  	rcv_charge_addition_flag,
	        zx_dist.self_assessed_flag                  self_assessed_flag,
            -- bug 6805655
            tax_dist.self_assessed_tax_liab_ccid        self_assessed_tax_liab_ccid,
            (-1)*tax_dist.prepay_tax_diff_amount prepay_tax_diff_amount -- BUG 7338249  bug 9040333 added (-1)* as this is reversal
	from	ap_self_assessed_tax_dist_all 	tax_dist,
		ap_invoice_distributions_all	item_dist,
		zx_rec_nrec_dist		zx_dist
	where	tax_dist.invoice_id		  = p_invoice_id
	/* -- Bug8575619 start */
	and     tax_dist.invoice_id               = zx_dist.trx_id
	and     zx_dist.application_id   = 200
	and     zx_dist.entity_code        = 'AP_INVOICES'
	and     zx_dist.event_class_code IN ('STANDARD INVOICES',
	                                     'PREPAYMENT INVOICES',
					     'EXPENSE REPORTS')
	/* -- Bug8575619 end */
	and	tax_dist.line_type_lookup_code    IN ('NONREC_TAX', 'REC_TAX')
	and	tax_dist.detail_tax_dist_id	  = zx_dist.reversed_tax_dist_id
	and	item_dist.invoice_distribution_id(+) = zx_dist.trx_line_dist_id  --bug7394712
	and	zx_dist.reverse_flag 		  = 'Y'
        --and     (p_line_number IS NULL -- bug 6056777
          --       or zx_dist.trx_line_id = p_line_number) --bug605677
	--bugfix:5582836
    /*  -- bug 6896627
        and     not exists(select detail_tax_dist_id
			   from ap_invoice_distributions aid
			   where aid.invoice_id = p_invoice_id
			   and aid.detail_tax_dist_id = zx_dist.rec_nrec_tax_dist_id)
    */
    AND NOT EXISTS
      (SELECT aid.detail_tax_dist_id
         FROM ap_self_assessed_tax_dist_all aid
        WHERE aid.invoice_id            = p_invoice_id
          AND aid.detail_tax_dist_id    = zx_dist.rec_nrec_tax_dist_id
          AND aid.line_type_lookup_code IN ('REC_TAX','NONREC_TAX'))
    -- bug 6896627
    ;
Line: 13157

	  select
              nvl(item_dist.accounting_date,
	        zx_dist.gl_date)                        accounting_date,  --bug 13101979
            'N'						accrual_posted_flag,
            'U'						assets_addition_flag,
            tax_dist.assets_tracking_flag		assets_tracking_flag, --Bug14772756
            'N'						cash_posted_flag,
            AP_ETAX_UTILITY_PKG.Get_Max_Dist_Num_Self(
		              p_invoice_id,
		              tax_dist.invoice_line_number)+1
							distribution_line_number,
            tax_dist.dist_code_combination_id		dist_code_combination_id,
            tax_dist.invoice_id				invoice_id,
            l_user_id					last_updated_by,
            l_sysdate					last_update_date,
            tax_dist.line_type_lookup_code		line_type_lookup_code,
            tax_dist.period_name			period_name,
            tax_dist.set_of_books_id			set_of_books_id,
            (-tax_dist.amount)				amount,
            (-tax_dist.base_amount)			base_amount,
            --P_Invoice_Header_Rec.batch_id		batch_id,
            l_user_id					created_by,
            l_sysdate					creation_date,
            tax_dist.description			description,
            NULL					final_match_flag,
            tax_dist.income_tax_region			income_tax_region,
            l_user_id					last_update_login,
            NULL					match_status_flag,
            'N'						posted_flag,
            tax_dist.po_distribution_id			po_distribution_id,
            NULL					program_application_id,
            NULL					program_id,
            NULL					program_update_date,
            NULL					quantity_invoiced,
            NULL					request_id,
            'Y'						reversal_flag,
            tax_dist.type_1099				type_1099,
            tax_dist.unit_price				unit_price,
            DECODE(tax_dist.encumbered_flag,
		   'R', 'R', 'N')   			encumbered_flag,    --Bug 8733916
            NULL					stat_amount,
            tax_dist.attribute1				attribute1,
            tax_dist.attribute10			attribute10,
            tax_dist.attribute11			attribute11,
            tax_dist.attribute12			attribute12,
            tax_dist.attribute13			attribute13,
            tax_dist.attribute14			attribute14,
            tax_dist.attribute15			attribute15,
            tax_dist.attribute2				attribute2,
            tax_dist.attribute3				attribute3,
            tax_dist.attribute4				attribute4,
            tax_dist.attribute5				attribute5,
            tax_dist.attribute6				attribute6,
            tax_dist.attribute7				attribute7,
            tax_dist.attribute8				attribute8,
            tax_dist.attribute9				attribute9,
            tax_dist.attribute_category			attribute_category,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
		   tax_dist.expenditure_item_date)	expenditure_item_date, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.expenditure_organization_id)  expenditure_organization_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
            	   tax_dist.expenditure_type)		expenditure_type, /* bug 11076722 */
            tax_dist.parent_invoice_id			parent_invoice_id,
            decode(zx_dist.recoverable_flag,
		   'Y', 'E',
		   item_dist.pa_addition_flag)		pa_addition_flag,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.pa_quantity)		pa_quantity, /* bug 11076722 */
            NULL					prepay_amount_remaining,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_accounting_context) project_accounting_context, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.project_id)		project_id, /* bug 11076722 */
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.task_id)			task_id, /* bug 11076722 */
            NULL					packet_id,
            'N'						awt_flag,
            tax_dist.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,
            tax_dist.org_id				org_id,
            NULL					awt_invoice_payment_id,
            tax_dist.global_attribute_category		global_attribute_category,
            tax_dist.global_attribute1			global_attribute1,
            tax_dist.global_attribute2			global_attribute2,
            tax_dist.global_attribute3			global_attribute3,
            tax_dist.global_attribute4			global_attribute4,
            tax_dist.global_attribute5			global_attribute5,
            tax_dist.global_attribute6			global_attribute6,
            tax_dist.global_attribute7			global_attribute7,
            tax_dist.global_attribute8			global_attribute8,
            tax_dist.global_attribute9			global_attribute9,
            tax_dist.global_attribute10			global_attribute10,
            tax_dist.global_attribute11			global_attribute11,
            tax_dist.global_attribute12			global_attribute12,
            tax_dist.global_attribute13			global_attribute13,
            tax_dist.global_attribute14			global_attribute14,
            tax_dist.global_attribute15			global_attribute15,
            tax_dist.global_attribute16			global_attribute16,
            tax_dist.global_attribute17			global_attribute17,
            tax_dist.global_attribute18			global_attribute18,
            tax_dist.global_attribute19			global_attribute19,
            tax_dist.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,
            decode(zx_dist.recoverable_flag,
                   'Y', NULL,
                   tax_dist.award_id)          		award_id,
            NULL                        		credit_card_trx_id,
            tax_dist.dist_match_type    		dist_match_type,
            tax_dist.rcv_transaction_id 		rcv_transaction_id,
            ap_invoice_distributions_s.NEXTVAL   	invoice_distribution_id,
            tax_dist.invoice_distribution_id     	parent_reversal_id,
            tax_dist.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,
            tax_dist.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,
	    -- bug9321979
            decode(p_calling_mode,'CANCEL INVOICE',
                   DECODE(tax_dist.prepay_distribution_id,NULL,'Y',NULL),Null) cancellation_flag,   --Bug8811102
            tax_dist.invoice_line_number	  	invoice_line_number,
            tax_dist.corrected_invoice_dist_id		corrected_invoice_dist_id,
            tax_dist.rounding_amt       	  	rounding_amt,
            decode(NVL(zx_dist.tax_only_line_flag,'N'),'Y',
			        NULL,zx_dist.trx_line_dist_id)		charge_applicable_to_dist_id, --Bug14772756
            NULL					corrected_quantity,
            -- bug 5572121
            -- NULL                                  	related_id,
            DECODE( tax_dist.related_id, NULL, NULL,
                    tax_dist.invoice_distribution_id,
                     ap_invoice_distributions_s.CURRVAL, NULL) related_id,

            NULL                                  	asset_book_type_code,
            NULL                                  	asset_category_id,
            tax_dist.distribution_class 	  	distribution_class,
            tax_dist.tax_code_id        	  	tax_code_id,
            tax_dist.intended_use                 	intended_use,
            zx_dist.rec_nrec_tax_dist_id 	  	detail_tax_dist_id,
            zx_dist.rec_nrec_rate     	  	  	rec_nrec_rate,
            zx_dist.recovery_rate_id  	  	  	recovery_rate_id,
            zx_dist.recovery_type_code	  	  	recovery_type_code,
            NULL                                  	withholding_tax_code_id,
            NULL			     	  	taxable_amount,
            NULL			 	  	taxable_base_amount,
            tax_dist.tax_already_distributed_flag	tax_already_distributed_flag,
            tax_dist.summary_tax_line_id 	  	summary_tax_line_id,
	        'N'				      	rcv_charge_addition_flag,
            zx_dist.self_assessed_flag                  self_assessed_flag,
            -- bug 6805655
            tax_dist.self_assessed_tax_liab_ccid        self_assessed_tax_liab_ccid,
            (-1)*tax_dist.prepay_tax_diff_amount  prepay_tax_diff_amount-- BUG 7338249  bug 9040333 added (-1)* as this is reversal
	from	ap_self_assessed_tax_dist_all 	tax_dist,
	        ap_invoice_distributions_all	item_dist,
                zx_rec_nrec_dist		zx_dist
	where	tax_dist.invoice_id		  = p_invoice_id
	/* -- Bug8575619 start */
	and     tax_dist.invoice_id               = zx_dist.trx_id
	and     zx_dist.application_id   = 200
	and     zx_dist.entity_code        = 'AP_INVOICES'
	and     zx_dist.event_class_code IN ('STANDARD INVOICES',
	                                     'PREPAYMENT INVOICES',
					     'EXPENSE REPORTS')
	/* -- Bug8575619 end */
	and	tax_dist.line_type_lookup_code    IN ('NONREC_TAX', 'REC_TAX')
	and	tax_dist.detail_tax_dist_id	  = zx_dist.reversed_tax_dist_id
	and	item_dist.invoice_distribution_id(+) = zx_dist.trx_line_dist_id  --bug7394712
	and	zx_dist.reverse_flag 		  = 'Y'
        and   zx_dist.trx_line_id = p_line_number --bug6056777
	--bugfix:5582836
    /*     -- bug 6896627
        and     not exists(select detail_tax_dist_id
			   from ap_invoice_distributions aid
			   where aid.invoice_id = p_invoice_id
			   and aid.detail_tax_dist_id = zx_dist.rec_nrec_tax_dist_id)
     */

    AND NOT EXISTS
      (SELECT aid.detail_tax_dist_id
         FROM ap_self_assessed_tax_dist_all aid
        WHERE aid.invoice_id            = p_invoice_id
          AND aid.detail_tax_dist_id    = zx_dist.rec_nrec_tax_dist_id
          AND aid.line_type_lookup_code IN ('REC_TAX','NONREC_TAX'))
    -- bug 6896627
    ;
Line: 13410

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 13415

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id = P_Invoice_Id
       AND line_type_lookup_code NOT IN ('TAX', 'AWT')
       AND NVL(tax_already_calculated_flag,'N') = 'Y'
       AND NVL(discarded_flag,'N')='N';
Line: 13424

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id  = P_Invoice_Id
       AND line_number = P_Line_Number
       AND line_type_lookup_code NOT IN ('TAX', 'AWT')
       AND NVL(tax_already_calculated_flag,'N') = 'Y';
Line: 13432

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id = P_Invoice_Id
       AND line_type_lookup_code IN ('TAX')
       AND NVL(discarded_flag,'N')='N'
       AND NVL(cancelled_flag,'N')='N';
Line: 13453

 /*Added the following delete statements for bug 12418361 -Begin*/
   l_debug_info := 'Purge staging tables of ZX';
Line: 13460

    DELETE zx_transaction_lines_gt;
Line: 13461

    DELETE zx_import_tax_lines_gt;
Line: 13462

    DELETE zx_trx_tax_link_gt;
Line: 13463

    DELETE zx_reverse_dist_gt;
Line: 13465

    AP_ETAX_SERVICES_PKG.G_SITE_ATTRIBUTES.DELETE;
Line: 13466

    AP_ETAX_SERVICES_PKG.G_ORG_ATTRIBUTES.DELETE;
Line: 13468

   /*Added the following delete statements for bug 12418361 -End*/


--Bug8811102
--==============================================================================
    -----------------------------------------------------------------
	l_debug_info := 'Step 1: Populating invoice header local record';
Line: 13620

   	    UPDATE ap_invoice_distributions_all aid
      	       SET aid.encumbered_flag='R'
    	     WHERE aid.invoice_id=p_invoice_id
     	       AND nvl(aid.encumbered_flag,'N') in ('N','H','P')
	       AND aid.charge_applicable_to_dist_id in (select invoice_distribution_id from ap_invoice_distributions_all aid1
	                                             where aid1.invoice_id=p_invoice_id
				  		       and aid1.invoice_line_number=p_line_number)
               AND aid.line_type_lookup_code in ('REC_TAX','NONREC_TAX','TRV','TERV','TIPV')
	       AND nvl(aid.reversal_flag,'N')<>'Y'
               AND EXISTS (SELECT 1
               		     FROM financials_system_params_all fsp
	                    WHERE fsp.org_id = aid.org_id
		              AND nvl(fsp.purch_encumbrance_flag, 'N') = 'Y');
Line: 13639

   	    UPDATE ap_invoice_distributions_all aid
               SET aid.encumbered_flag='R'
    	     WHERE aid.invoice_id=p_invoice_id
     	       AND nvl(aid.encumbered_flag,'N') in ('N','H','P')
	       AND aid.line_type_lookup_code in ('REC_TAX','NONREC_TAX','TRV','TERV','TIPV')
	       AND nvl(aid.reversal_flag,'N')<>'Y'
	       AND EXISTS (SELECT 1
                             FROM financials_system_params_all fsp
                            WHERE fsp.org_id = aid.org_id
                              AND nvl(fsp.purch_encumbrance_flag, 'N') = 'Y');
Line: 13659

      l_debug_info := 'Step 1: Insert into zx_reverse_dist_gt';
Line: 13665

      INSERT INTO zx_reverse_dist_gt(
        internal_organization_id,
        reversing_appln_id,
        reversing_entity_code,
        reversing_evnt_cls_code,
        reversing_trx_id,
        reversing_trx_level_type,
        reversing_trx_line_id,
        reversing_trx_line_dist_id,
        reversing_tax_line_id,
        reversed_appln_id,
        reversed_entity_code,
        reversed_evnt_cls_code,
        reversed_trx_id,
        reversed_trx_level_type,
        reversed_trx_line_id,
        reversed_trx_line_dist_id,
        reversed_tax_line_id
      )
      select	distinct
		item_dist.org_id                	internal_organization_id,
                zx_dist.application_id          	reversing_appln_id,
                zx_dist.entity_code             	reversing_entity_code,
                zx_dist.event_class_code        	reversing_evnt_cls_code,
                zx_dist.trx_id                  	reversing_trx_id,
                zx_dist.trx_level_type          	reversing_trx_level_type,
                zx_dist.trx_line_id             	reversing_trx_line_id,
                reverse_dist.invoice_distribution_id	reversing_trx_line_dist_id,
                zx_dist.tax_line_id             	reversing_tax_line_id,
                zx_dist.application_id          	reversed_appln_id,
                zx_dist.entity_code             	reversed_entity_code,
                zx_dist.event_class_code        	reversed_evnt_cls_code,
                zx_dist.trx_id                  	reversed_trx_id,
                zx_dist.trx_level_type          	reversed_trx_level_type,
                zx_dist.trx_line_id             	reversed_trx_line_id,
		        zx_dist.trx_line_dist_id        	reversed_trx_line_dist_id,
                zx_dist.tax_line_id             	reversed_tax_line_id
        from    ap_invoice_distributions_all    item_dist,
                ap_invoice_distributions_all    tax_dist,
                ap_invoice_distributions_all    reverse_dist,
                zx_rec_nrec_dist                zx_dist
        where   tax_dist.invoice_id                     = p_invoice_id
        and     tax_dist.invoice_id                     = item_dist.invoice_id
        and     tax_dist.charge_applicable_to_dist_id   = item_dist.invoice_distribution_id
        and  	item_dist.invoice_distribution_id	= reverse_dist.parent_reversal_id
        and     tax_dist.line_type_lookup_code          IN ('NONREC_TAX', 'REC_TAX', 'TIPV', 'TRV', 'TERV')
        and     tax_dist.detail_tax_dist_id             = zx_dist.rec_nrec_tax_dist_id
	and     item_dist.invoice_id                    = reverse_dist.invoice_id  --bug 12920913
        and     nvl(zx_dist.reverse_flag, 'N')          = 'N'
        and     (p_line_number IS NULL
                 or item_dist.invoice_line_number = p_line_number);
Line: 13721

        FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, 'Row Count inserted into zx_reverse_dist_gt: ' || l_reverse_dist_count);
Line: 13728

            SELECT COUNT(1)
              INTO l_unrev_dist_count
	      FROM ap_invoice_distributions_all tax_dist
	     WHERE tax_dist.invoice_id                    = p_invoice_id
               AND tax_dist.line_type_lookup_code        IN ('NONREC_TAX', 'REC_TAX', 'TIPV', 'TRV', 'TERV')
	       AND tax_dist.charge_applicable_to_dist_id IS NOT NULL
	       AND tax_dist.detail_tax_dist_id IS NOT NULL
	       AND tax_dist.parent_reversal_id IS NULL
               AND NOT EXISTS ( SELECT 1
	                          FROM ap_invoice_distributions_all rev_tax_dist
			         WHERE rev_tax_dist.invoice_id         = p_invoice_id
			           AND rev_tax_dist.parent_reversal_id = tax_dist.invoice_distribution_id
			      )
	       AND ROWNUM = 1 ;
Line: 13743

            SELECT COUNT(1)
              INTO l_unrev_dist_count
	      FROM ap_invoice_distributions_all tax_dist
	     WHERE tax_dist.invoice_id                    = p_invoice_id
               AND tax_dist.line_type_lookup_code        IN ('NONREC_TAX', 'REC_TAX', 'TIPV', 'TRV', 'TERV')
	       AND tax_dist.charge_applicable_to_dist_id IS NOT NULL
	       AND tax_dist.detail_tax_dist_id IS NOT NULL
	       AND tax_dist.parent_reversal_id IS NULL
               AND NOT EXISTS ( SELECT 1
	                          FROM ap_invoice_distributions_all rev_tax_dist
			         WHERE rev_tax_dist.invoice_id         = p_invoice_id
			           AND rev_tax_dist.parent_reversal_id = tax_dist.invoice_distribution_id
			      )
               AND tax_dist.charge_applicable_to_dist_id IN
	           ( SELECT item_dist.invoice_distribution_id
		       FROM ap_invoice_distributions_all item_dist
		      WHERE item_dist.invoice_id          = p_invoice_id
			AND item_dist.invoice_line_number = p_line_number
		   )
	       AND ROWNUM = 1 ;
Line: 13783

       l_debug_info := 'Inserting self assessed tax entries into zx_reverse_dist_gt';
Line: 13793

       INSERT INTO zx_reverse_dist_gt(
        internal_organization_id,
        reversing_appln_id,
        reversing_entity_code,
        reversing_evnt_cls_code,
        reversing_trx_id,
        reversing_trx_level_type,
        reversing_trx_line_id,
        reversing_trx_line_dist_id,
        reversing_tax_line_id,
        reversed_appln_id,
        reversed_entity_code,
        reversed_evnt_cls_code,
        reversed_trx_id,
        reversed_trx_level_type,
        reversed_trx_line_id,
        reversed_trx_line_dist_id,
        reversed_tax_line_id
      )
      select	distinct
		item_dist.org_id                	internal_organization_id,
                zx_dist.application_id          	reversing_appln_id,
                zx_dist.entity_code             	reversing_entity_code,
                zx_dist.event_class_code        	reversing_evnt_cls_code,
                zx_dist.trx_id                  	reversing_trx_id,
                zx_dist.trx_level_type          	reversing_trx_level_type,
                zx_dist.trx_line_id             	reversing_trx_line_id,
                reverse_dist.invoice_distribution_id	reversing_trx_line_dist_id,
                zx_dist.tax_line_id             	reversing_tax_line_id,
                zx_dist.application_id          	reversed_appln_id,
                zx_dist.entity_code             	reversed_entity_code,
                zx_dist.event_class_code        	reversed_evnt_cls_code,
                zx_dist.trx_id                  	reversed_trx_id,
                zx_dist.trx_level_type          	reversed_trx_level_type,
                zx_dist.trx_line_id             	reversed_trx_line_id,
		zx_dist.trx_line_dist_id        	reversed_trx_line_dist_id,
                zx_dist.tax_line_id             	reversed_tax_line_id
        from    ap_invoice_distributions_all    item_dist,
                ap_self_assessed_tax_dist_all    tax_dist,
                ap_invoice_distributions_all    reverse_dist,
                zx_rec_nrec_dist                zx_dist
        where   tax_dist.invoice_id                     = p_invoice_id
        and     tax_dist.invoice_id                     = item_dist.invoice_id
        and     tax_dist.charge_applicable_to_dist_id   = item_dist.invoice_distribution_id
        and	item_dist.invoice_distribution_id	= reverse_dist.parent_reversal_id
        and     tax_dist.line_type_lookup_code          IN ('NONREC_TAX', 'REC_TAX')
        and     tax_dist.detail_tax_dist_id             = zx_dist.rec_nrec_tax_dist_id
        and     nvl(zx_dist.reverse_flag, 'N')          = 'N'
        and     (p_line_number IS NULL
                 or item_dist.invoice_line_number = p_line_number);
Line: 13849

        FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, 'Row Count inserted into zx_reverse_dist_gt: ' || SQL%ROWCOUNT);
Line: 13856

            SELECT COUNT(1)
              INTO l_unrev_sa_dist_count
	      FROM ap_self_assessed_tax_dist_all tax_dist
	     WHERE tax_dist.invoice_id                    = p_invoice_id
               AND tax_dist.line_type_lookup_code        IN ('NONREC_TAX', 'REC_TAX' )
	       AND tax_dist.charge_applicable_to_dist_id IS NOT NULL
	       AND tax_dist.detail_tax_dist_id IS NOT NULL
	       AND tax_dist.parent_reversal_id IS NULL
               AND NOT EXISTS ( SELECT 1
	                          FROM ap_self_assessed_tax_dist_all rev_tax_dist
			         WHERE rev_tax_dist.invoice_id         = p_invoice_id
			           AND rev_tax_dist.parent_reversal_id = tax_dist.invoice_distribution_id
			      )
	       AND ROWNUM = 1 ;
Line: 13871

            SELECT COUNT(1)
              INTO l_unrev_sa_dist_count
	      FROM ap_self_assessed_tax_dist_all tax_dist
	     WHERE tax_dist.invoice_id                    = p_invoice_id
               AND tax_dist.line_type_lookup_code        IN ('NONREC_TAX', 'REC_TAX' )
	       AND tax_dist.charge_applicable_to_dist_id IS NOT NULL
	       AND tax_dist.detail_tax_dist_id IS NOT NULL
	       AND tax_dist.parent_reversal_id IS NULL
               AND NOT EXISTS ( SELECT 1
	                          FROM ap_self_assessed_tax_dist_all rev_tax_dist
			         WHERE rev_tax_dist.invoice_id         = p_invoice_id
			           AND rev_tax_dist.parent_reversal_id = tax_dist.invoice_distribution_id
			      )
               AND tax_dist.charge_applicable_to_dist_id IN
	           ( SELECT item_dist.invoice_distribution_id
		       FROM ap_invoice_distributions_all item_dist
		      WHERE item_dist.invoice_id          = p_invoice_id
			AND item_dist.invoice_line_number = p_line_number
		   )
	      AND ROWNUM = 1 ;
Line: 14034

       DELETE zx_transaction_lines_gt;
Line: 14035

       DELETE zx_import_tax_lines_gt;
Line: 14036

       DELETE zx_trx_tax_link_gt;
Line: 14037

       DELETE zx_reverse_dist_gt;
Line: 14039

    ELSE -- update the tax only line amount to 0
       -----------------------------------------------------------------
       l_debug_info := 'Update the tax line amount to 0';
Line: 14048

           UPDATE ap_invoice_lines_all a
              SET (amount,
                   base_amount,
                   cancelled_flag) =
                 (select  NVL(b.tax_amt,0),
                          NVL(b.tax_amt_funcl_curr,0),
                          b.cancel_flag
                    from zx_lines_summary b
                   where b.application_id 	 =  200
                     and b.entity_code 	     =  'AP_INVOICES'
                     and b.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                     and b.summary_tax_line_id = a.summary_tax_line_id
                     and b.trx_id            = p_invoice_id)
            WHERE a.invoice_id            =  p_invoice_id
              AND a.line_type_lookup_code = 'TAX'
              AND exists
                  (select 'Detail Line'
		             from zx_lines zx
		            where zx.application_id 	 =  200
                      and zx.entity_code 	     =  'AP_INVOICES'
		              and zx.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                      and zx.summary_tax_line_id = a.summary_tax_line_id
		              and zx.trx_id              = p_invoice_id);
Line: 14073

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

             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_Id
                AND ail.line_type_lookup_code NOT IN ('TAX', 'AWT');
Line: 14111

           UPDATE ap_invoice_lines_all a
              SET amount = 0,
                  base_amount=0,
                  cancelled_flag='Y'
            WHERE a.invoice_id            = p_invoice_id
              AND a.line_type_lookup_code = 'TAX'
              AND a.summary_tax_line_id IS NULL;
Line: 14128

             UPDATE ap_invoice_lines_all a
                SET (amount,base_amount) =
                    (select nvl(b.tax_amt,0),nvl(b.tax_amt_funcl_curr,0)
                       from zx_lines_summary b
                      where b.application_id 	    =  200
                        and b.entity_code 	    =  'AP_INVOICES'
		                and b.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                        and b.trx_id              = a.invoice_id
                        and b.summary_tax_line_id = a.summary_tax_line_id)
              WHERE a.invoice_id            = p_invoice_id
                AND a.line_type_lookup_code = 'TAX'
                AND exists
		            (select 'Detail Line'
		               from zx_lines zx
		              where zx.application_id 	   =  200
                        and zx.entity_code 	       =  'AP_INVOICES'
		                and zx.event_class_code IN ('STANDARD INVOICES', 'PREPAYMENT INVOICES', 'EXPENSE REPORTS')
                        and zx.summary_tax_line_id = a.summary_tax_line_id
		                and zx.trx_id              = p_invoice_id
		                and zx.trx_line_id         = p_line_number);
Line: 14157

       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 application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
                  AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
                  AND 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 zls.trx_id       = ai.invoice_id
                  AND NVL(zls.reporting_only_flag, 'N') = 'N')
        WHERE ai.invoice_id = p_invoice_id;
Line: 14183

       delete zx_tax_dist_id_gt;  --Bug 8350132
Line: 14188

       l_debug_info := 'Step 3: Insert reverse tax distributions into ap_invoice_distributions';
Line: 14209

			 select accounting_date,
			        period_name
			  into l_open_gl_date,
			       l_open_gl_period
			from ap_invoice_distributions_All aid
			    where rowid =
					 (select max(rowid)
					  from ap_invoice_distributions_All aid1
					  where aid1.invoice_id=l_reverse_tax_dist.invoice_id
					  and aid1.cancellation_flag = 'Y'
					  and aid1.detail_tax_dist_id is null
					  and aid1.prepay_distribution_id is null);
Line: 14243

	   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_type_code,
            withholding_tax_code_id,
            taxable_amount,
            taxable_base_amount,
            tax_already_distributed_flag,
            summary_tax_line_id,
	        rcv_charge_addition_flag,
            prepay_tax_diff_amount, -- BUG 7338249
            pay_awt_group_id) /*BUG 10261626*/
	VALUES
	(
	nvl(l_open_gl_date, l_reverse_tax_dist.accounting_date),  --bug 13101979
	l_reverse_tax_dist.accrual_posted_flag,
	l_reverse_tax_dist.assets_addition_flag,
	l_reverse_tax_dist.assets_tracking_flag,
	l_reverse_tax_dist.cash_posted_flag,
	l_reverse_tax_dist.distribution_line_number,
	l_reverse_tax_dist.dist_code_combination_id,
	l_reverse_tax_dist.invoice_id,
	l_reverse_tax_dist.last_updated_by,
	l_reverse_tax_dist.last_update_date,
	l_reverse_tax_dist.line_type_lookup_code,
	nvl(l_open_gl_period , l_reverse_tax_dist.period_name),  --bug 13101979
	l_reverse_tax_dist.set_of_books_id,
	l_reverse_tax_dist.amount,
	l_reverse_tax_dist.base_amount,
	--l_reverse_tax_dist.batch_id,
	l_reverse_tax_dist.created_by,
	l_reverse_tax_dist.creation_date,
	l_reverse_tax_dist.description,
	l_reverse_tax_dist.final_match_flag,
	l_reverse_tax_dist.income_tax_region,
	l_reverse_tax_dist.last_update_login,
	l_reverse_tax_dist.match_status_flag,
	l_reverse_tax_dist.posted_flag,
	l_reverse_tax_dist.po_distribution_id,
	l_reverse_tax_dist.program_application_id,
	l_reverse_tax_dist.program_id,
	l_reverse_tax_dist.program_update_date,
	l_reverse_tax_dist.quantity_invoiced,
	l_reverse_tax_dist.request_id,
	l_reverse_tax_dist.reversal_flag,
	l_reverse_tax_dist.type_1099,
	l_reverse_tax_dist.unit_price,
	l_reverse_tax_dist.encumbered_flag,
	l_reverse_tax_dist.stat_amount,
	l_reverse_tax_dist.attribute1,
	l_reverse_tax_dist.attribute10,
	l_reverse_tax_dist.attribute11,
	l_reverse_tax_dist.attribute12,
	l_reverse_tax_dist.attribute13,
	l_reverse_tax_dist.attribute14,
	l_reverse_tax_dist.attribute15,
	l_reverse_tax_dist.attribute2,
	l_reverse_tax_dist.attribute3,
	l_reverse_tax_dist.attribute4,
	l_reverse_tax_dist.attribute5,
	l_reverse_tax_dist.attribute6,
	l_reverse_tax_dist.attribute7,
	l_reverse_tax_dist.attribute8,
	l_reverse_tax_dist.attribute9,
	l_reverse_tax_dist.attribute_category,
	l_reverse_tax_dist.expenditure_item_date,
	l_reverse_tax_dist.expenditure_organization_id,
	l_reverse_tax_dist.expenditure_type,
	l_reverse_tax_dist.parent_invoice_id,
	l_reverse_tax_dist.pa_addition_flag,
	l_reverse_tax_dist.pa_quantity,
	l_reverse_tax_dist.prepay_amount_remaining,
	l_reverse_tax_dist.project_accounting_context,
	l_reverse_tax_dist.project_id,
	l_reverse_tax_dist.task_id,
	l_reverse_tax_dist.packet_id,
	l_reverse_tax_dist.awt_flag,
	l_reverse_tax_dist.awt_group_id,
	l_reverse_tax_dist.awt_tax_rate_id,
	l_reverse_tax_dist.awt_gross_amount,
	l_reverse_tax_dist.awt_invoice_id,
	l_reverse_tax_dist.awt_origin_group_id,
	l_reverse_tax_dist.reference_1,
	l_reverse_tax_dist.reference_2,
	l_reverse_tax_dist.org_id,
	l_reverse_tax_dist.awt_invoice_payment_id,
	l_reverse_tax_dist.global_attribute_category,
	l_reverse_tax_dist.global_attribute1,
	l_reverse_tax_dist.global_attribute2,
	l_reverse_tax_dist.global_attribute3,
	l_reverse_tax_dist.global_attribute4,
	l_reverse_tax_dist.global_attribute5,
	l_reverse_tax_dist.global_attribute6,
	l_reverse_tax_dist.global_attribute7,
	l_reverse_tax_dist.global_attribute8,
	l_reverse_tax_dist.global_attribute9,
	l_reverse_tax_dist.global_attribute10,
	l_reverse_tax_dist.global_attribute11,
	l_reverse_tax_dist.global_attribute12,
	l_reverse_tax_dist.global_attribute13,
	l_reverse_tax_dist.global_attribute14,
	l_reverse_tax_dist.global_attribute15,
	l_reverse_tax_dist.global_attribute16,
	l_reverse_tax_dist.global_attribute17,
	l_reverse_tax_dist.global_attribute18,
	l_reverse_tax_dist.global_attribute19,
	l_reverse_tax_dist.global_attribute20,
	l_reverse_tax_dist.receipt_verified_flag,
	l_reverse_tax_dist.receipt_required_flag,
	l_reverse_tax_dist.receipt_missing_flag,
	l_reverse_tax_dist.justification,
	l_reverse_tax_dist.expense_group,
	l_reverse_tax_dist.start_expense_date,
	l_reverse_tax_dist.end_expense_date,
	l_reverse_tax_dist.receipt_currency_code,
	l_reverse_tax_dist.receipt_conversion_rate,
	l_reverse_tax_dist.receipt_currency_amount,
	l_reverse_tax_dist.daily_amount,
	l_reverse_tax_dist.web_parameter_id,
	l_reverse_tax_dist.adjustment_reason,
	l_reverse_tax_dist.award_id,
	l_reverse_tax_dist.credit_card_trx_id,
	l_reverse_tax_dist.dist_match_type,
	l_reverse_tax_dist.rcv_transaction_id,
	l_reverse_tax_dist.invoice_distribution_id,
	l_reverse_tax_dist.parent_reversal_id,
	l_reverse_tax_dist.tax_recoverable_flag,
	l_reverse_tax_dist.merchant_document_number,
	l_reverse_tax_dist.merchant_name,
	l_reverse_tax_dist.merchant_reference,
	l_reverse_tax_dist.merchant_tax_reg_number,
	l_reverse_tax_dist.merchant_taxpayer_id,
	l_reverse_tax_dist.country_of_supply,
	l_reverse_tax_dist.matched_uom_lookup_code,
	l_reverse_tax_dist.gms_burdenable_raw_cost,
	l_reverse_tax_dist.accounting_event_id,
	l_reverse_tax_dist.prepay_distribution_id,
	l_reverse_tax_dist.upgrade_posted_amt,
	l_reverse_tax_dist.upgrade_base_posted_amt,
	l_reverse_tax_dist.inventory_transfer_status,
	l_reverse_tax_dist.company_prepaid_invoice_id,
	l_reverse_tax_dist.cc_reversal_flag,
	l_reverse_tax_dist.awt_withheld_amt,
	l_reverse_tax_dist.pa_cmt_xface_flag,
	l_reverse_tax_dist.cancellation_flag,
	l_reverse_tax_dist.invoice_line_number,
	l_reverse_tax_dist.corrected_invoice_dist_id,
	l_reverse_tax_dist.rounding_amt,
	l_reverse_tax_dist.charge_applicable_to_dist_id,
	l_reverse_tax_dist.corrected_quantity,
	l_reverse_tax_dist.related_id,
	l_reverse_tax_dist.asset_book_type_code,
	l_reverse_tax_dist.asset_category_id,
	l_reverse_tax_dist.distribution_class,
	l_reverse_tax_dist.tax_code_id,
	l_reverse_tax_dist.intended_use,
	l_reverse_tax_dist.detail_tax_dist_id,
	l_reverse_tax_dist.rec_nrec_rate,
	l_reverse_tax_dist.recovery_rate_id,
	l_reverse_tax_dist.recovery_type_code,
	l_reverse_tax_dist.withholding_tax_code_id,
	l_reverse_tax_dist.taxable_amount,
	l_reverse_tax_dist.taxable_base_amount,
	l_reverse_tax_dist.tax_already_distributed_flag,
	l_reverse_tax_dist.summary_tax_line_id,
	l_reverse_tax_dist.rcv_charge_addition_flag,
	l_reverse_tax_dist.prepay_tax_diff_amount, -- BUG 7338249
    l_reverse_tax_dist.pay_awt_group_id); /*BUG 10261626*/
Line: 14557

	INSERT into ZX_TAX_DIST_ID_GT (TAX_DIST_ID) values (l_reverse_tax_dist.detail_tax_dist_id) ;
Line: 14587

        l_debug_info := 'Step 3: Insert reverse self assessed tax distributions into ap_invoice_distributions';
Line: 14609

			 select accounting_date,
			        period_name
			  into l_open_gl_date,
			       l_open_gl_period
			from ap_invoice_distributions_All aid
			    where rowid =
					 (select max(rowid)
					  from ap_invoice_distributions_All aid1
					  where aid1.invoice_id=l_self_assess_rev_tax_dist.invoice_id
					  and aid1.cancellation_flag = 'Y'
					  and aid1.detail_tax_dist_id is null
					  and aid1.prepay_distribution_id is null);
Line: 14643

	   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_type_code,
                withholding_tax_code_id,
                taxable_amount,
                taxable_base_amount,
                tax_already_distributed_flag,
                summary_tax_line_id,
		        rcv_charge_addition_flag,
                self_assessed_flag,
                self_assessed_tax_liab_ccid, --bug6805655
                prepay_tax_diff_amount -- BUG 7338249
                )
		VALUES
		(
		nvl(l_open_gl_date,l_self_assess_rev_tax_dist.accounting_date), --bug 13101979
		l_self_assess_rev_tax_dist.accrual_posted_flag,
		l_self_assess_rev_tax_dist.assets_addition_flag,
		l_self_assess_rev_tax_dist.assets_tracking_flag,
		l_self_assess_rev_tax_dist.cash_posted_flag,
		l_self_assess_rev_tax_dist.distribution_line_number,
		l_self_assess_rev_tax_dist.dist_code_combination_id,
		l_self_assess_rev_tax_dist.invoice_id,
		l_self_assess_rev_tax_dist.last_updated_by,
		l_self_assess_rev_tax_dist.last_update_date,
		l_self_assess_rev_tax_dist.line_type_lookup_code,
		nvl(l_open_gl_period,l_self_assess_rev_tax_dist.period_name), --bug 13101979
		l_self_assess_rev_tax_dist.set_of_books_id,
		l_self_assess_rev_tax_dist.amount,
		l_self_assess_rev_tax_dist.base_amount,
		--l_self_assess_rev_tax_dist.batch_id,
		l_self_assess_rev_tax_dist.created_by,
		l_self_assess_rev_tax_dist.creation_date,
		l_self_assess_rev_tax_dist.description,
		l_self_assess_rev_tax_dist.final_match_flag,
		l_self_assess_rev_tax_dist.income_tax_region,
		l_self_assess_rev_tax_dist.last_update_login,
		l_self_assess_rev_tax_dist.match_status_flag,
		l_self_assess_rev_tax_dist.posted_flag,
		l_self_assess_rev_tax_dist.po_distribution_id,
		l_self_assess_rev_tax_dist.program_application_id,
		l_self_assess_rev_tax_dist.program_id,
		l_self_assess_rev_tax_dist.program_update_date,
		l_self_assess_rev_tax_dist.quantity_invoiced,
		l_self_assess_rev_tax_dist.request_id,
		l_self_assess_rev_tax_dist.reversal_flag,
		l_self_assess_rev_tax_dist.type_1099,
		l_self_assess_rev_tax_dist.unit_price,
		l_self_assess_rev_tax_dist.encumbered_flag,
		l_self_assess_rev_tax_dist.stat_amount,
		l_self_assess_rev_tax_dist.attribute1,
		l_self_assess_rev_tax_dist.attribute10,
		l_self_assess_rev_tax_dist.attribute11,
		l_self_assess_rev_tax_dist.attribute12,
		l_self_assess_rev_tax_dist.attribute13,
		l_self_assess_rev_tax_dist.attribute14,
		l_self_assess_rev_tax_dist.attribute15,
		l_self_assess_rev_tax_dist.attribute2,
		l_self_assess_rev_tax_dist.attribute3,
		l_self_assess_rev_tax_dist.attribute4,
		l_self_assess_rev_tax_dist.attribute5,
		l_self_assess_rev_tax_dist.attribute6,
		l_self_assess_rev_tax_dist.attribute7,
		l_self_assess_rev_tax_dist.attribute8,
		l_self_assess_rev_tax_dist.attribute9,
		l_self_assess_rev_tax_dist.attribute_category,
		l_self_assess_rev_tax_dist.expenditure_item_date,
		l_self_assess_rev_tax_dist.expenditure_organization_id,
		l_self_assess_rev_tax_dist.expenditure_type,
		l_self_assess_rev_tax_dist.parent_invoice_id,
		l_self_assess_rev_tax_dist.pa_addition_flag,
		l_self_assess_rev_tax_dist.pa_quantity,
		l_self_assess_rev_tax_dist.prepay_amount_remaining,
		l_self_assess_rev_tax_dist.project_accounting_context,
		l_self_assess_rev_tax_dist.project_id,
		l_self_assess_rev_tax_dist.task_id,
		l_self_assess_rev_tax_dist.packet_id,
		l_self_assess_rev_tax_dist.awt_flag,
		l_self_assess_rev_tax_dist.awt_group_id,
		l_self_assess_rev_tax_dist.awt_tax_rate_id,
		l_self_assess_rev_tax_dist.awt_gross_amount,
		l_self_assess_rev_tax_dist.awt_invoice_id,
		l_self_assess_rev_tax_dist.awt_origin_group_id,
		l_self_assess_rev_tax_dist.reference_1,
		l_self_assess_rev_tax_dist.reference_2,
		l_self_assess_rev_tax_dist.org_id,
		l_self_assess_rev_tax_dist.awt_invoice_payment_id,
		l_self_assess_rev_tax_dist.global_attribute_category,
		l_self_assess_rev_tax_dist.global_attribute1,
		l_self_assess_rev_tax_dist.global_attribute2,
		l_self_assess_rev_tax_dist.global_attribute3,
		l_self_assess_rev_tax_dist.global_attribute4,
		l_self_assess_rev_tax_dist.global_attribute5,
		l_self_assess_rev_tax_dist.global_attribute6,
		l_self_assess_rev_tax_dist.global_attribute7,
		l_self_assess_rev_tax_dist.global_attribute8,
		l_self_assess_rev_tax_dist.global_attribute9,
		l_self_assess_rev_tax_dist.global_attribute10,
		l_self_assess_rev_tax_dist.global_attribute11,
		l_self_assess_rev_tax_dist.global_attribute12,
		l_self_assess_rev_tax_dist.global_attribute13,
		l_self_assess_rev_tax_dist.global_attribute14,
		l_self_assess_rev_tax_dist.global_attribute15,
		l_self_assess_rev_tax_dist.global_attribute16,
		l_self_assess_rev_tax_dist.global_attribute17,
		l_self_assess_rev_tax_dist.global_attribute18,
		l_self_assess_rev_tax_dist.global_attribute19,
		l_self_assess_rev_tax_dist.global_attribute20,
		l_self_assess_rev_tax_dist.receipt_verified_flag,
		l_self_assess_rev_tax_dist.receipt_required_flag,
		l_self_assess_rev_tax_dist.receipt_missing_flag,
		l_self_assess_rev_tax_dist.justification,
		l_self_assess_rev_tax_dist.expense_group,
		l_self_assess_rev_tax_dist.start_expense_date,
		l_self_assess_rev_tax_dist.end_expense_date,
		l_self_assess_rev_tax_dist.receipt_currency_code,
		l_self_assess_rev_tax_dist.receipt_conversion_rate,
		l_self_assess_rev_tax_dist.receipt_currency_amount,
		l_self_assess_rev_tax_dist.daily_amount,
		l_self_assess_rev_tax_dist.web_parameter_id,
		l_self_assess_rev_tax_dist.adjustment_reason,
		l_self_assess_rev_tax_dist.award_id,
		l_self_assess_rev_tax_dist.credit_card_trx_id,
		l_self_assess_rev_tax_dist.dist_match_type,
		l_self_assess_rev_tax_dist.rcv_transaction_id,
		l_self_assess_rev_tax_dist.invoice_distribution_id,
		l_self_assess_rev_tax_dist.parent_reversal_id,
		l_self_assess_rev_tax_dist.tax_recoverable_flag,
		l_self_assess_rev_tax_dist.merchant_document_number,
		l_self_assess_rev_tax_dist.merchant_name,
		l_self_assess_rev_tax_dist.merchant_reference,
		l_self_assess_rev_tax_dist.merchant_tax_reg_number,
		l_self_assess_rev_tax_dist.merchant_taxpayer_id,
		l_self_assess_rev_tax_dist.country_of_supply,
		l_self_assess_rev_tax_dist.matched_uom_lookup_code,
		l_self_assess_rev_tax_dist.gms_burdenable_raw_cost,
		l_self_assess_rev_tax_dist.accounting_event_id,
		l_self_assess_rev_tax_dist.prepay_distribution_id,
		l_self_assess_rev_tax_dist.upgrade_posted_amt,
		l_self_assess_rev_tax_dist.upgrade_base_posted_amt,
		l_self_assess_rev_tax_dist.inventory_transfer_status,
		l_self_assess_rev_tax_dist.company_prepaid_invoice_id,
		l_self_assess_rev_tax_dist.cc_reversal_flag,
		l_self_assess_rev_tax_dist.awt_withheld_amt,
		l_self_assess_rev_tax_dist.pa_cmt_xface_flag,
		l_self_assess_rev_tax_dist.cancellation_flag,
		l_self_assess_rev_tax_dist.invoice_line_number,
		l_self_assess_rev_tax_dist.corrected_invoice_dist_id,
		l_self_assess_rev_tax_dist.rounding_amt,
		l_self_assess_rev_tax_dist.charge_applicable_to_dist_id,
		l_self_assess_rev_tax_dist.corrected_quantity,
		l_self_assess_rev_tax_dist.related_id,
		l_self_assess_rev_tax_dist.asset_book_type_code,
		l_self_assess_rev_tax_dist.asset_category_id,
		l_self_assess_rev_tax_dist.distribution_class,
		l_self_assess_rev_tax_dist.tax_code_id,
		l_self_assess_rev_tax_dist.intended_use,
		l_self_assess_rev_tax_dist.detail_tax_dist_id,
		l_self_assess_rev_tax_dist.rec_nrec_rate,
		l_self_assess_rev_tax_dist.recovery_rate_id,
		l_self_assess_rev_tax_dist.recovery_type_code,
		l_self_assess_rev_tax_dist.withholding_tax_code_id,
		l_self_assess_rev_tax_dist.taxable_amount,
		l_self_assess_rev_tax_dist.taxable_base_amount,
		l_self_assess_rev_tax_dist.tax_already_distributed_flag,
		l_self_assess_rev_tax_dist.summary_tax_line_id,
		l_self_assess_rev_tax_dist.rcv_charge_addition_flag,
		l_self_assess_rev_tax_dist.self_assessed_flag,
		l_self_assess_rev_tax_dist.self_assessed_tax_liab_ccid,  --bug6805655
        l_self_assess_rev_tax_dist.prepay_tax_diff_amount -- BUG 7338249
               );
Line: 14961

	INSERT into ZX_TAX_DIST_ID_GT (TAX_DIST_ID) values (l_self_assess_rev_tax_dist.detail_tax_dist_id) ;
Line: 14989

       /* ZX_API_PUB.Update_Tax_dist_gl_date (
				1.0,
				FND_API.G_TRUE,
				FND_API.G_FALSE,
				FND_API.G_VALID_LEVEL_FULL,
				l_return_status_service,
				l_msg_count,
				l_msg_data,
				l_inv_cancel_date );
Line: 15029

         l_debug_info := 'Inserting reverse entries into ap_invoice_distributions_all after line discard';
Line: 15040

	     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_type_code,
            withholding_tax_code_id,
            taxable_amount,
            taxable_base_amount,
            tax_already_distributed_flag,
            summary_tax_line_id,
	        rcv_charge_addition_flag,
            prepay_tax_diff_amount, -- BUG 7338249
            pay_awt_group_id) /*BUG 10261626*/
	VALUES
	(
	l_reverse_tax_dist.accounting_date,
	l_reverse_tax_dist.accrual_posted_flag,
	l_reverse_tax_dist.assets_addition_flag,
	l_reverse_tax_dist.assets_tracking_flag,
	l_reverse_tax_dist.cash_posted_flag,
	l_reverse_tax_dist.distribution_line_number,
	l_reverse_tax_dist.dist_code_combination_id,
	l_reverse_tax_dist.invoice_id,
	l_reverse_tax_dist.last_updated_by,
	l_reverse_tax_dist.last_update_date,
	l_reverse_tax_dist.line_type_lookup_code,
	l_reverse_tax_dist.period_name,
	l_reverse_tax_dist.set_of_books_id,
	l_reverse_tax_dist.amount,
	l_reverse_tax_dist.base_amount,
	--l_reverse_tax_dist.batch_id,
	l_reverse_tax_dist.created_by,
	l_reverse_tax_dist.creation_date,
	l_reverse_tax_dist.description,
	l_reverse_tax_dist.final_match_flag,
	l_reverse_tax_dist.income_tax_region,
	l_reverse_tax_dist.last_update_login,
	l_reverse_tax_dist.match_status_flag,
	l_reverse_tax_dist.posted_flag,
	l_reverse_tax_dist.po_distribution_id,
	l_reverse_tax_dist.program_application_id,
	l_reverse_tax_dist.program_id,
	l_reverse_tax_dist.program_update_date,
	l_reverse_tax_dist.quantity_invoiced,
	l_reverse_tax_dist.request_id,
	l_reverse_tax_dist.reversal_flag,
	l_reverse_tax_dist.type_1099,
	l_reverse_tax_dist.unit_price,
	l_reverse_tax_dist.encumbered_flag,
	l_reverse_tax_dist.stat_amount,
	l_reverse_tax_dist.attribute1,
	l_reverse_tax_dist.attribute10,
	l_reverse_tax_dist.attribute11,
	l_reverse_tax_dist.attribute12,
	l_reverse_tax_dist.attribute13,
	l_reverse_tax_dist.attribute14,
	l_reverse_tax_dist.attribute15,
	l_reverse_tax_dist.attribute2,
	l_reverse_tax_dist.attribute3,
	l_reverse_tax_dist.attribute4,
	l_reverse_tax_dist.attribute5,
	l_reverse_tax_dist.attribute6,
	l_reverse_tax_dist.attribute7,
	l_reverse_tax_dist.attribute8,
	l_reverse_tax_dist.attribute9,
	l_reverse_tax_dist.attribute_category,
	l_reverse_tax_dist.expenditure_item_date,
	l_reverse_tax_dist.expenditure_organization_id,
	l_reverse_tax_dist.expenditure_type,
	l_reverse_tax_dist.parent_invoice_id,
	l_reverse_tax_dist.pa_addition_flag,
	l_reverse_tax_dist.pa_quantity,
	l_reverse_tax_dist.prepay_amount_remaining,
	l_reverse_tax_dist.project_accounting_context,
	l_reverse_tax_dist.project_id,
	l_reverse_tax_dist.task_id,
	l_reverse_tax_dist.packet_id,
	l_reverse_tax_dist.awt_flag,
	l_reverse_tax_dist.awt_group_id,
	l_reverse_tax_dist.awt_tax_rate_id,
	l_reverse_tax_dist.awt_gross_amount,
	l_reverse_tax_dist.awt_invoice_id,
	l_reverse_tax_dist.awt_origin_group_id,
	l_reverse_tax_dist.reference_1,
	l_reverse_tax_dist.reference_2,
	l_reverse_tax_dist.org_id,
	l_reverse_tax_dist.awt_invoice_payment_id,
	l_reverse_tax_dist.global_attribute_category,
	l_reverse_tax_dist.global_attribute1,
	l_reverse_tax_dist.global_attribute2,
	l_reverse_tax_dist.global_attribute3,
	l_reverse_tax_dist.global_attribute4,
	l_reverse_tax_dist.global_attribute5,
	l_reverse_tax_dist.global_attribute6,
	l_reverse_tax_dist.global_attribute7,
	l_reverse_tax_dist.global_attribute8,
	l_reverse_tax_dist.global_attribute9,
	l_reverse_tax_dist.global_attribute10,
	l_reverse_tax_dist.global_attribute11,
	l_reverse_tax_dist.global_attribute12,
	l_reverse_tax_dist.global_attribute13,
	l_reverse_tax_dist.global_attribute14,
	l_reverse_tax_dist.global_attribute15,
	l_reverse_tax_dist.global_attribute16,
	l_reverse_tax_dist.global_attribute17,
	l_reverse_tax_dist.global_attribute18,
	l_reverse_tax_dist.global_attribute19,
	l_reverse_tax_dist.global_attribute20,
	l_reverse_tax_dist.receipt_verified_flag,
	l_reverse_tax_dist.receipt_required_flag,
	l_reverse_tax_dist.receipt_missing_flag,
	l_reverse_tax_dist.justification,
	l_reverse_tax_dist.expense_group,
	l_reverse_tax_dist.start_expense_date,
	l_reverse_tax_dist.end_expense_date,
	l_reverse_tax_dist.receipt_currency_code,
	l_reverse_tax_dist.receipt_conversion_rate,
	l_reverse_tax_dist.receipt_currency_amount,
	l_reverse_tax_dist.daily_amount,
	l_reverse_tax_dist.web_parameter_id,
	l_reverse_tax_dist.adjustment_reason,
	l_reverse_tax_dist.award_id,
	l_reverse_tax_dist.credit_card_trx_id,
	l_reverse_tax_dist.dist_match_type,
	l_reverse_tax_dist.rcv_transaction_id,
	l_reverse_tax_dist.invoice_distribution_id,
	l_reverse_tax_dist.parent_reversal_id,
	l_reverse_tax_dist.tax_recoverable_flag,
	l_reverse_tax_dist.merchant_document_number,
	l_reverse_tax_dist.merchant_name,
	l_reverse_tax_dist.merchant_reference,
	l_reverse_tax_dist.merchant_tax_reg_number,
	l_reverse_tax_dist.merchant_taxpayer_id,
	l_reverse_tax_dist.country_of_supply,
	l_reverse_tax_dist.matched_uom_lookup_code,
	l_reverse_tax_dist.gms_burdenable_raw_cost,
	l_reverse_tax_dist.accounting_event_id,
	l_reverse_tax_dist.prepay_distribution_id,
	l_reverse_tax_dist.upgrade_posted_amt,
	l_reverse_tax_dist.upgrade_base_posted_amt,
	l_reverse_tax_dist.inventory_transfer_status,
	l_reverse_tax_dist.company_prepaid_invoice_id,
	l_reverse_tax_dist.cc_reversal_flag,
	l_reverse_tax_dist.awt_withheld_amt,
	l_reverse_tax_dist.pa_cmt_xface_flag,
	l_reverse_tax_dist.cancellation_flag,
	l_reverse_tax_dist.invoice_line_number,
	l_reverse_tax_dist.corrected_invoice_dist_id,
	l_reverse_tax_dist.rounding_amt,
	l_reverse_tax_dist.charge_applicable_to_dist_id,
	l_reverse_tax_dist.corrected_quantity,
	l_reverse_tax_dist.related_id,
	l_reverse_tax_dist.asset_book_type_code,
	l_reverse_tax_dist.asset_category_id,
	l_reverse_tax_dist.distribution_class,
	l_reverse_tax_dist.tax_code_id,
	l_reverse_tax_dist.intended_use,
	l_reverse_tax_dist.detail_tax_dist_id,
	l_reverse_tax_dist.rec_nrec_rate,
	l_reverse_tax_dist.recovery_rate_id,
	l_reverse_tax_dist.recovery_type_code,
	l_reverse_tax_dist.withholding_tax_code_id,
	l_reverse_tax_dist.taxable_amount,
	l_reverse_tax_dist.taxable_base_amount,
	l_reverse_tax_dist.tax_already_distributed_flag,
	l_reverse_tax_dist.summary_tax_line_id,
	l_reverse_tax_dist.rcv_charge_addition_flag,
	l_reverse_tax_dist.prepay_tax_diff_amount, -- BUG 7338249
    l_reverse_tax_dist.pay_awt_group_id); /*BUG 10261626*/
Line: 15352

    INSERT into ZX_TAX_DIST_ID_GT (TAX_DIST_ID) values (l_reverse_tax_dist.detail_tax_dist_id) ; --bug 13101979
Line: 15378

       l_debug_info := 'Inserting reverse entries into ap_self_assessed_tax_dist_all';
Line: 15389

	   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_type_code,
                withholding_tax_code_id,
                taxable_amount,
                taxable_base_amount,
                tax_already_distributed_flag,
                summary_tax_line_id,
		        rcv_charge_addition_flag,
                self_assessed_flag,
                self_assessed_tax_liab_ccid,  --bug6805655
                prepay_tax_diff_amount -- BUG 7338249
                )
		VALUES
		(
		l_self_assess_rev_tax_dist_1.accounting_date,
		l_self_assess_rev_tax_dist_1.accrual_posted_flag,
		l_self_assess_rev_tax_dist_1.assets_addition_flag,
		l_self_assess_rev_tax_dist_1.assets_tracking_flag,
		l_self_assess_rev_tax_dist_1.cash_posted_flag,
		l_self_assess_rev_tax_dist_1.distribution_line_number,
		l_self_assess_rev_tax_dist_1.dist_code_combination_id,
		l_self_assess_rev_tax_dist_1.invoice_id,
		l_self_assess_rev_tax_dist_1.last_updated_by,
		l_self_assess_rev_tax_dist_1.last_update_date,
		l_self_assess_rev_tax_dist_1.line_type_lookup_code,
		l_self_assess_rev_tax_dist_1.period_name,
		l_self_assess_rev_tax_dist_1.set_of_books_id,
		l_self_assess_rev_tax_dist_1.amount,
		l_self_assess_rev_tax_dist_1.base_amount,
		--l_self_assess_rev_tax_dist_1.batch_id,
		l_self_assess_rev_tax_dist_1.created_by,
		l_self_assess_rev_tax_dist_1.creation_date,
		l_self_assess_rev_tax_dist_1.description,
		l_self_assess_rev_tax_dist_1.final_match_flag,
		l_self_assess_rev_tax_dist_1.income_tax_region,
		l_self_assess_rev_tax_dist_1.last_update_login,
		l_self_assess_rev_tax_dist_1.match_status_flag,
		l_self_assess_rev_tax_dist_1.posted_flag,
		l_self_assess_rev_tax_dist_1.po_distribution_id,
		l_self_assess_rev_tax_dist_1.program_application_id,
		l_self_assess_rev_tax_dist_1.program_id,
		l_self_assess_rev_tax_dist_1.program_update_date,
		l_self_assess_rev_tax_dist_1.quantity_invoiced,
		l_self_assess_rev_tax_dist_1.request_id,
		l_self_assess_rev_tax_dist_1.reversal_flag,
		l_self_assess_rev_tax_dist_1.type_1099,
		l_self_assess_rev_tax_dist_1.unit_price,
		l_self_assess_rev_tax_dist_1.encumbered_flag,
		l_self_assess_rev_tax_dist_1.stat_amount,
		l_self_assess_rev_tax_dist_1.attribute1,
		l_self_assess_rev_tax_dist_1.attribute10,
		l_self_assess_rev_tax_dist_1.attribute11,
		l_self_assess_rev_tax_dist_1.attribute12,
		l_self_assess_rev_tax_dist_1.attribute13,
		l_self_assess_rev_tax_dist_1.attribute14,
		l_self_assess_rev_tax_dist_1.attribute15,
		l_self_assess_rev_tax_dist_1.attribute2,
		l_self_assess_rev_tax_dist_1.attribute3,
		l_self_assess_rev_tax_dist_1.attribute4,
		l_self_assess_rev_tax_dist_1.attribute5,
		l_self_assess_rev_tax_dist_1.attribute6,
		l_self_assess_rev_tax_dist_1.attribute7,
		l_self_assess_rev_tax_dist_1.attribute8,
		l_self_assess_rev_tax_dist_1.attribute9,
		l_self_assess_rev_tax_dist_1.attribute_category,
		l_self_assess_rev_tax_dist_1.expenditure_item_date,
		l_self_assess_rev_tax_dist_1.expenditure_organization_id,
		l_self_assess_rev_tax_dist_1.expenditure_type,
		l_self_assess_rev_tax_dist_1.parent_invoice_id,
		l_self_assess_rev_tax_dist_1.pa_addition_flag,
		l_self_assess_rev_tax_dist_1.pa_quantity,
		l_self_assess_rev_tax_dist_1.prepay_amount_remaining,
		l_self_assess_rev_tax_dist_1.project_accounting_context,
		l_self_assess_rev_tax_dist_1.project_id,
		l_self_assess_rev_tax_dist_1.task_id,
		l_self_assess_rev_tax_dist_1.packet_id,
		l_self_assess_rev_tax_dist_1.awt_flag,
		l_self_assess_rev_tax_dist_1.awt_group_id,
		l_self_assess_rev_tax_dist_1.awt_tax_rate_id,
		l_self_assess_rev_tax_dist_1.awt_gross_amount,
		l_self_assess_rev_tax_dist_1.awt_invoice_id,
		l_self_assess_rev_tax_dist_1.awt_origin_group_id,
		l_self_assess_rev_tax_dist_1.reference_1,
		l_self_assess_rev_tax_dist_1.reference_2,
		l_self_assess_rev_tax_dist_1.org_id,
		l_self_assess_rev_tax_dist_1.awt_invoice_payment_id,
		l_self_assess_rev_tax_dist_1.global_attribute_category,
		l_self_assess_rev_tax_dist_1.global_attribute1,
		l_self_assess_rev_tax_dist_1.global_attribute2,
		l_self_assess_rev_tax_dist_1.global_attribute3,
		l_self_assess_rev_tax_dist_1.global_attribute4,
		l_self_assess_rev_tax_dist_1.global_attribute5,
		l_self_assess_rev_tax_dist_1.global_attribute6,
		l_self_assess_rev_tax_dist_1.global_attribute7,
		l_self_assess_rev_tax_dist_1.global_attribute8,
		l_self_assess_rev_tax_dist_1.global_attribute9,
		l_self_assess_rev_tax_dist_1.global_attribute10,
		l_self_assess_rev_tax_dist_1.global_attribute11,
		l_self_assess_rev_tax_dist_1.global_attribute12,
		l_self_assess_rev_tax_dist_1.global_attribute13,
		l_self_assess_rev_tax_dist_1.global_attribute14,
		l_self_assess_rev_tax_dist_1.global_attribute15,
		l_self_assess_rev_tax_dist_1.global_attribute16,
		l_self_assess_rev_tax_dist_1.global_attribute17,
		l_self_assess_rev_tax_dist_1.global_attribute18,
		l_self_assess_rev_tax_dist_1.global_attribute19,
		l_self_assess_rev_tax_dist_1.global_attribute20,
		l_self_assess_rev_tax_dist_1.receipt_verified_flag,
		l_self_assess_rev_tax_dist_1.receipt_required_flag,
		l_self_assess_rev_tax_dist_1.receipt_missing_flag,
		l_self_assess_rev_tax_dist_1.justification,
		l_self_assess_rev_tax_dist_1.expense_group,
		l_self_assess_rev_tax_dist_1.start_expense_date,
		l_self_assess_rev_tax_dist_1.end_expense_date,
		l_self_assess_rev_tax_dist_1.receipt_currency_code,
		l_self_assess_rev_tax_dist_1.receipt_conversion_rate,
		l_self_assess_rev_tax_dist_1.receipt_currency_amount,
		l_self_assess_rev_tax_dist_1.daily_amount,
		l_self_assess_rev_tax_dist_1.web_parameter_id,
		l_self_assess_rev_tax_dist_1.adjustment_reason,
		l_self_assess_rev_tax_dist_1.award_id,
		l_self_assess_rev_tax_dist_1.credit_card_trx_id,
		l_self_assess_rev_tax_dist_1.dist_match_type,
		l_self_assess_rev_tax_dist_1.rcv_transaction_id,
		l_self_assess_rev_tax_dist_1.invoice_distribution_id,
		l_self_assess_rev_tax_dist_1.parent_reversal_id,
		l_self_assess_rev_tax_dist_1.tax_recoverable_flag,
		l_self_assess_rev_tax_dist_1.merchant_document_number,
		l_self_assess_rev_tax_dist_1.merchant_name,
		l_self_assess_rev_tax_dist_1.merchant_reference,
		l_self_assess_rev_tax_dist_1.merchant_tax_reg_number,
		l_self_assess_rev_tax_dist_1.merchant_taxpayer_id,
		l_self_assess_rev_tax_dist_1.country_of_supply,
		l_self_assess_rev_tax_dist_1.matched_uom_lookup_code,
		l_self_assess_rev_tax_dist_1.gms_burdenable_raw_cost,
		l_self_assess_rev_tax_dist_1.accounting_event_id,
		l_self_assess_rev_tax_dist_1.prepay_distribution_id,
		l_self_assess_rev_tax_dist_1.upgrade_posted_amt,
		l_self_assess_rev_tax_dist_1.upgrade_base_posted_amt,
		l_self_assess_rev_tax_dist_1.inventory_transfer_status,
		l_self_assess_rev_tax_dist_1.company_prepaid_invoice_id,
		l_self_assess_rev_tax_dist_1.cc_reversal_flag,
		l_self_assess_rev_tax_dist_1.awt_withheld_amt,
		l_self_assess_rev_tax_dist_1.pa_cmt_xface_flag,
		l_self_assess_rev_tax_dist_1.cancellation_flag,
		l_self_assess_rev_tax_dist_1.invoice_line_number,
		l_self_assess_rev_tax_dist_1.corrected_invoice_dist_id,
		l_self_assess_rev_tax_dist_1.rounding_amt,
		l_self_assess_rev_tax_dist_1.charge_applicable_to_dist_id,
		l_self_assess_rev_tax_dist_1.corrected_quantity,
		l_self_assess_rev_tax_dist_1.related_id,
		l_self_assess_rev_tax_dist_1.asset_book_type_code,
		l_self_assess_rev_tax_dist_1.asset_category_id,
		l_self_assess_rev_tax_dist_1.distribution_class,
		l_self_assess_rev_tax_dist_1.tax_code_id,
		l_self_assess_rev_tax_dist_1.intended_use,
		l_self_assess_rev_tax_dist_1.detail_tax_dist_id,
		l_self_assess_rev_tax_dist_1.rec_nrec_rate,
		l_self_assess_rev_tax_dist_1.recovery_rate_id,
		l_self_assess_rev_tax_dist_1.recovery_type_code,
		l_self_assess_rev_tax_dist_1.withholding_tax_code_id,
		l_self_assess_rev_tax_dist_1.taxable_amount,
		l_self_assess_rev_tax_dist_1.taxable_base_amount,
		l_self_assess_rev_tax_dist_1.tax_already_distributed_flag,
		l_self_assess_rev_tax_dist_1.summary_tax_line_id,
		l_self_assess_rev_tax_dist_1.rcv_charge_addition_flag,
		l_self_assess_rev_tax_dist_1.self_assessed_flag,
 		l_self_assess_rev_tax_dist_1.self_assessed_tax_liab_ccid,   --bug6805655
        l_self_assess_rev_tax_dist_1.prepay_tax_diff_amount -- BUG 7338249
        );
Line: 15705

	INSERT into ZX_TAX_DIST_ID_GT (TAX_DIST_ID) values (l_self_assess_rev_tax_dist_1.detail_tax_dist_id) ; --bug 13101979
Line: 15732

        ZX_API_PUB.Update_Tax_dist_gl_date (
				1.0,
				FND_API.G_TRUE,
				FND_API.G_FALSE,
				FND_API.G_VALID_LEVEL_FULL,
				l_return_status_service,
				l_msg_count,
				l_msg_data,
				l_inv_cancel_date );
Line: 15770

        l_debug_info := 'Step 4: Update reversal_flag';
Line: 15776

        UPDATE ap_invoice_distributions_all aid
           SET reversal_flag = (select reverse_flag
                                  from zx_rec_nrec_dist zx
                                 where zx.rec_nrec_tax_dist_id = aid.detail_tax_dist_id)
         WHERE aid.invoice_id = p_invoice_id
           AND aid.detail_tax_dist_id IS NOT NULL;
Line: 15784

        l_debug_info := 'Step 5: Update related_flag';
Line: 15790

        UPDATE ap_invoice_distributions aid
           SET aid.related_id =
      			(SELECT invoice_distribution_id
                           FROM ap_invoice_distributions_all aid1
			  WHERE aid1.invoice_id = aid.invoice_id
			    AND aid1.invoice_line_number = aid.invoice_line_number
			    AND aid1.parent_reversal_id =
					(SELECT related_id
			                   FROM ap_invoice_distributions_all aid2
					  WHERE aid2.invoice_id = aid.invoice_id
					    AND aid2.invoice_line_number = aid.invoice_line_number
					    AND aid2.invoice_distribution_id = aid.parent_reversal_id)
                       )
        WHERE aid.related_id IS NULL
          AND aid.parent_reversal_id IS NOT NULL
          AND aid.invoice_id = p_invoice_id
          AND aid.reversal_flag = 'Y'
          AND aid.detail_tax_dist_id IS NOT NULL;
Line: 15816

           l_debug_info := 'Step 4: Update reversal_flag';
Line: 15822

           UPDATE ap_self_assessed_tax_dist_all aid
              SET reversal_flag = (select reverse_flag
                                     from zx_rec_nrec_dist zx
                                    where zx.rec_nrec_tax_dist_id = aid.detail_tax_dist_id)
            WHERE aid.invoice_id = p_invoice_id
              AND aid.detail_tax_dist_id IS NOT NULL;
Line: 15830

           l_debug_info := 'Step 5: Update related_flag';
Line: 15836

           UPDATE ap_self_assessed_tax_dist_all aid
              SET aid.related_id =
                        (SELECT invoice_distribution_id
                           FROM ap_self_assessed_tax_dist_all aid1
                          WHERE aid1.invoice_id = aid.invoice_id
                            AND aid1.invoice_line_number = aid.invoice_line_number
                            AND aid1.parent_reversal_id =
                                        (SELECT related_id
                                           FROM ap_self_assessed_tax_dist_all aid2
                                          WHERE aid2.invoice_id = aid.invoice_id
                                            AND aid2.invoice_line_number = aid.invoice_line_number
                                            AND aid2.invoice_distribution_id = aid.parent_reversal_id)
                       )
            WHERE aid.related_id IS NULL
              AND aid.parent_reversal_id IS NOT NULL
              AND aid.invoice_id = p_invoice_id
              AND aid.reversal_flag = 'Y'
              AND aid.detail_tax_dist_id IS NOT NULL;
Line: 15892

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 15897

    SELECT distinct prepLine.*
      FROM ap_invoice_distributions_all invDist,
           ap_invoice_distributions_all prepDist,
           ap_invoice_lines_all		prepLine
     WHERE invDist.prepay_distribution_id = prepDist.invoice_distribution_id
       AND prepLine.invoice_id		  = prepDist.invoice_id
       AND prepLine.line_number		  = prepDist.invoice_line_number
       AND invDist.line_type_lookup_code  = 'PREPAY'
       AND invDist.invoice_id             = p_invoice_id
       AND invDist.invoice_line_number    = p_invoice_line_number;
Line: 15996

         DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 15998

         AP_ETAX_SERVICES_PKG.G_SITE_ATTRIBUTES.DELETE;
Line: 15999

         AP_ETAX_SERVICES_PKG.G_ORG_ATTRIBUTES.DELETE;
Line: 16065

             l_debug_info := 'Step 5.1: Update Tax Already Calculated Flag';
Line: 16071

	     UPDATE ap_invoice_lines_all ail
	        SET ail.tax_already_calculated_flag = 'Y'
	      WHERE ail.invoice_id  = p_invoice_id
                AND ail.line_number = p_invoice_line_number;
Line: 16115

    DELETE FROM ZX_TRX_HEADERS_GT;
Line: 16116

    DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 16137

      DELETE FROM ZX_TRX_HEADERS_GT;
Line: 16138

      DELETE FROM ZX_TRANSACTION_LINES_GT;
Line: 16144

Function Delete_Tax_Distributions
			(p_invoice_id         IN  ap_invoice_distributions_all.invoice_id%Type,
			 p_calling_mode	      IN  VARCHAR2,
			 p_all_error_messages IN  VARCHAR2,
			 p_error_code         OUT NOCOPY VARCHAR2,
		         p_calling_sequence   IN  VARCHAR2) RETURN BOOLEAN IS

   -- Removed the cursor for the bug 9749258


   l_invoice_header_rec		ap_invoices_all%rowtype;
Line: 16173

   l_api_name                    CONSTANT VARCHAR2(100) := 'Delete_Tax_distributions';
Line: 16177

   l_curr_calling_sequence := 'AP_ETAX_SERVICES_PKG.Delete_Tax_Distributions<-' ||
                               p_calling_sequence;
Line: 16183

       l_debug_info := 'Exit delete_tax_distributions';
Line: 16198

   Select * Into l_invoice_header_rec
     From ap_invoices_all
    Where invoice_id = p_invoice_id;
Line: 16263

   UPDATE ap_invoice_distributions_All aid1
			    SET  aid1.amount = aid1.amount + nvl((SELECT SUM(nvl(amount,0))
			                            FROM ap_invoice_distributions_All aid2
			                           WHERE aid2.invoice_id =  p_invoice_id
                                         AND aid2.invoice_line_number = aid1.invoice_line_number
			                             AND aid2.charge_applicable_to_dist_id = aid1.invoice_distribution_id
			                             AND aid2.line_type_lookup_code IN ('REC_TAX','NONREC_TAX','TRV','TIPV')
                                         AND aid2.distribution_class = 'CANDIDATE'
                                         AND EXISTS (SELECT 1
                                                         FROM zx_rec_nrec_dist zd
                                                        WHERE zd.application_id =200
                                                          AND zd.entity_code = 'AP_INVOICES'
                                                          AND zd.event_class_code IN ('STANDARD INVOICES','EXPENSE REPORTS','PREPAYMENT INVOICES')
                                                          AND zd.trx_id = aid2.invoice_id
                                                          AND zd.rec_nrec_tax_dist_id = aid2.detail_tax_dist_id
                                                          AND NVL(zd.inclusive_flag,'N') = 'Y')),0),
			           aid1.base_amount =aid1.base_amount + nvl((SELECT SUM(nvl(base_amount,0))
			                            FROM ap_invoice_distributions_All aid3
			                           WHERE aid3.invoice_id =  p_invoice_id
                                         AND aid3.invoice_line_number = aid1.invoice_line_number
	                                     AND aid3.charge_applicable_to_dist_id = aid1.invoice_distribution_id
          		                         AND aid3.line_type_lookup_code IN ('REC_TAX','NONREC_TAX','TRV','TIPV')
                                         AND aid3.distribution_class = 'CANDIDATE'
                                         AND EXISTS (SELECT 1
                                                       FROM zx_rec_nrec_dist zd1
                                                      WHERE zd1.application_id =200
                                                        AND zd1.entity_code = 'AP_INVOICES'
                                                        AND zd1.event_class_code IN ('STANDARD INVOICES','EXPENSE REPORTS','PREPAYMENT INVOICES')
                                                        AND zd1.trx_id = aid3.invoice_id
                                                        AND zd1.rec_nrec_tax_dist_id = aid3.detail_tax_dist_id
                                                        AND NVL(zd1.inclusive_flag,'N') = 'Y')),0)   --ER CHANGES
			    WHERE aid1.invoice_id =  p_invoice_id
			      AND  aid1.line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS');   --bug9314506
Line: 16301

         INSERT INTO zx_tax_dist_id_gt
          (Select distinct  detail_tax_dist_id
             From ap_invoice_distributions_all
            Where invoice_id = p_invoice_id
              AND distribution_class = 'CANDIDATE'
              And line_type_lookup_code  In('NONREC_TAX', 'REC_TAX', 'TRV', 'TERV', 'TIPV')
           UNION
           Select distinct detail_tax_dist_id
             From ap_self_assessed_tax_dist_all
            Where invoice_id = p_invoice_id
              AND distribution_class = 'CANDIDATE'
              And line_type_lookup_code  In('NONREC_TAX', 'REC_TAX', 'TRV', 'TERV', 'TIPV'));
Line: 16328

           l_debug_info := 'Step 5: Call eTax API to delete tax distributions';
Line: 16335

	   ZX_NEW_SERVICES_PKG.delete_tax_dists(
	          p_api_version             =>  1.0,
	          p_init_msg_list           =>  FND_API.G_TRUE,
	          p_commit                  =>  FND_API.G_FALSE,
	          p_validation_level        =>  FND_API.G_VALID_LEVEL_FULL,
	          x_return_status           =>  l_return_status_service,
	          x_msg_count               =>  l_msg_count,
	          x_msg_data                =>  l_msg_data,
	          p_transaction_line_rec    =>  l_transaction_line_rec_type
	        );
Line: 16375

END Delete_Tax_distributions;
Line: 16383

    SELECT 'Tax Distributions Exist'
      INTO l_dummy
      FROM ap_invoice_distributions_all
     WHERE invoice_id = p_invoice_id
       AND line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX', 'TIPV', 'TRV', 'TERV')
       AND rownum = 1;
Line: 16407

   /* SELECT 'Tax Only Line Exist'
      INTO l_dummy
      FROM ap_invoice_distributions_all
     WHERE invoice_id = p_invoice_id
       AND line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX', 'TIPV', 'TRV', 'TERV')
       AND charge_applicable_to_dist_id IS NULL
       AND rownum = 1; */
Line: 16415

    SELECT 'Tax Only Line Exist'
      INTO l_dummy
      FROM zx_lines_summary zls
     WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
       AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
       AND 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 zls.trx_id = p_invoice_id
       AND NVL(zls.reporting_only_flag, 'N') = 'N'
       AND NVL(zls.tax_only_line_flag, 'N') = 'Y'
       AND rownum = 1;
Line: 16459

    SELECT 'Tax Distributions Exist'
      INTO l_dummy
      FROM ap_self_assessed_tax_dist_all asat,
           zx_rec_nrec_dist zx_dist
     WHERE invoice_id = p_invoice_id
       AND asat.detail_tax_dist_id = zx_dist.rec_nrec_tax_dist_id
       AND zx_dist.self_assessed_flag = 'Y'
       AND nvl(zx_dist.reverse_flag, 'N') <> 'Y'
       AND line_type_lookup_code IN ('REC_TAX', 'NONREC_TAX')
       AND rownum = 1;
Line: 16486

	 SELECT  D.unit_price		      unit_price,
                 D.quantity_invoiced      quantity_invoiced,  --Bug12834600
		     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: 16579

    SELECT *
      FROM ap_invoices_all
     WHERE invoice_id = P_Invoice_Id;
Line: 16584

    SELECT *
      FROM ap_invoice_lines_all
     WHERE invoice_id = P_Invoice_Id
       AND line_type_lookup_code = 'TAX'
       AND summary_tax_line_id IS NULL;
Line: 16829

        SELECT location_id
          INTO l_bill_to_location_id
          FROM hr_all_organization_units
         WHERE organization_id = P_Invoice_Header_Rec.org_id;
Line: 16847

        SELECT location_id, fob_lookup_code
          INTO l_location_id, l_fob_point
          FROM ap_supplier_sites_all
         WHERE vendor_site_id = P_Invoice_Header_Rec.vendor_site_id;
Line: 17112

    l_debug_info := 'Step 14: Bulk Insert into global temp tables';
Line: 17121

	DELETE FROM zx_transaction_lines_gt;
Line: 17124

          INSERT INTO zx_transaction_lines_gt
          VALUES trans_lines(m);
Line: 17166

        DELETE FROM zx_trx_headers_gt;
Line: 17168

	INSERT INTO zx_trx_headers_gt(
	        internal_organization_id,
	        application_id,
	        entity_code,
	        event_class_code,
	        event_type_code,
	        trx_id,
	        trx_date,
		    ledger_id,
	        trx_currency_code,
	        currency_conversion_date,
	        currency_conversion_rate,
	        currency_conversion_type,
	        minimum_accountable_unit,
	        precision,
	        legal_entity_id,
	        rounding_ship_from_party_id,
	        rounding_bill_from_party_id,
	        rndg_ship_from_party_site_id,
	        rndg_bill_from_party_site_id,
	        related_doc_application_id,
	        related_doc_entity_code,
	        related_doc_event_class_code,
	        related_doc_trx_id,
	        related_doc_number,
	        related_doc_date,
	        default_taxation_country,
	        quote_flag,
	        ctrl_total_hdr_tx_amt,
	        trx_number,
		    trx_description,
	        doc_seq_id,
	        doc_seq_name,
	        doc_seq_value,
	        document_sub_type,
	        supplier_tax_invoice_number,
	        supplier_tax_invoice_date,
	        supplier_exchange_rate,
	        tax_invoice_date,
	        tax_invoice_number,
	        bill_third_pty_acct_id,
	        bill_third_pty_acct_site_id,
		    ship_third_pty_acct_id,
		    ship_third_pty_acct_site_id
	        )
	  SELECT
	        ai.org_id,								--internal_organization_id
	        200,									--application_id
	        'AP_INVOICES',                        					--entity_code
	        (CASE
	           WHEN ai.invoice_type_lookup_code IN
			  ('STANDARD', 'CREDIT', 'DEBIT',   'MIXED',
	                   'ADJUSTMENT', 'PO PRICE ADJUST', 'INVOICE REQUEST',
	                   'CREDIT MEMO REQUEST', 'RETAINAGE RELEASE', 'PAYMENT REQUEST') -- bug 9281264
	                THEN 'STANDARD INVOICES'
	           WHEN (ai.invoice_type_lookup_code = 'PREPAYMENT')
	                 or (p_calling_mode IN ('RECOUPMENT', 'DISTRIBUTE RECOUP'))
	                THEN 'PREPAYMENT INVOICES'
	           WHEN ai.invoice_type_lookup_code = 'EXPENSE REPORT'
	                THEN 'EXPENSE REPORTS'
	        END), 				     					--event_class_code
	        (CASE
	           WHEN ai.invoice_type_lookup_code IN
			  ('STANDARD', 'CREDIT', 'DEBIT',   'MIXED',
	                   'ADJUSTMENT', 'PO PRICE ADJUST', 'INVOICE REQUEST',
	                   'CREDIT MEMO REQUEST', 'RETAINAGE RELEASE', 'PAYMENT REQUEST') -- bug 9281264
	                THEN 'STANDARD '
	           WHEN (ai.invoice_type_lookup_code = 'PREPAYMENT')
	                 or (p_calling_mode IN ('RECOUPMENT', 'DISTRIBUTE RECOUP'))
	                THEN 'PREPAYMENT '
	           WHEN ai.invoice_type_lookup_code = 'EXPENSE REPORT'
	                THEN 'EXPENSE REPORT '
	        END)||
	        DECODE(p_calling_mode,
			'CALCULATE',
                        (CASE ((SELECT 'Y'
				 FROM ap_invoice_lines_all
				WHERE invoice_id = ai.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)
                             --- Start for bug 6485124
                                UNION
                                          (SELECT 'Y'
                                             FROM zx_lines_det_factors
                                            WHERE application_id = 200
                                             AND  entity_code = 'AP_INVOICES'
                                             AND  trx_id = ai.invoice_id
                                             AND  event_class_code in ('STANDARD INVOICES','PREPAYMENT INVOICES','EXPENSE REPORTS')
                                             AND  ROWNUM=1))
                             --- End for bug 6485124
				WHEN 'Y' THEN 'UPDATED'
		            	ELSE 'CREATED'
                	END),
			'DISTRIBUTE',
			(CASE (SELECT 'Y'
				 FROM ap_invoice_distributions_all
				WHERE invoice_id = ai.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)
				WHEN 'Y' THEN 'REDISTRIBUTE'
				ELSE 'DISTRIBUTE'
			END)),								--event_type_code
	        ai.invoice_id,                   					--trx_id
	        ai.invoice_date,                 					--trx_date
	        ai.set_of_books_id,              					--ledger_id
	        ai.invoice_currency_code,        					--trx_currency_code
	        ai.exchange_date,                					--currency_conversion_date
	        ai.exchange_rate,                					--currency_conversion_rate
	        ai.exchange_rate_type,           					--currency_conversion_type
	        NVL(cur.minimum_accountable_unit,
			 (1/power(10,cur.precision))),   				--minimum_accountable_unit
	        nvl(cur.precision,0),            					--precision
	        ai.legal_entity_id,              					--legal_entity_id
	        ai.party_id,                     					--rounding_ship_from_party_id
	        ai.party_id,                     					--rounding_bill_from_party_id
	        ai.party_site_id,                					--rndg_ship_from_party_site_id
	        ai.party_site_id,                					--rndg_bill_from_party_site_id
                (CASE
                   WHEN related_ai.invoice_type_lookup_code IS NOT NULL
                        THEN 200
                        ELSE NULL
                END),									--related_doc_application_id
		(CASE
                   WHEN related_ai.invoice_type_lookup_code IS NOT NULL
                        THEN 'AP_INVOICES'
		        ELSE NULL
                END),									--related_doc_entity_code
	        (CASE
	           WHEN related_ai.invoice_type_lookup_code IN
		          ('STANDARD', 'CREDIT', 'DEBIT',   'MIXED',
	                   'ADJUSTMENT', 'PO PRICE ADJUST', 'INVOICE REQUEST',
	                   'CREDIT MEMO REQUEST', 'RETAINAGE RELEASE')
	                THEN 'STANDARD INVOICES'
	           WHEN ai.invoice_type_lookup_code = 'PREPAYMENT'
	                THEN 'PREPAYMENT INVOICES'
	           WHEN ai.invoice_type_lookup_code = 'EXPENSE REPORT'
	                THEN 'EXPENSE REPORTS'
	        END),									--related_doc_event_class_code
	        ai.tax_related_invoice_id,       					--related_doc_trx_id
	        related_ai.invoice_num,                            			--related_doc_number
	        related_ai.invoice_date,                           			--related_doc_date
	        ai.taxation_country,             					--default_taxation_country
	        decode(p_calling_mode,
				'CALCULATE QUOTE', 'Y', 'N'),				--quote_flag
	        ai.control_amount,               					--ctrl_total_hdr_tx_amt
	        ai.invoice_num,                  					--trx_number
	        ai.description,                  					--trx_description
	        ai.doc_sequence_id,              					--doc_seq_id
	        doc.name,            		     					--doc_seq_name
	        nvl(to_char(ai.doc_sequence_value), ai.voucher_num),				--doc_seq_value bug6656894
	        ai.document_sub_type,            					--document_sub_type
	        ai.supplier_tax_invoice_number,  					--supplier_tax_invoice_number
	        ai.supplier_tax_invoice_date,    					--supplier_tax_invoice_date
	        ai.supplier_tax_exchange_rate,   					--supplier_exchange_rate
	        ai.tax_invoice_recording_date,   					--tax_invoice_date
	        ai.tax_invoice_internal_seq,     					--tax_invoice_number
	        ai.vendor_id,			     					--bill_third_pty_acct_id
		ai.vendor_site_id,		     					--bill_third_pty_acct_site_id
	        ai.vendor_id,                    					--ship_third_pty_acct_id
	        ai.vendor_site_id                					--ship_third_pty_acct_site_id
	  FROM  ap_invoices_all        ai,
	        fnd_currencies         cur,
	        fnd_document_sequences doc,
	        ap_invoices_all        related_ai,
                ap_system_parameters_all asp --Bug14779241
	 WHERE  ai.invoice_currency_code  = cur.currency_code
	   AND  ai.doc_sequence_id        = doc.doc_sequence_id (+)
	   AND  ai.tax_related_invoice_id = related_ai.invoice_id (+)
           AND  nvl(ai.quick_credit,'N') = 'N'
           AND  ai.invoice_type_lookup_code NOT IN ('AWT', 'INTEREST') -- bug 9281264
	   AND  ai.validation_request_id  = p_validation_request_id
       	   AND  asp.org_id = ai.org_id /* Bug14779241: Start */
           AND  ((asp.base_currency_code = ai.invoice_currency_code) OR
	        (p_calling_mode IN ('CALCULATE')) OR
                (asp.base_currency_code <> ai.invoice_currency_code AND
                ai.exchange_rate IS NOT NULL AND p_calling_mode IN ('DISTRIBUTE','DISTRIBUTE IMPORT')
                )); /* Bug14779241: End */
Line: 17359

        FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, 'Rows inserted in zx_trx_headers_gt '||g_invoices_to_process);
Line: 17373

FUNCTION Update_Distributions(
             P_Invoice_header_rec    IN ap_invoices_all%ROWTYPE,
             P_Calling_Mode          IN VARCHAR2,
             P_All_Error_Messages    IN VARCHAR2,
             P_Error_Code            OUT NOCOPY VARCHAR2,
             P_Calling_Sequence      IN VARCHAR2) RETURN BOOLEAN
IS

    CURSOR c_reverse_dist (c_invoice_id NUMBER) IS
        SELECT aid_reverse.invoice_distribution_id invoice_distribution_id,
               aid_parent.invoice_distribution_id  parent_reversal_id,
               aid_parent.dist_code_combination_id parent_ccid
          FROM ap_invoice_distributions_all aid_reverse,
               ap_invoice_distributions_all aid_parent,
               zx_rec_nrec_dist zx
         WHERE aid_reverse.invoice_id         = c_invoice_id
           AND aid_reverse.detail_tax_dist_id = zx.rec_nrec_tax_dist_id
           AND aid_parent.detail_tax_dist_id  = zx.reversed_tax_dist_id
           AND aid_parent.line_type_lookup_code = aid_reverse.line_type_lookup_code;
Line: 17395

        SELECT aid_reverse.invoice_distribution_id invoice_distribution_id,
               aid_parent.invoice_distribution_id  parent_reversal_id,
               aid_parent.dist_code_combination_id parent_ccid
          FROM ap_self_assessed_tax_dist_all aid_reverse,
               ap_self_assessed_tax_dist_all aid_parent,
               zx_rec_nrec_dist zx
         WHERE aid_reverse.invoice_id         = c_invoice_id
           AND aid_reverse.detail_tax_dist_id = zx.rec_nrec_tax_dist_id
           AND aid_parent.detail_tax_dist_id  = zx.reversed_tax_dist_id
           AND aid_parent.line_type_lookup_code = aid_reverse.line_type_lookup_code;
Line: 17415

        SELECT amount,included_tax_amount,line_number,
               (total_rec_tax_amt_funcl_curr +total_nrec_tax_amt_funcl_curr) base_included_tax_amount,discarded_flag --Bug8717396
        FROM   ap_invoice_lines_all
        WHERE  invoice_id =  p_invoice_header_rec.invoice_id
        AND    line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS','PREPAY') --/*Bug7338249*/
        --Bug9436217
        AND    included_tax_amount <> 0 ; --ER CHANGES
Line: 17435

    l_api_name			CONSTANT VARCHAR2(100) := 'Update_Distributions';
Line: 17441

    l_debug_info := 'Step 1: Update the related_id column';
Line: 17447

    /*  UPDATE ap_invoice_distributions_all aid
         SET related_id = (SELECT DECODE(MIN(nrtax.invoice_distribution_id),
						NULL, MIN(other.invoice_distribution_id),
                                    		MIN(nrtax.invoice_distribution_id))
                             FROM ap_invoice_distributions_all nrtax,
                                  ap_invoice_distributions_all other
                            WHERE nrtax.invoice_id 	   = aid.invoice_id
                              AND other.invoice_id	   = aid.invoice_id
                              AND nrtax.detail_tax_dist_id = aid.detail_tax_dist_id
                              AND other.detail_tax_dist_id = aid.detail_tax_dist_id
                              AND nrtax.line_type_lookup_code <> 'TERV' --Bug9415464
                              AND (nrtax.line_type_lookup_code = 'NONREC_TAX'
                                   OR other.line_type_lookup_code IN ('TIPV', 'TRV'))
                             GROUP BY 1)
      WHERE aid.invoice_id = P_Invoice_Header_Rec.invoice_id
        AND aid.line_type_lookup_code in ('NONREC_TAX', 'TIPV', 'TRV', 'TERV')
        AND EXISTS (SELECT aid1.detail_tax_dist_id
                      FROM ap_invoice_distributions_all aid1
                     WHERE aid1.invoice_id = aid.invoice_id
                       AND aid1.detail_tax_dist_id = aid.detail_tax_dist_id
                    HAVING count(*) > 1
                     GROUP BY aid1.detail_tax_dist_id);*/
Line: 17473

      UPDATE ap_invoice_distributions_all aid
      SET related_id =DECODE((SELECT MIN(nrtax.invoice_distribution_id)
                                 FROM ap_invoice_distributions_all nrtax
                                 WHERE nrtax.invoice_id         = aid.invoice_id
                                 AND nrtax.detail_tax_dist_id = aid.detail_tax_dist_id
                                 AND nrtax.line_type_lookup_code = 'NONREC_TAX'
                                 GROUP BY 1) ,NULL ,
                                (SELECT MIN(other.invoice_distribution_id)
                                 FROM ap_invoice_distributions_all other
                                 WHERE other.invoice_id         = aid.invoice_id
                                 AND other.detail_tax_dist_id = aid.detail_tax_dist_id
                                 AND other.line_type_lookup_code IN ('TIPV', 'TRV')
                                 GROUP BY 1) ,
                                (SELECT MIN(nrtax.invoice_distribution_id)
                                 FROM ap_invoice_distributions_all nrtax
                                 WHERE nrtax.invoice_id         = aid.invoice_id
                                 AND nrtax.detail_tax_dist_id = aid.detail_tax_dist_id
                                 AND nrtax.line_type_lookup_code = 'NONREC_TAX'
                                 GROUP BY 1))
        WHERE aid.invoice_id = P_Invoice_Header_Rec.invoice_id
        AND aid.line_type_lookup_code in ('NONREC_TAX', 'TIPV', 'TRV', 'TERV')
        AND EXISTS (SELECT aid1.detail_tax_dist_id
                    FROM ap_invoice_distributions_all aid1
                    WHERE aid1.invoice_id = aid.invoice_id
                    AND aid1.detail_tax_dist_id = aid.detail_tax_dist_id
                    HAVING count(*) > 1
                    GROUP BY aid1.detail_tax_dist_id);
Line: 17502

    l_debug_info := 'Step 2: Update the related_id column for self assessed distributions';
Line: 17508

      UPDATE ap_self_assessed_tax_dist_all aid
         SET related_id = (SELECT DECODE(MIN(nrtax.invoice_distribution_id),
					 NULL, MIN(other.invoice_distribution_id),
					 MIN(nrtax.invoice_distribution_id))
                             FROM ap_self_assessed_tax_dist_all nrtax,
                                  ap_self_assessed_tax_dist_all other
                            WHERE nrtax.invoice_id 	   = aid.invoice_id
                              AND other.invoice_id 	   = aid.invoice_id
                              AND nrtax.detail_tax_dist_id = aid.detail_tax_dist_id
                              AND other.detail_tax_dist_id = aid.detail_tax_dist_id
                              AND nrtax.line_type_lookup_code <> 'TERV' --Bug9415464
                              AND (nrtax.line_type_lookup_code = 'NONREC_TAX'
                                   OR other.line_type_lookup_code IN ('TIPV', 'TRV'))
                             GROUP BY 1)
      WHERE aid.invoice_id = P_Invoice_Header_Rec.invoice_id
        AND aid.line_type_lookup_code in ('NONREC_TAX', 'TIPV', 'TRV', 'TERV')
        AND EXISTS (SELECT aid1.detail_tax_dist_id
                      FROM ap_self_assessed_tax_dist_all aid1
                     WHERE aid1.invoice_id = aid.invoice_id
                       AND aid1.detail_tax_dist_id = aid.detail_tax_dist_id
                    HAVING count(*) > 1
                     GROUP BY aid1.detail_tax_dist_id);
Line: 17533

    l_debug_info := 'Step 3: Update rounding_amt for the primary NONREC tax dist';
Line: 17539

      UPDATE ap_invoice_distributions_all aid
         SET rounding_amt =
             (SELECT zd.func_curr_rounding_adjustment
                FROM zx_rec_nrec_dist zd
               WHERE zd.rec_nrec_tax_dist_id = aid.detail_tax_dist_id)
      WHERE aid.invoice_id = P_Invoice_Header_Rec.invoice_id
        AND aid.line_type_lookup_code in ('NONREC_TAX', 'TIPV', 'TRV', 'TERV')
        AND (aid.related_id IS NULL
             OR aid.related_id = aid.invoice_distribution_id);
Line: 17551

    l_debug_info := 'Step 4: Update rounding_amt for the primary NONREC self assessed dist';
Line: 17557

      UPDATE ap_self_assessed_tax_dist_all aid
         SET rounding_amt =
             (SELECT zd.func_curr_rounding_adjustment
                FROM zx_rec_nrec_dist zd
               WHERE zd.rec_nrec_tax_dist_id = aid.detail_tax_dist_id)
      WHERE aid.invoice_id = P_Invoice_Header_Rec.invoice_id
        AND aid.line_type_lookup_code in ('NONREC_TAX', 'TIPV', 'TRV', 'TERV')
        AND (aid.related_id IS NULL
             OR aid.related_id = aid.invoice_distribution_id);
Line: 17569

   l_debug_info := 'Step 5: Update REC and NONREC totals at line level';
Line: 17575

      UPDATE ap_invoice_lines_all ail
         SET (ail.total_rec_tax_amount,
              ail.total_nrec_tax_amount,
              ail.total_rec_tax_amt_funcl_curr,
              ail.total_nrec_tax_amt_funcl_curr) =
             (SELECT SUM(DECODE(NVL(zd.recoverable_flag, 'N'),
                                'Y', NVL(zd.rec_nrec_tax_amt, 0),
                                0)),
                     SUM(DECODE(NVL(zd.recoverable_flag, 'N'),
                                'N', NVL(zd.rec_nrec_tax_amt, 0),
                                 0)),
                     SUM(DECODE(NVL(zd.recoverable_flag, 'N'),
                                'Y', NVL(zd.rec_nrec_tax_amt_funcl_curr, 0),
                                 0)),
                     SUM(DECODE(NVL(zd.recoverable_flag, 'N'),
                                'N', NVL(zd.rec_nrec_tax_amt_funcl_curr, 0),
                                 0))
                FROM zx_rec_nrec_dist zd
               WHERE application_id   = AP_ETAX_PKG.AP_APPLICATION_ID
                 AND entity_code      = AP_ETAX_PKG.AP_ENTITY_CODE
                 AND 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 zd.trx_id		= ail.invoice_id
                 AND ((zd.trx_line_id	= ail.line_number AND zd.inclusive_flag = 'Y')
                    OR (ail.summary_tax_line_id = zd.summary_tax_line_id AND zd.inclusive_flag = 'N'))  --Bug11720331
                 AND NVL(zd.self_assessed_flag, 'N') = 'N')
       WHERE ail.invoice_id		= P_Invoice_Header_Rec.invoice_id
         AND (ail.summary_tax_line_id IS NOT NULL
              OR (ail.line_type_lookup_code <> 'TAX'
                  AND ail.included_tax_amount IS NOT NULL));   --Bug11720331
Line: 17612

   l_debug_info := 'Step 5: Update tax_already_distributed_flag';
Line: 17618

      UPDATE ap_invoice_distributions_all aid
         SET aid.tax_already_distributed_flag = 'Y'
       WHERE aid.invoice_id = p_invoice_header_rec.invoice_id
         AND NVL(aid.tax_already_distributed_flag, 'N') = 'N'
         AND aid.invoice_distribution_id IN
             ( SELECT aid1.charge_applicable_to_dist_id
                 FROM ap_invoice_distributions_all aid1,
                      zx_rec_nrec_dist zd
                WHERE zd.REC_NREC_TAX_DIST_ID = aid1.DETAIL_TAX_DIST_ID
                  AND aid1.invoice_id = p_invoice_header_rec.invoice_id );
Line: 17630

   l_debug_info := 'Step 6: Update generate_dists on the invoice line';
Line: 17636

   UPDATE ap_invoice_lines_all ail
   SET    generate_dists = 'D'
   WHERE  ail.invoice_id = p_invoice_header_rec.invoice_id
   AND    ail.generate_dists <> 'D'
   AND    line_type_lookup_code = 'TAX'
   AND    EXISTS
		(SELECT aid.invoice_distribution_id
	           FROM ap_invoice_distributions_all aid
	          WHERE aid.invoice_id          = ail.invoice_id
	            AND aid.invoice_line_number = ail.line_number);
Line: 17648

    l_debug_info := 'Step 7: Update Invoice Includes Prepay Flag';
Line: 17653

    UPDATE ap_invoice_distributions_all tax
    SET    tax.invoice_includes_prepay_flag = 'Y'
    WHERE  tax.invoice_id = p_invoice_header_rec.invoice_id
    AND    nvl(tax.invoice_includes_prepay_flag,'N') <> 'Y'
    AND    line_type_lookup_code in ('NONREC_TAX','REC_TAX','TIPV','TERV','TRV')
    AND    exists
    		(SELECT 1
	         FROM   ap_invoice_lines_all prepay
	         WHERE  prepay.invoice_id	     = tax.invoice_id
       	         AND    prepay.line_number	     = tax.invoice_line_number
	         AND    prepay.line_type_lookup_code = 'TAX'
	         AND    prepay.prepay_line_number    IS NOT NULL
	         AND    nvl(prepay.invoice_includes_prepay_flag,'N') = 'Y');
Line: 17680

   l_debug_info := 'Step 7.1: Select sum of dist amount for each ITEM line';
Line: 17688

     SELECT sum(amount) -- Select added for bug 6326552 to make sure
     INTO   l_dist_amt  -- sure that we update the distributions only once.
     FROM   ap_invoice_distributions_All
     WHERE  invoice_id =  p_invoice_header_rec.invoice_id
     AND    invoice_line_number = i.line_number
     AND    line_type_lookup_code IN ('ITEM',   --Bug6653070 Added SUM()
                                                 --instead of only amount
-- bug 7145041: add start
-- These lookup codes also have inclusive amount included in their amount.
			'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS','PREPAY');
Line: 17709

   l_debug_info := 'Step 7.3: Select sum of dist amount for each TAX line';
Line: 17718

     SELECT SUM(amount)         -- Select added for bug 6326552 to make sure
     INTO   l_tot_tax_amt       -- sure that we update the distributions if
                                --  if included tax amount is changed at
       			       --  line level.       .
     FROM   ap_invoice_distributions_All
     WHERE  invoice_id =  p_invoice_header_rec.invoice_id
     AND    invoice_line_number = i.line_number
     AND    line_type_lookup_code IN ('REC_TAX','NONREC_TAX','TRV','TERV','TIPV');
Line: 17755

      l_debug_info := 'Step 7.5: Update dist amount for each included TAX' ;
Line: 17762

      UPDATE ap_invoice_distributions_All aid1    --Bug6653070
        SET    aid1.amount = aid1.amount - nvl((SELECT SUM(nvl(amount,0))
                                  FROM ap_invoice_distributions_All aid2
                                 WHERE aid2.invoice_id =  p_invoice_header_rec.invoice_id
                                   AND aid2.invoice_line_number = i.line_number
                                   AND aid2.charge_applicable_to_dist_id = aid1.invoice_distribution_id
                                   AND aid2.line_type_lookup_code IN ('REC_TAX','NONREC_TAX', 'TIPV', 'TRV')
                                   AND EXISTS (SELECT 1
                                                 FROM zx_rec_nrec_dist zd1
                                                WHERE zd1.application_id =200
                                                  AND zd1.entity_code = 'AP_INVOICES'
                                                AND zd1.event_class_code IN ('STANDARD INVOICES','EXPENSE REPORTS','PREPAYMENT INVOICES')
                                                  AND zd1.trx_id = aid2.invoice_id
                                                  AND zd1.rec_nrec_tax_dist_id = aid2.detail_tax_dist_id
                                                  AND NVL(zd1.inclusive_flag,'N') = 'Y')),0),
               aid1.base_amount =aid1.base_amount- nvl((SELECT SUM(nvl(base_amount,0))
                                 FROM ap_invoice_distributions_All aid3
                                WHERE aid3.invoice_id =  p_invoice_header_rec.invoice_id
                                  AND aid3.invoice_line_number = i.line_number
					                        AND aid3.charge_applicable_to_dist_id = aid1.invoice_distribution_id
                                  AND aid3.line_type_lookup_code IN ('REC_TAX','NONREC_TAX', 'TIPV', 'TRV','TERV')
                                  AND EXISTS (SELECT 1
                                                FROM zx_rec_nrec_dist zd2
                                               WHERE zd2.application_id =200
                                                 AND zd2.entity_code = 'AP_INVOICES'
                                                AND zd2.event_class_code IN ('STANDARD INVOICES','EXPENSE REPORTS','PREPAYMENT INVOICES')
                                                 AND zd2.trx_id = aid3.invoice_id
                                                 AND zd2.rec_nrec_tax_dist_id = aid3.detail_tax_dist_id
                                                 AND NVL(zd2.inclusive_flag,'N') = 'Y')),0)
        WHERE  aid1.invoice_id =  p_invoice_header_rec.invoice_id
        AND    aid1.invoice_line_number = i.line_number
        AND    aid1.line_type_lookup_code IN ('ITEM', 'ACCRUAL', 'FREIGHT', 'MISCELLANEOUS');/*Bug7338249, bug9314506*/
Line: 17809

   l_debug_info := 'Step 8: Update parent_reversal_id and parent_ccid';
Line: 17823

           UPDATE ap_invoice_distributions_all
	   SET    parent_reversal_id       = l_reveral_dist_tab(h).parent_reversal_id
	         ,dist_code_combination_id = l_reveral_dist_tab(h).parent_ccid
           WHERE invoice_distribution_id   = l_reveral_dist_tab(h).invoice_distribution_id
             AND nvl(reversal_flag, 'N') <> 'Y';
Line: 17840

    l_reveral_dist_tab.delete ;
Line: 17850

           UPDATE ap_self_assessed_tax_dist_all
	   SET    parent_reversal_id       = l_reveral_dist_tab(h).parent_reversal_id
	         ,dist_code_combination_id = l_reveral_dist_tab(h).parent_ccid
           WHERE invoice_distribution_id   = l_reveral_dist_tab(h).invoice_distribution_id
             AND nvl(reversal_flag, 'N') <> 'Y';
Line: 17862

   l_debug_info := 'Step 9: Update reversal_flag';
Line: 17868

    UPDATE ap_invoice_distributions_all aid
       SET reversal_flag = (select reverse_flag
                              from zx_rec_nrec_dist zx
                             where zx.rec_nrec_tax_dist_id = aid.detail_tax_dist_id)
     WHERE aid.invoice_id = p_invoice_header_rec.invoice_id
       AND aid.detail_tax_dist_id IS NOT NULL;
Line: 17883

    UPDATE ap_self_assessed_tax_dist_all aid
       SET reversal_flag = (select reverse_flag
                              from zx_rec_nrec_dist zx
                             where zx.rec_nrec_tax_dist_id = aid.detail_tax_dist_id)
     WHERE aid.invoice_id = p_invoice_header_rec.invoice_id
       AND aid.detail_tax_dist_id IS NOT NULL;
Line: 17918

END Update_Distributions;
Line: 17943

        SELECT location_id
          INTO AP_ETAX_SERVICES_PKG.g_org_attributes(p_org_id).bill_to_location_id
          FROM hr_all_organization_units
         WHERE organization_id = p_org_id;
Line: 17979

        SELECT  hps.location_id
         INTO   AP_ETAX_SERVICES_PKG.g_site_attributes(p_vendor_site_id).location_id
                FROM hz_party_sites hps
        WHERE party_site_id = p_vendor_site_id;
Line: 17985

        SELECT  location_id
             ,fob_lookup_code
        INTO  AP_ETAX_SERVICES_PKG.g_site_attributes(p_vendor_site_id).location_id
             ,AP_ETAX_SERVICES_PKG.g_site_attributes(p_vendor_site_id).fob_lookup_code
        FROM ap_supplier_sites_all
        WHERE vendor_site_id = p_vendor_site_id;
Line: 18033

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

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

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

    l_debug_info := 'Step 2: Update existing exclusive tax lines';
Line: 18090

      UPDATE ap_invoice_lines_all ail
         SET
       (-- Bug 10157751 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
        /* Bug 10157751
        DECODE( ail.line_source,
		'MANUAL LINE ENTRY', ail.description,
		'IMPORTED'         , ail.description,
                zls.tax_regime_code||' - '||zls.tax ),		-- description : Bug 9383712 - Added DECODE
	*/
        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: 18195

    l_debug_info := 'Step 5: Insert exclusive tax lines';
Line: 18201

      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
        NVL( AI.description, zls.tax_regime_code||' - '||zls.tax ),	-- description    Bug 10157751
        '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);
Line: 18597

    l_debug_info := 'Step 8: Delete exclusive tax lines if required';
Line: 18603

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

    l_debug_info := 'Step 10: Update total_tax_amount and self_assessed tax';
Line: 18641

      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', case when exists (SELECT 'Prepay App Exists'
                                          FROM ap_invoice_lines_all prepay
                                         WHERE prepay.invoice_id = zls.trx_id
                                         AND prepay.line_type_lookup_code = 'PREPAY'
                                         AND prepay.prepay_invoice_id  = zls.applied_from_trx_id
                                         AND prepay.prepay_line_number = zls.applied_from_line_id
                                         AND prepay.invoice_includes_prepay_flag = 'Y'
                                         AND (prepay.discarded_flag is null
                                           or prepay.discarded_flag = 'N')) THEN
                                           0
                                        ELSE NVL(zls.tax_amt, 0) end,
                                       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: 18691

    l_debug_info := 'Step 12: Update Invoice Includes Prepay Flag';
Line: 18698

   UPDATE ap_invoice_lines_all tax
     SET tax.invoice_includes_prepay_flag = CASE WHEN 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'
                             AND (prepay.discarded_flag is null or
                                 prepay.discarded_flag = 'N')) THEN
                               'Y'
                            ELSE
                              'N'
                            END /*added the case for bug 8638881*/
   WHERE tax.invoice_id = P_Invoice_Header_Rec.Invoice_Id
    AND tax.line_type_lookup_code = 'TAX'
    AND tax.prepay_invoice_id is not null;
Line: 18751

      l_api_name                   CONSTANT VARCHAR2(100) := 'Update';
Line: 18774

             SELECT
                  (CASE
                        WHEN ai.invoice_type_lookup_code IN('STANDARD' , 'CREDIT' , 'DEBIT' ,
                              'MIXED' , 'ADJUSTMENT' , 'PO PRICE ADJUST' , 'INVOICE REQUEST' ,
                              'CREDIT MEMO REQUEST' , 'RETAINAGE RELEASE','PAYMENT REQUEST')--Bug9122724
                        THEN 'STANDARD INVOICES'
                        WHEN(ai.invoice_type_lookup_code='PREPAYMENT')
                        THEN 'PREPAYMENT INVOICES'
                        WHEN ai.invoice_type_lookup_code='EXPENSE REPORT'
                        THEN 'EXPENSE REPORTS'
                  END) event_class_code
                ,
                  (CASE
                        WHEN ai.invoice_type_lookup_code IN('STANDARD' , 'CREDIT' , 'DEBIT' ,
                              'MIXED' , 'ADJUSTMENT' , 'PO PRICE ADJUST' , 'INVOICE REQUEST' ,
                              'CREDIT MEMO REQUEST' , 'RETAINAGE RELEASE','PAYMENT REQUEST')--Bug9122724
                        THEN 'STANDARD '
                        WHEN(ai.invoice_type_lookup_code='PREPAYMENT')
                        THEN 'PREPAYMENT '
                        WHEN ai.invoice_type_lookup_code='EXPENSE REPORT'
                        THEN 'EXPENSE REPORT '
                  END) || 'UPDATED' event_type_code
                , ai.invoice_id trx_id
                , ai.invoice_num trx_number
                , SUBSTRB(ai.description , 1 , 240) trx_description
                , ai.doc_sequence_id doc_seq_id
                , doc.name doc_seq_name
                , ai.doc_sequence_value doc_seq_value
                , ai.batch_id batch_source_id
                , NULL batch_source_name
                , NULL trx_type_description
                , ai.invoice_date trx_communicated_date
                , ai.terms_date trx_due_date
                , ai.supplier_tax_invoice_number supplier_tax_invoice_number
                , ai.supplier_tax_invoice_date supplier_tax_invoice_date
                , ai.supplier_tax_exchange_rate supplier_exchange_rate
                , ai.tax_invoice_internal_seq tax_invoice_number
                , ai.tax_invoice_recording_date tax_invoice_date
                , ai.tax_invoice_internal_seq tax_invoice_number
                , ai.invoice_type_lookup_code
                , ai.quick_credit
                , ai.credited_invoice_id
               FROM ap_invoices_all ai
                   , fnd_document_sequences doc
              WHERE ai.invoice_id=p_invoice_id
                AND ai.doc_sequence_id=doc.doc_sequence_id (+);
Line: 19077

           SELECT line_type_lookup_code,detail_tax_dist_id,
                  invoice_distribution_id,related_id
             INTO l_line_type_lookup_code,l_detail_tax_dist_id,
                  l_inv_dist_id,l_related_id
             FROM ap_invoice_distributions_all
            WHERE invoice_id               = p_invoice_id
              AND distribution_line_number = p_distribution_line_number
              AND invoice_line_number      = p_invoice_line_number;