Topic: Oracle Home

Create Customer Account, Site, Site Use using SOAP Webservice – Oracle Fusion 0

In the previous post, we have used REST API to create a Customer Organization that would create Party, Party Site, Party Site Usage and Location for an Organization. That post can be found here: http://oraclelabs.phaniadivi.com/2022/01/creating-a-party-or-organization-using-rest-api-oracle-fusion/

Note: An Organization / Party can be created using a REST API and a Customer account and Sites are created using SOAP Webservices.

In this Post, we will use a SOAP webservice to create Customer for an existing Party.

Of the Existing Party – Get the Party ID, Party Site ID from the BI Catalog by running the following queries:

select party_id from hz_parties where party_name = 'Oracle Learnings'; 

select party_site_id 
from hz_party_sites 
where party_id = (select party_id from hz_parties where party_name = 'Oracle Learning')

Using SOAP UI or other application run the following code:

WSDL: https://ehkm-test.fa.us6.oraclecloud.com/crmService/CustomerAccountService?WSDL

Payload:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/cdm/foundation/parties/customerAccountService/applicationModule/types/" xmlns:cus="http://xmlns.oracle.com/apps/cdm/foundation/parties/customerAccountService/" xmlns:cus1="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/custAccountContactRole/" xmlns:par="http://xmlns.oracle.com/apps/cdm/foundation/parties/partyService/" xmlns:sour="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/sourceSystemRef/" xmlns:cus2="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/custAccountContact/" xmlns:cus3="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/custAccountRel/" xmlns:cus4="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/custAccountSiteUse/" xmlns:cus5="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/custAccountSite/" xmlns:cus6="http://xmlns.oracle.com/apps/cdm/foundation/parties/flex/custAccount/">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:createCustomerAccount>
         <typ:customerAccount>
            <cus:PartyId>-- enter party id</cus:PartyId>
            <cus:AccountName>Customer Account Name</cus:AccountName>      
            <cus:AccountNumber>123456</cus:AccountNumber>
            <cus:CustomerType>R</cus:CustomerType>
            <cus:AccountEstablishedDate>2022-01-09</cus:AccountEstablishedDate>
            <cus:CreatedByModule>HZ_WS</cus:CreatedByModule>
            <cus:CustomerAccountSite>
               <cus:PartySiteId>-- enter party site id --</cus:PartySiteId>
               <cus:CreatedByModule>HZ_WS</cus:CreatedByModule>
               <cus:SetId>-- derive set id from configurations --</cus:SetId>
               <cus:StartDate>2022-01-09</cus:StartDate>
               <cus:CustomerAccountSiteUse>
                  <cus:SiteUseCode>BILL_TO</cus:SiteUseCode>
                  <cus:CreatedByModule>HZ_WS</cus:CreatedByModule>
               </cus:CustomerAccountSiteUse>
            </cus:CustomerAccountSite>
         </typ:customerAccount>
      </typ:createCustomerAccount>
   </soapenv:Body>
</soapenv:Envelope>

After the above code is run – check to see if the customer is created in the system or not using the following queries:

select * from hz_cust_accounts  -- get the account_number 

select * 
from hz_cust_acct_sites_all 
where cust_account_id = (select cust_account_id 
                           from hz_cust_accounts
                         where account_number = <account number>)

select * 
from hz_cust_site_uses_all
where CUST_ACCT_SITE_ID = (select CUST_ACCT_SITE_ID 
                           from hz_cust_acct_sites_all
                         where cust_account_id = (select cust_account_id 
                                                    from hz_cust_accounts
                                                     where account_number = <account number>))

Creating a Party or Organization using REST API – Oracle Fusion 0

In the next few posts, we will try to create the TCA hierarchy objects such as Organization, Party, Party Sites, Party Site Uses, Accounts, Account Sites, Contacts etc. using Webservice (and SOAP as a tool) .

Also, the FBDI process need to be used for large data imports like master conversion process and not for daily data integration with third party systems. For daily integrations, Webservices such as SOAP or REST need to be used.

After 20D release, Organizations will be created using REST API. Accounts, Sites, Site Usage, Profile will be created using SOAP Webservices.

In this post, we will see what is the data that is required to create a Party or Organization. Later we will run few queries to see the data created in Oracle Fusion.

Use POSTMAN or some other tool to run the following REST API.

Request URL: https://xxx-your-oracle.oraclecloud.com/crmRestApi/resources/11.13.18.05/hubOrganizations

Method: POST

Payload:

{
	   "PartyNumber":"9988770",
	   "SourceSystemReference":[
		  {
			 "SourceSystem":"FranSysCustom",
			 "SourceSystemReferenceValue":"9988770LCE"
		  }
	   ],
	   "OrganizationName":"Oracle Learnings",
	   "PartyUsageCode":"EXTERNAL_LEGAL_ENTITY",
	   "RawPhoneNumber":"9199199199",
	   "EmailAddress":"send_email@oracle.com",
	   "URL":"www.oracle.com",
	   "Address":[
		  {
			 "AddressType":"BILL_TO",
			 "Address1":"1234 Sample Address1",
			 "City":"Sample City",
			 "Country":"US",
			 "County":"Oakland",
			 "PostalCode":"94065",
			 "PostalPlus4Code":"",
			 "State":"NY"
		  }
	   ],
	   "CorpCurrencyCode":"USD",
	   "CurcyConvRateType":"Corporate",
	   "CurrencyCode":"USD",
	   "DUNSNumber":"123456789"
}

Upon running this, the response will have the Party ID and Party Site ID. You can use this Party ID to further create Accounts etc.

Queries:

select * from hz_parties where party_name = 'Oracle Learnings';
select * from hz_party_sites where party_id in (select party_id from hz_parties where party_name = 'Oracle Learnings');
select * 
from hz_party_site_uses 
where party_site_id in (select party_site_id 
                        from hz_party_sites 
                        where party_id in (select party_id from hz_parties where party_name = 'Oracle Learnings'))

select * 
from hz_locations 
where location_id in (select location_id from hz_party_sites where party_id in (select party_id from hz_parties where party_name = 'Oracle Learnings'))

And thus, your Organization / Party, Party Site, Party Site Use, Location is created with a single call to the REST API.

Update Receipt Method on AR Invoice 0

The following Webservice code can be used to Update Receipt Method on the AR Invoice. Some of the conditions that are required are that the Invoice need to be in Complete Status. The Complete button should be in enabled status. That is, if a receipt is applied on the invoice, then we cannot modify the Receipt Method on the Invoice.

Get the Customer Transaction ID for the Invoice using the following query:

select customer_trx_id from ra_customer_trx_all where trx_number = <ar_invoice_number>; 

WSDL used is: https://xxx-your-oracleserver.oraclecloud.com/fscmService/StandardReceiptService?WSDL

Code to update the Receipt Method is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/financials/receivables/transactions/invoices/invoiceService/types/" xmlns:inv="http://xmlns.oracle.com/apps/financials/receivables/transactions/invoices/invoiceService/" xmlns:typ1="http://xmlns.oracle.com/adf/svc/types/">
<soapenv:Header/>
<soapenv:Body>
   <typ:processUpdateCCToken>
      <typ:changeOperation>Create</typ:changeOperation>
      <!--Zero or more repetitions:-->
      <typ:updateCCToken>
      <inv:CustomerTrxId>9999938381</inv:CustomerTrxId>
      <inv:ReceiptMethod>New Receipt Method Name</inv:ReceiptMethod>
   </typ:updateCCToken>
      <typ:processControl>
         <typ1:partialFailureAllowed>true</typ1:partialFailureAllowed>
      </typ:processControl>
   </typ:processUpdateCCToken>
</soapenv:Body>
</soapenv:Envelope>

Script to create a Cash Receipt using Oracle API (AR) 0

The following post can be used to create a Cash receipt in Oracle Receivables. The “ar_receipt_api_pub.create_cash” SQL API is used to create cash receipts for the payment received in the form of a check or cash. Cash receipts can be created as identified (with a customer) or as unidentified (without a customer).

DECLARE
    l_return_status       VARCHAR2 (1);
    l_msg_count           NUMBER;
    l_msg_data            VARCHAR2 (240);
    p_count               NUMBER := 0;
    l_cash_receipt_id     ar_cash_receipts_all.cash_receipt_id%TYPE;
    l_user_name           fnd_user.user_name%TYPE := 'PADIVI';
    g_user_id             fnd_user.user_name%TYPE;
    l_resp_id             fnd_responsibility.responsibility_id%TYPE;
    l_appl_id             fnd_application.application_id%TYPE;
    l_ou_id               hr_operating_units.organization_id%TYPE;
    l_receipt_method_id   ar_receipt_methods.receipt_method_id%TYPE;
BEGIN
    -- Get User ID
    BEGIN
        SELECT user_id
          INTO g_user_id
          FROM fnd_user
         WHERE user_name = l_user_name;
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving User ID and error is: ' || SQLERRM);
    END;

    --Get Responsibility ID
    BEGIN
        SELECT RESPONSIBILITY_ID
          INTO l_resp_id
          FROM fnd_responsibility
         WHERE responsibility_key = 'RECEIVABLES_MANAGER'; --- enter the responsibility name that has access to create Invoices
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Responsibility ID and error is: '
                || SQLERRM);
    END;

    --Get Application ID
    BEGIN
        SELECT application_id
          INTO l_appl_id
          FROM fnd_application
         WHERE application_short_name = 'AR';
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving application ID and error is: '
                || SQLERRM);
    END;

    -- Get Organization ID for that Operating Unit
    BEGIN
        SELECT organization_id
          INTO l_ou_id
          FROM hr_operating_units
         WHERE name = 'p_ou_name';
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error while deriving Operating Unit ID and error is: '
                || SQLERRM);
    END;

    -- Get Receipt Method Id
    BEGIN
        SELECT RECEIPT_METHOD_ID
          INTO l_receipt_method_id
          FROM AR_RECEIPT_METHODS
         WHERE NAME = 'p_receipt_method'; -- Enter receipt method here.    
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error while deriving Operating Unit ID and error is: '
                || SQLERRM);
    END;

    mo_global.init ('AR');
    mo_global.set_policy_context ('S', l_ou_id);
    fnd_global.apps_initialize (user_id        => g_user_id,
                                resp_id        => l_resp_id,
                                resp_appl_id   => l_appl_id);

    ar_receipt_api_pub.create_cash (
        p_api_version         => 1.0,
        p_init_msg_list       => fnd_api.g_true,
        p_commit              => fnd_api.g_true,
        p_validation_level    => fnd_api.g_valid_level_full,
        x_return_status       => l_return_status,
        x_msg_count           => l_msg_count,
        x_msg_data            => l_msg_data,
        p_currency_code       => 'USD',
        p_amount              => 105,              -- Pass the Receipt Amount
        p_receipt_number      => 'Test Rcpt 101',  -- Pass the Receipt Number
        p_receipt_date        => SYSDATE,
        p_gl_date             => '30-NOV-2018',  
        p_customer_number     => 'p_customer_number',    -- Account number of the Customer against whom the Receipt is being created for. Hz_cust_accounts.account_number
        p_receipt_method_id   => l_receipt_method_id,
        p_cr_id               => l_cash_receipt_id);

    DBMS_OUTPUT.put_line (
           'API Return Status is - '
        || l_return_status
        || ' and l_msg_count is - '
        || l_msg_count);
    DBMS_OUTPUT.put_line ('Cash Receipt id is - ' || l_cash_receipt_id);


    IF l_msg_count = 1
    THEN
        DBMS_OUTPUT.put_line ('Error Message is - ' || l_msg_data);
    ELSIF l_msg_count > 1
    THEN
        LOOP
            p_count := p_count + 1;
            l_msg_data :=
                fnd_msg_pub.get (fnd_msg_pub.g_next, fnd_api.g_false);

            IF l_msg_data IS NULL
            THEN
                EXIT;
            END IF;

            DBMS_OUTPUT.put_line (
                'Message ' || p_count || '. ' || l_msg_data);
        END LOOP;
    END IF;
END;
/

Script to create a Receipt Write-off (AR) 0

The following post will detail the steps that are done to create a Receipt Write-Off on an AR Receipt. The PL/SQL API Ar_receipt_api_pub.activity_application is used to apply an adjustment on a Receipt – in this case – a Write-Off on a Receipt.

In this post – before doing a Write-Off on a Receipt – let us create a sample Receipt first. In order to create a Receipt – Navigate to the following: Receivables Superuser -> Receipts -> Receipts. Enter the following mandatory fields like – Receipt Method, Receipt Number, Receipt Amount, Customer details and click Save. Upon creating a Receipt – it shows up as below:

-- Script to create a Receipt Write-off
DECLARE
    CURSOR c_receipt_data
    IS
        SELECT cash_receipt_id, receipt_number, amount, org_id
          FROM ar_Cash_receipts_all
         WHERE receipt_number = '2220192'   -- Enter your receipt number here
           AND status = 'UNAPP';

    l_applied_payment_schedule_id    NUMBER;
    l_receivables_trx_id             NUMBER;
    
    x_return_status                  VARCHAR2 (200);
    x_msg_count                      NUMBER;
    x_msg_data                       VARCHAR2 (200);
    p_link_to_customer_trx_id        ra_customer_trx.customer_trx_id%TYPE;
    p_apply_date                     ar_receivable_applications.apply_date%TYPE;
    p_apply_gl_date                  ar_receivable_applications.gl_date%TYPE;
    p_ussgl_transaction_code         ar_receivable_applications.ussgl_transaction_code%TYPE;
    p_attribute_rec                  AR_RECEIPT_API_PUB.attribute_rec_type;
    p_global_attribute_rec           AR_RECEIPT_API_PUB.global_attribute_rec_type;
    p_comments                       ar_receivable_applications.comments%TYPE;
    p_application_ref_type           ar_receivable_applications.application_ref_type%TYPE;
    p_application_ref_id             ar_receivable_applications.application_ref_id%TYPE;
    p_application_ref_num            ar_receivable_applications.application_ref_num%TYPE;
    p_secondary_application_ref_id   ar_receivable_applications.secondary_application_ref_id%TYPE;
    p_payment_set_id                 ar_receivable_applications.payment_set_id%TYPE;
    p_receivable_application_id      ar_receivable_applications.receivable_application_id%TYPE;
    p_customer_reference             ar_receivable_applications.customer_reference%TYPE;
    p_val_writeoff_limits_flag       VARCHAR2 (200);
    p_called_from                    VARCHAR2 (200);
    p_netted_receipt_flag            VARCHAR2 (200);
    p_netted_cash_receipt_id         ar_cash_receipts.cash_receipt_id%TYPE;
    p_secondary_app_ref_type         ar_receivable_applications.secondary_application_ref_type%TYPE;
    p_secondary_app_ref_num          ar_receivable_applications.secondary_application_ref_num%TYPE;

BEGIN

    l_applied_payment_schedule_id := -3;

    SELECT RECEIVABLES_TRX_ID 
      INTO l_receivables_trx_id
      FROM ar_receivables_trx_all
     WHERE name = 'Receipt Write Off';

    FOR rec_recpt_data IN c_receipt_data
    LOOP 
    
    mo_global.init ('AR');
    mo_global.set_policy_context ('S', rec_recpt_data.org_id);
    
         AR_RECEIPT_API_PUB.Activity_application (
                                        p_api_version                    => 1.0,
                                        p_init_msg_list                  => FND_API.G_TRUE,
                                        p_commit                         => FND_API.G_TRUE,
                                        p_validation_level               => FND_API.G_VALID_LEVEL_FULL,
                                        x_return_status                  => x_return_status,
                                        x_msg_count                      => x_msg_count,
                                        x_msg_data                       => x_msg_data,
                                        p_cash_receipt_id                => rec_recpt_data.cash_receipt_id,
                                        p_receipt_number                 => rec_recpt_data.receipt_number,
                                        p_amount_applied                 => rec_recpt_data.amount,
                                        p_applied_payment_schedule_id    => l_applied_payment_schedule_id,
                                        p_link_to_customer_trx_id        => p_link_to_customer_trx_id,
                                        p_receivables_trx_id             => l_receivables_trx_id,
                                        p_apply_date                     => p_apply_date,
                                        p_apply_gl_date                  => p_apply_gl_date,
                                        p_ussgl_transaction_code         => p_ussgl_transaction_code,
                                        p_attribute_rec                  => p_attribute_rec,
                                        p_global_attribute_rec           => p_global_attribute_rec,
                                        p_comments                       => p_comments,
                                        p_application_ref_type           => p_application_ref_type,
                                        p_application_ref_id             => p_application_ref_id,
                                        p_application_ref_num            => p_application_ref_num,
                                        p_secondary_application_ref_id   => p_secondary_application_ref_id,
                                        p_payment_set_id                 => p_payment_set_id,
                                        p_receivable_application_id      => p_receivable_application_id,
                                        p_customer_reference             => p_customer_reference,
                                        p_val_writeoff_limits_flag       => p_val_writeoff_limits_flag,
                                        p_called_from                    => p_called_from,
                                        p_netted_receipt_flag            => p_netted_receipt_flag,
                                        p_netted_cash_receipt_id         => p_netted_cash_receipt_id,
                                        p_secondary_app_ref_type         => p_secondary_app_ref_type,
                                        p_secondary_app_ref_num          => p_secondary_app_ref_num);
        
        dbms_output.put_line ('Return status from API is: '||x_return_status);
        dbms_output.put_line ('Return= '||SUBSTR(x_msg_data,500));
        dbms_output.put_line ('Receivable Application ID is: '||p_receivable_application_id);    
    END LOOP; 

COMMIT; 

EXCEPTION
    WHEN OTHERS
    THEN
        DBMS_OUTPUT.put_line ('Error: ' || SQLERRM);
END;

And thus, happy Adjusting Write-offs.

Receipt Write-Off (AR) – Error Messages 0

There are a couple of steps to follow before doing any kind of Adjustment on AR Transactions.

  • In order to make any adjustments like a Receipt Write-Off – Approval Limits have to be defined for the user who is doing the Adjustment. If the Approval Limit is not set, then the Receivables window throws an error to set up the Approval Limit with the error Message: “APP-AR-96983: User Write-off limit does not exist.

In order to correct the above message, perform the following actions: Navigate to the following – Receivables Super User -> Setup -> Transactions -> Approval Limits. In the Approval Limits window – create a record. There exists one record with the combination of a User, Adjustment Type, Currency in the Approval Limits window. Enter a record for the user as below.

  • And there is a system profile option that needs to be setup before any adjustment is done on a receipt. Without setting that option first, the user may face the following error message – “APP-AR-96981: Please set the receipt write-off limits range system option.

In order to correct the above messages, perform the following actions: Navigate to Receivables Super User -> Setup -> System -> System Options -> Miscellaneous Tab. For the Write-off Limits Per Receipt – enter the values as required in the company. After entering the values – the screen looks like below.

These above two steps needs to be completed before creating an adjustment on an AR Receipt like a Receipt Write-Off.

Script to create a Debit Memo (AR) 0

The following script can be used to create a Basic Debit memo. The API that is used to create an AR Invoice is – “ar_invoice_api_pub.create_invoice“. The Cust_trx_type_id decides whether the invoice getting created is a Standard Invoice or a Credit Memo or a Debit memo. Based on this value, the API also checks the sign of the amount on the Line level that is being passed.

--Script to create Debit memo.
 
DECLARE
    l_index                  NUMBER := 0;
    l_line_index             NUMBER := 0;
    l_dist_index             NUMBER := 0;
    l_cm_customer_trx_id     NUMBER := 0;
    --
    l_batch_source_rec       ar_invoice_api_pub.batch_source_rec_type;
    l_trx_header_tbl         ar_invoice_api_pub.trx_header_tbl_type;
    l_trx_lines_tbl          ar_invoice_api_pub.trx_line_tbl_type;
    l_trx_line_id            NUMBER;
    l_return_status          VARCHAR2 (1);
    l_trx_dist_tbl           ar_invoice_api_pub.trx_dist_tbl_type;
    l_trx_salescredits_tbl   ar_invoice_api_pub.trx_salescredits_tbl_type;
    l_msg_data               VARCHAR2 (2000);
    l_resp_id                NUMBER;
    l_appl_id                NUMBER;
    l_user_name              VARCHAR2 (200);
    g_user_id                fnd_user.user_id%TYPE;
    l_line_number            NUMBER := 0;
    l_msg_count              NUMBER;
    l_ou_id                  hr_operating_units.organization_id%TYPE;
    l_batch_source_id        ra_batch_sources_all.batch_source_id%TYPE;
    l_cust_trx_type_id       ra_cust_trx_types_all.cust_trx_type_id%TYPE;
    l_cust_account_id        hz_cust_accounts.cust_account_id%TYPE;
    l_code_combination_id    gl_code_combinations_kfv.code_combination_id%TYPE; 
BEGIN
    DBMS_OUTPUT.put_line ('Start processing...');
 
    l_user_name := 'Phani Adivi'; --- enter your name here
 
    -- Get User ID
    BEGIN
        SELECT user_id
          INTO g_user_id
          FROM fnd_user
         WHERE user_name = l_user_name;
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving User ID and error is: ' || SQLERRM);
    END;
 
    --Get Responsibility ID
    BEGIN
        SELECT RESPONSIBILITY_ID
          INTO l_resp_id
          FROM fnd_responsibility
         WHERE responsibility_key = 'RECEIVABLES_MANAGER';    --- enter the responsibility name that has access to create Invoices
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Responsibility ID and error is: '
                || SQLERRM);
    END;
 
    --Get Application ID
    BEGIN
        SELECT application_id
          INTO l_appl_id
          FROM fnd_application
         WHERE application_short_name = 'AR';
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving application ID and error is: '
                || SQLERRM);
    END;
 
    -- Get Operating Unit ID
    BEGIN
        SELECT organization_id
          INTO l_ou_id
          FROM hr_operating_units
         WHERE name = 'enter OU Name';    --- enter the OU name in which this invoice is being created in
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving Operating Unit ID: ' || SQLERRM);
    END;
 
    --Get Batch Source ID
    BEGIN
        SELECT batch_source_id
          INTO l_batch_source_id
          FROM ra_batch_sources_all
         WHERE name = 'Source Name';   -- enter the Source name
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error while deriving Batch Source ID: ' || SQLERRM);
    END;
 
    -- Get Customer Trx Type ID
    BEGIN
        SELECT cust_trx_type_id
          INTO l_cust_trx_type_id
          FROM ra_cust_trx_types_all
         WHERE name = 'Debit Memo' 
           AND org_id = l_ou_id;
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Customer Transaction Type and error is: '
                || SQLERRM);
    END;
 
    -- Get Customer Account ID
    BEGIN
        SELECT cust_account_id
          INTO l_cust_account_id
          FROM hz_cust_accounts s
         WHERE account_name = 'Account Name';   -- enter the Account name of the Customer for which this invoice is being created for
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Customer Account ID and error is: '
                || SQLERRM);
    END;
    
    --Get Code Combination Id
    BEGIN
        SELECT code_combination_id
          INTO l_code_combination_id
          FROM gl_code_combinations_kfv
         WHERE concatenated_segments = 'concatenated_string';     -- get the concatenated segment information - this will be shown on the distributions screen
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving the code combination id: ' || SQLERRM);
    END; 
 
    mo_global.init ('AR');
    mo_global.set_policy_context ('S', l_ou_id);
    fnd_global.apps_initialize (user_id        => g_user_id,
                                resp_id        => l_resp_id,
                                resp_appl_id   => l_appl_id);
 
    -- Prepare Credit Memo;
    l_batch_source_rec.batch_source_id := l_batch_source_id;
    l_cm_customer_trx_id := ra_customer_trx_s.NEXTVAL;
    l_index := l_index + 1;
    --
    l_trx_header_tbl (l_index).org_id := l_ou_id;
    l_trx_header_tbl (l_index).trx_header_id := l_cm_customer_trx_id;
    --l_trx_header_tbl (l_index).trx_number := 2120191;               -- Enter the transaction number if the automatic numbering is not enabled
    l_trx_header_tbl (l_index).trx_date := SYSDATE; --TO_DATE('30-NOV-2018', 'DD-MON-RRRR');
    l_trx_header_tbl (l_index).gl_date :=  TO_DATE ('30-NOV-2018', 'DD-MON-RRRR');
    l_trx_header_tbl (l_index).trx_currency := 'USD';
    l_trx_header_tbl (l_index).cust_trx_type_id := l_cust_trx_type_id;
    l_trx_header_tbl (l_index).bill_to_customer_id := l_cust_account_id;
    l_trx_header_tbl (l_index).printing_option := 'NOT';
    l_trx_header_tbl (l_index).reference_number := 21220191;
 
    -- Prepare Credit Memo Lines
    l_trx_line_id := ra_customer_trx_lines_s.NEXTVAL;
    l_line_index := l_line_index + 1;
    l_line_number := l_line_number + 1;
    l_dist_index := l_dist_index + 1;
    --
    l_trx_lines_tbl (l_line_index).trx_header_id := l_cm_customer_trx_id;
    l_trx_lines_tbl (l_line_index).trx_line_id := l_trx_line_id;
    l_trx_lines_tbl (l_line_index).line_number := l_line_number;
    l_trx_lines_tbl (l_line_index).quantity_invoiced := 1;
    l_trx_lines_tbl (l_line_index).unit_selling_price := 12;
    l_trx_lines_tbl (l_line_index).line_type := 'LINE';
    l_trx_lines_tbl (l_line_index).taxable_flag := 'N';
 
    --
    l_trx_dist_tbl (l_dist_index).trx_dist_id   := RA_CUST_TRX_LINE_GL_DIST_S.NEXTVAL;
    l_trx_dist_tbl (l_dist_index).trx_line_id   := l_trx_line_id;
    l_trx_dist_tbl (l_dist_index).ACCOUNT_CLASS := 'REV';
    l_trx_dist_tbl (l_dist_index).percent := 100;
    l_trx_dist_tbl (l_dist_index).code_combination_id := l_code_combination_id;
 
    l_return_status := NULL;
    
    --Standard API call
    ar_invoice_api_pub.create_invoice (
        p_api_version            => 1.0,
        p_commit                 => fnd_api.g_false,
        p_batch_source_rec       => l_batch_source_rec,
        p_trx_header_tbl         => l_trx_header_tbl,
        p_trx_lines_tbl          => l_trx_lines_tbl,
        p_trx_dist_tbl           => l_trx_dist_tbl,
        p_trx_salescredits_tbl   => l_trx_salescredits_tbl,
        x_return_status          => l_return_status,
        x_msg_count              => l_msg_count,
        x_msg_data               => l_msg_data);
 
    DBMS_OUTPUT.put_line ('l_return_status is: ' || l_return_status);
 
    FOR cr_rec
        IN (SELECT trx_header_id,
                   trx_line_id,
                   error_message,
                   invalid_value
              FROM ar_trx_errors_gt)
    LOOP
        l_msg_data := NULL;
        l_msg_data :=
               'API Create CM/DM:'
            || cr_rec.trx_header_id
            || '-'
            || cr_rec.trx_line_id
            || '-'
            || cr_rec.error_message;
        DBMS_OUTPUT.put_line ('Message is: ' || l_msg_data);
    END LOOP;
 
    --
    COMMIT;
END;

Script to Create a Credit Memo (AR) 0

The following script can be used to create a Basic Credit memo. The API that is used to create an AR Invoice is – “ar_invoice_api_pub.create_invoice“. The Cust_trx_type_id decides whether the invoice getting created is a Standard Invoice or a Credit Memo or a Debit memo. Based on this value, the API also checks the sign of the amount on the Line level that is being passed.

--Script to create Credit memo.

DECLARE
    l_index                  NUMBER := 0;
    l_line_index             NUMBER := 0;
    l_dist_index             NUMBER := 0;
    l_cm_customer_trx_id     NUMBER := 0;
    --
    l_batch_source_rec       ar_invoice_api_pub.batch_source_rec_type;
    l_trx_header_tbl         ar_invoice_api_pub.trx_header_tbl_type;
    l_trx_lines_tbl          ar_invoice_api_pub.trx_line_tbl_type;
    l_trx_line_id            NUMBER;
    l_return_status          VARCHAR2 (1);
    l_trx_dist_tbl           ar_invoice_api_pub.trx_dist_tbl_type;
    l_trx_salescredits_tbl   ar_invoice_api_pub.trx_salescredits_tbl_type;
    l_msg_data               VARCHAR2 (2000);
    l_resp_id                NUMBER;
    l_appl_id                NUMBER;
    l_user_name              VARCHAR2 (200);
    g_user_id                fnd_user.user_id%TYPE;
    l_line_number            NUMBER := 0;
    l_msg_count              NUMBER;
    l_ou_id                  hr_operating_units.organization_id%TYPE;
    l_batch_source_id        ra_batch_sources_all.batch_source_id%TYPE;
    l_cust_trx_type_id       ra_cust_trx_types_all.cust_trx_type_id%TYPE;
    l_cust_account_id        hz_cust_accounts.cust_account_id%TYPE;
    l_code_combination_id    gl_code_combinations_kfv.code_combination_id%TYPE; 
BEGIN
    DBMS_OUTPUT.put_line ('Start processing...');

    l_user_name := 'Phani Adivi'; --- enter your name here

    -- Get User ID
    BEGIN
        SELECT user_id
          INTO g_user_id
          FROM fnd_user
         WHERE user_name = l_user_name;
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving User ID and error is: ' || SQLERRM);
    END;

    --Get Responsibility ID
    BEGIN
        SELECT RESPONSIBILITY_ID
          INTO l_resp_id
          FROM fnd_responsibility
         WHERE responsibility_key = 'RECEIVABLES_MANAGER';    --- enter the responsibility name that has access to create Invoices
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Responsibility ID and error is: '
                || SQLERRM);
    END;

    --Get Application ID
    BEGIN
        SELECT application_id
          INTO l_appl_id
          FROM fnd_application
         WHERE application_short_name = 'AR';
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving application ID and error is: '
                || SQLERRM);
    END;

    -- Get Operating Unit ID
    BEGIN
        SELECT organization_id
          INTO l_ou_id
          FROM hr_operating_units
         WHERE name = 'enter OU Name';    --- enter the OU name in which this invoice is being created in
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving Operating Unit ID: ' || SQLERRM);
    END;

    --Get Batch Source ID
    BEGIN
        SELECT batch_source_id
          INTO l_batch_source_id
          FROM ra_batch_sources_all
         WHERE name = 'Source Name';   -- enter the Source name
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error while deriving Batch Source ID: ' || SQLERRM);
    END;

    -- Get Customer Trx Type ID
    BEGIN
        SELECT cust_trx_type_id
          INTO l_cust_trx_type_id
          FROM ra_cust_trx_types_all
         WHERE name = 'Credit Memo' 
           AND org_id = l_ou_id;
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Customer Transaction Type and error is: '
                || SQLERRM);
    END;

    -- Get Customer Account ID
    BEGIN
        SELECT cust_account_id
          INTO l_cust_account_id
          FROM hz_cust_accounts s
         WHERE account_name = 'Account Name';   -- enter the Account name of the Customer for which this invoice is being created for
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                   'Error during deriving Customer Account ID and error is: '
                || SQLERRM);
    END;
    
    --Get Code Combination Id
    BEGIN
        SELECT code_combination_id
          INTO l_code_combination_id
          FROM gl_code_combinations_kfv
         WHERE concatenated_segments = 'concatenated_string';     -- get the concatenated segment information - this will be shown on the distributions screen
    EXCEPTION
        WHEN OTHERS
        THEN
            DBMS_OUTPUT.put_line (
                'Error during deriving the code combination id: ' || SQLERRM);
    END; 

    mo_global.init ('AR');
    mo_global.set_policy_context ('S', l_ou_id);
    fnd_global.apps_initialize (user_id        => g_user_id,
                                resp_id        => l_resp_id,
                                resp_appl_id   => l_appl_id);

    -- Prepare Credit Memo;
    l_batch_source_rec.batch_source_id := l_batch_source_id;
    l_cm_customer_trx_id := ra_customer_trx_s.NEXTVAL;
    l_index := l_index + 1;
    --
    l_trx_header_tbl (l_index).org_id := l_ou_id;
    l_trx_header_tbl (l_index).trx_header_id := l_cm_customer_trx_id;
    --l_trx_header_tbl (l_index).trx_number := 2120191;               -- Enter the transaction number if the automatic numbering is not enabled
    l_trx_header_tbl (l_index).trx_date := SYSDATE; --TO_DATE('30-NOV-2018', 'DD-MON-RRRR');
    l_trx_header_tbl (l_index).gl_date :=  TO_DATE ('30-NOV-2018', 'DD-MON-RRRR');
    l_trx_header_tbl (l_index).trx_currency := 'USD';
    l_trx_header_tbl (l_index).cust_trx_type_id := l_cust_trx_type_id;
    l_trx_header_tbl (l_index).bill_to_customer_id := l_cust_account_id;
    l_trx_header_tbl (l_index).printing_option := 'NOT';
    l_trx_header_tbl (l_index).reference_number := 21220191;

    -- Prepare Credit Memo Lines
    l_trx_line_id := ra_customer_trx_lines_s.NEXTVAL;
    l_line_index := l_line_index + 1;
    l_line_number := l_line_number + 1;
    l_dist_index := l_dist_index + 1;
    --
    l_trx_lines_tbl (l_line_index).trx_header_id := l_cm_customer_trx_id;
    l_trx_lines_tbl (l_line_index).trx_line_id := l_trx_line_id;
    l_trx_lines_tbl (l_line_index).line_number := l_line_number;
    l_trx_lines_tbl (l_line_index).quantity_invoiced := 1;
    l_trx_lines_tbl (l_line_index).unit_selling_price := -12;
    l_trx_lines_tbl (l_line_index).line_type := 'LINE';
    l_trx_lines_tbl (l_line_index).taxable_flag := 'N';

    --
    l_trx_dist_tbl (l_dist_index).trx_dist_id   := RA_CUST_TRX_LINE_GL_DIST_S.NEXTVAL;
    l_trx_dist_tbl (l_dist_index).trx_line_id   := l_trx_line_id;
    l_trx_dist_tbl (l_dist_index).ACCOUNT_CLASS := 'REV';
    l_trx_dist_tbl (l_dist_index).percent := 100;
    l_trx_dist_tbl (l_dist_index).code_combination_id := l_code_combination_id;

    l_return_status := NULL;
    
    --Standard API call
    ar_invoice_api_pub.create_invoice (
        p_api_version            => 1.0,
        p_commit                 => fnd_api.g_false,
        p_batch_source_rec       => l_batch_source_rec,
        p_trx_header_tbl         => l_trx_header_tbl,
        p_trx_lines_tbl          => l_trx_lines_tbl,
        p_trx_dist_tbl           => l_trx_dist_tbl,
        p_trx_salescredits_tbl   => l_trx_salescredits_tbl,
        x_return_status          => l_return_status,
        x_msg_count              => l_msg_count,
        x_msg_data               => l_msg_data);

    DBMS_OUTPUT.put_line ('l_return_status is: ' || l_return_status);

    FOR cr_rec
        IN (SELECT trx_header_id,
                   trx_line_id,
                   error_message,
                   invalid_value
              FROM ar_trx_errors_gt)
    LOOP
        l_msg_data := NULL;
        l_msg_data :=
               'API Create CM/DM:'
            || cr_rec.trx_header_id
            || '-'
            || cr_rec.trx_line_id
            || '-'
            || cr_rec.error_message;
        DBMS_OUTPUT.put_line ('Message is: ' || l_msg_data);
    END LOOP;

    --
    COMMIT;
END;

Query to derive the 4 C’s 0

The following query can be used to derive the details of the 4 C’s – that is: that have been setup for a particular Ledger.

  • Chart of Accounts
  • Currency
  • Calendar
  • Accounting Convention

SELECT gll.name                       "Legal Entity Name",
       gll.short_name                 "Short Code",
       gll.ledger_category_code       "Primary/Secondary Ledger",
       gll.chart_of_accounts_id,
       -- 4 C's details below
       fifs.id_flex_structure_name    "Chart of Accounts Name",
       gll.period_set_name            "Calendar",
       gll.currency_code              "Currency",
       gll.sla_accounting_method_code "Subledger Accounting"
  FROM gl_ledgers gll, fnd_id_flex_structures_tl fifs
 WHERE     gll.chart_of_accounts_id = fifs.id_flex_num
       AND fifs.id_flex_code = 'GL#'
       AND fifs.language = 'US'
       AND gll.name = p_legal_entity_name; -- Enter Legal Entity name here

Oracle Payables Query 0

Query to identify the various components that a Payables Invoice goes through a P2P process. Below query provides the details like Invoice, Supplier, Supplier Sites, Payment Method codes, terms, Distribution details, Payment schedules, Check details, Internal Bank Payment and Internal Bank details.

SELECT aia.invoice_num                 "Invoice Number",
       aps.vendor_name                 "Vendor Name" -- get vendor name from ap_suppliers table
                                                    ,
       assa.vendor_site_code           "Vendor Site Code",
       aia.invoice_id                  "Invoice ID",
       aia.invoice_currency_code       "Currency Code",
       aia.invoice_amount              "Invoice Amount",
       aia.amount_paid                 "Amount Paid",
       aia.invoice_type_lookup_code    "Invoice Type", -- values are derived from ap_lookup_codes and lookup_type = 'INVOICE TYPE'.
                                                       --STANDARD, CREDIT, DEBIT, EXPENSE REPORT, PREPAYMENT, MIXED, RETAINAGE RELEASE are other Invoice Types
       aia.description,
       aia.payment_method_lookup_code, -- values are derived from ap_lookup_codes table and lookup_type = 'PAYMENT METHOD'
                                       -- Check, Clearing, Electronic, Wire
       aia.terms_id                    "Terms ID", -- get terms name from ap_terms table
       aia.pay_group_lookup_code,                  -- values are derived from the fnd_lookup_values_vl and lookup_type = 'PAY GROUP'
       aia.org_id                      "Operating Unit ID", -- values are derived from hr_operating_units table - organization_id column
       aia.gl_date                     "GL Date",
       aia.wfapproval_status,
       ail.line_number                 "Line Number",
       ail.line_type_lookup_code       "Line Type", -- values are derived from ap_lookup_codes and lookup_type = 'INVOICE LINE TYPE'
                                                    -- Item, Freigh, Miscellaneous, Tax
       ail.amount                      "Line Amount",
       aid.dist_code_combination_id    "Distribution Code Comb ID", -- segment information can be derived from gl_code_combinations_kfv
       aid.accounting_event_id         "Invoice Accounting Event ID", -- will be used to link to SLA tables
       apsa.amount_remaining           "Remaining Invoice Amount",
       apsa.due_date                   "Due Date",
       aipa.accounting_event_id        "Payment Accounting Event ID",
       aca.amount                      "Check Amount",
       aca.check_number                "Check Number",
       aca.checkrun_name               "Payment Process Request",
       idpa.document_amount            "Payment Amount",
       idpa.pay_proc_trxn_type_code    "Payment Processing Document",
       idpa.calling_app_doc_ref_number "Invoice Number",
       ipa.paper_document_number       "Payment Number",
       ipa.payee_name                  "Paid to Name",
       ipa.payee_address1              "Paid to Address",
       ipa.payee_city                  "Paid to City",
       ipa.payee_postal_code           "Payee Postal Code",
       ipa.payee_state                 "Payee State",
       ipa.payee_country               "Payee Country",
       ipa.payment_profile_acct_name   "Payment Process Profile",
       ipa.int_bank_name               "Payee Bank Name",
       ipa.int_bank_number             "Payee Bank Number",
       ipa.int_bank_account_name       "Payee Bank Account Name",
       ipa.int_bank_account_number     "Payee Bank Account Number"
  FROM ap_invoices_all               aia,
       ap_invoice_lines_all          ail,
       ap_invoice_distributions_all  aid,
       ap_suppliers                  aps,
       ap_supplier_sites_all         assa,
       ap_payment_schedules_all      apsa,
       ap_invoice_payments_all       aipa,
       ap_checks_all                 aca,
       iby_docs_payable_all          idpa,
       iby_payments_all              ipa
 WHERE     1 = 1
       AND aia.invoice_id = ail.invoice_id
       AND aia.invoice_id = aid.invoice_id
       AND aia.vendor_id = aps.vendor_id
       AND aps.vendor_id = assa.vendor_id
       AND aia.invoice_id = apsa.invoice_id
       AND aia.invoice_id = aipa.invoice_id
       AND aipa.check_id = aca.check_id
       AND aia.invoice_id = idpa.calling_app_doc_unique_ref2
       AND idpa.calling_app_id = 200
       AND aps.party_id = idpa.payee_party_id
       AND ipa.payment_id = idpa.payment_id
       AND aps.segment1 = ipa.payee_supplier_number
       -- and assa.vendor_site_id = ipa.supplier_site_id
       AND assa.org_id = aia.org_id
       AND aca.vendor_site_id = assa.vendor_site_id
       AND invoice_num = p_invoice_num; -- Enter Invoice number here.