Friday, July 5, 2013

Oracle Receivables: Receipts API Overview, Setup, Sample Scripts and Troubleshooting




Purpose

Oracle provides several Application Program Interfaces (APIs) that enable users to create, apply, unapply and reverse receipts using PL/SQL code rather than 
manually entering them through the form or via Lockbox. 
There are public APIs to do the following:
  • Create a cash receipt or a miscellaneous receipt
  • Create a cash receipt and then apply it to a transaction
  • Create a cash receipt and then apply it to On-Account
  • Reverse a receipt
  • Apply and Unapply a receipt to:
    • a transaction
    • On-Account
    • an Activity (e.g. Refund)
    • Other Accounts (e.g. Claims)
    • a receipt
  • Apply a Receipt to a transaction at the line level
  • Update a Receipt from Unidentified to Unapplied
Detailed information describing each API and its input/output parameters is available in the Oracle Receivables Reference Guide.

This note provides an overview of the Receipt APIs, sample scripts for each of the available procedures and tips on troubleshooting the API.

Scope

This note provides sample scripts for a user with PL/SQL programming experience, to assist in developing their own code to use the following Receipt APIs:
  • CREATE_CASH
  • APPLY
  • CREATE_AND_APPLY
  • UNAPPLY
  • APPLY_ON_ACCOUNT
  • UNAPPLY_ON_ACCOUNT
  • REVERSE
  • ACTIVITY_APPLICATION
  • CREATE_MISC
  • APPLY_OTHER_ACCOUNT
  • APPLY_IN_DETAIL
  • UPDATE_RECEIPT_UNID_TO_UNAPP

Details

1. How do APIs work?

The Receipt APIs allow users to process receipts using simple calls to PL/SQL functions that mimic the creation and application of a receipt using the Receipts workbench user interface.

Receipt APIs are not intended to replace the existing Receipts workbench or Lockbox. It merely provides users with a programmatic option to create receipts. Some of the functions referenced by the Receipt APIs to create receipts are the same functions invoked from within the receipts workbench forms.

Prior to invoking an API, you need to initialize session variables that indicate the identity of who is creating the receipt. By doing this you are mimicking a user logging into the application and creating a receipt using the forms. To do this the function FND_GLOBAL.APPS_INITIALIZE is invoked. Further, if your custom code changes ORG_ID within the same session, you would also need to invoke ARP_STANDARD.INIT_STANDARD and ARP_GLOBAL.INIT_GLOBAL to reset the global variables associated with the ORG_ID.

2. Features of APIs

Flexibility
The receipt APIs adhere to Oracle API coding standards. For each input parameter, users may enter either an ID or its associated value. If both are provided the ID takes precedence over the value. This provides a wide degree of flexibility when using the API, both as a base table of the form and as a server-side routine call from the PL/SQL code.

The APIs use a defaulting mechanism for the input parameters to ensure that you will be able to achieve the basic business needs of creating a invoice by calling the API with a minimum number of parameters.

Modular Approach

The Receipt APIs are modular, the code is:
  • Easy understand
  • Easy to maintain
  • Easy to extend
  • Bulk enabled
Error Handling
The Receipt APIs provide extensive error-handling and error-reporting by storing all errors encountered during the Defaulting and Validation phases into a global temporary error table. The calling program can get all the error messages from the error table.

Robust Validation
The Receipt APIs perform robust validation, using the same logic employed by the receipts form.

Debug Messages
The Receipt APIs are also capable of harnessing the Oracle Applications Logging Framework to log
all debug messages in a central repository. These debug messages may be accessed from the FND_LOG_MESSAGES. General information on setting up and retrieving debug message are discussed in Note 433199.1, How to enable and retrieve FND debug log messages.

Integration with Oracle Payments
Since Oracle Receivables has Credit Card features, the APIs have built-in logic to interface with Oracle Payments for catpure and authorization of payments.

3. Alternatives to Receipt APIs

Aside from using Receipt APIs to create receipts, Oracle Receivables also supports the following:
  • Manually, using the Receipts Workbench
  • via Automatic Receipts
  • via Lockbox

4. Receipt API Programs

File NamePackage DefinedDescription
ARXPRECS.pls
ARXPRECB.pls
AR_RECEIPT_API_PUBThis is the main package definition for the Receipt API.
ARXPRELS.pls ARXPRELB.plsAR_RECEIPT_LIB_PVTPrivate library of utilities called by the Receipt API
ARXPREVS.pls ARXPREVB.plsAR_RECEIPT_VAL_PVTPrivate library of validation utilities
ARRERG2S.pls ARRERG2B.plsARP_PROC_RECEIPTS2Package for processing receipts
ARRICRS.pls
ARRICRB.pls
ARP_CASH_RECEIPTS_PKGPackage for processing receipts
ARXPREUS.pls ARXPREUB.pls
(Only available in R12)
AR_RECEIPT_UPDATE_API_PUBPackage to Update Receipt from Unidentified to Unapplied
ARCEAPPS.pls ARCEAPPB.plsARP_PROCESS_APPLICATIONPackage for Receipt Applications
ARREREVS.pls ARREREVB.plsARP_REVERSE_RECEIPTPackage for Receipt reversal
IBYPPADS.pls IBYPPADB.plsIBY_PAYMENT_ADAPTER_PUBOracle Payments packages
JGZZRCRS.pls JGZZRCRB.plsJG_AR_CASH_RECEIPTSGlobalization packages for the Receipts table
JGZZRRAS.pls JGZZRRAB.plsJG_AR_RECEIVABLE_APPLICATIONSGlobalization packages for the Applications table

5. Receipt API Procedures

The following lists the procedures that are publicly available from the Receipt API:
Procedure nameDescription
CREATE_CASHCreates a single cash receipt, as in the case of manually created cash receipts.
APPLYApplies a cash receipt to a particular installment of a debit item. The application can also be a cross currency application.
CREATE_AND_APPLYCreates a cash receipt and applies it to a specified installment of a debit item in one pass. Application will fail if the receipt cannot be created.

This API is a super-set of CREATE_CASH and APPLY. It provides more input parameters which allow the user to have more control over the type of receipt and application to create. For example, this API takes in a value for p_factor_discount_amount, whereas APPLY API above does not.
UNAPPLYUnapplies the application of a particular installment of a debit item against the specified cash receipt.
APPLY_ON_ACCOUNTCreates an on-account application for a cash receipt.
UNAPPLY_ON_ACCOUNTUnapplies the on-account application on the specified receipt.
REVERSEReverses the specified receipt.
ACTIVITY_APPLICATIONApplies to an activity, such as Receipt Write-off or Refund.
CREATE_MISCCreates a single miscellaneous receipt.
APPLY_OTHER_ACCOUNTApplies to other account activities, such as Claim Investigation (for Trade Management customers only).
UNAPPLY_OTHER_ACCOUNTUnapplies from other account activities, such as Claim Investigation.
APPLY_OPEN_RECEIPTCreates a receipt-to-receipt application (payment netting).
UNAPPLY_OPEN_RECEIPTUnapplies a receipt-to-receipt application.
CREATE_APPLY_ON_ACCCreates a cash receipt and an on-account application in one pass. Application will fail if the receipt cannot be created.
APPLY_IN_DETAILApply a receipt at invoice line level.
UPDATE_RECEITP_UNID_TO_UNAPPUpdate an receipt from Unidentified to Unapplied

6. Setup Requirements

Before using the Receipt API to process receipts, it is recommended that you have completed your setup such that you can create receipts manually using the Receipts form:

Responsibility: Receivables Manager
Navigation: Receipts > Receipts

When you enter data through the form, data validation takes place and you receive pop-up error messages alerting you of any issues. This makes it easier to sort out errors raised due to missing setup. After you successfully create a receipt using the form, you can use similar data to create a receipt using the API, thus minimizing the possibility of hitting setup errors that are a little bit more difficult to identify when using the API.

The following lists setup steps required to create a simple receipt using the receipt APIs.
  • Define Receipt Class and Methods
  • Define Receipt Sources
  • Define Receivable Activities
  • Define a Customer
  • Open Accounting Periods
All of these steps are discussed in detail in the Oracle Receivables User's Guide

7. Sample Code

The following scripts are provided to illustrate how to use/call the various procedures of the Receipt API.

   a. AR_RECEIPT_API_PUB.CREATE_CASH


Note:

Since this API creates only one receipt at a time, there is currently no functionality to pass in the Receipt Batch Source value.

Please see Enhancement Request Bug 3026454


This API creates a single cash receipt, as in the case of manually created cash receipts. Once created, the receipt will be in UNAPPLIED status.
You can save the sample script below in a file, for example rctapi1.sql

set serveroutput on size 1000000

DECLARE

   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;

BEGIN

    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(101190250559222,0);

    -- 2) Call the API
    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 => 1005.65,
      p_receipt_number => 'rct-api1',
      p_receipt_date => '22-JUL-2011',
      p_gl_date => '22-JUL-2011',
      p_customer_number => '1007',
      p_receipt_method_id => 1001,
      p_cr_id => l_cash_receipt_id );

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Cash Receipt id ' || l_cash_receipt_id );
    dbms_output.put_line('Message count ' || l_msg_count);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '||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;
/
The following explains the values in bold above. Please note that for illustration purposes the script uses actual values from the database. The values from your database may be different.

1) Set the Application Context
This area allows you to initialize the user, responsibility and operating unit associated with the user running the script. This simulates the initialization done when you log in to the application and pick a responsibility.
  • mo_global.set_policy_context('S','204');
    The value 204 indicates the Operating Unit or Org ID value
  • fnd_global.apps_initialize(1011902, 50559, 222,0);
    The parameters to this call are user_id, responsibility_id, application_id. To get the proper values use the following scripts:
    -- Get Responsibility Id

    Select responsibility_id,responsibility_name
    from fnd_responsibility_vl
    where application_id = 222
    and end_date IS NULL
    and responsibility_name LIKE '%&enter_search_string%';

    -- Get User Id
    Select user_id,user_name
    from fnd_user
    where user_name = '&user_name';
2) Call the API
  • p_currency_code => 'USD'
    Enter a currency code value, this value should exist in the follwing select statement:

    select currency_code from fnd_currencies;
  • p_amount => 1005.65
    Enter the amount of the receipt you want to create
  • p_receipt_number => 'rct-api1'
    Enter a unique value for your receipt number
  • p_receipt_date => '22-JUL-2011' and p_gl_date => '22-JUL-2011'
    Enter the Receipt Date and GL date respectively. Ensure that the GL date you enter is in an open period.
  • p_customer_number => 1007
    Enter the customer number associated to the Customer who paid the receipt, to get the correct value, you can run the following:

    select b.account_number
    from hz_parties a,
    hz_cust_accounts b
    where a.party_name = '&Customer_name'
    and a.party_id = b.party_id;

  • p_receipt_method_id => 1001
    Enter the receipt method you want to associate to the receipt, the value you enter should exist in the following select statement::

    select receipt_method_id from ar_receipt_methods;
3) Review the API Output: The API will generate debug/error messages to indicate issues that prevented it from creating the Receipt. The code in this section will expose the messages raised by the API.

During creation of the receipt, the following row is created in AR_RECEIVABLE_APPLICATIONS_ALL:

   b. AR_RECEIPT_API_PUB.APPLY

Note:

The following script provides an example of how to apply to a single invoice. If you want to apply a receipt to multiple invoice you can modify the script below and enclose it in a loop or call it multiple times to apply a receipt to many invoices.
This API applies an existing cash receipt to a particular installment of a debit item. The application can also be a cross currency application.
set serveroutput on size 1000000

DECLARE
   l_return_status varchar2(1);
   l_msg_count number;
   l_msg_data varchar2(240);
   p_count number :=0;

BEGIN

    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

    -- 2) Call the API
    AR_RECEIPT_API_PUB.APPLY
   ( 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,
     p_cash_receipt_id => 83989,
     p_customer_trx_id => 527928,
     x_return_status => l_return_status,
     x_msg_count => l_msg_count,
     x_msg_data => l_msg_data);

   -- 3) Review the API output
   dbms_output.put_line('Status ' || l_return_status);
   dbms_output.put_line('Message count ' || l_msg_count);

   if l_msg_count = 1 Then
      dbms_output.put_line('l_msg_data '|| 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;
/
Note that several parameters are similar to those provided in section a. above, please review the explanations there. The following explains the values of the other parameters in bold above. Please note that for illustration purposes the script uses actual values from the database. The values from your database may be different.
  • p_cash_receipt_id => 83989Provide the cash_receipt_id of the receipt you want to apply. In this example, we are using the CASH_RECEIPT_ID value for the receipt created by the previous API (CREATE_CASH). The value you enter here must exist in the select:
    select cash_receipt_id
    from ar_cash_receipts_all
    where org_id = &org_id;

  • p_customer_trx_id => 527928Provide the CUSTOMER_TRX_ID value of the transaction you want to apply the receipt to. This value must point to an existing transaction, and should exist in the following select, further it is typical that the transaction you apply to still has an open balance:

    select customer_trx_id
    from ra_customer_trx_all
    where org_id = &org_id;
During Receipt Application, 2 rows are created in the table AR_RECEIVABLE_APPLICATIONS_ALL:



Row 2 "deducts" the unapplied amount and Row 3 "adds" that amount to applied. Each activity made on a receipt will always create a pair of rows, to move amount from one status to another.

   c. AR_RECEIPT_API_PUB.CREATE_AND_APPLY

This API allows you to create a new cash receipt and apply it to a single transaction all in one API call. The effect is the same as calling the above 2 APIs: CREATE_CASH and APPLY.

Notes:

  1. This API is not capable of creating multiple applications, it will only create the receipt an apply it to a single transaction. If you need to apply the receipt to multiple transactions, you can use this API to create the receipt and apply to the first transaction, then you can call the AR_RECEIPT_API_PUB.APPLY API in a loop to apply to the other transactions.
  2. This API can be used to authorize and capture a credit card payment within a Receipt. You must pass the p_call_payment_processor parameter as fnd_api.g_true. Additionally, you must specify the p_customer_bank_account_id parameter.

    To have the AR_RECEIPT_API_PUB.Create_and_apply to not only authorize, but also to capture a credit card Receipt, the Receipt Class/Payment Method must allow the Receipt to be created in a status of 'Remitted' or 'Cleared'.


set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;

BEGIN
     -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);


    AR_RECEIPT_API_PUB.create_and_apply
   ( 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_amount => 2000.00,
     p_receipt_number => 'rct-api2',
     p_receipt_date => '22-JUL-2011',
     p_gl_date => '22-JUL-2011',
     p_customer_number => 1007,
     p_receipt_method_id => 1001,
     p_trx_number => '102317',
     p_cr_id => l_cash_receipt_id );

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);
    dbms_output.put_line('Cash Receipt ID ' || l_cash_receipt_id );

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

Note that several parameters are similar to those provided in section a. and section b. above, please review the explanations there. The following explains the values of the other parameters in bold above. Please note that for illustration purposes the script uses actual values from the database. The values from your database may be different.
  • p_trx_number => '102317',
    Provide the TRX_NUMBER of the transaction you want to apply the receipt to. This value must point to an existing transaction, and should exist in the following select, further it is typical that the transaction you apply to still has an open balance:

    select trx_number
    from ra_customer_trx_all
    where org_id = &org_id;

    Alternatively, you could also pass p_customer_trx_id instead, like we did in section b. above.

   d. AR_RECEIPT_API.PUB.UNAPPLY

This API allows you unapply a previous receipt application against a debit item. The amount you unapply goes back to the Unapplied balance of the receipt

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   p_count number := 0;
BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.UNAPPLY
   ( 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_cash_receipt_id => 83989,
     p_applied_payment_schedule_id => 182804,
     p_reversal_gl_date => '23-JUL-2011'
   );

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/
Note that several parameters are similar to those provided in section a. above, please review the explanations there. The following explains the values of the other parameters in bold above. Please note that for illustration purposes the script uses actual values from the database. The values from your database may be different.
  • p_applied_payment_schedule_id => 182804This value identifies the particular installment of the debit item to which you had originally applied the transaction. This value should exist in the select:

    select applied_payment_schedule_id
    from ar_receivable_applications_all
    where cash_receipt_id = &cr_id;

  • p_reversal_gl_date => '23-JUL-2011'Provide the GL date you want to associate to the Unapplication of the ReceiptTypically this date should come on or after the GL_DATE used when you applied the receipt to the transaction.
During Receipt Unapplication, ad additional 2 rows are created in the table AR_RECEIVABLE_APPLICATIONS_ALL:



Rows 4 and 5 "reverse" the effects of rows 2 and 3.

   e. AR_RECEIPT_API.PUB.APPLY_ON_ACCOUNT

This API creates an on-account application for a cash receipt.
set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;
BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.APPLY_ON_ACCOUNT
   ( 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_cash_receipt_id => 83992);

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

This API passes only one parameter, i.e. p_cash_receipt_id, this value should point to the CASH_RECEIPT_ID value for an existing Receipt for which you want to move an amount into On-Account.

During the application to on-account, Rows 2 and 3 shown below are created in AR_RECEIVABLE_APPLICATIONS_ALL:

   f. AR_RECEIPT_API.PUB.UNAPPLY_ON_ACCOUNT

This API unapplies the On-account application for a cash receipt.
set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;
BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.UNAPPLY_ON_ACCOUNT
   ( 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_cash_receipt_id => 83992,
     P_reversal_gl_date => '23-JUL-2011');

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

  • p_reversal_gl_date => '23-JUL-2011'
    Provide the GL date you want to associate to the Unapplication from On-Account. Typically, this date should come on or after the GL_DATE used when you applied the receipt to the transaction.

During the unapplication from on-account, Rows 4 and 5 shown below are created in AR_RECEIVABLE_APPLICATIONS_ALL, these rows "reverse" the effect of Rows 2 and 3:

   g. AR_RECEIPT_API.PUB.REVERSE


Note:

You can only reverse a receipt for the full amount. There is no functionality within the API (or the receipt workbench) to reverse only a partial amount of the receipt.
Reverses the specified receipt.
set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;
BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.reverse
   ( 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_cash_receipt_id => 83993,
     p_reversal_category_code => 'REV',
     p_reversal_reason_code => 'WRONG INVOICE');

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

  • p_cash_receipt_id => 83993
    Provide the cash_receipt_id of the receipt you want to reverse. The value you enter here must exist in the select:

    select cash_receipt_id
    from ar_cash_receipts_all
    where org_id = &org_id
    and status <> 'REV';

  • p_reversal_category_code => 'REV'
    Provide the reversal category code, the value you enter here must exist in the select:

    select lookup_code
    from fnd_lookup_values
    where lookup_type = 'REVERSAL_CATEGORY_TYPE';
  • p_reversal_reason_code => 'WRONG INVOICE'
    Provide the reversal reason code, the value you enter here must exist in the select:

    select lookup_code
    from fnd_lookup_values
    where lookup_type = 'CKAJST_REASON';

   h. AR_RECEIPT_API.PUB.ACTIVITY_APPLICATION

This API applies a receipt to an activity, such as Receipt Write-off.
set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;
   l_application_ref_type ar_receivable_applications.application_ref_type%TYPE;
   l_application_ref_id ar_receivable_applications.application_ref_id%TYPE;
   l_application_ref_num ar_receivable_applications.application_ref_num%TYPE;
   l_secondary_application_ref_id ar_receivable_applications.secondary_application_ref_id%TYPE;
   l_receivable_application_id ar_receivable_applications.receivable_application_id%TYPE;

BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   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 => l_return_status,
     x_msg_count => l_msg_count,
     x_msg_data => l_msg_data,
     p_cash_receipt_id => 83994,
     p_applied_payment_schedule_id => -3,
     p_receivables_trx_id => 2536,
     p_receivable_application_id => l_receivable_application_id
     p_application_ref_type => l_application_ref_type,
     p_application_ref_id => l_application_ref_id,
     p_application_ref_num => l_application_ref_num,
     p_secondary_application_ref_id => l_secondary_application_ref_id);

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);
    dbms_output.put_line('Application ID ' || l_receivable_application_id;

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

The following explains the values of the parameters in bold above. Please note that for illustration purposes the script uses actual values from the database. The values from your database may be different.
  • p_cash_receipt_id => 83994
    Provide the cash_receipt_id of an existing receipt you want to apply to a Receivable activity. The value you enter here must exist in the select:

    select cash_receipt_id
    from ar_cash_receipts_all
    where org_id = &org_id
    and status <> 'REV';
  • p_applied_payment_schedule_id => -3
    Enter the Payment schedule Id associated to the Receivable Activity you are trying to apply to. The value you enter here should exist in AR_PAYMENT_SCHEDULES_ALL, currently valid values are the following:

    Payment_Schedule_IdTransaction Number
    -2Short Term Debt
    -3Receipt Write-off
    -4Claim Investigation
    -5Chargeback
    -6Credit Card Refund
    -7Prepayment
    -8Refund
    -9Credit Card Chargeback
  • p_receivables_trx_id => 2536
    Enter the associated Receivables Activity ID. The activity type of the ID you specify should by synchronized with the applied payment schedule Id passed. In this example, we used p_applied_payment_schedule_id = -3 (Receipt Write-off), the Receivables Activity you pick should then have a type = WRITEOFF. For this example, valid values should be in the select:

    select name, receivables_trx_id
    from ar_receivables_trx_all
    where org_id = &ORG_ID
    and type = 'WRITEOFF';

    Following lists valid Receivable Activity Types:
    • SHORT_TERM_DEBT
    • WRITEOFF
    • CLAIM_INVESTIGATION
    • ADJUST
    • CCREFUND
    • PREPAYMENT
    • CM_REFUND
    • CC_CHARGEBACK

    Note: If the applied_payment_schedule_id does not match the type of the receivables_trx_id the API will raise an error.
During the Application to Activity, Rows 2 and 3 shown below are created in AR_RECEIVABLE_APPLICATIONS_ALL:



Note:

If you are using ACTIVITY_APPLICATION to create a Credit Card Refund, the code will automatically create the negative miscellaneous receipt for you.

   i. AR_RECEIPT_API.PUB.CREATE_MISC

Creates a single miscellaneous receipt.

set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;
   l_receipt_number varchar(10);

BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   l_receipt_number := 'misc-api1';

   AR_RECEIPT_API_PUB.CREATE_MISC
   ( 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_amount => 4560.00,
     p_receipt_date => '22-JUL-2011',
     p_gl_date => '22-JUL-2011',
     p_receipt_method_id => 1001,
     p_activity => 'Interest Income',
     p_misc_receipt_id => l_cash_receipt_id ,
     p_receipt_number => l_receipt_number);

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);
    dbms_output.put_line('Cash Receipt ID ' || l_cash_receipt_id );

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/
Note that several parameters are similar to those provided in section a. above, please review the explanations there. The following explains the values of the other parameters in bold above. Please note that for illustration purposes the script uses actual values from the database. The values from your database may be different.
  • p_activity => 'Interest Income'
    Provide the value for the Receivable activity name for which you are creating a Miscellaneous cash receipt. Valid values are returned by the select:

    select name, receivables_trx_id
    from ar_receivables_trx_all
    where org_id = &ORG_ID
    and type = 'MISCCASH';
Note:

The accounting used by the Miscellaneous Receipt is picked up from the Receivable Activity definition.

If you need the accounting to hit multiple GL accounts, you need to define a distribution set (Navigation: Setup > Receipts > Distribution Set) and then associate this distribution set to your Receivable Activity.

Otherwise, accounting is based on the Activity GL account you provide.

   j. AR_RECEIPT_API.PUB.APPLY_OTHER_ACCOUNT

This API applies to other account activities, such as Claim Investigation. This API is similar in function to ACTIVITY_APPLICATION.

set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   p_count NUMBER;
   x_receivable_application_id NUMBER;
   x_application_ref_id NUMBER;
   x_application_ref_num VARCHAR2(30);
   x_secondary_application_ref_id NUMBER;

BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   -- 2) Call the API
   AR_RECEIPT_API_PUB.apply_other_account
   ( 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_receivable_application_id => x_receivable_application_id,
     p_cash_receipt_id => 83997,
     p_receivables_trx_id => 1747,
     p_applied_payment_schedule_id => -4,
     p_amount_applied => 500.00,
     p_application_ref_id => x_application_ref_id,
     p_application_ref_num => x_application_ref_num,
     p_secondary_application_ref_id => x_secondary_application_ref_id,
     p_called_from => null);

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);
    dbms_output.put_line('Receivable Application Id ' || x_receivable_application_id);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/
Note that several parameters are similar to those provided in section h above, please review the explanations there.

In this example, we are creating an activity against Claim Investigation, hence the applied_payment_schedule = -4. It is therefore necessary to use a Receivable Activity whose type is CLAIM_INVESTIGATION.
  • p_applied_payment_schedule_id => -4
    Enter the Payment schedule Id associated to the Receivable Activity you are trying to apply to. The value you enter here should exist in AR_PAYMENT_SCHEDULES_ALL, see the list above in section h.
  • p_receivables_trx_id => 1747
    Enter the associated Receivables Activity ID. The activity type of the ID you specify should by synchronized with the applied payment schedule Id passed. In this example, we used p_applied_payment_schedule_id = -4 (Claim Investigation), the Receivables Activity you pick should then have a type = CLAIM_INVESTIGATION. For this example, valid values should be in the select:

    select name, receivables_trx_id
    from ar_receivables_trx_all
    where org_id = &ORG_ID
    and type = 'CLAIM_INVESTIGATION';

   k. AR_RECEIPT_API.PUB.UNAPPLY_OTHER_ACCOUNT

set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   p_count number := 0;

BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.UNAPPLY_OTHER_ACCOUNT
   ( 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_cash_receipt_id => 83997,
     p_reversal_gl_date => '26-SEP-2011',
     p_receivable_application_id => 285776,
     
p_cancel_claim_flag => 'Y',
     p_called_from => NULL);


    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/
  • p_cash_receipt_id => 83997Provide the CASH_RECEIPT_ID value of an existing receipt that has applications to OTHER_ACC
  • p_reversal_gl_date => '26-SEP-2011'
    Provide the GL date you want to use for the Unapplication from the Activity, this should be on or after the GL_DATE of the row you want to Unapply.
  • p_receivable_application_id => 285776Provide the AR_RECEIVABLE_APPLICATIONS_ALL.RECEIVABLE_APPLICATION_ID that you want to Unapply.

  • p_cancel_claim_flag => NULL
    Currently note used, leave as NULL
  • p_called_from => NULLIndicates from where the API is called, leave as NULL.

   l. AR_RECEIPT_API.PUB.APPLY_OPEN_RECEIPT

This API creates a receipt to receipt application.
set serveroutput on size 1000000

DECLARE
    l_return_status VARCHAR2(1);
    l_msg_count NUMBER;
    l_msg_data VARCHAR2(240);
    p_count number := 0;
    l_application_ref_num VARCHAR2(30);
    l_receivable_application_id NUMBER;
    l_applied_rec_app_id NUMBER;
    l_acctd_amount_applied_from NUMBER;
    l_acctd_amount_applied_to VARCHAR2(30);
BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.APPLY_OPEN_RECEIPT
   ( 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_amount_applied => -20.00,
     p_receipt_number => 'rct-api11',
     p_open_receipt_number => 'rct-api10',
     x_application_ref_num => l_application_ref_num,
     x_receivable_application_id => l_receivable_application_id,
     x_applied_rec_app_id => l_applied_rec_app_id,
     x_acctd_amount_applied_from => l_acctd_amount_applied_from,
     x_acctd_amount_applied_to => l_acctd_amount_applied_to);


    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);
    dbms_output.put_line('Receivable Application Id ' || l_receivable_application_id);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

The values passed into the API have the effect of moving $20.00 from the balance of rct-api10 into the balance of rct-api11.
  • p_amount_applied => -20.00
    Provide the value you want to transfer from p_open_receipt_number into p_receipt_number.
  • p_receipt_number => 'rct-api11'
    Provide the receipt number of the receipt receiving the amount.
  • p_open_receipt_number => 'rct-api10'
    Provide the receipt number of the receipt giving the amount.
In the above example, rct-api10 originally had 100.00 and rct-api11 originally had 20.00, after running the above the results are:

Receipt rct-api10 is the "giver":


Receipt rct-api11 is the "receiver":

   m. AR_RECEIPT_API.PUB.CREATE_APPLY_ON_ACC

This API creates the receipt and applies it to On-Account
set serveroutput on size 1000000

DECLARE
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   l_cash_receipt_id NUMBER;
   p_count number := 0;

BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   AR_RECEIPT_API_PUB.CREATE_APPLY_ON_ACC
   ( 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_amount => 555.00,
     p_receipt_number => 'rct-api12',
     p_receipt_date => '22-JUL-2011',
     p_gl_date => '22-JUL-2011',
     p_customer_number => 1007,
     p_receipt_method_id => 1001,
     p_cr_id => l_cash_receipt_id );

    -- 3) Review the API output
    dbms_output.put_line('Status ' || l_return_status);
    dbms_output.put_line('Message count ' || l_msg_count);
    dbms_output.put_line('Cash Receipt Id ' || l_cash_receipt_id);

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/

Note the parameters are similar to those provided in section a. above, please review the explanations there.

   n. AR_RECEIPT_API_PUB.APPLY_IN_DETAIL

This API does a line level receipt application against a specified transaction. In the example below, the API will apply to the lines of the specified Invoice. This invoice has 2 lines:

line 1: 5.000.00    tax:  424.53
line 2: 7,000.00    tax:  594.34
line 3: 9,000.00    tax:  764.15
set serveroutput on size 1000000

DECLARE
   cursor c1 is
   select line.customer_trx_line_id,
          line.line_number,
          line.extended_amount line_amount,
          tax.extended_amount tax_amount
   from ra_customer_trx_lines line,
       (select link_to_cust_trx_line_id,
        sum(nvl(extended_amount,0)) extended_amount
        from ra_customer_trx_lines
        where customer_trx_id = 528349
        and line_type = 'TAX'
        group by link_to_cust_trx_line_id) tax
   where line.customer_trx_id = 528349
   and line.line_type = 'LINE'
   and line.customer_trx_line_id = tax.LINK_TO_CUST_TRX_LINE_ID(+);

   l_llca_trx_lines_tbl ar_receipt_api_pub.llca_trx_lines_tbl_type;
   l_return_status VARCHAR2(1);
   l_msg_count NUMBER;
   l_msg_data VARCHAR2(240);
   p_count NUMBER := 0;
   l_cnt NUMBER := 0;


BEGIN
    -- 1) Set the applications context
    mo_global.init('AR');
    mo_global.set_policy_context('S','204');
    fnd_global.apps_initialize(1011902, 50559, 222,0);

   -- 2)  define the amounts to apply, for illustration purposes we will apply 10% of the original amounts
   for i in c1 loop
      l_cnt := l_cnt + 1;

      l_llca_trx_lines_tbl(l_cnt).customer_trx_line_id := i.customer_trx_line_id ;
      l_llca_trx_lines_tbl(l_cnt).line_amount := i.line_amount * .10;
      l_llca_trx_lines_tbl(l_cnt).amount_applied := i.line_amount * .10;
      l_llca_trx_lines_tbl(l_cnt).tax_amount := i.tax_amount *.10;
   end loop;

   AR_RECEIPT_API_PUB.APPLY_IN_DETAIL
   ( 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_cash_receipt_id => 84003,
     p_customer_trx_id => 528349,
     p_llca_type => 'L',
     p_org_id => 204,
     
p_llca_trx_lines_tbl => l_llca_trx_lines_tbl );
   

    if l_msg_count = 1 Then
       dbms_output.put_line('l_msg_data '|| 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;
/
  • p_cash_receipt_id => 84003
    Provide the CASH_RECEIPT_ID of the receipt you are going to apply at the line level to a particular transaction
  • p_customer_trx_id => 528349
    Provide the CUSTOMER_TRX_ID of the transaction you want to apply to
  • p_llca_type => 'L'
    This indicates you want to do a Line-Level Receipt Application
  • p_org_id => 204
    Provide the ORG_ID value associated to the Receipt and Transaction
After running the above API, a review of the Transaction shows that a 10% application was done against the Line and Tax amounts.

   o. AR_RECEIPT_UPDATE_API_PUB.UPDATE_RECEIPT_UNID_TO_UNAPP

This API updates an existing Receipt and changes its status from Unidentified to Unapplied. This API is only available in Release 12.
DECLARE
   p_api_version                 NUMBER;
   p_init_msg_list               VARCHAR2 (200);
   p_commit                      VARCHAR2 (200);
   p_validation_level            NUMBER;
   x_return_status               VARCHAR2 (200);
   x_msg_count                   NUMBER;
   x_msg_data                    VARCHAR2 (200);
   p_cash_receipt_id             NUMBER;
   p_pay_from_customer           NUMBER;
   p_comments                    VARCHAR2 (200);
   p_payment_trxn_extension_id   NUMBER;
   x_status                      VARCHAR2 (200);
   p_customer_bank_account_id    NUMBER;
   p_count                       NUMBER;
BEGIN
   p_api_version        := 1.0;
   p_init_msg_list      := fnd_api.g_true;
   p_commit             := fnd_api.g_false;
   p_validation_level   := fnd_api.g_valid_level_full;
   p_cash_receipt_id    := 12345;
   p_pay_from_customer  := 67890;
   p_comments           := 'TEST RECEIPT_API';
   
   AR_RECEIPT_UPDATE_API_PUB.UPDATE_RECEIPT_UNID_TO_UNAPP
          (p_api_version                    => p_api_version,
           p_init_msg_list                  => p_init_msg_list,
           p_commit                         => p_commit,
           p_validation_level               => p_validation_level,
           x_return_status                  => x_return_status,
           x_msg_count                      => x_msg_count,
           x_msg_data                       => x_msg_data,
           p_cash_receipt_id                => p_cash_receipt_id,
           p_pay_from_customer              => p_pay_from_customer,
           p_comments                       => p_comments,
           p_payment_trxn_extension_id      => p_payment_trxn_extension_id,
           x_status                         => x_status,
           p_customer_bank_account_id       => p_customer_bank_account_id
          );
   DBMS_OUTPUT.put_line ('X_RETURN_STATUS = ' || x_return_status);
   DBMS_OUTPUT.put_line ('X_MSG_COUNT = ' || x_msg_count);
   DBMS_OUTPUT.put_line ('X_MSG_DATA = ' || x_msg_data);
   DBMS_OUTPUT.put_line ('X_STATUS = ' || x_status);
   IF x_msg_count = 1
   THEN
      DBMS_OUTPUT.put_line ('l_msg_data ' || x_msg_data);
   ELSIF x_msg_count > 1
   THEN
      LOOP
         p_count := p_count + 1;
         x_msg_data := fnd_msg_pub.get (fnd_msg_pub.g_next, fnd_api.g_false);
         IF x_msg_data IS NULL
         THEN
            EXIT;
         END IF;
         DBMS_OUTPUT.put_line ('Message' || p_count || ' ---' || x_msg_data);
      END LOOP;
   END IF;
END;
  • p_cash_receipt_id    =>  12345
    Provide the CASH_RECEIPT_ID of the Unidentified receipt you are updating.
  • p_pay_from_customer  => 67890
    Provide the Customer ID of the customer to whom you want to associate this Unapplied receipt.
  • p_comments => 'TEST RECEIPT_API'Provide an optional comment/description.

7. Running APIs


After you have coded the API, you can invoke the script in sqlplus. For example, the script above for CREATE_CASH was saved into a file called rctapi1.sql, to execute this script you can do the following in sqlplus:

@rctapi1.sqlFollowing is the sample output for a successful run, Status = S:

Status S
Cash Receipt id 83989
Message count 0
Message =


The API above has create the receipt with CASH_RECEIPT_ID = 83988.

Following is the sample output for a run with errors, Status = E:

Status E
Cash Receipt id
Message count 2
Message 1. GL date, 22-SEP-11, is not in an open or future-enterable period.
Message 2. A cash receipt with this number, date, amount and customer already exists.


You would need to address the errors individually and then re-try the script to successfully create the receipt.
Note: The scripts provided above issue a COMMIT; after running due to the setting of the parameter:

p_commit => FND_API.G_TRUE,

If you prefer to issue a commit manually, you should change the value passed to: FND_API.G_FALSE, then you need to ensure you issue a COMMIT, otherwise the changes created by the API will not be saved to the database.

8. Reviewing the Receipt Created by the API

After executing the API and saving your work using the COMMIT; statement, you can query the receipt via the Receipts Workbench

Responsibility: Receivables Manager
Navigation: Receipts > Receipts

Run a query on the Receipt Number = rct-api1

Note: Since rct-api1 was created using the CREATE_CASH, this API simply takes care of creating the receipt, there won't be any applications of the receipt.



After running the APPLY API script above, which takes care of applying this same receipt to an invoice, the applications form will now show the application to an invoice:


9. Calling the Receipt APIs from a Concurrent Program

If you have a requirement to incorporate calling the Receipt API from within the Oracle Receivables application, you can create code that you can call as a concurrent Program. For more information on how to do this, please reviewNote 785369.1, How to Register a Receivables Application Programming Interface (API) as a Concurrent Request.
Note:

When submitting the Receipt API via a concurrent process, take care that you are not attempting to process similar data, such as applying 2 receipts in 2 separate concurrent processes against the same invoice. Such scenarios would cause contention/locking issues. If you need to run receipt API processes in parallel, it is suggested that you submit data such that there is no possibility of locking. for example: submit per customer, or per operating unit.


10. Troubleshooting & Tips

When encountering issues getting the API, you can better identify the issue by simplifying your API wrapper code:
  • If you are inserting multiple transactions, try inserting one transaction at a time an see if that works.
  • If you are generating system derived values for transaction number or batch number or some other field in the parameter list of the API, try passing constant values instead. This would eliminate errors caused by additional logic to generate values.
  • Enter a manual transaction via the form with the same constants used above to see if it is successful.
Once you have successfully generated a manual transaction, try to create a transaction using similar values through the API. Once you have the wrapper successfully creating a simple transaction, you can then expand on it.

For additional information on how to debug and trace an API, please review Note 784317.1, How to Troubleshoot Receivables API Issues

4 comments:





  1. Free custom receipt maker


    ExpensesReceipt is the best free custom receipt makers that make a free fake receipt, choose the simple receipt template and itemized receipt template to make a free custom receipt maker. Make best fake receipt generator online.


    https://expensesreceipt.com/

    ReplyDelete
  2. making receipts online - ExpensesReceipt is the best free custom receipt makers that make a free fake receipt, choose the simple receipt template and itemized receipt template to make a free custom receipt maker. Make best fake receipt generator online.

    ReplyDelete
  3. Very Nice Post. I am very happy to see this post. Such a wonderful information to share with us. I would like to share with my friends. For more information visit here Receipt Maker

    ReplyDelete
  4. Oracle Receivables Receipts API empowers seamless integration and management of financial transactions. Is Bad Games Developers leverage this interface to automate receipt creation, enhancing efficiency in accounts receivable processes.

    ReplyDelete