24 August, 2022

API to apply Credit Memo to refund activity

    The following sample code will use the existing credit memo, and will create a credit memo application to issue a refund using AR_CM_APPLICATION_PUB.ACTIVITY_APPLICATION.

--  Turn on DBMS_OUTPUT to display messages on screen
set serveroutput on size 1000000
--  Declaration section
DECLARE
   l_dummy varchar2(240);
   l_customer_trx_id ra_customer_trx.customer_trx_id%type;
   l_msg_count number := 0;
   l_msg_data varchar2(20000) := null;
   l_return_status varchar2(1);
   l_application_ref_type varchar2(30);
   l_application_ref_id number;
   l_application_ref_num VARCHAR2(30);
   l_receivable_application_id NUMBER;



BEGIN
   --  Set the applications and organization context
   fnd_global.apps_initialize(1318,50559,222,0);
   mo_global.init('AR');
   mo_global.set_policy_context('S',204);
   --  provide CUSTOMER_TRX_ID of the credit memo
   l_customer_trx_id := 527710;
   --  call ACTIVITY_APPLICATION
   AR_CM_APPLICATION_PUB.ACTIVITY_APPLICATION(
     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_customer_trx_id => l_customer_trx_id,
     p_amount_applied => 200,
     p_applied_payment_schedule_id => -8,
     p_receivables_trx_id => 2579,
     p_apply_date => to_date('04/20/2011','MM/DD/YYYY'),
     p_apply_gl_date => to_date('04/20/2011','MM/DD/YYYY'),
     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_receivable_application_id => l_application_ref_id,
     X_RETURN_STATUS => l_return_status,
     X_MSG_COUNT => l_msg_count,
     X_MSG_DATA => l_msg_data);
   --  return information about the status of the API run
   FND_MSG_PUB.count_and_get (
   p_encoded => FND_API.g_false,
   p_count => l_msg_count,
   p_data => l_msg_data );
   dbms_output.put_line('Return Status ==> '||l_return_status);
   dbms_output.put_line('l_msg_count ==> '||l_msg_count);

   -- display messages from the message stack
   FOR I IN 1..L_MSG_COUNT LOOP
       DBMS_OUTPUT.PUT_LINE(SUBSTR(FND_MSG_PUB.GET(P_MSG_INDEX => I, P_ENCODED => 'F'), 1, 254));
   END LOOP;
   IF l_return_status <> 'S' THEN
      NULL;
   ELSE
      dbms_output.put_line(' CM Application_id = '|| l_application_ref_id );
      -- You can issue a COMMIT; at this point if you want to save the created credit memo to the database
   END IF;
EXCEPTION
WHEN OTHERS THEN
   dbms_output.put_line('exception error!');
   dbms_output.put_line(substr(sqlerrm, 1, 80));
   fnd_message.retrieve(l_dummy);
   dbms_output.put_line(l_dummy);
END;

How to create Credit Memo: API to create Credit Memo

No comments:

Post a Comment