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;

Friday 4 October 2013

AR INTERFACE

DECLARE

    CURSOR C1 IS
    SELECT *
    FROM XX_UPLOAD_AR_INVOICES ar
    WHERE ar.PROCESS_FLAG IS NULL
    AND ar.SR_NO IN (3,4) ;
 
    v_trx_type      NUMBER;
    v_trx_name      VARCHAR2(60);
    v_batch_id      NUMBER;
    v_batch_name    VARCHAR2(60);
    v_gl_id         NUMBER;
    v_customer_id           NUMBER;
    v_bill_to_address_id    NUMBER;
    v_ship_to_address_id    NUMBER;
    V_TERM_ID       NUMBER;
    V_TERM          VARCHAR2(50);
    V_CC            NUMBER;
    V_ERR           VARCHAR2(4000);
    V_SITE          VARCHAr2(150);
    V_INTERFACE_LINE_ID     NUMBER;
 
 
BEGIN
 
    FOR i IN C1
    LOOP          
     
        V_ERR := Null;
     
        BEGIN
            /* ---- Check Batch Source Name ------ */
            SELECT rb.BATCH_SOURCE_ID, rb.NAME
            INTO v_batch_id, v_batch_name
            FROM RA_BATCH_SOURCES_ALL rb
            WHERE rb.NAME = 'Open Data Import Source'
            AND rb.ORG_ID = 82 ;
         
         
            /* -----  Check Transaction Type  -----*/
            SELECT rct.CUST_TRX_TYPE_ID, rct.NAME, rct.SET_OF_BOOKS_ID
            INTO v_trx_type, v_trx_name, v_gl_id
            FROM RA_CUST_TRX_TYPES_ALL rct
            WHERE rct.NAME = 'NEEPL_MCS_DOM_INV'  --- ar.CLASS                    
            AND rct.ORG_ID = 82 ;
         
            /* ----- Check Term Information ------ */
            BEGIN
         
             SELECT rt.TERM_ID, rt.NAME INTO V_TERM_ID, V_TERM
                FROM RA_TERMS rt
                WHERE UPPER(rt.NAME) = UPPER( i.PAYMENT_TERM );

            EXCEPTION
                WHEN OTHERS THEN
                     V_TERM_ID := 5;
            END;
         
            BEGIN
         
            SELECT hca.CUST_ACCOUNT_ID INTO v_customer_id
            FROM HZ_PARTIES hp,
            HZ_CUST_ACCOUNTS hca
            WHERE hp.PARTY_ID = hca.PARTY_ID
            AND UPPER(RTRIM(LTRIM(hp.PARTY_NAME))) = UPPER(RTRIM(LTRIM(i.BILL_TO_NAME)));
         
            EXCEPTION
                WHEN OTHERS THEN
                     v_customer_id := NULL;
                     V_ERR := V_ERR || ' Supplier Not Exists.';
         
            END;
            /* ----- Bill to address id ------ */
            BEGIN
                SELECT hcas.CUST_ACCT_SITE_ID INTO v_bill_to_address_id
                FROM hz_cust_accounts_all hca
                ,hz_cust_acct_sites_all hcas
                ,hz_cust_site_uses_all hcsu
                WHERE 1 = 1
                AND hca.cust_account_id = hcas.cust_account_id
                AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
                AND hcsu.status = 'A'
                AND hcsu.site_use_code = 'BILL_TO'
                AND hca.cust_account_id = v_customer_id
                AND hcsu.org_id = 82;
             
            EXCEPTION
                WHEN OTHERS THEN
                    v_bill_to_address_id := NULL;
                    V_ERR := V_ERR || ' Bill to Addrees not exist';
            END;
         
            BEGIN

                /* ----- Ship to Address ID ------ */
                SELECT hcas.CUST_ACCT_SITE_ID INTO v_ship_to_address_id
                FROM hz_cust_accounts_all hca
                ,hz_cust_acct_sites_all hcas
                ,hz_cust_site_uses_all hcsu
                WHERE 1 = 1
                AND hca.cust_account_id = hcas.cust_account_id
                AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
                AND hcsu.status = 'A'
                AND hcsu.site_use_code = 'SHIP_TO'
                AND hca.cust_account_id = v_customer_id
                AND hcsu.org_id = 82;

            EXCEPTION
                WHEN OTHERS THEN
                    v_ship_to_address_id := NULL;

            END;
       
        IF v_customer_id IS NOT NULL AND    v_bill_to_address_id IS NOT NULL THEN
     
            SELECT RA_CUSTOMER_TRX_LINES_S.NEXTVAL INTO V_INTERFACE_LINE_ID
            FROM DUAL;
         
            BEGIN
         
                SELECT ffv.FLEX_VALUE INTO V_SITE
                FROM FND_FLEX_VALUES_VL ffv
                WHERE ffv.FLEX_VALUE_SET_ID = 1014868
                AND UPPER(ffv.DESCRIPTION) = UPPER(i.SITE) ;

            EXCEPTION
                WHEN OTHERS THEN
                    V_SITE := NULL;
            END;
         
            INSERT INTO ra_interface_lines_all ria
            ( INTERFACE_LINE_ID,BATCH_SOURCE_NAME,LINE_TYPE,
                ria.TRX_NUMBER,
                CUST_TRX_TYPE_ID,
                cust_trx_type_name,
                SET_OF_BOOKS_ID,
                TRX_DATE,
                GL_DATE,
                CURRENCY_CODE,
                term_id,
                term_name,
                orig_system_bill_customer_id,
                ORIG_SYSTEM_BILL_CUSTOMER_REF,
                orig_system_bill_address_id,
                ORIG_SYSTEM_BILL_ADDRESS_REF,
                ria.ORIG_SYSTEM_SHIP_ADDRESS_ID,
                ria.ORIG_SYSTEM_SHIP_ADDRESS_REF,
                ria.INVENTORY_ITEM_ID,
                QUANTITY,
                ria.UNIT_SELLING_PRICE,
                AMOUNT,
                DESCRIPTION,
                org_id,
                CONVERSION_TYPE,
                ria.CONVERSION_RATE,
                ria.INTERFACE_LINE_CONTEXT,
                ria.INTERFACE_LINE_ATTRIBUTE1,
                ria.INTERFACE_LINE_ATTRIBUTE2,
                ria.INTERFACE_LINE_ATTRIBUTE3,
                ria.INTERFACE_LINE_ATTRIBUTE4,
                ria.INTERFACE_LINE_ATTRIBUTE5,
                ria.INTERFACE_LINE_ATTRIBUTE6,
                ria.INTERFACE_LINE_ATTRIBUTE7,
                ria.INTERFACE_LINE_ATTRIBUTE8,
                ria.INTERFACE_LINE_ATTRIBUTE9,
                ria.INTERFACE_LINE_ATTRIBUTE10,
                ria.INTERFACE_LINE_ATTRIBUTE11,
                ria.INTERFACE_LINE_ATTRIBUTE12,
                ria.INTERFACE_LINE_ATTRIBUTE13,
                ria.INTERFACE_LINE_ATTRIBUTE14,
                ria.INTERFACE_LINE_ATTRIBUTE15,
                ria.PRIMARY_SALESREP_NUMBER,
                ria.HEADER_ATTRIBUTE1,
                ria.HEADER_ATTRIBUTE2,
                ria.HEADER_ATTRIBUTE3
            )Values
            (V_INTERFACE_LINE_ID,
                'Open Data Import Source',
                'LINE',
                NULL,
                v_trx_type,                 -- cust_trx_type_id,
                'NEEPL_MCS_DOM_INV',        -- cust_trx_type_name,
                v_gl_id,
                i.INV_DATE ,
                '28-FEB-2013',
                'INR',                      -- currency_code,
                V_TERM_ID,                  -- term_id,
                V_TERM,                    -- term_name,
                v_customer_id,
                v_customer_id,
                v_bill_to_address_id,
                v_bill_to_address_id,
                v_ship_to_address_id,
                v_ship_to_address_id,
                NULL,                       --- Inventory item id
                1,                          --- Qty
                i.AMOUNT,                      --- Unit Selling Price
                i.AMOUNT,                      --- Invoice Amount
                'Test Invoice',             --- Description
                82,                         --- Orgid
                'User',                     --- Conversion Type
                1,                          --- Convesrion rate
                'ORDER ENTRY',
                i.BILL_TO_NUMBER ,
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                '0',
                -3,      ---primary saleperson -- No Sales Credits
                i.DIVISION,
                V_SITE,
                i.BILL_TO_NUMBER
            );

            COMMIT;
         

            BEGIN
             
                         
                SELECT gcc.CODE_COMBINATION_ID INTO V_CC
                FROM GL_CODE_COMBINATIONS gcc
                WHERE gcc.SEGMENT1||'.'||gcc.SEGMENT2||'.'||
                gcc.SEGMENT3||'.'||gcc.SEGMENT4||'.'||gcc.SEGMENT5||'.'||
                gcc.SEGMENT6||'.'||gcc.SEGMENT7||'.'||gcc.SEGMENT8 = TRIM(i.ACCOUNT_CODE);

            EXCEPTION
                WHEN OTHERS THEN
                         V_CC := NULL;
            END;
             
            INSERT INTO ra_interface_distributions_all rid
            (
            INTERFACE_LINE_ID
            ,account_class
            ,amount
            ,code_combination_id
            ,percent
            ,org_id
            )
            VALUES
            (
            V_INTERFACE_LINE_ID,
            'REV'
            ,i.AMOUNT                              --- Invoice Amt
            ,V_CC                               --- Code Combination ID
            ,100                              
            ,82
            );

            COMMIT;
         
            INSERT INTO RA_INTERFACE_SALESCREDITS_ALL rs
            (rs.INTERFACE_LINE_ID,
            rs.INTERFACE_LINE_CONTEXT,
            rs.INTERFACE_LINE_ATTRIBUTE1,
            rs.INTERFACE_LINE_ATTRIBUTE2,
            rs.INTERFACE_LINE_ATTRIBUTE3,
            rs.INTERFACE_LINE_ATTRIBUTE4,
            rs.INTERFACE_LINE_ATTRIBUTE5,
            rs.INTERFACE_LINE_ATTRIBUTE6,
            rs.INTERFACE_LINE_ATTRIBUTE7,
            rs.INTERFACE_LINE_ATTRIBUTE8,
            rs.INTERFACE_LINE_ATTRIBUTE9,
            rs.INTERFACE_LINE_ATTRIBUTE10,
            rs.INTERFACE_LINE_ATTRIBUTE11,
            rs.INTERFACE_LINE_ATTRIBUTE12,
            rs.INTERFACE_LINE_ATTRIBUTE13,
            rs.INTERFACE_LINE_ATTRIBUTE14,
            rs.INTERFACE_LINE_ATTRIBUTE15,
            rs.CREATION_DATE,
            rs.CREATED_BY,
            rs.SALES_CREDIT_AMOUNT_SPLIT,
            rs.SALES_CREDIT_PERCENT_SPLIT,
            rs.SALESREP_NUMBER,
            rs.SALESREP_ID,
            rs.SALES_CREDIT_TYPE_ID,
            rs.SALES_CREDIT_TYPE_NAME,
            rs.ORG_ID )
            VALUES
            (V_INTERFACE_LINE_ID,
            'ORDER ENTRY',
            i.BILL_TO_NUMBER,
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',
            '0',  
            '0',
            SYSDATE,
            1110,
            i.AMOUNT,                                  -- Amount
            100,
            -3,
            NULL,
            1,
            'Quota Sales Credit',
            82
            );
         
            COMMIT;
         
            UPDATE XX_UPLOAD_AR_INVOICES ar
                SET ar.PROCESS_FLAG = 'Y'
                , ar.ERROR_MESSAGE = NULL
                WHERE ar.SR_NO = i.SR_NO;
                COMMIT;
     
        ELSE
         
            UPDATE XX_UPLOAD_AR_INVOICES ar
                SET ar.PROCESS_FLAG = 'E'
                , ar.ERROR_MESSAGE = V_ERR
                WHERE ar.SR_NO = i.SR_NO;
                COMMIT;
         
        END IF;
     
        EXCEPTION
            WHEN OTHERS THEN
                V_ERR := SQLCODE || '-'|| SQLERRM;
               
                UPDATE XX_UPLOAD_AR_INVOICES ar
                SET ar.PROCESS_FLAG = 'EE'
                , ar.ERROR_MESSAGE = V_ERR
                WHERE ar.SR_NO = i.SR_NO;
                COMMIT;
        END;
    END LOOP;
 
END;

Thursday 8 August 2013


CREATE OR REPLACE PROCEDURE APPS.xx_cust_additionl_info_entry
-- ********************************************************************************
--            
-- ********************************************************************************
--    Project        :  SaaS
--     Application    :  Receivables
--     Script         :
--     Created by     :  Sachin Ingle
--     Creation date  :  5-AUG-2013
--     Description    :  This Package picks data from staging table / Customer Created for specific Operating unit and inserts Data into
--                       jai_cmn_cus_addresses/Additional info
--     Parameters     :  None
--     Inputs         :  None
--     Outputs        :  None
--     Database       :
--     Apps. Release  :  Oracle Applications 12.1.3
--
--     Development and Maintenance History :
--
--     Date                Version            Author               Description
--     ----------------------------------------------------------------------------
--     05-Aug-2013        1.0               Sachin Ingle              Initial
-- *********************************************************************************
AS
   ln_customer_id   NUMBER := 0;
   ln_address_id    NUMBER := 0;

   CURSOR customer_info
   IS
      SELECT DISTINCT hcas.cust_acct_site_id, hp.party_name,
                      hca.cust_account_id
                        --  hp.orig_system_reference,
                      --    hps.orig_system_reference,
                         -- hp.party_id,
                         -- hps.party_site_id
                 --    INTO l_address_id, l_customer_id,
                        --  l_address_ref,
                        --  l_customer_ref, l_party_id,
                        --  l_party_site_id
      FROM            hz_parties hp,
                      hz_party_sites hps,
                      hz_cust_accounts hca,
                      hz_cust_acct_sites_all hcas,
                      hz_cust_site_uses_all hcsu
                WHERE hca.party_id = hp.party_id
                  AND hp.party_id = hps.party_id
                  AND hca.cust_account_id = hcas.cust_account_id
                  AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
                  AND hcsu.site_use_code = 'BILL_TO'
                  AND hcsu.primary_flag = 'Y'
                  --   AND UPPER (LTRIM (RTRIM (hp.party_name))) =
                  AND hcas.org_id = 85
                  -- AND ROWNUM = 1;
               --  and hca.cust_account_id =561604;
               AND hca.cust_account_id NOT IN (SELECT customer_id
                                                FROM jai_cmn_cus_addresses);
BEGIN
   FOR i IN customer_info
   LOOP
      BEGIN
      /* This Isert Statement Enter Value with customer address site*/
         INSERT INTO jai_cmn_cus_addresses
                     (customer_id,
                      address_id,
                      cst_reg_no,
                      st_reg_no,
                      vat_reg_no,
                      service_tax_regno,
                      tax_category_list, price_list_id,
                      customer_address_id,
                      last_updated_by, last_update_date,
                      created_by, creation_date
                     )
              VALUES (i.cust_account_id                          --customer_id
                                       ,
                      i.cust_acct_site_id                    --address_id
                                              ,
                      'Not Applicable'                            --cst_reg_no
                                      ,
                      'Not Applicable'                             --st_reg_no
                                      ,
                      'Not Applicable'                            --vat_reg_no
                                      ,
                      'Not Applicable'                     --SERVICE_TAX_REGNO
                                      ,
                      NULL                                 --tax_category_list
                          , NULL                               --price_list_id
                                ,
                      jai_cmn_cus_addresses_s.NEXTVAL    --customer_address_id
                                                     ,
                      1110                                   --last_updated_by
                          , SYSDATE                         --last_update_date
                                   ,
                      1110                                        --created_by
                          , SYSDATE                            --creation_date
                     );
           /* This Insert statement Enters Value without Customer address */
         INSERT INTO jai_cmn_cus_addresses
                     (customer_id, address_id,
                      cst_reg_no,
                      st_reg_no,
                      vat_reg_no,
                      service_tax_regno,
                      tax_category_list, price_list_id,
                      customer_address_id,
                      last_updated_by, last_update_date,
                      created_by, creation_date
                     )
              VALUES (i.cust_account_id                          --customer_id
                                       , 0                        --address_id
                                          ,
                      'Not Applicable'                            --cst_reg_no
                                      ,
                      'Not Applicable'                             --st_reg_no
                                      ,
                      'Not Applicable'                            --vat_reg_no
                                      ,
                      'Not Applicable'                     --SERVICE_TAX_REGNO
                                      ,
                      NULL                                 --tax_category_list
                          , NULL                               --price_list_id
                                ,
                      jai_cmn_cus_addresses_s.NEXTVAL    --customer_address_id
                                                     ,
                      1110                                   --last_updated_by
                          , SYSDATE                         --last_update_date
                                   ,
                      1110                                        --created_by
                          , SYSDATE                            --creation_date
                     );

         COMMIT;
      END;
   END LOOP;
END;
/

Query to find submitted Concurrent requests

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