DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_OE_FORM_CANCEL_LINE

Source


1 PACKAGE BODY OE_OE_FORM_CANCEL_LINE AS
2 /* $Header: OEXFCANB.pls 120.3 2005/08/30 13:03:19 rbellamk ship $ */
3 
4 
5 --  Start of Comments
6 --  API name    OE_OE_FORM_CANCEL_LINE
7 --  Type        Private
8 --  Function
9 --
10 --  Pre-reqs
11 --
12 --  Parameters
13 --
14 --  Version     Current version = 1.0
15 --              Initial version = 1.0
16 --
17 --  Notes
18 --
19 --  End of Comments
20 g_line_rec                    OE_Order_PUB.Line_Rec_Type;
21 g_db_line_rec                 OE_Order_PUB.Line_Rec_Type;
22 FUNCTION Get_line
23 (   p_db_record                     IN  BOOLEAN := FALSE
24 ,   p_line_id                       IN  NUMBER
25 )
26 RETURN OE_Order_PUB.Line_Rec_Type;
27 
28 Procedure Process_cancel_quantity
29 (    p_num_of_records       IN NUMBER
30     ,p_record_ids           IN OE_GLOBALS.Selected_Record_Tbl -- MOAC
31     ,p_cancel_to_quantity   IN NUMBER
32     ,p_cancellation_comments IN VARCHAR2
33     ,p_reason_code          IN VARCHAR2
34     ,p_cancellation_type    IN VARCHAR2
35     ,p_mc_err_handling_flag IN NUMBER := FND_API.G_MISS_NUM
36 ,x_msg_count OUT NOCOPY NUMBER
37 
38 ,x_msg_data OUT NOCOPY VARCHAR2
39 
40 ,x_return_status OUT NOCOPY VARCHAR2
41 
42 ,x_error_count OUT NOCOPY NUMBER
43 
44 ) IS
45 l_line_rec            OE_ORDER_PUB.line_rec_type;
46 l_control_rec         OE_GLOBALS.Control_Rec_Type;
47 l_line_tbl            OE_ORDER_PUB.Line_Tbl_Type;
48 l_old_line_tbl        OE_ORDER_PUB.Line_Tbl_Type;
49 l_api_name            CONSTANT VARCHAR2(30) := 'Process_Cancel_quantity';
50 l_line_id             NUMBER;
51 l_return_status       VARCHAR2(30);
52 l_error_count         NUMBER :=0;
53 l_ordered_quantity    NUMBER ;
54 l_ordered_quantity2   NUMBER ; /* OPM change. NC - 03/30/01. Bug#1651766 */
55 j                     Integer;
56 initial               Integer;
57 nextpos               Integer;
58 
59 /* B:Included for bug# 2233213 */
60 t_line_id             NUMBER;
61 m                     Integer;
62 initialval            Integer;
63 nextposval            Integer;
64 set_flag              VARCHAR2(1) := 'N';
65 /* E:Included for bug# 2233213 */
66 
67 l_record_ids          OE_GLOBALS.Selected_Record_Tbl := p_record_ids ;
68 l_num_of_records      NUMBER;
69 l_cancel_to_quantity  NUMBER := p_cancel_to_quantity ;
70 l_prg_line_id         NUMBER;
71 
72 cursor prg_parent(c_line_id number)
73 is
74 select opa1.line_id
75 from   oe_price_adjustments opa1,
76        oe_price_adjustments opa2,
77        oe_price_adj_assocs opaa
78 where  opa1.list_line_type_code = 'PRG'
79 and    opa1.price_adjustment_id = opaa.price_adjustment_id
80 and    opa2.price_adjustment_id = opaa.rltd_price_adj_id
81 and    opa2.line_id             = c_line_id;
82 --
83 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
84 l_orgid number;
85 l_skip_process varchar2(1) := 'N';
86 l_header_id number;
87 l_tblcount number := 0;
88 --
89 BEGIN
90 x_return_status := fnd_api.g_ret_sts_success;
91 g_record_ids := l_record_ids;   -- Added For bug#2965878
92   IF l_debug_level  > 0 THEN
93       oe_debug_pub.add(  'ENTER PROCEDURE PROCESS CANCEL QTY' , 1 ) ;
94   END IF;
95   oe_msg_pub.initialize;
96   x_error_count := l_error_count;
97 
98   IF l_debug_level  > 0 THEN
99       oe_debug_pub.add(  ' NO. OF RECORDS: '||TO_CHAR ( P_NUM_OF_RECORDS ) , 1 ) ;
100   END IF;
101 
102  /* Not needed with MOAC
103  j := 1.0;
104   initial := 1.0;
105   nextpos := INSTR(l_record_ids,',',1,j) ;
106  */
107 
108   IF l_debug_level  > 0 THEN
109       oe_debug_pub.add(  'POS'||TO_CHAR ( NEXTPOS ) , 1 ) ;
110   END IF;
111   l_num_of_records := p_num_of_records;
112  g_num_of_records := l_num_of_records;  -- Added For bug#2965878
113 
114   l_line_tbl := OE_ORDER_PUB.G_MISS_LINE_TBL;
115   l_old_line_tbl := OE_ORDER_PUB.G_MISS_LINE_TBL;
116 
117   SAVEPOINT Process_cancel_quantity;
118 
119    	IF l_orgid is null  THEN
120 		l_orgid := l_record_ids(1).Org_Id;
121 
122   IF l_debug_level  > 0 THEN
123 oe_debug_pub.add(  ' ORG ID: '||TO_CHAR ( l_orgid ) , 1 ) ;
124   END IF;
125 
126  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
127                                p_org_id      => l_record_ids(1).Org_Id);
128 
129 	END IF;
130 
131   FOR i IN 1..l_num_of_records LOOP
132 
133     --OE_DEBUG_PUB.Add('Number Of records'||to_char(l_num_of_records),1);
134     --dbms_output.put_line('ini='||to_char(initial)||'next='||to_char(nextpos));
135 
136 		if l_header_id is null then
137 			l_header_id := l_record_ids(i).id2;
138 		elsif l_header_id <> l_record_ids(i).id2 THEN
139 			IF l_line_tbl.count <> 0 THEN
140   IF l_debug_level  > 0 THEN
141 oe_debug_pub.add(  ' Header ID: '||TO_CHAR ( l_header_id ) , 1 ) ;
142   END IF;
143 
144 			Call_Process_Order (p_line_tbl => l_line_tbl,
145 				p_old_line_tbl => l_old_line_tbl,
146 			    x_return_status => l_return_status);
147 
148 			END IF;
149 
150     		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
151       			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
152     		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
153       			RAISE FND_API.G_EXC_ERROR;
154     		END IF;
155 				l_header_id := l_record_ids(i).id2;
156 				l_line_tbl.delete;
157 				l_tblcount := 0;
158 				l_old_line_tbl.delete;
159 		end if; -- end if l header id
160 
161    	IF l_record_ids(i).org_id <> l_orgid THEN
162 		l_orgid := l_record_ids(i).Org_Id;
163   IF l_debug_level  > 0 THEN
164 oe_debug_pub.add(  ' ORG ID Change: '||TO_CHAR ( l_orgid ) , 1 ) ;
165   END IF;
166 
167  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
168                                p_org_id      => l_record_ids(i).Org_Id);
169 
170 	END IF;
171 
172 	l_line_id := l_record_ids(i).id1;
173     IF l_debug_level  > 0 THEN
174         oe_debug_pub.add(  'LINE ID: '||TO_CHAR ( L_LINE_ID ) , 1 ) ;
175     END IF;
176 
177 /* Not needed with MOAC changes
178     initial := nextpos + 1.0;
179     j := j + 1.0;
180     nextpos := INSTR(l_record_ids,',',1,j) ;
181 */
182 
183     OE_LINE_UTIL.Lock_Row
184     (   p_line_id       => l_line_id,
185 	p_x_line_rec    => l_line_rec,
186 	x_return_status => l_return_status
187     );
188 
189     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
190       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
191     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
192       RAISE FND_API.G_EXC_ERROR;
193     END IF;
194 
195     IF l_line_rec.split_action_code = FND_API.G_MISS_CHAR THEN
196       IF l_debug_level  > 0 THEN
197           oe_debug_pub.add(  'SPLIT ACTION CODE MISSING' , 1 ) ;
198       END IF;
199     ELSIF l_line_rec.split_action_code IS NULL THEN
200       IF l_debug_level  > 0 THEN
201           oe_debug_pub.add(  'SPLIT ACTION CODE NULL' , 1 ) ;
202       END IF;
203     ELSE
204       IF l_debug_level  > 0 THEN
205           oe_debug_pub.add(  'SPLIT ACTION CODE '||L_LINE_REC.SPLIT_ACTION_CODE , 1 ) ;
206       END IF;
207     END IF;
208 
209     IF l_debug_level  > 0 THEN
210         oe_debug_pub.add(  'LINE CATEGORY: '||L_LINE_REC.LINE_CATEGORY_CODE , 1 ) ;
211     END IF;
212 
213     l_ordered_quantity := l_line_rec.ordered_quantity;
214     /* OPM change. NC - 03/30/01. Bug#1651766 */
215     l_ordered_quantity2 := l_line_rec.ordered_quantity2;
216 
217     if (l_ordered_quantity = 0 or l_line_rec.cancelled_flag = 'Y') then
218       fnd_message.set_name('ONT', 'OE_CANCEL_NOTHING');
219       oe_msg_pub.add;
220       RAISE FND_API.G_EXC_ERROR ;
221     end if;
222 
223                      IF l_debug_level  > 0 THEN
224                          oe_debug_pub.add(  'LINE ID '||TO_CHAR ( L_LINE_REC.LINE_ID ) || ' , ORD QTY '||TO_CHAR ( L_LINE_REC.ORDERED_QUANTITY ) || ' , CANCEL TYPE '|| P_CANCELLATION_TYPE , 1 ) ;
225                      END IF;
226 
227     /* Begin:Included for bug# 2233213 */
228     IF l_line_rec.item_type_code = OE_Globals.G_ITEM_SERVICE AND
229        l_line_rec.service_reference_type_code = 'ORDER' THEN
230 
231      /* Not needed with MOAC changes  m := 1.0;
232       initialval := 1.0;
233       nextposval := INSTR(l_record_ids,',',1,m) ; */
234       set_flag := 'N';
235 
236       for n in 1..l_num_of_records loop
237         t_line_id := l_record_ids(n).id1;
238 /* Not needed with MOAC changes
239         initialval := nextposval + 1.0;
240         m := m + 1.0;
241         nextposval := INSTR(l_record_ids,',',1,m) ;
242 */
243 
244         if l_line_rec.service_reference_line_id = t_line_id then
245           set_flag := 'Y';
246           exit;
247         end if;
248       end loop;
249 
250       IF set_flag = 'Y' THEN
251         IF l_debug_level  > 0 THEN
252             oe_debug_pub.add(  'SKIP , PARENT OF THIS SERVICE LINE IS SELECTED FOR CANCELLATION' ) ;
253         END IF;
254         goto  end_loop;
255       END IF;
256     END IF;
257     /* End:Included for bug# 2233213 */
258 
259     /* Fix for bug # 2387919 */
260     set_flag := 'N';
261     for prg_parent_rec in prg_parent(l_line_rec.line_id) loop
262       IF set_flag = 'Y' THEN
263         exit;
264       end if;
265 
266  /* Not required for MOAC
267      m := 1.0;
268       initialval := 1.0;
269       nextposval := INSTR(l_record_ids,',',1,m) ; */
270 
271       for n in 1..l_num_of_records loop
272         t_line_id := l_record_ids(n).id1;
273 /* Not required with MOAC changes
274         initialval:= nextposval + 1.0;
275         m := m + 1.0;
276         nextposval := INSTR(l_record_ids,',',1,m) ;
277 */
278 
279         if prg_parent_rec.line_id = t_line_id then
280           set_flag := 'Y';
281           exit;
282         end if;
283       end loop;
284     end loop;
285 
286     IF set_flag = 'Y' THEN
287       IF l_debug_level  > 0 THEN
288           oe_debug_pub.add(  'SKIP , THIS IS A PROMOTIONAL LINE' ) ;
289       END IF;
290       goto  end_loop;
291     END IF;
292 
293     --l_line_tbl(1) := OE_ORDER_PUB.G_MISS_LINE_REC;
294 		IF l_tblcount = 0 THEN
295 			l_tblcount := 1;
296 		END IF;
297     l_line_tbl(l_tblcount) := l_line_rec;
298     -- l_old_line_tbl(l_tblcount) := l_line_rec;
299     -- l_line_tbl(1).line_id := l_line_id;
300     l_old_line_tbl(l_tblcount) := l_line_rec;
301     l_line_tbl(l_tblcount).operation := OE_GLOBALS.G_OPR_UPDATE;
302     l_ordered_quantity := 0;
303     l_line_tbl(l_tblcount).ordered_quantity :=l_ordered_quantity;
304 
305     /* OPM change. NC - 03/30/01. Bug#1651766 */
306     IF(l_ordered_quantity2 IS NOT NULL AND l_ordered_quantity2 <> 0 ) THEN
307       l_ordered_quantity2 := 0;
308       l_line_tbl(1).ordered_quantity2 := l_ordered_quantity2;
309     END IF;
310     /* End OPM change */
311 
312     l_line_tbl(l_tblcount).change_reason :=p_reason_code;
313     l_line_tbl(l_tblcount).change_comments :=p_cancellation_comments;
314 	l_tblcount := l_tblcount + 1;
315 
316     /* Included for bug# 2233213 */
317     <<end_loop>>
318     null;
319 
320   END LOOP;
321 
322   --  Call OE_Order_PVT.Process_order for last set of rows
323 
324   IF l_debug_level  > 0 THEN
325       oe_debug_pub.add(  'BEFORE CALLING PROCESSS ORDER LINES PROCEDURE' , 1 ) ;
326   END IF;
327 
328 
329 			IF l_line_tbl.count <> 0 THEN
330 
331 			Call_Process_Order (p_line_tbl => l_line_tbl,
332 				p_old_line_tbl => l_old_line_tbl,
333 			    x_return_status => l_return_status);
334 
335 			END IF;
336 
337   IF l_debug_level  > 0 THEN
338       oe_debug_pub.add(  'AFTER CALLING LINES PROCEDURE' , 1 ) ;
339   END IF;
340 
341   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
342     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
343   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
344     RAISE FND_API.G_EXC_ERROR;
345   END IF;
346 
347   IF l_debug_level  > 0 THEN
348       oe_debug_pub.add(  'AFTER CALLING PROCESSE for last set' , 1 ) ;
349   END IF;
350 
351   OE_MSG_PUB.Count_And_Get
352             ( p_count => x_msg_count,
353               p_data  => x_msg_data
354             );
355 
356   x_return_status  := l_return_status;
357 
358   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
359     IF l_debug_level  > 0 THEN
360         oe_debug_pub.add(  'INTO CANCELATION UNEXPECTED FAILURE' ) ;
361     END IF;
362     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
363   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
364     IF l_debug_level  > 0 THEN
365         oe_debug_pub.add(  'INTO CANCELLATION EXPECTED FAILURE' ) ;
366     END IF;
367     RAISE FND_API.G_EXC_ERROR;
368   END IF;
369 
370   IF l_debug_level  > 0 THEN
371       oe_debug_pub.add(  L_RETURN_STATUS ) ;
372   END IF;
373 
374 EXCEPTION  /* Procedure exception handler */
375 
376  WHEN FND_API.G_EXC_ERROR THEN
377         x_return_status := FND_API.G_RET_STS_ERROR ;
378         OE_MSG_PUB.Count_And_Get
379             ( p_count => x_msg_count,
380               p_data  => x_msg_data
381             );
382        ROLLBACK TO SAVEPOINT Process_cancel_quantity;
383 
384  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
385         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
386         OE_MSG_PUB.Count_And_Get
387             ( p_count => x_msg_count,
388               p_data  => x_msg_data
389             );
390 	ROLLBACK TO SAVEPOINT Process_cancel_quantity;
391 
392  WHEN OTHERS THEN
393         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
394         IF OE_MSG_PUB.Check_Msg_Level
395             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
396         THEN
397              OE_MSG_PUB.Add_Exc_Msg
398                     (G_PKG_NAME,
399                      l_api_name
400                 );
401         END IF;
402         OE_MSG_PUB.Count_And_Get
403             ( p_count => x_msg_count,
404               p_data  => x_msg_data);
405        ROLLBACK TO SAVEPOINT Process_cancel_quantity;
406 
407 end Process_cancel_quantity;
408 
409 Procedure Process_cancel_order
410 (    p_num_of_records       IN NUMBER
411     ,p_record_ids           IN OE_GLOBALS.Selected_Record_Tbl -- MOAC
412     ,p_cancellation_comments IN VARCHAR2
413     ,p_reason_code          IN VARCHAR2
414     ,p_mc_err_handling_flag IN NUMBER := FND_API.G_MISS_NUM
415 ,x_msg_count OUT NOCOPY NUMBER
416 
417 ,x_msg_data OUT NOCOPY VARCHAR2
418 
419 ,x_return_status OUT NOCOPY VARCHAR2
420 
421 ,x_error_count OUT NOCOPY NUMBER
422 
423 ) IS
424 l_header_rec                OE_ORDER_PUB.Header_Rec_Type;
425 l_line_rec                OE_ORDER_PUB.line_rec_type;
426 l_old_header_rec            OE_ORDER_PUB.Header_Rec_Type;
427 l_control_rec               OE_GLOBALS.Control_Rec_Type;
428 l_api_name         CONSTANT VARCHAR2(30)         := 'Process_Cancel_Order';
429 l_header_id         Number;
430 l_return_status             VARCHAR2(30);
431 l_error_count   NUMBER :=0;
432 l_ordered_quantity NUMBER ;
433 j Integer;
434 initial Integer;
435 nextpos Integer;
436 l_record_ids  OE_GLOBALS.Selected_Record_Tbl := p_record_ids ;
437 l_num_of_records number;
438 --
439 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
440 l_orgid number;
441 --
442 BEGIN
443 	oe_msg_pub.initialize;
444      IF l_debug_level  > 0 THEN
445          oe_debug_pub.add(  'PROCEDURE PROCESS_CANCEL_ORDER' , 1 ) ;
446      END IF;
447  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
448  l_old_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
449  l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;   --OE.G_OPR_UPDATE;
450  x_error_count := l_error_count;
451  g_ord_lvl_can := TRUE; --Fix for bug# 2922468.
452   IF l_debug_level  > 0 THEN
453       oe_debug_pub.add(  'No of IDS'||TO_CHAR ( P_NUM_OF_RECORDS ) , 1 ) ;
454   END IF;
455 /* Not required with MOAC changes
456          j := 1.0;
457          initial := 1.0;
458          nextpos := INSTR(l_record_ids,',',1,j) ;
459 */
460 
461 l_num_of_records := p_num_of_records;
462 
463 
464 FOR i IN 1..l_num_of_records LOOP
465  SAVEPOINT Process_cancel_order;
466 
467 
468  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
469  l_old_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
470    	IF l_orgid is null OR l_record_ids(i).org_id <> l_orgid THEN
471 		l_orgid := l_record_ids(i).Org_Id;
472 
473  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
474                                p_org_id      => l_record_ids(i).Org_Id);
475 
476 	END IF;
477 
478  l_header_id := l_record_ids(i).id1;
479 IF l_debug_level  > 0 THEN
480     oe_debug_pub.add(  'INSTR'||TO_CHAR ( L_HEADER_ID ) , 1 ) ;
481 END IF;
482 /* not required with MOAC changes
483  initial := nextpos + 1.0;
484  j := j + 1.0;
485  nextpos := INSTR(l_record_ids,',',1,j) ;
486 */
487 
488  OE_Header_Util.lock_Row
489         (   p_header_id                   => l_header_id,
490 		  p_x_header_rec                  => l_header_rec
491 		   ,x_return_status => l_return_status
492         );
493     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
494         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
495     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
496         RAISE FND_API.G_EXC_ERROR;
497     END IF;
498 
499 l_old_header_rec := l_header_rec;
500 IF l_debug_level  > 0 THEN
501     oe_debug_pub.add(  'CANCELLED FLAG'||L_HEADER_REC.CANCELLED_FLAG , 1 ) ;
502 END IF;
503 IF l_header_rec.cancelled_flag = 'Y' THEN
504 IF l_debug_level  > 0 THEN
505     oe_debug_pub.add(  'CANCELLED FLAG'||L_HEADER_REC.CANCELLED_FLAG , 1 ) ;
506 END IF;
507                 fnd_message.set_name('ONT', 'OE_CAN_ORDER_CANCEL_ALREADY');
508                  FND_MESSAGE.SET_TOKEN('ORDER',
509                                    L_header_rec.Order_Number);
510 
511 
512                 oe_msg_pub.Add;
513           	RAISE FND_API.G_EXC_ERROR ;
514 END IF;
515 IF nvl(l_header_rec.open_flag,'N') = 'N' THEN
516 IF l_debug_level  > 0 THEN
517     oe_debug_pub.add(  'CANCELLED FLAG'||L_HEADER_REC.CANCELLED_FLAG , 1 ) ;
518 END IF;
519                 fnd_message.set_name('ONT', 'OE_CAN_ORDER_CLOSED');
520                  FND_MESSAGE.SET_TOKEN('ORDER',
521                                    L_header_rec.Order_Number);
522                 oe_msg_pub.Add;
523           	RAISE FND_API.G_EXC_ERROR ;
524 END IF;
525 
526   l_header_rec.cancelled_flag :='Y';
527   l_header_rec.change_reason :=p_reason_code;
528  l_header_rec.change_comments :=p_cancellation_comments;
529  l_header_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
530 
531 	oe_order_pvt.Header
532 (   p_validation_level               =>    FND_API.G_VALID_LEVEL_NONE
533 ,   p_control_rec                   => l_control_rec
534 ,   p_x_header_rec                    =>  l_header_rec
535 ,   p_x_old_header_rec                => l_old_header_rec
536 ,   x_return_status     => l_return_status
537 
538 );
539 
540         OE_MSG_PUB.Count_And_Get
541             ( p_count => x_msg_count,
542               p_data  => x_msg_data
543             );
544 
545 
546 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
547         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
548     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
549         RAISE FND_API.G_EXC_ERROR;
550  END IF;
551 
552 
553 -- Api to call notify OC and Process Delayed Requests
554 
555      OE_Order_PVT.Process_Requests_And_Notify
556           ( p_process_requests          => TRUE
557           , p_notify                    => TRUE
558           , x_return_status             => l_return_status
559           , p_header_rec                => l_header_rec
560           , p_old_header_rec            => l_old_header_rec
561           );
562 
563 
564 
565 
566 x_return_status  := l_return_status;
567      IF l_debug_level  > 0 THEN
568          oe_debug_pub.add(  L_RETURN_STATUS ) ;
569      END IF;
570        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
571                IF l_debug_level  > 0 THEN
572                    oe_debug_pub.add(  'CANCELLATION UNEXPECTED FAILURE' ) ;
573                END IF;
574                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
575        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
576                IF l_debug_level  > 0 THEN
577                    oe_debug_pub.add(  'CANCELLATION EXPECTED FAILURE' ) ;
578                END IF;
579                  RAISE FND_API.G_EXC_ERROR;
580        END IF;
581 
582 
583 End LOOP; /* end of FOR loop */
584 
585 g_ord_lvl_can := FALSE; --For fix bug# 2922468.
586 
587 EXCEPTION  /* Procedure exception handler */
588 
589  WHEN FND_API.G_EXC_ERROR THEN
590         x_return_status := FND_API.G_RET_STS_ERROR ;
591         OE_MSG_PUB.Count_And_Get
592             ( p_count => x_msg_count,
593               p_data  => x_msg_data
594             );
595        g_ord_lvl_can := FALSE; --For fix bug# 2922468.
596        ROLLBACK TO SAVEPOINT Process_cancel_order;
597 
598  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
599         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
600         OE_MSG_PUB.Count_And_Get
601             ( p_count => x_msg_count,
602               p_data  => x_msg_data
603             );
604 g_ord_lvl_can:=FALSE; --Fix for bug# 2922468.
605 ROLLBACK TO SAVEPOINT Process_cancel_order;
606 
607  WHEN OTHERS THEN
608         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
609         IF OE_MSG_PUB.Check_Msg_Level
610             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
611         THEN
612              OE_MSG_PUB.Add_Exc_Msg
613                     (G_PKG_NAME,
614                      l_api_name
615                 );
616         END IF;
617         OE_MSG_PUB.Count_And_Get
618             ( p_count => x_msg_count,
619               p_data  => x_msg_data);
620        g_ord_lvl_can := FALSE; --Fix for bug# 2922468.
621        ROLLBACK TO SAVEPOINT Process_cancel_order;
622 
623 
624 end Process_cancel_order;
625 
626 
627 
628 FUNCTION Get_line
629 (   p_db_record                     IN  BOOLEAN := FALSE
630 ,   p_line_id                       IN  NUMBER
631 )
632 RETURN OE_Order_PUB.Line_Rec_Type
633 IS
634 --
635 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
636 --
637 BEGIN
638 
639     IF l_debug_level  > 0 THEN
640         oe_debug_pub.add(  'ENTERING OE_OE_FORM_CANCEL_LINE.GET_LINE' , 1 ) ;
641     END IF;
642 
643     IF  p_line_id <> g_line_rec.line_id
644     THEN
645 
646         --  Query row from DB
647 
648          OE_Line_Util.Query_Row
649         (   p_line_id                     => p_line_id,
650 		  x_line_rec                    => g_line_rec
651         );
652         g_line_rec.db_flag             := FND_API.G_TRUE;
653 
654         --  Load DB record
655 
656 
657         g_db_line_rec                  := g_line_rec;
658 
659     END IF;
660 
661     IF l_debug_level  > 0 THEN
662         oe_debug_pub.add(  'EXITING OE_OE_FORM_LINE.GET_LINE' , 1 ) ;
663     END IF;
664 
665     IF p_db_record THEN
666 
667         RETURN g_db_line_rec;
668 
669     ELSE
670 
671         RETURN g_line_rec;
672 
673     END IF;
674 
675 END Get_Line;
676 
677 -- Fix for bug 2259556.This procedure is now coded to take care of mass order cancellation.
678 Procedure Cancel_Remaining_Order(p_num_of_records IN NUMBER,
679                   p_record_ids IN OE_GLOBALS.Selected_Record_Tbl, --MOAC
680 x_return_status OUT NOCOPY VARCHAR2,
681 
682                     p_cancellation_comments IN VARCHAR2,
683                     p_reason_code          IN VARCHAR2,
684 x_msg_count OUT NOCOPY NUMBER,
685 
686 x_msg_data OUT NOCOPY VARCHAR2)IS
687 
688 l_header_rec OE_ORDER_PUB.header_rec_type :=
689 		oe_order_pub.g_miss_header_rec;
690 l_api_name varchar2(30) := 'Cancel Remaining Order';
691 l_header_id         Number;
692 j Integer;
693 initial Integer;
694 nextpos Integer;
695 l_record_ids  OE_GLOBALS.Selected_Record_Tbl := p_record_ids ;
696 l_num_of_records number;
697 
698 --
699 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
700 --
701 
702 l_orgid number;
703 BEGIN
704          l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;
705 IF l_debug_level  > 0 THEN
706     oe_debug_pub.add(  'num of IDS '||TO_CHAR ( P_NUM_OF_RECORDS ) , 1 ) ;
707 END IF;
708 /* Not required with MOAC changes
709          j := 1.0;
710          initial := 1.0;
711          nextpos := INSTR(l_record_ids,',',1,j) ;
712 */
713          l_num_of_records := p_num_of_records;
714 FOR i IN 1..l_num_of_records LOOP
715         SAVEPOINT Cancel_Remaining_Order;
716  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
717    	IF l_orgid is null OR l_record_ids(i).org_id <> l_orgid THEN
718 		l_orgid := l_record_ids(i).Org_Id;
719 
720  Mo_Global.Set_Policy_Context (p_access_mode => 'S',
721                                p_org_id      => l_record_ids(i).Org_Id);
722 
723 	END IF;
724 
725  l_header_id := l_record_ids(i).id1;
726  IF l_debug_level  > 0 THEN
727      oe_debug_pub.add(  'INSTR'||TO_CHAR ( L_HEADER_ID ) , 1 ) ;
728  END IF;
729 
730 /* Not required with MOAC changes
731  initial := nextpos + 1.0;
732  j := j + 1.0;
733  nextpos := INSTR(l_record_ids,',',1,j) ;
734 */
735 
736          OE_Header_Util.Query_Row
737         (   p_header_id                   => l_header_id,
738             x_header_rec                  =>l_header_rec
739         );
740 
741 		 l_header_rec.change_reason := p_reason_code;
742 		l_header_rec.change_comments := p_cancellation_comments;
743 
744 oe_sales_can_util.Cancel_Remaining_Order
745     (p_header_rec        => l_header_rec,
746      p_header_id         => l_header_id
747 ,   x_return_status      => x_return_status
748 );
749 
750        IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
751                IF l_debug_level  > 0 THEN
752                    oe_debug_pub.add(  'INTO CANCELATION UNEXPECTED FAILURE' ) ;
753                END IF;
754                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
755        ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
756                IF l_debug_level  > 0 THEN
757                    oe_debug_pub.add(  'INTO CANCELLATION EXPECTED FAILURE' ) ;
758                END IF;
759         OE_MSG_PUB.Count_And_Get
760             ( p_count => x_msg_count,
761               p_data  => x_msg_data
762             );
763 
764          /* Fix Bug # 3000720: If there is an error, everything must rollback */
765          RAISE FND_API.G_EXC_ERROR;
766        END IF;
767 
768 END LOOP;
769 
770 EXCEPTION  /* Procedure exception handler */
771 
772 WHEN FND_API.G_EXC_ERROR THEN
773         x_return_status := FND_API.G_RET_STS_ERROR ;
774         OE_MSG_PUB.Count_And_Get
775             ( p_count => x_msg_count,
776               p_data  => x_msg_data
777             );
778         ROLLBACK TO SAVEPOINT Cancel_Remaining_Order;
779  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
780         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
781         OE_MSG_PUB.Count_And_Get
782             ( p_count => x_msg_count,
783               p_data  => x_msg_data
784             );
785  WHEN OTHERS THEN
786         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
787         IF OE_MSG_PUB.Check_Msg_Level
788             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
789         THEN
790              OE_MSG_PUB.Add_Exc_Msg
791                     (G_PKG_NAME,
792                      l_api_name
793                 );
794         END IF;
795         OE_MSG_PUB.Count_And_Get
796             ( p_count => x_msg_count,
797               p_data  => x_msg_data);
798        ROLLBACK TO SAVEPOINT Cancel_Remaining_Order;
799 
800 END cancel_remaining_order;
801 
802 Procedure Call_Process_Order ( p_line_tbl IN OE_ORDER_PUB.LINE_TBL_TYPE,
803 			       p_old_line_tbl IN OE_ORDER_PUB.LINE_TBL_TYPE,
804 				x_return_status  OUT NOCOPY VARCHAR2)
805 IS
806 
807 l_line_tbl OE_ORDER_PUB.LINE_TBL_TYPE := p_line_tbl;
808 l_old_line_tbl OE_ORDER_PUB.LINE_TBL_TYPE := p_old_line_tbl;
809 x_msg_count number;
810 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
811 x_msg_data varchar2(32000);
812 l_control_rec         OE_GLOBALS.Control_Rec_Type;
813 l_api_name            CONSTANT VARCHAR2(30) := 'Call_Process_Order';
814 BEGIN
815 
816   IF l_debug_level  > 0 THEN
817       oe_debug_pub.add(  'BEFORE CALLING PROCESSS ORDER LINES PROCEDURE' , 1 ) ;
818   END IF;
819 
820 		x_return_status := FND_API.G_RET_STS_SUCCESS;
821 
822 
823   --  Call OE_Order_PVT.Process_order
824   IF l_debug_level  > 0 THEN
825       oe_debug_pub.add(  'CALLING PROCESS ORDER' , 1 ) ;
826   END IF;
827       oe_order_pvt.Lines
828   (   p_validation_level  =>    FND_API.G_VALID_LEVEL_NONE
829   ,   p_control_rec       => l_control_rec
830   ,   p_x_line_tbl         =>  l_line_tbl
831   ,   p_x_old_line_tbl    =>  l_old_line_tbl
832   ,   x_return_status     => x_return_status
833   );
834 
835   IF l_debug_level  > 0 THEN
836       oe_debug_pub.add(  'AFTER CALLING LINES PROCEDURE' , 1 ) ;
837   END IF;
838 
839   IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
840     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
841   ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
842     RAISE FND_API.G_EXC_ERROR;
843   END IF;
844 
845   OE_Order_PVT.Process_Requests_And_Notify
846           ( p_process_requests          => TRUE
847           , p_notify                    => TRUE
848           , x_return_status             => x_return_status
849           , p_line_tbl                  => l_line_tbl
850           , p_old_line_tbl             => l_old_line_tbl
851           );
852   IF l_debug_level  > 0 THEN
853       oe_debug_pub.add(  'AFTER CALLING PROCESSE' , 1 ) ;
854   END IF;
855 
856   OE_MSG_PUB.Count_And_Get
857             ( p_count => x_msg_count,
858               p_data  => x_msg_data
859             );
860 
861   x_return_status  := x_return_status;
862 
863   IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
864     IF l_debug_level  > 0 THEN
865         oe_debug_pub.add(  'INTO CANCELATION UNEXPECTED FAILURE' ) ;
866     END IF;
867     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
868   ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
869     IF l_debug_level  > 0 THEN
870         oe_debug_pub.add(  'INTO CANCELLATION EXPECTED FAILURE' ) ;
871     END IF;
872     RAISE FND_API.G_EXC_ERROR;
873   END IF;
874 
875   IF l_debug_level  > 0 THEN
876       oe_debug_pub.add(  x_RETURN_STATUS ) ;
877   END IF;
878 
879 EXCEPTION  /* Procedure exception handler */
880 
881  WHEN FND_API.G_EXC_ERROR THEN
882         x_return_status := FND_API.G_RET_STS_ERROR ;
883         OE_MSG_PUB.Count_And_Get
884             ( p_count => x_msg_count,
885               p_data  => x_msg_data
886             );
887 
888  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
889         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
890         OE_MSG_PUB.Count_And_Get
891             ( p_count => x_msg_count,
892               p_data  => x_msg_data
893             );
894  WHEN OTHERS THEN
895         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
896         IF OE_MSG_PUB.Check_Msg_Level
897             (OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
898         THEN
899              OE_MSG_PUB.Add_Exc_Msg
900                     (G_PKG_NAME,
901                      l_api_name
902                 );
903         END IF;
904         OE_MSG_PUB.Count_And_Get
905             ( p_count => x_msg_count,
906               p_data  => x_msg_data);
907 
908 END Call_Process_Order;
909 
910 END OE_OE_FORM_CANCEL_LINE;