DBA Data[Home] [Help]

APPS.AP_PMT_CALLOUT_PKG SQL Statements

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

Line: 28

  select exchange_rate
  into l_rate
  from ap_user_exchange_rates
  where checkrun_id = p_checkrun_id
  and ledger_currency_code = p_base_currency_code
  and payment_currency_code = p_payment_currency_code;
Line: 103

    select check_id
    from ap_checks_all
    where completed_pmts_group_id = p_completed_pmts_group_id
    and org_id = p_current_org_id;
Line: 112

  select next_voucher_number
  into l_next_voucher_number
  from ap_inv_selection_criteria_all
  where checkrun_id = p_checkrun_id
  for update;
Line: 128

    update ap_checks_all
    set check_voucher_num = l_next_voucher_number
    where check_id = l_check_id;
Line: 138

  update ap_inv_selection_criteria_all
  set next_voucher_number = l_next_voucher_number
  where checkrun_id = p_checkrun_id;
Line: 162

    SELECT i.invoice_id
    FROM   ap_invoice_payments_all aip,
           ap_checks_all c,
           ap_invoices_all i,
           ap_invoice_relationships ir
    WHERE  c.check_id = p_check_id
    AND    c.check_id = aip.check_id
    AND    aip.invoice_id = ir.related_invoice_id
    AND    aip.invoice_id = i.invoice_id
    AND    i.invoice_type_lookup_code = 'INTEREST';
Line: 215

      update ap_invoices_all
      set doc_sequence_id = l_int_dbseqid,
          doc_sequence_value = l_int_seqval,
          doc_category_code = 'INT INV'
      where invoice_id = l_invoice_id;
Line: 246

  select ac.check_id,
         ac.payment_document_id,
         ac.payment_method_code,
         ac.ce_bank_acct_use_id
  from ap_checks_all ac,
       iby_payment_profiles ipp
  where completed_pmts_group_id = p_completed_pmts_group_id
  and   ipp.payment_profile_id = ac.payment_profile_id
  and   ac.org_id = p_current_org_id;
Line: 464

        update ap_checks_all
        set doc_sequence_id = l_dbseqid,
            doc_sequence_value = l_seqval,
            doc_category_code = l_doc_category_code
        where check_id = l_check_id;
Line: 552

  l_checkrun_name ap_inv_selection_criteria_all.checkrun_name%type;
Line: 558

    SELECT invoice_id
    ,      vendor_id
    ,      payment_num
    FROM   ap_SELECTed_invoices_all ASI,
           ap_system_parameters_all asp,
           iby_fd_docs_payable_v ibydocs
    WHERE  checkrun_name = l_checkrun_name
      AND  original_invoice_id IS NULL
      /* Bug 6950891. Added TO_CHAR */
      AND  ibydocs.calling_app_doc_unique_ref1 = TO_CHAR(ASI.checkrun_id)
      AND  ibydocs.calling_app_doc_unique_ref2 = TO_CHAR(ASI.invoice_id)
      AND  ibydocs.calling_app_doc_unique_ref3 = TO_CHAR(ASI.payment_num)
      AND  ibydocs.rejected_docs_group_id = p_rejected_docs_group_id
      AND  asp.org_id = asi.org_id
       and ibydocs.org_id=asp.org_id
       and ibydocs.calling_app_id = 200
      and  checkrun_id = l_checkrun_id
       AND  decode(nvl(ASP.allow_awt_flag, 'N'), 'Y',
                  decode(ASP.create_awt_dists_type,'BOTH','Y','PAYMENT',
                   'Y', decode(ASP.create_awt_invoices_type,'BOTH','Y','PAYMENT',
                              'Y', 'N'),
                         'N'),--Bug6660355
                  'N') = 'Y';
Line: 590

  select calling_app_doc_unique_ref1
  into l_checkrun_id
  from iby_fd_docs_payable_v
  where rejected_docs_group_id = p_rejected_docs_group_id
  and rownum=1;
Line: 597

  select checkrun_name, check_date
  into l_checkrun_name, l_check_date
  from ap_inv_selection_criteria_all
  where checkrun_id = l_checkrun_id;
Line: 605

    l_debug_info := 'Fetch CURSOR for all SELECTed invoices';
Line: 619

                     ,P_Last_Updated_By        => to_number(FND_PROFILE.VALUE('USER_ID'))
                     ,P_Last_Update_Login      => to_number(FND_PROFILE.VALUE('LOGIN_ID'))
                     ,P_Program_Application_Id => to_number(FND_PROFILE.VALUE('PROGRAM_APPLICATION_ID'))
                     ,P_Program_Id             => to_number(FND_PROFILE.VALUE('PROGRAM_ID'))
                     ,P_Request_Id             => to_number(FND_PROFILE.VALUE('REQUEST_ID'))
                     ,P_Awt_Success            => undo_output
                     ,P_checkrun_id            => l_checkrun_id );
Line: 629

  l_debug_info := 'CLOSE CURSOR for all SELECTed invoices';
Line: 635

  delete from ap_unselected_invoices_all
  where checkrun_id = l_checkrun_id;
Line: 640

  delete from ap_selected_invoices_all
  where checkrun_id = l_checkrun_id
  /* Bug 6950891. Added TO_CHAR */
  and (TO_CHAR(invoice_id), TO_CHAR(payment_num)) in
      (select calling_app_doc_unique_ref2,
              calling_app_doc_unique_ref3
       from iby_fd_docs_payable_v
       where rejected_docs_group_id = p_rejected_docs_group_id);
Line: 649

  update ap_payment_schedules_all
  set checkrun_id = null
  where checkrun_id = l_checkrun_id
  /* Bug 6950891. Added TO_CHAR */
  and (TO_CHAR(invoice_id), TO_CHAR(payment_num)) in
      (select calling_app_doc_unique_ref2,
              calling_app_doc_unique_ref3
       from iby_fd_docs_payable_v
       where rejected_docs_group_id = p_rejected_docs_group_id);
Line: 707

l_last_updated_by              number;
Line: 737

SELECT distinct calling_app_doc_unique_ref1
  FROM iby_fd_payments_v pmts,
       iby_fd_docs_payable_v docs
  WHERE pmts.payment_id = docs.payment_id
  AND pmts.completed_pmts_group_id = p_completed_pmts_group_id
  AND pmts.org_type = 'OPERATING_UNIT';
Line: 746

SELECT distinct pmts.org_id
  FROM iby_fd_payments_v pmts,
       iby_fd_docs_payable_v docs
  WHERE pmts.payment_id = docs.payment_id
  AND pmts.completed_pmts_group_id = p_completed_pmts_group_id
  AND pmts.org_type = 'OPERATING_UNIT'
  AND docs.calling_app_doc_unique_ref1 = c_checkrun_id;
Line: 758

  SELECT Distinct AC.Check_ID,
         APR.Reg_Application_ID
  FROM   AP_Checks_All AC,
         AP_Invoice_Payments_All AIP,
         AP_Invoices_All AI,
         AP_Product_Registrations APR
  WHERE  AC.Checkrun_Name = l_checkrun_name
  AND    AC.Completed_Pmts_Group_ID = p_completed_pmts_group_id
  AND    AC.Org_ID = l_current_org_id
  AND    AC.Check_ID = AIP.Check_ID
  AND    AIP.Invoice_ID = AI.Invoice_ID
  AND    AI.Application_ID = APR.Reg_Application_ID
  AND    APR.Registration_Event_Type = 'PAYMENT_CREATED';
Line: 773

  CURSOR c_invoice_amounts(p_last_updated_by    Number,
                           p_completed_group_id Number,
                           p_current_org_id     Number,
                           p_checkrun_name      Varchar2) IS
  SELECT sysdate,
         p_last_updated_by,
         iby_amount_paid,
         iby_discount_amount_taken,
         AP_INVOICES_UTILITY_PKG.get_payment_status(inv.invoice_id),
         inv.invoice_id
  FROM   ap_invoices_all          inv,
         ap_selected_invoices_all si,
         (SELECT sum(ibydocs.payment_amount)                      iby_amount_paid,
                 nvl(sum(ibydocs.payment_curr_discount_taken),0)  iby_discount_amount_taken,
                 ibydocs.calling_app_doc_unique_ref1  ref1,
                 ibydocs.calling_app_doc_unique_ref2  ref2,
                 ibydocs.calling_app_doc_unique_ref3  ref3
          FROM   iby_fd_docs_payable_v ibydocs,
                 iby_fd_payments_v ibypmts
          WHERE  ibypmts.org_type = 'OPERATING_UNIT'
          AND    ibypmts.payment_id = ibydocs.payment_id
          AND    ibypmts.completed_pmts_group_id = p_completed_group_id
          AND    ibypmts.org_id = p_current_org_id
          GROUP BY ibydocs.calling_app_doc_unique_ref1,
                   ibydocs.calling_app_doc_unique_ref2,
                   ibydocs.calling_app_doc_unique_ref3) ibydpm
  WHERE  inv.invoice_id = si.invoice_id
  AND    si.checkrun_name = p_checkrun_name
  AND    inv.invoice_type_lookup_code <> 'INTEREST'
  AND    ibydpm.ref2 = to_char(inv.invoice_id)
  AND    ibydpm.ref1 = to_char(si.checkrun_id)
  AND    ibydpm.ref2 = to_char(si.invoice_id)
  AND    ibydpm.ref3 = to_char(si.payment_num);
Line: 809

  CURSOR c_schedule_amounts(p_last_updated_by    Number,
                            p_completed_group_id Number,
                            p_current_org_id     Number,
                            p_checkrun_name      Varchar2) IS
  SELECT sysdate,
         p_last_updated_by,
         (si.amount_remaining - ibydocs.payment_amount -
            nvl(ibydocs.payment_curr_discount_taken,0)),
         0,
         decode(si.amount_remaining - ibydocs.payment_amount -
           nvl(ibydocs.payment_curr_discount_taken,0), 0,
           'Y', 'P'),
	    /* commented by zrehman for Bug#6836199 on 24-Jun-2008
 	 (si.amount_remaining - si.proposed_payment_amount -
            nvl(ibydocs.payment_curr_discount_taken,0)),
         0,
         decode(si.amount_remaining - si.proposed_payment_amount -
           nvl(ibydocs.payment_curr_discount_taken,0), 0,
           'Y', 'P'),*/
         -- Added by epajaril to capture the AWT
	 si.withholding_amount,
         Null,
         ps.invoice_id,
         ps.payment_num
  FROM   ap_payment_schedules_all  ps,
         ap_invoices_all           inv,
         ap_selected_invoices_all  si,
         iby_fd_payments_v         ibypmts,
         iby_fd_docs_payable_v     ibydocs
  WHERE  si.checkrun_name = p_checkrun_name
  AND    si.payment_num = ps.payment_num
  AND    si.invoice_id = ps.invoice_id
  AND    ibydocs.calling_app_doc_unique_ref1 = to_char(si.checkrun_id)
  AND    ibydocs.calling_app_doc_unique_ref2 = to_char(si.invoice_id)
  AND    ibydocs.calling_app_doc_unique_ref3 = to_char(si.payment_num)
  AND    ibypmts.payment_id = ibydocs.payment_id
  AND    ibypmts.completed_pmts_group_id = p_completed_group_id
  AND    ibypmts.org_id = p_current_org_id
  AND    ibypmts.org_type = 'OPERATING_UNIT'
  AND    inv.invoice_id = si.invoice_id
  AND    inv.invoice_id = ps.invoice_id
  AND    inv.invoice_type_lookup_code <> 'INTEREST';
Line: 857

  last_update_date_inv_l       t_date_tab;
Line: 858

  last_updated_by_inv_l        t_number_tab;
Line: 864

  last_update_date_ps_l        t_date_tab;
Line: 865

  last_updated_by_ps_l         t_number_tab;
Line: 893

  SELECT displayed_field
  INTO   l_nls_int_inv_desc
  FROM   ap_lookup_codes
  WHERE  lookup_type = 'NLS TRANSLATION'
  AND    lookup_code = 'INTEREST OVERDUE INVOICE';
Line: 902

  SELECT calling_app_doc_unique_ref1
  INTO l_checkrun_id
  FROM iby_fd_payments_v pmts,
       iby_fd_docs_payable_v docs
  WHERE pmts.payment_id = docs.payment_id
  AND pmts.completed_pmts_group_id = p_completed_pmts_group_id
  AND pmts.org_type = 'OPERATING_UNIT'
  AND rownum=1;
Line: 949

      SELECT exchange_rate_type,
             transfer_priority,
             check_date,
             checkrun_name,
             first_voucher_number
      INTO l_exchange_rate_type,
           l_transfer_priority,
           l_check_date,  --use this for the exchange date also, PM confirmed
           l_checkrun_name,
           l_first_voucher_number
      FROM ap_inv_selection_criteria_all
      WHERE checkrun_id = l_checkrun_id;
Line: 969

        SELECT apt.term_id
        INTO   l_interest_terms_id
        FROM   ap_terms apt, ap_terms_lines atl
        WHERE  apt.term_id = atl.term_id
        AND    atl.due_days=0
        AND    nvl(end_date_active,sysdate+1) >= sysdate
        AND    rownum < 2;
Line: 980

      l_last_updated_by   := to_number(FND_GLOBAL.USER_ID);
Line: 1011

          SELECT nvl(when_to_account_pmt,'ALWAYS'),
                 --nvl(prorate_int_inv_across_dists,'N'),
                 interest_code_combination_id,
                 base_currency_code,
                 nvl(auto_calculate_interest_flag, 'N'),
                 interest_accts_pay_ccid,
                 DECODE(account_type, 'A','Y','N'),
                 to_char(sysdate, 'DD-MON-RR HH24:MI'),
                 gsob.name,
                 decode(l_batch_control_flag, 'Y', AP_BATCHES_S.nextval, null),
                 decode(nvl(ASP.allow_awt_flag, 'N'),
                            'Y', decode(ASP.create_awt_dists_type,
                                     'PAYMENT', 'Y',
                                                decode(ASP.create_awt_invoices_type,
                                                    'PAYMENT', 'Y',
                                                               'N')),
                            'N'),
                 asp.set_of_books_id,
                 ap_utilities_pkg.get_gl_period_name(l_check_date,l_current_org_id)
          INTO  l_when_to_account_payment,
                --l_prorate_int_inv_across_dists,
                l_interest_code_combination_id,
                l_base_currency_code,
                l_auto_calculate_interest_flag,
                l_interest_accts_pay_ccid,
                l_int_asset_tracking_flag,
                l_report_date,
                l_company_name,
                l_int_batch_id,
                l_perform_awt_flag,
                l_set_of_books_id,
                l_period_name
          FROM ap_system_parameters_all asp,
               gl_code_combinations gc,
               gl_sets_of_books gsob
          WHERE gc.code_combination_id(+) = asp.interest_code_combination_id
          AND   gsob.set_of_books_id = asp.set_of_books_id
          AND   asp.org_id = l_current_org_id;
Line: 1051

          select minimum_accountable_unit, precision
          into l_base_currency_mac, l_base_currency_precision
          from fnd_currencies
          where currency_code = l_base_currency_code;
Line: 1059

            l_debug_info := 'do interest invoice insertions';
Line: 1064

            INSERT INTO ap_invoices_all(
             invoice_id,
             last_update_date,
             last_updated_by,
             vendor_id,
             invoice_num,
             invoice_amount,
             vendor_site_id,
             amount_paid,
             discount_amount_taken,
             invoice_date,
             invoice_type_lookup_code,
             description,
             batch_id,
             amount_applicable_to_discount,
             tax_amount,
             terms_id,
             terms_date,
             voucher_num,
             pay_group_lookup_code,
             set_of_books_id,
             accts_pay_code_combination_id,
             invoice_currency_code,
             payment_currency_code,
             payment_status_flag,
             posting_status,
             creation_date,
             created_by,
             payment_cross_rate,
             exchange_rate,
             exchange_rate_type,
             exchange_date,
             base_amount,
             source,
             payment_method_code,
             pay_curr_invoice_amount,
             payment_cross_rate_date,
             payment_cross_rate_type,
             gl_date,
             exclusive_payment_flag,
             approval_ready_flag,
             wfapproval_status,
             legal_entity_id,
             org_id,
             party_id,
             party_site_id,
	     -- added below columns for 7673570
             remit_to_supplier_name,
             remit_to_supplier_id,
             remit_to_supplier_site,
             remit_to_supplier_site_id,
	     relationship_id)
            SELECT
                new.invoice_id,
                SYSDATE,
                l_last_updated_by,
                new.vendor_id,
                new.invoice_num,
                decode(fcinv.minimum_accountable_unit, null,
                           round((new.payment_amount/orig.payment_cross_rate),
                                 fcinv.precision),
                           round((new.payment_amount/orig.payment_cross_rate)
                                 /fcinv.minimum_accountable_unit)
                                * fcinv.minimum_accountable_unit),
                new.vendor_site_id,
                ibydocs.payment_amount,
                0,
                new.due_date,
                'INTEREST',
                new.invoice_description||orig.invoice_num,
                l_int_batch_id,
                null,
                null,
                orig.terms_id,  /* bug 5124784. Terms will be the parent Invoice term. */
                orig.terms_date,
                orig.voucher_num,
                orig.pay_group_lookup_code,
                orig.set_of_books_id,
                l_interest_accts_pay_ccid,
                orig.invoice_currency_code,
                orig.payment_currency_code,
                'Y',
                null,
                SYSDATE,
                l_last_updated_by,
                orig.payment_cross_rate,
                orig.exchange_rate,
                orig.exchange_rate_type,
                orig.exchange_date,
                decode(orig.invoice_currency_code, l_base_currency_code,
                       NULL,
                       decode(l_base_currency_mac, null,
                              round(new.payment_amount / orig.payment_cross_rate *
                                     decode(l_exchange_rate_type, 'User',
                                             ap_pmt_callout_pkg.get_user_rate(
                                                              l_base_currency_code,
                                                              ibypmts.payment_currency_code,
                                                              l_checkrun_id),
                                             nvl(ap_utilities_pkg.get_exchange_rate(
                                                   ibypmts.payment_currency_code,
                                                   l_base_currency_code,
                                                   l_exchange_rate_type,
                                                   l_check_date,
                                                   'CONFIRM'),1)), l_base_currency_precision),

                              round( (new.payment_amount / orig.payment_cross_rate *
                                     decode(l_exchange_rate_type, 'User',
                                             ap_pmt_callout_pkg.get_user_rate(
                                                              l_base_currency_code,
                                                              ibypmts.payment_currency_code,
                                                              l_checkrun_id),
                                             nvl(ap_utilities_pkg.get_exchange_rate(
                                                   ibypmts.payment_currency_code,
                                                   l_base_currency_code,
                                                   l_exchange_rate_type,
                                                   l_check_date,
                                                   'CONFIRM'),1)) ) /
                                      l_base_currency_mac) *
                                    l_base_currency_mac  ) ),

                'Confirm PaymentBatch',
                orig.payment_method_code,
                new.payment_amount,
                orig.payment_cross_rate_date,
                orig.payment_cross_rate_type,
                new.due_date,
                new.exclusive_payment_flag,
                'Y',
                'NOT REQUIRED',
                ibypmts.legal_entity_id,
                ibypmts.org_id,
                orig.party_id,
                orig.party_site_id,
		-- added below columns for 7673570
 	        ibypmts.PAYEE_NAME,
                aps.vendor_id,
                aps.vendor_site_code,
                ibypmts.supplier_site_id,
	        ibypmts.relationship_id
            FROM   ap_invoices_all orig,
                   ap_supplier_sites_all aps, -- bug 7673570
                   iby_fd_payments_v ibypmts,
                   ap_selected_invoices_all new,
                   iby_fd_docs_payable_v ibydocs,
                   fnd_currencies fcinv
            /* Bug 6950891. Added TO_CHAR */
            WHERE ibydocs.calling_app_doc_unique_ref1 = TO_CHAR(new.checkrun_id)
            AND   ibydocs.calling_app_doc_unique_ref2 = TO_CHAR(new.invoice_id)
            AND   ibydocs.calling_app_doc_unique_ref3 = TO_CHAR(new.payment_num)
            AND   new.original_invoice_id = orig.invoice_id
            and   ibypmts.org_type = 'OPERATING_UNIT'
            AND   ibypmts.payment_id = ibydocs.payment_id
            AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
            AND   aps.vendor_site_id = ibypmts.supplier_site_id -- bug 7673570
            AND   fcinv.currency_code = orig.invoice_currency_code
            AND   ibypmts.org_id = l_current_org_id;
Line: 1224

            l_debug_info := 'do interest invoice line insertions';
Line: 1229

            INSERT INTO ap_invoice_lines_all(
                INVOICE_ID,
                LINE_NUMBER,
                LINE_TYPE_LOOKUP_CODE,
                LAST_UPDATE_DATE,
                LAST_UPDATED_BY,
                CREATION_DATE,
                CREATED_BY,
                ACCOUNTING_DATE,
                PERIOD_NAME,
                AMOUNT,
                BASE_AMOUNT,
                DESCRIPTION,
                TYPE_1099,
                SET_OF_BOOKS_ID,
                ASSETS_TRACKING_FLAG,
          --      ASSET_BOOK_TYPE_CODE, ??
          --      ASSET_CATEGORY_ID,    ??
                LINE_SOURCE,
                GENERATE_DISTS,
                WFAPPROVAL_STATUS,
                org_id)
              SELECT  new.invoice_id,
                1,
                'ITEM',
                SYSDATE,
                l_last_updated_by,
                sysdate,
                l_last_updated_by,
                new.due_date,
                l_period_name,
                decode(fcinv.minimum_accountable_unit, null,
                           round((ibydocs.payment_amount/orig.payment_cross_rate),
                                 fcinv.precision),
                           round((ibydocs.payment_amount/orig.payment_cross_rate)
                                 /fcinv.minimum_accountable_unit)
                                * fcinv.minimum_accountable_unit),
                 decode(orig.invoice_currency_code, l_base_currency_code,
                        NULL,
                        decode(l_base_currency_mac, null,
                              round(new.payment_amount / orig.payment_cross_rate *
                                     decode(l_exchange_rate_type, 'User',
                                             ap_pmt_callout_pkg.get_user_rate(
                                                              l_base_currency_code,
                                                              ibypmts.payment_currency_code,
                                                              l_checkrun_id),
                                             nvl(ap_utilities_pkg.get_exchange_rate(
                                                   ibypmts.payment_currency_code,
                                                   l_base_currency_code,
                                                   l_exchange_rate_type,
                                                   l_check_date,
                                                   'CONFIRM'),1)), l_base_currency_precision),
                              round( (new.payment_amount / orig.payment_cross_rate *
                                     decode(l_exchange_rate_type, 'User',
                                             ap_pmt_callout_pkg.get_user_rate(
                                                              l_base_currency_code,
                                                              ibypmts.payment_currency_code,
                                                              l_checkrun_id),
                                             nvl(ap_utilities_pkg.get_exchange_rate(
                                                   ibypmts.payment_currency_code,
                                                   l_base_currency_code,
                                                   l_exchange_rate_type,
                                                   l_check_date,
                                                   'CONFIRM'),1)) ) /
                                      l_base_currency_mac) *
                                    l_base_currency_mac  ) ),
                new.invoice_description||orig.invoice_num,
                pv.type_1099,
                l_set_of_books_id,
                l_int_asset_tracking_flag,
                'AUTO INVOICE CREATION',
                'N',
                'NOT REQUIRED',
                l_current_org_id
              FROM
                po_vendors pv,
                ap_invoices_all orig,
                iby_fd_payments_v ibypmts,
                iby_fd_docs_payable_v ibydocs,
                ap_selected_invoices new,
                fnd_currencies fcinv
              /* Bug 6950891. Added TO_CHAR */
              WHERE ibydocs.calling_app_doc_unique_ref1 = TO_CHAR(new.checkrun_id)
              AND   ibydocs.calling_app_doc_unique_ref2 = TO_CHAR(new.invoice_id)
              AND   ibydocs.calling_app_doc_unique_ref3 = TO_CHAR(new.payment_num)
              AND   ibypmts.payment_id = ibydocs.payment_id
              AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
              AND   ibypmts.org_id = l_current_org_id
              and   ibypmts.org_type = 'OPERATING_UNIT'
              AND   new.original_invoice_id = orig.invoice_id
              AND   new.vendor_id = pv.vendor_id
              AND   new.checkrun_name = l_checkrun_name
              AND   fcinv.currency_code = orig.invoice_currency_code;
Line: 1336

                P_last_updated_by                => l_last_updated_by,
                P_period_name                    => l_period_name,
                P_asset_account_flag             => l_int_asset_tracking_flag,
                P_calling_sequence               => l_current_calling_sequence,
                p_checkrun_id                    => l_checkrun_id,
                p_completed_pmts_group_id        => p_completed_pmts_group_id,
                p_org_id                         => l_current_org_id);
Line: 1346

            l_debug_info := 'INSERT INTO ap_payment_schedules_all';
Line: 1351

            INSERT INTO ap_payment_schedules_all(
              invoice_id,
              payment_num,
              last_update_date,
              last_updated_by,
              due_date,
              gross_amount,
              discount_amount_available,
              amount_remaining,
              discount_amount_remaining,
              payment_priority,
              payment_status_flag,
              batch_id,
              payment_cross_rate,
              creation_date,
              created_by,
              payment_method_code,
              inv_curr_gross_amount,
              org_id,
	      -- added below columns for 7673570
              remit_to_supplier_name,
              remit_to_supplier_id,
              remit_to_supplier_site,
              remit_to_supplier_site_id,
	      relationship_id)
            SELECT
              new.invoice_id,
              1,
              SYSDATE,
              l_last_updated_by,
              new.due_date,
              ibydocs.payment_amount,
              0,
              0,
              0,
              new.payment_priority,
              'Y',
              l_int_batch_id,
              orig.payment_cross_rate,
              SYSDATE,
              l_last_updated_by,
              orig.payment_method_code,
              decode(fcinv.minimum_accountable_unit, null,
                           round((new.payment_amount/orig.payment_cross_rate),
                                 fcinv.precision),
                           round((new.payment_amount/orig.payment_cross_rate)
                                 /fcinv.minimum_accountable_unit)
                                * fcinv.minimum_accountable_unit),
              l_current_org_id,
	      -- added below columns for 7673570
	      ibypmts.PAYEE_NAME,
              aps.vendor_id,
              aps.vendor_site_code,
              ibypmts.supplier_site_id,
	      ibypmts.relationship_id
            FROM ap_invoices_all orig,
                 ap_selected_invoices_all new,
                 ap_supplier_sites_all aps, -- bug 7673570
                 fnd_currencies fcinv,
                 iby_fd_payments_v ibypmts,
                 iby_fd_docs_payable_v ibydocs
            /* Bug 6950891. Added TO_CHAR */
            WHERE ibydocs.calling_app_doc_unique_ref1 = TO_CHAR(new.checkrun_id)
            AND   ibydocs.calling_app_doc_unique_ref2 = TO_CHAR(new.invoice_id)
            AND   ibydocs.calling_app_doc_unique_ref3 = TO_CHAR(new.payment_num)
            AND   ibypmts.payment_id = ibydocs.payment_id
            AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
            and   ibypmts.org_type = 'OPERATING_UNIT'
            AND   ibypmts.org_id = l_current_org_id
	    AND   aps.vendor_site_id = ibypmts.supplier_site_id -- bug 7673570
            AND   new.original_invoice_id = orig.invoice_id
            AND   new.checkrun_name = l_checkrun_name
            AND   fcinv.currency_code = orig.invoice_currency_code;
Line: 1427

            l_debug_info := 'INSERT INTO ap_invoice_relationships';
Line: 1432

            INSERT INTO ap_invoice_relationships(
              original_invoice_id,
              related_invoice_id,
              created_by,
              creation_date,
              original_payment_num,
              last_updated_by,
              last_update_date,
              checkrun_name)
            SELECT orig.invoice_id,
                   new.invoice_id,
                   l_last_updated_by,
                   SYSDATE,
                   new.original_payment_num,
                   l_last_updated_by,
                   SYSDATE,
                   l_checkrun_name
            FROM ap_invoices_all orig,
                 ap_selected_invoices_all new,
                 iby_fd_payments_v ibypmts,
                 iby_fd_docs_payable_v ibydocs
            /* Bug 6950891. Added TO_CHAR */
            WHERE ibydocs.calling_app_doc_unique_ref1 = TO_CHAR(new.checkrun_id)
            AND   ibydocs.calling_app_doc_unique_ref2 = TO_CHAR(new.invoice_id)
            and   ibypmts.org_type = 'OPERATING_UNIT'
            AND   ibydocs.calling_app_doc_unique_ref3 = TO_CHAR(new.payment_num)
            AND   ibypmts.payment_id = ibydocs.payment_id
            AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
            AND   ibypmts.org_id = l_current_org_id
            AND   new.original_invoice_id = orig.invoice_id
            AND   new.checkrun_name = l_checkrun_name;
Line: 1468

                l_debug_info := 'INSERT INTO ap_batches_all';
Line: 1473

              INSERT INTO ap_batches_all(
                batch_id,
                batch_name,
                batch_date,
                last_update_date,
                last_updated_by,
                control_invoice_count,
                actual_invoice_count,
                creation_date,
                created_by,
                org_id) --4945922
              SELECT  l_int_batch_id,
                substrb(LC.displayed_field||l_checkrun_name, 1,50),
                SYSDATE,
                SYSDATE,
                l_last_updated_by,
                count(*),
                count(*),
                SYSDATE,
                l_last_updated_by,
                i.org_id
              FROM ap_invoices_all I,
                   ap_lookup_codes LC
              WHERE I.batch_id= l_int_batch_id
              AND   LC.lookup_code = 'NLS TRANLSATION'
              AND   LC.lookup_type = 'INTEREST ON PAYMENTBATCH'
              GROUP BY l_int_batch_id, l_checkrun_name,
                       LC.displayed_field, SYSDATE, l_last_updated_by, i.org_id;
Line: 1509

	/*bug8224330, transported the insert into ap_checks_all here, after the insertion of interest invoices related data
                	 into ap tables*/

          l_debug_info := 'insert into ap_checks_all';
Line: 1518

          INSERT INTO ap_checks_all
          (CHECK_ID,
           -- Bug 6845440 commented below field
           -- BANK_ACCOUNT_ID,
           CE_BANK_ACCT_USE_ID,
           BANK_ACCOUNT_NAME,
           AMOUNT,
           CHECK_NUMBER,
           CHECK_DATE,
           CURRENCY_CODE,
           LAST_UPDATE_DATE,
           LAST_UPDATED_BY,
           VENDOR_ID,
           VENDOR_NAME,
           VENDOR_SITE_ID,
           STATUS_LOOKUP_CODE,
           CHECKRUN_ID,
           CHECKRUN_NAME,
           ADDRESS_LINE1,
           ADDRESS_LINE2,
           ADDRESS_LINE3,
           ADDRESS_LINE4,
           CITY,
           STATE,
           ZIP,
           PROVINCE,
           COUNTRY,
        --   VENDOR_SITE_CODE,
           BANK_ACCOUNT_NUM,
        --   IBAN_NUMBER,
           BANK_NUM,
           BANK_ACCOUNT_TYPE,
           EXTERNAL_BANK_ACCOUNT_ID,
           TRANSFER_PRIORITY,
           PAYMENT_TYPE_FLAG,
           CREATION_DATE,
           CREATED_BY,
           PAYMENT_METHOD_code,
           EXCHANGE_RATE,
           EXCHANGE_RATE_TYPE,
           EXCHANGE_DATE,
           BASE_AMOUNT,
           FUTURE_PAY_DUE_DATE,
           MATURITY_EXCHANGE_DATE,
           MATURITY_EXCHANGE_RATE_TYPE,
           MATURITY_EXCHANGE_RATE,
           ANTICIPATED_VALUE_DATE,
           LEGAL_ENTITY_ID,
           ORG_ID,
           PAYMENT_ID,
           COMPLETED_PMTS_GROUP_ID,
           PAYMENT_PROFILE_ID, --SO WE CAN REFER BACK TO IBY
           PARTY_ID,
           PARTY_SITE_ID,
           PAYMENT_DOCUMENT_ID, --4752808
           PAYMENT_INSTRUCTION_ID, --4884849
	   -- added below columns for 7673570
           REMIT_TO_SUPPLIER_NAME,
           REMIT_TO_SUPPLIER_ID,
           REMIT_TO_SUPPLIER_SITE,
           REMIT_TO_SUPPLIER_SITE_ID,
	   RELATIONSHIP_ID)
          SELECT
               ap_checks_s.nextval,
               -- Bug 6845440 commented below field
               -- ce.bank_account_id,
               ce.bank_acct_use_id,
               ceb.bank_account_name,
               iby.payment_amount,
               nvl(iby.paper_document_number, iby.payment_reference_number),
               iby.payment_date,
               iby.payment_currency_code,
               SYSDATE,
               l_last_updated_by,
               pv.vendor_id,
               pv.vendor_name,
               iby.inv_supplier_site_id, -- 7673570
               decode(iby.maturity_date,null,'NEGOTIABLE','ISSUED'),
               l_checkrun_id,
               l_checkrun_name,
               iby.payee_address1,
               iby.payee_address2,
               iby.payee_address3,
               iby.payee_address4,
               iby.payee_city,
               iby.payee_state,
               iby.payee_postal_code,
               iby.payee_province,
               iby.payee_country,
        --       sc.vendor_site_code,
               iby.ext_bank_account_number,
        --       SC.iban_number, --need FROM iby
               -- iby.ext_bank_account_name,  -- Bug 5090441
               iby.EXT_BANK_NUMBER,
               iby.ext_bank_account_type,
               iby.external_bank_account_id,
               l_transfer_priority,
               'A',
               sysdate,
               l_last_updated_by,
               iby.payment_method_code,
               decode(iby.payment_currency_code, l_base_currency_code,
                      null,
                      decode(l_exchange_rate_type, 'User',
                             ap_pmt_callout_pkg.get_user_rate(
                                 l_base_currency_code,
                                 iby.payment_currency_code,
                                 l_checkrun_id),
                             ap_utilities_pkg.get_exchange_rate(
                                 iby.payment_currency_code,
                                 l_base_currency_code,
                                 l_exchange_rate_type,
                                 l_check_date,
                                 'CONFIRM'))),
               l_exchange_rate_type,
               l_check_date, --exchange rate date
               decode(iby.payment_currency_code, l_base_currency_code,
                      null,
                      ap_pmt_callout_pkg.get_base_amount(l_base_currency_code,
                                                        iby.payment_currency_code,
                                                        l_checkrun_id,
                                                        l_exchange_rate_type,
                                                        l_base_currency_mac,
                                                        iby.payment_amount,
                                                        l_base_currency_precision,
                                                        l_check_date)),
               iby.maturity_date,
               decode(iby.payment_currency_code, l_base_currency_code,
                       null,
                       decode(l_exchange_rate_type, 'User', l_check_date,
                              iby.maturity_date)),
               l_exchange_rate_type,
               decode(iby.payment_currency_code, l_base_currency_code, NULL,
                       decode(l_exchange_rate_type, 'User',
                              ap_pmt_callout_pkg.get_user_rate(l_base_currency_code,
                                                               iby.payment_currency_code,
                                                               l_checkrun_id),
                              ap_utilities_pkg.get_exchange_rate(
                                  iby.payment_currency_code,
                                  l_base_currency_code,
                                  l_exchange_rate_type,
                                  iby.maturity_date,
                                  'CONFIRM'))),
               iby.anticipated_value_date,
               iby.legal_entity_id,
               iby.org_id,
               iby.payment_id,
               iby.completed_pmts_group_id,
               iby.payment_profile_id,
               iby.inv_payee_party_id, -- 7673570 iby.payee_party_id,
               iby.inv_party_site_id,  -- 7673570 iby.party_site_id,
               iby.payment_document_id,
               iby.payment_instruction_id,
               -- added below columns for 7673570
	       iby.PAYEE_NAME,
               aps.vendor_id,
               aps.vendor_site_code,
               iby.supplier_site_id,
	       iby.relationship_id
          FROM iby_fd_payments_v iby,
               po_vendors pv,
               ce_bank_acct_uses_all ce,
               ce_bank_accounts ceb,
	       ap_supplier_sites_all aps -- 7673570
          WHERE  iby.inv_payee_party_id = pv.party_id(+) -- 7673570
	         --iby.payee_party_id = pv.party_id(+)   -- 7673570
         AND  aps.vendor_site_id = iby.supplier_site_id  -- 7673570
	 AND pv.end_date_active IS NULL       -- bug7166247
          --added condition as per Bug 7196023
         AND nvl(pv.vendor_id,-99) =  (select decode(inv.invoice_type_lookup_code,'PAYMENT REQUEST',-99,nvl(vendor_id,-99)) --Bug7493630
                                       from ap_invoices_all inv,iby_docs_payable_all idp
                                       where inv.invoice_id=idp.calling_app_doc_unique_ref2
                                       and idp.payment_id=iby.payment_id
                                       and idp.calling_app_doc_unique_ref1=l_checkrun_id
                                       and rownum=1
                                       )     --7196023
          AND    ce.bank_account_id = iby.internal_bank_account_id
          and    ceb.bank_account_id = ce.bank_account_id
          and    iby.org_type = 'OPERATING_UNIT'
          AND    ce.org_id = l_current_org_id
          AND    iby.org_id = l_current_org_id
          AND    iby.completed_pmts_group_id = p_completed_pmts_group_id
	  -- Bug 6752984
          AND    iby.payment_service_request_id =
                       (SELECT payment_service_request_id
                          FROM IBY_PAY_SERVICE_REQUESTS
                         WHERE call_app_pay_service_req_code = l_checkrun_name
                           AND CALLING_APP_ID = 200);
Line: 1740

              l_debug_info := 'AP_ACCOUNTING_EVENTS_PKG.update_pmt_batch_event_status';
Line: 1745

             AP_ACCOUNTING_EVENTS_PKG.update_pmt_batch_event_status(
                               p_checkrun_name    => l_checkrun_name,
                               p_org_id           => l_current_org_id,
                               p_completed_pmts_group_id => p_completed_pmts_group_id,
                               p_calling_sequence => l_current_calling_sequence);
Line: 1755

          l_debug_info := 'UPDATE ap_selected_invoices_all';
Line: 1760

          UPDATE ap_selected_invoices_all ASI
          SET    ASI.invoice_payment_id = ap_invoice_payments_s.nextval
          WHERE  ASI.checkrun_id = l_checkrun_id
          /* Bug 6950891. Added TO_CHAR */
          AND  (TO_CHAR(ASI.invoice_id), TO_CHAR(ASI.payment_num)) in
                   (select calling_app_doc_unique_ref2, calling_app_doc_unique_ref3
                    FROM iby_fd_docs_payable_v ibydocs,
                         iby_fd_payments_v ibypmts
                    WHERE ibydocs.payment_id = ibypmts.payment_id
                    and   ibypmts.org_type = 'OPERATING_UNIT'
                    AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
                    AND   ibypmts.org_id = l_current_org_id);
Line: 1776

             l_debug_info := ' UPDATE ap_awt_temp_distributions_all';
Line: 1781

            UPDATE ap_awt_temp_distributions_all AATD
            SET    AATD.invoice_payment_id =
                                (SELECT ASI.invoice_payment_id
                                 FROM   ap_selected_invoices_all ASI
                                 WHERE  ASI.checkrun_id = AATD.checkrun_id
                                 AND    ASI.invoice_id    = AATD.invoice_id
                                 AND    ASI.payment_num   = AATD.payment_num
                                 AND    asi.org_id = l_current_org_id)
            WHERE  AATD.checkrun_id = l_checkrun_id
            AND    aatd.org_id = l_current_org_id
            /* Bug 6950891. Added TO_CHAR */
            AND  (TO_CHAR(AATD.invoice_id), TO_CHAR(AATD.payment_num)) in
                   /* Bug 5383066, calling_app_doc_unique_ref3 should be used for payment_num*/
                   (select calling_app_doc_unique_ref2, calling_app_doc_unique_ref3
                    FROM iby_fd_docs_payable_v ibydocs,
                         iby_fd_payments_v ibypmts
                    WHERE ibydocs.payment_id = ibypmts.payment_id
                    and   ibypmts.org_type = 'OPERATING_UNIT'
                    AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
                    AND   ibypmts.org_id = l_current_org_id);
Line: 1808

                                                   l_last_updated_by,
                                                   --4863216
                                                   to_number(FND_PROFILE.VALUE('LOGIN_ID')),
                                                   to_number(FND_PROFILE.VALUE('PROGRAM_APPLICATION_ID')),
                                                   to_number(FND_PROFILE.VALUE('PROGRAM_ID')),
                                                   to_number(FND_PROFILE.VALUE('REQUEST_ID')),
                                                   l_checkrun_id,
                                                   p_completed_pmts_group_id,
                                                   l_current_org_id,
                                                   l_check_date);
Line: 1819

            l_debug_info := 'DELETE FROM ap_awt_temp_distributions_all';
Line: 1824

           /*  Bug 5383066. Foloowing Delete is not requeired. As call to
               AP_WITHHOLDING_PKG.AP_WITHHOLD_CANCEL cleans up temporary withholding dists.

            WHERE checkrun_name = l_checkrun_name
            AND   org_id = l_current_org_id
            and   checkrun_id = l_checkrun_id
            and   (invoice_id, payment_num) in
                  (select calling_app_doc_unique_ref2, calling_app_doc_unique_ref2
                   FROM iby_fd_docs_payable_v ibydocs
                   where calling_app_doc_unique_ref1 = l_checkrun_id
                   and completed_pmts_group_id = p_completed_pmts_group_id
                   and org_id = l_current_org_id);
Line: 1840

          OPEN c_schedule_amounts(l_last_updated_by              --Bug5733731
                                 ,p_completed_pmts_group_id
                                 ,l_current_org_id
                                 ,l_checkrun_name);
Line: 1848

                last_update_date_ps_l,
                last_updated_by_ps_l,
                amount_remaining_ps_l,
                discount_remaining_ps_l,
                payment_status_ps_l,
		awt_num_ps_l,
                checkrun_id_ps_l,
                invoice_id_ps_l,
                payment_num_ps_l
                LIMIT 1000;
Line: 1859

                l_debug_info := 'UPDATE ap_payment_schedules_all';
Line: 1865

                  UPDATE ap_payment_schedules_all
                  SET    last_update_date  = last_update_date_ps_l(i)
                        ,last_updated_by   = last_updated_by_ps_l(i)
		       -- Modified by epajaril, need to consider the AWT
                       -- ,amount_remaining  = amount_remaining_ps_l(i)
		       ,amount_remaining  = (amount_remaining_ps_l(i) -
                                              nvl(awt_num_ps_l(i),0))        --bug:7523065
                        ,discount_amount_remaining = discount_remaining_ps_l(i)
                        ,payment_status_flag = payment_status_ps_l(i)
                        ,checkrun_id       = checkrun_id_ps_l(i)
                   WHERE invoice_id = invoice_id_ps_l(i)
                   AND   payment_num = payment_num_ps_l(i);
Line: 1889

          OPEN c_invoice_amounts(l_last_updated_by
                                 ,p_completed_pmts_group_id
                                 ,l_current_org_id
                                 ,l_checkrun_name);
Line: 1898

                last_update_date_inv_l,
                last_updated_by_inv_l,
                amount_paid_inv_l,
                discount_taken_inv_l,
                payment_status_inv_l,
                invoice_id_inv_l
                LIMIT 1000;
Line: 1906

                l_debug_info := 'UPDATE ap_invoices_all';
Line: 1912

                  UPDATE ap_invoices_all
                  SET    last_update_date  = last_update_date_inv_l(i)
                        ,last_updated_by   = last_updated_by_inv_l(i)
                        ,amount_paid       = nvl(amount_paid,0) + amount_paid_inv_l(i)
                        ,discount_amount_taken = nvl(discount_amount_taken,0) + discount_taken_inv_l(i)
                        ,payment_status_flag = payment_status_inv_l(i)
                   WHERE invoice_id = invoice_id_inv_l(i);
Line: 1927

          l_debug_info := 'insert into ap_invoice_payments_all';
Line: 1932

          INSERT INTO ap_invoice_payments_all(
              INVOICE_PAYMENT_ID,
              INVOICE_ID,
              PAYMENT_NUM,
              CHECK_ID,
              AMOUNT,
              LAST_UPDATE_DATE,
              LAST_UPDATED_BY,
              ELECTRONIC_TRANSFER_ID,
              SET_OF_BOOKS_ID,
              ACCTS_PAY_CODE_COMBINATION_ID,
              ACCOUNTING_DATE,
              PERIOD_NAME,
              POSTED_FLAG,
              ACCRUAL_POSTED_FLAG,
              CASH_POSTED_FLAG,
              DISCOUNT_TAKEN,
              DISCOUNT_LOST,
              EXCHANGE_RATE,
              EXCHANGE_RATE_TYPE,
              GAIN_CODE_COMBINATION_ID,
              LOSS_CODE_COMBINATION_ID,
              ASSET_CODE_COMBINATION_ID,
              INVOICE_BASE_AMOUNT,
              PAYMENT_BASE_AMOUNT,
              EXCHANGE_DATE,
              BANK_ACCOUNT_NUM,
         --     IBAN_NUMBER, --Bug 2633878
              BANK_NUM,
              BANK_ACCOUNT_TYPE,
              EXTERNAL_BANK_ACCOUNT_ID,
              ATTRIBUTE1,
              ATTRIBUTE2,
              ATTRIBUTE3,
              ATTRIBUTE4,
              ATTRIBUTE5,
              ATTRIBUTE6,
              ATTRIBUTE7,
              ATTRIBUTE8,
              ATTRIBUTE9,
              ATTRIBUTE10,
              ATTRIBUTE11,
              ATTRIBUTE12,
              ATTRIBUTE13,
              ATTRIBUTE14,
              ATTRIBUTE15,
              ATTRIBUTE_CATEGORY, -- Bug 4087878
              FUTURE_PAY_CODE_COMBINATION_ID,
              FUTURE_PAY_POSTED_FLAG,
              ACCOUNTING_EVENT_ID,
              CREATION_DATE,
              CREATED_BY,
              ORG_ID, --4945922
              INVOICING_PARTY_ID, /*4739343, added 3rd party columns*/
              INVOICING_PARTY_SITE_ID,
              INVOICING_VENDOR_SITE_ID,  -- Bug 5658623
	      -- added below columns for 7673570
              REMIT_TO_SUPPLIER_NAME,
              REMIT_TO_SUPPLIER_ID,
              REMIT_TO_SUPPLIER_SITE,
              REMIT_TO_SUPPLIER_SITE_ID)
          SELECT /*+ Leading(xeg) index(ac ap_checks_u1) */
               SI.invoice_payment_id,
              SI.invoice_id,
              SI.payment_num,
              ac.check_id,
              ibydocs.payment_amount,
              sysdate,
              l_last_updated_by,
              NULL,
              l_set_of_books_id,
              null,
              trunc(l_check_date),    --bug6602676
              l_period_name,
              'N',
              'N',
              'N',
              DECODE(ibydocs.payment_curr_discount_taken,0,'',ibydocs.payment_curr_discount_taken),
              DECODE(ps.invoice_id, null, 0,
                 DECODE(ps.gross_amount, 0, 0,
                      (DECODE(FORE.minimum_accountable_unit,NULL,
                              ROUND((((ibydocs.payment_amount+ibydocs.payment_curr_discount_taken)/
                                      DECODE(ps.gross_amount,0,1,ps.gross_amount)) *
                                     (greatest (nvl(PS.discount_amount_available,0),
                                                nvl(PS.second_disc_amt_available,0),
                                                nvl(PS.third_disc_amt_available,0)))),
                                    FORE.precision),
                              ROUND((((ibydocs.payment_amount+ibydocs.payment_curr_discount_taken)/
                                      DECODE(ps.gross_amount,0,1,ps.gross_amount)) *
                                     (greatest (nvl(PS.discount_amount_available,0),
                                                nvl(PS.second_disc_amt_available,0),
                                                nvl(PS.third_disc_amt_available,0))))
                                    / FORE.minimum_accountable_unit)
                              * FORE.minimum_accountable_unit)
                       - ibydocs.payment_curr_discount_taken))),
              ac.exchange_rate,
              ac.exchange_rate_type,
              decode(ibydocs.payment_currency_code, l_base_currency_code,null,cegl.gain_code_combination_id),
              decode(ibydocs.payment_currency_code, l_base_currency_code,null,cegl.loss_code_combination_id),
              cegl.ap_asset_ccid,
              decode(AI.invoice_currency_code, l_base_currency_code,
                     decode(ibydocs.payment_currency_code, l_base_currency_code,
                           null,
                           decode(gl_currency_api.convert_amount_sql(
                                    ibydocs.payment_currency_code,
                                    l_base_currency_code,
                                    AI.payment_cross_rate_date,
                                    AI.payment_cross_rate_type,
                                    abs(ibydocs.payment_amount)),
                                    -1, null, -2, null,
                                    -1, null, -2, null,
                                  gl_currency_api.convert_amount_sql(
                                    ibydocs.payment_currency_code,
                                    l_base_currency_code,
                                    AI.payment_cross_rate_date,
                                    AI.payment_cross_rate_type,
                                    ibydocs.payment_amount))),
                     decode(SI.invoice_exchange_rate, null,
                            null,
                            decode(l_base_currency_mac,NULL,
                                       ROUND((ibydocs.payment_amount * SI.invoice_exchange_rate)
                                         / SI.payment_cross_rate, l_base_currency_precision),
                                       ROUND(((ibydocs.payment_amount * SI.invoice_exchange_rate)
                                          / SI.payment_cross_rate)
                                        / l_base_currency_mac)
                                        * l_base_currency_mac))),
              decode(ibydocs.payment_currency_code, l_base_currency_code,
                     decode(AI.invoice_currency_code, l_base_currency_code,
                              null,
                              ibydocs.payment_amount),
                     decode(l_exchange_rate_type , 'User',
                              decode(l_base_currency_mac, NULL,
                                         ROUND((ibydocs.payment_amount * ap_pmt_callout_pkg.get_user_rate(
                                                                           l_base_currency_code,
                                                                           ibydocs.payment_currency_code,
                                                                           l_checkrun_id))
                                              ,l_base_currency_precision),
                                         ROUND((ibydocs.payment_amount * ap_pmt_callout_pkg.get_user_rate(
                                                                           l_base_currency_code,
                                                                           ibydocs.payment_currency_code,
                                                                           l_checkrun_id))
                                              / l_base_currency_mac)
                                              * l_base_currency_mac),
                              decode(gl_currency_api.convert_amount_sql(
                                      ibydocs.payment_currency_code,
                                      l_base_currency_code,
                                      l_check_date,
                                      l_exchange_rate_type,
                                      abs(ibydocs.payment_amount)),
                                     -1, null, -2, null,
                                    gl_currency_api.convert_amount_sql(
                                      ibydocs.payment_currency_code,
                                      l_base_currency_code,
                                      l_check_date,
                                      l_exchange_rate_type,
                                      ibydocs.payment_amount)))),

              l_check_date,
              SI.bank_account_num,
        --      SI.iban_number,
              SI.bank_num,
              SI.bank_account_type,
              SI.external_bank_account_id,
              SI.attribute1,
              SI.attribute2,
              SI.attribute3,
              SI.attribute4,
              SI.attribute5,
              SI.attribute6,
              SI.attribute7,
              SI.attribute8,
              SI.attribute9,
              SI.attribute10,
              SI.attribute11,
              SI.attribute12,
              SI.attribute13,
              SI.attribute14,
              SI.attribute15,
              SI.attribute_category,
              cegl.future_dated_payment_ccid,
              'N',
              XEG.event_id,
              sysdate,
              l_last_updated_by,
              ai.org_id, --4945922
              ibydocs.beneficiary_party,
              decode(ibydocs.beneficiary_party, null, null, ai.party_site_id),
              decode(ibydocs.beneficiary_party, null, null, ai.vendor_site_id),
	      -- added below columns for 7673570
              ibypmts.PAYEE_NAME,
              aps.vendor_id,
              aps.vendor_site_code,
              ibypmts.supplier_site_id
          FROM
              iby_fd_payments_v ibypmts,
              iby_fd_docs_payable_v ibydocs,
              ap_selected_invoices_all SI,
              fnd_currencies FORE,
              ap_payment_schedules_all PS,
              ap_invoices_all AI,
              ap_checks_all ac,
	      ap_supplier_sites_all aps, -- bug 7673570
              ce_bank_acct_uses_all ceu,
              ce_gl_accounts_ccid cegl,
              XLA_EVENTS_INT_GT xeg
         /* Bug 6950891. Added TO_CHAR */
         WHERE  ibydocs.calling_app_doc_unique_ref1 = TO_CHAR(si.checkrun_id)
          AND   ibydocs.calling_app_doc_unique_ref2 = TO_CHAR(si.invoice_id)
          AND   ibydocs.calling_app_doc_unique_ref3 = TO_CHAR(si.payment_num)
          AND   ibypmts.payment_id = ibydocs.payment_id
          AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
          AND   ibypmts.org_id = l_current_org_id
          and   ibypmts.org_type = 'OPERATING_UNIT'
          AND   aps.vendor_site_id = ibypmts.supplier_site_id -- bug 7673570
          AND   SI.checkrun_name = l_checkrun_name
          AND   ac.payment_id = ibypmts.payment_id
          AND   ac.completed_pmts_group_id = p_completed_pmts_group_id
          AND   ibypmts.payment_currency_code = FORE.currency_code
          AND   PS.invoice_id(+) = SI.invoice_id
          AND   PS.payment_num(+) = SI.payment_num
          AND   AI.invoice_id = SI.invoice_id
          AND   ceu.bank_account_id = ibypmts.internal_bank_account_id
          AND   ceu.org_id = l_current_org_id
          AND   ceu.bank_acct_use_id = cegl.bank_acct_use_id
          AND   xeg.application_id = 200
          AND   XEG.ENTITY_CODE = 'AP_PAYMENTS'
          AND   XEG.SOURCE_ID_INT_1 = ac.check_id ;
Line: 2199

          l_debug_info := 'AP_DBI_PKG.Insert_Payment_Confirm_DBI';
Line: 2203

          AP_DBI_PKG.Insert_Payment_Confirm_DBI(
                        p_checkrun_name      => l_checkrun_name,
                        p_base_currency_code => l_base_currency_code,
                        p_key_table          => 'AP_INVOICE_PAYMENTS_ALL',
                        p_calling_sequence   => l_current_calling_sequence  );
Line: 2209

          l_debug_info := 'AP_Accounting_Events_Pkg.Batch_Update_Payment_Info';
Line: 2213

          AP_Accounting_Events_Pkg.Batch_Update_Payment_Info(
                                       p_checkrun_name  => l_checkrun_name,
                                       p_completed_pmts_group_id => p_completed_pmts_group_id,
                                       p_org_id => l_current_org_id,
                                       p_calling_sequence=>l_current_calling_sequence);
Line: 2225

       /*   OPEN c_schedule_amounts(l_last_updated_by     --Bug5733731
                                 ,p_completed_pmts_group_id
                                 ,l_current_org_id
                                 ,l_checkrun_name);
Line: 2233

                last_update_date_ps_l,
                last_updated_by_ps_l,
                amount_remaining_ps_l,
                discount_remaining_ps_l,
                payment_status_ps_l,
                checkrun_id_ps_l,
                invoice_id_ps_l,
                payment_num_ps_l
                LIMIT 1000;
Line: 2243

                l_debug_info := 'UPDATE ap_payment_schedules_all';
Line: 2249

                  UPDATE ap_payment_schedules_all
                  SET    last_update_date  = last_update_date_ps_l(i)
                        ,last_updated_by   = last_updated_by_ps_l(i)
                        ,amount_remaining  = amount_remaining_ps_l(i)
                        ,discount_amount_remaining = discount_remaining_ps_l(i)
                        ,payment_status_flag = payment_status_ps_l(i)
                        ,checkrun_id       = checkrun_id_ps_l(i)
                   WHERE invoice_id = invoice_id_ps_l(i)
                   AND   payment_num = payment_num_ps_l(i);
Line: 2270

          OPEN c_invoice_amounts(l_last_updated_by
                                 ,p_completed_pmts_group_id
                                 ,l_current_org_id
                                 ,l_checkrun_name);
Line: 2279

                last_update_date_inv_l,
                last_updated_by_inv_l,
                amount_paid_inv_l,
                discount_taken_inv_l,
                payment_status_inv_l,
                invoice_id_inv_l
                LIMIT 1000;
Line: 2287

                l_debug_info := 'UPDATE ap_invoices_all';
Line: 2293

                  UPDATE ap_invoices_all
                  SET    last_update_date  = last_update_date_inv_l(i)
                        ,last_updated_by   = last_updated_by_inv_l(i)
                        ,amount_paid       = nvl(amount_paid,0) + amount_paid_inv_l(i)
                        ,discount_amount_taken = nvl(discount_amount_taken,0) + discount_taken_inv_l(i)
                        ,payment_status_flag = payment_status_inv_l(i)
                   WHERE invoice_id = invoice_id_inv_l(i);
Line: 2306

        /*  UPDATE ap_payment_schedules_all ps1
          SET    (last_update_date,
                  last_updated_by,
                  amount_remaining,
                  discount_amount_remaining,
                  payment_status_flag,
                  checkrun_id) =
                 (SELECT sysdate,
                         l_last_updated_by,
                         SI1.amount_remaining - ibydocs.payment_amount -  nvl(ibydocs.payment_curr_discount_taken,0),
                         0,
                         decode(SI1.amount_remaining - ibydocs.payment_amount -  nvl(ibydocs.payment_curr_discount_taken,0), 0,
                                'Y', 'P'),
                         null --set checkrun_id to null
                  FROM  ap_selected_invoices_all SI1,
                        iby_fd_docs_payable_v ibydocs
                  WHERE checkrun_name = l_checkrun_name
                  AND   SI1.payment_num = ps1.payment_num
                  AND   SI1.invoice_id = ps1.invoice_id
                  AND   ibydocs.calling_app_doc_unique_ref1 = to_char(si1.checkrun_id)
                  AND   ibydocs.calling_app_doc_unique_ref2 = to_char(si1.invoice_id)
                  AND   ibydocs.calling_app_doc_unique_ref3 = to_char(si1.payment_num))
          WHERE (ps1.invoice_id, ps1.payment_num) in
                     (SELECT SI3.invoice_id, SI3.payment_num
                      FROM   ap_selected_invoices_all SI3,
                             iby_fd_payments_v ibypmts,
                             iby_fd_docs_payable_v ibydocs,
                             ap_invoices_all AI
                      WHERE  SI3.checkrun_name = l_checkrun_name
                      AND    ibydocs.calling_app_doc_unique_ref1 = to_char(si3.checkrun_id)
                      AND    ibydocs.calling_app_doc_unique_ref2 = to_char(si3.invoice_id)
                      AND    ibydocs.calling_app_doc_unique_ref3 = to_char(si3.payment_num)
                      AND    ibypmts.payment_id = ibydocs.payment_id
                      AND    ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
                      AND    ibypmts.org_id = l_current_org_id
                      and    ibypmts.org_type = 'OPERATING_UNIT'
                      AND    AI.invoice_id = SI3.invoice_id
                      AND    AI.invoice_type_lookup_code <> 'INTEREST');
Line: 2346

          l_debug_info := 'UPDATE ap_invoices_all';
Line: 2354

          UPDATE ap_invoices_all inv1
          SET    (last_update_date,
                  last_updated_by,
                  amount_paid,
                  discount_amount_taken,
                  payment_status_flag)=
                 (SELECT sysdate,
                         l_last_updated_by,
                         nvl(inv1.amount_paid,0) + sum(ibydocs.payment_amount),
                         nvl(inv1.discount_amount_taken,0) + nvl(sum(ibydocs.payment_curr_discount_taken),0),
                         AP_INVOICES_UTILITY_PKG.get_payment_status( inv1.invoice_id )
                  FROM   iby_fd_docs_payable_v ibydocs,
                         iby_fd_payments_v ibypmts
                  WHERE  ibypmts.org_type = 'OPERATING_UNIT'
                  AND    ibypmts.payment_id = ibydocs.payment_id
                  AND    ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
                  AND    ibypmts.org_id = l_current_org_id
                  and
		  (ibydocs.calling_app_doc_unique_ref1,ibydocs.calling_app_doc_unique_ref2,ibydocs.calling_app_doc_unique_ref3)
	           in (select si.checkrun_id,si.invoice_id,si.payment_num from
		       ap_selected_invoices_all si where si.invoice_id=inv1.invoice_id
	               and checkrun_name = l_checkrun_name)
		  )
          WHERE invoice_id IN
                      (SELECT ibydocs.calling_app_doc_unique_ref2
                       FROM  iby_fd_docs_payable_v ibydocs,
                             iby_fd_payments_v ibypmts
                       WHERE ibypmts.payment_id = ibydocs.payment_id
                       AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
                       and   ibypmts.org_type = 'OPERATING_UNIT'
                       AND   ibypmts.org_id = l_current_org_id)
          AND   invoice_type_lookup_code <> 'INTEREST';
Line: 2437

                             l_last_updated_by,
                             --4863216
                             to_number(FND_GLOBAL.USER_ID),--Bug6489464
                             --to_number(FND_PROFILE.VALUE('LOGIN_ID')),
                             to_number(FND_PROFILE.VALUE('PROGRAM_APPLICATION_ID')),
                             to_number(FND_PROFILE.VALUE('PROGRAM_ID')),
                             to_number(FND_PROFILE.VALUE('REQUEST_ID')),
                             l_checkrun_id,
                             p_completed_pmts_group_id,
                             l_current_org_id);
Line: 2461

           l_debug_info := 'DELETE FROM ap_selected_invoices_all';
Line: 2466

          DELETE FROM ap_selected_invoices_all
          WHERE checkrun_id = l_checkrun_id
          /* Bug 6950891. Added TO_CHAR */
          and (TO_CHAR(invoice_id), TO_CHAR(payment_num)) in
            (select ibydocs.calling_app_doc_unique_ref2,
                    ibydocs.calling_app_doc_unique_ref3
             from iby_fd_docs_payable_v ibydocs,
                  iby_fd_payments_v ibypmts
             where ibypmts.payment_id = ibydocs.payment_id
             and   ibypmts.org_type = 'OPERATING_UNIT'
             AND   ibypmts.completed_pmts_group_id = p_completed_pmts_group_id
             AND   ibypmts.org_id = l_current_org_id);
Line: 2483

      l_debug_info := 'DELETE FROM ap_unselected_invoices_all';
Line: 2488

      DELETE FROM ap_unselected_invoices_all
      WHERE checkrun_id = l_checkrun_id;
Line: 2494

  SELECT COUNT(*)
    INTO l_iby_check_count
    FROM iby_fd_payments_v
   WHERE completed_pmts_group_id =  p_completed_pmts_group_id;
Line: 2499

   SELECT COUNT(*)
    INTO l_iby_docs_count
    FROM iby_fd_docs_payable_v
   WHERE completed_pmts_group_id =  p_completed_pmts_group_id;
Line: 2793

  l_api_name                  CONSTANT VARCHAR2(30)   := 'Payment_Status_Updated';
Line: 2809

    update ap_checks_all
       set status_lookup_code = 'STOP INITIATED',
           stopped_date= p_stopped_date,   -- Bug 6957071
           stopped_by= p_stopped_by        -- Bug 6957071
     where payment_id = p_payment_id;
Line: 2832

  l_api_name                  CONSTANT VARCHAR2(30)   := 'Payment_Status_Updated';
Line: 2848

    update ap_checks_all
       set status_lookup_code = 'NEGOTIABLE',
	   stopped_date=null,  -- Bug 6957071
           stopped_by=null  -- Bug 6957071
     where payment_id = p_payment_id;