create or replace PROCEDURE "CREATE_SNGL_INVOICE_1" (l_customer_trx_id OUT number, l_return_status OUT varchar2 ) AS -- Error Msg Variables err_num_1 NUMBER; err_msg_1 VARCHAR2(100); BEGIN declare l_msg_count number; l_msg_data varchar2(2000); l_batch_id number; l_cnt 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_dist_tbl ar_invoice_api_pub.trx_dist_tbl_type; l_trx_salescredits_tbl ar_invoice_api_pub.trx_salescredits_tbl_type; type l_error is varray(10) of varchar(2000); err l_error; --err varchar(2000); cnt number; --xx number; BEGIN ---2. -- Initialise global params insert into ecorec_error(errormsg) values('1. STARTING TO INITIALISE GLOABAL PARAMS'); APPS.FND_GLOBAL.APPS_INITIALIZE( 0, -- Application User ID (SYSADMIN here) 20678, -- Responsibility ID (Receivables Manager here) 222 -- Responsibility Application ID (Receivables) ); APPS.MO_GLOBAL.INIT('AR'); APPS.MO_GLOBAL.set_policy_context('S',85 ); l_trx_header_tbl(1).trx_header_id := 101; --l_trx_header_tbl(1).trx_number := '12345678910123456789'; l_trx_header_tbl(1).bill_to_account_number := 1835; l_trx_header_tbl(1).cust_trx_type_id := 1; l_trx_header_tbl(1).trx_date := trunc(sysdate); l_trx_header_tbl(1).trx_currency := 'USD'; l_trx_header_tbl(1).org_id:=85; l_batch_source_rec.batch_source_id := -1; --l_trx_header_tbl(1).bill_to_customer_id := 5824; --l_trx_header_tbl(1).receipt_method_id:=1001; l_trx_header_tbl(1).term_id:=5; --l_trx_header_tbl(1).bill_to_contact_id:=4600; --l_trx_header_tbl(1).bill_to_address_id:=2252; --l_trx_header_tbl(1).bill_to_site_use_id:=3388; l_trx_header_tbl(1).gl_date:= sysdate; l_trx_lines_tbl(1).trx_header_id := 101; l_trx_lines_tbl(1).trx_line_id := 101; l_trx_lines_tbl(1).line_number := 1; l_trx_lines_tbl(1).description := 'Test'; l_trx_lines_tbl(1).UOM_CODE := 'Ea'; l_trx_lines_tbl(1).quantity_invoiced := 20; l_trx_lines_tbl(1).unit_selling_price := 10; l_trx_lines_tbl(1).line_type := 'LINE'; l_trx_lines_tbl(1).inventory_item_id:=800; --l_trx_lines_tbl(1).override_auto_accounting_flag:='Y'; ---distribution details l_trx_dist_tbl(1).trx_line_id := 101; l_trx_dist_tbl(1).trx_dist_id:=101; l_trx_dist_tbl(1).amount:=200; l_trx_dist_tbl(1).account_class:='REV'; l_trx_dist_tbl(1).code_combination_id:=3005; l_trx_dist_tbl(1).acctd_amount:=200; ------------------------------------------------------------------- -- REC Code l_trx_dist_tbl(2).trx_dist_id := 102; l_trx_dist_tbl(2).trx_header_id := l_trx_header_tbl(1).trx_header_id ; --l_trx_dist_tbl(2).trx_line_id := 101; l_trx_dist_tbl(2).account_class := 'REC'; l_trx_dist_tbl(2).percent := 100; l_trx_dist_tbl(2).code_combination_id := 8533; ------------------------------------------------------ --7. Call the invoice api to create multiple invoices in a batch. AR_INVOICE_API_PUB.create_single_invoice( p_api_version => 1.0, p_commit=>'F', 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_customer_trx_id => l_customer_trx_id, x_return_status => l_return_status, x_msg_count => l_msg_count, x_msg_data => l_msg_data); dbms_output.put_line('>>>> l_msg_count='||l_msg_count); dbms_output.put_line('>>>> l_msg_data='||l_msg_data); dbms_output.put_line('>>>> l_return_status='||l_return_status); dbms_output.put_line('>>>> l_customer_trx_id='||l_customer_trx_id); 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!'); raise_application_error('-20001', l_msg_data); ELSE --8. Check whether any record exist in error table --Invoice Creation API User Notes 6-21 SELECT count(*) Into cnt From ar_trx_errors_gt; IF cnt = 0 THEN dbms_output.put_line ( '>>>> Customer Trx id '|| l_customer_trx_id); ELSE dbms_output.put_line ( '>>>> Transaction not Created, Please check ar_trx_errors_gt table--'|| cnt); DECLARE errmsg ar_trx_errors_gt.error_message%TYPE; CURSOR c_err IS select error_message into errmsg from ar_trx_errors_gt; BEGIN OPEN c_err; LOOP FETCH c_err INTO errmsg; EXIT WHEN c_err%NOTFOUND; DBMS_OUTPUT.PUT_LINE('>>>> The error is:'||errmsg); END LOOP; CLOSE c_err; END; END IF; end if; end; EXCEPTION WHEN OTHERS THEN err_num_1 := SQLCODE; err_msg_1 := SUBSTR(SQLERRM, 1, 100); DBMS_OUTPUT.PUT_LINE('>>>> Exception Thrown : Code => '|| err_num_1 ||' , Msg => '|| err_msg_1); insert into ecorec_error(errormsg) values(' Exception : Code => '|| err_num_1 ||' , Msg => '|| err_msg_1); END CREATE_SNGL_INVOICE_1;