DBA Data[Home] [Help]

APPS.AP_PERIOD_CLOSE_PKG SQL Statements

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

Line: 8

    SELECT start_date, end_date, closing_status
    FROM  gl_period_statuses
    WHERE period_name = cp_period_name
    AND application_id = G_AP_APPLICATION_ID
    AND set_of_books_id = g_ledger_id
    and  (cp_include_adj_period is null or (nvl(adjustment_period_flag,'N') = cp_include_adj_period));
Line: 17

  select name, sla_ledger_cash_basis_flag
  from gl_sets_of_books
  where set_of_books_id = g_ledger_id;
Line: 75

      insert into ap_org_attributes_gt
                    (org_name
                    ,org_id
                    ,recon_accounting_flag
                    ,when_to_account_pmt
		    ,set_of_books_id
                    )
          values    (r_org.operating_unit_name
                    ,r_org.org_id
                    ,r_org.recon_accounting_flag
                    ,r_org.when_to_account_pmt
                    ,r_org.set_of_books_id
                    );
Line: 140

      insert into ap_period_close_excps_gt
                  (   invoice_id
                     ,invoice_distribution_id
		     ,invoice_payment_id  -- 7318763
		     ,accounting_event_id
                     ,accounting_date
                     ,org_id
                     ,invoice_num
                     ,invoice_currency_code
		     ,party_id
                     ,vendor_id
                     ,doc_sequence_value
                     ,voucher_num
                     ,invoice_date
                     ,invoice_amount
                     ,cancelled_date
                     ,match_status_flag
		     ,legal_entity_id
		     ,po_distribution_id
		     ,amount
		     ,detail_tax_dist_id
		     ,invoice_line_number
                     ,source_type
                     ,source_table_name
                  )
      select     ai.invoice_id
                ,aid.invoice_distribution_id
		,aid.awt_invoice_payment_id  -- 7318763
		,aid.accounting_event_id
                ,aid.accounting_date
                ,aid.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,aid.match_status_flag
                ,ai.legal_entity_id
                ,aid.po_distribution_id
                ,aid.amount
                ,aid.detail_tax_dist_id
		,aid.invoice_line_number
                ,G_SRC_TYP_UNACCT_DISTS
                ,G_SRC_TAB_AP_INV_DISTS_ALL
      from
                 ap_invoices_all ai
                ,ap_invoice_distributions_all aid
                ,ap_org_attributes_gt org_gtt
      where
                ai.invoice_id = aid.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
        and ( aid.accounting_date     between g_period_start_date and g_period_end_date)
        --and     aid.accounting_date     between g_period_start_date and g_period_end_date
        and     aid.posted_flag  in ('N' , 'S', 'P') -- N=Not Accounted, S=Selected for Accounting, P=Partially Accounted for CASH based accounting
        and     aid.set_of_books_id = g_ledger_id
        and     aid.org_id = org_gtt.org_id
        and     (  g_action <> G_ACTION_PERIOD_CLOSE
                OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
                );
Line: 206

insert into ap_period_close_excps_gt
                  (   invoice_id
                     ,invoice_distribution_id
		     ,invoice_payment_id  -- 7318763
		     ,accounting_event_id
                     ,accounting_date
                     ,org_id
                     ,invoice_num
                     ,invoice_currency_code
		     ,party_id
                     ,vendor_id
                     ,doc_sequence_value
                     ,voucher_num
                     ,invoice_date
                     ,invoice_amount
                     ,cancelled_date
                     ,match_status_flag
		     ,legal_entity_id
		     ,po_distribution_id
		     ,amount
		     ,detail_tax_dist_id
		     ,invoice_line_number
                     ,source_type
                     ,source_table_name
                  )
      select     ai.invoice_id
                ,aid.invoice_distribution_id
		,aid.awt_invoice_payment_id  -- 7318763
		,aid.accounting_event_id
                ,aid.accounting_date
                ,aid.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,aid.match_status_flag
                ,ai.legal_entity_id
                ,aid.po_distribution_id
                ,aid.amount
                ,aid.detail_tax_dist_id
		,aid.invoice_line_number
                ,G_SRC_TYP_UNACCT_DISTS
                ,G_SRC_TAB_AP_INV_DISTS_ALL
      from
                 ap_invoices_all ai
                ,ap_invoice_distributions_all aid
                ,ap_org_attributes_gt org_gtt
      where
                ai.invoice_id = aid.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
       -- and ( aid.accounting_date     between g_period_start_date and g_period_end_date)
        --and     aid.accounting_date     between g_period_start_date and g_period_end_date
        and     aid.posted_flag  in ('N' , 'S', 'P') -- N=Not Accounted, S=Selected for Accounting, P=Partially Accounted for CASH based accounting
        and     aid.set_of_books_id = g_ledger_id
        and     aid.org_id = org_gtt.org_id
        and     (  g_action <> G_ACTION_PERIOD_CLOSE
                OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
                );
Line: 272

       debug ('Total records inserted in ap_period_close_excps_gt for source_type='||G_SRC_TYP_UNACCT_DISTS||' is:'||sql%rowcount);
Line: 281

      insert into ap_period_close_excps_gt
                  (   invoice_id
                     ,invoice_distribution_id
		     ,accounting_event_id
                     ,accounting_date
                     ,org_id
                     ,invoice_num
                     ,invoice_currency_code
		     ,party_id
                     ,vendor_id
                     ,doc_sequence_value
                     ,voucher_num
                     ,invoice_date
                     ,invoice_amount
                     ,cancelled_date
                     ,match_status_flag
		     ,legal_entity_id
		     ,po_distribution_id
		     ,amount
		     ,detail_tax_dist_id
                     ,source_type
                     ,source_table_name
                  )
      select     ai.invoice_id
                ,astd.invoice_distribution_id
		,astd.accounting_event_id
                ,astd.accounting_date
                ,astd.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,astd.match_status_flag
                ,ai.legal_entity_id
                ,astd.po_distribution_id
                ,astd.amount
                ,astd.detail_tax_dist_id
                ,G_SRC_TYP_UNACCT_DISTS
                ,G_SRC_TAB_AP_SELF_TAX_DIST_ALL
      from
                 ap_invoices_all ai
                ,ap_self_assessed_tax_dist_all astd
                ,ap_org_attributes_gt org_gtt
      where
                ai.invoice_id = astd.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
        and (
             astd.accounting_date     between g_period_start_date and g_period_end_date )
        --and     astd.accounting_date     between g_period_start_date and g_period_end_date
        and     astd.posted_flag  in ('N' , 'S', 'P') -- N=Not Accounted, S=Selected for Accounting, P=Partially Accounted for CASH based accounting
        and    astd.set_of_books_id = g_ledger_id
        and     astd.org_id = org_gtt.org_id
        and     (  g_action <> G_ACTION_PERIOD_CLOSE
                OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
                );
Line: 342

        insert into ap_period_close_excps_gt
                  (   invoice_id
                     ,invoice_distribution_id
		     ,accounting_event_id
                     ,accounting_date
                     ,org_id
                     ,invoice_num
                     ,invoice_currency_code
		     ,party_id
                     ,vendor_id
                     ,doc_sequence_value
                     ,voucher_num
                     ,invoice_date
                     ,invoice_amount
                     ,cancelled_date
                     ,match_status_flag
		     ,legal_entity_id
		     ,po_distribution_id
		     ,amount
		     ,detail_tax_dist_id
                     ,source_type
                     ,source_table_name
                  )
      select     ai.invoice_id
                ,astd.invoice_distribution_id
		,astd.accounting_event_id
                ,astd.accounting_date
                ,astd.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,astd.match_status_flag
                ,ai.legal_entity_id
                ,astd.po_distribution_id
                ,astd.amount
                ,astd.detail_tax_dist_id
                ,G_SRC_TYP_UNACCT_DISTS
                ,G_SRC_TAB_AP_SELF_TAX_DIST_ALL
      from
                 ap_invoices_all ai
                ,ap_self_assessed_tax_dist_all astd
                ,ap_org_attributes_gt org_gtt
      where
                ai.invoice_id = astd.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
        and (
             astd.accounting_date     between g_period_start_date and g_period_end_date )
        --and     astd.accounting_date     between g_period_start_date and g_period_end_date
        and     astd.posted_flag  in ('N' , 'S', 'P') -- N=Not Accounted, S=Selected for Accounting, P=Partially Accounted for CASH based accounting
        and    astd.set_of_books_id = g_ledger_id
        and     astd.org_id = org_gtt.org_id
        and     (  g_action <> G_ACTION_PERIOD_CLOSE
                OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
                );
Line: 405

       debug ('Total records inserted in ap_period_close_excps_gt for source_type='||G_SRC_TYP_UNACCT_DISTS||'for table='||G_SRC_TAB_AP_SELF_TAX_DIST_ALL
 || ' is:'||sql%rowcount);
Line: 416

      insert into ap_period_close_excps_gt
              (   invoice_id
                 ,invoice_line_number
                 ,accounting_date
                 ,org_id
                 ,invoice_num
                 ,invoice_currency_code
		 ,party_id
                 ,vendor_id
                 ,doc_sequence_value
                 ,voucher_num
                 ,invoice_date
                 ,invoice_amount
                 ,cancelled_date
                 ,source_type
                 ,source_table_name
              )
                 select   /*+ leading(ail) */  ai.invoice_id
                ,ail.line_number
                ,ail.accounting_date
                ,ail.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,G_SRC_TYP_LINES_WITHOUT_DISTS
                ,G_SRC_TAB_AP_INV_LINES_ALL
          from
                ap_invoices_all ai
               ,ap_invoice_lines_all ail
               ,ap_org_attributes_gt org_gtt
          where
                ai.invoice_id = ail.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
        and (ail.accounting_date     between g_period_start_date and g_period_end_date)

        --and   ail.accounting_date     between g_period_start_date and g_period_end_date
          and   not exists (select 1                                          --> lines without distributions
                            from   ap_invoice_distributions_all aid
                            where  aid.invoice_id = ai.invoice_id
                            and    aid.invoice_line_number = ail.line_number

                            --Bug 7242216 Excluding invoices having discarded lines with
                            --no distributions
                            union
                            select 1 from dual where ail.discarded_flag = 'Y'
                           )
 	  and  ail.amount <> 0
          and  ai.cancelled_date is null
          and  ail.set_of_books_id = g_ledger_id
          and  ail.org_id = org_gtt.org_id
          and  (  g_action <> G_ACTION_PERIOD_CLOSE
               OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
               );
Line: 478

	   insert into ap_period_close_excps_gt
              (   invoice_id
                 ,invoice_line_number
                 ,accounting_date
                 ,org_id
                 ,invoice_num
                 ,invoice_currency_code
		 ,party_id
                 ,vendor_id
                 ,doc_sequence_value
                 ,voucher_num
                 ,invoice_date
                 ,invoice_amount
                 ,cancelled_date
                 ,source_type
                 ,source_table_name
              )
                 select  /*+ leading(ail) */   ai.invoice_id
                ,ail.line_number
                ,ail.accounting_date
                ,ail.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,G_SRC_TYP_LINES_WITHOUT_DISTS
                ,G_SRC_TAB_AP_INV_LINES_ALL
          from
                ap_invoices_all ai
               ,ap_invoice_lines_all ail
               ,ap_org_attributes_gt org_gtt
          where
                ai.invoice_id = ail.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
        --  and (ail.accounting_date     between g_period_start_date and g_period_end_date)

        --and   ail.accounting_date     between g_period_start_date and g_period_end_date
          and   not exists (select 1                                          --> lines without distributions
                            from   ap_invoice_distributions_all aid
                            where  aid.invoice_id = ai.invoice_id
                            and    aid.invoice_line_number = ail.line_number

                            --Bug 7242216 Excluding invoices having discarded lines with
                            --no distributions
                            union
                            select 1 from dual where ail.discarded_flag = 'Y'
                           )
 	  and  ail.amount <> 0
          and  ai.cancelled_date is null
          and  ail.set_of_books_id = g_ledger_id
          and  ail.org_id = org_gtt.org_id
          and  (  g_action <> G_ACTION_PERIOD_CLOSE
               OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
               );
Line: 543

       debug ('Total records inserted in ap_period_close_excps_gt for source_type='||G_SRC_TYP_LINES_WITHOUT_DISTS||' is:'||sql%rowcount);
Line: 553

      insert into ap_period_close_excps_gt
                  (   invoice_id
		     ,accounting_event_id
                     ,accounting_date
                     ,org_id
                     ,invoice_num
                     ,invoice_currency_code
		     ,party_id
                     ,vendor_id
                     ,doc_sequence_value
                     ,voucher_num
                     ,invoice_date
                     ,invoice_amount
                     ,cancelled_date
		     ,legal_entity_id
                     ,source_type
                     ,source_table_name
                  )
      select     ai.invoice_id
		,apph.accounting_event_id
                ,apph.accounting_date
                ,ai.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
		,ai.party_id
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,ai.legal_entity_id
                ,G_SRC_TYP_UNACCT_PREPAY_HIST
                ,G_SRC_TAB_AP_PREPAY_HIST
      from       ap_invoices_all ai
                ,ap_prepay_history_all apph
                ,ap_org_attributes_gt org_gtt
      where
                ai.invoice_id = apph.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
        and ( apph.accounting_date     between g_period_start_date and g_period_end_date)
        --and     aid.accounting_date     between g_period_start_date and g_period_end_date
        and     apph.posted_flag  in ('N' , 'S', 'P') -- N=Not Accounted, S=Selected for Accounting, P=Partially Accounted for CASH based accounting
	and     apph.accounting_event_id IS NOT NULL
        and     ai.set_of_books_id = g_ledger_id
        and     ai.org_id = org_gtt.org_id
        and     (  g_action <> G_ACTION_PERIOD_CLOSE
                OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
                );
Line: 604

		  insert into ap_period_close_excps_gt
                  (   invoice_id
		     ,accounting_event_id
                     ,accounting_date
                     ,org_id
                     ,invoice_num
                     ,invoice_currency_code
                     ,vendor_id
                     ,doc_sequence_value
                     ,voucher_num
                     ,invoice_date
                     ,invoice_amount
                     ,cancelled_date
		     ,legal_entity_id
                     ,source_type
                     ,source_table_name
                  )
      select     ai.invoice_id
		,apph.accounting_event_id
                ,apph.accounting_date
                ,ai.org_id
                ,ai.invoice_num
                ,ai.invoice_currency_code
                ,ai.vendor_id
                ,ai.doc_sequence_value
                ,ai.voucher_num
                ,ai.invoice_date
                ,ai.invoice_amount
                ,ai.cancelled_date
                ,ai.legal_entity_id
                ,G_SRC_TYP_UNACCT_PREPAY_HIST
                ,G_SRC_TAB_AP_PREPAY_HIST
      from       ap_invoices_all ai
                ,ap_prepay_history_all apph
                ,ap_org_attributes_gt org_gtt
      where
                ai.invoice_id = apph.invoice_id
        -- bug 7311486 UTR report must run even if dates and period is not specified
       -- and ( apph.accounting_date     between g_period_start_date and g_period_end_date)
        --and     aid.accounting_date     between g_period_start_date and g_period_end_date
        and     apph.posted_flag  in ('N' , 'S', 'P') -- N=Not Accounted, S=Selected for Accounting, P=Partially Accounted for CASH based accounting
	and     apph.accounting_event_id IS NOT NULL
        and     ai.set_of_books_id = g_ledger_id
        and     ai.org_id = org_gtt.org_id
        and     (  g_action <> G_ACTION_PERIOD_CLOSE
                OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
                );
Line: 652

      debug ('Total records inserted in ap_period_close_excps_gt for source_type='||G_SRC_TYP_UNACCT_PREPAY_HIST||' is:'||sql%rowcount);
Line: 669

    INSERT INTO AP_PERIOD_CLOSE_EXCPS_GT
            (payment_history_id
            ,accounting_event_id
            ,accounting_date
            ,check_id
            ,transaction_type
            ,org_id
            ,recon_accounting_flag
            ,check_number
            ,exchange_rate
            ,check_date
            ,legal_entity_id
            ,vendor_name
            ,bank_account_name
            ,check_amount
            ,currency_code
	    ,party_id
            ,vendor_id
            ,source_type
            ,source_table_name
            )
    SELECT  aph.payment_history_id,
            aph.accounting_event_id,
            aph.accounting_date,
            aph.check_id,
            aph.transaction_type,
            aph.org_id,
            orgs.recon_accounting_flag,
            ac.check_number,
            ac.exchange_rate,
            ac.check_date,
            ac.legal_entity_id,
	    ac.vendor_name,
            ac.bank_account_name,
            ac.amount,
            ac.currency_code,
	    ac.party_id,
            ac.vendor_id
            ,G_SRC_TYP_UNACCT_PMT_HISTORY
            ,G_SRC_TAB_AP_PMT_HISTORY
    FROM    ap_payment_history_all aph,
            ap_checks_all ac,
            ap_org_attributes_gt orgs
    WHERE  aph.posted_flag IN ('N','S')
    AND    ac.check_id = aph.check_id
    -- bug 7311486 UTR report must run even if dates and period is not specified
    and (
        (g_action <> G_ACTION_UTR and aph.accounting_date     between g_period_start_date and g_period_end_date)
     or (g_action = G_ACTION_UTR and g_period_start_date is not null and g_period_end_date is not null and aph.accounting_date     between g_period_start_date and g_period_end_date)
     or (g_action = G_ACTION_UTR and g_period_start_date is  null and g_period_end_date is  null and 1=1)
    )
    --AND    aph.accounting_date BETWEEN g_period_start_date and g_period_end_date
    AND    aph.org_id = orgs.org_id
    AND    ( NVL(orgs.when_to_account_pmt, 'ALWAYS') = 'ALWAYS' or
               (NVL(orgs.when_to_account_pmt, 'ALWAYS') = 'CLEARING ONLY'  and
                        aph.transaction_type in ('PAYMENT CLEARING', 'PAYMENT UNCLEARING')))
    and   (  g_action <> G_ACTION_PERIOD_CLOSE
          OR (g_action = G_ACTION_PERIOD_CLOSE and ROWNUM = 1 )  -- for period close we just need check if any such record exists
          );
Line: 729

    debug ('Total records inserted in ap_period_close_excps_gt for source_type='||G_SRC_TYP_UNACCT_PMT_HISTORY||' is:'||sql%rowcount);
Line: 739

    insert into ap_period_close_excps_gt
            (invoice_payment_id
            ,accounting_event_id
            ,accounting_date
            ,check_id
            ,payment_amount
            ,org_id
            ,recon_accounting_flag
            ,check_number
            ,exchange_rate
            ,check_date
            ,legal_entity_id
            ,vendor_name
            ,bank_account_name
            ,check_amount
            ,currency_code
            ,status_lookup_code
            ,party_id
            ,vendor_id
            ,source_type
            ,source_table_name
            )
    SELECT  aip.invoice_payment_id,
            aip.accounting_event_id,
            aip.accounting_date,
            aip.check_id,
            aip.amount,
            aip.org_id,
            orgs.recon_accounting_flag,
            ac.check_number,
            ac.exchange_rate,
            ac.check_date,
            ac.legal_entity_id,
            ac.vendor_name,
            ac.bank_account_name,
            ac.amount,
            ac.currency_code,
            ac.status_lookup_code,
	    ac.party_id,
            ac.vendor_id
            ,G_SRC_TYP_UNACCT_INV_PMTS
            ,G_SRC_TAB_AP_INV_PAYMENTS
    FROM    ap_invoice_payments_all aip,
    ap_checks_All ac,
            ap_org_attributes_gt orgs
    WHERE   aip.posted_flag IN ('N','S')
    -- bug 7311486 UTR report must run even if dates and period is not specified
    and (
        (g_action <> G_ACTION_UTR and aip.accounting_date     between g_period_start_date and g_period_end_date)
     or (g_action = G_ACTION_UTR and g_period_start_date is not null and g_period_end_date is not null and aip.accounting_date     between g_period_start_date and g_period_end_date)
     or (g_action = G_ACTION_UTR and g_period_start_date is  null and g_period_end_date is  null and 1=1)
    )
    --AND     aip.accounting_date BETWEEN g_period_start_date and g_period_end_date
    AND     aip.org_id = orgs.org_id
    AND     ac.check_id = aip.check_id
    AND     NVL(orgs.when_to_account_pmt, 'ALWAYS') = 'ALWAYS';
Line: 796

    debug ('Total records inserted in ap_period_close_excps_gt for source_type='||G_SRC_TYP_UNACCT_INV_PMTS||' is:'||sql%rowcount);
Line: 804

    SELECT message_text
    INTO AP_PERIOD_CLOSE_PKG.g_orphan_message_text
    FROM fnd_new_messages
    WHERE language_code = userenv('LANG')
    AND ((message_name = 'AP_ORPHAN_EVENTS_EXIST' AND
          g_action <> G_ACTION_SWEEP) OR
	 (message_name = 'AP_ORPHAN_EVENTS_CLEANED' AND
	  g_action = G_ACTION_SWEEP))
    AND EXISTS
      (SELECT 1
       FROM xla_events xe,
            xla_transaction_entities_upg xte,
            ap_org_attributes_gt aagt
       WHERE xe.application_id = 200
       AND xte.application_id = 200
       AND xe.event_status_code IN ('U',    'I')
       AND xe.process_status_code IN ('U', 'I')
       AND xe.entity_id = xte.entity_id
       AND xte.security_id_int_1 = aagt.org_id
       AND ((g_action <> G_ACTION_UTR AND
             xe.event_date BETWEEN g_period_start_date
                           AND g_period_end_date) OR
            (g_action = G_ACTION_UTR  AND
             g_period_start_date IS NOT NULL AND
             g_period_end_date IS NOT NULL AND
             xe.event_date BETWEEN g_period_start_date
                           AND g_period_end_date) OR
            (g_action = G_ACTION_UTR AND
             g_period_start_date IS NULL AND
             g_period_end_date IS NULL))
       AND NOT EXISTS
        (SELECT 1
         FROM ap_invoice_distributions_all aid
         WHERE aid.accounting_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_invoice_distributions_all aid
         WHERE aid.bc_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_self_assessed_tax_dist_all aid
         WHERE aid.accounting_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_self_assessed_tax_dist_all aid
         WHERE aid.bc_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_prepay_history_all apph
         WHERE apph.accounting_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_prepay_history_all apph
         WHERE apph.bc_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_invoice_payments_all aip
         WHERE aip.accounting_event_id = xe.event_id)
       AND NOT EXISTS
        (SELECT 1
         FROM ap_payment_history_all aph
         WHERE aph.accounting_event_id = xe.event_id)
       AND event_type_code <> 'MANUAL');
Line: 887

	SELECT meaning
	into lv_name
	FROM FND_LOOKUPS
	WHERE LOOKUP_TYPE = 'FND_MO_REPORTING_LEVEL'
	and lookup_code = g_reporting_level;
Line: 908

  select org_name
  from ap_org_attributes_gt
  where org_id = g_org_id;
Line: 946

    select count(1)
    from ap_org_attributes_gt all_orgs
    where org_id not in (select org_id from ap_system_parameters);
Line: 990

    SELECT  'Y'
    FROM ap_inv_selection_criteria_all AISC,
         iby_pay_service_requests  IPSR ,
         ap_selected_invoices_all ASI
    WHERE  IPSR.call_app_pay_service_req_code (+) = AISC.checkrun_name
    AND    trunc(aisc.check_date) between g_period_start_date and g_period_end_date
    AND DECODE(IPSR.payment_service_request_id, NULL,
              AISC.status,
              AP_PAYMENT_UTIL_PKG.get_psr_status(IPSR.payment_service_request_id,
                                                 IPSR.payment_service_request_status) )
               NOT IN ('CONFIRMED','CANCELED','QUICKCHECK', 'CANCELLED NO PAYMENTS', 'TERMINATED')
    AND aisc.checkrun_id = asi.checkrun_id
    AND asi.org_id in (select org_id org_id from ap_org_attributes_gt org_gtt)
    AND rownum = 1;
Line: 1008

      select    'Y'
      from	ap_checks_all c
      where	c.future_pay_due_date is not null
      and	c.status_lookup_code = 'ISSUED'
      and	c.future_pay_due_date between g_period_start_date
                                     and      g_period_end_date
      and       c.org_id in (select org_id org_id from ap_org_attributes_gt org_gtt)
      and       rownum = 1;
Line: 1097

      select set_of_books_id ledger_id
      from   ap_system_parameters_all
      where org_id = g_org_id;
Line: 1260

	  PSA_AP_BC_PVT.delete_events(
    		p_init_msg_list => 'F',
	    	p_ledger_id => g_ledger_id,
    		p_start_date => g_period_start_date,
    		p_end_date => g_period_end_date,
    		p_calling_sequence => 'ap_period_close_pkg.validate_action',
    		x_return_status => p_validation_flag,
    		x_msg_count =>l_msg_count,
    		x_msg_data => p_validation_message
 	  );
Line: 1372

 /*    select count(*)   --commented this peice of code 7318763
     into l_count
     from ap_invoice_distributions_all
     where accounting_event_id = p_event_id
     and invoice_id = p_trans_id
     and awt_invoice_payment_id is not null;  */
Line: 1381

         select ac.check_id, ac.check_number
         into l_check_id, l_check_number
       	 from ap_invoice_payments_all aip,
              ap_checks_all ac
         where aip.check_id=ac.check_id
         and   aip.accounting_event_id = p_event_id
         and   aip.invoice_id= p_trans_id;
Line: 1419

 |  FUNCTION  -  UPDATE_PO_CLOSE_DATE
 |
 |  DESCRIPTION
 |      This function is used to sweep closed date of PO Shipment and Headers
 |      to an open date in next accounting period for unaccounted invoice
 |      distributions matched to these shipments.
 |
 |
 |  PRAMETERS
 |
 |
 |  KNOWN ISSUES:
 |
 |  NOTES:
 |
 |  MODIFICATION HISTORY
 |  Date         Author             Description of Change
 |  14-MAR-08    PRANPAUL           New
 *===========================================================================*/
FUNCTION update_po_close_date RETURN BOOLEAN IS

BEGIN

	UPDATE po_headers_all POH
	SET POH.closed_date = g_sweep_to_date
	WHERE po_header_id in (SELECT PLL.PO_HEADER_ID
				   FROM   PO_LINE_LOCATIONS_ALL PLL,
				   PO_DISTRIBUTIONS_ALL PD,
				   AP_PERIOD_CLOSE_EXCPS_GT GT
				   WHERE PLL.LINE_LOCATION_ID = PD.LINE_LOCATION_ID
				   AND PD.PO_DISTRIBUTION_ID = GT.PO_DISTRIBUTION_ID
				   AND GT.SOURCE_TYPE = G_SRC_TYP_UNACCT_DISTS
				   AND GT.SOURCE_TABLE_NAME in ( G_SRC_TAB_AP_INV_DISTS_ALL,
								 G_SRC_TAB_AP_SELF_TAX_DIST_ALL)
				   AND ( PLL.CLOSED_DATE IS NOT NULL
				         AND PLL.CLOSED_DATE < g_sweep_to_date )
				   GROUP BY PLL.PO_HEADER_ID, GT.PO_DISTRIBUTION_ID
				   HAVING SUM(GT.AMOUNT) > 0)
	AND ( POH.CLOSED_DATE IS NOT NULL
	      AND POH.CLOSED_DATE < g_sweep_to_date );
Line: 1460

  debug ('update_po_close_date: total records updated in po_headers_all:'||sql%rowcount);
Line: 1463

	UPDATE po_line_locations_all
	SET closed_date = g_sweep_to_date
	WHERE line_location_id in (SELECT PLL.LINE_LOCATION_ID
				   FROM   PO_LINE_LOCATIONS_ALL PLL,
				   PO_DISTRIBUTIONS_ALL PD,
				   AP_PERIOD_CLOSE_EXCPS_GT GT
				   WHERE PLL.LINE_LOCATION_ID = PD.LINE_LOCATION_ID
				   AND PD.PO_DISTRIBUTION_ID = GT.PO_DISTRIBUTION_ID
				   AND GT.SOURCE_TYPE = G_SRC_TYP_UNACCT_DISTS
				   AND GT.SOURCE_TABLE_NAME in ( G_SRC_TAB_AP_INV_DISTS_ALL,
								 G_SRC_TAB_AP_SELF_TAX_DIST_ALL)
				   AND ( PLL.CLOSED_DATE IS NOT NULL
				         AND PLL.CLOSED_DATE < g_sweep_to_date )
				   GROUP BY PLL.LINE_LOCATION_ID, GT.PO_DISTRIBUTION_ID
				   HAVING SUM(GT.AMOUNT) > 0);
Line: 1479

  debug ('update_po_close_date: total records updated in po_line_locations_all:'||sql%rowcount);
Line: 1485

    debug ('EXCEPTION: update_po_close_date: '||sqlerrm);
Line: 1492

 |  FUNCTION  -  UPDATE_EBTAX_DISTS
 |
 |  DESCRIPTION
 |      This function is used to sweep all eBtax distributions to
 |      to an open date in next accounting period for unaccounted tax
 |      distributions generated by eBtax.
 |
 |
 |  PRAMETERS
 |
 |
 |  KNOWN ISSUES:
 |
 |  NOTES:
 |
 |  MODIFICATION HISTORY
 |  Date         Author             Description of Change
 |  14-MAR-08    PRANPAUL           New
 *===========================================================================*/
FUNCTION update_ebtax_dists RETURN BOOLEAN IS

l_return_status		varchar2(20);
Line: 1518

        INSERT into ZX_TAX_DIST_ID_GT
		(SELECT detail_tax_dist_id
		FROM ap_period_close_excps_gt
		WHERE detail_tax_dist_id is not null
		AND source_type = G_SRC_TYP_UNACCT_DISTS
		AND source_table_name in ( G_SRC_TAB_AP_INV_DISTS_ALL,
					   G_SRC_TAB_AP_SELF_TAX_DIST_ALL));
Line: 1526

    debug ('update_ebtax_dists: total records inserted in ZX_TAX_DIST_ID_GT: '||sql%rowcount);
Line: 1530

	ZX_API_PUB.Update_Tax_dist_gl_date (
				1.0,
				FND_API.G_TRUE,
				FND_API.G_FALSE,
				FND_API.G_VALID_LEVEL_FULL,
				l_return_status,
				l_msg_count,
				l_msg_data,
				g_sweep_to_date );
Line: 1540

  debug ('update_ebtax_dists: l_return_status='||l_return_status||';l_msg_data='||l_msg_data||';l_msg_count='||l_msg_count );
Line: 1551

    debug ('EXCEPTION: update_ebtax_dists: '||sqlerrm);
Line: 1557

 |  PROCEDURE  -  UPDATE_XLA_EVENTS
 |
 |  DESCRIPTION
 |      This procedure is used to sweep accounting events from one accounting period
 |      to another.
 |
 |
 |  PRAMETERS
 |
 |         p_sweep_to_date: The new event date
 |         p_calling_sequence: Debug information
 |
 |  KNOWN ISSUES:
 |
 |  NOTES:
 |
 |  MODIFICATION HISTORY
 |  Date         Author             Description of Change
 |  14-MAR-08    PRANPAUL           New
 *===========================================================================*/

PROCEDURE update_xla_events (
               p_calling_sequence IN    VARCHAR2,
	       p_success          OUT   NOCOPY BOOLEAN)
IS

  TYPE t_event_ids IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
Line: 1611

    SELECT gt.accounting_event_id accounting_event_id,
           decode (gt.source_table_name
                  ,G_SRC_TAB_AP_INV_DISTS_ALL, gt.invoice_id
		  ,G_SRC_TAB_AP_PREPAY_HIST, gt.invoice_id
		  ,G_SRC_TAB_AP_SELF_TAX_DIST_ALL, gt.invoice_id
                  ,G_SRC_TAB_AP_PMT_HISTORY  , gt.check_id
                  ) trans_id,
           gt.org_id org_id,
           gt.legal_entity_id legal_entity_id,
	         decode (gt.source_table_name
                  ,G_SRC_TAB_AP_INV_DISTS_ALL,  gt.invoice_num
                  ,G_SRC_TAB_AP_PREPAY_HIST, gt.invoice_num
		  ,G_SRC_TAB_AP_SELF_TAX_DIST_ALL, gt.invoice_num
                  ,G_SRC_TAB_AP_PMT_HISTORY  ,  gt.check_number
                  )trans_num,
	         decode(gt.source_table_name
                 ,G_SRC_TAB_AP_INV_DISTS_ALL, 'INV'
		 ,G_SRC_TAB_AP_PREPAY_HIST, 'INV'
		 ,G_SRC_TAB_AP_SELF_TAX_DIST_ALL, 'INV'
                 ,G_SRC_TAB_AP_PMT_HISTORY,'PMT'
                 ) source
		 ,invoice_payment_id  -- 7318763
    FROM ap_period_close_excps_gt gt
    WHERE gt.source_type in (G_SRC_TYP_UNACCT_DISTS, G_SRC_TYP_UNACCT_PMT_HISTORY,
                             G_SRC_TYP_UNACCT_PREPAY_HIST)
    AND	  gt.source_table_name in (G_SRC_TAB_AP_INV_DISTS_ALL, G_SRC_TAB_AP_PMT_HISTORY,
				   G_SRC_TAB_AP_SELF_TAX_DIST_ALL, G_SRC_TAB_AP_PREPAY_HIST)
    AND gt.accounting_event_id is NOT NULL;
Line: 1643

  debug ('begin update_xla_events: Bulk fetch cursor c_events');
Line: 1658

    debug ('update_xla_events: l_event_ids.count='||l_event_ids.count );
Line: 1668

        SELECT event_id, event_status_code
        INTO l_xla_event, l_xla_event_status
        FROM xla_events
        WHERE event_id = l_event_ids(i)
        AND application_id = 200;
Line: 1708

        AP_XLA_EVENTS_PKG.UPDATE_EVENT
        ( p_event_source_info => l_event_source_info,
          p_event_id => l_event_ids(i),
          p_event_type_code => NULL,
          p_event_date => g_sweep_to_date,
          p_event_status_code => NULL,
          p_valuation_method => NULL,
          p_security_context => l_event_security_context,
          p_calling_sequence => l_curr_calling_sequence
        );
Line: 1724

      UPDATE xla_ae_headers aeh
         SET aeh.accounting_date = g_sweep_to_date,
             aeh.period_name = g_sweep_to_period,
             last_update_date = SYSDATE,
             last_updated_by =  FND_GLOBAL.user_id
       WHERE aeh.event_id = l_event_ids(i)
         AND application_id = 200
         AND gl_transfer_status_code <> 'Y'
      AND accounting_entry_status_code <> 'F';
Line: 1735

    UPDATE xla_ae_lines ael
       SET ael.accounting_date = g_sweep_to_date,
           last_update_date = sysdate,
           last_updated_by =  FND_GLOBAL.user_id
     WHERE ael.ae_header_id in (
          SELECT aeh.ae_header_id
            FROM xla_ae_headers aeh
           WHERE aeh.event_id = l_event_ids(i)
             AND aeh.application_id = 200
             AND aeh.gl_transfer_status_code <> 'Y'
    AND aeh.accounting_entry_status_code <> 'F');
Line: 1750

  debug ('end update_xla_events');
Line: 1760

    debug ('EXCEPTION: update_xla_events: '|| sqlerrm);
Line: 1763

END update_xla_events;
Line: 1766

 |  FUNCTION  -  UPDATE_AP_ACCT_DATE
 |
 |  DESCRIPTION
 |      This function is used to sweep invoice distributions, lines and
 |      payment, payment history records to an open date in next accounting
 |      period that are unaccounted in the current period.
 |
 |
 |  PRAMETERS
 |
 |
 |  KNOWN ISSUES:
 |
 |  NOTES:
 |
 |  MODIFICATION HISTORY
 |  Date         Author             Description of Change
 |  14-MAR-08    PRANPAUL           New
 *===========================================================================*/
FUNCTION update_ap_acct_date RETURN BOOLEAN IS


  type typ_number_tab is table of number (15) index by binary_integer;
Line: 1797

	UPDATE ap_invoice_distributions_all aid
	SET accounting_date = g_sweep_to_date,
	    period_name = g_sweep_to_period,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE aid.invoice_distribution_id in (SELECT gt.invoice_distribution_id
					      FROM ap_period_close_excps_gt gt
					      WHERE gt.source_type = G_SRC_TYP_UNACCT_DISTS
					      AND   gt.source_table_name = G_SRC_TAB_AP_INV_DISTS_ALL)
        AND aid.posted_flag <> 'Y'
   returning invoice_distribution_id bulk collect into l_dbi_key_value_list;
Line: 1809

   debug ('update_ap_acct_date: total records updated in ap_invoice_distributions_all: '||sql%rowcount);
Line: 1812

     update ap_period_close_excps_gt gt
     set    process_status_flag = 'Y'
     where  invoice_distribution_id = l_dbi_key_value_list(i)
     AND  gt.source_type =G_SRC_TYP_UNACCT_DISTS
     AND  gt.source_table_name = G_SRC_TAB_AP_INV_DISTS_ALL;      -- 7318763
Line: 1822

                 p_calling_sequence => 'AP_PERIOD_CLOSE_PKG.update_ap_acct_date');
Line: 1824

   debug ('update_ap_acct_date: total distributions processed in ap_period_close_excps_gt: '||l_dbi_key_value_list.count);
Line: 1827

	UPDATE ap_invoice_lines_all ail
	SET accounting_date = g_sweep_to_date,
	    period_name = g_sweep_to_period,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE (ail.invoice_id, ail.line_number) in (SELECT  gt.invoice_id, gt.invoice_line_number
					      FROM ap_period_close_excps_gt gt
					      WHERE gt.invoice_distribution_id = l_dbi_key_value_list(i)
					      AND gt.source_type=G_SRC_TYP_UNACCT_DISTS
                                              AND gt.source_table_name = G_SRC_TAB_AP_INV_DISTS_ALL);     -- 7318763
Line: 1838

    debug ('update_ap_acct_date: total lines processed in ap_invoice_lines_all: '||l_dbi_key_value_list.count);
Line: 1840

  l_dbi_key_value_list.delete;
Line: 1843

	UPDATE ap_self_assessed_tax_dist_all astd
	SET accounting_date = g_sweep_to_date,
	    period_name = g_sweep_to_period,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE astd.invoice_distribution_id in (SELECT gt.invoice_distribution_id
					       FROM ap_period_close_excps_gt gt
					       WHERE gt.source_type = G_SRC_TYP_UNACCT_DISTS
					       AND   gt.source_table_name = G_SRC_TAB_AP_SELF_TAX_DIST_ALL)
        AND astd.posted_flag <> 'Y'
   returning invoice_distribution_id bulk collect into ltab_id;
Line: 1855

   debug ('update_ap_acct_date: total records updated in ap_self_assessed_tax_dist_all: '||sql%rowcount);
Line: 1858

     update ap_period_close_excps_gt  gt
     set    process_status_flag = 'Y'
     where  invoice_distribution_id = ltab_id(i)
     AND  gt.source_type =G_SRC_TYP_UNACCT_DISTS
     AND  gt.source_table_name = G_SRC_TAB_AP_SELF_TAX_DIST_ALL;   -- 7318763
Line: 1864

   debug ('update_ap_acct_date: total self assessed tax distributions processed in ap_period_close_excps_gt: '||ltab_id.count);
Line: 1866

  ltab_id.delete;
Line: 1869

	UPDATE ap_invoice_lines_all ail
	SET accounting_date = g_sweep_to_date,
	    period_name = g_sweep_to_period,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE (ail.invoice_id,ail.line_number) in
					(SELECT gt.invoice_id, gt.invoice_line_number
					 FROM ap_period_close_excps_gt gt
					 WHERE gt.source_type = G_SRC_TYP_LINES_WITHOUT_DISTS
					 AND   gt.source_table_name = G_SRC_TAB_AP_INV_LINES_ALL)
  returning ail.invoice_id, ail.line_number bulk collect into ltab_id, ltab_line_num;
Line: 1880

  debug ('update_ap_acct_date: total records updated in ap_invoice_lines_all: '||sql%rowcount);
Line: 1883

    update ap_period_close_excps_gt gt
    set    process_status_flag = 'Y'
    where  invoice_id = ltab_id(i)
    and    invoice_line_number = ltab_line_num(i)
    AND  gt.source_type =G_SRC_TYP_LINES_WITHOUT_DISTS
    AND  gt.source_table_name = G_SRC_TAB_AP_INV_LINES_ALL;     -- 7318763
Line: 1890

  debug ('update_ap_acct_date: total invoice lines processed in ap_period_close_excps_gt: '||ltab_id.count );
Line: 1892

  ltab_id.delete;
Line: 1894

	UPDATE ap_invoice_payments_all aip
	SET accounting_date = g_sweep_to_date,
	    period_name = g_sweep_to_period,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE aip.invoice_payment_id in (SELECT gt.invoice_payment_id
					 FROM ap_period_close_excps_gt gt
					 WHERE gt.source_type = G_SRC_TYP_UNACCT_INV_PMTS
					 AND   gt.source_table_name = G_SRC_TAB_AP_INV_PAYMENTS)
        AND aip.posted_flag <> 'Y'
  returning invoice_payment_id bulk collect into ltab_id;
Line: 1906

  debug ('update_ap_acct_date: total records updated in ap_invoice_payments_all: '||sql%rowcount);
Line: 1909

     update ap_period_close_excps_gt gt
     set    process_status_flag = 'Y'
     where  invoice_payment_id = ltab_id(i)
     AND  gt.source_type =G_SRC_TYP_UNACCT_INV_PMTS
     AND  gt.source_table_name = G_SRC_TAB_AP_INV_PAYMENTS;     -- 7318763
Line: 1915

  debug ('update_ap_acct_date: total invoice payments processed in ap_period_close_excps_gt: '||ltab_id.count );
Line: 1917

  ltab_id.delete;
Line: 1920

	UPDATE ap_payment_history_all aph
	SET accounting_date = g_sweep_to_date,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE aph.payment_history_id in (SELECT gt.payment_history_id
					 FROM ap_period_close_excps_gt gt
					 WHERE gt.source_type = G_SRC_TYP_UNACCT_PMT_HISTORY
					 AND   gt.source_table_name = G_SRC_TAB_AP_PMT_HISTORY)
        AND aph.posted_flag <> 'Y'
  returning aph.payment_history_id bulk collect into ltab_id;
Line: 1931

  debug ('update_ap_acct_date: total records updated in ap_payment_history_all: '||sql%rowcount);
Line: 1934

     update ap_period_close_excps_gt gt
     set    process_status_flag = 'Y'
     where  payment_history_id = ltab_id(i)
     AND  gt.source_type =G_SRC_TYP_UNACCT_PMT_HISTORY
     AND  gt.source_table_name = G_SRC_TAB_AP_PMT_HISTORY;        -- 7318763
Line: 1939

  debug ('update_ap_acct_date: total payment history processed in ap_period_close_excps_gt: '||ltab_id.count );
Line: 1941

  ltab_id.delete;
Line: 1945

        UPDATE ap_prepay_history_all apph
	SET accounting_date = g_sweep_to_date,
	    last_update_date = sysdate,
	    last_updated_by = 5
	WHERE apph.accounting_event_id in (SELECT gt.accounting_event_id
	                                   FROM ap_period_close_excps_gt gt
					   WHERE gt.source_type = G_SRC_TYP_UNACCT_PREPAY_HIST
					   AND gt.source_table_name = G_SRC_TAB_AP_PREPAY_HIST
					   AND gt.accounting_event_id IS NOT NULL)
        AND apph.posted_flag <> 'Y'
  returning apph.accounting_event_id bulk collect into ltab_id;
Line: 1957

  debug ('update_ap_acct_date: total records updated in ap_prepay_history_all: '||sql%rowcount);
Line: 1961

     update ap_period_close_excps_gt gt
     set process_status_flag = 'Y'
     where accounting_event_id = ltab_id(i)
     AND gt.source_type = G_SRC_TYP_UNACCT_PREPAY_HIST
     AND gt.source_table_name = G_SRC_TAB_AP_PREPAY_HIST;
Line: 1967

  debug ('update_ap_acct_date: total prepay history processed in ap_period_close_excps_gt: '||ltab_id.count );
Line: 1970

  ltab_id.delete;
Line: 1981

 |  FUNCTION  -  DELETE_ORPHAN_EVENTS
 |
 |  DESCRIPTION
 |      This function is used to delete the Orphan events in the
 |      system, for the current ledger which lie within the start
 |      and end dates.
 |
 |
 |  PRAMETERS
 |
 |
 |  KNOWN ISSUES:
 |
 |  NOTES:
 |
 |  MODIFICATION HISTORY
 |  Date         Author             Description of Change
 |  14-MAR-08    GAGRAWAL           New
 *===========================================================================*/

FUNCTION delete_orphan_events RETURN BOOLEAN IS

   TYPE orphan_events_tab IS
   TABLE OF xla_events.event_id%TYPE
   INDEX BY BINARY_INTEGER;
Line: 2015

   SELECT xe.event_id,
          xah.ae_header_id
   FROM xla_events xe,
        xla_transaction_entities_upg xte,
	xla_ae_headers xah
   WHERE xe.application_id = 200
   AND xte.application_id = 200
   AND xah.application_id(+) = 200
   AND xe.entity_id = xte.entity_id
   AND xe.event_status_code IN ('U','I')
   AND xe.process_status_code IN ('U','I')
   AND xte.ledger_id = g_ledger_id
   AND xe.event_id = xah.event_id(+)
   AND xe.event_date BETWEEN g_period_start_date
                     AND g_period_end_date
   AND NOT EXISTS
    (SELECT 1
     FROM ap_invoice_distributions_all aid
     WHERE aid.accounting_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_invoice_distributions_all aid
     WHERE aid.bc_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_self_assessed_tax_dist_all aid
     WHERE aid.accounting_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_self_assessed_tax_dist_all aid
     WHERE aid.bc_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_prepay_history_all apph
     WHERE apph.accounting_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_prepay_history_all apph
     WHERE apph.bc_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_invoice_payments_all aip
     WHERE aip.accounting_event_id = xe.event_id)
   AND NOT EXISTS
    (SELECT 1
     FROM ap_payment_history_all aph
     WHERE aph.accounting_event_id = xe.event_id)
   AND xe.event_type_code <> 'MANUAL';
Line: 2077

    DELETE FROM xla_distribution_links
    WHERE application_id = 200
    AND ae_header_id = l_orphan_headers_data(i)
    AND l_orphan_headers_data(i) IS NOT NULL;
Line: 2084

    DELETE FROM xla_ae_lines
    WHERE application_id = 200
    AND ae_header_id = l_orphan_headers_data(i)
    AND l_orphan_headers_data(i) IS NOT NULL;
Line: 2091

    DELETE FROM xla_ae_headers
    WHERE application_id = 200
    AND ae_header_id = l_orphan_headers_data(i)
    AND l_orphan_headers_data(i) IS NOT NULL;
Line: 2098

    DELETE FROM xla_events
    WHERE application_id = 200
    AND event_id = l_orphan_events_data(i);
Line: 2102

  debug('all deletes successful, returning true');
Line: 2145

    l_success := update_po_close_date;
Line: 2148

        print ('Failure in update_po_close_date while updating PO shipments');
Line: 2153

    update_xla_events('AP_PERIOD_CLOSE_EXCP_PKG.DO_SWEEP',
           l_success);
Line: 2157

        print ('Failure in update_xla_events while updating XLA unaccounted events');
Line: 2161

    l_success := update_ebtax_dists;
Line: 2164

        print ('Failure in update_ebtax_dists while updating tax distributions in eBtax');
Line: 2168

    l_success := update_ap_acct_date;
Line: 2172

        print ('Failure in update_ap_acct_date while updating payables invoices and payments');
Line: 2179

      l_success := delete_orphan_events;
Line: 2182

          print ('Failure in delete_orphan_events while deleting the orphan events');