DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_CONFIG_UTIL

Source


1 PACKAGE BODY OE_CONFIG_UTIL AS
2 /* $Header: OEXUCFGB.pls 120.45.12020000.3 2013/03/15 12:08:32 sahvivek ship $ */
3 
4 --  Global constant holding the package name
5 G_PKG_NAME      CONSTANT    VARCHAR2(30):='Oe_Config_Util';
6 
7 /*-----------------------------------------------------------------
8 forward declarations
9 ------------------------------------------------------------------*/
10 PROCEDURE Query_Config
11 ( p_link_to_line_id     IN  NUMBER := FND_API.G_MISS_NUM
12   , p_top_model_line_id   IN  NUMBER := FND_API.G_MISS_NUM
13   , p_ato_line_id         IN  NUMBER := FND_API.G_MISS_NUM
14   , x_line_tbl            OUT NOCOPY OE_ORDER_PUB.line_tbl_type);
15 
16 Procedure get_transaction_id(p_caller   IN  VARCHAR2);
17 
18 PROCEDURE Print_Time(p_msg   IN  VARCHAR2);
19 
20 PROCEDURE Log_Included_Item_Requests
21 ( p_line_tbl    IN  OE_Order_Pub.Line_Tbl_Type
22  ,p_booked_flag IN  VARCHAR2);
23 
24 PROCEDURE  Unlock_Config
25 (p_line_rec  IN OE_ORDER_PUB.line_rec_type,
26  x_return_status OUT NOCOPY VARCHAR2);
27 
28 /*-------------------------------------------------------------------------
29 Procedure Name : Config_Exists
30 Description    :
31 --------------------------------------------------------------------------*/
32 
33 FUNCTION Config_Exists(p_line_rec IN OE_ORDER_PUB.line_rec_type)
34 RETURN BOOLEAN
35 IS
36 --
37 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
38 --
39 BEGIN
40    RETURN TRUE;
41 END Config_Exists;
42 
43 /*------------------------------------------------------------------------
44 Procedure Name : Complete_Config
45 Description    : This procedure will cascade the quantity change from the
46                  parent to all it's children. Currently, implementing it
47                  as a single update statement.
48 ------------------------------------------------------------------------ */
49 Procedure Complete_Config
50 ( p_top_model_line_id IN  NUMBER
51 , x_return_status     OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
52 IS
53 --
54 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
55 --
56 BEGIN
57   -- Complete Config Config Using the BOM_EXPLOSIONS
58   -- Populate link_to_line_id
59   -- Populate ato_line_id
60   NULL;
61 END;
62 
63 
64 /*------------------------------------------------------------------------
65 Procedure Name : Cascade_Changes
66 Description    : This procedure will cascade the attribute changes from the
67                  top most parent to all it's children, including the
68                  included items, even if they are under a class of the
69                  top parent. If a parameter is passed with
70                  value other than null(te default of the params is null),
71                  it indicate that the colums has changed on top parent
72                  and needs to be cascaded.
73 
74 Change Record:
75 2031256: To populated shipped_quantity and actual_shipment_date
76 on ato child lines.
77 
78 Dropship fro config : cascade source type for ato: param15
79 ------------------------------------------------------------------------ */
80 
81 
82 Procedure Cascade_Changes
83 ( p_parent_line_id     IN  NUMBER,
84   p_request_rec        IN  OE_Order_Pub.Request_Rec_Type,
85   x_return_status      OUT NOCOPY /* file.sql.39 change */ VARCHAR2
86 )
87 
88 IS
89     -- params sent in request rec.
90     l_item_type_code       VARCHAR2(30)  := p_request_rec.param7;
91     l_child_item_type      VARCHAR2(30);
92     l_old_quantity         NUMBER        := to_number(p_request_rec.param1);
93     l_new_quantity         NUMBER        := to_number(p_request_rec.param2);
94     l_change_reason        VARCHAR2(100) := p_request_rec.param3;
95     l_change_comments      VARCHAR2(2000) := p_request_rec.param4;   -- 4495205
96     l_project_id           NUMBER        := to_number(p_request_rec.param5);
97     l_task_id              NUMBER        := to_number(p_request_rec.param6);
98     l_ship_tolerance_above NUMBER        := to_number(p_request_rec.param11);
99     l_ship_tolerance_below NUMBER        := to_number(p_request_rec.param12);
100     l_ship_quantity        NUMBER        := to_number(p_request_rec.param9);
101     l_set_zero             VARCHAR2(1)   := 'N';
102     l_ship_to_org_id       NUMBER        := to_number(p_request_rec.param14);
103     l_request_date         DATE          := p_request_rec.date_param1;
104     l_promise_date         DATE          := p_request_rec.date_param2;
105 /* Added the following parameter to fix the bug 2217336 */
106     l_freight_terms_code   VARCHAR2(100) := p_request_rec.param16;
107     l_ratio                NUMBER;
108     child_line_id          NUMBER;
109     l_inv_item_id          NUMBER;
110     l_ordered_qty          NUMBER;
111     l_shipped_qty          NUMBER;
112     l_model_line_id        NUMBER;
113     l_model_qty            NUMBER;
114     l_model_actual_ship_date   DATE;
115     l_parent_line_rec           OE_ORDER_PUB.Line_Rec_Type;
116     l_header_id            NUMBER := 0;
117 
118 
119     -- process_order in variables
120     l_control_rec              OE_GLOBALS.Control_Rec_Type;
121     l_header_rec               OE_Order_PUB.Header_Rec_Type;
122     l_line_rec                 OE_ORDER_PUB.Line_Rec_Type
123                                := OE_ORDER_PUB.G_MISS_LINE_REC;
124     l_old_line_tbl             OE_Order_PUB.Line_Tbl_Type;
125     l_line_tbl                 OE_Order_PUB.Line_Tbl_Type;
126     l_return_status            VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
127     l_line_count               NUMBER;
128     l_queried_quantity         NUMBER;
129 
130     CURSOR children is
131     SELECT line_id, inventory_item_id, ordered_quantity, item_type_code,
132            shipped_quantity
133     FROM   oe_order_lines
134     WHERE header_id = l_header_id
135     AND   open_flag = 'Y'
136     AND  ((top_model_line_id = p_parent_line_id
137            and line_id <> p_parent_line_id)
138           OR
139           (l_item_type_code  = OE_GLOBALS.G_ITEM_CLASS
140            and ato_line_id = p_parent_line_id
141            and line_id <> p_parent_line_id ));
142 
143 -- parent_line_id is either top_model_line_id for models and kits
144 -- or it can be class only for ato sub configs
145 -- in 2nd case we will get children using ato_line_id as a link.
146 
147 --
148 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
149 --
150 BEGIN
151 
152   IF l_debug_level  > 0 THEN
153     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.CASCADE_CHANGES' , 1);
154     oe_debug_pub.add('MODEL OLD QTY: ' ||L_OLD_QUANTITY , 2 );
155     oe_debug_pub.add('MODEL NEW QTY: ' ||L_NEW_QUANTITY , 2 );
156   END IF;
157 
158   IF l_old_quantity = 0 THEN
159     IF l_debug_level  > 0 THEN
160       oe_debug_pub.add('CASCADE_CHANGES RETURNING , SINCE OLD QTY = 0' , 1);
161     END IF;
162     x_return_status := l_return_status;
163     RETURN;
164   END IF;
165 
166   -- insted of modifying cursor, querying the line,
167   -- so that code remains clean.
168 
169   OE_Line_Util.Lock_Row( p_line_id       => p_parent_line_id
170                         ,p_x_line_rec    => l_parent_line_rec
171                         ,x_return_status => l_return_status);
172 
173   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
174         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
175   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
176         RAISE FND_API.G_EXC_ERROR;
177   END IF;
178 
179   IF l_item_type_code  = OE_GLOBALS.G_ITEM_MODEL THEN
180      l_model_actual_ship_date := l_parent_line_rec.actual_shipment_date;
181      l_model_qty              := l_parent_line_rec.ordered_quantity;
182   END IF;
183 
184   -- 3603308
185   -- Query to get header_id and order_qty is removed
186   l_header_id := l_parent_line_rec.header_id;
187   l_queried_quantity := l_parent_line_rec.ordered_quantity;
188 
189   IF l_new_quantity <> FND_API.G_MISS_NUM  THEN
190      IF l_debug_level > 0 THEN
191         OE_DEBUG_PUB.Add('New Quantity is not missing');
192      END IF;
193      l_new_quantity := l_queried_quantity;
194   END IF;
195 
196   IF l_debug_level > 0 THEN
197      oe_debug_pub.add('Before opening cursor...',3);
198      oe_debug_pub.add('Hdr ID:'||l_header_id,3);
199      oe_debug_pub.add('Proj:'||l_project_id||' Task Id:'||l_task_id,3);
200      oe_debug_pub.add('New Qty:'||l_new_quantity,3);
201      oe_debug_pub.add('Parent Line:'||p_parent_line_id,3);
202   END IF;
203 
204   -- actual processing starts.
205 
206   l_line_count := 0;
207   OPEN children ;
208   LOOP
209     FETCH children into child_line_id, l_inv_item_id,
210           l_ordered_qty, l_child_item_type, l_shipped_qty;
211     EXIT when children%NOTFOUND;
212 
213         l_line_count                 := l_line_count + 1;
214         l_line_rec                   := OE_ORDER_PUB.G_MISS_LINE_REC;
215         l_line_rec.line_id           := child_line_id;
216         l_line_rec.inventory_item_id := l_inv_item_id;
217         l_line_rec.ordered_quantity  := l_ordered_qty;
218         l_line_rec.shipped_quantity  := l_shipped_qty;
219         l_line_rec.item_type_code    := l_child_item_type;
220         l_line_tbl(l_line_count)     := l_line_rec;
221   END LOOP;
222 
223   IF l_line_count = 0 THEN
224     IF l_debug_level  > 0 THEN
225       oe_debug_pub.add('EXITING OE_CONFIG_UTIL.CASCADE_CHANGES' , 1);
226       oe_debug_pub.add('NO ROWS TO CASCADE' , 2 );
227     END IF;
228     RETURN;
229   END IF;
230 
231   IF l_debug_level  > 0 THEN
232     oe_debug_pub.add('NO OF LINES TO CASCADE: '
233                       || L_LINE_TBL.COUNT || P_REQUEST_REC.PARAM13 , 2 );
234     oe_debug_pub.add(L_NEW_QUANTITY || ' ' || L_ITEM_TYPE_CODE , 1);
235   END IF;
236 
237   IF l_new_quantity = 0 AND
238      (l_item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
239       l_item_type_code = OE_GLOBALS.G_ITEM_KIT)
240   THEN
241     IF l_debug_level  > 0 THEN
242       oe_debug_pub.add('DO NOT SUPRESS SCHEDULING' , 3 );
243     END IF;
244     l_set_zero := 'Y';
245   END IF;
246 
247   FOR I IN 1..l_line_tbl.count LOOP
248 
249     -- 1. ordered quantity
250 
251     IF l_new_quantity = 0    AND
252        p_request_rec.param13 = 'N' AND
253        (l_item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
254         l_item_type_code = OE_GLOBALS.G_ITEM_KIT)
255     THEN
256       IF l_line_tbl(I).item_type_code <> OE_GLOBALS.G_ITEM_CONFIG THEN
257         IF l_debug_level  > 0 THEN
258           oe_debug_pub.add('NEW QTY 0 ,NOT CANCELLATION ,SO DELETE',1);
259         END IF;
260         l_line_tbl(I).operation  := OE_GLOBALS.G_OPR_DELETE;
261       ELSE
262         l_line_tbl(I).operation  := OE_GLOBALS.G_OPR_NONE;
263       END IF;
264 
265     ELSE -- cancellation
266 
267       l_line_tbl(I).OPERATION := OE_GLOBALS.G_OPR_UPDATE;
268 
269       -- if qty becomes 0, the options will get cancelled eventually.
270       IF l_debug_level  > 0 THEN
271         oe_debug_pub.add('REGULAR CODE , BIG ELSE' , 1);
272       END IF;
273 
274       IF (l_line_tbl(I).item_type_code = OE_GLOBALS.G_ITEM_CONFIG AND
275           l_new_quantity = 0)
276       THEN
277         IF l_debug_level  > 0 THEN
278           oe_debug_pub.add('DO NOT CASCADE' , 3 );
279         END IF;
280         l_line_tbl(I).operation  := OE_GLOBALS.G_OPR_NONE;
281       ELSE
282 
283         IF  l_old_quantity <> l_new_quantity AND
284             (l_item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
285              l_item_type_code = OE_GLOBALS.G_ITEM_KIT)
286         THEN
287           IF l_debug_level  > 0 THEN
288             oe_debug_pub.add('CASCADE_CHANGES , OLD_ORD_QTY: '
289                              ||L_LINE_TBL (I).ORDERED_QUANTITY , 2 );
290           END IF;
291 
292           l_line_tbl(I).ordered_quantity  :=
293              (l_line_tbl(I).ordered_quantity/l_old_quantity) * l_new_quantity;
294 
295           /* Start Audit Trail */
296           l_line_tbl(I).change_reason    := 'SYSTEM';
297           /* End Audit Trail */
298 
299           IF l_debug_level  > 0 THEN
300             oe_debug_pub.add(L_LINE_TBL (I).LINE_ID||':'
301                              ||L_LINE_TBL (I).INVENTORY_ITEM_ID , 2 );
302             oe_debug_pub.add('NEW_ORD_QTY: '
303                              ||L_LINE_TBL (I).ORDERED_QUANTITY , 2 );
304           END IF;
305         END IF;
306 
307       END IF; -- qry cancellation cascade
308 
309 
310       -- 2. project and task.
311 
312       IF nvl(l_project_id, -1) <> FND_API.G_MISS_NUM THEN
313          l_line_tbl(I).project_id        := l_project_id;
314          IF l_debug_level  > 0 THEN
315            oe_debug_pub.add('PROJECT_ID CASCADED, L_LINE_TBL (I).LINE_ID: '
316                              || L_PROJECT_ID , 2 );
317          END IF;
318       END IF;
319 
320       IF nvl(l_task_id, -1) <> FND_API.G_MISS_NUM THEN
321          l_line_tbl(I).task_id := l_task_id;
322          IF l_debug_level  > 0 THEN
323            oe_debug_pub.add('TASK_ID CASCADED FOR,L_LINE_TBL (I).LINE_ID: '
324                              || L_TASK_ID , 2 );
325          END IF;
326       END IF;
327 
328 
329       -- 3. ship_tolerance_above and below
330 
331       IF nvl(l_ship_tolerance_above, -1) <> FND_API.G_MISS_NUM THEN
332          l_line_tbl(I).ship_tolerance_above  := l_ship_tolerance_above;
333       END IF;
334 
335       IF nvl(l_ship_tolerance_below, -1) <> FND_API.G_MISS_NUM THEN
336          l_line_tbl(I).ship_tolerance_below  := l_ship_tolerance_below;
337       END IF;
338 
339 
340       -- 4. shipped_quantity and actual_shipment_date
341 
342       IF nvl(l_ship_quantity, -1) <> FND_API.G_MISS_NUM THEN
343          IF l_line_tbl(I).shipped_quantity is null THEN
344            l_line_tbl(I).shipped_quantity  :=
345            (l_line_tbl(I).ordered_quantity / l_model_qty) * l_ship_quantity;
346             l_line_tbl(I).actual_shipment_date :=  l_model_actual_ship_date;
347 
348           IF l_debug_level  > 0 THEN
349              oe_debug_pub.add('CASCADED SHIPPED QTY , L_LINE_TBL (I).LINE_ID: '
350                               || L_LINE_TBL (I).SHIPPED_QUANTITY , 2 );
351              oe_debug_pub.add('CASCADED ACT_SHIP_DATE '
352                               || L_LINE_TBL (I).ACTUAL_SHIPMENT_DATE , 2 );
353           END IF;
354         END IF;
355       END IF;
356 
357 
358       -- 5. ship_to_org_id and request_date
359 
360       IF nvl(l_ship_to_org_id, -1)<> FND_API.G_MISS_NUM THEN
361          l_line_tbl(I).ship_to_org_id        := l_ship_to_org_id;
362          IF l_debug_level  > 0 THEN
363            oe_debug_pub.add('SHIP TO CASCADED , LINE_ID: '
364                              || L_SHIP_TO_ORG_ID , 2 );
365          END IF;
366       END IF;
367 
368       IF nvl(l_request_date, sysdate) <> FND_API.G_MISS_DATE THEN
369          l_line_tbl(I).request_date        := l_request_date;
370          IF l_debug_level  > 0 THEN
371            oe_debug_pub.add('REQUEST_DATE CASCADED , REQUEST_DATE: '
372                              || L_REQUEST_DATE , 2 );
373          END IF;
374       END IF;
375 
376       -- 6. source_type_code for ato configurations.
377 
378       IF nvl(p_request_rec.param15, 'X')<> FND_API.G_MISS_CHAR THEN
379          l_line_tbl(I).source_type_code     := p_request_rec.param15;
380          IF l_debug_level  > 0 THEN
381            oe_debug_pub.add('SOURCE_TYPE CASCADED: '
382                             || P_REQUEST_REC.PARAM15 , 2 );
383          END IF;
384       END IF;
385 
386 
387 /* Added the following logic to fix the bug 2217336 */
388       -- 7. freight_terms_code for ato configurations.
389 
390       IF nvl(l_freight_terms_code, 'X')<> FND_API.G_MISS_CHAR THEN
391          l_line_tbl(I).freight_terms_code     :=  l_freight_terms_code ;
392          IF l_debug_level  > 0 THEN
393            oe_debug_pub.add('FREIGHT_TERMS_CODE CASCADED: '
394                              || L_FREIGHT_TERMS_CODE , 2 );
395          END IF;
396       END IF;
397 
398       --  8. Promise date
399 
400            IF nvl(l_promise_date, sysdate) <> FND_API.G_MISS_DATE THEN
401              l_line_tbl(I).promise_date        := l_promise_date;
402               IF l_debug_level  > 0 THEN
403                 oe_debug_pub.add('PROMISE DATE OCASCADED , PROMISE_DATE: '
404                                  || L_PROMISE_DATE , 2 );
405               END IF;
406           END IF;
407 
408     END IF; -- if cancellation.
409 
410   END LOOP;
411 
412 
413   -- Call Process Order to update the record.
414 
415   --  Set control flags.
416 
417   l_control_rec.controlled_operation := TRUE;
418   l_control_rec.change_attributes    := TRUE;
419   l_control_rec.default_attributes   := TRUE;
420   l_control_rec.validate_entity      := TRUE;
421   l_control_rec.check_security       := TRUE;
422   l_control_rec.write_to_DB          := TRUE;
423   l_control_rec.validate_entity      := TRUE;
424   l_control_rec.process              := FALSE;
425   l_control_rec.clear_dependents     := TRUE;
426 
427   --  Instruct API to retain its caches
428 
429   l_control_rec.clear_api_cache      := FALSE;
430   l_control_rec.clear_api_requests   := FALSE;
431 
432   l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;
433 
434   -- Set the Recursive Call Constant to 'Y' to avoid the recursive
435   -- call to cascading while making this call to process order
436 
437   OE_CONFIG_UTIL.CASCADE_CHANGES_FLAG := 'Y';
438 
439   -- Set the Validate_config Call Constant to 'N' to avoid the validation
440 
441   OE_CONFIG_PVT.OECFG_VALIDATE_CONFIG := 'N';
442 
443   -- Set the scheduling flag to 'N', do not schedule in a recursive call.
444 
445   -- bug fix 1607036
446   IF l_set_zero = 'N' AND
447      nvl(l_parent_line_rec.ship_model_complete_flag, 'Y') <> 'N'
448   THEN
449     IF l_debug_level  > 0 THEN
450       oe_debug_pub.add('SCHEDULE FLAG SET TO N' , 5 );
451     END IF;
452     -- 4504362
453     OE_SCHEDULE_UTIL.OESCH_PERFORM_SCHEDULING := 'N';
454     OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'N';
455   END IF;
456 
457   IF l_debug_level  > 0 THEN
458     oe_debug_pub.add('CALLING PROCESS ORDER' , 2 );
459   END IF;
460 
461   --  Call OE_Order_PVT.Process_order
462 
463    OE_ORDER_PVT.Lines
464    (p_validation_level         => FND_API.G_VALID_LEVEL_NONE
465    ,p_control_rec              => l_control_rec
466    ,p_x_line_tbl               => l_line_tbl
467    ,p_x_old_line_tbl           => l_old_line_tbl
468    ,x_return_status            => l_return_status);
469 
470 
471   IF l_debug_level  > 0 THEN
472     oe_debug_pub.add('IN CASCADE CHANGES AFTER CALLING PROCESS ORDER' , 2 );
473     oe_debug_pub.add('L_RETURN_STATUS IS ' || L_RETURN_STATUS , 1);
474   END IF;
475 
476   -- Resetting the Recursive Call Constant to 'N'
477   OE_CONFIG_UTIL.CASCADE_CHANGES_FLAG := 'N';
478 
479   -- Resetting the Validation Constant to 'Y'
480   OE_CONFIG_PVT.OECFG_VALIDATE_CONFIG := 'Y';
481 
482   -- Set it back to 'Y'
483   -- 4504362
484   OE_SCHEDULE_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
485   OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
486 
487   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
488         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
489   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
490         RAISE FND_API.G_EXC_ERROR;
491   END IF;
492 
493   -- process_order call successful, and this was decrement to 0.
494   IF l_set_zero = 'Y'  THEN
495 
496     -- Instance Unlocking.
497 
498     IF l_debug_level  > 0 THEN
499         oe_debug_pub.add('Before calling Unlock_Config for parent line.' , 3 );
500     END IF;
501     IF l_parent_line_rec.item_type_code = 'MODEL'
502     AND l_parent_line_rec.Booked_flag = 'Y' THEN
503 
504        Unlock_Config(p_line_rec      => l_parent_line_rec,
505                      x_return_status => l_return_status);
506 
507         oe_debug_pub.add('After calling Unlock_Config for parent line ' || l_return_status , 3 );
508         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
509             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
510         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
511             RAISE FND_API.G_EXC_ERROR;
512         END IF;
513     END IF;
514     -- Instance Unlocking
515 
516     UPDATE oe_order_lines
517     SET    config_header_id = null,
518            config_rev_nbr   = null,
519            configuration_id = null,
520            lock_control     = lock_control + 1
521     WHERE  top_model_line_id = p_parent_line_id;
522 
523     IF SQL%FOUND THEN
524       IF l_debug_level  > 0 THEN
525         oe_debug_pub.add('CONFIG IDS SET TO NULL' , 3 );
526       END IF;
527     END IF;
528 
529     -- delete the SPC configuration data.
530     OE_Config_Pvt.Delete_Config
531     ( p_config_hdr_id   =>  l_parent_line_rec.config_header_id
532      ,p_config_rev_nbr  =>  l_parent_line_rec.config_rev_nbr
533      ,x_return_status   =>  l_return_status);
534 
535   END IF;
536 
537   OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
538 
539   /* added for 2653505 */
540   IF OE_CODE_CONTROL.get_code_release_level < '110508' THEN
541     OE_ORDER_PVT.Process_Requests_And_notify
542     ( p_process_requests       => FALSE
543      ,p_notify                 => TRUE
544      ,x_return_status          => l_return_status
545      ,p_line_tbl               => l_line_tbl
546      ,p_old_line_tbl           => l_old_line_tbl);
547 
548     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
549         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
550     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
551         RAISE FND_API.G_EXC_ERROR;
552     END IF;
553   END IF;
554 
555   x_return_status := l_return_status;
556 
557   IF l_debug_level  > 0 THEN
558     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.CASCADE_CHANGES' , 1);
559   END IF;
560 
561 EXCEPTION
562   WHEN OTHERS THEN
563     IF l_debug_level  > 0 THEN
564       oe_debug_pub.add('CASCADE_CHANGES ERROR '|| SQLERRM , 1);
565     END IF;
566     RAISE;
567 END;
568 
569 
570 /*----------------------------------------------------------------------
571 Procedure Name : Query_Config_Line
572 Description    :
573 -----------------------------------------------------------------------*/
574 
575 PROCEDURE Query_Config_Line
576 (p_parent_line_id IN NUMBER
577 ,x_line_rec       OUT NOCOPY OE_ORDER_PUB.line_rec_type)
578 IS
579  l_line_rec   OE_ORDER_PUB.line_rec_type;
580  --
581  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
582  --
583 BEGIN
584  x_line_rec := l_line_rec;
585 END;
586 
587 /*------------------------------------------------------------------------
588 Procedure Name : Change_Configuration
589 Description    : This procedure will change certain attributes across
590                  the whole configuration, when the attribute is changed
591                  even on one line of the configuration.
592                  E.g.: If the warehouse changes on a ATO option, all the
593                        lines of the ATO model should reflect the same
594                        warehouse. Same is true if the change took place
595                        on an option of a Ship model complete PTO.
596                        The attributes which we currently maintain same
597                        across an ATO or a SMC PTO are:
598                        1. Ship From Org
599                        2. Ship To Org
600                        3. Request Date
601                        4. Schedule Ship Date
602                 This procedure will be called only if the line is not
603                 scheduled. If the line is scheduled and any of the above
604                 attributes change, then scheduling code will take
605                 care of change across the configuration.
606 ------------------------------------------------------------------------ */
607 
608 Procedure Change_Configuration
609 ( p_request_rec        IN  OE_Order_Pub.Request_Rec_Type,
610   x_return_status      OUT NOCOPY /* file.sql.39 change */ VARCHAR2
611 )
612 
613 IS
614 -- params sent in request rec.
615 l_changed_line_rec              OE_ORDER_PUB.Line_Rec_Type;
616 l_top_model_line_id             NUMBER;
617 l_ato_line_id                   NUMBER;
618 l_line_id                       NUMBER;
619 l_count                         NUMBER:=0;
620 l_header_id                     NUMBER := 0;
621 
622 -- Process Order Variables
623 l_control_rec                   OE_GLOBALS.Control_Rec_Type;
624 l_header_rec                    OE_Order_PUB.Header_Rec_Type;
625 l_line_rec                      OE_ORDER_PUB.Line_Rec_Type
626                                 := OE_ORDER_PUB.G_MISS_LINE_REC;
627 l_line_tbl                      OE_Order_PUB.Line_Tbl_Type;
628 l_old_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
629 
630 l_return_status                 VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
631 
632     CURSOR configuration_line(p_header_id         IN NUMBER,
633                               p_top_model_line_id IN NUMBER,
634                               p_ato_line_id       IN NUMBER,
635                               p_line_id           IN NUMBER)
636     IS
637     SELECT line_id
638     FROM   oe_order_lines
639     WHERE((top_model_line_id = p_top_model_line_id
640            and line_id <> p_line_id)
641     OR    (ato_line_id  = p_ato_line_id and
642            line_id <> p_line_id ))
643     AND    open_flag = 'Y';
644 
645 -- parent_line_id is either top_model_line_id for models and kits
646 -- or it can be class only for ato sub configs
647 -- in 2nd case we will get children using ato_line_id as a link.
648 
649 --
650 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
651 --
652 BEGIN
653 
654    IF l_debug_level  > 0 THEN
655       oe_debug_pub.add('ENTERING OE_CONGIG_UTIL.CHANGE_CONFIGURATION' , 1);
656    END IF;
657 
658    -- insted of modifying cursor, querying the line,
659    -- so that code remains clean.
660 
661    OE_LINE_UTIL.Lock_Row(p_line_id       => p_request_rec.param1,
662                          p_x_line_rec    => l_changed_line_rec,
663                          x_return_status => l_return_status);
664 
665    IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
666       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
667    ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
668       RAISE FND_API.G_EXC_ERROR;
669    END IF;
670 
671    l_line_id   := l_changed_line_rec.line_id;
672    l_header_id := l_changed_line_rec.header_id;
673 
674    IF nvl(l_changed_line_rec.ship_model_complete_flag,'N') = 'N' THEN
675       l_ato_line_id       := l_changed_line_rec.ato_line_id;
676       l_top_model_line_id := null;
677    ELSE
678       l_top_model_line_id := l_changed_line_rec.top_model_line_id;
679       l_ato_line_id       := null;
680    END IF;
681 
682    OPEN configuration_line(l_header_id,
683                            l_top_model_line_id,
684                            l_ato_line_id,
685                            l_line_id);
686    LOOP
687       FETCH configuration_line into l_line_id;
688       EXIT when configuration_line%NOTFOUND;
689       l_line_rec                  := OE_ORDER_PUB.G_MISS_LINE_REC;
690       l_line_rec.line_id          := l_line_id;
691       l_line_rec.ship_from_org_id := l_changed_line_rec.ship_from_org_id;
692       l_line_rec.ship_to_org_id   := l_changed_line_rec.ship_to_org_id;
693       l_line_rec.request_date     := l_changed_line_rec.request_date;
694       l_line_rec.shipping_method_code
695          := l_changed_line_rec.shipping_method_code;
696       l_line_rec.freight_carrier_code
697          := l_changed_line_rec.freight_carrier_code;
698       l_line_rec.shipment_priority_code
699          := l_changed_line_rec.shipment_priority_code;
700       l_line_rec.demand_class_code := l_changed_line_rec.demand_class_code;
701 
702       -- Start Audit Trail
703       l_line_rec.change_reason    := 'SYSTEM';
704       -- End Audit Trail
705 
706       l_line_rec.OPERATION        := OE_GLOBALS.G_OPR_UPDATE;
707       l_count                     := l_count + 1;
708       l_line_tbl(l_count)         := l_line_rec;
709    END LOOP;
710 
711    IF l_count = 0 THEN
712       IF l_debug_level  > 0 THEN
713          oe_debug_pub.add('EXITING OE_CONGIG_UTIL.CHANGE_CONFIGURATION' , 1);
714          oe_debug_pub.add('NO ROWS TO PASS TO PROCESS_ORDER' , 2 );
715       END IF;
716       RETURN;
717    END IF;
718 
719    -- Call Process Order to update the record.
720 
721    --  Set control flags.
722 
723    l_control_rec.controlled_operation := TRUE;
724    l_control_rec.change_attributes    := TRUE;
725    l_control_rec.default_attributes   := TRUE;
726    l_control_rec.validate_entity      := TRUE;
727    l_control_rec.check_security       := TRUE; --FALSE;
728    l_control_rec.write_to_DB          := TRUE;
729    l_control_rec.validate_entity      := TRUE;
730    l_control_rec.process              := FALSE;
731    l_control_rec.clear_dependents     := TRUE;
732 
733    --  Instruct API to retain its caches
734 
735    l_control_rec.clear_api_cache      := FALSE;
736    l_control_rec.clear_api_requests   := FALSE;
737 
738    l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;
739 
740    -- Set the Change Configuration flag 'N' to avoid the recursive
741    -- call to changin configuration while making this call to process order
742    OE_GLOBALS.G_CHANGE_CFG_FLAG := 'N';
743 
744    -- Set recursion mode.
745    -- OE_GLOBALS.G_RECURSION_MODE := 'Y';
746 
747    -- Set the scheduling flag to 'N', do not schedule in a recursive call.
748    -- 4504362
749    OE_SCHEDULE_UTIL.OESCH_PERFORM_SCHEDULING := 'N';
750    OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'N';
751 
752    IF l_debug_level  > 0 THEN
753       oe_debug_pub.add('CALLING PROCESS ORDER WITH LINES: '
754                        || L_LINE_TBL.COUNT , 2 );
755    END IF;
756 
757    OE_ORDER_PVT.Lines
758       (p_validation_level         => FND_API.G_VALID_LEVEL_NONE
759        ,p_control_rec              => l_control_rec
760        ,p_x_line_tbl               => l_line_tbl
761        ,p_x_old_line_tbl           => l_old_line_tbl
762        ,x_return_status            => l_return_status);
763 
764 
765    -- Set it back to 'Y'
766    -- 4504362
767    OE_SCHEDULE_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
768    OE_ORDER_SCH_UTIL.OESCH_PERFORM_SCHEDULING := 'Y';
769 
770    -- Resetting the Change Configuration flag 'Y'
771    OE_GLOBALS.G_CHANGE_CFG_FLAG := 'Y';
772 
773    -- Resetting the Recursive Call Constant to 'N'
774    OE_CONFIG_UTIL.CASCADE_CHANGES_FLAG := 'N';
775 
776    -- ReSet recursion mode.
777    --OE_GLOBALS.G_RECURSION_MODE := 'N';
778 
779    IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
780       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
781    ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
782       RAISE FND_API.G_EXC_ERROR;
783    END IF;
784 
785    -- added for 2653505
786    IF OE_CODE_CONTROL.get_code_release_level < '110508' THEN
787       OE_ORDER_PVT.Process_Requests_And_notify
788          ( p_process_requests       => FALSE
789            ,p_notify                 => TRUE
790            ,x_return_status          => l_return_status
791            ,p_line_tbl               => l_line_tbl
792            ,p_old_line_tbl           => l_old_line_tbl);
793 
794       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
795          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
796       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
797          RAISE FND_API.G_EXC_ERROR;
798       END IF;
799    END IF;
800 
801    -- Setting G_CASCADING_REQUEST_LOGGED to requery the lines in the form
802    -- not reqd, done in vreqb.
803    OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
804 
805    x_return_status := l_return_status;
806 
807    IF l_debug_level  > 0 THEN
808       oe_debug_pub.add('EXITING OE_CONGIG_UTIL.CHANGE_CONFIGURATION' , 1);
809    END IF;
810 
811 END Change_Configuration;
812 
813 /*----------------------------------------------------------------------
814 Procedure Name : Delink_Config
815 Description    :
816 -----------------------------------------------------------------------*/
817 Procedure Delink_Config
818 ( p_line_id         IN  NUMBER
819 , x_return_status   OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
820 IS
821 
822 -- process_order in variables
823 l_control_rec                   OE_GLOBALS.Control_Rec_Type;
824 l_header_rec                    OE_Order_PUB.Header_Rec_Type;
825 l_line_rec                      OE_ORDER_PUB.Line_Rec_Type
826                                 := OE_ORDER_PUB.G_MISS_LINE_REC;
827 l_old_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
828 l_line_tbl                      OE_Order_PUB.Line_Tbl_Type;
829 
830 l_return_status                 VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
831 l_msg_count                     NUMBER;
832 l_msg_data                      VARCHAR2(2000);
833 
834 l_line_num        VARCHAR2(20);
835 l_po_header_id    NUMBER;
836 --bug 4411054
837 --l_po_status             VARCHAR2(4100);
838 l_po_status_rec         PO_STATUS_REC_TYPE;
839 l_autorization_status   VARCHAR2(30);
840 
841 --
842 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
843 --
844 BEGIN
845      OE_LINE_UTIL.Lock_Row(p_line_id       => p_line_id
846                           ,p_x_line_rec    => l_line_rec
847                           ,x_return_status => l_return_status);
848 
849     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
850        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
851     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
852        RAISE FND_API.G_EXC_ERROR;
853     END IF;
854 
855     IF l_debug_level  > 0 THEN
856       oe_debug_pub.add('ENTERING OE_CONGIG_UTIL.DELINK_CONFIG' , 1);
857     END IF;
858 
859     -- Changes for Enhanced DropShipments. Prevent Delink
860     -- if the PO associated with config item is Approved.
861 
862     -- #5252929, the following PO-APPROVED check is now disabled.  Now the
863     -- check is done only when user chooses Action->Delink from the SO pad
864     -- and that check is done in OEXOECFG.pld.
865     -- Here we donot want to check becuase the constraint check is already
866     -- done at the Model level.   If the user disables that constarint then
867     -- the delink should take place.  Please see bug for further details.
868 
869    /*  IF PO_CODE_RELEASE_GRP.Current_Release >=
870        PO_CODE_RELEASE_GRP.PRC_11i_Family_Pack_J AND
871             OE_CODE_CONTROL.Get_Code_Release_Level  >= '110510' AND
872                               l_line_rec.source_type_code = 'EXTERNAL' THEN
873 
874          BEGIN
875               SELECT po_header_id
876               INTO   l_po_header_id
877               FROM   oe_drop_ship_sources
878               WHERE  line_id    = l_line_rec.line_id
879               AND    header_id  = l_line_rec.header_id;
880          EXCEPTION
881               WHEN NO_DATA_FOUND THEN
882                    IF l_debug_level  > 0 THEN
883                       OE_DEBUG_PUB.Add('PO Not Created for Config.:'||
884                                                   l_line_rec.line_id , 2 );
885                    END IF;
886          END;
887 
888          IF l_po_header_id is not null THEN
889 
890                PO_DOCUMENT_CHECKS_GRP.po_status_check
891                                 (p_api_version => 1.0
892                                 , p_header_id => l_po_header_id
893                                 , p_mode => 'GET_STATUS'
894                                 , x_po_status_rec => l_po_status_rec
895                                 , x_return_status => l_return_status);
896 
897                IF(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
898                     l_autorization_status := l_po_status_rec.authorization_status(1);
899 
900                     IF l_debug_level > 0 THEN
901                         OE_DEBUG_PUB.Add('Sucess call from PO_DOCUMENT_CHECKS_GRP.po_status_check',2);
902                	 	OE_DEBUG_PUB.Add('Check PO Status : '|| l_autorization_status, 2);
903              	     END IF;
904        		ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
905              	     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
906        		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
907                      RAISE FND_API.G_EXC_ERROR;
908        		END IF;
909 
910          END IF;
911 
912          --IF (INSTR(nvl(l_po_status,'z'), 'APPROVED') <> 0 ) THEN
913          IF (nvl(l_autorization_status,'z')= 'APPROVED') THEN
914               l_line_num :=  RTRIM(l_line_rec.line_number||'.'||
915                              l_line_rec.shipment_number||'.'||
916                              l_line_rec.option_number||'.'||
917                              l_line_rec.component_number||'.'||
918                              l_line_rec.service_number,'.');
919               FND_MESSAGE.Set_Name('ONT', 'ONT_DELINK_NOT_ALLOWED');
920               FND_MESSAGE.Set_Token('LINE_NUM', l_line_num);
921               FND_MESSAGE.Set_Token('MODEL', l_line_rec.ordered_item);
922               OE_MSG_PUB.Add;
923               RETURN;
924          END IF;
925 
926      END IF; */
927 
928      l_line_rec           := OE_ORDER_PUB.G_MISS_LINE_REC;
929      l_line_rec.line_id   := p_line_id;
930      l_line_rec.operation := OE_GLOBALS.G_OPR_DELETE;
931      l_line_tbl(1)        := l_line_rec;
932 
933     -- check_security is made false so that
934     -- we can delete the config line overriding the constraint.
935 
936     l_control_rec.controlled_operation := TRUE;
937     l_control_rec.change_attributes    := TRUE;
938     l_control_rec.default_attributes   := TRUE;
939     l_control_rec.validate_entity      := TRUE;
940     l_control_rec.check_security       := FALSE;
941     l_control_rec.write_to_DB          := TRUE;
942     l_control_rec.process              := TRUE;
943     l_control_rec.clear_dependents     := TRUE;
944 
945     --  Instruct API to retain its caches
946 
947     l_control_rec.clear_api_cache      := FALSE;
948     l_control_rec.clear_api_requests   := FALSE;
949 
950     l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;
951 
952     IF l_debug_level  > 0 THEN
953       oe_debug_pub.add(' ' , 3 );
954       oe_debug_pub.add('IN DELINK_CONFIG CALLING PROCESS ORDER' , 3 );
955       oe_debug_pub.add('IN DELINK_CONFIG AFTER CALL TO PROCESS ORDER' , 3 );
956       oe_debug_pub.add('L_RETURN_STATUS IS: ' || L_RETURN_STATUS , 2 );
957     END IF;
958 
959    OE_ORDER_PVT.Lines
960    (p_validation_level         => FND_API.G_VALID_LEVEL_NONE
961    ,p_control_rec              => l_control_rec
962    ,p_x_line_tbl               => l_line_tbl
963    ,p_x_old_line_tbl           => l_old_line_tbl
964    ,x_return_status            => l_return_status);
965 
966 
967     -- count and get
968     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
969        IF l_debug_level  > 0 THEN
970          oe_debug_pub.add('STATUS:' || L_RETURN_STATUS , 3 );
971        END IF;
972        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
973     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
974        IF l_debug_level  > 0 THEN
975          oe_debug_pub.add('STATUS:' || L_RETURN_STATUS , 3 );
976        END IF;
977        RAISE FND_API.G_EXC_ERROR;
978     END IF;
979 
980    -- Call Notify OC, required ****************************
981 
982    OE_ORDER_PVT.Process_Requests_And_notify
983     (p_process_requests       => TRUE
984     ,p_notify                 => TRUE
985     ,x_return_status          => l_return_status
986     ,p_line_tbl               => l_line_tbl
987     ,p_old_line_tbl           => l_old_line_tbl);
988 
989     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
990        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
991     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
992        RAISE FND_API.G_EXC_ERROR;
993     END IF;
994 
995   oe_msg_pub.count_and_get
996   ( p_count      => l_msg_count
997    ,p_data       => l_msg_data  );
998 
999     -- if everything is OK.
1000     x_return_status := FND_API.G_RET_STS_SUCCESS;
1001 
1002   IF l_debug_level  > 0 THEN
1003     oe_debug_pub.add('IN OE_CONFIG_UTI.DELINK , X_RETURN_STATUS'
1004                       ||X_RETURN_STATUS , 2 );
1005     oe_debug_pub.add('EXITING OE_CONGIG_UTIL.DELINK_CONFIG' , 1);
1006   END IF;
1007 
1008 EXCEPTION
1009     WHEN FND_API.G_EXC_ERROR THEN
1010 
1011         x_return_status := FND_API.G_RET_STS_ERROR;
1012         --  Get message count and data
1013         oe_msg_pub.count_and_get
1014         ( p_count   => l_msg_count
1015         ,   p_data    => l_msg_data
1016         );
1017 
1018     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1019 
1020         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1021         --  Get message count and data
1022         oe_msg_pub.count_and_get
1023         ( p_count   => l_msg_count
1024         ,   p_data    => l_msg_data
1025         );
1026 
1027     WHEN OTHERS THEN
1028         IF l_debug_level  > 0 THEN
1029           oe_debug_pub.add('ERROR: ' || SUBSTR ( SQLERRM , 1 , 100 ) , 1);
1030         END IF;
1031 
1032         IF oe_msg_pub.Check_Msg_Level(oe_msg_pub.G_MSG_LVL_UNEXP_ERROR)
1033         THEN
1034             oe_msg_pub.Add_Exc_Msg
1035             ( G_PKG_NAME
1036             ,   'Oe_Config_Util'
1037             );
1038         END IF;
1039 
1040         --  Get message count and data
1041         oe_msg_pub.count_and_get
1042         ( p_count    => l_msg_count
1043         ,   p_data     => l_msg_data
1044         );
1045        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1046 
1047 END Delink_Config;
1048 
1049 
1050 
1051 /*----------------------------------------------------------------------
1052 Procedure Name : Validate_Cfgs_In_Order
1053 Description    : checks if the models in the order
1054                  are complete and valid
1055 -----------------------------------------------------------------------*/
1056 FUNCTION Validate_Cfgs_In_Order(p_header_id IN NUMBER)
1057 RETURN VARCHAR2
1058 IS
1059   l_line_id             number := null;
1060   l_return_status       VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
1061   l_valid_config        VARCHAR2(10);
1062   l_complete_config     VARCHAR2(10);
1063 
1064   -- Instance locking changes
1065 
1066   l_booked_flag         VARCHAR2(1);
1067   l_config_header_id    NUMBER;
1068   l_config_rev_nbr      NUMBER;
1069   l_configuration_id    NUMBER;
1070   l_top_container       VARCHAR2(1);
1071   l_part_of_container   VARCHAR2(1);
1072   l_locking_key         NUMBER;
1073   l_msg_count           NUMBER;
1074   l_msg_data            VARCHAR2(4000);
1075   l_order_number        NUMBER;
1076 
1077   -- Instance locking changes.
1078 
1079   CURSOR models is
1080   SELECT line_id,config_header_id,config_rev_nbr,
1081          configuration_id,booked_flag
1082   FROM   oe_order_lines
1083   WHERE  item_type_code = OE_GLOBALS.G_ITEM_MODEL
1084   AND    header_id = p_header_id
1085   AND    open_flag = 'Y';
1086 
1087 --
1088 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1089 --
1090 BEGIN
1091 
1092   IF l_debug_level  > 0 THEN
1093     oe_debug_pub.add('ENTERING OE_CONGIG_UTIL.VALIDATE_CFGS_IN_ORDER' , 1);
1094   END IF;
1095   --get_transaction_id(p_caller   => 'before validate_cfgs');
1096 
1097   OPEN models;
1098 
1099   LOOP
1100     FETCH models
1101     into l_line_id,l_config_header_id,l_config_rev_nbr,
1102          l_configuration_id,l_booked_flag;
1103 
1104     EXIT WHEN MODELS%NOTFOUND;
1105 
1106     Oe_Config_Util.validate_configuration
1107                 ( p_model_line_id      => l_line_id,
1108                   p_validate_flag      => 'Y',
1109                   p_complete_flag      => 'Y',
1110                   p_caller             => 'BOOKING',
1111                   x_valid_config       => l_valid_config,
1112                   x_complete_config    => l_complete_config,
1113                   x_return_status      => l_return_status);
1114 
1115     -- if the valid or complete flag is false, we error out.
1116 
1117     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1118       --get_transaction_id(p_caller   => 'after call to validate_cfgs');
1119       RETURN l_return_status ;
1120     ELSE
1121        IF LOWER(l_valid_config) = 'false' OR
1122           LOWER(l_complete_config) = 'false' THEN
1123           IF l_debug_level  > 0 THEN
1124             oe_debug_pub.add('RETURN_STATUS SUCCESS,BUT INVALID/INCOMPLETE',2);
1125           END IF;
1126           RETURN FND_API.G_RET_STS_ERROR;
1127        END IF;
1128     END IF;
1129 
1130     -- Instance locking
1131     IF l_booked_flag = 'Y' THEN
1132 
1133       IF l_debug_level  > 0 THEN
1134 
1135          oe_debug_pub.add(' Before calling Is part of container model ' || l_line_id,  2);
1136 
1137       END IF;
1138 
1139       OE_CONFIG_TSO_PVT.Is_Part_Of_Container_Model
1140        (  p_line_id             => l_line_id
1141          ,p_top_model_line_id   => l_line_id
1142          ,x_top_container_model => l_top_container
1143          ,x_part_of_container   => l_part_of_container  );
1144 
1145        IF l_top_container = 'Y' THEN
1146 
1147            -- BV code must have changed the rev number. Therefore we have to
1148            -- re-fetch the value to pass it to lock api.
1149            BEGIN
1150             Select config_rev_nbr
1151             Into   l_config_rev_nbr
1152             From   oe_order_lines_all
1153             Where  line_id = l_line_id;
1154            END;
1155 
1156            l_order_number := OE_SCHEDULE_UTIL.Get_Order_Number(p_header_id);
1157 
1158            IF l_debug_level  > 0 THEN
1159 
1160             oe_debug_pub.add(' Calling lock_Config' || l_config_header_id,  2);
1161             oe_debug_pub.add(' Config rev nbr' || l_config_rev_nbr,  2);
1162             oe_debug_pub.add(' Configuration_id ' || l_configuration_id,  2);
1163             oe_debug_pub.add(' Order Number  ' || l_order_number,  2);
1164 
1165           END IF;
1166 
1167           CZ_IB_LOCKING.Lock_Config
1168           ( p_api_version            => 1.0,
1169             p_config_session_hdr_id  => l_config_header_id,
1170             p_config_session_rev_nbr => l_config_rev_nbr,
1171             p_config_session_item_id => Null,
1172             p_source_application_id  => fnd_profile.value('RESP_APPL_ID'),
1173             p_source_header_ref      => l_order_number,
1174             p_source_line_ref1       => Null,
1175             p_source_line_ref2       => Null,
1176             p_source_line_ref3       => Null,
1177             p_commit                 => 'N',
1178             p_init_msg_list          => FND_API.G_TRUE,
1179             p_validation_level       => Null,
1180             x_locking_key            => l_locking_key,
1181             x_return_status          => l_return_status,
1182             x_msg_count              => l_msg_count,
1183             x_msg_data               => l_msg_data);
1184 
1185             IF l_debug_level  > 0 THEN
1186               oe_debug_pub.add(' After calling CZ lock API ' || l_return_status || l_msg_data,2);
1187             END IF;
1188             IF l_msg_count > 0 THEN
1189                   OE_MSG_PUB.Transfer_Msg_stack;
1190 
1191             END IF;
1192             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1193                RETURN l_return_status;
1194             END IF;
1195 
1196        END IF; -- Container
1197      END IF; -- Booked Flag
1198       -- Instance locking.
1199   END LOOP;
1200 
1201   CLOSE models;
1202 
1203   IF l_debug_level  > 0 THEN
1204     oe_debug_pub.add('LEAVING VALIDATE_CFGS_IN_ORDER:' || L_RETURN_STATUS ,2);
1205     oe_debug_pub.add('EXITING OE_CONGIG_UTIL.VALIDATE_CFGS_IN_ORDER' , 1);
1206   END IF;
1207   --get_transaction_id(p_caller   => 'leaving validate_cfgs');
1208 
1209   RETURN l_return_status;
1210 END Validate_Cfgs_In_Order;
1211 
1212 /*----------------------------------------------------------------------
1213 Procedure Name : Freeze_Inc_Items_For_Order
1214 Description    :
1215 
1216 Change Record:
1217   Calling process_included_items directly w/o call to
1218 freeze_included_items.
1219 -----------------------------------------------------------------------*/
1220 FUNCTION Freeze_Inc_Items_for_Order(p_header_id IN NUMBER)
1221 RETURN VARCHAR2
1222 IS
1223   l_line_id                   NUMBER;
1224   l_return_status             VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
1225 
1226   CURSOR order_lines is
1227   SELECT line_id
1228   FROM   oe_order_lines
1229   WHERE  item_type_code in (OE_GLOBALS.G_ITEM_MODEL,
1230                             OE_GLOBALS.G_ITEM_CLASS,
1231                             OE_GLOBALS.G_ITEM_KIT)
1232   AND    open_flag = 'Y'
1233   AND    header_id = p_header_id;
1234 
1235   --
1236   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1237   --
1238 BEGIN
1239 
1240   IF l_debug_level  > 0 THEN
1241     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.FREEZE_INC_ITEMS_FOR_ORDER' , 1);
1242   END IF;
1243 
1244   OPEN order_lines;
1245 
1246   LOOP
1247     FETCH order_lines
1248     into l_line_id;
1249     EXIT WHEN ORDER_LINES%NOTFOUND;
1250 
1251     l_return_status := Oe_Config_Util.Process_included_items
1252                        ( p_line_id  => l_line_id
1253                         ,p_freeze   => TRUE);
1254 
1255     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1256       RETURN l_return_status ;
1257     END IF;
1258   END LOOP;
1259 
1260   CLOSE order_lines;
1261 
1262   IF l_debug_level  > 0 THEN
1263     oe_debug_pub.add('LEAVING FREEZE_INC_ITEMS_FOR_ORDER:'
1264                      || L_RETURN_STATUS , 2 );
1265     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.FREEZE_INC_ITEMS_FOR_ORDER' , 1);
1266   END IF;
1267   RETURN l_return_status;
1268 END Freeze_Inc_Items_for_Order;
1269 
1270 /*----------------------------------------------------------------------
1271 Procedure Name : Validate_Configuration_upg
1272 
1273 ----------------------------------------------------------------------*/
1274 
1275 PROCEDURE Validate_Configuration_upg
1276 (p_model_line_id       IN     NUMBER,
1277  x_return_status       OUT NOCOPY /* file.sql.39 change */    VARCHAR2)
1278 
1279 IS
1280   l_valid_config             VARCHAR2(10);
1281   l_complete_config          VARCHAR2(10);
1282   l_return_status            VARCHAR2(1);
1283   --
1284   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1285   --
1286 BEGIN
1287   Oe_Config_Util.Validate_Configuration
1288   (p_model_line_id       => p_model_line_id,
1289    x_valid_config        => l_valid_config,
1290    x_complete_config     => l_complete_config,
1291    x_return_status       => l_return_status);
1292 
1293    x_return_status := l_return_status;
1294 END;
1295 
1296 
1297 /*----------------------------------------------------------------------
1298 forward declarations
1299 ----------------------------------------------------------------------*/
1300 
1301 PROCEDURE Complete_Configuration
1302 (p_top_model_line_id     IN  NUMBER,
1303  x_return_status         OUT NOCOPY /* file.sql.39 change */ VARCHAR2);
1304 
1305 
1306 PROCEDURE Cascade_Qty
1307 ( p_x_options_tbl  IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
1308  ,p_component_code  IN VARCHAR2
1309  ,p_ratio           IN NUMBER
1310   -- 4211654
1311  ,p_new_qty         in number
1312  ,p_old_qty         in number
1313  ,p_change_reason   IN VARCHAR2
1314  ,p_change_comments IN VARCHAR2);
1315 
1316 
1317 PROCEDURE Delete_Children
1318 (p_x_options_tbl  IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
1319 ,p_component_code IN VARCHAR2
1320 ,p_parent_item    IN VARCHAR2);
1321 
1322 
1323 PROCEDURE Delete_Parent
1324 (p_x_options_tbl      IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
1325 ,p_component_code     IN VARCHAR2
1326 ,p_top_model_line_id  IN NUMBER
1327 ,p_model_component    IN VARCHAR2
1328 ,p_ui_flag             IN   VARCHAR2 := 'N');
1329 
1330 
1331 FUNCTION No_More_Children_Left
1332 (p_x_options_tbl      IN Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
1333 ,p_component_code     IN VARCHAR2
1334 ,p_top_model_line_id  IN NUMBER
1335 ,p_model_component    IN VARCHAR2
1336 ,p_ui_flag            IN VARCHAR2 := 'N')
1337 RETURN BOOLEAN;
1338 
1339 
1340 PROCEDURE Propogate_Change_To_Parent
1341 (p_x_options_tbl      IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
1342 ,p_component_code     IN VARCHAR2
1343 ,p_top_model_line_id  IN NUMBER
1344 ,p_model_component    IN VARCHAR2
1345 ,p_ui_flag            IN VARCHAR2 := 'N');
1346 
1347 
1348 PROCEDURE Message_From_Cz
1349 (p_line_id            IN NUMBER
1350 ,p_valid_config       IN VARCHAR2
1351 ,p_complete_config    IN VARCHAR2
1352 ,p_config_header_id   IN NUMBER
1353 ,p_config_rev_nbr     IN NUMBER);
1354 
1355 /*----------------------------------------------------------------------
1356 PROCEDURE: Configurator_Validation
1357 Description    : checks if the configuration is complete/valid
1358                  returns success/error as status. It calls
1359                  send_input_xml : to send the configuration coptions to SPC
1360                  parse_output_xml : parse output of SPC to see if
1361                                     configuration is valid/complete
1362                  process_config : to save options in oe_order_lines
1363 
1364                  now that we have decided that we will treat invalid
1365                  configuration in the same way as incomplete configuration,
1366                  the arguments p_validate_flag and p_complete_flag do not
1367                  have a lot of meaning. We might remove them for the procedure.
1368                  We will save invali as well as incomplete configurations
1369                  in oe_order_lines before booking.
1370                  After booking we will put model on hold if configuraion
1371                  becomes invalid/incomplete.
1372 -----------------------------------------------------------------------*/
1373 PROCEDURE Configurator_Validation
1374 (p_model_line_id       IN     NUMBER,
1375  p_deleted_options_tbl IN     OE_Order_PUB.request_tbl_type
1376                                 := OE_Order_Pub.G_MISS_REQUEST_TBL,
1377  p_updated_options_tbl IN     OE_Order_PUB.request_tbl_type
1378                                 := OE_Order_Pub.G_MISS_REQUEST_TBL,
1379  p_caller              IN     VARCHAR2 := '',
1380  x_valid_config        OUT NOCOPY /* file.sql.39 change */    VARCHAR2,
1381  x_complete_config     OUT NOCOPY /* file.sql.39 change */    VARCHAR2,
1382  x_return_status       OUT NOCOPY /* file.sql.39 change */    VARCHAR2)
1383 IS
1384       l_header_id              NUMBER := NULL;
1385       l_model_line_id          NUMBER := p_model_line_id;
1386       l_model_line_rec         OE_ORDER_PUB.line_rec_type;
1387 
1388       l_updated_options_tbl    OE_Order_PUB.request_tbl_type
1389                                := p_updated_options_tbl;
1390       l_deleted_options_tbl    OE_Order_PUB.request_tbl_type
1391                                :=p_deleted_options_tbl;
1392 
1393       l_config_header_id       NUMBER;
1394       l_config_rev_nbr         NUMBER;
1395       l_valid_config           VARCHAR2(10):= 'true';
1396       l_complete_config        VARCHAR2(10):= 'true';
1397       l_change_flag            VARCHAR2(1) := 'N';
1398       l_booked_flag            VARCHAR2(1) := 'N';
1399       l_model_qty              NUMBER;
1400       l_msg_count              NUMBER;
1401       l_msg_data               VARCHAR2(2000);
1402       l_return_status          VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
1403       l_result_out             VARCHAR2(30);
1404       l_options_tbl
1405                        Oe_Process_Options_Pvt.Selected_Options_Tbl_Type;
1406       -- input xml message
1407       l_xml_message            LONG   := NULL;
1408       l_xml_hdr                VARCHAR2(2000);
1409 
1410       -- upgrade stuff
1411       l_upgraded_flag          VARCHAR2(1);
1412       l_source_document_type_id  NUMBER;
1413       l_order_source_id          NUMBER;
1414 
1415       -- cz's delete return value
1416       l_return_status_del      VARCHAR2(1);
1417 
1418       -- cz_verify output
1419       l_any_insert             NUMBER := 0;
1420       l_exists_flag            VARCHAR2(1) := FND_API.G_TRUE;
1421       l_complete_flag          VARCHAR2(1) := FND_API.G_TRUE;
1422       l_valid_flag             VARCHAR2(1) := FND_API.G_TRUE;
1423       --
1424       l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1425       --
1426 BEGIN
1427     IF l_debug_level  > 0 THEN
1428       oe_debug_pub.add('ENTERING CONFIGURATOR_VALIDATION' , 1);
1429       oe_debug_pub.add('QUERYING MODEL LINE' , 3 );
1430     END IF;
1431 
1432     BEGIN
1433       SELECT header_id, ordered_quantity, booked_flag,
1434              upgraded_flag,  config_header_id, config_rev_nbr,
1435              source_document_type_id,order_source_id
1436       INTO   l_header_id, l_model_qty, l_booked_flag,
1437              l_upgraded_flag ,l_config_header_id, l_config_rev_nbr,
1438              l_source_document_type_id, l_order_source_id
1439       FROM   OE_ORDER_LINES
1440       WHERE  line_id = p_model_line_id;
1441     EXCEPTION
1442       WHEN OTHERS THEN
1443         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1444     END;
1445 
1446     l_booked_flag := nvl(l_booked_flag, 'N');
1447     l_upgraded_flag := nvl(l_upgraded_flag, 'N');
1448 
1449     ------------- upgrade stuff ---------------
1450 
1451     BEGIN
1452        IF ( l_upgraded_flag = 'Y'     OR
1453             l_upgraded_flag = 'P' )   AND
1454           (l_config_header_id is null AND
1455            l_config_rev_nbr is null)  AND
1456            Oe_Config_Util.G_Upgraded_Flag = 'N'
1457        THEN
1458          IF l_debug_level  > 0 THEN
1459            oe_debug_pub.add('UPGRADE THE CONFIGURAION' , 2 );
1460          END IF;
1461 
1462          Oe_Config_Util.G_Upgraded_Flag := 'Y';
1463 
1464          Configurator_Validation
1465          (p_model_line_id       => p_model_line_id,
1466           x_valid_config        => l_valid_config,
1467           x_complete_config     => l_complete_config,
1468           x_return_status       => l_return_status);
1469 
1470          IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1471            FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_UPGARDE_ERROR');
1472            OE_Msg_Pub.Add;
1473            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1474          ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1475            FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_UPGARDE_ERROR');
1476            OE_Msg_Pub.Add;
1477            RAISE FND_API.G_EXC_ERROR;
1478          END IF;
1479 
1480          IF l_debug_level  > 0 THEN
1481            oe_debug_pub.add('CONFIGURAION GOT UPGRADED' , 2 );
1482          END IF;
1483        END IF;
1484     END;
1485 
1486 
1487     IF l_debug_level  > 0 THEN
1488        oe_debug_pub.add('REV NBR ' ||L_CONFIG_REV_NBR );
1489        oe_debug_pub.add('CONF HDR ID' ||L_CONFIG_HEADER_ID );
1490        oe_debug_pub.add('BOOKED FLAG ' || L_BOOKED_FLAG );
1491     END IF;
1492 
1493     --  Check if there is any INSERT option operation being
1494     --  performed on an existing Model
1495 
1496     IF l_booked_flag  = 'N' THEN
1497 
1498       SELECT count (*)
1499       INTO  l_any_insert
1500       FROM  OE_ORDER_LINES
1501       WHERE top_model_line_id = p_model_line_id
1502       AND   line_id <> p_model_line_id
1503       AND   config_header_id IS NULL
1504       AND   config_rev_nbr  IS NULL;
1505 
1506       IF l_debug_level  > 0 THEN
1507         OE_Debug_Pub.Add('lines w/o cfg hdr '|| l_any_insert, 3);
1508         OE_Debug_Pub.Add('Order Level Copy '||OE_ORDER_COPY_UTIL.G_ORDER_LEVEL_COPY, 3);
1509       END IF;
1510 
1511       IF l_any_insert = 0 THEN
1512 
1513         BEGIN
1514           SELECT 1
1515           INTO   l_any_insert
1516           FROM   cz_config_details_v cz, oe_order_lines oe
1517           WHERE  oe.line_id = p_model_line_id
1518           AND    oe.ordered_quantity <> cz.quantity
1519           AND    oe.config_header_id = cz.config_hdr_id
1520           AND    oe.config_rev_nbr   = cz.config_rev_nbr
1521           AND    oe.component_code   = cz.component_code;
1522 
1523           IF l_debug_level  > 0 THEN
1524             OE_Debug_Pub.Add('yes, need to call batch val for model qty',3);
1525           END IF;
1526 
1527         EXCEPTION
1528           WHEN NO_DATA_FOUND THEN
1529             IF l_debug_level  > 0 THEN
1530               OE_Debug_Pub.Add('no need to call batch val for model qty',3);
1531             END IF;
1532           WHEN OTHERS THEN
1533             IF l_debug_level  > 0 THEN
1534               oe_debug_pub.add(  'QTY SELECT: '|| SQLERRM , 1 ) ;
1535             END IF;
1536             RAISE;
1537         END;
1538       END IF; -- model qty check
1539 
1540     END IF; -- booked flag and new inserts check.
1541 
1542     IF l_booked_flag  = 'N' AND
1543        l_updated_options_tbl.COUNT =  0 AND
1544        l_deleted_options_tbl.COUNT =  0 AND
1545        l_any_insert = 0   AND
1546        OE_ORDER_COPY_UTIL.G_ORDER_LEVEL_COPY <> 1 AND
1547        l_config_rev_nbr is not null AND
1548        l_config_header_id is not null
1549     THEN
1550        IF l_debug_level  > 0 THEN
1551          OE_Debug_Pub.Add('Skip Batch Validation ');
1552          oe_debug_pub.add(  'CALLING CZ_CONFIG_API_PUB.verify_configuration', 0.5) ;  -- Added debug for bug 13435459
1553        END IF;
1554 
1555        CZ_CONFIG_API_PUB.verify_configuration
1556        ( p_api_version        => 1.0,
1557          p_config_hdr_id      => l_config_header_id,
1558          p_config_rev_nbr     => l_config_rev_nbr,
1559          x_exists_flag        => l_exists_flag,
1560          x_valid_flag         => l_valid_flag,
1561          x_complete_flag      => l_complete_flag,
1562          x_return_status      => l_return_status,
1563          x_msg_count          => l_msg_count,
1564          x_msg_data           => l_msg_data );
1565 
1566        IF l_debug_level  > 0 THEN
1567          oe_debug_pub.add (' Exists Flag :' ||l_exists_flag,2);
1568          oe_debug_pub.add (' Valid Flag :'|| l_valid_flag,2);
1569          oe_debug_pub.add (' Complete Flag :'|| l_complete_flag,2);
1570          oe_debug_pub.add (' Return Status :'|| l_return_status,2);
1571          oe_debug_pub.add (' Message Count :'|| l_msg_count,2);
1572          oe_debug_pub.add (' Message Data  :'|| l_msg_data,2);
1573          oe_debug_pub.add(  'AFTER CZ_CONFIG_API_PUB.verify_configuration', 0.5) ;  -- Added debug for bug 13435459
1574        END IF;
1575 
1576        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1577          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1578        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1579          RAISE FND_API.G_EXC_ERROR;
1580        ELSIF  l_return_status = FND_API.G_RET_STS_SUCCESS THEN
1581 
1582          IF l_exists_flag = FND_API.G_FALSE THEN
1583            IF l_debug_level  > 0 THEN
1584              oe_debug_pub.add('Configuration Does not Exist '|| l_msg_data,2);
1585            END IF;
1586            RAISE FND_API.G_EXC_ERROR;
1587 
1588          ELSE
1589            IF l_debug_level  > 0 THEN
1590              oe_debug_pub.add  (' Configuration Exists ',2);
1591            END IF;
1592 
1593            IF l_valid_flag  = FND_API.G_FALSE THEN
1594               l_valid_config := 'FALSE';
1595            ELSE
1596               l_valid_config := 'TRUE';
1597            END IF;
1598 
1599            IF l_complete_flag = FND_API.G_FALSE THEN
1600               l_complete_config := 'FALSE';
1601            ELSE
1602              IF l_debug_level  > 0 THEN
1603                oe_debug_pub.add('Configuration Exists, valid and Complete ',2);
1604              END IF;
1605              l_complete_config := 'TRUE';
1606            END IF;
1607          END IF; -- if exist flag = false
1608        END IF; -- if success
1609 
1610        Message_From_Cz
1611        ( p_line_id           => l_model_line_id,
1612          p_valid_config      => l_valid_config,
1613          p_complete_config   => l_complete_config,
1614          p_config_header_id  => l_config_header_id,
1615          p_config_rev_nbr    => l_config_rev_nbr);
1616 
1617     ELSE -- call batch val
1618 
1619       -- create xml initialization message,
1620       -- then we send it along with options to SPC
1621       -- then we parse the o/p xml from  SPC to get
1622       -- batch validation results
1623       -- Check if the user has already performed configurator validation
1624       -- If the call is from Order Import and not BOOKING then skip the
1625       -- Configurator BATCH Validation (bug 2560933)
1626 
1627       IF l_debug_level  > 0 THEN
1628         oe_debug_pub.add('CALLING CREATE_HDR_XML' , 2 );
1629         oe_debug_pub.add('--------INITIALIZATION MESSAGE------------' , 2 );
1630       END IF;
1631 
1632       Create_hdr_xml
1633       ( p_model_line_id        => p_model_line_id ,
1634         x_xml_hdr              => l_xml_hdr);
1635 
1636       IF l_debug_level  > 0 THEN
1637         oe_debug_pub.add('------AFTER CREATE INITIALIZATION MESSAGE----' , 2 );
1638         oe_debug_pub.add('CALLING SEND_INPUT_XML' , 2 );
1639       END IF;
1640 
1641       Send_Input_xml
1642       ( p_model_line_id        => l_model_line_id,
1643         p_deleted_options_tbl  => l_deleted_options_tbl,
1644         p_updated_options_tbl  => l_updated_options_tbl,
1645         p_model_qty            => l_model_qty,
1646         p_xml_hdr              => l_xml_hdr,
1647         x_out_xml_msg          => l_xml_message,
1648         x_return_status        => l_return_status );
1649 
1650       IF l_debug_level  > 0 THEN
1651         oe_debug_pub.add
1652         ('AFTER CALLING SEND_INPUT_XML: '||L_RETURN_STATUS , 2 );
1653       END IF;
1654       --get_transaction_id(p_caller   => 'after send_xml');
1655 
1656       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1657          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1658 
1659       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1660          RAISE FND_API.G_EXC_ERROR;
1661 
1662       END IF;
1663 
1664 
1665       l_xml_message := UPPER(l_xml_message);
1666 
1667       -- extract data from xml message.
1668 
1669        IF l_debug_level  > 0 THEN
1670          oe_debug_pub.add('CALLING PARSE_OUTPUT_XML' , 2 );
1671        END IF;
1672 
1673       Parse_Output_xml
1674       ( p_xml               => l_xml_message,
1675         p_line_id           => l_model_line_id,
1676         x_valid_config      => l_valid_config,
1677         x_complete_config   => l_complete_config,
1678         x_config_header_id  => l_config_header_id,
1679         x_config_rev_nbr    => l_config_rev_nbr,
1680         x_return_status     => l_return_status );
1681 
1682         IF l_debug_level  > 0 THEN
1683           oe_debug_pub.add('AFTER CALLING PARSE_XML: '||L_RETURN_STATUS , 2 );
1684         END IF;
1685 
1686         x_valid_config    := l_valid_config;
1687         x_complete_config := l_complete_config;
1688 
1689       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1690          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1691       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1692          RAISE FND_API.G_EXC_ERROR;
1693       END IF;
1694 
1695     END IF;  -- if skip batch val
1696 
1697     x_valid_config    := l_valid_config;
1698     x_complete_config := l_complete_config;
1699 
1700     IF p_caller = 'BOOKING' AND
1701        (l_valid_config = 'FALSE' OR
1702         l_complete_config = 'FALSE') THEN
1703 
1704         IF l_debug_level  > 0 THEN
1705           oe_debug_pub.add('CALLER IS BOOKING AND ERRORED OUT' , 2 );
1706         END IF;
1707 
1708         x_return_status   := l_return_status;
1709         RETURN;
1710     END IF;
1711 
1712 
1713     -- if the order id booked, we want to put hold on the model line
1714     -- if the configuration is invalid or incomplete. Also we want
1715     -- to release the hold, if the configuration becomes valid and complete
1716     -- after this particular change.
1717 
1718     IF l_debug_level  > 0 THEN
1719         oe_debug_pub.add('IS THIS IS A BOOKED ORDER , IF SO PUT HOLD: '
1720                          ||L_BOOKED_FLAG , 2 );
1721     END IF;
1722 
1723     IF l_booked_flag = 'Y' THEN
1724 
1725         OE_Config_Pvt.put_hold_and_release_hold
1726         (p_header_id       => l_header_id,
1727          p_line_id         => l_model_line_id,
1728          p_valid_config    => l_valid_config,
1729          p_complete_config => l_complete_config,
1730          x_msg_count       => l_msg_count,
1731          x_msg_data        => l_msg_data,
1732          x_return_status   => l_return_status);
1733 
1734         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
1735         THEN
1736            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1737         ELSIF l_return_status = FND_API.G_RET_STS_ERROR
1738         THEN
1739            RAISE FND_API.G_EXC_ERROR;
1740         END IF;
1741     END IF;
1742 
1743 
1744     -- call to process_config to insert new valid and complete confiuration
1745 
1746     IF l_debug_level  > 0 THEN
1747         oe_debug_pub.add('------- CALLING PROCESS_CONFIG -----------' , 2 );
1748     END IF;
1749 
1750     OE_Config_Pvt.Process_Config
1751     ( p_header_id          => l_header_id
1752      ,p_config_hdr_id      => l_config_header_id
1753      ,p_config_rev_nbr     => l_config_rev_nbr
1754      ,p_top_model_line_id  => l_model_line_id
1755      ,p_ui_flag            => 'N'
1756      ,x_change_flag        => l_change_flag
1757      ,x_msg_count          => l_msg_count
1758      ,x_msg_data           => l_msg_data
1759      ,x_return_status      => l_return_status );
1760 
1761     IF l_debug_level  > 0 THEN
1762         oe_debug_pub.add('AFTER CALL TO PROCESS_CONFIG: '
1763                          ||L_RETURN_STATUS , 2 );
1764     END IF;
1765 
1766     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1767        IF l_debug_level  > 0 THEN
1768          oe_debug_pub.add('PROCESS CONFIG UNEXPECTED ERROR' , 2 );
1769        END IF;
1770        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1771 
1772     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1773        IF l_debug_level  > 0 THEN
1774          oe_debug_pub.add('PROCESS CONFIG EXEC ERROR' , 2 );
1775        END IF;
1776        RAISE FND_API.G_EXC_ERROR;
1777 
1778     END IF;
1779 
1780     -- If you are here, things went off OK ! So return success
1781     x_return_status   := l_return_status;
1782 
1783     IF l_debug_level  > 0 THEN
1784       oe_debug_pub.add('LEAVING CONFIGURATOR_VALIDATION' , 1);
1785     END IF;
1786 EXCEPTION
1787   WHEN OTHERS THEN
1788     IF l_debug_level  > 0 THEN
1789       oe_debug_pub.add('ECXEPTION IN CONFIGURATOR_VALIDATION'|| SQLERRM , 1);
1790     END IF;
1791     RAISE;
1792 END Configurator_Validation;
1793 
1794 /*----------------------------------------------------------------------
1795 PROCEDURE: Bom_Config_Validation
1796 If Use_Configurator function returns false.
1797 
1798 Change Record:
1799 ER 2625376 : date effectivity - call to prepare_cascade_tables.
1800 
1801 MACD: No MACD functionality should be available in the options window
1802 -----------------------------------------------------------------------*/
1803 PROCEDURE Bom_Config_Validation
1804 (p_model_line_id       IN     NUMBER,
1805  p_header_id           IN     NUMBER,
1806  p_model_qty           IN     NUMBER,
1807  p_deleted_options_tbl IN     OE_Order_PUB.request_tbl_type
1808                                 := OE_Order_Pub.G_MISS_REQUEST_TBL,
1809  p_updated_options_tbl IN     OE_Order_PUB.request_tbl_type
1810                                 := OE_Order_Pub.G_MISS_REQUEST_TBL,
1811  p_caller              IN     VARCHAR2 := '',
1812  x_valid_config        OUT NOCOPY /* file.sql.39 change */    VARCHAR2,
1813  x_complete_config     OUT NOCOPY /* file.sql.39 change */    VARCHAR2,
1814  x_return_status       OUT NOCOPY /* file.sql.39 change */    VARCHAR2)
1815 IS
1816   l_options_tbl     Oe_Process_Options_Pvt.Selected_Options_Tbl_Type;
1817   l_updated_options_tbl OE_Order_PUB.request_tbl_type;
1818   l_deleted_options_tbl OE_Order_PUB.request_tbl_type;
1819   I                 NUMBER;
1820   l_change_flag     VARCHAR2(1);
1821   l_item_type_code  VARCHAR2(30);
1822   l_model_component VARCHAR2(1000);
1823   l_req_rec         OE_Order_Pub.Request_Rec_Type;
1824   l_return_status   VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
1825   l_msg_count       NUMBER;
1826   l_msg_data        VARCHAR2(2000);
1827 
1828   --
1829   l_debug_level     CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1830   --
1831 BEGIN
1832   IF l_debug_level  > 0 THEN
1833     oe_debug_pub.add('ENTERING BOM_CONFIG_VALIDATION' , 1);
1834     oe_debug_pub.add('GETTING PREVIOUSLY SAVED OPTIONS FROM DB' , 2 );
1835   END IF;
1836 
1837   IF OE_CODE_CONTROL.GET_CODE_RELEASE_LEVEL >= '110510' THEN
1838 
1839     OE_CONFIG_TSO_PVT.Is_Part_Of_Container_Model
1840     ( p_line_id              => p_model_line_id
1841      ,x_top_container_model  => l_change_flag
1842      ,x_part_of_container    => l_return_status );
1843 
1844     IF l_change_flag = 'Y' THEN
1845       IF l_debug_level > 0 THEN
1846         OE_DEBUG_PUB.Add('Line is top container, hence not allowed',3);
1847       END IF;
1848 
1849       x_return_status := FND_API.G_RET_STS_ERROR;
1850       FND_MESSAGE.SET_NAME('ONT','ONT_TSO_NOT_IN_OPTIONS_WINDOW');
1851       OE_MSG_PUB.Add;
1852       RETURN;
1853     END IF;
1854 
1855   END IF;
1856 
1857 
1858   l_return_status := FND_API.G_RET_STS_SUCCESS;
1859 
1860   OE_Process_Options_Pvt.Get_Options_From_DB
1861   ( p_top_model_line_id  => p_model_line_id
1862    ,p_get_model_line     => TRUE
1863    ,p_caller             => 'OPTIONS WINDOW BATCH'
1864    ,p_query_criteria     => 4
1865    ,x_disabled_options   => l_msg_data
1866    ,x_options_tbl        => l_options_tbl);
1867 
1868   IF p_deleted_options_tbl.COUNT > 0 OR
1869      p_updated_options_tbl.COUNT > 0 OR
1870      l_msg_data = 'Y' THEN
1871 
1872     SELECT component_code
1873     INTO   l_model_component
1874     FROM   oe_order_lines
1875     WHERE  line_id = p_model_line_id;
1876 
1877     l_updated_options_tbl := p_updated_options_tbl;
1878     l_deleted_options_tbl := p_deleted_options_tbl;
1879 
1880     IF l_msg_data = 'Y' THEN
1881 
1882       OE_Process_Options_Pvt.Prepare_Cascade_Tables
1883       ( p_options_tbl           => l_options_tbl
1884        ,p_top_model_line_id     => p_model_line_id
1885        ,p_x_updated_options_tbl => l_updated_options_tbl
1886        ,p_x_deleted_options_tbl => l_deleted_options_tbl);
1887 
1888     END IF;
1889 
1890     IF l_debug_level  > 0 THEN
1891       oe_debug_pub.add('CALLING CASCADE_UPDATES_DELETES '||
1892                         l_deleted_options_tbl.COUNT || '-' ||
1893                         l_updated_options_tbl.COUNT, 3);
1894     END IF;
1895 
1896     Cascade_Updates_Deletes
1897     ( p_model_line_id       => p_model_line_id
1898      ,p_model_component     => l_model_component
1899      ,p_x_options_tbl       => l_options_tbl
1900      ,p_deleted_options_tbl => l_deleted_options_tbl
1901      ,p_updated_options_tbl => l_updated_options_tbl
1902      ,x_return_status       => l_return_status);
1903 
1904   END IF; -- if we need to cascade
1905 
1906   IF l_debug_level  > 0 THEN
1907     oe_debug_pub.add('CALLING PROCESS_CONFIG_OPTIONS' , 1);
1908   END IF;
1909 
1910   OE_Process_Options_Pvt.Process_Config_Options
1911   (p_options_tbl       => l_options_tbl,
1912    p_header_id         => p_header_id,
1913    p_top_model_line_id => p_model_line_id,
1914    p_ui_flag           => 'N',
1915    p_caller            => p_caller, -- bug 4636208
1916    x_valid_config      => x_valid_config,
1917    x_complete_config   => x_complete_config,
1918    x_change_flag       => l_change_flag,
1919    x_msg_count         => l_msg_count,
1920    x_msg_data          => l_msg_data,
1921    x_return_status     => x_return_status);
1922 
1923   OE_Process_Options_Pvt.Handle_Ret_Status
1924   (p_return_Status   => x_return_status);
1925 
1926   IF l_debug_level  > 0 THEN
1927     oe_debug_pub.add('LEAVING BOM_CONFIG_VALIDATION' , 1);
1928   END IF;
1929 EXCEPTION
1930   WHEN OTHERS THEN
1931     IF l_debug_level  > 0 THEN
1932       oe_debug_pub.add('ECXEPTION IN BOM_CONFIG_VALIDATION'|| SQLERRM , 1);
1933     END IF;
1934     RAISE;
1935 END Bom_Config_Validation;
1936 
1937 
1938 /*----------------------------------------------------------------------
1939 Procedure Name :  Cascade_Updates_Deletes
1940 Description    :  This API will be used when there are updates and deletes
1941 to option/class of a configuration and we want to cascade the operation to
1942 either upwards or downwards.
1943   -- handle updates
1944   -- if any class is updated, modify the l_options-tbl so that, options
1945   -- qty cascades, set operation of update on the updated once, and none
1946   -- on the others
1947 
1948   -- handle deletes
1949   -- if any class deleted, delete all options underit.
1950   -- if a option is deleted, i.e. the only option in a class
1951   -- delete the class from l_options_tbl
1952 
1953   Note:
1954   If a kit under a model is updated/deleted, since its included items
1955   are not present in l_options_tbl, so we can not use cascade_qty
1956   or delete_options for it.
1957   We handle this seperately, before call to process_order in
1958   handle_dml in OEXVOPTB.pls. We also handle the case of included
1959   items under a PTO class in handle_dml.
1960 
1961  As part of pack J ato options decimal quantity project
1962  decimal_ratio_check is moved to OE_VALIDATE_LINE
1963  for Decimal quantities for ATO Options Project
1964  the decimal ratio check will be part of line entity
1965  validation
1966 -----------------------------------------------------------------------*/
1967 
1968 PROCEDURE Cascade_Updates_Deletes
1969 ( p_model_line_id        IN   NUMBER
1970  ,p_model_component      IN   VARCHAR2
1971  ,p_x_options_tbl        IN   OUT NOCOPY
1972                               Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
1973  ,p_deleted_options_tbl  IN   OE_Order_PUB.request_tbl_type
1974                               := OE_Order_Pub.G_MISS_REQUEST_TBL
1975  ,p_updated_options_tbl  IN   OE_Order_PUB.request_tbl_type
1976                               := OE_Order_Pub.G_MISS_REQUEST_TBL
1977  ,p_ui_flag              IN   VARCHAR2 := 'N'
1978  ,x_return_status        OUT NOCOPY /* file.sql.39 change */  VARCHAR2)
1979 IS
1980   I                          NUMBER;
1981   l_index                    NUMBER;
1982   l_ratio                    NUMBER;
1983   l_req_rec                  OE_Order_Pub.Request_Rec_Type;
1984   l_deleted_options_tbl      OE_Order_PUB.request_tbl_type
1985                              := p_deleted_options_tbl;
1986   l_return_status            VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
1987   l_qty                      NUMBER := 1;
1988   --
1989   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1990   --
1991 BEGIN
1992   IF l_debug_level  > 0 THEN
1993     oe_debug_pub.add('ENTERING CASCADE_UPDATES_DELETES' , 1);
1994     oe_debug_pub.add('FIRST UPDATES' , 2 );
1995   END IF;
1996 
1997   IF p_updated_options_tbl.COUNT > 0 THEN
1998     SELECT ordered_quantity
1999     INTO   l_qty
2000     FROM   oe_order_lines
2001     WHERE  line_id = p_model_line_id;
2002   END IF;
2003 
2004   I :=p_updated_options_tbl.FIRST;
2005   WHILE I is not NULL
2006   LOOP
2007     l_req_rec  := p_updated_options_tbl(I);
2008 
2009     IF l_debug_level  > 0 THEN
2010       oe_debug_pub.add('OPTIONS UPDATED ' , 4 );
2011     END IF;
2012 
2013     IF l_debug_level  > 0 THEN
2014       oe_debug_pub.add('QTY '|| L_REQ_REC.PARAM5||'CANCEL: '
2015                        ||L_REQ_REC.PARAM8 , 2 );
2016     END IF;
2017 
2018     IF l_req_rec.param5 = 0 AND l_req_rec.param8 = 'N' THEN
2019       IF l_debug_level  > 0 THEN
2020         oe_debug_pub.add('QTY = 0 AND NO CANCELLATION , SO DELETE' , 1);
2021       END IF;
2022 
2023       BEGIN
2024         -- set operation to delete
2025         l_index := OE_Process_Options_Pvt.Find_Matching_comp_index
2026         ( p_options_tbl  => p_x_options_tbl
2027          ,p_comp_code    => l_req_rec.param2);
2028 
2029         IF l_debug_level  > 0 THEN
2030           oe_debug_pub.add('INDEX: '|| L_INDEX , 2 );
2031         END IF;
2032         p_x_options_tbl(l_index).operation := OE_GLOBALS.G_OPR_DELETE;
2033 
2034       EXCEPTION
2035         WHEN FND_API.G_EXC_ERROR THEN
2036           IF l_debug_level  > 0 THEN
2037             oe_debug_pub.add('COMPONENT NOT PRESENT' , 1);
2038           END IF;
2039           RAISE;
2040       END;
2041 
2042       l_deleted_options_tbl(nvl(l_deleted_options_tbl.LAST, 0) + 1) :=
2043                                   l_req_rec; -- ok, since params match
2044 
2045     ELSE -- regular code
2046       IF l_debug_level  > 0 THEN
2047         oe_debug_pub.add('REGULAR CODE OF UPDATES'|| L_REQ_REC.PARAM3 , 1);
2048       END IF;
2049 
2050       IF l_req_rec.param3 = OE_GLOBALS.G_ITEM_CLASS THEN
2051 
2052         IF l_req_rec.param5 = 0 THEN
2053           l_ratio := 0;
2054         ELSE
2055           l_ratio := l_req_rec.param5/l_req_rec.param4;
2056         END IF;
2057 
2058         IF l_debug_level  > 0 THEN
2059           -- 4211654
2060           oe_debug_pub.add(L_REQ_REC.PARAM2||'   OLD QTY (l_req_rec.param4) = '
2061                            ||L_REQ_REC.PARAM4||'  New Qty (l_req_rec.param5) = '
2062                            ||l_req_rec.param5 , 1);
2063         END IF;
2064 
2065         Cascade_Qty( p_x_options_tbl   => p_x_options_tbl
2066                     ,p_component_code  => l_req_rec.param2
2067                     ,p_ratio           => l_ratio
2068                     -- 4211654
2069                     ,p_new_qty        => l_req_rec.param5
2070                     ,p_old_qty        => l_req_rec.param4
2071                     ,p_change_reason   => l_req_rec.param6
2072                     ,p_change_comments => l_req_rec.param7);
2073       END IF;
2074 
2075       IF l_req_rec.param8 = 'Y' AND
2076          l_req_rec.param5 = 0
2077       THEN
2078         IF l_debug_level  > 0 THEN
2079           oe_debug_pub.add('CALLING PROPOGATE CHANGE , CANCEL FLAG Y' , 1);
2080         END IF;
2081 
2082         Propogate_change_To_parent
2083         (p_x_options_tbl     => p_x_options_tbl
2084         ,p_component_code    => l_req_rec.param2
2085         ,p_top_model_line_id => p_model_line_id
2086         ,p_model_component   => p_model_component
2087         ,p_ui_flag      => p_ui_flag);
2088       END IF;
2089 
2090     END IF; -- qty 0 and cancel = 'N'
2091 
2092     I :=  p_updated_options_tbl.NEXT(I);
2093   END LOOP;
2094 
2095   IF l_debug_level  > 0 THEN
2096     oe_debug_pub.add('NOW DELETES' , 1);
2097   END IF;
2098 
2099   I :=l_deleted_options_tbl.FIRST;
2100   WHILE I is not NULL
2101   LOOP
2102     IF l_debug_level  > 0 THEN
2103       oe_debug_pub.add('THERE ARE ITEMS DELETED'|| L_REQ_REC.PARAM2 , 1);
2104     END IF;
2105 
2106     l_req_rec  := l_deleted_options_tbl(I);
2107 
2108     IF l_req_rec.param3 = OE_GLOBALS.G_ITEM_CLASS THEN
2109       IF l_debug_level  > 0 THEN
2110         oe_debug_pub.add('CLASS IS DELETED'|| L_REQ_REC.PARAM2 , 1);
2111       END IF;
2112 
2113       Delete_Children( p_x_options_tbl  => p_x_options_tbl
2114                       ,p_component_code => l_req_rec.param2
2115                       ,p_parent_item    => l_req_rec.param10 ); -- 3563690
2116     END IF;
2117 
2118     -- why a KIT and a Class are considered here.
2119     -- if user saves a configuration with a class or kit w/o any
2120     -- options/inc items and then deletes this class/kit, we
2121     -- should see if the parent needs to be deleted, rare case.
2122 
2123     IF p_model_component is NULL THEN
2124       IF l_debug_level  > 0 THEN
2125         oe_debug_pub.add('MODEL COMPONENT IS NULL' , 1);
2126       END IF;
2127       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2128     END IF;
2129 
2130     IF l_debug_level  > 0 THEN
2131       oe_debug_pub.add('OPTION/CLASS/KIT IS DELETED' , 1);
2132     END IF;
2133 
2134     Delete_Parent(p_x_options_tbl     => p_x_options_tbl
2135                  ,p_component_code    => l_req_rec.param2
2136                  ,p_top_model_line_id => p_model_line_id
2137                  ,p_model_component   => p_model_component
2138                  ,p_ui_flag           => p_ui_flag);
2139 
2140     I :=  l_deleted_options_tbl.NEXT(I);
2141   END LOOP;
2142 
2143   x_return_status := l_return_status;
2144   IF l_debug_level  > 0 THEN
2145     oe_debug_pub.add('LEAVING CASCADE_UPDATES_DELETES' , 1);
2146   END IF;
2147 
2148 EXCEPTION
2149   WHEN OTHERS THEN
2150     IF l_debug_level  > 0 THEN
2151       oe_debug_pub.add('EXCEPTION IN CASCADE_UPDATES_DELETES'|| SQLERRM , 1);
2152     END IF;
2153     RAISE;
2154 END Cascade_Updates_Deletes;
2155 
2156 /*---------------------------------------------------------------------
2157 PROCEDURE: Cascade_Qty
2158 bug fixed: Make sure to pass req. reason and comment, while cascading.
2159 bug fixed: only one level cascade will happen.
2160 ----------------------------------------------------------------------*/
2161 
2162 PROCEDURE Cascade_Qty
2163 ( p_x_options_tbl   IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
2164  ,p_component_code  IN VARCHAR2
2165  ,p_ratio           IN NUMBER
2166   -- 4211654
2167  ,p_new_qty         IN number
2168  ,p_old_qty         IN number
2169  ,p_change_reason   IN VARCHAR2
2170  ,p_change_comments IN VARCHAR2)
2171 IS
2172   I            NUMBER;
2173   l_length     NUMBER;
2174   --
2175   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2176   --
2177 BEGIN
2178   IF l_debug_level  > 0 THEN
2179     oe_debug_pub.add('ENTERING CASCADE_QTY '|| P_RATIO , 1);
2180   END IF;
2181 
2182   l_length := LENGTH(p_component_code);
2183 
2184   I := p_x_options_tbl.FIRST;
2185   WHILE I is not NULL
2186   LOOP
2187     IF SUBSTR(p_x_options_tbl(I).component_code, 1, l_length )
2188               = p_component_code
2189        AND p_x_options_tbl(I).component_code <> p_component_code
2190        AND p_x_options_tbl(I).operation <> OE_GLOBALS.G_OPR_DELETE
2191     THEN
2192        IF l_debug_level  > 0 THEN
2193          oe_debug_pub.add('OPTION TO BE UPDATED '
2194                           || P_X_OPTIONS_TBL (I).COMPONENT_CODE , 3 );
2195          oe_debug_pub.add('CHANGE REASON '|| P_CHANGE_REASON , 3 );
2196        END IF;
2197        /* 4211654 - instead of using p_ratio, used p_old_qty and p_new_qty to
2198         *           calculate p_x_options_tbl(I).ordered_quantity
2199         */
2200        p_x_options_tbl(I).ordered_quantity :=
2201           (p_x_options_tbl(I).ordered_quantity / p_old_qty) * p_new_qty;
2202        IF l_debug_level  > 0 THEN
2203          oe_debug_pub.add('NEW QTY '||P_X_OPTIONS_TBL (I).ORDERED_QUANTITY ,1);
2204        END IF;
2205        p_x_options_tbl(I).change_reason   := p_change_reason;
2206        p_x_options_tbl(I).change_comments := p_change_comments;
2207 
2208        --added IF condition for bug# 4116813
2209        IF p_x_options_tbl(I).operation <>  OE_GLOBALS.G_OPR_INSERT THEN
2210          p_x_options_tbl(I).operation := OE_GLOBALS.G_OPR_UPDATE;
2211        END IF;
2212 
2213 
2214     END IF;
2215     I := p_x_options_tbl.NEXT(I);
2216   END LOOP;
2217 
2218   IF l_debug_level  > 0 THEN
2219     oe_debug_pub.add('LEAVING CASCADE_QTY' , 1);
2220   END IF;
2221 EXCEPTION
2222   WHEN OTHERS THEN
2223     IF l_debug_level  > 0 THEN
2224       oe_debug_pub.add('ECXEPTION IN CASCADE_QTY'|| SQLERRM , 1);
2225     END IF;
2226     RAISE;
2227 END Cascade_Qty;
2228 
2229 
2230 /*----------------------------------------------------------------------
2231 PROCEDURE: Delete_Children
2232 3563690 => If operation is insert for a child line, do not set the
2233            operation to delete. Instead, raise an exception
2234            Changed the signature of the procedure to accept the  name
2235            of the class.
2236 ----------------------------------------------------------------------*/
2237 PROCEDURE Delete_Children
2238 ( p_x_options_tbl  IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
2239  ,p_component_code IN VARCHAR2
2240  ,p_parent_item    IN VARCHAR2)
2241 IS
2242   I            NUMBER;
2243   l_length     NUMBER;
2244   --
2245   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2246   --
2247 BEGIN
2248   IF l_debug_level  > 0 THEN
2249     oe_debug_pub.add('ENTERING DELETE_CHILDREN' , 1);
2250   END IF;
2251 
2252   l_length := LENGTH(p_component_code);
2253 
2254   I := p_x_options_tbl.FIRST;
2255   WHILE I is not NULL
2256   LOOP
2257     IF SUBSTR(p_x_options_tbl(I).component_code, 1, l_length )
2258               = p_component_code
2259        AND p_x_options_tbl(I).component_code <> p_component_code
2260     THEN
2261        IF l_debug_level  > 0 THEN
2262          oe_debug_pub.add('OPTION TO BE DELETED '
2263                           || P_X_OPTIONS_TBL (I).COMPONENT_CODE , 3 );
2264        END IF;
2265        IF p_x_options_tbl(I).operation <> OE_GLOBALS.G_OPR_INSERT
2266        THEN
2267          p_x_options_tbl(I).operation := OE_GLOBALS.G_OPR_DELETE;
2268        ELSE
2269          FND_MESSAGE.SET_NAME('ONT','ONT_CONFIG_INSERT_DELETE');
2270          FND_MESSAGE.Set_Token('CLASS',p_parent_item);
2271          FND_MESSAGE.Set_Token('ITEM',p_x_options_tbl(I).ordered_item);
2272          Oe_Msg_Pub.Add;
2273          IF l_debug_level > 0 THEN
2274            oe_debug_pub.add('OPERATION IS INSERT IN PROCEDURE DELETE_CHILDREN');
2275            oe_debug_pub.add('parent class : ' || p_parent_item);
2276            oe_debug_pub.add('child item   : ' || p_x_options_tbl(I).ordered_item);
2277          END IF;
2278          RAISE FND_API.G_EXC_ERROR;
2279        END IF;
2280     END IF;
2281     I := p_x_options_tbl.NEXT(I);
2282   END LOOP;
2283 
2284   IF l_debug_level  > 0 THEN
2285     oe_debug_pub.add('LEAVING DELETE_CHILDREN' , 1);
2286   END IF;
2287 EXCEPTION
2288   WHEN OTHERS THEN
2289     IF l_debug_level  > 0 THEN
2290       oe_debug_pub.add('ECXEPTION IN DELETE_CHILDREN'|| SQLERRM , 1);
2291     END IF;
2292     RAISE;
2293 END Delete_Children;
2294 
2295 
2296 /*----------------------------------------------------------------------
2297 PROCEDURE Delete_Parent
2298 delete the parent only if the only option under it is getting deleted.
2299 Never delete the model line.
2300 ----------------------------------------------------------------------*/
2301 PROCEDURE Delete_Parent
2302 (p_x_options_tbl      IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
2303 ,p_component_code     IN VARCHAR2
2304 ,p_top_model_line_id  IN NUMBER
2305 ,p_model_component    IN VARCHAR2
2306 ,p_ui_flag            IN VARCHAR2 := 'N')
2307 IS
2308   I                  NUMBER;
2309   l_count            NUMBER;
2310   l_link_to_line_id  NUMBER;
2311   l_parent           VARCHAR2(1000);
2312   --
2313   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2314   --
2315 BEGIN
2316   IF l_debug_level  > 0 THEN
2317     oe_debug_pub.add('ENTERING DELETE_PARENT' , 1);
2318   END IF;
2319 
2320   IF p_model_component is NULL THEN
2321     RAISE FND_API.G_EXC_ERROR;
2322   END IF;
2323 
2324 
2325   IF p_component_code = p_model_component THEN
2326     IF l_debug_level  > 0 THEN
2327       oe_debug_pub.add('MODEL REACHED' , 1);
2328     END IF;
2329     RETURN;
2330   END IF;
2331 
2332   IF l_debug_level  > 0 THEN
2333     oe_debug_pub.add('COMP SENT IN: '|| P_COMPONENT_CODE , 2 );
2334   END IF;
2335 
2336 
2337   IF no_more_children_left
2338      (p_x_options_tbl     => p_x_options_tbl
2339      ,p_component_code    => p_component_code
2340      ,p_top_model_line_id => p_top_model_line_id
2341      ,p_model_component   => p_model_component
2342      ,p_ui_flag           => p_ui_flag)
2343   THEN
2344 
2345     -- make a recursive call, because parent can be the
2346     -- only child to its parent.
2347 
2348     I := p_x_options_tbl.FIRST;
2349     WHILE I is not NULL
2350 
2351     LOOP
2352       IF l_debug_level  > 0 THEN
2353         oe_debug_pub.add(I || ': '|| P_X_OPTIONS_TBL (I).COMPONENT_CODE , 2 );
2354       END IF;
2355       l_parent :=
2356       SUBSTR(p_component_code, 1, INSTR(p_component_code, '-', -1) - 1);
2357 
2358       IF l_parent = p_x_options_tbl(I).component_code AND
2359          p_x_options_tbl(I).component_code <> p_model_component
2360       THEN
2361         IF l_debug_level  > 0 THEN
2362           oe_debug_pub.add('PARENT TO BE DELETED '
2363                            || P_X_OPTIONS_TBL (I).COMPONENT_CODE , 3 );
2364         END IF;
2365 
2366         p_x_options_tbl(I).operation := OE_GLOBALS.G_OPR_DELETE;
2367 
2368         -- recursive call.
2369 
2370         IF l_debug_level  > 0 THEN
2371           oe_debug_pub.add('RECURSIVE CALL'|| P_MODEL_COMPONENT , 1);
2372         END IF;
2373         Delete_Parent(p_x_options_tbl     => p_x_options_tbl
2374                      ,p_component_code    => l_parent
2375                      ,p_top_model_line_id => p_top_model_line_id
2376                      ,p_model_component   => p_model_component
2377                      ,p_ui_flag           => p_ui_flag);
2378 
2379         IF l_debug_level  > 0 THEN
2380           oe_debug_pub.add('MY CALL WORK DONE' , 1);
2381         END IF;
2382         RETURN;
2383       END IF;
2384       I := p_x_options_tbl.NEXT(I);
2385     END LOOP;
2386 
2387     IF l_debug_level  > 0 THEN
2388       oe_debug_pub.add('PARENT NOT FOUND??' , 1);
2389     END IF;
2390 
2391   END IF;
2392 
2393   IF l_debug_level  > 0 THEN
2394     oe_debug_pub.add('LEAVING DELETE_PARENT'|| P_COMPONENT_CODE , 1);
2395   END IF;
2396 EXCEPTION
2397   WHEN OTHERS THEN
2398     IF l_debug_level  > 0 THEN
2399       oe_debug_pub.add('ECXEPTION IN DELETE_PARENT'|| SQLERRM , 1);
2400     END IF;
2401     RAISE;
2402 END Delete_Parent;
2403 
2404 
2405 /*----------------------------------------------------------------------
2406 PROCEDURE Propogate_Change_To_Parent
2407 propogate change to the parent only if the only option under
2408 it is changed.
2409 ----------------------------------------------------------------------*/
2410 PROCEDURE Propogate_Change_To_Parent
2411 (p_x_options_tbl      IN OUT NOCOPY Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
2412 ,p_component_code     IN VARCHAR2
2413 ,p_top_model_line_id  IN NUMBER
2414 ,p_model_component    IN VARCHAR2
2415 ,p_ui_flag            IN VARCHAR2 := 'N')
2416 IS
2417   I                  NUMBER;
2418   l_count            NUMBER;
2419   l_link_to_line_id  NUMBER;
2420   l_parent           VARCHAR2(1000);
2421   --
2422   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2423   --
2424 BEGIN
2425   IF l_debug_level  > 0 THEN
2426     oe_debug_pub.add('ENTERING PROPOGATE_CHANGE_TO_PARENT' , 1);
2427   END IF;
2428 
2429   IF p_model_component is NULL THEN
2430     RAISE FND_API.G_EXC_ERROR;
2431   END IF;
2432 
2433 
2434   IF p_component_code = p_model_component THEN
2435     IF l_debug_level  > 0 THEN
2436       oe_debug_pub.add('MODEL REACHED' , 1);
2437     END IF;
2438     RETURN;
2439   END IF;
2440 
2441   IF l_debug_level  > 0 THEN
2442     oe_debug_pub.add('COMP SENT IN: '|| P_COMPONENT_CODE , 2 );
2443   END IF;
2444 
2445 
2446   IF no_more_children_left
2447      (p_x_options_tbl     => p_x_options_tbl
2448      ,p_component_code    => p_component_code
2449      ,p_top_model_line_id => p_top_model_line_id
2450      ,p_model_component   => p_model_component
2451      ,p_ui_flag           => p_ui_flag)
2452   THEN
2453 
2454     -- make a recursive call, because parent can be the
2455     -- only child to its parent.
2456 
2457     I := p_x_options_tbl.FIRST;
2458     WHILE I is not NULL
2459 
2460     LOOP
2461       IF l_debug_level  > 0 THEN
2462         oe_debug_pub.add(I || ': '|| P_X_OPTIONS_TBL (I).COMPONENT_CODE , 2 );
2463       END IF;
2464 
2465       l_parent :=
2466       SUBSTR(p_component_code, 1, INSTR(p_component_code, '-', -1) - 1);
2467 
2468       IF l_parent = p_x_options_tbl(I).component_code AND
2469          p_x_options_tbl(I).component_code <> p_model_component
2470       THEN
2471         IF l_debug_level  > 0 THEN
2472           oe_debug_pub.add('PARENT TO BE MODIFIED '
2473                            || P_X_OPTIONS_TBL (I).COMPONENT_CODE , 3 );
2474         END IF;
2475 
2476 
2477         p_x_options_tbl(I).operation := OE_GLOBALS.G_OPR_UPDATE;
2478         p_x_options_tbl(I).ordered_quantity := 0;
2479         p_x_options_tbl(I).change_reason := 'SYSTEM';
2480 
2481         -- recursive call.
2482 
2483         IF l_debug_level  > 0 THEN
2484           oe_debug_pub.add('RECURSIVE CALL'|| P_MODEL_COMPONENT , 1);
2485         END IF;
2486 
2487         Propogate_Change_To_Parent
2488                      (p_x_options_tbl     => p_x_options_tbl
2489                      ,p_component_code    => l_parent
2490                      ,p_top_model_line_id => p_top_model_line_id
2491                      ,p_model_component   => p_model_component
2492                      ,p_ui_flag           => p_ui_flag);
2493 
2494         IF l_debug_level  > 0 THEN
2495           oe_debug_pub.add('MY CALL WORK DONE' , 1);
2496         END IF;
2497         RETURN;
2498       END IF;
2499       I := p_x_options_tbl.NEXT(I);
2500     END LOOP;
2501 
2502     IF l_debug_level  > 0 THEN
2503       oe_debug_pub.add('PARENT NOT FOUND??' , 1);
2504     END IF;
2505 
2506   END IF;
2507 
2508   IF l_debug_level  > 0 THEN
2509     oe_debug_pub.add('LEAVING PROPOGATE_CHANGE_TO_PARENT'
2510                      || P_COMPONENT_CODE , 1);
2511   END IF;
2512 EXCEPTION
2513   WHEN OTHERS THEN
2514     IF l_debug_level  > 0 THEN
2515       oe_debug_pub.add('ECXEPTION IN PROPOGATE_CHANGE_TO_PARENT'
2516                        || SQLERRM , 1);
2517     END IF;
2518     RAISE;
2519 END Propogate_Change_To_Parent;
2520 
2521 
2522 /*----------------------------------------------------------------------
2523 PROCEDURE No_More_Children_Left
2524 delete the parent only if the only option under it is getting deleted.
2525 Never delete the model line.
2526 p_component_code is the component_code of the child, for which
2527 we are trying tofind out if this is the only child to its parent.
2528 ----------------------------------------------------------------------*/
2529 FUNCTION No_More_Children_Left
2530 (p_x_options_tbl      IN Oe_Process_Options_Pvt.Selected_Options_Tbl_Type
2531 ,p_component_code     IN VARCHAR2
2532 ,p_top_model_line_id  IN NUMBER
2533 ,p_model_component    IN VARCHAR2
2534 ,p_ui_flag            IN VARCHAR2 := 'N')
2535 RETURN BOOLEAN
2536 IS
2537   l_parent    VARCHAR2(1000);
2538   l_count     NUMBER;
2539   I           NUMBER;
2540   --
2541   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2542   --
2543 BEGIN
2544   IF l_debug_level  > 0 THEN
2545     oe_debug_pub.add('ENTERING NO_MORE_CHILDREN_LEFT'|| P_UI_FLAG , 1);
2546   END IF;
2547 
2548   l_parent :=
2549     SUBSTR(p_component_code, 1, INSTR(p_component_code, '-', -1) - 1);
2550 
2551   IF l_debug_level  > 0 THEN
2552     oe_debug_pub.add('PARENT: '|| L_PARENT , 3 );
2553   END IF;
2554 
2555   IF l_parent = p_model_component THEN
2556     IF l_debug_level  > 0 THEN
2557       oe_debug_pub.add('PARENT IS A MODEL' , 1);
2558     END IF;
2559     RETURN FALSE;
2560   END IF;
2561 
2562   I := p_x_options_tbl.FIRST;
2563 
2564   WHILE I is not NULL
2565   LOOP
2566     IF SUBSTR(p_x_options_tbl(I).component_code, 1,
2567               INSTR(p_component_code, '-', -1) - 1)
2568               =  SUBSTR(p_component_code, 1,
2569               INSTR(p_component_code, '-', -1) - 1)  -- same parent
2570        AND p_x_options_tbl(I).component_code <> l_parent
2571        AND p_x_options_tbl(I).component_code <> p_component_code
2572        AND p_x_options_tbl(I).operation <> OE_GLOBALS.G_OPR_DELETE
2573        AND NOT(p_x_options_tbl(I).operation = OE_GLOBALS.G_OPR_UPDATE AND
2574                p_x_options_tbl(I).ordered_quantity = 0) -- cancel
2575 
2576     THEN
2577       IF l_debug_level  > 0 THEN
2578         oe_debug_pub.add('OPTION UNDER SAME PARENT EXISTS' , 3 );
2579       END IF;
2580       RETURN FALSE;
2581     END IF;
2582 
2583     I :=  p_x_options_tbl.NEXT(I);
2584   END LOOP;
2585 
2586   IF l_debug_level  > 0 THEN
2587     oe_debug_pub.add('CAME OUT OF LOOP' , 3 );
2588   END IF;
2589 
2590   -- use sql, may be included item exist.
2591   l_count := 0;
2592 
2593   SELECT /* MOAC_SQL_CHANGE */ count(*)
2594   INTO   l_count
2595   FROM   oe_order_lines_all
2596   WHERE  top_model_line_id = p_top_model_line_id
2597   AND    item_type_code = OE_GLOBALS.G_ITEM_INCLUDED
2598   AND    open_flag      = 'Y'
2599   AND    link_to_line_id =
2600       (SELECT line_id
2601        FROM   oe_order_lines_all
2602        WHERE  top_model_line_id = p_top_model_line_id
2603        AND    component_code = l_parent
2604        AND    open_flag      = 'Y' );
2605 
2606   IF l_count > 0 THEN
2607     IF l_debug_level  > 0 THEN
2608       oe_debug_pub.add('SOME MORE OPTIONS EXIST' , 1);
2609     END IF;
2610     RETURN FALSE;
2611   END IF;
2612 
2613   IF l_debug_level  > 0 THEN
2614     oe_debug_pub.add('LEAVING NO_MORE_CHILDREN_LEFT' , 1);
2615   END IF;
2616 
2617   RETURN TRUE;
2618 EXCEPTION
2619   WHEN OTHERS THEN
2620     IF l_debug_level  > 0 THEN
2621       oe_debug_pub.add('ECXEPTION IN NO_MORE_CHILDREN_LEFT'|| SQLERRM , 1);
2622     END IF;
2623     RAISE;
2624 END No_More_Children_Left;
2625 
2626 
2627 /*----------------------------------------------------------------------
2628 Procedure Name : Validate_Configuration
2629 wrapper  API to decide which validation API should be used.
2630 
2631 Change Record:
2632 
2633 We do not need to call the apt complete_configuration anymore,
2634 because all the code is put in OEXVORDB.pls in the lines loop.
2635 -----------------------------------------------------------------------*/
2636 PROCEDURE Validate_Configuration
2637 (p_model_line_id       IN     NUMBER,
2638  p_deleted_options_tbl IN     OE_Order_PUB.request_tbl_type
2639                                 := OE_Order_Pub.G_MISS_REQUEST_TBL,
2640  p_updated_options_tbl IN     OE_Order_PUB.request_tbl_type
2641                                 := OE_Order_Pub.G_MISS_REQUEST_TBL,
2642  p_validate_flag       IN     VARCHAR2 := 'Y',
2643  p_complete_flag       IN     VARCHAR2 := 'Y',
2644  p_caller              IN     VARCHAR2 := '',
2645  x_valid_config        OUT NOCOPY /* file.sql.39 change */    VARCHAR2,
2646  x_complete_config     OUT NOCOPY /* file.sql.39 change */    VARCHAR2,
2647  x_return_status       OUT NOCOPY /* file.sql.39 change */    VARCHAR2)
2648 
2649 IS
2650   l_header_id                 NUMBER;
2651   l_config_hdr_id             NUMBER;
2652   l_config_rev_nbr            NUMBER;
2653   l_configuration_id          NUMBER;
2654   l_model_qty                 NUMBER;
2655   l_use_configurator          BOOLEAN;
2656   l_configurator_was_used     NUMBER;
2657   l_msg_count                 NUMBER;
2658   l_msg_data                  VARCHAR2(2000);
2659   l_return_status             VARCHAR2(1):=  FND_API.G_RET_STS_SUCCESS;
2660   l_order_source_id           NUMBER;
2661   l_orig_sys_document_ref     VARCHAR2(50);
2662   l_orig_sys_line_ref         VARCHAR2(50);
2663   l_orig_sys_shipment_ref     VARCHAR2(50);
2664   l_change_sequence           VARCHAR2(50);
2665   l_source_document_type_id   NUMBER;
2666   l_source_document_id        NUMBER;
2667   l_source_document_line_id   NUMBER;
2668   --
2669   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2670   --
2671 BEGIN
2672 
2673    IF l_debug_level  > 0 THEN
2674      oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.VALIDATE_CONFIGURATION' , 1);
2675    END IF;
2676 
2677 
2678 -- No Copy Changes. Initialized return status to success
2679 	x_return_status    := FND_API.G_RET_STS_SUCCESS;
2680 
2681 
2682 --get_transaction_id(p_caller   => 'inside validate_config');
2683 
2684    BEGIN
2685      SELECT header_id, config_header_id, config_rev_nbr, ordered_quantity,
2686             configuration_id, order_source_id, orig_sys_document_ref,
2687             orig_sys_line_ref, orig_sys_shipment_ref, change_sequence,
2688             source_document_type_id, source_document_id, source_document_line_id
2689      INTO   l_header_id, l_config_hdr_id, l_config_rev_nbr, l_model_qty,
2690             l_configuration_id, l_order_source_id, l_orig_sys_document_ref,
2691             l_orig_sys_line_ref, l_orig_sys_shipment_ref, l_change_sequence,
2692             l_source_document_type_id, l_source_document_id, l_source_document_line_id
2693      FROM   OE_ORDER_LINES_ALL
2694      WHERE  line_id = p_model_line_id;
2695    EXCEPTION
2696      WHEN OTHERS THEN
2697        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2698    END;
2699 
2700    OE_Msg_Pub.Set_Msg_Context
2701    (p_entity_code   => OE_GLOBALS.G_ENTITY_LINE
2702    ,p_entity_id     => p_model_line_id
2703    ,p_header_id     => l_header_id
2704    ,p_line_id       => p_model_line_id
2705    ,p_order_source_id            => l_order_source_id
2706    ,p_orig_sys_document_ref      => l_orig_sys_document_ref
2707    ,p_orig_sys_document_line_ref => l_orig_sys_line_ref
2708    ,p_orig_sys_shipment_ref      => l_orig_sys_shipment_ref
2709    ,p_change_sequence            => l_change_sequence
2710    ,p_source_document_type_id    => l_source_document_type_id
2711    ,p_source_document_id         => l_source_document_id
2712    ,p_source_document_line_id    => l_source_document_line_id);
2713 
2714    l_use_configurator := OE_Process_Options_Pvt.Use_Configurator;
2715 
2716    IF l_use_configurator THEN
2717      IF l_debug_level  > 0 THEN
2718        oe_debug_pub.add('USE CONFIGURATOR IS TRUE' , 1);
2719      END IF;
2720    END IF;
2721 
2722    IF l_config_hdr_id is NOT NULL AND
2723       l_config_rev_nbr   is NOT NULL THEN
2724       IF l_debug_level  > 0 THEN
2725         oe_debug_pub.add('CONFIGURATOR WAS USED' , 1);
2726       END IF;
2727       l_configurator_was_used := 0;
2728    ELSIF
2729       l_configuration_id is NOT NULL THEN
2730       IF l_debug_level  > 0 THEN
2731         oe_debug_pub.add('OPTIONS WINDOW WAS USED' , 1);
2732       END IF;
2733       l_configurator_was_used := 1;
2734    ELSE
2735       IF l_debug_level  > 0 THEN
2736         oe_debug_pub.add('NEW CONFIGURATION BEING CREATED' , 1);
2737       END IF;
2738       l_configurator_was_used := 2;
2739    END IF;
2740 
2741    IF l_use_configurator AND
2742       (l_configurator_was_used = 0 OR
2743        l_configurator_was_used = 2)
2744    THEN
2745        Configurator_Validation
2746        (p_model_line_id        => p_model_line_id,
2747         p_deleted_options_tbl  => p_deleted_options_tbl,
2748         p_updated_options_tbl  => p_updated_options_tbl,
2749         p_caller               => p_caller,
2750         x_valid_config         => x_valid_config,
2751         x_complete_config      => x_complete_config,
2752         x_return_status        => x_return_status);
2753 
2754         IF l_debug_level  > 0 THEN
2755           oe_debug_pub.add('RETURNING AFTER CONFIGURATOR_VALIDATION'
2756                            || X_RETURN_STATUS , 2 );
2757         END IF;
2758         RETURN;
2759    END IF;
2760 
2761 
2762    IF NOT(l_use_configurator) AND
2763       (l_configurator_was_used = 1 OR
2764        l_configurator_was_used = 2)
2765    THEN
2766 
2767        Bom_Config_Validation
2768        (p_model_line_id        => p_model_line_id,
2769         p_header_id            => l_header_id,
2770         p_model_qty            => l_model_qty,
2771         p_deleted_options_tbl  => p_deleted_options_tbl,
2772         p_updated_options_tbl  => p_updated_options_tbl,
2773         p_caller               => p_caller,
2774         x_valid_config         => x_valid_config,
2775         x_complete_config      => x_complete_config,
2776         x_return_status        => x_return_status);
2777 
2778         IF l_debug_level  > 0 THEN
2779           oe_debug_pub.add('RETURNING AFTER BOM_CONFIG_VALIDATION'
2780                            || X_RETURN_STATUS , 2 );
2781         END IF;
2782         RETURN;
2783    END IF;
2784 
2785    IF l_configurator_was_used <> 0 AND l_use_configurator THEN
2786      FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_USE_OPTIONS_WINDOW');
2787      OE_Msg_Pub.Add;
2788      x_return_status:= FND_API.G_RET_STS_ERROR;
2789    END IF;
2790 
2791    IF l_configurator_was_used <> 1 AND NOT (l_use_configurator) THEN
2792      FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_USE_CONFIGURATOR');
2793      OE_Msg_Pub.Add;
2794      x_return_status:= FND_API.G_RET_STS_ERROR;
2795    END IF;
2796 
2797    --get_transaction_id(p_caller   => ' leaving validate_config');
2798 
2799    oe_msg_pub.count_and_get
2800    ( p_count                       => l_msg_count
2801    ,   p_data                        => l_msg_data );
2802 
2803 
2804    OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
2805 
2806    IF l_debug_level  > 0 THEN
2807      oe_debug_pub.add('EXITING OE_CONFIG_UTIL.VALIDATE_CONFIGURATION' , 1);
2808    END IF;
2809 EXCEPTION
2810 
2811       WHEN FND_API.G_EXC_ERROR THEN
2812          x_return_status  := FND_API.G_RET_STS_ERROR;
2813          --get_transaction_id(p_caller   => 'exc error in validate_config');
2814 
2815 
2816       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2817          x_return_status  := FND_API.G_RET_STS_UNEXP_ERROR;
2818          --get_transaction_id(p_caller   => 'unxp error in validate_config');
2819 
2820 
2821       WHEN OTHERS THEN
2822          IF l_debug_level  > 0 THEN
2823            oe_debug_pub.add('ERROR IN VALIDATE_CONFIGURATION : '
2824                             || SUBSTR ( SQLERRM , 1 , 100 ) , 1);
2825          END IF;
2826          x_return_status   := FND_API.G_RET_STS_UNEXP_ERROR;
2827 
2828 END Validate_Configuration;
2829 
2830 
2831   -- create xml message, send it to ui manager
2832   -- get back pieces of xml message
2833   -- process them and generate a long output xml message
2834   -- hardcoded :url,user, passwd, gwyuid,fndnam,two_task
2835 
2836 /*-------------------------------------------------------------------
2837 Procedure Name : Send_input_xml
2838 Description    : sends the xml batch validation message to SPC that has
2839                  options that are newly inserted/updated/deleted
2840                  from the model.
2841 
2842                  SPC validation_status :
2843                  CONFIG_PROCESSED              constant NUMBER :=0;
2844                  CONFIG_PROCESSED_NO_TERMINATE constant NUMBER :=1;
2845                  INIT_TOO_LONG                 constant NUMBER :=2;
2846                  INVALID_OPTION_REQUEST        constant NUMBER :=3;
2847                  CONFIG_EXCEPTION              constant NUMBER :=4;
2848                  DATABASE_ERROR                constant NUMBER :=5;
2849                  UTL_HTTP_INIT_FAILED          constant NUMBER :=6;
2850                  UTL_HTTP_REQUEST_FAILED       constant NUMBER :=7;
2851 
2852 Change Record:
2853 
2854 Decimal ratio check is is moved to OE_VALIDATE_LINE
2855 for Decimal quantities for ATO Options Project
2856 the decimal ratio check will be part of line entity
2857 validation
2858 
2859 ---------------------------------------------------------------------*/
2860 
2861 PROCEDURE Send_input_xml
2862             ( p_model_line_id       IN NUMBER ,
2863               p_deleted_options_tbl IN   OE_Order_PUB.request_tbl_type
2864                                     := OE_Order_Pub.G_MISS_REQUEST_TBL,
2865               p_updated_options_tbl IN   OE_Order_PUB.request_tbl_type
2866                                     := OE_Order_Pub.G_MISS_REQUEST_TBL,
2867               p_model_qty           IN NUMBER,
2868               p_xml_hdr             IN VARCHAR2,
2869               x_out_xml_msg         OUT NOCOPY /* file.sql.39 change */ LONG ,
2870               x_return_status       OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
2871 IS
2872   l_html_pieces              CZ_BATCH_VALIDATE.CFG_OUTPUT_PIECES;
2873   l_option                   CZ_BATCH_VALIDATE.INPUT_SELECTION;
2874   l_batch_val_tbl            CZ_BATCH_VALIDATE.CFG_INPUT_LIST;
2875   l_db_options_tbl       OE_Process_Options_Pvt.SELECTED_OPTIONS_TBL_TYPE;
2876   -- update / delete options
2877   l_req_rec                       OE_Order_Pub.Request_Rec_Type;
2878   l_flag                          VARCHAR2(30) := '0';
2879 
2880   --variable to fetch from cursor Get_Options
2881   l_component_code                VARCHAR2(1000);
2882   l_configuration_id              NUMBER;
2883   l_send_model_flag               VARCHAR2(1);
2884   -- message related
2885   l_validation_status             NUMBER;
2886   l_sequence                      NUMBER := 0;
2887   l_url                           VARCHAR2(500):=
2888                                   FND_PROFILE.Value('CZ_UIMGR_URL');
2889   l_rec_index BINARY_INTEGER;
2890   l_xml_hdr                       VARCHAR2(2000);
2891   l_long_xml                      LONG := NULL;
2892   l_return_status                 VARCHAR2(1) :=
2893                                   FND_API.G_RET_STS_SUCCESS;
2894   I                               NUMBER;
2895   --
2896   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2897   --
2898  BEGIN
2899 
2900       IF l_debug_level  > 0 THEN
2901         oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.SEND_INPUT_XML' , 1);
2902         oe_debug_pub.add('UIMANAGER URL: ' || L_URL , 2 );
2903       END IF;
2904 
2905 
2906       l_xml_hdr := p_xml_hdr;
2907       IF l_debug_level  > 0 THEN
2908         oe_debug_pub.add('LENGTH OF INI MSG: ' || LENGTH ( L_XML_HDR ) , 2 );
2909       END IF;
2910 
2911 
2912       -- if there is change in model qty and we have cascaded it
2913       -- to all options, w/o communicating this to SPC
2914       -- send the new model qty in batch validation.
2915 
2916       l_send_model_flag := 'Y';
2917 
2918       BEGIN
2919         SELECT ol.component_code, ol.configuration_id
2920         INTO   l_component_code, l_configuration_id
2921         FROM   oe_order_lines ol, cz_config_details_v cz
2922         WHERE  ol.line_id        = p_model_line_id
2923         AND    cz.component_code = ol.component_code
2924         AND    cz.config_hdr_id  = ol.config_header_id
2925         AND    cz.config_rev_nbr = ol.config_rev_nbr
2926         AND    cz.quantity      <> ol.ordered_quantity;
2927 
2928       EXCEPTION
2929         WHEN NO_DATA_FOUND THEN
2930           l_send_model_flag := 'N';
2931 
2932         WHEN OTHERS THEN
2933           RAISE FND_API.G_EXC_ERROR;
2934       END;
2935 
2936 
2937      IF l_send_model_flag = 'Y' THEN
2938           l_sequence := l_sequence + 1;
2939           l_option.component_code     := l_component_code;
2940           l_option.quantity           := p_model_qty;
2941           l_option.input_seq          := l_sequence;
2942 
2943           IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
2944             IF l_debug_level  > 0 THEN
2945               oe_debug_pub.add('SEND XML UCFGB MI , PACK H NEW LOGIC' , 3 );
2946             END IF;
2947             l_option.config_item_id   := l_configuration_id;
2948           END IF;
2949 
2950           l_batch_val_tbl(l_sequence) := l_option;
2951 
2952           IF l_debug_level  > 0 THEN
2953             oe_debug_pub.add('NEW MODEL QTY: '|| P_MODEL_QTY , 2 );
2954           END IF;
2955 
2956      END IF;
2957 
2958      -- get the options from the from databse.
2959      IF l_debug_level  > 0 THEN
2960        oe_debug_pub.add('GETTING PREVIOUSLY SAVED OPTIONS FROM DB' , 2 );
2961      END IF;
2962 
2963      OE_Process_Options_Pvt.Get_Options_From_DB
2964      ( p_top_model_line_id  => p_model_line_id
2965       ,x_disabled_options   => l_flag
2966       ,x_options_tbl        => l_db_options_tbl);
2967 
2968      IF l_debug_level  > 0 THEN
2969        oe_debug_pub.add('cursor GET NEWLY INSERTED OPTIONS '|| l_flag , 2 );
2970      END IF;
2971 
2972      I := l_db_options_tbl.FIRST;
2973      WHILE I is not NULL
2974      LOOP
2975           IF l_debug_level  > 0 THEN
2976             oe_debug_pub.add('GET_OPTION : '
2977                             || L_DB_OPTIONS_TBL (I).COMPONENT_CODE , 2 );
2978           END IF;
2979 
2980           l_sequence := l_sequence + 1;
2981 
2982           l_option.component_code := l_db_options_tbl(I).component_code;
2983           l_option.input_seq      := l_sequence;
2984 
2985           IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
2986             IF l_debug_level  > 0 THEN
2987               oe_debug_pub.add('SEND XML UCFGB MI , PACK H NEW LOGIC' , 3 );
2988             END IF;
2989             l_option.config_item_id
2990                                 := l_db_options_tbl(I).configuration_id;
2991           END IF;
2992 
2993           IF l_debug_level  > 0 THEN
2994             oe_debug_pub.add('QTY RATIO : '
2995             || L_DB_OPTIONS_TBL (I).ORDERED_QUANTITY/P_MODEL_QTY , 2 );
2996             oe_debug_pub.add('OE QTY: '
2997             || L_DB_OPTIONS_TBL (I).ORDERED_QUANTITY , 2 );
2998           END IF;
2999 
3000           l_option.quantity   := l_db_options_tbl(I).ordered_quantity;
3001 
3002           l_batch_val_tbl(l_sequence) := l_option;
3003 
3004           IF l_debug_level  > 0 THEN
3005             oe_debug_pub.add(L_SEQUENCE||' '
3006                              ||L_DB_OPTIONS_TBL (I).CONFIGURATION_ID , 2 );
3007           END IF;
3008 
3009           I := l_db_options_tbl.NEXT(I);
3010       END LOOP;
3011 
3012       IF l_debug_level  > 0 THEN
3013         oe_debug_pub.add('OUT OF NEWLY INSERTED OPTIONS LOOP' , 2 );
3014       END IF;
3015 
3016 
3017      --------------- send updated options/classes----------------
3018 
3019 
3020      IF l_debug_level  > 0 THEN
3021        oe_debug_pub.add('NO. OF UPDATED OPTIONS: '
3022                         ||P_UPDATED_OPTIONS_TBL.COUNT , 2 );
3023        oe_debug_pub.add('ENTERING LOOP TO PASS UPDATED OPTIONS' , 2 );
3024      END IF;
3025 
3026 
3027      l_rec_index := 1;
3028 
3029      FOR I IN 1..p_updated_options_tbl.COUNT
3030      LOOP
3031          IF l_debug_level  > 0 THEN
3032            oe_debug_pub.add('WITHIN THE LOOP OF P_UPDATED_OPTIONS_TBL' , 2 );
3033            oe_debug_pub.add('L_REC_INDEX: ' || L_REC_INDEX , 2 );
3034          END IF;
3035 
3036          l_req_rec  := p_updated_options_tbl(l_rec_index);
3037 
3038          IF l_debug_level  > 0 THEN
3039            oe_debug_pub.add('UPDATE LINE_ID: ' || L_REQ_REC.ENTITY_ID , 2 );
3040            oe_debug_pub.add('COMPONENT_CODE: ' || L_REQ_REC.PARAM2 , 2 );
3041          END IF;
3042 
3043          l_sequence := l_sequence + 1;
3044 
3045          l_option.component_code := l_req_rec.param2;
3046          l_option.input_seq      := l_sequence;
3047 
3048          IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
3049            IF l_debug_level  > 0 THEN
3050              oe_debug_pub.add('UPD , SEND XML MI , PACK H NEW LOGIC' , 3 );
3051            END IF;
3052            l_option.config_item_id := l_req_rec.param9;
3053          END IF;
3054 
3055           -- check if integer
3056 
3057           IF l_debug_level  > 0 THEN
3058             oe_debug_pub.add(L_REQ_REC.PARAM2
3059             || ' OPTION UPDATED TO A QTY OF: ' || L_REQ_REC.PARAM5 , 3 );
3060           END IF;
3061 
3062           l_option.quantity       := l_req_rec.param5;
3063 
3064           l_batch_val_tbl(l_sequence) := l_option;
3065           l_rec_index := l_rec_index + 1;
3066 
3067           IF l_debug_level  > 0 THEN
3068             oe_debug_pub.add(L_SEQUENCE||' SEQ '||L_REQ_REC.PARAM9 , 2 );
3069           END IF;
3070 
3071      END LOOP;
3072 
3073      IF l_debug_level  > 0 THEN
3074        oe_debug_pub.add('LEAVING LOOP TO PASS UPDATED OPTIONS' , 2 );
3075      END IF;
3076 
3077 
3078 
3079      ------------ send deleted options/classes-------------------
3080 
3081      IF l_debug_level  > 0 THEN
3082        oe_debug_pub.add('NO. OF DELETED OPTIONS: '
3083                         ||P_DELETED_OPTIONS_TBL.COUNT , 2 );
3084        oe_debug_pub.add('ENTERING LOOP TO PASS DELETED OPTIONS' , 2 );
3085      END IF;
3086 
3087      l_rec_index := 1;
3088      FOR I IN 1..p_deleted_options_tbl.COUNT
3089      LOOP
3090 
3091          IF l_debug_level  > 0 THEN
3092            oe_debug_pub.add('WITHIN THE LOOP OF P_DELETED_OPTIONS_TBL' , 2 );
3093            oe_debug_pub.add('L_REC_INDEX: ' || L_REC_INDEX , 2 );
3094          END IF;
3095 
3096 
3097          l_req_rec := p_deleted_options_tbl(l_rec_index);
3098          IF l_debug_level  > 0 THEN
3099            oe_debug_pub.add('ENTITY ID: ' || L_REQ_REC.ENTITY_ID , 2 );
3100            oe_debug_pub.add('COMPONENT_CODE: ' || L_REQ_REC.PARAM2 , 2 );
3101          END IF;
3102 
3103          l_sequence := l_sequence + 1;
3104 
3105          l_option.component_code := l_req_rec.param2;
3106          l_option.input_seq      := l_sequence;
3107          l_option.quantity       := 0;
3108 
3109 
3110          IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
3111            IF l_debug_level  > 0 THEN
3112              oe_debug_pub.add('DEL , SEND XML MI , PACK H NEW LOGIC' , 3 );
3113            END IF;
3114            l_option.config_item_id
3115                               := l_req_rec.param9;
3116          END IF;
3117 
3118          l_batch_val_tbl(l_sequence) := l_option;
3119          l_rec_index := l_rec_index + 1;
3120 
3121          IF l_debug_level  > 0 THEN
3122            oe_debug_pub.add(L_SEQUENCE||' SEQ '||L_REQ_REC.PARAM9 , 2 );
3123          END IF;
3124      END LOOP;
3125 
3126      IF l_debug_level  > 0 THEN
3127        oe_debug_pub.add('OUT OF INSERT/UPDATE/DELETE OPTIONS LOOPS ' , 1);
3128      END IF;
3129 
3130 
3131      -- delete previous data.
3132      IF (l_html_pieces.COUNT <> 0) THEN
3133          l_html_pieces.DELETE;
3134      END IF;
3135 
3136 
3137       --get_transaction_id
3138       --(p_caller   => 'inside send_xml, before call to SPC validate');
3139             -- Added debug for bug 13435459
3140       IF l_debug_level  > 0 THEN
3141           oe_debug_pub.add(  'CALLING CZ_BATCH_VALIDATE.Validate' , 0.5);
3142       END IF;
3143 
3144       CZ_BATCH_VALIDATE.Validate
3145       ( config_input_list => l_batch_val_tbl ,
3146         init_message      => l_xml_hdr ,
3147         config_messages   => l_html_pieces ,
3148         validation_status => l_validation_status ,
3149         URL               => l_url );
3150 
3151 
3152       --get_transaction_id
3153       --(p_caller   => 'inside send_xml, after call to SPC validate');
3154 
3155       IF l_debug_level  > 0 THEN
3156         oe_debug_pub.add('AFTER CALL TO SPC , STATUS : ' ||L_VALIDATION_STATUS , 1);
3157         oe_debug_pub.add(  'AFTER CZ_BATCH_VALIDATE.Validate' , 0.5);   -- Added debug for bug 13435459
3158       END IF;
3159 
3160       IF l_validation_status <> 0 THEN
3161          IF l_debug_level  > 0 THEN
3162            oe_debug_pub.add('DO NOT PROCESS RESULTS , ERROR ',1);
3163          END IF;
3164          RAISE FND_API.G_EXC_ERROR;
3165       END IF;
3166 
3167       IF (l_html_pieces.COUNT <= 0) THEN
3168           IF l_debug_level  > 0 THEN
3169             oe_debug_pub.add('HTML_PIECES COUNT IS <= 0' , 2 );
3170           END IF;
3171           RAISE FND_API.G_EXC_ERROR;
3172       END IF;
3173 
3174 
3175       l_rec_index := l_html_pieces.FIRST;
3176       LOOP
3177           IF l_debug_level  > 0 THEN
3178             oe_debug_pub.add(L_REC_INDEX ||': PART OF OUTPUT_MESSAGE: '
3179             || SUBSTR ( L_HTML_PIECES ( L_REC_INDEX ) , 1 , 100 ) , 2 );
3180           END IF;
3181 
3182           l_long_xml := l_long_xml || l_html_pieces(l_rec_index);
3183 
3184           EXIT WHEN l_rec_index = l_html_pieces.LAST;
3185           l_rec_index := l_html_pieces.NEXT(l_rec_index);
3186 
3187       END LOOP;
3188 
3189       -- if everything ok, set out NOCOPY  values
3190       x_out_xml_msg := l_long_xml;
3191       x_return_status := l_return_status;
3192 
3193       IF l_debug_level  > 0 THEN
3194         oe_debug_pub.add('EXITING OE_CONFIG_UTIL.SEND_INPUT_XML' , 1);
3195       END IF;
3196 
3197 EXCEPTION
3198       WHEN FND_API.G_EXC_ERROR THEN
3199          --get_transaction_id
3200          --(p_caller   => 'send_xml exc error, before call to SPC validate');
3201 
3202          x_return_status := FND_API.G_RET_STS_ERROR;
3203          FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_VALIDATION_FAILURE');
3204          OE_Msg_Pub.Add;
3205 
3206       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3207          --get_transaction_id
3208          --(p_caller   => 'send_xml unxp, before call to SPC validate');
3209          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3210          IF l_debug_level  > 0 THEN
3211            oe_debug_pub.add('AN UNEXP ERROR RAISED' , 1);
3212          END IF;
3213 
3214          IF l_debug_level  > 0 THEN
3215            oe_debug_pub.add('SEND_INPUT_XML ERROR: '
3216                             || SUBSTR ( SQLERRM , 1 , 100 ) , 1);
3217          END IF;
3218 
3219 
3220       WHEN OTHERS THEN
3221          --get_transaction_id
3222          --(p_caller=> 'send_xml others error, before call to SPC validate');
3223 
3224          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3225 
3226          IF l_debug_level  > 0 THEN
3227            oe_debug_pub.add
3228            ('SEND_INPUT_XML ERROR: ' || SUBSTR ( SQLERRM , 1 , 100 ) , 1);
3229          END IF;
3230 
3231 END Send_input_xml;
3232 
3233 
3234 /*-------------------------------------------------------------------------
3235 Procedure Name : Create_hdr_xml
3236 Description    : creates a batch validation header message.
3237 --------------------------------------------------------------------------*/
3238 
3239 PROCEDURE Create_hdr_xml
3240 ( p_model_line_id       IN NUMBER
3241 , p_ui_flag             IN VARCHAR2 := 'N'
3242 , x_xml_hdr             OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
3243 IS
3244 
3245       TYPE param_name_type IS TABLE OF VARCHAR2(30)
3246       INDEX BY BINARY_INTEGER;
3247 
3248       TYPE param_value_type IS TABLE OF VARCHAR2(200)
3249       INDEX BY BINARY_INTEGER;
3250 
3251       param_name  param_name_type;
3252       param_value param_value_type;
3253 
3254       l_rec_index BINARY_INTEGER;
3255 
3256       l_model_line_rec                  OE_Order_Pub.Line_Rec_Type;
3257 
3258       -- SPC specific params
3259       l_database_id                     VARCHAR2(100);
3260       l_save_config_behavior            VARCHAR2(30):= 'new_revision';
3261       l_ui_type                         VARCHAR2(30):= null;
3262       l_msg_behavior                    VARCHAR2(30):= 'brief';
3263 
3264       --ont parameters
3265       l_context_org_id                  VARCHAR2(80);
3266       l_inventory_item_id               VARCHAR2(80);
3267       l_config_header_id                VARCHAR2(80);
3268       l_config_rev_nbr                  VARCHAR2(80);
3269       l_model_quantity                  VARCHAR2(80);
3270       l_pricing_package_name            VARCHAR2(100)
3271                                         := 'OE_Config_Price_Util';
3272       l_price_items_proc                VARCHAR2(100)
3273                                         := 'OE_Config_Price_Items';
3274       l_configurator_session_key        VARCHAR2(100):= NULL;
3275       l_session_id                      VARCHAR2(80)
3276                                         := FND_PROFILE.Value('DB_SESSION_ID');
3277       l_count                           NUMBER;
3278       -- message related
3279       l_xml_hdr                         VARCHAR2(2000):=
3280                                         '<initialize>';
3281       l_dummy                           VARCHAR2(500) := NULL;
3282       l_return_status                   VARCHAR2(1)
3283                                         := FND_API.G_RET_STS_SUCCESS;
3284 
3285       l_config_effective_date           DATE;
3286       l_old_behavior                    VARCHAR2(1);
3287       l_frozen_model_bill               VARCHAR2(1);
3288       --
3289       l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3290       --
3291   BEGIN
3292 
3293       IF l_debug_level  > 0 THEN
3294         oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.CREATE_HDR_XML' , 1);
3295       END IF;
3296 
3297       OE_LINE_UTIL.Query_Row(p_line_id  => p_model_line_id
3298                             ,x_line_rec => l_model_line_rec);
3299 
3300       -- now set the values from model_rec and org_id
3301       l_context_org_id        :=
3302                  OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
3303       l_inventory_item_id     := to_char(l_model_line_rec.inventory_item_id);
3304       l_config_header_id      := to_char(l_model_line_rec.config_header_id);
3305       l_config_rev_nbr        := to_char(l_model_line_rec.config_rev_nbr);
3306 
3307 
3308       l_model_quantity        := to_char(l_model_line_rec.ordered_quantity);
3309 
3310 
3311       IF l_debug_level  > 0 THEN
3312         oe_debug_pub.add('QUERIED FROM OE_LINES: ' || ' QTY: '
3313                           || L_MODEL_QUANTITY || ' CONFIG-HDR: '
3314                           || L_CONFIG_HEADER_ID || ' CONFIG-REV: '
3315                           || L_CONFIG_REV_NBR || ' ORG-ID: '
3316                           || L_CONTEXT_ORG_ID || ' ITEM-ID: '
3317                           || L_INVENTORY_ITEM_ID , 2 );
3318       END IF;
3319 
3320      -- profiles and env. variables.
3321       l_database_id            := fnd_web_config.database_id;
3322       IF l_debug_level  > 0 THEN
3323         oe_debug_pub.add('DATABASE_ID: '|| L_DATABASE_ID , 2 );
3324       END IF;
3325 
3326       -- set param_names
3327 
3328       param_name(1)  := 'database_id';
3329       param_name(2)  := 'context_org_id';
3330       param_name(3)  := 'config_creation_date';
3331       param_name(4)  := 'calling_application_id';
3332       param_name(5)  := 'responsibility_id';
3333       param_name(6)  := 'model_id';
3334       param_name(7)  := 'config_header_id';
3335       param_name(8)  := 'config_rev_nbr';
3336       param_name(9)  := 'read_only';
3337       param_name(10) := 'save_config_behavior';
3338       param_name(11) := 'ui_type';
3339       param_name(12) := 'validation_org_id';
3340       param_name(13) := 'terminate_msg_behavior';
3341       param_name(14) := 'model_quantity';
3342       param_name(15) := 'icx_session_ticket';
3343       param_name(16) := 'client_header';
3344       param_name(17) := 'client_line';
3345       param_name(18) := 'sbm_flag';
3346       param_name(19)  := 'config_effective_date';
3347       param_name(20)  := 'config_model_lookup_date';
3348       l_count := 20;
3349 
3350       IF p_ui_flag = 'Y' THEN
3351         param_name(21) := 'pricing_package_name';
3352         param_name(22) := 'price_mult_items_proc';
3353         param_name(23) := 'configurator_session_key';
3354         l_count := 23;
3355       END IF;
3356         -- set param values
3357 
3358       param_value(1)  := l_database_id;
3359       param_value(2)  := l_context_org_id;
3360       param_value(3)  := to_char(l_model_line_rec.creation_date,
3361                                          'MM-DD-YYYY-HH24-MI-SS');
3362       --5249719: hardcoding application id
3363       param_value(4)  := 660; --fnd_profile.value('RESP_APPL_ID');
3364       param_value(5)  := fnd_profile.value('RESP_ID');
3365       param_value(6)  := l_inventory_item_id;
3366       param_value(7)  := l_config_header_id;
3367       param_value(8)  := l_config_rev_nbr;
3368       param_value(9)  := null;
3369       param_value(10) := l_save_config_behavior;
3370       param_value(11) := l_ui_type;
3371       param_value(12) := null;
3372       param_value(13) := l_msg_behavior;
3373       param_value(14) := l_model_quantity;
3374       param_value(15) := cz_cf_api.icx_session_ticket;
3375       param_value(16) := to_char(l_model_line_rec.header_id);
3376       param_value(17) := to_char(l_model_line_rec.line_id);
3377 
3378       IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110508' THEN
3379         IF l_debug_level  > 0 THEN
3380           oe_debug_pub.add('UCFGB MI , PACK H NEW LOGIC' , 1);
3381         END IF;
3382         param_value(18) := 'TRUE';
3383       ELSE
3384         param_value(18) := 'FALSE';
3385       END IF;
3386 
3387       OE_Config_Util.Get_Config_Effective_Date
3388       ( p_model_line_rec        => l_model_line_rec
3389        ,x_old_behavior          => l_old_behavior
3390        ,x_config_effective_date => l_config_effective_date
3391        ,x_frozen_model_bill     => l_frozen_model_bill);
3392 
3393       IF l_old_behavior = 'N' THEN
3394         param_value(19) := to_char(l_config_effective_date,
3395                            'MM-DD-YYYY-HH24-MI-SS');
3396         param_value(20) := param_value(19);
3397       ELSE
3398         param_value(19) := null;
3399         param_value(20) := null;
3400 
3401         IF l_debug_level  > 0 THEN
3402           oe_debug_pub.add('old behavior no dates', 2 );
3403         END IF;
3404       END IF;
3405 
3406 
3407       IF p_ui_flag = 'Y' THEN
3408         param_value(21) := l_pricing_package_name;
3409         param_value(22) := l_price_items_proc;
3410 
3411         l_configurator_session_key
3412               := ( p_model_line_id || '#' || l_session_id);
3413 
3414         IF l_debug_level  > 0 THEN
3415           oe_debug_pub.add('CONFIG SESSION KEY : '
3416                             || L_CONFIGURATOR_SESSION_KEY , 2 );
3417         END IF;
3418 
3419         param_value(23) := l_configurator_session_key;
3420       END IF;
3421 
3422       IF l_debug_level  > 0 THEN
3423         oe_debug_pub.add('INSIDE CREATE_HDR_XML , PARAMETERS ARE SET' , 2 );
3424       END IF;
3425 
3426 
3427       l_rec_index := 1;
3428 
3429       LOOP
3430          -- ex : <param name="config_header_id">1890</param>
3431 
3432          IF (param_value(l_rec_index) IS NOT NULL) THEN
3433 
3434              l_dummy :=  '<param name=' ||
3435                          '"' || param_name(l_rec_index) || '"'
3436                          ||'>'|| param_value(l_rec_index) ||
3437                          '</param>';
3438 
3439              l_xml_hdr := l_xml_hdr || l_dummy;
3440 
3441           END IF;
3442 
3443           l_dummy := NULL;
3444 
3445           l_rec_index := l_rec_index + 1;
3446           EXIT WHEN l_rec_index > l_count;
3447 
3448       END LOOP;
3449 
3450 
3451       -- add termination tags
3452 
3453       l_xml_hdr := l_xml_hdr || '</initialize>';
3454       l_xml_hdr := REPLACE(l_xml_hdr, ' ' , '+');
3455 
3456       IF l_debug_level  > 0 THEN
3457         oe_debug_pub.add('1ST PART OF CREATE_HDR_XML IS : '
3458                          ||SUBSTR ( L_XML_HDR , 1 , 200 ) , 3 );
3459         oe_debug_pub.add('2ND PART OF CREATE_HDR_XML IS : '
3460                          ||SUBSTR ( L_XML_HDR , 201 , 200 ) , 3 );
3461         oe_debug_pub.add('3RD PART OF CREATE_HDR_XML IS : '
3462                          ||SUBSTR ( L_XML_HDR , 401 , 200 ) , 3 );
3463         oe_debug_pub.add('4TH PART OF CREATE_HDR_XML IS : '
3464                          ||SUBSTR ( L_XML_HDR , 601 , 200 ) , 3 );
3465       END IF;
3466 
3467       x_xml_hdr := l_xml_hdr;
3468       IF l_debug_level  > 0 THEN
3469         oe_debug_pub.add('LENGTH OF INI MSG:' || LENGTH ( L_XML_HDR ) , 3 );
3470         oe_debug_pub.add('LEAVING CREATE_HDR_XML' , 3 );
3471       END IF;
3472 EXCEPTION
3473    when others then
3474       IF l_debug_level  > 0 THEN
3475         oe_debug_pub.add('EXCEPTION IN CREATE_HDR_XML '|| SQLERRM , 3 );
3476       END IF;
3477       RAISE;
3478 END Create_hdr_xml;
3479 
3480 
3481 
3482 /*-------------------------------------------------------------------------
3483 Procedure Name : Parse_output_xml
3484 Description    : Parses the output of SPC to get the valid and complete flag
3485                  populates messages from SPC in oe's message stack.
3486 
3487 Change Record  :
3488 Bug 2292308    : Display different messages for Incomplete and
3489                  Invalid Configurations.
3490 --------------------------------------------------------------------------*/
3491 
3492 PROCEDURE  Parse_output_xml
3493                (p_xml                IN LONG,
3494                   p_line_id            IN NUMBER,
3495                   x_valid_config       OUT NOCOPY /* file.sql.39 change */ VARCHAR2,
3496                   x_complete_config    OUT NOCOPY /* file.sql.39 change */ VARCHAR2,
3497                   x_config_header_id   OUT NOCOPY /* file.sql.39 change */ NUMBER,
3498                   x_config_rev_nbr     OUT NOCOPY /* file.sql.39 change */ NUMBER,
3499                   x_return_status      OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
3500 IS
3501 
3502       l_exit_start_tag                VARCHAR2(20) := '<EXIT>';
3503       l_exit_end_tag                  VARCHAR2(20) := '</EXIT>';
3504       l_exit_start_pos                NUMBER;
3505       l_exit_end_pos                  NUMBER;
3506 
3507       l_valid_config_start_tag          VARCHAR2(30) := '<VALID_CONFIGURATION>';
3508       l_valid_config_end_tag            VARCHAR2(30) := '</VALID_CONFIGURATION>';
3509       l_valid_config_start_pos          NUMBER;
3510       l_valid_config_end_pos            NUMBER;
3511 
3512       l_complete_config_start_tag       VARCHAR2(30) := '<COMPLETE_CONFIGURATION>';
3513       l_complete_config_end_tag         VARCHAR2(30) := '</COMPLETE_CONFIGURATION>';
3514       l_complete_config_start_pos       NUMBER;
3515       l_complete_config_end_pos         NUMBER;
3516 
3517       l_config_header_id_start_tag      VARCHAR2(20) := '<CONFIG_HEADER_ID>';
3518       l_config_header_id_end_tag        VARCHAR2(20) := '</CONFIG_HEADER_ID>';
3519       l_config_header_id_start_pos      NUMBER;
3520       l_config_header_id_end_pos        NUMBER;
3521 
3522       l_config_rev_nbr_start_tag        VARCHAR2(20) := '<CONFIG_REV_NBR>';
3523       l_config_rev_nbr_end_tag          VARCHAR2(20) := '</CONFIG_REV_NBR>';
3524       l_config_rev_nbr_start_pos        NUMBER;
3525       l_config_rev_nbr_end_pos          NUMBER;
3526 
3527       l_message_text_start_tag          VARCHAR2(20) := '<MESSAGE_TEXT>';
3528       l_message_text_end_tag            VARCHAR2(20) := '</MESSAGE_TEXT>';
3529       l_message_text_start_pos          NUMBER;
3530       l_message_text_end_pos            NUMBER;
3531 
3532       l_message_type_start_tag          VARCHAR2(20) := '<MESSAGE_TYPE>';
3533       l_message_type_end_tag            VARCHAR2(20) := '</MESSAGE_TYPE>';
3534       l_message_type_start_pos          NUMBER;
3535       l_message_type_end_pos            NUMBER;
3536 
3537       l_exit                            VARCHAR(20);
3538       l_config_header_id                NUMBER;
3539       l_config_rev_nbr                  NUMBER;
3540       l_message_text                    VARCHAR2(2000);
3541       l_message_type                    VARCHAR2(200);
3542       l_list_price                      NUMBER;
3543       l_selection_line_id               NUMBER;
3544       l_valid_config                    VARCHAR2(10);
3545       l_complete_config                 VARCHAR2(10);
3546       l_header_id                       NUMBER;
3547       l_return_status                   VARCHAR2(1) :=
3548                                         FND_API.G_RET_STS_SUCCESS;
3549       l_return_status_del               VARCHAR2(1);
3550       l_msg                             VARCHAR2(2000);
3551       l_constraint                      VARCHAR2(16);
3552       l_flag                            VARCHAR2(1) := 'N';
3553 
3554       --
3555       l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3556       --
3557 BEGIN
3558 
3559       IF l_debug_level  > 0 THEN
3560         oe_debug_pub.add('ENTERING OE_CONGIG_UTIL.PARSE_OUTPUT_XML' , 1);
3561       END IF;
3562 
3563 
3564       l_exit_start_pos :=
3565                     INSTR(p_xml, l_exit_start_tag,1, 1) +
3566                                 length(l_exit_start_tag);
3567 
3568       l_exit_end_pos   :=
3569                           INSTR(p_xml, l_exit_end_tag,1, 1) - 1;
3570 
3571       l_exit           := SUBSTR (p_xml, l_exit_start_pos,
3572                                   l_exit_end_pos - l_exit_start_pos + 1);
3573 
3574       IF l_debug_level  > 0 THEN
3575         oe_debug_pub.add('L_EXIT: ' || L_EXIT , 3 );
3576       END IF;
3577 
3578       -- if error go to msg etc.
3579       IF nvl(l_exit,'ERROR') <> 'ERROR'  THEN
3580 
3581         l_valid_config_start_pos :=
3582                 INSTR(p_xml, l_valid_config_start_tag,1, 1) +
3583           length(l_valid_config_start_tag);
3584 
3585         l_valid_config_end_pos :=
3586                 INSTR(p_xml, l_valid_config_end_tag,1, 1) - 1;
3587 
3588         l_valid_config := SUBSTR( p_xml, l_valid_config_start_pos,
3589                                   l_valid_config_end_pos -
3590                                   l_valid_config_start_pos + 1);
3591 
3592         IF l_debug_level  > 0 THEN
3593           oe_debug_pub.add('GG1: '|| L_VALID_CONFIG , 3 );
3594         END IF;
3595 
3596         /* ex :- <VALID_CONFIGURATION>abc</VALID_CONFIGURATION>
3597            1st instr : posin of a(22), 2nd instr gives posn of c(24)
3598            substr gives string starting from
3599            posn a to posn c - posn a + 1(3)*/
3600 
3601         l_complete_config_start_pos :=
3602                    INSTR(p_xml, l_complete_config_start_tag,1, 1) +
3603         length(l_complete_config_start_tag);
3604         l_complete_config_end_pos :=
3605                    INSTR(p_xml, l_complete_config_end_tag,1, 1) - 1;
3606 
3607         l_complete_config := SUBSTR( p_xml, l_complete_config_start_pos,
3608                                      l_complete_config_end_pos -
3609                                      l_complete_config_start_pos + 1);
3610 
3611         IF l_debug_level  > 0 THEN
3612           oe_debug_pub.add('GG2: '|| L_COMPLETE_CONFIG , 3 );
3613         END IF;
3614 
3615 
3616           IF (nvl(l_valid_config, 'N')  <> 'TRUE') THEN
3617               IF l_debug_level  > 0 THEN
3618                 oe_debug_pub.add('SPC RETURNED VALID_FLAG AS NULL/FALSE' , 2 );
3619               END IF;
3620               l_flag := 'Y';
3621           END IF ;
3622 
3623 
3624           IF (nvl(l_complete_config, 'N') <> 'TRUE' ) THEN
3625               IF l_debug_level  > 0 THEN
3626                 oe_debug_pub.add('COMPLETE_FLAG AS NULL/FALSE' , 2 );
3627               END IF;
3628               l_flag := 'Y';
3629           END IF;
3630 
3631         IF l_debug_level  > 0 THEN
3632           oe_debug_pub.add('SPC VALID_CONFIG FLAG: ' || L_VALID_CONFIG , 2 );
3633           oe_debug_pub.add('COMPLETE_CONFIG FLAG: ' || L_COMPLETE_CONFIG , 2 );
3634         END IF;
3635 
3636       END IF; /* if not error */
3637 
3638 
3639       -- parsing message_text and type is not req. I use it for debugging.
3640 
3641       l_message_text_start_pos :=
3642                  INSTR(p_xml, l_message_text_start_tag,1, 1) +
3643                        length(l_message_text_start_tag);
3644       l_message_text_end_pos :=
3645                  INSTR(p_xml, l_message_text_end_tag,1, 1) - 1;
3646 
3647       l_message_text := SUBSTR( p_xml, l_message_text_start_pos,
3648                                 l_message_text_end_pos -
3649                                 l_message_text_start_pos + 1);
3650 
3651       IF l_debug_level  > 0 THEN
3652         oe_debug_pub.add('GG3: '|| L_MESSAGE_TEXT , 3 );
3653       END IF;
3654 
3655       l_message_type_start_pos :=
3656                  INSTR(p_xml, l_message_type_start_tag,1, 1) +
3657                  length(l_message_type_start_tag);
3658       l_message_type_end_pos :=
3659                  INSTR(p_xml, l_message_type_end_tag,1, 1) - 1;
3660 
3661       l_message_type := SUBSTR( p_xml, l_message_type_start_pos,
3662                                 l_message_type_end_pos -
3663                                 l_message_type_start_pos + 1);
3664 
3665 
3666       -- get the latest config_header_id, and rev_nbr to get
3667       -- messages if any.
3668 
3669       IF l_debug_level  > 0 THEN
3670         oe_debug_pub.add('SPC RETURNED MESSAGE_TEXT: '|| L_MESSAGE_TEXT , 2 );
3671         oe_debug_pub.add('SPC RETURNED MESSAGE_TYPE: '|| L_MESSAGE_TYPE , 2 );
3672       END IF;
3673 
3674 
3675       l_config_header_id_start_pos :=
3676                        INSTR(p_xml, l_config_header_id_start_tag, 1, 1)+
3677                        length(l_config_header_id_start_tag);
3678 
3679       l_config_header_id_end_pos :=
3680                        INSTR(p_xml, l_config_header_id_end_tag, 1, 1) - 1;
3681 
3682       l_config_header_id :=
3683                        to_number(SUBSTR( p_xml,l_config_header_id_start_pos,
3684                                          l_config_header_id_end_pos -
3685                                          l_config_header_id_start_pos + 1));
3686 
3687 
3688       l_config_rev_nbr_start_pos :=
3689                        INSTR(p_xml, l_config_rev_nbr_start_tag, 1, 1)+
3690                              length(l_config_rev_nbr_start_tag);
3691 
3692       l_config_rev_nbr_end_pos :=
3693                        INSTR(p_xml, l_config_rev_nbr_end_tag, 1, 1) - 1;
3694 
3695       l_config_rev_nbr :=
3696                        to_number(SUBSTR( p_xml,l_config_rev_nbr_start_pos,
3697                                          l_config_rev_nbr_end_pos -
3698                                          l_config_rev_nbr_start_pos + 1));
3699 
3700       IF l_debug_level  > 0 THEN
3701         oe_debug_pub.add('CONFIG_HEADER_ID AS:' || L_CONFIG_HEADER_ID  , 2 );
3702         oe_debug_pub.add('CONFIG_REV_NBR AS:' || L_CONFIG_REV_NBR , 2 );
3703       END IF;
3704 
3705 
3706       IF (l_flag = 'Y' ) OR
3707           l_exit is NULL OR
3708           l_exit = 'ERROR'  THEN
3709 
3710           IF l_debug_level  > 0 THEN
3711             oe_debug_pub.add('GETTING MESSAGES FROM CZ_CONFIG_MESSAGES' , 2 );
3712           END IF;
3713 
3714           Message_From_Cz
3715           ( p_line_id           => p_line_id,
3716             p_valid_config      => l_valid_config,
3717             p_complete_config   => l_complete_config,
3718             p_config_header_id  => l_config_header_id,
3719             p_config_rev_nbr    => l_config_rev_nbr);
3720 
3721       END IF;
3722 
3723       IF L_MESSAGE_TEXT IS NOT NULL THEN
3724          oe_msg_pub.add_text(L_MESSAGE_TEXT);
3725       END IF;
3726 
3727       IF l_exit is NULL OR
3728          l_exit = 'ERROR'  THEN
3729 
3730          IF l_debug_level  > 0 THEN
3731            oe_debug_pub.add('SPC RETURNED ERROR , FAIL TRANSACTION' , 2 );
3732          END IF;
3733 
3734          -- delete the SPC configuration in error
3735          OE_Config_Pvt.Delete_Config
3736                         ( p_config_hdr_id   =>  l_config_header_id
3737                          ,p_config_rev_nbr  =>  l_config_rev_nbr
3738                          ,x_return_status   =>  l_return_status_del);
3739 
3740          RAISE FND_API.G_EXC_ERROR;
3741       END IF;
3742 
3743 
3744           -- if everything ok, set return values
3745       x_return_status    := l_return_status;
3746       x_config_header_id := l_config_header_id;
3747       x_config_rev_nbr   := l_config_rev_nbr;
3748       x_complete_config  := nvl(l_complete_config, 'FALSE');
3749       x_valid_config     := nvl(l_valid_config, 'FALSE');
3750 
3751 
3752       IF l_debug_level  > 0 THEN
3753         oe_debug_pub.add('EXITING OE_CONFIG_UTIL.PARSE_OUTPUT_XML' , 1);
3754       END IF;
3755 
3756 EXCEPTION
3757       WHEN FND_API.G_EXC_ERROR THEN
3758          x_return_status := FND_API.G_RET_STS_ERROR;
3759          IF l_debug_level  > 0 THEN
3760            oe_debug_pub.add('SPC EXIT TAG IS ERROR' , 1);
3761          END IF;
3762 
3763       WHEN OTHERS THEN
3764          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3765          IF l_debug_level  > 0 THEN
3766            oe_debug_pub.add('PARSE_OUTPUT_XML ERROR: '
3767                             || SUBSTR ( SQLERRM , 1 , 100 ) , 1);
3768          END IF;
3769 
3770 END Parse_output_xml;
3771 
3772 
3773 /*----------------------------------------------------------------------
3774 Procedure Name : Query_Options
3775 Description    :
3776 -----------------------------------------------------------------------*/
3777 PROCEDURE Query_Options
3778 (p_top_model_line_id IN NUMBER
3779 ,p_send_cancel_lines IN VARCHAR2 := 'N'
3780 ,p_source_type       IN VARCHAR2 := ''
3781 ,x_line_tbl          OUT NOCOPY OE_ORDER_PUB.line_tbl_type)
3782 IS
3783     l_header_id           NUMBER := 0;
3784     l_line_rec            OE_Order_PUB.Line_Rec_Type
3785                           := OE_Order_PUB.G_MISS_LINE_REC;
3786 
3787 /* adding component number in this cursor to fix bug 2733667 */
3788 
3789     CURSOR c1 IS
3790     SELECT  line_id
3791     FROM    OE_ORDER_LINES_ALL
3792     WHERE   HEADER_ID = l_header_id AND
3793             TOP_MODEL_LINE_ID   = p_top_model_line_id
3794     ORDER BY line_number,shipment_number,nvl(option_number,-1),nvl(component_number,-1);
3795 
3796     --
3797     l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3798     --
3799 BEGIN
3800 
3801     IF l_debug_level  > 0 THEN
3802       oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.QUERY_OPTIONS' , 1);
3803       oe_debug_pub.add('SEND_CANCEL_LINES: '|| P_SEND_CANCEL_LINES , 3 );
3804     END IF;
3805 
3806     BEGIN
3807         SELECT header_id
3808         INTO   l_header_id
3809         FROM   oe_order_lines_all
3810         WHERE  line_id = p_top_model_line_id;
3811     EXCEPTION
3812         WHEN NO_DATA_FOUND THEN
3813              l_header_id := 0;
3814     END;
3815 
3816     --  Loop over fetched records
3817     FOR op in C1 LOOP
3818 
3819       OE_Line_Util.Query_Row( p_line_id  => op.line_id
3820                              ,x_line_rec => l_line_rec );
3821 
3822       IF (l_line_rec.open_flag = 'Y' OR
3823           p_send_cancel_lines = 'Y') AND
3824           l_line_rec.source_type_code =
3825             nvl(p_source_type, l_line_rec.source_type_code) THEN
3826 
3827         IF l_debug_level  > 0 THEN
3828           oe_debug_pub.add(L_LINE_REC.SOURCE_TYPE_CODE||' ADDING '
3829                            ||L_LINE_REC.OPEN_FLAG , 3 );
3830         END IF;
3831 
3832         x_line_tbl(x_line_tbl.COUNT + 1) := l_line_rec;
3833       END IF;
3834     END LOOP;
3835 
3836     IF l_debug_level  > 0 THEN
3837       oe_debug_pub.add('EXITING OE_CONFIG_UTIL.QUERY_OPTIONS' , 1);
3838     END IF;
3839 
3840 END;
3841 
3842 
3843 /*----------------------------------------------------------------------
3844 Procedure Name : Query_ATO_Options
3845 Description    :
3846 -----------------------------------------------------------------------*/
3847 PROCEDURE Query_ATO_Options
3848 ( p_ato_line_id       IN NUMBER
3849  ,p_send_cancel_lines IN VARCHAR2 := 'N'
3850  ,p_source_type       IN VARCHAR2 := ''
3851  ,x_line_tbl          OUT NOCOPY OE_ORDER_PUB.line_tbl_type)
3852 IS
3853     l_top_model_line_id   NUMBER := 0;
3854     l_header_id           NUMBER := 0;
3855     l_line_rec            OE_Order_PUB.Line_Rec_Type
3856                           := OE_Order_PUB.G_MISS_LINE_REC;
3857 
3858 
3859     CURSOR c1 IS
3860     SELECT  line_id
3861     FROM    OE_ORDER_LINES_ALL
3862     WHERE   HEADER_ID = l_header_id AND
3863             TOP_MODEL_LINE_ID   = l_top_model_line_id AND
3864             ATO_LINE_ID   = p_ato_line_id
3865     ORDER BY line_number,shipment_number,nvl(option_number,-1);
3866     --
3867     l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3868     --
3869 BEGIN
3870 
3871     IF l_debug_level  > 0 THEN
3872       oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.QUERY_ATO_OPTIONS' , 1);
3873       oe_debug_pub.add('SEND_CANCEL_LINES: '|| P_SEND_CANCEL_LINES , 3 );
3874     END IF;
3875 
3876      BEGIN
3877         SELECT top_model_line_id ,header_id
3878         INTO   l_top_model_line_id,l_header_id
3879         FROM   oe_order_lines_all
3880         WHERE  line_id = p_ato_line_id;
3881      EXCEPTION
3882         WHEN NO_DATA_FOUND THEN
3883              l_top_model_line_id := 0;
3884              l_header_id := 0;
3885      END;
3886 
3887     --  Loop over fetched records
3888     FOR ato_option in C1 LOOP
3889 
3890       OE_Line_Util.Query_Row( p_line_id  => ato_option.line_id
3891                              ,x_line_rec => l_line_rec );
3892 
3893       IF (l_line_rec.open_flag = 'Y' OR
3894           p_send_cancel_lines = 'Y') AND
3895           l_line_rec.source_type_code =
3896             nvl(p_source_type, l_line_rec.source_type_code) THEN
3897 
3898         IF l_debug_level  > 0 THEN
3899           oe_debug_pub.add(L_LINE_REC.SOURCE_TYPE_CODE||' ADDING '
3900                            ||L_LINE_REC.OPEN_FLAG , 3 );
3901         END IF;
3902         l_line_rec.reserved_quantity := Null;
3903         x_line_tbl(x_line_tbl.COUNT + 1) := l_line_rec;
3904       END IF;
3905 
3906     END LOOP;
3907 
3908     IF l_debug_level  > 0 THEN
3909       oe_debug_pub.add('EXITING OE_CONFIG_UTIL.QUERY_ATO_OPTIONS' , 1);
3910     END IF;
3911 
3912 EXCEPTION
3913   WHEN OTHERS THEN
3914     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3915 END;
3916 
3917 
3918 /*----------------------------------------------------------------------
3919 Procedure Name : Explode
3920 Description    :
3921 -----------------------------------------------------------------------*/
3922 Procedure Explode
3923 ( p_validation_org IN  NUMBER
3924 , p_group_id       IN  NUMBER := NULL
3925 , p_session_id     IN  NUMBER := NULL
3926 , p_levels         IN  NUMBER := 60
3927 , p_stdcompflag    IN  VARCHAR2
3928 , p_exp_quantity   IN  NUMBER := NULL
3929 , p_top_item_id    IN  NUMBER
3930 , p_revdate        IN  DATE
3931 , p_component_code IN  VARCHAR2 := NULL
3932 , x_msg_data       OUT NOCOPY /* file.sql.39 change */ VARCHAR2
3933 , x_error_code     OUT NOCOPY /* file.sql.39 change */ NUMBER
3934 , x_return_status  OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
3935 IS
3936   l_group_id   NUMBER; -- bom out NOCOPY param
3937   --
3938   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
3939   --
3940 BEGIN
3941 
3942     IF l_debug_level  > 0 THEN
3943       oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.EXPLODE' , 1);
3944       oe_debug_pub.add(' EXPLOSION TYPE ' || P_STDCOMPFLAG , 2 );
3945     END IF;
3946 
3947     BOMPNORD.Bmxporder_Explode_For_Order(
3948           org_id             => p_validation_org,
3949           copy_flag          => 2,
3950           expl_type          => p_stdcompflag,
3951           order_by           => 2,
3952           grp_id             => l_group_id,
3953           session_id         => p_session_id,
3954           levels_to_explode  => 60,
3955           item_id            => p_top_item_id,
3956           rev_date           => to_char(p_revdate,'YYYY/MM/DD HH24:MI'),
3957           user_id            => 0,
3958           commit_flag        => 'N',
3959           err_msg            => x_msg_data,
3960           error_code         => x_error_code);
3961 
3962     IF l_debug_level  > 0 THEN
3963       oe_debug_pub.add('AFTER CALLING BOM EXPLODE API' , 2 );
3964     END IF;
3965 
3966     IF x_error_code <> 0 THEN
3967       IF l_debug_level  > 0 THEN
3968         oe_debug_pub.add('ERROR IN BOM EXPLOSION' , 2 );
3969         oe_debug_pub.add('ERROR CODE IS ' || X_ERROR_CODE , 2 );
3970       END IF;
3971 
3972       IF x_msg_data is not null THEN
3973         IF l_debug_level  > 0 THEN
3974           oe_debug_pub.add('BOM MSG NAME: '
3975                            || SUBSTR ( X_MSG_DATA , 1 , 250 ) , 2 );
3976         END IF;
3977 
3978         -- girish from bom team told err_msg is msg name, track bug 1623728
3979 --        FND_MESSAGE.Set_Name('BOM', x_msg_data);
3980 --        oe_msg_pub.add;
3981         -- After BOM ER 2700606, BOM is sending a complete message
3982           oe_msg_pub.add_text(p_message_text => x_msg_data);
3983 
3984       END IF;
3985 
3986       RAISE FND_API.G_EXC_ERROR;
3987     END IF;
3988 
3989 
3990     x_return_status := FND_API.G_RET_STS_SUCCESS;
3991     IF l_debug_level  > 0 THEN
3992       oe_debug_pub.add('EXITING OE_CONFIG_UTIL.EXPLODE' , 1);
3993     END IF;
3994 
3995 EXCEPTION
3996    WHEN FND_API.G_EXC_ERROR THEN
3997         x_return_status := FND_API.G_RET_STS_ERROR;
3998 END Explode;
3999 
4000 /*----------------------------------------------------------------------
4001 Procedure Name : Query_Included_Item
4002 Description    : CURRENTLY NOT USED.
4003 -----------------------------------------------------------------------*/
4004 PROCEDURE Query_Included_Item
4005 ( p_top_model_line_id     IN  NUMBER
4006 , p_component_seqeunce_id IN  NUMBER
4007 , p_component_code        OUT NOCOPY /* file.sql.39 change */ VARCHAR2
4008 , x_line_rec              OUT NOCOPY  OE_ORDER_PUB.line_rec_type)
4009 IS
4010 l_line_rec OE_ORDER_PUB.line_rec_type;
4011 --
4012 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4013 --
4014 BEGIN
4015    x_line_rec := l_line_rec;
4016 END Query_Included_Item;
4017 
4018 /*----------------------------------------------------------------------
4019 Procedure Name : Query_Included_Items
4020 Description    : Queries all the included items for a particular
4021                  parent line.
4022 -----------------------------------------------------------------------*/
4023 PROCEDURE Query_Included_Items
4024 ( p_line_id           IN  NUMBER
4025 , p_header_id         IN  NUMBER   := FND_API.G_MISS_NUM
4026 , p_top_model_line_id IN  NUMBER   := FND_API.G_MISS_NUM
4027 , p_send_cancel_lines IN  VARCHAR2 := 'N'
4028 , p_source_type       IN  VARCHAR2 := ''
4029 , x_line_tbl          OUT NOCOPY OE_ORDER_PUB.line_tbl_type)
4030 IS
4031     l_top_model_line_id   NUMBER := 0;
4032     l_header_id           NUMBER := 0;
4033     l_line_rec            OE_Order_PUB.Line_Rec_Type
4034                           := OE_Order_PUB.G_MISS_LINE_REC;
4035 
4036 
4037     CURSOR c1 IS
4038     SELECT  line_id
4039     FROM    OE_ORDER_LINES_ALL
4040     WHERE   HEADER_ID = l_header_id AND
4041             TOP_MODEL_LINE_ID   = l_top_model_line_id AND
4042             LINK_TO_LINE_ID   = p_line_id AND
4043             ITEM_TYPE_CODE    = OE_GLOBALS.G_ITEM_INCLUDED
4044     ORDER BY line_number,shipment_number,nvl(option_number,-1);
4045 
4046 --
4047 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4048 --
4049 BEGIN
4050 
4051      IF l_debug_level  > 0 THEN
4052        oe_debug_pub.add('SEND_CANCEL_LINES: '|| P_SEND_CANCEL_LINES , 3 );
4053      END IF;
4054 
4055      IF p_header_id = FND_API.G_MISS_NUM AND
4056         p_top_model_line_id = FND_API.G_MISS_NUM THEN
4057 
4058         BEGIN
4059            SELECT top_model_line_id ,header_id
4060            INTO   l_top_model_line_id,l_header_id
4061            FROM   oe_order_lines_all
4062            WHERE  line_id = p_line_id;
4063         EXCEPTION
4064            WHEN NO_DATA_FOUND THEN
4065                 l_top_model_line_id := 0;
4066                 l_header_id := 0;
4067         END;
4068 
4069       ELSE
4070 
4071         l_top_model_line_id := p_top_model_line_id;
4072         l_header_id := p_header_id;
4073 
4074       END IF;
4075 
4076          IF l_debug_level  > 0 THEN
4077            oe_debug_pub.add('HEADER ID , TOP MODEL LINE ID '
4078                             ||L_HEADER_ID||'/'||L_TOP_MODEL_LINE_ID , 3 );
4079          END IF;
4080 
4081     --  Loop over fetched records
4082     FOR inc_item in C1 LOOP
4083 
4084       OE_Line_Util.Query_Row( p_line_id  => inc_item.line_id
4085                              ,x_line_rec => l_line_rec );
4086 
4087       IF (l_line_rec.open_flag = 'Y' OR
4088           p_send_cancel_lines = 'Y') AND
4089           l_line_rec.source_type_code =
4090             nvl(p_source_type, l_line_rec.source_type_code) THEN
4091 
4092         IF l_debug_level  > 0 THEN
4093           oe_debug_pub.add(L_LINE_REC.SOURCE_TYPE_CODE||' ADDING '
4094                            ||L_LINE_REC.OPEN_FLAG , 3 );
4095         END IF;
4096 
4097         x_line_tbl(x_line_tbl.COUNT + 1) := l_line_rec;
4098       END IF;
4099 
4100     END LOOP;
4101 
4102     IF l_debug_level  > 0 THEN
4103       oe_debug_pub.add('EXITING OE_CONFIG_UTIL.QUERY_INCLUDED_ITEMS' , 1);
4104     END IF;
4105 
4106 EXCEPTION
4107     WHEN OTHERS THEN
4108       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4109 END Query_Included_Items;
4110 
4111 -- forward declaration
4112 
4113 PROCEDURE update_component_number
4114 (p_line_id           IN  NUMBER ,
4115  p_top_model_line_id IN  NUMBER ,
4116  x_return_status     OUT NOCOPY /* file.sql.39 change */ VARCHAR2);
4117 
4118 /*----------------------------------------------------------------------
4119 Procedure Name : Process_Included_Items
4120 Description    :
4121 This procedure is used to explode the included items for a
4122 PTO model/class or a kit. This procedure is called from
4123 oe_line_util if,
4124  the included items freeze method profile options is ENTRY or NULL.
4125  a new line is created in a booked order.
4126  a line with included items is schduled.
4127 
4128 Lastly if the profile is set to PICK RELEASE OR BOOKING, the
4129 wrapper procedures finally call this method.
4130 
4131 Check whether the included items need to be processed
4132 If the line's explosion date is not NULL;
4133 or the line is ATO; or the item type is not a model, kit
4134 or class, then do not process included items
4135 
4136 included items  will have same
4137 line + ship + option number combination as the parent line.
4138 However we will populate component_number for them.
4139 
4140 To improve performance, we will explicitly log delayed
4141 requests using procedure log_included_items_requests.
4142 We will set the control_rec.change_attributes to FALSE.
4143 However execution of the delayed requests logged in that
4144 procedure is up to the caller of this API.
4145 
4146 Change Record:
4147 2002550
4148   the pricing attributes need to be set to 0, since we are not
4149   calling apply_attribute_changes as per perf changes.
4150 
4151   Assign pricing_quantity = ordered_quantity and
4152   pricing_quantity_uom = order_quantity_uom.
4153 
4154 2115192
4155   setting the ordered item field on included items.
4156   Also, insert_into_set call removed, moved to generic
4157   model_option_defaulting API.
4158 2508632
4159   Copy Calculate Price Flag of included items from Parent Line.
4160 
4161 Bug 2869052 :
4162   Default_Child_Line procedure would be called only if there are
4163   any new included items to be created. If the call returns an
4164   error an exception would be raised. New variable l_default_child_line
4165   has been created.
4166 -----------------------------------------------------------------------*/
4167 FUNCTION Process_Included_Items
4168 (p_line_rec         IN OE_ORDER_PUB.line_rec_type
4169                     := OE_ORDER_PUB.G_MISS_LINE_REC,
4170  p_line_id          IN  NUMBER := FND_API.G_MISS_NUM,
4171  p_freeze           IN  BOOLEAN,
4172  p_process_requests IN BOOLEAN DEFAULT FALSE)
4173 RETURN VARCHAR2
4174 IS
4175 
4176   -- process_order in variables
4177   l_control_rec               OE_GLOBALS.Control_Rec_Type;
4178   l_header_rec                OE_Order_PUB.Header_Rec_Type;
4179   l_line_rec                  OE_ORDER_PUB.Line_Rec_Type;
4180   l_old_line_tbl              OE_Order_PUB.Line_Tbl_Type;
4181   l_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
4182 
4183   l_return_status             VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
4184   l_msg_count                 NUMBER;
4185   l_msg_data                  VARCHAR2(2000);
4186 
4187   -- procedure variables
4188   l_parent_line_rec           OE_Order_PUB.Line_Rec_Type;
4189   l_line_count                NUMBER := 0;
4190   l_line_id                   NUMBER;
4191   l_component_number          NUMBER;
4192   l_adjust_comp_no_flag       VARCHAR2(1) := 'N';
4193   l_parent_component_sequence_id NUMBER := 0;
4194   l_option_number             NUMBER;
4195   l_top_model_quantity        NUMBER := 0;
4196   l_freeze_method             VARCHAR2(30);
4197   l_explosion_date            DATE;
4198   l_validation_org            NUMBER;
4199   l_error_code                NUMBER;
4200   l_default_child_line        BOOLEAN  := TRUE;
4201   l_freeze_macd_kit           BOOLEAN  := FALSE;
4202 
4203   --bug3269648
4204   l_return_code               NUMBER;
4205   l_error_buffer              VARCHAR2(240);
4206   --bug3269648
4207   -- tso with equipment
4208   l_top_container_model       VARCHAR2(1);
4209   l_part_of_container         VARCHAR2(1);
4210   l_config_mode               NUMBER;
4211   l_cz_config_mode               NUMBER;
4212   l_x_return_status           VARCHAR2(1);
4213 
4214    CURSOR new_included_items(p_top_bill_sequence_id IN NUMBER,
4215                              p_top_model_line_id    IN NUMBER,
4216                              p_std_comp_freeze_date IN DATE)
4217    IS
4218     SELECT
4219       component_item_id,
4220       component_sequence_id,
4221       extended_quantity,
4222       component_code,
4223       PRIMARY_UOM_CODE,
4224       sort_order
4225     FROM bom_explosions  be
4226     WHERE
4227       be.explosion_type = 'INCLUDED'
4228       AND be.plan_level >= 0
4229       AND be.extended_quantity > 0
4230       AND be.TOP_BILL_SEQUENCE_ID = p_top_bill_sequence_id
4231       AND be.EFFECTIVITY_DATE <= p_std_comp_freeze_date
4232       AND be.DISABLE_DATE > p_std_comp_freeze_date
4233       AND be.COMPONENT_ITEM_ID <> be.TOP_ITEM_ID
4234       AND NOT EXISTS
4235           (   SELECT 'X'
4236                 FROM  oe_order_lines l
4237                 WHERE l.top_model_line_id = p_top_model_line_id
4238                 AND   l.link_to_line_id   = l_parent_line_rec.line_id
4239                 AND   l.component_code = be.component_code
4240                 AND   l.open_flag = 'Y')
4241     ORDER BY sort_order;
4242     --ORDER BY COMPONENT_ITEM_ID, COMPONENT_CODE ;
4243 
4244 
4245   CURSOR update_included_items(p_top_bill_sequence_id IN NUMBER,
4246                                p_top_model_line_id    IN NUMBER,
4247                                p_top_model_quantity   IN NUMBER,
4248                                p_std_comp_freeze_date IN DATE)
4249   IS
4250     SELECT
4251          oel.line_id, be.extended_quantity * p_top_model_quantity
4252     FROM oe_order_lines oel, bom_explosions be
4253     WHERE oel.top_model_line_id = p_top_model_line_id
4254     AND oel.link_to_line_id     = l_parent_line_rec.line_id
4255     AND oel.item_type_code = 'INCLUDED'
4256     AND be.explosion_type = 'INCLUDED'
4257     AND be.plan_level >= 0
4258     AND be.TOP_BILL_SEQUENCE_ID = p_top_bill_sequence_id
4259     AND be.EFFECTIVITY_DATE <= p_std_comp_freeze_date
4260     AND be.DISABLE_DATE > p_std_comp_freeze_date
4261     AND be.COMPONENT_ITEM_ID <> be.TOP_ITEM_ID
4262     AND be.component_code = oel.component_code
4263     AND oel.ordered_quantity/p_top_model_quantity <> be.extended_quantity
4264     AND oel.open_flag = 'Y';
4265 
4266 
4267   CURSOR outdated_included_items(p_top_bill_sequence_id IN NUMBER,
4268                                  p_top_model_line_id    IN NUMBER,
4269                                  p_std_comp_freeze_date IN DATE)
4270   IS
4271     SELECT
4272          l.line_id
4273     FROM  oe_order_lines l
4274     WHERE l.link_to_line_id = l_parent_line_rec.line_id
4275     AND   l.top_model_line_id = p_top_model_line_id
4276     AND   l.item_type_code = 'INCLUDED'
4277     AND   l.open_flag = 'Y'
4278     AND NOT EXISTS
4279           (   SELECT 'X'
4280            FROM  bom_explosions be
4281            WHERE be.component_code = l.component_code
4282            AND be.explosion_type   = 'INCLUDED'
4283            AND be.plan_level >= 0
4284            AND be.TOP_BILL_SEQUENCE_ID =  p_top_bill_sequence_id
4285            AND be.EFFECTIVITY_DATE <= p_std_comp_freeze_date
4286            AND be.DISABLE_DATE > p_std_comp_freeze_date);
4287 
4288     --
4289     l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4290     --
4291 BEGIN
4292 
4293   Print_Time('Entering oe_config_util.process_included_items');
4294 
4295   l_parent_line_rec := p_line_rec;
4296 
4297   IF p_line_rec.line_id <> FND_API.G_MISS_NUM AND
4298      p_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
4299      IF l_debug_level  > 0 THEN
4300        oe_debug_pub.add('DO NOT LOCK' , 3 );
4301      END IF;
4302   ELSE
4303     IF p_line_id = FND_API.G_MISS_NUM THEN
4304       OE_LINE_UTIL.Lock_Row
4305       (p_line_id       => p_line_rec.line_id
4306       ,p_x_line_rec    => l_parent_line_rec
4307       ,x_return_status => l_return_status);
4308        -- Parent Line has been passed
4309        l_parent_line_rec := p_line_rec;
4310 
4311        IF l_debug_level  > 0 THEN
4312          oe_debug_pub.add('P_LINE_ID IS MISS_NUM' , 3 );
4313        END IF;
4314     ELSE
4315        -- Query the Parent Line
4316       IF l_debug_level  > 0 THEN
4317         oe_debug_pub.add('PARENT LINE_ID: '|| P_LINE_ID , 2 );
4318       END IF;
4319 
4320       OE_LINE_UTIL.Lock_Row
4321       (p_line_id       => p_line_id
4322       ,p_x_line_rec    => l_parent_line_rec
4323       ,x_return_status => l_return_status);
4324     END IF;
4325 
4326     IF l_debug_level  > 0 THEN
4327       oe_debug_pub.add('ROW LOCKED' , 3 );
4328     END IF;
4329   END IF;
4330 
4331 
4332   IF l_parent_line_rec.explosion_date is not null OR
4333      l_parent_line_rec.ato_line_id is not null OR
4334      l_parent_line_rec.item_type_code not in
4335      ('MODEL', 'KIT', 'CLASS') OR
4336      l_parent_line_rec.ordered_quantity = 0
4337   THEN
4338     IF l_debug_level  > 0 THEN
4339       oe_debug_pub.add('RETURNING FROM PROC_INC_ITEMS' , 3 );
4340     END IF;
4341     RETURN l_return_status;
4342   END IF;
4343 
4344   -- TSO with Equipment starts
4345   IF l_parent_line_rec.line_id <> l_parent_line_rec.top_model_line_id AND
4346      l_parent_line_rec.item_type_code = 'KIT' THEN
4347 
4348     OE_CONFIG_TSO_PVT.Is_Part_Of_Container_Model
4349     (p_line_id              =>  l_parent_line_rec.line_id ,
4350      x_top_container_model  =>  l_top_container_model,
4351      x_part_of_container    =>  l_part_of_container);
4352 
4353     -- The line is part of container
4354     IF l_part_of_container = 'Y' THEN
4355 
4356       OE_CONFIG_TSO_PVT.Get_MACD_Action_Mode
4357       (  p_line_id           => l_parent_line_rec.line_id
4358         ,x_config_mode       => l_config_mode
4359         ,x_return_status     => l_x_return_status );
4360 
4361       IF l_config_mode <> 1 THEN
4362         IF l_debug_level  > 0 THEN
4363           oe_debug_pub.add('Returning from Process_included_items for Kit in TSO configuration' , 3 );
4364         END IF;
4365 
4366         l_cz_config_mode :=
4367           CZ_NETWORK_API_PUB.is_item_added (p_config_hdr_id  => l_parent_line_rec.config_header_id
4368                                            ,p_config_rev_nbr => l_parent_line_rec.config_rev_nbr
4369                                            ,p_config_item_id => l_parent_line_rec.configuration_id);
4370         IF l_debug_level  > 0 THEN
4371           oe_debug_pub.add('After calling CZ_NETWORK_API_PUB.is_item_added: ' || l_cz_config_mode );
4372         END IF;
4373         IF l_cz_config_mode = 0 THEN
4374            --RETURN l_return_status;
4375            l_freeze_macd_kit := TRUE;
4376         END IF;
4377       END IF; -- Mode
4378     END IF;  -- Container
4379   END IF; -- KIT
4380   -- TSO with Equipment ends
4381 
4382   l_freeze_method := G_FREEZE_METHOD; /* Bug # 5036404 */
4383 
4384   IF l_debug_level  > 0 THEN
4385     oe_debug_pub.add('METHOD: '|| L_FREEZE_METHOD , 4 );
4386   END IF;
4387   -- 4359339
4388   l_freeze_method := nvl(l_freeze_method, OE_GLOBALS.G_IIFM_ENTRY);
4389 
4390   IF l_parent_line_rec.creation_date is null OR
4391      l_freeze_method <> OE_GLOBALS.G_IIFM_ENTRY
4392   THEN
4393      l_explosion_date := sysdate;
4394   ELSE
4395      l_explosion_date := l_parent_line_rec.creation_date;
4396   END IF;
4397 
4398   IF l_freeze_macd_kit THEN
4399 
4400      l_explosion_date := sysdate;
4401      l_return_status := FND_API.G_RET_STS_SUCCESS;
4402      GOTO UPDATE_EXP_DATE;
4403 
4404   END IF;
4405   l_validation_org    := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
4406 
4407   IF l_debug_level  > 0 THEN
4408     oe_debug_pub.add('EXPLOSION_DATE: ' || L_EXPLOSION_DATE , 2 );
4409     oe_debug_pub.add('P_TOP_ITEM_ID: '
4410                      || L_PARENT_LINE_REC.INVENTORY_ITEM_ID , 2 );
4411     oe_debug_pub.add('EXPLODING WITH ORG : ' || L_VALIDATION_ORG , 2 );
4412   END IF;
4413 
4414   Explode(p_validation_org => l_validation_org,
4415           p_levels         => 6, --??
4416           p_stdcompflag    => OE_BMX_STD_COMPS_ONLY,
4417           p_top_item_id    => l_parent_line_rec.inventory_item_id,
4418           p_revdate        => l_explosion_date,
4419           x_msg_data       => l_msg_data,
4420           x_error_code     => l_error_code,
4421           x_return_status  => l_return_status);
4422 
4423   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4424         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4425   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4426         RAISE FND_API.G_EXC_ERROR;
4427   END IF;
4428 
4429 
4430   BEGIN
4431     SELECT bill_sequence_id
4432     INTO   l_parent_component_sequence_id
4433     FROM   bom_bill_of_materials
4434     WHERE  ASSEMBLY_ITEM_ID = l_parent_line_rec.inventory_item_id
4435     AND    ORGANIZATION_ID = l_validation_org
4436     AND    ALTERNATE_BOM_DESIGNATOR IS NULL;
4437 
4438     IF l_debug_level  > 0 THEN
4439       oe_debug_pub.add('BILL SEQ ID '||L_PARENT_COMPONENT_SEQUENCE_ID , 1);
4440     END IF;
4441 
4442   EXCEPTION
4443     WHEN NO_DATA_FOUND THEN
4444       IF l_debug_level  > 0 THEN
4445         oe_debug_pub.add('BILL DOES NOT EXIST FOR THIS ITEM' , 3 );
4446       END IF;
4447       l_parent_component_sequence_id := 0;
4448     WHEN OTHERS THEN
4449       IF l_debug_level  > 0 THEN
4450         oe_debug_pub.add
4451         ('UNEXPECTED ERROR WHILE GETTING BILL SEQUENCE ID' , 3 );
4452       END IF;
4453       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4454   END;
4455 
4456   BEGIN
4457     SELECT max(component_number)
4458     INTO   l_component_number
4459     FROM   oe_order_lines
4460     WHERE  link_to_line_id = p_line_id
4461     AND    top_model_line_id = l_parent_line_rec.top_model_line_id;
4462   EXCEPTION
4463     WHEN OTHERS THEN
4464       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4465   END;
4466 
4467   l_line_rec := OE_Order_PUB.G_MISS_LINE_REC;
4468 
4469   OPEN new_included_items
4470      (p_top_bill_sequence_id =>  l_parent_component_sequence_id,
4471       p_top_model_line_id    =>  l_parent_line_rec.top_model_line_id,
4472       p_std_comp_freeze_date =>  l_explosion_date);
4473 
4474   LOOP
4475     FETCH new_included_items
4476     INTO  l_line_rec.inventory_item_id, l_line_rec.component_sequence_id,
4477           l_line_rec.ordered_quantity, l_line_rec.component_code,
4478           l_line_rec.order_quantity_uom, l_line_rec.sort_order;
4479     EXIT WHEN new_included_items%NOTFOUND;
4480 
4481     IF l_default_child_line THEN
4482 
4483        ------ 1. Insert new included items
4484        l_component_number     := nvl(l_component_number, 0);
4485        l_line_rec.operation   := OE_GLOBALS.G_OPR_CREATE;
4486        l_line_rec.item_identifier_type := 'INT';
4487        l_line_rec.option_number     := l_parent_line_rec.option_number;
4488        l_line_rec.item_type_code    := OE_GLOBALS.G_ITEM_INCLUDED;
4489        l_line_rec.top_model_line_id := l_parent_line_rec.top_model_line_id;
4490        l_line_rec.link_to_line_id   := l_parent_line_rec.line_id;
4491        l_line_rec.model_remnant_flag:= l_parent_line_rec.model_remnant_flag;
4492        l_line_rec.header_id         := l_parent_line_rec.header_id;
4493        l_line_rec.unit_list_price   := 0;
4494        l_line_rec.unit_selling_price          :=0;
4495        l_line_rec.unit_list_price_per_pqty    :=0;
4496        l_line_rec.unit_selling_price_per_pqty :=0;
4497        l_line_rec.calculate_price_flag :=
4498                            l_parent_line_rec.calculate_price_flag;
4499 
4500 
4501        IF l_parent_line_rec.booked_flag = 'Y' THEN
4502          l_line_rec.flow_status_code := 'BOOKED';
4503        ELSE
4504          l_line_rec.flow_status_code := 'ENTERED';
4505        END IF;
4506 
4507        IF l_debug_level  > 0 THEN
4508          oe_debug_pub.add('CALLING DEFAULT CHILD' , 2 );
4509        END IF;
4510 
4511        default_child_line
4512        (p_parent_line_rec  => l_parent_line_rec,
4513         p_x_child_line_rec => l_line_rec,
4514         x_return_status    => l_return_status);
4515 
4516        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4517              RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4518        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4519              RAISE FND_API.G_EXC_ERROR;
4520        END IF;
4521 
4522        l_default_child_line := FALSE;
4523 
4524     END IF;
4525 
4526     -- Get the concatanted segment value to be stored in
4527     -- order lines at ordered_item
4528 
4529     BEGIN
4530       SELECT concatenated_segments
4531       INTO   l_line_rec.ordered_item
4532       FROM   MTL_SYSTEM_ITEMS_KFV
4533       WHERE  inventory_item_id = l_line_rec.inventory_item_id
4534       AND    organization_id   = l_validation_org;
4535     EXCEPTION
4536       WHEN NO_DATA_FOUND THEN
4537         IF l_debug_level  > 0 THEN
4538           oe_debug_pub.add('CANCAT SEG FETCH ERROR' , 3 );
4539         END IF;
4540         RAISE FND_API.G_EXC_ERROR;
4541     END;
4542 
4543     IF l_debug_level  > 0 THEN
4544       oe_debug_pub.add('ORD ITEM IS: ' || L_LINE_REC.ORDERED_ITEM , 5 );
4545       oe_debug_pub.add('INSERTING....'|| L_LINE_REC.COMPONENT_CODE , 2 );
4546     END IF;
4547 
4548     -- Adding this flag for fulfillment purpose.
4549 
4550     SELECT OE_ORDER_LINES_S.NEXTVAL
4551     INTO   l_line_rec.line_id
4552     FROM   dual;
4553 
4554     l_component_number          := l_component_number + 1;
4555     l_line_rec.component_number := l_component_number;
4556     l_line_rec.ordered_quantity := l_parent_line_rec.ordered_quantity
4557                                    * l_line_rec.ordered_quantity;
4558     l_line_rec.pricing_quantity := l_line_rec.ordered_quantity;
4559     l_line_rec.pricing_quantity_uom := l_line_rec.order_quantity_uom;
4560     l_line_rec.line_type_id         := l_parent_line_rec.line_type_id;
4561     l_line_rec.org_id               := l_parent_line_rec.org_id;   -- Bug 6058501
4562     --Bug 4153518: Intialized Global DFF values to NULL
4563     l_line_rec.global_attribute1 := NULL;
4564     l_line_rec.global_attribute2 := NULL;
4565     l_line_rec.global_attribute3 := NULL;
4566     l_line_rec.global_attribute4 := NULL;
4567     l_line_rec.global_attribute5 := NULL;
4568     l_line_rec.global_attribute6 := NULL;
4569     l_line_rec.global_attribute7 := NULL;
4570     l_line_rec.global_attribute8 := NULL;
4571     l_line_rec.global_attribute9 := NULL;
4572     l_line_rec.global_attribute10 := NULL;
4573     l_line_rec.global_attribute11 := NULL;
4574     l_line_rec.global_attribute12 := NULL;
4575     l_line_rec.global_attribute13 := NULL;
4576     l_line_rec.global_attribute14 := NULL;
4577     l_line_rec.global_attribute15 := NULL;
4578     l_line_rec.global_attribute16 := NULL;
4579     l_line_rec.global_attribute17 := NULL;
4580     l_line_rec.global_attribute18 := NULL;
4581     l_line_rec.global_attribute19 := NULL;
4582     l_line_rec.global_attribute20 := NULL;
4583     l_line_rec.global_attribute_category := NULL;
4584 
4585     --bug3269648 start
4586     IF l_debug_level > 0 THEN
4587        OE_DEBUG_PUB.Add('Before calling JG ',2);
4588     END IF;
4589 
4590     JG_ZZ_OM_COMMON_PKG.default_gdf
4591     (  x_line_rec     => l_line_rec
4592       ,x_return_code  => l_return_code
4593       ,x_error_buffer => l_error_buffer );
4594 
4595     IF l_debug_level > 0 THEN
4596        OE_DEBUG_PUB.Add('After JG Call:'|| l_return_code || l_error_buffer,2);
4597     END IF;
4598     --bug3269648 ends
4599 
4600     l_line_count                := l_line_count + 1;
4601     l_line_tbl(l_line_count)    := l_line_rec;
4602 
4603   END LOOP;
4604   CLOSE new_included_items;
4605 
4606 
4607   -- open cursors only if some records exist to upd/del
4608   SELECT count(*)
4609   INTO   l_top_model_quantity
4610   FROM   oe_order_lines
4611   WHERE  item_type_code = 'INCLUDED'
4612   AND    top_model_line_id = l_parent_line_rec.top_model_line_id
4613   AND    link_to_line_id   = l_parent_line_rec.line_id;
4614 
4615   IF l_top_model_quantity > 0 THEN
4616 
4617     ----- 2. Update existing included items which needs to be updated
4618 
4619     IF l_parent_line_rec.ordered_quantity is null THEN
4620       l_top_model_quantity := 1;
4621     ELSE
4622       l_top_model_quantity := l_parent_line_rec.ordered_quantity;
4623     END IF;
4624 
4625     IF l_debug_level  > 0 THEN
4626       oe_debug_pub.add('MODEL ORDERED QUANTITY IS'
4627                        || L_TOP_MODEL_QUANTITY , 2 );
4628     END IF;
4629 
4630     l_line_rec             := OE_Order_PUB.G_MISS_LINE_REC;
4631     l_line_rec.operation   := OE_GLOBALS.G_OPR_UPDATE;
4632     l_line_rec.header_id   := l_parent_line_rec.header_id;
4633 
4634     OPEN update_included_items
4635        (p_top_bill_sequence_id =>  l_parent_component_sequence_id,
4636         p_top_model_line_id    =>  l_parent_line_rec.top_model_line_id,
4637         p_top_model_quantity   =>  l_top_model_quantity,
4638         p_std_comp_freeze_date =>  l_explosion_date);
4639     LOOP
4640 
4641       FETCH update_included_items
4642       INTO  l_line_rec.line_id, l_line_rec.ordered_quantity;
4643       EXIT WHEN update_included_items%NOTFOUND;
4644 
4645       IF l_debug_level  > 0 THEN
4646         oe_debug_pub.add('UPDATING....'|| L_LINE_REC.COMPONENT_CODE , 2 );
4647       END IF;
4648 
4649       -- Audit Trail
4650       l_line_rec.change_reason   := 'SYSTEM';
4651       l_line_count               := l_line_count + 1;
4652       l_line_tbl(l_line_count)   := l_line_rec;
4653 
4654     END LOOP;
4655     CLOSE update_included_items;
4656 
4657 
4658     ----- 3. Delete and included items that are not valid anymore
4659 
4660     IF l_debug_level  > 0 THEN
4661       oe_debug_pub.add('TOP MODEL LINE:' || L_PARENT_LINE_REC.LINE_ID , 2 );
4662     END IF;
4663 
4664     l_line_rec                := OE_Order_PUB.G_MISS_LINE_REC;
4665     l_line_rec.operation      := OE_GLOBALS.G_OPR_DELETE;
4666     l_line_rec.header_id      := l_parent_line_rec.header_id;
4667 
4668     OPEN outdated_included_items
4669     (p_top_bill_sequence_id =>  l_parent_component_sequence_id,
4670      p_top_model_line_id    =>  l_parent_line_rec.top_model_line_id,
4671      p_std_comp_freeze_date =>  l_explosion_date);
4672     LOOP
4673       FETCH outdated_included_items
4674       INTO  l_line_rec.line_id;
4675       EXIT WHEN outdated_included_items%NOTFOUND;
4676 
4677       l_adjust_comp_no_flag := 'Y';
4678 
4679       IF l_debug_level  > 0 THEN
4680         oe_debug_pub.add('DELETING....'|| L_LINE_REC.LINE_ID , 2 );
4681       END IF;
4682 
4683       l_line_count             := l_line_count + 1;
4684       l_line_tbl(l_line_count) := l_line_rec;
4685 
4686     END LOOP;
4687     CLOSE outdated_included_items;
4688 
4689   END IF; -- no need to open cursors
4690 
4691   IF l_debug_level  > 0 THEN
4692     oe_debug_pub.add('NO. OF LINES ' || TO_CHAR ( L_LINE_COUNT ) , 2 );
4693   END IF;
4694 
4695   IF l_line_count > 0 THEN
4696     l_header_rec.operation := OE_GLOBALS.G_OPR_NONE;
4697     l_header_rec.header_id := l_parent_line_rec.header_id;
4698 
4699     IF l_debug_level  > 0 THEN
4700       oe_debug_pub.add('CALLING PROCESS_ORDER' , 2 );
4701     END IF;
4702 
4703     l_control_rec.controlled_operation := TRUE;
4704     l_control_rec.check_security       := FALSE;
4705     l_control_rec.change_attributes    := FALSE;
4706 
4707     OE_ORDER_PVT.Lines
4708     (p_validation_level         => FND_API.G_VALID_LEVEL_NONE
4709     ,p_control_rec              => l_control_rec
4710     ,p_x_line_tbl               => l_line_tbl
4711     ,p_x_old_line_tbl           => l_old_line_tbl
4712     ,x_return_status            => l_return_status);
4713 
4714     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4715       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4716     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4717       RAISE FND_API.G_EXC_ERROR;
4718     END IF;
4719 
4720 
4721     Log_Included_Item_Requests
4722     ( p_line_tbl     => l_line_tbl
4723      ,p_booked_flag  => l_parent_line_rec.booked_flag);
4724 
4725 
4726     OE_ORDER_PVT.Process_Requests_And_notify
4727     (p_process_requests       => p_process_requests
4728     ,p_notify                 => TRUE
4729     ,x_return_status          => l_return_status
4730     ,p_line_tbl               => l_line_tbl
4731     ,p_old_line_tbl           => l_old_line_tbl);
4732 
4733 
4734     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4735       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4736     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
4737       RAISE FND_API.G_EXC_ERROR;
4738     END IF;
4739 
4740 
4741     IF l_adjust_comp_no_flag = 'Y' THEN
4742       IF l_debug_level  > 0 THEN
4743         oe_debug_pub.add('INCLUDED ITEMS GOT DELETED' , 1);
4744       END IF;
4745 
4746      update_component_number
4747       (p_line_id           => p_line_id,
4748        p_top_model_line_id => l_parent_line_rec.top_model_line_id,
4749        x_return_status     => l_return_status);
4750     END IF;
4751 
4752     oe_msg_pub.count_and_get
4753     ( p_count      => l_msg_count
4754      ,p_data       => l_msg_data  );
4755 
4756   END IF; -- count > 0
4757 
4758   -- now populate the explosion date on parent line, if p_freeze id TRUE.
4759   <<UPDATE_EXP_DATE>>
4760   IF nvl(p_freeze, FALSE) = TRUE OR
4761      l_freeze_macd_kit THEN
4762     -- Update the explosion date on the model line.
4763     BEGIN
4764       UPDATE OE_ORDER_LINES_ALL
4765       set explosion_date = l_explosion_date,
4766           lock_control   = lock_control + 1
4767       WHERE line_id      = l_parent_line_rec.line_id;
4768     EXCEPTION
4769        WHEN OTHERS THEN
4770          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4771     END;
4772   END IF;
4773 
4774 
4775   Print_Time('Exiting process_included_items: ' || l_return_status);
4776 
4777   RETURN l_return_status;
4778 
4779 EXCEPTION
4780     WHEN FND_API.G_EXC_ERROR THEN
4781         -- bug 4683857
4782         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
4783             OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Process_Included_Items');
4784         END IF;
4785         RETURN FND_API.G_RET_STS_ERROR;
4786 
4787     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4788         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4789         THEN
4790             OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME ,'Process_Included_Items');
4791         END IF;
4792         RETURN FND_API.G_RET_STS_UNEXP_ERROR;
4793     WHEN OTHERS THEN
4794         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4795         THEN
4796             OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME ,'Process_Included_Items');
4797         END IF;
4798         RETURN FND_API.G_RET_STS_UNEXP_ERROR;
4799 END Process_Included_Items;
4800 
4801 
4802 /*----------------------------------------------------------------------
4803 Procedure Name : update_component_number
4804 Description    : This procedure is written to update the
4805                  component_number on the included items,
4806                  if any of them is deleted.
4807 
4808 -----------------------------------------------------------------------*/
4809 
4810 PROCEDURE update_component_number(p_line_id           IN  NUMBER ,
4811                                   p_top_model_line_id IN  NUMBER ,
4812                                   x_return_status     OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
4813 IS
4814 
4815   CURSOR comp_number IS
4816   SELECT line_id
4817   FROM   oe_order_lines
4818   WHERE  link_to_line_id    = p_line_id
4819   AND    top_model_line_id  = p_top_model_line_id;
4820 
4821   l_component_number NUMBER := 0;
4822   l_line_id          NUMBER;
4823   --
4824   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4825   --
4826 BEGIN
4827   IF l_debug_level  > 0 THEN
4828     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.UPDATE_COMPONENT_NUMBER' , 1);
4829   END IF;
4830 
4831   OPEN  comp_number;
4832   LOOP
4833     FETCH comp_number INTO l_line_id;
4834     EXIT WHEN comp_number%NOTFOUND;
4835 
4836     l_component_number := l_component_number + 1;
4837 
4838     UPDATE oe_order_lines
4839     SET    component_number = l_component_number,
4840            lock_control     = lock_control + 1
4841     WHERE  line_id = l_line_id;
4842 
4843   END LOOP;
4844 
4845   x_return_status := FND_API.G_RET_STS_SUCCESS;
4846 
4847   IF l_debug_level  > 0 THEN
4848     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.UPDATE_COMPONENT_NUMBER' , 1);
4849   END IF;
4850 
4851 EXCEPTION
4852   WHEN OTHERS THEN
4853     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4854 END update_component_number;
4855 
4856 /*----------------------------------------------------------------------
4857 Procedure Name : Supply_Reserved
4858 Description    : This procedure is written for the validation
4859         template Supply Reserved. It will return 1 if the
4860                  line is line has supply reserved and 0 otherwise.
4861 
4862 -----------------------------------------------------------------------*/
4863 PROCEDURE  Supply_Reserved (
4864 p_application_id               in number,
4865 p_entity_short_name            in varchar2,
4866 p_validation_entity_short_name in varchar2,
4867 p_validation_tmplt_short_name  in varchar2,
4868 p_record_set_short_name        in varchar2,
4869 p_scope                        in varchar2,
4870 x_result                       out NOCOPY /* file.sql.39 change */  number)
4871 IS
4872 --
4873 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4874 --
4875 BEGIN
4876    x_result := 0;
4877 END;
4878 
4879 /*----------------------------------------------------------------------
4880 Procedure Name : Freeze_Included_Items
4881 Description    :
4882 -----------------------------------------------------------------------*/
4883 FUNCTION Freeze_Included_Items(p_line_id       IN  NUMBER)
4884 RETURN VARCHAR2
4885 IS
4886 --
4887 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4888 --
4889 BEGIN
4890     RETURN Process_Included_Items(p_line_id => p_line_id,
4891                                   p_freeze  => TRUE);
4892 END Freeze_Included_Items;
4893 
4894 
4895 
4896 /*----------------------------------------------------------------------
4897 Procedure Name : Is_ATO_Model
4898 Description    :
4899 -----------------------------------------------------------------------*/
4900 FUNCTION Is_ATO_Model
4901 (p_line_id    IN  NUMBER
4902                := FND_API.G_MISS_NUM ,
4903  p_line_rec   IN OE_Order_PUB.LINE_REC_TYPE
4904                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
4905 RETURN BOOLEAN
4906 IS
4907 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
4908 --
4909 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4910 --
4911 BEGIN
4912 
4913  IF l_debug_level  > 0 THEN
4914    oe_debug_pub.add('ENTERING IS_ATO_MODEL FUNCTION ' , 1);
4915  END IF;
4916 
4917  -- if p_line_rec.line_id is missing, query row
4918  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
4919  -- if p_line_rec is not missing, use it as line_rec insted of querying.
4920 
4921  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
4922     IF p_line_id <> FND_API.G_MISS_NUM THEN
4923        OE_Line_Util.Query_Row(p_line_id  => p_line_id
4924                              ,x_line_rec => l_line_rec);
4925     ELSE
4926       RAISE FND_API.G_EXC_ERROR;
4927     END IF;
4928  ELSE
4929     l_line_rec := p_line_rec;
4930  END IF;
4931 
4932  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_MODEL AND
4933     l_line_rec.ato_line_id = l_line_rec.line_id AND
4934     l_line_rec.top_model_line_id = l_line_rec.line_id -- redundent
4935  THEN
4936     IF l_debug_level  > 0 THEN
4937       oe_debug_pub.add('LEAVING IS_ATO_MODEL FUNCTION ' , 1);
4938     END IF;
4939     RETURN TRUE;
4940  ELSE
4941     IF l_debug_level  > 0 THEN
4942       oe_debug_pub.add('LEAVING IS_ATO_MODEL FUNCTION ' , 1);
4943     END IF;
4944     RETURN FALSE;
4945  END IF;
4946 
4947  IF l_debug_level  > 0 THEN
4948    oe_debug_pub.add('LEAVING IS_ATO_MODEL FUNCTION ' , 1);
4949  END IF;
4950 
4951 EXCEPTION
4952   when others then
4953   IF l_debug_level  > 0 THEN
4954     oe_debug_pub.add('EXCEPTION IN IS_ATO_MODEL FUNCTION ' , 1);
4955   END IF;
4956   RETURN FALSE;
4957 END Is_ATO_Model;
4958 
4959 
4960 
4961 /*----------------------------------------------------------------------
4962 Procedure Name : Is_PTO_Model
4963 Description    :
4964 -----------------------------------------------------------------------*/
4965 FUNCTION Is_PTO_Model
4966 (p_line_id   IN   NUMBER
4967                := FND_API.G_MISS_NUM ,
4968  p_line_rec  IN   OE_Order_PUB.LINE_REC_TYPE
4969                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
4970 RETURN BOOLEAN
4971 IS
4972 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
4973 
4974  --
4975  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
4976  --
4977 BEGIN
4978 
4979  IF l_debug_level  > 0 THEN
4980    oe_debug_pub.add('ENTERING IS_PTO_MODEL FUNCTION ' , 1);
4981  END IF;
4982 
4983  -- if p_line_rec.line_id is missing, query row
4984  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
4985  -- if p_line_rec is not missing, use it as line_rec insted of querying.
4986 
4987  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
4988     IF p_line_id <> FND_API.G_MISS_NUM THEN
4989        OE_Line_Util.Query_Row(p_line_id => p_line_id
4990                              ,x_line_rec => l_line_rec);
4991     ELSE
4992       RAISE FND_API.G_EXC_ERROR;
4993     END IF;
4994  ELSE
4995     l_line_rec := p_line_rec;
4996  END IF;
4997 
4998  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_MODEL AND
4999     l_line_rec.ato_line_id IS NULL AND
5000     l_line_rec.top_model_line_id = l_line_rec.line_id -- redundent
5001  THEN
5002     IF l_debug_level  > 0 THEN
5003       oe_debug_pub.add('LEAVING IS_PTO_MODEL FUNCTION ' , 1);
5004     END IF;
5005     RETURN TRUE;
5006  ELSE
5007     IF l_debug_level  > 0 THEN
5008       oe_debug_pub.add('LEAVING IS_PTO_MODEL FUNCTION ' , 1);
5009     END IF;
5010     RETURN FALSE;
5011  END IF;
5012 
5013  IF l_debug_level  > 0 THEN
5014    oe_debug_pub.add('LEAVING IS_PTO_MODEL FUNCTION ' , 1);
5015  END IF;
5016 
5017 EXCEPTION
5018   when others then
5019   IF l_debug_level  > 0 THEN
5020     oe_debug_pub.add('EXCEPTION IN IS_PTO_MODEL FUNCTION ' , 1);
5021   END IF;
5022   RETURN FALSE;
5023 END Is_PTO_Model;
5024 
5025 /*----------------------------------------------------------------------
5026 Procedure Name : Is_Included_Option
5027 Description    :
5028 -----------------------------------------------------------------------*/
5029 
5030 FUNCTION Is_Included_Option
5031 (p_line_id   IN   NUMBER
5032                := FND_API.G_MISS_NUM ,
5033  p_line_rec  IN   OE_Order_PUB.LINE_REC_TYPE
5034                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5035 RETURN BOOLEAN
5036 IS
5037 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5038 
5039  --
5040  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5041  --
5042 BEGIN
5043 
5044  IF l_debug_level  > 0 THEN
5045    oe_debug_pub.add('ENTERING IS_INCLUDED_OPTION FUNCTION ' , 1);
5046  END IF;
5047 
5048  -- if p_line_rec.line_id is missing, query row
5049  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5050  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5051 
5052  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5053     IF p_line_id <> FND_API.G_MISS_NUM THEN
5054        OE_Line_Util.Query_Row(p_line_id  => p_line_id
5055                              ,x_line_rec => l_line_rec);
5056     ELSE
5057       RAISE FND_API.G_EXC_ERROR;
5058     END IF;
5059  ELSE
5060     l_line_rec := p_line_rec;
5061  END IF;
5062 
5063  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_INCLUDED
5064  THEN
5065     IF l_debug_level  > 0 THEN
5066       oe_debug_pub.add('LEAVING IS_INCLUDED_OPTION FUNCTION ' , 1);
5067     END IF;
5068     RETURN TRUE;
5069  ELSE
5070     IF l_debug_level  > 0 THEN
5071       oe_debug_pub.add('LEAVING IS_INCLUDED_OPTION FUNCTION ' , 1);
5072     END IF;
5073     RETURN FALSE;
5074  END IF;
5075 
5076  IF l_debug_level  > 0 THEN
5077    oe_debug_pub.add('LEAVING IS_INCLUDED_OPTION FUNCTION ' , 1);
5078  END IF;
5079 
5080 EXCEPTION
5081   when others then
5082   IF l_debug_level  > 0 THEN
5083     oe_debug_pub.add('EXCEPTION IN IS_INCLUDED_OPTION FUNCTION ' , 1);
5084   END IF;
5085   RETURN FALSE;
5086 END Is_Included_Option;
5087 
5088 
5089 /*----------------------------------------------------------------------
5090 Procedure Name : Is_Config_Item
5091 Description    :
5092 -----------------------------------------------------------------------*/
5093 FUNCTION Is_Config_Item
5094 (p_line_id  IN    NUMBER
5095                := FND_API.G_MISS_NUM ,
5096  p_line_rec IN    OE_Order_PUB.LINE_REC_TYPE
5097                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5098 RETURN BOOLEAN
5099 IS
5100 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5101 
5102  --
5103  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5104  --
5105 BEGIN
5106 
5107  IF l_debug_level  > 0 THEN
5108    oe_debug_pub.add('ENTERING IS_CONFIG_ITEM FUNCTION ' , 1);
5109  END IF;
5110 
5111  -- if p_line_rec.line_id is missing, query row
5112  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5113  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5114 
5115  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5116     IF p_line_id <> FND_API.G_MISS_NUM THEN
5117       OE_Line_Util.Query_Row(p_line_id => p_line_id
5118                             ,x_line_rec => l_line_rec);
5119     ELSE
5120       RAISE FND_API.G_EXC_ERROR;
5121     END IF;
5122  ELSE
5123     l_line_rec := p_line_rec;
5124  END IF;
5125 
5126 
5127  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG
5128  THEN
5129     IF l_debug_level  > 0 THEN
5130       oe_debug_pub.add('LEAVING IS_CONFIG_ITEM FUNCTION ' , 1);
5131     END IF;
5132     RETURN TRUE;
5133  ELSE
5134     IF l_debug_level  > 0 THEN
5135       oe_debug_pub.add('LEAVING IS_CONFIG_ITEM FUNCTION ' , 1);
5136     END IF;
5137     RETURN FALSE;
5138  END IF;
5139 
5140  IF l_debug_level  > 0 THEN
5141    oe_debug_pub.add('LEAVING IS_CONFIG_ITEM FUNCTION ' , 1);
5142  END IF;
5143 
5144 EXCEPTION
5145   when others then
5146   IF l_debug_level  > 0 THEN
5147     oe_debug_pub.add('EXCEPTION IN IS_CONFIG_ITEM FUNCTION ' , 1);
5148   END IF;
5149   RETURN FALSE;
5150 END Is_Config_item;
5151 
5152 /*----------------------------------------------------------------------
5153 Procedure Name : Is_ATO_Option
5154 Description    :
5155 -----------------------------------------------------------------------*/
5156 FUNCTION Is_ATO_Option
5157 (p_line_id  IN NUMBER
5158                := FND_API.G_MISS_NUM ,
5159  p_line_rec IN OE_Order_PUB.LINE_REC_TYPE
5160                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5161 RETURN BOOLEAN
5162 IS
5163 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5164 
5165  --
5166  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5167  --
5168 BEGIN
5169 
5170  IF l_debug_level  > 0 THEN
5171    oe_debug_pub.add('ENTERING IS_ATO_OPTION FUNCTION ' , 1);
5172  END IF;
5173 
5174  -- if p_line_rec.line_id is missing, query row
5175  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5176  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5177 
5178  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5179     IF p_line_id <> FND_API.G_MISS_NUM THEN
5180        OE_Line_Util.Query_Row(p_line_id  => p_line_id
5181                              ,x_line_rec => l_line_rec);
5182     ELSE
5183       RAISE FND_API.G_EXC_ERROR;
5184     END IF;
5185  ELSE
5186     l_line_rec := p_line_rec;
5187  END IF;
5188 
5189 
5190  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_OPTION AND
5191     l_line_rec.ato_line_id is not null AND
5192     l_line_rec.top_model_line_id = l_line_rec.ato_line_id
5193     -- not an ato under pto
5194  THEN
5195     IF l_debug_level  > 0 THEN
5196       oe_debug_pub.add('LEAVING IS_ATO_OPTION FUNCTION ' , 1);
5197     END IF;
5198     RETURN TRUE;
5199  ELSE
5200     IF l_debug_level  > 0 THEN
5201       oe_debug_pub.add('LEAVING IS_ATO_OPTION FUNCTION ' , 1);
5202     END IF;
5203     RETURN FALSE;
5204  END IF;
5205 
5206  IF l_debug_level  > 0 THEN
5207    oe_debug_pub.add('LEAVING IS_ATO_OPTION FUNCTION ' , 1);
5208  END IF;
5209 
5210 EXCEPTION
5211   when others then
5212   IF l_debug_level  > 0 THEN
5213     oe_debug_pub.add('EXCEPTION IN IS_ATO_OPTION FUNCTION ' , 1);
5214   END IF;
5215   RETURN FALSE;
5216 END Is_ATO_Option;
5217 
5218 
5219 /*----------------------------------------------------------------------
5220 Procedure Name : Is_PTO_Option
5221 Description    :
5222 -----------------------------------------------------------------------*/
5223 FUNCTION Is_PTO_Option
5224 (p_line_id   IN  NUMBER
5225                := FND_API.G_MISS_NUM ,
5226  p_line_rec  IN  OE_Order_PUB.LINE_REC_TYPE
5227                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5228 RETURN BOOLEAN
5229 IS
5230 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5231 
5232  --
5233  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5234  --
5235 BEGIN
5236 
5237  IF l_debug_level  > 0 THEN
5238    oe_debug_pub.add('ENTERING IS_PTO_OPTION FUNCTION ' , 1);
5239  END IF;
5240 
5241  -- if p_line_rec.line_id is missing, query row
5242  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5243  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5244 
5245  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5246     IF p_line_id <> FND_API.G_MISS_NUM THEN
5247        OE_Line_Util.Query_Row(p_line_id  => p_line_id
5248                              ,x_line_rec => l_line_rec);
5249     ELSE
5250       RAISE FND_API.G_EXC_ERROR;
5251     END IF;
5252  ELSE
5253     l_line_rec := p_line_rec;
5254  END IF;
5255 
5256  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_OPTION AND
5257     l_line_rec.ato_line_id is null
5258  THEN
5259     IF l_debug_level  > 0 THEN
5260       oe_debug_pub.add('LEAVING IS_PTO_OPTION FUNCTION ' , 1);
5261     END IF;
5262     RETURN TRUE;
5263  ELSE
5264     IF l_debug_level  > 0 THEN
5265       oe_debug_pub.add('LEAVING IS_PTO_OPTION FUNCTION ' , 1);
5266     END IF;
5267     RETURN FALSE;
5268  END IF;
5269 
5270  IF l_debug_level  > 0 THEN
5271    oe_debug_pub.add('LEAVING IS_PTO_OPTION FUNCTION ' , 1);
5272  END IF;
5273 
5274 EXCEPTION
5275   when others then
5276     IF l_debug_level  > 0 THEN
5277       oe_debug_pub.add('EXCEPTION IN IS_PTO_OPTION FUNCTION ' , 1);
5278     END IF;
5279     RETURN FALSE;
5280 END Is_PTO_Option;
5281 
5282 /*----------------------------------------------------------------------
5283 Procedure Name : Is_ATO_Class
5284 Description    :
5285 -----------------------------------------------------------------------*/
5286 FUNCTION Is_ATO_Class
5287 (p_line_id  IN    NUMBER
5288                := FND_API.G_MISS_NUM ,
5289  p_line_rec IN   OE_Order_PUB.LINE_REC_TYPE
5290                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5291 RETURN BOOLEAN
5292 IS
5293 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5294 
5295  --
5296  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5297  --
5298 BEGIN
5299 
5300  IF l_debug_level  > 0 THEN
5301    oe_debug_pub.add('ENTERING IS_ATO_CLASS FUNCTION ' , 1);
5302  END IF;
5303 
5304  -- if p_line_rec.line_id is missing, query row
5305  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5306  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5307 
5308  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5309     IF p_line_id <> FND_API.G_MISS_NUM THEN
5310       OE_Line_Util.Query_Row(p_line_id  => p_line_id
5311                             ,x_line_rec => l_line_rec);
5312     ELSE
5313       RAISE FND_API.G_EXC_ERROR;
5314     END IF;
5315  ELSE
5316     l_line_rec := p_line_rec;
5317  END IF;
5318 
5319  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CLASS AND
5320     l_line_rec.ato_line_id is not null AND
5321     l_line_rec.top_model_line_id = l_line_rec.ato_line_id
5322     -- not an ato under pto
5323  THEN
5324     IF l_debug_level  > 0 THEN
5325       oe_debug_pub.add('LEAVING IS_ATO_CLASS FUNCTION ' , 1);
5326     END IF;
5327     RETURN TRUE;
5328  ELSE
5329     IF l_debug_level  > 0 THEN
5330       oe_debug_pub.add('LEAVING IS_ATO_CLASS FUNCTION ' , 1);
5331     END IF;
5332     RETURN FALSE;
5333  END IF;
5334 
5335  IF l_debug_level  > 0 THEN
5336    oe_debug_pub.add('LEAVING IS_ATO_CLASS FUNCTION ' , 1);
5337  END IF;
5338 
5339 EXCEPTION
5340   when others then
5341     IF l_debug_level  > 0 THEN
5342       oe_debug_pub.add('EXCEPTION IN IS_ATO_CLASS FUNCTION ' , 1);
5343     END IF;
5344     RETURN FALSE;
5345 END Is_ATO_Class;
5346 
5347 
5348 /*----------------------------------------------------------------------
5349 Procedure Name : Is_PTO_Class
5350 Description    :
5351 -----------------------------------------------------------------------*/
5352 FUNCTION Is_PTO_Class
5353 (p_line_id  IN   NUMBER
5354                := FND_API.G_MISS_NUM ,
5355  p_line_rec IN   OE_Order_PUB.LINE_REC_TYPE
5356                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5357 RETURN BOOLEAN
5358 IS
5359 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5360 
5361  --
5362  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5363  --
5364 BEGIN
5365 
5366  IF l_debug_level  > 0 THEN
5367    oe_debug_pub.add('ENTERING IS_PTO_CLASS FUNCTION ' , 1);
5368  END IF;
5369 
5370  -- if p_line_rec.line_id is missing, query row
5371  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5372  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5373 
5374  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5375     IF p_line_id <> FND_API.G_MISS_NUM THEN
5376       OE_Line_Util.Query_Row(p_line_id  => p_line_id
5377                             ,x_line_rec => l_line_rec);
5378     ELSE
5379       RAISE FND_API.G_EXC_ERROR;
5380     END IF;
5381  ELSE
5382     l_line_rec := p_line_rec;
5383  END IF;
5384 
5385  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CLASS AND
5386     l_line_rec.ato_line_id is not null
5387  THEN
5388     IF l_debug_level  > 0 THEN
5389       oe_debug_pub.add('LEAVING IS_PTO_CLASS FUNCTION ' , 1);
5390     END IF;
5391     RETURN TRUE;
5392  ELSE
5393     IF l_debug_level  > 0 THEN
5394       oe_debug_pub.add('LEAVING IS_PTO_CLASS FUNCTION ' , 1);
5395     END IF;
5396     RETURN FALSE;
5397  END IF;
5398 
5399  IF l_debug_level  > 0 THEN
5400    oe_debug_pub.add('LEAVING IS_PTO_CLASS FUNCTION ' , 1);
5401  END IF;
5402 
5403 EXCEPTION
5404   when others then
5405     IF l_debug_level  > 0 THEN
5406       oe_debug_pub.add('EXCEPTION IN IS_PTO_CLASS FUNCTION ' , 1);
5407     END IF;
5408     RETURN FALSE;
5409 END Is_PTO_Class;
5410 
5411 
5412 /*----------------------------------------------------------------------
5413 Procedure Name : Is_ATO_Subconfig
5414 Description    :
5415 -----------------------------------------------------------------------*/
5416 FUNCTION Is_ATO_Subconfig
5417 (p_line_id  IN    NUMBER
5418                := FND_API.G_MISS_NUM ,
5419  p_line_rec IN   OE_Order_PUB.LINE_REC_TYPE
5420                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5421 RETURN BOOLEAN
5422 IS
5423 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5424 
5425  --
5426  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5427  --
5428 BEGIN
5429 
5430  IF l_debug_level  > 0 THEN
5431    oe_debug_pub.add('ENTERING IS_ATO_SUBCONFIG FUNCTION ' , 1);
5432  END IF;
5433 
5434  -- if p_line_rec.line_id is missing, query row
5435  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5436  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5437 
5438  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5439     IF p_line_id <> FND_API.G_MISS_NUM THEN
5440       OE_Line_Util.Query_Row(p_line_id  => p_line_id
5441                             ,x_line_rec => l_line_rec);
5442     ELSE
5443       RAISE FND_API.G_EXC_ERROR;
5444     END IF;
5445  ELSE
5446     l_line_rec := p_line_rec;
5447  END IF;
5448 
5449  -- what about subconfig options
5450  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CLASS AND
5451     l_line_rec.ato_line_id is not null AND
5452     l_line_rec.top_model_line_id <> l_line_rec.ato_line_id
5453     -- ato under pto
5454  THEN
5455     IF l_debug_level  > 0 THEN
5456       oe_debug_pub.add('LEAVING IS_ATO_SUBCONFIG FUNCTION ' , 1);
5457     END IF;
5458     RETURN TRUE;
5459  ELSE
5460     IF l_debug_level  > 0 THEN
5461       oe_debug_pub.add('LEAVING IS_ATO_SUBCONFIG FUNCTION ' , 1);
5462     END IF;
5463     RETURN FALSE;
5464  END IF;
5465 
5466  IF l_debug_level  > 0 THEN
5467    oe_debug_pub.add('LEAVING IS_ATO_SUBCONFIG FUNCTION ' , 1);
5468  END IF;
5469 
5470 EXCEPTION
5471   when others then
5472     IF l_debug_level  > 0 THEN
5473       oe_debug_pub.add('EXCEPTION IN IS_ATO_SUBCONFIG FUNCTION ' , 1);
5474     END IF;
5475     RETURN FALSE;
5476 END Is_ATO_Subconfig;
5477 
5478 /*----------------------------------------------------------------------
5479 Procedure Name : Is_Kit
5480 Description    :
5481 -----------------------------------------------------------------------*/
5482 FUNCTION Is_Kit
5483 (p_line_id  IN   NUMBER
5484                := FND_API.G_MISS_NUM ,
5485  p_line_rec IN   OE_Order_PUB.LINE_REC_TYPE
5486                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5487 RETURN BOOLEAN
5488 IS
5489 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5490 
5491  --
5492  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5493  --
5494 BEGIN
5495 
5496  IF l_debug_level  > 0 THEN
5497    oe_debug_pub.add('ENTERING IS_KIT FUNCTION ' , 1);
5498  END IF;
5499 
5500  -- if p_line_rec.line_id is missing, query row
5501  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5502  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5503 
5504  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5505     IF p_line_id <> FND_API.G_MISS_NUM THEN
5506       OE_Line_Util.Query_Row(p_line_id  => p_line_id
5507                             ,x_line_rec => l_line_rec);
5508     ELSE
5509       RAISE FND_API.G_EXC_ERROR;
5510     END IF;
5511  ELSE
5512     l_line_rec := p_line_rec;
5513  END IF;
5514 
5515  IF l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_KIT
5516  THEN
5517     IF l_debug_level  > 0 THEN
5518       oe_debug_pub.add('LEAVING IS_KIT FUNCTION ' , 1);
5519     END IF;
5520     RETURN TRUE;
5521  ELSE
5522     IF l_debug_level  > 0 THEN
5523       oe_debug_pub.add('LEAVING IS_KIT FUNCTION ' , 1);
5524     END IF;
5525     RETURN FALSE;
5526  END IF;
5527 
5528  IF l_debug_level  > 0 THEN
5529    oe_debug_pub.add('LEAVING IS_KIT FUNCTION ' , 1);
5530  END IF;
5531 
5532 EXCEPTION
5533   when others then
5534     IF l_debug_level  > 0 THEN
5535       oe_debug_pub.add('EXCEPTION IN IS_KIT FUNCTION ' , 1);
5536     END IF;
5537     RETURN FALSE;
5538 END Is_Kit;
5539 
5540 /*----------------------------------------------------------------------
5541 Procedure Name : Is_Ato_Item
5542 Description    :
5543 -----------------------------------------------------------------------*/
5544 FUNCTION Is_Ato_Item
5545 (p_line_id  IN    NUMBER
5546                := FND_API.G_MISS_NUM ,
5547  p_line_rec IN   OE_Order_PUB.LINE_REC_TYPE
5548                :=  OE_ORDER_PUB.G_MISS_LINE_REC)
5549 RETURN BOOLEAN
5550 IS
5551 l_line_rec     OE_Order_PUB.LINE_REC_TYPE;
5552 
5553  --
5554  l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5555  --
5556 BEGIN
5557 
5558  IF l_debug_level  > 0 THEN
5559    oe_debug_pub.add('ENTERING IS_ATO_ITEM FUNCTION ' , 1);
5560  END IF;
5561 
5562  -- if p_line_rec.line_id is missing, query row
5563  -- if p_line_id and and p_line_rec both missing, RAISE FND_API.G_EXC_ERROR
5564  -- if p_line_rec is not missing, use it as line_rec insted of querying.
5565 
5566  IF p_line_rec.line_id = FND_API.G_MISS_NUM THEN
5567     IF p_line_id <> FND_API.G_MISS_NUM THEN
5568        OE_Line_Util.Query_Row(p_line_id  => p_line_id
5569                              ,x_line_rec => l_line_rec);
5570     ELSE
5571       RAISE FND_API.G_EXC_ERROR;
5572     END IF;
5573  ELSE
5574     l_line_rec := p_line_rec;
5575  END IF;
5576 
5577  IF (l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_STANDARD OR
5578      l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_OPTION OR
5579      l_line_rec.item_type_code = OE_GLOBALS.G_ITEM_INCLUDED ) AND -- 9775352
5580      l_line_rec.ato_line_id = l_line_rec.line_id
5581  THEN
5582     IF l_debug_level  > 0 THEN
5583       oe_debug_pub.add('LEAVING IS_ATO_ITEM FUNCTION ' , 1);
5584     END IF;
5585     RETURN TRUE;
5586  ELSE
5587     IF l_debug_level  > 0 THEN
5588       oe_debug_pub.add('LEAVING IS_ATO_ITEM FUNCTION ' , 1);
5589     END IF;
5590     RETURN FALSE;
5591  END IF;
5592 
5593  IF l_debug_level  > 0 THEN
5594    oe_debug_pub.add('LEAVING IS_ATO_ITEM FUNCTION ' , 1);
5595  END IF;
5596 
5597 EXCEPTION
5598   when others then
5599     IF l_debug_level  > 0 THEN
5600       oe_debug_pub.add('EXCEPTION IN IS_ATO_ITEM FUNCTION ' , 1);
5601     END IF;
5602     RETURN FALSE;
5603 END Is_Ato_Item;
5604 
5605 
5606 /*-------------------------------------------------------------------
5607 PROCEDURE  Query_Config:
5608   This function is called by query_options and query_included_items
5609   and query_ato_options. For query_ato and query_included, we make
5610   l_top_model_line_id as null, so that we do not return all the lines
5611   in that configuration bu only ato options/included items of that line
5612 ---------------------------------------------------------------------*/
5613 
5614 PROCEDURE  Query_Config
5615 ( p_link_to_line_id     IN  NUMBER := FND_API.G_MISS_NUM
5616   , p_top_model_line_id   IN  NUMBER := FND_API.G_MISS_NUM
5617   , p_ato_line_id         IN  NUMBER := FND_API.G_MISS_NUM
5618   , x_line_tbl            OUT NOCOPY OE_ORDER_PUB.line_tbl_type)
5619 IS
5620 l_line_rec           OE_Order_PUB.Line_Rec_Type
5621                      := OE_Order_PUB.G_MISS_LINE_REC;
5622 l_top_model_line_id  NUMBER;
5623 l_line_id                     NUMBER := 0;
5624 ll_line_id                    NUMBER := 0;
5625 l_header_id                   NUMBER := 0;
5626 
5627     CURSOR l_line_csr(l_top_model_line_id  NUMBER) IS
5628     SELECT  line_id
5629     FROM    OE_ORDER_LINES_ALL
5630     WHERE   HEADER_ID = l_header_id
5631     AND     (TOP_MODEL_LINE_ID   = l_top_model_line_id OR
5632             ( LINK_TO_LINE_ID   = p_link_to_line_id AND
5633               ITEM_TYPE_CODE    = OE_GLOBALS.G_ITEM_INCLUDED AND
5634               TOP_MODEL_LINE_ID = p_top_model_line_id) OR
5635             ( ATO_LINE_ID       = p_ato_line_id AND
5636               TOP_MODEL_LINE_ID = p_top_model_line_id))
5637     ORDER BY line_number,shipment_number,nvl(option_number,-1);
5638 
5639 --
5640 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5641 --
5642 BEGIN
5643     IF l_debug_level  > 0 THEN
5644       oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.QUERY_CONFIG' , 1);
5645     END IF;
5646 
5647     l_top_model_line_id := p_top_model_line_id;
5648 
5649     BEGIN
5650       IF (p_link_to_line_id is not null and
5651          p_link_to_line_id <> FND_API.G_MISS_NUM) THEN
5652          ll_line_id := p_link_to_line_id;
5653       ELSIF (p_top_model_line_id is not null and
5654          p_top_model_line_id <> FND_API.G_MISS_NUM) THEN
5655          ll_line_id := p_top_model_line_id;
5656       ELSIF (p_ato_line_id is not null and
5657          p_ato_line_id <> FND_API.G_MISS_NUM) THEN
5658          ll_line_id := p_ato_line_id;
5659       ELSE
5660          ll_line_id := 0;
5661       END IF;
5662 
5663       SELECT header_id
5664       INTO l_header_id
5665       FROM oe_order_lines_all
5666       WHERE line_id=ll_line_id;
5667 
5668     EXCEPTION
5669       WHEN OTHERS THEN
5670         l_header_id:=0;
5671     END;
5672 
5673     IF p_ato_line_id <> FND_API.G_MISS_NUM OR
5674        p_link_to_line_id <>  FND_API.G_MISS_NUM THEN
5675        l_top_model_line_id := NULL;
5676     END IF;
5677 
5678     IF l_debug_level  > 0 THEN
5679       oe_debug_pub.add('HEADER_ID: ' || L_HEADER_ID , 3 );
5680     END IF;
5681 
5682     --  Loop over fetched records
5683     OPEN l_line_csr(l_top_model_line_id);
5684 
5685     LOOP
5686       FETCH l_line_csr into l_line_id;
5687       EXIT WHEN  l_line_csr%NOTFOUND;
5688 
5689       OE_Line_Util.Query_Row( p_line_id  => l_line_id
5690                              ,x_line_rec => l_line_rec );
5691 
5692       x_line_tbl(x_line_tbl.COUNT + 1) := l_line_rec;
5693 
5694     END LOOP;
5695 
5696     IF l_debug_level  > 0 THEN
5697       oe_debug_pub.add('LEAVING QUERY CONFIG' , 1);
5698     END IF;
5699 
5700 EXCEPTION
5701     WHEN NO_DATA_FOUND THEN
5702       IF l_debug_level  > 0 THEN
5703         oe_debug_pub.add('NO_DATA_FOUND IN QUERY_CONFIG' , 1);
5704       END IF;
5705       RAISE NO_DATA_FOUND;
5706 
5707     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5708       IF l_debug_level  > 0 THEN
5709         oe_debug_pub.add('EXC_UNXP IN QUERY_CONFIG' , 1);
5710       END IF;
5711       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5712 
5713     WHEN OTHERS THEN
5714 
5715       IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5716       THEN
5717         IF l_debug_level  > 0 THEN
5718           oe_debug_pub.add('OTHERS IN QUERY_CONFIG' , 1);
5719         END IF;
5720         OE_MSG_PUB.Add_Exc_Msg
5721         ( G_PKG_NAME
5722           , 'Query_Config'
5723          );
5724       END IF;
5725 
5726      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5727 END Query_Config;
5728 
5729 
5730 /*------------------------------------------------------------
5731 helper to see who commits
5732 -------------------------------------------------------------*/
5733 
5734 Procedure get_transaction_id(p_caller   IN  VARCHAR2)
5735 IS
5736 l_tran_id       VARCHAR2(1000);
5737 --
5738 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5739 --
5740 BEGIN
5741 --insert into  values(1);
5742 --uncomment when you want to see tran id
5743 --should not go in tst115
5744 l_tran_id := dbms_transaction.local_transaction_id();
5745 IF l_debug_level  > 0 THEN
5746   oe_debug_pub.add(P_CALLER ||' , TRANSACTION_ID: '|| L_TRAN_ID , 1);
5747 END IF;
5748 END get_transaction_id;
5749 
5750 
5751 
5752 
5753 /*-----------------------------------------------------------
5754 PROCEDURE: Complete_Configuration
5755 
5756 Description:  if there is any ambiguity, exception here
5757               will indicate it. component_code should be
5758               passed in case of ambiguities. sort_order
5759               and comp_seq_id, I will get it through upd_cur
5760               in process_config. Component_code can also be
5761               derived there but we do  not want any ambiuities
5762               to be passedd to SPC. This procedure will also
5763               populate the component_sequence_id, sort_order
5764               and uom on the records if they are null.
5765 ------------------------------------------------------------*/
5766 
5767 PROCEDURE Complete_Configuration
5768 (p_top_model_line_id     IN  NUMBER,
5769  x_return_status         OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
5770 IS
5771 l_return_status             VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5772 l_sort_order                VARCHAR2(2000);  -- 4336446
5773 l_uom_code                  VARCHAR2(3);
5774 l_model_seq_id              NUMBER;
5775 l_model_comp_seq_id         NUMBER;
5776 l_component_code            VARCHAR2(1000);
5777 l_component_item_id         NUMBER;
5778 l_component_seq_id          NUMBER;
5779 l_rev_date                  DATE;
5780 l_validation_org            NUMBER := OE_SYS_PARAMETERS.VALUE
5781                                       ('MASTER_ORGANIZATION_ID');
5782 l_group_id                  NUMBER := null;
5783 l_session_id                NUMBER := 0;
5784 l_levels                    NUMBER := 60;
5785 l_stdcompflag               VARCHAR2(10) := Oe_Config_Util.OE_BMX_ALL_COMPS;
5786 l_exp_quantity              NUMBER;
5787 l_top_item_id               NUMBER;
5788 l_num_lines                 NUMBER := 0;
5789 l_model_ordered_item        VARCHAR2(2000);
5790 l_msg_data                  VARCHAR2(2000);
5791 l_error_code                NUMBER;
5792 
5793 CURSOR comp_code_upd IS
5794 SELECT line_id, inventory_item_id, ordered_item, component_code
5795 FROM   oe_order_lines
5796 WHERE  top_model_line_id = p_top_model_line_id
5797 AND    item_type_code <> OE_GLOBALS.G_ITEM_CONFIG
5798 AND    open_flag = 'Y'
5799 AND    (component_code is null OR
5800         component_sequence_id is null OR
5801         sort_order is null OR
5802         order_quantity_uom is null
5803        );
5804 
5805 --
5806 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
5807 --
5808 BEGIN
5809 
5810   IF l_debug_level  > 0 THEN
5811     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.COMPLETE_CONFIGURATION' , 1);
5812   END IF;
5813 
5814   BEGIN
5815 
5816     SELECT creation_date, component_code, component_sequence_id,
5817            inventory_item_id, ordered_quantity, ordered_item
5818     INTO   l_rev_date, l_component_code, l_model_seq_id,
5819            l_top_item_id, l_exp_quantity, l_model_ordered_item
5820     FROM   oe_order_lines
5821     WHERE  line_id = p_top_model_line_id;
5822 
5823   EXCEPTION
5824     WHEN OTHERS THEN
5825       IF l_debug_level  > 0 THEN
5826         oe_debug_pub.add('EXCEPTION IN SELECT' , 1);
5827       END IF;
5828       RAISE FND_API.G_EXC_ERROR;
5829   END;
5830 
5831 
5832    -- Explode the options in Bom_Explosions
5833   IF l_debug_level  > 0 THEN
5834     oe_debug_pub.add('CALL TO EXPLOSION' , 2 );
5835     oe_debug_pub.add('ORG ID: '|| L_VALIDATION_ORG , 2 );
5836   END IF;
5837 
5838 
5839   OE_CONFIG_UTIL.Explode
5840   ( p_validation_org   => l_validation_org
5841   , p_group_id         => l_group_id
5842   , p_session_id       => l_session_id
5843   , p_levels           => l_levels
5844   , p_stdcompflag      => l_stdcompflag
5845   , p_exp_quantity     => l_exp_quantity
5846   , p_top_item_id      => l_top_item_id
5847   , p_revdate          => l_rev_date
5848   , p_component_code   => l_component_code
5849   , x_msg_data         => l_msg_data
5850   , x_error_code       => l_error_code
5851   , x_return_status    => l_return_status  );
5852 
5853 
5854   IF l_debug_level  > 0 THEN
5855     oe_debug_pub.add('AFTER CALL TO EXPLODE: '|| L_RETURN_STATUS , 2 );
5856   END IF;
5857 
5858   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5859         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5860   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
5861         RAISE FND_API.G_EXC_ERROR;
5862   END IF;
5863 
5864   IF l_model_seq_id is null THEN
5865 
5866      BEGIN
5867        SELECT bill_sequence_id
5868        into l_model_seq_id
5869        FROM bom_explosions
5870        WHERE COMPONENT_ITEM_ID = l_top_item_id
5871        AND ORGANIZATION_ID = l_validation_org
5872        AND PLAN_LEVEL = 0
5873        AND effectivity_date <= l_rev_date
5874        AND disable_date > l_rev_date
5875        AND explosion_type   =  l_stdcompflag ;
5876 
5877      EXCEPTION
5878        WHEN NO_DATA_FOUND THEN
5879             IF l_debug_level  > 0 THEN
5880               oe_debug_pub.add('COMPONENT_SEQUENCE_ID QUERY FAILED' , 1);
5881             END IF;
5882             RAISE FND_API.G_EXC_ERROR;
5883      END;
5884 
5885   END IF;
5886 
5887   IF l_debug_level  > 0 THEN
5888     oe_debug_pub.add('COMP_SEQ_ID OF MODEL: ' || L_MODEL_SEQ_ID , 2 );
5889   END IF;
5890 
5891   FOR line_rec in comp_code_upd
5892   LOOP
5893     IF l_debug_level  > 0 THEN
5894       oe_debug_pub.add('COMPLETE ITEM: '|| LINE_REC.INVENTORY_ITEM_ID , 1);
5895     END IF;
5896 
5897     -- 1st obtain component_code using bom_explosions, if the select
5898     -- statement fetches more than one row, there is ambiguity in the bill
5899     -- we can not set the component_code for that item.
5900     BEGIN
5901 
5902       IF line_rec.component_code is not NULL THEN
5903         IF l_debug_level  > 0 THEN
5904           oe_debug_pub.add('COMPONENT CODE PASSED , SOMETHING ELSE NULL' , 3 );
5905         END IF;
5906 
5907         SELECT component_code, component_sequence_id, sort_order,
5908                primary_uom_code
5909         INTO   l_component_code, l_component_seq_id, l_sort_order,
5910                l_uom_code
5911         FROM   bom_explosions
5912         WHERE  component_item_id    = line_rec.inventory_item_id
5913         AND    explosion_type       = Oe_Config_Util.OE_BMX_ALL_COMPS
5914         AND    top_bill_sequence_id = l_model_seq_id
5915         AND    effectivity_date     <= l_rev_date
5916         AND    disable_date         > l_rev_date
5917         AND    organization_id      =  l_validation_org
5918         AND    component_code       = line_rec.component_code;
5919 
5920       ELSE
5921         IF l_debug_level  > 0 THEN
5922           oe_debug_pub.add('COMPONENT CODE NOT PASSED' , 3 );
5923         END IF;
5924 
5925         SELECT component_code, component_sequence_id, sort_order,
5926                primary_uom_code
5927         INTO   l_component_code, l_component_seq_id, l_sort_order,
5928                l_uom_code
5929         FROM   bom_explosions
5930         WHERE  component_item_id    = line_rec.inventory_item_id
5931         AND    explosion_type       = Oe_Config_Util.OE_BMX_ALL_COMPS
5932         AND    top_bill_sequence_id = l_model_seq_id
5933         AND    effectivity_date     <= l_rev_date
5934         AND    disable_date         > l_rev_date
5935         AND    organization_id      =  l_validation_org;
5936       END IF;
5937 
5938     EXCEPTION
5939       WHEN NO_DATA_FOUND THEN
5940         IF l_debug_level  > 0 THEN
5941           oe_debug_pub.add('SELECT COMP_CODE FAILED , NO DATA FOUND ' , 1);
5942           oe_debug_pub.add('ITEM: '|| LINE_REC.INVENTORY_ITEM_ID , 1);
5943         END IF;
5944 
5945         x_return_status := FND_API.G_RET_STS_ERROR;
5946 
5947         FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_ITEM_NOT_IN_BILL');
5948         FND_MESSAGE.Set_Token('COMPONENT', nvl(line_rec.ordered_item,line_rec.inventory_item_id));
5949         FND_MESSAGE.Set_Token('MODEL', nvl(l_model_ordered_item,l_top_item_id));
5950         oe_msg_pub.add;
5951         RETURN;
5952 
5953       WHEN TOO_MANY_ROWS THEN
5954         IF l_debug_level  > 0 THEN
5955           oe_debug_pub.add('SELECT COMP_CODE FAILED , TOO_MANY ROWS ' , 1);
5956           oe_debug_pub.add('ITEM: '|| LINE_REC.INVENTORY_ITEM_ID , 1);
5957         END IF;
5958 
5959         x_return_status := FND_API.G_RET_STS_ERROR;
5960 
5961         FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_AMBIGUITY');
5962         FND_MESSAGE.Set_Token('COMPONENT', nvl(line_rec.ordered_item,line_rec.inventory_item_id));
5963         FND_MESSAGE.Set_Token('MODEL', nvl(l_model_ordered_item,l_top_item_id));
5964         oe_msg_pub.add;
5965        RETURN;
5966 
5967      WHEN OTHERS THEN
5968        IF l_debug_level  > 0 THEN
5969          oe_debug_pub.add('SELECT COMP_CODE FAILED , OTHERS ' , 1);
5970          oe_debug_pub.add('ITEM: '|| LINE_REC.INVENTORY_ITEM_ID , 1);
5971        END IF;
5972        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5973     END;
5974 
5975     -- now update the oe table
5976     UPDATE oe_order_lines
5977     SET    component_code        = l_component_code,
5978            component_sequence_id = l_component_seq_id,
5979            sort_order            = l_sort_order,
5980            order_quantity_uom    = l_uom_code,
5981            lock_control          = lock_control + 1
5982     WHERE line_id = line_rec.line_id;
5983 
5984   END LOOP;
5985 
5986  x_return_status := FND_API.G_RET_STS_SUCCESS;
5987  IF l_debug_level  > 0 THEN
5988    oe_debug_pub.add('LEAVING COMPLETE CONFIGURATION' , 1);
5989  END IF;
5990 
5991 EXCEPTION
5992   WHEN OTHERS THEN
5993     IF l_debug_level  > 0 THEN
5994       oe_debug_pub.add('AMBIGUITY IN BILL'|| SUBSTR ( SQLERRM , 1 , 150 ) , 1);
5995     END IF;
5996     x_return_status := FND_API.G_RET_STS_ERROR;
5997 END Complete_Configuration;
5998 
5999 
6000 /*----------------------------------------------------------------------
6001 Procedure Name : Match_and_Reserve
6002 Description    :
6003      -- The Match and Reserve first matches the ordered configuration
6004      -- against existing configurations.  If a match is found,
6005      -- it will determine the available quantity to reserve.
6006      -- If the quantity available to reserve is less than the ordered
6007      -- quantity, the matching configuration item and available quantity are
6008      -- displayed for informational purposes.  Reservation should not be an
6009      -- option to the user.
6010 
6011      -- If sufficient quantity is available (greater than or equal to the
6012      -- quantity ordered), than this information is also displayed to the
6013      -- user who should then have the option to reserve.  No partial
6014      -- reservations are allowed at this time.
6015 
6016      -- no match : message.
6017      -- match with no qty, no message.
6018      -- match with qty : disply resv. question.
6019      -- comment completing w/f , when user said no.
6020 -----------------------------------------------------------------------*/
6021 
6022 PROCEDURE Match_and_Reserve
6023 ( p_line_id           IN     NUMBER
6024  ,x_return_status     OUT NOCOPY /* file.sql.39 change */    VARCHAR2)
6025 IS
6026 l_line_rec              OE_Order_Pub.line_rec_type;
6027 l_top_model_line_id     NUMBER;
6028 l_ordered_quantity      NUMBER;
6029 l_order_quantity_uom    VARCHAR2(3);
6030 l_config_id             NUMBER;
6031 l_available_qty         NUMBER;
6032 l_quantity_to_reserve   NUMBER;
6033 l_quantity_reserved     NUMBER;
6034 l_message_name          VARCHAR2(30);
6035 l_error_message         VARCHAR2(2000);
6036 l_result                BOOLEAN;
6037 l_return_status         VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6038 --
6039 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6040 --
6041 BEGIN
6042      IF l_debug_level  > 0 THEN
6043        oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.MATCH_AND_RESERVE' , 1);
6044      END IF;
6045      BEGIN
6046        SELECT top_model_line_id, ordered_quantity, order_quantity_uom
6047        INTO   l_top_model_line_id, l_ordered_quantity, l_order_quantity_uom
6048        FROM   oe_order_lines
6049        WHERE  line_id = p_line_id;
6050      EXCEPTION
6051        WHEN OTHERS THEN
6052          IF l_debug_level  > 0 THEN
6053            oe_debug_pub.add('OTHERS IN MATCH AND RESERVE' , 1);
6054          END IF;
6055          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6056      END;
6057 
6058 
6059      IF CTO_MATCH_AND_RESERVE.match_inquiry
6060         (p_model_line_id         => l_top_model_line_id,
6061          p_automatic_reservation => FALSE,
6062          p_quantity_to_reserve   => l_ordered_quantity,
6063          p_reservation_uom_code  => l_order_quantity_uom,
6064          x_config_id             => l_config_id,
6065          x_available_qty         => l_available_qty,
6066          x_quantity_reserved     => l_quantity_reserved,
6067          x_error_message         => l_error_message,
6068          x_message_name          => l_message_name)
6069      THEN
6070         IF l_config_id is NOT NULL THEN
6071 
6072           IF  l_available_qty > 0 THEN
6073 
6074             IF l_available_qty < l_ordered_quantity THEN
6075                l_quantity_to_reserve := l_available_qty;
6076             ELSE
6077                l_quantity_to_reserve := l_ordered_quantity;
6078             END IF;
6079 
6080             l_result := CTO_MATCH_AND_RESERVE.create_config_reservation
6081                          (p_model_line_id        => l_top_model_line_id,
6082                           p_config_item_id       => l_config_id,
6083                           p_quantity_to_reserve  => l_quantity_to_reserve,
6084                           p_reservation_uom_code => l_order_quantity_uom,
6085                           x_quantity_reserved    => l_quantity_reserved,
6086                           x_error_msg            => l_error_message,
6087                           x_error_msg_name       => l_message_name);
6088 
6089             IF l_message_name IS NOT NULL THEN
6090               FND_MESSAGE.Set_Name('BOM', l_message_name);
6091               OE_Msg_Pub.Add;
6092             END IF;
6093           END IF;
6094         ELSE  -- if config_id null
6095             FND_MESSAGE.Set_Name('BOM', l_message_name);
6096             OE_Msg_Pub.Add; -- config_id is null
6097         END IF;
6098 
6099      ELSE -- if cto return true for match
6100           FND_MESSAGE.Set_Name('BOM', l_message_name);
6101           OE_Msg_Pub.Add;
6102      END IF; -- if match found
6103 
6104      x_return_status := l_return_status;
6105      IF l_debug_level  > 0 THEN
6106        oe_debug_pub.add('EXITING OE_CONFIG_UTIL.MATCH_AND_RESERVE' , 1);
6107      END IF;
6108 
6109 EXCEPTION
6110       WHEN NO_DATA_FOUND THEN
6111         IF l_debug_level  > 0 THEN
6112           oe_debug_pub.add('NO DATA FOUND IN MATCH AND RESERVE' , 1);
6113         END IF;
6114         x_return_status := FND_API.G_RET_STS_ERROR;
6115 
6116       WHEN OTHERS THEN
6117         IF l_debug_level  > 0 THEN
6118           oe_debug_pub.add('EXCEPTION IN MATCH AND RESERVE' , 1);
6119         END IF;
6120         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6121 END Match_and_Reserve;
6122 
6123 
6124 /*----------------------------------------------------------------------
6125 Procedure Name : Delink_Config_batch
6126 Description    : Action supported for Order Import.
6127 Input Parameter: p_line_id : ATO Model Line Id(i.e. immediate parent of CONFIG line)
6128 -----------------------------------------------------------------------*/
6129 
6130 PROCEDURE Delink_Config_batch
6131 ( p_line_id         IN  NUMBER
6132 , x_return_status   OUT NOCOPY /* file.sql.39 change */ VARCHAR2
6133 )
6134 IS
6135    l_config_id      NUMBER ;
6136    l_item_type_code VARCHAR2(30);
6137    l_ato_line_id    NUMBER;
6138    l_inv_item_id    NUMBER;
6139    l_message_name   VARCHAR2(30);
6140    l_error_message  VARCHAR2(2000);
6141    l_table_name     VARCHAR2(30);
6142    l_cto_result     NUMBER;
6143    l_result         BOOLEAN;
6144    l_ordered_item   VARCHAR2(2000);
6145    l_return_status  VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6146 
6147    l_config_header_id NUMBER;
6148    l_config_line_id  NUMBER;
6149    l_source_type     VARCHAR2(10);
6150    l_line_num        VARCHAR2(20);
6151    l_po_header_id    NUMBER;
6152    --bug 4411054
6153    --l_po_status       VARCHAR2(4100);
6154    l_po_status_rec         PO_STATUS_REC_TYPE;
6155    l_autorization_status   VARCHAR2(30);
6156 
6157 --
6158 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6159 --
6160 BEGIN
6161    IF l_debug_level  > 0 THEN
6162      oe_debug_pub.add('ENTERING DELINK_CONFIG  with :'||p_line_id);
6163    END IF;
6164 
6165    BEGIN
6166      SELECT item_type_code, ato_line_id, ordered_item,inventory_item_id
6167      INTO   l_item_type_code, l_ato_line_id, l_ordered_item,l_inv_item_id
6168      FROM   oe_order_lines
6169      WHERE  line_id = p_line_id;
6170    EXCEPTION
6171      WHEN OTHERS THEN
6172        IF l_debug_level  > 0 THEN
6173          oe_debug_pub.add('DELINK BATCH ERROR' , 1);
6174        END IF;
6175        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6176    END;
6177 
6178    IF (l_item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
6179        l_item_type_code = OE_GLOBALS.G_ITEM_CLASS ) AND
6180        l_ato_line_id = p_line_id THEN
6181 
6182         SELECT inventory_item_id,line_id,header_id,
6183                RTRIM(line_number||'.'||shipment_number||'.'||
6184                option_number||'.'||component_number||'.'||
6185                service_number,'.'),source_type_code
6186         INTO   l_config_id,l_config_line_id,l_config_header_id,
6187                l_line_num,l_source_type
6188         FROM   oe_order_lines
6189         -- Bug#5026787: Start:- ato_line_id should be used instead of top_model_line_id.
6190         -- WHERE top_model_line_id = p_line_id
6191         WHERE ato_line_id = p_line_id
6192         -- Bug#5026787: End
6193         AND    item_type_code = 'CONFIG';
6194 
6195         -- Changes for Enhanced DropShipments. Prevent Delink
6196         -- if the PO associated with config item is Approved.
6197 
6198         IF PO_CODE_RELEASE_GRP.Current_Release >=
6199             PO_CODE_RELEASE_GRP.PRC_11i_Family_Pack_J AND
6200                      OE_CODE_CONTROL.Get_Code_Release_Level  >= '110510' AND
6201                                                l_source_type = 'EXTERNAL' THEN
6202 
6203            BEGIN
6204               SELECT po_header_id
6205               INTO   l_po_header_id
6206               FROM   oe_drop_ship_sources
6207               WHERE  line_id    = l_config_line_id
6208               AND    header_id  = l_config_header_id;
6209            EXCEPTION
6210               WHEN NO_DATA_FOUND THEN
6211                    IF l_debug_level  > 0 THEN
6212                       OE_DEBUG_PUB.Add('PO Not Created for Config.' , 2 );
6213                    END IF;
6214            END;
6215 
6216            IF l_po_header_id is not null THEN
6217 
6218               -- comment out for bug 4411054
6219               /*l_po_status := UPPER(PO_HEADERS_SV3.Get_PO_Status
6220                                         (x_po_header_id => l_po_header_id
6221                                         ));
6222                */
6223                PO_DOCUMENT_CHECKS_GRP.po_status_check
6224                                 (p_api_version => 1.0
6225                                 , p_header_id => l_po_header_id
6226                                 , p_mode => 'GET_STATUS'
6227                                 , x_po_status_rec => l_po_status_rec
6228                                 , x_return_status => l_return_status);
6229 
6230 	        IF(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
6231         	      l_autorization_status := l_po_status_rec.authorization_status(1);
6232 
6233              	      IF l_debug_level > 0 THEN
6234                 	OE_DEBUG_PUB.Add('Sucess call from PO_DOCUMENT_CHECKS_GRP.po_status_check',2);
6235                 	OE_DEBUG_PUB.Add('Check PO Status : '|| l_autorization_status, 2);
6236              	      END IF;
6237        		ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6238              	      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6239        		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6240              	      RAISE FND_API.G_EXC_ERROR;
6241        		END IF;
6242 
6243            END IF;
6244 
6245            --IF (INSTR(nvl(l_po_status,'z'), 'APPROVED') <> 0 ) THEN
6246            IF(nvl(l_autorization_status,'z')= 'APPROVED')  THEN
6247               FND_MESSAGE.Set_Name('ONT', 'ONT_DELINK_NOT_ALLOWED');
6248               FND_MESSAGE.Set_Token('LINE_NUM', l_line_num);
6249               FND_MESSAGE.Set_Token('MODEL', l_ordered_item);
6250               OE_MSG_PUB.Add;
6251               RETURN;
6252            END IF;
6253 
6254         END IF;
6255 
6256         IF l_debug_level  > 0 THEN
6257           oe_debug_pub.add('AFTER SELECT STMT.' , 2 );
6258         END IF;
6259 
6260         l_cto_result := CTO_CONFIG_ITEM_PK.Delink_Item
6261                         ( pModelLineId      => p_line_id,
6262                           pConfigId         => l_config_id,
6263                           xErrorMessage     => l_error_message,
6264                           xMessageName      => l_message_name,
6265                           xTableName        => l_table_name);
6266 
6267         --returns 1 in case of successful completion, 0 in case of error
6268 
6269         IF l_debug_level  > 0 THEN
6270           oe_debug_pub.add('AFTER CALL TO CTO_CONFIG_ITEM_PK.DELINK_ITEM ',2);
6271           oe_debug_pub.add('L_CTO_RESULT:'|| L_CTO_RESULT , 2 );
6272         END IF;
6273 
6274         IF (l_cto_result = 1) THEN
6275             IF l_debug_level  > 0 THEN
6276               oe_debug_pub.add('DELINKED CONFIG ITEM' , 2 );
6277             END IF;
6278         ELSE
6279             IF l_debug_level  > 0 THEN
6280               oe_debug_pub.add('CTO RESULT NOT 1' , 2 );
6281             END IF;
6282             IF l_message_name IS NOT NULL THEN
6283                  FND_MESSAGE.Set_Name('BOM', l_message_name);
6284                  oe_msg_pub.add;
6285             ELSE
6286                  IF l_debug_level  > 0 THEN
6287                    oe_debug_pub.add('CTO MESSAGE NAME NULL' , 2 );
6288                  END IF;
6289             END IF;
6290         END IF;
6291    ELSE
6292         IF l_debug_level  > 0 THEN
6293           oe_debug_pub.add('DELINK_CONFIG_ITEM ALLOWED ONLY FROM ATO MODEL',1);
6294         END IF;
6295         FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_INVALID_ACTION');
6296         FND_MESSAGE.Set_Token('ACTION', 'Delink Config');
6297         oe_msg_pub.add;
6298    END IF;
6299 
6300    IF l_debug_level  > 0 THEN
6301      oe_debug_pub.add('EXITING OE_CONFIG_UTIL.DELINK_CONFIG' , 1);
6302    END IF;
6303 
6304    x_return_status := l_return_status;
6305 
6306 EXCEPTION
6307   WHEN NO_DATA_FOUND THEN
6308     FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_NO_ITEM_TO_DELINK');
6309     FND_MESSAGE.Set_Token('MODEL', nvl(l_ordered_item,l_inv_item_id));
6310     oe_msg_pub.add;
6311     x_return_status := FND_API.G_RET_STS_ERROR;
6312 
6313   WHEN OTHERS THEN
6314     IF l_debug_level  > 0 THEN
6315       oe_debug_pub.add('EXCEPTION IN DELINK_CONFIG' , 1);
6316     END IF;
6317     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6318 END Delink_Config_batch;
6319 
6320 
6321 /*----------------------------------------------------------------------
6322 Procedure Name : Part_of_Configuration
6323 Description    : API used for constraint evaluation.
6324                  Result of 1 means operation is constrained.
6325 -----------------------------------------------------------------------*/
6326 
6327 PROCEDURE Part_of_Configuration
6328 ( p_application_id                IN   NUMBER,
6329   p_entity_short_name             IN   VARCHAR2,
6330   p_validation_entity_short_name  IN   VARCHAR2,
6331   p_validation_tmplt_short_name   IN   VARCHAR2,
6332   p_record_set_short_name         IN   VARCHAR2,
6333   p_scope                         IN   VARCHAR2,
6334   x_result                        OUT NOCOPY /* file.sql.39 change */  NUMBER )
6335 IS
6336   l_item_type_code      VARCHAR2(30);
6337   l_header_id           NUMBER;
6338   l_top_model_line_id   NUMBER;
6339   l_line_id             NUMBER;
6340   l_count               NUMBER;
6341   --
6342   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6343   --
6344 BEGIN
6345   IF l_debug_level  > 0 THEN
6346     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.PART_OF_CONFIGURATION' , 1);
6347   END IF;
6348 
6349   SELECT item_type_code,header_id, top_model_line_id, line_id
6350   INTO   l_item_type_code,l_header_id, l_top_model_line_id, l_line_id
6351   FROM   oe_order_lines
6352   WHERE  line_id = oe_line_security.g_record.line_id;
6353 
6354   IF l_item_type_code = OE_GLOBALS.G_ITEM_STANDARD OR
6355      l_item_type_code = OE_GLOBALS.G_ITEM_SERVICE  OR
6356      l_item_type_code = OE_GLOBALS.G_ITEM_INCLUDED
6357   THEN
6358     x_result := 0;
6359     RETURN;
6360   END IF;
6361 
6362   IF  l_item_type_code = OE_GLOBALS.G_ITEM_CLASS  OR
6363       l_item_type_code = OE_GLOBALS.G_ITEM_OPTION OR
6364       l_item_type_code = OE_GLOBALS.G_ITEM_CONFIG OR
6365       ( l_item_type_code = OE_GLOBALS.G_ITEM_KIT AND
6366         l_top_model_line_id <> l_line_id)
6367   THEN
6368     x_result := 1;
6369     RETURN;
6370   END IF;
6371 
6372   l_count := 0;
6373 
6374   IF  l_item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
6375      ( l_item_type_code = OE_GLOBALS.G_ITEM_KIT AND
6376        l_top_model_line_id = l_line_id)
6377   THEN
6378     SELECT count(*)
6379     INTO   l_count
6380     FROM   OE_ORDER_LINES
6381     WHERE  top_model_line_id = oe_line_security.g_record.line_id
6382     AND    line_id          <> oe_line_security.g_record.line_id
6383     AND    header_id         = l_header_id;
6384 
6385     IF l_count > 0 THEN
6386       x_result := 1;
6387       RETURN;
6388     ELSE
6389       x_result := 0;
6390       RETURN;
6391     END IF;
6392   END IF;
6393 
6394   x_result := 0;
6395   IF l_debug_level  > 0 THEN
6396     oe_debug_pub.add('EXITING PART_OF_CONFIGURATION, UNKNOWN ITEM_TYPE', 1);
6397   END IF;
6398 
6399 END Part_of_Configuration;
6400 
6401 /*----------------------------------------------------------------------
6402 Procedure Name :  Link_Config
6403 Description    : Action supported for Order Import.
6404 
6405 -----------------------------------------------------------------------*/
6406 
6407 PROCEDURE  Link_Config
6408 ( p_line_id         IN  NUMBER
6409 , p_config_item_id  IN  NUMBER
6410 , x_return_status   OUT NOCOPY /* file.sql.39 change */ VARCHAR2
6411 )
6412 IS
6413    l_item_type_code      VARCHAR2(30);
6414    l_ato_line_id         NUMBER;
6415    l_message_name        VARCHAR2(30);
6416    l_error_message       VARCHAR2(2000);
6417    l_table_name          VARCHAR2(30);
6418    l_result              BOOLEAN;
6419    l_cto_result          NUMBER(38) := 0;
6420    l_ordered_item        VARCHAR2(2000);
6421    l_valid               NUMBER;
6422    l_return_status       VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6423 
6424    --
6425    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6426    --
6427 BEGIN
6428    IF l_debug_level  > 0 THEN
6429      oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.LINK_CONFIG' , 1);
6430    END IF;
6431 
6432    BEGIN
6433      SELECT item_type_code, ato_line_id, ordered_item
6434      INTO   l_item_type_code, l_ato_line_id, l_ordered_item
6435      FROM   oe_order_lines
6436      WHERE  line_id = p_line_id;
6437    EXCEPTION
6438      WHEN OTHERS THEN
6439        IF l_debug_level  > 0 THEN
6440          oe_debug_pub.add('LINK CONFIG ERROR' , 2 );
6441        END IF;
6442        l_valid := 1;
6443        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6444    END;
6445 
6446    IF (l_item_type_code = OE_GLOBALS.G_ITEM_MODEL OR
6447        l_item_type_code = OE_GLOBALS.G_ITEM_CLASS ) AND
6448        l_ato_line_id = p_line_id THEN
6449 
6450         l_valid := 0;
6451 
6452         SELECT distinct 1
6453         INTO l_valid
6454         FROM oe_order_lines_all oel,
6455              mtl_system_items msi
6456         WHERE oel.line_id = p_line_id
6457         AND oel.inventory_item_id = msi.base_item_id
6458         AND msi.inventory_item_id = p_config_item_id;
6459 
6460         l_result :=   CTO_MANUAL_LINK_CONFIG.link_config
6461                       ( p_model_line_id  => p_line_id,
6462                         p_config_item_id => p_config_item_id,
6463                         x_error_message  => l_error_message,
6464                         x_message_name   => l_message_name );
6465 
6466        IF NOT (l_result) THEN
6467          FND_MESSAGE.Set_Name('BOM', l_message_name);
6468          oe_msg_pub.add();
6469        END IF;
6470 
6471    ELSE
6472         IF l_debug_level  > 0 THEN
6473           oe_debug_pub.add('LINK_CONFIG_ITEM ALLOWED ONLY FROM ATO MODEL', 2 );
6474         END IF;
6475         FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_INVALID_ACTION');
6476         FND_MESSAGE.Set_Token('ACTION', 'Link Config');
6477         oe_msg_pub.add;
6478    END IF;
6479 
6480    IF l_debug_level  > 0 THEN
6481      oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.LINK_CONFIG' , 1);
6482    END IF;
6483 
6484    x_return_status := l_return_status;
6485 
6486 EXCEPTION
6487   WHEN OTHERS THEN
6488     IF l_debug_level  > 0 THEN
6489       oe_debug_pub.add('EXCEPTION IN LINK_CONFIG' , 1);
6490     END IF;
6491 
6492        IF l_valid = 0 THEN
6493           FND_MESSAGE.Set_Name('BOM', 'CTO_INVALID_LINK_ERROR');
6494           OE_Msg_Pub.add;
6495        END IF;
6496 
6497     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6498 END Link_Config;
6499 
6500 
6501 /*----------------------------------------------------------------------
6502 Procedure Name :  Update_Comp_Seq_Id
6503 Description    :  API for CTO to do a direct update on
6504                   oe_order_lines w/o calling process_order.
6505 -----------------------------------------------------------------------*/
6506 
6507 PROCEDURE Update_Comp_Seq_Id
6508 ( p_line_id        IN  NUMBER
6509  ,p_comp_seq_id    IN  NUMBER
6510  ,x_return_status  OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
6511 IS
6512 --
6513 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6514 --
6515 BEGIN
6516   IF l_debug_level  > 0 THEN
6517     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.UPDATE_COMP_SEQ_ID' , 1);
6518   END IF;
6519 
6520   UPDATE oe_order_lines
6521   SET    component_sequence_id = p_comp_seq_id
6522         ,last_update_date      = sysdate
6523         ,last_updated_by       = FND_Global.User_Id
6524         ,last_update_login     = FND_Global.Login_Id
6525         ,lock_control          = lock_control + 1
6526   where  line_id = p_line_id;
6527 
6528   x_return_status := FND_API.G_RET_STS_SUCCESS;
6529 
6530   IF l_debug_level  > 0 THEN
6531     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.UPDATE_COMP_SEQ_ID' , 1);
6532   END IF;
6533 
6534 EXCEPTION
6535   WHEN no_data_found THEN
6536     IF l_debug_level  > 0 THEN
6537       oe_debug_pub.add('NO_DATA_FOUND IN UPDATE_COMP_SEQ_ID' , 1);
6538     END IF;
6539     x_return_status :=  FND_API.G_RET_STS_ERROR;
6540 
6541   WHEN others THEN
6542     IF l_debug_level  > 0 THEN
6543       oe_debug_pub.add('OTHERS EXCEPTION IN UPDATE_COMP_SEQ_ID' , 1);
6544     END IF;
6545     x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR;
6546 END Update_Comp_Seq_Id;
6547 
6548 
6549 /*----------------------------------------------------------------------
6550 Procedure Name :  Update_Visible_Demand_Flag
6551 Description    :  API for CTO to do a direct update on
6552                   oe_order_lines w/o calling process_order.
6553 -----------------------------------------------------------------------*/
6554 
6555 PROCEDURE  Update_Visible_Demand_Flag
6556 ( p_ato_line_id            IN  NUMBER
6557  ,p_visible_demand_flag    IN  VARCHAR2 := 'N'
6558  ,x_return_status          OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
6559 IS
6560 --
6561 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6562 --
6563 BEGIN
6564   IF l_debug_level  > 0 THEN
6565     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.UPDATE_VISIBLE_DEMAND_FLAG' , 1);
6566   END IF;
6567 
6568   UPDATE oe_order_lines
6569   SET    visible_demand_flag = p_visible_demand_flag
6570         ,last_update_date      = sysdate
6571         ,last_updated_by       = FND_Global.User_Id
6572         ,last_update_login     = FND_Global.Login_Id
6573         ,lock_control          = lock_control + 1
6574   where  ato_line_id = p_ato_line_id;
6575 
6576   x_return_status := FND_API.G_RET_STS_SUCCESS;
6577 
6578   IF l_debug_level  > 0 THEN
6579     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.UPDATE_VISIBLE_DEMAND_FLAG' , 1);
6580   END IF;
6581 
6582 EXCEPTION
6583   WHEN no_data_found THEN
6584     IF l_debug_level  > 0 THEN
6585       oe_debug_pub.add('NO_DATA_FOUND IN UPDATE_VISIBLE_DEMAND_FLAG' , 1);
6586     END IF;
6587     x_return_status :=  FND_API.G_RET_STS_ERROR;
6588 
6589   WHEN others THEN
6590     IF l_debug_level  > 0 THEN
6591       oe_debug_pub.add('OTHERS EXCEPTION IN UPDATE_VISIBLE_DEMAND_FLAG' , 1);
6592     END IF;
6593     x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR;
6594 END  Update_Visible_Demand_Flag;
6595 
6596 
6597 /*----------------------------------------------------------------------
6598 Procedure Name :  Update_Mfg_Comp_Seq_Id
6599 Description    :  API for CTO to do a direct update on
6600                   oe_order_lines w/o calling process_order.
6601 -----------------------------------------------------------------------*/
6602 
6603 PROCEDURE  Update_Mfg_Comp_Seq_Id
6604 ( p_ato_line_id            IN  NUMBER
6605  ,p_mfg_comp_seq_id        IN  NUMBER
6606  ,x_return_status          OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
6607 IS
6608 --
6609 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6610 --
6611 BEGIN
6612   IF l_debug_level  > 0 THEN
6613     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.UPDATE_MFG_COMP_SEQ_ID' , 1);
6614   END IF;
6615 
6616   UPDATE oe_order_lines_all
6617   SET    mfg_component_sequence_id = p_mfg_comp_seq_id
6618         ,last_update_date      = sysdate
6619         ,last_updated_by       = FND_Global.User_Id
6620         ,last_update_login     = FND_Global.Login_Id
6621         ,lock_control          = lock_control + 1
6622   where  ato_line_id = p_ato_line_id;
6623 
6624   x_return_status := FND_API.G_RET_STS_SUCCESS;
6625 
6626   IF l_debug_level  > 0 THEN
6627     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.UPDATE_MFG_COMP_SEQ_ID' , 1);
6628   END IF;
6629 
6630 EXCEPTION
6631   WHEN no_data_found THEN
6632     IF l_debug_level  > 0 THEN
6633       oe_debug_pub.add('NO_DATA_FOUND IN UPDATE_MFG_COMP_SEQ_ID' , 1);
6634     END IF;
6635     x_return_status :=  FND_API.G_RET_STS_ERROR;
6636 
6637   WHEN others THEN
6638     IF l_debug_level  > 0 THEN
6639       oe_debug_pub.add('OTHERS EXCEPTION IN UPDATE_MFG_COMP_SEQ_ID' , 1);
6640     END IF;
6641     x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR;
6642 END  Update_Mfg_Comp_Seq_Id;
6643 
6644 
6645 /*----------------------------------------------------------------------
6646 Procedure Name :  Update_Model_Group_Number
6647 Description    :  API for CTO to do a direct update on
6648                   oe_order_lines w/o calling process_order.
6649 -----------------------------------------------------------------------*/
6650 
6651 PROCEDURE  Update_Model_Group_Number
6652 ( p_ato_line_id            IN  NUMBER
6653  ,p_model_group_number     IN  NUMBER
6654  ,x_return_status          OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
6655 IS
6656 --
6657 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6658 --
6659 BEGIN
6660   IF l_debug_level  > 0 THEN
6661     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.UPDATE_MODEL_GROUP_NUMBER' , 1);
6662   END IF;
6663 
6664   UPDATE oe_order_lines
6665   SET    model_group_number = p_model_group_number
6666         ,last_update_date      = sysdate
6667         ,last_updated_by       = FND_Global.User_Id
6668         ,last_update_login     = FND_Global.Login_Id
6669         ,lock_control          = lock_control + 1
6670   where  ato_line_id = p_ato_line_id;
6671 
6672   x_return_status := FND_API.G_RET_STS_SUCCESS;
6673 
6674   IF l_debug_level  > 0 THEN
6675     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.UPDATE_MODEL_GROUP_NUMBER' , 1);
6676   END IF;
6677 
6678 EXCEPTION
6679   WHEN no_data_found THEN
6680     IF l_debug_level  > 0 THEN
6681       oe_debug_pub.add('NO_DATA_FOUND IN UPDATE_MODEL_GROUP_NUMBER' , 1);
6682     END IF;
6683     x_return_status :=  FND_API.G_RET_STS_ERROR;
6684 
6685   WHEN others THEN
6686     IF l_debug_level  > 0 THEN
6687       oe_debug_pub.add('OTHERS EXCEPTION IN UPDATE_MODEL_GROUP_NUMBER' , 1);
6688     END IF;
6689     x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR;
6690 END  Update_Model_Group_Number;
6691 
6692 
6693 /*----------------------------------------------------------------------
6694 Procedure Name :  Update_Cto_Columns
6695 Description    :  API for CTO to do a direct update on
6696                   oe_order_lines w/o calling process_order.
6697 -----------------------------------------------------------------------*/
6698 
6699 PROCEDURE  Update_Cto_Columns
6700 ( p_ato_line_id            IN  NUMBER
6701  ,p_request_id             IN  NUMBER
6702  ,p_program_id             IN  NUMBER
6703  ,p_prog_update_date       IN  DATE
6704  ,p_prog_appl_id           IN  NUMBER
6705  ,x_return_status          OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
6706 IS
6707 --
6708 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6709 --
6710 BEGIN
6711   IF l_debug_level  > 0 THEN
6712     oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.UPDATE_CTO_COLUMNS' , 1);
6713   END IF;
6714 
6715   UPDATE oe_order_lines
6716   SET    request_id             = p_request_id
6717         ,program_id             = p_program_id
6718         ,program_update_date    = p_prog_update_date
6719         ,program_application_id = p_prog_appl_id
6720         ,last_update_date       = sysdate
6721         ,last_updated_by        = FND_Global.User_Id
6722         ,last_update_login      = FND_Global.Login_Id
6723         ,lock_control           = lock_control + 1
6724   where  ato_line_id            = p_ato_line_id;
6725 
6726   x_return_status := FND_API.G_RET_STS_SUCCESS;
6727 
6728   IF l_debug_level  > 0 THEN
6729     oe_debug_pub.add('EXITING OE_CONFIG_UTIL.UPDATE_CTO_COLUMNS' , 1);
6730   END IF;
6731 
6732 EXCEPTION
6733   WHEN no_data_found THEN
6734     IF l_debug_level  > 0 THEN
6735       oe_debug_pub.add('NO_DATA_FOUND IN UPDATE_CTO_COLUMNS' , 1);
6736     END IF;
6737     x_return_status :=  FND_API.G_RET_STS_ERROR;
6738 
6739   WHEN others THEN
6740     IF l_debug_level  > 0 THEN
6741       oe_debug_pub.add('OTHERS EXCEPTION IN UPDATE_CTO_COLUMNS' , 1);
6742     END IF;
6743     x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR;
6744 END  Update_Cto_Columns;
6745 
6746 
6747 /*------------------------------------------------------------------
6748 PROCEDURE  Notify_CTO
6749 for cto change order notification.
6750 The IN parameters p_request_rec and p_request_tbl are mutually
6751 exclusive.
6752 -------------------------------------------------------------------*/
6753 
6754 PROCEDURE  Notify_CTO
6755 ( p_ato_line_id         IN  NUMBER
6756  ,p_request_rec         IN  OE_Order_Pub.Request_Rec_Type
6757                             := OE_Order_Pub.G_MISS_REQUEST_REC
6758  ,p_request_tbl         IN  OE_Order_PUB.request_tbl_type
6759                             := OE_Order_Pub.G_MISS_REQUEST_TBL
6760  ,p_split_tbl           IN  OE_Order_PUB.request_tbl_type
6761                             := OE_Order_Pub.G_MISS_REQUEST_TBL
6762  ,p_decimal_tbl         IN  OE_Order_PUB.request_tbl_type
6763                             := OE_Order_Pub.G_MISS_REQUEST_TBL
6764  ,x_return_status       OUT NOCOPY /* file.sql.39 change */ VARCHAR2 )
6765 IS
6766   l_return_status         VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6767   l_msg_count             NUMBER;
6768   l_msg_data              VARCHAR2(2000);
6769   l_cto_change_tbl        CTO_CHANGE_ORDER_PK.CHANGE_TABLE_TYPE;
6770   l_ato_line_id           NUMBER := p_ato_line_id;
6771   I                       NUMBER;
6772   l_split_tbl             CTO_CHANGE_ORDER_PK.SPLIT_CHG_TABLE_TYPE;
6773   l_decimal_tbl           CTO_CHANGE_ORDER_PK.OPTION_CHG_TABLE_TYPE;
6774 
6775   --
6776   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6777   --
6778 BEGIN
6779   IF l_debug_level  > 0 THEN
6780     oe_debug_pub.add('ENTERING NOTIFY_CTO' , 1);
6781   END IF;
6782 
6783   I := 0;
6784 
6785   IF p_request_rec.param1 is not NULL THEN
6786     I := I + 1;
6787     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.QTY_CHANGE;
6788     l_cto_change_tbl(I).old_value   := p_request_rec.param1;
6789     l_cto_change_tbl(I).new_value   := p_request_rec.param2;
6790   END IF;
6791 
6792   IF p_request_rec.param3 is not NULL THEN
6793     I := I + 1;
6794     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.RD_CHANGE;
6795     l_cto_change_tbl(I).old_value   := p_request_rec.param3;
6796     l_cto_change_tbl(I).new_value   := p_request_rec.param4;
6797   END IF;
6798 
6799   IF p_request_rec.param5 is not NULL THEN
6800     I := I + 1;
6801     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.SSD_CHANGE;
6802     l_cto_change_tbl(I).old_value   := p_request_rec.param5;
6803     l_cto_change_tbl(I).new_value   := p_request_rec.param6;
6804   END IF;
6805 
6806   IF p_request_rec.param7 is not NULL THEN
6807     I := I + 1;
6808     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.SAD_CHANGE;
6809     l_cto_change_tbl(I).old_value   := p_request_rec.param7;
6810     l_cto_change_tbl(I).new_value   := p_request_rec.param8;
6811   END IF;
6812 
6813   IF p_request_rec.param9 is not NULL THEN
6814     I := I + 1;
6815     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.CONFIG_CHANGE;
6816   END IF;
6817 
6818   IF p_request_rec.param10 is not NULL THEN
6819     I := I + 1;
6820     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.WAREHOUSE_CHANGE;
6821     l_cto_change_tbl(I).old_value   := p_request_rec.param10;
6822     l_cto_change_tbl(I).new_value   := p_request_rec.param11;
6823   END IF;
6824  -- INVCONV  start
6825 
6826   IF p_request_rec.param12 is not NULL THEN
6827     I := I + 1;
6828     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.QTY2_CHANGE;
6829     l_cto_change_tbl(I).old_value   := p_request_rec.param12;
6830     l_cto_change_tbl(I).new_value   := p_request_rec.param13;
6831   END IF;
6832     IF l_debug_level  > 0 THEN
6833     oe_debug_pub.add('NOTIFY_CTO 3 ' , 1);
6834   END IF;
6835   IF p_request_rec.param14 is not NULL THEN
6836     I := I + 1;
6837     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.QTY2_UOM_CHANGE;
6838     l_cto_change_tbl(I).old_value   := p_request_rec.param14;
6839     l_cto_change_tbl(I).new_value   := p_request_rec.param15;
6840   END IF;
6841     IF l_debug_level  > 0 THEN
6842     oe_debug_pub.add('NOTIFY_CTO 4 ' , 1);
6843   END IF;
6844   IF p_request_rec.param16 is not NULL THEN
6845     I := I + 1;
6846     l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.QTY_UOM_CHANGE;
6847     l_cto_change_tbl(I).old_value   := p_request_rec.param16;
6848     l_cto_change_tbl(I).new_value   := p_request_rec.param17;
6849   END IF;
6850 
6851   -- INVCONV  end
6852 
6853   I := p_request_tbl.FIRST;
6854   WHILE I is NOT NULL
6855   LOOP
6856     IF l_debug_level  > 0 THEN
6857       oe_debug_pub.add('PTO ATO CREATE'|| P_REQUEST_TBL (I).PARAM1 , 3 );
6858     END IF;
6859 
6860     SELECT ato_line_id
6861     INTO   l_ato_line_id
6862     FROM   oe_order_lines
6863     WHERE  line_id = p_request_tbl(I).param1;
6864 
6865     IF l_ato_line_id = p_request_tbl(I).param2 THEN
6866 
6867       IF l_debug_level  > 0 THEN
6868         oe_debug_pub.add('part of PTO, but correct ato_line_id ', 3 );
6869       END IF;
6870 
6871       l_cto_change_tbl(I).change_type := CTO_CHANGE_ORDER_PK.CONFIG_CHANGE;
6872       l_cto_change_tbl(I).old_value   := p_request_tbl(I).param1;
6873       l_cto_change_tbl(I).new_value   := 'PTO_ATO_CREATE';
6874       l_ato_line_id                   := null;
6875     END IF;
6876 
6877     I := p_request_tbl.NEXT(I);
6878   END LOOP;
6879 
6880   I := p_decimal_tbl.FIRST;
6881   WHILE I is NOT NULL
6882   LOOP
6883     IF l_debug_level  > 0 THEN
6884       oe_debug_pub.add('new qty '|| P_decimal_TBL (I).PARAM4 , 3 );
6885       oe_debug_pub.add('old qty '|| P_decimal_TBL (I).PARAM5 , 3 );
6886     END IF;
6887 
6888     l_decimal_tbl(I).line_id := p_decimal_tbl(I).entity_id;
6889     l_decimal_tbl(I).old_Qty := p_decimal_tbl(I).param5;
6890     l_decimal_tbl(I).new_Qty := p_decimal_tbl(I).param4;
6891     l_decimal_tbl(I).action  := p_decimal_tbl(I).param1;
6892     l_decimal_tbl(I).inventory_item_id := p_decimal_tbl(I).param6;
6893 
6894     I := p_decimal_tbl.NEXT(I);
6895   END LOOP;
6896 
6897   I := p_split_tbl.FIRST;
6898   WHILE I is NOT NULL
6899   LOOP
6900     IF l_debug_level  > 0 THEN
6901       oe_debug_pub.add('split from '|| p_split_tbl (I).PARAM3 , 3 );
6902       oe_debug_pub.add('split to '|| p_split_tbl (I).PARAM4 , 3 );
6903     END IF;
6904 
6905     l_split_tbl(I).line_id := p_split_tbl(I).PARAM4;
6906 
6907     I := p_split_tbl.NEXT(I);
6908   END LOOP;
6909 
6910   IF l_debug_level  > 0 THEN
6911     oe_debug_pub.add('OLD QTY' || P_REQUEST_REC.PARAM1 , 3 );
6912     oe_debug_pub.add('NEW QTY' || P_REQUEST_REC.PARAM2 , 3 );
6913     oe_debug_pub.add('OLD RD'  || P_REQUEST_REC.PARAM3 , 3 );
6914     oe_debug_pub.add('NEW RD'  || P_REQUEST_REC.PARAM4 , 3 );
6915     oe_debug_pub.add('OLD SSD' || P_REQUEST_REC.PARAM5 , 3 );
6916     oe_debug_pub.add('NEW SSD' || P_REQUEST_REC.PARAM6 , 3 );
6917     oe_debug_pub.add('OLD SAD' || P_REQUEST_REC.PARAM7 , 3 );
6918     oe_debug_pub.add('NEW SAD' || P_REQUEST_REC.PARAM8 , 3 );
6919     oe_debug_pub.add('CONFIG ' || P_REQUEST_REC.PARAM9 , 3 );
6920     oe_debug_pub.add('OLD QTY2' || P_REQUEST_REC.PARAM12 , 3 );
6921     oe_debug_pub.add('NEW QTY2' || P_REQUEST_REC.PARAM3 , 3 );
6922     oe_debug_pub.add('PTOATO ' || P_REQUEST_TBL.COUNT , 3 );
6923     oe_debug_pub.add('PLINEID '|| L_ATO_LINE_ID , 3 );
6924     oe_debug_pub.add('CALLING CTO PACKAGE '|| I , 3 );
6925   END IF;
6926 
6927   IF l_cto_change_tbl.COUNT > 0 THEN
6928 
6929     CTO_CHANGE_ORDER_PK.CHANGE_NOTIFY
6930     ( plineid           => l_ato_line_id
6931      ,pchgtype          => l_cto_change_tbl
6932      ,poptionchgdtls    => l_decimal_tbl
6933      ,psplitdtls        => l_split_tbl
6934      ,x_return_status   => l_return_status
6935      ,x_msg_count       => l_msg_count
6936      ,x_msg_data        => l_msg_data );
6937 
6938   END IF;
6939 
6940   x_return_status := l_return_status;
6941 
6942   IF l_debug_level  > 0 THEN
6943     oe_debug_pub.add('LEAVING NOTIFY_CTO'|| X_RETURN_STATUS , 1);
6944   END IF;
6945 EXCEPTION
6946   WHEN OTHERS THEN
6947     IF l_debug_level  > 0 THEN
6948       oe_debug_pub.add('EXCEPTION NOTIFY_CTO'|| SQLERRM , 1);
6949     END IF;
6950     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6951 END;
6952 
6953 
6954 /*------------------------------------------------------------------
6955 PROCEDURE  Decimal_Ratio_Check
6956 helper to populate a decimal ratio message.
6957 no return status since caller does not need to check.
6958 ====================================================================
6959 This procedure is moved to OE_VALIDATE_LINE
6960 for Decimal quantities for ATO Options Project
6961 the decimal ratio check will be part of line entity
6962 validation
6963 -------------------------------------------------------------------*/
6964 
6965 PROCEDURE Decimal_Ratio_Check
6966 ( p_top_model_line_id  IN NUMBER
6967  ,p_component_code     IN VARCHAR2
6968  ,p_ratio              IN NUMBER)
6969 IS
6970   l_ordered_item     VARCHAR2(2000);
6971   l_item_type_code   VARCHAR2(30);
6972   l_inv_item_id      NUMBER;
6973   --
6974   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
6975   --
6976 BEGIN
6977 
6978   IF l_debug_level  > 0 THEN
6979     oe_debug_pub.add('ENTERING DECIMAL_RATIO_CHECK '|| P_COMPONENT_CODE , 1);
6980   END IF;
6981 
6982   FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_DECIMAL_RATIO');
6983 
6984   SELECT ordered_item, item_type_code,inventory_item_id
6985   INTO   l_ordered_item, l_item_type_code,l_inv_item_id
6986   FROM   oe_order_lines
6987   WHERE  top_model_line_id = p_top_model_line_id
6988   AND    component_code = p_component_code
6989   AND    rownum = 1;
6990 
6991   FND_MESSAGE.Set_TOKEN('ITEM', nvl(l_ordered_item,l_inv_item_id));
6992   FND_MESSAGE.Set_TOKEN('TYPECODE', l_item_type_code);
6993   FND_MESSAGE.Set_TOKEN('VALUE',to_char(p_ratio));
6994 
6995   SELECT ordered_item, item_type_code,inventory_item_id
6996   INTO   l_ordered_item, l_item_type_code,l_inv_item_id
6997   FROM   oe_order_lines
6998   WHERE  line_id = p_top_model_line_id;
6999 
7000   FND_MESSAGE.Set_TOKEN('MODEL', nvl(l_ordered_item,l_inv_item_id));
7001   FND_MESSAGE.Set_TOKEN('PTYPECODE', l_item_type_code);
7002 
7003   OE_Msg_Pub.Add;
7004 
7005   IF l_debug_level  > 0 THEN
7006     oe_debug_pub.add('LEAVING DECIMAL_RATIO_CHECK' , 3 );
7007   END IF;
7008 
7009 EXCEPTION
7010   WHEN OTHERS THEN
7011     IF l_debug_level  > 0 THEN
7012       oe_debug_pub.add('DECIMAL_RATIO_CHECK '|| SQLERRM , 1);
7013     END IF;
7014 
7015 END Decimal_Ratio_Check;
7016 
7017 /*------------------------------------------------------------------
7018 PROCEDURE  Default_Child_Line
7019 This procedure will default certain attributes from model to
7020 children instead of getting values from header.
7021 
7022 This procedure will be called from,
7023 OEXDLINB.pls: Model_Option_Defaulting
7024 OEXUCFGB.pls: Process_Included_Items
7025 Since we are calling from process_included_items for the reason
7026 if class has an included item we cannot default in OEXDLINB.pls
7027 In DLINB.pls, code assumes that parent is created in db.
7028 
7029 Also, top_model_line_id, item_type_code, ato_line_id and
7030 ship_model_complete_flag should be set before calling this api
7031 from defauling.
7032 
7033 Donot add any inventory item dependent(OEXUDEPB.pls) attributes
7034 in this procedure.
7035 
7036 We have to default some columns for options under PTO and under
7037 top level ATO Model. For options under ATO subassembly, we will
7038 get the attributes from the ATO subassembly in Process_Config.
7039 Until the call to Process_Config, options and classes under ATO
7040 subassembly will get their attributes from the PTO parent.
7041 
7042 Change Record:
7043 
7044 bug 1950510: The inventory_item dependent fields should
7045 not be defaulted from the parent line to child lines,
7046 commenting out NOCOPY those fields from this procedure.
7047 
7048 bug 1963589: added p_direct_save parameter to default some
7049 additional columns from parent in case of direct insert of
7050 class line.
7051 
7052 bug 2015511:
7053 added cancelled_flag := 'N' in direct_save defaulting.
7054 
7055 2150536 : moved the ato/smc/set specific defaulting to
7056 here in default_child_line.
7057 
7058 bug 2208039: copy dff from parent to child.
7059 
7060 Dropship for config: populate the source_type from parent if
7061 ato_line_id not null.
7062 
7063 bug 2311690: get all reqd. attributes for ato under pto
7064 from the parent ato.
7065 
7066 Bug 2454658: Raise Error if Top Model line id or
7067 header id are NULL.
7068 
7069 Bug 1282873: Assign override_atp_date_code from the parent to child
7070 for ato model.
7071 
7072 Bug 2511313: For flexfield defaulting.
7073 The call to OE_Validate_Line.Validate_Flex is not for validation
7074 but to default the flex field segments, this call should be made
7075 after the ont_copy_model_dff logic.
7076 
7077 Bug 2703023: Setting calculate price flag to Y when direct save
7078 related profile is set to Yes
7079 
7080 Bug 2869052: copy dff from model to child has been extended to all
7081 callers and the validate_flex is called with validation level FULL
7082 and we raise an exception if it returns an error.
7083 
7084 Bug 3060043: Enabling the code to default blanket number,blanket
7085 version number and blanket line number for Config Items.
7086 Blanket Line number and Version Number for the Child lines will be
7087 defaulted only when blanket number is defined on the parent line.
7088 Otherwise it should not.
7089 This code was added by Srini to support CONFIG ITEMS for PACK-J.
7090 
7091 bug fix 3056512: ship to, bill to and request date not cascaded for
7092 non SMC models if caller provides a value.
7093 
7094 MACD: Different components of a container model should be allowed to
7095 have different line types when order is received from upstream
7096 sales application
7097 -------------------------------------------------------------------*/
7098 PROCEDURE Default_Child_Line
7099 ( p_parent_line_rec    IN   OE_Order_Pub.Line_Rec_Type
7100  ,p_x_child_line_rec   IN   OUT NOCOPY OE_Order_Pub.Line_Rec_Type
7101  ,p_direct_save        IN   BOOLEAN := FALSE
7102  ,x_return_status      OUT NOCOPY /* file.sql.39 change */  VARCHAR2)
7103 IS
7104 --
7105 l_debug_level CONSTANT   NUMBER := oe_debug_pub.g_debug_level;
7106 l_blanket_line_number    NUMBER;
7107 l_blanket_version_number NUMBER;
7108 l_blanket_number         NUMBER;
7109 l_blanket_req_date       date;
7110 l_top_container_model    VARCHAR2(1);
7111 l_part_of_container      VARCHAR2(1);
7112 l_return_status          VARCHAR2(1);
7113 
7114 BEGIN
7115   IF l_debug_level  > 0 THEN
7116     oe_debug_pub.add('ENTERING DEFAULT_CHILD_LINE' , 1);
7117   END IF;
7118   x_return_status := FND_API.G_RET_STS_SUCCESS;
7119 
7120   IF p_parent_line_rec.header_id is NULL OR
7121      p_parent_line_rec.top_model_line_id is NULL THEN
7122 
7123       IF l_debug_level  > 0 THEN
7124         oe_debug_pub.add('CORRUPT DATA' , 3 );
7125       END IF;
7126       FND_Message.Set_Name('ONT', 'OE_CONFIG_WRONG_MODEL_LINK');
7127       FND_MESSAGE.Set_TOKEN('ITEM', nvl(p_x_child_line_rec.ordered_item
7128                                     ,p_x_child_line_rec.inventory_item_id));
7129       OE_Msg_Pub.add();
7130       x_return_status := FND_API.G_RET_STS_ERROR;
7131       RAISE FND_API.G_EXC_ERROR;
7132   END IF;
7133 
7134   p_x_child_line_rec.shipment_number    := p_parent_line_rec.shipment_number;
7135   p_x_child_line_rec.line_number        := p_parent_line_rec.line_number;
7136   p_x_child_line_rec.project_id         := p_parent_line_rec.project_id;
7137   p_x_child_line_rec.task_id            := p_parent_line_rec.task_id;
7138   p_x_child_line_rec.ship_tolerance_above
7139                              := p_parent_line_rec.ship_tolerance_above;
7140   p_x_child_line_rec.ship_tolerance_below
7141                              := p_parent_line_rec.ship_tolerance_below;
7142   p_x_child_line_rec.ship_from_org_id   := p_parent_line_rec.ship_from_org_id;
7143 
7144   IF p_x_child_line_rec.ship_from_org_id IS NOT NULL THEN
7145      p_x_child_line_rec.re_source_flag := 'N';
7146   END IF;
7147 
7148   p_x_child_line_rec.shipping_method_code
7149                              := p_parent_line_rec.shipping_method_code;
7150   p_x_child_line_rec.ship_model_complete_flag
7151                              := p_parent_line_rec.ship_model_complete_flag;
7152   p_x_child_line_rec.freight_terms_code
7153   := p_parent_line_rec.freight_terms_code;
7154   p_x_child_line_rec.cust_po_number := p_parent_line_rec.cust_po_number;
7155   --{ Start fix for bug 2652187
7156 ---commenting out for fix# 10364601  p_x_child_line_rec.customer_line_number := p_parent_line_rec.customer_line_number;
7157   -- End fix for bug 2652187 }
7158   ---START bug 10364601
7159   IF  p_x_child_line_rec.customer_line_number <>   FND_API.G_MISS_CHAR THEN
7160         p_x_child_line_rec.customer_line_number := Nvl(p_x_child_line_rec.customer_line_number,p_parent_line_rec.customer_line_number);
7161   ELSE
7162    --{ Start fix for bug 2652187
7163       p_x_child_line_rec.customer_line_number :=p_parent_line_rec.customer_line_number;
7164     -- End fix for bug 2652187 }
7165    END IF ;
7166   ----END BUG 10364601
7167 
7168     IF l_debug_level > 0 THEN
7169         OE_DEBUG_PUB.Add(' parent customer line number'||p_parent_line_rec.customer_line_number,3);
7170         OE_DEBUG_PUB.Add(' child customer line number '|| p_x_child_line_rec.customer_line_number ,3);
7171      END IF;
7172 
7173 
7174   p_x_child_line_rec.salesrep_id        := p_parent_line_rec.salesrep_id;
7175   p_x_child_line_rec.pricing_date       := p_parent_line_rec.pricing_date;
7176   p_x_child_line_rec.agreement_id       := p_parent_line_rec.agreement_id;
7177   p_x_child_line_rec.tax_date           := p_parent_line_rec.tax_date;
7178   p_x_child_line_rec.tax_exempt_number  := p_parent_line_rec.tax_exempt_number;
7179   p_x_child_line_rec.tax_exempt_reason_code
7180                              := p_parent_line_rec.tax_exempt_reason_code;
7181   p_x_child_line_rec.tax_exempt_flag     := p_parent_line_rec.tax_exempt_flag;
7182   p_x_child_line_rec.planning_priority  := p_parent_line_rec.planning_priority;
7183   p_x_child_line_rec.ship_set_id        := p_parent_line_rec.ship_set_id;
7184   p_x_child_line_rec.arrival_set_id     := p_parent_line_rec.arrival_set_id;
7185   p_x_child_line_rec.shipment_priority_code
7186                              := p_parent_line_rec.shipment_priority_code;
7187   p_x_child_line_rec.fob_point_code     := p_parent_line_rec.fob_point_code;
7188   p_x_child_line_rec.subinventory       := p_parent_line_rec.subinventory;
7189   p_x_child_line_rec.demand_class_code  := p_parent_line_rec.demand_class_code;
7190   p_x_child_line_rec.deliver_to_org_id  := p_parent_line_rec.deliver_to_org_id;
7191   p_x_child_line_rec.earliest_acceptable_date
7192                              := p_parent_line_rec.earliest_acceptable_date;
7193   p_x_child_line_rec.latest_acceptable_date
7194                              := p_parent_line_rec.latest_acceptable_date;
7195   p_x_child_line_rec.first_ack_date     := p_parent_line_rec.first_ack_date;
7196   p_x_child_line_rec.last_ack_date      := p_parent_line_rec.last_ack_date;
7197   p_x_child_line_rec.first_ack_code     := p_parent_line_rec.first_ack_code;
7198   p_x_child_line_rec.last_ack_code      := p_parent_line_rec.last_ack_code;
7199 
7200   p_x_child_line_rec.promise_date       := p_parent_line_rec.promise_date;
7201   p_x_child_line_rec.shipping_instructions
7202                              := p_parent_line_rec.shipping_instructions;
7203   p_x_child_line_rec.packing_instructions
7204                              := p_parent_line_rec.packing_instructions;
7205   p_x_child_line_rec.model_remnant_flag := p_parent_line_rec.model_remnant_flag;
7206 
7207   -- MACD ---------------------------------------------------------------
7208   IF p_x_child_line_rec.line_type_id IS NOT NULL OR
7209      p_x_child_line_rec.line_type_id <> FND_API.G_MISS_NUM THEN
7210 
7211      IF l_debug_level > 0 THEN
7212         OE_DEBUG_PUB.Add('LineTypeID:'||p_x_child_line_rec.line_type_id,3);
7213         OE_DEBUG_PUB.Add('Inventory Item ID (from Parent Line):'
7214                          ||p_parent_line_rec.inventory_item_id,3);
7215      END IF;
7216 
7217      OE_CONFIG_TSO_PVT.Is_Part_Of_Container_Model
7218      (  p_inventory_item_id    => p_parent_line_rec.inventory_item_id
7219        ,x_top_container_model  => l_top_container_model
7220        ,x_part_of_container    => l_part_of_container );
7221 
7222      IF l_part_of_container = 'N' THEN
7223         p_x_child_line_rec.line_type_id := p_parent_line_rec.line_type_id;
7224 
7225         IF l_debug_level > 0 THEN
7226            OE_DEBUG_PUB.Add
7227            ('Line_type from parent: '||p_x_child_line_rec.line_type_id,3);
7228         END IF;
7229      ELSE
7230         IF l_debug_level > 0 THEN
7231            OE_DEBUG_PUB.Add
7232            ('Keeping Line_type: '||p_x_child_line_rec.line_type_id,3);
7233         END IF;
7234      END IF;
7235   ELSE
7236     p_x_child_line_rec.line_type_id := p_parent_line_rec.line_type_id;
7237     IF l_debug_level  > 0 THEN
7238       oe_debug_pub.add('COPY it: '|| P_X_CHILD_LINE_REC.line_type_id, 4 );
7239     END IF;
7240   END IF;
7241 
7242 
7243   IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
7244 
7245      IF p_parent_line_rec.blanket_number IS NOT NULL and
7246                   p_parent_line_rec.item_type_code  <> 'INCLUDED' THEN
7247 
7248        IF l_debug_level  > 0 THEN
7249           oe_debug_pub.add('Blanket No:'
7250                            ||p_parent_line_rec.blanket_number);
7251           oe_debug_pub.add('Top Model Inventory Item ID:'
7252                            ||p_parent_line_rec.inventory_item_id );
7253           oe_debug_pub.add('Child Inventory Item ID:'
7254                            ||p_x_child_line_rec.inventory_item_id );
7255           oe_debug_pub.add('Child Item Type Code:'
7256                            ||p_x_child_line_rec.item_type_code );
7257        END IF;
7258 
7259        -- For the bug fix #3579240
7260        IF p_x_child_line_rec.item_type_code <> 'INCLUDED'
7261        THEN
7262 
7263 
7264          -- Call Blanket Procedure for the Child Items
7265 
7266             oe_default_line.default_Blanket_Values (  p_blanket_number         => p_parent_line_rec.blanket_number,
7267                                                       p_cust_po_number         => p_parent_line_rec.cust_po_number,
7268 						      p_ordered_item_id        => p_x_child_line_rec.ordered_item_id, --bug6826787
7269                                                       p_ordered_item           => p_x_child_line_rec.ordered_item,
7270                                                       p_inventory_item_id      => p_x_child_line_rec.inventory_item_id,
7271                                                       p_item_identifier_type   => p_x_child_line_rec.item_type_code,
7272                                                       p_request_date           => p_x_child_line_rec.request_date,
7273                                                       p_sold_to_org_id         => p_x_child_line_rec.sold_to_org_id,
7274                                                       x_blanket_number         => p_x_child_line_rec.blanket_number,
7275                                                       x_blanket_line_number    => p_x_child_line_rec.blanket_line_number,
7276                                                       x_blanket_version_number => p_x_child_line_rec.blanket_version_number,
7277                                                       x_blanket_request_date   => l_blanket_req_date
7278                                                    );
7279 
7280        END IF;
7281 
7282      END IF;
7283 
7284   END IF;
7285 
7286 
7287   ---------------- dff -------------------------------------------
7288 
7289   IF G_COPY_MODEL_DFF = 'Y' /* Bug # 5036404 */
7290      -- OE_CONFIG_UTIL.G_CONFIG_UI_USED = 'Y'
7291     THEN
7292 
7293     IF l_debug_level  > 0 THEN
7294       oe_debug_pub.add('COPYING DFF TO CHILD' , 1);
7295     END IF;
7296 
7297     IF p_x_child_line_rec.attribute1 is null OR
7298        p_x_child_line_rec.attribute1 = FND_API.G_MISS_CHAR THEN
7299       p_x_child_line_rec.attribute1 := p_parent_line_rec.attribute1;
7300     END IF;
7301 
7302     IF p_x_child_line_rec.attribute2 is null OR
7303        p_x_child_line_rec.attribute2 = FND_API.G_MISS_CHAR THEN
7304       p_x_child_line_rec.attribute2 := p_parent_line_rec.attribute2;
7305     END IF;
7306 
7307     IF p_x_child_line_rec.attribute3 is null OR
7308        p_x_child_line_rec.attribute3 = FND_API.G_MISS_CHAR THEN
7309       p_x_child_line_rec.attribute3 := p_parent_line_rec.attribute3;
7310     END IF;
7311 
7312     IF p_x_child_line_rec.attribute4 is null OR
7313        p_x_child_line_rec.attribute4 = FND_API.G_MISS_CHAR THEN
7314       p_x_child_line_rec.attribute4 := p_parent_line_rec.attribute4;
7315     END IF;
7316 
7317     IF p_x_child_line_rec.attribute5 is null OR
7318        p_x_child_line_rec.attribute5 = FND_API.G_MISS_CHAR THEN
7319       p_x_child_line_rec.attribute5 := p_parent_line_rec.attribute5;
7320     END IF;
7321 
7322     IF p_x_child_line_rec.attribute6 is null OR
7323        p_x_child_line_rec.attribute6 = FND_API.G_MISS_CHAR THEN
7324       p_x_child_line_rec.attribute6 := p_parent_line_rec.attribute6;
7325     END IF;
7326 
7327     IF p_x_child_line_rec.attribute7 is null OR
7328        p_x_child_line_rec.attribute7 = FND_API.G_MISS_CHAR THEN
7329       p_x_child_line_rec.attribute7 := p_parent_line_rec.attribute7;
7330     END IF;
7331 
7332     IF p_x_child_line_rec.attribute8 is null OR
7333        p_x_child_line_rec.attribute8 = FND_API.G_MISS_CHAR THEN
7334       p_x_child_line_rec.attribute8 := p_parent_line_rec.attribute8;
7335     END IF;
7336 
7337     IF p_x_child_line_rec.attribute9 is null OR
7338        p_x_child_line_rec.attribute9 = FND_API.G_MISS_CHAR THEN
7339       p_x_child_line_rec.attribute9 := p_parent_line_rec.attribute9;
7340     END IF;
7341 
7342     IF p_x_child_line_rec.attribute10 is null OR
7343        p_x_child_line_rec.attribute10 = FND_API.G_MISS_CHAR THEN
7344       p_x_child_line_rec.attribute10 := p_parent_line_rec.attribute10;
7345     END IF;
7346 
7347     IF p_x_child_line_rec.attribute11 is null OR
7348        p_x_child_line_rec.attribute11 = FND_API.G_MISS_CHAR THEN
7349       p_x_child_line_rec.attribute11 := p_parent_line_rec.attribute11;
7350     END IF;
7351 
7352     IF p_x_child_line_rec.attribute12 is null OR
7353        p_x_child_line_rec.attribute12 = FND_API.G_MISS_CHAR THEN
7354       p_x_child_line_rec.attribute12 := p_parent_line_rec.attribute12;
7355     END IF;
7356 
7357     IF p_x_child_line_rec.attribute13 is null OR
7358        p_x_child_line_rec.attribute13 = FND_API.G_MISS_CHAR THEN
7359       p_x_child_line_rec.attribute13 := p_parent_line_rec.attribute13;
7360     END IF;
7361 
7362     IF p_x_child_line_rec.attribute14 is null OR
7363        p_x_child_line_rec.attribute14 = FND_API.G_MISS_CHAR THEN
7364       p_x_child_line_rec.attribute14 := p_parent_line_rec.attribute14;
7365     END IF;
7366 
7367     IF p_x_child_line_rec.attribute15 is null OR
7368        p_x_child_line_rec.attribute15 = FND_API.G_MISS_CHAR THEN
7369       p_x_child_line_rec.attribute15 := p_parent_line_rec.attribute15;
7370     END IF;
7371 
7372     IF p_x_child_line_rec.attribute16 is null OR  -- for bug 2184255
7373        p_x_child_line_rec.attribute16 = FND_API.G_MISS_CHAR THEN
7374       p_x_child_line_rec.attribute16 := p_parent_line_rec.attribute16;
7375     END IF;
7376 
7377     IF p_x_child_line_rec.attribute17 is null OR
7378        p_x_child_line_rec.attribute17 = FND_API.G_MISS_CHAR THEN
7379       p_x_child_line_rec.attribute17 := p_parent_line_rec.attribute17;
7380     END IF;
7381 
7382     IF p_x_child_line_rec.attribute18 is null OR
7383        p_x_child_line_rec.attribute18 = FND_API.G_MISS_CHAR THEN
7384       p_x_child_line_rec.attribute18 := p_parent_line_rec.attribute18;
7385     END IF;
7386 
7387     IF p_x_child_line_rec.attribute19 is null OR
7388        p_x_child_line_rec.attribute19 = FND_API.G_MISS_CHAR THEN
7389       p_x_child_line_rec.attribute19 := p_parent_line_rec.attribute19;
7390     END IF;
7391 
7392     IF p_x_child_line_rec.attribute20 is null OR  -- for bug 2184255
7393        p_x_child_line_rec.attribute20 = FND_API.G_MISS_CHAR THEN
7394       p_x_child_line_rec.attribute20 := p_parent_line_rec.attribute20;
7395     END IF;
7396 
7397     IF p_x_child_line_rec.context is null OR
7398        p_x_child_line_rec.context = FND_API.G_MISS_CHAR THEN
7399       p_x_child_line_rec.context := p_parent_line_rec.context;
7400     END IF;
7401 
7402 IF p_x_child_line_rec.industry_attribute1 is null OR
7403        p_x_child_line_rec.industry_attribute1 = FND_API.G_MISS_CHAR THEN
7404       p_x_child_line_rec.industry_attribute1 := p_parent_line_rec.industry_attribute1;
7405     END IF;
7406 
7407     IF p_x_child_line_rec.industry_attribute2 is null OR
7408        p_x_child_line_rec.industry_attribute2 = FND_API.G_MISS_CHAR THEN
7409       p_x_child_line_rec.industry_attribute2 := p_parent_line_rec.industry_attribute2;
7410     END IF;
7411 
7412     IF p_x_child_line_rec.industry_attribute3 is null OR
7413        p_x_child_line_rec.industry_attribute3 = FND_API.G_MISS_CHAR THEN
7414       p_x_child_line_rec.industry_attribute3 := p_parent_line_rec.industry_attribute3;
7415     END IF;
7416 
7417     IF p_x_child_line_rec.industry_attribute4 is null OR
7418        p_x_child_line_rec.industry_attribute4 = FND_API.G_MISS_CHAR THEN
7419       p_x_child_line_rec.industry_attribute4 := p_parent_line_rec.industry_attribute4;
7420     END IF;
7421 
7422     IF p_x_child_line_rec.industry_attribute5 is null OR
7423        p_x_child_line_rec.industry_attribute5 = FND_API.G_MISS_CHAR THEN
7424       p_x_child_line_rec.industry_attribute5 := p_parent_line_rec.industry_attribute5;
7425     END IF;
7426 
7427     IF p_x_child_line_rec.industry_attribute6 is null OR
7428        p_x_child_line_rec.industry_attribute6 = FND_API.G_MISS_CHAR THEN
7429       p_x_child_line_rec.industry_attribute6 := p_parent_line_rec.industry_attribute6;
7430     END IF;
7431 
7432     IF p_x_child_line_rec.industry_attribute7 is null OR
7433        p_x_child_line_rec.industry_attribute7 = FND_API.G_MISS_CHAR THEN
7434       p_x_child_line_rec.industry_attribute7 := p_parent_line_rec.industry_attribute7;
7435     END IF;
7436 
7437     IF p_x_child_line_rec.industry_attribute8 is null OR
7438        p_x_child_line_rec.industry_attribute8 = FND_API.G_MISS_CHAR THEN
7439       p_x_child_line_rec.industry_attribute8 := p_parent_line_rec.industry_attribute8;
7440     END IF;
7441 
7442    IF p_x_child_line_rec.industry_attribute9 is null OR
7443        p_x_child_line_rec.industry_attribute9 = FND_API.G_MISS_CHAR THEN
7444       p_x_child_line_rec.industry_attribute9 := p_parent_line_rec.industry_attribute9;
7445     END IF;
7446 
7447     IF p_x_child_line_rec.industry_attribute10 is null OR
7448        p_x_child_line_rec.industry_attribute10 = FND_API.G_MISS_CHAR THEN
7449       p_x_child_line_rec.industry_attribute10 := p_parent_line_rec.industry_attribute10;
7450     END IF;
7451 
7452     IF p_x_child_line_rec.industry_attribute11 is null OR
7453        p_x_child_line_rec.industry_attribute11 = FND_API.G_MISS_CHAR THEN
7454       p_x_child_line_rec.industry_attribute11 := p_parent_line_rec.industry_attribute11;
7455     END IF;
7456 
7457     IF p_x_child_line_rec.industry_attribute12 is null OR
7458        p_x_child_line_rec.industry_attribute12 = FND_API.G_MISS_CHAR THEN
7459       p_x_child_line_rec.industry_attribute12 := p_parent_line_rec.industry_attribute12;
7460     END IF;
7461 
7462     IF p_x_child_line_rec.industry_attribute13 is null OR
7463        p_x_child_line_rec.industry_attribute13 = FND_API.G_MISS_CHAR THEN
7464       p_x_child_line_rec.industry_attribute13 := p_parent_line_rec.industry_attribute13;
7465     END IF;
7466 
7467     IF p_x_child_line_rec.industry_attribute14 is null OR
7468        p_x_child_line_rec.industry_attribute14 = FND_API.G_MISS_CHAR THEN
7469       p_x_child_line_rec.industry_attribute14 := p_parent_line_rec.industry_attribute14;
7470     END IF;
7471 
7472     IF p_x_child_line_rec.industry_attribute15 is null OR
7473        p_x_child_line_rec.industry_attribute15 = FND_API.G_MISS_CHAR THEN
7474       p_x_child_line_rec.industry_attribute15 := p_parent_line_rec.industry_attribute15;
7475     END IF;
7476 
7477     IF p_x_child_line_rec.industry_attribute16 is null OR
7478        p_x_child_line_rec.industry_attribute16 = FND_API.G_MISS_CHAR THEN
7479       p_x_child_line_rec.industry_attribute16 := p_parent_line_rec.industry_attribute16;
7480     END IF;
7481 IF p_x_child_line_rec.industry_attribute17 is null OR
7482        p_x_child_line_rec.industry_attribute17 = FND_API.G_MISS_CHAR THEN
7483       p_x_child_line_rec.industry_attribute17 := p_parent_line_rec.industry_attribute17;
7484     END IF;
7485 
7486     IF p_x_child_line_rec.industry_attribute18 is null OR
7487        p_x_child_line_rec.industry_attribute18 = FND_API.G_MISS_CHAR THEN
7488       p_x_child_line_rec.industry_attribute18 := p_parent_line_rec.industry_attribute18;
7489     END IF;
7490 
7491     IF p_x_child_line_rec.industry_attribute19 is null OR
7492        p_x_child_line_rec.industry_attribute19 = FND_API.G_MISS_CHAR THEN
7493       p_x_child_line_rec.industry_attribute19 := p_parent_line_rec.industry_attribute19;
7494     END IF;
7495 
7496     IF p_x_child_line_rec.industry_attribute20 is null OR
7497        p_x_child_line_rec.industry_attribute20 = FND_API.G_MISS_CHAR THEN
7498       p_x_child_line_rec.industry_attribute20 := p_parent_line_rec.industry_attribute20;
7499     END IF;
7500 
7501     IF p_x_child_line_rec.industry_attribute21 is null OR
7502        p_x_child_line_rec.industry_attribute21 = FND_API.G_MISS_CHAR THEN
7503       p_x_child_line_rec.industry_attribute21 := p_parent_line_rec.industry_attribute21;
7504     END IF;
7505 
7506     IF p_x_child_line_rec.industry_attribute22 is null OR
7507        p_x_child_line_rec.industry_attribute22 = FND_API.G_MISS_CHAR THEN
7508       p_x_child_line_rec.industry_attribute22 := p_parent_line_rec.industry_attribute22;
7509     END IF;
7510 
7511     IF p_x_child_line_rec.industry_attribute23 is null OR
7512        p_x_child_line_rec.industry_attribute23 = FND_API.G_MISS_CHAR THEN
7513       p_x_child_line_rec.industry_attribute23 := p_parent_line_rec.industry_attribute23;
7514     END IF;
7515 
7516     IF p_x_child_line_rec.industry_attribute24 is null OR
7517        p_x_child_line_rec.industry_attribute24 = FND_API.G_MISS_CHAR THEN
7518       p_x_child_line_rec.industry_attribute24 := p_parent_line_rec.industry_attribute24;
7519     END IF;
7520 
7521     IF p_x_child_line_rec.industry_attribute25 is null OR
7522        p_x_child_line_rec.industry_attribute25 = FND_API.G_MISS_CHAR THEN
7523       p_x_child_line_rec.industry_attribute25 := p_parent_line_rec.industry_attribute25;
7524     END IF;
7525 
7526     IF p_x_child_line_rec.industry_attribute26 is null OR
7527        p_x_child_line_rec.industry_attribute26 = FND_API.G_MISS_CHAR THEN
7528       p_x_child_line_rec.industry_attribute26 := p_parent_line_rec.industry_attribute26;
7529     END IF;
7530 IF p_x_child_line_rec.industry_attribute27 is null OR
7531        p_x_child_line_rec.industry_attribute27 = FND_API.G_MISS_CHAR THEN
7532       p_x_child_line_rec.industry_attribute27 := p_parent_line_rec.industry_attribute27;
7533     END IF;
7534 
7535     IF p_x_child_line_rec.industry_attribute28 is null OR
7536        p_x_child_line_rec.industry_attribute28 = FND_API.G_MISS_CHAR THEN
7537       p_x_child_line_rec.industry_attribute28 := p_parent_line_rec.industry_attribute28;
7538     END IF;
7539 
7540     IF p_x_child_line_rec.industry_attribute29 is null OR
7541        p_x_child_line_rec.industry_attribute29 = FND_API.G_MISS_CHAR THEN
7542       p_x_child_line_rec.industry_attribute29 := p_parent_line_rec.industry_attribute29;
7543     END IF;
7544 
7545     IF p_x_child_line_rec.industry_attribute30 is null OR
7546        p_x_child_line_rec.industry_attribute30 = FND_API.G_MISS_CHAR THEN
7547       p_x_child_line_rec.industry_attribute30 := p_parent_line_rec.industry_attribute30;
7548     END IF;
7549 
7550     IF p_x_child_line_rec.industry_context is null OR
7551        p_x_child_line_rec.industry_context = FND_API.G_MISS_CHAR THEN
7552       p_x_child_line_rec.industry_context := p_parent_line_rec.industry_context;
7553     END IF;
7554     -----Start bug 11871834 ,11923383
7555      IF p_x_child_line_rec.tp_attribute1 is null OR
7556        p_x_child_line_rec.tp_attribute1 = FND_API.G_MISS_CHAR THEN
7557       p_x_child_line_rec.tp_attribute1 := p_parent_line_rec.tp_attribute1;
7558     END IF;
7559 
7560     IF p_x_child_line_rec.tp_attribute2 is null OR
7561        p_x_child_line_rec.tp_attribute2 = FND_API.G_MISS_CHAR THEN
7562       p_x_child_line_rec.tp_attribute2 := p_parent_line_rec.tp_attribute2;
7563     END IF;
7564 
7565     IF p_x_child_line_rec.tp_attribute3 is null OR
7566        p_x_child_line_rec.tp_attribute3 = FND_API.G_MISS_CHAR THEN
7567       p_x_child_line_rec.tp_attribute3 := p_parent_line_rec.tp_attribute3;
7568     END IF;
7569 
7570     IF p_x_child_line_rec.tp_attribute4 is null OR
7571        p_x_child_line_rec.tp_attribute4 = FND_API.G_MISS_CHAR THEN
7572       p_x_child_line_rec.tp_attribute4 := p_parent_line_rec.tp_attribute4;
7573     END IF;
7574 
7575     IF p_x_child_line_rec.tp_attribute5 is null OR
7576        p_x_child_line_rec.tp_attribute5 = FND_API.G_MISS_CHAR THEN
7577       p_x_child_line_rec.tp_attribute5 := p_parent_line_rec.tp_attribute5;
7578     END IF;
7579 
7580     IF p_x_child_line_rec.tp_attribute6 is null OR
7581        p_x_child_line_rec.tp_attribute6 = FND_API.G_MISS_CHAR THEN
7582       p_x_child_line_rec.tp_attribute6 := p_parent_line_rec.tp_attribute6;
7583     END IF;
7584 
7585     IF p_x_child_line_rec.tp_attribute7 is null OR
7586        p_x_child_line_rec.tp_attribute7 = FND_API.G_MISS_CHAR THEN
7587       p_x_child_line_rec.tp_attribute7 := p_parent_line_rec.tp_attribute7;
7588     END IF;
7589 
7590     IF p_x_child_line_rec.tp_attribute8 is null OR
7591        p_x_child_line_rec.tp_attribute8 = FND_API.G_MISS_CHAR THEN
7592       p_x_child_line_rec.tp_attribute8 := p_parent_line_rec.tp_attribute8;
7593     END IF;
7594 
7595    IF p_x_child_line_rec.tp_attribute9 is null OR
7596        p_x_child_line_rec.tp_attribute9 = FND_API.G_MISS_CHAR THEN
7597       p_x_child_line_rec.tp_attribute9 :=p_parent_line_rec.tp_attribute9;
7598     END IF;
7599 
7600     IF p_x_child_line_rec.tp_attribute10 is null OR
7601        p_x_child_line_rec.tp_attribute10 = FND_API.G_MISS_CHAR THEN
7602       p_x_child_line_rec.tp_attribute10 := p_parent_line_rec.tp_attribute10;
7603     END IF;
7604 
7605     IF p_x_child_line_rec.tp_attribute11 is null OR
7606        p_x_child_line_rec.tp_attribute11 = FND_API.G_MISS_CHAR THEN
7607       p_x_child_line_rec.tp_attribute11 := p_parent_line_rec.tp_attribute11;
7608     END IF;
7609 
7610     IF p_x_child_line_rec.tp_attribute12 is null OR
7611        p_x_child_line_rec.tp_attribute12 = FND_API.G_MISS_CHAR THEN
7612       p_x_child_line_rec.tp_attribute12 := p_parent_line_rec.tp_attribute12;
7613     END IF;
7614 
7615     IF p_x_child_line_rec.tp_attribute13 is null OR
7616        p_x_child_line_rec.tp_attribute13 = FND_API.G_MISS_CHAR THEN
7617       p_x_child_line_rec.tp_attribute13 := p_parent_line_rec.tp_attribute13;
7618     END IF;
7619 
7620     IF p_x_child_line_rec.tp_attribute14 is null OR
7621        p_x_child_line_rec.tp_attribute14 = FND_API.G_MISS_CHAR THEN
7622       p_x_child_line_rec.tp_attribute14 := p_parent_line_rec.tp_attribute14;
7623     END IF;
7624 
7625     IF p_x_child_line_rec.tp_attribute15 is null OR
7626        p_x_child_line_rec.tp_attribute15 = FND_API.G_MISS_CHAR THEN
7627       p_x_child_line_rec.tp_attribute15 := p_parent_line_rec.tp_attribute15;
7628     END IF;
7629 
7630     IF p_x_child_line_rec.tp_context is null OR
7631        p_x_child_line_rec.tp_context = FND_API.G_MISS_CHAR THEN
7632       p_x_child_line_rec.tp_context := p_parent_line_rec.tp_context;
7633     END IF;
7634 
7635  ------End bug 11871834 ,11923383
7636 
7637 
7638 
7639   END IF;
7640 
7641 
7642   OE_Validate_Line.Validate_Flex
7643   ( p_x_line_rec        => p_x_child_line_rec
7644    ,p_validation_level  => FND_API.G_VALID_LEVEL_FULL
7645    ,x_return_status     => x_return_status);
7646 
7647   IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN   -- For bug 2869052
7648         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7649   ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
7650         RAISE FND_API.G_EXC_ERROR;
7651   END IF;
7652 
7653   ---------------- for direct save only ------------------------
7654 
7655   IF p_direct_save THEN
7656 
7657     p_x_child_line_rec.operation          := OE_GLOBALS.G_OPR_CREATE;
7658     p_x_child_line_rec.header_id          := p_parent_line_rec.header_id;
7659     p_x_child_line_rec.top_model_line_id  := p_parent_line_rec.line_id;
7660     p_x_child_line_rec.item_identifier_type := 'INT';
7661     p_x_child_line_rec.item_type_code     := OE_GLOBALS.G_ITEM_CLASS;
7662     p_x_child_line_rec.line_category_code
7663                                  := p_parent_line_rec.line_category_code;
7664     p_x_child_line_rec.creation_date      := sysdate;
7665     p_x_child_line_rec.created_by         := p_parent_line_rec.created_by;
7666     p_x_child_line_rec.last_update_date   := p_parent_line_rec.last_update_date;
7667     p_x_child_line_rec.last_updated_by    := p_parent_line_rec.last_updated_by;
7668     p_x_child_line_rec.unit_list_price    := 0;
7669     p_x_child_line_rec.unit_selling_price := 0;
7670     p_x_child_line_rec.price_list_id      := p_parent_line_rec.price_list_id;
7671     p_x_child_line_rec.sold_to_org_id     := p_parent_line_rec.sold_to_org_id;
7672     p_x_child_line_rec.tax_code           := p_parent_line_rec.tax_code;
7673     p_x_child_line_rec.shippable_flag     := 'N';
7674     p_x_child_line_rec.shipping_interfaced_flag := 'N';
7675     p_x_child_line_rec.booked_flag        := 'N';
7676     p_x_child_line_rec.open_flag          := 'Y';
7677     p_x_child_line_rec.cancelled_flag     := 'N';
7678     p_x_child_line_rec.cancelled_quantity := 0;
7679     p_x_child_line_rec.source_type_code   := p_parent_line_rec.source_type_code;
7680     p_x_child_line_rec.org_id             := p_parent_line_rec.org_id;
7681     -- Bug 5912216: start
7682     -- p_x_child_line_rec.flow_status_code   := 'ENTERED'; (Commented out)
7683     p_x_child_line_rec.flow_status_code   := p_parent_line_rec.flow_status_code;
7684     p_x_child_line_rec.transaction_phase_code := p_parent_line_rec.transaction_phase_code;
7685     -- Bug 5912216: end
7686     p_x_child_line_rec.payment_term_id    := p_parent_line_rec.payment_term_id;
7687     p_x_child_line_rec.calculate_price_flag  := 'Y';
7688 
7689     -- this is for pure ato, pto+ato will get in change_columns.
7690     p_x_child_line_rec.ato_line_id        := p_parent_line_rec.ato_line_id;
7691 
7692   END IF;
7693 
7694 
7695   ---------- conditional defaulting here onwards----------
7696 
7697 
7698   ---------- SMC/ATO/SHIP and Arrival Set-----------------
7699 
7700   IF p_parent_line_rec.ship_model_complete_flag = 'Y' OR
7701      p_parent_line_rec.ato_line_id = p_parent_line_rec.top_model_line_id OR
7702      (p_parent_line_rec.ship_set_id is NOT NULL AND
7703       p_parent_line_rec.ship_set_id <> FND_API.G_MISS_NUM) OR
7704      (p_parent_line_rec.arrival_set_id is NOT NULL AND
7705       p_parent_line_rec.arrival_set_id <> FND_API.G_MISS_NUM)
7706   THEN
7707       IF l_debug_level  > 0 THEN
7708         oe_debug_pub.add('**PARENT IS ATO OR SMC PTO OR IN SET' , 1);
7709       END IF;
7710 
7711       p_x_child_line_rec.schedule_ship_date    :=
7712                          p_parent_line_rec.schedule_ship_date;
7713       p_x_child_line_rec.schedule_arrival_date :=
7714                          p_parent_line_rec.schedule_arrival_date;
7715       p_x_child_line_rec.freight_carrier_code  :=
7716                          p_parent_line_rec.freight_carrier_code;
7717 
7718 
7719       /* Added the following 3 lines to fix the bug 3056512 */
7720 
7721       p_x_child_line_rec.ship_to_org_id     := p_parent_line_rec.ship_to_org_id;
7722       p_x_child_line_rec.request_date       := p_parent_line_rec.request_date;
7723       p_x_child_line_rec.invoice_to_org_id  := p_parent_line_rec.invoice_to_org_id;
7724 
7725       /*Begin bug 7041018,7175458*/
7726        p_x_child_line_rec.intermed_ship_to_org_id := p_parent_line_rec.intermed_ship_to_org_id;
7727        p_x_child_line_rec.ship_to_contact_id := p_parent_line_rec.ship_to_contact_id;
7728      /*end bug 7041018, 7175458*/
7729       ------------- IF SMC ----------------------------------
7730 
7731       IF p_parent_line_rec.ship_model_complete_flag = 'Y' THEN
7732 
7733         IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
7734           p_x_child_line_rec.firm_demand_flag :=
7735                           p_parent_line_rec.firm_demand_flag;
7736         END IF;
7737       END IF;
7738 
7739       ------------- IF ATO ----------------------------------
7740       IF p_parent_line_rec.ato_line_id is not NULL THEN
7741         IF l_debug_level  > 0 THEN
7742           oe_debug_pub.add('1 **SOURCE TYPE ATO '
7743                            || P_PARENT_LINE_REC.SOURCE_TYPE_CODE , 4 );
7744         END IF;
7745 
7746         p_x_child_line_rec.source_type_code    :=
7747                          p_parent_line_rec.source_type_code;
7748 
7749         IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110509' THEN
7750           p_x_child_line_rec.override_atp_date_code :=
7751                        p_parent_line_rec.override_atp_date_code;
7752         END IF;
7753 
7754         IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
7755           p_x_child_line_rec.firm_demand_flag :=
7756                        p_parent_line_rec.firm_demand_flag;
7757         END IF;
7758       END IF;
7759 
7760   ------------- IF NON SMC, use this branch -----------------
7761   ELSE -- Added the else to fix the bug 3056512
7762 
7763       IF l_debug_level  > 0 THEN
7764         oe_debug_pub.add('**PARENT IS NON SMC PTO ' , 1);
7765       END IF;
7766 
7767       IF p_x_child_line_rec.ship_to_org_id = FND_API.G_MISS_NUM OR
7768          p_x_child_line_rec.ship_to_org_id IS NULL THEN
7769         p_x_child_line_rec.ship_to_org_id
7770                  := p_parent_line_rec.ship_to_org_id;
7771       END IF;
7772 
7773       IF p_x_child_line_rec.request_date = FND_API.G_MISS_DATE OR
7774          p_x_child_line_rec.request_date IS NULL THEN
7775          p_x_child_line_rec.request_date
7776                  := p_parent_line_rec.request_date;
7777       END IF;
7778 
7779       IF p_x_child_line_rec.invoice_to_org_id = FND_API.G_MISS_NUM OR
7780          p_x_child_line_rec.invoice_to_org_id IS NULL THEN
7781          p_x_child_line_rec.invoice_to_org_id
7782                  := p_parent_line_rec.invoice_to_org_id;
7783       END IF;
7784 
7785       /*Start bug7041018,7175458*/
7786       IF p_x_child_line_rec.intermed_ship_to_org_id = FND_API.G_MISS_NUM OR
7787          p_x_child_line_rec.intermed_ship_to_org_id IS NULL THEN
7788          p_x_child_line_rec.intermed_ship_to_org_id
7789                  := p_parent_line_rec.intermed_ship_to_org_id;
7790       END IF;
7791 
7792       IF p_x_child_line_rec.ship_to_contact_id = FND_API.G_MISS_NUM OR
7793          p_x_child_line_rec.ship_to_contact_id IS NULL THEN
7794          p_x_child_line_rec.ship_to_contact_id
7795                  := p_parent_line_rec.ship_to_contact_id;
7796       END IF;
7797 
7798       /*ENd bug 7041018,71754588*/
7799 
7800   END IF;  ------ if part of ato/smc/ship or arr set.
7801 
7802 
7803 
7804   --Begin- code to get user_item_description from the parent for the child
7805 
7806   IF p_x_child_line_rec.item_type_code = OE_GLOBALS.G_ITEM_CONFIG AND
7807      p_x_child_line_rec.ato_line_id is not NULL AND
7808      p_x_child_line_rec.line_id <> p_x_child_line_rec.ato_line_id THEN
7809 
7810      IF l_debug_level > 0 THEN
7811         oe_debug_pub.add('DEFAULTING USER_ITEM_DESCRIPTION
7812                           FROM ATO FOR CONFIG ITEMS ', 1);
7813      END IF;
7814 
7815      SELECT user_item_description
7816      INTO   p_x_child_line_rec.user_item_description
7817      FROM   oe_order_lines
7818      WHERE  line_id = p_x_child_line_rec.ato_line_id;
7819 
7820      --no need to handle exception here as exception is handled outside
7821 
7822      IF l_debug_level > 0 THEN
7823         oe_debug_pub.add('USER_ITEM_DESCRIPTION on child line is: '
7824                           || p_x_child_line_rec.user_item_description, 1);
7825      END IF;
7826 
7827      -- Populate delivery lead time from the parent.
7828      p_x_child_line_rec.delivery_lead_time := p_parent_line_rec.delivery_lead_time;
7829   END IF;
7830 
7831 
7832   ------------------ ATO within PTO -------------------------------
7833   IF p_x_child_line_rec.ato_line_id is not NULL AND
7834      p_x_child_line_rec.line_id <> p_x_child_line_rec.ato_line_id AND
7835      p_x_child_line_rec.top_model_line_id <> p_x_child_line_rec.ato_line_id
7836   THEN
7837 
7838      IF l_debug_level  > 0 THEN
7839        oe_debug_pub.add('ATO IN PTO '||P_X_CHILD_LINE_REC.ATO_LINE_ID , 2 );
7840      END IF;
7841 
7842      SELECT source_type_code, project_id, task_id,
7843             ship_from_org_id, ship_to_org_id,
7844             schedule_ship_date, schedule_arrival_date,
7845             request_date, shipping_method_code,
7846             freight_carrier_code, invoice_to_org_id,
7847             firm_demand_flag, override_atp_date_code,
7848             ship_to_contact_id,intmed_ship_to_org_id  --bug 7041018,7175458
7849      INTO   p_x_child_line_rec.source_type_code,
7850             p_x_child_line_rec.project_id,
7851             p_x_child_line_rec.task_id,
7852             p_x_child_line_rec.ship_from_org_id,
7853             p_x_child_line_rec.ship_to_org_id,
7854             p_x_child_line_rec.schedule_ship_date,
7855             p_x_child_line_rec.schedule_arrival_date,
7856             p_x_child_line_rec.request_date,
7857             p_x_child_line_rec.shipping_method_code,
7858             p_x_child_line_rec.freight_carrier_code,
7859             p_x_child_line_rec.invoice_to_org_id,
7860             p_x_child_line_rec.firm_demand_flag,
7861             p_x_child_line_rec.override_atp_date_code,
7862             p_x_child_line_rec.ship_to_contact_id,   --bug7041018,7175458
7863             p_x_child_line_rec.intermed_ship_to_org_id   --bug 7041018,7175458
7864      FROM   oe_order_lines
7865      WHERE  line_id = p_x_child_line_rec.ato_line_id;
7866 
7867      IF l_debug_level  > 0 THEN
7868        oe_debug_pub.add('2 **SOURCE TYPE ATO '
7869                         || P_X_CHILD_LINE_REC.SOURCE_TYPE_CODE , 4 );
7870      END IF;
7871 
7872   END IF;
7873 
7874 
7875   -------------------- any other conditions -------------------
7876   --IF
7877   --  put logic here
7878   --END IF;
7879 
7880 
7881   x_return_status := FND_API.G_RET_STS_SUCCESS;
7882   IF l_debug_level  > 0 THEN
7883     oe_debug_pub.add('LEAVING DEFAULT_CHILD_LINE' , 1);
7884   END IF;
7885 
7886 EXCEPTION
7887 
7888   WHEN FND_API.G_EXC_ERROR THEN
7889     IF l_debug_level  > 0 THEN
7890       oe_debug_pub.add('DEFAULT_CHILD_LINE, exc error '|| SQLERRM , 1);
7891     END IF;
7892     x_return_status := FND_API.G_RET_STS_ERROR;
7893 
7894   WHEN OTHERS THEN
7895     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7896     IF l_debug_level  > 0 THEN
7897       oe_debug_pub.add('others in DEFAULT_CHILD_LINE '|| SQLERRM , 1);
7898     END IF;
7899 
7900 END Default_Child_Line;
7901 
7902 
7903 /*---------------------------------------------------------------------
7904 PROCEDURE: Is_Included_Item_Constrained
7905 
7906 This API will check if the delete and update quantity operation
7907 performed on a Included item should be allowed or not.
7908 We will not allow any user delete/update quantity.
7909 We will allow system changes ex: cascading.
7910 
7911 We have to write a pl/sql api because we want the system to be able to
7912 do the operations.
7913 
7914 result of 1 means constrained.
7915 
7916 Process_Included_Items procedure will set the security_check to
7917 false, before calling process_order.
7918 
7919 --##1922440 bug fix.
7920 ----------------------------------------------------------------------*/
7921 PROCEDURE Is_Included_Item_Constrained
7922 ( p_application_id                IN   NUMBER,
7923   p_entity_short_name             IN   VARCHAR2,
7924   p_validation_entity_short_name  IN   VARCHAR2,
7925   p_validation_tmplt_short_name   IN   VARCHAR2,
7926   p_record_set_short_name         IN   VARCHAR2,
7927   p_scope                         IN   VARCHAR2,
7928   x_result                        OUT NOCOPY /* file.sql.39 change */  NUMBER )
7929 IS
7930   l_item_type_code         VARCHAR2(30);
7931   l_model_remnant_flag     VARCHAR2(1);
7932   l_pre_exploded_flag      VARCHAR2(1); -- DOO Preexploded Kit ER 9339742
7933   --
7934   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
7935   --
7936 BEGIN
7937 
7938   IF l_debug_level  > 0 THEN
7939     oe_debug_pub.add('ENTERING IS_INCLUDED_ITEM_CONSTRAINED' , 1);
7940     oe_debug_pub.add('OPERATION '|| OE_LINE_SECURITY.G_RECORD.OPERATION , 4 );
7941     oe_debug_pub.add('ITEM TYPE '||OE_LINE_SECURITY.G_RECORD.ITEM_TYPE_CODE,4);
7942   END IF;
7943 
7944   SELECT item_type_code, model_remnant_flag, pre_exploded_flag
7945   INTO   l_item_type_code, l_model_remnant_flag, l_pre_exploded_flag  -- DOO Preexploded Kit ER 9339742
7946   FROM   oe_order_lines
7947   WHERE  line_id = oe_line_security.g_record.line_id;
7948 
7949   IF l_debug_level  > 0 THEN -- DOO Preexploded Kit ER 9339742
7950     oe_debug_pub.add('Pre Exploded Flag is : '||l_pre_exploded_flag);
7951   END IF;
7952 
7953   IF nvl(l_item_type_code, 'A') <> 'INCLUDED' THEN
7954     x_result := 0;
7955     RETURN;
7956   END IF;
7957 
7958   IF  OE_CONFIG_UTIL.CASCADE_CHANGES_FLAG = 'Y' OR
7959       OE_CONFIG_PVT.OECFG_VALIDATE_CONFIG = 'N' OR
7960       l_model_remnant_flag = 'Y'                OR
7961       -- DOO Preexploded Kit ER 9339742
7962       l_pre_exploded_flag  = 'Y'                OR
7963       Oe_Genesis_Util.G_INCOMING_FROM_DOO
7964   THEN
7965     x_result := 0;
7966   ELSE
7967     x_result := 1;
7968   END IF;
7969 
7970   IF l_debug_level  > 0 THEN
7971     oe_debug_pub.add('LEAVING IS_INCLUDED_ITEM_CONSTRAINED '|| X_RESULT , 1);
7972   END IF;
7973 
7974 EXCEPTION
7975   WHEN OTHERS THEN
7976     IF l_debug_level  > 0 THEN
7977       oe_debug_pub.add('IS_INCLUDED_ITEM_CONSTRAINED ERROR '|| SQLERRM , 1);
7978     END IF;
7979     RAISE;
7980 END Is_Included_Item_Constrained;
7981 
7982 
7983 /*--------------------------------------------------------
7984 PROCEDURE: Log_Included_Item_Requests
7985 
7986 This procedure will be used to log delayed requests
7987 for included items. To improce performance of
7988 saving included items, we will set the
7989 control_rec.change_attributes parameter to FALSE.
7990 Hence all the delayed requests logged in
7991 oe_line_util.apply_attribute_changes procedure for
7992 included_items will be logged here.
7993 --------------------------------------------------------*/
7994 PROCEDURE Log_Included_Item_Requests
7995 ( p_line_tbl    IN  OE_Order_Pub.Line_Tbl_Type
7996  ,p_booked_flag IN  VARCHAR2)
7997 IS
7998   I                NUMBER;
7999   l_return_status  VARCHAR2(1);
8000   --
8001   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8002   --
8003   l_serviceable_item   VARCHAR2(1); -- Added for bug 5925600
8004   l_serviced_model     VARCHAR2(1); -- Added for bug 5925600
8005 
8006 BEGIN
8007   IF l_debug_level  > 0 THEN
8008     oe_debug_pub.add('ENTERING LOG_INCLUDED_ITEM_REQUESTS'
8009                      || P_LINE_TBL.COUNT , 1);
8010   END IF;
8011 
8012   I := p_line_tbl.FIRST;
8013   FOR I in p_line_tbl.FIRST..p_line_tbl.LAST
8014   LOOP
8015 
8016     IF nvl(FND_PROFILE.VALUE('ONT_CHARGES_FOR_INCLUDED_ITEM'),'N') = 'Y'
8017     THEN
8018 
8019       IF l_debug_level  > 0 THEN
8020         oe_debug_pub.add('RENGA-LOGGING REQ TO CHARGES FOR INCLUDED ' , 3 );
8021         oe_debug_pub.add('RENGA-LINE OPERATION IS : '
8022                           || P_LINE_TBL (I).OPERATION , 3 );
8023       END IF;
8024 
8025       OE_LINE_ADJ_UTIL.Register_Changed_Lines
8026       (p_line_id         => p_line_tbl(I).line_id,
8027        p_header_id       => p_line_tbl(I).header_id,
8028        p_operation       => p_line_tbl(I).operation );
8029 
8030       IF l_debug_level  > 0 THEN
8031         oe_debug_pub.add('RENGA-AFTER REGISTER_CHANGED_LINES Booked Flag=' || p_booked_flag , 3 );
8032       END IF;
8033 
8034     --Added the if clause for bug 6892989/6903859
8035       IF ( nvl(p_booked_flag,'N') = 'Y' ) THEN
8036       OE_delayed_requests_Pvt.log_request
8037       (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
8038        p_entity_id              => p_line_tbl(I).header_id,
8039        p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
8040        p_requesting_entity_id   => p_line_tbl(I).header_id,
8041        p_request_unique_key1    => 'BATCH,BOOK',
8042        p_param1                 => p_line_tbl(I).header_id,
8043        p_param2                 => 'BATCH,BOOK',
8044        p_request_type           => OE_GLOBALS.G_FREIGHT_FOR_INCLUDED,
8045        x_return_status          => l_return_status);
8046      ELSE
8047       OE_delayed_requests_Pvt.log_request
8048       (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
8049        p_entity_id              => p_line_tbl(I).header_id,
8050        p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
8051        p_requesting_entity_id   => p_line_tbl(I).header_id,
8052        p_request_unique_key1    => 'BATCH',
8053        p_param1                 => p_line_tbl(I).header_id,
8054        p_param2                 => 'BATCH',
8055        p_request_type           => OE_GLOBALS.G_FREIGHT_FOR_INCLUDED,
8056        x_return_status          => l_return_status);
8057      END IF;
8058 
8059 
8060       IF l_debug_level  > 0 THEN
8061         oe_debug_pub.add
8062         ('RENGA-AFTER LOGGING DELAYED REQ FREIGHT_FOR_INCLUDED-2' , 3 );
8063       END IF;
8064 
8065     END IF;
8066 
8067     IF l_debug_level  > 0 THEN
8068       oe_debug_pub.add('LOGGING REQ TO TAX_LINE ' , 3 );
8069       oe_debug_pub.add('REN: ITEM TYPE CODE IS: '
8070                        || P_LINE_TBL (I).ITEM_TYPE_CODE , 1);
8071     END IF;
8072 
8073    IF p_line_tbl(I).item_type_code not in ('INCLUDED', 'CONFIG') THEN
8074 
8075      IF l_debug_level  > 0 THEN
8076        oe_debug_pub.add('REN: ITEM TYPE CODE IS NOT INCLUDED OR CONFIG' , 1);
8077      END IF;
8078 
8079    IF (OE_GLOBALS.G_UI_FLAG) AND nvl(FND_PROFILE.VALUE('ONT_DELAY_TAX_CALC'), 'N') = 'N' THEN --TaxER
8080     OE_delayed_requests_Pvt.log_request
8081     (p_entity_code            => OE_GLOBALS.G_ENTITY_LINE,
8082      p_entity_id              => p_line_tbl(I).line_id,
8083      p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
8084      p_requesting_entity_id   => p_line_tbl(I).line_id,
8085      p_request_type           => OE_GLOBALS.g_tax_line,
8086      x_return_status          => l_return_status);
8087    --TaxER Start
8088    ELSE
8089     OE_delayed_requests_Pvt.log_request
8090     (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
8091      p_entity_id              => p_line_tbl(I).line_id,
8092      p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
8093      p_requesting_entity_id   => p_line_tbl(I).line_id,
8094      p_request_type           => OE_GLOBALS.g_tax_line,
8095      x_return_status          => l_return_status);
8096    END IF;
8097    --TaxER End
8098 
8099    END IF;
8100 
8101     IF OE_Commitment_Pvt.Do_Commitment_Sequencing AND
8102        p_line_tbl(I).commitment_id is not null
8103     THEN
8104       IF l_debug_level  > 0 THEN
8105         oe_debug_pub.add('LOGGING REQ TO CALC COMMITMENT' , 3 );
8106       END IF;
8107 
8108       OE_Delayed_Requests_Pvt.Log_Request
8109       (p_entity_code             => OE_GLOBALS.G_ENTITY_LINE,
8110        p_entity_id               => p_line_tbl(I).line_id,
8111        p_requesting_entity_code  => OE_GLOBALS.G_ENTITY_LINE,
8112        p_requesting_entity_id    => p_line_tbl(I).line_id,
8113        p_request_type            => OE_GLOBALS.G_CALCULATE_COMMITMENT,
8114        x_return_status           => l_return_status);
8115     END IF;
8116 
8117     IF p_booked_flag = 'Y' AND
8118        p_line_tbl(I).operation = 'UPDATE' THEN
8119 
8120       IF l_debug_level  > 0 THEN
8121         oe_debug_pub.add('LOGGING REQ TO VERIFY_PAYMENT' , 3 );
8122       END IF;
8123       OE_delayed_requests_Pvt.log_request
8124       (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
8125        p_entity_id              => p_line_tbl(I).header_id,
8126        p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
8127        p_requesting_entity_id   => p_line_tbl(I).line_id,
8128        p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
8129        x_return_status          => l_return_status);
8130 
8131     END IF;
8132 
8133     -- Log delayed request for Freight Rating.
8134     IF OE_Freight_Rating_Util.IS_FREIGHT_RATING_AVAILABLE
8135        AND OE_Freight_Rating_Util.Get_List_Line_Type_Code
8136                                   (p_line_tbl(I).header_id)
8137             = 'OM_CALLED_FREIGHT_RATES' THEN
8138        IF l_debug_level  > 0 THEN
8139          oe_debug_pub.add
8140          ('LOGGING DELAYED REQUEST FOR FREIGHT RATE FOR INCLUDED ITEM: '
8141           ||P_LINE_TBL (I).HEADER_ID , 2 );
8142        END IF;
8143 
8144        OE_delayed_requests_Pvt.log_request
8145        (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
8146         p_entity_id              => p_line_tbl(I).header_id,
8147         p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
8148         p_requesting_entity_id   => p_line_tbl(I).line_id,
8149         p_request_type           => OE_GLOBALS.G_FREIGHT_RATING,
8150         p_param1                 => 'Y',
8151         x_return_status          => l_return_status);
8152     END IF;
8153 
8154     /* Below code has been added for bug 5925600 */
8155     IF p_line_tbl(I).operation = OE_GLOBALS.G_OPR_CREATE THEN
8156 
8157       if l_debug_level > 0 then
8158         oe_debug_pub.add('Before checking if we need to log delayed request for G_CASCADE_OPTIONS_SERVICE', 5);
8159 	oe_debug_pub.ADD('operation : '|| p_line_tbl(I).operation);
8160 	oe_debug_pub.ADD('inventory_item_id : '|| p_line_tbl(I).inventory_item_id);
8161       end if;
8162 
8163       BEGIN
8164 	select 'Y'
8165 	into   l_serviceable_item
8166 	from   mtl_system_items mtl
8167 	where  mtl.inventory_item_id = p_line_tbl(I).inventory_item_id
8168 	and    mtl.organization_id = OE_SYS_PARAMETERS.VALUE('MASTER_ORGANIZATION_ID')
8169 	and    mtl.serviceable_product_flag='Y'
8170 	and    rownum = 1;
8171 
8172       EXCEPTION
8173 	  WHEN OTHERS THEN
8174 	    l_serviceable_item := 'N';
8175       END;
8176 
8177       if l_debug_level > 0 then
8178          oe_debug_pub.ADD('serviceable option :  '|| l_serviceable_item);
8179 	 oe_debug_pub.ADD('service_reference_line_id:  '|| p_line_tbl(I).top_model_line_id);
8180       end if;
8181 
8182       IF l_serviceable_item = 'Y' THEN
8183 
8184          BEGIN
8185 	   select 'Y'
8186            into   l_serviced_model
8187 	   from   oe_order_lines
8188 	   where  item_type_code = 'SERVICE'
8189 	   and    service_reference_line_id = p_line_tbl(I).top_model_line_id
8190 	   and    service_reference_type_code = 'ORDER'
8191 	   and    rownum = 1;
8192 
8193 	 EXCEPTION
8194 	    WHEN OTHERS THEN
8195 	      l_serviced_model := 'N';
8196 	 END;
8197 
8198 	 if l_debug_level > 0 then
8199 	    oe_debug_pub.ADD('serviced model :  '|| l_serviced_model);
8200 	 end if;
8201 
8202 	 IF l_serviced_model = 'Y' THEN
8203 
8204 	    if l_debug_level > 0 then
8205 	       oe_debug_pub.add('Before log delayed request -- G_CASCADE_OPTIONS_SERVICE',1);
8206 	    end if;
8207 
8208 	    OE_Delayed_Requests_Pvt.log_request
8209 		 (
8210 		   p_entity_code            => OE_GLOBALS.G_ENTITY_LINE,
8211 		   p_entity_id              => p_line_tbl(I).line_id,
8212 		   p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
8213 		   p_requesting_entity_id   => p_line_tbl(I).line_id,
8214 		   p_request_type           => OE_GLOBALS.G_CASCADE_OPTIONS_SERVICE,
8215 		   x_return_status          => l_return_status
8216 		 );
8217 
8218 	  END IF; /* l_serviced_model = 'Y' */
8219        END IF; /* l_serviceable_item = 'Y' */
8220     END IF; /* operation = CREATE */
8221     /* End of changes done for bug 5925600 */
8222 
8223   END LOOP;
8224 
8225   IF l_debug_level  > 0 THEN
8226     oe_debug_pub.add('LEAVING LOG_INCLUDED_ITEM_REQUESTS' , 1);
8227   END IF;
8228 EXCEPTION
8229   WHEN OTHERS THEN
8230     IF l_debug_level  > 0 THEN
8231       oe_debug_pub.add('LOG_INCLUDED_ITEM_REQUESTS '|| SQLERRM , 1);
8232     END IF;
8233     RAISE;
8234 END;
8235 
8236 
8237 /*--------------------------------------------------------
8238 PROCEDURE ATO_Remnant_Check
8239 Constraint API to not let some changes to remnant
8240 ATOs.
8241 --------------------------------------------------------*/
8242 
8243 PROCEDURE ATO_Remnant_Check
8244 ( p_application_id                IN   NUMBER,
8245   p_entity_short_name             IN   VARCHAR2,
8246   p_validation_entity_short_name  IN   VARCHAR2,
8247   p_validation_tmplt_short_name   IN   VARCHAR2,
8248   p_record_set_short_name         IN   VARCHAR2,
8249   p_scope                         IN   VARCHAR2,
8250   x_result                        OUT NOCOPY /* file.sql.39 change */  NUMBER )
8251 IS
8252 --
8253 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8254 --
8255 BEGIN
8256 
8257   x_result := 0;
8258 
8259   IF nvl(oe_line_security.g_record.model_remnant_flag, 'N') = 'N' THEN
8260     RETURN;
8261   END IF;
8262 
8263   IF oe_line_security.g_record.ato_line_id is NULL THEN
8264     RETURN;
8265   END IF;
8266 
8267   --IF oe_line_security.g_record.item_type_code = 'STANDARD' OR
8268     -- (oe_line_security.g_record.item_type_code = 'OPTION' AND
8269   --Begin Bug fix for bug#6153528
8270      IF oe_line_security.g_record.item_type_code IN ( 'STANDARD', 'OPTION', 'CONFIG', 'CLASS' )  OR
8271      (oe_line_security.g_record.item_type_code in ( 'OPTION', 'CLASS','INCLUDED' ) AND
8272   --added 'INCLUDED' above ^^ as a part of bug 13065898 , required after B2B ER.
8273   --End Bug fix for bug#6153528
8274       oe_line_security.g_record.line_id = oe_line_security.g_record.ato_line_id) THEN
8275     RETURN;
8276   END IF;
8277 
8278   IF l_debug_level  > 0 THEN
8279     oe_debug_pub.add('REMNANT ATO CHECK CONSTRAINED' , 3 );
8280   END IF;
8281 
8282   x_result := 1;
8283 
8284 EXCEPTION
8285   WHEN OTHERS THEN
8286     IF l_debug_level  > 0 THEN
8287       oe_debug_pub.add('ATO_REMNANT_CHECK ERROR '|| SQLERRM , 1);
8288     END IF;
8289     RAISE;
8290 END ATO_Remnant_Check;
8291 
8292 /*--------------------------------------------------------
8293 PROCEDURE Launch_Supply_Workbench
8294 
8295 This procedure is used to perform some checks on line/
8296 header before launching the supply to order wb.
8297 It also derives a wb item type and sends it as out NOCOPY param.
8298 This functionality is only available from pack I onwards.
8299 
8300 p_header_id is populated when the action is performed
8301 from header block and not when call is made from line block.
8302 rest of the params are populated when it is performed from
8303 line block.
8304 
8305 This action is only UI action not for batch call.
8306 
8307 This API will be called only if the order is booked.
8308 --------------------------------------------------------*/
8309 PROCEDURE Launch_Supply_Workbench
8310 ( p_header_id          IN  NUMBER
8311  ,p_top_model_line_id  IN  NUMBER
8312  ,p_ato_line_id        IN  NUMBER
8313  ,p_line_id            IN  NUMBER
8314  ,p_item_type_code     IN  VARCHAR2
8315  ,x_wb_item_type       OUT NOCOPY /* file.sql.39 change */ VARCHAR2
8316  ,x_return_status      OUT NOCOPY /* file.sql.39 change */ VARCHAR2)
8317 IS
8318   l_count   NUMBER;
8319   --
8320   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8321   --
8322 BEGIN
8323 
8324   Print_Time('entering Launch_Supply_Workbench');
8325 
8326   IF l_debug_level  > 0 THEN
8327     oe_debug_pub.add('-'|| P_HEADER_ID || '-' || P_TOP_MODEL_LINE_ID
8328                      || '-' || P_ATO_LINE_ID || '-' || P_LINE_ID
8329                      || '-' || P_ITEM_TYPE_CODE , 3 );
8330   END IF;
8331 
8332   IF p_header_id is not NULL AND
8333      p_line_id is not NULL THEN
8334     IF l_debug_level  > 0 THEN
8335       oe_debug_pub.add('WRONG PARAMTERS' , 1);
8336     END IF;
8337     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8338   END IF;
8339 
8340   x_return_status := FND_API.G_RET_STS_SUCCESS;
8341   x_wb_item_type  := null;
8342 
8343   SELECT count(*)
8344   INTO   l_count
8345   FROM   oe_order_lines
8346   WHERE  line_category_code  <> 'RETURN'
8347 	-- the condition below is commented for bug 3441504
8348  -- AND  booked_flag = 'Y'
8349   AND    (header_id          = p_header_id OR
8350           (top_model_line_id = p_top_model_line_id AND
8351            p_line_id         = p_top_model_line_id) OR
8352           (ato_line_id       = p_ato_line_id AND
8353            top_model_line_id = p_top_model_line_id AND
8354            p_line_id         = p_ato_line_id AND
8355            p_item_type_code in ('MODEL', 'CLASS')) OR
8356           line_id           = p_line_id)
8357   AND    ((source_type_code = 'EXTERNAL' AND
8358            shippable_flag = 'Y') OR
8359           (ato_line_id = line_id AND
8360            item_type_code in ('STANDARD', 'OPTION', 'INCLUDED')) OR --9775352
8361            item_type_code = 'CONFIG')
8362   AND     OPEN_FLAG = 'Y';
8363 
8364 
8365   IF l_count > 0 THEN
8366     IF l_debug_level  > 0 THEN
8367       oe_debug_pub.add('ELIGIBLE LINES EXIST '|| L_COUNT , 1);
8368     END IF;
8369   ELSE
8370     IF l_debug_level  > 0 THEN
8371       oe_debug_pub.add('NO ELIGIBLE LINES ' , 1);
8372     END IF;
8373     x_return_status := FND_API.G_RET_STS_ERROR;
8374     RETURN;
8375   END IF;
8376 
8377   IF p_header_id is not null AND
8378      p_line_id is null THEN
8379 
8380      IF l_debug_level  > 0 THEN
8381        oe_debug_pub.add('WB ITEM TYPE IS HEADER '|| P_HEADER_ID , 3 );
8382      END IF;
8383      x_wb_item_type := 'HEAD';
8384 
8385   ElSIF p_top_model_line_id is not null AND
8386         p_ato_line_id is null AND
8387         p_item_type_code = 'MODEL' THEN
8388 
8389     IF l_debug_level  > 0 THEN
8390       oe_debug_pub.add('WB ITEM TYPE IS PTO MODEL '
8391                        || P_TOP_MODEL_LINE_ID , 3 );
8392     END IF;
8393     x_wb_item_type := 'PTO';
8394 
8395   ElSIF p_ato_line_id = p_line_id AND
8396         (p_item_type_code = 'MODEL' OR
8397          p_item_type_code = 'CLASS') THEN
8398 
8399     IF l_debug_level  > 0 THEN
8400       oe_debug_pub.add('WB ITEM TYPE IS ATO MODEL ' || P_ATO_LINE_ID , 3 );
8401     END IF;
8402     x_wb_item_type := 'MDL';
8403 
8404    ELSE
8405 
8406      IF p_ato_line_id = p_line_id AND
8407         (p_item_type_code = 'STANDARD' OR
8408          p_item_type_code = 'OPTION' OR
8409 	 p_item_type_code = 'INCLUDED') THEN --9775352
8410 
8411        IF l_debug_level  > 0 THEN
8412          oe_debug_pub.add('WB ITEM TYPE IS ATO ITEM ' || P_LINE_ID , 3 );
8413        END IF;
8414        x_wb_item_type := 'ATO';
8415 
8416      ELSIF p_item_type_code = 'CONFIG' THEN
8417        IF l_debug_level  > 0 THEN
8418          oe_debug_pub.add('WB ITEM TYPE IS CONFIG ITEM ' || P_LINE_ID , 3 );
8419        END IF;
8420        x_wb_item_type := 'CFG';
8421 
8422      ELSE
8423        IF l_debug_level  > 0 THEN
8424          oe_debug_pub.add('WB ITEM TYPE IS STD DROPSHIP ITEM '
8425                           || P_LINE_ID , 3 );
8426        END IF;
8427        x_wb_item_type := 'STD';
8428      END IF;
8429 
8430   END IF; -- if l_count > 0
8431 
8432   Print_Time('leaving Launch_Supply_Workbench '|| x_wb_item_type);
8433 
8434 EXCEPTION
8435   WHEN OTHERS THEN
8436     IF l_debug_level  > 0 THEN
8437       oe_debug_pub.add('ERROR IN LAUNCH_SUPPLY_WORKBENCH'|| SQLERRM , 1);
8438     END IF;
8439     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8440 END Launch_Supply_Workbench;
8441 
8442 /* -----------------------------------------------------------
8443 PROCEDURE Message_From_Cz
8444 Called to copy the messages from the CZ schema to
8445 the OM tables
8446 --------------------------------------------------------------*/
8447 
8448 PROCEDURE Message_From_Cz
8449 ( p_line_id            IN NUMBER,
8450   p_valid_config       IN VARCHAR2,
8451   p_complete_config    IN VARCHAR2,
8452   p_config_header_id   IN NUMBER,
8453   p_config_rev_nbr     IN NUMBER )
8454 IS
8455 
8456     l_config_header_id                NUMBER := p_config_header_id;
8457     l_config_rev_nbr                  NUMBER := p_config_rev_nbr;
8458     l_message_text                    VARCHAR2(2000);
8459     l_msg                             VARCHAR2(2000);
8460     l_constraint                      VARCHAR2(16);
8461 
8462     CURSOR messages(p_config_hdr_id NUMBER, p_config_rev_nbr NUMBER) is
8463     SELECT constraint_type , message
8464     FROM   cz_config_messages
8465     WHERE  config_hdr_id =  p_config_hdr_id
8466     AND    config_rev_nbr = p_config_rev_nbr;
8467 
8468 
8469 BEGIN
8470     oe_debug_pub.add(' Entering Message_From_Cz');
8471 
8472     OPEN messages(l_config_header_id, l_config_rev_nbr);
8473 
8474     LOOP
8475       FETCH messages into l_constraint,l_msg;
8476       EXIT when messages%notfound;
8477 
8478       OE_Msg_Pub.Add_Text(l_msg);
8479       oe_debug_pub.add('msg from spc: '||messages%rowcount , 2);
8480       oe_debug_pub.add('msg from spc: '|| substr(l_msg, 1, 250) , 3);
8481 
8482     END LOOP;
8483 
8484     IF nvl(p_valid_config, 'FALSE') = 'FALSE' THEN
8485 
8486       FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_VALIDATION_FAILURE');
8487       OE_Msg_Pub.Add;
8488     END IF;
8489 
8490     IF nvl(p_complete_config, 'FALSE') = 'FALSE'  THEN
8491 
8492       BEGIN
8493 
8494         SELECT nvl(ordered_item,inventory_item_id )
8495         INTO   l_message_text
8496         FROM   oe_order_lines
8497         WHERE  line_id = p_line_id;
8498 
8499       EXCEPTION
8500         WHEN OTHERS THEN
8501           null;
8502       END;
8503 
8504       FND_MESSAGE.Set_Name('ONT', 'OE_CONFIG_INCOMPLETE_MODEL');
8505       FND_MESSAGE.SET_TOKEN('MODEL',l_message_text);
8506       OE_Msg_Pub.Add;
8507 
8508     END IF;
8509 
8510 EXCEPTION
8511     WHEN OTHERS THEN
8512       OE_Debug_Pub.Add('Error in Message_From_Cz '|| sqlerrm, 2);
8513 END Message_From_Cz;
8514 
8515 /*--------------------------------------------------------
8516 PROCEDURE Get_Config_Effective_Date
8517 
8518 one of the i/p params p_model_line_rec  or p_model_line_id
8519 should have a valid value - from caller.
8520 
8521 callers:
8522 cz ui call and batch val.
8523 process order
8524 options window ui and batch val.
8525 
8526 profile value,
8527 1 - old behavior
8528 2 - creation date of model
8529 3 - sysdate till booking.
8530 4 - sysdate till pick release   -- #6187663
8531 --------------------------------------------------------*/
8532 PROCEDURE Get_Config_Effective_Date
8533 ( p_model_line_rec        IN  OE_Order_Pub.Line_Rec_Type := null
8534  ,p_model_line_id         IN  NUMBER    := null
8535  ,x_old_behavior          OUT NOCOPY    VARCHAR2
8536  ,x_config_effective_date OUT NOCOPY    DATE
8537  ,x_frozen_model_bill     OUT NOCOPY    VARCHAR2)
8538 IS
8539 
8540   l_header_id           NUMBER;
8541   l_creation_date       DATE;
8542   l_profile             VARCHAR2(1);
8543   l_line_set_id         NUMBER;
8544   l_split_from_line_id  NUMBER;
8545   --
8546   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8547   --
8548 BEGIN
8549 
8550   IF l_debug_level > 0 THEN
8551     OE_Debug_Pub.Add
8552     ('entering Get_Config_Effective_Date '|| p_model_line_id, 3);
8553   END IF;
8554 
8555   IF p_model_line_rec.header_id is not NULL THEN
8556 
8557     l_header_id          := p_model_line_rec.header_id;
8558 
8559     OE_Debug_Pub.Add('model header id '|| p_model_line_rec.header_id, 3);
8560     OE_Debug_Pub.Add('split id '|| p_model_line_rec.split_from_line_id, 3);
8561     OE_Debug_Pub.Add('line id '|| p_model_line_rec.line_id, 3);
8562 
8563     IF p_model_line_rec.split_from_line_id is NOT NULL THEN
8564     BEGIN
8565       SELECT creation_date
8566       INTO   l_creation_date
8567       FROM   oe_order_lines
8568       WHERE  header_id = l_header_id
8569       AND    line_set_id = p_model_line_rec.line_set_id
8570       AND    split_from_line_id is NULL;
8571     EXCEPTION
8572     -- Begin of Bug Fix 11848700
8573     WHEN NO_DATA_FOUND THEN
8574       BEGIN
8575         IF l_debug_level > 0 THEN
8576 	      OE_Debug_Pub.Add('Getting the data from history for  '|| p_model_line_rec.split_from_line_id, 3);
8577 	END IF;
8578         SELECT creation_date
8579         INTO   l_creation_date
8580         FROM   oe_order_lines_history
8581         WHERE  header_id = l_header_id
8582         AND    line_set_id = p_model_line_rec.line_set_id
8583         AND    split_from_line_id is NULL
8584         AND    ROWNUM = 1;
8585       EXCEPTION
8586       WHEN NO_DATA_FOUND THEN
8587 	l_creation_date := p_model_line_rec.creation_date;
8588       END;
8589      -- End of Bug Fix 11848700
8590     END;
8591 
8592 
8593       IF l_debug_level > 0 THEN
8594         OE_Debug_Pub.Add
8595         ('split '||p_model_line_rec.split_from_line_id||l_creation_date,3);
8596       END IF;
8597 
8598     ELSE
8599 
8600       IF p_model_line_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
8601 
8602         l_creation_date := sysdate;
8603         IF l_debug_level > 0 THEN
8604           OE_Debug_Pub.Add('model is getting created today', 3);
8605         END IF;
8606 
8607       ELSE
8608         l_creation_date := p_model_line_rec.creation_date;
8609       END IF;
8610 
8611     END IF; -- split model or not
8612 
8613   ELSIF p_model_line_id is not NULL THEN
8614 
8615     IF l_debug_level > 0 THEN
8616       OE_Debug_Pub.Add('using model line id '|| p_model_line_id, 3);
8617     END IF;
8618 
8619     SELECT header_id, creation_date,
8620            line_set_id, split_from_line_id
8621     INTO   l_header_id, l_creation_date,
8622            l_line_set_id, l_split_from_line_id
8623     FROM   oe_order_lines
8624     WHERE  line_id = p_model_line_id;
8625 
8626     IF l_split_from_line_id is NOT NULL THEN
8627     BEGIN
8628       SELECT creation_date
8629       INTO   l_creation_date
8630       FROM   oe_order_lines
8631       WHERE  header_id = l_header_id
8632       AND    line_set_id = l_line_set_id
8633       AND    split_from_line_id is NULL;
8634     EXCEPTION
8635       -- Begin of Bug Fix 11848700
8636       WHEN NO_DATA_FOUND THEN
8637 
8638 	BEGIN
8639           IF l_debug_level > 0 THEN
8640 	      OE_Debug_Pub.Add('Getting the data from history for  '|| l_split_from_line_id, 3);
8641           END IF;
8642 	  SELECT creation_date
8643           INTO   l_creation_date
8644           FROM   oe_order_lines_history
8645           WHERE  header_id = l_header_id
8646           AND    line_set_id = l_line_set_id
8647           AND    split_from_line_id is NULL
8648           AND    ROWNUM = 1;
8649         EXCEPTION
8650         WHEN NO_DATA_FOUND THEN
8651 	  null;
8652         END;
8653         -- End of Bug Fix 11848700
8654     END;
8655 
8656 
8657       IF l_debug_level > 0 THEN
8658         OE_Debug_Pub.Add
8659         ('split case '|| l_split_from_line_id || l_creation_date, 3);
8660       END IF;
8661     END IF;
8662 
8663   ELSE
8664 
8665     IF l_debug_level > 0 THEN
8666       OE_Debug_Pub.Add('something wrong in i/p'|| p_model_line_id, 3);
8667     END IF;
8668 
8669     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8670 
8671   END IF; -- if model rec was sent in
8672 
8673 
8674   IF OE_CODE_CONTROL.get_code_release_level >= '110510' THEN
8675 
8676     l_profile := nvl(OE_Sys_Parameters.VALUE('ONT_CONFIG_EFFECTIVITY_DATE'),
8677                      '1');
8678 
8679     IF l_debug_level  > 0 THEN
8680       oe_debug_pub.add('pack J code '||l_profile, 1);
8681     END IF;
8682 
8683   ELSE
8684 
8685     l_profile := nvl(FND_PROFILE.Value('ONT_CONFIG_EFFECTIVITY_DATE'), '1');
8686 
8687     IF l_profile > 1 THEN
8688 
8689       IF OE_Process_Options_Pvt.Use_Configurator THEN
8690         IF l_debug_level  > 0 THEN
8691           oe_debug_pub.add('USE CONFIGURATOR, ct fix' , 1);
8692         END IF;
8693       ELSE
8694         l_profile := 1;
8695 
8696       END IF;
8697 
8698     END IF;
8699   END IF; -- decide l_profile value
8700 
8701 
8702   IF  l_profile = '1' THEN
8703     x_old_behavior          := 'Y';
8704     x_config_effective_date := l_creation_date;
8705     x_frozen_model_bill     := 'Y';
8706 
8707   ELSIF  l_profile = '2' THEN
8708     x_old_behavior          := 'N';
8709     x_config_effective_date := l_creation_date;
8710     x_frozen_model_bill     := 'Y';
8711 
8712     IF l_debug_level > 0 THEN
8713       OE_Debug_Pub.Add('creation date is effective date', 3);
8714     END IF;
8715 
8716   ELSIF l_profile = '3' THEN
8717 
8718     x_old_behavior          := 'N';
8719 
8720     SELECT nvl(booked_flag, 'N'), booked_date
8721     INTO   x_frozen_model_bill, x_config_effective_date
8722     FROM   oe_order_headers
8723     WHERE  header_id = l_header_id;
8724 
8725     IF l_debug_level > 0 THEN
8726       OE_Debug_Pub.Add('booked, frozen: ' || x_frozen_model_bill, 3);
8727     END IF;
8728 
8729     IF x_frozen_model_bill = 'Y' THEN
8730       IF l_creation_date > x_config_effective_date THEN   --bug5969409
8731         x_config_effective_date := l_creation_date;
8732       ELSE
8733         l_header_id := sysdate - x_config_effective_date;
8734 
8735        IF l_header_id < 0.007 THEN -- some 10 min right now***
8736          IF l_debug_level > 0 THEN
8737           OE_Debug_Pub.Add('not frozen, as booked now? '||l_header_id , 3);
8738          END IF;
8739          x_frozen_model_bill := 'N';
8740        END IF;
8741       END IF;
8742     ELSE
8743 
8744       IF l_debug_level > 0 THEN
8745         OE_Debug_Pub.Add('not frozen, not booked', 3);
8746       END IF;
8747       x_config_effective_date := sysdate;
8748     END IF;
8749     -- Added for ER#6187663 Start
8750   ELSIF l_profile = '4' THEN  --ER#6187663: for OM:Configuration Effective Date='System Date till Pick Release'
8751     x_old_behavior          := 'N';
8752     x_config_effective_date := sysdate;
8753     /* x_frozen_model_bill='Y' if SO Booked  eles N*/
8754     SELECT nvl(booked_flag, 'N')    INTO   x_frozen_model_bill
8755     FROM   oe_order_headers
8756     WHERE  header_id = l_header_id;
8757 
8758     -- Added for ER#6187663 Start
8759 
8760   ELSE
8761     IF l_debug_level > 0 THEN
8762       OE_Debug_Pub.Add('something wrong???', 3);
8763     END IF;
8764   END IF;
8765 
8766   IF l_debug_level > 0 THEN
8767     OE_Debug_Pub.Add
8768     ('leaving Get_Config_Effective_Date '||
8769       to_char(x_config_effective_date, 'DD-MON-YY HH24:MI:SS'), 3);
8770     OE_Debug_Pub.Add('sysdate '||to_char(sysdate, 'DD-MON-YY HH24:MI:SS'),3);
8771     OE_Debug_Pub.Add(x_frozen_model_bill  || '-'|| x_old_behavior, 3);
8772   END IF;
8773 
8774 EXCEPTION
8775   WHEN OTHERS THEN
8776     IF l_debug_level > 0 THEN
8777       OE_Debug_Pub.Add('Get_Config_Effective_Date '|| sqlerrm, 1);
8778     END IF;
8779 
8780     x_config_effective_date := null;
8781     x_frozen_model_bill     := null;
8782     x_old_behavior          := null;
8783 
8784     RAISE;
8785 
8786 END Get_Config_Effective_Date;
8787 
8788 
8789 /*--------------------------------------------------------
8790 PROCEDURE Print_Time
8791 
8792 --------------------------------------------------------*/
8793 
8794 PROCEDURE Print_Time(p_msg   IN  VARCHAR2)
8795 IS
8796   l_time    VARCHAR2(100);
8797   --
8798   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8799   --
8800 BEGIN
8801   l_time := to_char (new_time (sysdate, 'PST', 'EST'),
8802                                  'DD-MON-YY HH24:MI:SS');
8803   IF l_debug_level  > 0 THEN
8804     oe_debug_pub.add(P_MSG || ': '|| L_TIME , 1);
8805   END IF;
8806 END Print_Time;
8807 
8808 /*--------------------------------------------------------
8809 PROCEDURE Unlock_Config
8810 
8811 This API will be called before deleting or cacelling booked macd model.
8812 --------------------------------------------------------*/
8813 
8814 PROCEDURE  Unlock_Config(p_line_rec  IN OE_ORDER_PUB.line_rec_type,
8815                          x_return_status OUT NOCOPY VARCHAR2 )
8816 IS
8817 
8818   l_top_container       VARCHAR2(1);
8819   l_part_of_container   VARCHAR2(1);
8820   l_locking_key         NUMBER;
8821   l_msg_count           NUMBER;
8822   l_msg_data            VARCHAR2(4000);
8823   l_return_status       VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
8824   l_order_number        NUMBER;
8825 
8826   --
8827   l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
8828   --
8829 BEGIN
8830 
8831        IF l_debug_level  > 0 THEN
8832          oe_debug_pub.add('ENTERING OE_CONFIG_UTIL.Unlock_Config' , 1);
8833        END IF;
8834 
8835 
8836        OE_CONFIG_TSO_PVT.Is_Part_Of_Container_Model
8837        (  p_line_id             => p_line_rec.line_id
8838          ,p_top_model_line_id   => p_line_rec.line_id
8839          ,x_top_container_model => l_top_container
8840          ,x_part_of_container   => l_part_of_container  );
8841        IF l_top_container = 'Y' THEN
8842 
8843           l_order_number := OE_SCHEDULE_UTIL.get_order_number(p_line_rec.header_id);
8844 
8845           IF l_debug_level  > 0 THEN
8846 
8847             oe_debug_pub.add(' Calling Unlock_Config' || p_line_rec.config_header_id,  2);
8848             oe_debug_pub.add(' Config rev nbr' || p_line_rec.config_rev_nbr,  2);
8849             oe_debug_pub.add(' Configuration_id ' || p_line_rec.configuration_id,  2);
8850             oe_debug_pub.add(' order_number  ' || l_order_number,  2);
8851 
8852           END IF;
8853 
8854           CZ_IB_LOCKING.Unlock_Config
8855           ( p_api_version            => 1.0,
8856             p_config_session_hdr_id  => p_line_rec.config_header_id,
8857             p_config_session_rev_nbr => p_line_rec.config_rev_nbr,
8858             p_config_session_item_id => null,
8859             p_source_application_id  => fnd_profile.value('RESP_APPL_ID'),
8860             p_source_header_ref      => l_order_number,
8861             p_source_line_ref1       => Null,
8862             p_source_line_ref2       => Null,
8863             p_source_line_ref3       => Null,
8864             p_commit                 => 'N',
8865             p_init_msg_list          => FND_API.G_TRUE,
8866             p_validation_level       => Null,
8867             p_locking_key            => Null,
8868             x_return_status          => x_return_status,
8869             x_msg_count              => l_msg_count,
8870             x_msg_data               => l_msg_data);
8871 
8872             IF l_debug_level  > 0 THEN
8873 
8874               oe_debug_pub.add(' After calling CZ Unlock_Config ' || x_return_status,2);
8875             END IF;
8876 
8877             IF l_msg_count > 0 THEN
8878 
8879                OE_MSG_PUB.Transfer_Msg_Stack;
8880 
8881             END IF;
8882 
8883 
8884        END IF;
8885 
8886        IF l_debug_level  > 0 THEN
8887          oe_debug_pub.add('Exiting  OE_CONFIG_UTIL.Unlock_Config'  || x_return_status, 1);
8888        END IF;
8889 
8890 EXCEPTION
8891 
8892   WHEN OTHERS THEN
8893     IF l_debug_level  > 0 THEN
8894       oe_debug_pub.add('ERROR IN OE_CONFIG_UTIL.Unlock_Config'|| SQLERRM , 1);
8895     END IF;
8896     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8897 END Unlock_Config;
8898 
8899 -- Added for DOO Pre Exploded Kit ER 9339742
8900 PROCEDURE Process_Pre_Exploded_Kits
8901 ( p_top_model_line_id IN  NUMBER
8902 , p_explosion_date    IN  DATE
8903 -- p_top_model_line_id : has the Line_id of the top most parent in the Kit or PTO
8904 -- p_explosion_date : has little significance in the processing because we just
8905 --                  get this field from DOO so as to set the pre_exploded_flag value.
8906 , x_return_status     OUT NOCOPY VARCHAR2
8907 ) IS
8908 --
8909   l_return_status             VARCHAR2(30) := FND_API.G_RET_STS_SUCCESS;
8910   l_cursor_query              VARCHAR2(4000);
8911   l_parent_line_rec           OE_Order_PUB.Line_Rec_Type;
8912   l_included_item_tbl         OE_Order_PUB.Line_Tbl_Type;
8913   l_included_item_rec         OE_Order_PUB.Line_Rec_Type;
8914   l_explosion_date            DATE;
8915   l_validation_org            NUMBER;
8916   l_item_check                BOOLEAN := FALSE;
8917   l_validation_status         BOOLEAN := FALSE;
8918   l_component_number          NUMBER := 0;
8919   l_parent_component_sequence_id NUMBER;
8920   l_msg_count                 NUMBER;
8921   l_msg_data                  VARCHAR2(4000);
8922   l_error_code                NUMBER;
8923   l_temp_line_id              NUMBER;
8924   l_line_id                   NUMBER;
8925   l_comp_line_id              NUMBER;
8926   l_inventory_item_id         NUMBER;
8927   l_included_item_line_id     NUMBER;
8928   x                           NUMBER := 0;
8929   y                           NUMBER := 0;
8930 --
8931   -- Bom_Explosion_Rec record structure is created to store the values of each
8932   -- parent/sub-parent model information from EBS BOM based on parent
8933   -- Bill_Seq_id. It has two more fields: the OM's corresponding line_id of
8934   -- that immediate parent and its inventory item id, which is used later,
8935   -- after validating the DOO BOM with EBS BOM, to populate the reference
8936   -- information on OM tables i.e. Link_To_Line_id and Component_Code validation
8937   -- for each INCLUDED items in the BOM definition
8938   --
8939   TYPE Bom_Explosion_Rec IS RECORD
8940   ( component_item_id     bom_explosions.component_item_id%TYPE
8941   , component_sequence_id bom_explosions.component_sequence_id%TYPE
8942   , extended_quantity     bom_explosions.extended_quantity%TYPE
8943   , component_code        bom_explosions.component_code%TYPE
8944   , PRIMARY_UOM_CODE      bom_explosions.PRIMARY_UOM_CODE%TYPE
8945   , sort_order            bom_explosions.sort_order%TYPE
8946   , OM_Parent_Line_id     oe_order_lines_all.line_id%TYPE
8947   , OM_Parent_Inventory_Item_id    oe_order_lines_all.Inventory_Item_id%TYPE
8948   );
8949 
8950 
8951   CURSOR C_PreExploded_Kit (c_top_model_line_id IN NUMBER) IS
8952    SELECT line_id FROM oe_order_lines_all
8953    WHERE item_type_code = OE_GLOBALS.G_ITEM_INCLUDED
8954    AND top_model_line_id = c_top_model_line_id
8955    AND top_model_line_id <> line_id;
8956 
8957   CURSOR C_Bom_Explosion_Info (p_top_bill_sequence_id IN NUMBER,
8958                                p_std_comp_freeze_date IN DATE)
8959   IS
8960    SELECT
8961       component_item_id,
8962       component_sequence_id,
8963       extended_quantity,
8964       component_code,
8965       PRIMARY_UOM_CODE,
8966       sort_order,
8967       null OM_Parent_Line_id,
8968       null OM_Parent_Inventory_Item_id
8969       -- To OM fields, setting the NULL values so as to complete the record structure
8970    FROM bom_explosions  be
8971    WHERE
8972       be.explosion_type = OE_GLOBALS.G_ITEM_INCLUDED --'INCLUDED'
8973       AND be.plan_level >= 0
8974       AND be.extended_quantity > 0
8975       AND be.TOP_BILL_SEQUENCE_ID = p_top_bill_sequence_id
8976       AND be.EFFECTIVITY_DATE <= p_std_comp_freeze_date
8977       AND be.DISABLE_DATE > p_std_comp_freeze_date
8978       AND be.COMPONENT_ITEM_ID <> be.TOP_ITEM_ID
8979    ORDER BY sort_order; -- Here the sort_order is performing a very important
8980    -- task. It is helping to get the right order of the components in a given model
8981    -- which is used to refer the same on OM base tables based on data from DOO BOM and
8982    -- hence processing it in the same sequence.
8983 
8984   l_Bom_Explosion_Rec Bom_Explosion_Rec;
8985   TYPE Bom_Explosion_Tbl IS TABLE OF Bom_Explosion_Rec INDEX BY BINARY_INTEGER;
8986   l_Bom_Explosion_Tbl Bom_Explosion_Tbl;
8987 
8988   -- C_Bill_Seq_id gives the Bill_Seq_id for each parent/sub-parent along with
8989   -- its corresponding Line_id and Inventory_Item_id from OM tables, which later
8990   -- get sets to Bom_Explosion_Rec
8991   CURSOR C_Bill_Seq_id ( p_top_model_line_id IN NUMBER, p_header_id IN NUMBER
8992                        , p_validation_org IN NUMBER) IS
8993     SELECT bom.bill_sequence_id, oel.line_id, oel.inventory_item_id
8994     FROM   bom_bill_of_materials bom, oe_order_lines_all oel
8995     WHERE  bom.ASSEMBLY_ITEM_ID = oel.inventory_item_id
8996     AND    oel.top_model_line_id = p_top_model_line_id
8997     AND    oel.header_id = p_header_id
8998     AND    oel.item_type_code in (OE_GLOBALS.G_ITEM_CLASS,OE_GLOBALS.G_ITEM_KIT,OE_GLOBALS.G_ITEM_MODEL)
8999     AND    bom.ORGANIZATION_ID = p_validation_org
9000     AND    bom.ALTERNATE_BOM_DESIGNATOR IS NULL;
9001 
9002   -- comp_number is used to set the Component_Number column on OE_Order_Lines_All
9003   -- table for all the INCLUDED item components inside its given immediate parent
9004   CURSOR comp_number (c_parent_line_id IN NUMBER, c_top_model_line_id IN NUMBER, c_header_id IN NUMBER) IS
9005    SELECT line_id
9006    FROM   oe_order_lines_all
9007    WHERE  link_to_line_id    = c_parent_line_id
9008    AND    top_model_line_id  = c_top_model_line_id
9009    AND    header_id          = c_header_id
9010    AND    item_type_code     = OE_GLOBALS.G_ITEM_INCLUDED;
9011 --
9012   l_debug_level   CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9013 --
9014 BEGIN
9015 
9016   if l_debug_level > 0 then
9017     oe_debug_pub.add(' Entering OE_Config_Util.Process_Pre_Exploded_Kits',1);
9018   end if;
9019 
9020   x_return_status := l_return_status;
9021 
9022   -- Getting the complete record structure for the top model parent line
9023   -- and Locking it at the same time
9024   OE_LINE_UTIL.Lock_Row
9025      (p_line_id       => p_top_model_line_id
9026      ,p_x_line_rec    => l_parent_line_rec
9027      ,x_return_status => l_return_status);
9028 
9029   if l_debug_level > 0 then
9030     oe_debug_pub.add(' Parent Line is Locked and Queried',5);
9031   end if;
9032 
9033   -- A top model parent line can either be a MODEL in a case of PTO or KIT
9034   -- in case of Kits. It cannot have any other values. If it is then no
9035   -- processing is required. RETURN from the code.
9036   IF l_parent_line_rec.item_type_code Not IN (OE_GLOBALS.G_ITEM_MODEL,OE_GLOBALS.G_ITEM_KIT)
9037      OR l_parent_line_rec.ordered_quantity = 0
9038   -- OR l_parent_line_rec.explosion_date is null
9039   THEN
9040     if l_debug_level  > 0 then
9041       oe_debug_pub.add(' The parent line is not a Kit, Kit in a Class, or Qty is 0. RETURN...',1);
9042     end if;
9043     RETURN;
9044   END IF;
9045 
9046   OPEN C_PreExploded_Kit (l_parent_line_rec.top_model_line_id);
9047   IF C_PreExploded_Kit%ISOPEN THEN
9048     LOOP
9049       FETCH C_PreExploded_Kit INTO l_included_item_line_id;
9050       EXIT WHEN C_PreExploded_Kit%NOTFOUND;
9051         y := y + 1;
9052         OE_LINE_UTIL.Query_Row
9053         ( p_line_id       => l_included_item_line_id
9054         , x_line_rec      => l_included_item_rec);
9055         l_included_item_tbl(y) := l_included_item_rec;
9056     END LOOP;
9057   END IF;
9058   CLOSE C_PreExploded_Kit;
9059 
9060   if l_debug_level > 0 then
9061     oe_debug_pub.add(' Count of Included Items under Kit : '||l_included_item_tbl.COUNT,5);
9062   end if;
9063 
9064   l_explosion_date := SYSDATE;
9065   l_validation_org := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
9066 
9067   Explode( p_validation_org => l_validation_org,
9068            p_levels         => 6, --??
9069            p_stdcompflag    => OE_BMX_STD_COMPS_ONLY,
9070            p_top_item_id    => l_parent_line_rec.inventory_item_id,
9071            p_revdate        => l_explosion_date,
9072            x_msg_data       => l_msg_data,
9073            x_error_code     => l_error_code,
9074            x_return_status  => l_return_status);
9075 
9076   if l_debug_level > 0 then
9077     oe_debug_pub.add(' Return Status from BOM Explosion API is : '||l_return_status,1);
9078   end if;
9079 
9080   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
9081     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9082   ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
9083     RAISE FND_API.G_EXC_ERROR;
9084   END IF;
9085 
9086   OPEN C_Bill_Seq_id ( l_parent_line_rec.top_model_line_id,
9087                        l_parent_line_rec.header_id,
9088                        l_validation_org);
9089   IF C_Bill_Seq_id%ISOPEN THEN
9090     LOOP
9091       FETCH C_Bill_Seq_id INTO l_parent_component_sequence_id, l_line_id, l_inventory_item_id;
9092       EXIT WHEN C_Bill_Seq_id%NOTFOUND;
9093 
9094       if l_debug_level > 0 then
9095         oe_debug_pub.add(' Get BOM for parent Seq id = '||l_parent_component_sequence_id,5);
9096       end if;
9097       OPEN C_Bom_Explosion_Info (l_parent_component_sequence_id, l_explosion_date);
9098         IF C_Bom_Explosion_Info%ISOPEN THEN
9099           LOOP
9100             FETCH C_Bom_Explosion_Info INTO l_Bom_Explosion_Rec;
9101             EXIT WHEN C_Bom_Explosion_Info%NOTFOUND;
9102             x := x + 1;
9103             l_Bom_Explosion_Tbl(x) := l_Bom_Explosion_Rec;
9104             l_Bom_Explosion_Tbl(x).OM_Parent_Line_id := l_line_id;
9105             l_Bom_Explosion_Tbl(x).OM_Parent_Inventory_Item_id := l_inventory_item_id;
9106           END LOOP;
9107         END IF;
9108       CLOSE C_Bom_Explosion_Info;
9109     END LOOP;
9110   END IF;
9111   CLOSE C_Bill_Seq_id;
9112 
9113   if l_debug_level > 0 then
9114     oe_debug_pub.add(' Validating BOM definition between DOO and EBS',5);
9115     oe_debug_pub.add(' ---------------------------------------------',5);
9116     oe_debug_pub.add(' EBS OM Information from DOO -',5);
9117     oe_debug_pub.add(' Count of Included Items : '||l_included_item_tbl.count,5);
9118     IF l_included_item_tbl.COUNT > 0 THEN -- Bug 14172135
9119     for i in l_included_item_tbl.first .. l_included_item_tbl.last loop
9120       oe_debug_pub.add(' Line_id : '||l_included_item_tbl(i).line_id,5);
9121       oe_debug_pub.add(' Inventory Item id : '||l_included_item_tbl(i).inventory_item_id,5);
9122       oe_debug_pub.add(' Ordered Quantity UOM : '||l_included_item_tbl(i).order_quantity_uom,5);
9123       oe_debug_pub.add(' Ord Qty Ratio : '||l_included_item_tbl(i).ordered_quantity/l_parent_line_rec.ordered_quantity,5);
9124     end loop;
9125     END IF;
9126 
9127     oe_debug_pub.add(' EBS BOM Information -',5);
9128     oe_debug_pub.add(' Count of Included Items : '||l_Bom_Explosion_Tbl.count,5);
9129     IF l_Bom_Explosion_Tbl.COUNT > 0 THEN -- Bug 14172135
9130     for i in l_Bom_Explosion_Tbl.first .. l_Bom_Explosion_Tbl.last loop
9131       oe_debug_pub.add(' Inventory Item id : '||l_Bom_Explosion_Tbl(i).component_item_id,5);
9132       oe_debug_pub.add(' BOM Quantity UOM : '||l_Bom_Explosion_Tbl(i).primary_uom_code,5);
9133       oe_debug_pub.add(' Quantity Ratio : '||l_Bom_Explosion_Tbl(i).extended_quantity,5);
9134     end loop;
9135     END IF;
9136   end if;
9137 
9138   -- The DOO BOM and EBS BOM Validation Start
9139   -------------------------------------------
9140   --
9141   -- Note: It may be possible that DOO BOM pass invalid association
9142   -- between the Model, Class, Option Items, or Included Items via
9143   -- wrong Link_To_Line_Index. However, since the assumtion is: DOO
9144   -- BOM and EBS BOM will be always in sync, we are safe to assume
9145   -- it to be always same. Considering this factor, the below code
9146   -- is designed in such a manner that even with wrong Link_To_Line_index
9147   -- values, system will create a successful BOM in EBS with all the
9148   -- links correctly established. We are not validating this because
9149   -- if we happen to do it then we are contracting the assumption we
9150   -- have taken above, without which, there may be tens of many more
9151   -- required validation to be considered but we are safely ignoring
9152   -- them.
9153   --
9154   -- Validating if the EBS BOM definition in BOM_Explosions table
9155   -- and BOM information passed by DOO in OE_order_Lines_All table is same
9156   IF l_included_item_tbl.COUNT <> l_Bom_Explosion_Tbl.COUNT THEN
9157     if l_debug_level > 0 then
9158       oe_debug_pub.add(' The count of Included Items are not same',5);
9159     end if;
9160     l_return_status := FND_API.G_RET_STS_ERROR;
9161     FND_MESSAGE.Set_Name('ONT', 'OE_DOO_INVALID_BOM');
9162     oe_msg_pub.add;
9163     RAISE FND_API.G_EXC_ERROR;
9164   END IF;
9165 
9166   IF l_Bom_Explosion_Tbl.COUNT > 0 THEN
9167     FOR j IN l_Bom_Explosion_Tbl.FIRST .. l_Bom_Explosion_Tbl.LAST LOOP
9168       IF l_included_item_tbl.COUNT > 0 THEN
9169         FOR i IN l_included_item_tbl.FIRST .. l_included_item_tbl.LAST LOOP
9170 
9171           l_validation_status := FALSE;
9172 
9173           -- Inventory Item Check
9174           -- There is an assumption from DOO that a BOM definition
9175           -- will have every Inventory Item unique
9176           l_item_check := FALSE;
9177           IF l_included_item_tbl(i).inventory_item_id = l_Bom_Explosion_Tbl(j).component_item_id THEN
9178 
9179             l_item_check := TRUE;
9180             l_validation_status := TRUE;
9181 
9182             if l_debug_level > 0 then
9183               oe_debug_pub.add(' Inventory Item id is matching'||l_included_item_tbl(i).inventory_item_id,5);
9184             end if;
9185 
9186             -- Ordered Quantity Ratio Check
9187             IF l_included_item_tbl(i).ordered_quantity/l_parent_line_rec.ordered_quantity =
9188                       l_Bom_Explosion_Tbl(j).extended_quantity THEN
9189               if l_debug_level > 0 then
9190                 oe_debug_pub.add(' Quantity is in ratio : '||l_Bom_Explosion_Tbl(j).extended_quantity,5);
9191               end if;
9192             ELSE
9193               if l_debug_level > 0 then
9194                 oe_debug_pub.add(' Quantity is NOT in ratio',1);
9195               end if;
9196               l_validation_status := FALSE;
9197               l_return_status := FND_API.G_RET_STS_ERROR;
9198               FND_MESSAGE.Set_Name('ONT', 'OE_DOO_INVALID_QTY_RATIO');
9199               oe_msg_pub.add;
9200             END IF;
9201 
9202             -- Ordered Quantity UOM Check
9203             -- There is an assumption from DOO that DOO UOM, EBS OM UOM
9204             -- and EBS BOM UOM will be same
9205             IF l_included_item_tbl(i).order_quantity_uom = l_Bom_Explosion_Tbl(j).primary_uom_code THEN
9206               if l_debug_level > 0 then
9207                 oe_debug_pub.add(' Quantity UOM is matching : '||l_Bom_Explosion_Tbl(j).primary_uom_code,5);
9208               end if;
9209             ELSE
9210               if l_debug_level > 0 then
9211                 oe_debug_pub.add(' Quantity UOM is NOT matching : '||l_Bom_Explosion_Tbl(j).primary_uom_code,5);
9212               end if;
9213               l_validation_status := FALSE;
9214               l_return_status := FND_API.G_RET_STS_ERROR;
9215               FND_MESSAGE.Set_Name('ONT', 'OE_DOO_INVALID_UOM');
9216               oe_msg_pub.add;
9217             END IF;
9218 
9219             IF l_validation_status THEN
9220               if l_debug_level > 0 then
9221                 oe_debug_pub.add(' Setting the BOM data in OM for Line : '||l_included_item_tbl(i).line_id,5);
9222               end if;
9223 
9224               UPDATE OE_order_Lines_All
9225               SET    Component_Sequence_id = l_Bom_Explosion_Tbl(j).component_sequence_id
9226                    , Sort_Order = l_Bom_Explosion_Tbl(j).sort_order
9227                    , Component_Code = l_Bom_Explosion_Tbl(j).component_code
9228                    , Explosion_Date = l_explosion_date
9229                    , Link_To_Line_id = l_Bom_Explosion_Tbl(j).OM_Parent_Line_id
9230                    , lock_control = lock_control + 1
9231               WHERE  Line_id = l_included_item_tbl(i).line_id;
9232 
9233               l_included_item_tbl(i).Component_Sequence_id := l_Bom_Explosion_Tbl(j).component_sequence_id;
9234               l_included_item_tbl(i).Sort_Order            := l_Bom_Explosion_Tbl(j).sort_order;
9235               l_included_item_tbl(i).Component_Code        := l_Bom_Explosion_Tbl(j).component_code;
9236               l_included_item_tbl(i).Explosion_Date        := l_explosion_date;
9237               l_included_item_tbl(i).Link_To_Line_id       := l_Bom_Explosion_Tbl(j).OM_Parent_Line_id;
9238 
9239               IF l_included_item_tbl(i).component_code <> (l_Bom_Explosion_Tbl(j).OM_Parent_Inventory_Item_id||'-'||l_included_item_tbl(i).inventory_item_id) THEN
9240                 if l_debug_level > 0 then
9241                   oe_debug_pub.add(' Invalid Association between the Included Item and its immediate parent',1);
9242                 end if;
9243                 l_return_status := FND_API.G_RET_STS_ERROR;
9244                 FND_MESSAGE.Set_Name('ONT', 'OE_DOO_INVALID_BOM');
9245                 oe_msg_pub.add;
9246                 RAISE FND_API.G_EXC_ERROR;
9247               END IF;
9248 
9249               -- Since there is a valid match found and updated
9250               -- on the OM order line, Exit the child Loop
9251               EXIT;
9252 
9253             END IF;
9254 
9255           END IF; -- l_included_item_tbl(i).inventory_item_id
9256         END LOOP;
9257 
9258         IF NOT(l_item_check) THEN
9259           if l_debug_level > 0 then
9260             oe_debug_pub.add(' Inventory Item Mismatch : '||l_Bom_Explosion_Tbl(j).component_item_id,1);
9261           end if;
9262           l_validation_status := FALSE;
9263           l_return_status := FND_API.G_RET_STS_ERROR;
9264           FND_MESSAGE.Set_Name('ONT', 'OE_DOO_INVALID_ITEM');
9265           oe_msg_pub.add;
9266         END IF;
9267 
9268         IF NOT(l_validation_status) THEN
9269           if l_debug_level > 0 then
9270             oe_debug_pub.add(' BOM Validation Failure',1);
9271           end if;
9272           l_return_status := FND_API.G_RET_STS_ERROR;
9273           FND_MESSAGE.Set_Name('ONT', 'OE_DOO_INVALID_BOM');
9274           oe_msg_pub.add;
9275           RAISE FND_API.G_EXC_ERROR;
9276         END IF;
9277 
9278       ELSE
9279         if l_debug_level > 0 then
9280           oe_debug_pub.add(' There are no Included Items from BOM Explosion',5);
9281         end if;
9282       END IF; -- l_included_item_tbl
9283     END LOOP;
9284   END IF; -- l_Bom_Explosion_Tbl
9285 
9286   IF l_Bom_Explosion_Tbl.COUNT > 0 THEN
9287     FOR j IN l_Bom_Explosion_Tbl.FIRST .. l_Bom_Explosion_Tbl.LAST LOOP
9288       OPEN  comp_number ( l_Bom_Explosion_Tbl(j).OM_Parent_Line_id
9289                         , l_parent_line_rec.top_model_line_id
9290                         , l_parent_line_rec.header_id);
9291       LOOP
9292         FETCH comp_number INTO l_comp_line_id;
9293         EXIT WHEN comp_number%NOTFOUND;
9294 
9295         l_component_number := l_component_number + 1;
9296 
9297         UPDATE oe_order_lines
9298         SET    component_number = l_component_number,
9299                lock_control     = lock_control + 1
9300         WHERE  line_id = l_comp_line_id;
9301 
9302       END LOOP;
9303       CLOSE comp_number;
9304       l_component_number := 0;
9305     END LOOP;
9306   END IF;
9307 
9308   UPDATE OE_order_Lines_All
9309   SET    Explosion_Date = l_explosion_date
9310        , lock_control = lock_control + 1
9311   WHERE  Line_id = l_parent_line_rec.line_id;
9312 
9313   x_return_status := l_return_status;
9314 
9315   if l_debug_level > 0 then
9316     oe_debug_pub.add(' Exiting OE_Config_Util.Process_Pre_Exploded_Kits',1);
9317   end if;
9318 
9319 EXCEPTION
9320   WHEN FND_API.G_EXC_ERROR THEN
9321     x_return_status := FND_API.G_RET_STS_ERROR;
9322   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9323     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9324   WHEN OTHERS THEN
9325     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9326     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
9327       OE_MSG_PUB.Add_Exc_Msg
9328       ( G_PKG_NAME
9329       , 'Process_Pre_Exploded_Kits'
9330       );
9331     END IF;
9332 END Process_Pre_Exploded_Kits;
9333 
9334 END OE_CONFIG_UTIL;