CREATE OR REPLACE PACKAGE XXCP_COPY_SALES_ORDER is
PROCEDURE MAIN (P_ERRBUF OUT VARCHAR2,
P_RETCODE OUT NUMBER,
P_ORDER_NUM IN NUMBER
) ;
END;
/
CREATE OR REPLACE PACKAGE BODY XXCP_COPY_SALES_ORDER is
PROCEDURE MAIN
(P_ERRBUF OUT VARCHAR2,
P_RETCODE OUT NUMBER,
P_ORDER_NUM IN NUMBER
) is
l_query_header_id NUMBER;
l_return_status VARCHAR2(1);
l_msg_count NUMBER;
l_msg_data VARCHAR2(2000);
l_copy_rec Oe_order_copy_util.Copy_rec_type := Oe_order_copy_util.get_copy_rec;
l_new_order_number oe_order_headers_all.order_number%TYPE;
l_error_msg_data Oe_msg_pub.MSG_TBL_TYPE;
v_error_msg VARCHAR2(4000);
l_line_id varchar2(500);
l_line_type_id number;
l_header_id number;
l_order_type_id number;
l_Line_cnt number := 0;
l_ERRMSG varchar2(200);
MULTIPLE_ORDERS EXCEPTION;
cursor cur_line(p_header_id NUMBER) is select line_id,line_type_id from oe_order_lines
where header_id = p_header_id;
BEGIN
BEGIN
select header_id,order_type_id into l_header_id,l_order_type_id from oe_order_headers
where order_number = P_ORDER_NUM;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
l_ERRMSG:= 'ERROR:More Then One Order exist';
RAISE MULTIPLE_ORDERS;
WHEN OTHERS THEN
l_ERRMSG := SQLERRM;
FND_FILE.PUT_LINE(FND_FILE.LOG, l_ERRMSG);
RAISE MULTIPLE_ORDERS;
END;
for rec_line in cur_line(l_header_id) loop
l_Line_cnt := 1+l_Line_cnt;
l_line_id := to_char(rec_line.line_id)||','|| l_line_id;
l_line_type_id := rec_line.line_type_id;
end loop;
--- fnd_global.apps_initialize(0, 51124, 660);
l_copy_rec.api_version_number := 1;
l_copy_rec.init_msg_list := FND_API.G_TRUE;
l_copy_rec.COMMIT :=FND_API.G_TRUE;
l_copy_rec.Copy_Order := FND_API.G_TRUE;
l_copy_rec.hdr_count := 1;
l_copy_rec.hdr_list :=l_header_id;
l_copy_rec.append_to_header_id:= NULL;
l_copy_rec.hdr_info := 'T';
l_copy_rec.hdr_type := 1997;
l_copy_rec.hdr_descflex := 'T';
l_copy_rec.hdr_credit_card_details := 'T';
l_copy_rec.hdr_scredits := 'T';
l_copy_rec.hdr_attchmnts := 'T';
l_copy_rec.hdr_holds := 'T';
l_copy_rec.manual_order_number:= P_ORDER_NUM;
l_copy_rec.all_lines := 'T';
l_copy_rec.line_count := l_Line_cnt;
l_copy_rec.line_list := l_line_id;--l_line_list;
l_copy_rec.line_type := 1996;
l_copy_rec.incl_cancelled := 'T';
l_copy_rec.line_price_mode := 1;--Original Price;
--l_copy_rec.line_price_date := NULL;
-- l_copy_rec.line_discount_id := NULL;
l_copy_rec.line_descflex := 'T';
l_copy_rec.line_scredits := 'T';
l_copy_rec.line_attchmnts := 'T';
--l_copy_rec.return_reason_code := v_return_reason_code;
l_copy_rec.default_null_values:= 'T';
Oe_order_copy_util.copy_order( p_copy_rec => l_copy_rec
,x_header_id => l_query_header_id
,x_return_status => l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data);
IF l_return_status = 'S' THEN --Copy successful
update oe_order_lines_all set source_type_code = 'INTERNAL' where header_id = l_query_header_id;
OE_ORDER_BOOK_UTIL.Complete_Book_Eligible
(p_api_version_number=> 1
,p_init_msg_list=> FND_API.G_TRUE
,p_header_id => l_query_header_id
,x_return_status=> l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data
);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'Order Header ID:'|| l_query_header_id);
ELSE
Oe_msg_pub.GET_MSG_TBL(l_error_msg_data);
FOR i IN l_error_msg_data.FIRST .. l_error_msg_data.LAST LOOP
FND_FILE.PUT_LINE(FND_FILE.LOG,l_error_msg_data(i).message);
END LOOP;
END IF;
IF l_return_status = 'S' THEN
for rec_line in cur_line(l_query_header_id) loop
OE_ORDER_CLOSE_UTIL.Close_Line
( p_api_version_number => 1.0
, p_line_id => rec_line.line_id
, x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'CLOSE LINE:'||rec_line.line_id||'-'|| l_return_status);
END LOOP;
oe_order_close_util.close_order(1, NULL, l_query_header_id, l_return_status, l_msg_count, l_msg_data);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'CLOSE HEADER:'||l_query_header_id||'-'|| l_return_status);
END IF;
COMMIT;
EXCEPTION
WHEN MULTIPLE_ORDERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG, l_ERRMSG);
WHEN OTHERS THEN
l_ERRMSG := l_ERRMSG||'-'||l_msg_data;
ROLLBACK;
FND_FILE.PUT_LINE(FND_FILE.LOG, l_ERRMSG);
END MAIN;
END XXCP_COPY_SALES_ORDER;
/
ref: http://sriniik.blogspot.nl/2010/05/copy-sales-order-book-order-sales-order.html
PROCEDURE MAIN (P_ERRBUF OUT VARCHAR2,
P_RETCODE OUT NUMBER,
P_ORDER_NUM IN NUMBER
) ;
END;
/
CREATE OR REPLACE PACKAGE BODY XXCP_COPY_SALES_ORDER is
PROCEDURE MAIN
(P_ERRBUF OUT VARCHAR2,
P_RETCODE OUT NUMBER,
P_ORDER_NUM IN NUMBER
) is
l_query_header_id NUMBER;
l_return_status VARCHAR2(1);
l_msg_count NUMBER;
l_msg_data VARCHAR2(2000);
l_copy_rec Oe_order_copy_util.Copy_rec_type := Oe_order_copy_util.get_copy_rec;
l_new_order_number oe_order_headers_all.order_number%TYPE;
l_error_msg_data Oe_msg_pub.MSG_TBL_TYPE;
v_error_msg VARCHAR2(4000);
l_line_id varchar2(500);
l_line_type_id number;
l_header_id number;
l_order_type_id number;
l_Line_cnt number := 0;
l_ERRMSG varchar2(200);
MULTIPLE_ORDERS EXCEPTION;
cursor cur_line(p_header_id NUMBER) is select line_id,line_type_id from oe_order_lines
where header_id = p_header_id;
BEGIN
BEGIN
select header_id,order_type_id into l_header_id,l_order_type_id from oe_order_headers
where order_number = P_ORDER_NUM;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
l_ERRMSG:= 'ERROR:More Then One Order exist';
RAISE MULTIPLE_ORDERS;
WHEN OTHERS THEN
l_ERRMSG := SQLERRM;
FND_FILE.PUT_LINE(FND_FILE.LOG, l_ERRMSG);
RAISE MULTIPLE_ORDERS;
END;
for rec_line in cur_line(l_header_id) loop
l_Line_cnt := 1+l_Line_cnt;
l_line_id := to_char(rec_line.line_id)||','|| l_line_id;
l_line_type_id := rec_line.line_type_id;
end loop;
--- fnd_global.apps_initialize(0, 51124, 660);
l_copy_rec.api_version_number := 1;
l_copy_rec.init_msg_list := FND_API.G_TRUE;
l_copy_rec.COMMIT :=FND_API.G_TRUE;
l_copy_rec.Copy_Order := FND_API.G_TRUE;
l_copy_rec.hdr_count := 1;
l_copy_rec.hdr_list :=l_header_id;
l_copy_rec.append_to_header_id:= NULL;
l_copy_rec.hdr_info := 'T';
l_copy_rec.hdr_type := 1997;
l_copy_rec.hdr_descflex := 'T';
l_copy_rec.hdr_credit_card_details := 'T';
l_copy_rec.hdr_scredits := 'T';
l_copy_rec.hdr_attchmnts := 'T';
l_copy_rec.hdr_holds := 'T';
l_copy_rec.manual_order_number:= P_ORDER_NUM;
l_copy_rec.all_lines := 'T';
l_copy_rec.line_count := l_Line_cnt;
l_copy_rec.line_list := l_line_id;--l_line_list;
l_copy_rec.line_type := 1996;
l_copy_rec.incl_cancelled := 'T';
l_copy_rec.line_price_mode := 1;--Original Price;
--l_copy_rec.line_price_date := NULL;
-- l_copy_rec.line_discount_id := NULL;
l_copy_rec.line_descflex := 'T';
l_copy_rec.line_scredits := 'T';
l_copy_rec.line_attchmnts := 'T';
--l_copy_rec.return_reason_code := v_return_reason_code;
l_copy_rec.default_null_values:= 'T';
Oe_order_copy_util.copy_order( p_copy_rec => l_copy_rec
,x_header_id => l_query_header_id
,x_return_status => l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data);
IF l_return_status = 'S' THEN --Copy successful
update oe_order_lines_all set source_type_code = 'INTERNAL' where header_id = l_query_header_id;
OE_ORDER_BOOK_UTIL.Complete_Book_Eligible
(p_api_version_number=> 1
,p_init_msg_list=> FND_API.G_TRUE
,p_header_id => l_query_header_id
,x_return_status=> l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data
);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'Order Header ID:'|| l_query_header_id);
ELSE
Oe_msg_pub.GET_MSG_TBL(l_error_msg_data);
FOR i IN l_error_msg_data.FIRST .. l_error_msg_data.LAST LOOP
FND_FILE.PUT_LINE(FND_FILE.LOG,l_error_msg_data(i).message);
END LOOP;
END IF;
IF l_return_status = 'S' THEN
for rec_line in cur_line(l_query_header_id) loop
OE_ORDER_CLOSE_UTIL.Close_Line
( p_api_version_number => 1.0
, p_line_id => rec_line.line_id
, x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'CLOSE LINE:'||rec_line.line_id||'-'|| l_return_status);
END LOOP;
oe_order_close_util.close_order(1, NULL, l_query_header_id, l_return_status, l_msg_count, l_msg_data);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'CLOSE HEADER:'||l_query_header_id||'-'|| l_return_status);
END IF;
COMMIT;
EXCEPTION
WHEN MULTIPLE_ORDERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG, l_ERRMSG);
WHEN OTHERS THEN
l_ERRMSG := l_ERRMSG||'-'||l_msg_data;
ROLLBACK;
FND_FILE.PUT_LINE(FND_FILE.LOG, l_ERRMSG);
END MAIN;
END XXCP_COPY_SALES_ORDER;
/
ref: http://sriniik.blogspot.nl/2010/05/copy-sales-order-book-order-sales-order.html
No comments:
Post a Comment