Tuesday, May 25, 2010

API to cancel single AP invoice (AP_CANCEL_PKG.AP_CANCEL_SINGLE_INVOICE)

Below script will explain you to cancel an invoice through API

This script was tested in R12.1.1 instance.


SET SERVEROUTPUT ON;
DECLARE

v_invoice_id            NUMBER      := 11844;
v_last_updated_by       VARCHAR2(20):= 1961;
v_last_update_login     VARCHAR2(20):= 504106;
v_accounting_date       DATE        := SYSDATE;
v_boolean               BOOLEAN;

v_error_code            VARCHAR2(100);
v_debug_info            VARCHAR2(1000);

v_message_name          VARCHAR2(1000);
v_invoice_amount        NUMBER;
v_base_amount           NUMBER;
v_tax_amount            NUMBER;
v_temp_cancelled_amount NUMBER;
v_cancelled_by          VARCHAR2(1000);
v_cancelled_amount      NUMBER;
v_cancelled_date        DATE;
v_last_update_date      DATE;
v_token                 VARCHAR2(100);
v_orig_prepay_amt       NUMBER;
v_pay_cur_inv_amt       NUMBER;


FUNCTION set_context( i_user_name    IN  VARCHAR2
                      ,i_resp_name    IN  VARCHAR2
                      ,i_org_id       IN  NUMBER)
RETURN VARCHAR2
IS
 BEGIN
  NULL;
  -- Inorder to reduce the content of the post I moved the implementation part of this function to another post and it is available here 
END set_context;

BEGIN 
-- Setting the context ----
   v_context :=
              set_context ('&user', '&responsibility', 108); 
   IF v_context = 'F'
   THEN
      DBMS_OUTPUT.put_line ('Error while setting the context');
   END IF;  
--- context done ------------ 
DBMS_OUTPUT.put_line ('Calling API to check whetehr the Invoice is canellable ' );

v_boolean :=AP_CANCEL_PKG.IS_INVOICE_CANCELLABLE(
                P_invoice_id       => v_invoice_id,
                P_error_code       => v_error_code,   
                P_debug_info       => v_debug_info,
                P_calling_sequence => NULL);

IF v_boolean
THEN
DBMS_OUTPUT.put_line ('Invoice '||v_invoice_id|| ' is cancellable' );
ELSE
DBMS_OUTPUT.put_line ('Invoice '||v_invoice_id|| ' is not cancellable :'|| v_error_code );
END IF;     
 
DBMS_OUTPUT.put_line ('Calling API to Cancel Invoice' );

v_boolean := AP_CANCEL_PKG.AP_CANCEL_SINGLE_INVOICE
            (p_invoice_id                 => v_invoice_id,
             p_last_updated_by            => v_last_updated_by,
             p_last_update_login          => v_last_update_login,
             p_accounting_date            => v_accounting_date,
             p_message_name               => v_message_name,
             p_invoice_amount             => v_invoice_amount,
             p_base_amount                => v_base_amount,
             p_temp_cancelled_amount      => v_temp_cancelled_amount,
             p_cancelled_by               => v_cancelled_by,
             p_cancelled_amount           => v_cancelled_amount,
             p_cancelled_date             => v_cancelled_date,
             p_last_update_date           => v_last_update_date,
             p_original_prepayment_amount => v_orig_prepay_amt,
             p_pay_curr_invoice_amount    => v_pay_cur_inv_amt,
             P_Token                      => v_token,
             p_calling_sequence           => NULL
             );

IF v_boolean
THEN
DBMS_OUTPUT.put_line ('Successfully Cancelled the Invoice' );
COMMIT;
ELSE
DBMS_OUTPUT.put_line ('Failed to Cancel the Invoice' );
ROLLBACK;
END IF;

END;

1 Responses to “API to cancel single AP invoice (AP_CANCEL_PKG.AP_CANCEL_SINGLE_INVOICE)”

Unknown said...
May 20, 2016 at 4:52 AM This comment has been removed by the author.

Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.