DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_DELAYED_REQUESTS_UTIL

Source


1 PACKAGE BODY OE_Delayed_Requests_UTIL AS
2 /* $Header: OEXUREQB.pls 120.23.12010000.4 2008/11/19 10:59:21 vbkapoor ship $ */
3 
4 --  Global constant holding the package name
5 
6 G_PKG_NAME                    CONSTANT VARCHAR2(30) := 'OE_Delayed_Requests_UTIL';
7 
8 -- Procedure to validate quota percent total
9 
10 PROCEDURE Validate_LSC_QUOTA_TOTAL
11 ( x_return_status OUT NOCOPY Varchar2
12 
13   , p_line_id     IN NUMBER
14   ) IS
15 l_percent_total Number;
16 
17 Cursor C_LSC_Quota_Total(p_line_id number) IS
18    Select sum(Percent) Per_total
19    From oe_sales_credits sc,
20 	   oe_sales_credit_types sct
21    Where line_id = p_line_id
22    And sct.sales_credit_type_id = sc.sales_credit_type_id
23    And sct.quota_flag = 'Y';
24 
25 BEGIN
26 
27    oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.VALIDATE_LSC_QUOTA_TOTAL', 1);
28 
29    x_return_status := FND_API.G_RET_STS_SUCCESS;
30    OPEN C_LSC_Quota_Total(p_line_id);
31    FETCH C_LSC_Quota_Total
32    INTO  l_percent_total;
33    CLOSE C_LSC_Quota_Total;
34 
35 -- The Zero percent is added to include functionality which will exclude
36 -- Salesperson from getting Sales Credit
37    IF (l_percent_total <> 100 AND
38 	  l_percent_total <> 0)THEN
39        fnd_message.set_name('ONT','OE_VAL_TTL_LINE_CREDIT');
40        FND_MESSAGE.SET_TOKEN('TOTAL',to_char(l_percent_total));
41        OE_MSG_PUB.Add;
42        x_return_status := FND_API.G_RET_STS_ERROR;
43    END IF;
44 
45    oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.VALIDATE_LSC_QUOTA_TOTAL', 1);
46 
47 EXCEPTION
48 
49     WHEN FND_API.G_EXC_ERROR THEN
50 
51         x_return_status := FND_API.G_RET_STS_ERROR;
52 
53     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
54 
55         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
56 
57     WHEN OTHERS THEN
58 
59         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
60 
61         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
62         THEN
63             OE_MSG_PUB.Add_Exc_Msg
64             (   G_PKG_NAME
65             ,   'Validate_LSC_QUOTA_TOTAL'
66 );
67         END IF;
68 END Validate_LSC_QUOTA_TOTAL;
69 
70 -- Procedure to validate quota percent total
71 PROCEDURE Validate_HSC_QUOTA_TOTAL
72 ( x_return_status OUT NOCOPY Varchar2
73 
74   , p_header_id     IN NUMBER
75   ) IS
76 
77 BEGIN
78 
79    oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.VALIDATE_HSC_QUOTA_TOTAL', 1);
80 
81      OE_Validate_Header_Scredit.Validate_HSC_QUOTA_TOTAL(x_return_status => x_return_status,                                                                         p_header_id     => p_header_id);
82 
83    oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.VALIDATE_HSC_QUOTA_TOTAL', 1);
84 
85 EXCEPTION
86 
87     WHEN OTHERS THEN
88 
89         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
90 
91         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
92         THEN
93             OE_MSG_PUB.Add_Exc_Msg
94             (   G_PKG_NAME
95             ,   'Validate_HSC_QUOTA_TOTAL:'||SQLERRM
96             );
97         END IF;
98 END Validate_HSC_QUOTA_TOTAL;
99 
100 
101 PROCEDURE DFLT_Hscredit_Primary_Srep
102  ( p_header_id     IN Number
103   ,p_SalesRep_id    IN Number
104 ,x_return_status OUT NOCOPY Varchar2
105 
106    ) IS
107 l_sales_credits_count   Number;
108 l_sales_credit_id   Number;
109 
110 /* Changed the above cursor definition to fix the bug 1822931 */
111 l_scredit_type_id number;
112 l_Header_Scredit_rec          OE_Order_PUB.Header_Scredit_Rec_Type;
113 l_old_Header_Scredit_rec      OE_Order_PUB.Header_Scredit_Rec_Type;
114 l_Header_Scredit_tbl          OE_Order_PUB.Header_Scredit_Tbl_Type;
115 l_old_Header_Scredit_tbl      OE_Order_PUB.Header_Scredit_Tbl_Type;
116 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
117 l_return_status               VARCHAR2(30);
118 x_msg_count                   NUMBER;
119 x_msg_data                    VARCHAR2(2000);
120 Begin
121 
122     oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.DFLT_HSCREDIT_PRIMARY_SREP', 1);
123       OE_HEADER_SCREDIT_UTIL.DFLT_Hscredit_Primary_Srep
124          ( p_header_id    =>p_header_id
125           ,p_SalesRep_id  =>p_SalesRep_id
126           ,x_return_status=>x_return_status);
127     oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.DFLT_HSCREDIT_PRIMARY_SREP', 1);
128 
129 EXCEPTION
130 
131     WHEN OTHERS THEN
132 
133         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
134 
135         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
136         THEN
137             OE_MSG_PUB.Add_Exc_Msg
138             (   G_PKG_NAME
139             ,   'DFLT_Hscredit_Primary_Srep:'||SQLERRM
140             );
141         END IF;
142 End DFLT_Hscredit_Primary_Srep;
143 
144 
145 Procedure Cascade_Service_Scredit
146 ( x_return_status OUT NOCOPY Varchar2
147 
148  ,p_request_rec       IN  OE_ORDER_PUB.request_rec_type)
149 IS
150  l_Line_Scredit_tbl      OE_Order_PUB.Line_Scredit_Tbl_Type;
151  l_old_Line_Scredit_tbl  OE_Order_PUB.Line_Scredit_Tbl_Type;
152  l_control_rec           OE_GLOBALS.Control_Rec_Type;
153  l_line_id     NUMBER;
154  l_line_id1    NUMBER;
155  l_line_set_id NUMBER;
156  l_item_type_code VARCHAR2(30);
157  l_temp        NUMBER;
158  l_service_reference_line_id NUMBER;
159  l_inv_item_id number;
160  l_temp_inv_item_id number;
161  l_count NUMBER := 0;
162  l_new_quota_flag  VARCHAR2(1);
163  l_old_quota_flag  VARCHAR2(1);
164  l_per_total       NUMBER;
165  l_new_salesrep_id NUMBER;
166  l_old_salesrep_id NUMBER;
167  l_new_sales_credit_type_id NUMBER;
168  l_old_sales_credit_type_id NUMBER;
169  l_new_percent NUMBER;
170  l_old_percent NUMBER;
171  l_operation   VARCHAR2(30);
172  l_sales_credit_type_id NUMBER;
173  l_salesrep_id NUMBER;
174  l_percent NUMBER;
175  l_q_percent NUMBER;
176  l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
177  l_sales_credit_id NUMBER;
178  l_service_type_code VARCHAR2(30);  --Bug 4946843
179 
180  CURSOR PARENT IS
181  SELECT Line_id, item_type_code,line_set_id,
182 	   Service_reference_line_id,
183 	   inventory_item_id,
184 	   service_reference_type_code --Bug 4946843
185  FROM   OE_ORDER_LINES_ALL
186  WHERE  Line_id = l_line_id;
187 
188  CURSOR MODEL_SERVICES IS
189  SELECT /* MOAC_SQL_CHANGE */ line_id, header_id
190  FROM   OE_ORDER_LINES
191  WHERE  service_reference_line_id
192              in (SELECT line_id
193                  FROM   oe_order_lines_all
194                  WHERE top_model_line_id = l_line_id1)
195  AND   line_id <> l_line_id and
196  inventory_item_id = l_temp_inv_item_id;
197 
198 
199 BEGIN
200 
201   OE_DEBUG_PUB.Add('Entering OE_DELAYED_REQUESTS_UTIL.Cascade_Service_Scredit',1);
202   l_line_id          := p_request_rec.param8;
203   l_new_salesrep_id  := p_request_rec.param1;
204   l_old_salesrep_id  := p_request_rec.param2;
205   l_new_sales_credit_type_id  := p_request_rec.param3;
206   l_old_sales_credit_type_id  := p_request_rec.param4;
207   l_new_percent  := p_request_rec.param5;
208   l_old_percent  := p_request_rec.param6;
209   l_operation       := p_request_rec.param7;
210 
211   oe_debug_pub.add('l_line_id          :=  ' || p_request_rec.param8,2);
212   oe_debug_pub.add('l_new_salesrep_id  :=  ' || p_request_rec.param1,2);
213   oe_debug_pub.add('l_old_salesrep_id  := ' || p_request_rec.param2,2);
214   oe_debug_pub.add('l_new_sales_credit_type_id  :=' ||  p_request_rec.param3,2);
215   oe_debug_pub.add('l_old_sales_credit_type_id  := ' || p_request_rec.param4,2);
216   oe_debug_pub.add('l_new_percent  := ' || p_request_rec.param5,2);
217   oe_debug_pub.add('l_old_percent  := ' || p_request_rec.param6,2);
218   oe_debug_pub.add('l_operation       := ' || p_request_rec.param7,2);
219 
220   OPEN PARENT;
221   FETCH  PARENT
222   INTO  l_line_id,l_item_type_code,l_line_set_id,l_service_reference_line_id,
223   l_inv_item_id,l_service_type_code; --Bug 4946843
224   CLOSE PARENT;
225 
226   IF l_item_type_code = 'SERVICE'
227   AND l_service_type_code = 'ORDER' --Bug 4946843
228   AND l_service_reference_line_id IS NOT NULL THEN
229 
230     l_line_id := l_service_reference_line_id;
231     l_temp_inv_item_id := l_inv_item_id;
232 
233     OPEN PARENT;
234     FETCH PARENT
235     INTO  l_line_id1,l_item_type_code,l_line_set_id,l_service_reference_line_id
236     ,l_inv_item_id,l_service_type_code; --Bug 4946843
237     CLOSE PARENT;
238 
239     IF l_item_type_code = 'MODEL' THEN
240 
241 	  oe_debug_pub.Add('Need to cascade the sales credit');
242 
243 	FOR I IN MODEL_SERVICES LOOP
244       l_temp := 0;
245 	 -- For create check the existance of the record based on the
246 	 -- new data and for other operations check based on the old data.
247 
248 
249 	 IF l_operation = OE_GLOBALS.G_OPR_CREATE  THEN
250 
251 	    l_sales_credit_type_id := l_new_sales_credit_type_id;
252 	    l_salesrep_id := l_new_salesrep_id;
253 	    l_percent := l_new_percent;
254 	  oe_debug_pub.Add('In l_operation if');
255       ELSE
256 	    l_sales_credit_type_id := l_old_sales_credit_type_id;
257 	    l_salesrep_id := l_old_salesrep_id;
258 	    l_percent := l_old_percent;
259 	 END IF;
260       BEGIN
261        Select '1', sales_credit_id, nvl(percent,0)
262        INTO    l_temp, l_sales_credit_id, l_q_percent
263        from  oe_sales_credits
264        Where header_id = i.header_id
265        AND   line_id = i.line_id
266        And   sales_credit_type_id = l_sales_credit_type_id
267        AND   salesrep_id          = l_salesrep_id;
268 --       AND   Percent              = l_percent;
269 
270 	  oe_debug_pub.Add('l_q_percent  ' || l_q_percent);
271 	  oe_debug_pub.Add('l_percent  ' || l_percent);
272       EXCEPTION
273 
274        WHEN NO_DATA_FOUND THEN
275 
276          l_temp := 0;
277 
278        WHEN TOO_MANY_ROWS THEN
279 
280          l_temp := 2;
281 
282        WHEN OTHERS THEN
283 
284          l_temp := 10;
285 
286       END;
287 
288 	  oe_debug_pub.Add('l_temp: ' || l_temp);
289 	 --Get Quota flag.
290 
291 	 BEGIN
292 
293 	   Select quota_flag
294 	   Into   l_new_quota_flag
295 	   From   oe_sales_credit_types
296 	   Where  sales_credit_type_id = l_new_sales_credit_type_id;
297 
298 	   IF l_new_sales_credit_type_id <> l_old_sales_credit_type_id THEN
299 
300 	     Select quota_flag
301 	     Into   l_old_quota_flag
302 	     From   oe_sales_credit_types
303 	     Where  sales_credit_type_id = l_old_sales_credit_type_id;
304 
305 	   ELSE
306 
307 		 l_old_quota_flag := l_new_quota_flag;
308 
309 	   END IF;
310 
311       END;
312 
313        IF l_temp = 0 THEN -- Only when record not exist for child.
314 	    IF l_operation = OE_GLOBALS.G_OPR_CREATE THEN
315 
316           IF l_new_quota_flag = 'Y' THEN
317 
318 	       oe_debug_pub.Add(' In create  and quota');
319             Select nvl(sum(Percent),0) Per_total
320             Into  l_per_total
321             From  oe_sales_credits sc,
322                   oe_sales_credit_types sct
323             Where header_id = i.header_id
324             AND   line_id = i.line_id
325             And   sct.sales_credit_type_id = sc.sales_credit_type_id
326             And   sct.quota_flag = 'Y';
327 
328           END IF; -- Quota flag.
329 
330 	    oe_debug_pub.Add('  L_per_total : ' || nvl(l_per_total,0) || 'End');
331 	    oe_debug_pub.Add('  L_new_percent :  ' || nvl(l_new_percent,0) || 'End');
332 
333          IF (l_per_total + l_new_percent) <= 100
334          OR l_new_quota_flag = 'N'  THEN
335 
336 	       oe_debug_pub.Add('  Populate sales credit ');
337               -- Child.service does not have a sales credit and create the
338               -- same.
339             l_count := l_count + 1;
340 
341             l_Line_Scredit_tbl(l_count) := OE_Order_PUB.G_MISS_LINE_SCREDIT_REC;
342             l_Line_Scredit_tbl(l_count).Header_id := I.Header_id;
343             l_Line_Scredit_tbl(l_count).Line_id   := I.Line_id;
344             l_Line_Scredit_tbl(l_count).SalesRep_Id := l_new_salesRep_id;
345             l_Line_Scredit_tbl(l_count).Sales_credit_type_id :=
346                                                l_new_sales_credit_type_id;
347             l_Line_Scredit_tbl(l_count).PERCENT := l_new_percent;
348             l_Line_Scredit_tbl(l_count).Operation := OE_GLOBALS.G_OPR_CREATE;
349 
350          END IF; -- Check the percent
351 
352 	   END IF; -- Create.
353       ELSIF l_temp = 1
354 	 AND   l_percent = l_q_percent THEN
355 
356          --Sales credir record exists for the child service line.
357 
358         IF l_operation = OE_GLOBALS.G_OPR_UPDATE THEN
359 
360           oe_msg_pub.add('In Update');
361 
362           IF l_new_quota_flag = 'Y' THEN
363 
364             Select nvl(sum(Percent),0) Per_total
365             Into  l_per_total
366             From  oe_sales_credits sc,
367                   oe_sales_credit_types sct
368             Where header_id = i.header_id
369             AND   line_id = i.line_id
370             And   sct.sales_credit_type_id = sc.sales_credit_type_id
371             And   sct.quota_flag = 'Y';
372 
373 
374              IF l_old_quota_flag = 'Y' THEN
375 
376 			  l_per_total := l_per_total - nvl(l_old_percent,0) +
377 						  nvl(l_new_percent,0);
378 
379 		   ELSE
380 
381 			  l_per_total := l_per_total + nvl(l_new_percent,0);
382 
383              END IF;
384 
385           END IF; -- Quota flag.
386 
387 	    oe_debug_pub.Add('  L_per_total : ' || nvl(l_per_total,0) || 'End');
388 	    oe_debug_pub.Add('  L_new_percent :  ' || nvl(l_new_percent,0) || 'End');
389 
390 
391           IF nvl(l_per_total,0)  <= 100
392           OR l_new_quota_flag = 'N'  THEN
393 
394            l_count := l_count + 1;
395 
396 		 -- Setup new sales scredit record.
397            l_Line_Scredit_tbl(l_count) := OE_Order_PUB.G_MISS_LINE_SCREDIT_REC;
398            l_Line_Scredit_tbl(l_count).sales_credit_id := l_sales_credit_id;
399            l_Line_Scredit_tbl(l_count).Header_id := I.Header_id;
400            l_Line_Scredit_tbl(l_count).Line_id   := I.Line_id;
401            l_Line_Scredit_tbl(l_count).SalesRep_Id := l_new_salesRep_id;
402            l_Line_Scredit_tbl(l_count).Sales_credit_type_id :=
403                                              l_new_sales_credit_type_id;
404            l_Line_Scredit_tbl(l_count).PERCENT := l_new_percent;
405 		 /* Start Audit Trail */
406 		 l_Line_Scredit_tbl(l_count).change_reason := 'SYSTEM';
407 		 /* End Audit Trail */
408            l_Line_Scredit_tbl(l_count).Operation := OE_GLOBALS.G_OPR_UPDATE;
409 
410 		END IF; -- Percent.
411         ELSIF l_operation = OE_GLOBALS.G_OPR_DELETE
412 	   AND   l_percent = l_q_percent THEN
413 
414            l_count := l_count + 1;
415            l_Line_Scredit_tbl(l_count) := OE_Order_PUB.G_MISS_LINE_SCREDIT_REC;
416            l_Line_Scredit_tbl(l_count).sales_credit_id := l_sales_credit_id;
417            l_Line_Scredit_tbl(l_count).Header_id := I.Header_id;
418            l_Line_Scredit_tbl(l_count).Line_id   := I.Line_id;
419            l_Line_Scredit_tbl(l_count).Operation := OE_GLOBALS.G_OPR_DELETE;
420         END IF; -- operation
421       END IF; -- temp
422 	END LOOP;
423     END IF; -- Model.
424   END IF; -- Service
425 
426  oe_debug_pub.Add('  l_count :  ' || to_char(l_count));
427   IF l_count > 0 THEN -- Have some data that need to get cascaded.
428 
429    --  Call OE_Order_PVT.Process_order to insert sales credits.
430     -- Set recursion mode.
431     --   OE_GLOBALS.G_RECURSION_MODE := 'Y';
432 
433       OE_ORDER_PVT.Line_Scredits
434       (p_validation_level            => FND_API.G_VALID_LEVEL_FULL
435       ,p_control_rec                 => l_control_rec
436       ,p_x_Line_Scredit_tbl          => l_Line_Scredit_tbl
437       ,p_x_old_Line_Scredit_tbl      => l_old_Line_Scredit_tbl
438       ,x_return_status               => l_return_status);
439 
440     -- Reset recursion mode.
441     --   OE_GLOBALS.G_RECURSION_MODE := 'N';
442 
443        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
444            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
445        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
446            RAISE FND_API.G_EXC_ERROR;
447        END IF;
448 
449 --comment out for notification project
450 /*       OE_ORDER_PVT.Process_Requests_And_notify
451        ( p_process_requests       => FALSE
452         ,p_notify                 => TRUE
453         ,x_return_status          => l_return_status
454         ,p_Line_Scredit_tbl       => l_Line_Scredit_tbl
455         ,p_old_Line_Scredit_tbl   => l_old_Line_Scredit_tbl);
456 
457        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
458            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
459        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
460            RAISE FND_API.G_EXC_ERROR;
461        END IF;
462 */
463        -- Clear Table
464        l_Line_Scredit_tbl.DELETE;
465 
466   END IF; -- l_count.
467 
468   OE_DEBUG_PUB.Add('Exiting OE_DELAYED_REQUESTS_UTIL.Cascade_Service_Scredit',1);
469   x_return_status := l_return_status;
470 
471 EXCEPTION
472 
473     WHEN FND_API.G_EXC_ERROR THEN
474 
475         x_return_status := FND_API.G_RET_STS_ERROR;
476 
477     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
478 
479         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
480 
481     WHEN OTHERS THEN
482 
483         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
484 
485         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
486         THEN
487             OE_MSG_PUB.Add_Exc_Msg
488             (   G_PKG_NAME
489             ,   'CASCADE_SERVICE_SCREDIT'
490             );
491         END IF;
492 
493 
494 
495 END Cascade_Service_Scredit;
496 
497 PROCEDURE UPDATE_LINK_TO_LINE_ID
498 ( x_return_status OUT NOCOPY Varchar2
499 
500                   ,p_top_model_line_id  IN NUMBER
501                  )
502 IS
503 BEGIN
504 
505         null;
506 
507 END UPDATE_LINK_TO_LINE_ID;
508 
509 -- Procedure to Check for Duplicate Discounts
510 PROCEDURE check_duplicate
511 (p_request_rec	     IN  oe_order_pub.request_rec_type,
512 x_return_status OUT NOCOPY VARCHAR2)
513 
514   IS
515 l_entity_code	     VARCHAR2(30);
516 l_entity_id	     NUMBER := NULL;
517 l_header_id	     NUMBER := NULL;
518 l_line_id		     NUMBER := NULL;
519 l_discount_id     	NUMBER := 0;
520 l_duplicate	     VARCHAR2(30) := NULL;
521 l_return_status	VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
522 
523 DUPLICATE_DISCOUNT	EXCEPTION;
524 
525 BEGIN
526 
527    oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.CHECK_DUPLICATE', 1);
528 
529    l_entity_id		:= p_request_rec.entity_id;
530    l_entity_code	:= p_request_rec.entity_code;
531    l_discount_id	:= To_number(p_request_rec.param1);
532    l_header_id		:= To_number(p_request_rec.param2);
533    l_line_id		:= To_number(p_request_rec.param3);
534 
535    oe_debug_pub.ADD('OEXSRLNB: Check Duplicate. '||
536 		    ' entity_code = ' || l_entity_code, 2);
537 
538 
539    -- Check if same discount has already been applied
540    -- before on the header or any line
541    IF l_entity_code = OE_GLOBALS.G_ENTITY_HEADER_ADJ THEN
542 
543      SELECT  'DUPLICATE_DISCOUNT'
544 	INTO    l_duplicate
545 	FROM    oe_price_adjustments
546 	WHERE   header_id = l_header_id
547 	AND     discount_id = l_discount_id
548 	AND     price_adjustment_id <> Nvl(l_entity_id, -1)
549 	AND     line_id IS NULL;
550 
551 	IF SQL%rowcount <> 0
552 	  THEN
553 	   l_return_status := FND_API.G_RET_STS_ERROR;
554 
555 	   IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
556 	     THEN
557 
558 	      fnd_message.set_name('ONT', 'OE_DIS_DUPLICATE_ORD_DISC');
559 	      OE_MSG_PUB.Add;
560 
561 	   END IF;
562 
563 	   RAISE DUPLICATE_DISCOUNT;
564 
565 	END IF;
566 
567 
568     -- Check if same discount has already been applied
569     -- before on the line
570     ELSIF l_entity_code = OE_GLOBALS.G_ENTITY_LINE_ADJ THEN
571 
572       SELECT  'DUPLICATE_DISCOUNT'
573 	 INTO    l_duplicate
574 	 FROM    oe_price_adjustments
575 	 WHERE   header_id = l_header_id
576 	 AND     discount_id = l_discount_id
577 	 AND     line_id = l_line_id
578 	 AND     price_adjustment_id <> Nvl(l_entity_id, -1);
579 
580       IF SQL%rowcount <> 0 THEN
581 	    l_return_status := FND_API.G_RET_STS_ERROR;
582 
583 	    IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
584 	    THEN
585 
586 	       fnd_message.set_name('ONT', 'OE_DIS_DUPLICATE_LIN_DISC');
587 	       OE_MSG_PUB.Add;
588 
589 	    END IF;
590 
591 	    RAISE DUPLICATE_DISCOUNT;
592 
593       END IF;
594 
595    END IF;
596 
597 
598    x_return_status := l_return_status;
599 
600    oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.CHECK_DUPLICATE', 1);
601 
602 EXCEPTION
603 
604    WHEN NO_DATA_FOUND OR DUPLICATE_DISCOUNT
605      THEN
606       x_return_status := l_return_status;
607 
608    WHEN OTHERS
609      THEN
610       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
611 
612       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
613         THEN
614 	 OE_MSG_PUB.Add_Exc_Msg
615             (   G_PKG_NAME
616             ,   'CHECK_DUPLICATE'
617             );
618       END IF;
619 
620 END CHECK_DUPLICATE;
621 
622 --Procedure to Check Fixed price Discounts
623 PROCEDURE check_fixed_price
624 (p_request_rec	   IN oe_order_pub.request_rec_type,
625 x_return_status OUT NOCOPY VARCHAR2)
626 
627  IS
628 l_entity_code	     VARCHAR2(30);
629 l_entity_id	     NUMBER := NULL;
630 l_header_id	     NUMBER := NULL;
631 l_line_id		     NUMBER := NULL;
632 l_discount_line_id	NUMBER := 0;
633 l_count		     NUMBER;
634 l_discount_count	NUMBER;
635 l_fixed_price	     VARCHAR2(30) := NULL;
636 l_discount_name     VARCHAR2(30) := NULL;
637 l_return_status	VARCHAR2(1)  := FND_API.G_RET_STS_SUCCESS;
638 l_number		     NUMBER := 0;
639 
640 
641 FIXED_PRICE	EXCEPTION;
642 FIXED_PRICE_VIOLATE	EXCEPTION;
643 
644 CURSOR all_adjustments IS
645 SELECT count(p.price_adjustment_id)
646 FROM   oe_price_adjustments p
647 WHERE  p.header_id = l_header_id
648 AND    (p.line_id = l_line_id
649 OR      p.line_id IS NULL) ;
650 
651 CURSOR hdr_line_adjustments IS
652 SELECT p.line_id
653 FROM   oe_price_adjustments p
654 WHERE  p.header_id = l_header_id
655 AND    p.line_id IS NOT NULL
656 ORDER by p.line_id;
657 
658 
659 BEGIN
660 
661    oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.CHECK_FIXED_PRICE', 1);
662 
663    l_entity_id		   := p_request_rec.entity_id;
664    l_entity_code	   := p_request_rec.entity_code;
665    l_discount_line_id  := To_number(p_request_rec.param1);
666    l_header_id		   := To_number(p_request_rec.param2);
667    l_line_id		   := To_number(p_request_rec.param3);
668 
669 
670    oe_debug_pub.ADD('OEXSRLNB: Check Fixed Price. '||
671 		    ' entity_code = ' || l_entity_code, 2);
672 
673    IF l_entity_code = OE_GLOBALS.G_ENTITY_HEADER_ADJ THEN
674       FOR l_hdr_adjustment IN hdr_line_adjustments LOOP
675 
676 	     l_line_id := l_hdr_adjustment.line_id;
677 	     l_number := l_number + 1;
678 
679 	     OPEN  all_adjustments;
680 	     FETCH all_adjustments INTO l_discount_count;
681 	     CLOSE all_adjustments;
682 
683           SELECT  count(d.name)
684 	     INTO  l_count
685 	     FROM  oe_price_adjustments adj,
686                 oe_discount_lines dln,
687 	           oe_discounts d
688 	     WHERE adj.header_id = l_header_id
689 	     AND   Nvl(adj.line_id, l_line_id) = l_line_id
690           AND   d.discount_id = adj.discount_id
691 	     AND   dln.discount_line_id = adj.discount_line_id
692 	     AND   dln.price IS NOT NULL
693 	     AND   ROWNUM = 1;
694 
695 	     IF l_count <> 0
696           AND l_discount_count = 1 THEN
697            oe_debug_pub.ADD('OEXSRLNB2: Check Fixed Price. '||
698 		    ' entity_code = ' || l_entity_code, 2);
699 	       l_return_status := FND_API.G_RET_STS_ERROR;
700 	       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
701 	       THEN
702 
703 	         FND_MESSAGE.SET_NAME('ONT', 'OE_DIS_FIXED_PRICE_HEADER');
704 	         FND_MESSAGE.SET_TOKEN('NUMBER', to_char(l_number));
705 	         OE_MSG_PUB.Add;
706 
707 
708 	       END IF;
709 	       RAISE FIXED_PRICE_VIOLATE;
710 	     END IF;
711       END LOOP;
712    END IF;
713 
714    IF l_entity_code = OE_GLOBALS.G_ENTITY_LINE_ADJ THEN
715 
716       SELECT  count(adj.price_adjustment_id)
717 	 INTO    l_count
718 	 FROM    oe_price_adjustments adj
719 	 WHERE   adj.header_id = l_header_id
720 	 AND     Nvl(adj.line_id, l_line_id) = l_line_id
721 	 AND     exists
722 		   (SELECT 'fixed_price'
723 		    FROM   oe_discount_lines dln
724 		    WHERE  dln.discount_line_id = l_discount_line_id
725 		    AND    dln.price IS NOT NULL)
726 	 AND ROWNUM = 1;
727 
728       IF l_count <> 0 THEN
729 
730 	   IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
731 	   THEN
732 
733 	     FND_MESSAGE.SET_NAME('ONT', 'OE_DIS_FIXED_PRICE');
734 	     OE_MSG_PUB.Add;
735 
736 	   END IF;
737 
738 	   RAISE FIXED_PRICE;
739 
740       END IF;
741 
742 	 OPEN all_adjustments;
743 	 FETCH all_adjustments INTO l_discount_count;
744 	 CLOSE all_adjustments;
745 
746 
747       SELECT  d.name
748 	 INTO    l_fixed_price
749 	 FROM    oe_price_adjustments adj,
750               oe_discount_lines dln,
751 	         oe_discounts d
752 	 WHERE   adj.header_id = l_header_id
753 	 AND     Nvl(adj.line_id, l_line_id) = l_line_id
754       AND     d.discount_id = adj.discount_id
755 	 AND     dln.discount_line_id = adj.discount_line_id
756 	 AND     dln.price IS NOT NULL
757 	 AND     ROWNUM = 1;
758 
759        oe_debug_pub.ADD('OEXSRLNB1: Check Fixed Price. '||
760 		    ' entity_code = ' || l_entity_code, 2);
761       IF  SQL%rowcount <> 0
762       AND l_discount_count = 1 THEN
763          oe_debug_pub.ADD('OEXSRLNB2: Check Fixed Price. '||
764 		    ' entity_code = ' || l_entity_code, 2);
765 	    l_return_status := FND_API.G_RET_STS_ERROR;
766 	    IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
767 	    THEN
768 
769 	      FND_MESSAGE.SET_NAME('ONT', 'OE_DIS_FIXED_PRICE_VIOL');
770 	      FND_MESSAGE.SET_TOKEN('NAME', l_fixed_price);
771 	      OE_MSG_PUB.Add;
772 
773 	    END IF;
774 
775 	    RAISE FIXED_PRICE_VIOLATE;
776 
777       END IF;
778    END IF;
779 
780 
781    x_return_status := FND_API.G_RET_STS_SUCCESS;
782 
783    oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.CHECK_FIXED_PRICE', 1);
784 
785 EXCEPTION
786 
787    WHEN NO_DATA_FOUND OR FIXED_PRICE
788      THEN
789       x_return_status := FND_API.G_RET_STS_SUCCESS;
790 
791    WHEN  FIXED_PRICE_VIOLATE
792      THEN
793       x_return_status := l_return_status;
794 
795 
796    WHEN OTHERS
797      THEN
798       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
799 
800       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
801         THEN
802 	 OE_MSG_PUB.Add_Exc_Msg
803             (   G_PKG_NAME
804             ,   'CHECK_FIXED_PRICE'
805             );
806       END IF;
807 
808 END CHECK_FIXED_PRICE;
809 
810 
811 PROCEDURE check_percentage
812 (p_request_rec	IN oe_order_pub.request_rec_type,
813 x_return_status OUT NOCOPY VARCHAR2)
814 
815 IS
816 l_control_rec	     OE_GLOBALS.Control_Rec_Type;
817 l_entity_code	     VARCHAR2(30);
818 l_entity_id	     NUMBER := NULL;
819 l_header_id	     NUMBER := NULL;
820 l_line_id		     NUMBER := NULL;
821 l_percentage	     NUMBER := 0;
822 l_percent_total	NUMBER := 0;
823 l_return_status	VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
824 l_apply_order_adjs	VARCHAR2(1) :=
825                     Nvl(fnd_profile.value('OE_APPLY_ORDER_ADJS_TO_SERVICE'),
826 				   'N');
827 
828 percentage_exceeded	EXCEPTION;
829 
830 
831 CURSOR all_adjustments IS
832 SELECT  p.price_adjustment_id, Nvl(p.line_id, -1) line_id
833   FROM  oe_price_adjustments p,
834         oe_order_lines o
835  WHERE  p.header_id = l_header_id
836   AND   o.header_id = l_header_id
837   AND  (p.line_id = o.line_id
838    OR   p.line_id IS NULL)
839 ORDER  BY p.line_id;
840 
841 
842 CURSOR hdr_adj_total IS
843 SELECT Nvl(SUM(percent), 0)
844   FROM oe_price_adjustments p
845  WHERE header_id = l_header_id
846    AND  line_id IS NULL;
847 
848 
849 CURSOR line_adj_total IS
850 SELECT Nvl(SUM(percent), 0) + l_percent_total
851   FROM oe_price_adjustments
852  WHERE header_id = l_header_id
853    AND  line_id = l_line_id;
854 
855 
856 
857 CURSOR max_line_adj_total IS
858 SELECT NVL( MAX(SUM(PERCENT)), 0) + l_percent_total
859   FROM OE_PRICE_ADJUSTMENTS P, OE_ORDER_LINES L
860  WHERE P.HEADER_ID = l_header_id
861    AND P.LINE_ID IS NOT NULL
862    AND P.LINE_ID = L.LINE_ID
863 GROUP BY P.line_id;
864 
865 
866 BEGIN
867 
868    oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.CHECK_PERCENTAGE', 1);
869 
870    l_entity_code	:= p_request_rec.entity_code;
871 
872    oe_debug_pub.ADD('OEXSRLNB: Check Percentage. '||
873 		    ' entity_code = ' || l_entity_code, 2);
874 
875 
876    -- Check if maximum percentage has not been execeded on the
877    -- header price adjustment
878    IF l_entity_code = OE_GLOBALS.G_ENTITY_HEADER_ADJ
879      THEN
880 
881       l_header_id	:= p_request_rec.entity_id;
882 
883       oe_debug_pub.ADD('OEXSRLNB: check header percentage', 2);
884 
885       OPEN hdr_adj_total;
886       FETCH hdr_adj_total INTO l_percent_total;
887       CLOSE hdr_adj_total;
888 
889       OPEN max_line_adj_total;
890       FETCH max_line_adj_total INTO l_percent_total;
891       CLOSE max_line_adj_total;
892 
893       oe_debug_pub.ADD('OEXSRLNB: maximum percentage total = ' ||
894 		       To_char(l_percent_total), 2);
895 
896       IF ( l_percent_total > 100 ) THEN
897 
898 	    l_return_status := FND_API.G_RET_STS_ERROR;
899 
900 	    IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
901 	    THEN
902 
903 	      FND_MESSAGE.SET_NAME('ONT','OE_DIS_ADJUSTMENT_TOTAL');
904 	      FND_MESSAGE.SET_TOKEN('TOTAL', To_char(l_percent_total));
905 	      OE_MSG_PUB.Add;
906 
907 	    END IF;
908 
909 	    RAISE percentage_exceeded;
910 
911       END IF;
912 
913 
914     -- Check if maximum percentage has not been execeded on the
915     -- line price adjustment
916     ELSIF l_entity_code = OE_GLOBALS.G_ENTITY_LINE_ADJ THEN
917 
918       l_line_id		:= p_request_rec.entity_id;
919       l_header_id	:= To_number(p_request_rec.param1);
920 
921       oe_debug_pub.ADD('OEXSRLNB: check line percentage', 2);
922 
923       OPEN hdr_adj_total;
924       FETCH hdr_adj_total INTO l_percent_total;
925       CLOSE hdr_adj_total;
926 
927       OPEN line_adj_total;
928       FETCH line_adj_total INTO l_percent_total;
929       CLOSE line_adj_total;
930 
931       oe_debug_pub.ADD('OEXSRLNB: line percentage total = ' ||
932 		       To_char(l_percent_total), 2);
933 
934 
935       IF ( l_percent_total > 100 ) THEN
936 
937 	    l_return_status := FND_API.G_RET_STS_ERROR;
938 
939 	    IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
940 	    THEN
941 
942 	      FND_MESSAGE.SET_NAME('ONT','OE_DIS_ADJUSTMENT_TOTAL');
943 	      FND_MESSAGE.SET_TOKEN('TOTAL', To_char(l_percent_total));
944 	      OE_MSG_PUB.Add;
945 
946 	    END IF;
947 
948 	    RAISE percentage_exceeded;
949 
950       END IF;
951 
952 
953     -- Check all header and line level price adjustments in execess of
954     -- maximum allowable price adjustments
955     -- This is a call from Order Import
956 
957     ELSIF l_entity_code IS NULL
958     THEN
959 
960       FOR l_adjustment IN all_adjustments LOOP
961 
962 	 -- How to get header id in this case ????????
963 	   l_line_id := l_adjustment.line_id;
964 	   l_entity_id := l_adjustment.price_adjustment_id;
965 
966 	   IF l_line_id = -1 THEN	-- header level price adjustment
967 
968 	    OPEN hdr_adj_total;
969 	    FETCH hdr_adj_total INTO l_percent_total;
970 	    CLOSE hdr_adj_total;
971 
972 	    OPEN max_line_adj_total;
973 	    FETCH max_line_adj_total INTO l_percent_total;
974 	    CLOSE max_line_adj_total;
975 
976 	   ELSE			-- line level price adjustment
977 
978 	    OPEN line_adj_total;
979 	    FETCH line_adj_total INTO l_percent_total;
980 	    CLOSE line_adj_total;
981 
982 	   END IF;
983 
984       END LOOP;
985 
986    END IF;
987 
988 
989       x_return_status := l_return_status;
990 
991    oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.CHECK_PERCENTAGE', 1);
992 
993 EXCEPTION
994 
995    WHEN PERCENTAGE_EXCEEDED
996      THEN
997       x_return_status := l_return_status;
998 
999 
1000    WHEN OTHERS THEN
1001         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1002 
1003 	IF line_adj_total%isopen THEN
1004 	   CLOSE line_adj_total;
1005 	END IF;
1006 
1007 	IF all_adjustments%isopen THEN
1008 	   CLOSE all_adjustments;
1009 	END IF;
1010 
1011 	IF hdr_adj_total%isopen THEN
1012 	   CLOSE hdr_adj_total;
1013 	END IF;
1014 
1015 	IF max_line_adj_total%isopen THEN
1016 	   CLOSE max_line_adj_total;
1017 	END IF;
1018 
1019         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1020         THEN
1021             OE_MSG_PUB.Add_Exc_Msg
1022             (   G_PKG_NAME
1023             ,   'CHECK_PERCENTAGE'
1024             );
1025         END IF;
1026 
1027 END check_percentage;
1028 
1029 PROCEDURE CREATE_CONFIG_ITEM
1030 ( x_return_status OUT NOCOPY Varchar2
1031 
1032                   ,p_top_model_line_id  IN NUMBER
1033                   ,p_header_id          IN NUMBER
1034                  )
1035 IS
1036   l_return_status             VARCHAR2(1);
1037   l_control_rec               OE_GLOBALS.Control_Rec_Type;
1038   l_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
1039   l_old_line_tbl              OE_Order_PUB.Line_Tbl_Type;
1040   l_line_rec                  OE_Order_PUB.Line_Rec_Type;
1041   l_api_name                  CONSTANT VARCHAR2(30) := 'Insert_Order';
1042   l_line_id			     NUMBER;
1043   l_component_sequence_id	NUMBER;
1044   l_component_code		     VARCHAR2(1000);
1045   l_component_item_id		NUMBER;
1046   l_sort_order			     VARCHAR2(240);
1047   l_component_quantity		NUMBER;
1048   l_bom_item_type		     VARCHAR2(30);
1049   l_top_model_line_id         NUMBER;
1050   l_config_rec     		     OE_ORDER_PUB.line_rec_type;
1051   l_select_flag			VARCHAR2(1);
1052   l_bill_sequence_id		NUMBER;
1053   l_top_bill_sequence_id	     NUMBER;
1054   l_option_number		     NUMBER;
1055   l_request_rec      		OE_Order_Pub.request_rec_type;
1056   l_request_tbl			OE_Order_Pub.Request_Tbl_Type;
1057   req_ind			          NUMBER;
1058 BEGIN
1059 
1060    oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.CREATE_CONFIG_ITEM', 1);
1061 
1062 
1063      oe_debug_pub.add('In procedure Create_Config', 2);
1064 
1065      l_line_rec       := OE_Order_PUB.G_MISS_LINE_REC;
1066 
1067 
1068 -- Set Control Record
1069 
1070      l_control_rec.controlled_operation := TRUE;
1071      l_control_rec.default_attributes   := TRUE;
1072      l_control_rec.change_attributes    := TRUE;
1073      l_control_rec.validate_entity      := TRUE;
1074      l_control_rec.write_to_DB          := TRUE;
1075      l_control_rec.process              := FALSE;
1076 
1077 
1078      OE_DEBUG_PUB.ADD('Loading top_model_line_id: ' || p_top_model_line_id, 2);
1079         l_config_rec :=
1080     	     OE_Order_Cache.Load_Top_Model_Line (p_top_model_line_id);
1081 
1082      l_line_rec.top_model_line_id   := p_top_model_line_id;
1083      l_line_rec.header_id           := p_header_id;
1084      l_line_rec.item_type_code      := OE_GLOBALS.G_ITEM_CONFIG;
1085      l_line_rec.line_number         := l_config_rec.line_number;
1086      l_line_rec.shipment_number     := l_config_rec.shipment_number;
1087      l_line_rec.option_number       := NULL;
1088 --     l_line_rec.component_number := NULL;
1089      l_line_rec.operation           := OE_GLOBALS.G_OPR_CREATE;
1090 
1091      l_line_tbl(1) := l_line_rec;
1092 
1093     -- Set recursion mode.
1094     --  OE_GLOBALS.G_RECURSION_MODE := 'Y';
1095 
1096    OE_ORDER_PVT.Lines
1097         (p_validation_level  => FND_API.G_VALID_LEVEL_FULL
1098     	   ,p_control_rec       => l_control_rec
1099         ,p_x_line_tbl        => l_line_tbl
1100         ,p_x_old_line_tbl    => l_old_line_tbl
1101 	   ,x_return_status     => l_return_status);
1102 
1103     -- Reset recursion mode.
1104     --  OE_GLOBALS.G_RECURSION_MODE := 'N';
1105 
1106      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1107         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1108      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1109         RAISE FND_API.G_EXC_ERROR;
1110      END IF;
1111 
1112 --comment out for notification project
1113 /*    OE_ORDER_PVT.Process_Requests_And_notify
1114     ( p_process_requests       => FALSE
1115      ,p_notify                 => TRUE
1116      ,x_return_status          => l_return_status
1117      ,p_line_tbl               => l_line_tbl
1118      ,p_old_line_tbl           => l_old_line_tbl);
1119 
1120     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1121         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1122     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1123         RAISE FND_API.G_EXC_ERROR;
1124     END IF;
1125 */
1126 
1127      oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.CREATE_CONFIG_ITEM', 1);
1128 
1129 EXCEPTION
1130 
1131     WHEN FND_API.G_EXC_ERROR THEN
1132 
1133         x_return_status := FND_API.G_RET_STS_ERROR;
1134 
1135     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1136 
1137         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1138 
1139     WHEN OTHERS THEN
1140 
1141         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1142 
1143         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1144         THEN
1145             OE_MSG_PUB.Add_Exc_Msg
1146             (   G_PKG_NAME
1147             ,   'Validate_LSC_QUOTA_TOTAL'
1148         );
1149        END IF;
1150 END CREATE_CONFIG_ITEM;
1151 
1152 PROCEDURE INS_INCLUDED_ITEMS
1153 ( x_return_status OUT NOCOPY Varchar2
1154 
1155                   ,p_line_id            IN NUMBER
1156                  )
1157 IS
1158 BEGIN
1159 
1160     oe_debug_pub.add('Entering OE_DELAYED_REQUESTS_UTIL.INS_INCLUDED_ITEMS', 1);
1161 
1162     OE_DEBUG_PUB.ADD('Inserting Included Items', 2);
1163 
1164     oe_debug_pub.add('Exiting OE_DELAYED_REQUESTS_UTIL.INS_INCLUDED_ITEMS', 1);
1165     Null;
1166 END;
1167 
1168 PROCEDURE  verify_payment
1169 ( x_return_status OUT NOCOPY varchar2
1170 
1171                ,p_header_id          IN  Number
1172                )
1173 IS
1174 l_return_status     VARCHAR2(30);
1175 l_msg_count         NUMBER;
1176 l_msg_data          VARCHAR2(2000);
1177 BEGIN
1178 
1179       x_return_status := FND_API.G_RET_STS_SUCCESS;
1180 
1181       oe_debug_pub.ADD('Entering delayed request utility for verify payment',1);
1182 
1183 	 OE_Verify_Payment_PUB.Verify_Payment
1184                              ( p_header_id      => p_header_id
1185                              , p_calling_action => 'UPDATE'
1186                              , p_delayed_request=> FND_API.G_TRUE
1187                              , p_msg_count      => l_msg_count
1188                              , p_msg_data       => l_msg_data
1189                              , p_return_status  => l_return_status
1190                              );
1191 
1192       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1193         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1194       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1195         RAISE FND_API.G_EXC_ERROR;
1196       END IF;
1197 
1198       oe_debug_pub.ADD('Exiting delayed request utility for verify payment',1);
1199 
1200    EXCEPTION
1201 
1202     WHEN FND_API.G_EXC_ERROR THEN
1203 
1204         x_return_status := FND_API.G_RET_STS_ERROR;
1205 
1206     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1207 
1208         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1209 
1210     WHEN OTHERS THEN
1211 
1212         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1213 
1214         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1215         THEN
1216             OE_MSG_PUB.Add_Exc_Msg
1217             (   G_PKG_NAME
1218             ,   'Verify_Payment'
1219             );
1220         END IF;
1221 
1222 END Verify_Payment;
1223 
1224 
1225 /* procedure insert_rma_scredit_adjustment
1226    To insert sales credit of corresponding RMA lines.
1227    if sales credit exists on the existing line, delete them first,
1228    then insert new ones taken from the referenced line.
1229    Price adjustments has been moved to apply change attributes
1230 */
1231 Procedure INSERT_RMA_SCREDIT_ADJUSTMENT
1232 (p_line_id       IN  NUMBER
1233 ,x_return_status OUT NOCOPY VARCHAR2
1234 
1235 )
1236 IS
1237 l_Line_Scredit_tbl 	OE_Order_PUB.Line_Scredit_Tbl_Type;
1238 l_ref_header_id   	NUMBER;
1239 l_ref_line_id   	NUMBER;
1240 l_header_id		NUMBER;
1241 I               	NUMBER := 1;
1242 I1                  NUMBER := 1;
1243 I2                  NUMBER := 1;
1244 l_api_name 		CONSTANT VARCHAR(30) := 'INSERT_RMA_SCREDIT_ADJUSTMENT';
1245 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
1246 l_x_Line_Scredit_tbl          OE_Order_PUB.Line_Scredit_Tbl_Type;
1247 l_x_old_Line_Scredit_tbl      OE_Order_PUB.Line_Scredit_Tbl_Type;
1248 l_return_status               VARCHAR2(30);
1249 l_count                       NUMBER := 0;
1250 l_split_by                    VARCHAR2(30);
1251 l_src_doc_type_id             NUMBER; -- added for bug 6778016
1252 BEGIN
1253 
1254   OE_DEBUG_PUB.ADD('RMA: In INSERT_RMA_SCREDIT_ADJUSTMENT',1);
1255 
1256   OE_DEBUG_PUB.ADD('RMA: Line Id is '||TO_CHAR(p_line_id),2);
1257 
1258   x_return_status := FND_API.G_RET_STS_SUCCESS;
1259 
1260  -- bug 3317323
1261   BEGIN
1262    SELECT header_id, reference_header_id, reference_line_id,split_by
1263          ,SOURCE_DOCUMENT_TYPE_ID --added source document id as a part of 6778016
1264      INTO l_header_id,l_ref_header_id, l_ref_line_id, l_split_by
1265           ,l_src_doc_type_id           --added l_src_doc_type_id as a part of 6778016
1266      FROM oe_order_lines
1267     WHERE line_id = p_line_id;
1268   EXCEPTION
1269    WHEN NO_DATA_FOUND THEN
1270       OE_DEBUG_PUB.ADD('Invalid line_id',1);
1271          RETURN;
1272   END;
1273   IF l_split_by = 'SYSTEM' THEN
1274      RETURN;
1275   END IF;
1276  -- bug 3317323
1277 
1278   -- delete the existing Sales Credit on the RMA line
1279   BEGIN
1280       OE_Line_Scredit_Util.Lock_Rows
1281       (p_line_id          => p_line_id
1282       ,x_line_Scredit_tbl => l_Line_Scredit_tbl
1283 	 ,x_return_status    => l_return_status);
1284 
1285       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1286           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1287       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1288           RAISE FND_API.G_EXC_ERROR;
1289       END IF;
1290   EXCEPTION
1291 	 WHEN NO_DATA_FOUND THEN
1292           OE_DEBUG_PUB.ADD('There are no existing sales credits to delete',1);
1293 		NULL;
1294   END;
1295 
1296   IF l_Line_Scredit_tbl.COUNT > 0 THEN
1297 
1298     FOR I IN l_Line_Scredit_tbl.FIRST .. l_Line_Scredit_tbl.LAST LOOP
1299 
1300       l_x_Line_Scredit_tbl(I):= l_line_Scredit_tbl(I);
1301       l_x_Line_Scredit_tbl(I).operation := OE_GLOBALS.G_OPR_DELETE;
1302 
1303     END LOOP;
1304 
1305     -- Clear Table
1306     l_Line_Scredit_tbl.DELETE;
1307 
1308   END IF; /* end delete existing sales credit */
1309 
1310   -- get new sales credit and insert into RMA
1311 
1312   -- get the reference_id first
1313  /* moved to the beginning of the procedure to fix bug 3317323
1314   BEGIN
1315    SELECT header_id, reference_header_id, reference_line_id
1316      INTO l_header_id,l_ref_header_id, l_ref_line_id
1317      FROM oe_order_lines
1318     WHERE line_id = p_line_id;
1319   EXCEPTION
1320    WHEN NO_DATA_FOUND THEN
1321       OE_DEBUG_PUB.ADD('Invalid line_id',1);
1322 	 RETURN;
1323   END;
1324  */
1325 
1326   BEGIN
1327   OE_Line_Scredit_Util.Query_Rows(p_line_id          => l_ref_line_id
1328                                  ,x_line_Scredit_tbl => l_Line_Scredit_tbl);
1329   EXCEPTION
1330    WHEN NO_DATA_FOUND THEN
1331 	 --RETURN;
1332       OE_DEBUG_PUB.ADD('There are no Sales credits on the reference line',1);
1333 	 NULL;
1334   END;
1335 
1336   IF l_Line_Scredit_tbl.COUNT > 0 THEN
1337 
1338     l_count := l_x_line_Scredit_tbl.count;
1339 
1340     FOR I IN l_Line_Scredit_tbl.FIRST .. l_Line_Scredit_tbl.LAST LOOP
1341 
1342       l_x_Line_Scredit_tbl(l_count + I):= l_line_Scredit_tbl(I);
1343       l_x_Line_Scredit_tbl(l_count + I).operation := OE_GLOBALS.G_OPR_CREATE;
1344       l_x_Line_Scredit_tbl(l_count + I).header_id := l_header_id;
1345       l_x_Line_Scredit_tbl(l_count + I).line_id   := p_line_id;
1346       l_x_Line_Scredit_tbl(l_count + I).sales_credit_id := FND_API.G_MISS_NUM;
1347 
1348     END LOOP;
1349 
1350   END IF; /* end inserting sales credit */
1351 
1352   IF l_x_Line_Scredit_tbl.COUNT > 0 THEN
1353     --  Call OE_Order_PVT.Process_order to insert sales credits.
1354     -- Set recursion mode.
1355     -- OE_GLOBALS.G_RECURSION_MODE := 'Y';
1356 
1357     /* Adding the if condition for bug 6778016/
1358     /* The control record structure passsed while calling process_order oe_copy_util.copy_order
1359        has process_partial to true and clear_dependents to false. However, in between as we were
1360        initializing the control record in to oe_globals.Control_Rec_Type, the values are getting
1361       changed.This is resulting in some issues. Hence we are resetting these two parametes to the
1362       initial values passed.
1363     */
1364     if l_src_doc_type_id=2 then
1365      OE_DEBUG_PUB.ADD('Order is getting copied, Setting process partial flag to true');
1366     l_control_rec.controlled_operation:=true;
1367     l_control_rec.process_partial:=true;
1368     l_control_rec.clear_dependents:= FALSE;
1369     end if;                       /*End of changes for bug 6778016*/
1370 
1371     OE_DEBUG_PUB.ADD('Calling OE_ORDER_PVT.Line_Scredits',1);
1372     OE_ORDER_PVT.Line_Scredits
1373     (p_validation_level            => FND_API.G_VALID_LEVEL_FULL
1374     ,p_control_rec                 => l_control_rec
1375     ,p_x_Line_Scredit_tbl          => l_x_Line_Scredit_tbl
1376     ,p_x_old_Line_Scredit_tbl      => l_x_old_Line_Scredit_tbl
1377     ,x_return_status               => l_return_status);
1378 
1379     OE_DEBUG_PUB.ADD('After Calling OE_ORDER_PVT.Line_Scredits',1);
1380     -- Reset recursion mode.
1381     -- OE_GLOBALS.G_RECURSION_MODE := 'N';
1382 
1383     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1384         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1385     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1386         RAISE FND_API.G_EXC_ERROR;
1387     END IF;
1388 
1389 --comment out for notification project
1390 /*    OE_ORDER_PVT.Process_Requests_And_notify
1391     ( p_process_requests       => FALSE
1392      ,p_notify                 => TRUE
1393      ,x_return_status          => l_return_status
1394      ,p_Line_Scredit_tbl       => l_x_Line_Scredit_tbl
1395      ,p_old_Line_Scredit_tbl   => l_x_old_Line_Scredit_tbl);
1396 
1397     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1398         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1399     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1400         RAISE FND_API.G_EXC_ERROR;
1401     END IF;
1402 */
1403     -- Clear Table
1404     l_Line_Scredit_tbl.DELETE;
1405 
1406   END IF; /* end inserting sales credit */
1407 
1408   oe_debug_pub.add('Exit INSERT_RMA_SCREDIT_ADJUSTMENT',1);
1409 EXCEPTION
1410 
1411 
1412     WHEN FND_API.G_EXC_ERROR THEN
1413 
1414         x_return_status := FND_API.G_RET_STS_ERROR;
1415 
1416     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1417 
1418         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1419 
1420     WHEN OTHERS THEN
1421 
1422         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1423 
1424         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1425         THEN
1426             OE_MSG_PUB.Add_Exc_Msg
1427             (   G_PKG_NAME
1428             ,   'INSERT_RMA_SCREDIT_ADJUSTMENT'
1429             );
1430         END IF;
1431 
1432 END INSERT_RMA_SCREDIT_ADJUSTMENT;
1433 
1434 /*
1435 Commented out the procedure tax_line as it is not called from
1436 anywhere in the OM code.
1437 
1438 -------------------------------------------------------------------
1439 Procedure: TAX_LINE
1440 -------------------------------------------------------------------
1441 
1442 
1443 PROCEDURE Tax_Line ( x_return_status OUT NOCOPY VARCHAR2
1444 			    , p_line_id          IN   NUMBER
1445 			    )
1446 IS
1447 l_return_status               Varchar2(30):= FND_API.G_RET_STS_SUCCESS;
1448 --l_tax_value                   NUMBER := 0;
1449 l_line_id                     NUMBER := p_line_id;
1450 l_msg_count		          NUMBER := 0;
1451 l_count		               NUMBER := 0;
1452 l_counter		               NUMBER := 0;
1453 l_msg_data		          VARCHAR2(2000);
1454 l_tax_value		          NUMBER := 0;
1455 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
1456 l_tax_code                    VARCHAR2(50);
1457 l_line_rec                    OE_Order_PUB.Line_Rec_Type;
1458 l_old_line_rec                OE_Order_PUB.Line_Rec_Type;
1459 l_line_val_rec                OE_Order_PUB.Line_Val_Rec_Type;
1460 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
1461 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
1462 l_Line_Adj_rec                OE_Order_PUB.Line_Adj_Rec_Type;
1463 l_Line_Adj_tbl                OE_Order_PUB.Line_Adj_Tbl_Type;
1464 l_l_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
1465 l_Line_Adj_val_rec            OE_Order_PUB.Line_Adj_Val_Rec_Type;
1466 l_x_header_rec                OE_Order_PUB.Header_Rec_Type;
1467 l_x_Header_Adj_rec            OE_Order_PUB.Header_Adj_Rec_Type;
1468 l_x_Header_Adj_tbl            OE_Order_PUB.Header_Adj_Tbl_Type;
1469 l_x_Header_Scredit_rec        OE_Order_PUB.Header_Scredit_Rec_Type;
1470 l_x_Header_Scredit_tbl        OE_Order_PUB.Header_Scredit_Tbl_Type;
1471 l_x_line_rec                  OE_Order_PUB.Line_Rec_Type;
1472 l_x_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
1473 l_x_Line_Adj_rec              OE_Order_PUB.Line_Adj_Rec_Type;
1474 l_x_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
1475 l_x_Line_Scredit_rec          OE_Order_PUB.Line_Scredit_Rec_Type;
1476 l_x_Line_Scredit_tbl          OE_Order_PUB.Line_Scredit_Tbl_Type;
1477 l_x_Action_Request_tbl        OE_Order_PUB.Request_Tbl_Type;
1478 l_x_Lot_Serial_Tbl	          OE_Order_PUB.Lot_Serial_Tbl_Type;
1479 l_x_Header_price_Att_tbl      OE_Order_PUB.Header_Price_Att_Tbl_Type;
1480 l_x_Header_Adj_Att_tbl        OE_Order_PUB.Header_Adj_Att_Tbl_Type;
1481 l_x_Header_Adj_Assoc_tbl      OE_Order_PUB.Header_Adj_Assoc_Tbl_Type;
1482 l_x_Line_price_Att_tbl        OE_Order_PUB.Line_Price_Att_Tbl_Type;
1483 l_x_Line_Adj_Att_tbl          OE_Order_PUB.Line_Adj_Att_Tbl_Type;
1484 l_x_Line_Adj_Assoc_tbl        OE_Order_PUB.Line_Adj_Assoc_Tbl_Type;
1485 l_tax_rec_out_tbl             OM_TAX_UTIL.om_tax_out_tab_type;
1486 currency_code  varchar2(30) := NULL;
1487 header_org_id  number;
1488 inventory_org_id number;
1489 conversion_rate number;
1490 --serla begin
1491 l_x_Header_Payment_tbl        OE_Order_PUB.Header_Payment_Tbl_Type;
1492 l_x_Line_Payment_tbl          OE_Order_PUB.Line_Payment_Tbl_Type;
1493 --serla end
1494 l_header_rec                   OE_Order_PUB.Header_Rec_Type;
1495 BEGIN
1496        x_return_status  := l_return_status;
1497 
1498     -- Get the Line record
1499     oe_debug_pub.add('Entering Tax line',1);
1500 
1501     BEGIN
1502 
1503         OE_LINE_UTIL.Query_Row(p_line_id  => l_line_id,
1504 	                          x_line_rec => l_line_rec);
1505         l_old_line_rec := l_line_rec;
1506 
1507     EXCEPTION
1508 	   WHEN OTHERS THEN
1509 		  RAISE NO_DATA_FOUND;
1510     END;
1511 
1512 
1513     -- Call the procedure to get the Tax on the order line
1514     oe_order_cache.load_order_header(l_line_rec.header_id);
1515     l_header_rec := oe_order_cache.g_header_rec;
1516 
1517     OM_TAX_UTIL.TAX_LINE(p_line_rec => l_line_rec,
1518                          p_header_rec => l_header_Rec,
1519 			 x_tax_value => l_tax_value,
1520                          x_tax_out_tbl => l_tax_rec_out_tbl,
1521                          x_return_status => l_return_status );
1522 
1523     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1524         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1525     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1526         RAISE FND_API.G_EXC_ERROR;
1527     END IF;
1528 
1529     l_line_rec.tax_value := l_tax_value;
1530 
1531     oe_debug_pub.add('After Successfully calculating Tax',2);
1532 
1533     -- Check for existing TAX records in OE_PRICE_ADJUSTMENTS table for the
1534     -- given line record.
1535   -- Replace Query_rows with lock rows --
1536     BEGIN
1537        OE_Line_Adj_UTIL.Lock_Rows
1538          ( p_line_id       => l_line_id
1539           ,x_line_adj_tbl  => l_l_line_adj_tbl
1540           ,x_return_status => l_return_status);
1541        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1542            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1543        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1544            RAISE FND_API.G_EXC_ERROR;
1545        END IF;
1546     EXCEPTION
1547          WHEN OTHERS THEN
1548             x_return_status  := FND_API.G_RET_STS_SUCCESS;
1549     END;
1550 
1551     -- If any TAX records exists, then delete those records.
1552 oe_debug_pub.add('line_adj_tbl count is : ' || l_l_line_adj_tbl.count , 1);
1553 
1554     IF l_l_line_adj_tbl.COUNT > 0 THEN
1555 
1556       FOR I IN 1..l_l_line_adj_tbl.COUNT LOOP
1557           oe_debug_pub.add('Parent adj Id is '||
1558                   to_char(l_l_line_adj_tbl(I).parent_adjustment_id),2);
1559 	     IF l_l_line_adj_tbl(I).list_line_type_code = 'TAX'  AND
1560 		   l_l_line_adj_tbl(I).parent_adjustment_id IS NULL
1561 	     THEN
1562               l_counter := l_counter + 1;
1563 	         l_line_adj_tbl(l_counter) := l_l_line_adj_tbl(I);
1564           --  Set Operation to delete
1565               l_Line_Adj_tbl(l_counter).operation := OE_GLOBALS.G_OPR_DELETE;
1566           END IF;
1567       END LOOP;
1568     END IF;
1569 
1570     --  Load IN parameters for Line Adjustment record
1571 
1572 oe_debug_pub.add('line tax rec out nocopy table 1: ' || l_tax_rec_out_tbl.count , 1);
1573 
1574     IF  l_tax_rec_out_tbl.COUNT > 0
1575     THEN
1576         FOR I IN 1..l_tax_rec_out_tbl.COUNT LOOP
1577 
1578          IF l_tax_rec_out_tbl(I).trx_line_id = l_line_rec.line_id
1579          THEN
1580 
1581             l_Line_adj_tbl(l_counter+I) := OE_ORDER_PUB.G_MISS_LINE_ADJ_REC;
1582             l_Line_adj_tbl(l_counter+I).header_id := l_line_rec.header_id;
1583             l_Line_adj_tbl(l_counter+I).line_id := l_line_rec.line_id;
1584             l_Line_adj_tbl(l_counter+I).tax_code := l_tax_rec_out_tbl(I).tax_rate_code;
1585             l_Line_Adj_tbl(l_counter+I).operand := l_tax_rec_out_tbl(I).tax_rate;
1586             l_Line_Adj_tbl(l_counter+I).adjusted_amount :=
1587 						l_tax_rec_out_tbl(I).tax_amount;
1588             l_Line_Adj_tbl(l_counter+I).automatic_flag := 'N';
1589             l_Line_Adj_tbl(l_counter+I).list_line_type_code := 'TAX';
1590             l_Line_Adj_tbl(l_counter+I).arithmetic_operator := 'AMT';
1591 
1592           --  Set flex attributes to NULL in order to avoid defaulting them.
1593 
1594             l_Line_Adj_tbl(l_counter+I).context     := NULL;
1595             l_Line_Adj_tbl(l_counter+I).attribute1  := NULL;
1596             l_Line_Adj_tbl(l_counter+I).attribute2  := NULL;
1597             l_Line_Adj_tbl(l_counter+I).attribute3  := NULL;
1598             l_Line_Adj_tbl(l_counter+I).attribute4  := NULL;
1599             l_Line_Adj_tbl(l_counter+I).attribute5  := NULL;
1600             l_Line_Adj_tbl(l_counter+I).attribute6  := NULL;
1601             l_Line_Adj_tbl(l_counter+I).attribute7  := NULL;
1602             l_Line_Adj_tbl(l_counter+I).attribute8  := NULL;
1603             l_Line_Adj_tbl(l_counter+I).attribute9  := NULL;
1604             l_Line_Adj_tbl(l_counter+I).attribute10 := NULL;
1605             l_Line_Adj_tbl(l_counter+I).attribute11 := NULL;
1606             l_Line_Adj_tbl(l_counter+I).attribute12 := NULL;
1607             l_Line_Adj_tbl(l_counter+I).attribute13 := NULL;
1608             l_Line_Adj_tbl(l_counter+I).attribute14 := NULL;
1609             l_Line_Adj_tbl(l_counter+I).attribute15 := NULL;
1610 
1611        -- Set other attributes to NULL
1612 
1613             l_Line_Adj_tbl(l_counter+I).OPERATION	                  := NULL;
1614             l_Line_Adj_tbl(l_counter+I).PERCENT                     := NULL;
1615             l_Line_Adj_tbl(l_counter+I).DISCOUNT_ID                 := NULL;
1616             l_Line_Adj_tbl(l_counter+I).DISCOUNT_LINE_ID            := NULL;
1617             l_Line_Adj_tbl(l_counter+I).request_id                  := NULL;
1618             l_Line_Adj_tbl(l_counter+I).orig_sys_discount_ref       := NULL;
1619             l_Line_Adj_tbl(l_counter+I).list_header_id              := NULL;
1620             l_Line_Adj_tbl(l_counter+I).list_line_id                := NULL;
1621             l_Line_Adj_tbl(l_counter+I).modifier_mechanism_type_code:= NULL;
1622             l_Line_Adj_tbl(l_counter+I).modified_from               := NULL;
1623             l_Line_Adj_tbl(l_counter+I).modified_to                 := NULL;
1624             l_Line_Adj_tbl(l_counter+I).updated_flag                := NULL;
1625             l_Line_Adj_tbl(l_counter+I).update_allowed	             := NULL;
1626             l_Line_Adj_tbl(l_counter+I).applied_flag                := NULL;
1627             l_Line_Adj_tbl(l_counter+I).change_reason_code          := NULL;
1628             l_Line_Adj_tbl(l_counter+I).change_reason_text          := NULL;
1629             l_Line_Adj_tbl(l_counter+I).cost_id                     := NULL;
1630             l_Line_Adj_tbl(l_counter+I).tax_exempt_flag             := NULL;
1631             l_Line_Adj_tbl(l_counter+I).tax_exempt_number           := NULL;
1632             l_Line_Adj_tbl(l_counter+I).tax_exempt_reason_code      := NULL;
1633             l_Line_Adj_tbl(l_counter+I).parent_adjustment_id        := NULL;
1634             l_Line_Adj_tbl(l_counter+I).invoiced_flag               := NULL;
1635             l_Line_Adj_tbl(l_counter+I).estimated_flag              := NULL;
1636             l_Line_Adj_tbl(l_counter+I).inc_in_sales_performance    := NULL;
1637             l_Line_Adj_tbl(l_counter+I).split_action_code           := NULL;
1638 
1639           --  Set Operation to Create
1640             l_Line_Adj_tbl(l_counter+I).operation := OE_GLOBALS.G_OPR_CREATE;
1641 
1642          END IF;
1643 
1644         END LOOP;
1645     END IF;
1646 
1647     --  Load IN parameters for Line record
1648     IF NOT OE_GLOBALS.Equal(l_line_rec.tax_value, l_old_line_rec.tax_value)
1649     THEN
1650 	   -- Start Audit Trail --
1651 	   l_Line_rec.change_reason := 'SYSTEM';
1652 	   -- End Audit Trail --
1653         l_Line_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
1654     ELSE
1655         l_Line_rec.operation := OE_GLOBALS.G_OPR_NONE;
1656     END IF;
1657 
1658     -- Check to see if there are any records needed to be modified.
1659 
1660     IF NOT (OE_GLOBALS.Equal(l_line_rec.operation, OE_GLOBALS.G_OPR_NONE) AND
1661 	       l_line_adj_tbl.COUNT = 0)
1662     THEN
1663 
1664         --  Populate Line table
1665         l_Line_tbl(1)     := l_Line_rec;
1666         l_Old_Line_tbl(1) := l_Old_Line_rec;
1667 
1668         --  Set control flags.
1669         l_control_rec.controlled_operation := FALSE;
1670 
1671         oe_debug_pub.add('Before calling Process Order API',2);
1672 
1673     -- Set recursion mode.
1674     --  OE_GLOBALS.G_RECURSION_MODE := 'Y';
1675 
1676         OE_Order_PVT.Process_order
1677         (   p_api_version_number          => 1.0
1678         ,   p_init_msg_list               => FND_API.G_FALSE
1679         ,   x_return_status               => l_return_status
1680         ,   x_msg_count                   => l_msg_count
1681         ,   x_msg_data                    => l_msg_data
1682         ,   p_control_rec                 => l_control_rec
1683         ,   p_x_header_rec                => l_x_header_rec
1684         ,   p_x_Header_Adj_tbl            => l_x_Header_Adj_tbl
1685         ,   p_x_Header_price_Att_tbl      => l_x_Header_price_Att_tbl
1686         ,   p_x_Header_Adj_Att_tbl        => l_x_Header_Adj_Att_tbl
1687         ,   p_x_Header_Adj_Assoc_tbl      => l_x_Header_Adj_Assoc_tbl
1688         ,   p_x_Header_Scredit_tbl        => l_x_Header_Scredit_tbl
1689 --serla begin
1690         ,   p_x_Header_Payment_tbl          => l_x_Header_Payment_tbl
1691 --serla end
1692         ,   p_x_line_tbl                  => l_line_tbl
1693         ,   p_old_Line_tbl                => l_old_Line_tbl
1694         ,   p_x_Line_Adj_tbl              => l_Line_Adj_tbl
1695         ,   p_x_Line_price_Att_tbl        => l_x_Line_price_Att_tbl
1696         ,   p_x_Line_Adj_Att_tbl          => l_x_Line_Adj_Att_tbl
1697         ,   p_x_Line_Adj_Assoc_tbl        => l_x_Line_Adj_Assoc_tbl
1698         ,   p_x_Line_Scredit_tbl          => l_x_Line_Scredit_tbl
1699 --serla begin
1700         ,   p_x_Line_Payment_tbl            => l_x_Line_Payment_tbl
1701 --serla end
1702         ,   p_x_Lot_Serial_tbl            => l_x_Lot_Serial_tbl
1703         ,   p_x_action_request_tbl	       => l_x_action_request_tbl
1704         );
1705 
1706     -- Reset recursion mode.
1707     -- OE_GLOBALS.G_RECURSION_MODE := 'N';
1708 
1709         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1710             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1711         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1712             RAISE FND_API.G_EXC_ERROR;
1713         END IF;
1714         oe_debug_pub.add('After calling Process_order API',2);
1715     END IF;
1716     l_tax_rec_out_tbl.delete;
1717     x_return_status := l_return_status;
1718     oe_debug_pub.add('Exiting Tax Line',1);
1719 EXCEPTION
1720     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1721 	  x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1722 
1723     WHEN FND_API.G_EXC_ERROR THEN
1724 	  x_return_status := FND_API.G_RET_STS_ERROR;
1725 
1726     WHEN NO_DATA_FOUND THEN
1727        x_return_status  := FND_API.G_RET_STS_SUCCESS;
1728 
1729     WHEN OTHERS THEN
1730 
1731     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1732 	THEN
1733     	    OE_MSG_PUB.Add_Exc_Msg
1734     	    (	G_PKG_NAME  	    ,
1735     	        'Tax Line'
1736 	    );
1737     	END IF;
1738 	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1739 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1740 
1741 END Tax_Line;
1742 
1743 */
1744 
1745 
1746 
1747 
1748 ------------------------------------------------------------------
1749 -- procedure: SPLIT_HOLD
1750 -- Copy's the hold when a line gets split that has an active hold
1751 -----------------------------------------------------------------
1752 PROCEDURE split_hold (p_entity_code         IN   VARCHAR2
1753                      ,p_entity_id           IN   NUMBER
1754                      ,p_split_from_line_id  IN   NUMBER
1755 ,x_return_status OUT NOCOPY VARCHAR2
1756 
1757                      )
1758 IS
1759      l_return_status            VARCHAR2(30);
1760      l_msg_count                NUMBER;
1761      l_msg_data                 VARCHAR2(2000);
1762 
1763 BEGIN
1764 
1765    OE_Debug_PUB.Add('Entering OE_Delayed_Requests_Util.split_Hold',1);
1766 -- call the oe_holds_pub to split the line
1767    OE_Holds_pvt.split_hold (
1768                     p_line_id               => p_entity_id
1769                   , p_split_from_line_id    => p_split_from_line_id
1770                   , x_return_status         => x_return_status
1771                   , x_msg_count             => l_msg_count
1772                   , x_msg_data              => l_msg_data
1773                   );
1774         IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1775                 OE_Debug_PUB.Add('Error in OE_Holds_PUB.split_Holds',2);
1776                 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1777                         RAISE FND_API.G_EXC_ERROR;
1778                 ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1779                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1780                 END IF;
1781         END IF; -- if split hold was successful
1782 
1783       OE_Debug_PUB.Add('Exiting OE_Delayed_Requests_Util.split_Hold',2);
1784 
1785 EXCEPTION
1786 
1787     WHEN FND_API.G_EXC_ERROR THEN
1788 
1789         x_return_status := FND_API.G_RET_STS_ERROR;
1790 
1791     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1792 
1793         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1794 
1795     WHEN OTHERS THEN
1796 
1797         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1798         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1799         THEN
1800             OE_MSG_PUB.Add_Exc_Msg
1801             (   G_PKG_NAME
1802             ,   'Split_Hold'
1803             );
1804         END IF;
1805 
1806 
1807 END split_hold;
1808 
1809 -------------------------------------------------------------------
1810 -- Procedure: EVAL_HOLD_SOURCE
1811 -- Applies or removes holds if a hold source entity is updated
1812 -- on the order or line.
1813 -- Changed(1/3/2000): Moved all the login to the oe_holds_pub.evaluate_holds
1814 -------------------------------------------------------------------
1815 
1816 PROCEDURE Eval_Hold_Source(
1817 x_return_status OUT NOCOPY VARCHAR2
1818 
1819 			,  p_entity_code	   IN   VARCHAR2
1820 			,  p_entity_id		   IN   NUMBER
1821 			,  p_hold_entity_code  IN   VARCHAR2
1822 			--ER#7479609,  p_hold_entity_id	   IN   NUMBER
1823 			, p_hold_entity_id	 IN   oe_hold_sources_all.hold_entity_id%TYPE  --ER#7479609
1824 			)
1825 IS
1826      l_return_status     VARCHAR2(30);
1827      l_msg_count         NUMBER;
1828      l_msg_data          VARCHAR2(2000);
1829 
1830 BEGIN
1831 
1832     OE_Debug_PUB.Add('Entering Eval_Hold_Source', 1);
1833     Oe_debug_pub.add('Hold entity: '|| p_hold_entity_code ||' '|| p_hold_entity_id,2);
1834     x_return_status := FND_API.G_RET_STS_SUCCESS;
1835 
1836     oe_holds_pub.evaluate_holds ( p_entity_code  => p_entity_code
1837                                  ,p_entity_id    => p_entity_id
1838                                  ,p_hold_entity_code    => p_hold_entity_code
1839                                  ,p_hold_entity_id      => p_hold_entity_id
1840                                  ,x_return_status       => x_return_status
1841                                  ,x_msg_count           => l_msg_count
1842                                  ,x_msg_data            => l_msg_data
1843                                 );
1844 
1845 
1846 
1847         IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1848 	      OE_Debug_PUB.Add('Error in OE_Holds_PUB.evaluate_holds',2);
1849  	   IF x_return_status = FND_API.G_RET_STS_ERROR THEN
1850  		RAISE FND_API.G_EXC_ERROR;
1851  	   ELSIF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1852  		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1853  	   END IF;
1854         END IF;
1855 
1856     OE_Debug_PUB.Add('Exiting Eval_Hold_Source', 1);
1857 
1858 EXCEPTION
1859     WHEN FND_API.G_EXC_ERROR THEN
1860 
1861         x_return_status := FND_API.G_RET_STS_ERROR;
1862 
1863     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1864 
1865         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1866 
1867     WHEN OTHERS THEN
1868 
1869         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1870         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1871         THEN
1872             OE_MSG_PUB.Add_Exc_Msg
1873             (   G_PKG_NAME
1874             ,   'Eval_Hold_Source'
1875             );
1876         END IF;
1877 
1878 END Eval_Hold_Source;
1879 
1880 -------------------------------------------------------------------
1881 -- Procedure: APPLY_HOLD
1882 -- Applies holds to an order or line using hold ID, entity code and
1883 -- entity ID
1884 -------------------------------------------------------------------
1885 
1886 PROCEDURE Apply_Hold(p_validation_level  IN   NUMBER
1887                     ,x_request_rec   IN  OUT NOCOPY OE_Order_PUB.Request_Rec_Type
1888 			)
1889 IS
1890 l_header_id		NUMBER DEFAULT NULL;
1891 l_line_id		     NUMBER DEFAULT NULL;
1892 l_hold_source_rec	OE_Holds_PVT.Hold_Source_REC_type;
1893 l_request_rec		OE_Order_PUB.request_rec_type := x_request_rec;
1894 l_return_status	VARCHAR2(30);
1895 l_msg_count		NUMBER := 0;
1896 l_msg_data		VARCHAR2(2000) := NULL;
1897 l_line_rec                    OE_Order_PUB.Line_Rec_Type;
1898 BEGIN
1899 
1900    OE_Debug_PUB.Add('Entering OE_Delayed_Requests_Util.Apply_Hold',1);
1901 
1902    IF l_request_rec.entity_code = OE_Globals.G_ENTITY_HEADER THEN
1903       -- Indicates Header Level action
1904       --l_header_id := l_request_rec.entity_id;
1905       l_hold_source_rec.header_id := l_request_rec.entity_id;
1906       OE_Debug_PUB.Add('Header ID: '|| l_hold_source_rec.header_id,1);
1907 
1908    ELSIF l_request_rec.entity_code = OE_Globals.G_ENTITY_LINE THEN
1909 
1910 	OE_debug_pub.add('Line ID: '|| l_request_rec.entity_id,1);
1911      BEGIN
1912       SELECT header_id
1913         INTO l_header_id
1914         FROM oe_order_lines
1915        WHERE line_id = l_request_rec.entity_id;
1916      OE_debug_pub.add('OEXUREQB:Header ID: '|| l_header_id);
1917 
1918 
1919      EXCEPTION
1920         WHEN OTHERS THEN
1921             OE_debug_pub.add('OEXUREQB:No header ID for this line');
1922             RAISE NO_DATA_FOUND;
1923      END;
1924 
1925       l_hold_source_rec.header_id := l_header_id;
1926 	 l_hold_source_rec.line_id := l_request_rec.entity_id;
1927 
1928    END IF;
1929 
1930    l_hold_source_rec.hold_entity_code 	:= l_request_rec.param2;
1931    l_hold_source_rec.hold_id		     := l_request_rec.param1;
1932 
1933    -- Since an Order based source and Header is created at the same time, caller
1934    -- is unable to populate param3 with header_id.  We can user entity_id
1935 
1936    IF ((l_request_rec.entity_code = OE_GLOBALS.G_ENTITY_HEADER) AND
1937        (l_hold_source_rec.hold_entity_code = 'O')) THEN
1938        l_hold_source_rec.hold_entity_id := l_request_rec.entity_id;
1939    ELSIF ((l_request_rec.entity_code = OE_GLOBALS.G_ENTITY_LINE) AND
1940        (l_hold_source_rec.hold_entity_code = 'O')) THEN
1941        l_hold_source_rec.hold_entity_id := l_header_id;
1942    ELSE
1943        l_hold_source_rec.hold_entity_id	:= l_request_rec.param3;
1944    END IF;
1945 
1946    l_hold_source_rec.hold_comment 	:= l_request_rec.param4;
1947 
1948    l_hold_source_rec.hold_until_date 	:= l_request_rec.date_param1;
1949 
1950    -- Load Desc Flex
1951    l_hold_source_rec.context            := l_request_rec.param10;
1952    l_hold_source_rec.attribute1 	:= l_request_rec.param11;
1953    l_hold_source_rec.attribute2 	:= l_request_rec.param12;
1954    l_hold_source_rec.attribute3 	:= l_request_rec.param13;
1955    l_hold_source_rec.attribute4 	:= l_request_rec.param14;
1956    l_hold_source_rec.attribute5 	:= l_request_rec.param15;
1957    l_hold_source_rec.attribute6 	:= l_request_rec.param16;
1958    l_hold_source_rec.attribute7 	:= l_request_rec.param17;
1959    l_hold_source_rec.attribute8 	:= l_request_rec.param18;
1960    l_hold_source_rec.attribute9 	:= l_request_rec.param19;
1961    l_hold_source_rec.attribute10	:= l_request_rec.param20;
1962    l_hold_source_rec.attribute11	:= l_request_rec.param21;
1963    l_hold_source_rec.attribute12 	:= l_request_rec.param22;
1964    l_hold_source_rec.attribute13	:= l_request_rec.param23;
1965    l_hold_source_rec.attribute14 	:= l_request_rec.param24;
1966    l_hold_source_rec.attribute15 	:= l_request_rec.param25;
1967 
1968    l_request_rec.return_status := FND_API.G_RET_STS_SUCCESS;
1969 
1970    -- Changed the following to new signiture 2/24/2000 - ZB
1971    /*
1972      OE_Holds_PUB.Apply_Holds
1973 		(   p_api_version		=> 1.0
1974 		,   p_validation_level	=> p_validation_level
1975 		,   p_header_id		=> l_header_id
1976 		,   p_line_id			=> l_line_id
1977 		,   p_hold_source_rec		=> l_hold_source_rec
1978 		,   x_return_status		=> l_return_status
1979 		,   x_msg_count			=> l_msg_count
1980 		,   x_msg_data			=> l_msg_data
1981 		);
1982 	*/
1983 	OE_Holds_PUB.Apply_Holds
1984 		(   p_api_version        => 1.0
1985 		,   p_validation_level   => FND_API.G_VALID_LEVEL_NONE
1986 		,   p_hold_source_rec     => l_hold_source_rec
1987 		,   x_return_status      => l_return_status
1988 		,   x_msg_count          => l_msg_count
1989 		,   x_msg_data           => l_msg_data
1990            );
1991 
1992 
1993     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1994 	OE_Debug_PUB.Add('OEXUREQB:Error in OE_Holds_PUB.Apply_Holds',1);
1995  		IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1996  			RAISE FND_API.G_EXC_ERROR;
1997  		ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1998  			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1999  		END IF;
2000     ELSE
2001     	OE_Debug_PUB.Add('OEXUREQB:Hold applied',1);
2002     END IF;
2003 
2004     x_request_rec := l_request_rec;
2005 
2006     OE_Debug_PUB.Add('Exiting OE_Delayed_Requests_Util.Apply_Hold',1);
2007 EXCEPTION
2008 
2009     WHEN FND_API.G_EXC_ERROR THEN
2010 
2011         l_request_rec.return_status := FND_API.G_RET_STS_ERROR;
2012         x_request_rec := l_request_rec;
2013 
2014     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2015 
2016 	l_request_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2017 	x_request_rec := l_request_rec;
2018 
2019     WHEN OTHERS THEN
2020 
2021 	l_request_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2022 	x_request_rec := l_request_rec;
2023         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2024         THEN
2025             OE_MSG_PUB.Add_Exc_Msg
2026             (   G_PKG_NAME
2027             ,   'Apply_Hold'
2028             );
2029         END IF;
2030 
2031 
2032 END Apply_Hold;
2033 
2034 -------------------------------------------------------------------
2035 -- Procedure: RELEASE_HOLD
2036 -- Releases hold on an order or line that has a hold source that
2037 -- uses this hold ID, entity code and entity ID.
2038 -------------------------------------------------------------------
2039 
2040 PROCEDURE Release_Hold(
2041                   p_validation_level   IN  NUMBER
2042                  ,x_request_rec  IN  OUT NOCOPY OE_Order_PUB.Request_Rec_Type
2043 			)
2044 IS
2045 l_header_id		NUMBER DEFAULT NULL;
2046 l_line_id		     NUMBER DEFAULT NULL;
2047 l_hold_id		     NUMBER DEFAULT NULL;
2048 --ER#7479609 l_entity_code		VARCHAR2(1) DEFAULT NULL;
2049 --ER#7479609 l_entity_id		NUMBER DEFAULT NULL;
2050 l_entity_code		oe_hold_sources_all.hold_entity_code%TYPE DEFAULT NULL;  --ER#7479609
2051 l_entity_id		oe_hold_sources_all.hold_entity_id%TYPE DEFAULT NULL;	--ER#7479609
2052 l_request_rec		OE_Order_PUB.request_rec_type := x_request_rec;
2053 l_return_status	VARCHAR2(30);
2054 l_msg_count		NUMBER := 0;
2055 l_msg_data		VARCHAR2(2000) := NULL;
2056 
2057 l_hold_release_rec	OE_HOLDS_PVT.Hold_Release_Rec_Type;
2058 l_hold_source_rec   OE_HOLDS_PVT.Hold_Source_Rec_Type;
2059 BEGIN
2060 
2061   OE_Debug_PUB.Add('Entering OE_Delayed_Requests_Util.Release_Hold',1);
2062 
2063    IF l_request_rec.entity_code = OE_Globals.G_ENTITY_HEADER THEN
2064 -- Indicates Header Level action
2065 
2066        l_header_id := l_request_rec.entity_id;
2067        l_hold_source_rec.header_id := l_header_id; --Bug 5042664
2068        OE_Debug_PUB.Add('Header ID: '|| l_header_id,1);
2069 
2070    ELSIF l_request_rec.entity_code = OE_Globals.G_ENTITY_LINE THEN
2071 
2072      --l_line_id := l_request_rec.entity_id;
2073      OE_debug_pub.add('Line ID: '|| l_request_rec.entity_id,1);
2074      BEGIN
2075       SELECT header_id
2076         INTO l_header_id
2077         FROM oe_order_lines
2078        WHERE line_id = l_request_rec.entity_id;
2079      OE_debug_pub.add('OEXUREQB:Header ID: '|| l_header_id);
2080 
2081 
2082      EXCEPTION
2083         WHEN OTHERS THEN
2084             OE_debug_pub.add('OEXUREQB:No header ID for this line');
2085             RAISE NO_DATA_FOUND;
2086      END;
2087 
2088      l_hold_source_rec.header_id := l_header_id;
2089      l_hold_source_rec.line_id := l_request_rec.entity_id;
2090 
2091    END IF;
2092 
2093    l_request_rec.return_status := FND_API.G_RET_STS_SUCCESS;
2094 
2095    l_hold_id     := l_request_rec.param1;
2096    l_entity_code := l_request_rec.param2;
2097 
2098    -- Order Import is unable to send Hold Entity Id/Header Id as Param3
2099    -- Need to modify the code to use header id for hold entity code = 'O'
2100 
2101    IF ((l_request_rec.entity_code = OE_GLOBALS.G_ENTITY_HEADER) AND
2102        (l_entity_code = 'O')) THEN
2103      l_entity_id := l_request_rec.entity_id;
2104    ELSIF ((l_request_rec.entity_code = OE_GLOBALS.G_ENTITY_LINE) AND
2105        (l_entity_code = 'O')) THEN
2106      l_entity_id := l_header_id;
2107    ELSE
2108      l_entity_id := l_request_rec.param3;
2109    END IF;
2110 
2111    l_hold_release_rec.release_reason_code := l_request_rec.param4;
2112    l_hold_release_rec.release_comment     := l_request_rec.param5;
2113 
2114    l_hold_source_rec.hold_id          := l_hold_id;
2115    l_hold_source_rec.HOLD_ENTITY_CODE := l_entity_code;
2116    l_hold_source_rec.HOLD_ENTITY_ID   := l_entity_id;
2117 
2118 
2119    OE_Debug_PUB.Add('Calling OE_Holds_PUB.Release_Holds',1);
2120      /*
2121      OE_Holds_PUB.Release_Holds
2122 		(   p_api_version		=> 1.0
2123 		,   p_validation_level		=> p_validation_level
2124 		,   p_header_id			=> l_header_id
2125 		,   p_line_id			=> l_line_id
2126 		,   p_hold_id		        => l_hold_id
2127 		,   p_entity_code		=> l_entity_code
2128 		,   p_entity_id		        => l_entity_id
2129 		,   p_hold_release_rec		=> l_hold_release_rec
2130 		,   x_return_status		=> l_return_status
2131 		,   x_msg_count			=> l_msg_count
2132 		,   x_msg_data			=> l_msg_data
2133 		);
2134 		*/
2135 
2136 	  oe_holds_pvt.Release_Holds(
2137 		  p_hold_source_rec     =>  l_hold_source_rec
2138 		 ,p_hold_release_rec    =>  l_hold_release_rec
2139 	   	 ,x_return_status       =>  l_return_status
2140 	      ,x_msg_count           =>  l_msg_count
2141 	      ,x_msg_data            =>  l_msg_data
2142 										 );
2143        OE_DEBUG_PUB.Add('x_return_status:' || l_return_status,1);
2144 
2145     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2146 	OE_Debug_PUB.Add('Error in OE_Holds_PUB.Release_Holds',2);
2147  		IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2148  			RAISE FND_API.G_EXC_ERROR;
2149  		ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2150  			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2151  		END IF;
2152     ELSE
2153     	OE_Debug_PUB.Add('Hold released',1);
2154     END IF;
2155 
2156     x_request_rec := l_request_rec;
2157     OE_Debug_PUB.Add('Exiting OE_Delayed_Requests_Util.Release_Hold',1);
2158 EXCEPTION
2159 
2160     WHEN FND_API.G_EXC_ERROR THEN
2161 
2162         l_request_rec.return_status := FND_API.G_RET_STS_ERROR;
2163         x_request_rec := l_request_rec;
2164 
2165     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2166 
2167 	l_request_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2168 	x_request_rec := l_request_rec;
2169 
2170     WHEN OTHERS THEN
2171 
2172 	l_request_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2173 	x_request_rec := l_request_rec;
2174         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2175         THEN
2176             OE_MSG_PUB.Add_Exc_Msg
2177             (   G_PKG_NAME
2178             ,   'Release_Hold'
2179             );
2180         END IF;
2181 
2182 
2183 END Release_Hold;
2184 
2185 
2186 PROCEDURE Split_Set
2187   (p_request_rec	IN oe_order_pub.request_rec_type,
2188 x_return_status OUT NOCOPY VARCHAR2)
2189 
2190   IS
2191 l_return_status VARCHAR2(30);
2192 x_msg_data varchar2(2000);
2193 x_msg_count number;
2194 l_set_name varchar2(80);
2195 Begin
2196     l_set_name := p_request_rec.param1 ;
2197     OE_SET_UTIL.Split_Set
2198              (p_set_id     => p_request_rec.entity_id,
2199 		    p_set_name  =>  l_set_name,
2200               x_return_Status  => l_return_status,
2201               x_msg_count      => x_msg_count,
2202               x_msg_data       => x_msg_data);
2203     x_return_status := l_return_status;
2204     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2205         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2206     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2207         RAISE FND_API.G_EXC_ERROR;
2208     END IF;
2209 
2210 
2211 EXCEPTION
2212 
2213     WHEN FND_API.G_EXC_ERROR THEN
2214 
2215         x_return_status := FND_API.G_RET_STS_ERROR;
2216 
2217         --  Get message count and data
2218 
2219         OE_MSG_PUB.Count_And_Get
2220         (   p_count                       => x_msg_count
2221         ,   p_data                        => x_msg_data
2222         );
2223 
2224     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2225 
2226         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2227         --  Get message count and data
2228 
2229         OE_MSG_PUB.Count_And_Get
2230         (   p_count                       => x_msg_count
2231         ,   p_data                        => x_msg_data
2232         );
2233 
2234     WHEN OTHERS THEN
2235 
2236         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2237 
2238         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2239         THEN
2240             OE_MSG_PUB.Add_Exc_Msg
2241             (   G_PKG_NAME
2242             ,   'Split_Set'
2243             );
2244         END IF;
2245 
2246         --  Get message count and data
2247 
2248         OE_MSG_PUB.Count_And_Get
2249         (   p_count                       => x_msg_count
2250         ,   p_data                        => x_msg_data
2251         );
2252 
2253 End Split_set;
2254 
2255 PROCEDURE Insert_Set
2256   (p_request_rec	IN oe_order_pub.request_rec_type,
2257 x_return_status OUT NOCOPY VARCHAR2)
2258 
2259   IS
2260 l_return_status VARCHAR2(30);
2261 x_msg_data varchar2(2000);
2262 x_msg_count number;
2263 p_set_request oe_order_pub.request_tbl_type;
2264 Begin
2265     p_set_request(1) := p_request_rec;
2266     OE_SET_UTIL.Insert_Into_Set
2267                  (p_set_request_tbl => p_set_request,
2268                   p_Push_Set_Date => 'N',
2269                   X_Return_Status  => l_return_status,
2270                   x_msg_count      => x_msg_count,
2271                   x_msg_data       => x_msg_data);
2272     x_return_status := l_return_status;
2273     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2274         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2275     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2276         RAISE FND_API.G_EXC_ERROR;
2277     END IF;
2278 
2279 
2280 EXCEPTION
2281 
2282     WHEN FND_API.G_EXC_ERROR THEN
2283 
2284         x_return_status := FND_API.G_RET_STS_ERROR;
2285 
2286         --  Get message count and data
2287 
2288         OE_MSG_PUB.Count_And_Get
2289         (   p_count                       => x_msg_count
2290         ,   p_data                        => x_msg_data
2291         );
2292 
2293     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2294 
2295         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2296         --  Get message count and data
2297 
2298         OE_MSG_PUB.Count_And_Get
2299         (   p_count                       => x_msg_count
2300         ,   p_data                        => x_msg_data
2301         );
2302 
2303     WHEN OTHERS THEN
2304 
2305         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2306 
2307         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2308         THEN
2309             OE_MSG_PUB.Add_Exc_Msg
2310             (   G_PKG_NAME
2311             ,   'Insert_Set'
2312             );
2313 	END IF;
2314         --  Get message count and data
2315 
2316         OE_MSG_PUB.Count_And_Get
2317         (   p_count                       => x_msg_count
2318         ,   p_data                        => x_msg_data
2319         );
2320 
2321 NULL;
2322 
2323 End Insert_Set;
2324 
2325 
2326 PROCEDURE Book_Order
2327 	( p_validation_level	IN NUMBER
2328 	, p_header_id			IN NUMBER
2329 , x_return_status OUT NOCOPY VARCHAR2
2330 
2331 	)
2332 IS
2333 l_msg_count			NUMBER;
2334 l_msg_data			VARCHAR2(2000);
2335 BEGIN
2336 
2337 	x_return_status := FND_API.G_RET_STS_SUCCESS;
2338 
2339 	OE_Order_Book_Util.Complete_Book_Eligible
2340 			( p_api_version_number	=> 1.0
2341 			, p_header_id			=> p_header_id
2342 			, x_return_status		=> x_return_status
2343 			, x_msg_count			=> l_msg_count
2344 			, x_msg_data			=> l_msg_data);
2345 
2346 EXCEPTION
2347 	WHEN OTHERS THEN
2348 	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2349 	IF OE_MSG_PUB.Check_Msg_Level
2350 		    (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2351      THEN
2352 		   OE_MSG_PUB.Add_Exc_Msg
2353 				( G_PKG_NAME
2354 				, 'Book_Order'
2355 				);
2356 	END IF;
2357 END Book_Order;
2358 
2359 PROCEDURE Get_Ship_Method
2360         ( p_entity_code                 IN VARCHAR2
2361         , p_entity_id                   IN NUMBER
2362         , p_action_code	                IN VARCHAR2
2363 , x_return_status OUT NOCOPY VARCHAR2
2364 
2365         )
2366 IS
2367   l_msg_count                     NUMBER;
2368   l_msg_data                      VARCHAR2(2000);
2369   l_header_id                     NUMBER;
2370   l_action                        VARCHAR2(1);
2371 
2372 BEGIN
2373 
2374     x_return_status := FND_API.G_RET_STS_SUCCESS;
2375 
2376     IF p_entity_code = OE_Globals.G_ENTITY_HEADER THEN
2377 
2378        l_header_id := p_entity_id;
2379 
2380     ELSIF p_entity_code = OE_Globals.G_ENTITY_LINE THEN
2381 
2382           BEGIN
2383               SELECT header_id
2384               INTO   l_header_id
2385               FROM   oe_order_lines_all
2386               WHERE  line_id = p_entity_id;
2387           EXCEPTION
2388               WHEN OTHERS THEN
2389                    RAISE;
2390           END;
2391 
2392      END IF;
2393 
2394       IF OE_SYS_PARAMETERS.Value('FTE_INTEGRATION') = 'Y'
2395           AND p_action_code = OE_GLOBALS.G_GET_SHIP_METHOD_AND_RATES THEN
2396             l_action := 'B';
2397       ELSIF (OE_SYS_PARAMETERS.Value('FTE_INTEGRATION') = 'S'
2398              OR OE_SYS_PARAMETERS.Value('FTE_INTEGRATION') = 'Y')
2399              AND p_action_code =  OE_GLOBALS.G_GET_SHIP_METHOD THEN
2400                l_action := 'C';
2401       ELSIF (OE_SYS_PARAMETERS.Value('FTE_INTEGRATION') = 'F'
2402              OR OE_SYS_PARAMETERS.Value('FTE_INTEGRATION') = 'Y')
2403              AND p_action_code =  OE_GLOBALS.G_GET_FREIGHT_RATES THEN
2404                l_action := 'R';
2405       END IF;
2406 
2407      IF l_action IN ('B', 'C', 'R') THEN
2408 
2409        oe_debug_pub.add('calling Process_FTE_Action for Order Import.', 3);
2410 
2411        -- set p_ui_flag to Y since this is called from Action
2412        -- through Order Import.
2413        OE_FTE_INTEGRATION_PVT.Process_FTE_Action
2414        ( p_header_id           => l_header_id
2415         ,p_line_id             => null
2416         ,p_ui_flag             => 'Y'
2417         ,p_action              => l_action
2418         ,p_call_pricing_for_FR => 'Y'
2419         ,x_return_status       => x_return_status
2420         ,x_msg_count           => l_msg_count
2421         ,x_msg_data            => l_msg_data);
2422      ELSE
2423        fnd_message.set_name('ONT','OE_FTE_NOT_ENABLED');
2424        OE_MSG_PUB.Add;
2425        oe_debug_pub.add('Unable to process FTE integration either due to
2426                          FTE is not enabled or action code is invalid.', 3);
2427        x_return_status := FND_API.G_RET_STS_ERROR;
2428      END IF;
2429 
2430      OE_DEBUG_PUB.Add('Return Status fte action: '||x_return_status);
2431 
2432 EXCEPTION
2433         WHEN OTHERS THEN
2434              x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2435         IF OE_MSG_PUB.Check_Msg_Level
2436                     (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2437         THEN
2438            OE_MSG_PUB.Add_Exc_Msg
2439                      ( G_PKG_NAME
2440                      , 'Get_Ship_Method'
2441                      );
2442         END IF;
2443 END Get_Ship_Method;
2444 
2445 PROCEDURE Fulfillment_Sets
2446 ( p_entity_code                IN VARCHAR2
2447 , p_entity_id                  IN VARCHAR2
2448 , p_action_code                IN VARCHAR2
2449 , p_fulfillment_set_name       IN VARCHAR2
2450 , x_return_status              OUT NOCOPY VARCHAR2
2451 )
2452  IS
2453   l_msg_count              NUMBER;
2454   l_msg_data               VARCHAR2(2000);
2455   l_header_id              NUMBER;
2456   l_set_id                 NUMBER;
2457   l_action                 VARCHAR2(10);
2458   --R12.MOAC
2459   l_selelect_line_tbl     OE_GLOBALS.Selected_Record_Tbl;
2460 BEGIN
2461 
2462     x_return_status := FND_API.G_RET_STS_SUCCESS;
2463 
2464 
2465        BEGIN
2466               SELECT header_id
2467               INTO   l_header_id
2468               FROM   oe_order_lines_all
2469               WHERE  line_id = p_entity_id;
2470           EXCEPTION
2471               WHEN OTHERS THEN
2472                    RAISE;
2473           END;
2474 
2475     IF  p_action_code = OE_GLOBALS.G_ADD_FULFILLMENT_SET THEN
2476         l_action := 'ADD';
2477     ELSIF p_action_code = OE_GLOBALS.G_REMOVE_FULFILLMENT_SET THEN
2478         l_action := 'REMOVE';
2479     END IF;
2480 
2481     l_selelect_line_tbl(1).id1 := p_entity_id; --R12.MOAC
2482     OE_DEBUG_PUB.Add(' Before Calling Process Sets',1);
2483 
2484     --R12.MOAC
2485     OE_SET_UTIL.Process_Sets
2486     ( p_selected_line_tbl => l_selelect_line_tbl,
2487       p_record_count      => 1,
2488       p_set_name          => p_fulfillment_set_name,
2489       p_set_type          => 'FULFILLMENT',
2490       p_operation         => l_action,
2491       p_header_id         => l_header_id,
2492       x_Set_Id            => l_set_id,
2493       x_return_status     => x_return_status,
2494       x_msg_count         => l_msg_count ,
2495       x_msg_data          => l_msg_data);
2496 
2497 
2498     OE_DEBUG_PUB.Add('After Calling Process Sets'||x_return_status,1);
2499 
2500 
2501     IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2502         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2503     ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
2504         RAISE FND_API.G_EXC_ERROR;
2505     END IF;
2506 
2507 EXCEPTION
2508         WHEN OTHERS THEN
2509              x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2510         IF OE_MSG_PUB.Check_Msg_Level
2511                     (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2512         THEN
2513            OE_MSG_PUB.Add_Exc_Msg
2514                      ( G_PKG_NAME
2515                      ,'Fulfillment_Sets'
2516                      );
2517         END IF;
2518 
2519 END Fulfillment_Sets;
2520 
2521 
2522 
2523 /*----------------------------------------------------------------------
2524 PROCEDURE Update_shipping
2525 -----------------------------------------------------------------------*/
2526 PROCEDURE Update_shipping
2527 ( p_update_shipping_tbl     IN  OE_ORDER_PUB.request_tbl_type
2528 , p_line_id                 IN  NUMBER
2529 , p_operation               IN  VARCHAR2
2530 , x_return_status OUT NOCOPY VARCHAR2)
2531 
2532 IS
2533   l_update_shipping_index    NUMBER := 0;
2534   l_update_lines_tbl         OE_ORDER_PUB.request_tbl_type;
2535   l_update_lines_index       NUMBER := 0;
2536 BEGIN
2537 
2538   oe_debug_pub.add('Entering UTIL.Update_Shipping'||p_line_id, 1);
2539   -- bug 4741573
2540   OE_MSG_PUB.set_msg_context ( p_entity_code => 'LINE'
2541                               ,p_entity_id   => p_line_id
2542                               ,p_line_id     => p_line_id );
2543 
2544   l_update_shipping_index := p_update_shipping_tbl.FIRST;
2545 
2546   WHILE l_update_shipping_index IS NOT NULL
2547   LOOP
2548 
2549     IF  p_update_shipping_tbl(l_update_shipping_index).request_type
2550                                   = OE_GLOBALS.G_UPDATE_SHIPPING
2551     THEN
2552 
2553       l_update_lines_index := l_update_lines_index + 1;
2554       l_update_lines_tbl(l_update_lines_index)
2555                                   := p_update_shipping_tbl(l_update_shipping_index);
2556 
2557     END IF;
2558 
2559     l_update_shipping_index := p_update_shipping_tbl.NEXT(l_update_shipping_index);
2560 
2561   END LOOP;
2562 
2563   OE_Shipping_Integration_PVT.Update_Shipping_From_OE
2564   ( p_update_lines_tbl    =>  l_update_lines_tbl,
2565     x_return_status       =>  x_return_status);
2566 
2567 
2568   IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
2569 
2570     l_update_shipping_index := p_update_shipping_tbl.FIRST;
2571     WHILE l_update_shipping_index IS NOT NULL
2572     LOOP
2573 
2574     IF  p_update_shipping_tbl(l_update_shipping_index).request_type
2575                                      = OE_GLOBALS.G_UPDATE_SHIPPING
2576     THEN
2577 
2578       IF  NOT(p_line_id = p_update_shipping_tbl(l_update_shipping_index).entity_id AND
2579               p_operation
2580           = p_update_shipping_tbl(l_update_shipping_index).request_unique_key1)
2581       THEN
2582 
2583         oe_debug_pub.add
2584         ('deleting req '|| p_update_shipping_tbl(l_update_shipping_index).entity_id);
2585 
2586         OE_Delayed_Requests_PVT.Delete_Request
2587         (p_entity_code => p_update_shipping_tbl(l_update_shipping_index).entity_code
2588         ,p_entity_id   => p_update_shipping_tbl(l_update_shipping_index).entity_id
2589         ,p_request_Type => p_update_shipping_tbl(l_update_shipping_index).request_type
2590         ,p_request_unique_key1
2591                => p_update_shipping_tbl(l_update_shipping_index).request_unique_key1
2592         ,x_return_status => x_return_status);
2593 
2594       END IF;
2595 
2596     END IF;
2597 
2598     l_update_shipping_index := p_update_shipping_tbl.NEXT(l_update_shipping_index);
2599 
2600     END LOOP;
2601   END IF;
2602 
2603   -- bug 4741573
2604   OE_MSG_PUB.reset_msg_context('LINE');
2605 
2606   OE_Debug_PUB.Add('Exiting OE_Delayed_Requests_Util.Update_Shipping',1);
2607 EXCEPTION
2608   WHEN OTHERS THEN
2609   x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2610 
2611   IF OE_MSG_PUB.Check_Msg_Level
2612         (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2613      THEN
2614        OE_MSG_PUB.Add_Exc_Msg
2615         ( G_PKG_NAME
2616         , 'Update_Shipping'
2617         );
2618   END IF;
2619 
2620 END Update_Shipping;
2621 
2622 
2623 PROCEDURE Ship_Confirmation
2624 (
2625 	p_ship_confirmation_tbl 		IN  OE_ORDER_PUB.request_tbl_type
2626 ,	p_line_id					IN  NUMBER
2627 ,	p_process_type				IN  VARCHAR2
2628 ,	p_process_id				IN  VARCHAR2
2629 , x_return_status OUT NOCOPY VARCHAR2
2630 
2631 )
2632 IS
2633 	l_process_id			NUMBER;
2634 	l_shipping_index		NUMBER :=0 ;
2635 BEGIN
2636 
2637     	OE_Debug_PUB.Add('Entering OE_Delayed_Requests_Util.Ship_Confirmation'||p_process_type||p_process_id,1);
2638 
2639 	l_process_id     := to_number(p_process_id);
2640 	l_shipping_index := p_ship_confirmation_tbl.First;
2641 	oe_debug_pub.add('P_line_id :'||to_char(p_line_id),2);
2642 
2643     	WHILE	l_shipping_index IS NOT NULL LOOP
2644 
2645 oe_debug_pub.add('Request Type : '||p_ship_confirmation_tbl(l_shipping_index).request_type,2);
2646 oe_debug_pub.add('Param1 : '||p_ship_confirmation_tbl(l_shipping_index).param1,2);
2647 		IF p_ship_confirmation_tbl(l_shipping_index).request_type
2648                                       = OE_GLOBALS.G_SHIP_CONFIRMATION AND
2649 		   p_ship_confirmation_tbl(l_shipping_index).param1 = p_process_id THEN
2650 oe_debug_pub.add('RUnique 1 : '||p_ship_confirmation_tbl(l_shipping_index).request_unique_key1,2);
2651 oe_debug_pub.add('Entity Id : '||to_char(p_ship_confirmation_tbl(l_shipping_index).entity_id),2);
2652 			IF	p_line_id <> p_ship_confirmation_tbl(l_shipping_index).entity_id THEN
2653 
2654 				OE_Delayed_Requests_PVT.Delete_Request
2655 				(p_entity_code 	=> p_ship_confirmation_tbl(l_shipping_index).entity_code
2656                 	,p_entity_id     	=> p_ship_confirmation_tbl(l_shipping_index).entity_id
2657                 	,p_request_Type    	=> p_ship_confirmation_tbl(l_shipping_index).request_type
2658                 	,p_request_unique_key1	=> p_ship_confirmation_tbl(l_shipping_index).request_unique_key1
2659 			 	,x_return_status   	=> x_return_status);
2660 
2661 			END IF;
2662 		END IF;
2663 
2664 		l_shipping_index := p_ship_confirmation_tbl.NEXT(l_shipping_index);
2665 
2666 	END LOOP;
2667 
2668 	OE_Shipping_Integration_PVT.Process_Ship_Confirm
2669 	(
2670 		p_process_id		=>	l_process_id,
2671 		p_process_type		=>	p_process_type,
2672 		x_return_status	=>	x_return_status
2673 	);
2674     OE_Debug_PUB.Add('Exiting OE_Delayed_Requests_Util.Ship_Confirmation',1);
2675 
2676 EXCEPTION
2677 	WHEN OTHERS THEN
2678 	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2679 	IF OE_MSG_PUB.Check_Msg_Level
2680 		    (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2681      THEN
2682 		   OE_MSG_PUB.Add_Exc_Msg
2683 				( G_PKG_NAME
2684 				, 'Ship_Confirmation'
2685 				);
2686 	END IF;
2687 END Ship_Confirmation;
2688 
2689 
2690 Procedure SPLIT_RESERVATIONS
2691 ( p_reserved_line_id   IN  NUMBER
2692 , p_ordered_quantity   IN  NUMBER
2693 , p_reserved_quantity  IN  NUMBER
2694 , x_return_status OUT NOCOPY VARCHAR2)
2695 
2696 IS
2697 l_return_status  VARCHAR2(1);
2698 BEGIN
2699 
2700    oe_debug_pub.add('Entering SPLIT_RESERVATIONS',1);
2701 
2702    oe_debug_pub.add('Calling OE_ORDER_SCH_UTIL.SPLIT_RESERVATIONS',1);
2703 
2704    OE_ORDER_SCH_UTIL.SPLIT_RESERVATIONS
2705 	(p_reserved_line_id  => p_reserved_line_id,
2706       p_ordered_quantity  => p_ordered_quantity,
2707       p_reserved_quantity => p_reserved_quantity,
2708       x_return_status     => l_return_status);
2709 
2710    oe_debug_pub.add('After Calling OE_ORDER_SCH_UTIL.SPLIT_RESERVATIONS: '
2711                                        || l_return_status ,1);
2712 
2713    x_return_status := l_return_status;
2714 
2715 END SPLIT_RESERVATIONS;
2716 
2717 
2718 /*-------------------------------------------------------
2719 Not used at all.
2720 --------------------------------------------------------*/
2721 Procedure COMPLETE_CONFIGURATION
2722 ( p_top_model_line_id  IN  NUMBER
2723 , x_return_status OUT NOCOPY VARCHAR2)
2724 
2725 IS
2726 l_return_status       VARCHAR2(1);
2727 l_valid_config        VARCHAR2(10);
2728 l_complete_config     VARCHAR2(10);
2729 BEGIN
2730 
2731    oe_config_util.Validate_Configuration
2732           (p_model_line_id   => p_top_model_line_id,
2733            p_validate_flag   => 'Y',
2734            p_complete_flag   => 'Y',
2735            x_valid_config    => l_valid_config,
2736            x_complete_config => l_complete_config,
2737            x_return_status   => l_return_status);
2738 
2739 END COMPLETE_CONFIGURATION;
2740 
2741 
2742 /*---------------------------------------------------
2743 The call to oe_config_util does all the work.
2744 ----------------------------------------------------*/
2745 Procedure VALIDATE_CONFIGURATION
2746 ( p_top_model_line_id   IN NUMBER
2747 , p_deleted_options_tbl IN OE_Order_PUB.request_tbl_type
2748 , p_updated_options_tbl IN OE_Order_PUB.request_tbl_type
2749 , x_return_status OUT NOCOPY VARCHAR2
2750 
2751 )
2752 IS
2753 l_return_status       VARCHAR2(1);
2754 l_complete_flag       VARCHAR2(1):= 'N';
2755 l_valid_config        VARCHAR2(10);
2756 l_complete_config     VARCHAR2(10);
2757 
2758 BEGIN
2759    -- any option added to a booked order,
2760    -- validate_configuration should check
2761    -- for valid as well as complete .
2762 
2763    select booked_flag
2764    into l_complete_flag
2765    from oe_order_lines
2766    where line_id = p_top_model_line_id;
2767 
2768    l_complete_flag := nvl(l_complete_flag, 'N');
2769    oe_debug_pub.add('option added to a booked order? : '||l_complete_flag , 2);
2770 
2771        oe_config_util.Validate_Configuration
2772             (p_model_line_id       => p_top_model_line_id,
2773              p_deleted_options_tbl => p_deleted_options_tbl,
2774              p_updated_options_tbl => p_updated_options_tbl,
2775              p_validate_flag       => 'Y',
2776              p_complete_flag       => l_complete_flag,
2777              x_valid_config        => l_valid_config,
2778              x_complete_config     => l_complete_config,
2779              x_return_status       => l_return_status);
2780 
2781              x_return_status   := l_return_status;
2782 
2783    oe_debug_pub.add('leaving ureqb, validate config: '|| l_return_status, 1);
2784 
2785 EXCEPTION
2786    when no_data_found then
2787       oe_debug_pub.add
2788       ('no_data_found in OE_Delayed_Req_Util.VALIDATE_CONFIGURATION', 1);
2789       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2790    when others then
2791       oe_debug_pub.add
2792       ('Exception in OE_Delayed_Req_Util.VALIDATE_CONFIGURATION', 1);
2793       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2794 END VALIDATE_CONFIGURATION;
2795 
2796 Procedure Match_And_Reserve
2797 ( p_line_id         IN  NUMBER
2798 , x_return_status OUT NOCOPY VARCHAR2)
2799 
2800 IS
2801 BEGIN
2802   oe_config_util.match_and_reserve
2803 	 (p_line_id       => p_line_id,
2804        x_return_status => x_return_status);
2805 END;
2806 
2807 
2808 Procedure Group_Schedule
2809 ( p_request_rec     IN   oe_order_pub.request_rec_type
2810 , x_return_status OUT NOCOPY VARCHAR2)
2811 
2812 IS
2813 l_group_req_rec    OE_GRP_SCH_UTIL.Sch_Group_Rec_Type;
2814 l_atp_tbl          OE_ATP.ATP_Tbl_Type;
2815 l_line_rec         OE_ORDER_PUB.line_rec_type;
2816 l_return_status    VARCHAR2(1);
2817 BEGIN
2818 
2819   oe_debug_pub.add('Entering OE_Delayed_Requests_UTIL.Group_Schedule',1);
2820 
2821   oe_debug_pub.add('Entity is :' || p_request_rec.param3,2);
2822   oe_debug_pub.add('Action is :' || p_request_rec.param4,2);
2823 
2824   l_group_req_rec.entity_type               := p_request_rec.param3;
2825   l_group_req_rec.action                    := p_request_rec.param4;
2826   l_group_req_rec.line_id                   := p_request_rec.entity_id;
2827   l_group_req_rec.header_id                 := p_request_rec.param2;
2828   l_group_req_rec.old_schedule_ship_date    := p_request_rec.date_param1;
2829   l_group_req_rec.old_schedule_arrival_date := p_request_rec.date_param2;
2830   l_group_req_rec.old_request_date          := p_request_rec.date_param3;
2831   l_group_req_rec.old_ship_from_org_id      := p_request_rec.param7;
2832   l_group_req_rec.old_ship_set_number       := p_request_rec.param9;
2833   l_group_req_rec.old_arrival_set_number    := p_request_rec.param10;
2834 
2835   OE_LINE_UTIL.Query_Row(p_line_id  => p_request_rec.entity_id
2836                         ,x_line_rec => l_line_rec);
2837 
2838   IF NVL(p_request_rec.param11,'N') = 'Y' THEN
2839 
2840   oe_debug_pub.add('param 11' || p_request_rec.param11,1);
2841    l_group_req_rec.old_schedule_ship_date    := l_line_rec.schedule_ship_date;
2842    l_group_req_rec.old_schedule_arrival_date := l_line_rec.schedule_arrival_date
2843 ;
2844    l_group_req_rec.old_request_date          := l_line_rec.request_date;
2845    l_group_req_rec.old_ship_set_number       := l_line_rec.ship_set_id;
2846    l_group_req_rec.old_arrival_set_number    := l_line_rec.arrival_set_id;
2847 
2848 
2849   END IF;
2850 
2851 
2852   IF l_group_req_rec.entity_type = OE_ORDER_SCH_UTIL.OESCH_ENTITY_ARRIVAL_SET
2853   THEN
2854     l_group_req_rec.arrival_set_number    := p_request_rec.param1;
2855     l_group_req_rec.ship_to_org_id        := l_line_rec.ship_to_org_id;
2856 
2857     IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_arrival_date,
2858                             l_group_req_rec.old_schedule_arrival_date)
2859     THEN
2860        l_group_req_rec.schedule_arrival_date :=
2861                                      l_line_rec.schedule_arrival_date;
2862     END IF;
2863 
2864   ELSE
2865     l_group_req_rec.ship_set_number       := p_request_rec.param1;
2866     l_group_req_rec.ship_from_org_id      := l_line_rec.ship_from_org_id;
2867     l_group_req_rec.ship_to_org_id        := l_line_rec.ship_to_org_id;
2868     l_group_req_rec.freight_carrier       := l_line_rec.shipping_method_code;
2869 
2870     IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_ship_date,
2871                             l_group_req_rec.old_schedule_ship_date)
2872     THEN
2873        l_group_req_rec.schedule_ship_date :=
2874                                      l_line_rec.schedule_ship_date;
2875     END IF;
2876 
2877 	-- Added this part here. If there is a change in arrival date
2878 	-- we should pass this to group_schedule.
2879 
2880     IF NOT OE_GLOBALS.Equal(l_line_rec.schedule_arrival_date,
2881                             l_group_req_rec.old_schedule_arrival_date)
2882     THEN
2883        l_group_req_rec.schedule_arrival_date :=
2884                                      l_line_rec.schedule_arrival_date;
2885     END IF;
2886 
2887     IF NOT OE_GLOBALS.Equal(l_line_rec.request_date,
2888                             l_group_req_rec.old_request_date)
2889     THEN
2890        l_group_req_rec.request_date :=
2891                                      l_line_rec.request_date;
2892     END IF;
2893 
2894 
2895   END IF;
2896 
2897   oe_debug_pub.add('*********Printing Group Request Attributes***********',2);
2898   oe_debug_pub.add('Grp Entity    :' || l_group_req_rec.entity_type,2);
2899   oe_debug_pub.add('Grp Header Id :' || l_group_req_rec.header_id,2);
2900   oe_debug_pub.add('Line Id       :' || l_group_req_rec.line_id,2);
2901   oe_debug_pub.add('Grp Action    :' || l_group_req_rec.action,2);
2902   oe_debug_pub.add('Grp Warehouse :' || l_group_req_rec.ship_from_org_id,2);
2903   oe_debug_pub.add('Grp Ship to   :' || l_group_req_rec.ship_to_org_id,2);
2904   oe_debug_pub.add('Group Sh Set# :' || l_group_req_rec.ship_set_number,2);
2905   oe_debug_pub.add('Group Ar Set# :' || l_group_req_rec.arrival_set_number,2);
2906   oe_debug_pub.add('Grp Ship Date :' || l_group_req_rec.schedule_ship_date,2);
2907   oe_debug_pub.add('Grp Ship Meth :' || l_group_req_rec.freight_carrier,2);
2908   oe_debug_pub.add('Grp Arr Date  :' || l_group_req_rec.schedule_arrival_date,2);
2909   oe_debug_pub.add('***************************************************',2);
2910 
2911   OE_GRP_SCH_UTIL.Group_Schedule
2912        (p_group_req_rec    => l_group_req_rec
2913        ,x_atp_tbl          => l_atp_tbl
2914        ,x_return_status    => l_return_status);
2915 
2916   -- Set the cascade_flag to TRUE, so that we query the block,
2917   -- since multiple lines have changed.
2918 
2919   oe_debug_pub.add('Setting G_CASCADING_REQUEST_LOGGED',2);
2920 
2921   IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
2922       OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
2923   END IF;
2924 
2925   x_return_status := l_return_status;
2926 
2927 EXCEPTION
2928 
2929    WHEN FND_API.G_EXC_ERROR THEN
2930             x_return_status := FND_API.G_RET_STS_ERROR;
2931 
2932     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2933 
2934         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2935         THEN
2936             OE_MSG_PUB.Add_Exc_Msg
2937             (   G_PKG_NAME
2938             ,   'Group_Schedule'
2939             );
2940         END IF;
2941 
2942 
2943     WHEN OTHERS THEN
2944 
2945 
2946         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2947         THEN
2948             OE_MSG_PUB.Add_Exc_Msg
2949             (   G_PKG_NAME
2950             ,   'Group_Schedule'
2951             );
2952         END IF;
2953 
2954 END Group_Schedule;
2955 
2956 Procedure Delink_Config
2957 ( p_line_id         IN  NUMBER
2958 , x_return_status OUT NOCOPY VARCHAR2)
2959 
2960 IS
2961 BEGIN
2962 
2963   oe_config_util.delink_config_batch
2964 	 (p_line_id       => p_line_id,
2965        x_return_status => x_return_status);
2966 END;
2967 
2968 
2969 
2970 /* procedure insert_rma_options_included
2971    to insert options and included items
2972    for the corresponding RMA lines.
2973 */
2974 Procedure INSERT_RMA_OPTIONS_INCLUDED
2975 (p_line_id IN NUMBER
2976 ,x_return_status OUT NOCOPY VARCHAR2
2977 
2978 )
2979 IS
2980 
2981 l_number               	     NUMBER := 0;
2982 l_api_name 		          CONSTANT VARCHAR(30) := 'INSERT_RMA_OPTIONS_INCLUDED';
2983 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
2984 l_return_status               VARCHAR2(30);
2985 l_orig_line_rec               OE_Order_PUB.Line_Rec_Type;
2986 l_reference_line_rec          OE_Order_Pub.Line_Rec_Type;
2987 l_child_line_rec              OE_Order_Pub.Line_Rec_Type;
2988 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
2989 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
2990 I             			     NUMBER;
2991 l_line_id                    NUMBER;
2992 l_reference_line_id          NUMBER;
2993 l_top_model_line_id          NUMBER;
2994 l_ato_line_id          	     NUMBER;
2995 l_link_to_line_id          	 NUMBER;
2996 l_header_id          	     NUMBER;
2997 l_fulfillment_set_id         NUMBER := NULL;
2998 l_copy_call                  BOOLEAN;
2999 
3000 -- l_component_code             VARCHAR2(2000);
3001     CURSOR rma_children IS
3002      SELECT l.header_id, l.line_id, l.ordered_quantity
3003 	 FROM oe_order_lines l,mtl_system_items m
3004      WHERE l.top_model_line_id = l_top_model_line_id
3005      AND nvl(l.ato_line_id,1) 	= nvl(l_ato_line_id,nvl(l.ato_line_id,1))
3006      AND l.link_to_line_id = nvl(l_link_to_line_id,l.link_to_line_id)
3007 	 AND line_id <> l_reference_line_id
3008      AND l.header_id 	= l_header_id
3009 	 AND l.inventory_item_id = m.inventory_item_id
3010 	 AND nvl(m.returnable_flag,'Y') = 'Y'
3011      AND nvl(l.cancelled_flag,'N') = 'N'
3012 	 AND m.organization_id =
3013         OE_Sys_Parameters.VALUE_WNPS('MASTER_ORGANIZATION_ID')
3014         ORDER BY LINE_NUMBER , SHIPMENT_NUMBER ,NVL(OPTION_NUMBER, -1),
3015         NVL(COMPONENT_NUMBER,-1),NVL(SERVICE_NUMBER,-1);
3016 
3017 /* Added the order by to fix bug 2226940 */
3018 
3019 
3020 BEGIN
3021 
3022   OE_DEBUG_PUB.ADD('Entering INSERT_RMA_OPTIONS_INCLUDED',1);
3023 
3024   x_return_status := FND_API.G_RET_STS_SUCCESS;
3025 
3026   BEGIN
3027   -- query the return line and to see if it's a referenced line
3028   OE_Line_Util.query_row(p_line_id  => p_line_id,
3029                          x_line_rec => l_orig_line_rec);
3030   EXCEPTION
3031    WHEN NO_DATA_FOUND THEN
3032 	RETURN;
3033   END;
3034 
3035   IF l_orig_line_rec.return_context is NOT NULL THEN
3036 
3037      OE_Line_Util.query_row(p_line_id  => l_orig_line_rec.reference_line_id
3038                            ,x_line_rec => l_reference_line_rec);
3039 
3040     IF l_reference_line_rec.item_type_code in ('STANDARD','OPTION',
3041 			'INCLUDED','CONFIG','SERVICE') THEN
3042     		return;
3043     END IF;
3044 
3045     -- find the partial return proportion, which applies to all the options and included item lines
3046 
3047     l_reference_line_id 	:= l_orig_line_rec.reference_line_id;
3048     l_header_id 		:= l_reference_line_rec.header_id;
3049 
3050     IF l_orig_line_rec.source_document_type_id = 2 THEN
3051         l_copy_call := TRUE;
3052     END IF;
3053 
3054     IF l_reference_line_rec.top_model_line_id = l_reference_line_rec.line_id THEN
3055 		l_top_model_line_id := l_reference_line_rec.line_id;
3056     ELSIF l_reference_line_rec.ato_line_id = l_reference_line_rec.line_id THEN
3057 		l_ato_line_id := l_reference_line_rec.line_id;
3058 		l_top_model_line_id := l_reference_line_rec.top_model_line_id;
3059     ELSIF l_reference_line_rec.component_code is NOT NULL THEN
3060 /* commented out nocopy to fix 2410422 */
3061 
3062 		/* l_component_code := l_reference_line_rec.component_code||'%'; */
3063 		l_top_model_line_id := l_reference_line_rec.top_model_line_id;
3064         /* Added to fix 2410422 */
3065         l_link_to_line_id := l_reference_line_rec.line_id;
3066     ELSE
3067 	return;
3068     END IF;
3069 
3070 
3071     FOR l_child IN rma_children LOOP
3072      l_number := l_number + 1;
3073 
3074      l_line_tbl(l_number)  :=  OE_ORDER_PUB.G_MISS_LINE_REC;
3075      IF l_number = 1 THEN
3076 	  select oe_sets_s.nextval into l_fulfillment_set_id from dual;
3077 
3078        insert into oe_sets
3079           ( SET_ID, SET_NAME, SET_TYPE, HEADER_ID, SHIP_FROM_ORG_ID,
3080                SHIP_TO_ORG_ID,SCHEDULE_SHIP_DATE, SCHEDULE_ARRIVAL_DATE,
3081                FREIGHT_CARRIER_CODE, SHIPPING_METHOD_CODE,
3082                SHIPMENT_PRIORITY_CODE, SET_STATUS,
3083                CREATED_BY, CREATION_DATE, UPDATED_BY, UPDATE_DATE,
3084                UPDATE_LOGIN, INVENTORY_ITEM_ID,ORDERED_QUANTITY_UOM,
3085                LINE_TYPE_ID,SHIP_TOLERANCE_ABOVE, SHIP_TOLERANCE_BELOW)
3086        values
3087           ( l_fulfillment_set_id, to_char(l_fulfillment_set_id),
3088                'FULFILLMENT_SET',l_orig_line_rec.header_id,
3089 			null,null, null,null,null,
3090                null,null,null, 0,sysdate,0, sysdate,
3091                0,null,null,null,null,null
3092           );
3093 
3094         Insert into oe_line_sets(Line_id, Set_id, SYSTEM_REQUIRED_FLAG)
3095         Values (p_line_id, l_fulfillment_set_id, 'Y');
3096 
3097 	END IF;
3098 
3099      -- If COPY is calling and DFF is to be copied over
3100      IF OE_ORDER_COPY_UTIL.CALL_DFF_COPY_EXTN_API(l_orig_line_rec.org_id) AND
3101         l_copy_call
3102      THEN
3103          OE_Line_Util.query_row(p_line_id  => l_child.line_id,
3104                                 x_line_rec => l_child_line_rec);
3105 
3106          IF OE_ORDER_COPY_UTIL.G_COPY_REC.line_descflex = FND_API.G_TRUE THEN
3107          -- Pre populate the DFF info from reference line
3108              OE_ORDER_COPY_UTIL.copy_line_dff_from_ref
3109                     (p_ref_line_rec => l_child_line_rec,
3110                      p_x_line_rec => l_line_tbl(l_number));
3111 
3112          END IF;
3113 
3114          OE_COPY_UTIL_EXT.Copy_Line_DFF(
3115                                p_copy_rec => OE_ORDER_COPY_UTIL.G_COPY_REC,
3116                                p_operation =>  'ORDER_TO_RETURN',
3117                                p_ref_line_rec => l_child_line_rec,
3118                                p_copy_line_rec => l_line_tbl(l_number));
3119      END IF;
3120      l_line_tbl(l_number).return_context    := 'ORDER';
3121      l_line_tbl(l_number).return_attribute1 := l_child.header_id;
3122      l_line_tbl(l_number).return_attribute2 := l_child.line_id;
3123      l_line_tbl(l_number).ordered_quantity  := ( l_child.ordered_quantity *
3124      l_orig_line_rec.ordered_quantity)/l_reference_line_rec.ordered_quantity;
3125      l_line_tbl(l_number).item_type_code    := OE_GLOBALS.G_ITEM_STANDARD;
3126      l_line_tbl(l_number).operation         := OE_GLOBALS.G_OPR_CREATE;
3127      l_line_tbl(l_number).header_id         := l_orig_line_rec.header_id;
3128      l_line_tbl(l_number).line_type_id      := l_orig_line_rec.line_type_id;
3129      l_line_tbl(l_number).return_reason_code := l_orig_line_rec.return_reason_code;
3130      -- Added for bug fix 2600923
3131      l_line_tbl(l_number).calculate_price_flag :=
3132                                         l_orig_line_rec.calculate_price_flag;
3133      l_line_tbl(l_number).pricing_date := l_orig_line_rec.pricing_date;
3134 
3135     oe_debug_pub.add('RMA: Found options : '|| to_char(l_child.line_id), 2);
3136     END LOOP;
3137 
3138   END IF;
3139 
3140   IF l_number > 0 THEN
3141     oe_debug_pub.add('RMA: Found options and included item lines', 2);
3142 
3143     --  Set control flags.
3144     l_control_rec.controlled_operation := TRUE;
3145     l_control_rec.validate_entity      := TRUE;
3146     l_control_rec.write_to_DB          := TRUE;
3147 
3148     l_control_rec.default_attributes   := TRUE;
3149     l_control_rec.change_attributes    := TRUE;
3150     l_control_rec.clear_dependents     := TRUE;
3151     l_control_rec.process              := FALSE;
3152 
3153     --  Instruct API to retain its caches
3154 
3155     l_control_rec.clear_api_cache      := FALSE;
3156     l_control_rec.clear_api_requests   := FALSE;
3157 
3158     -- Call OE_Order_PVT.Process_order to insert lines
3159     -- Set recursion mode.
3160     --  OE_GLOBALS.G_RECURSION_MODE := 'Y';
3161 
3162 	-- Set the global so that delayed request will not be
3163 	-- logged for the child return line
3164 	  OE_GLOBALS.G_RETURN_CHILDREN_MODE := 'Y';
3165 
3166     OE_ORDER_PVT.Lines
3167     (p_validation_level  => FND_API.G_VALID_LEVEL_FULL
3168     ,p_control_rec       => l_control_rec
3169     ,p_x_line_tbl        => l_line_tbl
3170     ,p_x_old_line_tbl    => l_old_line_tbl
3171     ,x_return_status     => l_return_status);
3172 
3173     -- Reset recursion mode.
3174     -- OE_GLOBALS.G_RECURSION_MODE := 'N';
3175 
3176 	  OE_GLOBALS.G_RETURN_CHILDREN_MODE := 'N';
3177 
3178     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3179         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3180     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3181         RAISE FND_API.G_EXC_ERROR;
3182     END IF;
3183 
3184 --comment out for notification project
3185 /*    OE_ORDER_PVT.Process_Requests_And_notify
3186     ( p_process_requests       => FALSE
3187      ,p_notify                 => TRUE
3188      ,x_return_status          => l_return_status
3189      ,p_line_tbl               => l_line_tbl
3190      ,p_old_line_tbl           => l_old_line_tbl);
3191 
3192     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3193         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3194     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3195         RAISE FND_API.G_EXC_ERROR;
3196     END IF;
3197 */
3198     I := l_line_tbl.FIRST;
3199     WHILE I is not NULL LOOP
3200 
3201    	     -- Insert into Fulfillment set
3202           Insert into oe_line_sets(Line_id, Set_id, SYSTEM_REQUIRED_FLAG)
3203           Values (l_line_tbl(I).line_id, l_fulfillment_set_id, 'Y');
3204 
3205    		-- Insert RMA Sales Credits and Adjustments
3206 		INSERT_RMA_SCREDIT_ADJUSTMENT
3207                  ( x_return_status      => l_return_status
3208                   ,p_line_id            => l_line_tbl(I).line_id
3209                  );
3210 
3211    		-- Insert RMA Lot and Serial Numbers
3212 		INSERT_RMA_LOT_SERIAL
3213                  ( x_return_status      => l_return_status
3214                   ,p_line_id            => l_line_tbl(I).line_id
3215                  );
3216 
3217    		I := l_line_tbl.NEXT(I);
3218     END LOOP;
3219 
3220     OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
3221 
3222   END IF; /* end inserting lines */
3223 
3224   OE_DEBUG_PUB.ADD(' Exiting INSERT_RMA_OPTIONS_INCLUDED',1);
3225 EXCEPTION
3226 
3227     WHEN FND_API.G_EXC_ERROR THEN
3228 
3229         x_return_status := FND_API.G_RET_STS_ERROR;
3230 
3231     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3232 
3233         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3234 
3235     WHEN OTHERS THEN
3236 
3237         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3238 
3239         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3240         THEN
3241             OE_MSG_PUB.Add_Exc_Msg
3242             (   G_PKG_NAME
3243             ,   'INSERT_RMA_OPTIONS_INCLUDED'
3244             );
3245         END IF;
3246 
3247 END INSERT_RMA_OPTIONS_INCLUDED;
3248 
3249 /* procedure insert_rma_lot_serial
3250    to insert lot and serial numbers
3251    for the corresponding RMA lines.
3252 */
3253 Procedure INSERT_RMA_LOT_SERIAL
3254 (p_line_id        IN NUMBER
3255 ,x_return_status OUT NOCOPY VARCHAR2
3256 
3257 )
3258 IS
3259 
3260 l_number               	     NUMBER := 0;
3261 l_api_name 		          CONSTANT VARCHAR(30) := 'INSERT_RMA_LOT_SERIAL';
3262 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
3263 l_x_lot_serial_tbl            OE_Order_PUB.Lot_Serial_Tbl_Type;
3264 l_x_old_lot_serial_tbl        OE_Order_PUB.Lot_Serial_Tbl_Type;
3265 l_return_status               VARCHAR2(30);
3266 l_orig_line_rec               OE_Order_PUB.Line_Rec_Type;
3267 l_reference_line_rec          OE_Order_Pub.Line_Rec_Type;
3268 l_lot_serial_tbl              OE_Order_PUB.Lot_Serial_Tbl_Type;
3269 l_line_id                     NUMBER;
3270 l_inventory_item_id           NUMBER;
3271 l_reference_line_id           NUMBER;
3272 l_lot_control_flag            VARCHAR2(1) := 'N';
3273 l_serial_number_control_flag  VARCHAR2(1) := 'N';
3274 l_count                       NUMBER := 0;
3275 l_serial_number               VARCHAR2(30) := NULL;
3276 l_return_qty                  NUMBER := 0;
3277 l_lot_trxn_qty                NUMBER := 0;
3278 l_return_qty2                 NUMBER := 0; -- INVCONV
3279 l_lot_trxn_qty2               NUMBER := 0; -- INVCONV
3280 
3281 l_ship_from_org_id            NUMBER;
3282 /* OPM Bug 2739964 */
3283 l_item_rec         	      OE_ORDER_CACHE.item_rec_type;
3284 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3285 
3286 CURSOR control_codes IS
3287 SELECT decode(msi.lot_control_code,2,'Y','N'),
3288        decode(msi.serial_number_control_code,2,'Y',5,'Y',6,'Y','N'),
3289        primary_uom_code
3290   FROM mtl_system_items msi
3291  WHERE msi.inventory_item_id = l_inventory_item_id
3292    AND msi.organization_id =
3293               OE_Sys_Parameters.VALUE_WNPS('MASTER_ORGANIZATION_ID');
3294 
3295 -- Now Absolute value of transaction_quantity is selected to fix 1610964.
3296 -- Modified query to take care of over-shipped order lines(Bug # 1643433).
3297 -- Removed the view mtl_transaction_lot_val_v in the below cursor and used the tables involved in the view for bug 5395763
3298 CURSOR lot_numbers is
3299 SELECT u.lot_number,
3300        ABS(SUM(u.transaction_quantity)) transaction_quantity,
3301        ABS(SUM(u.secondary_transaction_quantity)) secondary_transaction_quantity -- INVCONV
3302  FROM  mtl_transaction_lot_numbers u,
3303        mtl_lot_numbers l,
3304        mtl_material_transactions m
3305 WHERE  m.transaction_id = u.transaction_id
3306   AND  u.inventory_item_id = l_inventory_item_id
3307   AND  m.transaction_source_type_id = 2
3308   AND  m.trx_source_line_id = l_reference_line_id
3309   AND  m.ORGANIZATION_ID = l_ship_from_org_id
3310   AND  m.INVENTORY_ITEM_ID = l_inventory_item_id
3311   and  u.organization_id=l.organization_id
3312   and  u.inventory_item_id=l.inventory_item_id
3313   and  u.lot_number = l.lot_number
3314 GROUP  BY u.lot_number;
3315 
3316 -- Added fix for bug 4493305
3317 CURSOR serial_numbers is
3318 SELECT DISTINCT u.serial_number
3319   FROM mtl_unit_transactions_all_v u,
3320        mtl_material_transactions m
3321  WHERE m.transaction_id = u.transaction_id
3322    AND m.INVENTORY_ITEM_ID = l_inventory_item_id
3323    AND u.serial_number = NVL(l_serial_number,u.serial_number)
3324    AND u.inventory_item_id = l_inventory_item_id
3325    AND m.transaction_source_type_id = 2
3326    AND m.trx_source_line_id = l_reference_line_id
3327    AND m.organization_id = l_ship_from_org_id
3328    AND m.transaction_action_id = 1
3329    AND m.transaction_type_id = 33;
3330 
3331 CURSOR lot_serial_numbers is
3332 SELECT DISTINCT t.lot_number,
3333         u.serial_number
3334  FROM mtl_unit_transactions_all_v u,
3335       mtl_material_transactions m,
3336       mtl_transaction_lot_val_v t
3337 WHERE u.serial_number = NVL(l_serial_number,u.serial_number)
3338   AND u.INVENTORY_ITEM_ID = t.inventory_item_id
3339   AND t.serial_transaction_id = u.transaction_id
3340   AND t.INVENTORY_ITEM_ID = m.INVENTORY_ITEM_ID
3341   AND m.transaction_id = t.transaction_id
3342   AND m.transaction_source_type_id = 2
3343   AND m.trx_source_line_id = l_reference_line_id
3344   AND m.ORGANIZATION_ID = l_ship_from_org_id
3345   AND m.INVENTORY_ITEM_ID = l_inventory_item_id;
3346 
3347 -- Added following variables for RMA bug 5288547
3348   l_need_to_fetch_all  BOOLEAN := FALSE;
3349   l_primary_uom        VARCHAR2(3);
3350 
3351 BEGIN
3352 
3353   OE_DEBUG_PUB.ADD(' Entering INSERT_RMA_LOT_SERIAL',1);
3354 
3355   OE_DEBUG_PUB.ADD('RMA: Line Id is '||TO_CHAR(p_line_id),2);
3356 
3357   -- if lot serial numbers exist, delete first
3358 
3359 
3360    x_return_status := FND_API.G_RET_STS_SUCCESS;
3361 
3362   BEGIN
3363      OE_Line_Util.query_row(p_line_id  => p_line_id
3364                            ,x_line_rec => l_orig_line_rec);
3365   EXCEPTION
3366       WHEN NO_DATA_FOUND THEN
3367           Return;
3368   END;
3369 
3370 
3371   oe_debug_pub.add(l_orig_line_rec.return_context,2);
3372 --  IF l_orig_line_rec.return_context is NULL THEN
3373 --    RETURN;
3374 --  END IF;
3375   IF l_orig_line_rec.return_context = 'SERIAL' THEN
3376 	 l_serial_number := l_orig_line_rec.return_attribute2;
3377   ELSE
3378      l_serial_number := NULL;
3379   END IF;
3380 
3381   BEGIN
3382       OE_Lot_serial_util.Lock_rows(p_line_id          => p_line_id,
3383 		                      x_lot_serial_tbl => l_lot_serial_tbl,
3384 						  x_return_status    => l_return_status);
3385 
3386       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3387           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3388       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3389           RAISE FND_API.G_EXC_ERROR;
3390       END IF;
3391 
3392   EXCEPTION
3393 	 WHEN NO_DATA_FOUND THEN
3394 		NULL;
3395   END;
3396 
3397   IF (l_lot_serial_tbl.count > 0) THEN
3398 
3399     oe_debug_pub.add('RMA: rma_lot_serial.DELETE_ROW', 2);
3400 
3401     FOR I IN l_lot_serial_tbl.FIRST .. l_Lot_Serial_tbl.LAST LOOP
3402 
3403 	 l_x_Lot_Serial_tbl(I) := l_Lot_Serial_tbl(I);
3404       l_x_Lot_Serial_tbl(I).operation := OE_GLOBALS.G_OPR_DELETE;
3405 
3406     END LOOP;
3407 
3408     -- Clear Table
3409     l_Lot_serial_tbl.DELETE;
3410 
3411   END IF; /* end delete existing lot serial numbers */
3412 
3413   l_reference_line_id  := l_orig_line_rec.reference_line_id;
3414   IF l_reference_line_id IS NOT NULL AND
3415 	l_reference_line_id <> FND_API.G_MISS_NUM THEN
3416 
3417       OE_DEBUG_PUB.ADD(' There is a reference Line',1);
3418       OE_Line_Util.query_row(p_line_id  => l_reference_line_id,
3419                     	x_line_rec => l_reference_line_rec);
3420       l_inventory_item_id  := l_reference_line_rec.inventory_item_id;
3421       l_ship_from_org_id   := l_reference_line_rec.ship_from_org_id;
3422       oe_debug_pub.add(to_char(l_inventory_item_id)||':'||to_char(l_ship_from_org_id),2);
3423 
3424       OPEN control_codes;
3425       FETCH control_codes INTO l_lot_control_flag,
3426                                l_serial_number_control_flag,
3427                                l_primary_uom;
3428       IF control_codes%notfound THEN
3429         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3430       END IF;
3431       CLOSE control_codes;
3432 
3433       -- Added following for RMA bug 5155914
3434 
3435       -- Shipping UOM is always the Primary UOM for an item. If the original order
3436       -- that shipped out, has non-primary order_quantity_UOM then we should be
3437       -- fetching all data from the MTL tables for all LOT and Serial numbers that
3438       -- shipped on the originalorder(Not restrict it by the quantity on the RMA)
3439       -- It will be left to users to manually edit the data if needed in
3440       -- oe_lot_serial_numbers table.
3441 
3442       IF l_reference_line_rec.order_quantity_uom <> l_primary_uom THEN
3443           l_need_to_fetch_all := TRUE;
3444       END IF;
3445 
3446 
3447       IF (l_lot_control_flag = 'Y' and l_serial_number_control_flag <> 'N') THEN
3448 
3449         -- If the Item is LOT and Serial controlled
3450 
3451         FOR l_lot_serial_numbers IN lot_serial_numbers LOOP
3452           /*
3453           ** Exit the loop if lot serial qty reaches line return qty.
3454           */
3455           IF l_return_qty >= l_orig_line_rec.ordered_quantity AND
3456             NOT l_need_to_fetch_all -- bug 5155914
3457           THEN
3458             EXIT;
3459           ELSE
3460             l_return_qty := l_return_qty + 1;
3461           END IF;
3462 
3463           OE_DEBUG_PUB.ADD(' In LOT-SERIAL-NUMBERS cursor',1);
3464           l_number := l_number + 1;
3465           l_lot_serial_tbl(l_number) := OE_ORDER_PUB.G_MISS_LOT_SERIAL_REC;
3466           l_lot_serial_tbl(l_number).lot_number := l_lot_serial_numbers.lot_number;
3467           l_lot_serial_tbl(l_number).from_serial_number := l_lot_serial_numbers.serial_number;
3468           l_lot_serial_tbl(l_number).quantity := 1;
3469         END LOOP;
3470 
3471       ELSIF (l_lot_control_flag = 'Y') THEN
3472 
3473         -- If the Item is just LOT controlled
3474 
3475         FOR l_lot_numbers IN lot_numbers LOOP
3476           /*
3477           ** Exit the loop if lot item qty reaches line return qty.
3478           */
3479           IF l_return_qty = l_orig_line_rec.ordered_quantity AND
3480              NOT l_need_to_fetch_all -- bug 5155914
3481           THEN
3482             EXIT;
3483           END IF;
3484 
3485           l_return_qty := l_return_qty + l_lot_numbers.transaction_quantity;
3486           l_return_qty2 := l_return_qty2 + l_lot_numbers.secondary_transaction_quantity; -- INVCONV
3487 
3488           IF l_return_qty > l_orig_line_rec.ordered_quantity AND
3489              NOT l_need_to_fetch_all -- bug 5155914
3490           THEN
3491             l_lot_trxn_qty := l_orig_line_rec.ordered_quantity - (l_return_qty - l_lot_numbers.transaction_quantity);
3492             l_return_qty := l_orig_line_rec.ordered_quantity;
3493             l_lot_trxn_qty2 := l_orig_line_rec.ordered_quantity2 - (l_return_qty2 - l_lot_numbers.secondary_transaction_quantity); -- INVCONV
3494             l_return_qty2 := l_orig_line_rec.ordered_quantity2; -- INVCONV
3495 
3496 
3497           ELSE
3498             l_lot_trxn_qty := l_lot_numbers.transaction_quantity;
3499             l_lot_trxn_qty2 := l_lot_numbers.secondary_transaction_quantity; -- INVCONV
3500           END IF;
3501 
3502           l_number := l_number + 1;
3503           OE_DEBUG_PUB.ADD(' In LOT-NUMBERS cursor',1);
3504           l_lot_serial_tbl(l_number) := OE_ORDER_PUB.G_MISS_LOT_SERIAL_REC;
3505           l_lot_serial_tbl(l_number).lot_number := l_lot_numbers.lot_number;
3506 
3507           -- transaction quantity is negative because of sales order issue
3508           -- Removed -ve sign to fix 1643433.
3509           l_lot_serial_tbl(l_number).quantity := l_lot_trxn_qty;
3510           l_lot_serial_tbl(l_number).quantity2 := l_lot_trxn_qty2; -- INVCONV
3511 
3512         END LOOP;
3513 
3514       ELSIF (l_serial_number_control_flag <> 'N') THEN
3515 
3516         -- If the Item is just Serial controlled
3517 
3518         FOR l_serial_numbers IN serial_numbers LOOP
3519           /*
3520           ** Exit the loop if serial item qty reaches line return qty.
3521           */
3522           IF l_return_qty >= l_orig_line_rec.ordered_quantity AND
3523              NOT l_need_to_fetch_all -- bug 5155914
3524           THEN
3525             EXIT;
3526           ELSE
3527             l_return_qty := l_return_qty + 1;
3528           END IF;
3529 
3530           l_number := l_number + 1;
3531           OE_DEBUG_PUB.ADD(' In SERIAL-NUMBERS cursor',1);
3532           l_lot_serial_tbl(l_number) := OE_ORDER_PUB.G_MISS_LOT_SERIAL_REC;
3533           l_lot_serial_tbl(l_number).from_serial_number := l_serial_numbers.serial_number;
3534           l_lot_serial_tbl(l_number).quantity := 1;
3535         END LOOP;
3536 
3537       END IF;
3538     END IF;
3539   -- END IF;-- INVCONV
3540   IF l_number > 0 THEN
3541     oe_debug_pub.add('RMA: FOUND LOT/SERIAL NUMBERS FOR THE LINE'||to_char(l_number), 1);
3542 
3543     FOR I IN l_Lot_serial_tbl.FIRST .. l_Lot_serial_tbl.LAST LOOP
3544 
3545 	 l_count := l_x_lot_serial_tbl.count;
3546       l_x_lot_serial_tbl(l_count + I) := l_lot_serial_tbl(I);
3547       l_x_lot_serial_tbl(l_count + I).operation := OE_GLOBALS.G_OPR_CREATE;
3548       l_x_lot_serial_tbl(l_count + I).line_id   := l_orig_line_rec.line_id;
3549 
3550     END LOOP;
3551   END IF; /* end inserting lot serial numbers */
3552 
3553   IF l_x_lot_serial_tbl.count > 0 THEN
3554     OE_DEBUG_PUB.ADD(' Before calling  OE_ORDER_PVT.Lot_Serials',1);
3555     --  Call OE_Order_PVT.Process_order to insert lines
3556     -- Set recursion mode.
3557     -- OE_GLOBALS.G_RECURSION_MODE := 'Y';
3558 
3559     OE_ORDER_PVT.Lot_Serials
3560     (p_validation_level            => FND_API.G_VALID_LEVEL_FULL
3561     ,p_control_rec                 => l_control_rec
3562     ,P_x_lot_serial_tbl            => l_x_lot_serial_tbl
3563     ,p_x_old_lot_serial_tbl        => l_x_old_lot_serial_tbl
3564     ,x_return_status               => l_return_status);
3565     -- Reset recursion mode.
3566     -- OE_GLOBALS.G_RECURSION_MODE := 'N';
3567     OE_DEBUG_PUB.ADD(' After calling  OE_ORDER_PVT.Lot_Serials',1);
3568 
3569     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3570         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3571     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3572         RAISE FND_API.G_EXC_ERROR;
3573     END IF;
3574 
3575 --comment out for nitification project
3576 /*    OE_ORDER_PVT.Process_Requests_And_notify
3577     ( p_process_requests     => FALSE
3578      ,p_notify               => TRUE
3579      ,x_return_status        => l_return_status
3580      ,p_lot_serial_tbl       => l_x_lot_serial_tbl
3581      ,p_old_lot_serial_tbl   => l_x_old_lot_serial_tbl);
3582 
3583     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3584         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3585     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3586         RAISE FND_API.G_EXC_ERROR;
3587     END IF;
3588 */
3589 
3590   END IF; /* end calling process order */
3591     -- Clear Table
3592     l_Lot_serial_tbl.DELETE;
3593 
3594   OE_DEBUG_PUB.ADD(' Exiting INSERT_RMA_LOT_SERIAL',1);
3595 
3596 EXCEPTION
3597 
3598 
3599     WHEN FND_API.G_EXC_ERROR THEN
3600 
3601         x_return_status := FND_API.G_RET_STS_ERROR;
3602 
3603     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3604 
3605         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3606 
3607     WHEN OTHERS THEN
3608 
3609         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3610 
3611         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3612         THEN
3613             OE_MSG_PUB.Add_Exc_Msg
3614             (   G_PKG_NAME
3615             ,   'INSERT_RMA_LOT_SERIAL'
3616             );
3617         END IF;
3618 
3619 END INSERT_RMA_LOT_SERIAL;
3620 
3621 PROCEDURE Validate_Line_Set(P_line_set_id   IN  NUMBER,
3622 x_return_status OUT NOCOPY VARCHAR2) IS
3623 
3624 l_line_tbl             OE_ORDER_PUB.LINE_TBL_TYPE;
3625 l_item_id              NUMBER;
3626 l_order_qty_uom        VARCHAR2(30);
3627 l_line_type_id         NUMBER;
3628 l_ship_tolerance_above NUMBER;
3629 l_ship_tolerance_below NUMBER;
3630 l_project_id           NUMBER;
3631 l_task_id              NUMBER;
3632 l_lin_line_id          NUMBER;  -- Bug 5754554
3633 
3634 BEGIN
3635  oe_debug_pub.add('Entering oe_delayed_requests_util.Validate_Line_Set',1);
3636  oe_line_util.query_rows(p_line_set_id => p_line_set_id,
3637                          x_line_tbl    => l_line_tbl);
3638 
3639 -- Start for bug 5754554
3640  IF l_line_tbl.count > 0 THEN
3641    FOR I IN 1 .. l_line_tbl.count LOOP
3642      IF l_line_tbl(I).open_flag = 'N' AND l_line_tbl(I).cancelled_flag = 'Y'
3643 THEN
3644      oe_debug_pub.add(' Line_id '||l_line_tbl(I).line_id||' is canceled. Discarding it from Line Set');
3645        l_line_tbl.DELETE(I);
3646      END IF;
3647    END LOOP;
3648  END IF;
3649 
3650  IF l_line_tbl.count > 0 THEN
3651   FOR I IN l_line_tbl.first .. l_line_tbl.last LOOP
3652    IF l_line_tbl.EXISTS(I) THEN
3653     l_item_id              := nvl(l_line_tbl(I).inventory_item_id,-99);
3654     l_order_qty_uom        := nvl(l_line_tbl(I).order_quantity_uom,'-99');
3655     l_line_type_id         := nvl(l_line_tbl(I).line_type_id,-99) ;
3656     l_ship_tolerance_above := nvl(l_line_tbl(I).ship_tolerance_above,-99);
3657     l_ship_tolerance_below := Nvl(l_line_tbl(I).ship_tolerance_below,-99);
3658     l_task_id              := Nvl(l_line_tbl(I).task_id,-99);
3659     l_project_id           := Nvl(l_line_tbl(I).project_id,-99);
3660     l_lin_line_id          := Nvl(l_line_tbl(I).line_id,-99);
3661    EXIT;
3662    END IF;
3663   END LOOP;
3664 
3665 /*
3666     l_item_id              := nvl(l_line_tbl(1).inventory_item_id,-99);
3667     l_order_qty_uom        := nvl(l_line_tbl(1).order_quantity_uom,'-99');
3668     l_line_type_id         := nvl(l_line_tbl(1).line_type_id,-99) ;
3669     l_ship_tolerance_above := nvl(l_line_tbl(1).ship_tolerance_above,-99);
3670     l_ship_tolerance_below := Nvl(l_line_tbl(1).ship_tolerance_below,-99);
3671     l_project_id           := Nvl(l_line_tbl(1).project_id,-99);
3672     l_task_id              := Nvl(l_line_tbl(1).task_id,-99);
3673 
3674             FOR I IN 2 .. l_line_tbl.count  */
3675             FOR I IN l_line_tbl.first .. l_line_tbl.last
3676             LOOP
3677               IF l_line_tbl.EXISTS(I) AND l_line_tbl(I).line_id <> l_lin_line_id
3678 THEN
3679 -- End for bug 5754554
3680 
3681 		IF (l_line_tbl(I).inventory_item_id <>
3682 		    l_item_id )  THEN
3683 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3684               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Item');
3685               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3686 							  to_char(l_line_tbl(I).shipment_number));
3687               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3688 							  to_char(l_line_tbl(I).line_number));
3689          	    OE_MSG_PUB.ADD;
3690 		    RAISE FND_API.G_EXC_ERROR;
3691 		ELSIF (l_line_tbl(I).order_quantity_uom <>
3692 		    l_order_qty_uom )  THEN
3693 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3694               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Unit of Measure');
3695               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3696 							  to_char(l_line_tbl(I).shipment_number));
3697               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3698 							  to_char(l_line_tbl(I).line_number));
3699          	    OE_MSG_PUB.ADD;
3700 		    RAISE FND_API.G_EXC_ERROR;
3701 		ELSIF (l_line_tbl(I).line_type_id <>
3702 		    l_line_type_id ) THEN
3703 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3704               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Line Type');
3705               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3706 							  to_char(l_line_tbl(I).shipment_number));
3707               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3708 							  to_char(l_line_tbl(I).line_number));
3709          	    OE_MSG_PUB.ADD;
3710 		    RAISE FND_API.G_EXC_ERROR;
3711 		ELSIF (l_line_tbl(I).ship_tolerance_above <>
3712 		    l_ship_tolerance_above )  THEN
3713 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3714               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Ship tolerance above');
3715               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3716 							  to_char(l_line_tbl(I).shipment_number));
3717               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3718 							  to_char(l_line_tbl(I).line_number));
3719          	    OE_MSG_PUB.ADD;
3720 		    RAISE FND_API.G_EXC_ERROR;
3721 		ELSIF (l_line_tbl(I).ship_tolerance_below <>
3722 		    l_ship_tolerance_below )  THEN
3723 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3724               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Ship tolerance below');
3725               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3726 							  to_char(l_line_tbl(I).shipment_number));
3727               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3728 							  to_char(l_line_tbl(I).line_number));
3729          	    OE_MSG_PUB.ADD;
3730 		    RAISE FND_API.G_EXC_ERROR;
3731 		ELSIF (l_line_tbl(I).project_id <>
3732 		    l_project_id ) THEN
3733 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3734               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Project');
3735               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3736 							  to_char(l_line_tbl(I).shipment_number));
3737               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3738 							  to_char(l_line_tbl(I).line_number));
3739          	    OE_MSG_PUB.ADD;
3740 		    RAISE FND_API.G_EXC_ERROR;
3741 		ELSIF (l_line_tbl(I).Task_id <>
3742 		    l_Task_id ) THEN
3743 		    FND_MESSAGE.SET_NAME('ONT','OE_VAL_LINE_SET_ATTR');
3744               FND_MESSAGE.SET_TOKEN('ATTRIBUTE_NAME','Task');
3745               FND_MESSAGE.SET_TOKEN('LINE_NUMBER',
3746 							  to_char(l_line_tbl(I).shipment_number));
3747               FND_MESSAGE.SET_TOKEN('PARENT_LINE_NUMBER',
3748 							  to_char(l_line_tbl(I).line_number));
3749          	    OE_MSG_PUB.ADD;
3750 		    RAISE FND_API.G_EXC_ERROR;
3751 	     END IF;
3752              END IF; -- For Bug 5754554
3753 	    END LOOP;
3754  END IF;
3755  oe_debug_pub.add('Exiting oe_delayed_requests_util.Validate_Line_Set',1);
3756 EXCEPTION
3757    WHEN FND_API.G_EXC_ERROR THEN
3758 
3759 		OE_MSG_PUB.reset_msg_context('SPLIT');
3760 			 RAISE;
3761 
3762 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3763 
3764 			 OE_MSG_PUB.reset_msg_context('SPLIT');
3765 			  RAISE;
3766 
3767 
3768      WHEN OTHERS THEN
3769       IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3770       THEN
3771        OE_MSG_PUB.Add_Exc_Msg
3772                (    G_PKG_NAME ,
3773                     'Validate Line Set'
3774                );
3775       END IF;
3776       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3777 
3778 END Validate_line_Set;
3779 
3780 PROCEDURE Process_Adjustments
3781 (p_adjust_tbl	     IN  OE_ORDER_PUB.REQUEST_TBL_TYPE,
3782 x_return_status OUT NOCOPY VARCHAR2)
3783 
3784 IS
3785 l_return_status               VARCHAR2(30);
3786 x_msg_data                    VARCHAR2(2000);
3787 x_msg_count                   NUMBER;
3788 l_adj_rec                     OE_ORDER_PUB.LINE_ADJ_REC_TYPE;
3789 l_adj_tbl                     OE_ORDER_PUB.LINE_ADJ_TBL_TYPE;
3790 l_x_header_rec                OE_Order_PUB.Header_Rec_Type;
3791 l_x_Header_Adj_tbl            OE_Order_PUB.Header_Adj_Tbl_Type;
3792 l_x_Header_Scredit_tbl        OE_Order_PUB.Header_Scredit_Tbl_Type;
3793 l_x_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
3794 l_x_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
3795 l_x_Line_Scredit_tbl          OE_Order_PUB.Line_Scredit_Tbl_Type;
3796 l_x_Lot_Serial_tbl            OE_Order_PUB.Lot_Serial_Tbl_Type;
3797 l_x_action_request_tbl	     OE_Order_PUB.Request_Tbl_Type;
3798 l_x_Header_price_Att_tbl      OE_Order_PUB.Header_Price_Att_Tbl_Type;
3799 l_x_Header_Adj_Att_tbl        OE_Order_PUB.Header_Adj_Att_Tbl_Type;
3800 l_x_Header_Adj_Assoc_tbl      OE_Order_PUB.Header_Adj_Assoc_Tbl_Type;
3801 l_x_Line_price_Att_tbl        OE_Order_PUB.Line_Price_Att_Tbl_Type;
3802 l_x_Line_Adj_Att_tbl          OE_Order_PUB.Line_Adj_Att_Tbl_Type;
3803 l_x_Line_Adj_Assoc_tbl        OE_Order_PUB.Line_Adj_Assoc_Tbl_Type;
3804 l_list_line_type_code         VARCHAR2(30) := NULL;
3805 l_list_line_id                NUMBER;
3806 --serla begin
3807 l_x_Header_Payment_tbl        OE_Order_PUB.Header_Payment_Tbl_Type;
3808 l_x_Line_Payment_tbl          OE_Order_PUB.Line_Payment_Tbl_Type;
3809 --serla end
3810 Begin
3811 
3812 
3813  oe_debug_pub.add('Entering oe_delayed_requests_util.Process_adjustments',1);
3814        FOR I IN 1..(p_adjust_tbl.COUNT) LOOP
3815 
3816          oe_debug_pub.add('I in p_adjust_tbl is : ' || I,2);
3817 
3818          oe_debug_pub.add(p_adjust_tbl(I).param3 || ' is there ',2);
3819 
3820          Select list_line_type_code
3821          Into   l_list_line_type_code
3822          From   qp_list_lines
3823          Where  list_line_id = to_number(p_adjust_tbl(I).param3);
3824 
3825          l_adj_rec := Oe_Order_Pub.G_MISS_LINE_ADJ_REC;
3826          /* l_adj_rec.list_line_type_code := 'DIS'; */
3827          l_adj_rec.price_adjustment_id := to_number(p_adjust_tbl(I).param1);
3828          l_adj_rec.list_header_id      := to_number(p_adjust_tbl(I).param2);
3829 
3830          l_adj_rec.list_line_id := to_number(p_adjust_tbl(I).param3);
3831 /*
3832          l_adj_rec.list_line_id := l_list_line_id;
3833 */
3834          l_adj_rec.automatic_flag      := p_adjust_tbl(I).param4;
3835          l_adj_rec.list_line_type_code := l_list_line_type_code;
3836          l_adj_rec.arithmetic_operator := '%';
3837          l_adj_rec.operand   := to_number(p_adjust_tbl(I).param5);
3838          l_adj_rec.line_id   := p_adjust_tbl(I).entity_id;
3839          l_adj_rec.header_id := to_number(p_adjust_tbl(I).param7);
3840          l_adj_rec.operation := p_adjust_tbl(I).param8;
3841 
3842          l_adj_tbl(I) := l_adj_rec;
3843 
3844 
3845        END LOOP;
3846 
3847        /* call process order */
3848 
3849     IF (l_adj_tbl.COUNT >= 1) THEN
3850 
3851     -- Set recursion mode.
3852     --  OE_GLOBALS.G_RECURSION_MODE := 'Y';
3853 
3854     OE_Order_PVT.Process_order
3855     (   p_api_version_number          => 1.0
3856     ,   x_return_status               => l_return_status
3857     ,   x_msg_count                   => x_msg_count
3858     ,   x_msg_data                    => x_msg_data
3859     ,   p_x_header_rec                => l_x_header_rec
3860     ,   p_x_Header_Adj_tbl            => l_x_Header_Adj_tbl
3861     ,   p_x_Header_Scredit_tbl        => l_x_Header_Scredit_tbl
3862 --serla begin
3863         ,   p_x_Header_Payment_tbl          => l_x_Header_Payment_tbl
3864 --serla end
3865     ,   p_x_line_tbl                  => l_x_line_tbl
3866     ,   p_x_Line_Adj_tbl              => l_Adj_tbl
3867     ,   p_x_Line_Scredit_tbl          => l_x_Line_Scredit_tbl
3868 --serla begin
3869         ,   p_x_Line_Payment_tbl            => l_x_Line_Payment_tbl
3870 --serla end
3871     ,   p_x_Lot_Serial_tbl            => l_x_Lot_Serial_tbl
3872     ,   p_x_action_request_tbl	   => l_x_action_request_tbl
3873     ,   p_x_header_price_att_tbl      => l_x_header_price_att_tbl
3874     ,   p_x_Header_Adj_att_tbl        => l_x_Header_Adj_att_tbl
3875     ,   p_x_Header_Adj_Assoc_tbl      => l_x_Header_Adj_Assoc_tbl
3876     ,   p_x_Line_Price_att_tbl        => l_x_Line_Price_att_tbl
3877     ,   p_x_Line_Adj_att_tbl          => l_x_Line_Adj_att_tbl
3878     ,   p_x_Line_Adj_Assoc_tbl        => l_x_Line_Adj_Assoc_tbl
3879     );
3880 
3881 
3882     -- Reset recursion mode.
3883     --  OE_GLOBALS.G_RECURSION_MODE := 'N';
3884 
3885     oe_debug_pub.add('after process order call ',2);
3886     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3887         oe_debug_pub.add('error1',2);
3888         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3889     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3890         oe_debug_pub.add('error2',2);
3891         RAISE FND_API.G_EXC_ERROR;
3892     END IF;
3893 
3894    end if; /* if l_adj_tbl.count >= 1 */
3895 
3896     oe_debug_pub.add('no error in process order ',2);
3897     x_return_status := l_return_status;
3898  oe_debug_pub.add('Exiting oe_delayed_requests_util.Process_adjustments',1);
3899 
3900 
3901 EXCEPTION
3902 
3903     WHEN FND_API.G_EXC_ERROR THEN
3904 
3905         x_return_status := FND_API.G_RET_STS_ERROR;
3906 
3907         --  Get message count and data
3908 
3909         OE_MSG_PUB.Count_And_Get
3910         (   p_count                       => x_msg_count
3911         ,   p_data                        => x_msg_data
3912         );
3913 
3914     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3915 
3916         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3917         --  Get message count and data
3918 
3919         OE_MSG_PUB.Count_And_Get
3920         (   p_count                       => x_msg_count
3921         ,   p_data                        => x_msg_data
3922         );
3923 
3924     WHEN OTHERS THEN
3925 
3926         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3927 
3928         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3929         THEN
3930             OE_MSG_PUB.Add_Exc_Msg
3931             (   G_PKG_NAME
3932             ,   'Process_Adjustments'
3933             );
3934 	END IF;
3935         --  Get message count and data
3936 
3937         OE_MSG_PUB.Count_And_Get
3938         (   p_count                       => x_msg_count
3939         ,   p_data                        => x_msg_data
3940         );
3941 
3942 NULL;
3943 
3944 End Process_Adjustments;
3945 
3946 PROCEDURE INSERT_SERVICE_FOR_OPTIONS
3947 (p_serviced_line_id  IN NUMBER
3948 ,x_return_status OUT NOCOPY VARCHAR2
3949 
3950 )
3951 
3952 IS
3953 
3954 l_number                      NUMBER := 0;
3955 l_api_name                    CONSTANT VARCHAR(30) := 'INSERT_SERVICE_FOR_OPTIONS';
3956 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
3957 l_return_status               Varchar2(30);
3958 l_orig_line_rec               OE_Order_PUB.Line_Rec_Type;
3959 l_reference_line_rec          OE_Order_Pub.Line_Rec_Type;
3960 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
3961 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
3962 l_line_id                     NUMBER;
3963 l_service_reference_line_id   NUMBER;
3964 l_header_id                   NUMBER;
3965 l_line_number                 NUMBER;
3966 l_order_number                NUMBER;
3967 l_shipment_number             NUMBER;
3968 l_option_number               NUMBER;
3969 l_component_number            NUMBER;
3970 
3971 
3972 -- For bug 2372098
3973 TYPE Line_Cur_Type IS ref CURSOR;
3974 srv_children line_cur_type;
3975 
3976 -- Commented for bug 2372098, this static cursor is replaced
3977 -- with a  cursor variable named srv_children
3978 
3979 -- 	CURSOR srv_children IS
3980 -- 	SELECT l.header_id,
3981 -- 		  l.line_id,
3982 -- 		  l.shipment_number,
3983 -- 		  l.line_number,
3984 -- 		  l.option_number,
3985 --                   l.component_number,
3986 -- 		  l.service_txn_reason_code,
3987 -- 		  l.service_txn_comments,
3988 -- 		  l.service_duration,
3989 -- 		  l.service_period,
3990 -- 		  l.service_start_date,
3991 -- 		  l.service_end_date,
3992 -- 		  l.service_coterminate_flag,
3993 -- 		  l.ordered_quantity
3994 --      FROM   oe_order_lines l
3995 --      WHERE  l.top_model_line_id = l_service_reference_line_id
3996 --      AND    l.item_type_code in ('INCLUDED','CLASS','OPTION')
3997 -- 	AND    exists (select null from mtl_system_items mtl where
3998 -- 		  mtl.inventory_item_id = l.inventory_item_id and
3999 -- 		  mtl.serviceable_product_flag = 'Y' and
4000 --               mtl.organization_id=OE_SYS_PARAMETERS.VALUE('MASTER_ORGANIZATION_ID') );
4001         --lchen added check for organizations to fix bug 2039304
4002 
4003      CURSOR srv_number IS
4004      SELECT max(l.service_number) service_number
4005 	FROM   oe_order_lines l
4006      WHERE  l.header_id = l_header_id
4007      AND    l.line_number   = l_line_number
4008      AND    l.shipment_number = l_shipment_number
4009      AND    nvl(l.option_number,0) = nvl(l_option_number,0)
4010      AND    nvl(l.component_number,0) = nvl(l_component_number,0);
4011 
4012 BEGIN
4013 
4014   OE_DEBUG_PUB.ADD('Entering INSERT_SERVICE_FOR_OPTIONS',1);
4015 
4016   IF fnd_profile.value('ONT_CASCADE_SERVICE') = 'N' THEN
4017     /* 3128684 */
4018     oe_debug_pub.add('Do not cascade services', 2);
4019     x_return_status := FND_API.G_RET_STS_SUCCESS;
4020     RETURN;
4021   END IF;
4022   oe_debug_pub.add('Do cascade services', 2);
4023 
4024   -- query the service line and to see if it's a referenced line
4025   OE_Line_Util.query_row(p_line_id  => p_serviced_line_id,
4026 					x_line_rec => l_orig_line_rec);
4027 
4028      SELECT /* MOAC_SQL_CHANGE */ h.order_number
4029      INTO   l_order_number
4030      FROM   oe_order_headers_all h, oe_order_lines l
4031      WHERE  h.header_id = l.header_id
4032      AND    h.header_id = l_orig_line_rec.header_id
4033 	AND    rownum = 1;
4034 
4035 
4036 
4037   IF l_orig_line_rec.service_reference_type_code is NOT NULL THEN
4038      OE_Line_Util.query_row(p_line_id  => l_orig_line_rec.service_reference_line_id,
4039 	                       x_line_rec => l_reference_line_rec);
4040      l_service_reference_line_id := l_orig_line_rec.service_reference_line_id;
4041 	oe_debug_pub.add('JPN: Service Reference Line is' || l_service_reference_line_id,2);
4042 
4043 -- For bug 2372098, the cursor variable srv_children would be associated
4044 -- with different queries based on source_type_document_id.
4045 
4046 -- * IMPORTANT *
4047 -- If the following SELECT statements are modified, then the definition of
4048 -- t_line_rec in OEXUREQS.pls also needs to be modified, else  fetching
4049 -- records from the cursor variable srv_children into l_child would
4050 -- raise an exception
4051 
4052      IF (l_orig_line_rec.source_document_type_id = 2 ) THEN
4053 
4054 	OPEN srv_children FOR
4055 	  SELECT l.header_id,
4056 		  l.line_id,
4057 		  l.shipment_number,
4058 		  l.line_number,
4059 		  l.option_number,
4060                   l.component_number,
4061 		  l.service_txn_reason_code,
4062 		  l.service_txn_comments,
4063 		  l.service_duration,
4064 		  l.service_period,
4065 		  l.service_start_date,
4066 		  l.service_end_date,
4067 		  l.service_coterminate_flag,
4068 		  l.ordered_quantity
4069 	  FROM   oe_order_lines l
4070 	  WHERE  l.top_model_line_id = l_service_reference_line_id
4071 	  AND    l.item_type_code = 'INCLUDED'
4072 	  AND    exists (select null from mtl_system_items mtl where
4073 		    mtl.inventory_item_id = l.inventory_item_id and
4074 		    mtl.serviceable_product_flag = 'Y' and
4075 			 mtl.organization_id=OE_SYS_PARAMETERS.VALUE('MASTER_ORGANIZATION_ID') );
4076       ELSE
4077 
4078 	OPEN srv_children FOR
4079 	  SELECT l.header_id,
4080 		  l.line_id,
4081 		  l.shipment_number,
4082 		  l.line_number,
4083 		  l.option_number,
4084                   l.component_number,
4085 		  l.service_txn_reason_code,
4086 		  l.service_txn_comments,
4087 		  l.service_duration,
4088 		  l.service_period,
4089 		  l.service_start_date,
4090 		  l.service_end_date,
4091 		  l.service_coterminate_flag,
4092 		  l.ordered_quantity
4093 	  FROM   oe_order_lines l
4094 	  WHERE  l.top_model_line_id = l_service_reference_line_id
4095           AND    l.top_model_line_id <> l.line_id     -- For bug 2938790
4096 	  AND    l.item_type_code in ('INCLUDED','CLASS','OPTION', 'KIT') -- For bug 2447402
4097 	  AND    exists (select null from mtl_system_items mtl where
4098 			 mtl.inventory_item_id = l.inventory_item_id and
4099 			 mtl.serviceable_product_flag = 'Y' and
4100 			 mtl.organization_id=OE_SYS_PARAMETERS.VALUE('MASTER_ORGANIZATION_ID') );
4101      END IF; /* source_type_doc_id = 2 */
4102 -- End 2372098
4103 
4104 -- For bug 2372098
4105 -- FOR cannot be used on cursor variables, so adding the following
4106 -- loop to fetch the records.
4107 --    FOR l_child IN srv_children LOOP
4108 
4109      LOOP
4110 	FETCH srv_children INTO l_child;
4111 	EXIT WHEN srv_children%NOTFOUND;
4112 
4113      l_number := l_number + 1;
4114      l_line_tbl(l_number) := OE_ORDER_PUB.G_MISS_LINE_REC;
4115      l_line_tbl(l_number).service_reference_type_code := 'ORDER';
4116      l_line_tbl(l_number).service_reference_line_id   := l_child.line_id;
4117 -- aksingh change it not right
4118      l_line_tbl(l_number).service_reference_system_id := l_child.line_id;
4119      l_line_tbl(l_number).service_txn_reason_code     := l_child.service_txn_reason_code;
4120      l_line_tbl(l_number).service_txn_comments := l_child.service_txn_comments;
4121      l_line_tbl(l_number).service_duration     := l_orig_line_rec.service_duration;
4122      l_line_tbl(l_number).service_period       := l_orig_line_rec.service_period;
4123      l_line_tbl(l_number).service_start_date   := l_orig_line_rec.service_start_date;
4124      l_line_tbl(l_number).service_end_date     := l_orig_line_rec.service_end_date;
4125      l_line_tbl(l_number).service_coterminate_flag := l_orig_line_rec.service_coterminate_flag;
4126      l_line_tbl(l_number).ordered_quantity   := l_child.ordered_quantity;
4127      l_line_tbl(l_number).order_quantity_uom := l_orig_line_rec.order_quantity_uom;
4128      l_line_tbl(l_number).item_identifier_type := 'INT';
4129      l_line_tbl(l_number).item_type_code := OE_GLOBALS.G_ITEM_SERVICE;
4130      l_Line_tbl(l_number).operation      := OE_GLOBALS.G_OPR_CREATE;
4131      l_line_tbl(l_number).header_id      := l_orig_line_rec.header_id;
4132      l_line_tbl(l_number).inventory_item_id := l_orig_line_rec.inventory_item_id;
4133      l_line_tbl(l_number).service_reference_line_id := l_child.line_id;
4134      --l_line_tbl(l_number).top_model_line_id := l_service_reference_line_id;
4135      --for bug 2545545
4136      l_line_tbl(l_number).context := l_orig_line_rec.context;
4137      l_line_tbl(l_number).attribute1 := l_orig_line_rec.attribute1;
4138      l_line_tbl(l_number).attribute2 := l_orig_line_rec.attribute2;
4139      l_line_tbl(l_number).attribute3 := l_orig_line_rec.attribute3;
4140      l_line_tbl(l_number).attribute4 := l_orig_line_rec.attribute4;
4141      l_line_tbl(l_number).attribute5 := l_orig_line_rec.attribute5;
4142      l_line_tbl(l_number).attribute6 := l_orig_line_rec.attribute6;
4143      l_line_tbl(l_number).attribute7 := l_orig_line_rec.attribute7;
4144      l_line_tbl(l_number).attribute8 := l_orig_line_rec.attribute8;
4145      l_line_tbl(l_number).attribute9 := l_orig_line_rec.attribute9;
4146      l_line_tbl(l_number).attribute10 := l_orig_line_rec.attribute10;
4147      l_line_tbl(l_number).attribute11 := l_orig_line_rec.attribute11;
4148      l_line_tbl(l_number).attribute12 := l_orig_line_rec.attribute12;
4149      l_line_tbl(l_number).attribute13 := l_orig_line_rec.attribute13;
4150      l_line_tbl(l_number).attribute14 := l_orig_line_rec.attribute14;
4151      l_line_tbl(l_number).attribute15 := l_orig_line_rec.attribute15;
4152      --end 2545545
4153      l_header_id   := l_child.header_id;
4154      l_line_number := l_child.line_number;
4155      l_shipment_number := l_child.shipment_number;
4156      l_option_number   := l_child.option_number;
4157      oe_debug_pub.add('l_number         => ' || to_char(l_number),2);
4158      oe_debug_pub.add('l_child.header_id=> ' || to_char(l_child.header_id),2);
4159  --    oe_debug_pub.add('item_type_code   => ' || to_char(l_child.item_type_code),2);
4160      oe_debug_pub.add('l_child.line_id=> ' || to_char(l_child.line_id),2);
4161      oe_debug_pub.add('l_child.shipment_number=> ' || to_char(l_child.shipment_number),2);
4162      oe_debug_pub.add('l_child.option_number=> ' || to_char(l_child.option_number),2);
4163      oe_debug_pub.add('l_child.component_number=> ' || to_char(l_child.component_number),2);
4164      oe_debug_pub.add('l_child.service_txn_reason_code=> ' || l_child.service_txn_reason_code,2);
4165      oe_debug_pub.add('l_orig_line_rec.service_duration => ' || l_orig_line_rec.service_duration,2);
4166      oe_debug_pub.add('l_orig_line_rec.service_period=> ' || l_orig_line_rec.service_period ,2);
4167      oe_debug_pub.add('l_orig_line_rec.service_start_date=> ' || l_orig_line_rec.service_start_date,2);
4168      oe_debug_pub.add('l_orig_line_rec.service_end_date=> ' ||l_orig_line_rec.service_end_date ,2);
4169 
4170 --	l_line_tbl(l_number).line_number := l_child.line_number;
4171 --	l_line_tbl(l_number).shipment_number := l_child.shipment_number;
4172 	l_line_tbl(l_number).line_number := l_orig_line_rec.line_number;  -- For bug 2924241
4173 	l_line_tbl(l_number).shipment_number := l_orig_line_rec.shipment_number;
4174 	l_line_tbl(l_number).option_number := l_child.option_number;
4175 	l_line_tbl(l_number).component_number := l_child.component_number;
4176 
4177      FOR l_srv_number IN srv_number LOOP
4178        oe_debug_pub.add('Inside l_srv_number loop      ',2);
4179        l_line_tbl(l_number).service_number := l_srv_number.service_number + 1;
4180      END LOOP;
4181     END LOOP;
4182 
4183 -- for bug 2372098
4184      IF ( srv_children%ISOPEN ) THEN
4185 	CLOSE srv_children;
4186      END IF;
4187 -- end 2372098
4188 
4189   END IF;
4190 
4191   IF l_number > 0 THEN
4192     oe_debug_pub.add('SRV: Found options and included item lines', 1);
4193 
4194     --  Set control flags.
4195     l_control_rec.controlled_operation := TRUE;
4196     l_control_rec.validate_entity      := TRUE;
4197     l_control_rec.write_to_DB          := TRUE;
4198 
4199     l_control_rec.default_attributes   := TRUE;
4200     l_control_rec.change_attributes    := TRUE;
4201     l_control_rec.clear_dependents     := TRUE;
4202     l_control_rec.process              := FALSE;
4203 
4204     --  Instruct API to retain its caches
4205 
4206     l_control_rec.clear_api_cache      := FALSE;
4207     l_control_rec.clear_api_requests   := FALSE;
4208 
4209     --  Call OE_Order_PVT.Process_order to insert lines
4210     -- Set recursion mode.
4211     --  OE_GLOBALS.G_RECURSION_MODE := 'Y';
4212 
4213     OE_ORDER_PVT.Lines
4214     (P_validation_level          => FND_API.G_VALID_LEVEL_FULL
4215     ,p_control_rec               => l_control_rec
4216     ,p_x_line_tbl                => l_line_tbl
4217     ,p_x_old_line_tbl            => l_old_line_tbl
4218     ,x_return_status             => l_return_status);
4219 
4220     -- Reset recursion mode.
4221     -- OE_GLOBALS.G_RECURSION_MODE := 'N';
4222 
4223     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4224         oe_debug_pub.add('Inside unexpected error  ',2);
4225         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4226     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4227         oe_debug_pub.add('Inside error  ',2);
4228         RAISE FND_API.G_EXC_ERROR;
4229     END IF;
4230 
4231 --comment out for notification project
4232 /*    OE_ORDER_PVT.Process_Requests_And_notify
4233     ( p_process_requests       => FALSE
4234      ,p_notify                 => TRUE
4235      ,x_return_status          => l_return_status
4236      ,p_line_tbl               => l_line_tbl
4237      ,p_old_line_tbl           => l_old_line_tbl);
4238 
4239     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4240         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4241     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4242         RAISE FND_API.G_EXC_ERROR;
4243     END IF;
4244 */
4245     -- Clear Table
4246 	l_line_tbl.DELETE;
4247    END IF;  /* End inserting lines */
4248   OE_DEBUG_PUB.ADD('Exiting INSERT_SERVICE_FOR_OPTIONS',1);
4249 
4250 EXCEPTION
4251 
4252     WHEN FND_API.G_EXC_ERROR THEN
4253         oe_debug_pub.add('Inside exception exe error  ',1);
4254 	   x_return_status := FND_API.G_RET_STS_ERROR;
4255 
4256     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4257         oe_debug_pub.add('Inside exception unexp error  ',1);
4258        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4259 
4260     WHEN OTHERS THEN
4261 
4262 	   x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4263         oe_debug_pub.add('Inside exception other error  ',1);
4264 
4265 	   IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4266 	   THEN
4267 		  OE_MSG_PUB.Add_Exc_Msg
4268 		  (   G_PKG_NAME
4269             ,  'INSERT_SERVICE_FOR_OPTIONS'
4270             );
4271         END IF;
4272 
4273 END INSERT_SERVICE_FOR_OPTIONS;
4274 
4275 
4276 /* lchen added procedure CASCADE_SERVICE_FOR_OPTIONS for bug 1761154 */
4277 
4278 PROCEDURE CASCADE_SERVICE_FOR_OPTIONS
4279 (p_option_line_id  IN NUMBER
4280 ,x_return_status OUT NOCOPY VARCHAR2
4281 
4282 )
4283 
4284 IS
4285 
4286 l_number                      NUMBER := 0;
4287 l_api_name                    CONSTANT VARCHAR(30) := 'CASCADE_SERVICE_FOR_OPTIONS';
4288 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
4289 l_return_status               Varchar2(30);
4290 l_orig_line_rec               OE_Order_PUB.Line_Rec_Type;
4291 --l_reference_line_rec          OE_Order_Pub.Line_Rec_Type;
4292 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
4293 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
4294 --l_line_id                     NUMBER;
4295 l_header_id                   NUMBER;
4296 l_line_number                 NUMBER;
4297 l_order_number                NUMBER;
4298 l_shipment_number             NUMBER;
4299 l_option_number               NUMBER;
4300 l_component_number            NUMBER; -- bug 2447402
4301 l_top_model_line_id           NUMBER;
4302 
4303 
4304    CURSOR srv_line IS
4305    SELECT l.header_id,
4306           l.line_id,
4307           l.service_txn_reason_code,
4308           l.service_txn_comments,
4309           l.service_duration,
4310           l.service_period,
4311           l.service_start_date,
4312 	  l.service_end_date,
4313 	  l.service_coterminate_flag,
4314           l.order_quantity_uom,
4315           l.inventory_item_id
4316    FROM oe_order_lines l
4317    where l.service_reference_line_id=l_top_model_line_id
4318    and l.item_type_code = 'SERVICE'
4319    and l.service_reference_type_code = 'ORDER';
4320 
4321      CURSOR srv_number IS
4322      SELECT max(l.service_number) service_number
4323 	FROM   oe_order_lines l
4324      WHERE  l.header_id = l_header_id
4325      AND    l.line_number   = l_line_number
4326      AND    l.shipment_number = l_shipment_number
4327      AND    nvl(l.option_number,0) = nvl(l_option_number,0)
4328      AND    nvl(l.component_number,0) = nvl(l_component_number,0);    --bug 2447402
4329 BEGIN
4330 
4331   OE_DEBUG_PUB.ADD('Entering CASCADE_SERVICE_FOR_OPTIONS',1);
4332 
4333   IF fnd_profile.value('ONT_CASCADE_SERVICE') = 'N' THEN
4334     /* 3128684 */
4335     oe_debug_pub.add('Do not cascade services', 2);
4336     x_return_status := FND_API.G_RET_STS_SUCCESS;
4337     RETURN;
4338   END IF;
4339   oe_debug_pub.add('Do cascade services', 2);
4340 
4341   -- query the option line
4342   OE_Line_Util.query_row(p_line_id  => p_option_line_id,
4343 					x_line_rec => l_orig_line_rec);
4344 
4345      SELECT /* MOAC_SQL_CHANGE */ h.order_number
4346      INTO   l_order_number
4347      FROM   oe_order_headers_all h, oe_order_lines l
4348      WHERE  h.header_id = l.header_id
4349      AND    h.header_id = l_orig_line_rec.header_id
4350 	AND    rownum = 1;
4351 
4352 
4353  l_top_model_line_id := l_orig_line_rec.top_model_line_id;
4354  oe_debug_pub.add('Top Model Line is' || l_top_model_line_id,2);
4355 
4356 
4357     FOR l_child IN srv_line LOOP
4358      l_number := l_number + 1;
4359      l_line_tbl(l_number) := OE_ORDER_PUB.G_MISS_LINE_REC;
4360      l_line_tbl(l_number).service_reference_type_code := 'ORDER';
4361      l_line_tbl(l_number).service_reference_line_id := l_orig_line_rec.line_id;
4362      l_line_tbl(l_number).service_reference_system_id := l_orig_line_rec.line_id;
4363      l_line_tbl(l_number).service_txn_reason_code := l_orig_line_rec.service_txn_reason_code;
4364      l_line_tbl(l_number).service_txn_comments := l_orig_line_rec.service_txn_comments;
4365      l_line_tbl(l_number).service_duration     := l_child.service_duration;
4366      l_line_tbl(l_number).service_period       := l_child.service_period;
4367      l_line_tbl(l_number).service_start_date   := l_child.service_start_date;
4368      l_line_tbl(l_number).service_end_date     := l_child.service_end_date;
4369      l_line_tbl(l_number).service_coterminate_flag := l_child.service_coterminate_flag;
4370      l_line_tbl(l_number).ordered_quantity   := l_orig_line_rec.ordered_quantity;
4371      l_line_tbl(l_number).order_quantity_uom := l_child.order_quantity_uom;
4372      l_line_tbl(l_number).item_identifier_type := 'INT';
4373      l_line_tbl(l_number).item_type_code := OE_GLOBALS.G_ITEM_SERVICE;
4374      l_Line_tbl(l_number).operation      := OE_GLOBALS.G_OPR_CREATE;
4375      l_line_tbl(l_number).header_id      := l_child.header_id;
4376      l_line_tbl(l_number).inventory_item_id := l_child.inventory_item_id;
4377      --l_line_tbl(l_number).top_model_line_id := l_top_model_line_id;
4378      l_header_id   := l_orig_line_rec.header_id;
4379      l_line_number := l_orig_line_rec.line_number;
4380      l_shipment_number := l_orig_line_rec.shipment_number;
4381      l_option_number   := l_orig_line_rec.option_number;
4382      l_component_number   := l_orig_line_rec.component_number; --bug 2447402
4383 
4384      oe_debug_pub.add('l_number         => ' || to_char(l_number),2);
4385      oe_debug_pub.add('l_orig_line_rec.header_id=> ' || to_char(l_orig_line_rec.header_id),2);
4386  --    oe_debug_pub.add('item_type_code   => ' || to_char(l_orig_line_rec.item_type_code),2);
4387      oe_debug_pub.add('l_orig_line_rec.line_id=> ' || to_char(l_orig_line_rec.line_id),2);
4388      oe_debug_pub.add('l_orig_line_rec.shipment_number=> ' || to_char(l_orig_line_rec.shipment_number),2);
4389      oe_debug_pub.add('l_orig_line_rec.option_number=> ' || to_char(l_orig_line_rec.option_number),2);
4390      oe_debug_pub.add('l_orig_line_rec.service_txn_reason_code=> ' || l_orig_line_rec.service_txn_reason_code,2);
4391      oe_debug_pub.add('l_child.service_duration => ' || l_child.service_duration,2);
4392      oe_debug_pub.add('l_child.service_period=> ' || l_child.service_period ,2);
4393      oe_debug_pub.add('l_child.service_start_date=> ' || l_child.service_start_date,2);
4394      oe_debug_pub.add('l_child.service_end_date=> ' ||l_child.service_end_date ,2);
4395 
4396 	l_line_tbl(l_number).shipment_number := l_orig_line_rec.shipment_number;
4397 	l_line_tbl(l_number).option_number := l_orig_line_rec.option_number;
4398 	l_line_tbl(l_number).line_number := l_orig_line_rec.line_number;
4399 	l_line_tbl(l_number).component_number := l_orig_line_rec.component_number; --bug 2447402
4400 
4401      FOR l_srv_number IN srv_number LOOP
4402        oe_debug_pub.add('Inside l_srv_number loop      ',2);
4403        l_line_tbl(l_number).service_number := l_srv_number.service_number + 1;
4404      END LOOP;
4405     END LOOP;
4406 
4407 
4408   IF l_number > 0 THEN
4409     oe_debug_pub.add('Inside cascade_service_for_options, Found top model service and options lines', 1);
4410 
4411     --  Set control flags.
4412     l_control_rec.controlled_operation := TRUE;
4413     l_control_rec.validate_entity      := TRUE;
4414     l_control_rec.write_to_DB          := TRUE;
4415 
4416     l_control_rec.default_attributes   := TRUE;
4417     l_control_rec.change_attributes    := TRUE;
4418     l_control_rec.clear_dependents     := TRUE;
4419     l_control_rec.process              := FALSE;
4420 
4421     --  Instruct API to retain its caches
4422 
4423     l_control_rec.clear_api_cache      := FALSE;
4424     l_control_rec.clear_api_requests   := FALSE;
4425 
4426     --  Call OE_Order_PVT.Process_order to insert lines
4427     -- Set recursion mode.
4428     --  OE_GLOBALS.G_RECURSION_MODE := 'Y';
4429 
4430     OE_ORDER_PVT.Lines
4431     (P_validation_level          => FND_API.G_VALID_LEVEL_FULL
4432     ,p_control_rec               => l_control_rec
4433     ,p_x_line_tbl                => l_line_tbl
4434     ,p_x_old_line_tbl            => l_old_line_tbl
4435     ,x_return_status             => l_return_status);
4436 
4437     -- Reset recursion mode.
4438     -- OE_GLOBALS.G_RECURSION_MODE := 'N';
4439 
4440     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4441         oe_debug_pub.add('Inside unexpected error  ',2);
4442         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4443     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4444         oe_debug_pub.add('Inside error  ',2);
4445         RAISE FND_API.G_EXC_ERROR;
4446     END IF;
4447 
4448 --comment out for notification project
4449 /*    OE_ORDER_PVT.Process_Requests_And_notify
4450     ( p_process_requests       => FALSE
4451      ,p_notify                 => TRUE
4452      ,x_return_status          => l_return_status
4453      ,p_line_tbl               => l_line_tbl
4454      ,p_old_line_tbl           => l_old_line_tbl);
4455 
4456     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4457         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4458     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4459         RAISE FND_API.G_EXC_ERROR;
4460     END IF;
4461 */
4462     -- Clear Table
4463 	l_line_tbl.DELETE;
4464    END IF;  /* End inserting lines */
4465   OE_DEBUG_PUB.ADD('Exiting CASCADE_SERVICE_FOR_OPTIONS',1);
4466 
4467 EXCEPTION
4468 
4469     WHEN FND_API.G_EXC_ERROR THEN
4470         oe_debug_pub.add('Inside exception exe error  ',1);
4471 	   x_return_status := FND_API.G_RET_STS_ERROR;
4472 
4473     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4474         oe_debug_pub.add('Inside exception unexp error  ',1);
4475        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4476 
4477     WHEN OTHERS THEN
4478 
4479 	   x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4480         oe_debug_pub.add('Inside exception other error  ',1);
4481 
4482 	   IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4483 	   THEN
4484 		  OE_MSG_PUB.Add_Exc_Msg
4485 		  (   G_PKG_NAME
4486             ,  'CASCADE_SERVICE_FOR_OPTIONS'
4487             );
4488          END IF;
4489 
4490 END CASCADE_SERVICE_FOR_OPTIONS;
4491 
4492 
4493 PROCEDURE Apply_Automatic_Attachments
4494 ( p_entity_code			IN VARCHAR2
4495 , p_entity_id				IN NUMBER
4496 , p_is_user_action			IN VARCHAR2
4497 , x_return_status OUT NOCOPY VARCHAR2
4498 
4499 )
4500 IS
4501 l_attachment_count			NUMBER;
4502 l_msg_count				NUMBER;
4503 l_msg_data				VARCHAR2(2000);
4504 BEGIN
4505 
4506 OE_DEBUG_PUB.Add('Enter OE_DELAYED_REQUESTS_UTIL.Apply_Automatic_Attachments', 1);
4507 
4508 	x_return_status := FND_API.G_RET_STS_SUCCESS;
4509 
4510 	OE_Atchmt_Util.Apply_Automatic_Attachments
4511 			( p_entity_code		=> p_entity_code
4512 			, p_entity_id		=> p_entity_id
4513 			, p_is_user_action	=> p_is_user_action
4514 			, x_attachment_count => l_attachment_count
4515 			, x_return_status	  => x_return_status
4516 			, x_msg_count		  => l_msg_count
4517 			, x_msg_data		  => l_msg_data
4518 			);
4519      IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4520           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4521      ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
4522           RAISE FND_API.G_EXC_ERROR;
4523      END IF;
4524 
4525 OE_DEBUG_PUB.Add('Exit OE_DELAYED_REQUESTS_UTIL.Apply_Automatic_Attachments', 1);
4526 
4527 EXCEPTION
4528     WHEN FND_API.G_EXC_ERROR THEN
4529         x_return_status := FND_API.G_RET_STS_ERROR;
4530     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4531         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4532 	WHEN OTHERS THEN
4533         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4534         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4535         THEN
4536             OE_MSG_PUB.Add_Exc_Msg
4537             (   G_PKG_NAME
4538             ,   'Apply_Automatic_Attachments'
4539 		);
4540         END IF;
4541 END Apply_Automatic_Attachments;
4542 
4543 PROCEDURE Copy_Attachments
4544 ( p_entity_code			IN VARCHAR2
4545 , p_from_entity_id			IN NUMBER
4546 , p_to_entity_id			IN NUMBER
4547 , p_manual_attachments_only	IN VARCHAR2
4548 , x_return_status OUT NOCOPY VARCHAR2
4549 
4550 )
4551 IS
4552 BEGIN
4553 
4554 OE_DEBUG_PUB.Add('Enter OE_DELAYED_REQUESTS_UTIL.Copy_Attachments, manual only'||
4555 		p_manual_attachments_only, 1);
4556 
4557 	x_return_status := FND_API.G_RET_STS_SUCCESS;
4558 
4559 	OE_Atchmt_Util.Copy_Attachments
4560 			( p_entity_code		=> p_entity_code
4561 			, p_from_entity_id		=> p_from_entity_id
4562 			, p_to_entity_id		=> p_to_entity_id
4563 			, p_manual_attachments_only	=> NVL(p_manual_attachments_only,'N')
4564 			, x_return_status	  => x_return_status
4565 			);
4566      IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4567           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4568      ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
4569           RAISE FND_API.G_EXC_ERROR;
4570      END IF;
4571 
4572 OE_DEBUG_PUB.Add('Exit OE_DELAYED_REQUESTS_UTIL.Copy_Attachments', 1);
4573 
4574 EXCEPTION
4575     WHEN FND_API.G_EXC_ERROR THEN
4576         x_return_status := FND_API.G_RET_STS_ERROR;
4577     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4578         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4579 	WHEN OTHERS THEN
4580         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4581         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4582         THEN
4583             OE_MSG_PUB.Add_Exc_Msg
4584             (   G_PKG_NAME
4585             ,   'Copy_Attachments'
4586 		);
4587         END IF;
4588 END Copy_Attachments;
4589 /*-------------------------------------------------------------------
4590 Procedure: Schedule_Line
4591 Description: This procedure will be called when the delayed request
4592 		   SCHEDULE_LINE is logged. This delayed request is logged
4593              when new lines are inserted to a SCHEDULE SET. A set being
4594              a user defined ship or arrival set, or a system defined
4595              ATO or SMC PTO model. When multiple lines are inserted
4596              to the same set, this procedure is called once for all the
4597              lines of the set.
4598 -------------------------------------------------------------------*/
4599 Procedure Schedule_Line
4600 ( p_sch_set_tbl     IN  OE_ORDER_PUB.request_tbl_type
4601 , x_return_status OUT NOCOPY VARCHAR2)
4602 
4603 IS
4604 l_ship_set_id        NUMBER := null;
4605 l_arrival_set_id     NUMBER := null;
4606 l_request_rec        OE_Order_PUB.request_rec_type;
4607 l_line_rec           OE_ORDER_PUB.line_rec_type;
4608 l_old_line_rec       OE_ORDER_PUB.line_rec_type;
4609 l_out_line_rec       OE_ORDER_PUB.line_rec_type;
4610 l_atp_tbl            OE_ATP.atp_tbl_type;
4611 l_return_status      VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
4612 l_group_req_rec      OE_GRP_SCH_UTIL.Sch_Group_Rec_Type;
4613 l_group_sch_required BOOLEAN := TRUE;
4614 BEGIN
4615 
4616   oe_debug_pub.add('Entering OE_Delayed_Requests_UTIL.Schedule_Line',1);
4617 
4618   OE_ORDER_SCH_UTIL.OESCH_PERFORM_GRP_SCHEDULING := 'N';
4619 
4620   FOR I in 1..p_sch_set_tbl.count LOOP
4621 
4622       l_request_rec  := p_sch_set_tbl(I);
4623 	 -- Assiging miss rec.
4624 	 l_line_rec     := OE_ORDER_PUB.G_MISS_LINE_REC;
4625 
4626       OE_LINE_UTIL.Lock_Row(p_line_id       => l_request_rec.entity_id,
4627 	                       p_x_line_rec    => l_line_rec,
4628 					   x_return_status => l_return_status);
4629 
4630        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4631           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4632        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4633           RAISE FND_API.G_EXC_ERROR;
4634        END IF;
4635 
4636       l_old_line_rec                      :=  l_line_rec;
4637 
4638       l_old_line_rec.schedule_ship_date   :=  null;
4639       l_old_line_rec.schedule_arrival_date:=  null;
4640 
4641       /* Start Audit Trail */
4642 	 l_line_rec.change_reason := 'SYSTEM';
4643 	 /* End Audit Trail */
4644 
4645       l_line_rec.operation             :=  OE_GLOBALS.G_OPR_UPDATE;
4646 
4647       IF p_sch_set_tbl(I).request_type = OE_GLOBALS.G_SCHEDULE_LINE THEN
4648           l_line_rec.schedule_action_code  :=
4649                              OE_ORDER_SCH_UTIL.OESCH_ACT_SCHEDULE;
4650           l_old_line_rec.ship_set_id           := l_request_rec.param9;
4651           l_old_line_rec.arrival_set_id        := l_request_rec.param10;
4652       ELSE
4653 
4654           l_old_line_rec.request_date          := l_request_rec.date_param1;
4655           l_old_line_rec.schedule_ship_date    := l_request_rec.date_param2;
4656           l_old_line_rec.schedule_arrival_date := l_request_rec.date_param3;
4657           l_old_line_rec.ship_from_org_id      := l_request_rec.param7;
4658           l_old_line_rec.ship_to_org_id        := l_request_rec.param8;
4659           l_old_line_rec.ship_set_id           := l_request_rec.param9;
4660           l_old_line_rec.arrival_set_id        := l_request_rec.param10;
4661       END IF;
4662 
4663       IF (l_line_rec.ato_line_id is not null and
4664           NOT (l_line_rec.ato_line_id = l_line_rec.line_id and
4665           l_line_rec.item_type_code IN (OE_GLOBALS.G_ITEM_STANDARD,
4666                                         OE_GLOBALS.G_ITEM_OPTION))) OR
4667           nvl(l_line_rec.ship_model_complete_flag,'N') = 'Y'
4668       THEN
4669          IF l_request_rec.param3 =
4670                        OE_ORDER_SCH_UTIL.OESCH_ENTITY_ARRIVAL_SET OR
4671             l_request_rec.param3 =
4672                        OE_ORDER_SCH_UTIL.OESCH_ENTITY_SHIP_SET THEN
4673 
4674                 IF (l_line_rec.line_id = l_line_rec.ato_line_id OR
4675                     l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_MODEL)
4676                 THEN
4677                    -- ATO model or SMC Model
4678                    l_group_sch_required := TRUE;
4679                 ELSE
4680                    -- The ato or smc pto line is being inserted into a ship
4681                    -- or arrival set. Check to see if it is the first line
4682                    -- to go into the set. If it is, then we will need to
4683                    -- schedule the whole ATO model.
4684                    BEGIN
4685                      SELECT ship_set_id,arrival_set_id
4686                      INTO l_ship_set_id,l_arrival_set_id
4687                      FROM oe_order_lines_all
4688                      WHERE line_id = l_line_rec.ato_line_id;
4689                    EXCEPTION
4690                      WHEN OTHERS THEN
4691                        l_ship_set_id    := null;
4692                        l_arrival_set_id := null;
4693                    END;
4694 
4695                    IF l_request_rec.param3 =
4696                          OE_ORDER_SCH_UTIL.OESCH_ENTITY_SHIP_SET
4697                         AND l_ship_set_id = to_number(l_request_rec.param1)
4698                    THEN
4699                      l_group_sch_required := FALSE;
4700                    ELSIF l_request_rec.param3 =
4701                      OE_ORDER_SCH_UTIL.OESCH_ENTITY_ARRIVAL_SET
4702                      AND l_arrival_set_id = to_number(l_request_rec.param1)
4703                    THEN
4704                      l_group_sch_required := FALSE;
4705                    ELSE
4706                      l_group_sch_required := TRUE;
4707                    END IF;
4708                 END IF;
4709 
4710          ELSE
4711            -- Line being inserted to an schedule ATO model
4712            l_group_sch_required := FALSE;
4713          END IF;
4714 
4715       ELSE
4716          -- Line is not an ATO model or option
4717          l_group_sch_required := FALSE;
4718       END IF;
4719 
4720       IF l_group_sch_required THEN
4721 
4722          -- If the line being scheduled is a ATO model, or a SMC PTO, we
4723          -- need to call group scheduling API.
4724 
4725          OE_ORDER_SCH_UTIL.Create_Group_Request
4726           (  p_line_rec         => l_line_rec
4727            , p_old_line_rec     => l_old_line_rec
4728            , x_group_req_rec    => l_group_req_rec
4729            , x_return_status    => l_return_status
4730           );
4731 
4732          l_group_req_rec.old_ship_set_number := l_request_rec.param9;
4733          l_group_req_rec.old_arrival_set_number := l_request_rec.param10;
4734 
4735          -- Set the Entity as ATO or SMC and not ship set.
4736 	 IF l_line_rec.ato_line_id is not null AND
4737          NOT (l_line_rec.ato_line_id = l_line_rec.line_id AND
4738 	      l_line_rec.item_type_code IN (OE_GLOBALS.G_ITEM_STANDARD,
4739                                             OE_GLOBALS.G_ITEM_OPTION)) THEN
4740 
4741             l_group_req_rec.entity_type :=
4742                       OE_ORDER_SCH_UTIL.OESCH_ENTITY_ATO_CONFIG;
4743             l_group_req_rec.ship_set_number := l_line_rec.ato_line_id;
4744          ELSE
4745 
4746             l_group_req_rec.entity_type :=
4747                       OE_ORDER_SCH_UTIL.OESCH_ENTITY_SMC;
4748             l_group_req_rec.ship_set_number := l_line_rec.top_model_line_id;
4749          END IF;
4750 
4751          oe_debug_pub.add('****Printing Group Request Attributes****',2);
4752          oe_debug_pub.add('Entity    :' || l_group_req_rec.entity_type,2);
4753          oe_debug_pub.add('Header Id :' || l_group_req_rec.header_id,2);
4754          oe_debug_pub.add('Line Id   :' || l_group_req_rec.line_id,2);
4755          oe_debug_pub.add('Action    :' || l_group_req_rec.action,2);
4756          oe_debug_pub.add('Warehouse :' || l_group_req_rec.ship_from_org_id,2);
4757          oe_debug_pub.add('Ship to   :' || l_group_req_rec.ship_to_org_id,2);
4758          oe_debug_pub.add('Sh Set#   :' || l_group_req_rec.ship_set_number,2);
4759          oe_debug_pub.add('Ar Set#   :' || l_group_req_rec.arrival_set_number,2);
4760          oe_debug_pub.add('Ship Date :' || l_group_req_rec.schedule_ship_date,2);
4761          oe_debug_pub.add('Arr Date  :' || l_group_req_rec.schedule_arrival_date,2);
4762          oe_debug_pub.add('*******************************************',2);
4763 
4764          oe_debug_pub.add('Calling Grp Schedule : ',2);
4765          OE_GRP_SCH_UTIL.Group_Schedule
4766            (p_group_req_rec    => l_group_req_rec
4767            ,x_atp_tbl          => l_atp_tbl
4768            ,x_return_status    => l_return_status);
4769 
4770          oe_debug_pub.add('After Calling Grp Schedule : || l_return_status',2);
4771 
4772          oe_debug_pub.add('Setting G_CASCADING_REQUEST_LOGGED to TRUE',2);
4773 
4774          IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
4775              OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
4776          END IF;
4777 
4778       ELSE
4779 
4780          oe_debug_pub.add('Sch_Line for line : '|| l_line_rec.line_id,2);
4781 
4782          oe_debug_pub.add('Sch_Line for line : '|| l_line_rec.line_id,2);
4783 
4784 	    -- We are doing this to retain the copy of l_line_rec.
4785          l_out_line_rec := l_line_rec;
4786 
4787          OE_ORDER_SCH_UTIL.Schedule_line
4788             ( p_x_line_rec     => l_out_line_rec
4789              , p_old_line_rec  => l_old_line_rec
4790              , p_write_to_db   => FND_API.G_TRUE
4791              , x_atp_tbl       => l_atp_tbl
4792              , x_return_status => l_return_status);
4793 
4794 
4795          oe_debug_pub.add('After Calling Sch_Line : '|| l_return_status,2);
4796 
4797       END IF;
4798 
4799       IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4800 
4801 oe_debug_pub.add('Line Id error out nocopy : ' || l_line_rec.line_id,2);
4802 
4803 
4804          IF l_request_rec.param3 =
4805                        OE_ORDER_SCH_UTIL.OESCH_ENTITY_ARRIVAL_SET OR
4806             l_request_rec.param3 =
4807                        OE_ORDER_SCH_UTIL.OESCH_ENTITY_SHIP_SET THEN
4808 
4809             -- Could not schedule the line on the set date. Let's schedule
4810             -- the whole set to see if we get another date got the whole
4811             -- set.
4812 
4813             IF fnd_profile.value('ONT_AUTO_PUSH_GRP_DATE') = 'Y' THEN
4814 
4815                 oe_debug_pub.add('Auto Push Group Date is Yes',2);
4816 
4817                 -- Added this stmt to fix big 1899651.
4818                 l_line_rec.schedule_action_code  :=
4819                              OE_ORDER_SCH_UTIL.OESCH_ACT_RESCHEDULE;
4820 
4821                 OE_ORDER_SCH_UTIL.Create_Group_Request
4822                  (  p_line_rec         => l_line_rec
4823                   , p_old_line_rec     => l_old_line_rec
4824                   , x_group_req_rec    => l_group_req_rec
4825                   , x_return_status    => l_return_status
4826                  );
4827 
4828                 oe_debug_pub.add('****Printing Group Request Attributes****',2);
4829                 oe_debug_pub.add('Entity    :' ||
4830                                     l_group_req_rec.entity_type,20);
4831                 oe_debug_pub.add('Header Id :' ||
4832                                     l_group_req_rec.header_id,2);
4833                 oe_debug_pub.add('Line Id   :' ||
4834                                     l_group_req_rec.line_id,2);
4835                 oe_debug_pub.add('Action    :' ||
4836                                     l_group_req_rec.action,2);
4837                 oe_debug_pub.add('Warehouse :' ||
4838                                     l_group_req_rec.ship_from_org_id,2);
4839                 oe_debug_pub.add('Ship to   :' ||
4840                                     l_group_req_rec.ship_to_org_id,2);
4841                 oe_debug_pub.add('Sh Set#   :' ||
4842                                     l_group_req_rec.ship_set_number,2);
4843                 oe_debug_pub.add('Ar Set#   :' ||
4844                                     l_group_req_rec.arrival_set_number,2);
4845                 oe_debug_pub.add('Ship Date :' ||
4846                                     l_group_req_rec.schedule_ship_date,2);
4847                 oe_debug_pub.add('Arr Date  :' ||
4848                                     l_group_req_rec.schedule_arrival_date,2);
4849                 oe_debug_pub.add('****************************************',2);
4850 
4851                 OE_ORDER_SCH_UTIL.OESCH_PERFORM_GRP_SCHEDULING := 'Y';
4852 
4853                 oe_debug_pub.add('Calling Grp Schedule : ',2);
4854 
4855                 OE_GRP_SCH_UTIL.Group_Schedule
4856                   (p_group_req_rec    => l_group_req_rec
4857                   ,x_atp_tbl          => l_atp_tbl
4858                   ,x_return_status    => l_return_status);
4859 
4860                 oe_debug_pub.add('After Calling Grp Schedule : ||
4861                                                l_return_status',1);
4862 
4863                 oe_debug_pub.add('Stng G_CASCADING_REQUEST_LOGGED to TRUE',2);
4864 
4865                 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
4866                     OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
4867                 END IF;
4868             END IF; /* If Auto Push Group Date is Yes */
4869 
4870             -- Scheduling Failed. If the line belongs to a Ship Set or Arrival
4871             -- Set, then just clear out the scheduling attributes and return a
4872             -- message that the line schedule failed. We will return a success
4873             -- since we do not want to fail the line insert due to this.
4874 
4875             IF l_return_status = FND_API.G_RET_STS_ERROR THEN
4876 
4877                fnd_message.set_name('ONT','OE_SCH_SET_INS_FAILED');
4878                OE_MSG_PUB.Add;
4879 
4880                IF p_sch_set_tbl(I).request_type = OE_GLOBALS.G_SCHEDULE_LINE
4881                THEN
4882 
4883                  UPDATE OE_ORDER_LINES_ALL
4884                  SET
4885                      (SCHEDULE_SHIP_DATE,
4886                       SCHEDULE_ARRIVAL_DATE,
4887                       SHIP_FROM_ORG_ID,
4888                       SHIP_SET_ID,
4889                       ARRIVAL_SET_ID) =
4890                      (SELECT null,
4891                              null,
4892                              decode(re_source_flag,'Y',ship_from_org_id,null),
4893                              null,
4894                              null
4895                       FROM OE_ORDER_LINES_ALL
4896                       WHERE line_id=l_line_rec.line_id)
4897                  WHERE line_id = l_line_rec.line_id;
4898 
4899                ELSE
4900                  UPDATE OE_ORDER_LINES_ALL
4901                  SET
4902                      SCHEDULE_SHIP_DATE    = l_old_line_rec.schedule_ship_date,
4903                      SCHEDULE_ARRIVAL_DATE = l_old_line_rec.schedule_arrival_date,
4904                      SHIP_FROM_ORG_ID      = l_old_line_rec.ship_from_org_id,
4905                      SHIP_SET_ID           = null,
4906                      ARRIVAL_SET_ID        = null
4907                  WHERE line_id = l_line_rec.line_id;
4908                END IF;
4909 
4910                IF l_line_rec.ship_model_complete_flag = 'Y'
4911                OR (l_line_rec.ato_line_id is not null
4912                AND  NOT (l_line_rec.ato_line_id = l_line_rec.line_id AND
4913                          l_line_rec.item_type_code IN
4914                                                (OE_GLOBALS.G_ITEM_STANDARD,
4915                                                 OE_GLOBALS.G_ITEM_OPTION)))
4916                THEN
4917                  -- Line is part of ato model or smc. Cannot insert a
4918                  -- line without scheduling the same when parent is
4919                  -- scheduled.
4920 
4921                   -- Bug 2185769
4922                   oe_debug_pub.add('Before failing the line',1);
4923                   fnd_message.set_name('ONT','OE_SCH_SET_INS_FAILED');
4924                   OE_MSG_PUB.Add;
4925 
4926                END IF;
4927 
4928                x_return_status := FND_API.G_RET_STS_SUCCESS;
4929             END IF; /* l_return_status = error */
4930 
4931          ELSE
4932 
4933             -- Scheduling Failed. If the line belongs to a ATO Model or SMC
4934             -- PTO, then return an error, since the option cannot be inserted
4935             -- to a scheduled ATO or SMC PTO if it cannot be scheduled on
4936             -- the same date as that of the model.
4937 
4938             fnd_message.set_name('ONT','OE_SCH_SET_INS_FAILED');
4939             OE_MSG_PUB.Add;
4940 
4941             RAISE  FND_API.G_EXC_ERROR;
4942 
4943 
4944          END IF;
4945       END IF; /* If g_ret_status is error */
4946 
4947   END LOOP;
4948   OE_ORDER_SCH_UTIL.OESCH_PERFORM_GRP_SCHEDULING := 'Y';
4949 
4950   oe_debug_pub.add('Exiting OE_Delayed_Requests_UTIL.Schedule_Line');
4951 EXCEPTION
4952 
4953    WHEN FND_API.G_EXC_ERROR THEN
4954             x_return_status := FND_API.G_RET_STS_ERROR;
4955 
4956     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4957 
4958         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4959         THEN
4960             OE_MSG_PUB.Add_Exc_Msg
4961             (   G_PKG_NAME
4962             ,   'Schedule_Line'
4963             );
4964         END IF;
4965 
4966 
4967     WHEN OTHERS THEN
4968 
4969 
4970         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4971         THEN
4972             OE_MSG_PUB.Add_Exc_Msg
4973             (   G_PKG_NAME
4974             ,   'Schedule_Line'
4975             );
4976         END IF;
4977 
4978 END Schedule_Line;
4979 
4980 PROCEDURE Process_Tax
4981 ( p_entity_id_tbl   IN OE_Delayed_Requests_PVT.Entity_Id_Tbl_Type
4982 , x_return_status OUT NOCOPY VARCHAR2)
4983 
4984 IS
4985 l_return_status               Varchar2(30):= FND_API.G_RET_STS_SUCCESS;
4986 l_tax_value                   NUMBER := 0;
4987 l_msg_count		          NUMBER := 0;
4988 l_tax_count		          NUMBER := 0;
4989 l_tax_index		          NUMBER := 0;
4990 l_count		               NUMBER := 0;
4991 l_index		               NUMBER := 0;
4992 l_counter		               NUMBER := 0;
4993 index1		               NUMBER := 0;
4994 l_msg_data		          VARCHAR2(2000);
4995 l_match_flag		          VARCHAR2(1);
4996 l_header_id		          NUMBER;
4997 l_line_id		               NUMBER;
4998 l_ship_to_org_id              NUMBER;
4999 l_unit_selling_price          NUMBER;
5000 l_price_adjustment_id         NUMBER;
5001 new_tax_value		       NUMBER;
5002 l_tax_rec_out_tbl             OM_TAX_UTIL.om_tax_out_tab_type;
5003 l_tax_classification_code     VARCHAR2(50);
5004 l_tax_rate_id                 NUMBER;
5005 l_Line_Adj_rec                OE_Order_PUB.Line_Adj_Rec_Type;
5006 l_l_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
5007 v_start NUMBER;
5008 v_end NUMBER;
5009 l_tax_date                    DATE;
5010 l_inventory_item_id           NUMBER;
5011 l_inventory_org_id            NUMBER;
5012 l_tax_exempt_flag             VARCHAR2(1);
5013 l_tax_exempt_number           VARCHAR2(80);
5014 l_tax_exempt_reason_code      VARCHAR2(30);
5015 l_invoicing_rule_id           NUMBER;
5016 l_fob_point_code              VARCHAR2(30);
5017 l_ordered_quantity            NUMBER;
5018 l_ship_from_org_id            NUMBER;
5019 l_payment_term_id             NUMBER;
5020 l_salesrep_id                 NUMBER;
5021 l_invoice_to_org_id           NUMBER;
5022 l_line_type_id                NUMBER;
5023 l_request_date                DATE;
5024 l_org_id                      NUMBER;
5025 l_conversion_rate             NUMBER;
5026 l_currency_code               VARCHAR2(30) := NULL;
5027 l_global_attribute5           VARCHAR2(240);
5028 l_global_attribute6           VARCHAR2(240);
5029 l_payment_type_code			VARCHAR2(30);
5030 l_commitment_id			NUMBER;
5031 l_line_category_code	      VARCHAR2(30);
5032 l_booked_flag		      VARCHAR2(1);
5033 l_shipped_quantity		NUMBER;
5034 --for bug 2610630 begin
5035 l_orig_sys_doc_ref            VARCHAR2(50);
5036 l_orig_sys_line_ref           VARCHAR2(50);
5037 l_order_src_id                NUMBER;
5038 --for bug 2610630 end
5039 l_call_credit_checking        VARCHAR2(30);
5040 l_request_ind                  NUMBER;
5041 l_orig_sys_shipment_ref       VARCHAR2(50);
5042 l_change_sequence             VARCHAR2(50);
5043 l_source_document_type_id     NUMBER;
5044 l_source_document_id          NUMBER;
5045 l_source_document_line_id     NUMBER;
5046 l_actual_shipment_date        DATE;
5047 l_schedule_ship_date          DATE;
5048 l_pricing_quantity_uom        oe_order_lines.pricing_quantity_uom%TYPE;
5049 l_order_quantity_uom          oe_order_lines.order_quantity_uom%TYPE;
5050 l_user_item_description       oe_order_lines.user_item_description%TYPE;
5051 l_global_attribute_category   VARCHAR2(30);
5052 l_line_rec                    OE_Order_PUB.Line_Rec_Type;
5053 l_header_rec                  OE_Order_PUB.Header_Rec_Type;
5054 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5055 -- bug 4378531
5056 l_hold_result                 VARCHAR2(30);
5057 
5058 BEGIN
5059 
5060   IF l_debug_level > 0 THEN
5061     v_start := DBMS_UTILITY.GET_TIME;
5062     oe_debug_pub.add('Entering Process_Tax ',1);
5063   END IF;
5064     x_return_status  := l_return_status;
5065 
5066     -- Get All Line records
5067     l_index := p_entity_id_tbl.FIRST;
5068     WHILE l_index IS NOT NULL LOOP
5069 	   l_line_id := p_entity_id_tbl(l_index).entity_id;
5070         Begin  --for bug 2173168
5071 	   SELECT /* MOAC_SQL_CHANGE */ l.header_id,
5072 	       l.tax_value,
5073 	       l.ship_to_org_id,
5074 	       l.unit_selling_price,
5075                l.tax_date,
5076                l.inventory_item_id,
5077                l.tax_exempt_flag,
5078                l.tax_exempt_number,
5079                l.tax_exempt_reason_code,
5080                l.invoicing_rule_id,
5081                l.fob_point_code,
5082                l.ordered_quantity,
5083                l.ship_from_org_id,
5084                l.payment_term_id,
5085                l.tax_code,
5086                l.salesrep_id,
5087                l.invoice_to_org_id,
5088                l.line_type_id,
5089                l.request_date,
5090                l.org_id,
5091                h.conversion_rate,
5092                h.transactional_curr_code,
5093                l.global_attribute5,
5094                l.global_attribute6,
5095                l.commitment_id,
5096                l.line_category_code,
5097                l.shipped_quantity,
5098 	       h.payment_type_code,
5099                h.booked_flag,
5100                l.orig_sys_document_ref,
5101                l.orig_sys_line_ref,
5102                l.order_source_id,
5103                l.orig_sys_shipment_ref,
5104                l.change_sequence,
5105                l.source_document_type_id,
5106                l.source_document_id,
5107                l.source_document_line_id,
5108                l.actual_shipment_date,
5109                l.schedule_ship_date,
5110                l.pricing_quantity_uom,
5111                l.order_quantity_uom,
5112                l.user_item_description,
5113                l.global_attribute_category
5114 	   INTO   l_header_id,
5115 	       l_tax_value,
5116 	       l_ship_to_org_id,
5117 	       l_unit_selling_price,
5118                l_tax_date,
5119                l_inventory_item_id,
5120                l_tax_exempt_flag,
5121                l_tax_exempt_number,
5122                l_tax_exempt_reason_code,
5123                l_invoicing_rule_id,
5124                l_fob_point_code,
5125                l_ordered_quantity,
5126                l_ship_from_org_id,
5127                l_payment_term_id,
5128                l_tax_classification_code,
5129                l_salesrep_id,
5130                l_invoice_to_org_id,
5131                l_line_type_id,
5132                l_request_date,
5133                l_org_id,
5134                l_conversion_rate,
5135                l_currency_code,
5136                l_global_attribute5,
5137                l_global_attribute6,
5138                l_commitment_id,
5139                l_line_category_code,
5140                l_shipped_quantity,
5141 	       l_payment_type_code,
5142                l_booked_flag,
5143                l_orig_sys_doc_ref,
5144                l_orig_sys_line_ref,
5145                l_order_src_id,
5146                l_orig_sys_shipment_ref,
5147                l_change_sequence,
5148                l_source_document_type_id,
5149                l_source_document_id,
5150                l_source_document_line_id,
5151                l_actual_shipment_date,
5152                l_schedule_ship_date,
5153                l_pricing_quantity_uom,
5154                l_order_quantity_uom,
5155                l_user_item_description,
5156                l_global_attribute_category
5157 	   FROM OE_ORDER_HEADERS h,
5158 		   OE_ORDER_LINES_all l
5159 	   WHERE l.HEADER_ID = h.HEADER_ID
5160 	   AND l.LINE_ID = l_line_id;
5161   -- incl. 3 parameters l_orig_sys_doc_ref,l_orig_sys_line_ref,l_order_src_id
5162   -- below to fix bug 2610630 and 2508851
5163 
5164         OE_MSG_PUB.set_msg_context
5165         ( p_entity_code                 => 'LINE'
5166          ,p_entity_id                   => l_line_id
5167          ,p_header_id                   => l_header_id
5168          ,p_line_id                     => l_line_id
5169          ,p_orig_sys_document_ref       => l_orig_sys_doc_ref
5170          ,p_orig_sys_document_line_ref  => l_orig_sys_line_ref
5171          ,p_orig_sys_shipment_ref       => l_orig_sys_shipment_ref
5172          ,p_change_sequence             => l_change_sequence
5173          ,p_order_source_id             => l_order_src_id
5174          ,p_source_document_type_id     => l_source_document_type_id
5175          ,p_source_document_id          => l_source_document_id
5176          ,p_source_document_line_id     => l_source_document_line_id
5177         );
5178 
5179 
5180           l_line_rec.line_id                   :=   l_line_id;
5181           l_line_rec.header_id                 :=   l_header_id;
5182           l_line_rec.ship_to_org_id            :=   l_ship_to_org_id;
5183           l_line_rec.invoice_to_org_id         :=   l_invoice_to_org_id;
5184           l_line_rec.tax_date                  :=   l_tax_date;
5185           l_line_rec.ordered_quantity          :=   l_ordered_quantity;
5186           l_line_rec.unit_selling_price        :=   l_unit_selling_price;
5187           l_line_rec.tax_exempt_number         :=   l_tax_exempt_number;
5188           l_line_rec.tax_Exempt_reason_code    :=   l_tax_Exempt_reason_code;
5189           l_line_rec.tax_exempt_flag           :=   l_tax_exempt_flag;
5190           l_line_rec.inventory_item_id         :=   l_inventory_item_id;
5191           l_line_rec.ship_from_org_id          :=   l_ship_from_org_id;
5192           l_line_rec.fob_point_code            :=   l_fob_point_code;
5193           l_line_rec.tax_code                  :=   l_tax_classification_code;
5194           l_line_rec.actual_shipment_date      :=   l_actual_shipment_date;
5195           l_line_rec.schedule_ship_date        :=   l_schedule_ship_date;
5196           l_line_rec.pricing_quantity_uom      :=   l_pricing_quantity_uom;
5197           l_line_rec.order_quantity_uom        :=   l_order_quantity_uom;
5198           l_line_rec.user_item_description     :=   l_user_item_description;
5199           l_line_rec.global_Attribute_category :=   l_global_Attribute_category;
5200           l_line_rec.global_Attribute5         :=   l_global_Attribute5;
5201           l_line_rec.global_attribute6         :=   l_global_attribute6;
5202           l_line_rec.tax_value                 :=   l_tax_value;
5203           l_line_rec.line_type_id              :=   l_line_type_id;
5204           l_line_rec.salesrep_id               :=   l_salesrep_id;
5205           l_line_rec.request_date              :=   l_request_date;
5206           l_line_rec.invoicing_rule_id         :=   l_invoicing_rule_id;
5207           l_line_rec.line_category_code        :=   l_line_category_code;
5208           l_line_rec.payment_term_id           :=   l_payment_term_id;
5209           l_line_rec.COMMITMENT_ID             :=   l_commitment_id; --bug6447586
5210 
5211           l_line_rec.org_id := l_org_id;  -- Added for bug 6661500
5212 
5213           oe_order_cache.load_order_header(l_line_rec.header_id);
5214           l_header_rec := oe_order_cache.g_header_rec;
5215          --l_header_Rec.transactional_curr_code  := l_currency_code ;
5216          --l_header_Rec.org_id                   := l_org_id                  ;
5217          --l_header_Rec.conversion_rate          := l_conversion_rate         ;
5218 
5219 
5220         -- l_inventory_org_id := oe_sys_parameters.value('MASTER_ORGANIZATION_ID',l_org_id);
5221 
5222         l_request_ind := p_entity_id_tbl(l_index).request_ind;
5223         IF l_debug_level > 0 THEN
5224           oe_debug_pub.add( 'value count '|| OE_Delayed_Requests_PVT.G_Delayed_Requests.count);
5225         END IF;
5226 
5227      /* Bug # 3337661: Corrected IF stmt by using OE_GLOBALS.G_TAX_LINE */
5228      -- Front Ported for bug 3397062
5229      if OE_Delayed_Requests_PVT.G_Delayed_Requests.exists(l_request_ind) and OE_Delayed_Requests_PVT.G_Delayed_Requests(l_request_ind).request_type = OE_GLOBALS.G_TAX_LINE then
5230 
5231         l_call_credit_checking := OE_Delayed_Requests_PVT.G_Delayed_Requests(l_request_ind).param1;
5232 
5233       end if;
5234 
5235       IF l_debug_level > 0 THEN
5236        oe_debug_pub.add('OEXUREQB: call_credit_checking is: '||l_call_credit_checking,1);
5237       END IF;
5238 
5239         l_tax_rec_out_tbl.delete; /* initializing the l_tax_rec_out_tbl */
5240 
5241         OM_TAX_UTIL.TAX_LINE(
5242 	 p_line_rec => l_line_rec,
5243          p_header_rec => l_header_rec,
5244          x_tax_value => new_tax_value,
5245          x_tax_out_tbl => l_tax_rec_out_tbl,
5246          x_return_status => l_return_status );
5247 
5248         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5249             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5250         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5251             RAISE FND_API.G_EXC_ERROR;
5252         END IF;
5253 
5254       IF l_debug_level > 0 THEN
5255         oe_debug_pub.add('After Successfully calculating Tax',2);
5256         oe_debug_pub.add('Old tax value :'||to_char(l_tax_value),2);
5257         oe_debug_pub.add('New tax value :'||to_char(new_tax_value),2);
5258         oe_debug_pub.add('return status : ' || l_return_status, 1);
5259         oe_debug_pub.add('Tax classification code : '||l_tax_classification_code,1);
5260       END IF;
5261 
5262 	--   IF NVL(new_tax_value,0) <> NVL(l_tax_value,0) THEN
5263        --changed if condition to fix bug 2198380
5264       -- if l_return_status = 'N' then tax engine was not called.
5265       -- Hence, the following check.
5266 
5267       --  Changed the file condition for bug 3367812
5268     IF l_return_status <> 'N' OR l_tax_classification_code IS NULL  THEN
5269 
5270 
5271        if ( (l_tax_value is not null and new_tax_value is not null and
5272              l_tax_value = new_tax_value) OR
5273             (l_tax_value is null and new_tax_value is null )
5274           ) then
5275          null;
5276        else
5277           IF l_debug_level > 0 THEN
5278             oe_debug_pub.add('Updateing tax value from '||to_char(l_tax_value)|| ' To ' ||to_char(new_tax_value) ,2);
5279           END IF;
5280 		  UPDATE OE_ORDER_LINES_ALL
5281 		  SET TAX_VALUE = new_tax_value
5282 		  WHERE line_id = l_line_id;
5283 
5284              -- lkxu, if tax_value changes, log delayed request for commitment.
5285              -- bug 1768906
5286              IF OE_Commitment_Pvt.Do_Commitment_Sequencing
5287                AND l_commitment_id IS NOT NULL  THEN
5288                  IF l_debug_level > 0 THEN
5289                    oe_debug_pub.add('Logging delayed request for Commitment when tax value changes.', 2);
5290                  END IF;
5291 	         OE_Delayed_Requests_Pvt.Log_Request(
5292 	          p_entity_code		   =>	OE_GLOBALS.G_ENTITY_LINE,
5293 	          p_entity_id		   =>	l_line_id,
5294 	          p_requesting_entity_code =>	OE_GLOBALS.G_ENTITY_LINE,
5295 	          p_requesting_entity_id   =>   l_line_id,
5296 	          p_request_type	   =>	OE_GLOBALS.G_CALCULATE_COMMITMENT,
5297 	          x_return_status	   =>	l_return_status);
5298 
5299               END IF;
5300 
5301             -- Do not log Verify Payment Delayed Requests for Return Lines
5302             --
5303             IF l_line_category_code <> 'RETURN' THEN
5304 	       -- lkxu, added for bug 1581188
5305 		  -- Logging delayed requests for Verify Payment if tax value
5306 		  -- has increased AND Payment Type Code is Credit Card.
5307 	       IF NVL(new_tax_value,0) > NVL(l_tax_value,0)
5308                      AND l_commitment_id IS NULL
5309 		     AND l_payment_type_code = 'CREDIT_CARD' THEN
5310 
5311                   -- if it is a prepaid, do not log request after shipping.
5312                   IF OE_PrePayment_UTIL.is_prepaid_order(l_header_id) = 'N'
5313                      OR (OE_PrePayment_UTIL.is_prepaid_order(l_header_id) = 'Y'
5314                          AND l_booked_flag ='Y'
5315                          AND l_shipped_quantity IS NULL) THEN
5316                     IF l_debug_level > 0 THEN
5317             	     oe_debug_pub.ADD('Logging delayed request for Verify Payment for change in tax value',2);
5318                     END IF;
5319             	     OE_delayed_requests_Pvt.log_request
5320                         (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
5321                          p_entity_id              => l_header_id,
5322                          p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
5323                          p_requesting_entity_id   => l_line_id,
5324                          p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
5325                          x_return_status          => l_return_status);
5326                    END IF;
5327 
5328                -- bug 2238438, credit card collection project.
5329                -- log delayed request for prepaid order even the tax value
5330                -- decreased, as a refund request might be needed.
5331                ELSIF NVL(new_tax_value,0) <  NVL(l_tax_value,0)
5332                    AND l_commitment_id IS NULL
5333                    AND OE_PrePayment_UTIL.is_prepaid_order(l_header_id) = 'Y'
5334                    AND l_booked_flag ='Y'
5335                    AND l_payment_type_code = 'CREDIT_CARD'
5336                    AND l_shipped_quantity IS NULL THEN
5337                 IF l_debug_level > 0 THEN
5338             	  oe_debug_pub.ADD('Logging delayed request for Verify Payment for change in tax value for prepaid order',2);
5339                 END IF;
5340             	OE_delayed_requests_Pvt.log_request
5341                   (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
5342                    p_entity_id              => l_header_id,
5343                    p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
5344                    p_requesting_entity_id   => l_line_id,
5345                    p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
5346                    x_return_status          => l_return_status);
5347             END IF;
5348 
5349             -- Start fix for bug# 4378531
5350             -- end of change for bug 1581188
5351 
5352             -- tbharti, Added for bug 1952363
5353             -- Tax Value changed, log a delayed request for Verify
5354             -- Payment if Payment Type Code is not Credit Card.
5355             -- Fix Bug # 2565813: Added IF condition to check for real change in tax value.
5356                IF nvl(l_payment_type_code, ' ') <> 'CREDIT_CARD' --bug 2679223
5357                   AND nvl(l_call_credit_checking, 'Y') <> 'No_Credit_Checking' THEN
5358 
5359 	          IF NVL(new_tax_value, 0) >  NVL(l_tax_value, 0) THEN
5360 
5361                      oe_debug_pub.ADD('Logging delayed request for Verify Payment for change in tax value',2);
5362 
5363                      OE_delayed_requests_Pvt.log_request
5364                       (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
5365                        p_entity_id              => l_header_id,
5366                        p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
5367                        p_requesting_entity_id   => l_line_id,
5368                        p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
5369                        x_return_status          => l_return_status);
5370 
5371                   ELSIF NVL(new_tax_value,0) <  NVL(l_tax_value,0) THEN
5372 
5373                     oe_debug_pub.add('CHECKING CREDIT CHECK HOLD FOR HEADER/LINE ID : ' || TO_CHAR (l_header_id) || '/' || TO_CHAR (l_line_id) ) ;
5374 
5375                     OE_HOLDS_PUB.Check_Holds
5376                       (  p_api_version    => 1.0
5377                        , p_header_id      => l_header_id
5378                        , p_line_id        => l_line_id
5379                        , p_hold_id        => 1
5380                        , p_entity_code    => 'O'
5381                        , p_entity_id      => l_header_id
5382                        , x_result_out     => l_hold_result
5383                        , x_msg_count      => l_msg_count
5384                        , x_msg_data       => l_msg_data
5385                        , x_return_status  => l_return_status
5386                       );
5387 
5388                     IF ( l_hold_result = FND_API.G_TRUE ) THEN
5389 
5390                        oe_debug_pub.add('Logging delayed request for verify payment for change in tax value and hold exist') ;
5391 
5392             	       OE_delayed_requests_Pvt.log_request
5393                         (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
5394                          p_entity_id              => l_header_id,
5395                          p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
5396                          p_requesting_entity_id   => l_line_id,
5397                          p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
5398                          x_return_status          => l_return_status);
5399                     END IF;
5400                   END IF;
5401                END IF;
5402             -- End fix for bug# 4378531
5403 
5404             END IF; -- Line Category not RETURN
5405 
5406 	   END IF; -- tax value is different
5407 
5408         -- Check for existing TAX records in OE_PRICE_ADJUSTMENTS table for
5409 	   -- the given line record.
5410 
5411         BEGIN
5412 
5413             l_l_line_adj_tbl.delete; /* initializing l_l_line_adj_tbl */
5414 
5415             OE_Line_Adj_UTIL.Lock_Rows
5416 			    ( p_line_id       => l_line_id,
5417 			      x_line_adj_tbl  => l_l_line_adj_tbl,
5418 				 x_return_status => l_return_status);
5419 
5420             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5421                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5422             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5423                 RAISE FND_API.G_EXC_ERROR;
5424             END IF;
5425         EXCEPTION
5426             WHEN NO_DATA_FOUND THEN
5427                    l_l_line_adj_tbl.delete;
5428                    x_return_status  := FND_API.G_RET_STS_SUCCESS;
5429         END;
5430 
5431         IF l_tax_rec_out_tbl.count > 0
5432         THEN
5433           IF l_debug_level > 0 THEN
5434             oe_debug_pub.add('Processing the Tax for the Line '||
5435 					    to_char(l_line_id),2);
5436           END IF;
5437             -- If any TAX records exists, mark them for delete
5438 
5439             l_tax_index := 0;
5440             l_tax_count := 0;
5441 
5442 
5443             FOR I IN 1..l_tax_rec_out_tbl.COUNT LOOP
5444 
5445               IF l_tax_rec_out_tbl(I).trx_line_id = l_line_id
5446               THEN
5447 
5448                    l_tax_rate_id := l_tax_rec_out_tbl(I).tax_rate_id;
5449 
5450              l_match_flag := 'N';
5451              IF l_l_line_adj_tbl.COUNT > 0 THEN
5452                 FOR J IN 1..l_l_line_adj_tbl.COUNT LOOP
5453                   IF l_debug_level > 0 THEN
5454                     oe_debug_pub.add('Price adj Id is '||
5455 		          to_char(l_l_line_adj_tbl(J).price_adjustment_id),2);
5456                   END IF;
5457 				-- Check if there are existing TAX records in adjustments
5458 
5459 	               IF l_l_line_adj_tbl(J).list_line_type_code = 'TAX'  AND
5460 		             l_l_line_adj_tbl(J).parent_adjustment_id IS NULL AND
5461 				   l_l_line_adj_tbl(J).tax_rate_id = l_tax_rate_id AND
5462 				   l_l_line_adj_tbl(J).OPERATION <> OE_GLOBALS.G_OPR_UPDATE
5463 	               THEN
5464 				  -- Set the Match flag
5465                       l_match_flag := 'Y';
5466                --Added for bug#1947306.Mark the record to avoid it from getting deleted.
5467                              l_l_line_adj_tbl(J).OPERATION :=OE_GLOBALS.G_OPR_UPDATE;
5468 
5469 
5470 				  IF NOT OE_GLOBALS.Equal(
5471 				     l_tax_rec_out_tbl(I).tax_amount,
5472 				     l_l_line_adj_tbl(J).adjusted_amount) OR
5473 				     NOT OE_GLOBALS.Equal(l_tax_rec_out_tbl(I).tax_rate,
5474 					l_l_line_adj_tbl(J).operand) THEN
5475                        IF l_debug_level > 0 THEN
5476                          oe_debug_pub.add('Updating the Adj record '||
5477 					   to_char(l_l_line_adj_tbl(J).price_adjustment_id),2);
5478                        END IF;
5479 				      UPDATE OE_PRICE_ADJUSTMENTS
5480 				      SET ADJUSTED_AMOUNT =
5481 						    l_tax_rec_out_tbl(I).tax_amount,
5482                                OPERAND = l_tax_rec_out_tbl(I).tax_rate,
5483                                tax_Rate_id = l_tax_rec_out_tbl(I).tax_rate_id,
5484 						 LAST_UPDATE_DATE  = sysdate,
5485 					      LAST_UPDATED_BY   = FND_GLOBAL.USER_ID,
5486 					      LAST_UPDATE_LOGIN = FND_GLOBAL.LOGIN_ID
5487 
5488                           WHERE price_adjustment_id =
5489 						    l_l_line_adj_tbl(J).price_adjustment_id;
5490 
5491                           l_l_line_adj_tbl(J).OPERATION :=
5492 										  OE_GLOBALS.G_OPR_UPDATE;
5493                           l_match_flag := 'Y';
5494 				  END IF;
5495                                EXIT;       -- If match found then exit from loop .added for bug#1947306
5496 				END IF;
5497                  END LOOP;
5498               END IF;
5499 		    IF l_match_flag = 'N' THEN
5500 
5501 			   select OE_PRICE_ADJUSTMENTS_S.nextval
5502 			   INTO l_price_adjustment_id
5503 			   FROM DUAL;
5504 
5505                   l_Line_adj_rec.price_adjustment_id := l_price_adjustment_id;
5506                   l_Line_adj_rec.header_id := l_header_id;
5507                   l_Line_adj_rec.last_update_date := SYSDATE;
5508                   l_Line_adj_rec.last_updated_by := FND_GLOBAL.USER_ID;
5509                   l_Line_adj_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
5510                   l_Line_adj_rec.creation_date := SYSDATE;
5511                   l_Line_adj_rec.created_by := FND_GLOBAL.USER_ID;
5512                   l_Line_adj_rec.line_id := l_line_id;
5513                   --l_Line_adj_rec.tax_code := l_tax_rate_code;
5514                   l_Line_adj_rec.tax_rate_id := l_tax_rec_out_tbl(I).tax_rate_id;
5515                   IF l_debug_level > 0 THEN
5516                     oe_debug_pub.add('Inserting the Adj record '||
5517 					   to_char(l_line_adj_rec.price_adjustment_id),2);
5518                   END IF;
5519                   l_Line_Adj_rec.operand := l_tax_rec_out_tbl(I).tax_rate;
5520                   l_Line_Adj_rec.adjusted_amount :=
5521 								l_tax_rec_out_tbl(I).tax_amount;
5522                   l_Line_Adj_rec.automatic_flag := 'N';
5523                   l_Line_Adj_rec.list_line_type_code := 'TAX';
5524                   l_Line_Adj_rec.arithmetic_operator := 'AMT';
5525                   l_Line_Adj_rec.operation := OE_GLOBALS.g_opr_create;
5526                   OE_LINE_ADJ_UTIL.INSERT_ROW(p_Line_Adj_rec =>
5527 										  l_line_adj_rec);
5528 		    END IF;
5529 
5530              END IF; -- if l_tax_rec_out_tbl(i).trx_line_id
5531                      -- = l_line_id
5532 
5533             END LOOP; -- For Tax_Rec_Out_Tbl
5534 
5535         END IF; -- l_tax_rec_out_tbl.count > 0
5536 
5537         -- Delete the old Tax Records from oe_price_adjustments if no match
5538 	   -- is found.
5539 
5540 --	   IF l_match_flag = 'N' THEN   --  removed for bug# 1947306
5541           IF l_l_line_adj_tbl.COUNT > 0 THEN
5542             FOR J IN 1..l_l_line_adj_tbl.COUNT LOOP
5543 
5544 	           IF l_l_line_adj_tbl(J).list_line_type_code = 'TAX'  AND
5545 		         l_l_line_adj_tbl(J).parent_adjustment_id IS NULL AND
5546 			    (l_l_line_adj_tbl(J).operation IS NULL
5547 			  	OR l_l_line_adj_tbl(J).operation = FND_API.G_MISS_CHAR)
5548 	           THEN
5549                      IF l_debug_level > 0 THEN
5550                        oe_debug_pub.add('Deleting adj Id '||
5551 		                 to_char(l_l_line_adj_tbl(J).price_adjustment_id),2);
5552                      END IF;
5553 				DELETE FROM OE_PRICE_ADJUSTMENTS
5554 				WHERE PRICE_ADJUSTMENT_ID =
5555 					l_l_line_adj_tbl(J).price_adjustment_id;
5556                 END IF;
5557 
5558             END LOOP;
5559 	     END IF;
5560 --	   END IF; --  removed for bug# 1947306
5561 
5562      END IF; -- if l_return_status <> 'N'
5563 
5564         l_tax_rec_out_tbl.delete;
5565         l_l_line_adj_tbl.delete;
5566    exception --bug 2173168
5567     when no_data_found then
5568       IF l_debug_level > 0 THEN
5569         oe_debug_pub.add('In No data found for line id:'||to_char(l_line_id),2);
5570       END IF;
5571     x_return_status := FND_API.G_RET_STS_SUCCESS;
5572    end ; -- bug 2173168
5573     l_index := p_entity_id_tbl.NEXT(l_index);
5574 
5575    END LOOP; -- l_index IS NOT NULL LOOP
5576 
5577     x_return_status := l_return_status;
5578     IF l_debug_level > 0 THEN
5579       v_end := DBMS_UTILITY.GET_TIME;
5580       oe_debug_pub.add('Time Of execution for Process_Tax '||
5581         to_char((v_end-v_start)/100),1);
5582     END IF;
5583     l_tax_rec_out_tbl.delete;
5584     l_l_line_adj_tbl.delete;
5585 
5586     OE_MSG_PUB.reset_msg_context('LINE');
5587 
5588   IF l_debug_level > 0 THEN
5589     oe_debug_pub.add('Exiting Process_Tax ',1);
5590   END IF;
5591 EXCEPTION
5592     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5593           l_tax_rec_out_tbl.delete;
5594           l_l_line_adj_tbl.delete;
5595 	  x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5596 
5597     WHEN FND_API.G_EXC_ERROR THEN
5598           l_tax_rec_out_tbl.delete;
5599           l_l_line_adj_tbl.delete;
5600 	  x_return_status := FND_API.G_RET_STS_ERROR;
5601 
5602     WHEN NO_DATA_FOUND THEN
5603           l_tax_rec_out_tbl.delete;
5604           l_l_line_adj_tbl.delete;
5605          IF l_debug_level > 0 THEN
5606 	  oe_debug_pub.add('Tax_Order: In No DATA Found',2);
5607          END IF;
5608        x_return_status  := FND_API.G_RET_STS_SUCCESS;
5609 
5610     WHEN OTHERS THEN
5611 
5612     	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5613 	THEN
5614     	    OE_MSG_PUB.Add_Exc_Msg
5615     	    (	G_PKG_NAME  	    ,
5616     	        'Tax Header'
5617 	    );
5618     	END IF;
5619 	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5620         l_tax_rec_out_tbl.delete;
5621         l_l_line_adj_tbl.delete;
5622 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5623 
5624 END Process_Tax;
5625 
5626 --Added by Mushenoy for the  auto Internal Requisition Creation (ikon) Aug 22 2001
5627 PROCEDURE auto_create_internal_req
5628 (p_ord_header_id  IN NUMBER
5629 ,x_return_status OUT NOCOPY VARCHAR2)
5630 
5631 IS
5632 /*
5633 **  PROGRAM LOGIC
5634 **--Query Order Header
5635 **--Query Order Line
5636 **--Derive Values not available on the Internal Sales Order
5637 **--Pass the Internal Sales Order Header values to the internal req header record
5638 **--Pass the Internal Sales Order Line values to the internal req Line table
5639 **--Call the Purchasing API and pass the internal req header record and line tables to Create the Internal Req
5640 **--Check return status of the Purchasing API
5641 **--Update the Internal Sales Order with the Req header id, Req line Ids, Req number and line numbers.
5642 **--Check for return status
5643 **--Handle Exceptions
5644  */
5645 l_int_req_Ret_sts varchar2(1);
5646 l_req_header_rec PO_CREATE_REQUISITION_SV.Header_rec_Type;
5647 l_req_line_tbl PO_CREATE_REQUISITION_SV.Line_Tbl_Type;
5648 l_created_by number;
5649 l_org_id  number;
5650 l_preparer_id number;
5651 l_destination_org_id number;
5652 l_deliver_to_locn_id number;
5653 l_msg_count      number;
5654 l_msg_data       varchar2(2000);
5655 k number := 0;
5656 j number := 0;
5657 
5658 Cursor ord_hdr_cur (p_header_id in number) is
5659 SELECT  created_by
5660        ,org_id
5661 FROM    OE_ORDER_HEADERS
5662 WHERE   header_id = p_header_id;
5663 
5664 Cursor ord_line_cur (p_header_id in number) is
5665 SELECT  line_id
5666         ,order_quantity_uom
5667         ,ordered_quantity
5668         ,sold_to_org_id
5669         ,inventory_item_id
5670         ,schedule_ship_date
5671         ,org_id
5672         ,ship_from_org_id
5673         ,subinventory
5674         ,source_document_id
5675         ,source_document_line_id
5676         ,item_type_code
5677 FROM    OE_ORDER_LINES
5678 WHERE   header_id = p_header_id;
5679 
5680 CURSOR employee_id_cur(p_user_id in number) IS
5681 SELECT employee_id
5682 FROM fnd_user
5683 WHERE user_id = p_user_id;
5684 
5685 CURSOR dest_org_locn_cur (p_cust_id in number) is
5686 SELECT b.location_id,
5687        b.organization_id
5688 FROM hz_party_sites_V a
5689     ,PO_LOCATION_ASSOCIATIONS b
5690 WHERE a.party_site_use_id =  b.SITE_USE_ID
5691 and b.customer_id = p_cust_id
5692 and primary_per_type = 'Y'
5693 and site_use_type = 'SHIP_TO';
5694 
5695 BEGIN
5696 
5697 oe_debug_pub.add(' Entering procedure auto_create_internal_req ',2);
5698 x_return_status := FND_API.G_RET_STS_SUCCESS;
5699 --Query Order Header
5700 OPEN ord_hdr_cur(p_ord_header_id);
5701 FETCH ord_hdr_cur into l_created_by,l_org_id;
5702 CLOSE ord_hdr_cur;
5703 oe_debug_pub.add('auto_create_internal_req after hdr query ',2);
5704 --Derive Values not available on the Internal Sales Order
5705    --Derive the Preparer_id
5706     BEGIN
5707         OPEN employee_id_cur(l_created_by);
5708         FETCH employee_id_cur into l_preparer_id;
5709         CLOSE employee_id_cur;
5710         EXCEPTION
5711         WHEN NO_DATA_FOUND THEN
5712       	 --This is a required field however PO will handle the error if these Fields are null
5713         l_preparer_id := null;
5714         WHEN OTHERS THEN
5715         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5716         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5717     END;
5718 
5719 --Pass the Internal Sales Order Header values to the internal req header record
5720     l_req_header_rec.preparer_id := l_preparer_id;
5721     l_req_header_rec.summary_flag := 'N';
5722     l_req_header_rec.enabled_flag := 'Y';
5723     l_req_header_rec.authorization_status := 'APPROVED';
5724     l_req_header_rec.type_lookup_code   := 'INTERNAL';
5725     l_req_header_rec.transferred_to_oe_flag := 'Y';
5726     l_req_header_rec.org_id      := l_org_id;
5727 
5728 --Pass the Internal Sales Order Line values to the internal req Line table
5729        --Here Loop for each Order Line
5730      FOR Cur_Ord_line in ord_line_cur(p_ord_header_id)
5731      LOOP
5732 	j := j+1;
5733      	IF  cur_ord_line.item_type_code <> OE_GLOBALS.G_ITEM_STANDARD THEN
5734      	fnd_message.set_name('ONT','ONT_ISO_ITEM_TYPE_NOT_STD');
5735         OE_MSG_PUB.Add;
5736         x_return_status := FND_API.G_RET_STS_ERROR;
5737         RAISE FND_API.G_EXC_ERROR;
5738      	END IF;
5739     	--get the destination organization id and deliver to location id for this order line
5740         BEGIN
5741         OPEN dest_org_locn_cur(cur_Ord_line.sold_to_org_id);
5742         FETCH dest_org_locn_cur INTO l_deliver_to_locn_id,l_destination_org_id;
5743         CLOSE dest_org_locn_cur;
5744 
5745         EXCEPTION
5746 	WHEN NO_DATA_FOUND THEN
5747 	--This is a required field however PO will handle the error if these Fields are null
5748         l_destination_org_id := null;
5749         l_deliver_to_locn_id := null;
5750         END;
5751 
5752         l_req_line_tbl(j).line_num                 := j;
5753         l_req_line_tbl(j).source_doc_line_reference:= Cur_Ord_line.line_id;
5754 	l_req_line_tbl(j).uom_code  := Cur_Ord_line.order_quantity_uom;
5755   	l_req_line_tbl(j).quantity               := Cur_Ord_line.ordered_quantity;
5756   	l_req_line_tbl(j).deliver_to_location_id := l_deliver_to_locn_id;
5757         l_req_line_tbl(j).destination_type_code       := 'INVENTORY';
5758 	l_req_line_tbl(j).destination_organization_id := l_destination_org_id;
5759         l_req_line_tbl(j).destination_subinventory    := Null;
5760   	l_req_line_tbl(j).to_person_id           := l_preparer_id;
5761    	l_req_line_tbl(j).source_type_code       := 'INVENTORY';
5762    	l_req_line_tbl(j).item_id                := Cur_Ord_line.inventory_item_id;
5763    	l_req_line_tbl(j).need_by_date           := Cur_Ord_line.schedule_ship_date;
5764 	l_req_line_tbl(j).source_organization_id := Cur_Ord_line.ship_from_org_id;
5765 	l_req_line_tbl(j).source_subinventory    := Cur_Ord_line.subinventory;
5766    	l_req_line_tbl(j).org_id                 := Cur_Ord_line.org_id;
5767      END LOOP;
5768 	oe_debug_pub.add(' auto_create_internal_req before PO API call ',2);
5769 
5770 --Call the PO API and pass the internal req header record and line tables to Create the Internal Req
5771 	BEGIN /* Call to the Purchasing API*/
5772 
5773 	PO_CREATE_REQUISITION_SV.process_requisition(px_header_rec   => l_req_header_rec
5774         	                                    ,px_line_table   => l_req_line_tbl
5775                 	                            ,x_return_status => l_int_req_Ret_sts
5776                         	                    ,x_msg_count     => l_msg_count
5777                                 	            ,x_msg_data      => l_msg_data );
5778 --Check return status of the Purchasing API
5779         IF l_int_req_Ret_sts = FND_API.G_RET_STS_UNEXP_ERROR THEN
5780         oe_debug_pub.add(' PO API call returned unexpected error '||l_msg_data,2);
5781  	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5782 
5783         ELSIF l_int_req_Ret_sts = FND_API.G_RET_STS_ERROR THEN
5784         oe_debug_pub.add(' PO API call returned error '||l_msg_data,2);
5785         RAISE FND_API.G_EXC_ERROR;
5786 	END IF;
5787 
5788    	END;/* Call to the Purchasing API*/
5789 
5790 --if it returns success Update the Internal Sales Order with the Req header id and Req line Ids
5791 	IF l_int_req_ret_sts = FND_API.G_RET_STS_SUCCESS THEN
5792 
5793 --Update the header with the requisition header id
5794         Update OE_Order_Headers
5795         set source_document_Id = l_req_header_rec.requisition_header_id
5796             ,orig_sys_document_ref = l_req_header_rec.segment1
5797             ,source_document_type_id = OE_GLOBALS.G_ORDER_SOURCE_INTERNAL -- i.e 10  for internal
5798             ,order_source_id         = OE_GLOBALS.G_ORDER_SOURCE_INTERNAL --i.e 10 for internal
5799         Where header_id = p_ord_header_id;
5800         oe_debug_pub.add('auto_create_internal_req after hdr update ',2);
5801 -- Update  the lines with the requisition header and requisition line ids, requisition number and line number
5802 
5803        FOR k in 1..l_req_line_tbl.count
5804        LOOP
5805          IF (l_req_line_tbl(k).requisition_line_id is not null) then
5806                 BEGIN
5807                 Update Oe_Order_lines
5808                 Set    source_document_id = l_req_header_rec.requisition_header_id
5809                        ,source_document_line_id = l_req_line_tbl(k).requisition_line_id
5810                        ,source_document_type_id = OE_GLOBALS.G_ORDER_SOURCE_INTERNAL -- i.e 10  for internal
5811                        ,orig_sys_document_ref=  l_req_header_rec.segment1
5812                        ,orig_sys_line_ref = l_req_line_tbl(k).line_num
5813                 where oe_order_lines.line_id = l_req_line_tbl(k).source_doc_line_reference;
5814                 END;
5815          END IF;
5816        END LOOP;
5817        oe_debug_pub.add('auto_create_internal_req after line update ',2);
5818        END IF;
5819 --Handle Exceptions
5820 EXCEPTION
5821 
5822 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5823 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5824 oe_debug_pub.add('auto_create_internal_req: In Unexpected error',2);
5825 
5826 WHEN FND_API.G_EXC_ERROR THEN
5827 x_return_status := FND_API.G_RET_STS_ERROR;
5828 oe_debug_pub.add('auto_create_internal_req: In execution error',2);
5829 
5830 --WHEN NO_DATA_FOUND THEN
5831 --x_return_status  := FND_API.G_RET_STS_SUCCESS;
5832 --oe_debug_pub.add('auto_create_internal_req: In No DATA Found',2);
5833 
5834 WHEN OTHERS THEN
5835 oe_debug_pub.add('auto_create_internal_req: In Other error',2);
5836 	IF OE_MSG_PUB.Check_Msg_Level (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5837         THEN
5838     	OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'auto_create_internal_req');
5839     	END IF;
5840 	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5841 
5842 END auto_create_internal_req;
5843 
5844 -------------------------------------------------------------------
5845 -- Procedure: REVERSE_LIMITS
5846 -- Increments promotional limit balance in response to a cancellation
5847 -- or return against the order or line.
5848 -- Introduced for BUG 2013611
5849 -------------------------------------------------------------------
5850 
5851 Procedure Reverse_Limits (p_action_code             IN  VARCHAR2,
5852                           p_cons_price_request_code IN  VARCHAR2,
5853                           p_orig_ordered_qty        IN  NUMBER,
5854                           p_amended_qty             IN  NUMBER,
5855                           p_ret_price_request_code  IN  VARCHAR2,
5856                           p_returned_qty            IN  NUMBER,
5857                           p_line_id                 IN  NUMBER,
5858 x_return_status OUT NOCOPY VARCHAR2)
5859 
5860 IS
5861      l_return_status            VARCHAR2(30);
5862      l_return_message           VARCHAR2(2000);
5863      l_orig_ordered_qty         NUMBER;
5864 
5865      --bug#7491829
5866      l_parent_line_id           NUMBER;
5867      l_header_id                NUMBER;
5868      --bug#7491829
5869 
5870      l_cons_price_request_code  OE_ORDER_LINES_ALL.price_request_code%TYPE;
5871      l_ret_price_request_code  OE_ORDER_LINES_ALL.price_request_code%TYPE;
5872 
5873      CURSOR REFERENCED_LINE is
5874      SELECT return.price_request_code,
5875             referenced.pricing_quantity,
5876             referenced.price_request_code
5877      FROM   OE_ORDER_LINES_ALL return , OE_ORDER_LINES_ALL referenced
5878      WHERE  return.line_id = p_line_id
5879             and referenced.line_id = return.reference_line_id;
5880 
5881      --bug #7491829
5882      CURSOR SPLIT_LINE IS
5883      SELECT parent.header_id,
5884             parent.pricing_quantity,
5885             parent.line_id
5886      FROM   OE_ORDER_LINES_ALL child, OE_ORDER_LINES_ALL parent
5887      WHERE  child.line_id = p_line_id
5888         and parent.line_id = child.split_from_line_id;
5889      --bug #7491829
5890 
5891 BEGIN
5892 
5893     OE_Debug_PUB.Add('Entering OE_Delayed_Requests_Util.Reverse_Limits', 1);
5894     OE_Debug_PUB.Add('BOTTOM LEVEL before QP call', 1);
5895     x_return_status := FND_API.G_RET_STS_SUCCESS;
5896 
5897     -- BUG 2670775 Reverse Limits Begin
5898     -- If Limits processing is not installed, no need to proceed further
5899     IF NVL(FND_PROFILE.VALUE('QP_LIMITS_INSTALLED'),'N') = 'N' THEN
5900        oe_debug_pub.add('QP LIMITS NOT installed so no call to QP_UTIL_PUB.Reverse_Limits',1);
5901        RETURN;
5902     END IF;
5903     -- BUG 2670775 Reverse Limits End
5904 
5905     l_cons_price_request_code := p_cons_price_request_code;
5906     l_orig_ordered_qty := p_orig_ordered_qty;
5907 
5908     IF p_action_code = 'RETURN' THEN
5909        -- Retrieve price_request_code for the current return line and the one it references
5910        OPEN REFERENCED_LINE;
5911        FETCH  REFERENCED_LINE INTO
5912               l_ret_price_request_code,l_orig_ordered_qty, l_cons_price_request_code;
5913        CLOSE REFERENCED_LINE;
5914     END IF;
5915 
5916    --bug #7491829
5917     IF p_action_code = 'SPLIT_NEW' THEN
5918        -- Retrieve price_request_code for the current child split line and its parent
5919        oe_debug_pub.add('Action code : ' || p_action_code);
5920        OPEN SPLIT_LINE;
5921        FETCH SPLIT_LINE INTO
5922              l_header_id, l_orig_ordered_qty, l_parent_line_id;
5923        CLOSE SPLIT_LINE;
5924        oe_Debug_pub.add('l_header_id : ' || l_header_id);
5925        oe_Debug_pub.add('l_orig_ordered_qty : ' || l_orig_ordered_qty);
5926        oe_Debug_pub.add('l_parent_line_id : ' || l_parent_line_id);
5927 
5928        l_ret_price_request_code := 'ONT-' || l_header_id || '-' || p_line_id;
5929        l_cons_price_request_code := 'ONT-' || l_header_id || '-' || l_parent_line_id;
5930        oe_Debug_pub.add('l_ret_price_request_code : ' || l_ret_price_request_code);
5931        oe_Debug_pub.add('l_cons_price_request_code : ' || l_cons_price_request_code);
5932     END IF;
5933     --bug #7491829
5934 
5935     IF p_action_code = 'RETURN' and l_ret_price_request_code is NULL THEN
5936        OE_Debug_PUB.Add('NO CALL made to QP_UTIL_PUB.Reverse_Limits ', 1);
5937        OE_DEBUG_PUB.Add('return price_request_code is null so block limits call', 1);
5938        RETURN;
5939     END IF;
5940 
5941     --bug#7491829
5942     IF p_action_code = 'SPLIT_NEW' and l_ret_price_request_code is NULL THEN
5943        OE_Debug_PUB.Add('NO CALL made to QP_UTIL_PUB.Reverse_Limits ', 1);
5944        OE_DEBUG_PUB.Add('split line price_request_code is null so block limits call', 1);
5945     END IF;
5946     --bug#7491829
5947 
5948     IF l_cons_price_request_code is NULL THEN
5949        OE_Debug_PUB.Add('NO CALL made to QP_UTIL_PUB.Reverse_Limits ', 1);
5950        OE_DEBUG_PUB.Add('consuming price_request_code is null so no limit for reversal', 1);
5951        RETURN;
5952     END IF;
5953 
5954     OE_Debug_PUB.Add('Call to QP_UTIL_PUB.Reverse_Limits: action_code is  '||p_action_code, 1);
5955     OE_Debug_PUB.Add('Call to QP_UTIL_PUB.Reverse_Limits: price_request_code is '||l_cons_price_request_code, 1);
5956     OE_Debug_PUB.Add('Call to QP_UTIL_PUB.Reverse_Limits: orig_ordered_qty is '||l_orig_ordered_qty, 1);
5957     OE_Debug_PUB.Add('Call to QP_UTIL_PUB.Reverse_Limits: return request code '||l_ret_price_request_code, 1);
5958     OE_Debug_PUB.Add('Call to QP_UTIL_PUB.Reverse_Limits: return qty          '||p_returned_qty, 1);
5959 
5960     QP_UTIL_PUB.Reverse_Limits (p_action_code                => p_action_code,
5961                                 p_cons_price_request_code    => l_cons_price_request_code,
5962                                 p_orig_ordered_qty           => l_orig_ordered_qty,
5963                                 p_amended_qty                => p_amended_qty,
5964                                 p_ret_price_request_code     => l_ret_price_request_code,
5965                                 p_returned_qty               => p_returned_qty,
5966                                 x_return_status              => l_return_status,
5967                                 x_return_message             => l_return_message
5968                                );
5969 
5970 
5971     OE_Debug_PUB.Add('QP_UTIL_PUB.Reverse_Limits returns status of '|| l_return_status, 1);
5972     OE_Debug_PUB.Add('QP_UTIL_PUB.Reverse_Limits returns message of '|| l_return_message   , 1);
5973     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5974       OE_Debug_PUB.Add('Error returned by QP_UTIL_PUB.Reverse_Limits',1);
5975         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5976           RAISE FND_API.G_EXC_ERROR;
5977  	ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5978  	  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5979  	END IF;
5980     END IF;
5981 
5982    --bug 7491829
5983     IF p_action_code = 'SPLIT_NEW' THEN
5984        update oe_order_lines_All
5985        set price_request_code = l_ret_price_request_code
5986        where line_id = p_line_id;
5987     END IF;
5988     --bug 7491829
5989 
5990     OE_Debug_PUB.Add('Exiting OE_Delayed_Requests_Util.Reverse_Limits with status of '|| x_return_status, 1);
5991 
5992 EXCEPTION
5993     WHEN FND_API.G_EXC_ERROR THEN
5994 
5995         x_return_status := FND_API.G_RET_STS_ERROR;
5996 
5997     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5998 
5999         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6000 
6001     WHEN OTHERS THEN
6002 
6003         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6004         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6005         THEN
6006             OE_MSG_PUB.Add_Exc_Msg
6007             (   G_PKG_NAME
6008             ,   'Reverse_Limits'
6009             );
6010         END IF;
6011 
6012 END Reverse_Limits;
6013 
6014 Procedure Process_XML_Delayed_Request (p_request_ind      IN NUMBER,
6015                                        x_return_status    OUT NOCOPY VARCHAR2)
6016 
6017 IS
6018 
6019 l_request_rec            OE_ORDER_PUB.REQUEST_REC_TYPE;
6020 l_header_id  		 NUMBER;
6021 l_order_source_id        NUMBER;
6022 l_orig_sys_document_ref  VARCHAR2(50);
6023 l_sold_to_org_id         NUMBER;
6024 l_change_sequence        VARCHAR2(50);
6025 l_org_id                 NUMBER;
6026 l_acknowledgment_type    VARCHAR2(30);
6027 l_flow_status_code       VARCHAR2(30);
6028 l_party_id               NUMBER;
6029 l_party_site_id          NUMBER;
6030 l_order_number           NUMBER;
6031 l_customer_id            NUMBER;
6032 l_return_status		 VARCHAR2(1);
6033 l_line_found             VARCHAR2(1) := 'N';
6034 l_line_ids               VARCHAR2(2000);
6035 l_count                  NUMBER;
6036 l_count_old              NUMBER;
6037 l_itemkey                NUMBER;
6038 l_bulk_line_rec          OE_WSH_BULK_GRP.LINE_REC_TYPE;
6039 i                        PLS_INTEGER := 1;
6040 ctr                      NUMBER;
6041 l_reciever_code          VARCHAR2(1);
6042 l_line_id_tbl            Line_ID_List;
6043 Raise_Event_XML          BOOLEAN := FALSE;
6044 
6045 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6046 
6047 Begin
6048 
6049 
6050 l_request_rec := OE_Delayed_Requests_PVT.G_Delayed_Requests(p_request_ind);
6051 l_header_id  		 := l_request_rec.entity_id;
6052 
6053       IF l_debug_level  > 0 THEN
6054           oe_debug_pub.add(  'retrieving key information from base table') ;
6055       END IF;
6056 
6057 
6058 SELECT order_source_id, orig_sys_document_ref, sold_to_org_id, change_sequence
6059 INTO l_order_source_id, l_orig_sys_document_ref, l_sold_to_org_id, l_change_sequence
6060 FROM oe_order_headers
6061 WHERE header_id=l_header_id;
6062 
6063 /* to fix issue in bug 3478862, now retrieve key information from base table
6064 l_order_source_id        := to_number(l_request_rec.param2);
6065 l_orig_sys_document_ref  := l_request_rec.param3;
6066 l_sold_to_org_id         := to_number(l_request_rec.param4);
6067 l_change_sequence        := l_request_rec.param5;
6068 */
6069 
6070 l_org_id                 := to_number(l_request_rec.param6);
6071 l_acknowledgment_type    := l_request_rec.param7;
6072 l_flow_status_code       := l_request_rec.param8;
6073 l_party_id               := to_number(l_request_rec.param9);
6074 l_party_site_id          := to_number(l_request_rec.param10);
6075 l_customer_id            := to_number(l_request_rec.param11);
6076 l_reciever_code          := l_request_rec.param12;
6077 l_order_number           := to_number(l_request_rec.param13);
6078 
6079 
6080       IF l_debug_level  > 0 THEN
6081           oe_debug_pub.add(  'l_reciever_code before:' || l_reciever_code ) ;
6082       END IF;
6083 
6084 
6085 IF l_reciever_code = FND_API.G_MISS_CHAR OR
6086    l_reciever_code IS NULL THEN
6087     l_reciever_code := 'C';
6088 END IF;
6089 
6090 -- l_reciever_code has 3 valid values:
6091 -- C => 'generate customer acknowledgment'
6092 -- P => 'raise product-level integration event'
6093 -- B => do both
6094 -- interpret a  passed for acknowledgment_type as signaling a product-level raise event
6095 
6096 IF l_acknowledgment_type IS NULL THEN
6097 l_reciever_code           := 'P';
6098 END IF;
6099 
6100       IF l_debug_level  > 0 THEN
6101           oe_debug_pub.add(  'l_reciever_code after:' || l_reciever_code ) ;
6102       END IF;
6103 
6104    IF l_request_rec.param1 IS NULL THEN
6105    -- header level request that should acknowledge all lines
6106    IF l_debug_level  > 0 THEN
6107           oe_debug_pub.add(  'RAISING HEADER-LEVEL EVENT TO ACK ALL LINES') ;
6108    END IF;
6109 
6110 
6111  IF l_reciever_code IN ('C', 'B') THEN
6112   IF l_acknowledgment_type in (OE_ACKNOWLEDGMENT_PUB.G_TRANSACTION_SSO, OE_ACKNOWLEDGMENT_PUB.G_TRANSACTION_CSO) THEN
6113 
6114       IF l_debug_level  > 0 THEN
6115           oe_debug_pub.add(  'SSO or CSO request' ) ;
6116       END IF;
6117     OE_Acknowledgment_Pub.Raise_Event_Showso
6118           (
6119            p_header_id              => l_header_id,
6120            p_line_id                => Null,
6121            p_customer_id            => l_sold_to_org_id,
6122            p_orig_sys_document_ref  => l_orig_sys_document_ref,
6123 	   p_change_sequence        => l_change_sequence,
6124            p_itemtype               => OE_ORDER_IMPORT_WF.G_WFI_CONC_PGM,
6125            p_party_id               => l_party_id,
6126            p_party_site_id          => l_party_site_id,
6127            p_transaction_type       => l_acknowledgment_type,
6128            p_commit_flag            => 'N',
6129            x_return_status          => l_return_status
6130           );
6131 
6132   ELSIF l_acknowledgment_type = OE_ACKNOWLEDGMENT_PUB.G_TRANSACTION_POI THEN
6133 
6134       IF l_debug_level  > 0 THEN
6135           oe_debug_pub.add(  '3A4 ACK request' ) ;
6136       END IF;
6137      Oe_Acknowledgment_Pub.Raise_Event_From_Oeoi(
6138         p_transaction_type       =>  l_acknowledgment_type,
6139         p_orig_sys_document_ref  =>  l_orig_sys_document_ref,
6140         p_request_id             =>  null,
6141         p_order_imported         =>  'Y',
6142         p_sold_to_org_id         =>  l_sold_to_org_id,
6143         p_change_sequence        =>  l_change_sequence,
6144         p_org_id                 =>  l_org_id,
6145         p_check_for_delivery     =>  'N',
6146         x_return_status          =>  l_return_status);
6147 
6148 
6149    END IF;
6150   END IF;
6151 
6152 
6153 
6154   IF l_reciever_code IN ('P', 'B') THEN
6155    -- raise integration event
6156      IF l_debug_level  > 0 THEN
6157           oe_debug_pub.add(  'RAISING INTEGRATION EVENT' ) ;
6158       END IF;
6159   OE_Acknowledgment_Pub.Raise_Event_XMLInt (
6160              p_order_source_id        =>  l_order_source_id,
6161              p_partner_document_num   =>  l_orig_sys_document_ref,
6162              p_sold_to_org_id         =>  l_sold_to_org_id,
6163 	     p_itemtype               =>  NULL,
6164              p_itemkey                =>  NULL,
6165 	     p_transaction_type       =>  NULL,
6166              p_message_text           =>  NULL,
6167              p_document_num           =>  l_order_number,
6168              p_change_sequence        =>  l_change_sequence,
6169              p_org_id                 =>  l_org_id,
6170              p_header_id              =>  l_header_id,
6171              p_subscriber_list        =>  'DEFAULT',
6172              p_line_ids               =>  'ALL',
6173              x_return_status          =>  l_return_status);
6174 
6175    END IF;
6176 
6177 
6178    ELSE       --do seeding of acknowledgment tables for passed header and line information
6179 
6180 
6181   IF l_reciever_code IN ('C', 'B') THEN  --start of check for customer ack request
6182       select OE_XML_MESSAGE_SEQ_S.nextval
6183       into l_itemkey
6184       from dual;
6185 
6186       IF l_debug_level  > 0 THEN
6187       oe_debug_pub.add(  'sequence value:  ' || l_itemkey) ;
6188       end if;
6189 
6190 
6191 --insert provided header information into table
6192       IF l_debug_level  > 0 THEN
6193           oe_debug_pub.add(  'SEEDEDING HEADER_ID FOR ACKNOWLEDGMENT => ' || l_header_id ) ;
6194       END IF;
6195 
6196 
6197    Insert Into OE_HEADER_ACKS (header_id, acknowledgment_type, last_ack_code, request_id, sold_to_org_id, change_sequence)
6198    Values (l_header_id, l_acknowledgment_type, l_flow_status_code, l_itemkey,
6199            l_sold_to_org_id, l_change_sequence);
6200 
6201       IF l_debug_level  > 0 THEN
6202           oe_debug_pub.add(  'AFTER HEADER INSERT') ;
6203       END IF;
6204  END IF;  -- end of check for customer ack request
6205 
6206 
6207    l_count := OE_Delayed_Requests_PVT.G_Delayed_Requests.first;
6208 
6209 --find and insert lines for that header
6210    WHILE l_count IS NOT NULL LOOP
6211 
6212    --Check to see if this is a line-level xml request for the same transaction type and header id
6213      IF OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).request_type = OE_GLOBALS.G_GENERATE_XML_REQ_LN
6214         AND OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).param1 = l_header_id
6215         AND nvl(OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).param7, 'INT') = nvl(l_acknowledgment_type, 'INT') THEN
6216 
6217    -- add this line to the lines table for insertion
6218       IF l_debug_level  > 0 THEN
6219           oe_debug_pub.add(  'LINE_ID FOR ACKNOWLEDGMENT => ' || OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).entity_id ) ;
6220       END IF;
6221 
6222       If l_line_found = 'N' then
6223       --set flag to show that a line has been found
6224       l_line_found := 'Y';
6225       End If;
6226 
6227       --extend the length of elements in the nested tables
6228 
6229     IF l_reciever_code IN ('C', 'B') THEN
6230 
6231       l_bulk_line_rec.header_id.extend;
6232       l_bulk_line_rec.line_id.extend;
6233       l_bulk_line_rec.xml_transaction_type_code.extend;
6234       l_bulk_line_rec.last_ack_code.extend;
6235       l_bulk_line_rec.request_id.extend;
6236       l_bulk_line_rec.sold_to_org_id.extend;
6237       l_bulk_line_rec.change_sequence.extend;
6238 
6239       l_bulk_line_rec.header_id(i) := l_header_id;
6240       l_bulk_line_rec.line_id(i) := OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).entity_id;
6241       l_bulk_line_rec.xml_transaction_type_code(i) := l_acknowledgment_type;
6242       l_bulk_line_rec.last_ack_code(i) := OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).param8;
6243       l_bulk_line_rec.request_id(i) := l_itemkey;
6244       l_bulk_line_rec.sold_to_org_id(i) := to_number(OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).param4);
6245       l_bulk_line_rec.change_sequence(i) :=OE_Delayed_Requests_PVT. G_Delayed_Requests(l_count).param5;
6246 
6247       IF l_debug_level  > 0 THEN
6248       oe_debug_pub.add(  'after assignment to bulk record') ;
6249       end if;
6250 
6251     END IF;
6252 
6253     IF l_reciever_code IN ('P', 'B') THEN
6254        -- 5738023
6255       IF l_debug_level  > 0 THEN
6256          oe_debug_pub.add(  'Assigning entity id to line table', 3);
6257       END IF;
6258      l_line_id_tbl(i).line_id := OE_Delayed_Requests_PVT.G_Delayed_Requests(l_count).entity_id;
6259     END IF;
6260 
6261       i := i + 1;
6262 
6263 
6264       l_count_old := l_count;
6265       l_count := OE_Delayed_Requests_PVT.G_Delayed_Requests.Next(l_count);
6266 
6267       -- Processing has been done, so delete line-level request now
6268       OE_Delayed_Requests_PVT.G_Delayed_Requests.Delete(l_count_old);
6269 
6270       ELSE
6271       l_count := OE_Delayed_Requests_PVT.G_Delayed_Requests.Next(l_count);
6272       END IF;
6273 
6274    END LOOP;
6275 
6276   IF l_reciever_code IN ('C', 'B') THEN
6277    IF l_line_found = 'Y' THEN
6278    --only do line insert if lines were found
6279 
6280    --bulk insert the lines into the lines table
6281    ctr := l_bulk_line_rec.line_id.count;
6282 
6283 
6284     IF l_debug_level  > 0 THEN
6285        oe_debug_pub.add(  'LINE COUNT:' || ctr) ;
6286        oe_debug_pub.add(  'BEFORE BULK INSERT OF LINES') ;
6287    END IF;
6288 
6289    FORALL j IN 1..ctr
6290         INSERT INTO OE_LINE_ACKS
6291             (header_id
6292             ,line_id
6293             ,acknowledgment_type
6294             ,last_ack_code
6295             ,request_id
6296             ,sold_to_org_id
6297             ,change_sequence)
6298         VALUES
6299             (l_bulk_line_rec.header_id(j)
6300             ,l_bulk_line_rec.line_id(j)
6301             ,l_acknowledgment_type
6302             ,l_bulk_line_rec.last_ack_code(j)
6303             ,l_bulk_line_rec.request_id(j)
6304             ,l_bulk_line_rec.sold_to_org_id(j)
6305             ,l_bulk_line_rec.change_sequence(j)
6306             );
6307 
6308    IF l_debug_level  > 0 THEN
6309        oe_debug_pub.add(  'AFTER BULK INSERT OF LINES') ;
6310    END IF;
6311 
6312   END IF;  --end of l_line_found conditional
6313 END IF;
6314 
6315    IF l_reciever_code IN ('C', 'B') THEN
6316      IF l_acknowledgment_type IN (OE_ACKNOWLEDGMENT_PUB.G_TRANSACTION_SSO, OE_ACKNOWLEDGMENT_PUB.G_TRANSACTION_CSO) THEN
6317 
6318       IF l_debug_level  > 0 THEN
6319           oe_debug_pub.add(  'SSO or CSO request' ) ;
6320       END IF;
6321 
6322        OE_Acknowledgment_Pub.Raise_Event_Showso
6323           (
6324            p_header_id              => l_header_id,
6325            p_line_id                => Null,
6326            p_customer_id            => l_sold_to_org_id,
6327            p_orig_sys_document_ref  => l_orig_sys_document_ref,
6328 	   p_change_sequence        => l_change_sequence,
6329            p_itemtype               => Null,
6330            p_itemkey                => l_itemkey,
6331            p_party_id                => l_party_id,
6332            p_party_site_id           => l_party_site_id,
6333            p_transaction_type       => l_acknowledgment_type,
6334            x_return_status          => l_return_status
6335           );
6336 
6337 
6338    ELSIF l_acknowledgment_type = OE_ACKNOWLEDGMENT_PUB.G_TRANSACTION_POI THEN
6339 
6340       IF l_debug_level  > 0 THEN
6341           oe_debug_pub.add(  '3A4 ACK request' ) ;
6342       END IF;
6343      Oe_Acknowledgment_Pub.Raise_Event_From_Oeoi(
6344         p_transaction_type       =>  l_acknowledgment_type,
6345         p_orig_sys_document_ref  =>  l_orig_sys_document_ref,
6346         p_request_id             =>  null,
6347         p_order_imported         =>  'Y',
6348         p_sold_to_org_id         =>  l_sold_to_org_id,
6349         p_change_sequence        =>  l_change_sequence,
6350         p_org_id                 =>  l_org_id,
6351         p_start_from_flow        =>  OE_ORDER_IMPORT_WF.G_WFI_PROC,
6352         p_check_for_delivery     =>  'N',
6353         x_return_status          =>  l_return_status);
6354 
6355    END IF;
6356 
6357 END IF;
6358 
6359 
6360  IF l_reciever_code IN ('P', 'B') THEN
6361    IF l_line_id_tbl.COUNT > 0 THEN  --5939693
6362  --    FOR I IN  l_line_id_tbl.FIRST..l_line_id_tbl.LAST  LOOP Commented for bug 5939693
6363     i := l_line_id_tbl.FIRST;
6364      WHILE i IS NOT NULL LOOP
6365         IF ((length(l_line_ids) + 2 * length(l_line_id_tbl(i).line_id)) > 2000 ) THEN
6366             Raise_Event_XML := TRUE;
6367         ELSE
6368          IF l_line_ids IS NULL THEN
6369             l_line_ids := l_line_id_tbl(i).line_id;
6370          ELSE
6371             l_line_ids := l_line_ids || ':' ||  l_line_id_tbl(i).line_id;
6372          END IF;
6373              IF I = l_line_id_tbl.LAST THEN
6374                 Raise_Event_XML := TRUE;
6375              END IF;
6376        END IF;
6377   IF Raise_Event_XML THEN
6378      IF l_debug_level  > 0 THEN
6379         oe_debug_pub.add(  'Raising Event with line id '|| l_line_id_tbl(i).line_id, 3);
6380         oe_debug_pub.add(  'Line_ids:' || l_line_ids, 3);
6381      END IF;
6382 
6383    -- raise integration event
6384     OE_Acknowledgment_Pub.Raise_Event_XMLInt (
6385              p_order_source_id        =>  l_order_source_id,
6386              p_partner_document_num   =>  l_orig_sys_document_ref,
6387              p_sold_to_org_id         =>  l_sold_to_org_id,
6388 	     p_itemtype               =>  NULL,
6389              p_itemkey                =>  NULL,
6390 	     p_transaction_type       =>  NULL,
6391              p_message_text           =>  NULL,
6392              p_document_num           =>  l_order_number,
6393              p_change_sequence        =>  l_change_sequence,
6394              p_org_id                 =>  l_org_id,
6395              p_header_id              =>  l_header_id,
6396              p_subscriber_list        =>  'DEFAULT',
6397              p_line_ids               =>  l_line_ids,
6398              x_return_status          =>  l_return_status);
6399 
6400 
6401       IF l_debug_level  > 0 THEN
6402           oe_debug_pub.add(  'line ids: ' || l_line_ids ) ;
6403       END IF;
6404          l_line_ids := NULL;
6405          Raise_Event_XML := FALSE;
6406 
6407    END IF;
6408    i:=l_line_id_tbl.NEXT(i);
6409  END LOOP;
6410 
6411 -- Added for bug #6726949
6412 /* Below code is needed for this new regression bug
6413    ------------------------------------------------ */
6414 ELSE -- l_line_id_tbl.COUNT is 0
6415     IF l_debug_level  > 0 THEN
6416        oe_debug_pub.add(' Raising XML Event for Order Header');
6417     END IF;
6418     l_line_ids := NULL;
6419     OE_Acknowledgment_Pub.Raise_Event_XMLInt (
6420              p_order_source_id        =>  l_order_source_id,
6421              p_partner_document_num   =>  l_orig_sys_document_ref,
6422              p_sold_to_org_id         =>  l_sold_to_org_id,
6423              p_itemtype               =>  NULL,
6424              p_itemkey                =>  NULL,
6425              p_transaction_type       =>  NULL,
6426              p_message_text           =>  NULL,
6427              p_document_num           =>  l_order_number,
6428              p_change_sequence        =>  l_change_sequence,
6429              p_org_id                 =>  l_org_id,
6430              p_header_id              =>  l_header_id,
6431              p_subscriber_list        =>  'DEFAULT',
6432              p_line_ids               =>  l_line_ids,
6433              x_return_status          =>  l_return_status);
6434 /* Changes Ends for this new regression bug
6435    ---------------------------------------- */
6436 
6437  END IF;
6438  END IF;
6439 END IF;
6440 
6441     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6442       IF l_debug_level  > 0 THEN
6443       OE_Debug_PUB.Add('ERROR RETURNED BY RAISE_EVENT FOR: ' || l_acknowledgment_type);
6444       END IF;
6445     END IF;
6446 
6447 
6448      x_return_status := l_return_status;
6449 
6450 
6451 
6452 
6453 
6454 
6455 Exception
6456 When others then
6457       IF l_debug_level  > 0 THEN
6458           oe_debug_pub.add(  'IN OTHERS EXCEPTION:' || SQLERRM) ;
6459       END IF;
6460       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6461       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6462 End Process_XML_Delayed_Request;
6463 
6464 
6465 /* 7576948: IR ISO Change Management project Start */
6466 /*
6467 Procedure Name : Update_Requisition_Info
6468 Input Params   : P_Header_id - Primary key of the order header
6469                  P_Line_id - Primary key of the order line. This parameter
6470                              will be null for order header cancellation
6471                  P_Requisition_Header_id - Primary key of the requisition
6472                                            header
6473                  P_Requisition_Line_id - Primary key of the requisition line
6474                  p_Line_ids - String variable containing line_ids delimited
6475                               by comma ?Q,?R. Will be populated only if it is
6476                               a partial order cancellation
6477                  p_num_records - Number of total order line records cancelled
6478                                  while processing partial order cancellation
6479                  P_Quantity_Change - It will denote net change in order quantity
6480                                      with respective single requisition line.
6481                                      If it is greater than 0 then it is an
6482                                      increment in the quantity, while if it is
6483                                      less than 0 then it is a decrement in the
6484                                      ordered quantity. If it is 0 then it
6485                                      indicates there is no change in ordered
6486                                      quantity value
6487                  P_New_Schedule_Ship_Date - It will denote the change in
6488                                             Schedule Ship Date
6489                  P_Cancel_Order - It will denote whether internal sales order
6490                                   is cancelled or not. If it is cancelled then
6491                                   respective Purchasing api will be called to
6492                                   trigger the requisition header cancellation.
6493 Output Params  : X_Return_Status - The return status of the API
6494                                    (Expected/Unexpected/Success)
6495 Brief Description : This program unit is added for IR ISO Change
6496                     management project, so as to trigger the new
6497                     program unit OE_Process_Requisition_Pvt.Updat
6498                     e_Internal_Requisition introduced as part of
6499                     this project, and responsible for calling several
6500                     Purchasing APIs based on the action performed
6501                     on the internal sales order header/line.
6502 
6503                     Possible actions can be:
6504                        Header Level FULL Cancellation
6505                        Header Level PARTIAL Cancellation
6506                        Line Level Cancellation
6507                        Line Ordered Quantity update
6508                        Line Schedule Ship/Arrival Date update
6509                        Line Ordered Quantity and Schedule Ship/Arrival
6510                        Date update
6511 
6512 -- For details on IR ISO CMS project, please refer to FOL >
6513 -- OM Development > OM GM > 12.1.1 > TDD > IR_ISO_CMS_TDD.doc
6514 */
6515 
6516 Procedure Update_Requisition_Info -- Package Body
6517 ( p_header_id              IN NUMBER    -- Param5 or Entity id
6518 , p_line_id                IN NUMBER   -- Entity id
6519 , P_Line_ids               IN VARCHAR2 -- Long_Param1
6520 , P_num_records            IN NUMBER   -- Param6
6521 , P_Requisition_Header_id  IN NUMBER    -- Param3
6522 , P_Requisition_Line_id    IN NUMBER DEFAULT NULL   -- Param4
6523 , P_Quantity_Change        IN NUMBER DEFAULT NULL   -- Param1
6524 , P_New_Schedule_Ship_Date IN DATE -- Date_Param1
6525 , P_Cancel_order           IN BOOLEAN -- Param2
6526 , x_return_status OUT NOCOPY varchar2
6527 )
6528 IS
6529 --
6530 l_return_status       VARCHAR2(30);
6531 l_msg_count           NUMBER;
6532 l_msg_data            VARCHAR2(2000);
6533 l_new_ord_quantity    NUMBER;
6534 l_cancel_line         BOOLEAN := FALSE;
6535 l_New_Schedule_Ship_Date DATE;
6536 --
6537 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6538 --
6539 BEGIN
6540   IF l_debug_level > 0 THEN
6541     oe_debug_pub.ADD('Entering delayed request utility for Update_Requisition_Info',1);
6542     oe_debug_pub.ADD(' Header id '||p_header_id,5);
6543     oe_debug_pub.ADD(' Line id '||p_line_id,5);
6544     oe_debug_pub.ADD(' Number of shipment Lines updated '||p_num_records,5);
6545     oe_debug_pub.ADD(' Req Header id '||p_requisition_header_id,5);
6546     oe_debug_pub.ADD(' Req Line id '||p_requisition_line_id,5);
6547     oe_debug_pub.ADD(' Quantity Change '||p_quantity_change,5);
6548     oe_debug_pub.ADD(' New Schedule Ship Date '||p_new_schedule_ship_date,5);
6549     IF p_cancel_order THEN
6550       oe_debug_pub.ADD(' Order Level Cancellation',5);
6551    ELSE
6552       oe_debug_pub.ADD(' Not an Order Level Cancellation',5);
6553     END IF;
6554   END IF;
6555 
6556   x_return_status := FND_API.G_RET_STS_SUCCESS;
6557   l_New_Schedule_Ship_Date := p_New_Schedule_Ship_Date;
6558 
6559   IF NOT p_Cancel_Order THEN
6560     IF p_line_id IS NULL THEN
6561       IF l_debug_level > 0 THEN
6562         oe_debug_pub.add(' Invalid processing since Line_id is null for non-order header cancellation',1);
6563       END IF;
6564       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6565     END IF;
6566     Begin
6567       select nvl(ordered_quantity,0)
6568       into   l_new_ord_quantity
6569       from   oe_order_lines_all
6570       where  line_id = p_line_id;
6571     End;
6572     IF l_new_ord_quantity = 0 THEN
6573       IF l_debug_level > 0 THEN
6574        oe_debug_pub.ADD(' Line is cancelled, cancel the Requisition Line',5);
6575       END IF;
6576       l_cancel_line := TRUE;
6577     END IF;
6578   END IF; -- Not P_Cancel_Order
6579 
6580   OE_Process_Requisition_Pvt.Update_Internal_Requisition
6581   ( P_Header_id               => p_header_id
6582   , P_Line_id                 => p_line_id
6583   , p_line_ids                => p_line_ids
6584   , p_num_records             => p_num_records
6585   , P_Req_Header_id           => P_Requisition_Header_id
6586   , P_Req_Line_id             => P_Requisition_Line_id
6587   , P_Quantity_Change         => P_Quantity_Change
6588   , P_New_Schedule_Ship_Date  => l_New_Schedule_Ship_Date
6589   , P_Cancel_Order            => P_Cancel_order
6590   , P_Cancel_line             => l_cancel_line
6591   , X_msg_count               => l_msg_count
6592   , X_msg_data                => l_msg_data
6593   , X_return_status           => l_return_status
6594   );
6595 
6596   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6597     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6598   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6599     RAISE FND_API.G_EXC_ERROR;
6600   END IF;
6601 
6602   X_return_status := l_return_status;
6603 
6604   IF l_debug_level > 0 THEN
6605     oe_debug_pub.ADD('Exiting delayed request utility for Update_Requisition_Info',1);
6606   END IF;
6607 EXCEPTION
6608   WHEN FND_API.G_EXC_ERROR THEN
6609     x_return_status := FND_API.G_RET_STS_ERROR;
6610   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6611     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6612   WHEN OTHERS THEN
6613     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6614     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
6615       OE_MSG_PUB.Add_Exc_Msg
6616       ( G_PKG_NAME
6617       , 'Update_Requisition_Info'
6618       );
6619     END IF;
6620 END Update_Requisition_Info;
6621 
6622 
6623 /* ============================= */
6624 /* IR ISO Change Management Ends */
6625 
6626 
6627 END OE_Delayed_Requests_UTIL;