Create Oracle Receivables Invoice using public API

| No Comments | No TrackBacks
Sample Code to create Single AR Invoice through API.

DECLARE
    p_msg_count             number;
    p_msg_data              varchar2(2000);
    p_trx_header_tbl        ar_invoice_api_pub.trx_header_tbl_type;
    p_trx_lines_tbl         ar_invoice_api_pub.trx_line_tbl_type;
    p_trx_dist_tbl          ar_invoice_api_pub.trx_dist_tbl_type;
    p_trx_salescredits_tbl  ar_invoice_api_pub.trx_salescredits_tbl_type;
    p_batch_source_rec      ar_invoice_api_pub.batch_source_rec_type;
    l_cnt number := 0;   
    l_customer_trx_id       number;
    l_return_status         varchar2(80);
    v_org_id number;
BEGIN
   DBMS_OUTPUT.PUT_LINE('*******START******');
    MO_GLOBAL.SET_POLICY_CONTEXT('S', 270);
    --MO_GLOBAL.INIT('AR'); ** IMP Comment this Line **
    select MO_GLOBAL.get_current_org_id() 
    into v_org_id from dual;
   DBMS_OUTPUT.PUT_LINE('Current MO Org_id='||v_org_id);
-- this is the header
    p_batch_source_rec.batch_source_id := 1261;
    p_trx_header_tbl(1).trx_header_id := 7267;
    p_trx_header_tbl(1).cust_trx_type_id := 1125;
    p_trx_header_tbl(1).trx_date := trunc(sysdate);
    p_trx_header_tbl(1).bill_to_customer_id := 16058;
    p_trx_header_tbl(1).trx_currency := 'USD';
    p_trx_header_tbl(1).trx_NUMBER := '10045';
    p_trx_header_tbl(1).term_id := 1003;
-- this is the first line  
    p_trx_lines_tbl(1).trx_header_id := 7267;
    p_trx_lines_tbl(1).trx_line_id := 13631;
    p_trx_lines_tbl(1).line_number := 1;
    p_trx_lines_tbl(1).description := '1st line';
    p_trx_lines_tbl(1).quantity_invoiced := 1;
    p_trx_lines_tbl(1).unit_selling_price := 10;
    p_trx_lines_tbl(1).line_type := 'LINE';
    p_trx_lines_tbl(1).inventory_item_id :=11040;
    
    AR_INVOICE_API_PUB.create_single_invoice(
             p_api_version           => 1.0,
             x_return_status         => l_return_status,
             x_msg_count             => p_msg_count,
             x_msg_data              => p_msg_data,
             x_customer_trx_id       => l_customer_trx_id,
             p_batch_source_rec      => p_batch_source_rec,
             p_trx_header_tbl        => p_trx_header_tbl,
             p_trx_lines_tbl         => p_trx_lines_tbl,
             p_trx_dist_tbl          => p_trx_dist_tbl,
             p_trx_salescredits_tbl  => p_trx_salescredits_tbl
            );
            
       DBMS_OUTPUT.PUT_LINE( 'Msg '|| substr(p_msg_data,1,225));
       DBMS_OUTPUT.PUT_LINE('Status '|| l_return_status);

   IF l_return_status = fnd_api.g_ret_sts_error OR
       l_return_status = fnd_api.g_ret_sts_unexp_error THEN
       DBMS_OUTPUT.PUT_LINE('unexpected errors found!');
   ELSE
      SELECT count(*)
      Into l_cnt
      From ar_trx_errors_gt;
      IF l_cnt = 0
      THEN
         DBMS_OUTPUT.PUT_LINE('Customer Trx id '|| l_customer_trx_id);
         COMMIT;
      ELSE
          FOR recERR in (
          SELECT DISTINCT trx_header_id, trx_line_id, error_message, invalid_value
          FROM Ar_Trx_Errors_Gt)
          LOOP
              DBMS_OUTPUT.PUT_LINE( recerr.error_message);
          END LOOP;

         DBMS_OUTPUT.PUT_LINE( 'Transaction not Created');
      END IF;
   END IF;
END;

Useful Metalink Notes:
265604.1 
1158903.1

No TrackBacks

TrackBack URL: http://chandramouly.com/MT/mt/mt-tb.cgi/17

Leave a comment

About this Entry

This page contains a single entry by chandramouly published on September 17, 2010 1:33 AM.

FNDLOAD - Upload, download oracle program definitions was the previous entry in this blog.

Find recent content on the main index or look in the archives to find all content.