[Home] [Help]
PACKAGE BODY: APPS.OE_INVOICE_PUB
Source
1 PACKAGE BODY OE_Invoice_PUB AS
2 /* $Header: OEXPINVB.pls 120.77.12020000.8 2013/04/12 05:36:44 sujithku ship $ */
3
4 -- Global constant holding the package name
5
6 G_PKG_NAME CONSTANT VARCHAR2(30) := 'OE_Invoice_PUB';
7 G_ITEMTYPE VARCHAR2(8);
8
9 --bug5336639 start
10 G_CURRENT_LINE_ID NUMBER := null;
11 G_IS_CURR_LINE_INVOICEABLE BOOLEAN := null;
12 --bug5336639 end
13
14 inv_num VARCHAR2(40);
15 -- 3757279
16 TYPE Prf_Rec_Type IS RECORD
17 ( concat_segment varchar2(240) := NULL
18 , prf_value varchar2(240) := NULL
19 );
20
21 TYPE Prf_Tbl_Type IS TABLE OF Prf_Rec_Type
22 INDEX BY BINARY_INTEGER;
23
24 Prf_Tbl Prf_Tbl_Type;
25
26 TABLE_SIZE binary_integer := 2147483646; /*Size of the above Table*/
27
28 FUNCTION find(p_concat_segment IN VARCHAR2)
29 RETURN binary_integer
30 IS
31 l_tab_index BINARY_INTEGER;
32 l_found BOOLEAN;
33 l_hash_value NUMBER;
34
35 BEGIN
36 l_tab_index := dbms_utility.get_hash_value(p_concat_segment,1,TABLE_SIZE);
37 oe_debug_pub.add('Find: hash_value:'||l_tab_index,1);
38 IF Prf_Tbl.EXISTS(l_tab_index) THEN
39 IF Prf_Tbl(l_tab_index).concat_segment = p_concat_segment THEN
40 RETURN l_tab_index;
41 ELSE
42 l_hash_value := l_tab_index;
43 l_found := FALSE;
44 WHILE (l_tab_index < TABLE_SIZE)
45 AND NOT l_found LOOP
46 IF Prf_Tbl.EXISTS(l_tab_index) THEN
47 IF Prf_Tbl(l_tab_index).concat_segment = p_concat_segment THEN
48 l_found := TRUE;
49 ELSE
50 l_tab_index := l_tab_index + 1;
51 END IF;
52 ELSE
53 RETURN (TABLE_SIZE+1);
54 END IF;
55 END LOOP;
56 IF NOT l_found THEN
57 l_tab_index := 1;
58 WHILE (l_tab_index < l_hash_value)
59 AND NOT l_found LOOP
60 IF Prf_Tbl.EXISTS(l_tab_index) THEN
61 IF Prf_Tbl(l_tab_index).concat_segment = p_concat_segment THEN
62 l_found := TRUE;
63 ELSE
64 l_tab_index := l_tab_index + 1;
65 END IF;
66 ELSE
67 RETURN (TABLE_SIZE+1);
68 END IF;
69 END LOOP;
70 END IF;
71 IF NOT l_found THEN
72 RETURN (TABLE_SIZE+1);
73 END IF;
74 END IF;
75 ELSE
76 RETURN (TABLE_SIZE+1);
77 END IF;
78 RETURN l_tab_index;
79 EXCEPTION
80 WHEN OTHERS THEN
81 RETURN TABLE_SIZE+1;
82 END find;
83
84 PROCEDURE put(p_concat_segment IN VARCHAR2,
85 p_user_id IN NUMBER,
86 p_resp_id IN NUMBER,
87 p_appl_id IN NUMBER,
88 x_prof_value OUT NOCOPY VARCHAR2)
89 IS
90 l_tab_index BINARY_INTEGER;
91 l_stored BOOLEAN :=FALSE;
92 l_prof_value VARCHAR2(240);
93 l_hash_value NUMBER;
94 BEGIN
95 l_tab_index := dbms_utility.get_hash_value(p_concat_segment,1,TABLE_SIZE);
96 --l_prof_value := FND_PROFILE.VALUE_SPECIFIC('AR_ALLOW_TAX_CODE_OVERRIDE',p_user_id,p_resp_id,p_appl_id);
97 l_prof_value := FND_PROFILE.VALUE_SPECIFIC('ZX_ALLOW_TAX_CLASSIF_OVERRIDE',p_user_id,p_resp_id,p_appl_id);
98 oe_debug_pub.add('Put:hash_value:'||l_tab_index,1);
99 IF Prf_Tbl.EXISTS(l_tab_index) THEN
100 IF Prf_Tbl(l_tab_index).concat_segment = p_concat_segment THEN
101 Prf_Tbl(l_tab_index).prf_value := l_prof_value;
102 l_stored := TRUE;
103 ELSE
104 l_hash_value := l_tab_index;
105 WHILE l_tab_index < TABLE_SIZE
106 AND NOT l_stored LOOP
107 IF Prf_Tbl.EXISTS(l_tab_index) THEN
108 IF Prf_Tbl(l_tab_index).concat_segment = p_concat_segment THEN
109 Prf_Tbl(l_tab_index).prf_value := l_prof_value;
110 l_stored := TRUE;
111 ELSE
112 l_tab_index := l_tab_index +1;
113 END IF;
114 ELSE
115 Prf_Tbl(l_tab_index).prf_value := l_prof_value;
116 Prf_Tbl(l_tab_index).concat_segment := p_concat_segment;
117 l_stored := TRUE;
118 END IF;
119 END LOOP;
120 IF NOT l_stored THEN
121 l_tab_index := 1;
122 WHILE l_tab_index < l_hash_value
123 AND NOT l_stored LOOP
124 IF Prf_Tbl.EXISTS(l_tab_index) THEN
125 IF Prf_Tbl(l_tab_index).concat_segment = p_concat_segment THEN
126 Prf_Tbl(l_tab_index).prf_value := l_prof_value;
127 l_stored := TRUE;
128 ELSE
129 l_tab_index := l_tab_index +1;
130 END IF;
131 ELSE
132 Prf_Tbl(l_tab_index).prf_value := l_prof_value;
133 Prf_Tbl(l_tab_index).concat_segment := p_concat_segment;
134 l_stored := TRUE;
135 END IF;
136 END LOOP;
137 END IF;
138 END IF;
139 ELSE
140 Prf_Tbl(l_tab_index).prf_value := l_prof_value;
141 Prf_Tbl(l_tab_index).concat_segment := p_concat_segment;
142 l_stored := TRUE;
143 END IF;
144 x_prof_value := l_prof_value;
145 EXCEPTION
146 WHEN OTHERS THEN
147 NULL;
148 END put;
149 -- 3757279
150
151 FUNCTION Invoice_Balance(
152 P_CUSTOMER_TRX_ID IN NUMBER )
153 RETURN NUMBER
154 IS
155 v_balance NUMBER := NULL ;
156 BEGIN
157 IF ( P_CUSTOMER_TRX_ID IS NOT NULL )
158 THEN
159 SELECT NVL(SUM(AMOUNT_DUE_REMAINING),0)
160 INTO v_balance
161 FROM AR_PAYMENT_SCHEDULES
162 WHERE CUSTOMER_TRX_ID = P_CUSTOMER_TRX_ID;
163 END IF;
164 RETURN(v_balance);
165 EXCEPTION
166 WHEN NO_DATA_FOUND THEN
167 return(NULL);
168 END; -- INVOICE_BALANCE
169
170
171
172 /*
173 * This procedure is added for bug# 7231974
174 * This proc is exact copy of OE_LINE_FULLFILL.UPDATE_SERVICE_DATES(). Therefore, any changes in oe_line_fullfill.update_service_dates()
175 * should be imported to this proc as well.
176 * This proc is called in case of SERVICE lines, with ORDER reference type, with VARIABLE type accounting rule, with ACCOUNTING_RULE_DURATION field being null
177 * and service_start_date and service_end_Date being null.
178 *
179 */
180 PROCEDURE Update_Service_Dates
181 (
182 p_line_rec IN OUT NOCOPY OE_Order_Pub.Line_Rec_Type
183 --13724397 Start
184 ,x_return_status OUT NOCOPY VARCHAR2
185 --13724397 End
186 )
187 IS
188 l_return_status VARCHAR2(1);
189 l_line_rec OE_Order_Pub.Line_Rec_Type;
190 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
191 BEGIN
192
193 IF l_debug_level > 0 THEN
194 oe_debug_pub.add('entering oe_invoice_pub . update_service_dates() '
195 ||' p_line_rec.line_id = ' || P_LINE_REC.LINE_ID
196 ||' p_line_rec.service_start_date = '||TO_CHAR(P_LINE_REC.SERVICE_START_DATE, 'YYYY/MM/DD' )
197 ||' p_line_rec.service_end_date = '|| TO_CHAR ( P_LINE_REC.SERVICE_END_DATE , 'YYYY/MM/DD' )
198 ) ;
199 END IF;
200
201 IF p_line_rec.service_start_date IS NULL OR p_line_rec.service_start_date = FND_API.G_MISS_DATE THEN
202 l_line_rec := p_line_rec;
203 l_line_rec.service_start_date := NULL;
204 l_line_rec.service_reference_type_code := 'GET_SVC_START';
205 OE_SERVICE_UTIL.Get_Service_Duration(
206 p_x_line_rec => l_line_rec,
207 x_return_status => l_return_status
208 );
209
210 oe_debug_pub.add(' l_line_rec.service_start_date = '|| l_line_rec.service_start_date);
211 oe_debug_pub.add(' l_return_status = '||l_return_status);
212
213 p_line_rec.service_start_date := l_line_rec.service_start_date;
214
215 IF p_line_rec.service_start_date IS NOT NULL THEN
216 p_line_rec.service_end_date := NULL;
217 OE_SERVICE_UTIL.Get_Service_Duration(
218 p_x_line_rec => p_line_rec,
219 x_return_status => l_return_status
220 );
221 oe_debug_pub.add(' l_return_status == '||l_return_status);
222 END IF;
223
224 ELSIF p_line_rec.service_end_date IS NULL OR p_line_rec.service_end_date = FND_API.G_MISS_DATE THEN
225
226 OE_SERVICE_UTIL.Get_Service_Duration(
227 p_x_line_rec => p_line_rec,
228 x_return_status => l_return_status
229 );
230 oe_debug_pub.add(' l_return_status == > '||l_return_status);
231 END IF;
232 --13724397 Start
233 x_return_status :=l_return_status;
234 --13724397 End
235 IF l_debug_level > 0 THEN
236 oe_debug_pub.add('exiting oe_invoice_pub . update_service_dates() '
237 ||' p_line_rec.line_id = ' || P_LINE_REC.LINE_ID
238 ||' p_line_rec.service_start_date = '||TO_CHAR(P_LINE_REC.SERVICE_START_DATE, 'YYYY/MM/DD' )
239 ||' p_line_rec.service_end_date = '|| TO_CHAR ( P_LINE_REC.SERVICE_END_DATE , 'YYYY/MM/DD' )
240 ) ;
241 END IF;
242
243 END Update_Service_Dates;
244
245 -- 8319535 start
246 /*9040537
247 PROCEDURE Update_Credit_Invoice
248 (
249 p_line_rec IN OUT NOCOPY OE_Order_Pub.Line_Rec_Type,
250 p_header_rec IN OUT NOCOPY OE_Order_Pub.Header_Rec_Type
251 )
252 IS
253 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
254 l_defaulting_invoice_line_id NUMBER := NULL;
255 l_defaulting_order_line_id NUMBER := NULL;
256
257 BEGIN
258
259 IF l_debug_level > 0 THEN
260 oe_debug_pub.add('Entering Update_Credit_Invoice');
261 END IF;
262
263 IF p_line_rec.return_attribute2 is NOT NULL AND
264 p_line_rec.return_attribute2 <> FND_API.G_MISS_CHAR AND
265 p_line_rec.Credit_Invoice_Line_Id IS NULL AND
266 p_line_rec.line_category_code = 'RETURN'
267 THEN
268 l_defaulting_invoice_line_id :=
269 OE_Default_Line.Get_Def_Invoice_Line_Int
270 (p_line_rec.return_context,
271 p_line_rec.return_attribute1,
272 p_line_rec.return_attribute2,
273 p_header_rec.sold_to_org_id,
274 p_header_rec.transactional_curr_code,
275 l_defaulting_order_line_id);
276
277 p_line_rec.Credit_Invoice_Line_Id := l_defaulting_invoice_line_id;
278 END IF;
279
280 IF l_debug_level > 0 THEN
281 oe_debug_pub.add('Exitting Update_Credit_Invoice');
282 END IF;
283
284 EXCEPTION
285 WHEN OTHERS THEN
286 IF l_debug_level > 0 THEN
287 oe_debug_pub.add('Error occured in Update_Credit_Invoice:'||SQLERRM);
288 END IF;
289 END Update_Credit_Invoice;
290 9040537*/
291 -- 8319535 end
292
293 FUNCTION Return_Line
294 (p_line_rec IN OE_Order_Pub.Line_Rec_Type
295 )
296 RETURN BOOLEAN
297 IS
298 --
299 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
300 --
301 l_header_id NUMBER;
302 l_line_id NUMBER;
303
304 BEGIN
305 IF l_debug_level > 0 THEN
306 oe_debug_pub.add( 'ENTER RETURN_LINE ' , 1 ) ;
307 END IF;
308 IF p_line_rec.line_category_code = 'RETURN' THEN
309 IF l_debug_level > 0 THEN
310 oe_debug_pub.add( 'EXIT , THIS IS A RETURN LINE' , 1 ) ;
311 END IF;
312 RETURN TRUE;
313 ELSE
314 IF l_debug_level > 0 THEN
315 oe_debug_pub.add( 'EXIT , THIS IS A REGULAR LINE' , 1 ) ;
316 END IF;
317 RETURN FALSE;
318 END IF;
319 EXCEPTION
320 WHEN OTHERS THEN
321 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
322 IF l_debug_level > 0 THEN
323 oe_debug_pub.add( 'RETURN_LINE: WHEN OTHERS EXCEPTION ' , 1 ) ;
324 END IF;
325 OE_MSG_PUB.Add_Exc_Msg
326 ( G_PKG_NAME
327 , 'Return_Line'
328 );
329 END IF;
330 END Return_Line;
331
332 Procedure Update_line_flow_status
333 ( p_line_id IN NUMBER
334 , p_flow_status_code IN VARCHAR2
335 , p_order_source_id IN NUMBER DEFAULT NULL -- 8541809
336 ) IS
337 --
338 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
339
340 -- 8541809: Start
341 l_item_key_sso NUMBER;
342 l_header_rec Oe_Order_Pub.Header_Rec_Type;
343 l_line_rec Oe_Order_Pub.Line_Rec_Type;
344 l_ret_stat Varchar2(30);
345 -- 8541809: End
346 l_existing_fsc oe_order_lines_all.flow_status_code%type; -- Bug 13870263
347 --
348 Begin
349 IF l_debug_level > 0 THEN
350 oe_debug_pub.add( 'Inside Update Line Flow Status');
351 oe_debug_pub.add( 'line id : ' || p_line_id);
352 oe_debug_pub.add( 'flow status code : ' || p_flow_status_code);
353 END IF;
354
355 ------------ Bug 13870263:: Start
356 BEGIN
357 SELECT flow_status_code INTO l_existing_fsc
358 FROM oe_order_lines_all
359 WHERE line_id = p_line_id;
360 EXCEPTION
361 WHEN Others THEN
362 l_existing_fsc := NULL;
363 END;
364
365 IF l_existing_fsc = p_flow_status_code THEN
366 IF l_debug_level > 0 THEN
367 oe_debug_pub.add('Old and New Flow Status Codes are the same.');
368 oe_debug_pub.add(' Not updating flow status code anymore...');
369 END IF;
370
371 --
372 -- Should be OK to return here, because this corresponds to a scenario
373 -- wherein there is no real change to flow status code at all. This
374 -- RETURN effectively skips the execution of the ensuing UPDATE
375 -- statement, and also the AIA sync APIs. It is OK to skip the
376 -- AIA sync in such a case because the flow status code sync
377 -- will have been completed earlier once; and it is not necessary
378 -- to initiate a sync every time INVOICE_INTERFACE WF activity gets
379 -- to execute because of becoming "Timed Out".
380 --
381 RETURN;
382 END IF; -- Check on existing and new flow status codes.
383 ------------ Bug 13870263::: END
384
385 Update oe_order_lines_all
386 Set flow_status_code = p_flow_status_code
387 , last_update_date = sysdate --BUG#9539541
388 , last_updated_by = NVL(oe_standard_wf.g_user_id, fnd_global.user_id) --BUG#9539541
389 Where line_id = p_line_id;
390
391 --OIP SUN ER changes
392 If p_flow_status_code = 'INVOICED' then
393 Oe_Line_Util.Query_Row(p_line_id, l_line_rec);
394 OE_ORDER_UTIL.RAISE_BUSINESS_EVENT(l_line_rec.header_id,
395 l_line_rec.line_id,
396 'INVOICED');
397 end if;
398
399 -- 8541809 : Start
400 IF l_debug_level > 0 THEN
401 oe_debug_pub.add('Initiating O2C/Genesis Sync...');
402 END IF;
403
404 IF p_order_source_id IS NOT NULL THEN
405
406 IF Oe_Genesis_Util.Status_Needs_Sync(p_flow_status_code) THEN
407 IF Oe_Genesis_Util.Source_AIA_Enabled(p_order_source_id)
408 THEN
409 Oe_Line_Util.Query_Row(p_line_id, l_line_rec);
410 Oe_Header_Util.Query_Row(l_line_rec.header_id, l_header_rec);
411
412 SELECT oe_xml_message_seq_s.NEXTVAL
413 INTO l_item_key_sso
414 FROM Dual;
415
416 IF l_debug_level > 0 THEN
417 oe_debug_pub.add(' l_item_key_sso: ' || l_item_key_sso);
418 END IF;
419
420 Oe_Sync_Order_Pvt.Insert_Sync_Line(
421 p_line_rec => l_line_rec,
422 p_change_type => 'LINE_STATUS',
423 p_req_id => l_item_key_sso,
424 x_return_status => l_ret_stat
425 );
426
427 IF l_debug_level > 0 THEN
428 oe_debug_pub.add(' Insert_Sync_Line Return Status: ' ||
429 l_ret_stat);
430 END IF;
431
432 Oe_Sync_Order_Pvt.Sync_Header_Line(
433 p_header_rec => l_header_rec,
434 p_line_rec => l_line_rec,
435 p_hdr_req_id => l_item_key_sso,
436 p_lin_req_id => l_item_key_sso,
437 p_change_type => 'LINE_STATUS'
438 );
439
440
441 END IF; -- on source_aia_enabled
442 END IF; -- on status_needs_sync
443
444 IF l_debug_level > 0 THEN
445 oe_debug_pub.add('Done with O2C/Genesis Sync.');
446 END IF;
447
448 END IF; -- on p_order_source_id being non-null
449 -- 8541809 : End
450
451 End Update_line_flow_status;
452
453 Procedure Update_header_flow_status
454 ( p_header_id IN NUMBER
455 , p_flow_status_code IN VARCHAR2
456 ) IS
457 --
458 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
459 --
460 l_item_key_sso NUMBER; -- 8541809
461 l_header_rec Oe_Order_Pub.Header_Rec_Type; -- 8541809
462 --
463 Begin
464 IF l_debug_level > 0 THEN
465 oe_debug_pub.add( 'Inside Update Header Flow Status');
466 END IF;
467
468 Update oe_order_headers_all
469 Set flow_status_code = p_flow_status_code
470 , last_update_date = sysdate --BUG#9539541
471 , last_updated_by = NVL(oe_standard_wf.g_user_id, fnd_global.user_id) --BUG#9539541
472 Where header_id = p_header_id;
473
474 -- 8541809 : Start
475 IF l_debug_level > 0 THEN
476 oe_debug_pub.add('Initiating O2C/Genesis Sync...');
477 END IF;
478
479 IF Oe_Genesis_Util.Status_Needs_Sync(p_flow_status_code) = TRUE THEN
480
481 Oe_Header_Util.Query_Row(p_header_id, l_header_rec);
482
483 IF Oe_Genesis_Util.Source_AIA_Enabled(l_header_rec.order_source_id) THEN
484
485 SELECT oe_xml_message_seq_s.NEXTVAL
486 INTO l_item_key_sso
487 FROM DUAL;
488
489 IF l_debug_level > 0 THEN
490 oe_debug_pub.add(' l_item_key_sso: ' || l_item_key_sso);
491 END IF;
492
493 Oe_Sync_Order_Pvt.Sync_Header_Line(
494 p_header_rec => l_header_rec,
495 p_line_rec => NULL,
496 p_hdr_req_id => l_item_key_sso,
497 p_lin_req_id => NULL,
498 p_change_type => 'LINE_STATUS'
499 );
500
501 END IF; -- source_aia_enabled
502 END IF; -- status_needs_sync
503
504 IF l_debug_level > 0 THEN
505 oe_debug_pub.add('Done with O2C/Genesis Sync.');
506 END IF;
507 -- 8541809 : End
508
509 End Update_header_flow_status;
510
511
512 FUNCTION Shipping_info_Available
513 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
514 )
515 RETURN BOOLEAN
516 IS
517 l_count NUMBER;
518 --
519 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
520 --
521 BEGIN
522 IF l_debug_level > 0 THEN
523 oe_debug_pub.add( 'ENTER SHIPPING_INFO_AVAILABLE ' , 1 ) ;
524 END IF;
525 -- Fix for bug 2196494
526 IF (p_line_rec.shippable_flag = 'Y' OR p_line_rec.item_type_code in ('MODEL','CLASS','KIT'))
527 AND p_line_rec.line_category_code <> 'RETURN'
528 AND p_line_rec.source_type_code <> 'EXTERNAL' THEN
529
530 /* Modified the condition clause for bug 4003538 */
531 IF (nvl(p_line_rec.shipped_quantity,0) = 0 AND
532 p_line_rec.model_remnant_flag = 'Y' AND
533 p_line_rec.item_type_code in ('MODEL','CLASS','KIT')) THEN
534 IF l_debug_level > 0 THEN
535 oe_debug_pub.add('Exit Shipping_info_Available (4) Remnant Model',1);
536 END IF;
537 RETURN TRUE;
538 -- If line is shipped, shipped quantity will be filled in otherwise it will be null
539 ELSIF p_line_rec.shipped_quantity IS NULL THEN -- Changed IF to ELSIF
540 IF l_debug_level > 0 THEN
541 oe_debug_pub.add('Exit Shipping_info_Available (1) non shippable', 1);
542 END IF;
543 RETURN FALSE;
544 ELSE
545 IF l_debug_level > 0 THEN
546 oe_debug_pub.add('Exit Shipping_info_Available (2)-shippable', 1);
547 END IF;
548 RETURN TRUE;
549 END IF;
550 ELSE
551 IF l_debug_level > 0 THEN
552 oe_debug_pub.add( 'EXIT SHIPPING_INFO_AVAILABLE ( 3 ) ' , 1 ) ;
553 END IF;
554 RETURN FALSE;
555 END IF;
556 EXCEPTION
557 WHEN OTHERS THEN
558 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
559 THEN
560 IF l_debug_level > 0 THEN
561 oe_debug_pub.add( 'SHIPPPING_INFO_AVAILABLE: WHEN OTHERS EXCEPTION ' , 1 ) ;
562 END IF;
563 OE_MSG_PUB.Add_Exc_Msg
564 ( G_PKG_NAME
565 , 'Shippping_info_Available'
566 );
567 END IF;
568 END Shipping_info_Available;
569
570 FUNCTION Line_Invoiceable
571 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
572 )
573 RETURN BOOLEAN
574 IS
575 l_invoiceable_item_flag VARCHAR2(1);
576 l_invoice_enabled_flag VARCHAR2(1);
577 l_serviceable_product_flag VARCHAR2(1);
578 l_order_line_id NUMBER;
579 l_return_status VARCHAR2(1);
580 l_service_reference_line_id NUMBER;
581 l_cancelled_delivery_detail NUMBER;
582 --bug5336639
583 l_master_organization_id NUMBER;
584 --
585 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
586 --
587 BEGIN
588 IF l_debug_level > 0 THEN
589 oe_debug_pub.add( 'ENTERING LINE_INVOICEABLE' , 1 ) ;
590 END IF;
591
592 --bug5336639
593 IF G_CURRENT_LINE_ID = p_line_rec.line_id THEN
594
595 IF l_debug_level > 0 THEN
596 oe_debug_pub.add('Returning the cached value..');
597 IF G_IS_CURR_LINE_INVOICEABLE THEN
598 oe_debug_pub.add('This line is invoiceable');
599 ELSE
600 oe_debug_pub.add('This line is not invoiceable');
601 END IF;
602 END IF;
603
604 RETURN G_IS_CURR_LINE_INVOICEABLE;
605 END IF;
606
607 -- sol_ord_er #16014165 /* If full billing from Contracts, line can't be invoiced */
608 IF p_line_rec.service_bill_option_code = 'FBOKS' THEN
609 IF l_debug_level > 0 THEN
610 oe_debug_pub.add( 'Full Billing to be done from Service Contracts, Line Not Invoiceable' , 1 ) ;
611 END IF;
612 G_CURRENT_LINE_ID := p_line_rec.line_id;
613 G_IS_CURR_LINE_INVOICEABLE := FALSE;
614 RETURN FALSE;
615 END IF;
616 -- sol_ord_er #16014165 end
617 /* For internal orders source_document_type_id is 10 */
618 IF p_line_rec.source_document_type_id = 10 THEN
619 IF l_debug_level > 0 THEN
620 oe_debug_pub.add( 'INTERNAL ORDER , NOT INVOICEABLE' , 1 ) ;
621 END IF;
622 --bug5336639 start
623 G_CURRENT_LINE_ID := p_line_rec.line_id;
624 G_IS_CURR_LINE_INVOICEABLE := FALSE;
625 --bug5336639 end;
626 RETURN FALSE;
627 END IF;
628
629 -- Begin 4172500
630 IF p_line_rec.shippable_flag = 'Y' AND nvl(p_line_rec.shipped_quantity,0) = 0 THEN
631 BEGIN
632
633 SELECT COUNT(*)
634 INTO l_cancelled_delivery_detail
635 FROM WSH_DELIVERY_DETAILS
636 WHERE SOURCE_LINE_ID = p_line_rec.line_id
637 AND SOURCE_CODE='OE'
638 AND RELEASED_STATUS = 'D';
639 IF NVL(l_cancelled_delivery_detail,0) > 0 THEN
640 IF l_debug_level > 0 THEN
641 oe_debug_pub.add('This line not eligible for invoice since shipping within tolerance'||p_line_rec.line_id,1);
642 END IF;
643 --bug5336639 start
644 G_CURRENT_LINE_ID := p_line_rec.line_id;
645 G_IS_CURR_LINE_INVOICEABLE := FALSE;
646 --bug5336639 end;
647 RETURN FALSE;
648 END IF;
649 EXCEPTION WHEN OTHERS THEN
650 IF l_debug_level > 0 THEN
651 oe_debug_pub.add('In Others',1);
652 END IF;
653 NULL;
654 END;
655 END IF;
656 -- End 4172500
657
658 --bug5336639
659 l_master_organization_id := oe_sys_parameters.value('MASTER_ORGANIZATION_ID', p_line_rec.org_id);
660
661 BEGIN
662 SELECT INVOICEABLE_ITEM_FLAG, INVOICE_ENABLED_FLAG
663 INTO l_invoiceable_item_flag, l_invoice_enabled_flag
664 FROM mtl_system_items
665 WHERE inventory_item_id = p_line_rec.inventory_item_id
666 AND organization_id = nvl(p_line_rec.ship_from_org_id,l_master_organization_id); --bug5336639
667
668 EXCEPTION
669 WHEN NO_DATA_FOUND THEN
670 IF l_debug_level > 0 THEN
671 oe_debug_pub.add( 'ITEM DEFINITION DOES NOT EXISTS IN THE SHIP FROM ORG' );
672 END IF;
673 RAISE NO_DATA_FOUND;
674 END;
675 /* If the service reference context is ORDER, then the service_reference
676 line_id is the line_id of the parent. However, if the service ref
677 context is Customer Product then we need to first retrieve the
678 original order line id */
679
680 IF p_line_rec.item_type_code = 'SERVICE' AND
681 p_line_rec.service_reference_type_code='CUSTOMER_PRODUCT' AND
682 p_line_rec.service_reference_line_id IS NOT NULL THEN
683 IF l_debug_level > 0 THEN
684 oe_debug_pub.add( 'LINE IS A CUSTOMER PRODUCT' ) ;
685 END IF;
686 /* Commenting for bug# 5032978
687 OE_SERVICE_UTIL.Get_Cust_Product_Line_Id
688 ( x_return_status => l_return_status
689 , p_reference_line_id => p_line_rec.service_reference_line_id
690 , p_customer_id => p_line_rec.sold_to_org_id
691 , x_cust_product_line_id => l_order_line_id
692 );
693 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
694 IF l_debug_level > 0 THEN
695 oe_debug_pub.add( 'SERVICE LINE ID IS ' || L_ORDER_LINE_ID ) ;
696 END IF;
697 l_service_reference_line_id := l_order_line_id;
698 ELSE
699 IF l_debug_level > 0 THEN
700 oe_debug_pub.add( 'NOT ABLE TO RETRIEVE CUST PRODUCT LINE ID' ) ;
701 END IF;
702 FND_MESSAGE.SET_NAME('ONT','ONT_NO_CUST_PROD_LINE');
703 OE_MSG_PUB.ADD;
704 RAISE NO_DATA_FOUND;
705 END IF;
706 end commenting for bug# 5032978 */
707 l_service_reference_line_id := NULL;
708
709 ELSE
710 l_service_reference_line_id := p_line_rec.service_reference_line_id;
711 END IF;
712 IF p_line_rec.item_type_code = 'SERVICE' AND l_service_reference_line_id IS NOT NULL THEN
713 BEGIN
714 /*Bug3261460*/
715 SELECT msi.SERVICEABLE_PRODUCT_FLAG
716 INTO l_serviceable_product_flag
717 FROM oe_order_lines_all ol, mtl_system_items msi
718 WHERE ol.line_id = l_service_reference_line_id
719 AND ol.inventory_item_id = msi.inventory_item_id
720 AND msi.organization_id = nvl(ol.ship_from_org_id, oe_sys_parameters.value('MASTER_ORGANIZATION_ID', ol.org_id));
721 EXCEPTION
722 WHEN NO_DATA_FOUND THEN
723 IF l_debug_level > 0 THEN
724 oe_debug_pub.add( 'IN NO DATA FOUND WHEN TRYING TO GET SERVICEABLE PRODUCT FLAG' ,5);
725 END IF;
726 l_serviceable_product_flag := 'Y';
727 WHEN OTHERS THEN
728 IF l_debug_level > 0 THEN
729 oe_debug_pub.add( 'UNABLE TO DEFINE SERVICEABLE PRODUCT '||SQLERRM , 1 ) ;
730 END IF;
731 RAISE NO_DATA_FOUND;
732 END;
733 ELSE
734 l_serviceable_product_flag := 'Y';
735 END IF;
736
737 IF (l_invoiceable_item_flag = 'N') OR
738 (l_invoice_enabled_flag = 'N') OR
739 (p_line_rec.item_type_code = 'SERVICE' AND l_serviceable_product_flag = 'N') THEN
740 IF l_debug_level > 0 THEN
741 oe_debug_pub.add( 'ITEM NOT INVOICEABLE ( 2 ) ' , 1 ) ;
742 END IF;
743 --bug5336639 start
744 G_CURRENT_LINE_ID := p_line_rec.line_id;
745 G_IS_CURR_LINE_INVOICEABLE := FALSE;
746 --bug5336639 end;
747 RETURN FALSE;
748 END IF;
749
750 IF p_line_rec.item_type_code = 'INCLUDED' THEN
751 IF l_debug_level > 0 THEN
752 oe_debug_pub.add( 'INCLUDED ITEM , NOT INVOICEABLE ( 3 ) ' , 1 ) ;
753 END IF;
754 --bug5336639 start
755 G_CURRENT_LINE_ID := p_line_rec.line_id;
756 G_IS_CURR_LINE_INVOICEABLE := FALSE;
757 --bug5336639 end;
758 RETURN FALSE;
759 END IF;
760
761 IF p_line_rec.item_type_code = 'CONFIG' THEN -- for bug# 5224264
762 IF l_debug_level > 0 THEN
763 oe_debug_pub.add( 'CONFIG ITEM , NOT INVOICEABLE ( 3 ) ' , 1 ) ;
764 END IF;
765 --bug5336639 start
766 G_CURRENT_LINE_ID := p_line_rec.line_id;
767 G_IS_CURR_LINE_INVOICEABLE := FALSE;
768 --bug5336639 end;
769 RETURN FALSE;
770 END IF;
771
772 IF Return_Line(p_line_rec) THEN
773 IF OE_LINE_UTIL.Get_Return_Item_Type_Code(p_line_rec) = 'CONFIG' OR
774 OE_LINE_UTIL.Get_Return_Item_Type_Code(p_line_rec) = 'INCLUDED' THEN
775 IF l_debug_level > 0 THEN
776 oe_debug_pub.add( 'ITEM NOT INVOICEABLE ( 4 ) ' , 1 ) ;
777 END IF;
778 --bug5336639 start
779 G_CURRENT_LINE_ID := p_line_rec.line_id;
780 G_IS_CURR_LINE_INVOICEABLE := FALSE;
781 --bug5336639 end;
782 RETURN FALSE;
783 END IF;
784
785 --Added for bug # 6945716 start
786 IF p_line_rec.line_category_code = 'RETURN'
787 AND(NVL(FND_PROFILE.VALUE('ONT_GENERATE_CREDIT_REJECTED_RETURNS'), 'N')='N'
788 AND NVL(p_line_rec.shipped_quantity,0) = 0
789 AND NVL(p_line_rec.fulfilled_quantity,0) = 0 ) THEN
790
791 IF l_debug_level > 0 THEN
792 oe_debug_pub.add( 'ITEM was Completely rejected, DO NOT Invoice ' , 1 ) ;
793 END IF;
794
795 RETURN FALSE;
796 END IF;
797 --Added for bug # 6945716 end
798 END IF;
799 IF l_debug_level > 0 THEN
800 oe_debug_pub.add( 'THIS LINE IS INVOICEABLE ( 5 ) ' , 5 ) ;
801 END IF;
802 --bug5336639 start
803 G_CURRENT_LINE_ID := p_line_rec.line_id;
804 G_IS_CURR_LINE_INVOICEABLE := TRUE;
805 --bug5336639 end;
806 RETURN TRUE;
807
808 EXCEPTION
809 WHEN NO_DATA_FOUND THEN
810 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
811 --RAISE FND_API.G_EXC_ERROR;
812 WHEN OTHERS THEN
813 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
814 THEN
815 IF l_debug_level > 0 THEN
816 oe_debug_pub.add( 'LINE_INVOICEABLE: WHEN OTHERS EXCEPTION '||SQLERRM , 1 ) ;
817 END IF;
818 OE_MSG_PUB.Add_Exc_Msg ( G_PKG_NAME ,'Line_Invoiceable');
819 END IF;
820 END Line_Invoiceable;
821
822 PROCEDURE Check_Invoicing_Holds
823 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
824 , p_itemtype IN VARCHAR2
825 , x_return_status OUT NOCOPY VARCHAR2
826 )
827 IS
828 l_hold_result_out VARCHAR2(30);
829 l_hold_return_status VARCHAR2(30);
830 l_hold_msg_count NUMBER;
831 l_hold_msg_data VARCHAR2(240);
832 --
833 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
834 --
835 BEGIN
836
837 -- We should honor invoice specific and generic holds
838 -- call to check_hold api to check for holds
839 IF l_debug_level > 0 THEN
840 oe_debug_pub.add( 'ENTER CHECK_INVOICING_HOLDS ' , 5 ) ;
841 END IF;
842 -- Check for Generic and invoice activity specific holds
843 -- IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
844 OE_HOLDS_PUB.CHECK_HOLDS(p_api_version => 1.0,
845 p_line_id => p_line_rec.line_id,
846 p_wf_item => OE_GLOBALS.G_WFI_LIN,
847 p_wf_activity => 'INVOICE_INTERFACE',
848 x_result_out => l_hold_result_out,
849 x_return_status => l_hold_return_status,
850 x_msg_count => l_hold_msg_count,
851 x_msg_data => l_hold_msg_data);
852 IF ( l_hold_return_status = FND_API.G_RET_STS_SUCCESS AND
853 l_hold_result_out = FND_API.G_TRUE )
854 THEN
855 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_HOLD');
856 OE_MSG_PUB.ADD;
857 x_return_status := FND_API.G_RET_STS_ERROR;
858 IF l_debug_level > 0 THEN
859 oe_debug_pub.add( 'A Line level Invoicing hold or generic hold found ( 1 ) , Return status : '||X_RETURN_STATUS , 1 ) ;
860 END IF;
861 RETURN;
862 ELSE
863 x_return_status := FND_API.G_RET_STS_SUCCESS;
864 END IF;
865 -- ELSIF p_itemtype = 'OEOH' THEN
866 OE_HOLDS_PUB.CHECK_HOLDS(p_api_version => 1.0,
867 p_line_id => p_line_rec.line_id,
868 p_wf_item => OE_GLOBALS.G_WFI_HDR,
869 p_wf_activity => 'HEADER_INVOICE_INTERFACE',
870 x_result_out => l_hold_result_out,
871 x_return_status => l_hold_return_status,
872 x_msg_count => l_hold_msg_count,
873 x_msg_data => l_hold_msg_data);
874
875 IF ( l_hold_return_status = FND_API.G_RET_STS_SUCCESS AND
876 l_hold_result_out = FND_API.G_TRUE )
877 THEN
878 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_HOLD');
879 OE_MSG_PUB.ADD;
880 x_return_status := FND_API.G_RET_STS_ERROR;
881 IF l_debug_level > 0 THEN
882 oe_debug_pub.add( 'A Header level Invoicing hold or generic hold found ( 2 ) , Return status '||X_RETURN_STATUS , 1 ) ;
883 END IF;
884 RETURN;
885 ELSE
886 x_return_status := FND_API.G_RET_STS_SUCCESS;
887 END IF;
888 -- END IF;
889 IF l_debug_level > 0 THEN
890 oe_debug_pub.add( 'NO HOLDS FOUND FOR THIS LINE ( 3 ) , RETURN STATUS '||X_RETURN_STATUS , 1 ) ;
891 END IF;
892 EXCEPTION
893 WHEN OTHERS THEN
894 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
895 IF FND_MSG_PUB.Check_Msg_Level
896 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
897 THEN
898 IF l_debug_level > 0 THEN
899 oe_debug_pub.add( 'Check_Invoicing_Holds: WHEN OTHERS EXCEPTION '||SQLERRM , 1 ) ;
900 END IF;
901 OE_MSG_PUB.Add_Exc_Msg ( G_PKG_NAME ,'Check_Invoicing_Holds');
902 END IF;
903 END Check_Invoicing_Holds;
904
905 FUNCTION Show_Detail_Discounts
906 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
907 ) RETURN BOOLEAN IS
908 l_price_adj_tbl OE_Header_Adj_Util.Line_Adjustments_Tab_Type;
909 --
910 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
911 --
912 l_header_id NUMBER;
913 l_line_id NUMBER;
914 BEGIN
915 IF l_debug_level > 0 THEN
916 oe_debug_pub.add( 'ENTER SHOW_DETAIL_DISCOUNTS ( ) ' , 5 ) ;
917 END IF;
918 -- sol_ord_er #16014165
919 If p_line_rec.service_bill_option_code = 'FPOM' then
920 IF l_debug_level > 0 THEN
921 oe_debug_pub.add( 'Billing Option set to First Period from OM, Subsequent from OKS' , 5 ) ;
922 END IF;
923 -- since OKS is involved in billing, Do not Show Discounts
924 RETURN FALSE;
925 END IF;
926 -- sol_ord_er #16014165 end
927 -- We should not depend on list price, selling price to determine if
928 -- there are any discounts. There is bug in pricing now.
929 -- Eventhough the discounts are not actually inserted into oe_price_adj table,
930 -- Selling price is adjusted to discounted price)
931 -- To avoid this look at adj table to see if there are any adjustments
932 -- IF p_line_rec.unit_list_price <> p_line_rec.unit_selling_price AND
933 IF (oe_sys_parameters.value('OE_DISCOUNT_DETAILS_ON_INVOICE',p_line_rec.org_id) = 'Y') THEN --moac
934 -- 3661895 The IF will be true only for return retrobilled RMA, all others will go through else
935 -- RT{
936 IF (p_line_rec.line_category_code = 'RETURN'
937 and p_line_rec.reference_line_id IS NOT NULL
938 and p_line_rec.retrobill_request_id IS NOT NULL) THEN
939
940 OE_RETROBILL_PVT.Get_Line_Adjustments
941 (p_line_rec => p_line_rec
942 ,x_line_adjustments => l_price_adj_tbl);
943 ELSE
944
945 OE_Header_Adj_Util.Get_Line_Adjustments
946 (p_header_id => p_line_rec.header_id
947 ,p_line_id => p_line_rec.line_id
948 ,x_line_adjustments => l_price_adj_tbl);
949 END IF;
950 -- RT}
951 IF l_debug_level > 0 THEN
952 oe_debug_pub.add( 'HEADER_ID : '||P_LINE_REC.HEADER_ID , 5 ) ;
953 oe_debug_pub.add( 'LINE_ID : '||P_LINE_REC.LINE_ID , 5 ) ;
954 oe_debug_pub.add( 'COUNT IS : '||L_PRICE_ADJ_TBL.COUNT , 5 ) ;
955 END IF;
956 IF l_price_adj_tbl.COUNT <> 0 THEN
957 IF l_debug_level > 0 THEN
958 oe_debug_pub.add( 'SHOW DETAIL DISCOUNTS IS ON' , 1 ) ;
959 END IF;
960 RETURN TRUE;
961 ELSE
962 IF l_debug_level > 0 THEN
963 oe_debug_pub.add( 'SHOW DETAIL DISCOUNTS IS OFF ( 1 ) ' , 1 ) ;
964 END IF;
965 RETURN FALSE;
966 END IF;
967 ELSE
968 IF l_debug_level > 0 THEN
969 oe_debug_pub.add( 'SHOW DETAIL DISCOUNTS IS OFF ( 2 ) ' , 1 ) ;
970 END IF;
971 RETURN FALSE;
972 END IF;
973 END Show_Detail_Discounts;
974
975 PROCEDURE Rounded_Amount
976 ( p_currency_code IN VARCHAR2
977 , p_unrounded_amount IN NUMBER
978 , x_rounded_amount OUT NOCOPY NUMBER
979 )
980 IS
981 l_precision NUMBER;
982 l_ext_precision NUMBER;
983 l_min_acct_unit NUMBER;
984 --
985 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
986 --
987 BEGIN
988
989 IF l_debug_level > 0 THEN
990 oe_debug_pub.add( 'ENTERING ROUNDED_AMOUNT ( ) ' , 5 ) ;
991 END IF;
992 FND_CURRENCY.GET_INFO(Currency_Code => p_currency_code,
993 precision => l_precision,
994 ext_precision => l_ext_precision,
995 min_acct_unit => l_min_acct_unit);
996
997 IF (l_min_acct_unit = 0 OR l_min_acct_unit IS NULL) THEN
998 x_rounded_amount := ROUND(p_unrounded_amount, l_precision);
999 ELSE
1000 x_rounded_amount := ROUND(p_unrounded_amount/l_min_acct_unit)*l_min_acct_unit;
1001 END IF;
1002 IF l_debug_level > 0 THEN
1003 oe_debug_pub.add( 'EXITING ROUNDED AMOUNT ( ) WITH AMOUNT : '||X_ROUNDED_AMOUNT , 5 ) ;
1004 END IF;
1005 END Rounded_Amount;
1006
1007 PROCEDURE Return_Credit_Info
1008 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1009 , x_credit_memo_type_id OUT NOCOPY NUMBER
1010 , x_credit_creation_sign OUT NOCOPY VARCHAR2
1011 )
1012 IS
1013 l_inv_cust_trx_type_id NUMBER;
1014 --
1015 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1016 --
1017 BEGIN
1018 IF l_debug_level > 0 THEN
1019 oe_debug_pub.add( ' ENTER RETURN CREDIT INFO ( ) ' , 5 ) ;
1020 END IF;
1021 --Hierarchy of retrieval:
1022 --1)Get cust_trx_type_id from referenced line.
1023 --2)Get cust_trx_type_id from referenced order.
1024 --3)Get cust_trx_type_id from that line.
1025 --4)Get cust_trx_type_id from that order.
1026 --5)Get cust_trx_type_id from PROFILE OPTION.
1027 IF p_line_rec.return_context = 'INVOICE' THEN
1028 IF l_debug_level > 0 THEN
1029 oe_debug_pub.add( ' RETURN TYPE IS INVOICE ' , 5 ) ;
1030 END IF;
1031 OE_DEBUG_PUB.DUMPDEBUG;
1032 -- Introducing this pl/sql block #3349781
1033 BEGIN
1034 SELECT nvl(ctt.credit_memo_type_id, 0),
1035 ctt_credit.creation_sign
1036 INTO x_credit_memo_type_id, x_credit_creation_sign
1037 FROM ra_customer_trx_lines_all ctl,
1038 ra_customer_trx_all ct,
1039 ra_cust_trx_types_all ctt,
1040 ra_cust_trx_types_all ctt_credit
1041 WHERE ctl.customer_trx_line_id = p_line_rec.reference_customer_trx_line_id
1042 AND ct.customer_trx_id = ctl.customer_trx_id
1043 AND ctt.cust_trx_type_id = ct.cust_trx_type_id
1044 AND ctt_credit.cust_trx_type_id = ctt.credit_memo_type_id
1045 AND NVL(ctt.org_id, -3114) = NVL(ctl.org_id, -3114)
1046 /* DECODE(ctt.cust_trx_type_id,
1047 1, -3113,
1048 2, -3113,
1049 7, -3113,
1050 8, -3113,
1051 NVL(ctl.org_id, -3114)) Commented for the bug 3027150 */
1052 AND NVL(ctt_credit.org_id, -3114) = NVL(ctl.org_id, -3114);
1053 /* DECODE(ctt_credit.cust_trx_type_id,
1054 1, -3113,
1055 2, -3113,
1056 7, -3113,
1057 8, -3113,
1058 NVL(ctl.org_id, -3114)); Commented for the bug 3027150 */
1059 -- cust_trx_type_id 1,2,7,8 (for Invoice, Credit Memo, PA Invoice, PA Credit memo) are seeded with org_id -3113
1060 EXCEPTION WHEN NO_DATA_FOUND THEN
1061 OE_DEBUG_PUB.add('Unable to derive credit memo type id from referenced order line, verify setup',1);
1062 x_credit_memo_type_id:= 0;
1063 x_credit_creation_sign := NULL;
1064 NULL;
1065 END;
1066
1067 IF l_debug_level > 0 THEN
1068 oe_debug_pub.add( 'CREDIT_MEMO_TYPE_ID FROM INVOICE : '||X_CREDIT_MEMO_TYPE_ID , 5 ) ;
1069 END IF;
1070 ELSIF p_line_rec.return_context in ('PO', 'ORDER', 'SERIAL') THEN
1071 IF l_debug_level > 0 THEN
1072 oe_debug_pub.add( ' RETURN TYPE IS PO/ORDER/SERIAL' , 5 ) ;
1073 END IF;
1074 OE_DEBUG_PUB.DUMPDEBUG;
1075 -- Get cust_trx_type_id from line type
1076 --Bug2293944 Get information from the reference line or reference order.
1077 SELECT NVL(lt.cust_trx_type_id, 0)
1078 INTO l_inv_cust_trx_type_id
1079 FROM oe_line_types_v lt
1080 WHERE lt.line_type_id = (SELECT line_type_id
1081 FROM oe_order_lines_all /* MOAC SQL CHANGE */
1082 WHERE line_id = p_line_rec.reference_line_id);
1083 IF l_debug_level > 0 THEN
1084 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM REFERENCE LINE TYPE : '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1085 END IF;
1086 IF l_inv_cust_trx_type_id = 0 THEN
1087 SELECT NVL(ot.cust_trx_type_id,0)
1088 INTO l_inv_cust_trx_type_id
1089 FROM oe_order_types_v ot,
1090 oe_order_headers_all oh /* MOAC SQL CHANGE */
1091 WHERE ot.order_type_id = oh.order_type_id
1092 AND oh.header_id = (SELECT header_id
1093 FROM oe_order_lines_all /* MOAC SQL CHANGE */
1094 WHERE line_id = p_line_rec.reference_line_id);
1095 END IF;
1096 IF l_debug_level > 0 THEN
1097 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM REFERENCE ORDER TYPE : '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1098 END IF;
1099 ELSE
1100 IF l_debug_level > 0 THEN
1101 oe_debug_pub.add( 'RETURN TYPE : '||P_LINE_REC.RETURN_CONTEXT , 5 ) ;
1102 END IF;
1103 x_credit_memo_type_id:= 0;
1104 x_credit_creation_sign := NULL;
1105 END IF;
1106 IF (l_inv_cust_trx_type_id = 0 or x_credit_memo_type_id = 0)THEN
1107 --use cache instead of SQL for bug 4200055
1108 IF ( p_line_rec.line_type_id is not null
1109 AND p_line_rec.line_type_id <> FND_API.G_MISS_NUM ) THEN
1110 if (OE_Order_Cache.g_line_type_rec.line_type_id <> p_line_rec.Line_Type_id) THEN
1111 OE_Order_Cache.Load_Line_type(p_line_rec.Line_Type_id) ;
1112 end if ;
1113 if (OE_Order_Cache.g_line_type_rec.line_type_id = p_line_rec.Line_Type_id )
1114 then
1115 l_inv_cust_trx_type_id := nvl(OE_Order_Cache.g_line_type_rec.cust_trx_type_id,0);
1116 else
1117 l_inv_cust_trx_type_id := 0 ;
1118 end if ;
1119 ELSE
1120 l_inv_cust_trx_type_id := 0 ;
1121 END IF ;
1122 /*SELECT NVL(lt.cust_trx_type_id,0)
1123 INTO l_inv_cust_trx_type_id
1124 FROM oe_line_types_v lt
1125 WHERE lt.line_type_id = p_line_rec.line_type_id; */
1126 -- end bug 4200055
1127 IF l_debug_level > 0 THEN
1128 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM LINE TYPE : '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1129 END IF;
1130 IF l_inv_cust_trx_type_id = 0 THEN
1131 -- Get cust_trx_type_id from order type
1132 SELECT NVL(ot.cust_trx_type_id, 0)
1133 INTO l_inv_cust_trx_type_id
1134 FROM oe_order_types_v ot,
1135 oe_order_headers_all oh /* MOAC SQL CHANGE */
1136 WHERE ot.order_type_id = oh.order_type_id
1137 AND oh.header_id = p_line_rec.header_id;
1138 END IF;
1139 IF l_debug_level > 0 THEN
1140 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM ORDER TYPE : '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1141 END IF;
1142 END IF;
1143 IF l_inv_cust_trx_type_id <> 0 THEN -- cust_trx_type_id exists at line/order type
1144 IF l_debug_level > 0 THEN
1145 oe_debug_pub.add( 'CUST_TRX_TYPE_ID FROM LINE/ORDER TYPE: '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1146 END IF;
1147 -- Introducing this pl/sql block #3349781
1148 BEGIN
1149 SELECT NVL(ctt.credit_memo_type_id, 0),
1150 ctt_credit.creation_sign
1151 INTO x_credit_memo_type_id, x_credit_creation_sign
1152 FROM ra_cust_trx_types_all ctt,
1153 ra_cust_trx_types_all ctt_credit
1154 WHERE ctt.cust_trx_type_id = l_inv_cust_trx_type_id
1155 AND ctt_credit.cust_trx_type_id = ctt.credit_memo_type_id
1156 AND NVL(ctt.org_id, -3114) = NVL(p_line_rec.org_id, -3114)
1157 /* DECODE(ctt.cust_trx_type_id,
1158 1, -3113,
1159 2, -3113,
1160 7, -3113,
1161 8, -3113,
1162 NVL(p_line_rec.org_id, -3114)) Commented for the bug 3027150 */
1163 AND NVL(ctt_credit.org_id, -3114) = NVL(p_line_rec.org_id, -3114);
1164 /* DECODE(ctt_credit.cust_trx_type_id,
1165 1, -3113,
1166 2, -3113,
1167 7, -3113,
1168 8, -3113,
1169 NVL(p_line_rec.org_id, -3114)); Commented for the bug 3027150 */
1170 EXCEPTION WHEN NO_DATA_FOUND THEN
1171 OE_DEBUG_PUB.add('Unable to derive credit memo type id from order line, verify setup',1);
1172 x_credit_memo_type_id:= 0;
1173 x_credit_creation_sign := NULL;
1174 NULL;
1175 END;
1176
1177 IF l_debug_level > 0 THEN
1178 oe_debug_pub.add( 'CREDIT MEMO TYPE : '||X_CREDIT_MEMO_TYPE_ID , 5 ) ;
1179 END IF;
1180 -- cust_trx_type_id 1,2,7,8 (for Invoice, Credit Memo, PA Invoice, PA Credit memo) are seeded with org_id -3113
1181 END IF;
1182 IF l_inv_cust_trx_type_id = 0 OR x_credit_memo_type_id = 0 THEN
1183 -- no cust_trx_type_id at line/order type
1184 IF l_debug_level > 0 THEN
1185 oe_debug_pub.add( 'NO CUST TRX TYPE AT ORDER OR LINE TYPE LEVEL' , 5 ) ;
1186 END IF;
1187 x_credit_memo_type_id := 0;
1188 x_credit_creation_sign := NULL;
1189 END IF;
1190
1191 IF l_debug_level > 0 THEN
1192 oe_debug_pub.add( 'CREDIT MEMO TYPE ID : '||X_CREDIT_MEMO_TYPE_ID , 5 ) ;
1193 END IF;
1194 IF l_debug_level > 0 THEN
1195 oe_debug_pub.add( 'CREATION_SIGN : '||X_CREDIT_CREATION_SIGN , 5 ) ;
1196 oe_debug_pub.add( ' EXITING RETURN_CREDIT_INFO ( ) ' , 1 ) ;
1197 END IF;
1198 EXCEPTION
1199 WHEN NO_DATA_FOUND THEN
1200 IF l_debug_level > 0 THEN
1201 oe_debug_pub.add( 'EXCEPTION. EXITING RETURN_CREDIT_INFO ( 1 ) '||SQLERRM , 1 ) ;
1202 END IF;
1203 x_credit_memo_type_id := 0;
1204 x_credit_creation_sign := NULL;
1205 WHEN TOO_MANY_ROWS THEN
1206 IF l_debug_level > 0 THEN
1207 oe_debug_pub.add( 'EXCEPTION. EXITING RETURN_CREDIT_INFO ( 2 ) '||SQLERRM , 1 ) ;
1208 END IF;
1209 x_credit_memo_type_id := 0;
1210 x_credit_creation_sign := NULL;
1211 WHEN OTHERS THEN
1212 IF l_debug_level > 0 THEN
1213 oe_debug_pub.add( 'EXCEPTION. EXITING RETURN_CREDIT_INFO ( 3 ) '||SQLERRM , 1 ) ;
1214 END IF;
1215 x_credit_memo_type_id := 0;
1216 x_credit_creation_sign := NULL;
1217 END Return_Credit_Info;
1218
1219 FUNCTION Get_Credit_Creation_Sign
1220 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1221 , p_cust_trx_type_id IN NUMBER)
1222 RETURN VARCHAR2 IS
1223 l_creation_sign VARCHAR2(30):= NULL;
1224 --
1225 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1226 --
1227 BEGIN
1228 IF l_debug_level > 0 THEN
1229 oe_debug_pub.add( 'ENTERING GET_CREDIT_CREATION_SIGN' , 5 ) ;
1230 END IF;
1231 IF p_cust_trx_type_id IS NOT NULL AND p_cust_trx_type_id <> 0 THEN
1232 SELECT creation_sign
1233 INTO l_creation_sign
1234 FROM ra_cust_trx_types
1235 WHERE cust_trx_type_id = p_Cust_Trx_Type_Id;
1236 END IF;
1237 IF l_debug_level > 0 THEN
1238 oe_debug_pub.add( 'CREATION_SIGN: '||L_CREATION_SIGN ) ;
1239 oe_debug_pub.add( 'EXITING GET_CREDIT_CREATION_SIGN ( 1 ) '||' SIGN= '||L_CREATION_SIGN , 1 ) ;
1240 END IF;
1241 RETURN(l_creation_sign);
1242
1243 EXCEPTION
1244 WHEN OTHERS THEN
1245 IF l_debug_level > 0 THEN
1246 oe_debug_pub.add( 'EXCEPTION. EXITING GET_CREDIT_CREATION_SIGN ( 1 ) '||SQLERRM , 1 ) ;
1247 END IF;
1248 RETURN(NULL);
1249 END Get_Credit_Creation_Sign;
1250
1251 PROCEDURE Get_Commitment_Info
1252 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1253 , x_commitment_applied OUT NOCOPY NUMBER
1254 , x_commitment_interfaced OUT NOCOPY NUMBER)
1255 IS
1256 --
1257 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1258 --
1259 BEGIN
1260 IF l_debug_level > 0 THEN
1261 oe_debug_pub.add( 'ENTERING GET_COMMITMENT_INFO' , 5 ) ;
1262 END IF;
1263 IF p_line_rec.commitment_id IS NOT NULL THEN
1264 --serla begin
1265 IF OE_PrePayment_UTIL.IS_MULTIPLE_PAYMENTS_ENABLED THEN
1266 SELECT nvl(commitment_applied_amount, 0)
1267 ,nvl(commitment_interfaced_amount, 0)
1268 INTO x_commitment_applied
1269 ,x_commitment_interfaced
1270 FROM oe_payments
1271 WHERE payment_trx_id = p_line_rec.commitment_id
1272 AND payment_type_code = 'COMMITMENT'
1273 AND line_id = p_line_rec.line_id;
1274 ELSE
1275 --serla end
1276 SELECT nvl(commitment_applied_amount, 0)
1277 ,nvl(commitment_interfaced_amount, 0)
1278 INTO x_commitment_applied
1279 ,x_commitment_interfaced
1280 FROM oe_payments
1281 WHERE payment_trx_id = p_line_rec.commitment_id
1282 AND line_id = p_line_rec.line_id;
1283 --serla begin
1284 END IF;
1285 --serla end
1286 END IF;
1287 IF l_debug_level > 0 THEN
1288 oe_debug_pub.add( ' COMMITMENT APPLIED : '||X_COMMITMENT_APPLIED , 1 ) ;
1289 oe_debug_pub.add( ' COMMITMENT INTERFACED :'||X_COMMITMENT_INTERFACED , 1 ) ;
1290 END IF;
1291 EXCEPTION
1292 WHEN OTHERS THEN
1293 IF l_debug_level > 0 THEN
1294 oe_debug_pub.add( 'EXCEPTION. EXITING GET_COMMITMENT_INFO ( 1 ) '||SQLERRM , 1 ) ;
1295 END IF;
1296 x_commitment_applied := NULL;
1297 x_commitment_interfaced := NULL;
1298 END Get_Commitment_Info;
1299
1300 PROCEDURE Get_Item_Description
1301 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1302 , x_item_description OUT NOCOPY VARCHAR2
1303 ) IS
1304 -- bug#12645586, l_organization_id NUMBER := oe_sys_parameters.value('MASTER_ORGANIZATION_ID', p_line_rec.org_id);
1305 l_organization_id NUMBER := nvl(p_line_rec.ship_from_org_id,
1306 oe_sys_parameters.value('MASTER_ORGANIZATION_ID', p_line_rec.org_id)); -- Added for bug#12645586
1307 --
1308 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1309 --
1310 l_item_description VARCHAR2(240) := null ;
1311 BEGIN
1312 IF l_debug_level > 0 THEN
1313 oe_debug_pub.add( ' ENTERING GET_ITEM_DESCRIPTION ( ) ' , 5 ) ;
1314 oe_debug_pub.add( ' Item Identifier Type :'||p_line_rec.item_identifier_type);
1315 oe_debug_pub.add('Inventory Item ID '||p_line_rec.inventory_item_id,5);
1316 oe_debug_pub.add('Organization ID '||l_organization_ID,5);
1317 oe_debug_pub.add('Ordered Item ID '||p_line_rec.ordered_item_id);
1318 END IF;
1319 IF nvl(p_line_rec.item_identifier_type,'INT') = 'INT' THEN -- Bug #3684306
1320 SELECT description
1321 INTO x_item_description
1322 FROM mtl_system_items_vl
1323 WHERE inventory_item_id =p_line_rec.inventory_item_id
1324 AND organization_id = l_organization_id;
1325 ELSIF nvl(p_line_rec.item_identifier_type,'INT') = 'CUST' THEN -- Bug #3684306
1326 -- changes for bug 4237123
1327 /*SELECT nvl(citems.customer_item_desc, sitems.description)
1328 INTO x_item_description
1329 FROM mtl_customer_items citems
1330 ,mtl_customer_item_xrefs cxref
1331 ,mtl_system_items_vl sitems
1332 WHERE citems.customer_item_id = cxref.customer_item_id
1333 AND cxref.inventory_item_id = sitems.inventory_item_id
1334 AND sitems.inventory_item_id = p_line_rec.inventory_item_id
1335 AND sitems.organization_id = l_organization_id
1336 AND citems.customer_item_id = p_line_rec.ordered_item_id
1337 AND citems.customer_id = p_line_rec.sold_to_org_id; */
1338
1339 SELECT citems.customer_item_desc INTO l_item_description
1340 FROM mtl_customer_items citems
1341 WHERE citems.customer_item_id = p_line_rec.ordered_item_id
1342 AND citems.customer_id = p_line_rec.sold_to_org_id;
1343 if l_item_description is null then
1344 SELECT sitems.description INTO l_item_description
1345 FROM mtl_system_items_vl sitems
1346 WHERE sitems.inventory_item_id = p_line_rec.inventory_item_id
1347 and sitems.organization_id = l_organization_id ;
1348 end if ;
1349 x_item_description := l_item_description ;
1350 ELSE
1351 SELECT nvl(items.description, sitems.description)
1352 INTO x_item_description
1353 FROM mtl_cross_reference_types types
1354 , mtl_cross_references items
1355 , mtl_system_items_vl sitems
1356 WHERE types.cross_reference_type = items.cross_reference_type
1357 AND items.inventory_item_id = sitems.inventory_item_id
1358 AND sitems.organization_id = l_organization_id
1359 AND sitems.inventory_item_id = p_line_rec.inventory_item_id
1360 AND items.cross_reference_type = p_line_rec.item_identifier_type
1361 AND items.cross_reference = p_line_rec.ordered_item
1362 AND ROWNUM = 1; -- Bug3333235
1363 END IF;
1364 IF l_debug_level > 0 THEN
1365 oe_debug_pub.add( 'ITEM_DESCRIPTION : '||X_ITEM_DESCRIPTION ) ;
1366 oe_debug_pub.add( ' EXITING GET_ITEM_DESCRIPTION: '||X_ITEM_DESCRIPTION , 1 ) ;
1367 END IF;
1368 EXCEPTION
1369 WHEN NO_DATA_FOUND THEN --added for bug 4191624
1370 IF l_debug_level > 0 THEN
1371 oe_debug_pub.add('When no data found then get desc from system items '||SQLERRM,1);
1372 END IF;
1373 SELECT sitems.description
1374 INTO x_item_description
1375 FROM mtl_system_items_vl sitems
1376 WHERE sitems.inventory_item_id = p_line_rec.inventory_item_id
1377 and sitems.organization_id = l_organization_id ;
1378 WHEN OTHERS THEN
1379 IF l_debug_level > 0 THEN
1380 oe_debug_pub.add( 'EXCEPTION. GET ITEM DESCRIPTION '||SQLERRM , 1 ) ;
1381 END IF;
1382 NULL;
1383 END Get_Item_Description;
1384
1385 PROCEDURE Get_Service_Item_Description
1386 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1387 , x_item_description OUT NOCOPY VARCHAR2
1388 ) IS
1389 l_line_rec OE_Order_Pub.Line_Rec_Type;
1390 l_order_line_id NUMBER;
1391 l_return_status VARCHAR2(1);
1392 l_service_reference_line_id NUMBER;
1393 l_service_item_desc VARCHAR2(240);
1394 l_item_serviced_desc VARCHAR2(240) := null;
1395
1396 /*Bug3261460-start*/
1397 l_inventory_item_id NUMBER;
1398 l_ordered_item_id NUMBER;
1399 l_sold_to_org_id NUMBER;
1400 l_item_identifier_type VARCHAR2(30);
1401 l_ordered_item VARCHAR2(2000);
1402 l_org_id NUMBER;
1403 /*Bug3261460-end*/
1404
1405 l_organization_id NUMBER := oe_sys_parameters.value('MASTER_ORGANIZATION_ID', p_line_rec.org_id);
1406 --
1407 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1408 --
1409 BEGIN
1410 IF l_debug_level > 0 THEN
1411 oe_debug_pub.add( ' ENTERING GET SERVICE ITEM DESCRIPTION ( ) ' , 5 ) ;
1412 END IF;
1413 IF p_line_rec.item_type_code = 'SERVICE' AND
1414 p_line_rec.service_reference_type_code='CUSTOMER_PRODUCT' AND
1415 p_line_rec.service_reference_line_id IS NOT NULL THEN
1416 IF l_debug_level > 0 THEN
1417 oe_debug_pub.add( 'REFERENCED BY CUSTOMER PRODUCT' , 5 ) ;
1418 END IF;
1419 /* Commenting for bug# 5032978
1420 OE_SERVICE_UTIL.Get_Cust_Product_Line_Id
1421 ( x_return_status => l_return_status
1422 , p_reference_line_id => p_line_rec.service_reference_line_id
1423 , p_customer_id => p_line_rec.sold_to_org_id
1424 , x_cust_product_line_id => l_order_line_id
1425 );
1426 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
1427 IF l_debug_level > 0 THEN
1428 oe_debug_pub.add( 'SERVICE LINE ID IS : ' || L_ORDER_LINE_ID , 5 ) ;
1429 END IF;
1430 l_service_reference_line_id := l_order_line_id;
1431 ELSE
1432 IF l_debug_level > 0 THEN
1433 oe_debug_pub.add( 'NOT ABLE TO RETRIEVE CUST PRODUCT LINE ID '||SQLERRM , 1 ) ;
1434 END IF;
1435 RAISE NO_DATA_FOUND;
1436 END IF;
1437 end commenting for bug# 5032978 */
1438 l_service_reference_line_id := NULL;
1439 ELSE
1440 l_service_reference_line_id := p_line_rec.service_reference_line_id;
1441 END IF;
1442 Get_Item_Description(p_line_rec, l_service_item_desc);
1443 IF l_service_reference_line_id IS NOT NULL THEN
1444 /*Bug3261460-Changes made to get the serviced item description*/
1445 -- l_line_rec := OE_LINE_UTIL.Query_Row(l_service_reference_line_id);
1446 -- Get_Item_Description(l_line_rec, l_item_serviced_desc);
1447 BEGIN
1448 select inventory_item_id,ordered_item_id,sold_to_org_id,item_identifier_type,ordered_item,org_id
1449 into l_inventory_item_id,l_ordered_item_id,l_sold_to_org_id,l_item_identifier_type,l_ordered_item,l_org_id
1450 from OE_ORDER_LINES_ALL
1451 where line_id = l_service_reference_line_id;
1452 EXCEPTION
1453 WHEN NO_DATA_FOUND THEN
1454 IF l_debug_level > 0 THEN
1455 oe_debug_pub.add( 'NOT ABLE TO GET SERVICE LINE DETAILS', 1);
1456 END IF;
1457 l_item_identifier_type := NULL;
1458 l_inventory_item_id := NULL;
1459 l_organization_id := NULL;
1460 END;
1461 l_organization_id := oe_sys_parameters.value('MASTER_ORGANIZATION_ID', l_org_id);
1462 oe_debug_pub.add('Executed the first sql',1);
1463 BEGIN -- added for bug 4237123
1464 IF nvl(l_item_identifier_type,'INT') = 'INT' THEN -- Bug #3684306
1465 oe_debug_pub.add('Item identifier type is INT',1);
1466 BEGIN
1467 SELECT description
1468 INTO l_item_serviced_desc
1469 FROM mtl_system_items_vl
1470 WHERE inventory_item_id =l_inventory_item_id
1471 AND organization_id = l_organization_id;
1472 EXCEPTION
1473 WHEN NO_DATA_FOUND THEN
1474 IF l_debug_level > 0 THEN
1475 oe_debug_pub.add( 'NO DATA FOUND IN SERVICE ITEM DESCRIPTION');
1476 END IF;
1477 l_item_serviced_desc := NULL;
1478 END;
1479 ELSIF nvl(l_item_identifier_type,'INT') = 'CUST' THEN -- Bug #3684306
1480 oe_debug_pub.add('Item Identifier typs is CUST',1);
1481 -- changes for bug 4237123
1482 /*SELECT nvl(citems.customer_item_desc, sitems.description)
1483 INTO l_item_serviced_desc
1484 FROM mtl_customer_items citems
1485 ,mtl_customer_item_xrefs cxref
1486 ,mtl_system_items_vl sitems
1487 WHERE citems.customer_item_id = cxref.customer_item_id
1488 AND cxref.inventory_item_id = sitems.inventory_item_id
1489 AND sitems.inventory_item_id = l_inventory_item_id
1490 AND sitems.organization_id = l_organization_id
1491 AND citems.customer_item_id = l_ordered_item_id
1492 AND citems.customer_id = l_sold_to_org_id; */
1493
1494 SELECT citems.customer_item_desc INTO l_item_serviced_desc
1495 FROM mtl_customer_items citems
1496 WHERE citems.customer_item_id = l_ordered_item_id
1497 AND citems.customer_id = l_sold_to_org_id;
1498 if l_item_serviced_desc is null then
1499 SELECT sitems.description INTO l_item_serviced_desc
1500 FROM mtl_system_items_vl sitems
1501 WHERE sitems.inventory_item_id = l_inventory_item_id
1502 and sitems.organization_id = l_organization_id ;
1503 end if ;
1504 ELSE
1505 oe_debug_pub.add('In else part of item identifier type',1);
1506 SELECT nvl(items.description, sitems.description)
1507 INTO l_item_serviced_desc
1508 FROM mtl_cross_reference_types types
1509 , mtl_cross_references items
1510 , mtl_system_items_vl sitems
1511 WHERE types.cross_reference_type = items.cross_reference_type
1512 AND items.inventory_item_id = sitems.inventory_item_id
1513 AND sitems.organization_id = l_organization_id
1514 AND sitems.inventory_item_id = l_inventory_item_id
1515 AND items.cross_reference_type = l_item_identifier_type
1516 AND items.cross_reference = l_ordered_item
1517 AND ROWNUM = 1; -- added for Bug 7583908
1518 END IF;
1519 OE_DEBUG_PUB.ADD('Item_Description of serviced item: '||l_item_serviced_desc);
1520 EXCEPTION --aded for bug 4237123
1521 WHEN NO_DATA_FOUND THEN
1522 IF l_debug_level > 0 THEN
1523 oe_debug_pub.add('When no data found then get desc from system items '||SQLERRM,1);
1524 END IF;
1525 SELECT sitems.description
1526 INTO l_item_serviced_desc
1527 FROM mtl_system_items_vl sitems
1528 WHERE sitems.inventory_item_id = l_inventory_item_id
1529 and sitems.organization_id = l_organization_id ;
1530 END ;
1531 END IF;
1532 x_item_description := substr(l_service_item_desc,1,90)||' - '||
1533 p_line_rec.ordered_quantity
1534 ||' '||substr(l_item_serviced_desc,1,90)||': '
1535 ||p_line_rec.service_start_date||' - '||p_line_rec.service_end_date ;
1536
1537 IF l_debug_level > 0 THEN
1538 oe_debug_pub.add( 'SERVICE ITEM_DESCRIPTION: '||X_ITEM_DESCRIPTION ) ;
1539 oe_debug_pub.add( ' EXITING GET_SERVICE_ITEM_DESCRIPTION: '||X_ITEM_DESCRIPTION , 1 ) ;
1540 END IF;
1541 EXCEPTION
1542 WHEN OTHERS THEN
1543 IF l_debug_level > 0 THEN
1544 oe_debug_pub.add( 'EXCEPTION. GET SERVICE ITEM DESCRIPTION ( ) '||SQLERRM , 1 ) ;
1545 END IF;
1546 NULL;
1547 END Get_Service_Item_Description;
1548
1549 FUNCTION Get_Overship_Invoice_Basis
1550 (p_line_rec IN OE_Order_Pub.Line_Rec_Type)
1551 RETURN VARCHAR2
1552 IS
1553 l_overship_invoice_basis VARCHAR2(30):= NULL;
1554 --
1555 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1556 --
1557 BEGIN
1558 /*
1559 Get l_overship_invoice_basis from control set
1560 1. Item
1561 2. Ship_to_site
1562 3. Customer
1563 4.Profile
1564 */
1565 IF l_debug_level > 0 THEN
1566 oe_debug_pub.add( ' ENTERING GET_OVERSHIP_INVOICE_BASIS' , 5 ) ;
1567 END IF;
1568 IF p_line_rec.ship_to_org_id IS NOT NULL THEN
1569 SELECT invoice_quantity_rule
1570 INTO l_overship_invoice_basis
1571 FROM hz_cust_site_uses
1572 WHERE site_use_id = p_line_rec.ship_to_org_id
1573 AND site_use_code = 'SHIP_TO';
1574 IF l_debug_level > 0 THEN
1575 oe_debug_pub.add( 'OVERSHIP_INVOICE_BASIS ( 2 ) : '||L_OVERSHIP_INVOICE_BASIS , 5 ) ;
1576 END IF;
1577 END IF;
1578 IF l_overship_invoice_basis IS NULL THEN
1579 IF p_line_rec.sold_to_org_id IS NOT NULL THEN
1580 SELECT invoice_quantity_rule
1581 INTO l_overship_invoice_basis
1582 FROM hz_cust_accounts
1583 WHERE cust_account_id = p_line_rec.sold_to_org_id;
1584 IF l_debug_level > 0 THEN
1585 oe_debug_pub.add( 'OVERSHIP_INVOICE_BASIS ( 1 ) : '||L_OVERSHIP_INVOICE_BASIS , 5 ) ;
1586 END IF;
1587 END IF;
1588 END IF;
1589 IF l_overship_invoice_basis IS NULL THEN
1590 l_overship_invoice_basis := oe_sys_parameters.value('OE_OVERSHIP_INVOICE_BASIS',p_line_rec.org_id); --moac
1591 IF l_debug_level > 0 THEN
1592 oe_debug_pub.add( 'OVERSHIP_INVOICE_BASIS ( 3 ) : '||L_OVERSHIP_INVOICE_BASIS , 5 ) ;
1593 END IF;
1594 END IF;
1595 IF l_debug_level > 0 THEN
1596 oe_debug_pub.add( 'OVERSHIP_INVOICE_BASIS: '||L_OVERSHIP_INVOICE_BASIS , 5 ) ;
1597 oe_debug_pub.add( ' EXITING GET_OVERSHIP_INVOICE_BASIS: '||L_OVERSHIP_INVOICE_BASIS , 5 ) ;
1598 END IF;
1599 RETURN l_overship_invoice_basis;
1600
1601 END Get_Overship_Invoice_Basis;
1602
1603 FUNCTION Get_Invoice_Source
1604 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1605 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
1606 )
1607 RETURN VARCHAR2
1608 IS
1609 l_invoice_source_id NUMBER := NULL;
1610 l_invoice_source VARCHAR2(50):= NULL;
1611 --
1612 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1613 --
1614 BEGIN
1615 IF l_debug_level > 0 THEN
1616 oe_debug_pub.add( ' ENTERING GET_INVOICE_SOURCE' , 5 ) ;
1617 END IF;
1618 IF FND_PROFILE.VALUE('WSH_INVOICE_NUMBERING_METHOD')= 'D' AND
1619 (Return_Line(p_line_rec) OR NOT Shipping_Info_Available(p_line_rec) OR
1620 (p_interface_line_rec.interface_line_attribute3 = '0')) THEN
1621 SELECT NVL(lt.non_delivery_invoice_source_id,
1622 ot.non_delivery_invoice_source_id)
1623 INTO l_invoice_source_id
1624 FROM oe_line_types_v lt,
1625 oe_order_types_v ot,
1626 oe_order_headers_all oh /* MOAC SQL CHANGE */
1627 WHERE lt.line_type_id = p_line_rec.line_type_id
1628 AND ot.order_type_id = oh.order_type_id
1629 AND oh.header_id = p_line_rec.header_id;
1630 IF l_invoice_source_id IS NOT NULL THEN
1631 SELECT name
1632 INTO l_invoice_source
1633 FROM ra_batch_sources
1634 WHERE batch_source_id = l_invoice_source_id;
1635 IF l_debug_level > 0 THEN
1636 oe_debug_pub.add( 'INVOICE_SOURCE IS ( 1 ) : '||L_INVOICE_SOURCE , 5 ) ;
1637 END IF;
1638 RETURN l_invoice_source;
1639 ELSE
1640 l_invoice_source := oe_sys_parameters.value('OE_NON_DELIVERY_INVOICE_SOURCE',p_line_rec.org_id); --moac
1641 IF l_debug_level > 0 THEN
1642 oe_debug_pub.add( 'INVOICE_SOURCE IS ( 2 ) : '||L_INVOICE_SOURCE , 5 ) ;
1643 END IF;
1644 RETURN l_invoice_source;
1645 END IF;
1646 ELSE -- Invoice numbering method is 'Automatic' OR 'delivery' with shipping information available
1647 SELECT NVL(lt.invoice_source_id,
1648 ot.invoice_source_id)
1649 INTO l_invoice_source_id
1650 FROM oe_line_types_v lt,
1651 oe_order_types_v ot,
1652 oe_order_headers_all oh /* MOAC SQL CHANGE */
1653 WHERE lt.line_type_id = p_line_rec.line_type_id
1654 AND ot.order_type_id = oh.order_type_id
1655 AND oh.header_id = p_line_rec.header_id;
1656 IF l_invoice_source_id IS NOT NULL THEN
1657 SELECT name
1658 INTO l_invoice_source
1659 FROM ra_batch_sources
1660 WHERE batch_source_id = l_invoice_source_id;
1661 IF l_debug_level > 0 THEN
1662 oe_debug_pub.add( 'INVOICE SOURCE IS ( 3 ) : '||L_INVOICE_SOURCE , 5 ) ;
1663 END IF;
1664 RETURN l_invoice_source;
1665 ELSE
1666 l_invoice_source := oe_sys_parameters.value('OE_INVOICE_SOURCE',p_line_rec.org_id); --moac
1667 IF l_debug_level > 0 THEN
1668 oe_debug_pub.add( 'INVOICE_SOURCE IS ( 4 ) : '||L_INVOICE_SOURCE , 5 ) ;
1669 END IF;
1670 RETURN l_invoice_source;
1671 END IF;
1672 END IF;
1673 EXCEPTION
1674 WHEN OTHERS THEN
1675 IF l_debug_level > 0 THEN
1676 oe_debug_pub.add( 'In Others of Function Get_Invoice_Source', 5);
1677 END IF;
1678 RETURN l_invoice_source;
1679 END Get_Invoice_Source;
1680
1681 FUNCTION Get_Customer_Transaction_Type
1682 ( p_record IN OE_AK_ORDER_LINES_V%ROWTYPE
1683 ) RETURN NUMBER IS
1684 l_inv_cust_trx_type_id NUMBER;
1685 l_cust_trx_type_id NUMBER;
1686 l_creation_sign VARCHAR2(30);
1687 l_line_rec OE_Order_Pub.Line_Rec_Type;
1688 --
1689 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1690 --
1691 BEGIN
1692 IF l_debug_level > 0 THEN
1693 oe_debug_pub.add( ' ENTER GET_CUSTOMER_TRANSACTION_TYPE' , 5 ) ;
1694 END IF;
1695 IF l_debug_level > 0 THEN
1696 oe_debug_pub.add( 'Before the call to Rowtype_Rec_To_API_Rec ', 1);
1697 END IF;
1698 OE_Line_Util_Ext.Rowtype_Rec_To_API_Rec(p_record,l_line_rec);
1699 IF l_debug_level > 0 THEN
1700 oe_debug_pub.add( 'After the call to Rowtype_Rec_To_API_Rec ', 1);
1701 END IF;
1702
1703 l_cust_trx_type_id := Get_Customer_Transaction_Type(l_line_rec);
1704 RETURN(l_cust_trx_type_id);
1705
1706 EXCEPTION
1707 WHEN OTHERS THEN
1708 IF l_debug_level > 0 THEN
1709 oe_debug_pub.add( 'EXCEPTION. EXITING GET_CUSTOMER_TRANSACTION_TYPE ( ) , '||SQLERRM , 1 ) ;
1710 END IF;
1711 return(0);
1712 END Get_Customer_Transaction_Type;
1713
1714 FUNCTION Get_Customer_Transaction_Type
1715 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1716 ) RETURN NUMBER IS
1717 l_inv_cust_trx_type_id NUMBER;
1718 l_cust_trx_type_id NUMBER;
1719 l_creation_sign VARCHAR2(30);
1720 --
1721 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1722 --
1723 BEGIN
1724 IF l_debug_level > 0 THEN
1725 oe_debug_pub.add( ' ENTER GET_CUSTOMER_TRANSACTION_TYPE' , 5 ) ;
1726 END IF;
1727
1728 --use cache instead of SQL for bug 4200055
1729 IF ( p_line_rec.line_type_id is not null
1730 AND p_line_rec.line_type_id <> FND_API.G_MISS_NUM
1731 AND OE_Order_Cache.g_line_type_rec.line_type_id <> p_line_rec.Line_Type_id) THEN
1732 OE_Order_Cache.Load_Line_type(p_line_rec.Line_Type_id) ;
1733 END IF ; -- end
1734
1735 IF NOT Return_Line(p_line_rec) THEN -- Standard Order Line
1736 IF l_debug_level > 0 THEN
1737 oe_debug_pub.add( 'THIS IA A STANDARD ORDER LINE' , 5 ) ;
1738 END IF;
1739 --use cache instead of SQL for bug 4200055
1740 if (OE_Order_Cache.g_line_type_rec.line_type_id = p_line_rec.Line_Type_id ) then
1741 l_cust_trx_type_id := nvl(OE_Order_Cache.g_line_type_rec.cust_trx_type_id,0) ;
1742 else
1743 l_cust_trx_type_id := 0 ;
1744 end if ;
1745 /*SELECT NVL(lt.cust_trx_type_id, 0)
1746 INTO l_cust_trx_type_id
1747 FROM oe_line_types_v lt
1748 WHERE lt.line_type_id = p_line_rec.line_type_id; */
1749 -- end bug 4200055
1750 IF l_debug_level > 0 THEN
1751 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM LINE TYPE : '||L_CUST_TRX_TYPE_ID , 5 ) ;
1752 END IF;
1753 IF l_cust_trx_type_id = 0 THEN
1754 SELECT NVL(ot.cust_trx_type_id, 0)
1755 INTO l_cust_trx_type_id
1756 FROM oe_order_types_v ot,
1757 oe_order_headers_all oh /* MOAC SQL CHANGE */
1758 WHERE ot.order_type_id = oh.order_type_id
1759 AND oh.header_id = p_line_rec.header_id;
1760 IF l_debug_level > 0 THEN
1761 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM ORDER TYPE : '||L_CUST_TRX_TYPE_ID , 5 ) ;
1762 END IF;
1763 IF l_cust_trx_type_id = 0 THEN
1764 SELECT NVL(oe_sys_parameters.value('OE_INVOICE_TRANSACTION_TYPE_ID',p_line_rec.org_id), 0) --moac
1765 INTO l_cust_trx_type_id
1766 FROM DUAL;
1767 IF l_debug_level > 0 THEN
1768 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM PROFILE : '||L_CUST_TRX_TYPE_ID , 5 ) ;
1769 END IF;
1770 END IF;
1771 END IF;
1772 IF l_debug_level > 0 THEN
1773 oe_debug_pub.add( 'GET CUSTOMER TRANSACTION TYPE ( 1 ) : '||L_CUST_TRX_TYPE_ID , 5 ) ;
1774 END IF;
1775 RETURN(l_cust_trx_type_id);
1776 ELSIF p_line_rec.reference_line_id IS NOT NULL THEN -- Referenced Return Line
1777 IF l_debug_level > 0 THEN
1778 oe_debug_pub.add( 'THIS IA A REFERENCED RETURN LINE' , 5 ) ;
1779 END IF;
1780 -- Get from reference line (Ignore l_creation_sign value here)
1781 Return_Credit_Info(p_line_rec, l_cust_trx_type_id, l_creation_sign);
1782 IF l_cust_trx_type_id = 0 THEN -- no cust_trx_type_id at line/order type
1783 SELECT OE_SYS_PARAMETERS.Value('OE_CREDIT_TRANSACTION_TYPE_ID',p_line_rec.org_id) --moac
1784 INTO l_cust_trx_type_id
1785 FROM DUAL;
1786 IF l_debug_level > 0 THEN
1787 oe_debug_pub.add( ' CUSTOMER TRANSACTION TYPE ID FROM PROFILE ' , 5 ) ;
1788 END IF;
1789 END IF;
1790 IF l_debug_level > 0 THEN
1791 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID ( 2 ) : '||L_CUST_TRX_TYPE_ID , 5 ) ;
1792 END IF;
1793 RETURN(l_cust_trx_type_id);
1794 ELSE -- Non Referenced Return Line
1795 IF l_debug_level > 0 THEN
1796 oe_debug_pub.add( 'THIS IS A NON-REFERENCED RETURN LINE ' , 5 ) ;
1797 END IF;
1798 --use cache instead of SQL for bug 4200055
1799 if (OE_Order_Cache.g_line_type_rec.line_type_id = p_line_rec.Line_Type_id ) then
1800 l_inv_cust_trx_type_id := nvl(OE_ORDER_CACHE.g_line_type_rec.cust_trx_type_id,0);
1801 else
1802 l_inv_cust_trx_type_id := 0 ;
1803 end if ;
1804 /*SELECT NVL(lt.cust_trx_type_id, 0)
1805 INTO l_inv_cust_trx_type_id
1806 FROM oe_line_types_v lt
1807 WHERE lt.line_type_id = p_line_rec.line_type_id; */
1808 -- end bug 4200055
1809 IF l_debug_level > 0 THEN
1810 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM LINE TYPE : '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1811 END IF;
1812 --Bug2293944 Removed the decode statement.
1813 IF l_inv_cust_trx_type_id = 0 THEN
1814 SELECT NVL(ot.cust_trx_type_id,0)
1815 INTO l_inv_cust_trx_type_id
1816 FROM oe_order_types_v ot,
1817 oe_order_headers_all oh /* MOAC SQL CHANGE */
1818 WHERE ot.order_type_id = oh.order_type_id
1819 AND oh.header_id = p_line_rec.header_id;
1820 IF l_debug_level > 0 THEN
1821 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM ORDER TYPE: '||L_INV_CUST_TRX_TYPE_ID , 5 ) ;
1822 END IF;
1823 END IF;
1824 IF l_inv_cust_trx_type_id <> 0 THEN
1825 IF l_debug_level > 0 THEN
1826 oe_debug_pub.add( 'GET CREDIT MEMO TYPE ' , 5 ) ;
1827 END IF;
1828 SELECT nvl(ctt.credit_memo_type_id, 0)
1829 INTO l_cust_trx_type_id
1830 FROM ra_cust_trx_types_all ctt
1831 WHERE ctt.cust_trx_type_id = l_inv_cust_trx_type_id
1832 AND NVL(ctt.org_id, -3114) = NVL(p_line_rec.org_id, -3114);
1833 /* DECODE(ctt.cust_trx_type_id,
1834 1, -3113,
1835 2, -3113,
1836 7, -3113,
1837 8, -3113,
1838 NVL(p_line_rec.org_id, -3114)); Commented for the bug 3027150 */
1839 IF l_debug_level > 0 THEN
1840 oe_debug_pub.add( 'CREDIT MEMO TYPE FROM LINE TYPE/ORDER TYPE OF CURRENT LINE'||L_CUST_TRX_TYPE_ID , 5 ) ;
1841 END IF;
1842 END IF;
1843 IF l_inv_cust_trx_type_id = 0 OR l_cust_trx_type_id = 0 THEN
1844 SELECT NVL(oe_sys_parameters.value('OE_CREDIT_TRANSACTION_TYPE_ID',p_line_rec.org_id), 0) --moac
1845 INTO l_cust_trx_type_id
1846 FROM DUAL;
1847 IF l_debug_level > 0 THEN
1848 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID FROM PROFILE' , 5 ) ;
1849 END IF;
1850 END IF;
1851 IF l_debug_level > 0 THEN
1852 oe_debug_pub.add( 'CUSTOMER TRANSACTION TYPE ID ( 3 ) : '||L_CUST_TRX_TYPE_ID , 5 ) ;
1853 END IF;
1854 RETURN(l_cust_trx_type_id);
1855 END IF;
1856 EXCEPTION
1857 WHEN OTHERS THEN
1858 IF l_debug_level > 0 THEN
1859 oe_debug_pub.add( 'EXCEPTION. EXITING GET_CUSTOMER_TRANSACTION_TYPE ( ) , '||SQLERRM , 1 ) ;
1860 END IF;
1861 return(0);
1862 END Get_Customer_Transaction_Type;
1863
1864 PROCEDURE Get_Credit_Method_Code
1865 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
1866 , x_accting_credit_method_code OUT NOCOPY VARCHAR2
1867 , x_invcing_credit_method_code OUT NOCOPY VARCHAR2
1868 ) IS
1869 l_accting_credit_method_code VARCHAR2(30):= NULL;
1870 l_invcing_credit_method_code VARCHAR2(30):= NULL;
1871 --
1872 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1873 --
1874 BEGIN
1875 IF l_debug_level > 0 THEN
1876 oe_debug_pub.add( 'ENTERING GET_CREDIT_METHOD_CODE ( ) ' , 5 ) ;
1877 END IF;
1878 SELECT NVL(lt.accounting_credit_method_code,ot.accounting_credit_method_code),--Bug 5699774
1879 NVL(lt.invoicing_credit_method_code,ot.invoicing_credit_method_code) --Bug 5699774
1880 INTO l_accting_credit_method_code,
1881 l_invcing_credit_method_code
1882 FROM oe_line_types_v lt,
1883 oe_order_types_v ot,
1884 oe_order_headers_all oh /* MOAC SQL CHANGE */
1885 WHERE lt.line_type_id = p_line_rec.line_type_id
1886 AND ot.order_type_id = oh.order_type_id
1887 AND oh.header_id = p_line_rec.header_id;
1888 x_accting_credit_method_code := l_accting_credit_method_code;
1889 x_invcing_credit_method_code := l_invcing_credit_method_code;
1890 IF l_debug_level > 0 THEN
1891 oe_debug_pub.add( 'ACCOUNTING CREDIT METHOD CODE : '||X_ACCTING_CREDIT_METHOD_CODE , 5 ) ;
1892 oe_debug_pub.add( 'INVOICING CREDIT METHOD CODE : '||X_INVCING_CREDIT_METHOD_CODE , 5 ) ;
1893 oe_debug_pub.add( 'EXITING GET_CREDIT_METHOD_CODE ' , 5 ) ;
1894 END IF;
1895 EXCEPTION
1896 WHEN OTHERS THEN
1897 IF l_debug_level > 0 THEN
1898 oe_debug_pub.add( 'EXCEPTION. EXITING GET_CREDIT_METHOD_CODE ( ) '||SQLERRM , 1 ) ;
1899 END IF;
1900 x_accting_credit_method_code := 'LIFO';
1901 x_invcing_credit_method_code := 'LIFO';
1902 END Get_Credit_Method_Code;
1903
1904 -- PTO RFR handling starts here
1905 FUNCTION Is_PTO
1906 (p_line_rec IN OE_Order_Pub.Line_Rec_Type)
1907 RETURN BOOLEAN
1908 IS
1909 --
1910 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1911 --
1912 BEGIN
1913 IF p_line_rec.model_remnant_flag = 'Y' AND
1914 p_line_rec.item_type_code in ('MODEL', 'CLASS', 'OPTION', 'KIT', 'INCLUDED')
1915 THEN
1916 IF (p_line_rec.item_type_code = 'OPTION' AND
1917 p_line_rec.ato_line_id = p_line_rec.line_id ) OR
1918 p_line_rec.ato_line_id is NULL
1919 THEN
1920 IF l_debug_level > 0 THEN
1921 oe_debug_pub.add( 'THIS IS A REMNANT PTO ' , 5 ) ;
1922 END IF;
1923 RETURN TRUE;
1924 ELSE
1925 IF l_debug_level > 0 THEN
1926 oe_debug_pub.add( 'THIS IS NOT A REMNANT PTO ' , 5 ) ;
1927 END IF;
1928 RETURN FALSE;
1929 END IF;
1930 ELSE
1931 IF l_debug_level > 0 THEN
1932 oe_debug_pub.add( 'THIS IS NOT REMNANT PTO ' , 5 ) ;
1933 END IF;
1934 RETURN FALSE;
1935 END IF;
1936 END Is_PTO;
1937
1938 FUNCTION Is_Class
1939 (p_line_id IN NUMBER)
1940 RETURN BOOLEAN
1941 IS
1942 l_item_type_code VARCHAR2(30);
1943 --
1944 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1945 --
1946 BEGIN
1947 SELECT item_type_code
1948 INTO l_item_type_code
1949 FROM OE_ORDER_LINES
1950 WHERE line_id = p_line_id;
1951 IF l_item_type_code = 'CLASS' THEN
1952 IF l_debug_level > 0 THEN
1953 oe_debug_pub.add( 'ITEM TYPE OF THIS LINE IS CLASS' , 5 ) ;
1954 END IF;
1955 RETURN TRUE;
1956 ELSE
1957 IF l_debug_level > 0 THEN
1958 oe_debug_pub.add( ' ITEM TYPE IS NOT CLASS' , 5 ) ;
1959 END IF;
1960 RETURN FALSE;
1961 END IF;
1962 EXCEPTION
1963 WHEN OTHERS THEN
1964 RETURN FALSE;
1965 END Is_Class;
1966
1967 PROCEDURE RFR_Children
1968 (p_line_id IN NUMBER,
1969 x_return_code OUT NOCOPY VARCHAR2,
1970 x_RFR_children_tbl OUT NOCOPY Id_Tbl_Type)
1971 IS
1972 Cursor rfr_child is
1973 SELECT line_id
1974 FROM oe_order_lines Line,
1975 bom_inventory_components bic
1976 WHERE Line.link_to_line_id = p_line_id
1977 AND Line.open_flag || '' = 'Y'
1978 AND bic.component_sequence_id = Line.component_sequence_id
1979 AND bic.component_item_id = Line.inventory_item_id
1980 AND bic.required_for_revenue = 1
1981 ORDER BY Line.inventory_item_id;
1982 /* the order by clause is important, do not remove!!! */
1983 I NUMBER := 1;
1984 --
1985 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1986 --
1987 BEGIN
1988 Open rfr_child;
1989 LOOP
1990 Fetch rfr_child into x_RFR_children_tbl(I);
1991 Exit WHEN rfr_child%NOTFOUND;
1992 I := I + 1;
1993 END LOOP;
1994 IF x_RFR_children_tbl.count <> 0 THEN
1995 x_return_code := 'Y';
1996 ELSE
1997 x_return_code := 'N';
1998 END IF;
1999 Close rfr_child;
2000 IF l_debug_level > 0 THEN
2001 oe_debug_pub.add( 'RFR CHILDREN , RETURN CODE IS '|| X_RETURN_CODE , 5 ) ;
2002 END IF;
2003 END RFR_Children;
2004
2005 PROCEDURE RFR_Sibling
2006 (p_link_to_line_id IN NUMBER,
2007 p_line_inventory_item_id IN NUMBER,
2008 x_return_code OUT NOCOPY VARCHAR2,
2009 x_RFR_sibling_tbl OUT NOCOPY Id_Tbl_Type)
2010 IS
2011
2012 -- we use inventory_item_id to select
2013 -- siblings, to prevent selecting splitted
2014 -- lines
2015 Cursor rfr_sibling is
2016 SELECT line_id
2017 FROM oe_order_lines Line,
2018 bom_inventory_components bic
2019 WHERE Line.link_to_line_id = p_link_to_line_id
2020 AND Line.inventory_item_id <> p_line_inventory_item_id
2021 AND Line.open_flag || '' = 'Y'
2022 AND bic.component_sequence_id = Line.component_sequence_id
2023 AND bic.component_item_id = Line.inventory_item_id
2024 AND bic.required_for_revenue = 1
2025 order by Line.inventory_item_id;
2026 /* the order by clause is important, do not remove!!! */
2027 I NUMBER := 1;
2028 --
2029 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2030 --
2031 BEGIN
2032 Open rfr_sibling;
2033 LOOP
2034 Fetch rfr_sibling into x_RFR_sibling_tbl(I);
2035 Exit WHEN rfr_sibling%NOTFOUND;
2036 I := I + 1;
2037 END LOOP;
2038
2039 IF x_RFR_sibling_tbl.count <> 0 THEN
2040 x_return_code := 'Y';
2041 ELSE
2042 x_return_code := 'N';
2043 END IF;
2044 Close rfr_sibling;
2045 IF l_debug_level > 0 THEN
2046 oe_debug_pub.add( 'RFR SIBLING , RETURN CODE IS '|| X_RETURN_CODE , 1 ) ;
2047 END IF;
2048 END RFR_Sibling;
2049
2050 FUNCTION Is_RFR
2051 (p_line_id IN NUMBER)
2052 RETURN BOOLEAN
2053 IS
2054 l_rfr VARCHAR2(1) := 'N';
2055 --
2056 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2057 --
2058 BEGIN
2059 SELECT 'Y'
2060 INTO l_rfr
2061 FROM oe_order_lines Line,
2062 bom_inventory_components bic
2063 WHERE Line.line_id = p_line_id
2064 AND Line.open_flag || '' = 'Y'
2065 AND bic.component_sequence_id = Line.component_sequence_id
2066 AND bic.component_item_id = Line.inventory_item_id
2067 AND bic.required_for_revenue = 1;
2068 IF l_rfr = 'Y' THEN
2069 IF l_debug_level > 0 THEN
2070 oe_debug_pub.add( 'RFR RETURNING TRUE' , 5 ) ;
2071 END IF;
2072 RETURN TRUE;
2073 ELSE
2074 IF l_debug_level > 0 THEN
2075 oe_debug_pub.add( 'RFR: RETURNING FALSE' , 5 ) ;
2076 END IF;
2077 RETURN FALSE;
2078 END IF;
2079 EXCEPTION
2080 WHEN OTHERS THEN
2081 RETURN FALSE;
2082 END Is_RFR;
2083
2084 FUNCTION Something_To_Invoice
2085 (p_line_rec IN OE_Order_Pub.Line_Rec_Type)
2086 RETURN BOOLEAN IS
2087 l_rfr_child_flag VARCHAR2(1);
2088 l_rfr_sibling_flag VARCHAR2(1);
2089 l_rfr_children_tbl Id_Tbl_Type;
2090 l_rfr_sibling_tbl Id_Tbl_Type;
2091 l_child_rec OE_Order_Pub.Line_Rec_type;
2092 l_sibling_rec OE_Order_Pub.Line_Rec_type;
2093 l_ratio NUMBER;
2094 max_to_invoice NUMBER;
2095 qty_to_invoice NUMBER;
2096 x_qty_to_invoice NUMBER;
2097 i NUMBER;
2098 l_child_inventory_item_id NUMBER := 0;
2099 l_child_total_ordered_qty NUMBER;
2100 l_child_total_fulfilled_qty NUMBER;
2101 l_sibling_inventory_item_id NUMBER := 0;
2102 l_sibling_total_ordered_qty NUMBER;
2103 l_sibling_total_fulfilled_qty NUMBER;
2104 l_total_ordered_qty NUMBER;
2105 l_total_invoiced_qty NUMBER;
2106 l_overship_invoice_basis VARCHAR2(30);
2107 x_result_code VARCHAR2(240);
2108 --
2109 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2110 --
2111 BEGIN
2112 IF l_debug_level > 0 THEN
2113 oe_debug_pub.add( 'RFR: IN SOMETHING_TO_INVOICE' , 5 ) ;
2114 END IF;
2115 IF (nvl(p_line_rec.ordered_quantity, 0) > nvl(p_line_rec.fulfilled_quantity, 0)) THEN
2116 qty_to_invoice := nvl(p_line_rec.ordered_quantity,0);
2117 x_qty_to_invoice := nvl(p_line_rec.ordered_quantity,0);
2118 ELSE -- initialize for overshipment cases
2119 qty_to_invoice := nvl(p_line_rec.fulfilled_quantity,0);
2120 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0);
2121 END IF;
2122 RFR_Children(p_line_rec.line_id, l_rfr_child_flag, l_rfr_children_tbl);
2123 IF (l_rfr_child_flag = 'Y') THEN
2124 FOR i IN 1..l_rfr_children_tbl.count LOOP
2125 OE_Line_Util.Query_Row(p_line_id => l_rfr_children_tbl(i), x_line_rec => l_child_rec);
2126 IF l_child_rec.inventory_item_id <> l_child_inventory_item_id then
2127 l_child_inventory_item_id := l_child_rec.inventory_item_id;
2128 select nvl(sum(ordered_quantity), 0), nvl(sum(fulfilled_quantity), 0)
2129 into l_child_total_ordered_qty, l_child_total_fulfilled_qty
2130 from oe_order_lines
2131 where link_to_line_id = p_line_rec.line_id
2132 and inventory_item_id = l_child_inventory_item_id;
2133 l_ratio := nvl(p_line_rec.ordered_quantity,0) / l_child_total_ordered_qty;
2134 -- ordered_quantity must be according to ratio
2135 Select Floor(nvl(l_child_total_fulfilled_qty, 0) * nvl(p_line_rec.ordered_quantity,0) / l_child_total_ordered_qty)
2136 Into max_to_invoice
2137 From dual;
2138 IF max_to_invoice < qty_to_invoice THEN
2139 IF l_debug_level > 0 THEN
2140 oe_debug_pub.add( 'RFR: MAX_TO_INVOICE < QTY_TO_INVOICE' , 5 ) ;
2141 END IF;
2142 qty_to_invoice := max_to_invoice;
2143 END IF;
2144 END IF; --if this is a new inventory_item_id
2145 END LOOP;
2146 IF nvl(p_line_rec.fulfilled_quantity,0) <= qty_to_invoice THEN
2147 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2148 ELSIF nvl(p_line_rec.fulfilled_quantity, 0) > qty_to_invoice
2149 AND qty_to_invoice < p_line_rec.ordered_quantity THEN
2150 x_qty_to_invoice := qty_to_invoice - nvl(p_line_rec.invoiced_quantity, 0);
2151 ELSE -- full or overshipment
2152 l_overship_invoice_basis := Get_Overship_Invoice_Basis(p_line_rec);
2153 IF l_overship_invoice_basis = 'ORDERED' THEN
2154 x_qty_to_invoice := qty_to_invoice - nvl(p_line_rec.invoiced_quantity, 0);
2155 ELSE
2156 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2157 END IF;
2158 END IF;
2159 END IF;
2160 IF l_debug_level > 0 THEN
2161 oe_debug_pub.add( 'RFR: FINISH CHECK CHILDREN' , 5 ) ;
2162 END IF;
2163 IF IS_CLASS(p_line_rec.link_to_line_id) THEN
2164 RFR_Sibling(p_line_rec.link_to_line_id,
2165 p_line_rec.inventory_item_id,
2166 l_rfr_sibling_flag, l_rfr_sibling_tbl);
2167 IF (l_rfr_sibling_flag = 'Y') THEN
2168 FOR i IN 1..l_rfr_sibling_tbl.count LOOP
2169 OE_Line_Util.Query_Row(p_line_id => l_rfr_sibling_tbl(i), x_line_rec =>l_sibling_rec );
2170 IF l_sibling_rec.inventory_item_id <> l_sibling_inventory_item_id THEN
2171 l_sibling_inventory_item_id := l_sibling_rec.inventory_item_id;
2172 select nvl(sum(ordered_quantity), 0), nvl(sum(fulfilled_quantity), 0)
2173 into l_sibling_total_ordered_qty, l_sibling_total_fulfilled_qty
2174 from oe_order_lines
2175 where link_to_line_id = p_line_rec.link_to_line_id
2176 and inventory_item_id = l_sibling_inventory_item_id;
2177 -- current line may be splitted from the original line
2178 -- just like the sibling line may be splitted
2179 select nvl(sum(ordered_quantity), 0), nvl(sum(invoiced_quantity), 0)
2180 into l_total_ordered_qty, l_total_invoiced_qty
2181 from oe_order_lines
2182 where link_to_line_id = p_line_rec.link_to_line_id
2183 and inventory_item_id = p_line_rec.inventory_item_id;
2184 l_ratio := l_total_ordered_qty / l_sibling_total_ordered_qty;
2185 -- ordered_quantity must be according to ratio
2186 Select Floor(nvl(l_sibling_total_fulfilled_qty, 0) * l_total_ordered_qty / l_sibling_total_ordered_qty)
2187 Into max_to_invoice
2188 From dual;
2189 IF max_to_invoice < qty_to_invoice THEN
2190 qty_to_invoice := max_to_invoice;
2191 END IF;
2192 END IF; -- new inventory_item_id
2193 END LOOP;
2194 IF l_total_invoiced_qty < qty_to_invoice THEN
2195 IF l_debug_level > 0 THEN
2196 oe_debug_pub.add( 'RFR: FULFILL < QTY_TO_INVOICE' , 4 ) ;
2197 END IF;
2198 IF (nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0)) <= (qty_to_invoice - l_total_invoiced_qty)
2199 AND (nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0) < x_qty_to_invoice) THEN
2200 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2201 ELSIF (nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0)) > (qty_to_invoice - l_total_invoiced_qty)
2202 AND (qty_to_invoice - l_total_invoiced_qty < x_qty_to_invoice)
2203 AND qty_to_invoice < l_total_ordered_qty THEN
2204 x_qty_to_invoice := qty_to_invoice - l_total_invoiced_qty;
2205 x_result_code := 'RFR-PENDING';
2206 ELSIF (nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0)) > (qty_to_invoice - l_total_invoiced_qty)
2207 AND (qty_to_invoice - l_total_invoiced_qty < x_qty_to_invoice)
2208 AND qty_to_invoice >= l_total_ordered_qty THEN -- overshipment
2209 l_overship_invoice_basis := Get_Overship_Invoice_Basis(p_line_rec);
2210 IF l_overship_invoice_basis = 'ORDERED' THEN
2211 x_qty_to_invoice := qty_to_invoice - l_total_invoiced_qty;
2212 ELSE
2213 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2214 END IF;
2215 END IF;
2216 END IF;
2217 END IF;
2218 END IF;
2219 IF nvl(p_line_rec.fulfilled_quantity, 0) <= qty_to_invoice THEN
2220 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2221 ELSIF nvl(p_line_rec.fulfilled_quantity, 0) > qty_to_invoice
2222 AND qty_to_invoice < nvl(p_line_rec.ordered_quantity, 0) THEN
2223 x_qty_to_invoice := qty_to_invoice - nvl(p_line_rec.invoiced_quantity, 0);
2224 ELSE -- full or overshipment
2225 l_overship_invoice_basis := Get_Overship_Invoice_Basis(p_line_rec);
2226 IF l_overship_invoice_basis = 'ORDERED' THEN
2227 x_qty_to_invoice := qty_to_invoice - nvl(p_line_rec.invoiced_quantity, 0);
2228 ELSE
2229 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2230 END IF;
2231 END IF;
2232 IF x_qty_to_invoice > 0 THEN
2233 IF l_debug_level > 0 THEN
2234 oe_debug_pub.add( ' SOMETHING_TO_INVOICE: RETURNING TRUE' , 5 ) ;
2235 END IF;
2236 RETURN TRUE;
2237 ELSE
2238 IF l_debug_level > 0 THEN
2239 oe_debug_pub.add( ' SOMETHING_TO_INVOICE: RETURNING FALSE' , 5 ) ;
2240 END IF;
2241 RETURN FALSE;
2242 END IF;
2243 END Something_To_Invoice;
2244
2245 PROCEDURE Get_Regular_Qty_To_Invoice
2246 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
2247 , x_regular_qty_to_invoice OUT NOCOPY NUMBER
2248 )
2249 IS
2250 l_overship_invoice_basis VARCHAR2(30);
2251 l_fulfilled_qty NUMBER;
2252
2253 -- changes for bug 3728587 start
2254 l_unsplit_ordered_qty NUMBER;
2255 l_unsplit_fulfilled_qty NUMBER;
2256 l_unsplit_invoiced_qty NUMBER;
2257 l_temp NUMBER;
2258 l_set_type VARCHAR2(30);
2259 -- changes for bug 3728587 end
2260
2261 --
2262 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2263 --
2264 BEGIN
2265 -- This may subject to change based on fulfillment design
2266 -- This may subject to change for required for revenue cases as there are
2267 -- chances for partial invoicing (should be looking at invoiced_quantity)
2268
2269 -- changes for bug 3728587 start
2270 --check if line is splitted or not
2271 if(p_line_rec.line_set_id is not null) then
2272 select set_type into l_set_type from oe_sets where set_id = p_line_rec.line_set_id;
2273 end if;
2274 oe_debug_pub.add('l_set_type = '||l_set_type, 5 ) ;
2275
2276 if(l_set_type = 'SPLIT') then
2277 -- line is splitted
2278 -- get the total amounts
2279 select sum(nvl(ordered_quantity,0)), sum(nvl(fulfilled_quantity,nvl(shipped_quantity,0))), sum(nvl(invoiced_quantity,0))
2280 into l_unsplit_ordered_qty , l_unsplit_fulfilled_qty, l_unsplit_invoiced_qty
2281 from oe_order_lines_all where header_id = p_line_rec.header_id and line_set_id = p_line_rec.line_set_id;
2282 else
2283 l_unsplit_ordered_qty := nvl(p_line_rec.ordered_quantity,0);
2284 l_unsplit_fulfilled_qty := nvl(p_line_rec.fulfilled_quantity,nvl(p_line_rec.shipped_quantity,0));
2285 l_unsplit_invoiced_qty := nvl(p_line_rec.invoiced_quantity,0);
2286 end if;
2287 -- changes for bug 3728587 end;
2288
2289 IF l_debug_level > 0 THEN
2290 oe_debug_pub.add( 'ENTER TO GET REGULAR QUANTITY TO INVOICE ' , 5 ) ;
2291 oe_debug_pub.add( 'FULFILLED QUANTITY = '|| TO_CHAR ( P_LINE_REC.FULFILLED_QUANTITY ) , 5 ) ;
2292 oe_debug_pub.add( 'SHIPPED QUANTITY = '|| TO_CHAR ( P_LINE_REC.SHIPPED_QUANTITY ) , 5 ) ;
2293 oe_debug_pub.add( 'ORDERED QUANTITY = '|| TO_CHAR ( P_LINE_REC.ORDERED_QUANTITY ) , 5 ) ;
2294 -- changes for bug 3728587 end;
2295 oe_debug_pub.add( 'UNSPLIT ORDERED QUANTITY = '|| TO_CHAR ( l_unsplit_ordered_qty ) , 5 ) ;
2296 oe_debug_pub.add( 'UNSPLIT FULFILLED QUANTITY = '|| TO_CHAR ( l_unsplit_fulfilled_qty ) , 5 ) ;
2297 oe_debug_pub.add( 'UNSPLIT INVOICED QUANTITY = '|| TO_CHAR ( l_unsplit_invoiced_qty ) , 5 ) ;
2298 -- changes for bug 3728587 end;
2299 END IF;
2300
2301 IF p_line_rec.shipped_quantity IS NOT NULL THEN
2302 -- calculate quantity to invoice based on ship tolerances
2303 -- If we ship less than ship tolerance below, then the line will be split.
2304 l_fulfilled_qty := NVL(p_line_rec.fulfilled_quantity, NVL(p_line_rec.shipped_quantity, 0));
2305 IF l_debug_level > 0 THEN
2306 oe_debug_pub.add( 'L_FULFILLED_QUANTITY = '|| L_FULFILLED_QTY , 5 ) ;
2307 END IF;
2308 -- changes for bug 3728587 start
2309 -- IF (l_fulfilled_qty <= nvl(p_line_rec.ordered_quantity, 0)) then
2310 IF (l_unsplit_fulfilled_qty <= nvl(l_unsplit_ordered_qty, 0)) then
2311 -- changes for bug 3728587 end
2312 x_regular_qty_to_invoice := l_fulfilled_qty - NVL(p_line_rec.invoiced_quantity, 0);
2313 IF l_debug_level > 0 THEN
2314 oe_debug_pub.add( 'EXIT CALCUALTE_QTY_TO_INVOICE ( 1 ) : '||X_REGULAR_QTY_TO_INVOICE , 5 ) ;
2315 END IF;
2316 RETURN;
2317 -- changes for bug 3728587 start
2318 -- ELSIF ( l_fulfilled_qty > NVL(p_line_rec.ordered_quantity, 0)
2319 -- AND (l_fulfilled_qty < (NVL(p_line_rec.ordered_quantity, 0) + (NVL(p_line_rec.ordered_quantity, 0) * NVL(p_line_rec.ship_tolerance_above, 0)))) ) THEN
2320 ELSIF ( l_unsplit_fulfilled_qty > NVL(l_unsplit_ordered_qty, 0)
2321 AND (l_unsplit_fulfilled_qty <= (NVL(l_unsplit_ordered_qty, 0) + ((NVL(l_unsplit_ordered_qty, 0) * NVL(p_line_rec.ship_tolerance_above, 0))/100))) ) THEN
2322 -- changes for bug 3728587 end
2323 l_overship_invoice_basis := Get_Overship_Invoice_Basis(p_line_rec);
2324 IF l_overship_invoice_basis = 'ORDERED' THEN
2325 x_regular_qty_to_invoice := NVL(p_line_rec.ordered_quantity, 0) - NVL(p_line_rec.invoiced_quantity, 0);
2326 IF l_debug_level > 0 THEN
2327 oe_debug_pub.add( 'EXIT CALCUALTE_QTY_TO_INVOICE ( 2 ) : '||X_REGULAR_QTY_TO_INVOICE , 1 ) ;
2328 END IF;
2329 RETURN;
2330 ELSE -- 'SHIPPED'
2331 x_regular_qty_to_invoice := l_fulfilled_qty - NVL(p_line_rec.invoiced_quantity, 0);
2332 IF l_debug_level > 0 THEN
2333 oe_debug_pub.add( 'EXIT CALCUALTE_QTY_TO_INVOICE ( 3 ) : '||X_REGULAR_QTY_TO_INVOICE , 5 ) ;
2334 END IF;
2335 RETURN;
2336 END IF;
2337 ELSE -- overshipped (> ordered +tolerance), we only invoice up to the ordered + tolerance. user should manually handle the outstanding qtys
2338 -- changes for bug 3728587 start
2339 -- x_regular_qty_to_invoice := NVL(p_line_rec.ordered_quantity, 0) + (NVL(p_line_rec.ordered_quantity, 0) * NVL(p_line_rec.ship_tolerance_above, 0)) - NVL(p_line_rec.invoiced_quantity, 0);
2340
2341 l_temp := NVL(l_unsplit_ordered_qty, 0) + ((NVL(l_unsplit_ordered_qty, 0) * NVL(p_line_rec.ship_tolerance_above, 0))/100) - NVL(l_unsplit_invoiced_qty, 0);
2342 -- select min of l_temp and l_fulfilled_qty
2343 if(l_temp<l_fulfilled_qty) then
2344 x_regular_qty_to_invoice := l_temp;
2345 else
2346 x_regular_qty_to_invoice := l_fulfilled_qty;
2347 end if;
2348 -- changes for bug 3728587 end
2349 -- Issue Message here. (overshipment above tolerance should be invoiced manually)
2350 IF l_debug_level > 0 THEN
2351 oe_debug_pub.add( 'QUANTITY TO INVOICE AT ( 4 ) = ' || TO_CHAR ( X_REGULAR_QTY_TO_INVOICE ) , 5 ) ;
2352 END IF;
2353 FND_MESSAGE.SET_NAME('ONT','OE_MANUAL_INVOICE_OVERSHIP_QTY');
2354 OE_MSG_PUB.ADD;
2355 IF l_debug_level > 0 THEN
2356 oe_debug_pub.add( 'EXIT CALCUALTE_QTY_TO_INVOICE ( 4 ) : '||X_REGULAR_QTY_TO_INVOICE , 5 ) ;
2357 END IF;
2358 RETURN;
2359 END IF;
2360 ELSE -- no ship cycle
2361 l_fulfilled_qty := NVL(p_line_rec.fulfilled_quantity, NVL(p_line_rec.shipped_quantity, NVL(p_line_rec.ordered_quantity, 0)));
2362 x_regular_qty_to_invoice := l_fulfilled_qty - NVL(p_line_rec.invoiced_quantity, 0);
2363 IF l_debug_level > 0 THEN
2364 oe_debug_pub.add( 'EXIT CALCUALTE_QTY_TO_INVOICE ( 5 ) : '||X_REGULAR_QTY_TO_INVOICE , 5 ) ;
2365 END IF;
2366 RETURN;
2367 END IF;
2368 END Get_Regular_Qty_To_Invoice;
2369 -- new OUT parameter x_return_code
2370 PROCEDURE Get_Qty_To_Invoice
2371 (p_line_rec IN OE_Order_Pub.Line_Rec_Type
2372 , x_qty_to_invoice OUT NOCOPY NUMBER
2373 , x_result_code OUT NOCOPY VARCHAR2
2374 )
2375 IS
2376 l_rfr_child_flag VARCHAR2(1);
2377 l_rfr_sibling_flag VARCHAR2(1);
2378 l_rfr_children_tbl Id_Tbl_Type;
2379 l_rfr_sibling_tbl Id_Tbl_Type;
2380 l_line_rec OE_Order_Pub.Line_Rec_Type;
2381 l_child_rec OE_Order_Pub.Line_Rec_Type;
2382 l_sibling_rec OE_Order_Pub.Line_Rec_Type;
2383 l_ratio NUMBER;
2384 max_to_invoice NUMBER := 0;
2385 qty_to_invoice NUMBER := 0;
2386 l_child_inventory_item_id NUMBER := 0;
2387 l_child_total_ordered_qty NUMBER := 0;
2388 l_child_total_fulfilled_qty NUMBER := 0;
2389 l_sibling_inventory_item_id NUMBER := 0;
2390 l_sibling_total_ordered_qty NUMBER := 0;
2391 l_sibling_total_fulfilled_qty NUMBER := 0;
2392 l_total_ordered_qty NUMBER := 0;
2393 l_total_invoiced_qty NUMBER := 0;
2394 l_total_fulfilled_qty NUMBER := 0;
2395 l_overship_invoice_basis VARCHAR2(30);
2396 i NUMBER;
2397 l_fulfilled_qty NUMBER;
2398
2399 --
2400 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2401 --
2402 BEGIN
2403 IF l_debug_level > 0 THEN
2404 oe_debug_pub.add( 'ENTER TO GET QUANTITY TO INVOICE ( ) ' , 5 ) ;
2405 END IF;
2406 x_result_code := 'NORMAL';
2407 l_fulfilled_qty := NVL(p_line_rec.fulfilled_quantity, NVL(p_line_rec.shipped_quantity, NVL(p_line_rec.ordered_quantity, 0)));
2408 IF Is_PTO(p_line_rec) THEN
2409 IF (nvl(p_line_Rec.ordered_quantity, 0) > l_fulfilled_qty) THEN
2410 qty_to_invoice := nvl(p_line_rec.ordered_quantity, 0);
2411 x_qty_to_invoice := nvl(p_line_rec.ordered_quantity, 0);
2412 ELSE -- initialize for overshipment cases
2413 qty_to_invoice := l_fulfilled_qty;
2414 x_qty_to_invoice := l_fulfilled_qty;
2415 END IF;
2416 RFR_Children(p_line_rec.line_id, l_rfr_child_flag, l_rfr_children_tbl);
2417 IF l_debug_level > 0 THEN
2418 oe_debug_pub.add( 'RFR: QTY_TO_INVOICE: '||QTY_TO_INVOICE ||' L_RFR_CHILD_FLAG: '|| L_RFR_CHILD_FLAG , 5 ) ;
2419 END IF;
2420 IF (l_rfr_child_flag = 'Y') THEN
2421 FOR i IN 1..l_rfr_children_tbl.count LOOP
2422 -- l_rfr_children_tbl is ordered by inventory_item_id
2423 -- so same inventory_item_id will come next to each other
2424 OE_Line_Util.Query_Row(p_line_id => l_rfr_children_tbl(i), x_line_rec => l_child_rec);
2425 IF l_debug_level > 0 THEN
2426 oe_debug_pub.add( 'RFR: L_CHILD_REC.LINE_ID: '||L_CHILD_REC.LINE_ID ||' L_CHILD_REC.INVENTORY_ITEM_ID: '|| L_CHILD_REC.INVENTORY_ITEM_ID , 5 ) ;
2427 END IF;
2428 IF l_child_rec.inventory_item_id <> l_child_inventory_item_id then
2429 l_child_inventory_item_id := l_child_rec.inventory_item_id;
2430 select nvl(sum(ordered_quantity), 0), nvl(sum(fulfilled_quantity), 0)
2431 into l_child_total_ordered_qty, l_child_total_fulfilled_qty
2432 from oe_order_lines
2433 where link_to_line_id = p_line_rec.line_id
2434 and inventory_item_id = l_child_inventory_item_id;
2435 IF l_debug_level > 0 THEN
2436 oe_debug_pub.add( 'RFR: L_CHILD_TOTAL_ORDERED_QTY: '||L_CHILD_TOTAL_ORDERED_QTY||' L_CHILD_TOTAL_FULFILLED_QTY:'||L_CHILD_TOTAL_FULFILLED_QTY , 5 ) ;
2437 END IF;
2438 l_ratio := nvl(p_line_rec.ordered_quantity, 0) / l_child_total_ordered_qty;
2439 IF l_debug_level > 0 THEN
2440 oe_debug_pub.add( 'RFR:L_RATIO :'||L_RATIO , 5 ) ;
2441 END IF;
2442 -- ordered_quantity must be according to ratio
2443 Select Floor(nvl(l_child_total_fulfilled_qty, 0) * nvl(p_line_rec.ordered_quantity, 0) / l_child_total_ordered_qty)
2444 Into max_to_invoice
2445 From dual;
2446 IF l_debug_level > 0 THEN
2447 oe_debug_pub.add( 'RFR:MAX_TO_INVOICE: '||MAX_TO_INVOICE , 5 ) ;
2448 END IF;
2449 IF max_to_invoice < qty_to_invoice THEN
2450 IF l_debug_level > 0 THEN
2451 oe_debug_pub.add( 'RFR: MAX_TO_INVOICE < QTY_TO_INVOICE' , 5 ) ;
2452 END IF;
2453 qty_to_invoice := max_to_invoice;
2454 END IF;
2455 END IF; -- if this is a new inventory_item_id
2456 END LOOP;
2457 IF l_debug_level > 0 THEN
2458 oe_debug_pub.add( 'RFR:FULFILLED_QUANTITY: '||P_LINE_REC.FULFILLED_QUANTITY||' QTY_TO_INVOICE:'||QTY_TO_INVOICE , 4 ) ;
2459 END IF;
2460 IF nvl(p_line_rec.fulfilled_quantity, 0) <= qty_to_invoice THEN
2461 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2462 IF l_debug_level > 0 THEN
2463 oe_debug_pub.add( ' ( 1 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2464 END IF;
2465 IF l_debug_level > 0 THEN
2466 oe_debug_pub.add( ' NOT SETTING TO RFR-PENDING' , 5 ) ;
2467 END IF;
2468 ELSIF nvl(p_line_rec.fulfilled_quantity, 0) > qty_to_invoice
2469 AND qty_to_invoice < nvl(p_line_rec.ordered_quantity, 0) THEN
2470 x_qty_to_invoice := qty_to_invoice - nvl(p_line_rec.invoiced_quantity, 0);
2471 IF l_debug_level > 0 THEN
2472 oe_debug_pub.add( ' ( 2 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2473 oe_debug_pub.add( 'SET X_RESULT_CODE -> RFR-PENDING' , 5 ) ;
2474 END IF;
2475 x_result_code := 'RFR-PENDING';
2476 ELSE -- full or overshipment
2477 l_overship_invoice_basis := Get_Overship_Invoice_Basis(p_line_rec);
2478 IF l_overship_invoice_basis = 'ORDERED' THEN
2479 x_qty_to_invoice := qty_to_invoice - nvl(p_line_rec.invoiced_quantity, 0);
2480 IF l_debug_level > 0 THEN
2481 oe_debug_pub.add( ' ( 3 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2482 END IF;
2483 ELSE
2484 x_qty_to_invoice := nvl(p_line_rec.fulfilled_quantity, 0) - nvl(p_line_rec.invoiced_quantity, 0);
2485 IF l_debug_level > 0 THEN
2486 oe_debug_pub.add( ' ( 4 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2487 END IF;
2488 END IF;
2489 END IF;
2490 ELSE -- no rfr children
2491 Get_Regular_Qty_To_Invoice(p_line_rec, x_qty_to_invoice);
2492 IF l_debug_level > 0 THEN
2493 oe_debug_pub.add( ' ( 5 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2494 END IF;
2495 END IF;
2496 IF l_debug_level > 0 THEN
2497 oe_debug_pub.add( 'RFR: FINISH CHECK CHILDREN' , 5 ) ;
2498 END IF;
2499
2500 -- fix for bug 2516823
2501 IF IS_CLASS(p_line_rec.link_to_line_id) THEN
2502 RFR_Sibling(p_line_rec.link_to_line_id
2503 ,p_line_rec.inventory_item_id
2504 ,l_rfr_sibling_flag
2505 ,l_rfr_sibling_tbl);
2506 IF l_rfr_sibling_flag = 'Y' THEN
2507 FOR i IN 1..l_rfr_sibling_tbl.count LOOP
2508 OE_Line_Util.Query_Row(p_line_id => l_rfr_sibling_tbl(i)
2509 ,x_line_rec => l_sibling_rec);
2510 IF l_debug_level > 0 THEN
2511 oe_debug_pub.add( 'RFR:L_SIBLING_REC.LINE_ID: ' ||L_SIBLING_REC.LINE_ID ||' L_SIBLING_REC.INVENTORY_ITEM_ID:' ||L_SIBLING_REC.INVENTORY_ITEM_ID , 3 ) ;
2512 END IF;
2513 IF l_sibling_rec.inventory_item_id <> l_sibling_inventory_item_id THEN
2514 l_sibling_inventory_item_id := l_sibling_rec.inventory_item_id;
2515 SELECT NVL(SUM(ordered_quantity),0)
2516 ,NVL(SUM(fulfilled_quantity),0)
2517 INTO l_sibling_total_ordered_qty
2518 ,l_sibling_total_fulfilled_qty
2519 FROM oe_order_lines
2520 WHERE link_to_line_id = p_line_rec.link_to_line_id
2521 AND inventory_item_id = l_sibling_inventory_item_id;
2522
2523 -- current line may be splitted from the original line
2524 -- just like the sibling line may be splitted
2525
2526 SELECT NVL(SUM(ordered_quantity),0)
2527 ,NVL(SUM(invoiced_quantity),0)
2528 ,NVL(SUM(fulfilled_quantity),0)
2529 INTO l_total_ordered_qty
2530 ,l_total_invoiced_qty
2531 ,l_total_fulfilled_qty
2532 FROM oe_order_lines
2533 WHERE link_to_line_id = p_line_rec.link_to_line_id
2534 AND inventory_item_id = p_line_rec.inventory_item_id;
2535
2536 l_ratio := l_total_ordered_qty/l_sibling_total_ordered_qty;
2537 -- ordered_quantity must be according to ratio
2538 max_to_invoice := FLOOR(nvl(l_sibling_total_fulfilled_qty,0) *l_total_ordered_qty / l_sibling_total_ordered_qty);
2539 IF l_debug_level > 0 THEN
2540 oe_debug_pub.add( 'MAX_TO_INVOICE:'||MAX_TO_INVOICE||':QTY_TO_INVOICE:'||QTY_TO_INVOICE ) ;
2541 END IF;
2542 IF max_to_invoice < qty_to_invoice THEN
2543 qty_to_invoice := max_to_invoice;
2544 END IF;
2545 END IF; -- new inventory_item_id
2546 END LOOP;
2547
2548 IF l_debug_level > 0 THEN
2549 oe_debug_pub.add( 'L_TOTAL_INVOICED_QTY:'||L_TOTAL_INVOICED_QTY , 5 ) ;
2550 oe_debug_pub.add( 'L_TOTAL_FULFILLED_QTY:'||L_TOTAL_FULFILLED_QTY , 5 ) ;
2551 oe_debug_pub.add( 'QTY_TO_INVOICE:'||QTY_TO_INVOICE , 5 ) ;
2552 END IF;
2553
2554 IF l_total_fulfilled_qty <= qty_to_invoice THEN
2555 x_qty_to_invoice := l_total_fulfilled_qty
2556 - l_total_invoiced_qty;
2557 IF l_debug_level > 0 THEN
2558 oe_debug_pub.add( ' ( 5 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2559 END IF;
2560 ELSIF l_total_fulfilled_qty - l_total_invoiced_qty
2561 > qty_to_invoice
2562 AND qty_to_invoice <l_total_ordered_qty THEN
2563 x_qty_to_invoice
2564 := qty_to_invoice - l_total_invoiced_qty;
2565 IF l_debug_level > 0 THEN
2566 oe_debug_pub.add( ' ( 6 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2567 END IF;
2568 IF l_debug_level > 0 THEN
2569 oe_debug_pub.add( 'SET X_RESULT_CODE -> RFR-PENDING' , 5 ) ;
2570 END IF;
2571 x_result_code := 'RFR-PENDING';
2572 ELSE
2573 l_overship_invoice_basis := Get_Overship_Invoice_Basis(p_line_rec);
2574 IF l_overship_invoice_basis = 'ORDERED' THEN
2575 x_qty_to_invoice := qty_to_invoice - l_total_invoiced_qty;
2576 IF l_debug_level > 0 THEN
2577 oe_debug_pub.add( ' ( 7 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2578 END IF;
2579 ELSE
2580 x_qty_to_invoice := l_total_fulfilled_qty - l_total_invoiced_qty;
2581 IF l_debug_level > 0 THEN
2582 oe_debug_pub.add( ' ( 8 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2583 END IF;
2584 END IF;
2585 END IF;
2586 -- ELSE -- no siblings
2587 -- Get_Regular_Qty_To_Invoice(p_line_rec, x_qty_to_invoice);
2588 END IF;
2589 END IF;
2590 ELSE -- not pto
2591 Get_Regular_Qty_To_Invoice(p_line_rec, x_qty_to_invoice);
2592 IF l_debug_level > 0 THEN
2593 oe_debug_pub.add( ' ( 9 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2594 END IF;
2595 END IF;
2596 IF l_debug_level > 0 THEN
2597 oe_debug_pub.add( ' ( 10 ) QUANTITY TO INVOICE : '||X_QTY_TO_INVOICE , 5 ) ;
2598 END IF;
2599 END Get_Qty_To_Invoice;
2600
2601 FUNCTION Validate_Required_Attributes
2602 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
2603 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
2604 )
2605 RETURN BOOLEAN
2606 IS
2607 --
2608 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2609 --
2610 BEGIN
2611 IF l_debug_level > 0 THEN
2612 oe_debug_pub.add( 'VALIDATING REQUIRED ATTRIBUTES' , 5 ) ;
2613 END IF;
2614 -- Check For all Required Attributes
2615 IF p_interface_line_rec.Batch_Source_Name IS NULL THEN
2616 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2617 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Batch_Source_Name');
2618 OE_MSG_PUB.ADD;
2619 IF l_debug_level > 0 THEN
2620 oe_debug_pub.add( 'REQUIRED ATTRIBUTE BATCH SOURCE NAME IS MISSING' , 1 ) ;
2621 END IF;
2622 RETURN FALSE;
2623 ELSIF p_interface_line_rec.Set_Of_Books_Id IS NULL THEN
2624 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2625 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Set_Of_Books_Id');
2626 OE_MSG_PUB.ADD;
2627 IF l_debug_level > 0 THEN
2628 oe_debug_pub.add( 'REQUIRED ATTRIBUTE SET OF BOOKS ID IS MISSING ' , 1 ) ;
2629 END IF;
2630 RETURN FALSE;
2631 ELSIF p_interface_line_rec.Line_Type IS NULL THEN
2632 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2633 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Line_Type');
2634 OE_MSG_PUB.ADD;
2635 IF l_debug_level > 0 THEN
2636 oe_debug_pub.add( 'REQUIRED ATTRIBUTE LINE TYPE IS MISSING' , 1 ) ;
2637 END IF;
2638 RETURN FALSE;
2639 ELSIF p_interface_line_rec.Description IS NULL THEN
2640 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2641 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Description');
2642 OE_MSG_PUB.ADD;
2643 IF l_debug_level > 0 THEN
2644 oe_debug_pub.add( 'REQUIRED ATTRIBUTE DESCRIPTION IS MISSING' , 1 ) ;
2645 END IF;
2646 RETURN FALSE;
2647 ELSIF p_interface_line_rec.Currency_Code IS NULL THEN
2648 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2649 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Currency_Code');
2650 OE_MSG_PUB.ADD;
2651 IF l_debug_level > 0 THEN
2652 oe_debug_pub.add( 'REQUIRED ATTRIBUTE CURRENCY CODE IS MISSING' , 1 ) ;
2653 END IF;
2654 RETURN FALSE;
2655 ELSIF p_interface_line_rec.Conversion_Type IS NULL THEN
2656 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2657 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Conversion_Type');
2658 OE_MSG_PUB.ADD;
2659 IF l_debug_level > 0 THEN
2660 oe_debug_pub.add( 'REQUIRED ATTRIBUTE CONVERSION TYPE IS MISSING' , 1 ) ;
2661 END IF;
2662 RETURN FALSE;
2663 ELSIF p_line_rec.commitment_id IS NULL AND
2664 (p_interface_line_rec.Cust_Trx_Type_Id IS NULL OR
2665 p_interface_line_rec.Cust_Trx_Type_Id = 0) THEN
2666 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2667 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Cust_Trx_Type_Id');
2668 OE_MSG_PUB.ADD;
2669 IF l_debug_level > 0 THEN
2670 oe_debug_pub.add( 'REQUIRED ATTRIBUTE CUSTOMER TRX TYPE ID IS MISSING' , 1 ) ;
2671 END IF;
2672 RETURN FALSE;
2673 ELSIF p_interface_line_rec.ACCOUNTING_RULE_DURATION = -1 THEN
2674 -- Appropriate message was already posted for bug#4190312
2675 IF l_debug_level > 0 THEN
2676 oe_debug_pub.add( 'REQUIRED ATTRIBUTE ACCOUNTING RULE DURATION IS MISSING' , 1 ) ;
2677 END IF;
2678 RETURN FALSE;
2679 ELSIF p_interface_line_rec.customer_bank_account_id = -1 THEN
2680 FND_MESSAGE.SET_NAME('ONT','OE_VPM_CC_ACCT_NOT_SET');
2681 OE_MSG_PUB.ADD;
2682 IF l_debug_level > 0 THEN
2683 oe_debug_pub.add( 'REQUIRED ATTRIBUTE CUSTOMER CREDIT CARD BANK ACCOUNT IS MISSING' , 1 ) ;
2684 END IF;
2685 RETURN FALSE;
2686 ELSIF p_interface_line_rec.customer_bank_account_id > 0
2687 AND p_interface_line_rec.receipt_method_id IS NULL THEN
2688 FND_MESSAGE.SET_NAME('ONT','OE_VPM_NO_PAY_METHOD');
2689 OE_MSG_PUB.ADD;
2690 IF l_debug_level > 0 THEN
2691 oe_debug_pub.add( 'REQUIRED ATTRIBUTE PAYMENT METHOD IS MISSING' , 1 ) ;
2692 END IF;
2693 RETURN FALSE;
2694 -- bug 8494362 start
2695 ELSIF p_interface_line_rec.INTERFACE_LINE_CONTEXT IS NULL THEN
2696 FND_MESSAGE.SET_NAME('ONT','OE_INVOICING_ATTR_REQUIRED');
2697 FND_MESSAGE.SET_TOKEN('ATTRIBUTE','Interface Line Context');
2698 OE_MSG_PUB.ADD;
2699 IF l_debug_level > 0 THEN
2700 oe_debug_pub.add( 'REQUIRED ATTRIBUTE INTERFACE_LINE_CONTEXT IS MISSING' , 1 ) ;
2701 END IF;
2702 RETURN FALSE;
2703 -- bug 8494362 end
2704
2705 /* ELSIF -- will be updated with list of mandatory and conditionally required attributes
2706 Mandatory Columns:
2707 Batch_Source_Name
2708 Set_Of_Books_Id
2709 Line_Type
2710 Description
2711 Currency_Code
2712 Conversion_Type
2713
2714 Optional columns:
2715 Term_Id is required for non credit transactions
2716 IF any thing is missing THEN
2717 -- Issue error message here
2718 RETURN FALSE;*/
2719 ELSE
2720 IF l_debug_level > 0 THEN
2721 oe_debug_pub.add( 'EXIT VALIDATE REQUIRED ATTRIBUTES ( ) ' , 1 ) ;
2722 END IF;
2723 RETURN TRUE;
2724 END IF;
2725 END Validate_Required_Attributes;
2726
2727 PROCEDURE Header_Invoicing_Validation
2728 (p_header_id IN NUMBER)
2729 IS
2730 --
2731 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2732 --
2733 BEGIN
2734 /*
2735 -- Following may be a result of wrong workflow setup
2736 if atleast one line is not ready for Invoicing then
2737 issue error message
2738 elsif atleast one line is already invoiced then
2739 issue error message
2740 Add any other validation here
2741 */
2742 IF l_debug_level > 0 THEN
2743 oe_debug_pub.add( 'ENTERING HEADER_INVOICING_VALIDATION' ) ;
2744 END IF;
2745 NULL;
2746 END Header_Invoicing_Validation;
2747
2748 PROCEDURE Query_Line_Scredits
2749 ( p_line_id IN NUMBER
2750 , p_quota_flag IN VARCHAR2
2751 , x_line_scredit_tbl IN OUT NOCOPY OE_Order_Pub.Line_Scredit_Tbl_Type
2752 , x_total_percent OUT NOCOPY NUMBER --FP bug 3872166
2753 ) IS
2754 l_Line_Scredit_rec OE_Order_PUB.Line_Scredit_Rec_Type;
2755 CURSOR l_Line_Scredit_csr IS
2756 SELECT SC.ATTRIBUTE1
2757 , SC.ATTRIBUTE10
2758 , SC.ATTRIBUTE11
2759 , SC.ATTRIBUTE12
2760 , SC.ATTRIBUTE13
2761 , SC.ATTRIBUTE14
2762 , SC.ATTRIBUTE15
2763 , SC.ATTRIBUTE2
2764 , SC.ATTRIBUTE3
2765 , SC.ATTRIBUTE4
2766 , SC.ATTRIBUTE5
2767 , SC.ATTRIBUTE6
2768 , SC.ATTRIBUTE7
2769 , SC.ATTRIBUTE8
2770 , SC.ATTRIBUTE9
2771 , SC.CONTEXT
2772 , SC.CREATED_BY
2773 , SC.CREATION_DATE
2774 , SC.DW_UPDATE_ADVICE_FLAG
2775 , SC.HEADER_ID
2776 , SC.LAST_UPDATED_BY
2777 , SC.LAST_UPDATE_DATE
2778 , SC.LAST_UPDATE_LOGIN
2779 , SC.LINE_ID
2780 , SC.PERCENT
2781 , SC.SALESREP_ID
2782 , SC.sales_credit_type_id
2783 , SC.SALES_CREDIT_ID
2784 , SC.WH_UPDATE_DATE
2785 --SG{
2786 , SC.SALES_GROUP_ID
2787 --SG}
2788 , SC.LOCK_CONTROL
2789 FROM OE_SALES_CREDITS SC
2790 , OE_SALES_CREDIT_TYPES SCT
2791 WHERE SC.sales_credit_type_id = sct.sales_credit_type_id
2792 AND SCT.quota_flag = p_quota_flag
2793 AND SC.line_id = p_line_id;
2794
2795 --
2796 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2797 --
2798 BEGIN
2799 IF l_debug_level > 0 THEN
2800 oe_debug_pub.add( 'ENTERING QUERY_LINE_SCREDITS' , 5 ) ;
2801 END IF;
2802 -- Initialize table so that it clears previous records
2803 x_line_scredit_tbl.DELETE;
2804
2805 --FP bug 3872166
2806 x_total_percent := 0;
2807
2808 -- Loop over fetched records
2809 FOR l_implicit_rec IN l_Line_Scredit_csr LOOP
2810 l_Line_Scredit_rec.attribute1 := l_implicit_rec.ATTRIBUTE1;
2811 l_Line_Scredit_rec.attribute10 := l_implicit_rec.ATTRIBUTE10;
2812 l_Line_Scredit_rec.attribute11 := l_implicit_rec.ATTRIBUTE11;
2813 l_Line_Scredit_rec.attribute12 := l_implicit_rec.ATTRIBUTE12;
2814 l_Line_Scredit_rec.attribute13 := l_implicit_rec.ATTRIBUTE13;
2815 l_Line_Scredit_rec.attribute14 := l_implicit_rec.ATTRIBUTE14;
2816 l_Line_Scredit_rec.attribute15 := l_implicit_rec.ATTRIBUTE15;
2817 l_Line_Scredit_rec.attribute2 := l_implicit_rec.ATTRIBUTE2;
2818 l_Line_Scredit_rec.attribute3 := l_implicit_rec.ATTRIBUTE3;
2819 l_Line_Scredit_rec.attribute4 := l_implicit_rec.ATTRIBUTE4;
2820 l_Line_Scredit_rec.attribute5 := l_implicit_rec.ATTRIBUTE5;
2821 l_Line_Scredit_rec.attribute6 := l_implicit_rec.ATTRIBUTE6;
2822 l_Line_Scredit_rec.attribute7 := l_implicit_rec.ATTRIBUTE7;
2823 l_Line_Scredit_rec.attribute8 := l_implicit_rec.ATTRIBUTE8;
2824 l_Line_Scredit_rec.attribute9 := l_implicit_rec.ATTRIBUTE9;
2825 l_Line_Scredit_rec.context := l_implicit_rec.CONTEXT;
2826 l_Line_Scredit_rec.created_by := l_implicit_rec.CREATED_BY;
2827 l_Line_Scredit_rec.creation_date := l_implicit_rec.CREATION_DATE;
2828 l_Line_Scredit_rec.dw_update_advice_flag := l_implicit_rec.DW_UPDATE_ADVICE_FLAG;
2829 l_Line_Scredit_rec.header_id := l_implicit_rec.HEADER_ID;
2830 l_Line_Scredit_rec.last_updated_by := l_implicit_rec.LAST_UPDATED_BY;
2831 l_Line_Scredit_rec.last_update_date := l_implicit_rec.LAST_UPDATE_DATE;
2832 l_Line_Scredit_rec.last_update_login := l_implicit_rec.LAST_UPDATE_LOGIN;
2833 l_Line_Scredit_rec.line_id := l_implicit_rec.LINE_ID;
2834 l_Line_Scredit_rec.percent := l_implicit_rec.PERCENT;
2835 l_Line_Scredit_rec.salesrep_id := l_implicit_rec.SALESREP_ID;
2836 l_Line_Scredit_rec.sales_credit_type_id := l_implicit_rec.sales_credit_type_id;
2837 l_Line_Scredit_rec.sales_credit_id := l_implicit_rec.SALES_CREDIT_ID;
2838 l_Line_Scredit_rec.wh_update_date := l_implicit_rec.WH_UPDATE_DATE;
2839 --SG{
2840 l_Line_Scredit_rec.sales_group_id:=l_implicit_rec.sales_group_id;
2841 --SG}
2842 l_Line_Scredit_rec.lock_control := l_implicit_rec.LOCK_CONTROL;
2843 x_Line_Scredit_tbl(x_Line_Scredit_tbl.COUNT + 1) := l_Line_Scredit_rec;
2844 --FP bug 3872166
2845 x_total_percent := x_total_percent + l_implicit_rec.PERCENT;
2846 END LOOP;
2847 IF l_debug_level > 0 THEN
2848 oe_debug_pub.add( 'EXITING QUERY_LINE_SCREDITS' , 5 ) ;
2849 END IF;
2850 EXCEPTION
2851 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2852 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2853 WHEN OTHERS THEN
2854 IF l_debug_level > 0 THEN
2855 oe_debug_pub.add( 'EXCEPTION , QUERY LINE SALES CREDITS '||SQLERRM , 1 ) ;
2856 END IF;
2857 IF oe_msg_pub.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2858 THEN
2859 oe_msg_pub.Add_Exc_Msg
2860 ( G_PKG_NAME
2861 , 'Query_Line_Scredits'
2862 );
2863 END IF;
2864 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2865 END Query_Line_Scredits;
2866
2867 PROCEDURE Query_Header_Scredits
2868 ( p_header_id IN NUMBER
2869 , p_quota_flag IN VARCHAR2
2870 , x_header_scredit_tbl IN OUT NOCOPY OE_Order_Pub.Header_Scredit_Tbl_Type
2871 ) IS
2872 l_Header_Scredit_rec OE_Order_PUB.Header_Scredit_Rec_Type;
2873 CURSOR l_Header_Scredit_csr IS
2874 SELECT SC.ATTRIBUTE1
2875 , SC.ATTRIBUTE10
2876 , SC.ATTRIBUTE11
2877 , SC.ATTRIBUTE12
2878 , SC.ATTRIBUTE13
2879 , SC.ATTRIBUTE14
2880 , SC.ATTRIBUTE15
2881 , SC.ATTRIBUTE2
2882 , SC.ATTRIBUTE3
2883 , SC.ATTRIBUTE4
2884 , SC.ATTRIBUTE5
2885 , SC.ATTRIBUTE6
2886 , SC.ATTRIBUTE7
2887 , SC.ATTRIBUTE8
2888 , SC.ATTRIBUTE9
2889 , SC.CONTEXT
2890 , SC.CREATED_BY
2891 , SC.CREATION_DATE
2892 , SC.DW_UPDATE_ADVICE_FLAG
2893 , SC.HEADER_ID
2894 , SC.LAST_UPDATED_BY
2895 , SC.LAST_UPDATE_DATE
2896 , SC.LAST_UPDATE_LOGIN
2897 , SC.LINE_ID
2898 , SC.PERCENT
2899 , SC.SALESREP_ID
2900 , SC.sales_credit_type_id
2901 , SC.SALES_CREDIT_ID
2902 , SC.WH_UPDATE_DATE
2903 --SG
2904 , SC.Sales_Group_Id
2905 --SG
2906 , SC.LOCK_CONTROL
2907 FROM OE_SALES_CREDITS SC
2908 , OE_SALES_CREDIT_TYPES SCT
2909 WHERE SC.sales_credit_type_id = sct.sales_credit_type_id
2910 AND SCT.quota_flag = p_quota_flag
2911 AND SC.header_id = p_header_id
2912 AND SC.line_id IS NULL;
2913 --
2914 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2915 --
2916 BEGIN
2917 IF l_debug_level > 0 THEN
2918 oe_debug_pub.add( 'ENTERING QUERY_HEADER_SCREDITS' , 5 ) ;
2919 oe_debug_pub.add( 'P_QUOTA_FLAG: '||P_QUOTA_FLAG , 5 ) ;
2920 END IF;
2921 -- Initialize table so that it clears previous records
2922 x_header_scredit_tbl.DELETE;
2923 -- Loop over fetched records
2924 FOR l_implicit_rec IN l_Header_Scredit_csr LOOP
2925 l_Header_Scredit_rec.attribute1 := l_implicit_rec.ATTRIBUTE1;
2926 l_Header_Scredit_rec.attribute10 := l_implicit_rec.ATTRIBUTE10;
2927 l_Header_Scredit_rec.attribute11 := l_implicit_rec.ATTRIBUTE11;
2928 l_Header_Scredit_rec.attribute12 := l_implicit_rec.ATTRIBUTE12;
2929 l_Header_Scredit_rec.attribute13 := l_implicit_rec.ATTRIBUTE13;
2930 l_Header_Scredit_rec.attribute14 := l_implicit_rec.ATTRIBUTE14;
2931 l_Header_Scredit_rec.attribute15 := l_implicit_rec.ATTRIBUTE15;
2932 l_Header_Scredit_rec.attribute2 := l_implicit_rec.ATTRIBUTE2;
2933 l_Header_Scredit_rec.attribute3 := l_implicit_rec.ATTRIBUTE3;
2934 l_Header_Scredit_rec.attribute4 := l_implicit_rec.ATTRIBUTE4;
2935 l_Header_Scredit_rec.attribute5 := l_implicit_rec.ATTRIBUTE5;
2936 l_Header_Scredit_rec.attribute6 := l_implicit_rec.ATTRIBUTE6;
2937 l_Header_Scredit_rec.attribute7 := l_implicit_rec.ATTRIBUTE7;
2938 l_Header_Scredit_rec.attribute8 := l_implicit_rec.ATTRIBUTE8;
2939 l_Header_Scredit_rec.attribute9 := l_implicit_rec.ATTRIBUTE9;
2940 l_Header_Scredit_rec.context := l_implicit_rec.CONTEXT;
2941 l_Header_Scredit_rec.created_by := l_implicit_rec.CREATED_BY;
2942 l_Header_Scredit_rec.creation_date := l_implicit_rec.CREATION_DATE;
2943 l_Header_Scredit_rec.dw_update_advice_flag := l_implicit_rec.DW_UPDATE_ADVICE_FLAG;
2944 l_Header_Scredit_rec.header_id := l_implicit_rec.HEADER_ID;
2945 l_Header_Scredit_rec.last_updated_by := l_implicit_rec.LAST_UPDATED_BY;
2946 l_Header_Scredit_rec.last_update_date := l_implicit_rec.LAST_UPDATE_DATE;
2947 l_Header_Scredit_rec.last_update_login := l_implicit_rec.LAST_UPDATE_LOGIN;
2948 l_Header_Scredit_rec.line_id := l_implicit_rec.LINE_ID;
2949 l_Header_Scredit_rec.percent := l_implicit_rec.PERCENT;
2950 l_Header_Scredit_rec.salesrep_id := l_implicit_rec.SALESREP_ID;
2951 l_Header_Scredit_rec.sales_credit_type_id := l_implicit_rec.sales_credit_type_id;
2952 l_Header_Scredit_rec.sales_credit_id := l_implicit_rec.SALES_CREDIT_ID;
2953 l_Header_Scredit_rec.wh_update_date := l_implicit_rec.WH_UPDATE_DATE;
2954 --sg
2955 l_Header_Scredit_rec.sales_group_id := l_implicit_rec.sales_group_id;
2956 --sg
2957 l_Header_Scredit_rec.lock_control := l_implicit_rec.LOCK_CONTROL;
2958 x_Header_Scredit_tbl(x_Header_Scredit_tbl.COUNT + 1) := l_Header_Scredit_rec;
2959 IF l_debug_level > 0 THEN
2960 oe_debug_pub.add( 'SALESREP_ID: '||L_HEADER_SCREDIT_REC.SALESREP_ID ) ;
2961 oe_debug_pub.add( 'SALES_CREDIT_TYPE_ID: '||L_HEADER_SCREDIT_REC.SALES_CREDIT_TYPE_ID ) ;
2962 oe_debug_pub.add( 'PERCENT: '||L_HEADER_SCREDIT_REC.PERCENT ) ;
2963 END IF;
2964 END LOOP;
2965 IF l_debug_level > 0 THEN
2966 oe_debug_pub.add( 'EXITING QUERY_HEADER_SCREDITS ( ) ' , 5 ) ;
2967 END IF;
2968 EXCEPTION
2969 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2970 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2971 WHEN OTHERS THEN
2972 IF l_debug_level > 0 THEN
2973 oe_debug_pub.add( 'EXCEPTION , QUERY HEADER SALES CREDITS ( ) ' , 5 ) ;
2974 END IF;
2975 IF oe_msg_pub.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2976 THEN
2977 oe_msg_pub.Add_Exc_Msg
2978 ( G_PKG_NAME
2979 , 'Query_Header_Scredits'
2980 );
2981 END IF;
2982 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2983 END Query_Header_Scredits;
2984
2985 PROCEDURE Insert_Line
2986 ( p_interface_line_rec IN RA_interface_Lines_Rec_Type
2987 , x_return_status OUT NOCOPY VARCHAR2
2988 ) IS
2989 update_sql_stmt VARCHAR2(32767);
2990 /* START PREPAYMENT */
2991 update_sql_stmt1 VARCHAR2(32767);
2992 /* END PREPAYMENT */
2993 err_msg VARCHAR2(5000);
2994 l_rowid UROWID;
2995 --
2996 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2997 --
2998 BEGIN
2999 IF l_debug_level > 0 THEN
3000 oe_debug_pub.add( 'ENTERING INSERT_LINE ( ) PROCEDURE' , 1 ) ;
3001 END IF;
3002 INSERT INTO RA_INTERFACE_LINES_ALL
3003 (CREATED_BY
3004 ,CREATION_DATE
3005 ,LAST_UPDATED_BY
3006 ,LAST_UPDATE_DATE
3007 ,INTERFACE_LINE_ATTRIBUTE1
3008 ,INTERFACE_LINE_ATTRIBUTE2
3009 ,INTERFACE_LINE_ATTRIBUTE3
3010 ,INTERFACE_LINE_ATTRIBUTE4
3011 ,INTERFACE_LINE_ATTRIBUTE5
3012 ,INTERFACE_LINE_ATTRIBUTE6
3013 ,INTERFACE_LINE_ATTRIBUTE7
3014 ,INTERFACE_LINE_ATTRIBUTE8
3015 ,INTERFACE_LINE_ATTRIBUTE9
3016 ,INTERFACE_LINE_ATTRIBUTE10
3017 ,INTERFACE_LINE_ATTRIBUTE11
3018 ,INTERFACE_LINE_ATTRIBUTE12
3019 ,INTERFACE_LINE_ATTRIBUTE13
3020 ,INTERFACE_LINE_ATTRIBUTE14
3021 ,INTERFACE_LINE_ATTRIBUTE15
3022 ,INTERFACE_LINE_ID
3023 ,INTERFACE_LINE_CONTEXT
3024 ,WAREHOUSE_ID
3025 ,BATCH_SOURCE_NAME
3026 ,SET_OF_BOOKS_ID
3027 ,LINE_TYPE
3028 ,DESCRIPTION
3029 ,CURRENCY_CODE
3030 ,AMOUNT
3031 ,CONVERSION_TYPE
3032 ,CONVERSION_DATE
3033 ,CONVERSION_RATE
3034 ,CUST_TRX_TYPE_NAME
3035 ,CUST_TRX_TYPE_ID
3036 ,TERM_NAME
3037 ,TERM_ID
3038 ,ORIG_SYSTEM_BILL_CUSTOMER_REF
3039 ,ORIG_SYSTEM_BILL_CUSTOMER_ID
3040 ,ORIG_SYSTEM_BILL_ADDRESS_REF
3041 ,ORIG_SYSTEM_BILL_ADDRESS_ID
3042 ,ORIG_SYSTEM_BILL_CONTACT_REF
3043 ,ORIG_SYSTEM_BILL_CONTACT_ID
3044 ,ORIG_SYSTEM_SHIP_CUSTOMER_REF
3045 ,ORIG_SYSTEM_SHIP_CUSTOMER_ID
3046 ,ORIG_SYSTEM_SHIP_ADDRESS_REF
3047 ,ORIG_SYSTEM_SHIP_ADDRESS_ID
3048 ,ORIG_SYSTEM_SHIP_CONTACT_REF
3049 ,ORIG_SYSTEM_SHIP_CONTACT_ID
3050 ,ORIG_SYSTEM_SOLD_CUSTOMER_REF
3051 ,ORIG_SYSTEM_SOLD_CUSTOMER_ID
3052 ,LINK_TO_LINE_ID
3053 ,LINK_TO_LINE_CONTEXT
3054 ,LINK_TO_LINE_ATTRIBUTE1
3055 ,LINK_TO_LINE_ATTRIBUTE2
3056 ,LINK_TO_LINE_ATTRIBUTE3
3057 ,LINK_TO_LINE_ATTRIBUTE4
3058 ,LINK_TO_LINE_ATTRIBUTE5
3059 ,LINK_TO_LINE_ATTRIBUTE6
3060 ,LINK_TO_LINE_ATTRIBUTE7
3061 ,LINK_TO_LINE_ATTRIBUTE8
3062 ,LINK_TO_LINE_ATTRIBUTE9
3063 ,LINK_TO_LINE_ATTRIBUTE10
3064 ,LINK_TO_LINE_ATTRIBUTE11
3065 ,LINK_TO_LINE_ATTRIBUTE12
3066 ,LINK_TO_LINE_ATTRIBUTE13
3067 ,LINK_TO_LINE_ATTRIBUTE14
3068 ,LINK_TO_LINE_ATTRIBUTE15
3069 ,PAYMENT_TYPE_CODE --8427382
3070 ,RECEIPT_METHOD_NAME
3071 ,RECEIPT_METHOD_ID
3072 -- ,CUSTOMER_BANK_ACCOUNT_ID -- R12 cc encryption
3073 -- ,CUSTOMER_BANK_ACCOUNT_NAME
3074 -- ,PAYMENT_SERVER_ORDER_NUM
3075 -- ,APPROVAL_CODE
3076 ,CUSTOMER_TRX_ID
3077 ,TRX_DATE
3078 ,GL_DATE
3079 ,DOCUMENT_NUMBER
3080 ,DOCUMENT_NUMBER_SEQUENCE_ID
3081 ,TRX_NUMBER
3082 ,QUANTITY
3083 ,QUANTITY_ORDERED
3084 ,UNIT_SELLING_PRICE
3085 ,UNIT_STANDARD_PRICE
3086 ,UOM_CODE
3087 ,UOM_NAME
3088 ,PRINTING_OPTION
3089 ,INTERFACE_STATUS
3090 ,REQUEST_ID
3091 ,RELATED_BATCH_SOURCE_NAME
3092 ,RELATED_TRX_NUMBER
3093 ,RELATED_CUSTOMER_TRX_ID
3094 ,PREVIOUS_CUSTOMER_TRX_ID
3095 ,INITIAL_CUSTOMER_TRX_ID
3096 ,CREDIT_METHOD_FOR_ACCT_RULE
3097 ,CREDIT_METHOD_FOR_INSTALLMENTS
3098 ,REASON_CODE_MEANING
3099 ,REASON_CODE
3100 ,TAX_RATE
3101 ,TAX_CODE
3102 ,TAX_PRECEDENCE
3103 ,TAX_EXEMPT_FLAG
3104 ,TAX_EXEMPT_NUMBER
3105 ,TAX_EXEMPT_REASON_CODE
3106 ,EXCEPTION_ID
3107 ,EXEMPTION_ID
3108 ,SHIP_DATE_ACTUAL
3109 ,FOB_POINT
3110 ,SHIP_VIA
3111 ,WAYBILL_NUMBER
3112 ,INVOICING_RULE_NAME
3113 ,INVOICING_RULE_ID
3114 ,ACCOUNTING_RULE_NAME
3115 ,ACCOUNTING_RULE_ID
3116 ,ACCOUNTING_RULE_DURATION
3117 ,RULE_START_DATE
3118 ,RULE_END_DATE --bug5336618
3119 ,PRIMARY_SALESREP_NUMBER
3120 ,PRIMARY_SALESREP_ID
3121 ,SALES_ORDER
3122 ,SALES_ORDER_LINE
3123 ,SALES_ORDER_DATE
3124 ,SALES_ORDER_SOURCE
3125 ,SALES_ORDER_REVISION
3126 ,PURCHASE_ORDER
3127 ,PURCHASE_ORDER_REVISION
3128 ,PURCHASE_ORDER_DATE
3129 ,AGREEMENT_NAME
3130 ,AGREEMENT_ID
3131 ,MEMO_LINE_NAME
3132 ,MEMO_LINE_ID
3133 ,INVENTORY_ITEM_ID
3134 ,MTL_SYSTEM_ITEMS_SEG1
3135 ,MTL_SYSTEM_ITEMS_SEG2
3136 ,MTL_SYSTEM_ITEMS_SEG3
3137 ,MTL_SYSTEM_ITEMS_SEG4
3138 ,MTL_SYSTEM_ITEMS_SEG5
3139 ,MTL_SYSTEM_ITEMS_SEG6
3140 ,MTL_SYSTEM_ITEMS_SEG7
3141 ,MTL_SYSTEM_ITEMS_SEG8
3142 ,MTL_SYSTEM_ITEMS_SEG9
3143 ,MTL_SYSTEM_ITEMS_SEG10
3144 ,MTL_SYSTEM_ITEMS_SEG11
3145 ,MTL_SYSTEM_ITEMS_SEG12
3146 ,MTL_SYSTEM_ITEMS_SEG13
3147 ,MTL_SYSTEM_ITEMS_SEG14
3148 ,MTL_SYSTEM_ITEMS_SEG15
3149 ,MTL_SYSTEM_ITEMS_SEG16
3150 ,MTL_SYSTEM_ITEMS_SEG17
3151 ,MTL_SYSTEM_ITEMS_SEG18
3152 ,MTL_SYSTEM_ITEMS_SEG19
3153 ,MTL_SYSTEM_ITEMS_SEG20
3154 ,REFERENCE_LINE_ID
3155 ,REFERENCE_LINE_CONTEXT
3156 ,REFERENCE_LINE_ATTRIBUTE1
3157 ,REFERENCE_LINE_ATTRIBUTE2
3158 ,REFERENCE_LINE_ATTRIBUTE3
3159 ,REFERENCE_LINE_ATTRIBUTE4
3160 ,REFERENCE_LINE_ATTRIBUTE5
3161 ,REFERENCE_LINE_ATTRIBUTE6
3162 ,REFERENCE_LINE_ATTRIBUTE7
3163 ,REFERENCE_LINE_ATTRIBUTE8
3164 ,REFERENCE_LINE_ATTRIBUTE9
3165 ,REFERENCE_LINE_ATTRIBUTE10
3166 ,REFERENCE_LINE_ATTRIBUTE11
3167 ,REFERENCE_LINE_ATTRIBUTE12
3168 ,REFERENCE_LINE_ATTRIBUTE13
3169 ,REFERENCE_LINE_ATTRIBUTE14
3170 ,REFERENCE_LINE_ATTRIBUTE15
3171 ,TERRITORY_ID
3172 ,TERRITORY_SEGMENT1
3173 ,TERRITORY_SEGMENT2
3174 ,TERRITORY_SEGMENT3
3175 ,TERRITORY_SEGMENT4
3176 ,TERRITORY_SEGMENT5
3177 ,TERRITORY_SEGMENT6
3178 ,TERRITORY_SEGMENT7
3179 ,TERRITORY_SEGMENT8
3180 ,TERRITORY_SEGMENT9
3181 ,TERRITORY_SEGMENT10
3182 ,TERRITORY_SEGMENT11
3183 ,TERRITORY_SEGMENT12
3184 ,TERRITORY_SEGMENT13
3185 ,TERRITORY_SEGMENT14
3186 ,TERRITORY_SEGMENT15
3187 ,TERRITORY_SEGMENT16
3188 ,TERRITORY_SEGMENT17
3189 ,TERRITORY_SEGMENT18
3190 ,TERRITORY_SEGMENT19
3191 ,TERRITORY_SEGMENT20
3192 ,ATTRIBUTE_CATEGORY
3193 ,ATTRIBUTE1
3194 ,ATTRIBUTE2
3195 ,ATTRIBUTE3
3196 ,ATTRIBUTE4
3197 ,ATTRIBUTE5
3198 ,ATTRIBUTE6
3199 ,ATTRIBUTE7
3200 ,ATTRIBUTE8
3201 ,ATTRIBUTE9
3202 ,ATTRIBUTE10
3203 ,ATTRIBUTE11
3204 ,ATTRIBUTE12
3205 ,ATTRIBUTE13
3206 ,ATTRIBUTE14
3207 ,ATTRIBUTE15
3208 ,HEADER_ATTRIBUTE_CATEGORY
3209 ,HEADER_ATTRIBUTE1
3210 ,HEADER_ATTRIBUTE2
3211 ,HEADER_ATTRIBUTE3
3212 ,HEADER_ATTRIBUTE4
3213 ,HEADER_ATTRIBUTE5
3214 ,HEADER_ATTRIBUTE6
3215 ,HEADER_ATTRIBUTE7
3216 ,HEADER_ATTRIBUTE8
3217 ,HEADER_ATTRIBUTE9
3218 ,HEADER_ATTRIBUTE10
3219 ,HEADER_ATTRIBUTE11
3220 ,HEADER_ATTRIBUTE12
3221 ,HEADER_ATTRIBUTE13
3222 ,HEADER_ATTRIBUTE14
3223 ,HEADER_ATTRIBUTE15
3224 ,COMMENTS
3225 ,INTERNAL_NOTES
3226 ,MOVEMENT_ID
3227 ,ORG_ID
3228 ,HEADER_GDF_ATTR_CATEGORY
3229 ,HEADER_GDF_ATTRIBUTE1
3230 ,HEADER_GDF_ATTRIBUTE2
3231 ,HEADER_GDF_ATTRIBUTE3
3232 ,HEADER_GDF_ATTRIBUTE4
3233 ,HEADER_GDF_ATTRIBUTE5
3234 ,HEADER_GDF_ATTRIBUTE6
3235 ,HEADER_GDF_ATTRIBUTE7
3236 ,HEADER_GDF_ATTRIBUTE8
3237 ,HEADER_GDF_ATTRIBUTE9
3238 ,HEADER_GDF_ATTRIBUTE10
3239 ,HEADER_GDF_ATTRIBUTE11
3240 ,HEADER_GDF_ATTRIBUTE12
3241 ,HEADER_GDF_ATTRIBUTE13
3242 ,HEADER_GDF_ATTRIBUTE14
3243 ,HEADER_GDF_ATTRIBUTE15
3244 ,HEADER_GDF_ATTRIBUTE16
3245 ,HEADER_GDF_ATTRIBUTE17
3246 ,HEADER_GDF_ATTRIBUTE18
3247 ,HEADER_GDF_ATTRIBUTE19
3248 ,HEADER_GDF_ATTRIBUTE20
3249 ,HEADER_GDF_ATTRIBUTE21
3250 ,HEADER_GDF_ATTRIBUTE22
3251 ,HEADER_GDF_ATTRIBUTE23
3252 ,HEADER_GDF_ATTRIBUTE24
3253 ,HEADER_GDF_ATTRIBUTE25
3254 ,HEADER_GDF_ATTRIBUTE26
3255 ,HEADER_GDF_ATTRIBUTE27
3256 ,HEADER_GDF_ATTRIBUTE28
3257 ,HEADER_GDF_ATTRIBUTE29
3258 ,HEADER_GDF_ATTRIBUTE30
3259 ,LINE_GDF_ATTR_CATEGORY
3260 ,LINE_GDF_ATTRIBUTE1
3261 ,LINE_GDF_ATTRIBUTE2
3262 ,LINE_GDF_ATTRIBUTE3
3263 ,LINE_GDF_ATTRIBUTE4
3264 ,LINE_GDF_ATTRIBUTE5
3265 ,LINE_GDF_ATTRIBUTE6
3266 ,LINE_GDF_ATTRIBUTE7
3267 ,LINE_GDF_ATTRIBUTE8
3268 ,LINE_GDF_ATTRIBUTE9
3269 ,LINE_GDF_ATTRIBUTE10
3270 ,LINE_GDF_ATTRIBUTE11
3271 ,LINE_GDF_ATTRIBUTE12
3272 ,LINE_GDF_ATTRIBUTE13
3273 ,LINE_GDF_ATTRIBUTE14
3274 ,LINE_GDF_ATTRIBUTE15
3275 ,LINE_GDF_ATTRIBUTE16
3276 ,LINE_GDF_ATTRIBUTE17
3277 ,LINE_GDF_ATTRIBUTE18
3278 ,LINE_GDF_ATTRIBUTE19
3279 ,LINE_GDF_ATTRIBUTE20
3280 ,TRANSLATED_DESCRIPTION
3281 ,PAYMENT_TRXN_EXTENSION_ID
3282 ,PARENT_LINE_ID
3283 ,DEFERRAL_EXCLUSION_FLAG
3284 )
3285 VALUES (
3286 p_interface_line_rec.CREATED_BY
3287 ,p_interface_line_rec.CREATION_DATE
3288 ,p_interface_line_rec.LAST_UPDATED_BY
3289 ,p_interface_line_rec.LAST_UPDATE_DATE
3290 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1
3291 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2
3292 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3
3293 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4
3294 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5
3295 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE6
3296 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7
3297 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8
3298 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9
3299 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE10
3300 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE11
3301 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE12
3302 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE13
3303 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE14
3304 ,p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE15
3305 ,p_interface_line_rec.INTERFACE_LINE_ID
3306 ,p_interface_line_rec.INTERFACE_LINE_CONTEXT
3307 ,p_interface_line_rec.WAREHOUSE_ID
3308 ,p_interface_line_rec.BATCH_SOURCE_NAME
3309 ,p_interface_line_rec.SET_OF_BOOKS_ID
3310 ,p_interface_line_rec.LINE_TYPE
3311 ,p_interface_line_rec.DESCRIPTION
3312 ,p_interface_line_rec.CURRENCY_CODE
3313 ,p_interface_line_rec.AMOUNT
3314 ,p_interface_line_rec.CONVERSION_TYPE
3315 ,p_interface_line_rec.CONVERSION_DATE
3316 ,p_interface_line_rec.CONVERSION_RATE
3317 ,p_interface_line_rec.CUST_TRX_TYPE_NAME
3318 ,p_interface_line_rec.CUST_TRX_TYPE_ID
3319 ,p_interface_line_rec.TERM_NAME
3320 ,p_interface_line_rec.TERM_ID
3321 ,p_interface_line_rec.ORIG_SYSTEM_BILL_CUSTOMER_REF
3322 ,p_interface_line_rec.ORIG_SYSTEM_BILL_CUSTOMER_ID
3323 ,p_interface_line_rec.ORIG_SYSTEM_BILL_ADDRESS_REF
3324 ,p_interface_line_rec.ORIG_SYSTEM_BILL_ADDRESS_ID
3325 ,p_interface_line_rec.ORIG_SYSTEM_BILL_CONTACT_REF
3326 ,p_interface_line_rec.ORIG_SYSTEM_BILL_CONTACT_ID
3327 ,p_interface_line_rec.ORIG_SYSTEM_SHIP_CUSTOMER_REF
3328 ,p_interface_line_rec.ORIG_SYSTEM_SHIP_CUSTOMER_ID
3329 ,p_interface_line_rec.ORIG_SYSTEM_SHIP_ADDRESS_REF
3330 ,p_interface_line_rec.ORIG_SYSTEM_SHIP_ADDRESS_ID
3331 ,p_interface_line_rec.ORIG_SYSTEM_SHIP_CONTACT_REF
3332 ,p_interface_line_rec.ORIG_SYSTEM_SHIP_CONTACT_ID
3333 ,p_interface_line_rec.ORIG_SYSTEM_SOLD_CUSTOMER_REF
3334 ,p_interface_line_rec.ORIG_SYSTEM_SOLD_CUSTOMER_ID
3335 ,p_interface_line_rec.LINK_TO_LINE_ID
3336 ,p_interface_line_rec.LINK_TO_LINE_CONTEXT
3337 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE1
3338 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE2
3339 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE3
3340 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE4
3341 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE5
3342 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE6
3343 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE7
3344 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE8
3345 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE9
3346 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE10
3347 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE11
3348 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE12
3349 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE13
3350 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE14
3351 ,p_interface_line_rec.LINK_TO_LINE_ATTRIBUTE15
3352 ,p_interface_line_rec.payment_type_code --8427382
3353 ,p_interface_line_rec.RECEIPT_METHOD_NAME
3354 ,p_interface_line_rec.RECEIPT_METHOD_ID
3355 -- ,p_interface_line_rec.CUSTOMER_BANK_ACCOUNT_ID -- R12 cc encryption
3356 -- ,p_interface_line_rec.CUSTOMER_BANK_ACCOUNT_NAME
3357 -- ,p_interface_line_rec.PAYMENT_SERVER_ORDER_NUM
3358 -- ,p_interface_line_rec.APPROVAL_CODE
3359 ,p_interface_line_rec.CUSTOMER_TRX_ID
3360 ,p_interface_line_rec.TRX_DATE
3361 ,p_interface_line_rec.GL_DATE
3362 ,p_interface_line_rec.DOCUMENT_NUMBER
3363 ,p_interface_line_rec.DOCUMENT_NUMBER_SEQUENCE_ID
3364 ,p_interface_line_rec.TRX_NUMBER
3365 ,p_interface_line_rec.QUANTITY
3366 ,p_interface_line_rec.QUANTITY_ORDERED
3367 ,p_interface_line_rec.UNIT_SELLING_PRICE
3368 ,p_interface_line_rec.UNIT_STANDARD_PRICE
3369 ,p_interface_line_rec.UOM_CODE
3370 ,p_interface_line_rec.UOM_NAME
3371 ,p_interface_line_rec.PRINTING_OPTION
3372 ,p_interface_line_rec.INTERFACE_STATUS
3373 ,p_interface_line_rec.REQUEST_ID
3374 ,p_interface_line_rec.RELATED_BATCH_SOURCE_NAME
3375 ,p_interface_line_rec.RELATED_TRX_NUMBER
3376 ,p_interface_line_rec.RELATED_CUSTOMER_TRX_ID
3377 ,p_interface_line_rec.PREVIOUS_CUSTOMER_TRX_ID
3378 ,p_interface_line_rec.INITIAL_CUSTOMER_TRX_ID
3379 ,p_interface_line_rec.CREDIT_METHOD_FOR_ACCT_RULE
3380 ,p_interface_line_rec.CREDIT_METHOD_FOR_INSTALLMENTS
3381 ,p_interface_line_rec.REASON_CODE_MEANING
3382 ,p_interface_line_rec.REASON_CODE
3383 ,p_interface_line_rec.TAX_RATE
3384 ,p_interface_line_rec.TAX_CODE
3385 ,p_interface_line_rec.TAX_PRECEDENCE
3386 ,p_interface_line_rec.TAX_EXEMPT_FLAG
3387 ,p_interface_line_rec.TAX_EXEMPT_NUMBER
3388 ,p_interface_line_rec.TAX_EXEMPT_REASON_CODE
3389 ,p_interface_line_rec.EXCEPTION_ID
3390 ,p_interface_line_rec.EXEMPTION_ID
3391 ,p_interface_line_rec.SHIP_DATE_ACTUAL
3392 ,p_interface_line_rec.FOB_POINT
3393 ,p_interface_line_rec.SHIP_VIA
3394 ,p_interface_line_rec.WAYBILL_NUMBER
3395 ,p_interface_line_rec.INVOICING_RULE_NAME
3396 ,p_interface_line_rec.INVOICING_RULE_ID
3397 ,p_interface_line_rec.ACCOUNTING_RULE_NAME
3398 ,p_interface_line_rec.ACCOUNTING_RULE_ID
3399 ,p_interface_line_rec.ACCOUNTING_RULE_DURATION
3400 ,p_interface_line_rec.RULE_START_DATE
3401 ,p_interface_line_rec.RULE_END_DATE --bug5336618
3402 ,p_interface_line_rec.PRIMARY_SALESREP_NUMBER
3403 ,p_interface_line_rec.PRIMARY_SALESREP_ID
3404 ,p_interface_line_rec.SALES_ORDER
3405 ,p_interface_line_rec.SALES_ORDER_LINE
3406 ,p_interface_line_rec.SALES_ORDER_DATE
3407 ,p_interface_line_rec.SALES_ORDER_SOURCE
3408 ,p_interface_line_rec.SALES_ORDER_REVISION
3409 ,p_interface_line_rec.PURCHASE_ORDER
3410 ,p_interface_line_rec.PURCHASE_ORDER_REVISION
3411 ,p_interface_line_rec.PURCHASE_ORDER_DATE
3412 ,p_interface_line_rec.AGREEMENT_NAME
3413 ,p_interface_line_rec.AGREEMENT_ID
3414 ,p_interface_line_rec.MEMO_LINE_NAME
3415 ,p_interface_line_rec.MEMO_LINE_ID
3416 ,p_interface_line_rec.INVENTORY_ITEM_ID
3417 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG1
3418 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG2
3419 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG3
3420 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG4
3421 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG5
3422 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG6
3423 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG7
3424 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG8
3425 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG9
3426 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG10
3427 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG11
3428 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG12
3429 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG13
3430 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG14
3431 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG15
3432 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG16
3433 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG17
3434 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG18
3435 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG19
3436 ,p_interface_line_rec.MTL_SYSTEM_ITEMS_SEG20
3437 ,p_interface_line_rec.REFERENCE_LINE_ID
3438 ,p_interface_line_rec.REFERENCE_LINE_CONTEXT
3439 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE1
3440 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE2
3441 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE3
3442 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE4
3443 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE5
3444 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE6
3445 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE7
3446 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE8
3447 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE9
3448 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE10
3449 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE11
3450 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE12
3451 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE13
3452 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE14
3453 ,p_interface_line_rec.REFERENCE_LINE_ATTRIBUTE15
3454 ,p_interface_line_rec.TERRITORY_ID
3455 ,p_interface_line_rec.TERRITORY_SEGMENT1
3456 ,p_interface_line_rec.TERRITORY_SEGMENT2
3457 ,p_interface_line_rec.TERRITORY_SEGMENT3
3458 ,p_interface_line_rec.TERRITORY_SEGMENT4
3459 ,p_interface_line_rec.TERRITORY_SEGMENT5
3460 ,p_interface_line_rec.TERRITORY_SEGMENT6
3461 ,p_interface_line_rec.TERRITORY_SEGMENT7
3462 ,p_interface_line_rec.TERRITORY_SEGMENT8
3463 ,p_interface_line_rec.TERRITORY_SEGMENT9
3464 ,p_interface_line_rec.TERRITORY_SEGMENT10
3465 ,p_interface_line_rec.TERRITORY_SEGMENT11
3466 ,p_interface_line_rec.TERRITORY_SEGMENT12
3467 ,p_interface_line_rec.TERRITORY_SEGMENT13
3468 ,p_interface_line_rec.TERRITORY_SEGMENT14
3469 ,p_interface_line_rec.TERRITORY_SEGMENT15
3470 ,p_interface_line_rec.TERRITORY_SEGMENT16
3471 ,p_interface_line_rec.TERRITORY_SEGMENT17
3472 ,p_interface_line_rec.TERRITORY_SEGMENT18
3473 ,p_interface_line_rec.TERRITORY_SEGMENT19
3474 ,p_interface_line_rec.TERRITORY_SEGMENT20
3475 ,p_interface_line_rec.ATTRIBUTE_CATEGORY
3476 ,p_interface_line_rec.ATTRIBUTE1
3477 ,p_interface_line_rec.ATTRIBUTE2
3478 ,p_interface_line_rec.ATTRIBUTE3
3479 ,p_interface_line_rec.ATTRIBUTE4
3480 ,p_interface_line_rec.ATTRIBUTE5
3481 ,p_interface_line_rec.ATTRIBUTE6
3482 ,p_interface_line_rec.ATTRIBUTE7
3483 ,p_interface_line_rec.ATTRIBUTE8
3484 ,p_interface_line_rec.ATTRIBUTE9
3485 ,p_interface_line_rec.ATTRIBUTE10
3486 ,p_interface_line_rec.ATTRIBUTE11
3487 ,p_interface_line_rec.ATTRIBUTE12
3488 ,p_interface_line_rec.ATTRIBUTE13
3489 ,p_interface_line_rec.ATTRIBUTE14
3490 ,p_interface_line_rec.ATTRIBUTE15
3491 ,p_interface_line_rec.HEADER_ATTRIBUTE_CATEGORY
3492 ,p_interface_line_rec.HEADER_ATTRIBUTE1
3493 ,p_interface_line_rec.HEADER_ATTRIBUTE2
3494 ,p_interface_line_rec.HEADER_ATTRIBUTE3
3495 ,p_interface_line_rec.HEADER_ATTRIBUTE4
3496 ,p_interface_line_rec.HEADER_ATTRIBUTE5
3497 ,p_interface_line_rec.HEADER_ATTRIBUTE6
3498 ,p_interface_line_rec.HEADER_ATTRIBUTE7
3499 ,p_interface_line_rec.HEADER_ATTRIBUTE8
3500 ,p_interface_line_rec.HEADER_ATTRIBUTE9
3501 ,p_interface_line_rec.HEADER_ATTRIBUTE10
3502 ,p_interface_line_rec.HEADER_ATTRIBUTE11
3503 ,p_interface_line_rec.HEADER_ATTRIBUTE12
3504 ,p_interface_line_rec.HEADER_ATTRIBUTE13
3505 ,p_interface_line_rec.HEADER_ATTRIBUTE14
3506 ,p_interface_line_rec.HEADER_ATTRIBUTE15
3507 ,p_interface_line_rec.COMMENTS
3508 ,p_interface_line_rec.INTERNAL_NOTES
3509 ,p_interface_line_rec.MOVEMENT_ID
3510 ,p_interface_line_rec.ORG_ID
3511 ,p_interface_line_rec.HEADER_GDF_ATTR_CATEGORY
3512 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE1
3513 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE2
3514 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE3
3515 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE4
3516 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE5
3517 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE6
3518 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE7
3519 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE8
3520 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE9
3521 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE10
3522 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE11
3523 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE12
3524 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE13
3525 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE14
3526 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE15
3527 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE16
3528 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE17
3529 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE18
3530 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE19
3531 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE20
3532 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE21
3533 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE22
3534 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE23
3535 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE24
3536 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE25
3537 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE26
3538 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE27
3539 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE28
3540 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE29
3541 ,p_interface_line_rec.HEADER_GDF_ATTRIBUTE30
3542 ,p_interface_line_rec.LINE_GDF_ATTR_CATEGORY
3543 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE1
3544 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE2
3545 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE3
3546 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE4
3547 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE5
3548 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE6
3549 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE7
3550 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE8
3551 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE9
3552 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE10
3553 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE11
3554 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE12
3555 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE13
3556 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE14
3557 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE15
3558 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE16
3559 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE17
3560 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE18
3561 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE19
3562 ,p_interface_line_rec.LINE_GDF_ATTRIBUTE20
3563 ,p_interface_line_rec.TRANSLATED_DESCRIPTION
3564 ,p_interface_line_rec.payment_trxn_extension_id
3565 ,p_interface_line_rec.PARENT_LINE_ID
3566 ,p_interface_line_rec.DEFERRAL_EXCLUSION_FLAG
3567 ) RETURNING rowid INTO l_rowid;
3568
3569 IF l_debug_level > 0 THEN
3570 oe_debug_pub.add( 'INSERT COMPLETED' , 1 ) ;
3571 END IF;
3572 IF OE_Commitment_Pvt.DO_Commitment_Sequencing
3573 AND p_interface_line_rec.promised_commitment_amount IS NOT NULL THEN
3574 IF l_debug_level > 0 THEN
3575 oe_debug_pub.add( 'BUILD UPDATE STATEMENT WITH PROMISED COMMITMENT AMOUNT' , 1 ) ;
3576 END IF;
3577 update_sql_stmt := 'UPDATE RA_INTERFACE_LINES_ALL
3578 SET PROMISED_COMMITMENT_AMOUNT = :1
3579 WHERE ROWID = :r1';
3580 IF l_debug_level > 0 THEN
3581 oe_debug_pub.add( 'EXECUTING UPDATE STMT FOR PROMISED_COMMITMENT_AMOUNT' , 1 ) ;
3582 END IF;
3583 EXECUTE IMMEDIATE update_sql_stmt USING
3584 p_interface_line_rec.promised_commitment_amount
3585 ,l_rowid;
3586 END IF;
3587
3588 /* START PREPAYMENT */
3589 IF p_interface_line_rec.payment_set_id IS NOT NULL THEN
3590 IF l_debug_level > 0 THEN
3591 oe_debug_pub.add( 'BUILD UPDATE STATEMENT WITH PAYMENT_SET_ID' , 1 ) ;
3592 END IF;
3593 update_sql_stmt1 := 'UPDATE RA_INTERFACE_LINES_ALL
3594 SET PAYMENT_SET_ID = :2
3595 WHERE ROWID = :r2';
3596 IF l_debug_level > 0 THEN
3597 oe_debug_pub.add( 'EXECUTING UPDATE STMT FOR PAYMENT_SET_ID: '||P_INTERFACE_LINE_REC.PAYMENT_SET_ID , 1 ) ;
3598 END IF;
3599 EXECUTE IMMEDIATE update_sql_stmt1 USING
3600 p_interface_line_rec.PAYMENT_SET_ID
3601 ,l_rowid;
3602 END IF;
3603 /* END PREPAYMENT */
3604 -- Fix for the bug 2187074
3605 x_return_status := FND_API.G_RET_STS_SUCCESS;
3606 IF l_debug_level > 0 THEN
3607 oe_debug_pub.add( 'EXIT INSERT_LINE ( ) PROCEDURE' , 1 ) ;
3608 END IF;
3609 EXCEPTION
3610 WHEN OTHERS THEN
3611 err_msg := 'Error while inserting to RA_INTERFACE_LINES_ALL :\n '|| SQLERRM;
3612 IF l_debug_level > 0 THEN
3613 oe_debug_pub.add( ERR_MSG || ' SQLCODE: '||TO_CHAR ( SQLCODE ) , 1 ) ;
3614 END IF;
3615 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3616 OE_MSG_PUB.Add_Exc_Msg
3617 ( G_PKG_NAME
3618 , 'Insert_Line'
3619 );
3620 END IF;
3621 /* fix for 2140223, do not raise hard error, but capture error in debug log */
3622 -- raise_application_error(-20101, 'Failing while inserting into ra_interface_lines');
3623 -- Fix for the bug 2187074
3624 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3625 END Insert_Line;
3626
3627 PROCEDURE Prepare_Salescredit_rec
3628 ( p_line_scredit_rec IN OE_Order_Pub.Line_Scredit_Rec_Type
3629 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
3630 , x_interface_scredit_rec OUT NOCOPY RA_Interface_Scredits_Rec_Type
3631 ) IS
3632 --
3633 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3634 --
3635 BEGIN
3636 IF l_debug_level > 0 THEN
3637 oe_debug_pub.add( 'ENTER LINE PREPARE_SALESCREDIT_REC ( ) PROCEDURE' , 5 ) ;
3638 END IF;
3639
3640 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
3641 x_interface_scredit_rec.CREATION_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
3642 x_interface_scredit_rec.LAST_UPDATE_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
3643 ELSE
3644 x_interface_scredit_rec.CREATION_DATE := sysdate;
3645 x_interface_scredit_rec.LAST_UPDATE_DATE := sysdate;
3646 END IF;
3647
3648 x_interface_scredit_rec.CREATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
3649 x_interface_scredit_rec.LAST_UPDATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
3650 x_interface_scredit_rec.INTERFACE_SALESCREDIT_ID := NULL;
3651 x_interface_scredit_rec.INTERFACE_LINE_ID := NULL;
3652 x_interface_scredit_rec.INTERFACE_LINE_CONTEXT := p_interface_line_rec.INTERFACE_LINE_CONTEXT;
3653 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE1 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1;
3654 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE2 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2;
3655 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE3 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3;
3656 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE4 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4;
3657 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE5 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5;
3658 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE6 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE6;
3659 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE7 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7;
3660 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE8 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8;
3661 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE9 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9;
3662 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE10 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE10;
3663 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE11 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE11;
3664 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE12 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE12;
3665 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE13 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE13;
3666 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE14 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE14;
3667 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE15 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE15;
3668 x_interface_scredit_rec.SALESREP_NUMBER := NULL;
3669 x_interface_scredit_rec.SALESREP_ID := p_line_scredit_rec.salesrep_id;
3670 x_interface_scredit_rec.SALES_CREDIT_TYPE_ID := p_line_scredit_rec.sales_credit_type_id;
3671 x_interface_scredit_rec.SALES_CREDIT_PERCENT_SPLIT := p_line_scredit_rec.percent;
3672 x_interface_scredit_rec.ATTRIBUTE_CATEGORY := p_line_scredit_rec.context;
3673 --SG
3674 x_interface_scredit_rec.SALES_GROUP_ID := p_line_scredit_rec.sales_group_id;
3675 --SG
3676
3677 --oe_debug_pub.add(x_interface_scredit_rec.SALES_GROUP_ID);
3678
3679 --oe_debug_pub.add(
3680 x_interface_scredit_rec.ATTRIBUTE1 := substrb(p_line_scredit_rec.attribute1, 1, 150);
3681 x_interface_scredit_rec.ATTRIBUTE2 := substrb(p_line_scredit_rec.attribute2, 1, 150);
3682 x_interface_scredit_rec.ATTRIBUTE3 := substrb(p_line_scredit_rec.attribute3, 1, 150);
3683 x_interface_scredit_rec.ATTRIBUTE4 := substrb(p_line_scredit_rec.attribute4, 1, 150);
3684 x_interface_scredit_rec.ATTRIBUTE5 := substrb(p_line_scredit_rec.attribute5, 1, 150);
3685 x_interface_scredit_rec.ATTRIBUTE6 := substrb(p_line_scredit_rec.attribute6, 1, 150);
3686 x_interface_scredit_rec.ATTRIBUTE7 := substrb(p_line_scredit_rec.attribute7, 1, 150);
3687 x_interface_scredit_rec.ATTRIBUTE8 := substrb(p_line_scredit_rec.attribute8, 1, 150);
3688 x_interface_scredit_rec.ATTRIBUTE9 := substrb(p_line_scredit_rec.attribute9, 1, 150);
3689 x_interface_scredit_rec.ATTRIBUTE10 := substrb(p_line_scredit_rec.attribute10, 1, 150);
3690 x_interface_scredit_rec.ATTRIBUTE11 := substrb(p_line_scredit_rec.attribute11, 1, 150);
3691 x_interface_scredit_rec.ATTRIBUTE12 := substrb(p_line_scredit_rec.attribute12, 1, 150);
3692 x_interface_scredit_rec.ATTRIBUTE13 := substrb(p_line_scredit_rec.attribute13, 1, 150);
3693 x_interface_scredit_rec.ATTRIBUTE14 := substrb(p_line_scredit_rec.attribute14, 1, 150);
3694 x_interface_scredit_rec.ATTRIBUTE15 := substrb(p_line_scredit_rec.attribute15, 1, 150);
3695 x_interface_scredit_rec.ORG_ID := p_interface_line_rec.org_id;
3696
3697 IF l_debug_level > 0 THEN
3698 oe_debug_pub.add ( 'value of sysdate '||sysdate);
3699 oe_debug_pub.add ( 'value of CREATION_DATE '||x_interface_scredit_rec.CREATION_DATE||
3700 ' value of LAST_UPDATE_DATE '|| x_interface_scredit_rec.LAST_UPDATE_DATE);
3701 END IF;
3702
3703 IF l_debug_level > 0 THEN
3704 oe_debug_pub.add( 'EXITING LINE PREPARE_SALESCREDIT_REC' , 5 ) ;
3705 END IF;
3706 END Prepare_Salescredit_rec;
3707
3708 PROCEDURE Prepare_Salescredit_rec
3709 ( p_header_scredit_rec IN OE_Order_Pub.Header_Scredit_Rec_Type
3710 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
3711 , x_interface_scredit_rec OUT NOCOPY RA_Interface_Scredits_Rec_Type
3712 ) IS
3713 --
3714 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3715 --
3716 BEGIN
3717 IF l_debug_level > 0 THEN
3718 oe_debug_pub.add( 'ENTER HEADER PREPARE_SALESCREDIT_REC ( ) PROCEDURE ' , 5 ) ;
3719 END IF;
3720
3721 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
3722 x_interface_scredit_rec.CREATION_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
3723 x_interface_scredit_rec.LAST_UPDATE_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
3724 ELSE
3725 x_interface_scredit_rec.CREATION_DATE := sysdate;
3726 x_interface_scredit_rec.LAST_UPDATE_DATE := sysdate;
3727 END IF;
3728
3729 x_interface_scredit_rec.CREATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
3730 x_interface_scredit_rec.LAST_UPDATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
3731 x_interface_scredit_rec.INTERFACE_SALESCREDIT_ID := NULL;
3732 x_interface_scredit_rec.INTERFACE_LINE_ID := NULL;
3733 x_interface_scredit_rec.INTERFACE_LINE_CONTEXT := p_interface_line_rec.INTERFACE_LINE_CONTEXT;
3734 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE1 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1;
3735 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE2 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2;
3736 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE3 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3;
3737 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE4 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4;
3738 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE5 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5;
3739 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE6 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE6;
3740 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE7 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7;
3741 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE8 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8;
3742 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE9 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9;
3743 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE10 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE10;
3744 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE11 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE11;
3745 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE12 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE12;
3746 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE13 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE13;
3747 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE14 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE14;
3748 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE15 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE15;
3749 x_interface_scredit_rec.SALESREP_NUMBER := NULL;
3750 x_interface_scredit_rec.SALESREP_ID := p_header_scredit_rec.salesrep_id;
3751 x_interface_scredit_rec.SALES_CREDIT_TYPE_ID := p_header_scredit_rec.sales_credit_type_id;
3752 x_interface_scredit_rec.SALES_CREDIT_PERCENT_SPLIT := p_header_scredit_rec.percent;
3753 x_interface_scredit_rec.ATTRIBUTE_CATEGORY := p_header_scredit_rec.context;
3754 --SG{
3755 x_interface_scredit_rec.SALES_GROUP_ID := p_header_scredit_rec.sales_group_id;
3756 --SG}
3757 x_interface_scredit_rec.ATTRIBUTE1 := substrb(p_header_scredit_rec.attribute1, 1, 150);
3758 x_interface_scredit_rec.ATTRIBUTE2 := substrb(p_header_scredit_rec.attribute2, 1, 150);
3759 x_interface_scredit_rec.ATTRIBUTE3 := substrb(p_header_scredit_rec.attribute3, 1, 150);
3760 x_interface_scredit_rec.ATTRIBUTE4 := substrb(p_header_scredit_rec.attribute4, 1, 150);
3761 x_interface_scredit_rec.ATTRIBUTE5 := substrb(p_header_scredit_rec.attribute5, 1, 150);
3762 x_interface_scredit_rec.ATTRIBUTE6 := substrb(p_header_scredit_rec.attribute6, 1, 150);
3763 x_interface_scredit_rec.ATTRIBUTE7 := substrb(p_header_scredit_rec.attribute7, 1, 150);
3764 x_interface_scredit_rec.ATTRIBUTE8 := substrb(p_header_scredit_rec.attribute8, 1, 150);
3765 x_interface_scredit_rec.ATTRIBUTE9 := substrb(p_header_scredit_rec.attribute9, 1, 150);
3766 x_interface_scredit_rec.ATTRIBUTE10 := substrb(p_header_scredit_rec.attribute10, 1, 150);
3767 x_interface_scredit_rec.ATTRIBUTE11 := substrb(p_header_scredit_rec.attribute11, 1, 150);
3768 x_interface_scredit_rec.ATTRIBUTE12 := substrb(p_header_scredit_rec.attribute12, 1, 150);
3769 x_interface_scredit_rec.ATTRIBUTE13 := substrb(p_header_scredit_rec.attribute13, 1, 150);
3770 x_interface_scredit_rec.ATTRIBUTE14 := substrb(p_header_scredit_rec.attribute14, 1, 150);
3771 x_interface_scredit_rec.ATTRIBUTE15 := substrb(p_header_scredit_rec.attribute15, 1, 150);
3772 -- Fix for bug2185729
3773 x_interface_scredit_rec.ORG_ID := p_interface_line_rec.org_id;
3774
3775 IF l_debug_level > 0 THEN
3776 oe_debug_pub.add ( 'value of sysdate '||sysdate);
3777 oe_debug_pub.add ( 'value of CREATION_DATE '||x_interface_scredit_rec.CREATION_DATE||
3778 ' value of LAST_UPDATE_DATE '|| x_interface_scredit_rec.LAST_UPDATE_DATE);
3779 END IF;
3780
3781 IF l_debug_level > 0 THEN
3782 oe_debug_pub.add( 'EXIT HEADER PREPARE_SALESCREDIT_REC ( ) PROCEDURE ' , 5 ) ;
3783 END IF;
3784 END Prepare_Salescredit_rec;
3785
3786 PROCEDURE Prepare_Salescredit_rec
3787 ( p_interface_line_rec IN RA_Interface_Lines_Rec_Type
3788 , x_interface_scredit_rec OUT NOCOPY RA_Interface_Scredits_Rec_Type
3789 ) IS
3790 --
3791 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3792 --
3793 BEGIN
3794 IF l_debug_level > 0 THEN
3795 oe_debug_pub.add( 'ENTER PREPARE_SALESCREDIT_REC ( ) PROCEDURE' , 1 ) ;
3796 END IF;
3797 --Fix for bug 2192220.
3798 Select SALES_CREDIT_TYPE_ID
3799 into x_interface_scredit_rec.SALES_CREDIT_TYPE_ID
3800 from ra_salesreps where salesrep_id=-3;
3801 IF l_debug_level > 0 THEN
3802 oe_debug_pub.add( 'SALES_CREDIT_TYPE_ID'||X_INTERFACE_SCREDIT_REC.SALES_CREDIT_TYPE_ID ) ;
3803 END IF;
3804
3805 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
3806 x_interface_scredit_rec.CREATION_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
3807 x_interface_scredit_rec.LAST_UPDATE_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
3808 ELSE
3809 x_interface_scredit_rec.CREATION_DATE := sysdate;
3810 x_interface_scredit_rec.LAST_UPDATE_DATE := sysdate;
3811 END IF;
3812
3813 x_interface_scredit_rec.CREATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
3814 x_interface_scredit_rec.LAST_UPDATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
3815 x_interface_scredit_rec.INTERFACE_SALESCREDIT_ID := NULL;
3816 x_interface_scredit_rec.INTERFACE_LINE_ID := NULL;
3817 x_interface_scredit_rec.INTERFACE_LINE_CONTEXT := p_interface_line_rec.INTERFACE_LINE_CONTEXT;
3818 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE1 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1;
3819 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE2 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2;
3820 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE3 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3;
3821 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE4 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4;
3822 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE5 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5;
3823 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE6 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE6;
3824 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE7 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7;
3825 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE8 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8;
3826 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE9 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9;
3827 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE10 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE10;
3828 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE11 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE11;
3829 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE12 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE12;
3830 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE13 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE13;
3831 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE14 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE14;
3832 x_interface_scredit_rec.INTERFACE_LINE_ATTRIBUTE15 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE15;
3833 x_interface_scredit_rec.SALESREP_NUMBER := NULL;
3834 x_interface_scredit_rec.SALESREP_ID := -3;
3835 --x_interface_scredit_rec.SALES_CREDIT_TYPE_ID := 1; Commented off as part of fix for bug 2192220
3836 x_interface_scredit_rec.SALES_CREDIT_PERCENT_SPLIT := 100;
3837 x_interface_scredit_rec.ATTRIBUTE_CATEGORY := NULL;
3838 x_interface_scredit_rec.ATTRIBUTE1 := NULL;
3839 x_interface_scredit_rec.ATTRIBUTE2 := NULL;
3840 x_interface_scredit_rec.ATTRIBUTE3 := NULL;
3841 x_interface_scredit_rec.ATTRIBUTE4 := NULL;
3842 x_interface_scredit_rec.ATTRIBUTE5 := NULL;
3843 x_interface_scredit_rec.ATTRIBUTE6 := NULL;
3844 x_interface_scredit_rec.ATTRIBUTE7 := NULL;
3845 x_interface_scredit_rec.ATTRIBUTE8 := NULL;
3846 x_interface_scredit_rec.ATTRIBUTE9 := NULL;
3847 x_interface_scredit_rec.ATTRIBUTE10 := NULL;
3848 x_interface_scredit_rec.ATTRIBUTE11 := NULL;
3849 x_interface_scredit_rec.ATTRIBUTE12 := NULL;
3850 x_interface_scredit_rec.ATTRIBUTE13 := NULL;
3851 x_interface_scredit_rec.ATTRIBUTE14 := NULL;
3852 x_interface_scredit_rec.ATTRIBUTE15 := NULL;
3853 -- Fix for bug2185729
3854 x_interface_scredit_rec.ORG_ID := p_interface_line_rec.org_id;
3855
3856 IF l_debug_level > 0 THEN
3857 oe_debug_pub.add ( 'value of sysdate '||sysdate);
3858 oe_debug_pub.add ( ' value of CREATION_DATE '||x_interface_scredit_rec.CREATION_DATE||
3859 ' value of LAST_UPDATE_DATE '|| x_interface_scredit_rec.LAST_UPDATE_DATE);
3860 END IF;
3861
3862 IF l_debug_level > 0 THEN
3863 oe_debug_pub.add( 'EXIT PREPARE_SALESCREDIT_REC ( ) PROCEDURE ' , 1 ) ;
3864 END IF;
3865 END Prepare_Salescredit_rec;
3866
3867 procedure convert_to_ar(p_oe_salescredit_rec IN Ra_Interface_Scredits_Rec_Type,
3868 x_ar_salescredit_rec OUT NOCOPY AR_InterfaceSalesCredits_GRP.salescredit_rec_type) IS
3869 Begin
3870 x_ar_salescredit_rec.INTERFACE_SALESCREDIT_ID :=p_oe_salescredit_rec.INTERFACE_SALESCREDIT_ID ;
3871 x_ar_salescredit_rec.INTERFACE_LINE_ID :=p_oe_salescredit_rec.INTERFACE_LINE_ID ;
3872 x_ar_salescredit_rec.INTERFACE_LINE_CONTEXT :=p_oe_salescredit_rec.INTERFACE_LINE_CONTEXT ;
3873 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE1 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE1;
3874 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE2 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE2;
3875 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE3 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE3;
3876 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE4 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE4;
3877 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE5 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE5;
3878 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE6 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE6;
3879 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE7 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE7;
3880 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE8 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE8;
3881 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE9 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE9;
3882 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE10 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE10;
3883 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE11 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE11;
3884 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE12 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE12;
3885 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE13 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE13;
3886 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE14 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE14;
3887 x_ar_salescredit_rec.INTERFACE_LINE_ATTRIBUTE15 :=p_oe_salescredit_rec.INTERFACE_LINE_ATTRIBUTE15;
3888 x_ar_salescredit_rec.SALESREP_NUMBER :=p_oe_salescredit_rec.SALESREP_NUMBER ;
3889 x_ar_salescredit_rec.SALESREP_ID :=p_oe_salescredit_rec.SALESREP_ID ;
3890 x_ar_salescredit_rec.SALESGROUP_ID :=p_oe_salescredit_rec.SALES_GROUP_ID ;
3891 x_ar_salescredit_rec.SALES_CREDIT_TYPE_NAME :=p_oe_salescredit_rec.SALES_CREDIT_TYPE_NAME ;
3892 x_ar_salescredit_rec.SALES_CREDIT_TYPE_ID :=p_oe_salescredit_rec.SALES_CREDIT_TYPE_ID ;
3893 x_ar_salescredit_rec.SALES_CREDIT_AMOUNT_SPLIT :=p_oe_salescredit_rec.SALES_CREDIT_AMOUNT_SPLIT;
3894 x_ar_salescredit_rec.SALES_CREDIT_PERCENT_SPLIT :=p_oe_salescredit_rec.SALES_CREDIT_PERCENT_SPLIT;
3895 x_ar_salescredit_rec.INTERFACE_STATUS :=p_oe_salescredit_rec.INTERFACE_STATUS ;
3896 x_ar_salescredit_rec.REQUEST_ID :=p_oe_salescredit_rec.REQUEST_ID ;
3897 x_ar_salescredit_rec.ATTRIBUTE_CATEGORY :=p_oe_salescredit_rec.ATTRIBUTE_CATEGORY ;
3898 x_ar_salescredit_rec.ATTRIBUTE1 :=p_oe_salescredit_rec.ATTRIBUTE1 ;
3899 x_ar_salescredit_rec.ATTRIBUTE2 :=p_oe_salescredit_rec.ATTRIBUTE2 ;
3900 x_ar_salescredit_rec.ATTRIBUTE3 :=p_oe_salescredit_rec.ATTRIBUTE3 ;
3901 x_ar_salescredit_rec.ATTRIBUTE4 :=p_oe_salescredit_rec.ATTRIBUTE4 ;
3902 x_ar_salescredit_rec.ATTRIBUTE5 :=p_oe_salescredit_rec.ATTRIBUTE5 ;
3903 x_ar_salescredit_rec.ATTRIBUTE6 :=p_oe_salescredit_rec.ATTRIBUTE6 ;
3904 x_ar_salescredit_rec.ATTRIBUTE7 :=p_oe_salescredit_rec.ATTRIBUTE7 ;
3905 x_ar_salescredit_rec.ATTRIBUTE8 :=p_oe_salescredit_rec.ATTRIBUTE8 ;
3906 x_ar_salescredit_rec.ATTRIBUTE9 :=p_oe_salescredit_rec.ATTRIBUTE9 ;
3907 x_ar_salescredit_rec.ATTRIBUTE10 :=p_oe_salescredit_rec.ATTRIBUTE10 ;
3908 x_ar_salescredit_rec.ATTRIBUTE11 :=p_oe_salescredit_rec.ATTRIBUTE11 ;
3909 x_ar_salescredit_rec.ATTRIBUTE12 :=p_oe_salescredit_rec.ATTRIBUTE12 ;
3910 x_ar_salescredit_rec.ATTRIBUTE13 :=p_oe_salescredit_rec.ATTRIBUTE13 ;
3911 x_ar_salescredit_rec.ATTRIBUTE14 :=p_oe_salescredit_rec.ATTRIBUTE14 ;
3912 x_ar_salescredit_rec.ATTRIBUTE15 :=p_oe_salescredit_rec.ATTRIBUTE15 ;
3913 x_ar_salescredit_rec.CREATED_BY :=p_oe_salescredit_rec.CREATED_BY ;
3914 x_ar_salescredit_rec.CREATION_DATE :=p_oe_salescredit_rec.CREATION_DATE ;
3915 x_ar_salescredit_rec.LAST_UPDATED_BY :=p_oe_salescredit_rec.LAST_UPDATED_BY ;
3916 x_ar_salescredit_rec.LAST_UPDATE_DATE :=p_oe_salescredit_rec.LAST_UPDATE_DATE ;
3917 --x_ar_salescredit_rec.LAST_UPDATE_LOGIN :=p_oe_salescredit_rec.LAST_UPDATE_LOGIN ;
3918 x_ar_salescredit_rec.ORG_ID :=p_oe_salescredit_rec.ORG_ID ;
3919
3920 End;
3921
3922
3923 PROCEDURE Insert_Salescredit
3924 ( p_salescredit_rec IN Ra_Interface_Scredits_Rec_Type
3925 ) IS
3926 --
3927 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3928 --
3929 l_msg_count NUMBER;
3930 l_msg_data VARCHAR2(2000);
3931 l_return_status VARCHAR2(15);
3932 l_ar_salescredit_rec AR_InterfaceSalesCredits_GRP.salescredit_rec_type;
3933 BEGIN
3934
3935
3936 IF l_debug_level > 0 THEN
3937 oe_debug_pub.add( 'INSERTING SALES CREDIT RECORDS ' , 5 ) ;
3938 END IF;
3939
3940 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
3941 --OE_Invoice_Ext_Pvt.Insert_Salescredit(p_salescredit_rec);
3942 convert_to_ar(p_oe_salescredit_rec=>p_salescredit_rec,
3943 x_ar_salescredit_rec=>l_ar_salescredit_rec);
3944
3945 AR_InterfaceSalesCredits_GRP.Insert_Salescredit(
3946 p_salescredit_rec=>l_ar_salescredit_rec,
3947 x_return_status =>l_return_status,
3948 x_msg_count =>l_msg_count,
3949 x_msg_data =>l_msg_data);
3950 ELSE --old behavior
3951 INSERT INTO RA_INTERFACE_SALESCREDITS_ALL
3952 (CREATED_BY
3953 ,CREATION_DATE
3954 ,LAST_UPDATED_BY
3955 ,LAST_UPDATE_DATE
3956 ,INTERFACE_SALESCREDIT_ID
3957 ,INTERFACE_LINE_ID
3958 ,INTERFACE_LINE_CONTEXT
3959 ,INTERFACE_LINE_ATTRIBUTE1
3960 ,INTERFACE_LINE_ATTRIBUTE2
3961 ,INTERFACE_LINE_ATTRIBUTE3
3962 ,INTERFACE_LINE_ATTRIBUTE4
3963 ,INTERFACE_LINE_ATTRIBUTE5
3964 ,INTERFACE_LINE_ATTRIBUTE6
3965 ,INTERFACE_LINE_ATTRIBUTE7
3966 ,INTERFACE_LINE_ATTRIBUTE8
3967 ,INTERFACE_LINE_ATTRIBUTE9
3968 ,INTERFACE_LINE_ATTRIBUTE10
3969 ,INTERFACE_LINE_ATTRIBUTE11
3970 ,INTERFACE_LINE_ATTRIBUTE12
3971 ,INTERFACE_LINE_ATTRIBUTE13
3972 ,INTERFACE_LINE_ATTRIBUTE14
3973 ,INTERFACE_LINE_ATTRIBUTE15
3974 ,SALESREP_NUMBER
3975 ,SALESREP_ID
3976 ,SALES_CREDIT_TYPE_NAME
3977 ,SALES_CREDIT_TYPE_ID
3978 ,SALES_CREDIT_AMOUNT_SPLIT
3979 ,SALES_CREDIT_PERCENT_SPLIT
3980 ,INTERFACE_STATUS
3981 ,REQUEST_ID
3982 ,ATTRIBUTE_CATEGORY
3983 ,ATTRIBUTE1
3984 ,ATTRIBUTE2
3985 ,ATTRIBUTE3
3986 ,ATTRIBUTE4
3987 ,ATTRIBUTE5
3988 ,ATTRIBUTE6
3989 ,ATTRIBUTE7
3990 ,ATTRIBUTE8
3991 ,ATTRIBUTE9
3992 ,ATTRIBUTE10
3993 ,ATTRIBUTE11
3994 ,ATTRIBUTE12
3995 ,ATTRIBUTE13
3996 ,ATTRIBUTE14
3997 ,ATTRIBUTE15
3998 ,ORG_ID)
3999 VALUES
4000 (p_salescredit_rec.CREATED_BY
4001 ,p_salescredit_rec.CREATION_DATE
4002 ,p_salescredit_rec.LAST_UPDATED_BY
4003 ,p_salescredit_rec.LAST_UPDATE_DATE
4004 ,p_salescredit_rec.INTERFACE_SALESCREDIT_ID
4005 ,p_salescredit_rec.INTERFACE_LINE_ID
4006 ,p_salescredit_rec.INTERFACE_LINE_CONTEXT
4007 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE1
4008 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE2
4009 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE3
4010 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE4
4011 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE5
4012 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE6
4013 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE7
4014 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE8
4015 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE9
4016 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE10
4017 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE11
4018 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE12
4019 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE13
4020 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE14
4021 ,p_salescredit_rec.INTERFACE_LINE_ATTRIBUTE15
4022 ,p_salescredit_rec.SALESREP_NUMBER
4023 ,p_salescredit_rec.SALESREP_ID
4024 ,p_salescredit_rec.SALES_CREDIT_TYPE_NAME
4025 ,p_salescredit_rec.SALES_CREDIT_TYPE_ID
4026 ,p_salescredit_rec.SALES_CREDIT_AMOUNT_SPLIT
4027 ,p_salescredit_rec.SALES_CREDIT_PERCENT_SPLIT
4028 ,p_salescredit_rec.INTERFACE_STATUS
4029 ,p_salescredit_rec.REQUEST_ID
4030 ,p_salescredit_rec.ATTRIBUTE_CATEGORY
4031 ,p_salescredit_rec.ATTRIBUTE1
4032 ,p_salescredit_rec.ATTRIBUTE2
4033 ,p_salescredit_rec.ATTRIBUTE3
4034 ,p_salescredit_rec.ATTRIBUTE4
4035 ,p_salescredit_rec.ATTRIBUTE5
4036 ,p_salescredit_rec.ATTRIBUTE6
4037 ,p_salescredit_rec.ATTRIBUTE7
4038 ,p_salescredit_rec.ATTRIBUTE8
4039 ,p_salescredit_rec.ATTRIBUTE9
4040 ,p_salescredit_rec.ATTRIBUTE10
4041 ,p_salescredit_rec.ATTRIBUTE11
4042 ,p_salescredit_rec.ATTRIBUTE12
4043 ,p_salescredit_rec.ATTRIBUTE13
4044 ,p_salescredit_rec.ATTRIBUTE14
4045 ,p_salescredit_rec.ATTRIBUTE15
4046 ,p_salescredit_rec.ORG_ID);
4047 END IF;
4048
4049 IF l_debug_level > 0 THEN
4050 oe_debug_pub.add( 'SUCCESSFULLY INSERTED SALES CREDIT RECORDS' , 5 ) ;
4051 END IF;
4052 EXCEPTION WHEN OTHERS THEN
4053 IF l_debug_level > 0 THEN
4054 oe_debug_pub.add( 'UNABLE TO INSERT SALES CREDIT RECORDS -> '||SQLERRM , 1 ) ;
4055 END IF;
4056 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4057 OE_MSG_PUB.Add_Exc_Msg
4058 ( G_PKG_NAME
4059 , 'Insert_Salescredit'
4060 );
4061 END IF;
4062 END Insert_Salescredit;
4063
4064 PROCEDURE Interface_SalesCredits
4065 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
4066 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
4067 , x_return_status OUT NOCOPY VARCHAR2
4068 )
4069 IS
4070 l_interface_scredit_rec RA_Interface_Scredits_Rec_Type;
4071 l_line_scredit_tbl OE_Order_Pub.Line_Scredit_Tbl_Type;
4072 l_header_scredit_tbl OE_Order_Pub.Header_Scredit_Tbl_Type;
4073 l_line_scredit_rec OE_Order_Pub.Line_Scredit_Rec_Type;
4074 l_header_scredit_rec OE_Order_Pub.Header_Scredit_Rec_Type;
4075 l_line_credits NUMBER := 0 ;
4076 l_header_credits NUMBER := 0 ;
4077 Insert_Header_Scredits_flag VARCHAR2(1);
4078 service_grand_parent_id NUMBER := 0;
4079 i NUMBER;
4080 l_quota_flag VARCHAR2(1);
4081 l_order_line_id NUMBER;
4082 l_return_status VARCHAR2(1);
4083 l_service_reference_line_id NUMBER;
4084
4085 --FP bug 3872166
4086 l_total_percent NUMBER;
4087
4088 --
4089 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4090 --
4091 BEGIN
4092 IF l_debug_level > 0 THEN
4093 oe_debug_pub.add( 'ENTER INTERFACE_SALES_CREDITS ( ) PROCEDURE ' , 5 ) ;
4094 END IF;
4095 FOR i IN 1..2 LOOP
4096 IF i=1 THEN
4097 l_quota_flag := 'Y';
4098 IF l_debug_level > 0 THEN
4099 oe_debug_pub.add( 'INSERTING QUOTA SALES CREDITS..' , 5 ) ;
4100 END IF;
4101 ELSIF i = 2 THEN
4102 l_quota_flag := 'N';
4103 IF l_debug_level > 0 THEN
4104 oe_debug_pub.add( 'INSERTING NON-QUOTA SALES CREDITS..' , 5 ) ;
4105 END IF;
4106 END IF;
4107 Query_Line_Scredits(p_line_id => p_line_rec.line_id
4108 ,p_quota_flag => l_quota_flag
4109 ,x_line_scredit_tbl => l_line_scredit_tbl
4110 --FP bug 3872166
4111 ,x_total_percent => l_total_percent );
4112 -- Prepare and insert line sales credits
4113 IF l_line_scredit_tbl.COUNT <> 0 AND
4114 (l_quota_flag = 'N' OR (l_quota_flag = 'Y' AND l_total_percent <> 0)) THEN --FP bug 3872166
4115 FOR I IN 1..l_line_scredit_tbl.COUNT LOOP
4116 l_line_scredit_rec := l_line_scredit_tbl(I);
4117 Prepare_Salescredit_rec
4118 (p_line_scredit_rec => l_line_scredit_rec
4119 ,p_interface_line_rec => p_interface_line_rec
4120 ,x_interface_scredit_rec => l_interface_scredit_rec);
4121 Insert_Salescredit(l_interface_scredit_rec);
4122 END LOOP;
4123 IF l_debug_level > 0 THEN
4124 oe_debug_pub.add( 'INSERTED LINE SALESCREDITS' , 1 ) ;
4125 END IF;
4126 Insert_Header_Scredits_Flag := 'N';
4127 ELSE -- Line has no sales credits
4128 IF p_line_rec.item_type_code = 'SERVICE' AND p_line_rec.service_reference_line_id IS NOT NULL THEN -- line is service and has parent
4129 IF l_debug_level > 0 THEN
4130 oe_debug_pub.add( 'RETRIEVING CUSTOMER PRODUCT LINE ID' ) ;
4131 END IF;
4132 IF p_line_rec.service_reference_type_code = 'CUSTOMER_PRODUCT' THEN
4133 /* Commenting for bug# 5032978
4134 OE_SERVICE_UTIL.Get_Cust_Product_Line_Id
4135 (x_return_status => l_return_status
4136 ,p_reference_line_id => p_line_rec.service_reference_line_id
4137 ,p_customer_id => p_line_rec.sold_to_org_id
4138 ,x_cust_product_line_id=> l_order_line_id
4139 );
4140 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
4141 IF l_debug_level > 0 THEN
4142 oe_debug_pub.add( 'CUSTOMER PRODUCT LINE ID -> ' || L_ORDER_LINE_ID , 5 ) ;
4143 END IF;
4144 l_service_reference_line_id := l_order_line_id;
4145 ELSE
4146 IF l_debug_level > 0 THEN
4147 oe_debug_pub.add( 'UNABLE TO RETRIEVE CUSTOMER PRODUCT LINE ID' , 1 ) ;
4148 END IF;
4149 RAISE NO_DATA_FOUND;
4150 END IF;
4151 end commenting for bug# 5032978 */
4152 l_service_reference_line_id := NULL;
4153 ELSE
4154 l_service_reference_line_id := p_line_rec.service_reference_line_id;
4155 END IF;
4156 END IF;
4157 IF l_service_reference_line_id is NOT NULL then -- service line has a parent
4158 -- Get sales credits for service parent
4159 Query_Line_Scredits(p_line_id => l_service_reference_line_id
4160 , p_quota_flag => l_quota_flag
4161 , x_line_scredit_tbl => l_line_scredit_tbl
4162 -- FP bug 3872166
4163 , x_total_percent => l_total_percent);
4164 IF l_line_scredit_tbl.COUNT <> 0 AND
4165 (l_quota_flag = 'N' OR (l_quota_flag = 'Y' AND l_total_percent <> 0)) THEN -- FP bug 3872166
4166 FOR I IN 1..l_line_scredit_tbl.COUNT LOOP
4167 l_line_scredit_rec := l_line_scredit_tbl(I);
4168 Prepare_Salescredit_rec
4169 (p_line_scredit_rec => l_line_scredit_rec
4170 ,p_interface_line_rec => p_interface_line_rec
4171 ,x_interface_scredit_rec => l_interface_scredit_rec);
4172 Insert_Salescredit(l_interface_scredit_rec);
4173 END LOOP;
4174 IF l_debug_level > 0 THEN
4175 oe_debug_pub.add( 'INSERTED SERVICE PARENT LINE SALESCREDITS' , 1 ) ;
4176 END IF;
4177 Insert_Header_Scredits_Flag := 'N';
4178 ELSE -- Service parent has no sales credits
4179 -- Check if service parent has parent (In case if service parent is an option, class, kit etc)
4180 BEGIN
4181 SELECT top_model_line_id
4182 INTO service_grand_parent_id
4183 FROM oe_order_lines_all /*Bug3261460*/
4184 WHERE line_id = l_service_reference_line_id;
4185 EXCEPTION
4186 WHEN NO_DATA_FOUND THEN
4187 IF l_debug_level > 0 THEN
4188 oe_debug_pub.add( 'UNABLE TO GET SERVICE GRAND PARENT ITEM' , 1);
4189 END IF;
4190 service_grand_parent_id := NULL;
4191 END;
4192 IF (nvl(service_grand_parent_id,0) <> 0 AND service_grand_parent_id <> l_service_reference_line_id) THEN
4193 -- Get sales credits for service grand parent
4194 Query_Line_Scredits(p_line_id => service_grand_parent_id
4195 , p_quota_flag => l_quota_flag
4196 , x_line_scredit_tbl => l_line_scredit_tbl
4197 --FP bug 3872166
4198 , x_total_percent => l_total_percent);
4199 IF l_line_scredit_tbl.COUNT <> 0 AND
4200 (l_quota_flag = 'N' OR (l_quota_flag = 'Y' AND l_total_percent <> 0)) THEN -- FP bug 3872166
4201 FOR I IN 1..l_line_scredit_tbl.COUNT LOOP
4202 l_line_scredit_rec := l_line_scredit_tbl(I);
4203 Prepare_Salescredit_rec
4204 (p_line_scredit_rec => l_line_scredit_rec
4205 ,p_interface_line_rec => p_interface_line_rec
4206 ,x_interface_scredit_rec => l_interface_scredit_rec);
4207 Insert_Salescredit(l_interface_scredit_rec);
4208 END LOOP;
4209 IF l_debug_level > 0 THEN
4210 oe_debug_pub.add( 'INSERTED SERVICE GRAND PARENT LINE SALESCREDITS' , 1 ) ;
4211 END IF;
4212 Insert_Header_Scredits_Flag := 'N';
4213 ELSE -- Service grand parent has no sales credits
4214 --Get header sales credits
4215 Insert_Header_Scredits_Flag := 'Y';
4216 END IF; -- end of service grand parent salescredits
4217 ELSE -- Service has no grand parent
4218 --Get header sales credits
4219 Insert_Header_Scredits_Flag := 'Y';
4220 END IF; -- end of service grand parent
4221 END IF; -- end of service parent
4222 -- Check if line is option, class or kit
4223 ELSIF (p_line_rec.top_model_line_id IS NOT NULL AND
4224 p_line_rec.top_model_line_id <> p_line_rec.line_id) THEN
4225 -- Get sales credits for parent line
4226 Query_Line_Scredits(p_line_id => p_line_rec.top_model_line_id
4227 , p_quota_flag => l_quota_flag
4228 , x_line_scredit_tbl => l_line_scredit_tbl
4229 -- FP bug 3872166
4230 , x_total_percent => l_total_percent);
4231 IF l_line_scredit_tbl.COUNT <> 0 AND
4232 (l_quota_flag = 'N' OR (l_quota_flag = 'Y' AND l_total_percent <> 0)) THEN --FP bug 3872166
4233 FOR I IN 1..l_line_scredit_tbl.COUNT LOOP
4234 l_line_scredit_rec := l_line_scredit_tbl(I);
4235 Prepare_Salescredit_rec
4236 (p_line_scredit_rec => l_line_scredit_rec
4237 ,p_interface_line_rec => p_interface_line_rec
4238 ,x_interface_scredit_rec => l_interface_scredit_rec);
4239 Insert_Salescredit(l_interface_scredit_rec);
4240 END LOOP;
4241 IF l_debug_level > 0 THEN
4242 oe_debug_pub.add( 'INSERTED PARENT LINE SALESCREDITS' , 1 ) ;
4243 END IF;
4244 Insert_Header_Scredits_Flag := 'N';
4245 ELSE -- parent has no sales credits
4246 -- Prepare and insert header sales credits
4247 Insert_Header_Scredits_flag := 'Y';
4248 END IF; -- end of model line
4249 ELSE -- line has no parent
4250 Insert_Header_Scredits_flag := 'Y';
4251 END IF;
4252 END IF;
4253 IF Insert_Header_Scredits_flag = 'Y' THEN
4254 -- Prepare and insert header sales credits
4255 Query_Header_Scredits(p_header_id => p_line_rec.header_id
4256 , p_quota_flag => l_quota_flag
4257 , x_header_scredit_tbl => l_header_scredit_tbl);
4258 IF l_header_scredit_tbl.COUNT <> 0 THEN
4259 FOR I IN 1..l_header_scredit_tbl.COUNT LOOP
4260 l_header_scredit_rec := l_header_scredit_tbl(I);
4261 Prepare_Salescredit_rec
4262 (p_header_scredit_rec => l_header_scredit_rec
4263 ,p_interface_line_rec => p_interface_line_rec
4264 ,x_interface_scredit_rec => l_interface_scredit_rec);
4265 Insert_Salescredit(l_interface_scredit_rec);
4266 END LOOP;
4267 IF l_debug_level > 0 THEN
4268 oe_debug_pub.add( 'INSERTED HEADER SALESCREDITS' , 1 ) ;
4269 END IF;
4270 Insert_Header_Scredits_Flag := 'N';
4271 END IF;
4272 END IF;
4273 END LOOP;
4274 x_return_status := FND_API.G_RET_STS_SUCCESS;
4275 IF l_debug_level > 0 THEN
4276 oe_debug_pub.add( 'INTERFACE_SALES_CREDITS ( ) PROCDURE SUCCESS : '||X_RETURN_STATUS , 1 ) ;
4277 END IF;
4278 EXCEPTION
4279 WHEN OTHERS THEN
4280 IF l_debug_level > 0 THEN
4281 oe_debug_pub.add( 'EXCEPTION INTERFACE_SALES_CREDITS ( ) '||SQLERRM , 1 ) ;
4282 END IF;
4283 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4284 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4285 THEN
4286 OE_MSG_PUB.Add_Exc_Msg
4287 ( G_PKG_NAME
4288 , 'Interface_SalesCredits');
4289 END IF;
4290 END Interface_SalesCredits;
4291
4292 PROCEDURE Interface_scredits_for_freight
4293 ( p_line_rec IN OE_Order_PUB.Line_Rec_Type
4294 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
4295 , p_line_level_charge IN VARCHAR2
4296 ) IS
4297 l_header_scredit_tbl OE_Order_PUB.Header_Scredit_Tbl_Type;
4298 l_header_scredit_rec OE_Order_PUB.Header_Scredit_Rec_Type;
4299 l_interface_scredit_rec RA_Interface_Scredits_Rec_Type;
4300 l_cr_srep_for_freight VARCHAR2(30); --moac moving the initialization to the body
4301 l_return_status VARCHAR2(30);
4302 --
4303 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4304 --
4305 BEGIN
4306 IF l_debug_level > 0 THEN
4307 oe_debug_pub.add( 'INTERFACING SALES CREDITS FOR FREIGHT' , 5 ) ;
4308 END IF;
4309 --moac
4310 l_cr_srep_for_freight := NVL(OE_SYS_PARAMETERS.value('WSH_CR_SREP_FOR_FREIGHT',p_line_rec.org_id), 'N');
4311 -- If the profile option 'OM: Credit Salesperson for Freight on Sales'
4312 -- is set to 'Yes' then interface header/line sales credits otherwise
4313 -- insert dummy sales credits.
4314 IF l_cr_srep_for_freight = 'Y' THEN
4315 IF p_line_level_charge = 'Y' THEN
4316 -- interface line sales credits if there are any otherwise get from its parent
4317 Interface_Salescredits(p_line_rec
4318 ,p_interface_line_rec
4319 ,l_return_status);
4320 ELSE
4321 --Interface quota, non-quota Header Sales Credits
4322 OE_Header_Scredit_Util.Query_Rows(p_header_id => p_line_rec.header_id, x_header_scredit_tbl=>l_header_scredit_tbl);
4323 IF l_header_scredit_tbl.COUNT <> 0 THEN
4324 FOR I IN 1..l_header_scredit_tbl.COUNT LOOP
4325 l_header_scredit_rec := l_header_scredit_tbl(I);
4326 Prepare_Salescredit_rec
4327 (p_header_scredit_rec => l_header_scredit_rec
4328 ,p_interface_line_rec => p_interface_line_rec
4329 ,x_interface_scredit_rec => l_interface_scredit_rec);
4330 Insert_Salescredit(l_interface_scredit_rec);
4331 END LOOP;
4332 END IF;
4333 END IF;
4334 ELSE
4335 -- Interface dummy quota freight sales credits
4336 Prepare_Salescredit_rec
4337 (p_interface_line_rec => p_interface_line_rec
4338 ,x_interface_scredit_rec => l_interface_scredit_rec);
4339 Insert_Salescredit(l_interface_scredit_rec);
4340 END IF;
4341 IF l_debug_level > 0 THEN
4342 oe_debug_pub.add( 'INTERFACE SALES CREDITS FOR FREIGHT SUCCESSFULLY ' , 5 ) ;
4343 END IF;
4344 EXCEPTION
4345 WHEN OTHERS THEN
4346 IF l_debug_level > 0 THEN
4347 oe_debug_pub.add( 'EXCEPTION , INTERFACE SALES CREDITS FOR FREIGHT '||SQLERRM , 1 ) ;
4348 END IF;
4349 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4350 THEN
4351 OE_MSG_PUB.Add_Exc_Msg
4352 ( G_PKG_NAME
4353 , 'Interface_scredits_for_freight'
4354 );
4355 END IF;
4356 END Interface_scredits_for_freight;
4357 --Customer Acceptance
4358 FUNCTION Line_Rejected(p_line_rec IN OE_ORDER_PUB.Line_Rec_Type) RETURN BOOLEAN IS
4359 BEGIN
4360
4361 IF p_line_rec.line_category_code= 'ORDER' THEN
4362 IF (p_line_rec.flow_status_code='PRE-BILLING_ACCEPTANCE' OR
4363 OE_ACCEPTANCE_UTIL.Pre_billing_acceptance_on (p_line_rec => p_line_rec))
4364 AND OE_ACCEPTANCE_UTIL.Acceptance_Status(p_line_rec => p_line_rec) = 'REJECTED' THEN
4365 RETURN TRUE;
4366 ELSE
4367 RETURN FALSE;
4368 END IF;
4369
4370 ELSE -- Return line
4371
4372 IF p_line_rec.reference_line_id IS NOT NULL THEN
4373 IF OE_ACCEPTANCE_UTIL.Pre_billing_acceptance_on (p_line_id => p_line_rec.reference_line_id)
4374 AND OE_ACCEPTANCE_UTIL.Acceptance_Status(p_line_id => p_line_rec.reference_line_id) = 'REJECTED' THEN
4375 RETURN TRUE;
4376 ELSE
4377 RETURN FALSE;
4378 END IF;
4379 ELSE
4380 RETURN FALSE;
4381 END IF;
4382 END IF;
4383 END Line_Rejected;
4384
4385 PROCEDURE Prepare_Contingency_rec
4386 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
4387 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
4388 , x_interface_conts_rec IN OUT NOCOPY RA_Interface_Conts_Rec_Type
4389 ) IS
4390 l_revrec_event_code VARCHAR2(30);
4391 l_expiration_days NUMBER;
4392 --
4393 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4394 --
4395 BEGIN
4396 IF l_debug_level > 0 THEN
4397 oe_debug_pub.add( 'ENTER PREPARE_CONTINGENCIES_REC ( ) PROCEDURE' , 5 ) ;
4398 END IF;
4399
4400 OE_ACCEPTANCE_UTIL.Get_Contingency_attributes
4401 (p_line_rec => p_line_rec
4402 ,x_contingency_id => x_interface_conts_rec.contingency_id
4403 ,x_revrec_event_code => l_revrec_event_code
4404 ,x_revrec_expiration_days => l_expiration_days);
4405
4406 IF x_interface_conts_rec.contingency_id IS NULL THEN
4407 IF l_debug_level > 0 THEN
4408 oe_debug_pub.add( 'Returning from prepare_contingencies - no contingency');
4409 END IF;
4410 RETURN;
4411 END IF;
4412 x_interface_conts_rec.CREATION_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
4413 x_interface_conts_rec.LAST_UPDATE_DATE:= INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(sysdate,p_interface_line_rec.org_id);
4414 x_interface_conts_rec.CREATED_BY := p_interface_line_rec.created_by;
4415 x_interface_conts_rec.LAST_UPDATED_BY := p_interface_line_rec.last_updated_by;
4416 x_interface_conts_rec.INTERFACE_LINE_CONTEXT := p_interface_line_rec.INTERFACE_LINE_CONTEXT;
4417 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE1 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1;
4418 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE2 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2;
4419 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE3 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3;
4420 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE4 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4;
4421 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE5 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5;
4422 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE6 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE6;
4423 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE7 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7;
4424 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE8 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8;
4425 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE9 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9;
4426 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE10 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE10;
4427 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE11 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE11;
4428 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE12 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE12;
4429 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE13 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE13;
4430 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE14 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE14;
4431 x_interface_conts_rec.INTERFACE_LINE_ATTRIBUTE15 := p_interface_line_rec.INTERFACE_LINE_ATTRIBUTE15;
4432
4433 x_interface_conts_rec.EXPIRATION_DAYS := nvl(p_line_rec.REVREC_EXPIRATION_DAYS, l_expiration_days);
4434 x_interface_conts_rec.EXPIRATION_DATE := NULL;
4435 IF p_line_rec.REVREC_SIGNATURE_DATE IS NOT NULL THEN
4436 x_interface_conts_rec.COMPLETED_FLAG := 'Y';
4437 END IF;
4438 /* commenting out because AR does not support expiration date on ar_interface_conts_all at this point of time. See bug# 5026580
4439 IF x_interface_conts_rec.EXPIRATION_DATE IS NOT NULL THEN
4440 x_interface_conts_rec.EXPIRATION_DATE := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(x_interface_conts_rec.EXPIRATION_DATE,p_line_rec.org_id);
4441 x_interface_conts_rec.COMPLETED_FLAG := 'Y';
4442 ELSE -- bug# 5049677
4443 x_interface_conts_rec.expiration_days := nvl(p_line_rec.REVREC_EXPIRATION_DAYS, l_expiration_days);
4444 END IF; */
4445 x_interface_conts_rec.org_id := p_line_rec.org_id;
4446 x_interface_conts_rec.completed_by := p_line_rec.accepted_by;
4447
4448 IF l_debug_level > 0 THEN
4449 oe_debug_pub.add( 'EXITING PREPARE_CONTINGENCY_REC' , 5 ) ;
4450 END IF;
4451 END Prepare_Contingency_rec;
4452
4453 PROCEDURE Insert_Contingency
4454 ( p_contingency_rec IN Ra_Interface_Conts_Rec_Type
4455 ) IS
4456 --
4457 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4458 --
4459 l_msg_count NUMBER;
4460 l_msg_data VARCHAR2(2000);
4461 l_return_status VARCHAR2(15);
4462
4463 BEGIN
4464
4465 IF l_debug_level > 0 THEN
4466 oe_debug_pub.add( 'INSERTING CONTINGENCY RECORDS ' , 5 ) ;
4467 END IF;
4468
4469 INSERT INTO AR_INTERFACE_CONTS_ALL
4470 (CREATED_BY
4471 ,CREATION_DATE
4472 ,LAST_UPDATED_BY
4473 ,LAST_UPDATE_DATE
4474 ,INTERFACE_LINE_CONTEXT
4475 ,INTERFACE_LINE_ATTRIBUTE1
4476 ,INTERFACE_LINE_ATTRIBUTE2
4477 ,INTERFACE_LINE_ATTRIBUTE3
4478 ,INTERFACE_LINE_ATTRIBUTE4
4479 ,INTERFACE_LINE_ATTRIBUTE5
4480 ,INTERFACE_LINE_ATTRIBUTE6
4481 ,INTERFACE_LINE_ATTRIBUTE7
4482 ,INTERFACE_LINE_ATTRIBUTE8
4483 ,INTERFACE_LINE_ATTRIBUTE9
4484 ,INTERFACE_LINE_ATTRIBUTE10
4485 ,INTERFACE_LINE_ATTRIBUTE11
4486 ,INTERFACE_LINE_ATTRIBUTE12
4487 ,INTERFACE_LINE_ATTRIBUTE13
4488 ,INTERFACE_LINE_ATTRIBUTE14
4489 ,INTERFACE_LINE_ATTRIBUTE15
4490 ,INTERFACE_CONTINGENCY_ID
4491 ,CONTINGENCY_ID
4492 ,EXPIRATION_DAYS
4493 ,EXPIRATION_DATE
4494 ,COMPLETED_FLAG
4495 ,EXPIRATION_EVENT_DATE
4496 ,COMPLETED_BY
4497 ,ORG_ID)
4498 VALUES
4499 (p_contingency_rec.CREATED_BY
4500 ,p_contingency_rec.CREATION_DATE
4501 ,p_contingency_rec.LAST_UPDATED_BY
4502 ,p_contingency_rec.LAST_UPDATE_DATE
4503 ,p_contingency_rec.INTERFACE_LINE_CONTEXT
4504 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE1
4505 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE2
4506 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE3
4507 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE4
4508 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE5
4509 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE6
4510 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE7
4511 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE8
4512 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE9
4513 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE10
4514 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE11
4515 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE12
4516 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE13
4517 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE14
4518 ,p_contingency_rec.INTERFACE_LINE_ATTRIBUTE15
4519 ,p_contingency_rec.interface_contingency_id
4520 , p_contingency_rec.contingency_id
4521 , p_contingency_rec.expiration_days
4522 , p_contingency_rec.EXPIRATION_DATE
4523 , p_contingency_rec.COMPLETED_FLAG
4524 , p_contingency_rec.EXPIRATION_EVENT_DATE
4525 , p_contingency_rec.completed_by
4526 ,p_contingency_rec.ORG_ID);
4527
4528 IF l_debug_level > 0 THEN
4529 oe_debug_pub.add( 'SUCCESSFULLY INSERTED CONTINGENCY RECORDS' , 5 ) ;
4530 END IF;
4531 EXCEPTION WHEN OTHERS THEN
4532 IF l_debug_level > 0 THEN
4533 oe_debug_pub.add( 'UNABLE TO INSERT CONTINGENCY RECORDS -> '||SQLERRM , 1 ) ;
4534 END IF;
4535 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4536 OE_MSG_PUB.Add_Exc_Msg
4537 ( G_PKG_NAME
4538 , 'Insert_Contingency'
4539 );
4540 END IF;
4541 END Insert_Contingency;
4542
4543 --This procedure interfaces the contingency record by preparing it and inserting into AR_INTERFACE_CONTS_ALL
4544
4545 PROCEDURE Interface_Contingencies
4546 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
4547 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
4548 , x_return_status OUT NOCOPY VARCHAR2
4549 )
4550 IS
4551 l_interface_conts_rec RA_Interface_Conts_Rec_Type;
4552 l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
4553 --
4554 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4555 --
4556 BEGIN
4557 IF l_debug_level > 0 THEN
4558 oe_debug_pub.add( 'ENTER INTERFACE_CONTINGENCIES ( ) PROCEDURE ' , 5 ) ;
4559 END IF;
4560
4561 IF NVL(OE_SYS_PARAMETERS.VALUE('ENABLE_FULFILLMENT_ACCEPTANCE'), 'N') = 'N' THEN
4562 IF l_debug_level > 0 THEN
4563 oe_debug_pub.add( 'Acceptance not enabled, Not interfacing Contingency details');
4564 END IF;
4565 -- Do not interface acceptance details
4566 RETURN;
4567 END IF;
4568
4569 Prepare_Contingency_rec
4570 ( p_line_rec => p_line_rec
4571 , p_interface_line_rec => p_interface_line_rec
4572 , x_interface_conts_rec => l_interface_conts_rec
4573 );
4574
4575 IF l_interface_conts_rec.contingency_id IS NOT NULL THEN
4576 IF l_debug_level > 0 THEN
4577 oe_debug_pub.add( 'Interfacing Contingency details');
4578 END IF;
4579 Insert_Contingency(l_interface_conts_rec);
4580 ELSE
4581 IF l_debug_level > 0 THEN
4582 oe_debug_pub.add( 'No Contingency on the line, Not interfacing Contingency details');
4583 END IF;
4584 RETURN;
4585 END IF;
4586 x_return_status := l_return_status;
4587 IF l_debug_level > 0 THEN
4588 oe_debug_pub.add( 'INTERFACE_CONTINGENCIES ( ) PROCDURE SUCCESS : '||l_RETURN_STATUS , 1 ) ;
4589 END IF;
4590 EXCEPTION
4591 WHEN OTHERS THEN
4592 IF l_debug_level > 0 THEN
4593 oe_debug_pub.add( 'EXCEPTION INTERFACE_CONTINGENCIES ( ) '||SQLERRM , 1 ) ;
4594 END IF;
4595 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4596 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4597 THEN
4598 OE_MSG_PUB.Add_Exc_Msg
4599 ( G_PKG_NAME
4600 , 'Interface_Contingencies');
4601 END IF;
4602 END Interface_Contingencies;
4603 --customer acceptance
4604 -- 3685479 Changed the signature of the procedure with extra parameter p_adjustments_tbl
4605 PROCEDURE Get_Rounding_Diff
4606 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
4607 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
4608 , p_adjustments_tbl IN OE_Header_Adj_Util.Line_Adjustments_Tab_Type
4609 , x_rounding_diff OUT NOCOPY NUMBER
4610 ) IS
4611 l_adjustments_tbl OE_Header_Adj_Util.Line_Adjustments_Tab_Type;
4612 l_adjustments_rec OE_Header_Adj_Util.Line_Adjustments_Rec_Type;
4613 l_line_adj_rec OE_Order_PUB.Line_Adj_Rec_Type;
4614 l_line_tot_amount NUMBER;
4615 l_ind_line_tot NUMBER;
4616 l_ind_disc_tot NUMBER;
4617 l_comb_ind_line_tots NUMBER;
4618 --
4619 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4620 --
4621 l_header_id NUMBER;
4622 l_line_id NUMBER;
4623 BEGIN
4624 IF l_debug_level > 0 THEN
4625 oe_debug_pub.add( 'ENTER GET_ROUNDING_DIFF ( ) PROCEDURE' , 5 ) ;
4626 END IF;
4627
4628 -- Removed the previous call to get_line_adjustments as adjustment table is passed now
4629
4630 IF l_debug_level > 0 THEN
4631 oe_debug_pub.add( 'p_adjustments_tbl.COUNT:'||p_adjustments_tbl.COUNT);
4632 END IF;
4633
4634 -- 3685479 Replaced call to show_detail_discounts by the foll IF
4635 IF (oe_sys_parameters.value('OE_DISCOUNT_DETAILS_ON_INVOICE',p_line_rec.org_id) = 'Y'
4636 AND p_adjustments_tbl.COUNT > 0
4637 AND NVL(p_line_rec.service_bill_option_code,'FBOM') <> 'FPOM') THEN --moac -- sol_ord_er #16014165
4638 -- get line total when the profile is off
4639 Rounded_Amount(p_currency_code => p_interface_line_rec.currency_code
4640 ,p_unrounded_amount => (p_line_rec.unit_selling_price * p_interface_line_rec.quantity)
4641 ,x_rounded_amount => l_line_tot_amount);
4642 IF l_debug_level > 0 THEN
4643 oe_debug_pub.add( 'LINE TOTAL WHEN SHOW DISCOUNTS PROFILE IS OFF: '||L_LINE_TOT_AMOUNT , 5 ) ;
4644 END IF;
4645 -- get line total when the profile is on
4646 Rounded_Amount(p_currency_code => p_interface_line_rec.currency_code
4647 ,p_unrounded_amount => (p_line_rec.unit_list_price * p_interface_line_rec.quantity)
4648 ,x_rounded_amount => l_ind_line_tot);
4649 IF l_debug_level > 0 THEN
4650 oe_debug_pub.add( 'LINE TOTAL WHEN SHOW DISCOUNTS PROFILE IS ON: '||L_IND_LINE_TOT , 5 ) ;
4651 END IF;
4652 IF p_adjustments_tbl.COUNT <> 0 THEN
4653 FOR I IN 1..p_adjustments_tbl.COUNT LOOP
4654 l_adjustments_rec := p_adjustments_tbl(I);
4655 Rounded_Amount(p_currency_code => p_interface_line_rec.currency_code
4656 ,p_unrounded_amount => (l_adjustments_rec.unit_discount_amount * p_interface_line_rec.quantity * -1)
4657 ,x_rounded_amount => l_ind_disc_tot);
4658 IF l_debug_level > 0 THEN
4659 oe_debug_pub.add( 'PROCESSING RECORD# '||I|| ': '||'DISCOUNT LINE TOTAL FOR ADJ_ID= '||L_ADJUSTMENTS_REC.PRICE_ADJUSTMENT_ID||': ' ||L_IND_DISC_TOT , 5 ) ;
4660 END IF;
4661 l_ind_line_tot := l_ind_line_tot + l_ind_disc_tot;
4662 IF l_debug_level > 0 THEN
4663 oe_debug_pub.add( 'INTERMEDIATE TOTAL: '||L_IND_LINE_TOT , 5 ) ;
4664 END IF;
4665 END LOOP;
4666 Rounded_Amount(p_currency_code => p_interface_line_rec.currency_code
4667 ,p_unrounded_amount => l_ind_line_tot
4668 ,x_rounded_amount => l_comb_ind_line_tots);
4669 IF l_debug_level > 0 THEN
4670 oe_debug_pub.add( 'ROUNDED TOTAL FOR THE LINE WHEN SHOW DISCOUNTS IS ON => '||L_COMB_IND_LINE_TOTS , 5 ) ;
4671 END IF;
4672 END IF;
4673 IF l_line_tot_amount = l_comb_ind_line_tots THEN
4674 x_rounding_diff := NULL;
4675 ELSE
4676 -- This difference should go with the first discount line
4677 x_rounding_diff := l_line_tot_amount - l_comb_ind_line_tots;
4678 END IF;
4679 END IF;
4680 IF l_debug_level > 0 THEN
4681 oe_debug_pub.add( 'EXIT GET_ROUNDING_DIFF ( ) WITH ROUNDING DIFFERENCE : '||X_ROUNDING_DIFF , 5 ) ;
4682 END IF;
4683 EXCEPTION
4684 WHEN OTHERS THEN
4685 IF l_debug_level > 0 THEN
4686 oe_debug_pub.add( 'EXCEPTION , ROUNDING DIFFERENCE '||SQLERRM , 1 ) ;
4687 END IF;
4688 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4689 THEN
4690 OE_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,'Get_Rounding_Diff');
4691 END IF;
4692 END Get_Rounding_Diff;
4693
4694 PROCEDURE Interface_Detail_Discounts
4695 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
4696 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
4697 , x_return_status OUT NOCOPY VARCHAR2
4698 ) IS
4699 l_discounts_rec RA_Interface_Lines_Rec_Type;
4700 l_adjustments_tbl OE_Header_Adj_Util.Line_Adjustments_Tab_Type;
4701 l_adjustments_rec OE_Header_Adj_Util.Line_Adjustments_Rec_Type;
4702 l_line_adj_rec OE_Order_PUB.Line_Adj_Rec_Type;
4703 l_header_adj_rec OE_Order_PUB.Header_Adj_Rec_Type;
4704 l_return_status VARCHAR2(30);
4705 l_rounding_diff NUMBER;
4706 l_rounding_diff_applied VARCHAR2(1) :='N';
4707 l_reference_line_id NUMBER;
4708
4709 l_ref_header_id NUMBER;
4710 l_ref_line_id NUMBER;
4711 l_rounded_amount NUMBER;
4712
4713 cursor order_info(c_line_id number)
4714 is
4715 select header_id, line_id
4716 from oe_order_lines_all
4717 where line_id = c_line_id;
4718 --
4719 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4720 --
4721 l_header_id NUMBER;
4722 l_line_id NUMBER;
4723 BEGIN
4724 IF l_debug_level > 0 THEN
4725 oe_debug_pub.add( 'ENTERING INTERFACE_DETAIL_DISCOUNTS ( ) PROCEDURE ' , 5 ) ;
4726 END IF;
4727 -- 3661895 The IF will be true only for return retrobilled RMA, all others will go through else
4728 -- RT{
4729 IF (p_line_rec.line_category_code = 'RETURN'
4730 and p_line_rec.reference_line_id IS NOT NULL
4731 and p_line_rec.retrobill_request_id IS NOT NULL) THEN
4732
4733 OE_RETROBILL_PVT.Get_Line_Adjustments
4734 (p_line_rec => p_line_rec
4735 ,x_line_adjustments => l_adjustments_tbl);
4736 ELSE
4737
4738 OE_Header_Adj_Util.Get_Line_Adjustments
4739 (p_header_id => p_line_rec.header_id
4740 ,p_line_id => p_line_rec.line_id
4741 ,x_line_adjustments => l_adjustments_tbl);
4742 END IF;
4743 -- RT}
4744
4745 -- Prepare l_discounts_rec from l_adjustments_tbl and p_interface_line_rec
4746 -- keep all other info same as line
4747 IF l_adjustments_tbl.COUNT <> 0 THEN
4748 FOR I IN 1..l_adjustments_tbl.COUNT LOOP
4749 l_adjustments_rec := l_adjustments_tbl(I);
4750 l_discounts_rec := p_interface_line_rec;
4751 OE_Line_Adj_Util.Query_Row(p_price_adjustment_id=>l_adjustments_rec.price_adjustment_id,x_line_adj_rec=>l_line_adj_rec);
4752 -- Do not set mandatory grouping columns to different value than order line.
4753 -- This can cause discount lines to group into different invoice (if values
4754 -- are different from sales order line)
4755 -- l_discounts_rec.INTERFACE_LINE_ATTRIBUTE3 := '0';
4756 --l_discounts_rec.INTERFACE_LINE_ATTRIBUTE4 := '0'; -- bug 5843869
4757 l_discounts_rec.INTERFACE_LINE_ATTRIBUTE7 := '0';
4758 /* 1847224 l_discounts_rec.INTERFACE_LINE_ATTRIBUTE8 := '0'; */
4759 l_discounts_rec.INTERFACE_LINE_ATTRIBUTE11 := l_adjustments_rec.price_adjustment_id;
4760 /* 1789057, populate list_line_no in addition to adjustment name */
4761 if l_adjustments_rec.list_line_no is NULL then
4762 l_discounts_rec.Description := l_adjustments_rec.adjustment_name;
4763 else
4764 l_discounts_rec.Description := substr(l_adjustments_rec.adjustment_name,1,119)||'.'||substr(l_adjustments_rec.list_line_no,1,120);
4765 end if;
4766
4767 -- bug 2509121.
4768 -- translated description is only needed for sales order line.
4769 IF l_discounts_rec.translated_description is not null THEN
4770 l_discounts_rec.translated_description := null;
4771 END IF;
4772
4773 -- Quantity comes with the correct creation sign from the interface_line record. No need to adjust here
4774 l_discounts_rec.Unit_Selling_Price := l_adjustments_rec.unit_discount_amount * -1;
4775 l_discounts_rec.Unit_Standard_Price := l_adjustments_rec.unit_discount_amount * -1;
4776 IF l_debug_level > 0 THEN
4777 oe_debug_pub.add( 'ORIGINAL UNIT DISCOUNT AMOUNT : '||L_ADJUSTMENTS_REC.UNIT_DISCOUNT_AMOUNT , 5 ) ;
4778 END IF;
4779 Rounded_Amount(p_currency_code => l_discounts_rec.currency_code
4780 ,p_unrounded_amount => (l_discounts_rec.unit_selling_price * l_discounts_rec.quantity)
4781 ,x_rounded_amount => l_discounts_rec.amount);
4782 IF l_debug_level > 0 THEN
4783 oe_debug_pub.add( 'DISCOUNT UNIT_SELLING_PRICE: '||L_DISCOUNTS_REC.UNIT_SELLING_PRICE , 5 ) ;
4784 oe_debug_pub.add( 'DISCOUNT UNIT_STANDARD_PRICE: '||L_DISCOUNTS_REC.UNIT_STANDARD_PRICE , 5 ) ;
4785 oe_debug_pub.add( 'DISCOUNT AMOUNT: '||L_DISCOUNTS_REC.AMOUNT , 5 ) ;
4786 END IF;
4787 IF l_rounding_diff_applied = 'N' THEN
4788 IF (l_discounts_rec.quantity = 0 OR l_discounts_rec.amount = 0) THEN
4789 IF l_debug_level > 0 THEN
4790 oe_debug_pub.add( 'NOT APPLYING ROUNDING DIFF TO THIS DISCOUNT' ) ;
4791 END IF;
4792 ELSE
4793 -- 3685479 Changed signature to pass adjustments table
4794 Get_Rounding_Diff(p_line_rec => p_line_rec
4795 ,p_interface_line_rec => p_interface_line_rec
4796 ,p_adjustments_tbl => l_adjustments_tbl
4797 , x_rounding_diff => l_rounding_diff);
4798 IF (l_rounding_diff IS NOT NULL AND l_rounding_diff <> 0) THEN
4799 l_discounts_rec.amount := l_discounts_rec.amount + l_rounding_diff;
4800 IF l_debug_level > 0 THEN
4801 oe_debug_pub.add( 'DISCOUNT TOTAL AFTER ADDING ROUNDING DIFF: '||L_DISCOUNTS_REC.AMOUNT , 5 ) ;
4802 END IF;
4803
4804 Rounded_Amount(p_currency_code => l_discounts_rec.currency_code
4805 ,p_unrounded_amount => l_discounts_rec.amount
4806 ,x_rounded_amount => l_rounded_amount);
4807
4808 l_discounts_rec.amount := l_rounded_amount;
4809
4810 IF l_debug_level > 0 THEN
4811 oe_debug_pub.add( 'DISCOUNT TOTAL AFTER ADDING ROUNDING DIFF AND ROUNDING: '||L_DISCOUNTS_REC.AMOUNT , 5 ) ;
4812 END IF;
4813 l_discounts_rec.unit_selling_price := l_discounts_rec.amount /l_discounts_rec.quantity;
4814 IF l_debug_level > 0 THEN
4815 oe_debug_pub.add( 'DISCOUNT UNIT_SELLING_PRICE AFTER ADDING ROUNDING DIFF: '||L_DISCOUNTS_REC.UNIT_SELLING_PRICE , 5 ) ;
4816 END IF;
4817 END IF;
4818 l_rounding_diff_applied := 'Y';
4819 END IF;
4820 END IF;
4821 l_discounts_rec.Fob_Point := NULL;
4822 -- l_discounts_rec.Ship_Via := NULL; -- for bug# 5024577
4823 -- l_discounts_rec.Waybill_Number := NULL; --bug 5843869
4824 IF l_debug_level > 0 THEN
4825 oe_debug_pub.add( 'REFERENCE LINE_ID '||L_DISCOUNTS_REC.REFERENCE_LINE_ID , 5 ) ;
4826 oe_debug_pub.add( 'LINE CATEGORY CODE '||P_LINE_REC.LINE_CATEGORY_CODE , 5 ) ;
4827 END IF;
4828 IF p_line_rec.line_category_code = 'RETURN' AND l_discounts_rec.reference_line_id IS NOT NULL THEN
4829 -- 3645784
4830 -- RT{Retrobill Lines with line type return will not have reference information populated
4831 -- So setting the reference info with original order Header_id and Line_id
4832 IF ( p_line_rec.order_source_id = 27) THEN
4833 l_ref_header_id := to_number(p_line_rec.orig_sys_document_ref);
4834 l_ref_line_id := to_number(p_line_rec.orig_sys_line_ref);
4835 oe_debug_pub.add('Retro:After setting reference line id');
4836 ELSE
4837 FOR order_info_rec in order_info(p_line_rec.reference_line_id) loop
4838 l_ref_header_id := order_info_rec.header_id;
4839 l_ref_line_id := order_info_rec.line_id;
4840 END LOOP;
4841 END IF;
4842 oe_debug_pub.add('l_ref_header_id'||l_ref_header_id);
4843 oe_debug_pub.add('l_ref_line_id'||l_ref_line_id);
4844 BEGIN
4845 SELECT dis.customer_trx_line_id
4846 INTO l_reference_line_id
4847 FROM RA_CUSTOMER_TRX_LINES_ALL DIS,
4848 RA_CUSTOMER_TRX_LINES_ALL PAR
4849 WHERE PAR.CUSTOMER_TRX_LINE_ID = L_DISCOUNTS_REC.REFERENCE_LINE_ID
4850 AND PAR.CUSTOMER_TRX_ID = DIS.CUSTOMER_TRX_ID
4851 AND DIS.INTERFACE_LINE_ATTRIBUTE6 = NVL(l_ref_line_id,DIS.INTERFACE_LINE_ATTRIBUTE6) --Bug2966839
4852 AND DIS.INTERFACE_LINE_ATTRIBUTE11 =
4853 (SELECT D.PRICE_ADJUSTMENT_ID
4854 FROM OE_PRICE_ADJUSTMENTS D
4855 WHERE D.HEADER_ID = l_ref_header_id
4856 AND NVL(D.LINE_ID, l_ref_line_id) = l_ref_line_id
4857 AND D.APPLIED_FLAG = 'Y' -- 3630426 Added for Retrobilling
4858 AND D.LIST_LINE_ID =
4859 (SELECT D2.LIST_LINE_ID
4860 FROM OE_PRICE_ADJUSTMENTS D2
4861 WHERE D2.PRICE_ADJUSTMENT_ID = L_DISCOUNTS_REC.INTERFACE_LINE_ATTRIBUTE11));
4862
4863 EXCEPTION
4864 WHEN OTHERS THEN
4865 -- 3661895 l_reference_line_id must be cleared when the sql fails
4866 l_reference_line_id := NULL;
4867 IF l_debug_level > 0 THEN
4868 oe_debug_pub.add( 'FAILED TO INSERT DISCOUNT RECORDS FOR THE RETURN LINES '||SQLERRM , 1 ) ;
4869 END IF;
4870 -- Added for the FP bug #3802957
4871 l_reference_line_id := l_discounts_rec.Reference_Line_Id;
4872 NULL;
4873 END;
4874 l_discounts_rec.Reference_Line_Id := l_reference_line_id;
4875 IF l_debug_level > 0 THEN
4876 oe_debug_pub.add( 'REFERENCE LINE_ID FOR DISCOUNT LINE : '||L_DISCOUNTS_REC.REFERENCE_LINE_ID , 5 ) ;
4877 END IF;
4878 END IF;
4879 -- l_discounts_rec.Reference_Line_Id := NULL;
4880 l_discounts_rec.PROMISED_COMMITMENT_AMOUNT := 0; -- For bug 6798675 NULL;
4881 l_discounts_rec.Attribute_Category := l_line_adj_rec.Context;
4882 l_discounts_rec.Attribute1 := substrb(l_line_adj_rec.Attribute1, 1, 150);
4883 l_discounts_rec.Attribute2 := substrb(l_line_adj_rec.Attribute2, 1, 150);
4884 l_discounts_rec.Attribute3 := substrb(l_line_adj_rec.Attribute3, 1, 150);
4885 l_discounts_rec.Attribute4 := substrb(l_line_adj_rec.Attribute4, 1, 150);
4886 l_discounts_rec.Attribute5 := substrb(l_line_adj_rec.Attribute5, 1, 150);
4887 l_discounts_rec.Attribute6 := substrb(l_line_adj_rec.Attribute6, 1, 150);
4888 l_discounts_rec.Attribute7 := substrb(l_line_adj_rec.Attribute7, 1, 150);
4889 l_discounts_rec.Attribute8 := substrb(l_line_adj_rec.Attribute8, 1, 150);
4890 l_discounts_rec.Attribute9 := substrb(l_line_adj_rec.Attribute9, 1, 150);
4891 l_discounts_rec.Attribute10 := substrb(l_line_adj_rec.Attribute10, 1, 150);
4892 l_discounts_rec.Attribute11 := substrb(l_line_adj_rec.Attribute11, 1, 150);
4893 l_discounts_rec.Attribute12 := substrb(l_line_adj_rec.Attribute12, 1, 150);
4894 l_discounts_rec.Attribute13 := substrb(l_line_adj_rec.Attribute13, 1, 150);
4895 l_discounts_rec.Attribute14 := substrb(l_line_adj_rec.Attribute14, 1, 150);
4896 l_discounts_rec.Attribute15 := substrb(l_line_adj_rec.Attribute15, 1, 150);
4897
4898 Insert_Line(l_discounts_rec
4899 ,x_return_status=>l_return_status);
4900 -- Fix for the bug 2187074
4901 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4902 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4903 END IF;
4904
4905 -- Populate salescredits for discount lines
4906 Interface_Salescredits(p_line_rec
4907 ,l_discounts_rec
4908 ,l_return_status);
4909 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4910 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4911 END IF;
4912
4913 --Customer Acceptance
4914 Interface_Contingencies
4915 ( p_line_rec => p_line_rec
4916 , p_interface_line_rec => l_discounts_rec
4917 , x_return_status => l_return_status
4918 );
4919
4920 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4921 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4922 END IF;
4923 --Customer Acceptance
4924 END LOOP;
4925 END IF;
4926 -- Fix for the bug 2187074
4927 x_return_status := FND_API.G_RET_STS_SUCCESS;
4928 IF l_debug_level > 0 THEN
4929 oe_debug_pub.add( 'EXITING INTERFACE_DETAIL_DISCOUNTS ( ) PROCEDURE ' , 5 ) ;
4930 END IF;
4931
4932 EXCEPTION
4933 WHEN OTHERS THEN
4934 IF l_debug_level > 0 THEN
4935 oe_debug_pub.add( 'EXCEPTION IN INTERFACE_DETAIL_DISCOUNTS '||SQLERRM , 1 ) ;
4936 END IF;
4937 -- Fix for the bug 2187074
4938 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4939 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4940 OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME , 'Interface_Detail_Discounts');
4941 END IF;
4942
4943 END Interface_Detail_Discounts;
4944
4945 PROCEDURE Update_Invoiced_Flag
4946 ( p_price_adjustment_id IN NUMBER
4947 , p_adjusted_amount IN NUMBER
4948 , p_invoiced_amount IN NUMBER
4949 , x_return_status OUT NOCOPY VARCHAR2
4950 ) IS
4951 l_Header_Adj_tbl OE_Order_PUB.Header_Adj_Tbl_Type;
4952 l_Old_Header_Adj_tbl OE_Order_PUB.Header_Adj_Tbl_Type;
4953 l_return_status VARCHAR2(30);
4954 l_notify_index NUMBER; -- jolin
4955
4956 --
4957 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4958 --
4959 BEGIN
4960 IF l_debug_level > 0 THEN
4961 oe_debug_pub.add( 'ENTERING UPDATE_INVOICED_FLAG' , 1 ) ;
4962 END IF;
4963 OE_Header_Adj_Util.Lock_Rows
4964 (P_PRICE_ADJUSTMENT_ID=>p_price_adjustment_id,
4965 X_HEADER_ADJ_TBL=>l_old_header_adj_tbl,
4966 X_RETURN_STATUS => l_return_status);
4967 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4968 RAISE FND_API.G_EXC_ERROR;
4969 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4970 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4971 END IF;
4972 l_Header_Adj_tbl := l_old_Header_Adj_Tbl;
4973
4974 oe_debug_pub.add('Charges Amount '||p_adjusted_amount);
4975 oe_debug_pub.add('Invoiced Amount'||p_invoiced_amount);
4976
4977 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
4978 UPDATE OE_PRICE_ADJUSTMENTS
4979 SET INVOICED_FLAG = 'Y'
4980 , INVOICED_AMOUNT = nvl(invoiced_amount,0) + p_invoiced_amount -- update with unrounded amount, for bug# 5400517
4981 , LOCK_CONTROL = LOCK_CONTROL + 1
4982 WHERE PRICE_ADJUSTMENT_ID = p_price_adjustment_id;
4983
4984 --bug 4760069
4985 /*UPDATE OE_PRICE_ADJUSTMENTS
4986 SET UPDATED_FLAG = 'Y'
4987 WHERE PRICE_ADJUSTMENT_ID = p_price_adjustment_id
4988 AND line_id IS NOT NULL;*/
4989
4990 l_Header_Adj_tbl(1).Invoiced_Amount := nvl(l_Header_Adj_tbl(1).Invoiced_Amount, 0)+p_invoiced_amount;
4991 Else
4992 UPDATE OE_PRICE_ADJUSTMENTS
4993 SET INVOICED_FLAG = 'Y'
4994 , UPDATED_FLAG = 'Y'
4995 , LOCK_CONTROL = LOCK_CONTROL + 1
4996 WHERE PRICE_ADJUSTMENT_ID = p_price_adjustment_id;
4997 End If;
4998
4999 x_return_status := FND_API.G_RET_STS_SUCCESS;
5000 l_Header_Adj_tbl(1).Invoiced_Flag := 'Y';
5001 l_Header_Adj_tbl(1).lock_control := l_Header_Adj_tbl(1).lock_control + 1;
5002
5003 -- jolin start
5004 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
5005
5006 -- call notification framework to get header adj index position
5007 OE_ORDER_UTIL.Update_Global_Picture
5008 (p_Upd_New_Rec_If_Exists =>FALSE
5009 , p_hdr_adj_rec => l_Header_Adj_tbl(1)
5010 , p_old_hdr_adj_rec => l_Old_Header_Adj_tbl(1)
5011 , p_hdr_adj_id => l_Header_Adj_tbl(1).price_adjustment_id
5012 , x_index => l_notify_index
5013 , x_return_status => l_return_status);
5014
5015 IF l_debug_level > 0 THEN
5016 oe_debug_pub.add( 'UPDATE_GLOBAL RETURN STATUS FOR HDR ADJ IS: ' || L_RETURN_STATUS ) ;
5017 oe_debug_pub.add( 'HDR ADJ INDEX IS: ' || L_NOTIFY_INDEX , 1 ) ;
5018 END IF;
5019
5020 IF l_notify_index is not null then
5021 -- modify Global Picture
5022 OE_ORDER_UTIL.g_old_header_adj_tbl(l_notify_index) := l_old_header_adj_tbl(1);
5023 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index) := OE_ORDER_UTIL.g_old_header_adj_tbl(l_notify_index);
5024 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index).invoiced_amount:=
5025 l_Header_Adj_tbl(1).invoiced_amount;
5026 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index).invoiced_flag:=
5027 l_Header_Adj_tbl(1).invoiced_flag;
5028 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index).lock_control:=
5029 l_header_adj_tbl(1).lock_control;
5030 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index).last_update_date:=
5031 l_header_adj_tbl(1).last_update_date;
5032 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index).header_id:=
5033 l_header_adj_tbl(1).header_id;
5034 OE_ORDER_UTIL.g_header_adj_tbl(l_notify_index).line_id:=
5035 l_header_adj_tbl(1).line_id;
5036
5037 IF l_debug_level > 0 THEN
5038 oe_debug_pub.add( 'GLOBAL HDR ADJ INVOICED_FLAG IS: ' || OE_ORDER_UTIL.G_HEADER_ADJ_TBL ( L_NOTIFY_INDEX ) .INVOICED_FLAG , 1 ) ;
5039 oe_debug_pub.add( 'GLOBAL HDR ADJ LOCK_CONTROL IS: ' || OE_ORDER_UTIL.G_HEADER_ADJ_TBL ( L_NOTIFY_INDEX ) .LOCK_CONTROL , 1 ) ;
5040
5041 END IF;
5042
5043 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
5044 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5045 END IF;
5046
5047 -- Process requests is TRUE so still need to call it, but don't need to notify
5048 IF l_debug_level > 0 THEN
5049 oe_debug_pub.add( 'OEXPINVB: HDRADJ BEFORE CALLING PROCESS_REQUESTS_AND_NOTIFY' ) ;
5050 END IF;
5051 OE_Order_PVT.PROCESS_REQUESTS_AND_NOTIFY(
5052 P_HEADER_ADJ_TBL =>l_Header_Adj_tbl,
5053 P_OLD_HEADER_ADJ_TBL =>l_Old_Header_Adj_tbl,
5054 P_PROCESS_REQUESTS => TRUE,
5055 P_NOTIFY => FALSE,
5056 X_RETURN_STATUS => l_return_status);
5057
5058 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
5059 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5060 END IF;
5061
5062 END IF ; /* global entity index null check */
5063
5064 ELSE /* pre-pack H */
5065
5066 IF l_debug_level > 0 THEN
5067 oe_debug_pub.add( 'OEXPINVB: HDRADJ BEFORE CALLING PROCESS_REQUESTS_AND_NOTIFY' ) ;
5068 END IF;
5069 OE_Order_PVT.PROCESS_REQUESTS_AND_NOTIFY(
5070 P_HEADER_ADJ_TBL =>l_Header_Adj_tbl,
5071 P_OLD_HEADER_ADJ_TBL =>l_Old_Header_Adj_tbl,
5072 P_PROCESS_REQUESTS => TRUE,
5073 P_NOTIFY => TRUE,
5074 X_RETURN_STATUS => l_return_status);
5075
5076 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
5077 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5078 END IF;
5079
5080 END IF; /* code set is pack H or higher */
5081 /* jolin end*/
5082
5083 IF l_debug_level > 0 THEN
5084 oe_debug_pub.add( 'EXIT UPDATE_INVOICED_FLAG ( ) PROCEDURE' , 1 ) ;
5085 END IF;
5086
5087 EXCEPTION
5088 WHEN OTHERS THEN
5089 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5090 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5091 THEN
5092 OE_MSG_PUB.Add_Exc_Msg
5093 ( G_PKG_NAME
5094 , 'Update_Invoiced_flag'
5095 );
5096 END IF;
5097 END Update_Invoiced_Flag;
5098
5099 PROCEDURE Prepare_Freight_Charges_Rec
5100 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
5101 , p_x_charges_rec IN OUT NOCOPY RA_Interface_Lines_Rec_Type
5102 ) IS
5103 -- l_vat_flag VARCHAR2(1);
5104 l_freight_as_line VARCHAR2(1);
5105 l_freight_item NUMBER;
5106 l_reference_line_id NUMBER;
5107
5108 l_ref_header_id NUMBER;
5109 l_ref_line_id NUMBER;
5110 l_ref_order_number VARCHAR2(30);
5111 l_ref_order_type VARCHAR2(30);
5112 l_rounded_amount NUMBER;
5113
5114 CURSOR ORDER_INFO(c_line_id NUMBER) IS
5115 SELECT ooh.header_id
5116 , ool.line_id
5117 , ooh.order_number
5118 , ott.name order_type
5119 FROM oe_order_lines ool,
5120 oe_order_headers_all ooh, /* MOAC SQL CHANGE */
5121 oe_transaction_types_tl ott
5122 WHERE ool.line_id = c_line_id
5123 AND ooh.header_id = ool.header_id
5124 AND ott.transaction_type_id = ooh.order_type_id
5125 AND ott.language =
5126 (select language_code
5127 from fnd_languages
5128 where installed_flag = 'B');
5129 --
5130 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5131 --
5132 BEGIN
5133 IF l_debug_level > 0 THEN
5134 oe_debug_pub.add( 'ENTER PREPARE_FREIGHT_CHARGES_REC ( ) PROCEDURE ' , 5 ) ;
5135 oe_debug_pub.add( 'PREPARING FOR CHARGE ID : '|| P_X_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 ) ;
5136 END IF;
5137
5138 -- Do not set mandatory grouping columns to different value than order line.
5139 -- This can cause freight charges to group into different invoice (if values
5140 -- are different from sales order line)
5141 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE5 := 1;
5142 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE7 := '0'; --picking line id
5143 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE8 := '0'; -- bill_of_lading;
5144 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE9 := '0'; -- customer item number
5145 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE12 := lpad('0', 30); -- shipment number
5146 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE13 := lpad('0', 30); -- option number
5147 p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE14 := lpad('0', 30); -- service number
5148 -- l_vat_flag := NVL(FND_PROFILE.VALUE('AR_ALLOW_TAX_CODE_OVERRIDE'), 'N');
5149 l_freight_as_line := NVL(oe_sys_parameters.value('OE_INVOICE_FREIGHT_AS_LINE',p_line_rec.org_id), 'N'); --moac
5150 IF l_debug_level > 0 THEN
5151 oe_debug_pub.add( 'INVOICE FREIGHT AS REVENUE '||L_FREIGHT_AS_LINE ) ;
5152 END IF;
5153 l_freight_item := oe_sys_parameters.value('OE_INVENTORY_ITEM_FOR_FREIGHT',p_line_rec.org_id); --moac
5154 /* VAT on freight
5155 if vat_flag = 'Y'
5156 if freight_as_line = 'Y'
5157 if freight_item is NULL
5158 o inventory_item_id = NULL
5159 o description = lookup meaning for FREIGHT
5160 o line_type = 'LINE'
5161 else
5162 o inventory_item_id = freight_item
5163 o description = freight item's description
5164 o line_type = 'LINE'
5165 else
5166 o inventory_item_id = NULL
5167 o description = lookup meaning for FREIGHT
5168 o line_type = 'FREIGHT'
5169 if vat = 'Y' and freight_as_line = 'Y' and freight_item not null
5170 get description from mtl_system_items
5171 else
5172 get description from ar_lookups */
5173
5174 -- per bug 2382340, take out the dependency on AR_ALLOW_TAX_CODE_OVERRIDE.
5175 -- IF l_vat_flag = 'Y' AND l_freight_as_line = 'Y'AND l_freight_item IS NOT NULL THEN
5176 BEGIN
5177 IF l_freight_as_line = 'Y'AND l_freight_item IS NOT NULL THEN
5178 SELECT description
5179 ,primary_uom_code
5180 INTO p_x_charges_rec.Description
5181 ,p_x_charges_rec.Uom_Code
5182 FROM mtl_system_items
5183 WHERE inventory_item_id = l_freight_item
5184 AND organization_id = oe_sys_parameters.value('MASTER_ORGANIZATION_ID', p_line_rec.org_id);
5185 ELSE
5186 SELECT meaning
5187 ,NULL
5188 INTO p_x_charges_rec.Description
5189 ,p_x_charges_rec.Uom_Code
5190 FROM ar_lookups
5191 WHERE lookup_type = 'STD_LINE_TYPE'
5192 AND lookup_code = 'FREIGHT';
5193 END IF;
5194
5195 EXCEPTION
5196 WHEN NO_DATA_FOUND THEN
5197 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
5198 FND_MESSAGE.SET_NAME('ONT','ONT_FREIGHT_ITEM_REQUIRED');
5199 OE_MSG_PUB.ADD;
5200 END IF;
5201
5202 RAISE FND_API.G_EXC_ERROR;
5203 END;
5204
5205 IF l_freight_as_line = 'Y' THEN
5206 IF l_freight_item IS NULL THEN
5207 p_x_charges_rec.Inventory_Item_Id := NULL;
5208 p_x_charges_rec.Line_Type := 'LINE';
5209 ELSE
5210 p_x_charges_rec.Inventory_Item_Id := l_freight_item;
5211 p_x_charges_rec.Line_Type := 'LINE';
5212 END IF;
5213 ELSE
5214 p_x_charges_rec.Inventory_Item_Id := NULL;
5215 p_x_charges_rec.Line_Type := 'FREIGHT';
5216 p_x_charges_rec.Tax_Exempt_Flag := NULL;
5217 p_x_charges_rec.Tax_Exempt_Number := NULL;
5218 p_x_charges_rec.Tax_Exempt_Reason_Code := NULL;
5219 END IF;
5220
5221 IF l_debug_level > 0 THEN
5222 oe_debug_pub.add( 'LINE TYPE IS SET AS ' ||P_X_CHARGES_REC.LINE_TYPE , 1 ) ;
5223 END IF;
5224
5225 -- bug 8221567 start
5226
5227 IF p_x_charges_rec.Credit_Method_For_Acct_Rule = 'UNIT' AND l_freight_as_line = 'Y' THEN
5228 p_x_charges_rec.Quantity := 1;
5229 ELSE
5230 p_x_charges_rec.Quantity := NULL;
5231 END IF;
5232 IF l_debug_level > 0 THEN
5233 oe_debug_pub.add( 'p_x_charges_rec.Quantity ' ||p_x_charges_rec.Quantity , 1 ) ;
5234
5235 END IF;
5236 -- bug 8221567 end
5237
5238
5239 p_x_charges_rec.Quantity_Ordered := NULL;
5240 p_x_charges_rec.Unit_Selling_Price := NULL;
5241 p_x_charges_rec.Unit_Standard_Price := NULL;
5242
5243 Rounded_Amount(p_currency_code => p_x_charges_rec.currency_code
5244 ,p_unrounded_amount => p_x_charges_rec.amount
5245 ,x_rounded_amount => l_rounded_amount );
5246
5247 p_x_charges_rec.amount := l_rounded_amount;
5248
5249 p_x_charges_rec.Sales_Order_Line := NULL;
5250 IF l_debug_level > 0 THEN
5251 oe_debug_pub.add( 'LINE CATEGORY CODE : '||P_LINE_REC.LINE_CATEGORY_CODE , 5 ) ;
5252 END IF;
5253 -- Change made for the FP bug #3802957
5254 IF p_line_rec.line_category_code = 'RETURN' then
5255 IF l_debug_level > 0 THEN
5256 oe_debug_pub.add( 'REFERENCE LINE_ID FOR FREIGHT RECORD BEFORE : '||P_X_CHARGES_REC.REFERENCE_LINE_ID , 5 ) ;
5257 oe_debug_pub.add( 'P_LINE_REC.REFERENCE_LINE_ID : '||P_LINE_REC.REFERENCE_LINE_ID , 5 ) ;
5258 oe_debug_pub.add( 'INTERFACE_LINE_ATTRIBUTE6 : '||P_X_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 , 5 ) ;
5259 END IF;
5260
5261 -- 3645784
5262 -- RT{Retrobill lines will not have freight charges applied
5263 -- so for retrobill lines shouldnt come to this part at all
5264 -- But still coded it so that it doesnt fail
5265 IF ( p_line_rec.order_source_id = 27) THEN
5266 l_ref_header_id := to_number(p_line_rec.orig_sys_document_ref);
5267 l_ref_line_id := to_number(p_line_rec.orig_sys_line_ref);
5268 ELSE
5269 FOR order_info_rec in ORDER_INFO(p_line_rec.reference_line_id) LOOP
5270 l_ref_header_id := order_info_rec.header_id;
5271 l_ref_line_id := order_info_rec.line_id;
5272 l_ref_order_number := to_char(order_info_rec.order_number);
5273 l_ref_order_type := order_info_rec.order_type;
5274 END LOOP;
5275 END IF;
5276
5277 BEGIN
5278
5279 SELECT FRE.customer_trx_line_id
5280 INTO l_reference_line_id
5281 FROM RA_CUSTOMER_TRX_LINES_ALL FRE
5282 WHERE FRE.LINE_TYPE IN ('LINE', 'FREIGHT')
5283 AND FRE.INTERFACE_LINE_CONTEXT = 'ORDER ENTRY'
5284 AND FRE.INTERFACE_LINE_ATTRIBUTE1 = l_ref_order_number
5285 AND FRE.INTERFACE_LINE_ATTRIBUTE2 = l_ref_order_type
5286 AND FRE.INTERFACE_LINE_ATTRIBUTE6 =
5287 (SELECT TO_CHAR(D.PRICE_ADJUSTMENT_ID)
5288 FROM OE_PRICE_ADJUSTMENTS D
5289 WHERE D.HEADER_ID = l_ref_header_id
5290 AND NVL(D.LINE_ID, l_ref_line_id) = l_ref_line_id
5291 AND D.LIST_LINE_ID =
5292 (SELECT D2.LIST_LINE_ID
5293 FROM OE_PRICE_ADJUSTMENTS D2
5294 WHERE D2.PRICE_ADJUSTMENT_ID=p_x_charges_rec.INTERFACE_LINE_ATTRIBUTE6));
5295
5296 EXCEPTION
5297 WHEN OTHERS THEN
5298 IF l_debug_level > 0 THEN
5299 oe_debug_pub.add( 'UNABLE TO FIND REFERENCE LINE ID : '||SQLERRM , 1 ) ;
5300 END IF;
5301 NULL;
5302 END;
5303 IF l_reference_line_id IS NULL THEN
5304 BEGIN
5305 SELECT ra1.customer_trx_line_id
5306 INTO l_reference_line_id
5307 from ra_customer_trx_lines_all ra1, /* MOAC SQL CHANGE */
5308 ra_customer_trx_lines ra2
5309 where ra2.customer_trx_line_id = p_x_charges_rec.reference_line_id
5310 and ra1.customer_trx_id = ra2.customer_trx_id
5311 and ra1.line_type = 'FREIGHT'
5312 and ra1.request_id is not null;
5313 EXCEPTION
5314 WHEN OTHERS THEN
5315 IF l_debug_level > 0 THEN
5316 oe_debug_pub.add( 'UNABLE TO FIND REFERENCE LINE ID - 2 : '||SQLERRM , 1 ) ;
5317 END IF;
5318 NULL;
5319 END;
5320 END IF;
5321 p_x_charges_rec.Reference_Line_Id := l_reference_line_id;
5322 IF l_debug_level > 0 THEN
5323 oe_debug_pub.add( 'REFERENCE LINE_ID FOR FREIGHT LINE AFTER : '||P_X_CHARGES_REC.REFERENCE_LINE_ID , 5 ) ;
5324 END IF;
5325 end if;
5326 -- IF p_line_rec.commitment_id is not null then
5327 -- re populate cust_trx_type_id which was nulled out for interface line
5328 -- p_x_charges_rec.Cust_Trx_Type_Id := Get_Customer_Transaction_Type(p_line_rec);
5329 -- END IF;
5330 p_x_charges_rec.PROMISED_COMMITMENT_AMOUNT := 0; -- For bug 6798675 NULL;
5331 -- Adding for bug# 4071445
5332 IF p_x_charges_rec.LINE_TYPE = 'FREIGHT' OR
5333 nvl(FND_PROFILE.VALUE('ONT_TAX_CODE_FOR_FREIGHT'), 'N') = 'N' THEN
5334 p_x_charges_rec.Tax_Code := NULL;
5335 IF l_debug_level > 0 THEN
5336 oe_debug_pub.add('tax_code for freight is set as ' ||p_x_charges_rec.tax_code , 5 ) ;
5337 END IF;
5338 END IF;
5339 --Customer Acceptance
5340 -- should be set always irrespective of customer acceptance enabled or not
5341 p_x_charges_rec.deferral_exclusion_flag := 'Y';
5342 --Customer Acceptance
5343 -- bug 2509121.
5344 -- translated description is only needed for sales order line.
5345 IF p_x_charges_rec.translated_description is not null THEN
5346 p_x_charges_rec.translated_description := null;
5347 END IF;
5348
5349 IF l_debug_level > 0 THEN
5350 oe_debug_pub.add( 'EXIT PREPARE_FREIGHT_CHARGES_REC ( ) PROCEDURE' , 5 ) ;
5351 END IF;
5352 END Prepare_Freight_Charges_Rec;
5353
5354 PROCEDURE Interface_Freight_Charges
5355 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
5356 , p_interface_line_rec IN RA_Interface_Lines_Rec_Type
5357 , x_return_status OUT NOCOPY VARCHAR2
5358 ) IS
5359 l_charges_rec RA_Interface_Lines_Rec_Type;
5360 l_return_status VARCHAR2(30);
5361 l_line_rec OE_Order_Pub.Line_Rec_Type;
5362 config_line_id NUMBER;
5363 l_invoiced_amount NUMBER;
5364 l_charge_amount NUMBER;
5365 l_count1 NUMBER := 0;
5366 l_count2 NUMBER := 0 ;
5367 --pnpl
5368 l_hdr_payment_term_id NUMBER;
5369 CURSOR Line_Charges_Cursor(p_header_id IN NUMBER, p_line_id IN NUMBER) IS
5370 SELECT CHARGE_ID
5371 ,CHARGE_NAME
5372 ,CHARGE_AMOUNT
5373 ,nvl(INVOICED_AMOUNT,CHARGE_AMOUNT)
5374 ,CURRENCY_CODE
5375 ,CONTEXT
5376 ,substrb(ATTRIBUTE1, 1, 150)
5377 ,substrb(ATTRIBUTE2, 1, 150)
5378 ,substrb(ATTRIBUTE3, 1, 150)
5379 ,substrb(ATTRIBUTE4, 1, 150)
5380 ,substrb(ATTRIBUTE5, 1, 150)
5381 ,substrb(ATTRIBUTE6, 1, 150)
5382 ,substrb(ATTRIBUTE7, 1, 150)
5383 ,substrb(ATTRIBUTE8, 1, 150)
5384 ,substrb(ATTRIBUTE9, 1, 150)
5385 ,substrb(ATTRIBUTE10, 1, 150)
5386 ,substrb(ATTRIBUTE11, 1, 150)
5387 ,substrb(ATTRIBUTE12, 1, 150)
5388 ,substrb(ATTRIBUTE13, 1, 150)
5389 ,substrb(ATTRIBUTE14, 1, 150)
5390 ,substrb(ATTRIBUTE15, 1, 150)
5391 FROM oe_charge_lines_v
5392 WHERE header_id = p_header_id
5393 AND line_id = p_line_id
5394 AND nvl(invoiced_flag, 'N') = 'N';
5395
5396 CURSOR Header_Charges_Cursor(p_header_id IN NUMBER, p_line_id IN NUMBER) IS
5397 SELECT CHARGE_ID
5398 ,CHARGE_NAME
5399 ,CHARGE_AMOUNT
5400 ,nvl(INVOICED_AMOUNT,CHARGE_AMOUNT)
5401 ,CURRENCY_CODE
5402 ,CONTEXT
5403 ,substrb(ATTRIBUTE1, 1, 150)
5404 ,substrb(ATTRIBUTE2, 1, 150)
5405 ,substrb(ATTRIBUTE3, 1, 150)
5406 ,substrb(ATTRIBUTE4, 1, 150)
5407 ,substrb(ATTRIBUTE5, 1, 150)
5408 ,substrb(ATTRIBUTE6, 1, 150)
5409 ,substrb(ATTRIBUTE7, 1, 150)
5410 ,substrb(ATTRIBUTE8, 1, 150)
5411 ,substrb(ATTRIBUTE9, 1, 150)
5412 ,substrb(ATTRIBUTE10, 1, 150)
5413 ,substrb(ATTRIBUTE11, 1, 150)
5414 ,substrb(ATTRIBUTE12, 1, 150)
5415 ,substrb(ATTRIBUTE13, 1, 150)
5416 ,substrb(ATTRIBUTE14, 1, 150)
5417 ,substrb(ATTRIBUTE15, 1, 150)
5418 FROM oe_charge_lines_v
5419 WHERE header_id = p_line_rec.header_id
5420 AND line_id IS NULL
5421 AND nvl(invoiced_flag, 'N') = 'N'
5422 for update nowait; -- Bug #3686558
5423
5424 CURSOR Modified_Header_Charges_Cursor(p_header_id IN NUMBER, p_line_id IN NUMBER) IS
5425 SELECT CHARGE_ID
5426 ,CHARGE_NAME
5427 ,(CHARGE_AMOUNT - INVOICED_AMOUNT)
5428 ,CHARGE_AMOUNT
5429 ,(CHARGE_AMOUNT - INVOICED_AMOUNT) -- should be diff amount which is not rounded, for bug 5400517
5430 ,CURRENCY_CODE
5431 ,CONTEXT
5432 ,substrb(ATTRIBUTE1, 1, 150)
5433 ,substrb(ATTRIBUTE2, 1, 150)
5434 ,substrb(ATTRIBUTE3, 1, 150)
5435 ,substrb(ATTRIBUTE4, 1, 150)
5436 ,substrb(ATTRIBUTE5, 1, 150)
5437 ,substrb(ATTRIBUTE6, 1, 150)
5438 ,substrb(ATTRIBUTE7, 1, 150)
5439 ,substrb(ATTRIBUTE8, 1, 150)
5440 ,substrb(ATTRIBUTE9, 1, 150)
5441 ,substrb(ATTRIBUTE10, 1, 150)
5442 ,substrb(ATTRIBUTE11, 1, 150)
5443 ,substrb(ATTRIBUTE12, 1, 150)
5444 ,substrb(ATTRIBUTE13, 1, 150)
5445 ,substrb(ATTRIBUTE14, 1, 150)
5446 ,substrb(ATTRIBUTE15, 1, 150)
5447 FROM oe_charge_lines_v
5448 WHERE header_id = p_header_id
5449 AND line_id IS NULL
5450 AND nvl(invoiced_flag, 'N') = 'Y'
5451 AND invoiced_amount IS NOT NULL
5452 AND invoiced_amount <> charge_amount
5453 for update nowait; -- Bug #3686558
5454
5455 CURSOR config_for_model (l_line_id NUMBER) IS
5456 SELECT LINE_ID
5457 FROM OE_ORDER_LINES
5458 WHERE LINK_TO_LINE_ID = l_line_id
5459 AND ITEM_TYPE_CODE = 'CONFIG';
5460
5461 --
5462 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5463 --
5464 BEGIN
5465 IF l_debug_level > 0 THEN
5466 oe_debug_pub.add( 'ENTER INTERFACE_FREIGHT_CHARGES ( ) PROCEDURE' , 5 ) ;
5467 END IF;
5468 l_charges_rec := p_interface_line_rec;
5469 OPEN Line_Charges_Cursor(p_line_rec.header_id, p_line_rec.line_id);
5470 LOOP
5471 IF l_debug_level > 0 THEN
5472 oe_debug_pub.add( 'IN THE LOOP: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 , 5 ) ;
5473 END IF;
5474 FETCH Line_Charges_Cursor INTO
5475 l_charges_rec.INTERFACE_LINE_ATTRIBUTE6 -- charge_id
5476 ,l_charges_rec.description
5477 ,l_charges_rec.amount
5478 ,l_invoiced_amount
5479 ,l_charges_rec.currency_code
5480 ,l_charges_rec.attribute_category
5481 ,l_charges_rec.attribute1
5482 ,l_charges_rec.attribute2
5483 ,l_charges_rec.attribute3
5484 ,l_charges_rec.attribute4
5485 ,l_charges_rec.attribute5
5486 ,l_charges_rec.attribute6
5487 ,l_charges_rec.attribute7
5488 ,l_charges_rec.attribute8
5489 ,l_charges_rec.attribute9
5490 ,l_charges_rec.attribute10
5491 ,l_charges_rec.attribute11
5492 ,l_charges_rec.attribute12
5493 ,l_charges_rec.attribute13
5494 ,l_charges_rec.attribute14
5495 ,l_charges_rec.attribute15;
5496 EXIT WHEN Line_Charges_Cursor%NOTFOUND;
5497 IF l_debug_level > 0 THEN
5498 oe_debug_pub.add( 'IN THE LOOP 1: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 , 5 ) ;
5499 oe_debug_pub.add( 'INVOICE SOURCE BEFORE CALLING PREPARE_FREIGHT_CHARGES_REC '|| L_CHARGES_REC.BATCH_SOURCE_NAME , 5 ) ;
5500 END IF;
5501 --prepare l_charges_rec
5502 Prepare_Freight_Charges_Rec(p_line_rec => p_line_rec
5503 ,p_x_charges_rec => l_charges_rec);
5504 IF l_debug_level > 0 THEN
5505 oe_debug_pub.add( 'INVOICE SOURCE AFTER : '|| L_CHARGES_REC.BATCH_SOURCE_NAME , 5 ) ;
5506 oe_debug_pub.add( 'FREIGHT LINE TYPE : '||L_CHARGES_REC.LINE_TYPE , 5 ) ;
5507 END IF;
5508 IF l_charges_rec.Amount = 0 THEN
5509 -- Issue Message (Zero Amount Freight Charge not interfaced)
5510 IF l_debug_level > 0 THEN
5511 oe_debug_pub.add( 'ZERO AMOUNT FREIGHT NOT INTERFACED' , 5 ) ;
5512 END IF;
5513 ELSE
5514 Insert_Line(l_charges_rec
5515 ,x_return_status=>l_return_status);
5516 -- Fix for the bug 2187074
5517 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5518 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5519 END IF;
5520
5521 IF l_charges_rec.line_type = 'LINE' THEN
5522 Interface_scredits_for_freight
5523 (p_line_rec => p_line_rec
5524 , p_interface_line_rec => l_charges_rec
5525 , p_line_level_charge => 'Y');
5526 END IF;
5527 --Set oe_price_adjustment.Invoiced_flag for the interfaced charge line
5528 Update_Invoiced_Flag(to_number(l_charges_rec.INTERFACE_LINE_ATTRIBUTE6)
5529 ,l_charges_rec.amount
5530 ,l_invoiced_amount
5531 ,l_return_status);
5532 END IF;
5533 END LOOP;
5534 CLOSE Line_Charges_Cursor;
5535 --Bug2465201
5536 IF p_line_rec.item_type_code IN ( 'MODEL','CLASS') THEN
5537 OPEN CONFIG_FOR_MODEL (p_line_rec.line_id);
5538 FETCH CONFIG_FOR_MODEL INTO config_line_id;
5539 CLOSE CONFIG_FOR_MODEL;
5540
5541 IF config_line_id IS NOT NULL THEN
5542 IF l_debug_level > 0 THEN
5543 oe_debug_pub.add( 'FOUND CONFIG LINE : '||CONFIG_LINE_ID , 1 ) ;
5544 END IF;
5545 -- Initialize API return status to success
5546 x_return_status := FND_API.G_RET_STS_SUCCESS;
5547 OE_Line_Util.Lock_Row(p_line_id=>config_line_id
5548 , p_x_line_rec => l_line_rec
5549 , x_return_status => l_return_status
5550 );
5551 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5552 IF l_debug_level > 0 THEN
5553 oe_debug_pub.add( 'UNABLE TO LOCK LINE ID '||CONFIG_LINE_ID||' '||SQLERRM , 1 ) ;
5554 END IF;
5555 RAISE FND_API.G_EXC_ERROR;
5556 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5557 IF l_debug_level > 0 THEN
5558 oe_debug_pub.add( 'UNABLE TO LOCK LINE ID '||CONFIG_LINE_ID||' '||SQLERRM , 1 ) ;
5559 END IF;
5560 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5561 END IF;
5562 IF l_debug_level > 0 THEN
5563 oe_debug_pub.add( 'INTERFACING OTHER CHARGES ASSOCIATED WITH THIS MODEL..' , 1 ) ;
5564 END IF;
5565 OPEN Line_Charges_Cursor(p_line_rec.header_id, config_line_id);
5566 LOOP
5567 IF l_debug_level > 0 THEN
5568 oe_debug_pub.add( 'IN THE LOOP: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 , 5 ) ;
5569 END IF;
5570 FETCH Line_Charges_Cursor INTO
5571 l_charges_rec.INTERFACE_LINE_ATTRIBUTE6 -- charge_id
5572 ,l_charges_rec.description
5573 ,l_charges_rec.amount
5574 ,l_invoiced_amount
5575 ,l_charges_rec.currency_code
5576 ,l_charges_rec.attribute_category
5577 ,l_charges_rec.attribute1
5578 ,l_charges_rec.attribute2
5579 ,l_charges_rec.attribute3
5580 ,l_charges_rec.attribute4
5581 ,l_charges_rec.attribute5
5582 ,l_charges_rec.attribute6
5583 ,l_charges_rec.attribute7
5584 ,l_charges_rec.attribute8
5585 ,l_charges_rec.attribute9
5586 ,l_charges_rec.attribute10
5587 ,l_charges_rec.attribute11
5588 ,l_charges_rec.attribute12
5589 ,l_charges_rec.attribute13
5590 ,l_charges_rec.attribute14
5591 ,l_charges_rec.attribute15;
5592 EXIT WHEN Line_Charges_Cursor%NOTFOUND;
5593 IF l_debug_level > 0 THEN
5594 oe_debug_pub.add( 'IN THE LOOP 1: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 , 5 ) ;
5595 oe_debug_pub.add( 'INVOICE SOURCE BEFORE CALLING PREPARE_FREIGHT_CHARGES_REC '|| L_CHARGES_REC.BATCH_SOURCE_NAME , 5 ) ;
5596 END IF;
5597 --prepare l_charges_rec
5598 Prepare_Freight_Charges_Rec(p_line_rec => p_line_rec
5599 ,p_x_charges_rec => l_charges_rec);
5600 IF l_debug_level > 0 THEN
5601 oe_debug_pub.add( 'INVOICE SOURCE AFTER : '|| L_CHARGES_REC.BATCH_SOURCE_NAME , 5 ) ;
5602 oe_debug_pub.add( 'FREIGHT LINE TYPE : '||L_CHARGES_REC.LINE_TYPE , 5 ) ;
5603 END IF;
5604 IF l_charges_rec.Amount = 0 THEN
5605 -- Issue Message (Zero Amount Freight Charge not interfaced)
5606 IF l_debug_level > 0 THEN
5607 oe_debug_pub.add( 'ZERO AMOUNT FREIGHT NOT INTERFACED' , 5 ) ;
5608 END IF;
5609 ELSE
5610 Insert_Line(l_charges_rec
5611 ,x_return_status=>l_return_status);
5612 -- Fix for the bug 2187074
5613 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5614 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5615 END IF;
5616
5617 /* Added for the bug 3019754 */
5618 IF l_charges_rec.line_type = 'LINE' THEN
5619 Interface_scredits_for_freight
5620 (p_line_rec => p_line_rec
5621 , p_interface_line_rec => l_charges_rec
5622 , p_line_level_charge => 'Y');
5623 END IF;
5624
5625 --Set oe_price_adjustment.Invoiced_flag for the interfaced charge line
5626 Update_Invoiced_Flag(to_number(l_charges_rec.INTERFACE_LINE_ATTRIBUTE6)
5627 ,l_charges_rec.amount
5628 ,l_invoiced_amount
5629 ,l_return_status);
5630 END IF;
5631 END LOOP;
5632 CLOSE Line_Charges_Cursor;
5633 END IF;
5634 END IF;
5635 IF l_debug_level > 0 THEN
5636 oe_debug_pub.add( 'INTERFACING HEADER CHARGES...' , 1 ) ;
5637 END IF;
5638 l_charges_rec := p_interface_line_rec;
5639 --pnpl
5640 --get header level payment term for header level charges
5641 -- bug 4680186
5642 IF NOT Return_Line(p_line_rec) THEN
5643 BEGIN
5644 SELECT payment_term_id INTO l_hdr_payment_term_id
5645 FROM oe_order_headers_all
5646 WHERE header_id = p_line_rec.header_id;
5647 EXCEPTION
5648 WHEN NO_DATA_FOUND THEN
5649 l_hdr_payment_term_id := null;
5650 END;
5651 END IF;
5652
5653 OPEN Header_Charges_Cursor(p_line_rec.header_id, p_line_rec.line_id);
5654 LOOP
5655 IF l_debug_level > 0 THEN
5656 oe_debug_pub.add( 'IN THE LOOP: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 ) ;
5657 END IF;
5658 FETCH Header_Charges_Cursor INTO
5659 l_charges_rec.INTERFACE_LINE_ATTRIBUTE6 -- charge_id
5660 ,l_charges_rec.description
5661 ,l_charges_rec.amount
5662 ,l_invoiced_amount
5663 ,l_charges_rec.currency_code
5664 ,l_charges_rec.attribute_category
5665 ,l_charges_rec.attribute1
5666 ,l_charges_rec.attribute2
5667 ,l_charges_rec.attribute3
5668 ,l_charges_rec.attribute4
5669 ,l_charges_rec.attribute5
5670 ,l_charges_rec.attribute6
5671 ,l_charges_rec.attribute7
5672 ,l_charges_rec.attribute8
5673 ,l_charges_rec.attribute9
5674 ,l_charges_rec.attribute10
5675 ,l_charges_rec.attribute11
5676 ,l_charges_rec.attribute12
5677 ,l_charges_rec.attribute13
5678 ,l_charges_rec.attribute14
5679 ,l_charges_rec.attribute15;
5680 --pnpl
5681 l_charges_rec.term_id := l_hdr_payment_term_id;
5682 EXIT WHEN Header_Charges_Cursor%NOTFOUND;
5683
5684
5685 IF l_debug_level > 0 THEN
5686 oe_debug_pub.add( 'IN THE LOOP 1: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 ) ;
5687 oe_debug_pub.add( 'INVOICE SOURCE BEFORE CALLING PREPARE_FREIGHT_CHARGES_REC '|| L_CHARGES_REC.BATCH_SOURCE_NAME ) ;
5688 --pnpl
5689 oe_debug_pub.add( 'l_charges_rec.term_id : ' || l_charges_rec.term_id);
5690 END IF;
5691 --prepare l_charges_rec
5692 Prepare_Freight_Charges_Rec(p_line_rec => p_line_rec
5693 ,p_x_charges_rec => l_charges_rec);
5694 IF l_debug_level > 0 THEN
5695 oe_debug_pub.add( 'INVOICE SOURE AFTER CALLING PREPARE_FREIGHT_CHARGES_REC '|| L_CHARGES_REC.BATCH_SOURCE_NAME ) ;
5696 oe_debug_pub.add( 'FREIGHT LINE TYPE: '||L_CHARGES_REC.LINE_TYPE ) ;
5697 END IF;
5698 IF l_charges_rec.Amount = 0 THEN
5699 IF l_debug_level > 0 THEN
5700 oe_debug_pub.add( ' ZERO AMOUNT FREIGHT NOT INTERFACED' , 5 ) ;
5701 END IF;
5702 ELSE
5703 Insert_Line(l_charges_rec
5704 ,x_return_status=>l_return_status);
5705 -- Fix for the bug 2187074
5706 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5707 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5708 END IF;
5709
5710 IF l_charges_rec.line_type = 'LINE' THEN
5711 Interface_scredits_for_freight
5712 (p_line_rec => p_line_rec
5713 , p_interface_line_rec => l_charges_rec
5714 , p_line_level_charge => 'N');
5715 END IF;
5716 --Set oe_price_adjustment.Invoiced_flag for the interfaced charge line
5717 Update_Invoiced_Flag(to_number(l_charges_rec.INTERFACE_LINE_ATTRIBUTE6)
5718 ,l_charges_rec.amount
5719 ,l_invoiced_amount
5720 ,l_return_status);
5721 END IF;
5722 END LOOP;
5723 CLOSE Header_Charges_Cursor;
5724 x_return_status := FND_API.G_RET_STS_SUCCESS;
5725
5726 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
5727 IF l_debug_level > 0 THEN
5728 oe_debug_pub.add( 'INTERFACING Modified HEADER CHARGES...' , 1 ) ;
5729 END IF;
5730 l_charges_rec := p_interface_line_rec;
5731 OPEN Modified_Header_Charges_Cursor(p_line_rec.header_id, p_line_rec.line_id);
5732 LOOP
5733 IF l_debug_level > 0 THEN
5734 oe_debug_pub.add( 'IN THE LOOP: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 ) ;
5735 END IF;
5736 FETCH Modified_Header_Charges_Cursor INTO
5737 l_charges_rec.INTERFACE_LINE_ATTRIBUTE6 -- charge_id
5738 ,l_charges_rec.description
5739 ,l_charges_rec.amount
5740 ,l_charge_amount
5741 ,l_invoiced_amount
5742 ,l_charges_rec.currency_code
5743 ,l_charges_rec.attribute_category
5744 ,l_charges_rec.attribute1
5745 ,l_charges_rec.attribute2
5746 ,l_charges_rec.attribute3
5747 ,l_charges_rec.attribute4
5748 ,l_charges_rec.attribute5
5749 ,l_charges_rec.attribute6
5750 ,l_charges_rec.attribute7
5751 ,l_charges_rec.attribute8
5752 ,l_charges_rec.attribute9
5753 ,l_charges_rec.attribute10
5754 ,l_charges_rec.attribute11
5755 ,l_charges_rec.attribute12
5756 ,l_charges_rec.attribute13
5757 ,l_charges_rec.attribute14
5758 ,l_charges_rec.attribute15;
5759
5760 --pnpl
5761 l_charges_rec.term_id := l_hdr_payment_term_id;
5762 EXIT WHEN Modified_Header_Charges_Cursor%NOTFOUND;
5763 IF l_debug_level > 0 THEN
5764 oe_debug_pub.add( 'IN THE LOOP 1: L_CHARGES_REC.CHARGE_ID: '|| L_CHARGES_REC.INTERFACE_LINE_ATTRIBUTE6 ) ;
5765 oe_debug_pub.add( 'Charge_Amount:'||l_charge_amount ||':Invoiced_Amount:'||l_invoiced_amount) ;
5766 --pnpl
5767 oe_debug_pub.add( 'l_charges_rec.term_id : ' || l_charges_rec.term_id);
5768 END IF;
5769
5770 --prepare l_charges_rec
5771 Prepare_Freight_Charges_Rec(p_line_rec => p_line_rec
5772 ,p_x_charges_rec => l_charges_rec);
5773
5774 SELECT nvl(max(interface_line_attribute5),0) --Bug 3338492
5775 INTO l_count1
5776 FROM ra_interface_lines_all
5777 WHERE interface_line_context = 'ORDER ENTRY'
5778 AND interface_line_attribute1 = l_charges_rec.INTERFACE_LINE_ATTRIBUTE1
5779 AND interface_line_attribute2 = l_charges_rec.INTERFACE_LINE_ATTRIBUTE2
5780 AND interface_line_attribute6 = l_charges_rec.INTERFACE_LINE_ATTRIBUTE6
5781 AND interface_line_attribute11 = '0'
5782 AND NVL(interface_status, '~') <> 'P';
5783 SELECT nvl(max(interface_line_attribute5),0)
5784 INTO l_count2
5785 FROM ra_customer_trx_lines_all
5786 WHERE interface_line_context = 'ORDER ENTRY'
5787 AND interface_line_attribute1 = l_charges_rec.INTERFACE_LINE_ATTRIBUTE1
5788 AND interface_line_attribute2 = l_charges_rec.INTERFACE_LINE_ATTRIBUTE2
5789 AND interface_line_attribute6 = l_charges_rec.INTERFACE_LINE_ATTRIBUTE6
5790 AND interface_line_attribute11 = '0';
5791
5792 IF l_count1 > l_count2 THEN
5793 l_charges_rec.INTERFACE_LINE_ATTRIBUTE5 := l_count1 + 1 ;
5794 ELSE
5795 l_charges_rec.INTERFACE_LINE_ATTRIBUTE5 := l_count2 + 1 ;
5796 END IF;
5797
5798 IF l_debug_level > 0 THEN
5799 oe_debug_pub.add( 'INTERFACE_LINE_ATTRIBUTE5: '|| l_charges_rec.INTERFACE_LINE_ATTRIBUTE5 , 5 ) ;
5800 oe_debug_pub.add( 'INVOICE SOURE AFTER CALLING PREPARE_FREIGHT_CHARGES_REC '|| L_CHARGES_REC.BATCH_SOURCE_NAME ) ;
5801 oe_debug_pub.add( 'FREIGHT LINE TYPE: '||L_CHARGES_REC.LINE_TYPE ) ;
5802 END IF;
5803
5804 IF l_charges_rec.Amount = 0 THEN
5805 IF l_debug_level > 0 THEN
5806 oe_debug_pub.add( ' ZERO AMOUNT FREIGHT NOT INTERFACED' , 5 ) ;
5807 END IF;
5808 ELSE
5809 Insert_Line(l_charges_rec
5810 ,x_return_status=>l_return_status);
5811 -- Fix for the bug 2187074
5812 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5813 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5814 END IF;
5815
5816 IF l_charges_rec.line_type = 'LINE' THEN
5817 Interface_scredits_for_freight
5818 (p_line_rec => p_line_rec
5819 , p_interface_line_rec => l_charges_rec
5820 , p_line_level_charge => 'N');
5821 END IF;
5822 --Set oe_price_adjustment.Invoiced_flag for the interfaced charge line
5823 Update_Invoiced_Flag(to_number(l_charges_rec.INTERFACE_LINE_ATTRIBUTE6)
5824 , l_charges_rec.amount
5825 ,l_invoiced_amount
5826 ,l_return_status);
5827 END IF;
5828 END LOOP;
5829 CLOSE Modified_Header_Charges_Cursor;
5830 x_return_status := FND_API.G_RET_STS_SUCCESS;
5831 END IF;
5832 IF l_debug_level > 0 THEN
5833 oe_debug_pub.add( 'EXITING INTERFACE_FREIGHT_CHARGES' , 5 ) ;
5834 END IF;
5835 EXCEPTION
5836 WHEN FND_API.G_EXC_ERROR THEN
5837 IF l_debug_level > 0 THEN
5838 oe_debug_pub.add( 'EXPECTED ERROR. EXITING INTERFACE_FREIGHT_CHARGES : '||SQLERRM , 1 ) ;
5839 END IF;
5840 x_return_status := FND_API.G_RET_STS_ERROR;
5841 WHEN APP_EXCEPTIONS.RECORD_LOCK_EXCEPTION THEN -- Bug #3686558
5842 IF l_debug_level > 0 THEN
5843 OE_DEBUG_PUB.Add('Unable to lock the line',3);
5844 END IF;
5845 x_return_status := FND_API.G_RET_STS_SUCCESS;
5846 WHEN OTHERS THEN
5847 IF l_debug_level > 0 THEN
5848 oe_debug_pub.add( 'EXCEPTION , INTERFACE_FREIGHT_CHARGES ( ) '||SQLERRM , 1 ) ;
5849 END IF;
5850 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5851 IF FND_MSG_PUB.Check_Msg_Level
5852 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5853 THEN
5854 OE_MSG_PUB.Add_Exc_Msg
5855 ( G_PKG_NAME
5856 , 'Interface_Freight_Charges'
5857 );
5858 END IF;
5859 IF (Line_Charges_Cursor%ISOPEN) THEN
5860 CLOSE Line_Charges_Cursor;
5861 END IF;
5862 IF (Header_Charges_Cursor%ISOPEN) THEN
5863 CLOSE Header_Charges_Cursor;
5864 END IF;
5865 END Interface_Freight_Charges;
5866
5867 PROCEDURE Prepare_Interface_Line_Rec
5868 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
5869 , p_header_rec IN OE_Order_Pub.Header_Rec_Type
5870 , p_x_interface_line_rec IN OUT NOCOPY RA_Interface_Lines_Rec_Type
5871 , x_result_code OUT NOCOPY VARCHAR2
5872 ) IS
5873 l_creation_sign VARCHAR2(30);
5874 l_territory_code VARCHAR2(30);
5875 l_delivery_line_id NUMBER;
5876 l_bank_acct_id NUMBER;
5877 l_bank_acct_uses_id NUMBER;
5878 l_pay_method_id NUMBER;
5879 l_pay_method_name VARCHAR2(50);
5880 l_merchant_id NUMBER;
5881 l_trxn_id NUMBER;
5882 l_tangible_id VARCHAR2(80);
5883 l_hdr_inv_to_cust_id NUMBER;
5884 l_gdf_rec OE_GDF_Rec_Type;
5885 l_jg_return_code NUMBER;
5886 l_jg_error_buffer VARCHAR2(240);
5887 l_rma_date DATE;
5888 l_rma_result VARCHAR2(1);
5889 l_count1 NUMBER := 0 ;
5890 l_count2 NUMBER := 0 ;
5891 l_item_description VARCHAR2(2000);
5892 l_course_end_date DATE;
5893 l_ship_method_code VARCHAR2(30);
5894 l_return_status VARCHAR2(1);
5895 l_accounting_rule_type VARCHAR2(10);
5896 l_acct_rule_duration NUMBER;
5897 l_orig_sys_ship_addr_id NUMBER;
5898 l_commitment_applied NUMBER;
5899 l_commitment_interfaced NUMBER;
5900 l_partial_line_amount NUMBER := 0;
5901 l_partial_line_tax_amount NUMBER := 0;
5902 l_partial_line_freight_amount NUMBER := 0;
5903 l_partial_line_promised_amount NUMBER := 0;
5904 l_fulfilled_qty NUMBER;
5905 l_set_of_books_rec OE_Order_Cache.Set_Of_Books_Rec_Type;
5906 l_user_id NUMBER;
5907 l_resp_id NUMBER;
5908 l_appl_id NUMBER;
5909 /*Added for FP bug # 3647389*/
5910 l_cur_user_id NUMBER;
5911 l_cur_resp_id NUMBER;
5912 l_cur_appl_id NUMBER;
5913 l_AR_Sys_Param_Rec AR_SYSTEM_PARAMETERS_ALL%ROWTYPE;
5914 --serla begin
5915 l_payment_type_code VARCHAR2(30);
5916 l_payment_trx_id NUMBER;
5917 l_receipt_method_id NUMBER;
5918 l_credit_card_holder_name VARCHAR2(80);
5919 l_credit_card_approval_code VARCHAR2(80);
5920 --serla end
5921 l_trx_date DATE;
5922 l_max_actual_shipment_date DATE;
5923 l_fulfillment_set_flag VARCHAR2(1) := FND_API.G_FALSE;
5924 -- 3757279
5925 l_concat_segment VARCHAR2(240) := NULL;
5926 l_prof_value VARCHAR2(240) := NULL;
5927 l_table_index BINARY_INTEGER;
5928 -- 3757279
5929 --Adding for bug#4190312
5930 l_return_code VARCHAR2(30);
5931 l_unmapped_date DATE;
5932 l_frequency VARCHAR2(15);
5933 l_calendar_name VARCHAR2(15);
5934
5935 --Customer Acceptance
5936 l_top_model_line_id NUMBER;
5937 l_parent_line_id NUMBER;
5938 l_order_line_id NUMBER;
5939 --
5940 l_payment_trxn_extension_id NUMBER;
5941 l_interface_line_rec RA_Interface_Lines_Rec_Type; --bug 4738947
5942
5943 l_invoice_to_customer_id NUMBER; -- Added for bug 6911267
5944
5945 --bug6086777 Reverting the fix for 5849568
5946 --bug5849568
5947 --l_cust_pay_method_id NUMBER;
5948 --bug6086340 Refix the fix for 5849568
5949 l_cust_pay_method_id NUMBER;
5950 L_ACCOUNTING_RULE_ID NUMBER;
5951 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5952 l_unround_amt NUMBER := 0; -- sol_ord_er #16014165
5953 --
5954 BEGIN
5955 IF l_debug_level > 0 THEN
5956 oe_debug_pub.add( 'ENTER PREPARE_INTERFACE_LINE_REC ( ) PROCEDURE ' , 5 ) ;
5957 END IF;
5958 l_interface_line_rec.request_id := p_x_interface_line_rec.request_id; --bug 4738947
5959 p_x_interface_line_rec := l_interface_line_rec; --bug 4738947
5960 l_delivery_line_id := Null;
5961 IF Shipping_info_Available(p_line_rec) THEN
5962 -- Fix for bug 2196494
5963 IF p_line_rec.item_type_code NOT In ('MODEL','CLASS','KIT') THEN
5964 BEGIN
5965 --Bug2181628 TO retrieve the minimum delivery_id of a line,if it is present
5966 --in more than one delivery.Hence used "MIN"instead of "ROWNUM".Hence split the SQL Query.
5967 SELECT min(dl.delivery_id)
5968 INTO l_delivery_line_id
5969 FROM wsh_new_deliveries dl,
5970 wsh_delivery_assignments da,
5971 wsh_delivery_details dd
5972 WHERE dd.delivery_detail_id = da.delivery_detail_id
5973 AND da.delivery_id = dl.delivery_id
5974 AND dd.source_code = 'OE'
5975 AND dd.released_status = 'C' -- bug 6721251
5976 AND dd.source_line_id = p_line_rec.line_id;
5977 -- AND rownum = 1;
5978 EXCEPTION
5979 WHEN NO_DATA_FOUND THEN
5980 IF l_debug_level > 0 THEN
5981 oe_debug_pub.add( 'REACHING NO DATA FOUND. DELIVERY DETAILS NOT FOUND FOR THIS LINE..' , 1 ) ;
5982 END IF;
5983 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3 := '0';
5984 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4 := '0';
5985 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7 := '0';
5986 END;
5987 /* Populate bill of lading */
5988 IF l_delivery_line_id Is Not Null Then
5989 BEGIN
5990 SELECT NVL(SUBSTR(dl.name, 1, 30), '0')
5991 ,NVL(SUBSTR(dl.waybill, 1, 30), '0')
5992 ,dl.ship_method_code
5993 ,dl.initial_pickup_date
5994 INTO p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3
5995 ,p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4
5996 ,l_ship_method_code
5997 ,p_x_interface_line_rec.SHIP_DATE_ACTUAL
5998 FROM wsh_new_deliveries dl
5999 WHERE dl.delivery_id = l_delivery_line_id;
6000
6001 IF l_debug_level > 0 THEN
6002 oe_debug_pub.add( 'POPULATING BILL OF LADING NUMBER ..' , 5 ) ;
6003 END IF;
6004 SELECT wdi.sequence_number
6005 INTO p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8
6006 FROM wsh_delivery_legs wdl,
6007 wsh_document_instances wdi
6008 where wdi.entity_name = 'WSH_DELIVERY_LEGS'
6009 and wdi.entity_id = wdl.delivery_leg_id
6010 and wdl.delivery_id =l_delivery_line_id
6011 and wdi.status <> 'CANCELLED'
6012 and rownum=1;
6013 IF l_debug_level > 0 THEN
6014 oe_debug_pub.add( 'BILL OF LADING NUMBER IS POPULATED AS ..'||P_X_INTERFACE_LINE_REC.INTERFACE_LINE_ATTRIBUTE8 , 5 ) ;
6015 END IF;
6016 EXCEPTION
6017 WHEN NO_DATA_FOUND THEN
6018 IF l_debug_level > 0 THEN
6019 oe_debug_pub.add( 'NO DETAILS FOR BILL OF LADING NUMBER FOUND ...' , 5 ) ;
6020 END IF;
6021 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8 := '0';
6022 END;
6023 END IF;
6024 --Fix for bug 3661402
6025 IF l_ship_method_code IS NOT NULL THEN
6026 GOTO get_ship_via;
6027 END IF;
6028 --End of Fix for bug 3661402
6029
6030 -- commented for bug 3661402
6031 /* BEGIN
6032 IF l_debug_level > 0 THEN
6033 oe_debug_pub.add( 'GETTING SHIP_VIA FROM SHIP_METHOD_CODE: '||L_SHIP_METHOD_CODE|| ' AND ORGANIZATION_ID: '||P_LINE_REC.SHIP_FROM_ORG_ID , 5 ) ;
6034 END IF;
6035 -- fix bug# 1382196
6036 IF l_ship_method_code IS NOT NULL THEN
6037 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' THEN
6038
6039 SELECT substr(freight_code,1,25)
6040 INTO p_x_interface_line_rec.SHIP_VIA
6041 FROM wsh_carriers wsh_ca,wsh_carrier_services wsh,
6042 wsh_org_carrier_services wsh_org
6043 WHERE wsh_org.organization_id = p_line_rec.ship_from_org_id
6044 AND wsh.carrier_service_id = wsh_org.carrier_service_id
6045 AND wsh_ca.carrier_id = wsh.carrier_id
6046 AND wsh.ship_method_code = l_ship_method_code
6047 AND wsh_org.enabled_flag = 'Y';
6048 ELSE
6049 SELECT substr(freight_code,1,25)
6050 INTO p_x_interface_line_rec.SHIP_VIA
6051 FROM wsh_carrier_ship_methods
6052 WHERE ship_method_code = l_ship_method_code
6053 AND organization_id = p_line_rec.ship_from_org_id;
6054 END IF;
6055 END IF;
6056 EXCEPTION
6057 WHEN NO_DATA_FOUND THEN
6058 p_x_interface_line_rec.SHIP_VIA := NULL;
6059 END; */
6060 ELSE --non ship line
6061 If p_line_rec.item_type_code In ('MODEL','CLASS','KIT') Then
6062 BEGIN
6063 --Bug2181628 TO retrieve the minimum delivery_id of a line,if it is present
6064 --in more than one delivery.Hence used "MIN"instead of "ROWNUM".Hence Split the Query.
6065 SELECT min(dl.delivery_id)
6066 INTO l_delivery_line_id
6067 FROM wsh_new_deliveries dl,
6068 wsh_delivery_assignments da,
6069 wsh_delivery_details dd
6070 WHERE dd.delivery_detail_id = da.delivery_detail_id
6071 AND da.delivery_id = dl.delivery_id
6072 AND dd.source_code = 'OE'
6073 AND dd.released_status = 'C' -- bug 6721251
6074 AND dd.top_model_line_id = p_line_rec.line_id;
6075 -- AND rownum = 1;
6076 EXCEPTION
6077 WHEN NO_DATA_FOUND THEN
6078 IF l_debug_level > 0 THEN
6079 oe_debug_pub.add( 'REACHING NO DATA FOUND. DELIVERY DETAILS NOT FOUND FOR THIS LINE..' , 1 ) ;
6080 END IF;
6081 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3 := '0';
6082 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4 := '0';
6083 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7 := '0';
6084 END;
6085 IF l_delivery_line_id Is Not Null Then
6086 BEGIN
6087 SELECT NVL(SUBSTR(dl.name, 1, 30), '0')
6088 ,NVL(SUBSTR(dl.waybill, 1, 30), '0')
6089 ,dl.ship_method_code
6090 ,dl.initial_pickup_date
6091 INTO p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3
6092 ,p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4
6093 ,l_ship_method_code
6094 ,p_x_interface_line_rec.SHIP_DATE_ACTUAL
6095 FROM wsh_new_deliveries dl
6096 WHERE dl.delivery_id = l_delivery_line_id;
6097
6098
6099 IF l_debug_level > 0 THEN
6100 oe_debug_pub.add( 'POPULATING BILL OF LADING NUMBER ..' , 5 ) ;
6101 END IF;
6102 SELECT substr(wdi.sequence_number,1,30)
6103 INTO p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8
6104 FROM wsh_delivery_legs wdl,
6105 wsh_document_instances wdi
6106 where wdi.entity_name = 'WSH_DELIVERY_LEGS'
6107 and wdi.entity_id = wdl.delivery_leg_id
6108 and wdl.delivery_id =l_delivery_line_id
6109 and wdi.status <> 'CANCELLED'
6110 and rownum=1;
6111 IF l_debug_level > 0 THEN
6112 oe_debug_pub.add( 'BILL OF LADING NUMBER IS POPULATED AS ..'||P_X_INTERFACE_LINE_REC.INTERFACE_LINE_ATTRIBUTE8 , 5 ) ;
6113 END IF;
6114 EXCEPTION
6115 WHEN NO_DATA_FOUND THEN
6116 IF l_debug_level > 0 THEN
6117 oe_debug_pub.add( 'NO DETAILS FOR BILL OF LADING NUMBER FOUND ...' , 5 ) ;
6118 END IF;
6119 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8 := '0';
6120 END;
6121
6122 --Fix for bug 3661402
6123 IF l_ship_method_code IS NOT NULL THEN
6124 GOTO get_ship_via;
6125 END IF;
6126 --End of Fix for bug 3661402
6127
6128 --Commented for bug 3661402
6129 /* Added for the bug number 2988432 */
6130
6131 /* BEGIN
6132 IF l_debug_level > 0 THEN
6133 oe_debug_pub.add( 'GETTING SHIP_VIA FROM SHIP_METHOD_CODE: '||L_SHIP_METHOD_CODE|| ' AND ORGANIZATION_ID: '||P_LINE_REC.SHIP_FROM_ORG_ID , 5 ) ;
6134 END IF;
6135 -- fix bug# 1382196
6136 IF l_ship_method_code IS NOT NULL THEN
6137 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' THEN
6138
6139 SELECT substr(freight_code,1,25)
6140 INTO p_x_interface_line_rec.SHIP_VIA
6141 FROM wsh_carriers wsh_ca,wsh_carrier_services wsh,
6142 wsh_org_carrier_services wsh_org
6143 WHERE wsh_org.organization_id = p_line_rec.ship_from_org_id
6144 AND wsh.carrier_service_id = wsh_org.carrier_service_id
6145 AND wsh_ca.carrier_id = wsh.carrier_id
6146 AND wsh.ship_method_code = l_ship_method_code
6147 AND wsh_org.enabled_flag = 'Y';
6148 ELSE
6149 SELECT substr(freight_code,1,25)
6150 INTO p_x_interface_line_rec.SHIP_VIA
6151 FROM wsh_carrier_ship_methods
6152 WHERE ship_method_code = l_ship_method_code
6153 AND organization_id = p_line_rec.ship_from_org_id;
6154 END IF;
6155 END IF;
6156 EXCEPTION
6157 WHEN NO_DATA_FOUND THEN
6158 p_x_interface_line_rec.SHIP_VIA := NULL;
6159 END; */
6160 /* Added for the bug number 2988432 */
6161
6162 END IF;
6163 END IF;
6164 END IF;
6165 END IF;
6166
6167 --Fix for bug 3661402
6168
6169 if l_ship_method_code is null then
6170 if p_line_rec.ship_from_org_id is not null then
6171 l_ship_method_code := p_line_rec.shipping_method_code;
6172 end if;
6173 end if;
6174
6175 <<get_ship_via>>
6176
6177 BEGIN
6178 IF l_debug_level > 0 THEN
6179 oe_debug_pub.add( 'GETTING SHIP_VIA FROM SHIP_METHOD_CODE: '||L_SHIP_METHOD_CODE|| ' AND ORGANIZATION_ID: '||P_LINE_REC.SHIP_FROM_ORG_ID ,5 ) ;
6180 END IF;
6181 IF l_ship_method_code IS NOT NULL THEN
6182 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509' THEN
6183
6184 SELECT substr(freight_code,1,25)
6185 INTO p_x_interface_line_rec.SHIP_VIA
6186 FROM wsh_carriers wsh_ca,wsh_carrier_services wsh,
6187 wsh_org_carrier_services wsh_org
6188 WHERE wsh_org.organization_id =
6189 p_line_rec.ship_from_org_id
6190 AND wsh.carrier_service_id =
6191 wsh_org.carrier_service_id
6192 AND wsh_ca.carrier_id = wsh.carrier_id
6193 AND wsh.ship_method_code = l_ship_method_code
6194 AND wsh_org.enabled_flag = 'Y';
6195 ELSE
6196 SELECT substr(freight_code,1,25)
6197 INTO p_x_interface_line_rec.SHIP_VIA
6198 FROM wsh_carrier_ship_methods
6199 WHERE ship_method_code = l_ship_method_code
6200 AND organization_id = p_line_rec.ship_from_org_id;
6201 END IF;
6202 END IF;
6203 EXCEPTION
6204 WHEN NO_DATA_FOUND THEN
6205 p_x_interface_line_rec.SHIP_VIA := NULL;
6206 END;
6207
6208 --End of fix for bug 3661402
6209
6210 /* 1847224 */
6211 IF l_delivery_line_id IS NULL THEN -- for Returns and non shippable lines
6212 IF l_debug_level > 0 THEN
6213 oe_debug_pub.add( 'NON SHIPPABLE OR RETURN LINE ' , 5 ) ;
6214 END IF;
6215 if p_line_rec.line_category_code <> 'RETURN' THEN
6216 IF l_debug_level > 0 THEN
6217 oe_debug_pub.add( 'THIS IS A NON-SHIPPABLE LINE..' , 5 ) ;
6218 END IF;
6219
6220 -- fixed bug 3435298
6221 -- for non-shippable line in a fulfillment set
6222 l_fulfillment_set_flag
6223 := OE_Line_Fullfill.Is_Part_Of_Fulfillment_Set
6224 (p_line_rec.line_id);
6225 IF l_fulfillment_set_flag = FND_API.G_TRUE THEN
6226 IF l_debug_level > 0 THEN
6227 oe_debug_pub.add( 'SETTING TRANSACTION DATE AS THE ACTUAL_SHIPMENT_DATE OF THE LAST SHIPPED ITEM IN THE SET. ' , 5 ) ;
6228 END IF;
6229
6230 BEGIN
6231 SELECT max(actual_shipment_date)
6232 INTO l_max_actual_shipment_date
6233 FROM oe_order_lines_all ool,
6234 oe_line_sets ols
6235 WHERE ool.shippable_flag = 'Y'
6236 AND ool.line_id = ols.line_id
6237 AND ols.set_id IN (SELECT os.set_id
6238 FROM oe_line_sets ls,
6239 oe_sets os
6240 WHERE ls.line_id = p_line_rec.line_id
6241 AND ls.set_id = os.set_id
6242 AND os.set_type='FULFILLMENT_SET');
6243 EXCEPTION WHEN NO_DATA_FOUND THEN
6244 null;
6245 END;
6246
6247 --4483722
6248 IF l_max_actual_shipment_date IS NULL THEN
6249 IF (fnd_profile.value('OE_RECEIVABLES_DATE_FOR_NONSHIP_LINES') = 'Y') THEN
6250 l_max_actual_shipment_date := SYSDATE;
6251 ELSE
6252 --Should we let the date be null?
6253 Null;
6254 END IF;
6255 END IF;
6256 --4483722
6257
6258 p_x_interface_line_rec.SHIP_DATE_ACTUAL := l_max_actual_shipment_date;
6259 -- for non-shippable line not in a fulfillment set
6260 ELSIF (fnd_profile.value('OE_RECEIVABLES_DATE_FOR_NONSHIP_LINES') = 'Y') THEN
6261 IF l_debug_level > 0 THEN
6262 oe_debug_pub.add( 'SETTING TRANSACTION DATE AS CURRENT DATE FOR THIS NONSHIP LINE ' , 5 ) ;
6263 END IF;
6264 p_x_interface_line_rec.SHIP_DATE_ACTUAL := SYSDATE;
6265
6266 END IF;
6267 end if;
6268 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3 := '0';
6269 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4 := '0';
6270 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7 := '0';
6271 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8 := '0';
6272 END IF;
6273 -- for bug# 1468820
6274 IF p_line_rec.source_type_code = 'EXTERNAL' THEN
6275 BEGIN
6276 --following line added for bug 3712551
6277 IF(p_line_rec.actual_shipment_date is null) THEN
6278 SELECT nvl ( max ( transaction_date ) , sysdate )
6279 INTO p_x_interface_line_rec.ship_date_actual
6280 FROM rcv_transactions t , oe_drop_ship_sources s
6281 WHERE t.po_header_id = s.po_header_id
6282 AND t.po_line_location_id = s.line_location_id
6283 AND transaction_type = 'RECEIVE'
6284 AND s.line_id = p_line_rec.line_id;
6285 ELSE
6286 --following line added for bug 3712551
6287 p_x_interface_line_rec.ship_date_actual := p_line_rec.actual_shipment_date;
6288 END IF;
6289
6290 EXCEPTION
6291 WHEN OTHERS THEN
6292 IF l_debug_level > 0 THEN
6293 oe_debug_pub.add( 'SETTING SHIP_DATE_ACTUAL FOR DROPSHIP LINE TO SYSDATE' , 5 ) ;
6294 END IF;
6295 p_x_interface_line_rec.ship_date_actual := sysdate;
6296 END;
6297 IF l_debug_level > 0 THEN
6298 oe_debug_pub.add( 'SHIP_DATE_ACTUAL FOR DROPSHIP LINE: '|| TO_CHAR ( P_X_INTERFACE_LINE_REC.SHIP_DATE_ACTUAL , 'DD-MON-YYYY HH24:MI:SS' ) , 5 ) ;
6299 END IF;
6300 END IF;
6301
6302 -- Get information into p_x_interface_line_rec
6303 p_x_interface_line_rec.CREATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
6304 p_x_interface_line_rec.CREATION_DATE := sysdate;
6305 p_x_interface_line_rec.LAST_UPDATED_BY := NVL(oe_standard_wf.g_user_id, fnd_global.user_id); -- 3169637
6306 p_x_interface_line_rec.LAST_UPDATE_DATE := sysdate;
6307 -- bug 8494362 start
6308 --p_x_interface_line_rec.INTERFACE_LINE_CONTEXT := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
6309
6310 l_cur_user_id := fnd_global.user_id;
6311 l_cur_resp_id := fnd_global.RESP_ID;
6312 l_cur_appl_id := fnd_global.RESP_APPL_ID;
6313
6314
6315
6316 p_x_interface_line_rec.INTERFACE_LINE_CONTEXT := fnd_profile.value_specific('ONT_SOURCE_CODE',l_cur_user_id,l_cur_resp_id,l_cur_appl_id,null,null);
6317
6318 oe_debug_pub.add('After Value Specific -' || p_x_interface_line_rec.INTERFACE_LINE_CONTEXT , 1 ) ;
6319
6320 -- bug 8494362 end
6321 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1 := to_char(p_header_rec.order_number);
6322
6323 SELECT tt.name
6324 INTO p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2
6325 FROM oe_transaction_types_tl tt,
6326 oe_order_headers oh
6327 WHERE tt.language = ( select language_code
6328 from fnd_languages
6329 where installed_flag = 'B')
6330 AND tt.transaction_type_id = oh.order_type_id
6331 AND oh.header_id = p_line_rec.header_id;
6332 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE6 := to_char(p_line_rec.line_id);
6333 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7 := '0'; -- picking_line_id
6334 --rt{ Retrobilling change
6335 /*IF (p_line_rec.line_category_code = 'RETURN'
6336 and p_line_rec.reference_line_id is not null
6337 and p_line_rec.retrobill_request_id is not null) THEN
6338 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5 := p_line_rec.retrobill_request_id;
6339 END IF;*/
6340 --rt} End Retrobilling change
6341
6342
6343 IF p_line_rec.invoiced_quantity IS NOT NULL THEN
6344 IF l_debug_level > 0 THEN
6345 oe_debug_pub.add( 'THIS LINE WAS INTERFACED ATLEAST ONCE BEFORE' , 5 ) ;
6346 END IF;
6347 SELECT count(*)
6348 INTO l_count1
6349 FROM ra_interface_lines_all
6350 WHERE interface_line_context = 'ORDER ENTRY'
6351 AND interface_line_attribute1 = p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1
6352 AND interface_line_attribute2 = p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2
6353 AND interface_line_attribute6= to_char(p_line_rec.line_id)
6354 AND interface_line_attribute11 = '0'
6355 AND NVL(interface_status, '~') <> 'P';
6356 SELECT count(*)
6357 INTO l_count2
6358 FROM ra_customer_trx_lines_all
6359 WHERE interface_line_context = 'ORDER ENTRY'
6360 AND interface_line_attribute1 = p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1
6361 AND interface_line_attribute2 = p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE2
6362 AND interface_line_attribute6= to_char(p_line_rec.line_id)
6363 AND interface_line_attribute11 = '0'
6364 AND sales_order = p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE1;
6365 END IF;
6366 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5 := l_count1 + l_count2 ; -- no of times this line is interfaced to AR
6367 IF l_debug_level > 0 THEN
6368 oe_debug_pub.add( 'INTERFACE_LINE_ATTRIBUTE5: '|| P_X_INTERFACE_LINE_REC.INTERFACE_LINE_ATTRIBUTE5 , 5 ) ;
6369 END IF;
6370
6371 --rt{ Retrobilling change
6372 IF (p_line_rec.line_category_code = 'RETURN'
6373 and p_line_rec.reference_line_id is not null
6374 and p_line_rec.retrobill_request_id is not null) THEN
6375 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE5 := p_line_rec.retrobill_request_id;
6376 END IF;
6377 --rt} End Retrobilling change
6378
6379 IF NVL(p_line_rec.item_identifier_type, 'INT') = 'CUST' THEN
6380 BEGIN
6381 SELECT customer_item_number
6382 INTO p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9
6383 FROM mtl_customer_items citems
6384 WHERE customer_item_id = p_line_rec.ordered_item_id;
6385 EXCEPTION
6386 WHEN OTHERS THEN
6387 IF l_debug_level > 0 THEN
6388 oe_debug_pub.add( 'EXCEPTION , POPULATING ATTRIBUTE9 AS 0 =>'||SQLERRM , 1 ) ;
6389 END IF;
6390 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9 := '0';
6391 END;
6392 IF l_debug_level > 0 THEN
6393 oe_debug_pub.add( 'GETTING CUSTOMER ITEM NUMBER: '|| P_X_INTERFACE_LINE_REC.INTERFACE_LINE_ATTRIBUTE9 ) ;
6394 END IF;
6395 ELSE
6396 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE9 := '0';
6397 END IF;
6398 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE10 := nvl(to_char(p_line_rec.ship_from_org_id), '0');
6399 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE11 := '0';
6400 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE12 := lpad(to_char(nvl(p_line_rec.Shipment_Number,0)),30);
6401 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE13 := lpad(to_char(nvl(p_line_rec.Option_Number,0)),30);
6402 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE14 := lpad(to_char(nvl(p_line_rec.Service_Number,0)),30);
6403 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE15 := NULL;
6404 p_x_interface_line_rec.SET_OF_BOOKS_ID := oe_sys_parameters.value('SET_OF_BOOKS_ID', p_line_rec.org_id);
6405 p_x_interface_line_rec.LINE_TYPE := 'LINE';
6406 p_x_interface_line_rec.WAREHOUSE_ID := p_line_rec.ship_from_org_id;
6407
6408 /* If the Line is of OTA type, then we need to call an OTA API to get the */
6409 /* concaternated string for item description */
6410
6411 IF p_line_rec.order_quantity_uom in ('EVT','ENR') THEN
6412 IF l_debug_level > 0 THEN
6413 oe_debug_pub.add( 'GETTING THE OTA DESCRIPTION' , 5 ) ;
6414 END IF;
6415
6416 IF p_line_rec.line_category_code = 'RETURN' and
6417 p_line_rec.reference_line_id is not null then
6418
6419 IF l_debug_level > 0 THEN
6420 oe_debug_pub.add( 'GETTING THE OTA DESCRIPTION FOR RETURN' , 5 ) ;
6421 END IF;
6422
6423 OE_OTA_UTIL.Get_OTA_Description
6424 (p_line_id => p_line_rec.reference_line_id
6425 ,p_uom => p_line_rec.order_quantity_uom
6426 ,x_description => l_item_description
6427 ,x_course_end_date => l_course_end_date
6428 ,x_return_status => l_return_status
6429 );
6430 p_x_interface_line_rec.DESCRIPTION := l_item_description;
6431 IF l_debug_level > 0 THEN
6432 oe_debug_pub.add( 'OTA DESCRIPTION' || L_ITEM_DESCRIPTION , 5 ) ;
6433 END IF;
6434 p_x_interface_line_rec.GL_DATE := l_course_end_date;
6435
6436 ELSE
6437
6438 OE_OTA_UTIL.Get_OTA_Description
6439 (p_line_id => p_line_rec.line_id
6440 ,p_uom => p_line_rec.order_quantity_uom
6441 ,x_description => l_item_description
6442 ,x_course_end_date => l_course_end_date
6443 ,x_return_status => l_return_status
6444 );
6445 p_x_interface_line_rec.DESCRIPTION := l_item_description;
6446 IF l_debug_level > 0 THEN
6447 oe_debug_pub.add( 'OTA DESCRIPTION' || L_ITEM_DESCRIPTION , 5 ) ;
6448 END IF;
6449 p_x_interface_line_rec.GL_DATE := l_course_end_date;
6450
6451 END IF;
6452 ELSE
6453 IF p_line_rec.item_type_code = 'SERVICE' THEN
6454 Get_Service_Item_Description(p_line_rec, p_x_interface_line_rec.DESCRIPTION);
6455 ELSE
6456 Get_Item_Description(p_line_rec, p_x_interface_line_rec.DESCRIPTION);
6457 END IF;
6458
6459 END IF;
6460
6461 -- bug 2509121.
6462 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509'
6463 AND p_line_rec.user_item_description IS NOT NULL
6464 AND p_line_rec.user_item_description <> FND_API.G_MISS_CHAR THEN
6465 p_x_interface_line_rec.translated_description := p_line_rec.user_item_description;
6466 END IF;
6467
6468 -- Commenting if condition for bug# 4063920
6469 --IF p_x_interface_line_rec.CURRENCY_CODE IS NULL THEN
6470 p_x_interface_line_rec.CURRENCY_CODE := p_header_rec.transactional_curr_code;
6471 --END IF;
6472 IF p_line_rec.Commitment_Id IS NOT NULL THEN
6473 IF l_debug_level > 0 THEN
6474 oe_debug_pub.add( 'GETTING CUST_TRX_TYPE_ID FROM COMMITMENT: '||P_LINE_REC.COMMITMENT_ID , 5 ) ;
6475 END IF;
6476 SELECT NVL(cust_type.subsequent_trx_type_id,cust_type.cust_trx_type_id)
6477 INTO p_x_interface_line_rec.Cust_Trx_Type_Id
6478 FROM ra_cust_trx_types cust_type,ra_customer_trx_all cust_trx /* MOAC SQL CHANGE */
6479 WHERE cust_type.cust_trx_type_id = cust_trx.cust_trx_type_id
6480 AND cust_trx.customer_trx_id = p_line_rec.Commitment_Id;
6481 IF l_debug_level > 0 THEN
6482 oe_debug_pub.add( 'CUST_TRX_TYPE_ID FROM COMMITMENT IS '||P_X_INTERFACE_LINE_REC.CUST_TRX_TYPE_ID ) ;
6483 END IF;
6484 ELSE
6485 p_x_interface_line_rec.Cust_Trx_Type_Id := Get_Customer_Transaction_Type(p_line_rec);
6486 END IF;
6487 /* START PREPAYMENT */
6488 IF NOT Return_Line(p_line_rec) THEN
6489 IF OE_PrePayment_Util.Is_Prepaid_Order(p_header_rec) = 'Y' THEN
6490 -- p_x_interface_line_rec.Term_Id := p_header_rec.payment_term_id;
6491 IF l_debug_level > 0 THEN
6492 oe_debug_pub.add( 'GETTING PAYMENT_SET_ID FROM OE_PAYMENTS' ) ;
6493 END IF;
6494 BEGIN
6495 --serla begin
6496 IF OE_PrePayment_UTIL.IS_MULTIPLE_PAYMENTS_ENABLED THEN
6497 SELECT payment_set_id
6498 INTO p_x_interface_line_rec.Payment_Set_ID
6499 FROM oe_payments
6500 WHERE header_id = p_line_rec.header_id
6501 AND payment_set_id IS NOT NULL
6502 AND rownum=1;
6503 ELSE
6504 --serla end
6505 SELECT payment_set_id
6506 INTO p_x_interface_line_rec.Payment_Set_ID
6507 FROM oe_payments
6508 WHERE header_id = p_line_rec.header_id
6509 AND line_id is null
6510 AND payment_type_code = 'CREDIT_CARD';
6511 --serla begin
6512 END IF;
6513 --serla end
6514 EXCEPTION
6515 WHEN NO_DATA_FOUND THEN
6516 p_x_interface_line_rec.Payment_Set_ID := NULL;
6517 WHEN TOO_MANY_ROWS THEN
6518 p_x_interface_line_rec.Payment_Set_ID := NULL;
6519 END;
6520 IF l_debug_level > 0 THEN
6521 oe_debug_pub.add( 'AFTER GETTING PAYMENT_SET_ID: '||P_X_INTERFACE_LINE_REC.PAYMENT_SET_ID ) ;
6522 END IF;
6523 p_x_interface_line_rec.approval_code := NULL;
6524 -- ELSE
6525 -- p_x_interface_line_rec.Term_Id := p_line_rec.payment_term_id;
6526 END IF;
6527 p_x_interface_line_rec.Term_Id := p_line_rec.payment_term_id;
6528 END IF;
6529 /* END PREPAYMENT */
6530 Get_Qty_To_Invoice(p_line_rec, p_x_interface_line_rec.QUANTITY, x_result_code);
6531 -- sol_ord_er #16014165
6532 IF l_debug_level > 0 THEN
6533 oe_debug_pub.add( 'Service Billing Option: '||p_line_rec.service_bill_option_code , 5 ) ;
6534 END IF;
6535 -- sol_ord_er #16014165
6536 IF OE_Commitment_Pvt.DO_Commitment_Sequencing THEN-- commitment sequencing functionality ON
6537 IF p_line_rec.commitment_id IS NOT NULL THEN
6538 Get_Commitment_Info(p_line_rec
6539 ,l_commitment_applied
6540 ,l_commitment_interfaced);
6541 IF x_result_code = 'RFR-PENDING' THEN
6542 IF l_debug_level > 0 THEN
6543 oe_debug_pub.add( 'GET PARTIAL PROMISED AMOUNT FOR PARTIALLY INVOICED LINE' , 5 ) ;
6544 END IF;
6545 Rounded_Amount(p_currency_code => p_x_interface_line_rec.currency_code
6546 ,p_unrounded_amount => (p_line_rec.unit_selling_price * p_x_interface_line_rec.quantity)
6547 ,x_rounded_amount => l_partial_line_amount);
6548 IF OE_COMMITMENT_PVT.Get_Allocate_Tax_Freight(p_line_rec) = 'Y' THEN
6549 l_fulfilled_qty := NVL(p_line_rec.fulfilled_quantity, NVL(p_line_rec.shipped_quantity, NVL(p_line_rec.ordered_quantity, 0)));
6550 l_partial_line_tax_amount := nvl(p_line_rec.tax_value * (p_x_interface_line_rec.QUANTITY/l_fulfilled_qty), 0);
6551 SELECT nvl(sum(charge_amount), 0)
6552 INTO l_partial_line_freight_amount
6553 FROM oe_charge_lines_v
6554 WHERE header_id = p_line_rec.header_id
6555 AND line_id = p_line_rec.line_id
6556 AND nvl(invoiced_flag, 'N') = 'N';
6557 END IF;
6558
6559 IF l_debug_level > 0 THEN
6560 oe_debug_pub.add( 'PARTIAL LINE AMOUNT '||L_PARTIAL_LINE_AMOUNT||' - PARTIAL TAX AMOUNT '||L_PARTIAL_LINE_TAX_AMOUNT||' - PARTIAL LINE FREIGHT AMOUNT '||L_PARTIAL_LINE_FREIGHT_AMOUNT , 5 ) ;
6561 END IF;
6562 l_partial_line_promised_amount := l_partial_line_amount + l_partial_line_tax_amount + l_partial_line_freight_amount;
6563 IF (l_commitment_applied-l_commitment_interfaced) >= l_partial_line_promised_amount THEN
6564 p_x_interface_line_rec.promised_commitment_amount := l_partial_line_promised_amount;
6565 IF l_debug_level > 0 THEN
6566 oe_debug_pub.add( 'RFR- PASS FULL AMOUNT FOR THIS INTERFACE: '|| P_X_INTERFACE_LINE_REC.PROMISED_COMMITMENT_AMOUNT , 3 ) ;
6567 END IF;
6568 ELSE
6569 p_x_interface_line_rec.promised_commitment_amount := l_commitment_applied-l_commitment_interfaced;
6570 IF l_debug_level > 0 THEN
6571 oe_debug_pub.add( 'PASS PARTIAL AMOUNT FOR THIS INTERFACE: ' ||P_X_INTERFACE_LINE_REC.PROMISED_COMMITMENT_AMOUNT , 3 ) ;
6572 END IF;
6573 END IF;
6574 ELSE
6575 p_x_interface_line_rec.PROMISED_COMMITMENT_AMOUNT := l_commitment_applied-l_commitment_interfaced;
6576 IF l_debug_level > 0 THEN
6577 oe_debug_pub.add( 'NOT RFR- PROMISED_COMMITMENT_AMOUNT: '|| P_X_INTERFACE_LINE_REC.PROMISED_COMMITMENT_AMOUNT ) ;
6578 END IF;
6579 END IF;
6580 END IF;
6581 END IF; -- end of commitment sequencing functionality ON
6582 p_x_interface_line_rec.Unit_Standard_Price := p_line_rec.Unit_List_Price;
6583 IF Show_Detail_Discounts(p_line_rec) THEN
6584 -- If we show detail discounts, original line selling and extended amounts should not include discount amount.
6585 p_x_interface_line_rec.Unit_Selling_Price := p_line_rec.Unit_List_Price;
6586 Rounded_Amount(p_currency_code => p_x_interface_line_rec.currency_code
6587 ,p_unrounded_amount => (p_line_rec.unit_list_price * p_x_interface_line_rec.quantity)
6588 ,x_rounded_amount => p_x_interface_line_rec.amount);
6589 ELSE
6590 If NVL(p_line_rec.service_bill_option_code,'FBOM')='FBOM' THEN -- sol_ord_er #16014165
6591 p_x_interface_line_rec.Unit_Selling_Price := p_line_rec.Unit_Selling_Price;
6592 l_unround_amt := (p_line_rec.unit_selling_price * p_x_interface_line_rec.quantity);
6593 -- sol_ord_er #16014165
6594 elsif p_line_rec.service_bill_option_code = 'FPOM' THEN
6595 p_x_interface_line_rec.Unit_Selling_Price := '';
6596 l_unround_amt := p_line_rec.service_first_period_amount;
6597 p_x_interface_line_rec.Unit_Standard_Price := '';
6598 end if;
6599 -- sol_ord_er #16014165 end
6600 Rounded_Amount(p_currency_code => p_x_interface_line_rec.currency_code
6601 -- ,p_unrounded_amount => (p_line_rec.unit_selling_price * p_x_interface_line_rec.quantity)--sol_ord_er #16014165
6602 ,p_unrounded_amount => l_unround_amt
6603 ,x_rounded_amount => p_x_interface_line_rec.amount);
6604 END IF;
6605 p_x_interface_line_rec.Quantity_Ordered := p_line_rec.Ordered_Quantity;
6606 -- Get Creation_sign
6607 l_creation_sign := Get_Credit_Creation_Sign(p_line_rec, p_x_interface_line_rec.cust_trx_type_id);
6608 IF l_debug_level > 0 THEN
6609 oe_debug_pub.add( ' CREATION SIGN IS '|| L_CREATION_SIGN , 5 ) ;
6610 END IF;
6611
6612 IF l_creation_sign = 'A' THEN
6613 IF Return_Line(p_line_rec) THEN
6614 IF l_debug_level > 0 THEN
6615 oe_debug_pub.add( 'SETTING -VE SIGN FOR RETURN LINE' , 5 ) ;
6616 END IF;
6617 p_x_interface_line_rec.Amount := p_x_interface_line_rec.amount * -1;
6618 p_x_interface_line_rec.Quantity := p_x_interface_line_rec.Quantity * -1;
6619 p_x_interface_line_rec.Quantity_Ordered := p_line_rec.Ordered_Quantity * -1;
6620 END IF;
6621 ELSIF l_creation_sign = 'P' THEN
6622 NULL;
6623 ELSIF l_creation_sign = 'N' THEN
6624 p_x_interface_line_rec.Amount := p_x_interface_line_rec.amount * -1;
6625 p_x_interface_line_rec.Quantity := p_x_interface_line_rec.Quantity * -1;
6626 p_x_interface_line_rec.Quantity_Ordered := p_line_rec.Ordered_Quantity * -1;
6627 END IF;
6628
6629 IF l_debug_level > 0 THEN
6630 oe_debug_pub.add( 'LINE UNIT SELLING PRICE: '||P_X_INTERFACE_LINE_REC.UNIT_SELLING_PRICE , 5 ) ;
6631 oe_debug_pub.add( 'LINE UNIT STANDARD PRICE: '||P_X_INTERFACE_LINE_REC.UNIT_STANDARD_PRICE , 5 ) ;
6632 oe_debug_pub.add( 'LINE AMOUNT: '||P_X_INTERFACE_LINE_REC.AMOUNT ) ;
6633 END IF;
6634
6635 -- invoice_to_org_id is required at booking
6636 IF p_line_rec.invoice_to_org_id IS NOT NULL THEN
6637 IF l_debug_level > 0 THEN
6638 oe_debug_pub.add( 'GETTING ORIG_SYSTEM_BILL_CUSTOMER_ID , ORIG_SYSTEM_BILL_ADDRESS_ID INFO' , 5 ) ;
6639 END IF;
6640 BEGIN
6641 /* Commented for bug #3519137 added new select statement */
6642 /*SELECT bill_to_org.customer_id
6643 ,bill_to_org.address_id
6644 INTO p_x_interface_line_rec.ORIG_SYSTEM_BILL_CUSTOMER_ID
6645 ,p_x_interface_line_rec.ORIG_SYSTEM_BILL_ADDRESS_ID
6646 FROM oe_invoice_to_orgs_v bill_to_org
6647 WHERE bill_to_org.organization_id = p_line_rec.invoice_to_org_id;*/
6648
6649 SELECT acct_site.cust_account_id, site.cust_acct_site_id
6650 INTO p_x_interface_line_rec.ORIG_SYSTEM_BILL_CUSTOMER_ID
6651 ,p_x_interface_line_rec.ORIG_SYSTEM_BILL_ADDRESS_ID
6652 FROM hz_cust_acct_sites_all acct_site, hz_cust_site_uses_all site
6653 WHERE SITE.SITE_USE_CODE = 'BILL_TO'
6654 AND SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
6655 AND SITE.SITE_USE_ID = p_line_rec.invoice_to_org_id;
6656
6657 EXCEPTION
6658 WHEN OTHERS THEN
6659 IF l_debug_level > 0 THEN
6660 oe_debug_pub.add( 'EXCEPTION , '||SQLERRM , 1 ) ;
6661 END IF;
6662 p_x_interface_line_rec.ORIG_SYSTEM_BILL_CUSTOMER_ID := NULL;
6663 p_x_interface_line_rec.ORIG_SYSTEM_BILL_ADDRESS_ID := NULL;
6664 END;
6665 END IF;
6666 -- ship_to_org_id is not required at booking for return lines
6667 IF p_line_rec.ship_to_org_id IS NOT NULL THEN
6668 IF l_debug_level > 0 THEN
6669 oe_debug_pub.add( 'GETTING ORIG_SYSTEM_SHIP_CUSTOMER_ID , ORIG_SYSTEM_SHIP_ADDRESS_ID INFO' ) ;
6670 END IF;
6671 BEGIN
6672 /* Commented for bug #3519137 added new select statement */
6673 /*SELECT ship_to_org.customer_id
6674 ,ship_to_org.address_id
6675 INTO p_x_interface_line_rec.ORIG_SYSTEM_SHIP_CUSTOMER_ID
6676 ,l_orig_sys_ship_addr_id
6677 FROM oe_ship_to_orgs_v ship_to_org
6678 WHERE ship_to_org.organization_id = p_line_rec.ship_to_org_id;*/
6679
6680 SELECT acct_site.cust_account_id, site.cust_acct_site_id
6681 INTO p_x_interface_line_rec.ORIG_SYSTEM_SHIP_CUSTOMER_ID
6682 ,l_orig_sys_ship_addr_id
6683 FROM hz_cust_acct_sites_all acct_site, hz_cust_site_uses_all site
6684 WHERE SITE.SITE_USE_CODE = 'SHIP_TO'
6685 AND SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
6686 AND SITE.SITE_USE_ID = p_line_rec.ship_to_org_id;
6687
6688 EXCEPTION
6689 WHEN OTHERS THEN
6690 IF l_debug_level > 0 THEN
6691 oe_debug_pub.add( 'EXCEPTION , '||SQLERRM , 1 ) ;
6692 END IF;
6693 p_x_interface_line_rec.ORIG_SYSTEM_SHIP_CUSTOMER_ID := NULL;
6694 l_orig_sys_ship_addr_id := NULL;
6695 END;
6696 END IF;
6697 p_x_interface_line_rec.orig_system_ship_address_id := nvl(p_x_interface_line_rec.orig_system_ship_address_id, l_orig_sys_ship_addr_id);
6698 p_x_interface_line_rec.orig_system_bill_contact_id := p_line_rec.invoice_to_contact_id;
6699 p_x_interface_line_rec.orig_system_ship_contact_id := p_line_rec.ship_to_contact_id;
6700 p_x_interface_line_rec.orig_system_sold_customer_id := p_line_rec.sold_to_org_id;
6701 p_x_interface_line_rec.conversion_type := NVL(p_header_rec.conversion_type_code, 'User');
6702 p_x_interface_line_rec.conversion_date := p_header_rec.conversion_rate_date;
6703 p_x_interface_line_rec.conversion_rate := p_header_rec.conversion_rate;
6704 IF p_x_interface_line_rec.conversion_rate IS NULL THEN
6705 IF p_x_interface_line_rec.conversion_type = 'User' THEN
6706 p_x_interface_line_rec.conversion_rate := 1;
6707 END IF;
6708 END IF;
6709
6710 IF p_header_rec.conversion_type_code IS NOT NULL THEN
6711 l_set_of_books_rec := OE_Order_Cache.Load_Set_Of_Books;
6712 IF l_debug_level > 0 THEN
6713 oe_debug_pub.add( 'SOB CURRENCY: '||L_SET_OF_BOOKS_REC.CURRENCY_CODE||' TRANSACTIONAL CURRENCY: '||P_HEADER_REC.TRANSACTIONAL_CURR_CODE ) ;
6714 END IF;
6715 IF p_header_rec.transactional_curr_code = l_set_of_books_rec.currency_code THEN
6716 p_x_interface_line_rec.conversion_type := 'User';
6717 p_x_interface_line_rec.conversion_rate := 1;
6718 END IF;
6719 END IF;
6720
6721 p_x_interface_line_rec.Primary_salesrep_Id := NVL(p_line_rec.Salesrep_Id, p_header_rec.Salesrep_Id);
6722 p_x_interface_line_rec.Sales_Order := to_char(p_header_rec.Order_Number);
6723 p_x_interface_line_rec.Sales_Order_Line := to_char(p_line_rec.Line_Number);
6724 p_x_interface_line_rec.Sales_Order_Date := p_header_rec.Ordered_Date;
6725 p_x_interface_line_rec.Sales_Order_Source := FND_PROFILE.VALUE('ONT_SOURCE_CODE');
6726 p_x_interface_line_rec.Agreement_Id := p_line_rec.Agreement_Id;
6727 p_x_interface_line_rec.Purchase_Order := p_line_rec.Cust_PO_Number;
6728 p_x_interface_line_rec.Inventory_Item_Id := p_line_rec.Inventory_Item_Id;
6729
6730 -- Changes for #3144768 begin
6731
6732 BEGIN
6733 SELECT NUMBER_VALUE
6734 INTO l_user_id
6735 FROM WF_ITEM_ATTRIBUTE_VALUES
6736 WHERE ITEM_KEY = to_char(p_line_rec.line_id)
6737 AND ITEM_TYPE = 'OEOL'
6738 AND NAME = 'USER_ID';
6739
6740 SELECT NUMBER_VALUE
6741 INTO l_resp_id
6742 FROM WF_ITEM_ATTRIBUTE_VALUES
6743 WHERE ITEM_KEY = to_char(p_line_rec.line_id)
6744 AND ITEM_TYPE = 'OEOL'
6745 AND NAME = 'RESPONSIBILITY_ID';
6746
6747 SELECT NUMBER_VALUE
6748 INTO l_appl_id
6749 FROM WF_ITEM_ATTRIBUTE_VALUES
6750 WHERE ITEM_KEY = to_char(p_line_rec.line_id)
6751 AND ITEM_TYPE = 'OEOL'
6752 AND NAME = 'APPLICATION_ID';
6753
6754 EXCEPTION WHEN OTHERS THEN
6755 l_user_id := NULL;
6756 l_resp_id := NULL;
6757 l_appl_id := NULL;
6758 OE_DEBUG_PUB.add('Unable to find item attributes while searching for Tax Code profile value : '||sqlerrm,1);
6759 NULL;
6760 END;
6761
6762 OE_DEBUG_PUB.add('Tax code value on the Order Line '||p_line_rec.tax_code,5);
6763 OE_DEBUG_PUB.add('ID => User,Resp,Appl : '||l_user_id||','||l_resp_id||','||l_appl_id,5);
6764
6765 -- 3757279
6766 l_concat_segment := 'u'||l_user_id||'r'||l_resp_id||'a'||l_appl_id;
6767 oe_debug_pub.add('l_concat_segment'||l_concat_segment,1);
6768 l_table_index := FIND(l_concat_segment);
6769 IF l_table_index < TABLE_SIZE THEN
6770 IF l_debug_level > 0 THEN
6771 --oe_debug_pub.add( 'cached FND PROFILE AR_ALLOW_TAX_CODE_OVERRIDE: '||Prf_Tbl(l_table_index).prf_value,1);
6772 oe_debug_pub.add( 'cached FND PROFILE ZX_ALLOW_TAX_CLASSIF_OVERRIDE: '||Prf_Tbl(l_table_index).prf_value,1);
6773 END IF;
6774 l_prof_value := Prf_Tbl(l_table_index).prf_value;
6775 ELSE
6776 put(l_concat_segment,l_user_id,l_resp_id,l_appl_id,l_prof_value);
6777 IF l_debug_level > 0 THEN
6778 --oe_debug_pub.add( ' Uncached first time FND PROFILE AR_ALLOW_TAX_CODE_OVERRIDE: '||l_prof_value,1);
6779 oe_debug_pub.add( ' Uncached first time FND PROFILE ZX_ALLOW_TAX_CLASSIF_OVERRIDE: '||l_prof_value,1);
6780 END IF;
6781 END IF;
6782 -- 3757279
6783
6784 IF NVL(l_prof_value,'N') = 'Y' THEN
6785 p_x_interface_line_rec.Tax_code := p_line_rec.Tax_code;
6786 END IF;
6787 OE_DEBUG_PUB.add('Tax Code interfaced to AR is : '||p_line_rec.Tax_Code,1);
6788
6789 -- Changes for 3144768 End
6790 IF Return_Line(p_line_rec) THEN
6791 IF l_debug_level > 0 THEN
6792 oe_debug_pub.add( 'SETTING INFORMATION FOR RETURN LINE' , 5 ) ;
6793 END IF;
6794 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3 := '0';
6795 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE4 := '0';
6796 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE7 := '0';
6797 p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE8 := '0';
6798 p_x_interface_line_rec.Reason_Code := p_line_rec.Return_Reason_Code;
6799 --Bug2302812.Commented the procedure "Get_Received_Status" and in turn we get the
6800 --Receipt date from "RCV_TRANSACTIONS".
6801 /* OE_LINE_STATUS_PUB.Get_Received_Status(p_line_id => p_line_rec.line_id, x_result=>l_rma_result, x_result_date=>l_rma_date);*/
6802 --Bug2758528-Added a check for 'RECEIVE' Transaction type.
6803
6804 -- With the new fix we are populating the actual_shipment_date for RMAs.
6805 -- But for old RMAs it may be still NULL, hence adding this logic
6806 -- to avoid the data upgrade impact for open RMA lines.
6807
6808 IF p_line_rec.actual_shipment_date IS NULL THEN
6809 SELECT max ( transaction_date ) -- Bug#3343004
6810 INTO l_rma_date
6811 FROM rcv_transactions
6812 WHERE transaction_type IN ('RECEIVE','UNORDERED')
6813 AND oe_order_line_id = p_line_rec.line_id;
6814
6815 p_x_interface_line_rec.Ship_Date_Actual := l_rma_date;
6816
6817 ELSE
6818 p_x_interface_line_rec.Ship_Date_Actual :=
6819 p_line_rec.actual_shipment_date;
6820 END IF;
6821
6822 IF p_x_interface_line_rec.Ship_Date_Actual is NULL THEN
6823 IF (fnd_profile.value('OE_RECEIVABLES_DATE_FOR_NONSHIP_LINES') = 'Y')
6824 THEN
6825 p_x_interface_line_rec.Ship_Date_Actual := SYSDATE;
6826 END IF;
6827 END IF;
6828
6829 --p_x_interface_line_rec.Ship_Date_Actual := l_rma_date;
6830 p_x_interface_line_rec.Fob_Point := NULL;
6831 p_x_interface_line_rec.Ship_Via := NULL;
6832 p_x_interface_line_rec.Waybill_Number := NULL;
6833 p_x_interface_line_rec.Reference_Line_Id := p_line_rec.Credit_Invoice_Line_Id;
6834 p_x_interface_line_rec.Accounting_Rule_Id := NULL;
6835 p_x_interface_line_rec.Invoicing_Rule_Id := NULL;
6836 p_x_interface_line_rec.Term_Id := NULL;
6837 --bug 6324173, populate credit method only if referenced invoice has accounting rule
6838 IF p_x_interface_line_rec.Reference_Line_Id is NOT NULL THEN
6839 select ACCOUNTING_RULE_ID INTO L_ACCOUNTING_RULE_ID from RA_CUSTOMER_TRX_LINES_all
6840 where CUSTOMER_TRX_LINE_ID= p_x_interface_line_rec.Reference_Line_Id;
6841 IF L_ACCOUNTING_RULE_ID is NOT NULL THEN
6842 Get_Credit_Method_Code(p_line_rec
6843 ,p_x_interface_line_rec.Credit_Method_For_Acct_Rule
6844 ,p_x_interface_line_rec.Credit_Method_For_Installments);
6845 END IF;
6846 END IF;
6847 ELSE
6848 p_x_interface_line_rec.Reason_Code := NULL;
6849 p_x_interface_line_rec.Ship_Date_Actual := NVL(p_x_interface_line_rec.Ship_Date_Actual, p_line_rec.actual_shipment_date);
6850 p_x_interface_line_rec.Fob_Point := p_line_rec.fob_point_code;
6851 p_x_interface_line_rec.Waybill_Number := p_x_interface_line_rec.Interface_line_Attribute4;
6852 -- p_x_interface_line_rec.Ship_Via := NVL(p_x_interface_line_rec.Ship_Via, p_line_rec.freight_carrier_code); -- Should it be shipping_method_code???
6853 IF p_line_rec.Commitment_Id IS NOT NULL THEN
6854 IF l_debug_level > 0 THEN
6855 oe_debug_pub.add( 'REFERENCE_LINE_ID FROM COMMITMENT ID IS '||P_LINE_REC.COMMITMENT_ID ) ;
6856 END IF;
6857 SELECT customer_trx_line_id
6858 INTO p_x_interface_line_rec.Reference_Line_Id
6859 FROM ra_customer_trx_lines_all
6860 WHERE customer_trx_id = p_line_rec.Commitment_Id;
6861 -- p_x_interface_line_rec.Cust_Trx_Type_Id := NULL; -- bug 4744262
6862 END IF;
6863 IF /*p_line_rec.accounting_rule_id = 1 or*/ p_line_rec.accounting_rule_id is NULL THEN--Bug 5730802
6864 p_x_interface_line_rec.accounting_rule_id := NULL;
6865 p_x_interface_line_rec.invoicing_rule_id := NULL;
6866 ELSE
6867 p_x_interface_line_rec.accounting_rule_id := p_line_rec.accounting_rule_id;
6868 p_x_interface_line_rec.invoicing_rule_id := p_line_rec.invoicing_rule_id;
6869 END IF;
6870 END IF;
6871 -- This may be a temporary fix for bug# 1386715.
6872 -- need to understand if we need to convert duration into different unit
6873 -- Right now, it is in units of Months.
6874 -- But, Autoinvoice uses accounting rule's period.
6875 IF NOT Return_Line(p_line_rec) AND p_x_interface_line_rec.accounting_rule_id IS NOT NULL THEN
6876 IF l_debug_level > 0 THEN
6877 oe_debug_pub.add( 'GET ACCOUNTING RULE TYPE ' , 5 ) ;
6878 END IF;
6879 --Modified for bug#4190312
6880 SELECT type,frequency
6881 INTO l_accounting_rule_type, l_frequency
6882 FROM ra_rules
6883 WHERE rule_id = p_x_interface_line_rec.accounting_rule_id;
6884 IF l_accounting_rule_type = 'ACC_DUR' THEN
6885 -- accounting rule duration is required for regular (non service) lines at booking
6886 IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110509' THEN
6887 IF l_debug_level > 0 THEN
6888 oe_debug_pub.add( 'INTERFACING ACCOUNTING_RULE_DURATION FOR REGULAR LINES:'|| P_LINE_REC.ACCOUNTING_RULE_DURATION ) ;
6889 END IF;
6890 p_x_interface_line_rec.ACCOUNTING_RULE_DURATION := p_line_rec.accounting_rule_duration;
6891 ELSE
6892 IF l_debug_level > 0 THEN
6893 oe_debug_pub.add( 'BELOW PACK I , DO NOT INTERFACE DURATION' ) ;
6894 END IF;
6895 p_x_interface_line_rec.ACCOUNTING_RULE_DURATION := NULL;
6896 END IF;
6897 IF p_line_rec.item_type_code = 'SERVICE' THEN
6898 p_x_interface_line_rec.rule_start_date := p_line_rec.service_start_date; -- 1833680
6899 --PP Revenue Recognition
6900 --bug 4893057
6901 --Need to pass the rule end date for partial revenue recognition enhancement
6902 --bug 5608550 Commenting the code since we are in 'Variable schedule' ie 'ACC_DUR'
6903 --p_x_interface_line_rec.rule_end_date := p_line_rec.service_end_date;
6904 IF p_x_interface_line_rec.accounting_rule_duration IS NULL THEN
6905 IF p_line_rec.service_start_date IS NULL OR p_line_rec.service_end_date IS NULL THEN
6906 -- bug# 4190312 post message and complete with status INCOMPLETE
6907 FND_MESSAGE.SET_NAME('ONT','OE_INVALID_ACCT_RULE_DURATION');
6908 OE_MSG_PUB.ADD;
6909 IF l_debug_level > 0 THEN
6910 oe_debug_pub.add( 'SERVICE START DATE OR SERVICE END DATE IS NULL' , 3 ) ;
6911 END IF;
6912 p_x_interface_line_rec.ACCOUNTING_RULE_DURATION := -1;
6913 ELSE
6914 BEGIN
6915 --Modified for bug#4190312
6916 /*
6917 l_acct_rule_duration := ceil(OKS_TIME_MEASURES_PUB.GET_QUANTITY(
6918 p_start_date => p_line_rec.service_start_date
6919 ,p_end_date => p_line_rec.service_end_date));
6920 */
6921
6922 SELECT period_set_name
6923 INTO l_calendar_name
6924 FROM gl_sets_of_books
6925 WHERE set_of_books_id = p_x_interface_line_rec.SET_OF_BOOKS_ID;
6926
6927 -- sol_ord_er #16014165
6928 IF l_debug_level > 0 THEN
6929 oe_debug_pub.add( 'SK_OEXPINVB Before act rule duration SFPED= '
6930 ||p_line_rec.service_first_period_enddate , 3 ) ;
6931 END IF;
6932 -- sol_ord_er #16014165
6933
6934 GL_CALENDAR_PKG.get_num_periods_in_date_range(
6935 calendar_name => l_calendar_name,
6936 period_type => l_frequency,
6937 start_date => p_line_rec.service_start_date,
6938 --end_date => p_line_rec.service_end_date, -- sol_ord_er #16014165
6939 end_date => NVL(p_line_rec.service_first_period_enddate,p_line_rec.service_end_date),
6940 check_missing => TRUE,
6941 num_periods => l_acct_rule_duration,
6942 return_code => l_return_code,
6943 unmapped_date => l_unmapped_date);
6944
6945 IF l_debug_level > 0 THEN
6946 oe_debug_pub.add('l_acct_rule_duration:'||l_acct_rule_duration);
6947 oe_debug_pub.add('l_return_code:'||l_return_code);
6948 oe_debug_pub.add('l_unmapped_date:'||l_unmapped_date);
6949 END IF;
6950 IF l_return_code = 'SUCCESS' THEN
6951 p_x_interface_line_rec.ACCOUNTING_RULE_DURATION := l_acct_rule_duration;
6952 ELSE
6953 p_x_interface_line_rec.ACCOUNTING_RULE_DURATION := -1;
6954 -- post message
6955 FND_MESSAGE.SET_NAME('ONT','ONT_GL_UNMAPPED_DATES');
6956 FND_MESSAGE.SET_TOKEN('START_DATE', p_line_rec.service_start_date);
6957 --FND_MESSAGE.SET_TOKEN('END_DATE', p_line_rec.service_end_date); -- sol_ord_er #16014165
6958 FND_MESSAGE.SET_TOKEN('END_DATE', NVL(p_line_rec.service_first_period_enddate,p_line_rec.service_end_date));
6959 FND_MESSAGE.SET_TOKEN('CALENDAR_NAME', l_calendar_name);
6960 OE_MSG_PUB.ADD;
6961 IF l_debug_level > 0 THEN
6962 oe_debug_pub.add('Atleast one or more dates ('||l_unmapped_date||') within the date range that are not associated with any adjustment period.');
6963 END IF;
6964 END IF;
6965 EXCEPTION
6966 WHEN OTHERS THEN
6967 p_x_interface_line_rec.ACCOUNTING_RULE_DURATION := -1;
6968 -- Modified for bug# 4190312
6969 FND_MESSAGE.SET_NAME('ONT','ONT_GL_UNMAPPED_DATES');
6970 FND_MESSAGE.SET_TOKEN('START_DATE', p_line_rec.service_start_date);
6971 --FND_MESSAGE.SET_TOKEN('END_DATE', p_line_rec.service_end_date); -- sol_ord_er #16014165
6972 FND_MESSAGE.SET_TOKEN('END_DATE', NVL(p_line_rec.service_first_period_enddate,p_line_rec.service_end_date));
6973 FND_MESSAGE.SET_TOKEN('CALENDAR_NAME', l_calendar_name);
6974 OE_MSG_PUB.ADD;
6975 IF l_debug_level > 0 THEN
6976 oe_debug_pub.add( 'ERROR IN GL_CALENDAR_PKG.Get_Num_Periods_In_Date_Range ; ERROR => '||SQLERRM , 1 ) ;
6977 END IF;
6978 END;
6979 END IF; -- end of service service start/end dates
6980 END IF; -- null accounting_rule_duaration
6981 END IF; --service line
6982 ELSE -- fixed accounting rule
6983 -- Pass rule_start_date for service lines for fixed rules also (as it was before change for variable accounting rules)
6984 IF p_line_rec.item_type_code = 'SERVICE'
6985 OR (l_accounting_rule_type = 'PP_DR_ALL' OR l_accounting_rule_type = 'PP_DR_PP')THEN -- webroot bug 6826344 modified the contition
6986 oe_debug_pub.add( 'Start date assigned: l_accounting_rule_type: ' || l_accounting_rule_type) ;
6987 p_x_interface_line_rec.rule_start_date := p_line_rec.service_start_date; -- 1833680
6988 --PP Revenue Recognition
6989 --bug 4893057
6990 --Need to pass the rule end date for partial revenue recognition enhancement
6991 --bug 5608550 Need to pass the rule end date ONLY for partial revenue recognition
6992 IF ((l_accounting_rule_type = 'PP_DR_ALL') OR (l_accounting_rule_type = 'PP_DR_PP')) THEN
6993
6994 oe_debug_pub.add( 'End date assigned: l_accounting_rule_type: ' || l_accounting_rule_type) ;
6995 --p_x_interface_line_rec.rule_end_date := p_line_rec.service_end_date; -- sol_ord_er #16014165
6996 p_x_interface_line_rec.rule_end_date := NVL(p_line_rec.service_first_period_enddate,p_line_rec.service_end_date);
6997 END IF;
6998 END IF;
6999 END IF; -- variable/fixed accounting rule
7000 END IF;
7001
7002 IF l_debug_level > 0 THEN
7003 oe_debug_pub.add( 'GET ATTRIBUTE VALUES' , 5 ) ;
7004 END IF;
7005 p_x_interface_line_rec.Attribute_Category := p_line_rec.Context;
7006 p_x_interface_line_rec.Attribute1 := substrb(p_line_rec.Attribute1, 1, 150);
7007 p_x_interface_line_rec.Attribute2 := substrb(p_line_rec.Attribute2, 1, 150);
7008 p_x_interface_line_rec.Attribute3 := substrb(p_line_rec.Attribute3, 1, 150);
7009 p_x_interface_line_rec.Attribute4 := substrb(p_line_rec.Attribute4, 1, 150);
7010 p_x_interface_line_rec.Attribute5 := substrb(p_line_rec.Attribute5, 1, 150);
7011 p_x_interface_line_rec.Attribute6 := substrb(p_line_rec.Attribute6, 1, 150);
7012 p_x_interface_line_rec.Attribute7 := substrb(p_line_rec.Attribute7, 1, 150);
7013 p_x_interface_line_rec.Attribute8 := substrb(p_line_rec.Attribute8, 1, 150);
7014 p_x_interface_line_rec.Attribute9 := substrb(p_line_rec.Attribute9, 1, 150);
7015 p_x_interface_line_rec.Attribute10 := substrb(p_line_rec.Attribute10, 1, 150);
7016 p_x_interface_line_rec.Attribute11 := substrb(p_line_rec.Attribute11, 1, 150);
7017 p_x_interface_line_rec.Attribute12 := substrb(p_line_rec.Attribute12, 1, 150);
7018 p_x_interface_line_rec.Attribute13 := substrb(p_line_rec.Attribute13, 1, 150);
7019 p_x_interface_line_rec.Attribute14 := substrb(p_line_rec.Attribute14, 1, 150);
7020 p_x_interface_line_rec.Attribute15 := substrb(p_line_rec.Attribute15, 1, 150);
7021
7022 p_x_interface_line_rec.Header_Attribute_Category := p_header_rec.Context;
7023 p_x_interface_line_rec.Header_Attribute1 := substrb(p_header_rec.Attribute1, 1, 150);
7024 p_x_interface_line_rec.Header_Attribute2 := substrb(p_header_rec.Attribute2, 1, 150);
7025 p_x_interface_line_rec.Header_Attribute3 := substrb(p_header_rec.Attribute3, 1, 150);
7026 p_x_interface_line_rec.Header_Attribute4 := substrb(p_header_rec.Attribute4, 1, 150);
7027 p_x_interface_line_rec.Header_Attribute5 := substrb(p_header_rec.Attribute5, 1, 150);
7028 p_x_interface_line_rec.Header_Attribute6 := substrb(p_header_rec.Attribute6, 1, 150);
7029 p_x_interface_line_rec.Header_Attribute7 := substrb(p_header_rec.Attribute7, 1, 150);
7030 p_x_interface_line_rec.Header_Attribute8 := substrb(p_header_rec.Attribute8, 1, 150);
7031 p_x_interface_line_rec.Header_Attribute9 := substrb(p_header_rec.Attribute9, 1, 150);
7032 p_x_interface_line_rec.Header_Attribute10 := substrb(p_header_rec.Attribute10, 1, 150);
7033 p_x_interface_line_rec.Header_Attribute11 := substrb(p_header_rec.Attribute11, 1, 150);
7034 p_x_interface_line_rec.Header_Attribute12 := substrb(p_header_rec.Attribute12, 1, 150);
7035 p_x_interface_line_rec.Header_Attribute13 := substrb(p_header_rec.Attribute13, 1, 150);
7036 p_x_interface_line_rec.Header_Attribute14 := substrb(p_header_rec.Attribute14, 1, 150);
7037 p_x_interface_line_rec.Header_Attribute15 := substrb(p_header_rec.Attribute15, 1, 150);
7038
7039 p_x_interface_line_rec.UOM_Code := p_line_rec.Order_Quantity_UOM;
7040 p_x_interface_line_rec.Tax_Exempt_Flag := nvl(p_line_rec.Tax_Exempt_Flag, 'S');
7041 p_x_interface_line_rec.Tax_Exempt_Number := p_line_rec.Tax_Exempt_Number;
7042 p_x_interface_line_rec.Tax_Exempt_Reason_Code := p_line_rec.Tax_Exempt_Reason_Code;
7043 p_x_interface_line_rec.Org_id := p_line_rec.Org_id;
7044
7045 IF l_debug_level > 0 THEN
7046 oe_debug_pub.add( 'GET DEFAULT TERRITORY' , 5 ) ;
7047 END IF;
7048
7049 IF oe_code_control.code_release_level < '110510' THEN
7050 SELECT asp.default_territory
7051 INTO l_territory_code
7052 FROM ar_system_parameters asp
7053 WHERE nvl(asp.org_id, -3114) = nvl(p_line_rec.org_id, -3114);
7054 ELSE
7055 l_AR_Sys_Param_Rec := OE_Sys_Parameters_Pvt.Get_AR_Sys_Params(p_line_rec.org_id);
7056 l_territory_code := l_AR_Sys_Param_Rec.default_territory;
7057 END IF;
7058
7059 -- Get territory information into p_x_interface_line_rec
7060 IF l_debug_level > 0 THEN
7061 oe_debug_pub.add( 'PREPARE TERRITORY INFORMATION. l_territory_code: ' ||l_territory_code, 5 ) ;
7062 END IF;
7063 OE_DEBUG_PUB.DUMPDEBUG;
7064
7065 p_x_interface_line_rec.territory_id := 0;
7066
7067 IF (l_territory_code = 'SALES') THEN
7068 SELECT max(nvl(rst.territory_id, 0))
7069 INTO p_x_interface_line_rec.territory_id
7070 FROM ra_salesrep_territories rst
7071 WHERE rst.salesrep_id = nvl(p_line_rec.salesrep_id, p_header_rec.salesrep_id)
7072 AND sysdate between nvl(start_date_active, sysdate)
7073 AND nvl(end_date_active, sysdate);
7074 ELSIF (l_territory_code = 'BILL' AND p_line_rec.invoice_to_org_id IS NOT NULL) THEN
7075 SELECT nvl(sub.territory_id,0)
7076 INTO p_x_interface_line_rec.territory_id
7077 FROM hz_cust_site_uses sub
7078 WHERE sub.site_use_id = p_line_rec.invoice_to_org_id;
7079 ELSIF (l_territory_code = 'SHIP' AND p_line_rec.ship_to_org_id IS NOT NULL) THEN
7080 SELECT nvl(sus.territory_id,0)
7081 INTO p_x_interface_line_rec.territory_id
7082 FROM hz_cust_site_uses sus
7083 WHERE sus.site_use_id = p_line_rec.ship_to_org_id;
7084 END IF;
7085 IF l_debug_level > 0 THEN
7086 oe_debug_pub.add( 'territory_id:'|| p_x_interface_line_rec.territory_id , 5 ) ;
7087 END IF;
7088 IF (p_x_interface_line_rec.territory_id > 0) THEN
7089 SELECT terr.segment1
7090 ,terr.segment2
7091 ,terr.segment3
7092 ,terr.segment4
7093 ,terr.segment5
7094 ,terr.segment6
7095 ,terr.segment7
7096 ,terr.segment8
7097 ,terr.segment9
7098 ,terr.segment10
7099 ,terr.segment11
7100 ,terr.segment12
7101 ,terr.segment13
7102 ,terr.segment14
7103 ,terr.segment15
7104 ,terr.segment16
7105 ,terr.segment17
7106 ,terr.segment18
7107 ,terr.segment19
7108 ,terr.segment20
7109 INTO p_x_interface_line_rec.TERRITORY_SEGMENT1
7110 ,p_x_interface_line_rec.TERRITORY_SEGMENT2
7111 ,p_x_interface_line_rec.TERRITORY_SEGMENT3
7112 ,p_x_interface_line_rec.TERRITORY_SEGMENT4
7113 ,p_x_interface_line_rec.TERRITORY_SEGMENT5
7114 ,p_x_interface_line_rec.TERRITORY_SEGMENT6
7115 ,p_x_interface_line_rec.TERRITORY_SEGMENT7
7116 ,p_x_interface_line_rec.TERRITORY_SEGMENT8
7117 ,p_x_interface_line_rec.TERRITORY_SEGMENT9
7118 ,p_x_interface_line_rec.TERRITORY_SEGMENT10
7119 ,p_x_interface_line_rec.TERRITORY_SEGMENT11
7120 ,p_x_interface_line_rec.TERRITORY_SEGMENT12
7121 ,p_x_interface_line_rec.TERRITORY_SEGMENT13
7122 ,p_x_interface_line_rec.TERRITORY_SEGMENT14
7123 ,p_x_interface_line_rec.TERRITORY_SEGMENT15
7124 ,p_x_interface_line_rec.TERRITORY_SEGMENT16
7125 ,p_x_interface_line_rec.TERRITORY_SEGMENT17
7126 ,p_x_interface_line_rec.TERRITORY_SEGMENT18
7127 ,p_x_interface_line_rec.TERRITORY_SEGMENT19
7128 ,p_x_interface_line_rec.TERRITORY_SEGMENT20
7129 FROM ra_territories terr
7130 WHERE terr.territory_id = p_x_interface_line_rec.territory_id;
7131 END IF;
7132 IF p_x_interface_line_rec.territory_id = 0 THEN
7133 p_x_interface_line_rec.territory_id := NULL;
7134 END IF;
7135 IF l_debug_level > 0 THEN
7136 oe_debug_pub.add( 'FINISH TERRITORY' , 5 ) ;
7137 END IF;
7138 p_x_interface_line_rec.Batch_Source_Name := Get_Invoice_source(p_line_rec, p_x_interface_line_rec);
7139 IF l_debug_level > 0 THEN
7140 oe_debug_pub.add( 'BATCH SOURCE NAME : '||P_X_INTERFACE_LINE_REC.BATCH_SOURCE_NAME ) ;
7141 END IF;
7142 IF p_x_interface_line_rec.INTERFACE_LINE_ATTRIBUTE3 = '0' THEN
7143 IF p_x_interface_line_rec.REQUEST_ID IS NOT NULL THEN
7144 IF l_debug_level > 0 THEN
7145 oe_debug_pub.add( 'SET REQUEST_ID TO NULL FOR NON DELIVERY LINES' , 5 ) ;
7146 END IF;
7147 p_x_interface_line_rec.REQUEST_ID := NULL;
7148 END IF;
7149 END IF;
7150 --Customer Acceptance
7151 -- Populate acceptance date as trx_date for pre-billing lines to get it as invoice date
7152 IF (p_line_rec.flow_status_code='PRE-BILLING_ACCEPTANCE' OR
7153 OE_ACCEPTANCE_UTIL.Pre_billing_acceptance_on(p_line_rec => p_line_rec)) THEN
7154
7155 p_x_interface_line_rec.trx_date := p_line_rec.Revrec_signature_date;
7156 END IF;
7157
7158 -- parent_line_id, deferral_exclusion_flag should be set always
7159 -- irrespective of customer acceptance enabled or not
7160 IF p_line_rec.top_model_line_id is not null and p_line_rec.top_model_line_id <> p_line_rec.line_id THEN
7161 p_x_interface_line_rec.parent_line_id := p_line_rec.top_model_line_id;
7162 END IF;
7163 IF p_line_rec.item_type_code = 'SERVICE' THEN
7164 -- get parent line_id for service line.
7165 IF p_line_rec.service_reference_type_code='CUSTOMER_PRODUCT' AND
7166 p_line_rec.service_reference_line_id IS NOT NULL THEN
7167 BEGIN
7168 OE_SERVICE_UTIL.Get_Cust_Product_Line_Id
7169 ( x_return_status => l_return_status
7170 , p_reference_line_id => p_line_rec.service_reference_line_id
7171 , p_customer_id => p_line_rec.sold_to_org_id
7172 , x_cust_product_line_id => l_order_line_id
7173 );
7174 EXCEPTION
7175 WHEN OTHERS THEN
7176 l_parent_line_id := NULL;
7177 END;
7178 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
7179 l_parent_line_id := l_order_line_id;
7180 ELSE
7181 FND_MESSAGE.SET_NAME('ONT','ONT_NO_CUST_PROD_LINE');
7182 OE_MSG_PUB.ADD;
7183 END IF;
7184 ELSE -- not a customer product
7185 l_parent_line_id := p_line_rec.service_reference_line_id;
7186 END IF;
7187 IF l_parent_line_id IS NOT NULL THEN
7188 BEGIN
7189 Select top_model_line_id
7190 into l_top_model_line_id
7191 from oe_order_lines_all
7192 where line_id = l_parent_line_id ;
7193 EXCEPTION WHEN NO_DATA_FOUND THEN
7194 p_x_interface_line_rec.parent_line_id := l_parent_line_id ;
7195 END;
7196
7197 IF l_top_model_line_id IS NOT NULL then --service parent is a child line
7198 p_x_interface_line_rec.parent_line_id := l_top_model_line_id;
7199 else
7200 p_x_interface_line_rec.parent_line_id := l_parent_line_id ;
7201 end if;
7202 ELSE
7203 p_x_interface_line_rec.deferral_exclusion_flag := 'Y';
7204 END IF;
7205 END IF;
7206 --Customer Acceptance
7207 IF l_debug_level > 0 THEN
7208 oe_debug_pub.add( 'START CREDIT CARD PROCESSING' , 5 ) ;
7209 END IF;
7210 --serla begin
7211 IF NOT OE_PREPAYMENT_UTIL.IS_MULTIPLE_PAYMENTS_ENABLED THEN
7212 --serla end
7213 -- Check if the Line has an associated Credit Card Payment
7214 IF p_header_rec.credit_card_number is NOT NULL AND
7215 NOT Return_Line(p_line_rec) THEN /* Bug #3463843 */
7216 IF l_debug_level > 0 THEN
7217 oe_debug_pub.add( 'CREDIT CARD INFO EXISTS' , 5 ) ;
7218 -- Fix for Bug # 1586750.
7219 -- Get the Customer Id for Invoice To Org at the Header Level.
7220 oe_debug_pub.add( 'GET CUSTOMER ID FOR INVOICE TO ORG AT HEADER' , 5 ) ;
7221 END IF;
7222
7223 BEGIN
7224 /* Commented for bug #3519137 added new select statement */
7225 /* SELECT customer_id
7226 INTO l_hdr_inv_to_cust_id
7227 FROM oe_invoice_to_orgs_v
7228 WHERE organization_id = p_header_rec.invoice_to_org_id;*/
7229
7230 SELECT acct_site.cust_account_id
7231 INTO l_hdr_inv_to_cust_id
7232 FROM hz_cust_acct_sites_all acct_site, hz_cust_site_uses_all site
7233 WHERE SITE.SITE_USE_CODE = 'BILL_TO'
7234 AND SITE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
7235 AND SITE.SITE_USE_ID = p_header_rec.invoice_to_org_id;
7236
7237 EXCEPTION
7238 WHEN OTHERS THEN
7239 IF l_debug_level > 0 THEN
7240 oe_debug_pub.add( 'INVOICE TO CUSTOMER ID : '||L_HDR_INV_TO_CUST_ID , 1 ) ;
7241 oe_debug_pub.add( 'ORGANIZATION ID : '||P_HEADER_REC.INVOICE_TO_ORG_ID , 1 ) ;
7242 oe_debug_pub.add( 'IN OTHERS EXCEPTION ( OE_INVOICE_TO_ORGS_V ) '||SQLERRM , 1 ) ;
7243 END IF;
7244 END;
7245 -- Calling Process Customer Bank Account
7246 IF l_debug_level > 0 THEN
7247 oe_debug_pub.add( 'BEFORE CALLING AR PACKAGE PROCESS_CUST_BANK_ACCOUNT ( ) ' , 5 ) ;
7248 END IF;
7249 --
7250 l_trx_date := nvl(p_header_rec.ordered_date, sysdate)
7251 - nvl( to_number(fnd_profile.value('ONT_DAYS_TO_BACKDATE_BANK_ACCT')), 0);
7252 BEGIN
7253 /*
7254 ** Fix Bug # 2438201
7255 ** p_trx_date to be passed as order creation date so that autoinvoice succceds
7256 */
7257
7258 null;
7259
7260 /*** Commented out for R12 cc encryption
7261 arp_bank_pkg.process_cust_bank_account
7262 ( p_trx_date => l_trx_date
7263 , p_currency_code => p_header_rec.transactional_curr_code
7264 , p_cust_id => l_hdr_inv_to_cust_id
7265 , p_site_use_id => p_header_rec.invoice_to_org_id
7266 , p_credit_card_num => p_header_rec.credit_card_number
7267 , p_acct_name => p_header_rec.credit_card_holder_name
7268 , p_exp_date => p_header_rec.credit_card_expiration_date
7269 , p_bank_account_id => l_bank_acct_id
7270 , p_bank_account_uses_id => l_bank_acct_uses_id
7271 ) ;
7272 EXCEPTION
7273 WHEN OTHERS THEN
7274 l_bank_acct_id := -1;
7275 p_x_interface_line_rec.customer_bank_account_id := -1;
7276 IF l_debug_level > 0 THEN
7277 oe_debug_pub.add( 'AR PACKAGE ARP_BANK_PKG.PROCESS_CUST_BANK_ACCOUNT ( ) RETURNED ERROR : '||SQLERRM , 1 ) ;
7278 END IF;
7279 ***/
7280 END;
7281 IF l_debug_level > 0 THEN
7282 oe_debug_pub.add( 'AFTER CALLING PROCESS_CUST_BANK_ACCOUNT ( ) PROCEDURE ' , 5 ) ;
7283 END IF;
7284 -- Check if a Valid Bank Account Id returned
7285 IF NVL(l_bank_acct_id, 0) > 0 THEN
7286 -- Setup the Bank Account Information
7287 IF l_debug_level > 0 THEN
7288 oe_debug_pub.add( 'BANK ACCOUNT ID : '||L_BANK_ACCT_ID ) ;
7289 END IF;
7290 p_x_interface_line_rec.customer_bank_account_id := l_bank_acct_id;
7291 p_x_interface_line_rec.customer_bank_account_name
7292 := p_header_rec.credit_card_holder_name;
7293 /* Fix FP Bug # 3647389: Get the Current Context Values */
7294 l_cur_user_id := fnd_global.user_id;
7295 fnd_profile.get('RESP_ID',l_cur_resp_id);
7296 fnd_profile.get('RESP_APPL_ID',l_cur_appl_id);
7297
7298 /* Fix FP Bug # 3647389: Set the Context using Original Values */
7299 fnd_global.apps_initialize(l_user_id, l_resp_id, l_appl_id);
7300
7301 -- Call Get Primary Pay Method to get the method id
7302 IF l_debug_level > 0 THEN
7303 oe_debug_pub.add( 'GETTING PRIMAY PAYMENT METHOD' , 5 ) ;
7304 END IF;
7305
7306 l_pay_method_id := OE_Verify_Payment_PUB.Get_Primary_Pay_Method
7307 ( p_header_rec => p_header_rec ) ;
7308 IF l_debug_level > 0 THEN
7309 oe_debug_pub.add( 'AFTER GETTING PRIMARY PAYMENT METHOD' , 5 ) ;
7310 END IF;
7311
7312 /* Fix FP Bug # 3647389: Reset the Context using Current Values */
7313 fnd_global.apps_initialize(l_cur_user_id, l_cur_resp_id, l_cur_appl_id);
7314
7315 -- Check if a Valid Pay Method Id returned
7316 IF NVL(l_pay_method_id, 0) > 0 THEN
7317 IF l_debug_level > 0 THEN
7318 oe_debug_pub.add( 'PAYMENT METHOD IS VALID' ) ;
7319 -- Call Get Pay Method Info to get the method name
7320 oe_debug_pub.add( 'GET PAYMENT METHOD INFORMATION ' , 5 ) ;
7321 END IF;
7322 OE_Verify_Payment_PUB.Get_Pay_Method_Info
7323 ( p_pay_method_id => l_pay_method_id
7324 , p_pay_method_name => l_pay_method_name
7325 , p_merchant_id => l_merchant_id
7326 ) ;
7327 IF l_debug_level > 0 THEN
7328 oe_debug_pub.add( 'AFTER GETTING PAYMENT METHOD INFORMATION' , 5 ) ;
7329 -- Setup the Payment Method Information
7330 oe_debug_pub.add( 'PAYMENT METHOD ID IS : '||L_PAY_METHOD_ID , 5 ) ;
7331 END IF;
7332 p_x_interface_line_rec.receipt_method_id := l_pay_method_id;
7333 p_x_interface_line_rec.receipt_method_name := l_pay_method_name;
7334 -- Check if Credit Card Approval Code exists
7335 IF p_header_rec.credit_card_approval_code is NOT NULL THEN
7336 IF l_debug_level > 0 THEN
7337 oe_debug_pub.add( 'CREDIT CARD APPROVAL CODE EXISTS' , 5 ) ;
7338 -- Call Fetch Current Auth to get the tangible id
7339 oe_debug_pub.add( 'FETCH CURRENT AUTHORIZATION CODE , IF ANY' , 5 ) ;
7340 END IF;
7341 OE_Verify_Payment_PUB.Fetch_Current_Auth
7342 ( p_header_rec => p_header_rec
7343 , p_trxn_id => l_trxn_id
7344 , p_tangible_id => l_tangible_id
7345 ) ;
7346 IF l_debug_level > 0 THEN
7347 oe_debug_pub.add( ' AFTER CALLING FETCH_CURRENT_AUTH' ) ;
7348 -- Setup the CC Approval Info
7349 oe_debug_pub.add( 'TANGIBLE ID IS : '||L_TANGIBLE_ID , 5 ) ;
7350 END IF;
7351 p_x_interface_line_rec.approval_code := p_header_rec.credit_card_approval_code;
7352 p_x_interface_line_rec.payment_server_order_num := l_tangible_id;
7353 END IF; -- IF Approval Code Exists
7354 END IF; -- IF Pay Method ID is VALID
7355 END IF; -- IF Bank Account ID is VALID
7356 END IF; -- IF Credit Card Payment Exists
7357 --serla begin
7358 ELSE -- multiple payments enabled
7359 IF l_debug_level > 0 THEN
7360 oe_debug_pub.add('multiple payment enabled. getting payments data from line payments');
7361 END IF;
7362 -- R12 CC encryption
7363 BEGIN
7364 SELECT payment_type_code
7365 , payment_trx_id
7366 , receipt_method_id
7367 -- , tangible_id
7368 -- , credit_card_holder_name
7369 -- , credit_card_approval_code
7370 , trxn_extension_id
7371 INTO l_payment_type_code
7372 , l_payment_trx_id
7373 , l_receipt_method_id
7374 -- , l_tangible_id
7375 -- , l_credit_card_holder_name
7376 -- , l_credit_card_approval_code
7377 , l_payment_trxn_extension_id
7378 FROM oe_payments
7379 WHERE line_id = p_line_rec.line_id
7380 AND header_id = p_line_rec.header_id
7381 AND payment_type_code <> 'COMMITMENT'
7382 AND payment_collection_event = 'INVOICE';
7383 IF l_debug_level > 0 THEN
7384 oe_debug_pub.add('l_payment_type_code:'||l_payment_type_code||'l_payment_trx_id:'||l_payment_trx_id||':l_receipt_method_id:'||l_receipt_method_id);
7385 END IF;
7386 EXCEPTION
7387 WHEN NO_DATA_FOUND THEN
7388 IF l_debug_level > 0 THEN
7389 oe_debug_pub.add('No invoice payments at line level');
7390 END IF;
7391 l_payment_type_code := NULL;
7392 l_payment_trx_id := NULL;
7393 l_receipt_method_id := NULL;
7394 /*
7395 l_tangible_id := NULL;
7396 l_credit_card_holder_name := NULL;
7397 l_credit_card_approval_code := NULL;
7398 */
7399 l_payment_trxn_extension_id := NULL;
7400
7401 END;
7402
7403 IF l_payment_type_code IS NULL THEN
7404 oe_debug_pub.add('Getting payments data from header payments');
7405 BEGIN
7406 SELECT payment_type_code
7407 , payment_trx_id
7408 , receipt_method_id
7409 -- , tangible_id
7410 -- , credit_card_holder_name
7411 -- , credit_card_approval_code
7412 , trxn_extension_id
7413 INTO l_payment_type_code
7414 , l_payment_trx_id
7415 , l_receipt_method_id
7416 -- , l_tangible_id
7417 -- , l_credit_card_holder_name
7418 -- , l_credit_card_approval_code
7419 , l_payment_trxn_extension_id
7420 FROM oe_payments
7421 WHERE header_id = p_line_rec.header_id
7422 AND line_id is NULL
7423 AND payment_collection_event = 'INVOICE';
7424 IF l_debug_level > 0 THEN
7425 oe_debug_pub.add('l_payment_type_code:'||l_payment_type_code||'l_payment_trx_id:'||l_payment_trx_id||':l_receipt_method_id:'||l_receipt_method_id);
7426 END IF;
7427 EXCEPTION
7428 WHEN NO_DATA_FOUND THEN
7429 l_payment_type_code := NULL;
7430 l_payment_trx_id := NULL;
7431 l_receipt_method_id := NULL;
7432 /*
7433 l_tangible_id := NULL;
7434 l_credit_card_holder_name := NULL;
7435 l_credit_card_approval_code := NULL;
7436 */
7437 l_payment_trxn_extension_id := NULL;
7438 END;
7439 END IF;
7440
7441 p_x_interface_line_rec.payment_type_code := l_payment_type_code; --8427382
7442
7443
7444 /* also need to pass payment_trxn_extension_id for pay later lines per AR.
7445 --pnpl
7446 -- we only need to interface auth code and tangible id
7447 -- for pay now lines
7448 -- set these values to null for pay later line
7449
7450 IF OE_PREPAYMENT_UTIL.Get_installment_Options = 'ENABLE_PAY_NOW' THEN
7451 IF NOT OE_PREPAYMENT_UTIL.Is_Pay_Now_Line(p_line_rec.line_id)
7452 -- AND l_credit_card_approval_code IS NOT NULL
7453 THEN
7454 *
7455 l_credit_card_approval_code := null;
7456 l_tangible_id := null;
7457 *
7458
7459 l_payment_trxn_extension_id := null;
7460
7461 END IF;
7462 END IF;
7463 */
7464
7465
7466 IF l_payment_type_code = 'CREDIT_CARD' OR
7467 l_payment_type_code = 'ACH' OR
7468 l_payment_type_code = 'DIRECT_DEBIT' OR /* Bug #3510892 */
7469 l_payment_type_code = 'CASH' OR
7470 l_payment_type_code = 'CHECK' THEN /* Bug #3742304 */
7471 p_x_interface_line_rec.receipt_method_id := l_receipt_method_id;
7472 p_x_interface_line_rec.payment_trxn_extension_id := l_payment_trxn_extension_id;
7473
7474 /* R12 CC encryption
7475 p_x_interface_line_rec.customer_bank_account_id := l_payment_trx_id;
7476 p_x_interface_line_rec.customer_bank_account_name := l_credit_card_holder_name;
7477 */
7478
7479 IF l_receipt_method_id IS NOT NULL THEN
7480 BEGIN
7481 SELECT NAME
7482 INTO p_x_interface_line_rec.receipt_method_name
7483 FROM AR_RECEIPT_METHODS
7484 WHERE RECEIPT_METHOD_ID = l_receipt_method_id;
7485 /* AND SYSDATE >= NVL(START_DATE, SYSDATE)
7486 AND SYSDATE <= NVL(END_DATE, SYSDATE); */
7487 EXCEPTION
7488 WHEN NO_DATA_FOUND THEN
7489 p_x_interface_line_rec.receipt_method_name := NULL;
7490 WHEN OTHERS THEN
7491 p_x_interface_line_rec.receipt_method_name := NULL;
7492 END;
7493 END IF;
7494
7495 --bug6086777 Reverting the fix made by bug 5849568
7496 /*
7497 --bug5849568
7498 --Creating a receipt method assignment at the site level if it does not exist so that Autoinvoice goes through
7499 IF l_receipt_method_id IS NOT NULL THEN
7500 IF l_debug_level > 0 THEN
7501 oe_debug_pub.add('Before creating receipt method assignment at site level if it does not exist');
7502 END IF;
7503 l_trx_date := nvl(p_header_rec.ordered_date, sysdate)
7504 - nvl( to_number(fnd_profile.value('ONT_DAYS_TO_BACKDATE_BANK_ACCT')), 0);
7505 --bug6025064 Using SQL Statement since API arp_bank_pkg.process_cust_pay_method has been obsoleted
7506 l_cust_pay_method_id := arp_bank_pkg.process_cust_pay_method
7507 ( p_pay_method_id => l_receipt_method_id
7508 , p_customer_id => p_header_rec.sold_to_org_id
7509 , p_site_use_id => p_header_rec.invoice_to_org_id
7510 , p_as_of_date => l_trx_date
7511 );
7512
7513 SELECT cust_receipt_method_id
7514 INTO l_cust_pay_method_id
7515 FROM ra_cust_receipt_methods rm
7516 WHERE rm.customer_id = p_header_rec.sold_to_org_id
7517 AND rm.SITE_USE_ID = NVL(p_header_rec.invoice_to_org_id, -1)
7518 AND rm.receipt_method_id = NVL(l_receipt_method_id, rm.receipt_method_id)
7519 AND l_trx_date BETWEEN rm.start_date AND NVL(rm.end_date, l_trx_date)
7520 AND primary_flag = 'Y';
7521 --bug6025064
7522
7523 IF l_debug_level > 0 THEN
7524 oe_debug_pub.add('l_cust_pay_method_id returned for Receipt Method ' || p_x_interface_line_rec.receipt_method_name|| 'is ' ||l_cust_pay_method_id);
7525 END IF;
7526
7527 END IF;
7528 --bug5849568
7529 */
7530 --bug6086777
7531
7532 --bug6086340 Refix the fix made by bug 5849568 using new AR API arp_ext_bank_pkg.process_cust_pay_method()
7533 --Creating a receipt method assignment at the site level if it does not exist so that Autoinvoice goes through
7534 IF l_receipt_method_id IS NOT NULL THEN
7535 -- Added for bug 6911267, to get Invoice To Customer Id
7536 oe_oe_form_header.get_invoice_to_customer_id(p_site_use_id => p_header_rec.invoice_to_org_id,
7537 x_invoice_to_customer_id => l_invoice_to_customer_id);
7538 IF l_debug_level > 0 THEN
7539 oe_debug_pub.add('Before creating receipt method assignment at site level if it does not exist', 5);
7540 oe_debug_pub.add('Invoice To Customer : ' || l_invoice_to_customer_id ||'; Invoice To Site : ' || p_header_rec.invoice_to_org_id, 5);
7541 END IF;
7542 l_trx_date := nvl(p_header_rec.ordered_date, sysdate)
7543 - nvl( to_number(fnd_profile.value('ONT_DAYS_TO_BACKDATE_BANK_ACCT')), 0);
7544
7545 l_cust_pay_method_id := arp_ext_bank_pkg.process_cust_pay_method
7546 ( p_pay_method_id => l_receipt_method_id
7547 , p_customer_id => l_invoice_to_customer_id -- p_header_rec.sold_to_org_id -- Bug 6911267
7548 , p_site_use_id => p_header_rec.invoice_to_org_id
7549 , p_as_of_date => l_trx_date
7550 );
7551
7552
7553 IF l_debug_level > 0 THEN
7554 oe_debug_pub.add('l_cust_pay_method_id returned for Receipt Method ' || p_x_interface_line_rec.receipt_method_name|| 'is ' ||l_cust_pay_method_id);
7555 END IF;
7556
7557 END IF;
7558 --bug6086340
7559
7560 -- comment out the following code for R12 cc encryption
7561 /*
7562 IF l_credit_card_approval_code IS NOT NULL THEN
7563 p_x_interface_line_rec.approval_code := l_credit_card_approval_code;
7564 --bug3906851 getting the tangible_id from oe_verify_payment_pub.fetch_current_auth if it is null
7565 IF l_tangible_id IS NULL THEN
7566
7567 OE_Verify_Payment_PUB.Fetch_Current_Auth
7568 ( p_header_rec => p_header_rec
7569 , p_trxn_id => l_trxn_id
7570 , p_tangible_id => l_tangible_id
7571 ) ;
7572
7573 IF l_debug_level > 0 THEN
7574 oe_debug_pub.add( ' AFTER CALLING FETCH_CURRENT_AUTH' ) ;
7575 -- Setup the CC Approval Info
7576 oe_debug_pub.add( 'TANGIBLE ID IS : '||L_TANGIBLE_ID , 5 ) ;
7577 END IF;
7578
7579 END IF;
7580 p_x_interface_line_rec.payment_server_order_num := l_tangible_id;
7581 END IF;
7582 */
7583 oe_debug_pub.add('l_receipt_method_id:'||l_receipt_method_id||'Name:'||p_x_interface_line_rec.receipt_method_name);
7584 END IF;
7585 END IF;
7586
7587 --serla end
7588
7589 IF l_debug_level > 0 THEN
7590 oe_debug_pub.add( 'FINISH CREDIT CARD PROCESSING' , 5 ) ;
7591 oe_debug_pub.add( 'START GLOBALIZATION' , 5 ) ;
7592 END IF;
7593 l_gdf_rec.interface_line_attribute3 := p_x_interface_line_rec.interface_line_attribute3;
7594 l_gdf_rec.interface_line_attribute6 := p_x_interface_line_rec.interface_line_attribute6;
7595 l_gdf_rec.line_type := p_x_interface_line_rec.line_type;
7596 l_gdf_rec.inventory_item_id := p_line_rec.inventory_item_id;
7597 l_gdf_rec.line_gdf_attr_category := p_line_rec.global_attribute_category;
7598 l_gdf_rec.line_gdf_attribute1 := substrb(p_line_rec.global_attribute1, 1, 150);
7599 l_gdf_rec.line_gdf_attribute2 := substrb(p_line_rec.global_attribute2, 1, 150);
7600 l_gdf_rec.line_gdf_attribute3 := substrb(p_line_rec.global_attribute3, 1, 150);
7601 l_gdf_rec.line_gdf_attribute4 := substrb(p_line_rec.global_attribute4, 1, 150);
7602 l_gdf_rec.line_gdf_attribute5 := substrb(p_line_rec.global_attribute5, 1, 150);
7603 l_gdf_rec.line_gdf_attribute6 := substrb(p_line_rec.global_attribute6, 1, 150);
7604 l_gdf_rec.line_gdf_attribute7 := substrb(p_line_rec.global_attribute7, 1, 150);
7605 l_gdf_rec.line_gdf_attribute8 := substrb(p_line_rec.global_attribute8, 1, 150);
7606 l_gdf_rec.line_gdf_attribute9 := substrb(p_line_rec.global_attribute9, 1, 150);
7607 l_gdf_rec.line_gdf_attribute10 := substrb(p_line_rec.global_attribute10, 1, 150);
7608 l_gdf_rec.line_gdf_attribute11 := substrb(p_line_rec.global_attribute11, 1, 150);
7609 l_gdf_rec.line_gdf_attribute12 := substrb(p_line_rec.global_attribute12, 1, 150);
7610 l_gdf_rec.line_gdf_attribute13 := substrb(p_line_rec.global_attribute13, 1, 150);
7611 l_gdf_rec.line_gdf_attribute14 := substrb(p_line_rec.global_attribute14, 1, 150);
7612 l_gdf_rec.line_gdf_attribute15 := substrb(p_line_rec.global_attribute15, 1, 150);
7613 l_gdf_rec.line_gdf_attribute16 := substrb(p_line_rec.global_attribute16, 1, 150);
7614 l_gdf_rec.line_gdf_attribute17 := substrb(p_line_rec.global_attribute17, 1, 150);
7615 l_gdf_rec.line_gdf_attribute18 := substrb(p_line_rec.global_attribute18, 1, 150);
7616 l_gdf_rec.line_gdf_attribute19 := substrb(p_line_rec.global_attribute19, 1, 150);
7617 l_gdf_rec.line_gdf_attribute20 := substrb(p_line_rec.global_attribute20, 1, 150);
7618 IF l_debug_level > 0 THEN
7619 oe_debug_pub.add( 'CALLING THE GLOBALIZATION PACKAGE' , 5 ) ;
7620 END IF;
7621 JG_ZZ_OM_COMMON_PKG.copy_gdff(p_interface_line_rec => l_gdf_rec,
7622 x_interface_line_rec => l_gdf_rec,
7623 x_return_code => l_jg_return_code,
7624 x_error_buffer => l_jg_error_buffer);
7625 IF l_debug_level > 0 THEN
7626 oe_debug_pub.add( 'AFTER CALLING GLOBALIZATION PACKAGE' , 5 ) ;
7627 END IF;
7628 p_x_interface_line_rec.line_gdf_attr_category := l_gdf_rec.line_gdf_attr_category;
7629 p_x_interface_line_rec.line_gdf_attribute1 := l_gdf_rec.line_gdf_attribute1;
7630 p_x_interface_line_rec.line_gdf_attribute2 := l_gdf_rec.line_gdf_attribute2;
7631 p_x_interface_line_rec.line_gdf_attribute3 := l_gdf_rec.line_gdf_attribute3;
7632 p_x_interface_line_rec.line_gdf_attribute4 := l_gdf_rec.line_gdf_attribute4;
7633 p_x_interface_line_rec.line_gdf_attribute5 := l_gdf_rec.line_gdf_attribute5;
7634 p_x_interface_line_rec.line_gdf_attribute6 := l_gdf_rec.line_gdf_attribute6;
7635 p_x_interface_line_rec.line_gdf_attribute7 := l_gdf_rec.line_gdf_attribute7;
7636 p_x_interface_line_rec.line_gdf_attribute8 := l_gdf_rec.line_gdf_attribute8;
7637 p_x_interface_line_rec.line_gdf_attribute9 := l_gdf_rec.line_gdf_attribute9;
7638 p_x_interface_line_rec.line_gdf_attribute10 := l_gdf_rec.line_gdf_attribute10;
7639 p_x_interface_line_rec.line_gdf_attribute11 := l_gdf_rec.line_gdf_attribute11;
7640 p_x_interface_line_rec.line_gdf_attribute12 := l_gdf_rec.line_gdf_attribute12;
7641 p_x_interface_line_rec.line_gdf_attribute13 := l_gdf_rec.line_gdf_attribute13;
7642 p_x_interface_line_rec.line_gdf_attribute14 := l_gdf_rec.line_gdf_attribute14;
7643 p_x_interface_line_rec.line_gdf_attribute15 := l_gdf_rec.line_gdf_attribute15;
7644 p_x_interface_line_rec.line_gdf_attribute16 := l_gdf_rec.line_gdf_attribute16;
7645 p_x_interface_line_rec.line_gdf_attribute17 := l_gdf_rec.line_gdf_attribute17;
7646 p_x_interface_line_rec.line_gdf_attribute18 := l_gdf_rec.line_gdf_attribute18;
7647 p_x_interface_line_rec.line_gdf_attribute19 := l_gdf_rec.line_gdf_attribute19;
7648 p_x_interface_line_rec.line_gdf_attribute20 := l_gdf_rec.line_gdf_attribute20;
7649 p_x_interface_line_rec.header_gdf_attr_category := l_gdf_rec.header_gdf_attr_category;
7650 p_x_interface_line_rec.header_gdf_attribute1 := l_gdf_rec.header_gdf_attribute1;
7651 p_x_interface_line_rec.header_gdf_attribute2 := l_gdf_rec.header_gdf_attribute2;
7652 p_x_interface_line_rec.header_gdf_attribute3 := l_gdf_rec.header_gdf_attribute3;
7653 p_x_interface_line_rec.header_gdf_attribute4 := l_gdf_rec.header_gdf_attribute4;
7654 p_x_interface_line_rec.header_gdf_attribute5 := l_gdf_rec.header_gdf_attribute5;
7655 p_x_interface_line_rec.header_gdf_attribute6 := l_gdf_rec.header_gdf_attribute6;
7656 p_x_interface_line_rec.header_gdf_attribute7 := l_gdf_rec.header_gdf_attribute7;
7657 p_x_interface_line_rec.header_gdf_attribute8 := l_gdf_rec.header_gdf_attribute8;
7658 p_x_interface_line_rec.header_gdf_attribute9 := l_gdf_rec.header_gdf_attribute9;
7659 p_x_interface_line_rec.header_gdf_attribute10 := l_gdf_rec.header_gdf_attribute10;
7660 p_x_interface_line_rec.header_gdf_attribute11 := l_gdf_rec.header_gdf_attribute11;
7661 p_x_interface_line_rec.header_gdf_attribute12 := l_gdf_rec.header_gdf_attribute12;
7662 p_x_interface_line_rec.header_gdf_attribute13 := l_gdf_rec.header_gdf_attribute13;
7663 p_x_interface_line_rec.header_gdf_attribute14 := l_gdf_rec.header_gdf_attribute14;
7664 p_x_interface_line_rec.header_gdf_attribute15 := l_gdf_rec.header_gdf_attribute15;
7665 p_x_interface_line_rec.header_gdf_attribute16 := l_gdf_rec.header_gdf_attribute16;
7666 p_x_interface_line_rec.header_gdf_attribute17 := l_gdf_rec.header_gdf_attribute17;
7667 p_x_interface_line_rec.header_gdf_attribute18 := l_gdf_rec.header_gdf_attribute18;
7668 p_x_interface_line_rec.header_gdf_attribute19 := l_gdf_rec.header_gdf_attribute19;
7669 p_x_interface_line_rec.header_gdf_attribute20 := l_gdf_rec.header_gdf_attribute20;
7670 p_x_interface_line_rec.header_gdf_attribute21 := l_gdf_rec.header_gdf_attribute21;
7671 p_x_interface_line_rec.header_gdf_attribute22 := l_gdf_rec.header_gdf_attribute22;
7672 p_x_interface_line_rec.header_gdf_attribute23 := l_gdf_rec.header_gdf_attribute23;
7673 p_x_interface_line_rec.header_gdf_attribute24 := l_gdf_rec.header_gdf_attribute24;
7674 p_x_interface_line_rec.header_gdf_attribute25 := l_gdf_rec.header_gdf_attribute25;
7675 p_x_interface_line_rec.header_gdf_attribute26 := l_gdf_rec.header_gdf_attribute26;
7676 p_x_interface_line_rec.header_gdf_attribute27 := l_gdf_rec.header_gdf_attribute27;
7677 p_x_interface_line_rec.header_gdf_attribute28 := l_gdf_rec.header_gdf_attribute28;
7678 p_x_interface_line_rec.header_gdf_attribute29 := l_gdf_rec.header_gdf_attribute29;
7679 p_x_interface_line_rec.header_gdf_attribute30 := l_gdf_rec.header_gdf_attribute30;
7680
7681 IF l_debug_level > 0 THEN
7682 oe_debug_pub.add('Before calling Legal Entity Time Zone ');
7683 oe_debug_pub.add('Value of ship_date_actual '||p_x_interface_line_rec.ship_date_actual||
7684 ' Value of creation_date '|| p_x_interface_line_rec.creation_date);
7685 oe_debug_pub.add('Value of last_update_date '||p_x_interface_line_rec.last_update_date||
7686 ' Value of sales_order_date '||p_x_interface_line_rec.sales_order_date|| ' Value of trx_date '||p_x_interface_line_rec.trx_date);
7687 END IF;
7688
7689 IF oe_code_control.code_release_level >= '110510' THEN
7690 IF p_line_rec.org_id IS NOT NULL THEN
7691 IF p_x_interface_line_rec.ship_date_actual IS NOT NULL THEN
7692 p_x_interface_line_rec.ship_date_actual := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.ship_date_actual,p_line_rec.org_id);
7693 END IF;
7694 IF p_x_interface_line_rec.creation_date IS NOT NULL THEN
7695 p_x_interface_line_rec.creation_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.creation_date,p_line_rec.org_id);
7696 END IF;
7697 IF p_x_interface_line_rec.last_update_date IS NOT NULL THEN
7698 p_x_interface_line_rec.last_update_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.last_update_date,p_line_rec.org_id);
7699 END IF;
7700 IF p_x_interface_line_rec.GL_Date IS NOT NULL THEN
7701 p_x_interface_line_rec.GL_Date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.GL_Date,p_line_rec.org_id);
7702 END IF;
7703 IF p_x_interface_line_rec.conversion_date IS NOT NULL THEN
7704 p_x_interface_line_rec.conversion_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.conversion_date,p_line_rec.org_id);
7705 END IF;
7706 IF p_x_interface_line_rec.sales_order_date IS NOT NULL THEN
7707 p_x_interface_line_rec.sales_order_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.sales_order_date,p_line_rec.org_id);
7708 END IF;
7709 IF p_x_interface_line_rec.rule_start_date IS NOT NULL THEN
7710 p_x_interface_line_rec.rule_start_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.rule_start_date,p_line_rec.org_id);
7711 END IF;
7712 IF p_x_interface_line_rec.rule_end_date IS NOT NULL THEN
7713 p_x_interface_line_rec.rule_end_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.rule_end_date,p_line_rec.org_id);
7714 END IF;
7715 IF p_x_interface_line_rec.trx_date IS NOT NULL THEN
7716 p_x_interface_line_rec.trx_date := INV_LE_TIMEZONE_PUB.Get_Le_Day_Time_For_Ou(p_x_interface_line_rec.trx_date,p_line_rec.org_id);
7717 END IF;
7718 END IF;
7719 END IF;
7720
7721 IF l_debug_level > 0 THEN
7722 oe_debug_pub.add('After calling Legal Entity Time Zone ');
7723 oe_debug_pub.add('Value of ship_date_actual '||p_x_interface_line_rec.ship_date_actual||
7724 ' Value of creation_date '|| p_x_interface_line_rec.creation_date);
7725 oe_debug_pub.add('Value of last_update_date '||p_x_interface_line_rec.last_update_date||
7726 ' Value of sales_order_date '||p_x_interface_line_rec.sales_order_date|| ' Value of trx_date '||p_x_interface_line_rec.trx_date);
7727 END IF;
7728
7729 IF l_debug_level > 0 THEN
7730 oe_debug_pub.add( 'END GLOBALIZATION' , 5 ) ;
7731 END IF;
7732 OE_DEBUG_PUB.dumpdebug;
7733 IF l_debug_level > 0 THEN
7734 oe_debug_pub.add( 'EXITING PREPARE_INTERFACE_LINE_REC ( ) PROCEDURE' , 5 ) ;
7735 END IF;
7736 END Prepare_Interface_Line_Rec;
7737
7738 PROCEDURE Update_Invoice_Attributes
7739 ( p_line_rec IN OE_Order_Pub.Line_Rec_Type
7740 , p_interface_line_rec IN RA_interface_Lines_Rec_Type
7741 , p_invoice_interface_status IN VARCHAR2
7742 , x_return_status OUT NOCOPY VARCHAR2
7743 ) IS
7744 l_invoiced_quantity NUMBER;
7745 l_Line_tbl OE_Order_PUB.Line_Tbl_Type;
7746 l_Old_Line_tbl OE_Order_PUB.Line_Tbl_Type;
7747 l_return_status VARCHAR2(30);
7748 l_flow_status_code VARCHAR2(30);
7749 err_msg VARCHAR2(240);
7750 l_notify_index NUMBER; -- jolin
7751 l_trxn_extension_id NUMBER:=NULL; --CC Reversal ER#16014135
7752
7753 --
7754 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7755 --
7756 -- 8541809: Start
7757 l_item_key_sso NUMBER;
7758 l_header_rec Oe_Order_Pub.Header_Rec_Type;
7759 l_ret_stat Varchar2(30);
7760 -- 8541809: End
7761 BEGIN
7762 IF l_debug_level > 0 THEN
7763 oe_debug_pub.add( 'UPDATING INVOICE ATTRIBUTES' , 5 ) ;
7764 oe_debug_pub.add( 'STATUS= '||p_invoice_interface_status);
7765 END IF;
7766 IF OE_GLOBALS.G_ASO_INSTALLED IS NULL THEN
7767 OE_GLOBALS.G_ASO_INSTALLED := OE_GLOBALS.CHECK_PRODUCT_INSTALLED(697);
7768 END IF;
7769 l_invoiced_quantity := nvl(p_line_rec.invoiced_quantity, 0) + nvl(p_interface_line_rec.quantity, 0);
7770 --Bug2361642.Added a check for lines in "MANUAL-PENDING" status too.
7771 IF (p_invoice_interface_status = 'RFR-PENDING' OR
7772 p_invoice_interface_status= 'NOT_ELIGIBLE' OR
7773 p_invoice_interface_status = 'MANUAL-PENDING' OR
7774 p_invoice_interface_status = 'ACCEPTANCE-PENDING' OR --Customer Acceptance
7775 p_invoice_interface_status = 'BILLED_FROM_CONTRACTS') AND -- sol_ord_er #16014165
7776 nvl(l_invoiced_quantity, 0) = 0 THEN -- changed for bug# 4097203
7777 l_invoiced_quantity := null;
7778 END IF;
7779 --Bug2361642 Added an ELSE condition to retain the flow_status_code otherwise.
7780 -- invoiced quantity should not be populated for not eligible lines
7781 IF p_invoice_interface_status= 'NOT_ELIGIBLE' THEN
7782 l_invoiced_quantity := null;
7783 END IF;
7784 IF l_debug_level > 0 THEN
7785 oe_debug_pub.add( 'INVOICED QUANTITY IS '|| TO_CHAR ( L_INVOICED_QUANTITY ) , 5 ) ;
7786 END IF;
7787
7788 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL < '110510' THEN
7789 IF p_invoice_interface_status = 'YES' THEN
7790 l_flow_status_code := 'INVOICED';
7791 ELSIF p_invoice_interface_status = 'RFR-PENDING' THEN
7792 l_flow_status_code := 'INVOICED_PARTIAL';
7793 ELSE l_flow_status_code := p_line_rec.flow_status_code;
7794 END IF;
7795 ELSE
7796 IF p_invoice_interface_status = 'YES' THEN
7797 l_flow_status_code := 'INVOICED';
7798 ELSIF p_invoice_interface_status = 'MANUAL-PENDING' THEN
7799 l_flow_status_code := 'INVOICE_DELIVERY';
7800 ELSIF p_invoice_interface_status = 'RFR-PENDING' THEN
7801 IF nvl(l_invoiced_quantity, 0) = 0 THEN -- changed for bug# 4097203
7802 l_flow_status_code := 'INVOICE_RFR';
7803 ELSE
7804 l_flow_status_code := 'PARTIAL_INVOICE_RFR';
7805 END IF;
7806 ELSIF p_invoice_interface_status = 'NOT_ELIGIBLE' THEN
7807 l_flow_status_code := 'INVOICE_NOT_APPLICABLE';
7808 -- sol_ord_er #16014165
7809 ELSIF p_invoice_interface_status = 'BILLED_FROM_CONTRACTS' THEN
7810 l_flow_status_code := 'BILLED_FROM_CONTRACTS';
7811 -- sol_ord_er #16014165 end
7812 --Customer Acceptance
7813 ELSIF p_invoice_interface_status = 'ACCEPTANCE-PENDING' THEN
7814 l_flow_status_code := 'PRE-BILLING_ACCEPTANCE';
7815 --Customer Acceptance
7816 ELSE l_flow_status_code := p_line_rec.flow_status_code;
7817 END IF;
7818 END IF;
7819
7820 IF l_debug_level > 0 THEN
7821 oe_debug_pub.add( 'UPDATING FLOW STATUS CODE AS '||L_FLOW_STATUS_CODE , 5 ) ;
7822 oe_debug_pub.add( ' UPDATING p_line_rec.SERVICE_START_DATE = '||p_line_rec.SERVICE_START_DATE , 5 ) ; -- bug# 7231974
7823 oe_debug_pub.add( ' p_line_rec.SERVICE_END_DATE = '|| p_line_rec.SERVICE_END_DATE , 5 ) ;
7824 END IF;
7825
7826 UPDATE OE_ORDER_LINES_ALL
7827 SET INVOICE_INTERFACE_STATUS_CODE = p_invoice_interface_status,
7828 INVOICED_QUANTITY = l_invoiced_quantity,
7829 FLOW_STATUS_CODE = l_flow_status_code,
7830 SERVICE_START_DATE = p_line_rec.SERVICE_START_DATE, --bug# 7231974 :- as srvc_dates are derived in OE_INVOICE_PUB, they should be updated in OM tables as well
7831 SERVICE_END_DATE = p_line_rec.SERVICE_END_DATE, --bug # 7231974
7832 --9040537 CREDIT_INVOICE_LINE_ID = p_line_rec.CREDIT_INVOICE_LINE_ID, --8319535
7833 CALCULATE_PRICE_FLAG = 'N',
7834 LOCK_CONTROL = LOCK_CONTROL + 1
7835 , last_update_date = sysdate --BUG#9539541
7836 , last_updated_by = NVL(oe_standard_wf.g_user_id, fnd_global.user_id) --BUG#9539541
7837 WHERE LINE_ID = p_line_rec.line_id;
7838 --CC Reversal ER#16014135 Start
7839 IF OE_VERIFY_PAYMENT_PUB.Get_CC_Rev_Reauth_Code(p_line_rec.header_id) IS NOT NULL THEN
7840
7841 IF l_debug_level > 0 THEN
7842 oe_debug_pub.add( 'Credit card reversal ER is check begin ', 5 ) ;
7843 END IF;
7844 BEGIN
7845 SELECT trxn_extension_id
7846 INTO l_trxn_extension_id
7847 FROM oe_payments
7848 WHERE header_id = p_line_rec.header_id
7849 AND line_id =p_line_rec.line_id
7850 AND PAYMENT_LEVEL_CODE ='LINE'
7851 AND PAYMENT_COLLECTION_EVENT='INVOICE';
7852 EXCEPTION
7853 WHEN NO_DATA_FOUND THEN
7854 l_trxn_extension_id :=NULL;
7855 WHEN OTHERS THEN
7856 l_trxn_extension_id :=NULL;
7857 END;
7858 IF l_debug_level > 0 THEN
7859 oe_debug_pub.add( 'line level invoice payment exists with trxn_extension_id '||l_trxn_extension_id, 5 ) ;
7860 END IF;
7861 IF l_trxn_extension_id IS NULL THEN --if no line level invoice payment then only check for header level invoice payment
7862 IF l_debug_level > 0 THEN
7863 oe_debug_pub.add( 'checking header level level invoice payment ', 5 ) ;
7864 END IF;
7865
7866 BEGIN
7867 SELECT trxn_extension_id
7868 INTO l_trxn_extension_id
7869 FROM oe_payments
7870 WHERE header_id = p_line_rec.header_id
7871 AND line_id is NULL
7872 AND PAYMENT_LEVEL_CODE ='ORDER'
7873 AND PAYMENT_TYPE_CODE ='CREDIT_CARD'
7874 AND PAYMENT_COLLECTION_EVENT='INVOICE';
7875 EXCEPTION
7876 WHEN NO_DATA_FOUND THEN
7877 l_trxn_extension_id :=NULL;
7878 WHEN OTHERS THEN
7879 l_trxn_extension_id :=NULL;
7880 END;
7881 IF l_debug_level > 0 THEN
7882 oe_debug_pub.add( 'header level invoice payment exists with trxn_extension_id '||l_trxn_extension_id, 5 ) ;
7883 END IF;
7884
7885
7886 IF l_trxn_extension_id IS NOT NULL THEN --headerlevel invoice payment check for credit card
7887 IF l_debug_level > 0 THEN
7888 oe_debug_pub.add( 'updating header level invoice payment ', 5 ) ;
7889 END IF;
7890
7891 UPDATE OE_PAYMENTS
7892 SET INVOICED_FLAG ='Y'
7893 WHERE header_id = p_line_rec.header_id
7894 AND line_id is NULL
7895 AND PAYMENT_LEVEL_CODE ='ORDER'
7896 AND PAYMENT_TYPE_CODE ='CREDIT_CARD'
7897 AND PAYMENT_COLLECTION_EVENT='INVOICE';
7898 IF l_debug_level > 0 THEN
7899 oe_debug_pub.add( 'updating header level invoice payment... done ', 5 ) ;
7900 END IF;
7901 END IF;
7902 END IF;--End if of line level l_trxn_extension_id check
7903 END IF;-- cc reversal ER flag check
7904 --CC Reversal ER#16014135 end
7905 IF ( (OE_GLOBALS.G_ASO_INSTALLED = 'Y') OR
7906 (NVL(FND_PROFILE.VALUE('ONT_DBI_INSTALLED'),'N') = 'Y') ) THEN
7907
7908 l_Line_tbl(1) := p_line_rec;
7909 l_Old_Line_tbl(1) := p_line_rec;
7910 l_Line_tbl(1).calculate_price_flag := 'N';
7911 l_Line_tbl(1).invoice_interface_status_code := p_invoice_interface_status;
7912 l_Line_tbl(1).invoiced_quantity := l_invoiced_quantity;
7913 l_Line_tbl(1).flow_status_code := l_flow_status_code;
7914 l_line_tbl(1).lock_control := l_line_tbl(1).lock_control + 1;
7915
7916 -- jolin start
7917 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110508' THEN
7918
7919 -- call notification framework to get this line's index position
7920 OE_ORDER_UTIL.Update_Global_Picture
7921 (p_Upd_New_Rec_If_Exists =>FALSE
7922 , p_line_rec => l_line_tbl(1)
7923 , p_old_line_rec => l_old_line_tbl(1)
7924 , p_line_id => l_line_tbl(1).line_id
7925 , x_index => l_notify_index
7926 , x_return_status => l_return_status);
7927
7928 IF l_debug_level > 0 THEN
7929 oe_debug_pub.add( 'UPDATE_GLOBAL RET_STATUS FOR LINE_ID '||L_LINE_TBL ( 1 ) .LINE_ID ||' IS: ' || L_RETURN_STATUS , 1 ) ;
7930 oe_debug_pub.add( 'UPDATE_GLOBAL INDEX FOR LINE_ID '||L_LINE_TBL ( 1 ) .LINE_ID ||' IS: ' || L_NOTIFY_INDEX , 1 ) ;
7931 END IF;
7932
7933 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
7934 RAISE FND_API.G_EXC_ERROR;
7935 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7936 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7937 END IF;
7938
7939 IF l_notify_index is not null then
7940 -- modify Global Picture
7941 OE_ORDER_UTIL.g_old_line_tbl(l_notify_index) := l_old_line_tbl(1);
7942 OE_ORDER_UTIL.g_line_tbl(l_notify_index) := OE_ORDER_UTIL.g_old_line_tbl(l_notify_index);
7943 OE_ORDER_UTIL.g_line_tbl(l_notify_index).invoice_interface_status_code:=
7944 l_line_tbl(1).invoice_interface_status_code;
7945 OE_ORDER_UTIL.g_line_tbl(l_notify_index).invoiced_quantity:=
7946 l_line_tbl(1).invoiced_quantity;
7947 OE_ORDER_UTIL.g_line_tbl(l_notify_index).flow_status_code:=
7948 l_line_tbl(1).flow_status_code;
7949 OE_ORDER_UTIL.g_line_tbl(l_notify_index).calculate_price_flag:=
7950 l_line_tbl(1).calculate_price_flag;
7951 OE_ORDER_UTIL.g_line_tbl(l_notify_index).lock_control:=
7952 l_line_tbl(1).lock_control;
7953 OE_ORDER_UTIL.g_line_tbl(l_notify_index).last_update_date:=
7954 l_line_tbl(1).last_update_date;
7955 OE_ORDER_UTIL.g_line_tbl(l_notify_index).line_id:=
7956 l_line_tbl(1).line_id;
7957 OE_ORDER_UTIL.g_line_tbl(l_notify_index).header_id:=
7958 l_line_tbl(1).header_id;
7959
7960 IF l_debug_level > 0 THEN
7961 oe_debug_pub.add( 'GLOBAL LINE INVOICED_QUANTITY IS: ' || OE_ORDER_UTIL.G_LINE_TBL ( L_NOTIFY_INDEX ) .INVOICED_QUANTITY , 1 ) ;
7962 oe_debug_pub.add( 'GLOBAL LINE CALCULATE_PRICE_FLAG IS: ' || OE_ORDER_UTIL.G_LINE_TBL ( L_NOTIFY_INDEX ) .CALCULATE_PRICE_FLAG , 1 ) ;
7963 oe_debug_pub.add( 'GLOBAL LINE INVOICE_INTERFACE_STATUS_CODE IS: ' || OE_ORDER_UTIL.G_LINE_TBL ( L_NOTIFY_INDEX ) .INVOICE_INTERFACE_STATUS_CODE , 1 ) ;
7964 oe_debug_pub.add( 'GLOBAL LINE FLOW_STATUS_CODE IS: ' || OE_ORDER_UTIL.G_LINE_TBL ( L_NOTIFY_INDEX ) .FLOW_STATUS_CODE , 1 ) ;
7965 END IF;
7966
7967 -- Process requests is TRUE so still need to call it, but don't need to notify
7968 IF l_debug_level > 0 THEN
7969 oe_debug_pub.add( 'OEXPINVB: BEFORE CALLING LINE PROCESS_REQUESTS_AND_NOTIFY' ) ;
7970 END IF;
7971 OE_Order_PVT.PROCESS_REQUESTS_AND_NOTIFY(
7972 P_LINE_TBL =>l_Line_tbl,
7973 P_OLD_LINE_TBL =>l_Old_Line_tbl,
7974 P_PROCESS_REQUESTS => TRUE,
7975 P_NOTIFY => FALSE,
7976 P_PROCESS_ACK => FALSE,
7977 X_RETURN_STATUS => l_return_status);
7978
7979 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
7980 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7981 END IF;
7982
7983 END IF ; /* global entity index null check */
7984
7985 ELSE /* pre-pack H */
7986
7987 IF l_debug_level > 0 THEN
7988 oe_debug_pub.add( 'OEXPINVB: BEFORE CALLING LINE PROCESS_REQUESTS_AND_NOTIFY' ) ;
7989 END IF;
7990 OE_Order_PVT.PROCESS_REQUESTS_AND_NOTIFY(
7991 P_LINE_TBL =>l_Line_tbl,
7992 P_OLD_LINE_TBL =>l_Old_Line_tbl,
7993 P_PROCESS_REQUESTS => TRUE,
7994 P_NOTIFY => TRUE,
7995 P_PROCESS_ACK => FALSE,
7996 X_RETURN_STATUS => l_return_status);
7997
7998 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
7999 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8000 END IF;
8001
8002 END IF; /* code set is pack H or higher */
8003 /* jolin end*/
8004
8005 END IF;
8006
8007 x_return_status := FND_API.G_RET_STS_SUCCESS;
8008
8009 IF l_debug_level > 0 THEN
8010 oe_debug_pub.add( 'RETURN STATUS : ' ||X_RETURN_STATUS ) ;
8011 END IF;
8012
8013 -- 8541809: Start
8014 IF l_debug_level > 0 THEN
8015 oe_debug_pub.add('Calling O2C Sync for flow status... ', 1);
8016 END IF;
8017
8018 Update_Line_Flow_Status(p_line_rec.line_id, l_flow_status_code,
8019 p_line_rec.order_source_id);
8020
8021 IF l_debug_level > 0 THEN
8022 oe_debug_pub.add('Done with O2C Sync for flow status... ', 1);
8023 END IF;
8024 -- 8541809: End
8025
8026 IF OE_Commitment_Pvt.DO_Commitment_Sequencing THEN --commitment sequencing ON
8027 IF p_line_rec.commitment_id IS NOT NULL AND
8028 p_interface_line_rec.promised_commitment_amount IS NOT NULL THEN
8029 IF l_debug_level > 0 THEN
8030 oe_debug_pub.add( 'UPDATING OE_PAYMENTS' , 3 ) ;
8031 END IF;
8032 UPDATE oe_payments
8033 SET commitment_interfaced_amount = nvl(commitment_interfaced_amount, 0) + nvl(p_interface_line_rec.promised_commitment_amount, 0)
8034 WHERE LINE_ID = p_line_rec.line_id
8035 AND PAYMENT_TRX_ID = p_line_rec.commitment_id;
8036 END IF;
8037 END IF;
8038
8039 IF l_debug_level > 0 THEN
8040 oe_debug_pub.add( 'DONE UPDATING INVOICE ATTRIBUTES' , 1 ) ;
8041 END IF;
8042
8043 EXCEPTION
8044 WHEN OTHERS THEN
8045 IF l_debug_level > 0 THEN
8046 oe_debug_pub.add( 'EXCEPTION WHILE UPDATING INVOICE ATTRIBUTES : '||SQLERRM , 1 ) ;
8047 END IF;
8048 err_msg := 'Error in Update_Invoice_Attributes:\n '||SQLERRM;
8049 IF l_debug_level > 0 THEN
8050 oe_debug_pub.add( ERR_MSG ) ;
8051 END IF;
8052 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8053 IF FND_MSG_PUB.Check_Msg_Level
8054 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8055 THEN
8056 OE_MSG_PUB.Add_Exc_Msg
8057 ( G_PKG_NAME
8058 , 'Update_Invoice_Attributes'
8059 );
8060 END IF;
8061 END Update_Invoice_Attributes;
8062
8063 FUNCTION Header_Activity
8064 (p_line_id IN NUMBER
8065 ) RETURN BOOLEAN IS
8066 l_header_id NUMBER;
8067 --
8068 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8069 --
8070 BEGIN
8071 IF l_debug_level > 0 THEN
8072 oe_debug_pub.add( 'ENTER HEADER_ACTIVITY ( ) PROCEDURE ' , 5 ) ;
8073 END IF;
8074 SELECT header_id
8075 INTO l_header_id
8076 FROM oe_order_lines
8077 WHERE line_id = p_line_id;
8078 RETURN( WF_ENGINE.Activity_Exist_In_Process(
8079 p_item_type => OE_GLOBALS.G_WFI_HDR
8080 ,p_item_key => to_char(l_header_id)
8081 ,p_activity_name => 'HEADER_INVOICE_INTERFACE'));
8082 END Header_Activity;
8083
8084 FUNCTION Line_Activity
8085 (p_line_id IN NUMBER
8086 ) RETURN BOOLEAN IS
8087 --
8088 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8089 --
8090 BEGIN
8091 IF l_debug_level > 0 THEN
8092 oe_debug_pub.add( 'ENTER LINE_ACTIVITY ( ) PROCEDURE ' , 5 ) ;
8093 END IF;
8094 -- This function is provided by WF for our use with bug# 1040262.
8095 -- WF team removed this function at one stage and now provided the same
8096 -- for backward compatibility purpose with bug# 1869241.
8097 -- Issue with invoice interface due the the missing wf function is reported in bug# 1868026.
8098 RETURN( WF_ENGINE.Activity_Exist_In_Process(
8099 p_item_type => OE_GLOBALS.G_WFI_LIN
8100 ,p_item_key => to_char(p_line_id)
8101 ,p_activity_name => 'INVOICE_INTERFACE'));
8102 END Line_Activity;
8103
8104 FUNCTION Update_Invoice_Numbers
8105 ( p_del_id IN NUMBER
8106 , p_del_name IN VARCHAR2
8107 )RETURN NUMBER IS
8108 inv_num_index NUMBER;
8109 inv_num_base VARCHAR2(40);
8110 err_msg VARCHAR2(240);
8111 --
8112 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8113 --
8114 BEGIN
8115 IF l_debug_level > 0 THEN
8116 oe_debug_pub.add( 'ENTER UPDATE_INVOICE_NUMBERS ( ) PROCEDURE ' , 5 ) ;
8117 oe_debug_pub.add( 'UPDATE INVOICE NUMBERS: DEL_ID ' || TO_CHAR ( P_DEL_ID ) ||' DEL NAME: ' || P_DEL_NAME , 5 ) ;
8118 END IF;
8119 inv_num_base := p_del_name;
8120 SELECT nvl((max(index_number)+1), 0)
8121 INTO inv_num_index
8122 FROM oe_invoice_numbers
8123 WHERE delivery_id = p_del_id;
8124 IF ( SQL%NOTFOUND ) THEN
8125 inv_num_index := 1;
8126 END IF;
8127 IF ( inv_num_index = 0 ) THEN
8128 inv_num := inv_num_base;
8129 ELSE
8130 inv_num := inv_num_base || '-' || to_char(inv_num_index);
8131 END IF;
8132 IF l_debug_level > 0 THEN
8133 oe_debug_pub.add( 'GLOBAL USER ' || NVL(oe_standard_wf.g_user_id, fnd_global.user_id)); -- 3169637
8134 oe_debug_pub.add( 'INV NUM INDEX ' || TO_CHAR ( INV_NUM_INDEX ) ) ;
8135 END IF;
8136 INSERT INTO OE_INVOICE_NUMBERS(
8137 INVOICE_NUMBER_ID
8138 , DELIVERY_ID
8139 , INDEX_NUMBER
8140 , LAST_UPDATE_DATE
8141 , LAST_UPDATED_BY
8142 , CREATION_DATE
8143 , CREATED_BY)
8144 VALUES
8145 ( oe_invoice_numbers_s.nextval
8146 , p_del_id
8147 , inv_num_index
8148 , SYSDATE
8149 , NVL(oe_standard_wf.g_user_id, fnd_global.user_id) -- 3169637
8150 , SYSDATE
8151 , NVL(oe_standard_wf.g_user_id, fnd_global.user_id)); -- 3169637
8152
8153 IF l_debug_level > 0 THEN
8154 oe_debug_pub.add( 'DONE UPDATE_INVOICE_NUMBERS W/SUCCESS' , 5 ) ;
8155 END IF;
8156 RETURN 0;
8157 EXCEPTION
8158 WHEN OTHERS THEN
8159 err_msg := 'Error in update_invoice_numbers:\n '||SQLERRM;
8160 IF l_debug_level > 0 THEN
8161 oe_debug_pub.add( ERR_MSG ) ;
8162 oe_debug_pub.add( 'WHEN OTHERS :EXITING UPDATE_INVOICE_NUMBERS' , 1 ) ;
8163 END IF;
8164 RETURN -1;
8165 END Update_Invoice_Numbers;
8166
8167 PROCEDURE Update_Numbers
8168 ( p_id IN NUMBER
8169 , x_return_status OUT NOCOPY VARCHAR2
8170 ) IS
8171 l_count NUMBER := 0;
8172 group_col_clause varchar2(10000) := '';
8173 select_col varchar2(10000) := '';
8174 col_name varchar2(100) ;
8175 grp_stmt varchar2(20000);
8176 col_length NUMBER;
8177 group_cursor INTEGER;
8178 rows_processed INTEGER;
8179
8180 last_concat_cols varchar2(5000) := '';
8181 this_concat_cols varchar2(5000) := '';
8182
8183 last_del_name varchar2(30) := '';
8184 this_del_name varchar2(30) := '';
8185 this_del_id Number;
8186 this_rowid Varchar2(20);
8187 err_msg VARCHAR2(240);
8188
8189 Type DelCurType IS REF CURSOR;
8190 del_cursor DelCurType;
8191 CURSOR cur_get_cols IS
8192 SELECT upper(c.from_column_name), c.from_column_length
8193 FROM ra_group_by_columns c
8194 WHERE c.column_type = 'M';
8195
8196 CURSOR cur_get_del_id (p_del_name IN VARCHAR2) IS
8197 SELECT delivery_id
8198 FROM wsh_new_deliveries
8199 WHERE name = p_del_name;
8200 --
8201 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8202 --
8203 BEGIN
8204 IF l_debug_level > 0 THEN
8205 oe_debug_pub.add( 'ENTER UPDATE_NUMBERS ( ) PROCEDURE' , 5 ) ;
8206 END IF;
8207 SELECT count(*)
8208 INTO l_count
8209 FROM ra_interface_lines_all
8210 WHERE request_id = -1 * p_id;
8211
8212 IF l_count = 0 THEN
8213 IF l_debug_level > 0 THEN
8214 oe_debug_pub.add( 'NO LINES NEED MANUAL NUMBERING' , 5 ) ;
8215 END IF;
8216 x_return_status := FND_API.G_RET_STS_SUCCESS;
8217 RETURN;
8218 END IF;
8219 -- Get all the group by columns from ra_group_by_columns table
8220 -- and build up the select and group by column clauses.
8221 OPEN cur_get_cols;
8222 LOOP
8223 FETCH cur_get_cols Into col_name, col_length;
8224 EXIT WHEN cur_get_cols%NOTFOUND;
8225 IF ( group_col_clause is NULL ) THEN
8226 group_col_clause := col_name;
8227 select_col := col_name;
8228 select_col := col_name;
8229 ELSE
8230 group_col_clause := group_col_clause || ', ' || col_name;
8231 select_col := select_col || '||' || '''~'''|| '||'|| col_name;
8232 END IF;
8233 END LOOP;
8234 CLOSE cur_get_cols;
8235 IF l_debug_level > 0 THEN
8236 oe_debug_pub.add( 'POSITION 2' ) ;
8237 -- Build the full select statement and using dbms_sql execute
8238 -- the statement
8239 oe_debug_pub.add( 'POSITION 2-1' ) ;
8240 END IF;
8241 grp_stmt := 'Select ' || select_col || ' group_cols,' ||
8242 ' l.interface_line_attribute3, ROWID ' ||
8243 ' From RA_INTERFACE_LINES_ALL L' ||
8244 ' Where trx_number is NULL' ||
8245 ' And request_id = :p' ||
8246 ' Order by ' || group_col_clause ||
8247 ' , l.interface_line_attribute3, l.org_id' ;
8248 OPEN del_cursor FOR grp_stmt USING (-1 * p_id);
8249 LOOP
8250 FETCH del_cursor INTO this_concat_cols, this_del_name, this_rowid;
8251 EXIT WHEN del_cursor%NOTFOUND;
8252 IF l_debug_level > 0 THEN
8253 oe_debug_pub.add( 'DELIVERY NAME: ' || THIS_DEL_NAME , 5 ) ;
8254 oe_debug_pub.add( 'CONCAT COLS: ' || THIS_CONCAT_COLS , 5 ) ;
8255 END IF;
8256 IF ( last_del_name is NULL OR
8257 last_del_name <> this_del_name ) THEN
8258 IF l_debug_level > 0 THEN
8259 oe_debug_pub.add( 'POSITION 5' ) ;
8260 END IF;
8261 OPEN cur_get_del_id(this_del_name);
8262 FETCH cur_get_del_id Into this_del_id;
8263 IF (cur_get_del_id%NOTFOUND ) THEN
8264 fnd_message.set_token('DELIVERY_NAME', this_del_name);
8265 fnd_message.set_name('OE', 'WSH_AR_INVALID_DEL_NAME');
8266 err_msg := fnd_message.get;
8267 IF l_debug_level > 0 THEN
8268 oe_debug_pub.add( ERR_MSG ) ;
8269 END IF;
8270 CLOSE cur_get_del_id;
8271 --return;
8272 END IF;
8273 IF ( cur_get_del_id%ISOPEN ) THEN
8274 Close cur_get_del_id;
8275 END IF;
8276 IF l_debug_level > 0 THEN
8277 oe_debug_pub.add( 'DELIVERY ID: ' || TO_CHAR ( THIS_DEL_ID ) , 5 ) ;
8278 END IF;
8279 END IF;
8280 IF ( last_concat_cols is NULL OR
8281 last_concat_cols <> this_concat_cols ) THEN
8282 IF l_debug_level > 0 THEN
8283 oe_debug_pub.add( 'CONCAT COLS CHANGED , CALLING UPDATE_INVOICE' ) ;
8284 END IF;
8285 IF ( Update_Invoice_Numbers ( this_del_id, this_del_name) < 0 ) THEN
8286 x_return_status := FND_API.G_RET_STS_SUCCESS;
8287 RETURN;
8288 END IF;
8289 last_del_name := this_del_name;
8290 last_concat_cols := this_concat_cols;
8291 ELSE
8292 IF ( last_del_name <> this_del_name ) THEN
8293 IF l_debug_level > 0 THEN
8294 oe_debug_pub.add( 'DEL NAME CHANGED , CALLING UPDATE_INVOICE' ) ;
8295 END IF;
8296 IF ( update_invoice_numbers ( this_del_id, this_del_name) < 0 ) THEN
8297 x_return_status := FND_API.G_RET_STS_SUCCESS;
8298 RETURN;
8299 END IF;
8300 last_del_name := this_del_name;
8301 END IF;
8302 END IF;
8303 IF l_debug_level > 0 THEN
8304 oe_debug_pub.add( 'TRANSACTION NUMBER IS : '|| INV_NUM , 5 ) ;
8305 END IF;
8306 Update RA_INTERFACE_LINES_ALL
8307 set trx_number = substr(inv_num,1,20) -- substr(inv_num,20)--inv_num --bug#7592350 -- Bug 8216166
8308 where rowid = chartorowid(this_rowid);
8309 END LOOP;
8310 CLOSE del_cursor;
8311 IF l_debug_level > 0 THEN
8312 oe_debug_pub.add( 'SETTING REQUEST ID TO NULL' , 5 ) ;
8313 END IF;
8314 update ra_interface_lines_all
8315 set request_id=null
8316 where request_id = -1 * p_id;
8317 x_return_status := FND_API.G_RET_STS_SUCCESS;
8318 IF l_debug_level > 0 THEN
8319 oe_debug_pub.add( 'EXITING UPDATE_NUMBERS ( ) PROCEDURE' , 5 ) ;
8320 END IF;
8321 RETURN;
8322 EXCEPTION
8323 WHEN OTHERS THEN
8324 IF l_debug_level > 0 THEN
8325 oe_debug_pub.add( 'ORACLE ERROR: ' || SQLERRM , 1 ) ;
8326 END IF;
8327 err_msg := 'Error in update_numbers:\n '|| SQLERRM;
8328 IF l_debug_level > 0 THEN
8329 oe_debug_pub.add( ERR_MSG ) ;
8330 END IF;
8331 x_return_status := FND_API.G_RET_STS_ERROR;
8332 IF (cur_get_cols%ISOPEN) THEN
8333 CLOSE cur_get_cols;
8334 END IF;
8335 IF (cur_get_del_id%ISOPEN) THEN
8336 CLOSE cur_get_del_id;
8337 END IF;
8338 IF l_debug_level > 0 THEN
8339 oe_debug_pub.add( 'EXITING UPDATE_NUMBERS' , 1 ) ;
8340 END IF;
8341 RETURN;
8342 IF l_debug_level > 0 THEN
8343 oe_debug_pub.add( 'EXITING UPDATE_NUMBERS' , 1 ) ;
8344 END IF;
8345 END Update_Numbers;
8346
8347 PROCEDURE Interface_Single_Line
8348 ( p_line_rec IN OE_Order_PUB.Line_Rec_Type
8349 , p_header_rec IN OE_Order_PUB.Header_Rec_Type
8350 , p_x_interface_line_rec IN OUT NOCOPY RA_Interface_Lines_Rec_Type
8351 , x_return_status OUT NOCOPY VARCHAR2
8352 , x_result_out OUT NOCOPY VARCHAR2
8353 ) IS
8354 --gaynagar
8355 l_freight_count NUMBER;
8356
8357 CURSOR Pending_Lines IS
8358 SELECT Line.line_id --SQL# 16487863 Added the UNION clause to avoid FTS
8359 FROM oe_order_lines Line
8360 WHERE (Line.link_to_line_id = p_line_rec.link_to_line_id)
8361 AND invoice_interface_status_code = 'RFR-PENDING'
8362 UNION
8363 SELECT Line.line_id
8364 FROM oe_order_lines Line
8365 WHERE (Line.line_id = p_line_rec.link_to_line_id)
8366 AND invoice_interface_status_code = 'RFR-PENDING';
8367
8368 l_pending_line_id NUMBER;
8369 l_pending_line_rec OE_Order_Pub.Line_Rec_Type;
8370
8371 l_result_code VARCHAR2(240);
8372 l_return_status VARCHAR2(30);
8373 --Customer Acceptance
8374 l_line_invoiceable BOOLEAN;
8375 l_line_rejected BOOLEAN;
8376
8377 --
8378 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8379 --
8380 -- sol_ord_er #16014165
8381 l_inv_stat varchar2(50) := '';
8382 BEGIN
8383 IF l_debug_level > 0 THEN
8384 oe_debug_pub.add( 'ENTERING INTERFACE_SINGLE_LINE ( ) PROCEDURE' , 5 ) ;
8385 oe_debug_pub.add( 'INTERFACING LINE ID '||TO_CHAR ( P_LINE_REC.LINE_ID ) , 1 ) ;
8386 END IF;
8387 x_return_status := FND_API.G_RET_STS_SUCCESS;
8388 --Customer Acceptance
8389 l_line_invoiceable := Line_Invoiceable(p_line_rec);
8390 l_line_rejected := Line_Rejected(p_line_rec);
8391
8392 --gaynagar added code for handling non-invoiceable lines
8393 -- IF NOT Line_Invoiceable(p_line_rec) THEN
8394 IF NOT l_line_invoiceable OR l_line_rejected THEN --Customer Acceptance
8395 oe_debug_pub.add('Line is non invoiceable',1);
8396 /* Bug#2666125 start-check freight records and holds for non invoiceable items*/
8397 /* BEGIN
8398 IF oe_code_control.code_release_level < '110510' then
8399 SELECT count(*)
8400 INTO l_freight_count
8401 FROM oe_price_adjustments p
8402 WHERE p.header_id = p_line_rec.header_id
8403 AND (p.line_id IS NULL OR p.line_id = p_line_rec.line_id)
8404 AND p.list_line_type_code = 'FREIGHT_CHARGE'
8405 AND p.applied_flag = 'Y'
8406 AND NVL(p.invoiced_flag, 'N') = 'N';
8407 ELSE
8408 SELECT count(*)
8409 INTO l_freight_count
8410 FROM oe_price_adjustments p
8411 WHERE p.header_id = p_line_rec.header_id
8412 AND p.line_id IS NULL
8413 AND p.list_line_type_code = 'FREIGHT_CHARGE'
8414 AND p.applied_flag = 'Y'
8415 AND (NVL(p.invoiced_flag, 'N') = 'N' OR (NVL(p.invoiced_flag, 'N') = 'Y' AND p.adjusted_amount <> nvl(p.invoiced_amount, p.adjusted_amount)));
8416 IF l_freight_count = 0 then
8417 SELECT count(*)
8418 INTO l_freight_count
8419 FROM oe_price_adjustments p
8420 WHERE p.header_id = p_line_rec.header_id
8421 AND p.line_id = p_line_rec.line_id
8422 AND p.list_line_type_code = 'FREIGHT_CHARGE'
8423 AND p.applied_flag = 'Y'
8424 AND NVL(p.invoiced_flag, 'N') = 'N';
8425 END IF;
8426 END IF;
8427
8428 EXCEPTION
8429 WHEN NO_DATA_FOUND THEN
8430 IF l_debug_level > 0 THEN
8431 oe_debug_pub.add('Non-invoiceable lines-In when no data found of freight');
8432 END IF;
8433 l_freight_count := 0;
8434 END;
8435 IF l_debug_level > 0 THEN
8436 oe_debug_pub.add('l_freight_count: '||l_freight_count);
8437 END IF;
8438 IF l_freight_count >0 then
8439 Check_Invoicing_Holds(p_line_rec, g_itemtype, x_return_status);
8440 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8441 x_result_out := OE_GLOBALS.G_WFR_ON_HOLD;
8442 RAISE FND_API.G_EXC_ERROR;
8443 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8444 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8445 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8446 END IF;
8447 END IF; */
8448 /* Bug#2666125 end-check freight records and holds for non invoiceable items*/
8449
8450 -- sol_ord_er #16014165
8451 --Set Status as Billed from Contracts
8452 IF p_line_rec.service_bill_option_code = 'FBOKS' THEN
8453 l_inv_stat := 'BILLED_FROM_CONTRACTS';
8454 Else
8455 l_inv_stat := 'NOT_ELIGIBLE';
8456 End If;
8457 -- sol_ord_er #16014165 end
8458 Update_Invoice_Attributes(p_line_rec
8459 ,p_x_interface_line_rec
8460 --,'NOT_ELIGIBLE' --sol_ord_er #16014165
8461 ,l_inv_stat --sol_ord_er #16014165
8462 ,x_return_status);
8463 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8464 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8465 RAISE FND_API.G_EXC_ERROR;
8466 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8467 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8468 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8469 END IF;
8470 --- Eventhough line is not eligible for invoicing, there might be some other
8471 --- lines that are waiting for this line to trigger their invoicing activity.
8472 --- Ex: Included Items are not invoiceable but due to RFR, there might be
8473 --- some lines in RFR-PENDING block. We should invoice them.
8474 IF Is_PTO(p_line_rec) THEN
8475 IF Is_RFR(p_line_rec.line_id) THEN
8476 IF l_debug_level > 0 THEN
8477 oe_debug_pub.add( 'RFR: THIS LINE IS RFR BUT NOT ELIGIBLE FOR INVOICING- CHECKING FOR PENDING LINES' , 5 ) ;
8478 END IF;
8479 Open Pending_Lines;
8480 LOOP
8481 Fetch Pending_Lines Into l_pending_line_id;
8482 EXIT WHEN Pending_Lines%NOTFOUND;
8483 OE_Line_Util.Query_Row(p_line_id=>l_pending_line_id,x_line_rec=>l_pending_line_rec);
8484 IF l_debug_level > 0 THEN
8485 oe_debug_pub.add( 'RFR: PENDING LINE ID : ' || TO_CHAR ( L_PENDING_LINE_ID ) , 5 ) ;
8486 END IF;
8487 IF Something_To_Invoice(l_pending_line_rec) THEN -- the pending line now has something to
8488 -- invoice because current line has been shipped
8489 IF l_debug_level > 0 THEN
8490 oe_debug_pub.add( 'RFR: INTERFACING PENDING LINE ID :'||L_PENDING_LINE_ID , 5 ) ;
8491 END IF;
8492 Interface_Single_line(p_line_rec => l_pending_line_rec
8493 ,p_header_rec => p_header_rec
8494 ,p_x_interface_line_rec => p_x_interface_line_rec
8495 ,x_return_status => x_return_status
8496 ,x_result_out => x_result_out);
8497 IF l_debug_level > 0 THEN
8498 oe_debug_pub.add( 'INTERFACING PENDING LINE ID ' || L_PENDING_LINE_REC.LINE_ID , 5 ) ;
8499 END IF;
8500 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8501 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8502 RAISE FND_API.G_EXC_ERROR;
8503 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8504 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8505 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8506 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8507 IF x_result_out = OE_GLOBALS.G_WFR_PRTL_COMPLETE THEN
8508 IF l_debug_level > 0 THEN
8509 oe_debug_pub.add( 'RFR PENDING LINE PARTIALLY INTERFACED' , 5 ) ;
8510 END IF;
8511 ELSE --x_result_out = OE_GLOBALS.G_WFR_COMPLETE THEN
8512 IF l_debug_level > 0 THEN
8513 oe_debug_pub.add( 'RFR-PENDING LINE INTERFACED SUCCESSFULLY' , 5 ) ;
8514 END IF;
8515 WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_LIN, l_pending_line_rec.line_id, 'INVOICING_WAIT_FOR_RFR', 'COMPLETE');
8516 END IF;
8517 END IF;
8518 END IF;
8519 END LOOP;
8520 close Pending_Lines;
8521 END IF; -- itself is a RFR line
8522 END IF; -- PTO line
8523 --freight line rec info comes from interface line rec. so prepare interface line rec
8524 /* START Enhancement Request# 1915736 */
8525 -- Prepare interface line rec only if there are any freight charges to interface (Enhancement Request# 1915736)
8526 IF NOT l_line_rejected THEN --Customer Acceptance
8527 BEGIN
8528
8529 IF oe_code_control.code_release_level < '110510' then
8530 SELECT count(*)
8531 INTO l_freight_count
8532 FROM oe_price_adjustments p
8533 WHERE p.header_id = p_line_rec.header_id
8534 AND (p.line_id IS NULL OR p.line_id = p_line_rec.line_id)
8535 AND p.list_line_type_code = 'FREIGHT_CHARGE'
8536 AND p.applied_flag = 'Y'
8537 AND NVL(p.invoiced_flag, 'N') = 'N'
8538 AND NVL(p_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
8539 ELSE
8540 SELECT count(*)
8541 INTO l_freight_count
8542 FROM oe_price_adjustments p
8543 WHERE p.header_id = p_line_rec.header_id
8544 AND p.line_id IS NULL
8545 AND p.list_line_type_code = 'FREIGHT_CHARGE'
8546 AND p.applied_flag = 'Y'
8547 AND (NVL(p.invoiced_flag, 'N') = 'N' OR (NVL(p.invoiced_flag, 'N') = 'Y' AND p.adjusted_amount <> nvl(p.invoiced_amount, p.adjusted_amount)))
8548 AND NVL(p_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
8549 IF l_freight_count = 0 then
8550 SELECT count(*)
8551 INTO l_freight_count
8552 FROM oe_price_adjustments p
8553 WHERE p.header_id = p_line_rec.header_id
8554 AND p.line_id = p_line_rec.line_id
8555 AND p.list_line_type_code = 'FREIGHT_CHARGE'
8556 AND p.applied_flag = 'Y'
8557 AND NVL(p.invoiced_flag, 'N') = 'N'
8558 AND NVL(p_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
8559 END IF;
8560 END IF;
8561
8562 EXCEPTION
8563 WHEN NO_DATA_FOUND THEN
8564 IF l_debug_level > 0 THEN
8565 oe_debug_pub.add( 'IN WHEN NO DATA FOUND OF FREIGHT' ) ;
8566 END IF;
8567 l_freight_count := 0;
8568 END;
8569 IF l_debug_level > 0 THEN
8570 oe_debug_pub.add( 'L_FREIGHT_COUNT: '||L_FREIGHT_COUNT ) ;
8571 END IF;
8572 IF l_freight_count > 0 THEN
8573 /* END Enhancement Request# 1915736 */
8574 IF l_debug_level > 0 THEN
8575 oe_debug_pub.add( 'PREPARING INTERFACE LINE RECORD' , 5 ) ;
8576 END IF;
8577
8578 Prepare_Interface_Line_Rec(p_line_rec => p_line_rec
8579 ,p_header_rec => p_header_rec
8580 ,p_x_interface_line_rec => p_x_interface_line_rec
8581 ,x_result_code => l_result_code);
8582 IF l_debug_level > 0 THEN
8583 oe_debug_pub.add( 'VALIDATING REQUIRED ATTRIBUTES' , 5 ) ;
8584 END IF;
8585 IF NOT Validate_Required_Attributes(p_line_rec, p_x_interface_line_rec) THEN
8586 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8587 RAISE FND_API.G_EXC_ERROR;
8588 END IF;
8589 IF l_debug_level > 0 THEN
8590 oe_debug_pub.add( 'INTERFACING FREIGHT CHARGES' , 5 ) ;
8591 END IF;
8592 Interface_Freight_Charges(p_line_rec
8593 , p_x_interface_line_rec
8594 , x_return_status);
8595 /* START Enhancement Request# 1915736 */
8596 END IF; -- for freight
8597 /* END Enhancement Request# 1915736 */
8598 END IF; -- for Non-rejected_lines Customer Acceptance
8599
8600 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8601 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8602 RAISE FND_API.G_EXC_ERROR;
8603 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8604 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8605 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8606 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8607 -- sol_ord_er #16014165
8608 If l_inv_stat = OE_GLOBALS.G_CONTRACTS_BILLED then
8609 x_result_out := OE_GLOBALS.G_CONTRACTS_BILLED;
8610 else
8611 -- sol_ord_er #16014165 end
8612 x_result_out := OE_GLOBALS.G_WFR_NOT_ELIGIBLE;
8613 end if; --sol_ord_er #16014165
8614 IF l_debug_level > 0 THEN
8615 oe_debug_pub.add( 'RETURN AFTER INVOICEABLE ELIGIBLE CHECK' , 1 ) ;
8616 END IF;
8617 --Customer Acceptance
8618 IF l_line_rejected AND p_line_rec.line_category_code = 'RETURN' THEN
8619 FND_MESSAGE.SET_NAME('ONT','ONT_RMA_NO_CREDIT');
8620 OE_MSG_PUB.ADD;
8621 END IF;
8622 --Customer Acceptance
8623 RETURN;
8624 END IF;
8625 END IF;
8626 --gaynagar end
8627
8628 IF l_debug_level > 0 THEN
8629 oe_debug_pub.add( 'PREPARING INTERFACE LINE RECORD' , 5 ) ;
8630 END IF;
8631 Prepare_Interface_Line_Rec(p_line_rec => p_line_rec
8632 ,p_header_rec => p_header_rec
8633 ,p_x_interface_line_rec => p_x_interface_line_rec
8634 ,x_result_code => l_result_code);
8635 IF l_debug_level > 0 THEN
8636 oe_debug_pub.add( 'REQUEST_ID: '||P_X_INTERFACE_LINE_REC.REQUEST_ID || ' RESULT_CODE: '||L_RESULT_CODE , 5 ) ;
8637 END IF;
8638 IF ((p_x_interface_line_rec.QUANTITY = 0 OR p_x_interface_line_rec.QUANTITY IS NULL) AND l_result_code = 'RFR-PENDING') THEN
8639 IF l_debug_level > 0 THEN
8640 oe_debug_pub.add( 'ZERO QUANTITY LINE - NOT INTERFACED' , 5 ) ;
8641 oe_debug_pub.add( 'UPDATING INVOICE FLAG AND QUANTITY' , 5 ) ;
8642 END IF;
8643 IF l_result_code = 'RFR-PENDING' THEN
8644 Update_Invoice_Attributes(p_line_rec
8645 ,p_x_interface_line_rec
8646 ,'RFR-PENDING'
8647 ,x_return_status);
8648 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
8649 FND_MESSAGE.SET_NAME('ONT','OE_INVOICE_WAIT_FOR_RFR');
8650 OE_MSG_PUB.ADD;
8651 END IF;
8652 END IF;
8653 IF l_debug_level > 0 THEN
8654 oe_debug_pub.add( 'REQUEST_ID AFTER INSERTING '||P_X_INTERFACE_LINE_REC.REQUEST_ID , 5 ) ;
8655 END IF;
8656 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8657 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8658 RAISE FND_API.G_EXC_ERROR;
8659 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8660 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8661 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8662 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8663 IF l_result_code = 'RFR-PENDING' THEN
8664 x_result_out := OE_GLOBALS.G_WFR_PRTL_COMPLETE;
8665 IF l_debug_level > 0 THEN
8666 oe_debug_pub.add( 'LINE ID '||TO_CHAR ( P_LINE_REC.LINE_ID ) ||' PARTIALLY INTERFACED SUCCESSFULLY ' || 'X_RESULT_OUT: '||X_RESULT_OUT ||' L_RESULT_CODE '||L_RESULT_CODE ) ;
8667 END IF;
8668 IF l_debug_level > 0 THEN
8669 oe_debug_pub.add( 'EXITING INTERFACE_SINGLE_LINE' , 5 ) ;
8670 END IF;
8671 RETURN; --Do not need to interface this line
8672 END IF;
8673 END IF;
8674 IF l_debug_level > 0 THEN
8675 oe_debug_pub.add( 'EXIT INTERFACE_SINGLE_LINE ( ) PROCEDURE ( 1 ) ' , 1 ) ;
8676 END IF;
8677 RETURN; --Do not need to interface this line
8678 END IF; -- Zero invoice quantity RFR
8679 IF l_debug_level > 0 THEN
8680 oe_debug_pub.add( 'VALIDATE REQUIRED ATTRIBUTES' , 5 ) ;
8681 END IF;
8682 IF NOT Validate_Required_Attributes(p_line_rec, p_x_interface_line_rec) THEN
8683 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8684 RAISE FND_API.G_EXC_ERROR;
8685 END IF;
8686 IF l_debug_level > 0 THEN
8687 oe_debug_pub.add( 'INSERTING LINE INTO RA_INTERFACE_LINES' , 5 ) ;
8688 END IF;
8689 Insert_Line(p_x_interface_line_rec
8690 ,x_return_status=>l_return_status);
8691 -- Fix for the bug 2187074
8692 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8693 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8694 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8695 END IF;
8696
8697 -- 3685479 Replacing show detail dis by the following IF
8698 -- Adjustments need not be queried here as it is anyway going to be queried in interface_detail_discounts
8699 IF (oe_sys_parameters.value('OE_DISCOUNT_DETAILS_ON_INVOICE',p_line_rec.org_id) = 'Y'
8700 AND NVL(p_line_rec.service_bill_option_code,'FBOM') = 'FBOM') THEN --moac --sol_ord_er #16014165
8701 IF l_debug_level > 0 THEN
8702 oe_debug_pub.add( 'INSERTING DISCOUNT DETAILS' , 5 ) ;
8703 END IF;
8704 Interface_Detail_Discounts(p_line_rec, p_x_interface_line_rec
8705 ,x_return_status);
8706 -- Fix for the bug 2187074
8707 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8708 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8709 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8710 END IF;
8711 END IF;
8712 IF l_debug_level > 0 THEN
8713 oe_debug_pub.add( 'INTERFACING FREIGHT CHARGES' , 5 ) ;
8714 END IF;
8715 /* Freight will be interfaced only if Billing is completely from OM */
8716 If (NVL(p_line_rec.service_bill_option_code,'FBOM') = 'FBOM') THEN -- sol_ord_er #16014165
8717 Interface_Freight_Charges(p_line_rec
8718 , p_x_interface_line_rec
8719 , x_return_status);
8720 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8721 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8722 RAISE FND_API.G_EXC_ERROR;
8723 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8724 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8725 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8726 END IF;
8727 --sol_ord_er #16014165 start
8728 Else
8729 IF l_debug_level > 0 THEN
8730 oe_debug_pub.add( 'FREIGHT CHARGES will not be interfaced as Billing Option= '||p_line_rec.service_bill_option_code , 5 ) ;
8731 END IF;
8732 End If;
8733 --sol_ord_er #16014165 end
8734 IF l_debug_level > 0 THEN
8735 oe_debug_pub.add( 'INTERFACING SALES CREDITS' , 5 ) ;
8736 END IF;
8737 Interface_Salescredits(p_line_rec
8738 ,p_x_interface_line_rec
8739 ,x_return_status);
8740 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8741 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8742 RAISE FND_API.G_EXC_ERROR;
8743 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8744 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8745 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8746 END IF;
8747
8748 --Customer Acceptance
8749 IF l_debug_level > 0 THEN
8750 oe_debug_pub.add( 'INTERFACING Contingencies' , 5 ) ;
8751 END IF;
8752 Interface_Contingencies
8753 ( p_line_rec => p_line_rec
8754 , p_interface_line_rec => p_x_interface_line_rec
8755 , x_return_status => x_return_status
8756 );
8757
8758 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8759 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8760 END IF;
8761 --Customer Acceptance
8762
8763 IF l_debug_level > 0 THEN
8764 oe_debug_pub.add( 'UPDATING INVOICE FLAG AND QUANTITY' , 5 ) ;
8765 END IF;
8766 IF l_result_code = 'RFR-PENDING' THEN
8767 Update_Invoice_Attributes(p_line_rec
8768 ,p_x_interface_line_rec
8769 ,'RFR-PENDING'
8770 ,x_return_status);
8771 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
8772 FND_MESSAGE.SET_NAME('ONT','OE_INVOICE_WAIT_FOR_RFR');
8773 OE_MSG_PUB.ADD;
8774 END IF;
8775 ELSE
8776 Update_Invoice_Attributes(p_line_rec
8777 ,p_x_interface_line_rec
8778 ,'YES'
8779 ,x_return_status);
8780 END IF;
8781 IF l_debug_level > 0 THEN
8782 oe_debug_pub.add( 'REQUEST_ID AFTER INSERTING '||P_X_INTERFACE_LINE_REC.REQUEST_ID ) ;
8783 END IF;
8784 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
8785 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8786 RAISE FND_API.G_EXC_ERROR;
8787 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8788 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
8789 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8790 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8791 IF l_result_code = 'RFR-PENDING' THEN
8792 x_result_out := OE_GLOBALS.G_WFR_PRTL_COMPLETE;
8793 IF l_debug_level > 0 THEN
8794 oe_debug_pub.add( 'LINE ID '||TO_CHAR ( P_LINE_REC.LINE_ID ) ||' PARTIALLY INTERFACED SUCCESSFULLY' , 1 ) ;
8795 END IF;
8796 ELSE
8797 x_result_out := OE_GLOBALS.G_WFR_COMPLETE;
8798 IF l_debug_level > 0 THEN
8799 oe_debug_pub.add( 'LINE ID '||TO_CHAR ( P_LINE_REC.LINE_ID ) ||' INTERFACED SUCCESSFULLY' , 1 ) ;
8800 END IF;
8801 END IF;
8802 END IF;
8803
8804 IF l_debug_level > 0 THEN
8805 oe_debug_pub.add( 'EXIT INTERFACE_SINGLE_LINE ( ) PROCEDURE SUCCESSFULLY' , 1 ) ;
8806 END IF;
8807 EXCEPTION
8808 WHEN FND_API.G_EXC_ERROR THEN
8809 IF l_debug_level > 0 THEN
8810 oe_debug_pub.add( 'EXPECTED ERROR. EXITING INTERFACE_SINGLE_LINE : '||SQLERRM , 1 ) ;
8811 END IF;
8812 x_return_status := FND_API.G_RET_STS_ERROR;
8813 IF l_debug_level > 0 THEN
8814 oe_debug_pub.add( 'RETURN STATUS :'||X_RETURN_STATUS||' OUT RESULT : '||X_RESULT_OUT , 5 ) ;
8815 END IF;
8816 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8817 IF l_debug_level > 0 THEN
8818 oe_debug_pub.add( 'UNEXPECTED ERROR. EXITING INTERFACE_SINGLE_LINE '||SQLERRM , 1 ) ;
8819 oe_debug_pub.add( 'RETURN STATUS :'||X_RETURN_STATUS||' OUT RESULT : '||X_RESULT_OUT , 5 ) ;
8820 END IF;
8821 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8822 WHEN OTHERS THEN
8823 IF l_debug_level > 0 THEN
8824 oe_debug_pub.add( 'OTHER EXCEPTION. EXITING INTERFACE_SINGLE_LINE : '||SQLERRM , 1 ) ;
8825 oe_debug_pub.add( 'RETURN STATUS :'||X_RETURN_STATUS||' OUT RESULT : '||X_RESULT_OUT , 5 ) ;
8826 END IF;
8827 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8828 OE_MSG_PUB.Add_Exc_Msg
8829 ( G_PKG_NAME
8830 , 'Interface_Single_line'
8831 );
8832 END IF;
8833 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8834 END Interface_Single_line;
8835
8836 PROCEDURE Interface_Line
8837 ( p_line_id IN NUMBER
8838 , p_itemtype IN VARCHAR2
8839 , x_result_out OUT NOCOPY VARCHAR2
8840 , x_return_status OUT NOCOPY VARCHAR2
8841 ) IS
8842 l_interface_line_rec RA_Interface_Lines_Rec_Type;
8843 l_line_rec OE_Order_Pub.Line_Rec_Type;
8844 l_header_rec OE_Order_Pub.Header_Rec_Type;
8845 l_dummy VARCHAR2(240);
8846 l_delivery_line_id NUMBER := NULL;
8847 l_line_delivery_id NUMBER := NULL;
8848 l_line_id NUMBER;
8849 l_interface_status_code VARCHAR2(30);
8850 l_old_interface_status_code VARCHAR2(30);
8851 l_pending_line_id NUMBER;
8852 l_pending_line_rec OE_Order_Pub.Line_Rec_Type;
8853 del_line_ready_flag VARCHAR2(1) := NULL;
8854 interface_this_line VARCHAR2(1) := 'Y';
8855 l_result_code VARCHAR2(240);
8856 generate_invoice_number VARCHAR2(1) := 'N';
8857 x_msg_count NUMBER;
8858 x_msg_data VARCHAR2(240);
8859 p_header_id NUMBER := NULL;
8860 l_return_status VARCHAR2(30);
8861 l_open_flag VARCHAR2(1);
8862 l_flow_status_code VARCHAR2(30);
8863 /* START Enhancement Request# 1915736 */
8864 l_freight_count NUMBER;
8865 /* END Enhancement Request# 1915736 */
8866 -- Fix for bug 2224248
8867 l_invoice_rec OE_Order_Pub.Line_Rec_Type;
8868 --Customer Acceptance
8869 l_line_invoiceable BOOLEAN;
8870 l_line_rejected BOOLEAN;
8871
8872 -- Fix for the bug 2196494
8873 CURSOR delivery_lines_cursor(p_delivery_id IN NUMBER) IS
8874 SELECT distinct dd.source_line_id
8875 FROM wsh_new_deliveries dl,
8876 wsh_delivery_assignments da,
8877 wsh_delivery_details dd
8878 WHERE dd.delivery_detail_id = da.delivery_detail_id
8879 AND da.delivery_id = dl.delivery_id
8880 AND dd.source_code = 'OE'
8881 AND dl.delivery_id = p_delivery_id
8882 AND dd.source_line_id is not null
8883 UNION ALL
8884 SELECT distinct dd.top_model_line_id
8885 FROM wsh_new_deliveries dl,
8886 wsh_delivery_assignments da,
8887 wsh_delivery_details dd
8888 WHERE dd.delivery_detail_id = da.delivery_detail_id
8889 AND da.delivery_id = dl.delivery_id
8890 AND dd.source_code = 'OE'
8891 AND dl.delivery_id = p_delivery_id
8892 AND dd.top_model_line_id is not null;
8893
8894 CURSOR cur1(p_delivery_id IN NUMBER) IS -- added for 4084965
8895 SELECT 'x'
8896 FROM wsh_new_deliveries dl,
8897 wsh_delivery_assignments da,
8898 wsh_delivery_details dd
8899 WHERE dd.delivery_detail_id = da.delivery_detail_id
8900 AND da.delivery_id = dl.delivery_id
8901 AND dd.source_code = 'OE'
8902 AND dl.delivery_id = p_delivery_id
8903 AND (dd.source_line_id is not null OR
8904 dd.top_model_line_id is not null)
8905 for update of dd.source_line_id nowait;
8906
8907 CURSOR Pending_Lines IS
8908 SELECT Line.line_id
8909 FROM oe_order_lines Line
8910 WHERE (Line.link_to_line_id = l_line_rec.link_to_line_id
8911 OR Line.line_id = l_line_rec.link_to_line_id)
8912 AND invoice_interface_status_code = 'RFR-PENDING';
8913 --
8914 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8915 --
8916 l_delivery_name VARCHAR2(30);
8917 --bug# 4094835
8918 delivery_line_processed VARCHAR2(1):='N';
8919 current_line_return_status VARCHAR2(30);
8920 current_line_result_out VARCHAR2(30);
8921 v_line_id NUMBER;
8922 v_lock_control NUMBER;
8923 l_inv_stat varchar2(50) := ''; --sol_ord_er #16014165
8924 -- 16620434 start
8925 l_old_line_tbl OE_ORDER_PUB.line_tbl_type;
8926 l_line_tbl OE_ORDER_PUB.line_tbl_type;
8927 l_global_index NUMBER;
8928 -- 16620434 end
8929 BEGIN
8930 IF l_debug_level > 0 THEN
8931 oe_debug_pub.add( 'ENTERING INTERFACE_LINE ( ) PROCEDURE' , 1 ) ;
8932 oe_debug_pub.add( 'LINE ID : '|| P_LINE_ID , 5 ) ;
8933 oe_debug_pub.add( 'ITEM TYPE : '||P_ITEMTYPE , 5 ) ;
8934 END IF;
8935 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
8936 SAVEPOINT INVOICE_INTERFACE;
8937 END IF;
8938
8939 --bug 5336623 Commented the following call to OE_MSG_PUB.set_msg_context
8940 --Exception management begin
8941 /* OE_MSG_PUB.set_msg_context(
8942 p_entity_code => 'LINE'
8943 ,p_entity_id => p_line_id
8944 ,p_line_id => p_line_id ); */
8945 --Exception management end
8946
8947 -- Initialize API return status to success
8948 x_return_status := FND_API.G_RET_STS_SUCCESS;
8949 G_ITEMTYPE := p_itemtype;
8950
8951 --bug 5336623
8952 oe_line_util.Query_Row
8953 (p_line_id => p_line_id
8954 ,x_line_rec => l_line_rec
8955 );
8956 --bug 5336623
8957
8958 ----bug 5336623 commented the following call to OE_Line_Util.Lock_Row
8959 /* OE_Line_Util.Lock_Row(p_line_id=>p_line_id
8960 , p_x_line_rec => l_line_rec
8961 , x_return_status => l_return_status
8962 );
8963 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
8964 RAISE FND_API.G_EXC_ERROR;
8965 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8966 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8967 END IF; */
8968
8969 --bug 5336623 Moved the following call to OE_Header_Util.Query_row after the line is locked
8970 --OE_Header_Util.Query_row(p_header_id=>l_line_rec.header_id,x_header_rec=>l_header_rec);
8971 IF p_itemtype = OE_GLOBALS.G_WFI_HDR THEN
8972 p_header_id := l_line_rec.header_id;
8973 END IF;
8974 -- Set message context
8975 OE_MSG_PUB.set_msg_context(
8976 p_entity_code => 'LINE'
8977 ,p_entity_id => l_line_rec.line_id
8978 ,p_header_id => l_line_rec.header_id
8979 ,p_line_id => l_line_rec.line_id
8980 ,p_order_source_id => l_line_rec.order_source_id
8981 ,p_orig_sys_document_ref => l_line_rec.orig_sys_document_ref
8982 ,p_orig_sys_document_line_ref => l_line_rec.orig_sys_line_ref
8983 ,p_orig_sys_shipment_ref => l_line_rec.orig_sys_shipment_ref
8984 ,p_change_sequence => l_line_rec.change_sequence
8985 ,p_source_document_type_id => l_line_rec.source_document_type_id
8986 ,p_source_document_id => l_line_rec.source_document_id
8987 ,p_source_document_line_id => l_line_rec.source_document_line_id );
8988
8989 --bug 5336623
8990 begin
8991
8992 select line_id, lock_control into v_line_id, v_lock_control
8993 from oe_order_lines_all where line_id = l_line_rec.line_id
8994 FOR UPDATE NOWAIT;
8995
8996 IF l_debug_level > 0 THEN
8997 oe_debug_pub.add('Locking successful');
8998 END IF;
8999
9000 exception
9001 --- bug# 7600960 : Start
9002 /*
9003 WHEN APP_EXCEPTIONS.RECORD_LOCK_EXCEPTION THEN
9004 IF l_debug_level > 0 THEN
9005 oe_debug_pub.add('in lock record exception, someone else working on the row');
9006 END IF;
9007 x_return_status := FND_API.G_RET_STS_ERROR;
9008 l_line_rec.return_status := FND_API.G_RET_STS_ERROR;
9009 l_line_rec.line_id := null;
9010 FND_MESSAGE.Set_Name('ONT', 'OE_LINE_LOCKED');
9011 OE_MSG_PUB.Add;
9012 RAISE FND_API.G_EXC_ERROR;
9013 */
9014
9015 WHEN APP_EXCEPTIONS.RECORD_LOCK_EXCEPTION THEN
9016 IF l_debug_level > 0 THEN
9017 oe_debug_pub.add(' in lock record exception, someone else working on the row ');
9018 oe_debug_pub.add(' SQLERRM = '|| SQLERRM );
9019 oe_debug_pub.add( ' Unable to LOCK this Line. Going to make it DEFERRED so that it can be picked by another WFBP ');
9020 END IF;
9021
9022 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
9023 ROLLBACK TO INVOICE_INTERFACE;
9024 END IF;
9025 x_result_out := NULL;
9026 x_return_status := 'DEFERRED';
9027 FND_MESSAGE.Set_Name('ONT', 'OE_LINE_LOCKED');
9028 OE_MSG_PUB.Add;
9029 RETURN;
9030 --- bug# 7600960 : end
9031
9032 WHEN NO_DATA_FOUND THEN
9033 IF l_debug_level > 0 THEN
9034 oe_debug_pub.add('no_data_found, record lock exception');
9035 END IF;
9036 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9037
9038 WHEN OTHERS THEN
9039 IF l_debug_level > 0 THEN
9040 oe_debug_pub.add('record lock exception, others');
9041 oe_debug_pub.add('line id '|| v_line_id , 1);
9042 END IF;
9043 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9044 END;
9045
9046 OE_Header_Util.Query_row(p_header_id=>l_line_rec.header_id,x_header_rec=>l_header_rec);
9047 --bug 5336623
9048
9049
9050 ---Bug 8683948 : Start
9051 if l_line_rec.source_document_type_id = 10 THEN
9052 x_result_out := OE_GLOBALS.G_WFR_NOT_ELIGIBLE;
9053 x_return_status := FND_API.G_RET_STS_SUCCESS ;
9054 IF l_debug_level > 0 THEN
9055 oe_debug_pub.add( ' This is Internal Sales Order line... not doing anything for ISO flow.' , 1 ) ;
9056 END IF;
9057 --- bug# 9370369 : Start --
9058 BEGIN
9059 Update_Invoice_Attributes(l_line_rec
9060 ,l_interface_line_rec
9061 ,'NOT_ELIGIBLE'
9062 ,x_return_status);
9063
9064 oe_debug_pub.add( ' x_return_status after Update_Invoice_Attributes() : '|| x_return_status , 5 ) ;
9065
9066 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9067 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9068 RAISE FND_API.G_EXC_ERROR;
9069 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9070 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9071 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9072 END IF;
9073 END;
9074 oe_debug_pub.add( ' before returning ...',5);
9075 --- bug# 9370369 : End--
9076 RETURN;
9077 end if;
9078 ---Bug 8683948 : end
9079
9080 -- bug# 7231974 : before starting processing, fetch the service date
9081 oe_debug_pub.add( ' trying to fetch srv_start/end_date ... ' , 5 ) ;
9082 IF l_line_Rec.item_type_code = 'SERVICE' and l_line_Rec.accounting_rule_duration is null
9083 and (l_line_rec.SERVICE_START_DATE is null or l_line_rec.SERVICE_START_DATE is null) THEN
9084 --13724397 Start
9085 --Update_Service_Dates(l_line_Rec);
9086 Update_Service_Dates(l_line_Rec,x_return_status);
9087 --- sol_ord_er #16014165
9088 If NVL(l_line_rec.service_bill_option_code,'FBOM') = 'FPOM'
9089 AND l_line_rec.SERVICE_START_DATE is not NULL and l_line_rec.SERVICE_END_DATE is not null
9090 THEN
9091 --16620434 Start
9092 -- Update the current line being processed
9093 IF l_debug_level > 0 THEN
9094 oe_debug_pub.add('OEXPINVB Update Service Start Date= '
9095 ||to_char(l_line_rec.SERVICE_START_DATE,'DD-MON-YYYY HH24:MI:SS')
9096 ||'and End Date'
9097 ||to_char(l_line_rec.SERVICE_END_DATE,'DD-MON-YYYY HH24:MI:SS')
9098 ||' for line_id= '||l_line_rec.line_id);
9099 End IF;
9100 UPDATE oe_order_lines_all
9101 SET SERVICE_START_DATE = l_line_rec.SERVICE_START_DATE,
9102 SERVICE_END_DATE = l_line_rec.SERVICE_END_DATE
9103 WHERE line_id = l_line_rec.line_id;
9104 l_old_line_tbl(1) := l_line_rec;
9105 l_line_tbl(1) := l_line_rec;
9106 l_line_tbl(1).SERVICE_START_DATE := l_line_rec.SERVICE_START_DATE;
9107 l_line_tbl(1).SERVICE_END_DATE := l_line_rec.SERVICE_END_DATE;
9108 IF (Oe_Code_Control.Code_Release_Level >= '110508') THEN
9109 Oe_Order_Util.Update_Global_Picture ( p_Upd_New_Rec_If_Exists => FALSE,
9110 p_header_id => l_line_rec.header_id,
9111 p_old_line_rec => l_old_line_tbl(1),
9112 p_line_rec => l_line_tbl(1),
9113 p_line_id => l_line_rec.line_id,
9114 x_index => l_global_index,
9115 x_return_status => l_return_status );
9116 IF l_debug_level > 0 THEN
9117 oe_debug_pub.add('OEXPINVB 1: after update global picture, status: '
9118 || l_return_status, 1 ) ;
9119 oe_debug_pub.add('OEXPINVB 2: global picture index: ' || l_global_index , 1 ) ;
9120 END IF;
9121
9122 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
9123 RAISE Fnd_Api.G_EXC_ERROR;
9124 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9125 RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
9126 END IF;
9127
9128 IF l_global_index IS NOT NULL THEN
9129 Oe_Order_Util.g_line_tbl(l_global_index).SERVICE_START_DATE := l_line_tbl(1).SERVICE_START_DATE;
9130 Oe_Order_Util.g_line_tbl(l_global_index).SERVICE_END_DATE := l_line_tbl(1).SERVICE_END_DATE;
9131 END IF; -- on l_index being non-null
9132 END IF; -- on code release level
9133 --16620434 End
9134 IF l_debug_level > 0 THEN
9135 oe_Debug_pub.add(' ..101.. Calculating first period amount from OEXPINVB ');
9136 End If;
9137
9138 oe_delayed_requests_util.First_period_bill_amt (
9139 p_header_id => '',
9140 p_line_id => l_line_rec.line_id,
9141 x_return_status => l_return_status);
9142 -- Though update global picture gets called in above procedure,
9143 -- there is no requery happening within the current procedure
9144 BEGIN
9145 Select l.service_first_period_amount , l.service_first_period_enddate
9146 into l_line_rec.service_first_period_amount , l_line_rec.service_first_period_enddate
9147 from oe_order_lines_all l
9148 where l.line_id = l_line_rec.line_id;
9149 EXCEPTION
9150 WHEN NO_DATA_FOUND THEN
9151 IF l_debug_level > 0 THEN
9152 oe_Debug_pub.add(' ..101.. No Data Found in OEXPINVB for line_id '||l_line_rec.line_id);
9153 End If;
9154 x_return_status := FND_API.G_RET_STS_ERROR;
9155 WHEN OTHERS THEN
9156 IF l_debug_level > 0 THEN
9157 oe_Debug_pub.add(' ..101.. UnExpected Error in OEXPINVB for line_id '||l_line_rec.line_id);
9158 End If;
9159 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9160 END;
9161 End If;
9162 -- sol_ord_er #16014165 end
9163
9164 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9165 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9166 RAISE FND_API.G_EXC_ERROR;
9167 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9168 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9169 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9170 END IF;
9171 --13724397 End
9172 END IF;
9173 -- 7231974
9174
9175 -- Populate credit invoice line id in line rec
9176 --9040537 Update_Credit_Invoice(p_line_rec => l_line_rec,p_header_rec => l_header_rec); --8319535
9177
9178
9179 --Customer Acceptance
9180 IF NVL(OE_SYS_PARAMETERS.VALUE('ENABLE_FULFILLMENT_ACCEPTANCE'), 'N') = 'Y' AND
9181 OE_ACCEPTANCE_UTIL.Pre_billing_acceptance_on(l_line_rec)
9182 AND OE_ACCEPTANCE_UTIL.Acceptance_Status(l_line_rec) = 'NOT_ACCEPTED' THEN
9183 IF l_debug_level > 0 THEN
9184 oe_debug_pub.add('top_model_line_id:'||l_line_rec.top_model_line_id);
9185 END IF;
9186
9187 -- added following for bug# 5232503
9188 -- If it is a child line then check if the parent is accepted.
9189 -- Do not wait for acceptance if parent is already accepted. -- This check is added to make sure that child line won't get stuck
9190 -- if the system parameter is changed from yes to no to yes again.
9191 IF ((l_line_rec.top_model_line_id is not null
9192 AND l_line_rec.line_id <> l_line_rec.top_model_line_id
9193 AND OE_ACCEPTANCE_UTIL.Acceptance_Status(l_line_rec.top_model_line_id) = 'ACCEPTED')
9194 OR
9195 (l_line_rec.item_type_code = 'SERVICE'
9196 AND l_line_rec.service_reference_type_code='ORDER'
9197 AND l_line_rec.service_reference_line_id IS NOT NULL
9198 AND OE_ACCEPTANCE_UTIL.Acceptance_Status(l_line_rec.service_reference_line_id) = 'ACCEPTED')) THEN
9199 IF l_debug_level > 0 THEN
9200 oe_debug_pub.add('acceptance not required. item_type:'||l_line_rec.item_type_code);
9201 END IF;
9202 ELSE
9203 Update_Invoice_Attributes(l_line_rec ,l_interface_line_rec ,'ACCEPTANCE-PENDING' ,x_return_status);
9204 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9205 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9206 RAISE FND_API.G_EXC_ERROR;
9207 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9208 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9209 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9210 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9211 x_result_out := OE_GLOBALS.G_WFR_PENDING_ACCEPTANCE; -- this is pending for Acceptance
9212 RETURN;
9213 END IF;
9214 END IF;
9215 END IF;
9216 l_line_invoiceable := Line_Invoiceable(l_line_rec);
9217 l_line_rejected := Line_Rejected(l_line_rec);
9218 --Customer Acceptance
9219
9220
9221 -- gaynagar controlled code for non-invoiceable lines based on invoice numbering method
9222 -- IF NOT Line_Invoiceable(l_line_rec) THEN
9223 IF NOT l_line_invoiceable OR l_line_rejected THEN
9224 IF NOT l_line_Invoiceable THEN
9225 /* Bug#2666125 start-check freight records and holds for non invoiceable items*/
9226 BEGIN
9227 IF oe_code_control.code_release_level < '110510' then
9228 SELECT count(*)
9229 INTO l_freight_count
9230 FROM oe_price_adjustments p
9231 WHERE p.header_id = l_line_rec.header_id
9232 AND (p.line_id IS NULL OR p.line_id = l_line_rec.line_id)
9233 AND p.list_line_type_code = 'FREIGHT_CHARGE'
9234 AND p.applied_flag = 'Y'
9235 AND NVL(p.invoiced_flag, 'N') = 'N'
9236 AND NVL(l_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
9237 ELSE
9238 SELECT count(*)
9239 INTO l_freight_count
9240 FROM oe_price_adjustments p
9241 WHERE p.header_id = l_line_rec.header_id
9242 AND p.line_id IS NULL
9243 AND p.list_line_type_code = 'FREIGHT_CHARGE'
9244 AND p.applied_flag = 'Y'
9245 AND (NVL(p.invoiced_flag, 'N') = 'N' OR (NVL(p.invoiced_flag, 'N') = 'Y' AND p.adjusted_amount <> nvl(p.invoiced_amount, p.adjusted_amount)))
9246 AND NVL(l_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
9247 IF l_freight_count = 0 then
9248 SELECT count(*)
9249 INTO l_freight_count
9250 FROM oe_price_adjustments p
9251 WHERE p.header_id = l_line_rec.header_id
9252 AND p.line_id = l_line_rec.line_id
9253 AND p.list_line_type_code = 'FREIGHT_CHARGE'
9254 AND p.applied_flag = 'Y'
9255 AND NVL(p.invoiced_flag, 'N') = 'N'
9256 AND NVL(l_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
9257 END IF;
9258 END IF;
9259 EXCEPTION
9260 WHEN NO_DATA_FOUND THEN
9261 IF l_debug_level > 0 THEN
9262 oe_debug_pub.add('Non-invoiceable lines-In when no data found of freight');
9263 END IF;
9264 l_freight_count := 0;
9265 END;
9266 IF l_debug_level > 0 THEN
9267 oe_debug_pub.add('l_freight_count: '||l_freight_count);
9268 END IF;
9269 IF l_freight_count >0 then
9270 Check_Invoicing_Holds(l_line_rec, p_itemtype, x_return_status);
9271 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9272 x_result_out := OE_GLOBALS.G_WFR_ON_HOLD;
9273 RAISE FND_API.G_EXC_ERROR;
9274 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9275 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9276 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9277 END IF;
9278 END IF;
9279 END IF; -- noninvoiceable line
9280 /* Bug#2666125 end-check freight records and holds for non invoiceable items*/
9281 IF
9282 -- l_freight_count = 0 OR
9283 FND_PROFILE.VALUE('WSH_INVOICE_NUMBERING_METHOD') = 'A' THEN
9284 oe_debug_pub.add('Handling non-invoiceable lines with no freight or automatic numbering',1);
9285 -- sol_ord_er #16014165 end
9286 IF l_line_rec.service_bill_option_code = 'FBOKS' THEN
9287 l_inv_stat := 'BILLED_FROM_CONTRACTS';
9288 Else
9289 l_inv_stat := 'NOT_ELIGIBLE';
9290 End If;
9291 -- sol_ord_er #16014165 end
9292 Update_Invoice_Attributes(l_line_rec
9293 ,l_interface_line_rec
9294 --,'NOT_ELIGIBLE' --sol_ord_er #16014165
9295 ,l_inv_stat --sol_ord_er #16014165
9296 ,x_return_status);
9297 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9298 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9299 RAISE FND_API.G_EXC_ERROR;
9300 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9301 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9302 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9303 END IF;
9304 --- Eventhough line is not eligible for invoicing, there might be some other
9305 --- lines that are waiting for this line to trigger their invoicing activity.
9306 --- Ex: Included Items are not invoiceable but due to RFR, there might be
9307 --- some lines in RFR-PENDING block. We should invoice them.
9308 IF Is_PTO(l_line_rec) THEN
9309 IF Is_RFR(l_line_rec.line_id) THEN
9310 IF l_debug_level > 0 THEN
9311 oe_debug_pub.add( 'RFR: THIS LINE IS RFR BUT NOT ELIGIBLE FOR INVOICING- CHECKING FOR PENDING LINES' , 5 ) ;
9312 END IF;
9313 Open Pending_Lines;
9314 LOOP
9315 Fetch Pending_Lines Into l_pending_line_id;
9316 EXIT WHEN Pending_Lines%NOTFOUND;
9317 OE_Line_Util.Query_Row(p_line_id=>l_pending_line_id,x_line_rec=>l_pending_line_rec);
9318 IF l_debug_level > 0 THEN
9319 oe_debug_pub.add( 'RFR: PENDING LINE ID : ' || TO_CHAR ( L_PENDING_LINE_ID ) , 5 ) ;
9320 END IF;
9321 IF Something_To_Invoice(l_pending_line_rec) THEN -- the pending line now has something to
9322 -- invoice because current line has been shipped
9323 IF l_debug_level > 0 THEN
9324 oe_debug_pub.add( 'RFR: INTERFACING PENDING LINE ID :'||L_PENDING_LINE_ID , 5 ) ;
9325 END IF;
9326 Interface_Single_line(p_line_rec => l_pending_line_rec
9327 ,p_header_rec => l_header_rec
9328 ,p_x_interface_line_rec => l_interface_line_rec
9329 ,x_return_status => x_return_status
9330 ,x_result_out => x_result_out);
9331 IF l_debug_level > 0 THEN
9332 oe_debug_pub.add( 'INTERFACING PENDING LINE ID ' || L_PENDING_LINE_REC.LINE_ID , 5 ) ;
9333 END IF;
9334 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9335 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9336 RAISE FND_API.G_EXC_ERROR;
9337 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9338 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9339 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9340 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9341 IF x_result_out = OE_GLOBALS.G_WFR_PRTL_COMPLETE THEN
9342 IF l_debug_level > 0 THEN
9343 oe_debug_pub.add( 'RFR PENDING LINE PARTIALLY INTERFACED' , 5 ) ;
9344 END IF;
9345 ELSE --x_result_out = OE_GLOBALS.G_WFR_COMPLETE THEN
9346 IF l_debug_level > 0 THEN
9347 oe_debug_pub.add( 'RFR-PENDING LINE INTERFACED SUCCESSFULLY' , 5 ) ;
9348 END IF;
9349 WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_LIN, l_pending_line_rec.line_id, 'INVOICING_WAIT_FOR_RFR', 'COMPLETE');
9350 END IF;
9351 END IF;
9352 END IF;
9353 END LOOP;
9354 close Pending_Lines;
9355 END IF; -- itself is a RFR line
9356 END IF; -- PTO line
9357 --freight line rec info comes from interface line rec. so prepare interface line rec
9358 /* START Enhancement Request# 1915736 */
9359 -- Prepare interface line rec only if there are any freight charges to interface (Enhancement Request# 1915736)
9360 IF NOT l_line_rejected THEN --Customer Acceptance
9361 BEGIN
9362 IF oe_code_control.code_release_level < '110510' then
9363 SELECT count(*)
9364 INTO l_freight_count
9365 FROM oe_price_adjustments p
9366 WHERE p.header_id = l_line_rec.header_id
9367 AND (p.line_id IS NULL OR p.line_id = l_line_rec.line_id)
9368 AND p.list_line_type_code = 'FREIGHT_CHARGE'
9369 AND p.applied_flag = 'Y'
9370 AND NVL(p.invoiced_flag, 'N') = 'N'
9371 AND NVL(l_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
9372 ELSE
9373 SELECT count(*)
9374 INTO l_freight_count
9375 FROM oe_price_adjustments p
9376 WHERE p.header_id = l_line_rec.header_id
9377 AND p.line_id IS NULL
9378 AND p.list_line_type_code = 'FREIGHT_CHARGE'
9379 AND p.applied_flag = 'Y'
9380 AND (NVL(p.invoiced_flag, 'N') = 'N' OR (NVL(p.invoiced_flag, 'N') = 'Y' AND p.adjusted_amount <> nvl(p.invoiced_amount, p.adjusted_amount)))
9381 AND NVL(l_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
9382 IF l_freight_count = 0 then
9383 SELECT count(*)
9384 INTO l_freight_count
9385 FROM oe_price_adjustments p
9386 WHERE p.header_id = l_line_rec.header_id
9387 AND p.line_id = l_line_rec.line_id
9388 AND p.list_line_type_code = 'FREIGHT_CHARGE'
9389 AND p.applied_flag = 'Y'
9390 AND NVL(p.invoiced_flag, 'N') = 'N'
9391 AND NVL(l_line_rec.service_bill_option_code,'FBOM')='FBOM'; --sol_ord_er #16014165
9392 END IF;
9393 END IF;
9394 EXCEPTION
9395 WHEN NO_DATA_FOUND THEN
9396 IF l_debug_level > 0 THEN
9397 oe_debug_pub.add( 'IN WHEN NO DATA FOUND OF FREIGHT' ) ;
9398 END IF;
9399 l_freight_count := 0;
9400 END;
9401 IF l_debug_level > 0 THEN
9402 oe_debug_pub.add( 'L_FREIGHT_COUNT: '||L_FREIGHT_COUNT ) ;
9403 END IF;
9404 IF l_freight_count > 0 THEN
9405 /* END Enhancement Request# 1915736 */
9406 IF l_debug_level > 0 THEN
9407 oe_debug_pub.add( 'PREPARING INTERFACE LINE RECORD' , 5 ) ;
9408 END IF;
9409 Prepare_Interface_Line_Rec(p_line_rec => l_line_rec
9410 ,p_header_rec => l_header_rec
9411 ,p_x_interface_line_rec => l_interface_line_rec
9412 ,x_result_code => l_result_code);
9413 IF l_debug_level > 0 THEN
9414 oe_debug_pub.add( 'VALIDATING REQUIRED ATTRIBUTES' , 5 ) ;
9415 END IF;
9416 IF NOT Validate_Required_Attributes(l_line_rec, l_interface_line_rec) THEN
9417 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9418 RAISE FND_API.G_EXC_ERROR;
9419 END IF;
9420 IF l_debug_level > 0 THEN
9421 oe_debug_pub.add( 'INTERFACING FREIGHT CHARGES' , 5 ) ;
9422 END IF;
9423 Interface_Freight_Charges(l_line_rec
9424 , l_interface_line_rec
9425 , x_return_status);
9426 /* START Enhancement Request# 1915736 */
9427 END IF; -- for freight
9428 /* END Enhancement Request# 1915736 */
9429 END IF; -- for Non-rejected_lines Customer Acceptance
9430 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9431 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9432 RAISE FND_API.G_EXC_ERROR;
9433 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9434 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9435 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9436 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9437 -- sol_ord_er #16014165
9438 If l_inv_stat = OE_GLOBALS.G_CONTRACTS_BILLED then
9439 x_result_out := OE_GLOBALS.G_CONTRACTS_BILLED;
9440 else
9441 -- sol_ord_er #16014165 end
9442 x_result_out := OE_GLOBALS.G_WFR_NOT_ELIGIBLE;
9443 end if; --sol_ord_er #16014165
9444 IF l_debug_level > 0 THEN
9445 oe_debug_pub.add( 'RETURN AFTER INVOICEABLE ELIGIBLE CHECK' , 1 ) ;
9446 END IF;
9447 --Customer Acceptance
9448 IF l_line_rejected AND l_line_rec.line_category_code = 'RETURN' THEN
9449 FND_MESSAGE.SET_NAME('ONT','ONT_RMA_NO_CREDIT');
9450 OE_MSG_PUB.ADD;
9451 END IF;
9452 --Customer Acceptance
9453 RETURN;
9454 END IF;
9455 END IF; --freight_count zero or automatic numbering
9456 END IF; -- non-invoiceable lines check
9457
9458 Check_Invoicing_Holds(l_line_rec, p_itemtype, x_return_status);
9459 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9460 x_result_out := OE_GLOBALS.G_WFR_ON_HOLD;
9461 RAISE FND_API.G_EXC_ERROR;
9462 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9463 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9464 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9465 END IF;
9466 IF FND_PROFILE.VALUE('WSH_INVOICE_NUMBERING_METHOD') = 'D' THEN
9467 IF l_debug_level > 0 THEN
9468 oe_debug_pub.add( 'INVOICE NUMBERING SET TO MANUAL' , 5 ) ;
9469 END IF;
9470 IF Shipping_Info_Available(l_line_rec) AND NOT Return_Line(l_line_rec) THEN
9471 -- Fix for bug 2196494
9472 IF (l_line_rec.item_type_code NOT IN ('MODEL','CLASS','KIT')) THEN
9473 IF l_debug_level > 0 THEN
9474 oe_debug_pub.add( 'SHIPPING INFORMATION IS AVAILABLE' ) ;
9475 END IF;
9476 --Bug2181628 TO retrieve the minimum delivery_id of a line,if it is present
9477 --in more than one delivery.Hence used "MIN"instead of "ROWNUM".
9478 SELECT min(dl.delivery_id)
9479 INTO l_delivery_line_id
9480 FROM wsh_new_deliveries dl,
9481 wsh_delivery_assignments da,
9482 wsh_delivery_details dd
9483 WHERE dd.delivery_detail_id = da.delivery_detail_id
9484 AND da.delivery_id = dl.delivery_id
9485 AND dd.source_code = 'OE'
9486 AND dd.released_status = 'C' -- bug 6721251
9487 AND dd.source_line_id = l_line_rec.line_id;
9488 -- AND rownum = 1;
9489 -- Fix for bug 2196494
9490 ELSE
9491 SELECT min(dl.delivery_id)
9492 INTO l_delivery_line_id
9493 FROM wsh_new_deliveries dl,
9494 wsh_delivery_assignments da,
9495 wsh_delivery_details dd
9496 WHERE dd.delivery_detail_id = da.delivery_detail_id
9497 AND da.delivery_id = dl.delivery_id
9498 AND dd.source_code = 'OE'
9499 AND dd.released_status = 'C' -- bug 6721251
9500 AND dd.top_model_line_id = l_line_rec.line_id;
9501 -- AND rownum = 1;
9502 END IF;
9503
9504 -- fix: temporary
9505 IF l_delivery_line_id IS NOT NULL THEN
9506 IF l_debug_level > 0 THEN
9507 oe_debug_pub.add( 'DELIVERY ID : '||L_DELIVERY_LINE_ID , 5 ) ;
9508 END IF;
9509
9510 /* added for bug fix 4084965 */
9511 BEGIN
9512 IF l_debug_level > 0 THEN
9513 oe_debug_pub.add( 'locking '||to_char(sysdate,'HH24:MI:SS') ,5 ) ;
9514 END IF;
9515 open cur1(l_delivery_line_id);
9516 close cur1;
9517 IF l_debug_level > 0 THEN
9518 oe_debug_pub.add( 'locking: locked' , 5 ) ;
9519 END IF;
9520 EXCEPTION
9521 when app_exceptions.RECORD_LOCK_EXCEPTION then
9522 IF l_debug_level > 0 THEN
9523 oe_debug_pub.add( 'locking: cannot lock' , 5 ) ;
9524 END IF;
9525 x_return_status := 'DEFERRED';
9526 RETURN;
9527 when others then
9528 IF l_debug_level > 0 THEN
9529 oe_debug_pub.add( 'locking: exception:'||sqlerrm , 5 ) ;
9530 END IF;
9531 END; -- end of bug fix 4084965
9532
9533 OPEN delivery_lines_cursor(l_delivery_line_id);
9534 LOOP
9535 FETCH delivery_lines_cursor INTO l_line_id;
9536 EXIT WHEN delivery_lines_cursor%NOTFOUND;
9537 SELECT invoice_interface_status_code, open_flag
9538 INTO l_interface_status_code, l_open_flag
9539 FROM oe_order_lines
9540 WHERE line_id = l_line_id;
9541 IF l_debug_level > 0 THEN
9542 oe_debug_pub.add( 'LINE ID : '||L_LINE_ID , 5 ) ;
9543 END IF;
9544 IF l_interface_status_code = 'YES' OR
9545 l_interface_status_code = 'NOT_ELIGIBLE' OR
9546 l_interface_status_code = 'MANUAL-PENDING' OR
9547 l_interface_status_code = 'RFR-PENDING' OR
9548 l_open_flag = 'N' OR
9549 l_line_id = p_line_id THEN --this line is ready to invoice
9550 del_line_ready_flag := 'Y';
9551 ELSE
9552 --If there is no INVOICE_INTERFACE activity in the flow then do not wait for the line
9553 IF NOT Line_Activity(l_line_id) then
9554 del_line_ready_flag := 'Y';
9555 -- Fix for bug 2164555
9556 -- Fix for bug 2224248. Changed the variable l_line_rec to l_invoice_rec.
9557 ELSE
9558 l_invoice_rec :=OE_Line_Util.Query_Row(p_line_id=>l_line_id);
9559 --Bug2181628 Check if the current line's delivery_id is the same as the delivery_id
9560 --being processed.If it is the same then wait for this line,else do not wait indefinetely.
9561 --Bug3071154 Check the shippable flag also
9562 IF Shipping_Info_Available(l_invoice_rec)
9563 AND (l_invoice_rec.shippable_flag = 'Y') THEN
9564 l_line_delivery_id := NULL;
9565 SELECT min(dl.delivery_id)
9566 INTO l_line_delivery_id
9567 FROM wsh_new_deliveries dl,
9568 wsh_delivery_assignments da,
9569 wsh_delivery_details dd
9570 WHERE dd.delivery_detail_id = da.delivery_detail_id
9571 AND da.delivery_id = dl.delivery_id
9572 AND dd.source_code = 'OE'
9573 AND dd.released_status = 'C' -- bug 6721251
9574 AND dd.source_line_id = l_line_id;
9575
9576 IF l_line_delivery_id IS NULL AND l_invoice_rec.item_type_code in ('MODEL', 'CLASS', 'KIT') THEN
9577 SELECT min(dl.delivery_id)
9578 INTO l_line_delivery_id
9579 FROM wsh_new_deliveries dl,
9580 wsh_delivery_assignments da,
9581 wsh_delivery_details dd
9582 WHERE dd.delivery_detail_id = da.delivery_detail_id
9583 AND da.delivery_id = dl.delivery_id
9584 AND dd.source_code = 'OE'
9585 AND dd.released_status = 'C' -- bug 6721251
9586 AND dd.top_model_line_id = l_line_id;
9587 END IF;
9588 ELSE
9589 IF l_invoice_rec.item_type_code in ('MODEL', 'CLASS', 'KIT') THEN
9590 l_line_delivery_id := NULL;
9591 SELECT min(dl.delivery_id)
9592 INTO l_line_delivery_id
9593 FROM wsh_new_deliveries dl,
9594 wsh_delivery_assignments da,
9595 wsh_delivery_details dd
9596 WHERE dd.delivery_detail_id = da.delivery_detail_id
9597 AND da.delivery_id = dl.delivery_id
9598 AND dd.source_code = 'OE'
9599 AND dd.released_status = 'C' -- bug 6721251
9600 AND dd.top_model_line_id = l_line_id;
9601 END IF;
9602 END IF;
9603 IF (l_line_delivery_id <> l_delivery_line_id) THEN
9604 del_line_ready_flag := 'Y';
9605 ELSE
9606 del_line_ready_flag := 'N';
9607 END IF;
9608 END IF;
9609 END IF;
9610 EXIT WHEN del_line_ready_flag = 'N';
9611 END LOOP;
9612 CLOSE delivery_lines_cursor;
9613 IF l_debug_level > 0 THEN
9614 oe_debug_pub.add( 'DELIVERY LINE READY FLAG : '||DEL_LINE_READY_FLAG , 5 ) ;
9615 END IF;
9616 IF del_line_ready_flag = 'N' THEN -- atleast one line in delivery is not ready to interface
9617 IF l_debug_level > 0 THEN
9618 oe_debug_pub.add( 'SOME OF THE LINES IN THE DELIVERY ARE NOT READY' , 5 ) ;
9619 END IF;
9620 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
9621 IF l_debug_level > 0 THEN
9622 oe_debug_pub.add( 'LINE LEVEL INVOICING-SET STATUS TO PENDING' , 5 ) ;
9623 END IF;
9624 Update_Invoice_Attributes(l_line_rec
9625 ,l_interface_line_rec
9626 ,'MANUAL-PENDING'
9627 ,x_return_status);
9628 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
9629 IF l_delivery_line_id Is Not Null Then
9630 SELECT NVL(SUBSTR(dl.name, 1, 30), '0')
9631 INTO l_delivery_name
9632 FROM wsh_new_deliveries dl
9633 WHERE dl.delivery_id = l_delivery_line_id;
9634 END IF;
9635 FND_MESSAGE.SET_NAME('ONT','OE_INVOICE_WAIT_FOR_DELIVERY');
9636 FND_MESSAGE.SET_TOKEN('DELIVERY_NAME',l_delivery_name);
9637 OE_MSG_PUB.ADD;
9638 END IF;
9639 IF l_debug_level > 0 THEN
9640 oe_debug_pub.add( 'INTERFACE STATUS : '||L_LINE_REC.INVOICE_INTERFACE_STATUS_CODE , 5 ) ;
9641 oe_debug_pub.add( 'X_RETURN_STATUS : '||X_RETURN_STATUS , 5 ) ;
9642 END IF;
9643 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9644 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9645 RAISE FND_API.G_EXC_ERROR;
9646 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9647 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9648 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9649 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9650 x_result_out := OE_GLOBALS.G_WFR_PRTL_COMPLETE; -- this actually is pending, we call it partial for WF
9651 RETURN;
9652 END IF;
9653 ELSE -- header level invoice, all delivery lines are not ready to invoice. do not honor delivery.
9654 IF l_debug_level > 0 THEN
9655 oe_debug_pub.add( 'HDR INVOICING- PROCEED W/INVOICING' , 5 ) ;
9656 END IF;
9657 generate_invoice_number := 'Y';
9658 interface_this_line := 'Y';
9659 END IF;
9660 ELSIF del_line_ready_flag = 'Y' THEN --invoice all lines in delivery
9661 IF l_debug_level > 0 THEN
9662 oe_debug_pub.add( 'ALL LINES IN DELIVERY ARE READY' , 5 ) ;
9663 END IF;
9664 --except we need to check for any line in the delivery actually is not invoiciable
9665 --due to RFR
9666 OPEN delivery_lines_cursor(l_delivery_line_id);
9667 LOOP
9668 FETCH delivery_lines_cursor INTO l_line_id;
9669 EXIT WHEN delivery_lines_cursor%NOTFOUND;
9670 OE_Line_Util.Query_Row(p_line_id=>l_line_id, x_line_rec=>l_line_rec);
9671 OE_Header_Util.Query_row(p_header_id=>l_line_rec.header_id,x_header_rec=>l_header_rec);
9672 IF l_debug_level > 0 THEN
9673 oe_debug_pub.add( 'LINE ID : '||L_LINE_REC.LINE_ID , 5 ) ;
9674 END IF;
9675 --gaynagar processing non-invoiceable lines with delivery lines
9676 IF l_line_rec.open_flag='Y' AND
9677 NVL(l_line_rec.invoice_interface_status_code, 'NO') <> 'YES' AND
9678 NVL(l_line_rec.invoice_interface_status_code, 'NO') <> 'NOT_ELIGIBLE' THEN
9679 -- Fix for bug 2224248
9680 --Line_Invoiceable(l_line_rec) THEN
9681 IF (l_line_id <> p_line_id AND Line_Activity(l_line_rec.line_id) OR (l_line_id = p_line_id))THEN
9682 -- in devliery and pto, and has something/full qty to invoice - invoice whatever possible,
9683 -- update to RFR-PENDING if necessarily
9684 -- in delivery and pto, nothing to invoice - update status to RFR-PENDING
9685 -- in delivery and not in pto - invoice
9686 -- it is possible for lines in differnt orders in the same delivery
9687 -- so ready in a delivery doesn't mean line has something to interface
9688 --Bug2181628 Check if the current line's delivery_id is the same as the delivery_id
9689 --being processed.If it is the same then wait for this line,else do not wait indefinetely.
9690 --Bug 3071154 Check the shippable flag also.
9691 IF (l_line_id <> p_line_id) THEN
9692 IF Shipping_Info_Available(l_line_rec)
9693 AND (l_line_rec.shippable_flag = 'Y') THEN
9694 l_line_delivery_id := NULL;
9695 SELECT min(dl.delivery_id)
9696 INTO l_line_delivery_id
9697 FROM wsh_new_deliveries dl,
9698 wsh_delivery_assignments da,
9699 wsh_delivery_details dd
9700 WHERE dd.delivery_detail_id = da.delivery_detail_id
9701 AND da.delivery_id = dl.delivery_id
9702 AND dd.source_code = 'OE'
9703 AND dd.released_status = 'C' -- bug 6721251
9704 AND dd.source_line_id = l_line_id;
9705
9706 IF l_line_delivery_id IS NULL AND l_line_rec.item_type_code in ('MODEL', 'CLASS', 'KIT') THEN
9707 SELECT min(dl.delivery_id)
9708 INTO l_line_delivery_id
9709 FROM wsh_new_deliveries dl,
9710 wsh_delivery_assignments da,
9711 wsh_delivery_details dd
9712 WHERE dd.delivery_detail_id = da.delivery_detail_id
9713 AND da.delivery_id = dl.delivery_id
9714 AND dd.source_code = 'OE'
9715 AND dd.released_status = 'C' -- bug 6721251
9716 AND dd.top_model_line_id = l_line_id;
9717 END IF;
9718
9719 IF l_debug_level > 0 THEN
9720 oe_debug_pub.add( 'CURRENT LINES DELIVERY ID = '||L_LINE_DELIVERY_ID , 5 ) ;
9721 END IF;
9722 ELSE
9723 IF l_line_rec.item_type_code in ('MODEL', 'CLASS', 'KIT') THEN
9724 SELECT min(dl.delivery_id)
9725 INTO l_line_delivery_id
9726 FROM wsh_new_deliveries dl,
9727 wsh_delivery_assignments da,
9728 wsh_delivery_details dd
9729 WHERE dd.delivery_detail_id = da.delivery_detail_id
9730 AND da.delivery_id = dl.delivery_id
9731 AND dd.source_code = 'OE'
9732 AND dd.released_status = 'C' -- bug 6721251
9733 AND dd.top_model_line_id = l_line_id;
9734 IF l_debug_level > 0 THEN
9735 oe_debug_pub.add( 'CURRENT LINES DELIVERY ID MODEL , CLASS , KIT = '||L_LINE_DELIVERY_ID , 5 ) ;
9736 END IF;
9737 END IF;
9738 END IF;
9739 END IF;
9740 -- Bug2181628 Only now Process the line.
9741 IF ((l_line_id = p_line_id) OR (l_line_delivery_id = l_delivery_line_id)) THEN
9742 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
9743 l_interface_line_rec.request_id := -1 * p_line_id;
9744 ELSE
9745 l_interface_line_rec.request_id := -1 * p_header_id;
9746 END IF;
9747 generate_invoice_number := 'Y';
9748 l_old_interface_status_code := l_line_rec.invoice_interface_status_code;
9749 IF Is_PTO(l_line_rec) THEN
9750 IF l_debug_level > 0 THEN
9751 oe_debug_pub.add( 'RFR: PTO IS TRUE - IN DELIVERY HANDLING' , 5 ) ;
9752 END IF;
9753 IF Something_To_Invoice(l_line_rec) THEN
9754 IF l_debug_level > 0 THEN
9755 oe_debug_pub.add( 'RFR: SOMETHING_TO_INVOICE IS TRUE , GO AHEAD INTERFACE - IN DELIVERY HANDLING' , 5 ) ;
9756 END IF;
9757 Interface_Single_line(p_line_rec => l_line_rec
9758 ,p_header_rec => l_header_rec
9759 ,p_x_interface_line_rec => l_interface_line_rec
9760 ,x_return_status => x_return_status
9761 ,x_result_out => x_result_out);
9762 IF l_debug_level > 0 THEN
9763 oe_debug_pub.add( 'INTERFACED W/REQUEST_ID : '||L_INTERFACE_LINE_REC.REQUEST_ID , 5 ) ;
9764 -- if this line can only invoice partial, it will become RFR-PENDING while interfacing whatever it can
9765 -- x_result_out should have set appropriately
9766 oe_debug_pub.add( 'AFTER INTERFACE SINGLE LINE , RESULT_OUT IS ' || X_RESULT_OUT ||': And x_return_status:'||x_return_status, 5 ) ;
9767 END IF;
9768 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9769 RAISE FND_API.G_EXC_ERROR;
9770 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9771 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9772 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9773 -- bug# 4094835, if RFR line is fully is fully invoiced or not eligible
9774 IF (x_result_out = OE_GLOBALS.G_WFR_COMPLETE OR x_result_out=OE_GLOBALS.G_WFR_NOT_ELIGIBLE) THEN
9775 IF l_old_interface_status_code = 'MANUAL-PENDING' OR l_old_interface_status_code = 'RFR-PENDING' THEN
9776 IF l_debug_level > 0 THEN
9777 oe_debug_pub.add( 'RFR: MANUAL-PENDING + RFR LINE HAS BEEN FULLY INVOICED' , 5 ) ;
9778 oe_debug_pub.add( 'NOW COMPLETING THE WF BLOCK ACTIVITY' , 5 ) ;
9779 END IF;
9780 WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_LIN, l_line_rec.line_id, 'INVOICING_WAIT_FOR_RFR', 'COMPLETE');
9781 END IF;
9782 END IF;
9783 IF x_result_out = OE_GLOBALS.G_WFR_PRTL_COMPLETE THEN -- RFR line is partially invoiced
9784 IF l_debug_level > 0 THEN
9785 oe_debug_pub.add( 'RFR: THIS LINE IS PARTIALLY INVOICED' , 5 ) ;
9786 END IF;
9787 END IF;
9788 -- real invoice_interface_status_code should have updated to right value
9789 -- from interface_single_line already
9790 END IF;
9791 ELSE -- PTO in a delivery, but nothing available to invoice, update to RFR-PENDING
9792 IF l_debug_level > 0 THEN
9793 oe_debug_pub.add( 'RFR: NOTHING AVAILABLE FOR PTO TO INVOICE , UDPATE RFR-PENDING' , 5 ) ;
9794 oe_debug_pub.add( 'l_interface_line_rec.quantity:'|| l_interface_line_rec.quantity||':l_line_rec.invoiced_quantity:'||l_line_rec.invoiced_quantity,5 ) ;
9795 END IF;
9796 l_interface_line_rec.quantity := 0; -- for bug# 4760143, setting the quantity to zero as nothing to invoice
9797 IF l_debug_level > 0 THEN
9798 oe_debug_pub.add( 'l_interface_line_rec.quantity after resetting:'|| l_interface_line_rec.quantity,5 ) ;
9799 END IF;
9800 Update_Invoice_Attributes(l_line_rec
9801 ,l_interface_line_rec
9802 ,'RFR-PENDING'
9803 ,x_return_status);
9804 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
9805 FND_MESSAGE.SET_NAME('ONT','OE_INVOICE_WAIT_FOR_RFR');
9806 OE_MSG_PUB.ADD;
9807 END IF;
9808 IF l_debug_level > 0 THEN
9809 oe_debug_pub.add( 'RFR: L_LINE_REC.INTERFACE_STATUS '||L_LINE_REC.INVOICE_INTERFACE_STATUS_CODE , 5 ) ;
9810 oe_debug_pub.add( 'RFR: X_RETURN_STATUS :'||X_RETURN_STATUS , 5 ) ;
9811 END IF;
9812 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9813 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9814 RAISE FND_API.G_EXC_ERROR;
9815 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9816 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9817 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9818 --bug# 4094835
9819 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9820 x_result_out := OE_GLOBALS.G_WFR_PRTL_COMPLETE;
9821 IF l_debug_level > 0 THEN
9822 oe_debug_pub.add( 'RFR: LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) ||' PARTIALLY INTERFACED SUCCESSFULLY ' || 'X_RESULT_OUT: '||X_RESULT_OUT) ;
9823 END IF;
9824 END IF; -- check for update_invoice_attribute results
9825 END IF; -- check for anything to invoice for this PTO
9826 ELSE -- not in a PTO
9827 Interface_Single_line(p_line_rec => l_line_rec
9828 ,p_header_rec => l_header_rec
9829 ,p_x_interface_line_rec => l_interface_line_rec
9830 ,x_return_status => x_return_status
9831 ,x_result_out => x_result_out);
9832 IF l_debug_level > 0 THEN
9833 oe_debug_pub.add( 'INTERFACED W/REQUEST_ID : '||L_INTERFACE_LINE_REC.REQUEST_ID , 5 ) ;
9834 END IF;
9835 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9836 RAISE FND_API.G_EXC_ERROR;
9837 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9838 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9839 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9840 IF l_debug_level > 0 THEN
9841 oe_debug_pub.add( 'L_LINE_ID: '||L_LINE_ID||' P_LINE_ID: '||P_LINE_ID|| ' INVOICE_INTERFACE_STATUS_CODE: '||L_LINE_REC.INVOICE_INTERFACE_STATUS_CODE , 5 ) ;
9842 END IF;
9843 IF l_old_interface_status_code = 'MANUAL-PENDING' THEN
9844 IF l_debug_level > 0 THEN
9845 oe_debug_pub.add( 'MANUAL-PENDING LINE HAS BEEN INVOICED' , 5 ) ;
9846 oe_debug_pub.add( 'NOW COMPLETING THE WF BLOCK ACTIVITY' , 5 ) ;
9847 END IF;
9848 WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_LIN, l_line_rec.line_id, 'INVOICING_WAIT_FOR_RFR', 'COMPLETE');
9849 END IF;
9850 END IF; -- check for interface_single_line result
9851 END IF; -- check for PTO
9852 END IF; -- Bug2181628.Process the line.
9853 END IF;
9854 END IF; -- line has not been interface yet
9855 --bug# 4094835
9856 IF l_line_id = p_line_id THEN
9857 delivery_line_processed := 'Y';
9858 current_line_return_status := x_return_status;
9859 current_line_result_out := x_result_out;
9860 IF l_debug_level > 0 THEN
9861 oe_debug_pub.add( 'Current line status:'||current_line_return_status||': Current line result_out:'||current_line_result_out);
9862 END IF;
9863 END IF;
9864 END LOOP;
9865 CLOSE delivery_lines_cursor;
9866 -- Setting the current line status correctly. This is
9867 -- required if the current line is not processed at the end
9868 --bug# 4094835
9869 IF delivery_line_processed = 'Y' THEN
9870 IF l_debug_level > 0 THEN
9871 oe_debug_pub.add( 'Setting the current line status correctly.'||current_line_return_status||':'||current_line_result_out);
9872 END IF;
9873 x_return_status := current_line_return_status;
9874 x_result_out := current_line_result_out;
9875 END IF;
9876 interface_this_line := 'N';
9877 END IF; -- are delivery lines ready?
9878 ELSE -- delivery_id is null
9879 interface_this_line := 'Y';
9880 generate_invoice_number := 'N';
9881 IF l_debug_level > 0 THEN
9882 oe_debug_pub.add( 'DELIVERY ID IS NULL' , 5 ) ;
9883 END IF;
9884 END IF; -- delivery id
9885 END IF; --shipping info avaialable
9886 ELSE -- automatic invoice numbering
9887 interface_this_line := 'Y';
9888 generate_invoice_number := 'N';
9889 IF l_debug_level > 0 THEN
9890 oe_debug_pub.add( 'AUTOMATIC INVOICE NUMBERING' , 5 ) ;
9891 END IF;
9892 END IF;
9893 IF interface_this_line = 'Y' THEN -- for automatic invoice numbering
9894 IF l_debug_level > 0 THEN
9895 oe_debug_pub.add( 'INTERFACING LINE ID : '||L_LINE_REC.LINE_ID , 5 ) ;
9896 END IF;
9897 IF generate_invoice_number = 'Y' THEN
9898 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
9899 l_interface_line_rec.request_id := -1 * p_line_id;
9900 ELSE
9901 l_interface_line_rec.request_id := -1 * p_header_id;
9902 END IF;
9903 IF l_debug_level > 0 THEN
9904 oe_debug_pub.add( 'SETTING REQUEST_ID' || L_INTERFACE_LINE_REC.REQUEST_ID , 5 ) ;
9905 END IF;
9906 END IF;
9907 -- Retrobilling:
9908 -- For RMAs that reference a retrobilled order line
9909 -- We might need to create multiple credit memos
9910 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510'
9911 and Oe_Retrobill_Pvt.retrobill_enabled
9912 and Return_Line(l_line_rec)
9913 and l_line_rec.reference_line_id IS NOT NULL
9914 THEN
9915 --dbms_output.put_line('inside retrobill rma');
9916 Oe_Retrobill_Pvt.Interface_Retrobilled_RMA(p_line_rec => l_line_rec
9917 ,p_header_rec => l_header_rec
9918 ,x_Return_status => x_return_status
9919 , x_result_out => x_result_out);
9920 ELSE
9921 Interface_Single_line(p_line_rec => l_line_rec
9922 ,p_header_rec => l_header_rec
9923 ,p_x_interface_line_rec => l_interface_line_rec
9924 ,x_return_status => x_return_status
9925 ,x_result_out => x_result_out);
9926 END IF;
9927 IF l_debug_level > 0 THEN
9928 oe_debug_pub.add( 'INTERFACED W/REQUEST_ID : '||L_INTERFACE_LINE_REC.REQUEST_ID || ' X_RETURN_STATUS: '|| X_RETURN_STATUS , 5 ) ;
9929 END IF;
9930 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9931 RAISE FND_API.G_EXC_ERROR;
9932 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9933 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9934 END IF;
9935 -- if this line is RFR and there are lines waiting for it, interface those lines
9936 IF Is_PTO(l_line_rec) THEN
9937 IF Is_RFR(l_line_rec.line_id) THEN
9938 IF l_debug_level > 0 THEN
9939 oe_debug_pub.add( 'RFR: THIS LINE ITSELF IS RFR' , 5 ) ;
9940 END IF;
9941 Open Pending_Lines;
9942 LOOP
9943 Fetch Pending_Lines Into l_pending_line_id;
9944 IF l_debug_level > 0 THEN
9945 oe_debug_pub.add( 'RFR: PENDING LINE ID ' || TO_CHAR ( L_PENDING_LINE_ID ) , 5 ) ;
9946 END IF;
9947 EXIT WHEN Pending_Lines%NOTFOUND;
9948 OE_Line_Util.Query_Row(p_line_id=>l_pending_line_id, x_line_rec=>l_pending_line_rec);
9949 IF Something_To_Invoice(l_pending_line_rec) THEN -- the pending line now has something to
9950 -- invoice because current line has been shipped
9951 -- check for delivery and invoice delivery if necessarily
9952 IF l_debug_level > 0 THEN
9953 oe_debug_pub.add( 'RFR: LINE IS RFR AND DELIVERY INVOICING' , 5 ) ;
9954 END IF;
9955 Interface_Single_line(p_line_rec => l_pending_line_rec
9956 ,p_header_rec => l_header_rec
9957 ,p_x_interface_line_rec => l_interface_line_rec
9958 ,x_return_status => x_return_status
9959 ,x_result_out => x_result_out);
9960 IF l_debug_level > 0 THEN
9961 oe_debug_pub.add( 'RFR: INTERFACE RFR-PENDING LINE , ID: ' || L_PENDING_LINE_REC.LINE_ID , 5 ) ;
9962 END IF;
9963 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
9964 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9965 RAISE FND_API.G_EXC_ERROR;
9966 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9967 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
9968 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9969 ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9970 IF x_result_out = OE_GLOBALS.G_WFR_PRTL_COMPLETE THEN
9971 IF l_debug_level > 0 THEN
9972 oe_debug_pub.add( 'RFR: RFR-PENDING LINE PARTIALLY INTERFACED' , 5 ) ;
9973 END IF;
9974 ELSE --x_result_out = OE_GLOBALS.G_WFR_COMPLETE THEN
9975 IF l_debug_level > 0 THEN
9976 oe_debug_pub.add( 'RFR: RFR-PENDING LINE INTERFACED SUCCESSFULLY , COMPLETING BLOCK' , 5 ) ;
9977 END IF;
9978 WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_LIN, l_pending_line_rec.line_id, 'INVOICING_WAIT_FOR_RFR', 'COMPLETE');
9979 END IF;
9980 END IF;
9981 END IF;
9982 END LOOP;
9983 -- run for the pending lines just interfaced
9984 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
9985 IF x_result_out = OE_GLOBALS.G_WFR_COMPLETE OR x_result_out = OE_GLOBALS.G_WFR_NOT_ELIGIBLE THEN
9986 IF generate_invoice_number = 'Y' THEN
9987 IF l_debug_level > 0 THEN
9988 oe_debug_pub.add( 'RFR:LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) ||' INTERFACED SUCCESSFULLY' , 5 ) ;
9989 oe_debug_pub.add( 'RFR: CALLING UPDATE_NUMBERS' , 5 ) ;
9990 END IF;
9991 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
9992 Update_Numbers(p_line_id, x_return_status);
9993 ELSE
9994 Update_Numbers(p_header_id, x_return_status);
9995 END IF;
9996 IF l_debug_level > 0 THEN
9997 oe_debug_pub.add( 'RFR: RETURN STATUS : '||X_RETURN_STATUS , 5 ) ;
9998 END IF;
9999 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
10000 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10001 RAISE FND_API.G_EXC_ERROR;
10002 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10003 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10004 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10005 ELSE
10006 x_result_out := OE_GLOBALS.G_WFR_COMPLETE;
10007 IF l_debug_level > 0 THEN
10008 oe_debug_pub.add( 'RFR: UPDATE NUMBER DONE FOR RFR-PENDING LINE ( CURRENT LINE IS RFR ) ' , 5 ) ;
10009 END IF;
10010 END IF;
10011 ELSE
10012 IF l_debug_level > 0 THEN
10013 oe_debug_pub.add( 'RFR:LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) ||' INTERFACED SUCCESSFULLY' , 5 ) ;
10014 oe_debug_pub.add( 'RFR:W/AUTOMATIC NUMBERING' , 5 ) ;
10015 END IF;
10016 END IF;
10017 END IF;
10018 END IF;
10019 close Pending_Lines;
10020 END IF; -- itself is a RFR line
10021 END IF; -- PTO line
10022 END IF; -- if interface_this_line is Y
10023 IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
10024 IF x_result_out = OE_GLOBALS.G_WFR_COMPLETE OR x_result_out = OE_GLOBALS.G_WFR_NOT_ELIGIBLE THEN
10025 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
10026 IF generate_invoice_number = 'Y' THEN
10027 IF l_debug_level > 0 THEN
10028 oe_debug_pub.add( 'LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) ||' INTERFACED SUCCESSFULLY' , 2 ) ;
10029 oe_debug_pub.add( 'CALLING UPDATE_NUMBERS' ) ;
10030 END IF;
10031 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
10032 Update_Numbers(p_line_id, x_return_status);
10033 ELSE
10034 Update_Numbers(p_header_id, x_return_status);
10035 END IF;
10036 IF l_debug_level > 0 THEN
10037 oe_debug_pub.add( 'RETURN STATUS : '||X_RETURN_STATUS , 5 ) ;
10038 END IF;
10039 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
10040 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10041 RAISE FND_API.G_EXC_ERROR;
10042 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10043 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10044 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10045 ELSE
10046 x_result_out := OE_GLOBALS.G_WFR_COMPLETE;
10047 IF l_debug_level > 0 THEN
10048 oe_debug_pub.add( 'EXITING INTERFACE_LINE' , 5 ) ;
10049 END IF;
10050 RETURN;
10051 END IF;
10052 ELSE
10053 IF l_debug_level > 0 THEN
10054 oe_debug_pub.add( 'LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) ||' INTERFACED SUCCESSFULLY' , 5 ) ;
10055 oe_debug_pub.add( 'W/AUTOMATIC NUMBERING' , 2 ) ;
10056 END IF;
10057 RETURN;
10058 END IF;
10059 END IF;
10060 END IF;
10061 END IF;
10062 EXCEPTION
10063 WHEN FND_API.G_EXC_ERROR THEN
10064 IF l_debug_level > 0 THEN
10065 oe_debug_pub.add( 'EXPECTED ERROR. EXIT LINE INVOICING : '||SQLERRM , 1 ) ;
10066 END IF;
10067 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
10068 ROLLBACK TO INVOICE_INTERFACE;
10069 END IF;
10070
10071 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
10072 IF x_result_out = OE_GLOBALS.G_WFR_ON_HOLD Then
10073 l_flow_status_code := 'INVOICE_HOLD';
10074 ELSIF x_result_out = OE_GLOBALS.G_WFR_INCOMPLETE THEN
10075 l_flow_status_code := 'INVOICE_INCOMPLETE';
10076 END IF;
10077
10078 Update_line_flow_status(l_line_rec.line_id,l_flow_status_code,
10079 l_line_rec.order_source_id); -- 8541809
10080 END IF;
10081
10082 OE_MSG_PUB.Count_And_Get
10083 ( p_count => x_msg_count
10084 , p_data => x_msg_data
10085 );
10086 x_return_status := FND_API.G_RET_STS_ERROR;
10087 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10088 IF l_debug_level > 0 THEN
10089 oe_debug_pub.add( 'UNEXPECTED ERROR. EXITING FROM LINE INVOICING : '||SQLERRM , 1 ) ;
10090 END IF;
10091 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
10092 ROLLBACK TO INVOICE_INTERFACE;
10093 END IF;
10094 OE_MSG_PUB.Count_And_Get
10095 ( p_count => x_msg_count
10096 , p_data => x_msg_data
10097 );
10098 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10099 WHEN OTHERS THEN
10100 IF l_debug_level > 0 THEN
10101 oe_debug_pub.add( 'EXCEPTION , OTHERS. EXITING FROM LINE INVOICING : '||SQLERRM , 1 ) ;
10102 END IF;
10103 IF (delivery_lines_cursor%ISOPEN) THEN
10104 CLOSE delivery_lines_cursor;
10105 END IF;
10106 IF (Pending_Lines%ISOPEN) THEN
10107 CLOSE Pending_Lines;
10108 END IF;
10109 IF p_itemtype = OE_GLOBALS.G_WFI_LIN THEN
10110 ROLLBACK TO INVOICE_INTERFACE;
10111 END IF;
10112 IF FND_MSG_PUB.Check_Msg_Level
10113 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10114 THEN
10115 OE_MSG_PUB.Add_Exc_Msg
10116 ( G_PKG_NAME
10117 , 'Interface_Line'
10118 );
10119 END IF;
10120 OE_MSG_PUB.Count_And_Get
10121 ( p_count => x_msg_count
10122 , p_data => x_msg_data
10123 );
10124 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10125 END Interface_Line;
10126
10127 PROCEDURE Interface_Header
10128 ( p_header_id IN NUMBER
10129 , p_itemtype IN VARCHAR2
10130 , x_result_out OUT NOCOPY VARCHAR2
10131 , x_return_status OUT NOCOPY VARCHAR2
10132 ) IS
10133 x_msg_count NUMBER;
10134 x_msg_data VARCHAR2(240);
10135 l_return_status VARCHAR2(30);
10136 l_result_out VARCHAR2(30);
10137 l_flow_status_code VARCHAR2(30);
10138 CURSOR order_line_cursor IS
10139 SELECT ol.line_id
10140 FROM oe_order_lines ol
10141 WHERE ol.header_id = p_header_id
10142 AND ol.open_flag = 'Y';
10143 l_line_id NUMBER;
10144
10145 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
10146
10147 l_source_document_type_id NUMBER; --- Bug 8683948
10148
10149 BEGIN
10150 IF l_debug_level > 0 THEN
10151 oe_debug_pub.add( 'ENTER INTERFACE_HEADER ( ) PROCEDURE' , 5 ) ;
10152 END IF;
10153 SAVEPOINT HEADER_INVOICE_INTERFACE;
10154 -- Initialize API return status to success
10155 x_return_status := FND_API.G_RET_STS_SUCCESS;
10156
10157 /* ------------ Bug# 9370369 : Start : Moving this code of bug# 8993414 little below -----
10158 ---Bug 8683948 : Start
10159 select source_document_type_id into l_source_document_type_id
10160 from oe_order_headers_all where header_id = p_header_id;
10161
10162 if l_source_document_type_id = 10 THEN
10163 x_result_out := OE_GLOBALS.G_WFR_NOT_ELIGIBLE;
10164 x_return_status := FND_API.G_RET_STS_SUCCESS ;
10165 IF l_debug_level > 0 THEN
10166 oe_debug_pub.add( ' This is Internal Sales Order ... not doing anything for ISO....' ) ;
10167 END IF;
10168 RETURN;
10169 end if;
10170 ---Bug 8683948 : End
10171 */ --- bug: 9370369 : End -----------------------------
10172
10173 -- Header_Invoicing_Validation
10174 OPEN order_line_cursor;
10175 LOOP
10176 FETCH order_line_cursor INTO l_line_id;
10177 EXIT WHEN order_line_cursor%NOTFOUND;
10178 IF l_debug_level > 0 THEN
10179 oe_debug_pub.add( 'PROCESSING LINE_ID: '||L_LINE_ID , 5 ) ;
10180 END IF;
10181 Interface_Line(l_line_id, p_itemtype, l_result_out, l_return_status);
10182 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
10183 IF l_result_out = OE_GLOBALS.G_WFR_ON_HOLD THEN
10184 x_result_out := OE_GLOBALS.G_WFR_ON_HOLD;
10185 ELSIF l_result_out = OE_GLOBALS.G_WFR_INCOMPLETE THEN
10186 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10187 END IF;
10188 RAISE FND_API.G_EXC_ERROR;
10189 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10190 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10191 ELSE
10192 IF l_debug_level > 0 THEN
10193 oe_debug_pub.add( 'CONTINUE WITH NEXT LINE IF THIS IS NOT LAST ONE' , 5 ) ;
10194 END IF;
10195 END IF;
10196 END LOOP;
10197 CLOSE order_line_cursor;
10198
10199 ---- Bug# 9370369 : Start
10200 select source_document_type_id into l_source_document_type_id
10201 from oe_order_headers_all where header_id = p_header_id;
10202 oe_debug_pub.add( ' l_source_document_type_id = '|| l_source_document_type_id , 5) ;
10203
10204 if l_source_document_type_id = 10 THEN
10205 x_result_out := OE_GLOBALS.G_WFR_NOT_ELIGIBLE;
10206 x_return_status := FND_API.G_RET_STS_SUCCESS ;
10207 IF l_debug_level > 0 THEN
10208 oe_debug_pub.add( ' This is Internal Sales Order ... not doing anything for ISO....', 5 ) ;
10209 END IF;
10210 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
10211 l_flow_status_code := 'INVOICE_NOT_APPLICABLE';
10212 Update_header_flow_status(p_header_id,l_flow_status_code);
10213 END IF;
10214 oe_debug_pub.add( ' returning from Interface_Header() ...',5);
10215 RETURN;
10216 end if;
10217 --- bug: 9370369 : End
10218
10219 IF l_debug_level > 0 THEN
10220 oe_debug_pub.add( 'CALL UPDATE_NUMBERS FOR HEADER LEVEL INVOICING' , 5 ) ;
10221 END IF;
10222
10223 Update_Numbers(p_header_id, x_return_status);
10224
10225 IF l_debug_level > 0 THEN
10226 oe_debug_pub.add( 'RETURN STATUS : '||X_RETURN_STATUS , 5 ) ;
10227 END IF;
10228
10229 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
10230 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10231 RAISE FND_API.G_EXC_ERROR;
10232 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10233 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10234 ELSE
10235 x_return_status := FND_API.G_RET_STS_SUCCESS;
10236 x_result_out := OE_GLOBALS.G_WFR_COMPLETE;
10237 IF l_debug_level > 0 THEN
10238 oe_debug_pub.add( 'EXIT INTERFACE_LINE ( ) PROCEDURE' , 5 ) ;
10239 END IF;
10240 END IF;
10241
10242 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
10243 l_flow_status_code := 'INVOICED';
10244 Update_header_flow_status(p_header_id,l_flow_status_code);
10245 END IF;
10246
10247 IF l_debug_level > 0 THEN
10248 oe_debug_pub.add( 'EXITING INTERFACE_HEADER ( ) PROCEDURE' , 5 ) ;
10249 END IF;
10250
10251 EXCEPTION
10252 WHEN FND_API.G_EXC_ERROR THEN
10253 IF l_debug_level > 0 THEN
10254 oe_debug_pub.add( 'EXPECTED ERROR. EXIT FROM HEADER INVOICING' , 5 ) ;
10255 END IF;
10256 IF (order_line_cursor%ISOPEN) THEN
10257 CLOSE order_line_cursor;
10258 END IF;
10259 ROLLBACK TO HEADER_INVOICE_INTERFACE;
10260
10261 IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
10262 IF x_result_out = OE_GLOBALS.G_WFR_ON_HOLD Then
10263 l_flow_status_code := 'INVOICE_HOLD';
10264 ELSIF x_result_out = OE_GLOBALS.G_WFR_INCOMPLETE THEN
10265 l_flow_status_code := 'INVOICE_INCOMPLETE';
10266 END IF;
10267 Update_header_flow_status(p_header_id,l_flow_status_code);
10268 END IF;
10269
10270 OE_MSG_PUB.Count_And_Get
10271 ( p_count => x_msg_count
10272 , p_data => x_msg_data
10273 );
10274 x_return_status := FND_API.G_RET_STS_ERROR;
10275 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10276 IF l_debug_level > 0 THEN
10277 oe_debug_pub.add( 'UNEXPECTED ERROR. EXITING FROM HEADER INVOICING' , 5 ) ;
10278 END IF;
10279 IF (order_line_cursor%ISOPEN) THEN
10280 CLOSE order_line_cursor;
10281 END IF;
10282 ROLLBACK TO HEADER_INVOICE_INTERFACE;
10283 OE_MSG_PUB.Count_And_Get
10284 ( p_count => x_msg_count
10285 , p_data => x_msg_data
10286 );
10287 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10288 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10289 WHEN OTHERS THEN
10290 IF l_debug_level > 0 THEN
10291 oe_debug_pub.add( 'EXCEPTION OTHERS. EXIT FROM HEADER INVOICING' , 5 ) ;
10292 END IF;
10293 IF (order_line_cursor%ISOPEN) THEN
10294 CLOSE order_line_cursor;
10295 END IF;
10296 ROLLBACK TO HEADER_INVOICE_INTERFACE;
10297 IF OE_MSG_PUB.Check_Msg_Level
10298 (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10299 THEN
10300 OE_MSG_PUB.Add_Exc_Msg
10301 ( G_PKG_NAME
10302 , 'Interface_Header'
10303 );
10304 END IF;
10305 OE_MSG_PUB.Count_And_Get
10306 ( p_count => x_msg_count
10307 , p_data => x_msg_data
10308 );
10309 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10310 x_result_out := OE_GLOBALS.G_WFR_INCOMPLETE;
10311
10312 END Interface_Header;
10313
10314
10315 Procedure Any_Line_ARInterfaced( p_application_id IN NUMBER,
10316 p_entity_short_name in VARCHAR2,
10317 p_validation_entity_short_name in VARCHAR2,
10318 p_validation_tmplt_short_name in VARCHAR2,
10319 p_record_set_tmplt_short_name in VARCHAR2,
10320 p_scope in VARCHAR2,
10321 p_result OUT NOCOPY NUMBER ) IS
10322
10323 l_header_id NUMBER ;
10324 any_line_interfaced NUMBER := 0;
10325 -- 3740077
10326 line_payment_not_exists NUMBER :=0;
10327 -- 3740077
10328
10329 BEGIN
10330
10331 IF p_validation_entity_short_name = 'HEADER_SCREDIT' THEN
10332 l_header_id := oe_header_scredit_security.g_record.header_id;
10333 ELSIF p_validation_entity_short_name = 'HEADER_ADJ' THEN
10334 l_header_id := oe_header_adj_security.g_record.header_id;
10335 ELSIF p_validation_entity_short_name = 'HEADER_PAYMENT' THEN
10336 l_header_id := oe_header_payment_security.g_record.header_id;
10337 END IF;
10338
10339 IF l_header_id IS NULL OR
10340 l_header_id = FND_API.G_MISS_NUM
10341 THEN
10342 OE_MSG_PUB.Update_Msg_Context(p_attribute_code => null);
10343 p_result := 0;
10344 END IF;
10345
10346 -- 3740077 Added the If
10347 IF p_validation_entity_short_name = 'HEADER_PAYMENT' THEN
10348 IF (nvl(oe_header_payment_security.g_record.payment_collection_event,'PREPAY')='INVOICE' and
10349 oe_header_payment_security.g_record.line_id is NULL) THEN
10350
10351 BEGIN
10352 SELECT 1
10353 INTO line_payment_not_exists
10354 FROM OE_ORDER_LINES L
10355 WHERE HEADER_ID = l_header_id
10356 AND invoice_interface_status_code = 'YES'
10357 AND NOT EXISTS
10358 (select 'x' from oe_payments
10359 WHERE header_id = l_header_id
10360 AND line_id = L.line_id
10361 AND payment_type_code <> 'COMMITMENT'
10362 )
10363 AND ROWNUM=1;
10364 EXCEPTION
10365 WHEN NO_DATA_FOUND THEN
10366 p_result := 0;
10367 END;
10368
10369 IF line_payment_not_exists = 1 THEN
10370 p_result := 1;
10371 oe_debug_pub.add('skubendr going in');
10372 ELSE
10373 p_result := 0;
10374 END IF;
10375 ELSE
10376 -- this is a prepayment.
10377 p_result := 0;
10378 END IF;
10379 ELSE
10380 BEGIN
10381 SELECT 1
10382 INTO any_line_interfaced
10383 FROM OE_ORDER_LINES
10384 WHERE HEADER_ID = l_header_id
10385 AND invoice_interface_status_code = 'YES'
10386 AND ROWNUM = 1;
10387 EXCEPTION
10388 WHEN NO_DATA_FOUND THEN
10389 any_line_interfaced := 0;
10390 END;
10391 IF any_line_interfaced = 1 THEN
10392 p_result := 1;
10393 ELSE
10394 p_result := 0;
10395 END IF;
10396 END IF;
10397 END Any_Line_ARInterfaced;
10398
10399
10400
10401 Procedure All_Lines_ARInterfaced( p_application_id IN NUMBER,
10402 p_entity_short_name in VARCHAR2,
10403 p_validation_entity_short_name in VARCHAR2,
10404 p_validation_tmplt_short_name in VARCHAR2,
10405 p_record_set_tmplt_short_name in VARCHAR2,
10406 p_scope in VARCHAR2,
10407 p_result OUT NOCOPY NUMBER ) IS
10408
10409 l_header_id NUMBER ;
10410 any_line_not_interfaced NUMBER := 0;
10411 l_lines_exist NUMBER := 0;
10412 BEGIN
10413 IF p_validation_entity_short_name = 'HEADER_SCREDIT' THEN
10414 l_header_id := oe_header_scredit_security.g_record.header_id;
10415 ELSIF p_validation_entity_short_name = 'HEADER_ADJ' THEN
10416 l_header_id := oe_header_adj_security.g_record.header_id;
10417 -- 3740077
10418 ELSIF p_validation_entity_short_name = 'HEADER_PAYMENT' THEN
10419 l_header_id := oe_header_payment_security.g_record.header_id;
10420 ELSIF p_validation_entity_short_name = 'LINE_PAYMENT' THEN
10421 l_header_id := oe_line_payment_security.g_record.header_id;
10422 -- 3740077
10423 END IF;
10424
10425 IF l_header_id IS NULL OR
10426 l_header_id = FND_API.G_MISS_NUM
10427 THEN
10428 OE_MSG_PUB.Update_Msg_Context(p_attribute_code => null);
10429 p_result := 0;
10430 END IF;
10431
10432 IF l_header_id is not null and
10433 l_header_id <> FND_API.G_MISS_NUM THEN
10434
10435 BEGIN
10436 select 1 into l_lines_exist
10437 from oe_order_lines
10438 where header_id = l_header_id
10439 and rownum = 1;
10440
10441 EXCEPTION
10442 WHEN NO_DATA_FOUND THEN
10443 l_lines_exist := 0;
10444 p_result := 0;
10445 any_line_not_interfaced := 1;
10446 END;
10447
10448 END IF;
10449
10450 IF l_lines_exist = 1 THEN
10451
10452 BEGIN
10453 SELECT 1
10454 INTO any_line_not_interfaced
10455 FROM OE_ORDER_LINES
10456 WHERE HEADER_ID = l_header_id
10457 AND NVL(invoice_interface_status_code, 'NO') in ('NO', 'MANUAL-PENDING', 'RFR-PENDING', 'ACCEPTANCE-PENDING')
10458 AND
10459 ( --Bug 5230279
10460 open_flag = 'Y'
10461 OR (nvl(cancelled_flag, 'N') = 'Y' AND open_flag = 'N') -- bug 5181988
10462 ) -- bug 5230279
10463 AND ROWNUM = 1;
10464 EXCEPTION
10465 WHEN NO_DATA_FOUND THEN
10466 any_line_not_interfaced := 0;
10467 END;
10468
10469 END IF; -- if l_lines_exist = 1
10470
10471 IF any_line_not_interfaced = 1 THEN
10472 p_result := 0;
10473 ELSE
10474 p_result := 1;
10475 END IF;
10476
10477 END All_Lines_ARInterfaced;
10478
10479
10480 Procedure This_Line_ARInterfaced( p_application_id IN NUMBER,
10481 p_entity_short_name in VARCHAR2,
10482 p_validation_entity_short_name in VARCHAR2,
10483 p_validation_tmplt_short_name in VARCHAR2,
10484 p_record_set_tmplt_short_name in VARCHAR2,
10485 p_scope in VARCHAR2,
10486 p_result OUT NOCOPY NUMBER ) IS
10487
10488 l_line_id NUMBER ;
10489 this_line_interfaced NUMBER := 0;
10490 BEGIN
10491
10492 oe_debug_pub.add(' Entering This_Line_ARInterfaced');
10493 l_line_id := OE_LINE_SECURITY.g_record.line_id;
10494
10495 IF p_validation_entity_short_name = 'LINE_PAYMENT' THEN
10496 l_line_id := oe_line_payment_security.g_record.line_id;
10497 END IF;
10498
10499 oe_debug_pub.add(' Line Id :'||l_line_id);
10500
10501 IF l_line_id IS NULL OR
10502 l_line_id = FND_API.G_MISS_NUM
10503 THEN
10504 OE_MSG_PUB.Update_Msg_Context(p_attribute_code => null);
10505 p_result := 0;
10506 END IF;
10507
10508 BEGIN
10509 SELECT 1
10510 INTO this_line_interfaced
10511 FROM OE_ORDER_LINES
10512 WHERE LINE_ID = l_line_id
10513 AND invoice_interface_status_code = 'YES';
10514
10515 EXCEPTION
10516 WHEN NO_DATA_FOUND THEN
10517 this_line_interfaced := 0;
10518 END;
10519 IF this_line_interfaced = 1 THEN
10520 p_result := 1;
10521 ELSE
10522 p_result := 0;
10523 END IF;
10524 END This_Line_ARInterfaced;
10525
10526
10527 -- BUG# 7431368 : Performance fix : Start
10528 Procedure set_header_id ( p_header_id IN NUMBER)IS
10529 begin
10530 G_INVOICE_HEADER_ID := p_header_id;
10531 End;
10532
10533 Procedure set_line_id ( p_line_id IN NUMBER) IS
10534 begin
10535 G_INVOICE_LINE_ID := P_line_id;
10536 END;
10537
10538 /* Start of bug 10030712 */
10539 Procedure set_order_type ( p_order_type IN VARCHAR2 ) IS
10540 Begin
10541 G_ORDER_TYPE := p_order_type;
10542 End set_order_type;
10543
10544 Procedure set_order_number ( p_order_number IN NUMBER ) IS
10545 Begin
10546 G_ORDER_NUMBER := p_order_number;
10547 End set_order_number;
10548
10549 Function get_order_type return VARCHAR2 IS
10550 Begin
10551 return (G_ORDER_TYPE);
10552 End get_order_type;
10553
10554 Function get_order_number return VARCHAR2 IS
10555 Begin
10556 return( to_char(G_ORDER_NUMBER) );
10557 End get_order_number;
10558 /* End of bug 10030712 */
10559
10560 Function get_header_id return NUMBER IS
10561 begin
10562 return G_INVOICE_HEADER_ID;
10563 END;
10564
10565 Function get_line_id return NUMBER IS
10566 begin
10567 return G_INVOICE_LINE_ID;
10568 END;
10569 -- BUG# 7431368 : Performance fix : End
10570
10571
10572 END OE_Invoice_PUB;