Wednesday 11 December 2013

Service Contracts Multiple Billing Through Order Management

The Below code Describes The multiple Billing Schedule for contract that is created through Order Management.

Issue : When we create service Contract from Order management we cant use the Multiple billing schedule option of Service Contracts Module.

Solution :

Refrences :http://www.oraclebusinessapps.com/2008/07/26/r12-service-contract-from-order-management-part-iii/

1. Create a temp Table
------------------------------------------------------------------------------------------------------------
/*<Temprory Table to Store Order Details  Service LIne >*/
CREATE TABLE XX_OKS_OM_TST_TBL
(
  FROM_INTEGRATION  VARCHAR2(300 BYTE),
  TRANSACTION_TYPE  VARCHAR2(100 BYTE),
  TRANSACTION_DATE  DATE,
  ORDER_LINE_ID     NUMBER,
  OLD_INSTANCE_ID   NUMBER,
  NEW_INSTANCE_ID   NUMBER,
  CHR_ID            NUMBER,
  TOPLINE_ID        NUMBER,
  SUBLINE_ID        NUMBER
);
/
------------------------------------------------------------------------------------------------------------

2.
CREATE OR REPLACE PACKAGE APPS.xx_alter_contract_from_om
IS
   PROCEDURE prepare_contract (
      p_from_integration   IN              VARCHAR2
    , p_transaction_type   IN              VARCHAR2
    , p_transaction_date   IN              DATE
    , p_order_line_id      IN              NUMBER
    , p_old_instance_id    IN              NUMBER
    , p_new_instance_id    IN              NUMBER
    , p_chr_id             IN              NUMBER
    , p_topline_id         IN              NUMBER
    , p_subline_id         IN              NUMBER
    , x_return_status      OUT NOCOPY      VARCHAR2
    , x_msg_count          OUT NOCOPY      NUMBER
    , x_msg_data           OUT NOCOPY      VARCHAR2
   );
END xx_alter_contract_from_om;
/
------------------------------------------------------------------------------------------------------------

CREATE OR REPLACE PACKAGE BODY APPS.xx_alter_contract_from_om
IS
   PROCEDURE prepare_contract (
      p_from_integration   IN              VARCHAR2
    , p_transaction_type   IN              VARCHAR2
    , p_transaction_date   IN              DATE
    , p_order_line_id      IN              NUMBER
    , p_old_instance_id    IN              NUMBER
    , p_new_instance_id    IN              NUMBER
    , p_chr_id             IN              NUMBER
    , p_topline_id         IN              NUMBER
    , p_subline_id         IN              NUMBER
    , x_return_status      OUT NOCOPY      VARCHAR2
    , x_msg_count          OUT NOCOPY      NUMBER
    , x_msg_data           OUT NOCOPY      VARCHAR2
   )
   IS
      l_bclv_rec_type      oks_billcontline_pub.bclv_rec_type;
      l_bslv_rec_type      oks_billsubline_pub.bslv_rec_type;
      x_bill_cont_status   VARCHAR2 (1);
      x_sub_line_status    VARCHAR2 (1);
      x_rgp_id             NUMBER;
      x_status             VARCHAR2 (1);
      l_top_months         NUMBER;
      l_sub_months         NUMBER;
      l_order_uom          VARCHAR2 (10);
   BEGIN
      okc_context.set_okc_org_context (p_chr_id => p_chr_id);
      fnd_global.apps_initialize (1005902, 21708, 515);

/*==========================================================================
|select order UOM. This logic is to create billing schedules with UOM month.|
|So create an order for the service item with MTH has UOM or create item    |
|with UOM of MTH so that it defaults into order line. This UOM will used in |
|updating the stream headers later                                          |
+==========================================================================*/
      BEGIN
         SELECT order_quantity_uom
           INTO l_order_uom
           FROM oe_order_lines
          WHERE line_id = p_order_line_id;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;

/*==========================================================================
|Since our intention is to create multiple schedules compared to what OKS   |
|Contract Order Capture Program creates, we need to select number of months |
|between start date and End Date. This logic gets harder if you do not      |
|populate the same. It is not required to be populated because the start    |
|date can be calculated based on warranty start date or fulfillment date    |
+==========================================================================*/
      BEGIN
         SELECT CEIL (MONTHS_BETWEEN (end_date, start_date))
           INTO l_top_months
           FROM okc_k_lines_b
          WHERE ID = p_topline_id;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;

      BEGIN
         SELECT CEIL (MONTHS_BETWEEN (end_date, start_date))
           INTO l_sub_months
           FROM okc_k_lines_b
          WHERE ID = p_subline_id;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;

      BEGIN
         SELECT ID
           INTO l_bslv_rec_type.ID
           FROM oks_bill_sub_lines
          WHERE cle_id = p_subline_id;

/*==========================================================================
|Now delete the billing tables. This table is populated to avoid billing for|
|these contracts. This needs to be deleted.Subline here.                    |
+==========================================================================*/
         oks_billsubline_pub.delete_bill_subline_pub (p_api_version        => 1.0
                                                    , p_init_msg_list      => okc_api.g_false
                                                    , x_return_status      => x_sub_line_status
                                                    , x_msg_count          => x_msg_count
                                                    , x_msg_data           => x_msg_data
                                                    , p_bslv_rec           => l_bslv_rec_type
                                                     );
         x_return_status := x_sub_line_status;
         DBMS_OUTPUT.put_line ('Return Status of deleting subline billing record :' || x_sub_line_status);
         DBMS_OUTPUT.put_line ('msg count of deleting sub line billing record:' || x_msg_count);

         IF x_sub_line_status = 'S'
         THEN
/*==========================================================================
|Delete existing billing schedules as we have to recreate them. Blind delete|
|is OK as this schedule comes with completed date and never got billed before|
+==========================================================================*/
            DELETE      oks_level_elements
                  WHERE cle_id = p_subline_id;

/*============================================================================
|Update the number of level periods to the number of periods in months so that|
|billing can happen monthly.Update UOM too!!                                  |
+==========================================================================*/
            UPDATE oks_stream_levels_b
               SET level_periods = l_sub_months
                 , uom_code = l_order_uom
                 , uom_per_period=1
             WHERE cle_id = p_subline_id;

            x_status := 'S';
            --oks_bill_util_pub.refresh_bill_sch (p_cle_id => i.ID, x_rgp_id => x_rgp_id, x_status => x_status);
            DBMS_OUTPUT.put_line ('Return Status of refreshing bill schedules is:' || x_status);
            x_msg_data := NULL;
            x_msg_count := NULL;
            x_return_status := NULL;
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;

      BEGIN
         SELECT ID
           INTO l_bclv_rec_type.ID
           FROM oks_bill_cont_lines
          WHERE cle_id = p_topline_id;

/*==========================================================================
|Now delete the billing tables. This table is populated to avoid billing for|
|these contracts. This needs to be deleted.Top Linehere.                    |
+==========================================================================*/
         oks_billcontline_pub.delete_bill_cont_line (p_api_version        => 1.0
                                                   , p_init_msg_list      => okc_api.g_false
                                                   , x_return_status      => x_bill_cont_status
                                                   , x_msg_count          => x_msg_count
                                                   , x_msg_data           => x_msg_data
                                                   , p_bclv_rec           => l_bclv_rec_type
                                                    );
         x_return_status := x_bill_cont_status;
         DBMS_OUTPUT.put_line ('Return Status of deleting contractline billing record:' || x_bill_cont_status);
         DBMS_OUTPUT.put_line ('msg count of deleting contractline billing record:' || x_msg_count);

         IF x_bill_cont_status = 'S'
         THEN
/*==========================================================================
|Delete existing billing schedules as we have to recreate them. Blind delete|
|is OK as this schedule comes with completed date and never got billed before|
+==========================================================================*/
            DELETE      oks_level_elements
                  WHERE cle_id = p_topline_id;

/*============================================================================
|Update the number of level periods to the number of periods in months so that|
|billing can happen monthly.Update UOM too!!                                  |
+==========================================================================*/
            UPDATE oks_stream_levels_b
               SET level_periods = l_top_months
                 , uom_code = l_order_uom
                 , uom_per_period=1
             WHERE cle_id = p_topline_id;

            x_status := 'S';
            DBMS_OUTPUT.put_line ('Return Status of refreshing bill schedules is:' || x_status);
            x_msg_data := NULL;
            x_msg_count := NULL;
            x_return_status := NULL;
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;

      IF (x_bill_cont_status <> 'S' OR x_sub_line_status <> 'S' OR x_status <> 'S')
      THEN
         ROLLBACK;
      END IF;

/*============================================================================
|Now create new billing schedules                                            |
+==========================================================================*/
      oks_bill_sch.create_bill_sch_cp (p_top_line_id        => p_topline_id
                                     , p_cp_line_id         => p_subline_id
                                     , p_cp_new             => 'Y'
                                     , x_return_status      => x_return_status
                                     , x_msg_count          => x_msg_count
                                     , x_msg_data           => x_msg_data
                                      );
      DBMS_OUTPUT.put_line ('Return Status of refreshing bill schedules is:' || x_return_status);
      DBMS_OUTPUT.put_line ('msg count of refreshing bill sch:' || x_msg_count);

/*=================================================================================
|Finally update the related objects table so that this contract line can be billed!|
+==================================================================================*/
      UPDATE okc_k_rel_objs
         SET cle_id = -1
       WHERE cle_id = p_subline_id;
   END;
END xx_alter_contract_from_om;
/
------------------------------------------------------------------------------------------------------------

Friday 6 December 2013

How to get OAF Page Trace File

1.Click the 'Diagnostics' link in top right of screen

2. From the Diagnostic drop down select 'Set Trace Level' and click 'Go'

3.There will be Six Options In the LOV

4. Select The appropriate option

5. Note down the Trace ID Numbers returned and click 'Save'

6 . Perform The Search/Operation.

7. Select "Disable Trace " after Operation.

8. The trace files should be output to the directory returned by the following query

SELECT value
FROM v$parameter
WHERE name = 'user_dump_dest';

Wednesday 4 December 2013

Find Workflow Email Notification Disabled for whihh User

select * from wf_roles where notification_preference in ('DISABLED','QUERY')
and orig_system='PER'

Query TO Find Chart Of Account Structure (COA)

select sob.name Ledger_Name
, sob.ledger_id Ledger_Id
, sob.chart_of_accounts_id coa_id
, fifst.id_flex_structure_name struct_name
, ifs.segment_name
, ifs.application_column_name column_name
, sav1.attribute_value BALANCING
, sav2.attribute_value COST_CENTER
, sav3.attribute_value NATURAL_ACCOUNT
, sav4.attribute_value INTERCOMPANY
, sav5.attribute_value SECONDARY_TRACKING
, sav6.attribute_value GLOBAL
, ffvs.flex_value_set_name
, ffvs.flex_value_set_id
from fnd_id_flex_structures fifs
, fnd_id_flex_structures_tl fifst
, fnd_segment_attribute_values sav1
, fnd_segment_attribute_values sav2
, fnd_segment_attribute_values sav3
, fnd_segment_attribute_values sav4
, fnd_segment_attribute_values sav5
, fnd_segment_attribute_values sav6
, fnd_id_flex_segments ifs
, fnd_flex_value_sets ffvs
, gl_ledgers sob
where 1=1
and fifs.id_flex_code = 'GL#'
and fifs.application_id = fifst.application_id
and fifs.id_flex_code = fifst.id_flex_code
and fifs.id_flex_num = fifst.id_flex_num
and fifs.application_id = ifs.application_id
and fifs.id_flex_code = ifs.id_flex_code
and fifs.id_flex_num = ifs.id_flex_num
and sav1.application_id = ifs.application_id
and sav1.id_flex_code = ifs.id_flex_code
and sav1.id_flex_num = ifs.id_flex_num
and sav1.application_column_name = ifs.application_column_name
and sav2.application_id = ifs.application_id
and sav2.id_flex_code = ifs.id_flex_code
and sav2.id_flex_num = ifs.id_flex_num
and sav2.application_column_name = ifs.application_column_name
and sav3.application_id = ifs.application_id
and sav3.id_flex_code = ifs.id_flex_code
and sav3.id_flex_num = ifs.id_flex_num
and sav3.application_column_name = ifs.application_column_name
and sav4.application_id = ifs.application_id
and sav4.id_flex_code = ifs.id_flex_code
and sav4.id_flex_num = ifs.id_flex_num
and sav4.application_column_name = ifs.application_column_name
and sav5.application_id = ifs.application_id
and sav5.id_flex_code = ifs.id_flex_code
and sav5.id_flex_num = ifs.id_flex_num
and sav5.application_column_name = ifs.application_column_name
and sav6.application_id = ifs.application_id
and sav6.id_flex_code = ifs.id_flex_code
and sav6.id_flex_num = ifs.id_flex_num
and sav6.application_column_name = ifs.application_column_name
and sav1.segment_attribute_type = 'GL_BALANCING'
and sav2.segment_attribute_type = 'FA_COST_CTR'
and sav3.segment_attribute_type = 'GL_ACCOUNT'
and sav4.segment_attribute_type = 'GL_INTERCOMPANY'
and sav5.segment_attribute_type = 'GL_SECONDARY_TRACKING'
and sav6.segment_attribute_type = 'GL_GLOBAL'
and ifs.id_flex_num = sob.chart_of_accounts_id
and ifs.flex_value_set_id = ffvs.flex_value_set_id
and sob.ledger_id =
nvl(fnd_profile.value('GL_SET_OF_BKS_ID'),sob.ledger_id)
order by sob.name, sob.chart_of_accounts_id, ifs.application_column_name;

Query TO Find Chart Of Account Structure (COA)

select sob.name Ledger_Name
, sob.ledger_id Ledger_Id
, sob.chart_of_accounts_id coa_id
, fifst.id_flex_structure_name struct_name
, ifs.segment_name
, ifs.application_column_name column_name
, sav1.attribute_value BALANCING
, sav2.attribute_value COST_CENTER
, sav3.attribute_value NATURAL_ACCOUNT
, sav4.attribute_value INTERCOMPANY
, sav5.attribute_value SECONDARY_TRACKING
, sav6.attribute_value GLOBAL
, ffvs.flex_value_set_name
, ffvs.flex_value_set_id
from fnd_id_flex_structures fifs
, fnd_id_flex_structures_tl fifst
, fnd_segment_attribute_values sav1
, fnd_segment_attribute_values sav2
, fnd_segment_attribute_values sav3
, fnd_segment_attribute_values sav4
, fnd_segment_attribute_values sav5
, fnd_segment_attribute_values sav6
, fnd_id_flex_segments ifs
, fnd_flex_value_sets ffvs
, gl_ledgers sob
where 1=1
and fifs.id_flex_code = 'GL#'
and fifs.application_id = fifst.application_id
and fifs.id_flex_code = fifst.id_flex_code
and fifs.id_flex_num = fifst.id_flex_num
and fifs.application_id = ifs.application_id
and fifs.id_flex_code = ifs.id_flex_code
and fifs.id_flex_num = ifs.id_flex_num
and sav1.application_id = ifs.application_id
and sav1.id_flex_code = ifs.id_flex_code
and sav1.id_flex_num = ifs.id_flex_num
and sav1.application_column_name = ifs.application_column_name
and sav2.application_id = ifs.application_id
and sav2.id_flex_code = ifs.id_flex_code
and sav2.id_flex_num = ifs.id_flex_num
and sav2.application_column_name = ifs.application_column_name
and sav3.application_id = ifs.application_id
and sav3.id_flex_code = ifs.id_flex_code
and sav3.id_flex_num = ifs.id_flex_num
and sav3.application_column_name = ifs.application_column_name
and sav4.application_id = ifs.application_id
and sav4.id_flex_code = ifs.id_flex_code
and sav4.id_flex_num = ifs.id_flex_num
and sav4.application_column_name = ifs.application_column_name
and sav5.application_id = ifs.application_id
and sav5.id_flex_code = ifs.id_flex_code
and sav5.id_flex_num = ifs.id_flex_num
and sav5.application_column_name = ifs.application_column_name
and sav6.application_id = ifs.application_id
and sav6.id_flex_code = ifs.id_flex_code
and sav6.id_flex_num = ifs.id_flex_num
and sav6.application_column_name = ifs.application_column_name
and sav1.segment_attribute_type = 'GL_BALANCING'
and sav2.segment_attribute_type = 'FA_COST_CTR'
and sav3.segment_attribute_type = 'GL_ACCOUNT'
and sav4.segment_attribute_type = 'GL_INTERCOMPANY'
and sav5.segment_attribute_type = 'GL_SECONDARY_TRACKING'
and sav6.segment_attribute_type = 'GL_GLOBAL'
and ifs.id_flex_num = sob.chart_of_accounts_id
and ifs.flex_value_set_id = ffvs.flex_value_set_id
and sob.ledger_id =
nvl(fnd_profile.value('GL_SET_OF_BKS_ID'),sob.ledger_id)
order by sob.name, sob.chart_of_accounts_id, ifs.application_column_name;

Query To Get Customer Details

SELECT hp.party_id
      ,hp.party_number
      ,hp.party_name
      ,hp.party_type
      ,hp.orig_system_reference
      ,hp.tax_reference
      ,hpua.party_usg_assignment_id
      ,hpua.party_usage_code
      ,hpua.effective_start_date
      ,hpua.effective_end_date
      ,hop.organization_profile_id
      ,hop.organization_name_phonetic
      ,hop.organization_type
      ,hps.party_site_id
      ,hps.party_site_number
      ,hps.orig_system_reference party_site_reference
      ,hps.party_site_name
      ,aps.vendor_id
      ,aps.vendor_name
      ,aps.vendor_name_alt
      ,aps.segment1
      ,aps.vendor_type_lookup_code
      ,aps.payment_currency_code
      ,aps.invoice_currency_code
      ,aps.hold_all_payments_flag
      ,aps.vat_registration_num
      ,aps.match_option
      ,apss.vendor_site_id
      ,apss.vendor_site_code
      ,apss.purchasing_site_flag
      ,apss.rfq_only_site_flag
      ,apss.pay_site_flag
      ,apss.address_line1
      ,apss.address_line2
      ,apss.zip
      ,apss.country
      ,apss.bill_to_location_id
      ,apss.accts_pay_code_combination_id
      ,iep.ext_payee_id
      ,iep.payment_function
      ,iep.org_type
      ,iep.default_payment_method_code
      ,iep.remit_advice_delivery_method
      ,iep.remit_advice_fax
      ,zxtp.party_type_code
      ,zxtp.rep_registration_number
FROM   hz_parties hp
      ,hz_party_usg_assignments hpua
      ,hz_organization_profiles hop
      ,hz_party_sites hps
      ,ap_suppliers aps
      ,ap_supplier_sites_all apss
      ,iby_external_payees_all iep
      ,zx_party_tax_profile zxtp
WHERE  1 = 1
AND    hp.party_id        = hpua.party_id
AND    hp.party_id        = hop.party_id
AND    hp.party_id        = hps.party_id
AND    hp.party_id        = aps.party_id
AND    aps.vendor_id      = apss.vendor_id
AND    hps.party_site_id  = apss.party_site_id
AND    hp.party_id        = iep.payee_party_id
AND    apss.vendor_site_id= iep.supplier_site_id
AND    hps.party_site_id  = iep.party_site_id
AND    hp.party_id        = zxtp.party_id

Query To Find Application URL

Select PROFILE_OPTION_VALUE
From   FND_PROFILE_OPTION_VALUES
WHERE  PROFILE_OPTION_ID =
       (SELECT PROFILE_OPTION_ID
        FROM FND_PROFILE_OPTIONS
        WHERE PROFILE_OPTION_NAME ='APPS_FRAMEWORK_AGENT')
        AND LEVEL_VALUE=0;

All Concurrent Program Run By User

SELECT
    user_concurrent_program_name,
    responsibility_name,
    request_date,
    argument_text,
    request_id,
    phase_code,
    status_code,
    logfile_name,
    outfile_name,
    output_file_type
FROM
    fnd_concurrent_requests fcr,
    fnd_concurrent_programs_tl fcp,
    fnd_responsibility_tl fr,
    fnd_user fu
WHERE
    fcr.CONCURRENT_PROGRAM_ID = fcp.concurrent_program_id
    and fcr.responsibility_id = fr.responsibility_id
    and fcr.requested_by = fu.user_id
    and user_name = upper(:user_name)
ORDER BY REQUEST_DATE DESC;

Request Details

SELECT
    user_concurrent_program_name,
    responsibility_name,
    request_date,
    argument_text,
    request_id,
    phase_code,
    status_code,
    logfile_name,
    outfile_name,
    output_file_type
FROM
    fnd_concurrent_requests fcr,
    fnd_concurrent_programs_tl fcp,
    fnd_responsibility_tl fr,
    fnd_user fu
WHERE
    fcr.CONCURRENT_PROGRAM_ID = fcp.concurrent_program_id
    and fcr.responsibility_id = fr.responsibility_id
    and fcr.requested_by = fu.user_id
    and user_name = upper(:user_name)
ORDER BY REQUEST_DATE DESC;

Query to find submitted Concurrent requests

  Query to find Concurrent Requests SELECT      user_concurrent_program_name,      responsibility_name,      request_date,      argument_tex...