Tuesday, 16 May 2023

Invoice Interface Status code shows as "Not Eligible", though the Invoice Enabled item and Invoicable item properties are enabled. [Oracle APPS R12]

 Along with the item attributes (INVOICEABLE_ITEM_FLAG, INVOICE_ENABLED_FLAG), below conditions are also checked to determine whether an order line is eligible for Invoice Interface.

If any of the following conditions is true, the line is considered not eligible for Invoice Interface

  1. Invoice Enabled item property is set to NO or Invoicable Item property is set to NO.
  2. Line is part of an internal order.(source_document_type_id = 10)
  3. Line is a service line and the servicable_product_flag for parent is set to NO.
  4. Line is an Included Item.
  5. Referenced returns with CONFIG/INCLUDED item type code.
  6. If profile OM: Generate credit for rejected returns is No , with shipped qty and fulfilled qty 0 then its not eligible.


The possible values for the column OE_ORDER_LINES_ALL.INVOICE_INTERFACE_STATUS_CODE are

  1. YES
  2. NOT_ELIGIBLE
  3. NULL

When the sales order line is created with workflow such as "Shipping Only", the workflow does not include invoice interface activity. Hence the line will never come to invoice interface activity and is not invoice eligible. In this case, the INVOICE_INTERFACE_STATUS_CODE will never be set and it will be NULL value only.

INVOICE_INTERFACE_STATUS_CODE is set to NOT_ELIGIBLE if any of the following conditions are met

  1. The invoiceable item flag or invoice enabled flag for the item is set to 'No'. Order Management will first check for these item attributes in Ship From organization. If Ship From organization is null, then it checks in Item Validation organization and if still null then it checks in Item Master organization.
  2. Internal order lines are not invoiceable. Internal orders are the orders between two organizations in a company
  3. Included items are not  invoiceable. All mandatory items under a BOM are considered as included items. We can also check whether an item is included item or not from the item type field on order lines.
  4. Service items with non-serviceable parent are not invoiceable. This means that the serviceable product flag for the parent item is set to 'N'.  If not set, it defaults to 'Y'.
  5. Configuration items are not invoiceable

If the order line does not satisfy any of the 5 conditions mentioned above, then the line is invoice eligible and INVOICE_INTERFACE_STATUS_CODE is set to YES once the line is interfaced to Receivables.

Friday, 12 May 2023

API For Customer Limit Update

 /*Query to find Customer Credit Limit*/

SELECT Z.account_number CUSTOMER_NUMBER,
       Z1.party_name    CUSTOMER_NAME,
       X.credit_checking,
       --X.CUST_ACCOUNT_PROFILE_ID,
       -- Y.CUST_ACCT_PROFILE_AMT_ID,
       Y.overall_credit_limit
FROM   hz_customer_profiles X,
       hz_cust_profile_amts Y,
       hz_cust_accounts Z,
       hz_parties Z1
WHERE  X.cust_account_id = Y.cust_account_id(+)
       AND X.cust_account_id = Z.cust_account_id
       AND Z.party_id = Z1.party_id
       AND X.status = 'A'
       AND X.site_use_id IS NULL
       AND X.cust_account_profile_id = Y.cust_account_profile_id(+); 



/*API For Customer Limit Update in Apps R12*/

CREATE TABLE xx_cust_credit_limit_upld_temp
             (
                          account_number       VARCHAR2(30 byte),
                          party_name           VARCHAR2(360 byte),
                          overall_credit_limit NUMBER
             );

DECLARE
    p_customer_profile_rec_type
    hz_customer_profile_v2pub.customer_profile_rec_type;
    p_cust_account_profile_id NUMBER;
    p_object_version_number   NUMBER;
    x_return_status           VARCHAR2(2000);
    x_msg_count               NUMBER;
    x_msg_data                VARCHAR2(2000);
    l_user_id                 NUMBER;
    l_resp_id                 NUMBER;
    l_respid_id               NUMBER;
    in_out_version_no         NUMBER;
    in_out_version_no_hcpa    NUMBER;
    v_customer_profile_amt
    hz_customer_profile_v2pub.cust_profile_amt_rec_type;
    v_cust_act_prof_amt_id    NUMBER;
    v_cust_account_profile_id NUMBER;
    v_return_status           VARCHAR2(2000);
    v_msg_count               NUMBER;
    v_msg_data                VARCHAR2(2000);
    p_create_profile_amt      VARCHAR2(2000);
    v_msg_dummy               VARCHAR2(5000);
    t_output                  VARCHAR2(5000);
    mtrx                      NUMBER;
    moverall                  NUMBER;
BEGIN
    FOR i IN (SELECT hcp.cust_account_profile_id profile_id,
                     hca.cust_account_id,
                     hca.account_number          customer_number,
                     hp.party_name               customer_name,
                     xx.party_name,
                     hcp.credit_checking,
                     hcpa.overall_credit_limit,
                     hcpa.trx_credit_limit       order_credit_limit,
                     hcpa.cust_acct_profile_amt_id,
                     xx.overall_credit_limit     crdt_lmt2upld
              FROM   hz_customer_profiles hcp,
                     hz_cust_profile_amts hcpa,
                     hz_cust_accounts hca,
                     hz_parties hp,
                     xx_cust_credit_limit_upld_temp xx
              WHERE  hcp.cust_account_id = hcpa.cust_account_id (+)
                     AND hcp.cust_account_id = hca.cust_account_id
                     AND hca.party_id = hp.party_id
                     AND hcp.status = 'A'
                     AND hcp.site_use_id IS NULL
                     AND hcp.cust_account_profile_id hcpa.cust_account_profile_id (+)
                     AND hca.account_number = xx.account_number
                     --and hp.party_name = xx.PARTY_NAME
             ) LOOP
        p_customer_profile_rec_type.cust_account_profile_id := i.profile_id;

        dbms_output.Put_line('profile_id = ' || i.profile_id);
        mo_global.Init('AR');
        mo_global.Set_policy_context('S', '103');
        l_user_id := 2739;
        l_resp_id := 53313;
        l_respid_id := 660;
        fnd_global.Apps_initialize(l_user_id, l_resp_id, l_respid_id);

        --dbms_output.put_line('Credit Limit = '|| mtrx|| ' '|| moverall);
        dbms_output.Put_line('CUST_ACCT_PROFILE_AMT_ID = '|| i.cust_acct_profile_amt_id);

        v_customer_profile_amt.cust_account_profile_id := i.profile_id;

        v_customer_profile_amt.cust_acct_profile_amt_id :=
        i.cust_acct_profile_amt_id;

        v_customer_profile_amt.cust_account_id := i.cust_account_id;

        --v_customer_profile_amt.site_use_id := i.site_use_id;
        --v_customer_profile_amt.currency_code := 'BHD';
        --v_customer_profile_amt.trx_credit_limit := mtrx;
        v_customer_profile_amt.overall_credit_limit := i.crdt_lmt2upld;

        SELECT hcpa.object_version_number
        INTO   in_out_version_no_hcpa
        FROM   hz_customer_profiles hcp,
               hz_cust_profile_amts hcpa
        WHERE  hcp.cust_account_profile_id = i.profile_id
               AND hcp.cust_account_profile_id = hcpa.cust_account_profile_id;

        dbms_output.Put_line('Profile amt version = '|| in_out_version_no_hcpa);

        p_object_version_number := in_out_version_no_hcpa;

        hz_customer_profile_v2pub.Update_cust_profile_amt (
        p_init_msg_list => 'T',
        p_cust_profile_amt_rec => v_customer_profile_amt,
        p_object_version_number => p_object_version_number,
        x_return_status => x_return_status, x_msg_count => x_msg_count,
        x_msg_data => x_msg_data);

        dbms_output.Put_line('x_return_status = '
                             || Substr(x_return_status, 1, 255));

        dbms_output.Put_line('Object Version Number = '
                             || To_char(p_object_version_number));

        dbms_output.Put_line('Credit Rating = '
                             || p_customer_profile_rec_type.credit_rating);

        dbms_output.Put_line('x_msg_count = '
                             || To_char(x_msg_count));

        dbms_output.Put_line('x_msg_data = '
                             || Substr(x_msg_data, 1, 255));

        IF x_msg_count > 1 THEN
          FOR i IN 1..x_msg_count LOOP
              dbms_output.Put_line(i
                                   || '.'
                                   || Substr(fnd_msg_pub.Get(p_encoded =>
                                      fnd_api.g_false), 1,
                                      255));
          END LOOP;
        END IF;
    END LOOP;
EXCEPTION
    WHEN OTHERS THEN
      dbms_output.Put_line('Error: '
                           || SQLERRM);
END;