DBA Data[Home] [Help]

APPS.JL_AR_AP_WITHHOLDING_PKG SQL Statements

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

Line: 31

                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null);
Line: 44

 *              (AutoSelect/Build Payment Stage)                          *
 *              Processing units to be executed:                          *
 *              1. Create Temporary Distribution Lines                    *
 *                                                                        *
 **************************************************************************/
PROCEDURE Do_AWT_Build_Payment_Batch
                    (P_Checkrun_Name            IN     Varchar2,
                     p_Checkrun_id              IN     Number,
                     P_Calling_Module           IN     Varchar2,
                     P_Calling_Sequence         IN     Varchar2,
                     P_AWT_Success              OUT NOCOPY    Varchar2,
                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null);
Line: 78

                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null);
Line: 92

 *              It also updates buckets and credit letter amounts.        *
 *                                                                        *
 **************************************************************************/
PROCEDURE Calculate_AWT_Amounts
                    (P_Checkrun_Name            IN     Varchar2,
                     P_Checkrun_ID              IN     Number,
                     P_Check_Id                 IN     Number,
                     P_Selected_Check_Id        IN     Number,
                     P_AWT_Date                 IN     Date,
                     P_Calling_Module           IN     Varchar2,
                     P_Calling_Sequence         IN     Varchar2,
                     P_Total_Wh_Amount          OUT NOCOPY    Number,
                     P_AWT_Success              OUT NOCOPY    Varchar2,
                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null);
Line: 152

       P_Selected_Check_Id      IN     Number,
       P_Calling_Sequence       IN     Varchar2,
       P_Tab_Withhold           IN OUT NOCOPY Jl_Zz_Ap_Withholding_Pkg.Tab_Withholding,
       P_Total_Wh_Amount        IN OUT NOCOPY Number,
       P_AWT_Success            OUT NOCOPY    Varchar2,
       P_Last_Updated_By        IN     Number     Default null,
       P_Last_Update_Login      IN     Number     Default null,
       P_Program_Application_Id IN     Number     Default null,
       P_Program_Id             IN     Number     Default null,
       P_Request_Id             IN     Number     Default null,
       P_Calling_Module         IN     Varchar2   Default null,
       P_Checkrun_Name          IN     Varchar2   Default null,
       P_Checkrun_ID            IN     Number     Default null,
       P_Payment_Num            IN     Number     Default null);
Line: 184

                      P_Selected_Check_Id        IN     Number,
                      P_Currency_Code            IN     Varchar2,
                      P_Tab_Inv_Amounts          IN OUT NOCOPY Tab_Amounts,
                      P_Calling_Module           IN     Varchar2,
                      P_Calling_Sequence         IN     Varchar2);
Line: 233

 * Name       : Update_Credit_Letter                                      *
 * Purpose    : Updates the withheld amount for each tax name contained   *
 *              into the PL/SQL table. The credit letters table is also   *
 *              updated                                                   *
 *                                                                        *
 **************************************************************************/
PROCEDURE Update_Credit_Letter
      (P_Vendor_Id              IN     Number,
       P_Rec_AWT_Type           IN     jl_zz_ap_awt_types%ROWTYPE,
       P_AWT_Date               IN     Date,
       P_Payment_Num            IN     Number,
       P_Check_Id               IN     Number,
       P_Selected_Check_Id      IN     Number,
       P_Calling_Sequence       IN     Varchar2,
       P_Tab_Withhold           IN OUT NOCOPY Jl_Zz_Ap_Withholding_Pkg.Tab_Withholding,
       P_Last_Updated_By        IN     Number     Default null,
       P_Last_Update_Login      IN     Number     Default null,
       P_Program_Application_Id IN     Number     Default null,
       P_Program_Id             IN     Number     Default null,
       P_Request_Id             IN     Number     Default null);
Line: 259

 * Name       : Insert_Credit_Letter_Amount                               *
 * Purpose    : Stores current information about credit letters into the  *
 *              JL_AR_AP_SUP_AWT_CR_LTS table                             *
 *                                                                        *
 **************************************************************************/
PROCEDURE Insert_Credit_Letter_Amount
                (P_Vendor_Id               IN     Number,
                 P_AWT_Type_Code           IN     Varchar2,
                 P_Tax_Id                  IN     Number,
                 P_AWT_Date                IN     Date,
                 P_Withheld_Amount         IN     Number,
                 P_Actual_Withheld_Amount  IN     Number,
                 P_Balance                 IN     Number,
                 P_Status                  IN     Varchar2,
                 P_Payment_Num             IN     Number,
                 P_Check_Id                IN     Number,
                 P_Selected_Check_Id       IN     Number,
                 P_Calling_Sequence        IN     Varchar2,
                 P_Last_Updated_By         IN     Number     Default null,
                 P_Last_Update_Login       IN     Number     Default null,
                 P_Program_Application_Id  IN     Number     Default null,
                 P_Program_Id              IN     Number     Default null,
                 P_Request_Id              IN     Number     Default null);
Line: 296

                 P_Selected_Check_Id       IN     Number,
                 P_AWT_Date                IN     Date,
                 P_Payment_Num             IN     Number,
                 P_Calling_Sequence        IN     Varchar2,
                 P_Last_Updated_By         IN     Number     Default null,
                 P_Last_Update_Login       IN     Number     Default null,
                 P_Program_Application_Id  IN     Number     Default null,
                 P_Program_Id              IN     Number     Default null,
                 P_Request_Id              IN     Number     Default null);
Line: 311

 * Name       : Update_Quick_Payment                                      *
 * Purpose    : Updates the payment amount by subtracting the withheld    *
 *              amount.                                                   *
 *                                                                        *
 **************************************************************************/
PROCEDURE Update_Quick_Payment
                    (P_Check_Id                 IN     Number,
                     P_Calling_Sequence         IN     Varchar2);
Line: 325

 * Name       : Update_Payment_Batch                                      *
 * Purpose    : Updates the amounts of the payment batch by subtracting   *
 *              the withholding amount.                                   *
 *                                                                        *
 **************************************************************************/
PROCEDURE Update_Payment_Batch
                (P_Checkrun_Name           IN     Varchar2,
                 p_checkrun_id             IN     Number,
                 P_Selected_Check_Id       IN     Number,
                 P_Calling_Sequence        IN     Varchar2);
Line: 384

                  P_Selected_Check_Id    IN     Number,
                  P_Calling_Module       IN     Varchar2,
                  P_Total_Wh_Amount      IN     Number,
                  P_Calling_Sequence     IN     Varchar2,
                  P_Vendor_Name          OUT NOCOPY    Varchar2,
                  P_Vendor_Site_Code     OUT NOCOPY    Varchar2)
                  RETURN Boolean;
Line: 398

 * Purpose    : Updates the credit letters table in order to store the    *
 *              the final check ID, when users confirm a payment batch.   *
 *              This procedure is not called for Quick Payments because   *
 *              the check ID is known from the begining.                  *
 *                                                                        *
 **************************************************************************/
PROCEDURE Confirm_Credit_Letters
                (P_Checkrun_Name           IN     Varchar2,
                 P_Checkrun_ID             IN     Number,
                 P_Calling_Sequence        IN     Varchar2);
Line: 413

 * Purpose    : Sets the "Ok To Pay" flag for all the selected invoices   *
 *              within the payment when the calculation routine is not    *
 *              successful                                                *
 *                                                                        *
 **************************************************************************/
PROCEDURE Reject_Payment_Batch
                (P_Selected_Check_Id       IN     Number,
                 P_AWT_Success             IN     Varchar2,
                 P_Calling_Sequence        IN     Varchar2);
Line: 447

               P_Last_Updated_By        IN     Number,
               P_Last_Update_Login      IN     Number,
               P_Program_Application_Id IN     Number     Default null,
               P_Program_Id             IN     Number     Default null,
               P_Request_Id             IN     Number     Default null,
               P_Awt_Success            OUT NOCOPY    Varchar2,
               P_Invoice_Payment_Id     IN     Number     Default null,
               P_Check_Id               IN     Number     Default null)
IS

    l_debug_info             Varchar2(300);
Line: 510

                              P_Last_Updated_By,
                              P_Last_Update_Login,
                              P_Program_Application_Id,
                              P_Program_Id,
                              P_Request_Id);
Line: 536

    * (AutoSelect/Build Payment Stage)                     *
    * ---------------------------------------------------- *
    * Processing units to be executed:                     *
    * 1. Create Temporary Distribution Lines               *
    *                                                      *
    ********************************************************/
    ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
        l_debug_info := 'Calculating Withholding for Payment Batch (Build)';
Line: 555

                            P_Last_Updated_By,
                            P_Last_Update_Login,
                            P_Program_Application_Id,
                            P_Program_Id,
                            P_Request_Id);
Line: 591

                            P_Last_Updated_By,
                            P_Last_Update_Login,
                            P_Program_Application_Id,
                            P_Program_Id,
                            P_Request_Id);
Line: 654

               P_Last_Updated_By        IN     Number,
               P_Last_Update_Login      IN     Number,
               P_Program_Application_Id IN     Number     Default null,
               P_Program_Id             IN     Number     Default null,
               P_Request_Id             IN     Number     Default null)
IS

    ------------------------------
    -- Local variables definition
    ------------------------------
    l_check_id               Number;
Line: 666

    l_selected_check_id      Number;
Line: 693

    SELECT apip.check_id        check_id,
           apip.payment_num     payment_num,
               apip.invoice_id      invoice_id
    INTO   l_check_id,
           l_payment_num,
               l_invoice_id
    FROM   ap_invoice_payments apip
    WHERE  apip.invoice_payment_id = P_Parent_Id;
Line: 703

    select ac.payment_id
    into   l_payment_id
    from   ap_checks ac
    where  ac.check_id = l_check_id;
Line: 720

                        null,              -- Selected Check Id
                        P_Undo_AWT_Date,
                        l_payment_num,
                        l_calling_sequence,
                        P_Last_Updated_By,
                        P_Last_Update_Login,
                        P_Program_Application_Id,
                        P_Program_Id,
                        P_Request_Id);
Line: 755

    UPDATE ap_invoice_distributions
       SET Global_Attribute5 = 0
     WHERE invoice_id = l_invoice_id
       and nvl(to_number(Global_Attribute5),0) > 0;
Line: 815

        p_selected_check_id     IN     Number,
        P_Calling_Sequence      IN     Varchar2)
IS


-----------VARIABLES-----------
    l_debug_info                Varchar2(300);
Line: 826

    l_selected_check_id         Number;
Line: 842

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameter: p_selected_check_id='||to_char(p_selected_check_id));
Line: 846

     UPDATE     jl_ar_ap_awt_certif
     set     status = 'VOID'
     where   checkrun_name   =      p_checkrun_name
     and   check_number    NOT IN (
           SELECT apsi.check_number
           FROM   ap_selected_invoice_checks   apsi
           WHERE  apsi.checkrun_name = P_Checkrun_Name
           AND   (apsi.status_lookup_code ='NEGOTIABLE' or apsi.status_lookup_code='ISSUED') );
Line: 899

               P_Last_Updated_By        IN     Number,
               P_Last_Update_Login      IN     Number,
               P_Program_Application_Id IN     Number     Default null,
               P_Program_Id             IN     Number     Default null,
               P_Request_Id             IN     Number     Default null)
IS

    -------------------------------
    -- Local variables definition
    -------------------------------
    l_selected_check_id      Number;
Line: 916

    CURSOR c_selected_invoices (P_Invoice_Id    IN     Number,
                                P_Payment_Num   IN     Number,
                                P_Checkrun_Name IN     Varchar2)
    IS
    SELECT Ihd.Payment_id  selected_check_id
    FROM   IBY_Hook_Docs_in_PMT_T ihd
    WHERE  ihd.calling_app_doc_unique_ref2  = P_Invoice_Id
    AND    ihd.calling_app_doc_unique_ref3  = P_Payment_Num
    AND    ihd.calling_App_doc_unique_ref1  = P_Checkrun_ID
    AND    ihd.calling_app_id = 200 ;
Line: 948

    OPEN c_selected_invoices (P_Invoice_Id, P_Payment_Num, P_Checkrun_Name);
Line: 950

        FETCH c_selected_invoices INTO l_selected_check_id;
Line: 951

        EXIT WHEN c_selected_invoices%NOTFOUND;
Line: 958

                            l_selected_check_id,
                            P_Undo_AWT_Date,
                            P_Payment_Num,
                            l_calling_sequence,
                            P_Last_Updated_By,
                            P_Last_Update_Login,
                            P_Program_Application_Id,
                            P_Program_Id,
                            P_Request_Id);
Line: 971

	        JL_ZZ_AP_EXT_AWT_UTIL.Debug ('After Cursor c_selected_invoices');
Line: 974

    CLOSE c_selected_invoices;
Line: 993

    If (P_Calling_Module='CANCEL') or (P_Calling_Module = 'AUTOSELECT') then
      JL_AR_AP_WITHHOLDING_PKG.JL_AR_AP_VOID_SELEC_CERTIF(p_checkrun_name,
                                                          l_selected_check_id,
                                                          l_calling_sequence);
Line: 1069

   select pmt.payment_id
   from   iby_fd_payments_v pmt
   where  pmt.payment_instruction_id = p_pmt_instruction_id
   and    pmt.payment_status ='REMOVED_DOCUMENT_SPOILED' ;
Line: 1075

   select pmt.payment_id
   from   iby_fd_payments_v pmt
   where  pmt.payment_instruction_id = p_pmt_instruction_id
   and    pmt.payment_status ='READY_TO_REPRINT';
Line: 1082

   select pmt.payment_id
   from   iby_fd_payments_v pmt
   where  pmt.payment_instruction_id = p_pmt_instruction_id ;
Line: 1216

                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null)
IS

    ------------------------------
    -- Local variables definition
    ------------------------------
    l_create_distr           Varchar2(25);
Line: 1250

    SELECT apin.invoice_id              invoice_id,
           apin.invoice_currency_code   invoice_currency_code,
           apip.payment_num             payment_num
    FROM   ap_invoice_payments apip,
           ap_invoices         apin
    WHERE  apin.invoice_id = apip.invoice_id
    AND    apip.check_id = P_Check_Id;
Line: 1285

    Select payment_type_flag
      into l_payment_type
      from ap_checks
     where check_id = P_Check_id;
Line: 1339

                           P_Last_Updated_By,
                           P_Last_Update_Login,
                           P_Program_Id,
                           P_Request_Id);
Line: 1415

                             P_Last_Updated_By,
                             P_Last_Update_Login,
                             P_Program_Application_Id,
                             P_Program_Id,
                             P_Request_Id,
                             l_calling_sequence,
       -- Payment Exchange Rate ER 8648739 Start
                             P_Check_Id);
Line: 1447

                             P_Last_Updated_By,
                             P_Last_Update_Login,
                             P_Program_Application_Id,
                             P_Program_Id,
                             P_Request_Id,
                             l_calling_sequence);
Line: 1480

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('==> Calling Update_Quick_Payment');
Line: 1484

    Update_Quick_Payment (P_Check_Id,
                          l_calling_sequence);
Line: 1526

 *              (AutoSelect/Build Payment Stage)                          *
 *              Processing units to be executed:                          *
 *              1. Create Temporary Distribution Lines                    *
 *                                                                        *
 **************************************************************************/
PROCEDURE Do_AWT_Build_Payment_Batch
                    (P_Checkrun_Name            IN     Varchar2,
                       P_Checkrun_ID              IN     Number,
                     P_Calling_Module           IN     Varchar2,
                     P_Calling_Sequence         IN     Varchar2,
                     P_AWT_Success              OUT NOCOPY    Varchar2,
                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null)
IS
    ------------------------------------------------
    -- Cursor to select all the checks ID included
    -- within the payment batch
    ------------------------------------------------
    CURSOR c_selected_checks (P_Checkrun_Name Varchar2)
    IS
/*    SELECT apsic.selected_check_id selected_check_id
    FROM   ap_selected_invoice_checks   apsic
    WHERE  apsic.checkrun_name = P_Checkrun_Name;*/
Line: 1553

   SELECT ipmt.payment_id payment_id, ipmt.payment_date
   from IBY_HOOK_PAYMENTS_T ipmt
   where ipmt.call_app_pay_service_req_code   = P_Checkrun_Name
   and   ipmt.calling_app_id= 200;
Line: 1561

    rec_selected_checks      c_selected_checks%ROWTYPE;
Line: 1622

/*    SELECT apisc.check_date
    INTO   l_awt_date
    FROM   ap_invoice_selection_criteria apisc
    WHERE  apisc.checkrun_name = P_Checkrun_Name;
Line: 1628

   SELECT payment_date
   INTO l_awt_date
   FROM IBY_HOOK_PAYMENTS_T ipmt
   WHERE ipmt.call_app_pay_service_req_code  = P_Checkrun_Name
   AND   ipmt.calling_app_id=200;
Line: 1639

    OPEN c_selected_checks (P_Checkrun_Name);
Line: 1643

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Looping thru c_selected_checks');
Line: 1648

        FETCH c_selected_checks INTO rec_selected_checks;
Line: 1649

        EXIT WHEN c_selected_checks%NOTFOUND;
Line: 1666

                               rec_selected_checks.payment_id,
                               rec_selected_checks.payment_date,
                               P_Calling_Module,
                               l_calling_sequence,
                               l_total_wh_amount,
                               P_AWT_Success,
                               P_Last_Updated_By,
                               P_Last_Update_Login,
                               P_Program_Id,
                               P_Request_Id);
Line: 1693

            Reject_Payment_Batch (rec_selected_checks.payment_id,
                                  P_AWT_Success,
                                  l_calling_sequence);
Line: 1702

                                       rec_selected_checks.payment_id,
                                       P_Calling_Module,
                                       l_total_wh_amount,
                                       l_calling_sequence,
                                       l_vendor_name,
                                       l_vendor_site_code)) THEN
             --                          l_payment_amount))     Bug# 2807464
             --  AND l_payment_amount > 0 THEN --- Bug 2157401  Bug# 2807464

            -- Debug Information
            IF (DEBUG_Var = 'Y') THEN
               JL_ZZ_AP_EXT_AWT_UTIL.Debug (' ==> Calling - NOT Partial_Payment_Paid_In_Full');
Line: 1730

            Reject_Payment_Batch (rec_selected_checks.payment_id,
                                  P_AWT_Success,
                                  l_calling_sequence);
Line: 1742

               JL_ZZ_AP_EXT_AWT_UTIL.Debug (' ==> Calling Update_Payment_Batch');
Line: 1744

               JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameter: rec_selected_checks.selected_check_id = '||
                                                         to_char(rec_selected_checks.payment_id));
Line: 1749

            Update_Payment_Batch (P_Checkrun_Name,
                                  p_checkrun_id,
                                  rec_selected_checks.payment_id,
                                  l_calling_sequence);
Line: 1760

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Close Cursor c_selected_checks');
Line: 1764

    CLOSE c_selected_checks;
Line: 1820

                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null)
IS
    -------------------------------
    -- Local Variables Definition
    -------------------------------
    l_create_distr           Varchar2(25);
Line: 1839

/*    CURSOR c_selected_invoices (P_Checkrun_Name IN Varchar2)
    IS
    SELECT apsi.invoice_id                invoice_id,
           apsi.payment_num               payment_num,
           apin.invoice_currency_code     invoice_curr_code
    FROM   ap_selected_invoices           apsi,
           ap_selected_invoice_checks     apsic,
unique_ref2 invoice_id,
          docs.calling_app_doc_uniq
           ap_invoices                    apin
    WHERE  apsic.checkrun_name           = P_Checkrun_Name
    AND    apsi.checkrun_name            = P_Checkrun_Name
    AND   (apsic.status_lookup_code      = 'NEGOTIABLE'
        OR apsic.status_lookup_code      = 'ISSUED')
    AND    apsic.selected_check_id       = apsi.pay_selected_check_id
    AND    nvl(apsi.ok_to_pay_flag, 'Y') = 'Y'
    AND    apin.invoice_id               = apsi.invoice_id
    AND    apsi.original_invoice_id IS NULL;
Line: 1860

 CURSOR c_selected_invoices (p_checkrun_id IN NUMBER) IS
   SELECT docs.calling_app_doc_unique_ref2 invoice_id,
          docs.calling_app_doc_unique_ref3 payment_num,
          docs.document_currency_code invoice_curr_code,
          docs.payment_date,
          docs.org_id
   FROM IBY_FD_PAYMENTS_V ipmt,
        IBY_FD_DOCS_PAYABLE_V  docs
   WHERE to_number(docs.calling_app_doc_unique_ref1) = p_checkrun_id
   AND   ipmt.payment_id = docs.payment_id
   AND   (ipmt.payment_status      = 'NEGOTIABLE'
        OR ipmt.payment_status      = 'ISSUED'
        OR ipmt.payment_status      = 'FORMATTED'
        OR ipmt.payment_status      = 'TRANSMITTED'
        OR ipmt.payment_status      = 'ACKNOWLEDGED'
        OR ipmt.payment_status      = 'BANK_VALIDATED'
        OR ipmt.payment_status      = 'PAID')
   AND   ipmt.payments_complete_flag ='Y'
   AND   docs.calling_app_id= 200;
Line: 1883

    rec_sel_inv   c_selected_invoices%ROWTYPE;
Line: 1912

    OPEN c_selected_invoices (P_Checkrun_ID);
Line: 1916

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Looping Thru c_selected_invoices');
Line: 1921

        FETCH c_selected_invoices INTO rec_sel_inv;
Line: 1922

        EXIT WHEN c_selected_invoices%NOTFOUND;
Line: 1952

       SELECT  nvl(create_awt_dists_type, 'NEVER'),
               nvl(create_awt_invoices_type, 'NEVER')
       INTO    l_create_distr,
               l_create_invoices
       FROM    ap_system_parameters_all
       WHERE   org_id = rec_sel_inv.org_id;
Line: 1974

   /*    SELECT apisc.check_date
       INTO   l_awt_date
       FROM   ap_invoice_selection_criteria apisc
       WHERE  apisc.checkrun_name = P_Checkrun_Name;
Line: 1997

                                 P_Last_Updated_By,
                                 P_Last_Update_Login,
                                 P_Program_Application_Id,
                                 P_Program_Id,
                                 P_Request_Id,
                                 l_calling_sequence);
Line: 2025

                                     P_Last_Updated_By,
                                     P_Last_Update_Login,
                                     P_Program_Application_Id,
                                     P_Program_Id,
                                     P_Request_Id,
                                     l_calling_sequence);
Line: 2039

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Close Cursor c_selected_invoices');
Line: 2043

    CLOSE c_selected_invoices;
Line: 2091

 *              It also updates buckets and credit letter amounts.        *
 *                                                                        *
 **************************************************************************/
PROCEDURE Calculate_AWT_Amounts
                    (P_Checkrun_Name            IN     Varchar2,
                     P_Checkrun_ID              IN     Number,
                     P_Check_Id                 IN     Number,
                     P_Selected_Check_Id        IN     Number,
                     P_AWT_Date                 IN     Date,
                     P_Calling_Module           IN     Varchar2,
                     P_Calling_Sequence         IN     Varchar2,
                     P_Total_Wh_Amount          OUT NOCOPY    Number,
                     P_AWT_Success              OUT NOCOPY    Varchar2,
                     P_Last_Updated_By          IN     Number     Default null,
                     P_Last_Update_Login        IN     Number     Default null,
                     P_Program_Application_Id   IN     Number     Default null,
                     P_Program_Id               IN     Number     Default null,
                     P_Request_Id               IN     Number     Default null)
IS
    ------------------------
    -- Variables Definition
    ------------------------
    l_previous_awt_type_code    Varchar2(30);
Line: 2139

    SELECT
       jlst.awt_type_code                         awt_type_code,
       jlsc.tax_id                                tax_id,
       apin.invoice_id                            invoice_id,
       apin.vendor_id                             vendor_id,
       apid.invoice_distribution_id               invoice_distribution_id, -- Lines
       nvl(apin.invoice_amount, apin.base_amount) invoice_amount,
       -- Payment Exchange Rate ER 8648739 Start 1
       -- nvl(apid.base_amount, apid.amount)         line_amount,
       (apid.amount * nvl(apip.exchange_rate,1))  line_amount,
       -- Payment Exchange Rate ER 8648739 End 1
       apip.amount                                payment_amount,
       apip.invoice_payment_id                    invoice_payment_id,
       apip.payment_num                           payment_num,
       jlty.taxable_base_amount_basis             tax_base_amount_basis
    FROM
       jl_zz_ap_inv_dis_wh         jlwh,
       ap_invoices                 apin,
       ap_invoice_distributions    apid,
       ap_invoice_payments         apip,
       jl_zz_ap_supp_awt_types     jlst,
       jl_zz_ap_sup_awt_cd         jlsc,
       jl_zz_ap_awt_types          jlty
    WHERE
           apid.invoice_id               = jlwh.invoice_id
    -- AND    apid.distribution_line_number = jlwh.distribution_line_number - Lines 4382256
    AND    apid.invoice_distribution_id  = jlwh.invoice_distribution_id -- Lines
    AND    apin.invoice_id               = apid.invoice_id
    AND    apin.invoice_id               = apip.invoice_id
    AND    jlwh.supp_awt_code_id         = jlsc.supp_awt_code_id
    AND    jlsc.supp_awt_type_id         = jlst.supp_awt_type_id
    AND    jlst.awt_type_code            = jlty.awt_type_code
    AND    apip.check_id                 = P_Check_Id
    -- added recently
    AND    NVL(apid.REVERSAL_FLAG,'N') <> 'Y'
    AND    NVL(apip.ACCOUNTING_DATE,sysdate) between                                  -- Argentina AWT ER 6624809
 	                 NVL(jlsc.effective_start_date,To_Date('01-01-1950', 'DD-MM-YYYY'))
 	             and NVL(jlsc.effective_end_date,To_Date('31-12-9999', 'DD-MM-YYYY'))
    ORDER BY
           to_number(decode(jlty.taxable_base_amount_basis, 'INVOICE',
                                                             apin.invoice_id,
                                                             DUMMY_INVOICE_ID)),
           jlst.awt_type_code,
           jlsc.tax_id,
           apin.invoice_id,
           apip.invoice_payment_id;
Line: 2187

    SELECT
       jlst.awt_type_code                         awt_type_code,
       jlsc.tax_id                                tax_id,
       apin.invoice_id                            invoice_id,
       apin.vendor_id                             vendor_id,
       apid.invoice_distribution_id               invoice_distribution_id,  -- Lines
       nvl(apin.invoice_amount, apin.base_amount) invoice_amount,
       nvl(apid.base_amount, apid.amount)         line_amount,
 --       apsi.payment_amount                     payment_amount,
       docs.document_amount                       payment_amount,
       null                                       invoice_payment_id,
  --     apsi.payment_num                           payment_num,
        to_number(docs.calling_app_doc_unique_ref3)          payment_num,
       jlty.taxable_base_amount_basis             tax_base_amount_basis
    FROM
       jl_zz_ap_inv_dis_wh         jlwh,
       ap_invoices                 apin,
       ap_invoice_distributions    apid,
       iby_hook_docs_in_pmt_t      docs,
       jl_zz_ap_supp_awt_types     jlst,
       jl_zz_ap_sup_awt_cd         jlsc,
       jl_zz_ap_awt_types          jlty
    WHERE  docs.payment_id = P_Check_Id
    AND apid.invoice_id    = jlwh.invoice_id
 -- AND    apid.distribution_line_number = jlwh.distribution_line_number - Lines 4382256
    AND    apid.invoice_distribution_id  = jlwh.invoice_distribution_id -- Lines
    AND    apin.invoice_id               = apid.invoice_id
    AND    apin.invoice_id    = to_number(docs.calling_app_doc_unique_ref2)
    AND    jlwh.supp_awt_code_id         = jlsc.supp_awt_code_id
    AND    jlsc.supp_awt_type_id         = jlst.supp_awt_type_id
    AND    jlst.awt_type_code            = jlty.awt_type_code
    AND    docs.dont_pay_flag  = 'N'
    AND    docs.calling_app_id =200
     ORDER BY
           to_number(decode(jlty.taxable_base_amount_basis, 'INVOICE',
                                                             apin.invoice_id,
                                                             DUMMY_INVOICE_ID)),
           jlst.awt_type_code,
           jlsc.tax_id,
           docs.calling_app_doc_unique_ref2,
           docs.calling_app_doc_unique_ref3;
Line: 2242

    CURSOR c_payment_batch_withholdings (P_Selected_Check_Id  Number)
    IS
    SELECT distinct jlst.awt_type_code            awt_type_code,  --bug 12613506
       jlsc.tax_id                                tax_id,
       apin.invoice_id                            invoice_id,
       apin.vendor_id                             vendor_id,
       apid.invoice_distribution_id               invoice_distribution_id,  -- Lines
       nvl(apin.invoice_amount, apin.base_amount) invoice_amount,
       -- Payment Exchange Rate ER 8648739 Start 2
       -- nvl(apid.base_amount, apid.amount)         line_amount,
       (apid.amount * nvl(apsi.payment_exchange_rate,1)) line_amount,
       -- Payment Exchange Rate ER 8648739 End 2
 --       apsi.payment_amount                     payment_amount,
       docs.document_amount                       payment_amount,
       null                                       invoice_payment_id,
  --     apsi.payment_num                           payment_num,
        to_number(docs.calling_app_doc_unique_ref3)          payment_num,
       jlty.taxable_base_amount_basis             tax_base_amount_basis
    FROM
       jl_zz_ap_inv_dis_wh         jlwh,
       ap_invoices                 apin,
       ap_invoice_distributions    apid,
       -- Payment Exchange Rate ER 8648739 Start 3
       ap_selected_invoices        apsi,
       -- Payment Exchange Rate ER 8648739 End 3
       iby_hook_docs_in_pmt_t      docs,
       jl_zz_ap_supp_awt_types     jlst,
       jl_zz_ap_sup_awt_cd         jlsc,
       jl_zz_ap_awt_types          jlty
    WHERE  docs.payment_id = P_Selected_Check_Id
    AND apid.invoice_id    = jlwh.invoice_id
 -- AND    apid.distribution_line_number = jlwh.distribution_line_number - Lines 4382256
    AND    apid.invoice_distribution_id  = jlwh.invoice_distribution_id -- Lines
    AND    apin.invoice_id               = apid.invoice_id
--     AND    apin.invoice_id               = apsi.invoice_id
    AND    apin.invoice_id    = to_number(docs.calling_app_doc_unique_ref2)
    AND    jlwh.supp_awt_code_id         = jlsc.supp_awt_code_id
    AND    jlsc.supp_awt_type_id         = jlst.supp_awt_type_id
    AND    jlst.awt_type_code            = jlty.awt_type_code
    AND    docs.dont_pay_flag  = 'N'
    AND    docs.calling_app_id =200
        -- added recently
    AND    NVL(apid.REVERSAL_FLAG,'N') <> 'Y'
--   AND    apsi.pay_selected_check_id    = P_Selected_Check_Id
--   AND    nvl(apsi.ok_to_pay_flag, 'Y') = 'Y'
--    AND    apsi.original_invoice_id IS NULL
    -- Payment Exchange Rate ER 8648739 Start 4
    AND apsi.invoice_id = docs.calling_app_doc_unique_ref2
    -- Payment Exchange Rate ER 8648739 End 4
     ORDER BY
           to_number(decode(jlty.taxable_base_amount_basis, 'INVOICE',
                                                             apin.invoice_id,
                                                             DUMMY_INVOICE_ID)),
           jlst.awt_type_code,
           jlsc.tax_id,
           apin.invoice_id,  --bug 12613506
           payment_num;  --bug 12613506
Line: 2332

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameters: P_Selected_Check_Id : '||to_char(P_Selected_Check_Id));
Line: 2377

                                    P_Selected_Check_Id,
                                    l_base_currency_code,
                                    tab_inv_amounts,
                                    P_Calling_Module,
                                    l_calling_sequence);
Line: 2421

    ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
        OPEN c_payment_batch_withholdings (P_Selected_Check_Id);
Line: 2426

           JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Open Cursor c_payment_batch_withholdings for AutoSelect');
Line: 2485

       select TO_DATE(apip.ACCOUNTING_DATE, 'DD-MM-YYYY') into l_CODE_ACCOUNTING_DATE          -- Argentina AWT ER
 	     from ap_invoice_payments apip
 	     where apip.INVOICE_PAYMENT_ID = rec_payment_wh.invoice_payment_id;
Line: 2494

      SELECT TO_DATE (apip.accounting_date, 'DD-MM-YYYY')
        INTO l_code_accounting_date                        -- Argentina AWT ER
        FROM ap_invoice_payments apip
       WHERE apip.invoice_payment_id = rec_payment_wh.invoice_payment_id;
Line: 2498

    ELSIF (p_calling_module = 'AUTOSELECT') then
       SELECT TO_DATE (apsc.check_date, 'DD-MM-YYYY')
        INTO l_code_accounting_date                        -- Argentina AWT ER
        FROM ap_inv_selection_criteria_all apsc
       WHERE apsc.checkrun_id = p_checkrun_id;
Line: 2549

        ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
            l_not_found := c_payment_batch_withholdings%NOTFOUND;
Line: 2607

                                  P_Selected_Check_Id,
                                  l_calling_sequence,
                                  tab_payment_wh,
                                  l_total_wh_amount,
                                  P_AWT_Success,
                                  P_Last_Updated_By,
                                  P_Last_Update_Login,
                                  P_Program_Application_Id,
                                  P_Program_Id,
                                  P_Request_Id,
                                  P_Calling_Module,
                                  P_Checkrun_Name,
                                  P_Checkrun_ID,
                                  rec_payment_wh.payment_num);
Line: 2698

                                  P_Selected_Check_Id,
                                  l_calling_sequence,
                                  tab_payment_wh,
                                  l_total_wh_amount,
                                  P_AWT_Success,
                                  P_Last_Updated_By,
                                  P_Last_Update_Login,
                                  P_Program_Application_Id,
                                  P_Program_Id,
                                  P_Request_Id,
                                  P_Calling_Module,
                                  P_Checkrun_Name,
                                  P_Checkrun_ID,
                                  rec_payment_wh.payment_num);
Line: 2741

      SELECT TO_DATE (apip.accounting_date, 'DD-MM-YYYY')
        INTO l_code_accounting_date                        -- Argentina AWT ER
        FROM ap_invoice_payments apip
       WHERE apip.invoice_payment_id = rec_payment_wh.invoice_payment_id;
Line: 2745

    ELSIF (p_calling_module = 'AUTOSELECT') then
       SELECT TO_DATE (apsc.check_date, 'DD-MM-YYYY')
        INTO l_code_accounting_date                        -- Argentina AWT ER
        FROM ap_inv_selection_criteria_all apsc
       WHERE apsc.checkrun_id = p_checkrun_id;
Line: 2963

        ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
            FETCH c_payment_batch_withholdings INTO rec_payment_wh;
Line: 2999

    ELSIF (P_Calling_Module = 'AUTOSELECT') THEN

        -- Debug Information
        IF (DEBUG_Var = 'Y') THEN
            JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Close Cursor c_payment_batch_withholdings');
Line: 3040

                    ', Selected Check_Id= ' || to_char(P_Selected_Check_Id) ||
                    ', AWT Date= '          || to_char(P_AWT_Date,'YYYY/MM/DD')          ||
                    ', Calling Module= '    || P_Calling_Module);
Line: 3152

       P_Selected_Check_Id      IN     Number,
       P_Calling_Sequence       IN     Varchar2,
       P_Tab_Withhold           IN OUT NOCOPY Jl_Zz_Ap_Withholding_Pkg.Tab_Withholding,
       P_Total_Wh_Amount        IN OUT NOCOPY Number,
       P_AWT_Success            OUT NOCOPY    Varchar2,
       P_Last_Updated_By        IN     Number     Default null,
       P_Last_Update_Login      IN     Number     Default null,
       P_Program_Application_Id IN     Number     Default null,
       P_Program_Id             IN     Number     Default null,
       P_Request_Id             IN     Number     Default null,
       P_Calling_Module         IN     Varchar2   Default null,
       P_Checkrun_Name          IN     Varchar2   Default null,
       P_Checkrun_ID            IN     Number     Default null,
       P_Payment_Num            IN     Number     Default null)
IS

    l_debug_info             Varchar2(300);
Line: 3189

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameters: P_Selected_Check_Id= '||to_char(P_Selected_Check_Id));
Line: 3246

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' ==> Calling Update_Credit_Letter');
Line: 3250

    Update_Credit_Letter (P_Vendor_Id,
                          P_Rec_AWT_Type,
                          P_AWT_Date,
                          P_Payment_Num,
                          P_Check_Id,
                          P_Selected_Check_Id,
                          l_calling_sequence,
                          P_Tab_Withhold,
                          P_Last_Updated_By,
                          P_Last_Update_Login,
                          P_Program_Application_Id,
                          P_Program_Id,
                          P_Request_Id);
Line: 3266

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' After Called Update_Credit_Letter');
Line: 3310

                                 TRUE,                -- Update Bucket
                                 P_AWT_Success,
                                 P_Last_Updated_By,
                                 P_Last_Update_Login,
                                 P_Program_Application_Id,
                                 P_Program_Id,
                                 P_Request_Id,
                                 P_Calling_Module,
                                 P_Checkrun_Name,
                                 P_Checkrun_ID,
                                 P_Payment_Num);
Line: 3363

                 ', Selected Check_Id= '  || to_char(P_Selected_Check_Id) ||
                 ', Calling Module=  '    || P_Calling_Module             ||
                 ', Checkrun Name= '      || P_Checkrun_Name              ||
                 ', Payment Num= '        || to_char(P_Payment_Num));
Line: 3390

                      P_Selected_Check_Id        IN     Number,
                      P_Currency_Code            IN     Varchar2,
                      P_Tab_Inv_Amounts          IN OUT NOCOPY Tab_Amounts,
                      P_Calling_Module           IN     Varchar2,
                      P_Calling_Sequence         IN     Varchar2)
IS
    ------------------------
    -- Variables definition
    ------------------------
    l_not_found             Boolean := TRUE;
Line: 3423

    SELECT apin.invoice_id                            invoice_id,
           apid.invoice_distribution_id               invoice_distribution_id , -- Lines
           -- Payment Exchange Rate ER 8648739 Start 5
           -- nvl(apid.base_amount, apid.amount)         amount,
           (apid.amount * nvl(apip.exchange_rate,1))     amount,
           -- Payment Exchange Rate ER 8648739 End 5
           nvl(apid.global_attribute4, 0)             tax_inclusive_amount,
           -- Payment Exchange Rate ER 8648739 Start 6
           -- nvl(apip.invoice_base_amount,apip.amount)  payment_amount,
           (apip.amount * nvl(apip.exchange_rate,1))  payment_amount,
           -- Payment Exchange Rate ER 8648739 End 6
           apip.invoice_payment_id                    invo_payment_id
    FROM   ap_invoices apin,
           ap_invoice_distributions apid,
           ap_invoice_payments apip
    WHERE  apin.invoice_id = apid.invoice_id
    AND    apin.invoice_id = apip.invoice_id
    AND    apip.check_id = P_Check_Id
    AND    apid.line_type_lookup_code <> 'AWT'
            -- added recently
    AND    NVL(apid.REVERSAL_FLAG,'N') <> 'Y'
    ORDER BY apin.invoice_id,
             apip.invoice_payment_id,
             apid.invoice_distribution_id ; -- Lines
Line: 3449

   SELECT apin.invoice_id                            invoice_id,
           apid.invoice_distribution_id               invoice_distribution_id , -- Lines
           nvl(apid.base_amount, apid.amount)         amount,
           nvl(apid.global_attribute4, 0)             tax_inclusive_amount,
--           apsi.payment_amount*nvl(apsi.invoice_exchange_rate,1)           payment_amount,
--          ,apsi.payment_num                           payment_num
            docs.document_amount* nvl(apsi.invoice_exchange_rate,1)  payment_amount,
            docs.calling_app_doc_unique_ref3     payment_num
    FROM   ap_invoices apin,
           ap_invoice_distributions apid,
           ap_selected_invoices apsi,
           iby_hook_docs_in_pmt_t  docs
    WHERE  apin.invoice_id = apid.invoice_id
    AND    apin.invoice_id = apsi.invoice_id
--    AND    apsi.pay_selected_check_id = P_Selected_Check_Id
    and    docs.payment_id = P_Check_Id
    and    apsi.invoice_id = docs.calling_app_doc_unique_ref2
--    AND   apsi.original_invoice_id IS NULL
    AND   docs.dont_pay_flag = 'N'
    AND   apid.line_type_lookup_code <> 'AWT'
    and   docs.calling_app_id = 200
    ORDER BY apin.invoice_id,
             docs.calling_app_doc_unique_ref3,
             apid.invoice_distribution_id ;
Line: 3478

    CURSOR c_batch_invoice_amounts (P_Selected_Check_Id IN Number) IS
    SELECT distinct apin.invoice_id                            invoice_id, --bug 12613506
           apid.invoice_distribution_id               invoice_distribution_id , -- Lines
           -- Payment Exchange Rate ER 8648739 Start 7
           -- nvl(apid.base_amount, apid.amount)         amount,
           (apid.amount * nvl(apsi.payment_exchange_rate, 1))         amount,
           -- Payment Exchange Rate ER 8648739 End 7
           nvl(apid.global_attribute4, 0)             tax_inclusive_amount,
           -- Payment Exchange Rate ER 8648739 Start 8
           -- docs.document_amount* nvl(apsi.invoice_exchange_rate,1)  payment_amount,
           (docs.document_amount * nvl(apsi.payment_exchange_rate,1))  payment_amount,
           -- Payment Exchange Rate ER 8648739 End 8
           docs.calling_app_doc_unique_ref3     payment_num
    FROM   ap_invoices apin,
           ap_invoice_distributions apid,
           ap_selected_invoices apsi,
           iby_hook_docs_in_pmt_t  docs
    WHERE  apin.invoice_id = apid.invoice_id
    AND    apin.invoice_id = apsi.invoice_id
--    AND    apsi.pay_selected_check_id = P_Selected_Check_Id
    and    docs.payment_id = P_Selected_Check_Id
    and    apsi.invoice_id = docs.calling_app_doc_unique_ref2
--    AND   apsi.original_invoice_id IS NULL
    AND   docs.dont_pay_flag = 'N'
    AND   apid.line_type_lookup_code <> 'AWT'
    AND   docs.calling_app_id = 200
    -- added recently
    AND    NVL(apid.REVERSAL_FLAG,'N') <> 'Y'
    ORDER BY apin.invoice_id,
             docs.calling_app_doc_unique_ref3,
             apid.invoice_distribution_id ; -- Lines
Line: 3524

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameters: P_Selected_Check_Id= '||to_char(P_Selected_Check_Id));
Line: 3543

    ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
        OPEN c_batch_invoice_amounts (P_Selected_Check_Id);
Line: 3586

        ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
            FETCH c_batch_invoice_amounts INTO l_invoice_id,
                                               l_dist_line_no,
                                               l_amount,
                                               l_tax_inclusive_amount,
                                               l_payment_amount,
                                               l_invo_payment_num;
Line: 3645

       ELSIF (P_Calling_Module = 'AUTOSELECT') THEN

              IF ((l_previous_invoice_id IS NOT NULL AND
                  l_previous_invoice_id <> l_invoice_id)
                OR (l_previous_invoice_id IS NOT NULL AND
                    l_previous_invoice_id = l_invoice_id  AND
                    l_invo_payment_num <> l_previous_inv_pay_num))

              THEN

                  FOR i IN l_initial_position .. (l_position - 1) LOOP
                      P_Tab_Inv_Amounts(i).invoice_amount := l_invoice_amount;
Line: 3661

                     JL_ZZ_AP_EXT_AWT_UTIL.Debug(' AUTOSELECT and l_previous_invoice_id <> l_invoice_id');
Line: 3726

    ELSIF (P_Calling_Module = 'AUTOSELECT') THEN

        -- Debug Information
        IF (DEBUG_Var = 'Y') THEN
           JL_ZZ_AP_EXT_AWT_UTIL.Debug('Close Cursor c_invoice_amounts');
Line: 3861

    IF (P_Calling_Module = 'AUTOSELECT') THEN
       -------------------------
       -- Processes last amount
       -------------------------
       P_Tab_Inv_Amounts(P_Tab_Inv_Amounts.COUNT).taxable_base_amount :=
                     P_Tab_Inv_Amounts(P_Tab_Inv_Amounts.COUNT).payment_amount -
                     l_cumulative_amount;
Line: 3871

            JL_ZZ_AP_EXT_AWT_UTIL.Debug(' Last Row for AUTOSELECT - Payment Amount');
Line: 3894

                 ', Selected Check Id= ' || to_char(P_Selected_Check_Id) ||
                 ', Currency Code= '     || P_Currency_Code              ||
                 ', Calling Module= '    || P_Calling_Module);
Line: 4006

      ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
        EXIT WHEN (P_Tab_Inv_Amounts(i).invoice_id > P_Invoice_Id);
Line: 4122

    SELECT max(seq_num)
    INTO   l_seq_num
    FROM   jl_ar_ap_sup_awt_cr_lts
    WHERE  po_vendor_id = P_Vendor_Id
    AND    awt_type_code = P_AWT_Type_Code;
Line: 4132

    SELECT balance
    INTO   l_credit_letter_amount
    FROM   jl_ar_ap_sup_awt_cr_lts
    WHERE  po_vendor_id = P_Vendor_Id
    AND    awt_type_code = P_AWT_Type_Code
    AND    seq_num = l_seq_num;
Line: 4173

 * Name       : Update_Credit_Letter                                      *
 * Purpose    : Updates the withheld amount for each tax name contained   *
 *              into the PL/SQL table. The credit letters table is also   *
 *              updated                                                   *
 *                                                                        *
 **************************************************************************/
PROCEDURE Update_Credit_Letter
      (P_Vendor_Id              IN     Number,
       P_Rec_AWT_Type           IN     jl_zz_ap_awt_types%ROWTYPE,
       P_AWT_Date               IN     Date,
       P_Payment_Num            IN     Number,
       P_Check_Id               IN     Number,
       P_Selected_Check_Id      IN     Number,
       P_Calling_Sequence       IN     Varchar2,
       P_Tab_Withhold           IN OUT NOCOPY Jl_Zz_Ap_Withholding_Pkg.Tab_Withholding,
       P_Last_Updated_By        IN     Number     Default null,
       P_Last_Update_Login      IN     Number     Default null,
       P_Program_Application_Id IN     Number     Default null,
       P_Program_Id             IN     Number     Default null,
       P_Request_Id             IN     Number     Default null)
IS

    l_credit_letter_amount     Number;
Line: 4209

                          'Update_Credit_Letter<--' || P_Calling_Sequence;
Line: 4214

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('FUNCTION Update_Credit_Letter(+)');
Line: 4296

            Insert_Credit_Letter_Amount (P_Vendor_Id,
                                         P_Rec_AWT_Type.awt_type_code,
                                         l_tax_id,
                                         P_AWT_Date,
                                         l_orig_withheld_amount,
                                         l_actual_withheld_amount,
                                         l_credit_letter_amount,
                                         'AA',
                                         P_Payment_Num,
                                         P_Check_Id,
                                         P_Selected_Check_Id,
                                         l_calling_sequence,
                                         P_Last_Updated_By,
                                         P_Last_Update_Login,
                                         P_Program_Application_Id,
                                         P_Program_Id,
                                         P_Request_Id);
Line: 4351

        Insert_Credit_Letter_Amount (P_Vendor_Id,
                                     P_Rec_AWT_Type.awt_type_code,
                                     l_tax_id,
                                     P_AWT_Date,
                                     l_orig_withheld_amount,
                                     l_actual_withheld_amount,
                                     l_credit_letter_amount,
                                     'AA',
                                     P_Payment_Num,
                                     P_Check_Id,
                                     P_Selected_Check_Id,
                                     l_calling_sequence,
                                     P_Last_Updated_By,
                                     P_Last_Update_Login,
                                     P_Program_Application_Id,
                                     P_Program_Id,
                                     P_Request_Id);
Line: 4372

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('FUNCTION Update_Credit_Letter(-)');
Line: 4387

                ', Selected_Check_Id= '  || to_char(P_Selected_Check_Id));
Line: 4393

END Update_Credit_Letter;
Line: 4400

 * Name       : Insert_Credit_Letter_Amount                               *
 * Purpose    : Stores current information about credit letters into the  *
 *              JL_AR_AP_SUP_AWT_CR_LTS table                             *
 *                                                                        *
 **************************************************************************/
PROCEDURE Insert_Credit_Letter_Amount
                (P_Vendor_Id               IN     Number,
                 P_AWT_Type_Code           IN     Varchar2,
                 P_Tax_Id                  IN     Number,
                 P_AWT_Date                IN     Date,
                 P_Withheld_Amount         IN     Number,
                 P_Actual_Withheld_Amount  IN     Number,
                 P_Balance                 IN     Number,
                 P_Status                  IN     Varchar2,
                 P_Payment_Num             IN     Number,
                 P_Check_Id                IN     Number,
                 P_Selected_Check_Id       IN     Number,
                 P_Calling_Sequence        IN     Varchar2,
                 P_Last_Updated_By         IN     Number     Default null,
                 P_Last_Update_Login       IN     Number     Default null,
                 P_Program_Application_Id  IN     Number     Default null,
                 P_Program_Id              IN     Number     Default null,
                 P_Request_Id              IN     Number     Default null)
IS

    l_debug_info             Varchar2(300);
Line: 4433

                          'Insert_Credit_Letter_Amount<--' ||
                           P_Calling_Sequence;
Line: 4438

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('PROCEDURE Insert_Credit_Letter_Amount(+)');
Line: 4444

    INSERT INTO jl_ar_ap_sup_awt_cr_lts
        (seq_num,
         po_vendor_id,
         awt_type_code,
         tax_id,
         trx_date,
         calc_wh_amnt,
         act_wheld_amnt,
         balance,
         check_id,
         selected_check_id,
         pay_number,
         created_by,
         creation_date,
         last_updated_by,
         last_update_date,
         last_update_login,
         program_application_id,
         program_id,
         request_id,
         status)
    VALUES
        (jl_ar_ap_sup_awt_cr_lts_s.nextval,
         P_Vendor_Id,
         P_AWT_Type_Code,
         P_Tax_Id,
         P_AWT_Date,
         P_Withheld_Amount,
         P_Actual_Withheld_Amount,
         P_Balance,
         P_Check_Id,
         P_Selected_Check_Id,
         P_Payment_Num,
         fnd_global.user_id,
         sysdate,
         P_Last_Updated_By,
         sysdate,
         P_Last_Update_Login,
         P_Program_Application_Id,
         P_Program_Id,
         P_Request_Id,
         P_Status);
Line: 4489

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('PROCEDURE Insert_Credit_Letter_Amount(-)');
Line: 4510

             ', Selected Check Id= '      || to_char(P_Selected_Check_Id));
Line: 4516

END Insert_Credit_Letter_Amount;
Line: 4530

                 P_Selected_Check_Id       IN     Number,
                 P_AWT_Date                IN     Date,
                 P_Payment_Num             IN     Number,
                 P_Calling_Sequence        IN     Varchar2,
                 P_Last_Updated_By         IN     Number     Default null,
                 P_Last_Update_Login       IN     Number     Default null,
                 P_Program_Application_Id  IN     Number     Default null,
                 P_Program_Id              IN     Number     Default null,
                 P_Request_Id              IN     Number     Default null)

IS
    ---------------------
    -- Types definition
    ---------------------
    TYPE Rec_Credit_Letter IS RECORD
    (
        vendor_id            Number,
        awt_type_code        Varchar2(30),
        amount_to_reverse    Number
    );
Line: 4558

                             P_Selected_Check_Id IN Number) IS
    SELECT jlcl.po_vendor_id             vendor_id,
           jlcl.awt_type_code            awt_type_code,
           jlcl.calc_wh_amnt             calc_wh_amnt,
           jlcl.act_wheld_amnt           act_wheld_amnt
    FROM   jl_ar_ap_sup_awt_cr_lts jlcl
    WHERE  jlcl.status = 'AA'
    AND   ((P_Check_Id IS NOT NULL AND
           jlcl.check_id = P_Check_Id) OR
           (P_Selected_Check_Id IS NOT NULL AND
           jlcl.selected_check_id = P_Selected_Check_Id))
    ORDER BY jlcl.po_vendor_id,
             jlcl.awt_type_code,
             jlcl.seq_num
    FOR UPDATE OF jlcl.status;
Line: 4608

    OPEN c_credit_letters (P_Check_Id, P_Selected_Check_Id);
Line: 4636

        UPDATE jl_ar_ap_sup_awt_cr_lts
        SET    status = 'AR'
        WHERE  CURRENT OF c_credit_letters;
Line: 4667

        Insert_Credit_Letter_Amount(tab_cr_letter(i).vendor_id,
                                    tab_cr_letter(i).awt_type_code,
                                    null,           -- Tax ID
                                    P_AWT_Date,
                                    null,           -- Calc. Withheld Amount
                                    null,           -- Actual Withheld Amount
                                    l_balance,
                                    'AR',           -- Status
                                    P_Payment_Num,
                                    P_Check_Id,
                                    P_Selected_Check_Id,
                                    l_calling_sequence,
                                    P_Last_Updated_By,
                                    P_Last_Update_Login,
                                    P_Program_Application_Id,
                                    P_Program_Id,
                                    P_Request_Id);
Line: 4698

                ', Selected Check Id= ' || to_char(P_Selected_Check_Id) ||
                ', AWT Date= '          || to_char(P_AWT_Date,'YYYY/MM/DD')  ||
                ', Payment Num= '       || to_char(P_Payment_Num));
Line: 4712

 * Name       : Update_Quick_Payment                                      *
 * Purpose    : Updates the payment amount by subtracting the withheld    *
 *              amount.                                                   *
 *                                                                        *
 **************************************************************************/
PROCEDURE Update_Quick_Payment
                    (P_Check_Id                 IN     Number,
                     P_Calling_Sequence         IN     Varchar2)
IS

    ------------------------------
    -- Local variables definition
    ------------------------------
    l_invoice_payment_id    Number;
Line: 4749

    SELECT apip.invoice_payment_id      invoice_payment_id,
           apip.invoice_id              invoice_id,
           apip.exchange_rate           pay_exchange_rate,
           apip.payment_num             payment_num,
           apip.amount                  amount,
           apip.payment_base_amount     payment_base_amount,
           apip.invoice_base_amount     invoice_base_amount
    FROM   ap_invoice_payments apip
    WHERE  apip.check_id = P_Check_Id
    FOR UPDATE OF apip.amount,
                  apip.payment_base_amount,
                  apip.invoice_base_amount;
Line: 4767

    SELECT apch.amount        amount,
           apch.base_amount   base_amount,
           apch.currency_code currency_code    -- Bug 2886571
    FROM   ap_checks          apch
    WHERE  apch.check_id = P_Check_Id
    FOR UPDATE OF apch.amount,
                  apch.base_amount;
Line: 4780

                          'Update_Quick_Payment<--' || P_Calling_Sequence;
Line: 4787

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('PROCEDURE Update_Quick_Payment(+)');
Line: 4830

        SELECT nvl(sum(apid.amount), 0)
        INTO   l_withhold_amount
        FROM   ap_invoice_distributions apid
        WHERE  apid.invoice_id = l_invoice_id
        AND    apid.awt_invoice_payment_id = l_invoice_payment_id
            -- added recently
        AND    NVL(apid.REVERSAL_FLAG,'N') <> 'Y';
Line: 4849

            SELECT apin.exchange_rate,
                   apps.payment_cross_rate,
                   apin.payment_currency_code
            INTO   l_inv_exchange_rate,
                   l_payment_cross_rate,
                   l_payment_currency_code      -- Bug 2886571
            FROM   ap_invoices          apin,
                   ap_payment_schedules apps
            WHERE  apin.invoice_id    = l_invoice_id
            AND    apps.invoice_id    = l_invoice_id
            AND    apps.payment_num   = l_payment_num;
Line: 4873

            UPDATE ap_payment_schedules
            SET    amount_remaining = ap_utilities_pkg.ap_round_currency(
                                        amount_remaining - (l_withhold_amount * nvl(l_payment_cross_rate, 1)),
                                        l_payment_currency_code),
                   payment_status_flag = decode( ap_utilities_pkg.ap_round_currency(amount_remaining -
                                                (l_withhold_amount *
                                                 nvl(l_payment_cross_rate, 1)),l_payment_currency_code),
                                                 0, 'Y',
                                                 amount_remaining,
                                                 payment_status_flag, 'P')
            WHERE  invoice_id  = l_invoice_id
            AND    payment_num = l_payment_num;
Line: 4890

            UPDATE ap_invoices
            SET    amount_paid         = ap_utilities_pkg.ap_round_currency(
                                          nvl(amount_paid, 0) +
                                         (l_withhold_amount *
                                          nvl(l_payment_cross_rate, 1)),l_payment_currency_code),
                   payment_status_flag = AP_INVOICES_UTILITY_PKG.get_payment_status(l_invoice_id)
            WHERE invoice_id = l_invoice_id;
Line: 4916

            AP_AIP_TABLE_HANDLER_PKG.Update_Amounts(
                                   l_invoice_payment_id
                                  ,l_pay_amount
                                  ,l_invoice_base_amount
                                  ,l_payment_base_amount
                                  ,l_calling_sequence);
Line: 4954

           AP_AC_TABLE_HANDLER_PKG.Update_Amounts(
                       P_check_id
                      ,l_amount
                      ,l_base_amount
                      ,l_calling_sequence);
Line: 4965

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Procedure Update_Quick_Payment(-)');
Line: 4983

END Update_Quick_Payment;
Line: 4988

 * Name       : Update_Payment_Batch                                      *
 * Purpose    : Updates the amounts of the payment batch by subtracting   *
 *              the withholding amount.                                   *
 *  just update invoices in same payment check                            *
 **************************************************************************/
PROCEDURE Update_Payment_Batch
                (P_Checkrun_Name           IN     Varchar2,
                 P_Checkrun_ID             IN     Number,
                 P_Selected_Check_Id       IN     Number,
                 P_Calling_Sequence        IN     Varchar2)
IS
    ----------------------
    -- Cursor definition
    ----------------------
    CURSOR c_selected_invoices (P_Selected_Check_Id  IN Number) IS

/*  RG  update documents
  SELECT apsi.invoice_id                invoice_id,
           apsi.payment_num                   payment_num,
           apsi.payment_amount                payment_amount,
           nvl(apsi.invoice_exchange_rate, 1) invoice_exchange_rate,
          nvl(apsi.payment_cross_rate, 1)     payment_cross_rate
    FROM   ap_selected_invoices apsi
    WHERE  apsi.pay_selected_check_id = P_Selected_Check_id
    AND    nvl(apsi.ok_to_pay_flag, 'Y') = 'Y'
    AND    apsi.original_invoice_id IS NULL
    FOR UPDATE;
Line: 5016

   SELECT distinct docs.CALLING_APP_DOC_UNIQUE_REF2 invoice_id, --bug 12613506
      docs.document_payable_id document_payable_id,
      docs.CALLING_APP_DOC_UNIQUE_REF3 payment_num,
      docs.document_amount payment_amount ,
      -- Payment Exchange Rate ER 8648739 Start 9
      -- nvl(apsi.invoice_exchange_rate, 1) invoice_exchange_rate,
      nvl(apsi.payment_exchange_rate, 1) payment_exchange_rate,
      -- Payment Exchange Rate ER 8648739  End 9
      nvl(apsi.payment_cross_rate, 1)    payment_cross_rate
   FROM iby_hook_docs_in_pmt_t docs,
        ap_selected_invoices apsi
   WHERE docs.payment_id = P_Selected_Check_id
   AND   docs.calling_app_id = 200
   AND   apsi.invoice_id = docs.calling_app_doc_unique_ref2
   AND   nvl(docs.dont_pay_flag,'N')='N';
Line: 5034

    CURSOR c_selected_invoice_checks (P_Selected_Check_Id  IN Number) IS
    SELECT apsic.check_amount     check_amount,
           apsic.vendor_amount    vendor_amount
    FROM   ap_selected_invoice_checks  apsic
    WHERE  apsic.selected_check_id = P_Selected_Check_Id
    FOR UPDATE OF apsic.check_amount,
                  apsic.vendor_amount;
Line: 5043

  CURSOR c_selected_invoice_checks (P_Selected_Check_Id  IN Number) IS
  SELECT ipmt.payment_amount payment_amount
  FROM iby_hook_payments_t ipmt
  WHERE ipmt.payment_id = P_Selected_Check_id
  AND   ipmt.calling_app_id = 200
  FOR UPDATE OF ipmt.payment_amount;
Line: 5054

    rec_sel_inv              c_selected_invoices%ROWTYPE;
Line: 5073

                          'Update_Payment_Batch<--' || P_Calling_Sequence;
Line: 5079

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('PROCEDURE Update_Payment_Batch(+)');
Line: 5081

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameter P_Selected_Check_Id: '||to_char(P_Selected_Check_Id));
Line: 5090

     SELECT count(*)
     INTO   l_count_inv
     FROM   iby_hook_docs_in_pmt_t docs,
-- RG ap_selected_invoices apsi,
            ap_awt_temp_distributions awtd
     WHERE  docs.payment_id = P_Selected_Check_Id
      AND  nvl(docs.dont_pay_flag,'N') ='N'
      AND   docs.calling_app_doc_unique_ref2  = awtd.invoice_id
      AND   docs.calling_app_id=200 ;
Line: 5107

        JL_ZZ_AP_EXT_AWT_UTIL.Debug ('Just update the invoices in the same payment check: '||to_char(l_count_inv));
Line: 5120

     SELECT SUM(docs.document_amount)
     INTO   l_prop_payment_amount
     FROM   iby_hook_docs_in_pmt_t docs
-- ap_selected_invoices apsi
     WHERE  docs.payment_id = P_Selected_Check_Id
      AND  nvl(docs.dont_pay_flag,'N') ='N'
      AND docs.calling_app_id =200;
Line: 5144

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('OPEN Cursor c_selected_invoices');
Line: 5148

    OPEN c_selected_invoices (P_Selected_Check_Id);
Line: 5151

        FETCH c_selected_invoices INTO rec_sel_inv;
Line: 5152

        EXIT WHEN c_selected_invoices%NOTFOUND;
Line: 5171

SELECT payment_currency_code
         INTO   l_payment_currency_code
         FROM   ap_invoices_all
         WHERE  invoice_id = rec_sel_inv.invoice_id;
Line: 5177

    SELECT document_currency_code
      INTO l_payment_currency_code
      FROM IBY_HOOK_DOCS_IN_PMT_T
     WHERE payment_id = P_Selected_Check_Id
       AND document_payable_id = rec_sel_inv.document_payable_id;
Line: 5186

        SELECT nvl(sum(withholding_amount), 0)
        INTO   l_withholding_amount
        FROM   ap_awt_temp_distributions
        WHERE  checkrun_name = P_Checkrun_Name
        AND    checkrun_id= p_checkrun_id
        AND    invoice_id = rec_sel_inv.invoice_id
        AND    payment_num = rec_sel_inv.payment_num;
Line: 5225

        UPDATE ap_selected_invoices apsi
        SET  apsi.proposed_payment_amount = ap_utilities_pkg.ap_round_currency(
                           apsi.proposed_payment_amount - l_withholding_amount,
                           l_payment_currency_code),
             apsi.payment_amount          = ap_utilities_pkg.ap_round_currency(
                             apsi.payment_amount - l_withholding_amount,
                           l_payment_currency_code),
            -- bug: 9037712 :: Amount_remaining should not be updated.
            -- JL code modified to be in sync with AP side processing for PPRs.
            -- apsi.amount_remaining        = ap_utilities_pkg.ap_round_currency(
            --                   apsi.amount_remaining - l_withholding_amount,
            --                   l_payment_currency_code),
             apsi.withholding_amount      = ap_utilities_pkg.ap_round_currency(
                           l_withholding_amount, l_payment_currency_code)
        WHERE  invoice_id = rec_sel_inv.invoice_id
          AND  payment_num = rec_sel_inv.payment_num; --bug 12921144
Line: 5243

   UPDATE iby_hook_docs_in_pmt_t docs
     SET docs.document_amount = ap_utilities_pkg.ap_round_currency(
                           docs.document_amount - l_withholding_amount,
                           l_payment_currency_code),
         docs.amount_withheld = ap_utilities_pkg.ap_round_currency(
                           l_withholding_amount, l_payment_currency_code)
     WHERE document_payable_id = rec_sel_inv.document_payable_id;
Line: 5256

    CLOSE c_selected_invoices;
Line: 5269

    OPEN c_selected_invoice_checks (P_Selected_Check_Id);
Line: 5270

    FETCH c_selected_invoice_checks INTO l_check_amount;
Line: 5272

    IF (NOT c_selected_invoice_checks%NOTFOUND) THEN

/*  RG
        UPDATE ap_selected_invoice_checks apsic
        SET    apsic.check_amount  = ap_utilities_pkg.ap_round_currency(
                            NVL(l_prop_payment_amount, l_check_amount ) -
                            l_total_wh_amount, apsic.currency_code),
               apsic.vendor_amount = ap_utilities_pkg.ap_round_currency(
                            -1 * l_total_wh_amount, apsic.currency_code)
        WHERE CURRENT OF c_selected_invoice_checks;
Line: 5283

    UPDATE iby_hook_payments_t ipmt
    SET ipmt.payment_amount = ap_utilities_pkg.ap_round_currency(
                            NVL(l_prop_payment_amount, l_check_amount ) -
                l_total_wh_amount, ipmt.payment_currency_code)
    WHERE CURRENT OF c_selected_invoice_checks;
Line: 5291

    CLOSE c_selected_invoice_checks;
Line: 5295

       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('PROCEDURE Update_Payment_Batch(-)');
Line: 5308

                ', Selected Check Id= '  || to_char(P_Selected_Check_Id));
Line: 5314

END Update_Payment_Batch;
Line: 5388

        SELECT count('Withholding Already Calculated')
        INTO   l_count
        FROM   ap_awt_temp_distributions apatd
        WHERE  apatd.invoice_id = P_Invoice_Id
        AND    apatd.tax_name = P_Tax_Name;
Line: 5401

        SELECT nvl(sum(apid.amount), 0)
        INTO   l_withheld_amount
        FROM   ap_invoice_distributions apid
        WHERE  apid.invoice_id = P_Invoice_Id
        AND    apid.line_type_lookup_code = 'AWT'
        AND    apid.withholding_tax_code_id = P_Tax_Id
            -- added recently
        AND    NVL(apid.REVERSAL_FLAG,'N') <> 'Y';
Line: 5518

                  P_Selected_Check_Id    IN     Number,
                  P_Calling_Module       IN     Varchar2,
                  P_Total_Wh_Amount      IN     Number,
                  P_Calling_Sequence     IN     Varchar2,
                  P_Vendor_Name          OUT NOCOPY    Varchar2,
                  P_Vendor_Site_Code     OUT NOCOPY    Varchar2)
                  --P_Payment_Amount       OUT NOCOPY    Number)  Bug# 2807464
                  RETURN Boolean
IS

    l_payment_amount    Number := 0;
Line: 5553

        SELECT nvl(apchk.base_amount, apchk.amount),
               apchk.vendor_name,
               apchk.vendor_site_code
        INTO   l_payment_amount,
               l_vendor_name,
               l_vendor_site_code
        FROM   ap_checks apchk
        WHERE  apchk.check_id = P_Check_Id;
Line: 5565

    ELSIF (P_Calling_Module = 'AUTOSELECT') THEN
        SELECT nvl(sum(docs.document_amount/
                       nvl(apsi.payment_cross_rate, 1) *
                       nvl(apsi.invoice_exchange_rate, 1)), 0)
        INTO   l_payment_amount
        FROM   iby_hook_docs_in_pmt_t docs,
               ap_selected_invoices apsi
       WHERE  docs.payment_id = P_Selected_Check_id
       AND    apsi.invoice_id = docs.calling_app_doc_unique_ref2
       AND   docs.dont_pay_flag = 'N'
--      AND    apsi.pay_selected_check_id = P_Selected_Check_id
--       AND    apsi.original_invoice_id IS NULL
       AND    docs.calling_app_id=200;
Line: 5579

/* RG        SELECT vendor_name,
               vendor_site_code
        INTO   l_vendor_name,
               l_vendor_site_code
        FROM   ap_selected_invoice_checks
        WHERE  selected_check_id = P_Selected_Check_id;
Line: 5587

       SELECT asi.vendor_name,
              asi.vendor_site_code
       INTO l_vendor_name,
            l_vendor_site_code
       FROM IBY_HOOK_DOCS_IN_PMT_T docs,
            ap_selected_invoices_all asi
       WHERE docs.payment_id = P_Selected_Check_id
       AND   docs.calling_app_doc_unique_ref2 = asi.invoice_id
       AND   docs.calling_app_id=200;
Line: 5598

      select a.vendor_name, b.vendor_site_code
        into l_vendor_name,
             l_vendor_site_code
        from ap_suppliers a, ap_supplier_sites_all b,
             iby_hook_payments_t c
       where c.PAYEE_PARTY_ID = a.party_id
         and c.SUPPLIER_SITE_ID = b.vendor_site_id
         and a.vendor_id = b.vendor_id
         and c.payment_id = P_Selected_Check_id;
Line: 5633

               ', Selected Check_Id= ' || to_char(P_Selected_Check_Id) ||
               ', Calling Module= '    || P_Calling_Module             ||
               ', Total Wh Amount= '   || to_char(P_Total_Wh_Amount));
Line: 5648

 * Purpose    : Updates the credit letters table in order to store the    *
 *              the final check ID, when users confirm a payment batch.   *
 *              This procedure is not called for Quick Payments because   *
 *              the check ID is known from the begining.                  *
 *                                                                        *
 **************************************************************************/
PROCEDURE Confirm_Credit_Letters
                (P_Checkrun_Name           IN     Varchar2,
                 p_checkrun_id             IN     Number,
                 P_Calling_Sequence        IN     Varchar2)
IS

    ------------------------------
    -- Local variables definition
    ------------------------------
    l_check_id             Number;
Line: 5664

    l_selected_check_id    Number;
Line: 5672

    CURSOR c_selected_invoice_checks
    IS
     SELECT distinct(d.payment_id) check_id
       FROM iby_fd_payments_v p,iby_fd_docs_payable_v d
      WHERE d.calling_app_doc_unique_ref1 = to_char(p_checkrun_id) --bug9836895
	  AND p.payment_id = d.payment_id
       AND d.calling_app_id = 200; --bug9836895
Line: 5682

    SELECT apsic.selected_check_id    selected_check_id,
           apsic.check_id             check_id
    FROM   ap_selected_invoice_checks apsic
    WHERE  checkrun_name = P_Checkrun_Name;
Line: 5705

    OPEN c_selected_invoice_checks;
Line: 5707

        FETCH c_selected_invoice_checks INTO l_check_id;
Line: 5709

        EXIT WHEN c_selected_invoice_checks%NOTFOUND;
Line: 5716

            UPDATE jl_ar_ap_sup_awt_cr_lts
            SET    check_id          = l_check_id,
                   selected_check_id = null
            WHERE  selected_check_id = l_check_id;
Line: 5724

    CLOSE c_selected_invoice_checks;
Line: 5761

 * Purpose    : Sets the "Ok To Pay" flag for all the selected invoices   *
 *              within the payment when the calculation routine is not    *
 *              successful                                                *
 *                                                                        *
 *  RG Sets the DONT_PAY_FLAG for all documents in payment                *
 **************************************************************************/
PROCEDURE Reject_Payment_Batch
                (P_Selected_Check_Id       IN     Number,
                 P_AWT_Success             IN     Varchar2,
                 P_Calling_Sequence        IN     Varchar2)
IS
    ------------------------------
    -- Local variables definition
    ------------------------------
    l_ok_to_pay_flag          Varchar2(10);
Line: 5785

    CURSOR c_selected_invoices (P_Selected_Check_Id  IN Number) IS
    SELECT docs.dont_pay_flag dont_pay_flag ,
           docs.dont_pay_reason_code dont_pay_reason,
           docs.calling_app_doc_unique_ref2   invoice_id
-- apsi.ok_to_pay_flag        ok_to_pay_flag,
--           apsi.dont_pay_reason_code  dont_pay_reason_code,
--           apsi.dont_pay_description  dont_pay_description
    FROM   iby_hook_docs_in_pmt_t docs
 -- ap_selected_invoices       apsi
    WHERE  docs.payment_id     =  P_Selected_Check_id
    AND    docs.dont_pay_flag  = 'N'
    AND    docs.calling_app_id = 200
--  apsi.pay_selected_check_id = P_Selected_Check_id
--  AND    nvl(apsi.ok_to_pay_flag, 'Y') = 'Y'
--   AND    apsi.original_invoice_id IS NULL
    FOR UPDATE OF docs.dont_pay_flag,
                  docs.dont_pay_reason_code;
Line: 5815

       JL_ZZ_AP_EXT_AWT_UTIL.Debug (' Parameter P_Selected_Check_Id: '||to_char(P_Selected_Check_Id));
Line: 5823

    OPEN c_selected_invoices (P_Selected_Check_Id);
Line: 5825

        FETCH c_selected_invoices INTO l_ok_to_pay_flag,
                                       l_dont_pay_reason_code,
                                       l_invoice_id;
Line: 5829

        EXIT WHEN c_selected_invoices%NOTFOUND;
Line: 5830

        UPDATE iby_hook_docs_in_pmt_t docs
        SET    docs.dont_pay_flag = 'Y',
               docs.dont_pay_reason_code = AWT_ERROR
        WHERE  CURRENT OF c_selected_invoices;
Line: 5835

        UPDATE ap_selected_invoices
        SET    ok_to_pay_flag = 'N',
               dont_pay_reason_code =  AWT_ERROR
        WHERE   invoice_id     = l_invoice_id;
Line: 5842

    CLOSE c_selected_invoices;
Line: 5845

      UPDATE iby_hook_payments_t ipmt
      SET ipmt.dont_pay_flag = 'Y',
          ipmt.dont_pay_reason_code = AWT_ERROR
      WHERE  ipmt.payment_id =  P_Selected_Check_id;
Line: 5863

                '  Selected Check Id= ' || to_char(P_Selected_Check_Id) ||
                ', AWT Success= '       || P_AWT_Success);
Line: 5891

                         ,P_Last_Updated_By        IN     number
                         ,P_Last_Update_Login      IN     number
                         ,P_Program_Application_Id IN     number
                                                          default null
                         ,P_Program_Id             IN     number
                                                          default null
                         ,P_Request_Id             IN     number
                                                          default null
                         ,P_Awt_Success            OUT NOCOPY    varchar2
                         ,P_Invoice_Payment_Id     IN     number
                                                          default null
                         ,P_Check_Id               IN     number
                         )
IS
BEGIN

    	  -- Debug Information
    IF (DEBUG_Var = 'Y') THEN
       JL_ZZ_AP_EXT_AWT_UTIL.Debug ('PROCEDURE JL_CALL_DO_AWT(+)');
Line: 5920

                   ,P_Last_Updated_By
                   ,P_Last_Update_Login
                   ,P_Program_Application_id
                   ,P_Program_Id
                   ,P_Request_Id
                   ,P_Awt_Success
                   ,P_Invoice_Payment_Id
                   ,P_Check_Id
                   );
Line: 5943

 * Purpose    : Updates the payment amount by adding the withheld         *
 *              amount.                                                   *
 *                                                                        *
 **************************************************************************/
PROCEDURE Undo_Quick_Payment
                    (P_Check_Id                 IN     Number,
                     P_Old_Check_Id             IN     Number,
                     P_Calling_Sequence         IN     Varchar2)
IS

    ------------------------------
    -- Local variables definition
    ------------------------------
    l_invoice_payment_id    Number;
Line: 5979

    SELECT apip.invoice_payment_id      invoice_payment_id,
           apip.invoice_id              invoice_id,
           apip.exchange_rate           pay_exchange_rate,
           apip.payment_num             payment_num,
           apip.amount                  amount,
           apip.payment_base_amount     payment_base_amount,
           apip.invoice_base_amount     invoice_base_amount
    FROM   ap_invoice_payments apip
    WHERE  apip.check_id = P_Check_Id
    FOR UPDATE OF apip.amount,
                  apip.payment_base_amount,
                  apip.invoice_base_amount;
Line: 5997

    SELECT apch.amount        amount,
           apch.base_amount   base_amount
    FROM   ap_checks          apch
    WHERE  apch.check_id = P_Check_Id
    FOR UPDATE OF apch.amount,
                  apch.base_amount;
Line: 6012

   SELECT sum(aid.amount)
   FROM   ap_invoice_distributions aid,
          ap_invoice_payments aip,
          ap_invoices ai
   WHERE  aid.invoice_id  = aip.invoice_id
     AND  ai.invoice_id = aid.invoice_id
     AND  aid.invoice_id  = P_Invoice_Id
     AND  aid.awt_invoice_payment_id = aip.invoice_payment_id
     AND  aid.amount < 0
     AND  aip.check_id   = P_Old_Check_Id
     AND  ai.invoice_type_lookup_code NOT IN ('CREDIT','DEBIT')
     -- added recently
     --bug 12335657 AND    NVL(aid.REVERSAL_FLAG,'N') <> 'Y'
   UNION
    SELECT sum(aid.amount)
   FROM   ap_invoice_distributions aid,
          ap_invoice_payments aip,
          ap_invoices ai
   WHERE  aid.invoice_id  = aip.invoice_id
     AND  ai.invoice_id = aid.invoice_id
     AND  aid.invoice_id  = P_Invoice_Id
     AND  aid.awt_invoice_payment_id = aip.invoice_payment_id
     AND  aid.amount > 0
     AND  aip.check_id   = P_Old_Check_Id
     AND  ai.invoice_type_lookup_code IN ('CREDIT','DEBIT')
     -- added recently
     --bug 12335657 AND    NVL(aid.REVERSAL_FLAG,'N') <> 'Y'
   GROUP BY aid.invoice_id;
Line: 6110

            SELECT apin.exchange_rate,
                   apps.payment_cross_rate
            INTO   l_inv_exchange_rate,
                   l_payment_cross_rate
            FROM   ap_invoices          apin,
                   ap_payment_schedules apps
            WHERE  apin.invoice_id    = l_invoice_id
            AND    apps.invoice_id    = l_invoice_id
            AND    apps.payment_num   = l_payment_num;
Line: 6130

            UPDATE ap_payment_schedules
            SET    amount_remaining = amount_remaining +
                                      (l_withhold_amount *
                                       nvl(l_payment_cross_rate, 1)),
                   payment_status_flag = decode(amount_remaining +
                                                (l_withhold_amount *
                                                 nvl(l_payment_cross_rate, 1)),
                                                 0, 'Y',
                                                 amount_remaining,
                                                 payment_status_flag, 'P')
            WHERE  invoice_id  = l_invoice_id
            AND    payment_num = l_payment_num;
Line: 6147

            UPDATE ap_invoices
            SET    amount_paid         = nvl(amount_paid, 0) -
                                         (l_withhold_amount *
                                          nvl(l_payment_cross_rate, 1)),
                   payment_status_flag = AP_INVOICES_UTILITY_PKG.get_payment_status(l_invoice_id)
            WHERE invoice_id = l_invoice_id;
Line: 6173

            AP_AIP_TABLE_HANDLER_PKG.Update_Amounts(
                                   l_invoice_payment_id
                                  ,l_pay_amount
                                  ,l_invoice_base_amount
                                  ,l_payment_base_amount
                                  ,l_calling_sequence);
Line: 6211

           AP_AC_TABLE_HANDLER_PKG.Update_Amounts(
                       P_check_id
                      ,l_amount
                      ,l_base_amount
                      ,l_calling_sequence);