DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_ORDER_ADJ_PVT

Source


1 PACKAGE BODY oe_order_adj_pvt AS
2 /* $Header: OEXVADJB.pls 120.27.12020000.5 2013/01/07 15:41:26 sujithku ship $ */
3 
4 G_DEBUG BOOLEAN;
5 G_Pricing_Phase_Id_Tbl Char_Tbl_Type;
6 G_11iG_PERFORMANCE varchar2(1)
7       := nvl(fnd_profile.value('ONT_11IG_PERFORMANCE'),'Y');
8 G_CHARGES_FOR_INCLUDED_ITEM Varchar2(1) := nvl(fnd_profile.value('ONT_CHARGES_FOR_INCLUDED_ITEM'),'N');
9 G_REQUEST_ID NUMBER:=NULL;
10 G_ORDER_CURRENCY VARCHAR2(30);
11 G_IPL_ERRORS_TBL Index_Tbl_Type;
12 G_BINARY_LIMIT CONSTANT NUMBER := OE_GLOBALS.G_BINARY_LIMIT; -- Added for bug 8631297
13 
14 
15 procedure Adj_Debug (p_text IN VARCHAR2, p_dummy IN NUMBER:=0) As
16 Begin
17   If G_DEBUG Then
18      oe_debug_pub.add(p_text,3);
19   End If;
20 End;
21 
22 --btea perf end
23 
24 
25 Function get_version Return Varchar2 is
26 Begin
27 
28  Return('/* $Header: OEXVADJB.pls 120.27.12020000.5 2013/01/07 15:41:26 sujithku ship $ */');
29 
30 End;
31 
32 -- BLANKETS: Start Code Merge, Local Functions
33 
34 Function Get_List_Type (p_price_list_id in number)
35 Return VARCHAR2
36 IS
37 l_list_type             VARCHAR2(30);
38 Begin
39 
40    SELECT list_type_code
41      INTO l_list_type
42      FROM QP_LIST_HEADERS
43     WHERE LIST_HEADER_ID = p_price_list_id;
44 
45   RETURN l_list_type;
46 
47 Exception
48   WHEN OTHERS THEN
49     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
50     THEN
51        OE_MSG_PUB.Add_Exc_Msg
52            (   G_PKG_NAME
53             ,   'Get_List_Type'
54            );
55     END IF;
56     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
57 End Get_List_Type;
58 
59 Function Get_Enforce_Price_List
60        (p_blanket_number in number
61         ,p_blanket_line_number in number)
62 Return VARCHAR2
63 IS
64 l_flag             VARCHAR2(1);
65 Begin
66 
67    SELECT enforce_price_list_flag
68      INTO l_flag
69      FROM OE_BLANKET_LINES_EXT E
70     WHERE E.ORDER_NUMBER = p_blanket_number
71       AND E.LINE_NUMBER = p_blanket_line_number;
72 
73   RETURN l_flag;
74 
75 Exception
76   WHEN OTHERS THEN
77     IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
78     THEN
79        OE_MSG_PUB.Add_Exc_Msg
80            (   G_PKG_NAME
81             ,   'Get_Enforce_Price_List'
82            );
83     END IF;
84     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
85 End Get_Enforce_Price_List;
86 
87 -- BLANKETS: End Code Merge, Local Functions
88 
89 
90 --As per discussion with AMY and RAVI
91 --If error occurs from pricing engine we need to look at pricing temp table
92 --copy the temp table unit selling price to the line
93 Procedure Reset_Fields(p_line_rec in Oe_Order_Pub.Line_Rec_Type)As
94 
95 Cursor get_price(p_line_id in Number) is
96 Select Unit_Price,
97        Adjusted_Unit_Price,
98        priced_quantity,
99        priced_uom_code
100 From   QP_PREQ_LINES_TMP
101 Where  Line_Id = p_line_id;
102 
103 Cursor c_line(p_line_id in Number) is
104 Select line_id,
105        blanket_number,
106        blanket_line_number,
107        unit_selling_price,
108        ordered_quantity,
109        order_quantity_uom,
110        inventory_item_id,
111        line_set_id,
112        fulfilled_flag,
113        header_id,
114        line_category_code,
115        commitment_id,
116        transaction_phase_code --for bug 3108881
117 From   OE_ORDER_LINES
118 Where  Line_Id = p_line_id;
119 
120 l_qp_unit_price          Number;
121 l_qp_adjusted_unit_price Number;
122 l_pricing_quantity       Number;
123 l_pricing_quantity_uom   Varchar2(15);
124 l_unit_price Number;
125 l_selling_price Number;
126 l_tax_value              Number;
127 
128 l_return_status          Varchar2(30);
129 --
130 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
131 --
132 
133 Begin
134   oe_debug_pub.add('Entering Reset Field:line_id:'||(p_line_rec.line_id));
135   open get_price(p_line_rec.line_id);
136   fetch get_price into l_qp_unit_price,
137                        l_qp_adjusted_unit_price,
138                        l_pricing_quantity,
139                        l_pricing_quantity_uom;
140   close get_price;
141 
142   If l_qp_adjusted_unit_price is not null OR
143      l_qp_unit_price is not null Then
144     If nvl(p_line_rec.ordered_quantity,0) <> 0 Then
145       If OE_CODE_CONTROL.Get_Code_Release_Level >= '110509' THEN
146         l_unit_price := Null;
147         l_selling_price := Null;
148         l_qp_unit_price := Null;
149         l_qp_adjusted_unit_price := Null;
150       else
151      l_unit_price :=
152       (l_qp_unit_price * p_line_rec.pricing_quantity)/ p_line_rec.ordered_quantity;
153      l_selling_price :=
154       (l_qp_adjusted_unit_price * p_line_rec.pricing_quantity)/ p_line_rec.ordered_quantity;
155       end if;
156     Else
157      l_unit_price := Null;
158      l_selling_price := Null;
159     End If;
160 
161   End If;
162 
163   -- Bug 2757443, need to set tax value accordingly if unit selling
164   -- price gets set to null.
165   IF l_selling_price is null THEN
166      l_tax_value := null;
167   ELSE
168      l_tax_value := p_line_rec.tax_value;
169   END IF;
170 
171   -- BUG 2746595 => if a valid price list is not found when currency is updated,
172   -- the price list and price is nulled out in this procedure. This should log
173   -- a request to update the total released amount on the blanket.
174   -- BLANKETS: log request to update blanket amounts if price changes
175   IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110509'
176   THEN
177 
178     FOR update_line IN c_line(p_line_rec.line_id) LOOP
179 
180       IF update_line.line_category_code = 'ORDER'
181          AND update_line.blanket_number IS NOT NULL
182       THEN
183 
184        IF l_debug_level > 0 THEN
185           oe_debug_pub.add('OEXVADJB log blanket request');
186           oe_debug_pub.add('old SP :'||update_line.unit_selling_price);
187           oe_debug_pub.add('new SP :'||l_selling_price);
188        END IF;
189 
190        OE_Order_Cache.Load_Order_Header(update_line.header_id);
191 --for bug 3108881.Log the request for Orders only
192        IF nvl(update_line.transaction_phase_code,'F') = 'F' THEN
193 
194 	       OE_Delayed_Requests_Pvt.Log_Request
195 	       (p_entity_code               => OE_GLOBALS.G_ENTITY_ALL
196       	 	,p_entity_id                 => update_line.line_id
197        		,p_requesting_entity_code    => OE_GLOBALS.G_ENTITY_LINE
198        		,p_requesting_entity_id      => update_line.line_id
199        		,p_request_type              => OE_GLOBALS.G_PROCESS_RELEASE
200        		-- Old values
201        		,p_param1                    => update_line.blanket_number
202        		,p_param2                    => update_line.blanket_line_number
203        		,p_param3                    => update_line.ordered_quantity
204        		,p_param4                    => update_line.order_quantity_uom
205        		,p_param5                    => update_line.unit_selling_price
206        		,p_param6                    => update_line.inventory_item_id
207        		-- New values
208        		,p_param11                   => update_line.blanket_number
209        		,p_param12                   => update_line.blanket_line_number
210        		,p_param13                   => update_line.ordered_quantity
211        		,p_param14                   => update_line.order_quantity_uom
212        		,p_param15                   => l_selling_price
213        		,p_param16                   => update_line.inventory_item_id
214        		-- Other parameters
215        		,p_param8                    => update_line.fulfilled_flag
216        		,p_param9                    => update_line.line_set_id
217        		,p_request_unique_key1       =>
218                         OE_Order_Cache.g_header_rec.transactional_curr_code
219        		,x_return_status             => l_return_status
220        		);
221 
222 		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
223         	   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
224        		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
225        		   RAISE FND_API.G_EXC_ERROR;
226        		END IF;
227 
228        		IF update_line.line_set_id IS NOT NULL THEN
229          		OE_Delayed_Requests_Pvt.Log_Request
230          		  (p_entity_code               => OE_GLOBALS.G_ENTITY_ALL
231          		  ,p_entity_id                 => update_line.line_set_id
232          		  ,p_requesting_entity_code    => OE_GLOBALS.G_ENTITY_LINE
233          		  ,p_requesting_entity_id      => update_line.line_id
234          		  ,p_request_type              => 'VALIDATE_RELEASE_SHIPMENTS'
235          		  ,p_request_unique_key1       => update_line.blanket_number
236          		  ,p_request_unique_key2       => update_line.blanket_line_number
237          		  ,p_param1                    =>
238                         	OE_Order_Cache.g_header_rec.transactional_curr_code
239          		  ,x_return_status             => l_return_status
240          		  );
241          		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
242               		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
243          	  	ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
244               	   	   RAISE FND_API.G_EXC_ERROR;
245            		END IF;
246        		END IF;
247 	END IF;--End of check for order/quote
248 
249       END IF; -- End of log blanket request for release order line
250 
251       -- bug 2757443.
252       IF update_line.commitment_id IS NOT NULL
253          AND OE_Commitment_Pvt.Do_Commitment_Sequencing THEN
254 
255            oe_debug_pub.add('Logging delayed request for Commitment.', 2);
256            OE_Delayed_Requests_Pvt.Log_Request(
257            p_entity_code                => OE_GLOBALS.G_ENTITY_LINE,
258            p_entity_id                  => update_line.line_id,
259            p_requesting_entity_code     => OE_GLOBALS.G_ENTITY_LINE,
260            p_requesting_entity_id       => update_line.line_id,
261            p_request_type               => OE_GLOBALS.G_CALCULATE_COMMITMENT,
262            x_return_status              => l_return_status);
263 
264       END IF;
265 
266 
267     END LOOP; -- End of loop to fetch line fields
268 
269   END IF; -- End of check for code release level
270 
271   Update Oe_Order_Lines
272   Set    Unit_Selling_Price= l_selling_price,
273          Unit_List_Price = l_unit_price,
274          unit_selling_price_per_pqty = l_qp_adjusted_unit_price,
275          unit_list_price_per_pqty = l_qp_unit_price,
276          pricing_quantity         = l_pricing_quantity,
277          pricing_quantity_uom     = l_pricing_quantity_uom,
278          tax_value                = l_tax_value,
279          lock_control             = lock_control +1
280   Where  Line_id = p_line_rec.line_id;
281 
282   --Delete all related adjustments
283   oe_line_adj_util.delete_row(p_line_id => p_line_rec.line_id);
284 
285   --set cascade flag to reflect changes.
286   OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
287   Oe_Debug_Pub.add('Leaving reset_fields');
288 Exception When Others Then
289   Oe_Debug_Pub.add('In procedure reset_fields:'||SQLERRM);
290 End;
291 
292 
293 Function Get_List_Lines (p_line_id Number) Return Varchar2 As
294  Cursor list_lines_no is
295  Select c.name,
296         a.list_line_no
297  From   qp_preq_ldets_tmp a,
298         qp_preq_lines_tmp b,
299         qp_list_headers_vl c
300  Where  b.line_id = p_line_id
301  And    b.line_index = a.line_index
302  And    a.created_from_list_header_id = c.list_header_id
303  And    a.automatic_flag = 'Y'
304  And    a.pricing_status_code = 'N'
305  And    a.created_from_list_line_type <> 'PLL';
306 
307  l_list_line_nos Varchar2(2000):=' ';
308  l_sperator Varchar2(1):='';
309 Begin
310  For i in List_Lines_no Loop
311    l_list_line_nos := i.name||':'||i.list_line_no||l_sperator||l_list_line_nos;
312    l_sperator := ',';
313  End Loop;
314  Return l_list_line_nos;
315 End;
316 
317 
318 PROCEDURE Header_Adjs
319 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
320 ,   p_validation_level              IN  NUMBER
321 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
322 ,   p_x_Header_Adj_tbl              IN OUT NOCOPY  OE_Order_PUB.Header_Adj_Tbl_Type
323 ,   p_x_old_Header_Adj_tbl          IN OUT NOCOPY  OE_Order_PUB.Header_Adj_Tbl_Type
324 )
325 IS
326 l_return_status               VARCHAR2(1);
327 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
328 l_Header_Adj_rec              OE_Order_PUB.Header_Adj_Rec_Type;
329 l_old_Header_Adj_rec          OE_Order_PUB.Header_Adj_Rec_Type;
330 -- local variables to store OUT parameters from security check procedures
331 l_sec_result            NUMBER;
332 l_on_operation_action   NUMBER;
333 I 				    pls_integer; -- Used as index for while loop
334 --
335 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
336 --
337   l_order_source_id           NUMBER;
338   l_orig_sys_document_ref     VARCHAR2(50);
339   l_change_sequence           VARCHAR2(50);
340   l_source_document_type_id   NUMBER;
341   l_source_document_id        NUMBER;
342 
343 BEGIN
344 
345     IF l_debug_level > 0 THEN
346       G_DEBUG:=TRUE;
347     END IF;
348 
349     oe_order_pvt.set_recursion_mode(p_Entity_Code => 3,
350                                    p_In_out  => 1);
351 
352     IF FND_API.to_Boolean(p_init_msg_list) THEN
353         OE_MSG_PUB.initialize;
354     END IF;
355 
356 IF l_control_rec.Process_Partial THEN
357 SAVEPOINT Header_Adjs;
358 END IF;
359 
360     --  Init local table variables.
361 
362     adj_debug('Entering oe_order_Adj_pvt.HEADER_ADJS', 1);
363 
364 
365 --    FOR I IN 1..p_x_Header_Adj_tbl.COUNT LOOP
366 
367     I := p_x_header_adj_tbl.FIRST;
368 
369     WHILE I IS NOT NULL LOOP
370     BEGIN
371 
372         --  Load local records.
373 
374         l_Header_Adj_rec := p_x_header_adj_tbl(I);
375 
376         IF p_x_old_Header_Adj_tbl.EXISTS(I) THEN
377             l_old_Header_Adj_rec := p_x_old_Header_Adj_tbl(I);
378         ELSE
379             l_old_Header_Adj_rec := OE_Order_PUB.G_MISS_HEADER_ADJ_REC;
380         END IF;
381 
382     if l_old_header_adj_rec.price_adjustment_id = FND_API.G_MISS_NUM  then
383 
384       IF l_header_adj_rec.header_Id IS NOT NULL AND
385          l_header_adj_rec.header_Id <> FND_API.G_MISS_NUM THEN
386            BEGIN
387                IF l_debug_level  > 0 THEN
388                   oe_debug_pub.add('Getting reference data for header_id:'||l_header_adj_rec.header_Id);
389                END IF;
390                SELECT order_source_id, orig_sys_document_ref, change_sequence,
391                source_document_type_id, source_document_id
392                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
393                l_source_document_type_id, l_source_document_id
394                FROM   OE_ORDER_HEADERS_ALL
395                WHERE  header_id = l_header_adj_rec.header_Id;
396             EXCEPTION
397                WHEN NO_DATA_FOUND THEN
398                    l_order_source_id := null;
399                    l_orig_sys_document_ref := null;
400                    l_change_sequence := null;
401                    l_source_document_type_id := null;
402                    l_source_document_id := null;
403                WHEN OTHERS THEN
404                    l_order_source_id := null;
405                    l_orig_sys_document_ref := null;
406                    l_change_sequence := null;
407                    l_source_document_type_id := null;
408                    l_source_document_id := null;
409             END;
410       END IF;
411 
412       OE_MSG_PUB.set_msg_context(
413 	 p_entity_code			=> 'HEADER_ADJ'
414   	,p_entity_id         		=> l_header_adj_rec.price_adjustment_id
415     	,p_header_id         		=> l_header_adj_rec.header_Id
416         ,p_line_id                      => null
417         ,p_order_source_id              => l_order_source_id
418         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
419         ,p_orig_sys_document_line_ref   => null
420         ,p_change_sequence              => l_change_sequence
421         ,p_source_document_type_id      => l_source_document_type_id
422         ,p_source_document_id           => l_source_document_id
423         ,p_source_document_line_id      => null );
424 
425     else
426 
427       IF l_old_header_adj_rec.header_Id IS NOT NULL AND
428          l_old_header_adj_rec.header_Id <> FND_API.G_MISS_NUM THEN
429 
430             BEGIN
431                IF l_debug_level  > 0 THEN
432                   oe_debug_pub.add('Getting reference data for old header_id:'||l_old_header_adj_rec.header_id);
433                END IF;
434                SELECT order_source_id, orig_sys_document_ref, change_sequence,
435                source_document_type_id, source_document_id
436                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
437                l_source_document_type_id, l_source_document_id
438                FROM   OE_ORDER_HEADERS_ALL
439                WHERE  header_id = l_old_header_adj_rec.header_id;
440             EXCEPTION
441                WHEN NO_DATA_FOUND THEN
442                    l_order_source_id := null;
443                    l_orig_sys_document_ref := null;
444                    l_change_sequence := null;
445                    l_source_document_type_id := null;
446                    l_source_document_id := null;
447                WHEN OTHERS THEN
448                    l_order_source_id := null;
449                    l_orig_sys_document_ref := null;
450                    l_change_sequence := null;
451                    l_source_document_type_id := null;
452                    l_source_document_id := null;
453             END;
454       END IF;
455 
456       OE_MSG_PUB.set_msg_context(
457 	 p_entity_code			=> 'HEADER_ADJ'
458   	,p_entity_id         		=> l_old_header_adj_rec.price_adjustment_id
459     	,p_header_id         		=> l_old_header_adj_rec.header_Id
460         ,p_line_id                      => null
461         ,p_order_source_id              => l_order_source_id
462         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
463         ,p_orig_sys_document_line_ref   => null
464         ,p_change_sequence              => l_change_sequence
465         ,p_source_document_type_id      => l_source_document_type_id
466         ,p_source_document_id           => l_source_document_id
467         ,p_source_document_line_id      => null );
468 
469     end if;
470 
471         --  Load API control record
472 
473         l_control_rec := OE_GLOBALS.Init_Control_Rec
474         (   p_operation     => l_Header_Adj_rec.operation
475         ,   p_control_rec   => p_control_rec
476         );
477 
478         --  Set record return status.
479 
480         l_Header_Adj_rec.return_status := FND_API.G_RET_STS_SUCCESS;
481         p_x_Header_Adj_tbl(I).return_status := FND_API.G_RET_STS_SUCCESS;
482 
483         --  Prepare record.
484 
485         IF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
486 
487             l_Header_Adj_rec.db_flag := FND_API.G_FALSE;
488 
489             --  Set missing old record elements to NULL.
490 
491    		 adj_debug('Entering OE_Header_Adj_Util.Convert_Miss_To_Null', 1);
492           /* change to nocopy procedure
493             l_old_Header_Adj_rec :=
494             OE_Header_Adj_Util.Convert_Miss_To_Null (l_old_Header_Adj_rec);
495            */
496             OE_Header_Adj_Util.Convert_Miss_To_Null(l_old_Header_Adj_rec);
497 
498         ELSIF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE
499         OR    l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_DELETE
500         THEN
501 
502             l_Header_Adj_rec.db_flag := FND_API.G_TRUE;
503 
504             --  Query Old if missing
505 
506             IF  l_old_Header_Adj_rec.price_adjustment_id = FND_API.G_MISS_NUM
507               OR l_old_Header_Adj_rec.price_adjustment_id IS NULL
508             THEN
509 
510                 OE_Header_Adj_Util.Query_Row
511                 (   p_price_adjustment_id         => l_Header_Adj_rec.price_adjustment_id
512                 ,   x_Header_Adj_Rec              => l_old_Header_Adj_rec
513                 );
514                   p_x_old_Header_Adj_tbl(I) := l_old_Header_Adj_rec;
515 
516             ELSE
517 
518                 --  Set missing old record elements to NULL.
519 
520 --                l_old_Header_Adj_rec :=
521                 OE_Header_Adj_Util.Convert_Miss_To_Null (l_old_Header_Adj_rec);
522 
523             END IF;
524 
525             --  Complete new record from old
526 
527 --            l_Header_Adj_rec :=
528             OE_Header_Adj_Util.Complete_Record
529             (   p_x_Header_Adj_rec              => l_Header_Adj_rec
530             ,   p_old_Header_Adj_rec          => l_old_Header_Adj_rec
531             );
532 
533       	   OE_MSG_PUB.update_msg_context(
534 	 	 p_entity_code			=> 'HEADER_ADJ'
535   		,p_entity_id         		=> l_header_adj_rec.price_adjustment_id
536     		,p_header_id         		=> l_header_adj_rec.header_Id);
537 
538         END IF;
539 
540         IF I = p_x_header_adj_tbl.FIRST THEN
541 	       IF NOT oe_order_pvt.Valid_Upgraded_Order(l_header_adj_rec.header_id) THEN
542                  RAISE FND_API.G_EXC_ERROR;
543             END IF;
544         END IF;
545 
546    -- Check security
547    IF l_control_rec.check_security
548       AND (l_header_adj_rec.operation = OE_GLOBALS.G_OPR_CREATE
549          OR l_header_adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
550    THEN
551 
552         adj_debug('Check Attributes Security');
553         -- check if this operation is allowed
554         -- on all the changed attributes
555            OE_Header_Adj_Security.Attributes
556                 (p_header_adj_rec   	=> l_header_adj_rec
557                 , p_old_header_adj_rec	=> l_old_header_adj_rec
558                 , x_result      	=> l_sec_result
559                 , x_return_status 	=> l_return_status
560                 );
561 
562             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
563                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
564             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
565                 RAISE FND_API.G_EXC_ERROR;
566             END IF;
567 
568            IF l_sec_result = OE_PC_GLOBALS.YES THEN
569                 RAISE FND_API.G_EXC_ERROR;
570            END IF;
571 
572     END IF;
573 
574         --  Attribute level validation.
575 
576             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
577 
578                 OE_Validate_Header_Adj.Attributes
579                 (   x_return_status               => l_return_status
580                 ,   p_Header_Adj_rec              => l_Header_Adj_rec
581                 ,   p_old_Header_Adj_rec          => l_old_Header_Adj_rec
582                 );
583 
584                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
585                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
586                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
587                     RAISE FND_API.G_EXC_ERROR;
588                 END IF;
589 
590             END IF;
591 
592 
593             --  Clear dependent attributes.
594 
595         IF  l_control_rec.clear_dependents THEN
596 
597             OE_Header_Adj_Util.Clear_Dependent_Attr
598             (   p_x_Header_Adj_rec              => l_Header_Adj_rec
599             ,   p_old_Header_Adj_rec          => l_old_Header_Adj_rec
600             --,   x_Header_Adj_rec              => l_Header_Adj_rec
601             );
602 
603         END IF;
604 
605         --  Default missing attributes
606 
607         IF  l_control_rec.default_attributes
608         THEN
609 
610            OE_Default_Header_Adj.Attributes
611             (   p_x_Header_Adj_rec              => l_Header_Adj_rec
612             ,   p_old_header_adj_rec	      => l_old_header_adj_rec
613             --,   x_Header_Adj_rec              => l_Header_Adj_rec
614             );
615 		  null;
616 
617         END IF;
618 
619         --  Apply attribute changes
620 
621         IF  l_control_rec.change_attributes
622         THEN
623 
624 	   -- This will also log request/s to check duplicity of
625 	   -- price adjustment entered
626             OE_Header_Adj_Util.Apply_Attribute_Changes
627             (   p_x_Header_Adj_rec              => l_Header_Adj_rec
628             ,   p_old_Header_Adj_rec          => l_old_Header_Adj_rec
629             --,   x_Header_Adj_rec              => l_Header_Adj_rec
630             );
631 
632         END IF;
633 
634 	-- If there has any activity causing a change in any attribute
635 	-- log a request for repricing
636 
637         --  Entity level validation.
638 
639         IF l_control_rec.validate_entity THEN
640 
641             IF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
642 
643                 OE_Validate_Header_Adj.Entity_Delete
644                 (   x_return_status               => l_return_status
645                 ,   p_Header_Adj_rec              => l_Header_Adj_rec
646                 );
647 
648             ELSE
649 
650                 OE_Validate_Header_Adj.Entity
651                 (   x_return_status               => l_return_status
652                 ,   p_Header_Adj_rec              => l_Header_Adj_rec
653                 ,   p_old_Header_Adj_rec          => l_old_Header_Adj_rec
654                 );
655 
656             END IF;
657 
658             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
659                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
660             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
661                 RAISE FND_API.G_EXC_ERROR;
662             END IF;
663 
664         END IF;
665 
666     -- Check entity level security again as some attributes
667     -- may have changed due to defaulting.
668     --IF l_control_rec.check_security THEN
669     --bug5467785
670     IF NOT (l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE
671                AND OE_Header_Adj_Security.g_check_all_cols_constraint = 'Y')
672     AND  l_control_rec.check_security THEN
673 
674         adj_debug('Check Entity Security');
675 
676            OE_Header_Adj_Security.Entity
677                 (p_header_adj_rec   	=> l_header_adj_rec
678                 , x_result      	=> l_sec_result
679                 , x_return_status 	=> l_return_status
680                 );
681 
682             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
683                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
684             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
685                 RAISE FND_API.G_EXC_ERROR;
686             END IF;
687 
688            IF l_sec_result = OE_PC_GLOBALS.YES THEN
689                 RAISE FND_API.G_EXC_ERROR;
690            END IF;
691 
692     END IF;
693 
694         --  Step 4. Write to DB
695 
696         IF l_control_rec.write_to_db THEN
697 
698            /* Start AuditTrail */
699            OE_DEBUG_PUB.add('OEXVADJB:calling to insert audit history reason for header adj in pre_write_process', 2);
700 
701 	       Oe_Header_ADJ_Util.Pre_Write_Process
702 		    (p_x_header_adj_rec => l_header_adj_rec,
703 			p_old_header_adj_rec => l_old_header_adj_rec);
704 
705            oe_debug_pub.add('OEXVADJB:After calling to insert audit history');
706            /* End AuditTrail */
707 
708             IF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
709 
710                 OE_Header_Adj_Util.Delete_Row
711                 (   p_price_adjustment_id         => l_Header_Adj_rec.price_adjustment_id
712                 );
713 
714 		-- Log a delayed request to cause repricing due to deleted
715 		-- record
716 		-- NOTE: Requesting entity is header, not header adj. as the adj. itself
717 		-- has been deleted and this request should be deleted when the order is
718 		-- deleted. Should be revisited if the entity logged against is changed
719 		-- to header.
720 		  	IF OE_Globals.G_RECURSION_MODE <> 'Y' AND
721 			   l_header_adj_rec.list_line_type_code NOT IN ('COST','TAX')
722 		     then
723 			  --CC Reversal ER#16014135 Start
724                           IF OE_VERIFY_PAYMENT_PUB.Get_CC_Rev_Reauth_Code(l_header_adj_rec.Header_id) IS NOT NULL THEN
725                             OE_delayed_requests_Pvt.log_request
726                             (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
727                              p_entity_id              => l_header_adj_rec.Header_id,
728                              p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
729                              p_requesting_entity_id   =>l_header_adj_rec.Header_id,
730                              p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
731                              x_return_status          => l_return_status);
732 
733                             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
734 			      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
735        		            ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
736 			        RAISE FND_API.G_EXC_ERROR;
737 		  	    END IF;
738                           END IF;
739 			  --CC Reversal ER#16014135 End
740 
741 			        adj_debug('Log header level PRICE_ADJ');
742 		    	 	oe_delayed_requests_pvt.log_request(p_entity_code     => OE_GLOBALS.G_ENTITY_ALL,
743 					p_entity_id              => l_header_adj_rec.Header_id,
744 					p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
745 					p_requesting_entity_id   => l_header_adj_rec.HEader_id,
746 					p_request_type           => OE_GLOBALS.G_PRICE_ADJ,
747 					x_return_status          => l_return_status);
748 					-- sol_ord_er #16014165 start
749 					IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
750 					   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
751                     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
752 					   RAISE FND_API.G_EXC_ERROR;
753 					END IF;
754 					-- If a manual Header Adjustment gets cascaded
755 					oe_delayed_requests_pvt.log_request(
756 								 p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
757 								 p_entity_id              => l_header_adj_rec.Header_Id,
758 								 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
759 								 p_requesting_entity_id   => l_header_adj_rec.Header_Id,
760 								 p_request_type           => OE_GLOBALS.G_SERVICE_FIRST_PERIOD_BILL,
761 								 p_request_unique_key1 => 'ORDER',
762 								 p_param1                 => l_header_adj_rec.Header_Id,
763 								 x_return_status          => l_return_status);
764 					-- sol_ord_er #16014165 end
765 			End If;
766 
767 		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
768 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
769 		 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
770 		   RAISE FND_API.G_EXC_ERROR;
771 		END IF;
772 
773             ELSE
774 
775                 --  Get Who Information
776 
777                 l_Header_Adj_rec.last_update_date := SYSDATE;
778                 l_Header_Adj_rec.last_updated_by := FND_GLOBAL.USER_ID;
779                 l_Header_Adj_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
780 
781                 IF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
782 
783                     OE_Header_Adj_Util.Update_Row (l_Header_Adj_rec);
784 
785                 ELSIF l_Header_Adj_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
786 
787                     l_Header_Adj_rec.creation_date := SYSDATE;
788                     l_Header_Adj_rec.created_by    := FND_GLOBAL.USER_ID;
789 
790                     OE_Header_Adj_Util.Insert_Row (l_Header_Adj_rec);
791 
792                 END IF;
793 
794             END IF;
795 
796         END IF;
797 
798         --  Load tables.
799 
800         p_x_header_adj_tbl(I)            := l_Header_Adj_rec;
801         p_x_old_Header_Adj_tbl(I)        := l_old_Header_Adj_rec;
802 
803          IF l_header_adj_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
804                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
805          ELSIF l_header_adj_rec.return_status = FND_API.G_RET_STS_ERROR THEN
806                 RAISE FND_API.G_EXC_ERROR;
807          END IF;
808 
809     OE_Header_Adj_Security.g_check_all_cols_constraint := 'Y';
810         OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
811     --   loop exception handler.
812 
813 
814 
815 
816     --
817 -- Start : Changes made as a part of DBI ER # 4185227
818 --
819     IF l_debug_level  > 0 THEN
820         oe_debug_pub.add(  'CALLING OE_DBI_UTIL FOR HEADER PRICE ADJUSTMENTS' , 1 ) ;
821         oe_debug_pub.add(  'CACHED VALUE' || OE_ORDER_CACHE.G_HEADER_REC.BOOKED_FLAG ) ;
822         oe_debug_pub.add(  'RECURSION VALUE' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION ) ;
823         oe_debug_pub.add(  'PROFILE VALUE' || FND_PROFILE.VALUE ( 'ONT_DBI_INSTALLED' ) ) ;
824     END IF;
825 
826     IF  NVL(FND_PROFILE.VALUE('ONT_DBI_INSTALLED'), 'N') = 'Y' AND
827         oe_order_cache.g_header_rec.booked_flag = 'Y' AND
828         oe_order_util.g_recursion_without_exception = 'N' AND
829         l_control_rec.write_to_db
830     THEN
831 
832       OE_DBI_UTIL.Update_DBI_Log( x_return_status  => l_return_status);
833 
834      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
835         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
836      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
837         RAISE FND_API.G_EXC_ERROR;
838      END IF;
839     END IF;
840 
841 --
842 -- End : Changes made as a part of DBI ER # 4185227
843 --
844 
845 
846     EXCEPTION
847 
848         WHEN FND_API.G_EXC_ERROR THEN
849 
850             l_Header_Adj_rec.return_status := FND_API.G_RET_STS_ERROR;
851             p_x_header_adj_tbl(I)            := l_Header_Adj_rec;
852             p_x_old_Header_Adj_tbl(I)        := l_old_Header_Adj_rec;
853     	    OE_Header_Adj_Security.g_check_all_cols_constraint := 'Y';
854             OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
855 oe_delayed_requests_pvt.delete_request(p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_ADJ,
856 		  	   p_entity_id => l_header_adj_rec.Price_adjustment_id,
857 	                   p_request_type => NULL,
858 	                   x_return_status => l_return_status);
859 		IF l_control_rec.Process_Partial THEN
860 			ROLLBACK TO SAVEPOINT Header_Adjs;
861 		ELSE
862                 RAISE FND_API.G_EXC_ERROR;
863 	        END IF;
864 
865 
866         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
867 
868             l_Header_Adj_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
869             p_x_header_adj_tbl(I)            := l_Header_Adj_rec;
870             p_x_old_Header_Adj_tbl(I)        := l_old_Header_Adj_rec;
871     	    OE_Header_Adj_Security.g_check_all_cols_constraint := 'Y';
872             OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
873 oe_delayed_requests_pvt.delete_request(p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_ADJ,
874 		  	   p_entity_id => l_header_adj_rec.Price_adjustment_id,
875 	                   p_request_type => NULL,
876 	                   x_return_status => l_return_status);
877             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
878 
879         WHEN OTHERS THEN
880 
881             l_Header_Adj_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
882             p_x_header_adj_tbl(I)            := l_Header_Adj_rec;
883             p_x_old_Header_Adj_tbl(I)        := l_old_Header_Adj_rec;
884     	    OE_Header_Adj_Security.g_check_all_cols_constraint := 'Y';
885 oe_delayed_requests_pvt.delete_request(p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_ADJ,
886 		  	   p_entity_id => l_header_adj_rec.Price_adjustment_id,
887 	                   p_request_type => NULL,
888 	                   x_return_status => l_return_status);
889 
890             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
891             THEN
892                 OE_MSG_PUB.Add_Exc_Msg
893                 (   G_PKG_NAME
894                 ,   'Header_Adjs'
895                 );
896             END IF;
897 
898             OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
899             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
900 
901     END;
902     I := p_x_header_adj_tbl.NEXT(I);
903     END LOOP;
904 
905     --  Load OUT parameters
906 
907       adj_debug('Exiting oe_order_Adj_pvt.HEADER_ADJS', 1);
908       OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
909 
910       oe_order_pvt.set_recursion_mode(p_Entity_Code => 3,
911                                    p_In_out  => 0);
912 
913 EXCEPTION
914 
915     WHEN FND_API.G_EXC_ERROR THEN
916       oe_order_pvt.set_recursion_mode(p_Entity_Code => 3,
917                                    p_In_out  => 0);
918 
919       OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
920       RAISE;
921 
922     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
923       oe_order_pvt.set_recursion_mode(p_Entity_Code => 3,
924                                    p_In_out  => 0);
925 
926       OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
927       RAISE;
928 
929     WHEN OTHERS THEN
930       oe_order_pvt.set_recursion_mode(p_Entity_Code => 3,
931                                    p_In_out  => 0);
932 
933         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
934         THEN
935             OE_MSG_PUB.Add_Exc_Msg
936             (   G_PKG_NAME
937             ,   'Header_Adjs'
938             );
939         END IF;
940 
941 
942         OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
943         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
944 
945 END Header_Adjs;
946 
947 --  Line_Adjs
948 
949 PROCEDURE Line_Adjs
950 (   p_init_msg_list                 IN VARCHAR2 := FND_API.G_FALSE
951 ,   p_validation_level              IN  NUMBER
952 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
953 ,   p_x_Line_Adj_tbl                IN OUT NOCOPY  OE_Order_PUB.Line_Adj_Tbl_Type
954 ,   p_x_old_Line_Adj_tbl            IN OUT NOCOPY  OE_Order_PUB.Line_Adj_Tbl_Type
955 )
956 IS
957 l_return_status               VARCHAR2(1);
958 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
959 l_Line_Adj_rec                OE_Order_PUB.Line_Adj_Rec_Type;
960 l_old_Line_Adj_rec            OE_Order_PUB.Line_Adj_Rec_Type;
961 -- local variables to store OUT parameters from security check procedures
962 l_sec_result            NUMBER;
963 l_on_operation_action   NUMBER;
964 I                       pls_integer; -- Used as table index for the loop.
965 --
966 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
967 --
968 l_last_line_id  Number;    --bug 2721485
969 l_line_found  Varchar2(1); --bug 2721485
970 
971 l_order_source_id           NUMBER;
972 l_orig_sys_document_ref     VARCHAR2(50);
973 l_orig_sys_line_ref     VARCHAR2(50);
974 l_orig_sys_shipment_ref     VARCHAR2(50);
975 l_change_sequence           VARCHAR2(50);
976 l_source_document_type_id   NUMBER;
977 l_source_document_id        NUMBER;
978 l_source_document_line_id        NUMBER;
979 l_line_temp_rec  OE_Order_PUB.Line_Rec_Type;
980 
981 BEGIN
982 
983  IF l_debug_level > 0 THEN
984    G_DEBUG := TRUE;
985  END IF;
986 
987     adj_debug('Entering oe_order_Adj_pvt.LINE_ADJS', 1);
988     oe_order_pvt.set_recursion_mode(p_Entity_Code => 6,
989                                    p_In_out  => 1);
990 
991     IF FND_API.to_Boolean(p_init_msg_list) THEN
992         OE_MSG_PUB.initialize;
993     END IF;
994 
995 IF l_control_rec.Process_Partial THEN
996 SAVEPOINT Line_Adjs;
997 END IF;
998 
999 
1000 --    FOR I IN 1..p_x_Line_Adj_tbl.COUNT LOOP
1001 
1002     I := p_x_Line_Adj_tbl.FIRST;
1003 
1004     WHILE I IS NOT NULL LOOP
1005     BEGIN
1006 
1007         --  Load local records.
1008 
1009         l_Line_Adj_rec := p_x_Line_Adj_tbl(I);
1010 
1011 	   adj_debug('price_adj_id :'||l_line_adj_rec.price_adjustment_id,3);
1012 	   adj_debug('operation is  :'||l_line_adj_rec.operation,3);
1013 
1014         IF p_x_old_Line_Adj_tbl.EXISTS(I) THEN
1015             l_old_Line_Adj_rec := p_x_old_Line_Adj_tbl(I);
1016         ELSE
1017             l_old_Line_Adj_rec := OE_Order_PUB.G_MISS_LINE_ADJ_REC;
1018         END IF;
1019 
1020         if l_old_line_Adj_rec.price_adjustment_id = FND_API.G_MISS_NUM then
1021 
1022            IF l_line_adj_rec.line_id IS NOT NULL AND
1023               l_line_adj_rec.line_id <> FND_API.G_MISS_NUM THEN
1024               BEGIN
1025                IF l_debug_level  > 0 THEN
1026                   oe_debug_pub.add('Getting reference data for line_id:'||l_line_adj_rec.line_id);
1027                END IF;
1028                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1029                source_document_type_id, source_document_id, orig_sys_line_ref,
1030                source_document_line_id, orig_sys_shipment_ref
1031                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1032                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
1033                l_source_document_line_id, l_orig_sys_shipment_ref
1034                FROM   OE_ORDER_LINES_ALL
1035                WHERE  line_id = l_line_adj_rec.line_id;
1036               EXCEPTION
1037                WHEN NO_DATA_FOUND THEN
1038                    l_order_source_id := null;
1039                    l_orig_sys_document_ref := null;
1040                    l_change_sequence := null;
1041                    l_source_document_type_id := null;
1042                    l_source_document_id := null;
1043                    l_orig_sys_line_ref := null;
1044                    l_source_document_line_id := null;
1045                    l_orig_sys_shipment_ref := null;
1046                WHEN OTHERS THEN
1047                    l_order_source_id := null;
1048                    l_orig_sys_document_ref := null;
1049                    l_change_sequence := null;
1050                    l_source_document_type_id := null;
1051                    l_source_document_id := null;
1052                    l_orig_sys_line_ref := null;
1053                    l_source_document_line_id := null;
1054                    l_orig_sys_shipment_ref := null;
1055               END;
1056            END IF;
1057 
1058            OE_MSG_PUB.set_msg_context(
1059 		 p_entity_code			=> 'LINE_ADJ'
1060   		,p_entity_id         		=> l_line_adj_rec.price_adjustment_id
1061     		,p_header_id         		=> l_line_adj_rec.header_id
1062     		,p_line_id           		=> l_line_adj_rec.line_id
1063                 ,p_order_source_id              => l_order_source_id
1064                 ,p_orig_sys_document_ref        => l_orig_sys_document_ref
1065                 ,p_orig_sys_document_line_ref   => l_orig_sys_line_ref
1066                 ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
1067                 ,p_change_sequence              => l_change_sequence
1068                 ,p_source_document_type_id      => l_source_document_type_id
1069                 ,p_source_document_id           => l_source_document_id
1070                 ,p_source_document_line_id      => l_source_document_line_id );
1071 
1072         else
1073 
1074            IF l_old_line_adj_rec.line_id IS NOT NULL AND
1075               l_old_line_adj_rec.line_id <> FND_API.G_MISS_NUM THEN
1076               BEGIN
1077                IF l_debug_level  > 0 THEN
1078                   oe_debug_pub.add('Getting reference data for old line_id:'||l_old_line_adj_rec.line_id);
1079                END IF;
1080                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1081                source_document_type_id, source_document_id, orig_sys_line_ref,
1082                source_document_line_id, orig_sys_shipment_ref
1083                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1084                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
1085                l_source_document_line_id, l_orig_sys_shipment_ref
1086                FROM   OE_ORDER_LINES_ALL
1087                WHERE  line_id = l_old_line_adj_rec.line_id;
1088               EXCEPTION
1089                WHEN NO_DATA_FOUND THEN
1090                    l_order_source_id := null;
1091                    l_orig_sys_document_ref := null;
1092                    l_change_sequence := null;
1093                    l_source_document_type_id := null;
1094                    l_source_document_id := null;
1095                    l_orig_sys_line_ref := null;
1096                    l_source_document_line_id := null;
1097                    l_orig_sys_shipment_ref := null;
1098                WHEN OTHERS THEN
1099                    l_order_source_id := null;
1100                    l_orig_sys_document_ref := null;
1101                    l_change_sequence := null;
1102                    l_source_document_type_id := null;
1103                    l_source_document_id := null;
1104                    l_orig_sys_line_ref := null;
1105                    l_source_document_line_id := null;
1106                    l_orig_sys_shipment_ref := null;
1107               END;
1108            END IF;
1109 
1110            OE_MSG_PUB.set_msg_context(
1111 		 p_entity_code			=> 'LINE_ADJ'
1112   		,p_entity_id         		=> l_old_line_adj_rec.price_adjustment_id
1113     		,p_header_id         		=> l_old_line_adj_rec.header_id
1114     		,p_line_id           		=> l_old_line_adj_rec.line_id
1115                 ,p_order_source_id              => l_order_source_id
1116                 ,p_orig_sys_document_ref        => l_orig_sys_document_ref
1117                 ,p_orig_sys_document_line_ref   => l_orig_sys_line_ref
1118                 ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
1119                 ,p_change_sequence              => l_change_sequence
1120                 ,p_source_document_type_id      => l_source_document_type_id
1121                 ,p_source_document_id           => l_source_document_id
1122                 ,p_source_document_line_id      => l_source_document_line_id );
1123         end if;
1124 
1125         --  Load API control record
1126 
1127         l_control_rec := OE_GLOBALS.Init_Control_Rec
1128         (   p_operation     => l_Line_Adj_rec.operation
1129         ,   p_control_rec   => p_control_rec
1130         );
1131 
1132         --  Set record return status.
1133 
1134         l_Line_Adj_rec.return_status   := FND_API.G_RET_STS_SUCCESS;
1135         p_x_line_adj_tbl(I).return_status       := FND_API.G_RET_STS_SUCCESS;
1136 
1137         --  Prepare record.
1138 
1139         IF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1140 
1141             l_Line_Adj_rec.db_flag := FND_API.G_FALSE;
1142 
1143             --  Set missing old record elements to NULL.
1144 
1145 --            l_old_Line_Adj_rec :=
1146             OE_Line_Adj_Util.Convert_Miss_To_Null (l_old_Line_Adj_rec);
1147        --bug 2721485  Begin
1148 	 adj_debug('Line id :'||l_line_adj_rec.line_id,3);
1149          if OE_GLOBALS.G_PRICING_RECURSION = 'N' and
1150          l_line_adj_rec.line_id is not null then
1151           if l_last_line_id = l_line_adj_rec.line_id
1152           and l_line_found = 'Y' then
1153             null;
1154           elsif l_last_line_id = l_line_adj_rec.line_id
1155           and l_line_found = 'N' then
1156 	   adj_debug('Line ID not found 1',3);
1157            GOTO line_not_in_db;
1158           else
1159            Begin
1160             --bug 2825766 begin
1161              oe_oe_form_line.get_line(p_db_record => FALSE,
1162                                   p_line_id => l_line_adj_rec.line_id,
1163                                   x_line_rec => l_line_temp_rec);
1164             l_last_line_id := l_line_adj_rec.line_id;
1165             if nvl(l_line_temp_rec.line_id,FND_API.G_MISS_NUM) <>
1166              FND_API.G_MISS_NUM then
1167                l_line_found := 'Y';
1168              adj_debug('Line id found:');
1169             else
1170              l_line_found := 'N';
1171              adj_debug('Line id not found 1:');
1172              GOTO line_not_in_db;
1173             end if;
1174             --bug 2825766 end
1175            Exception
1176              when others then
1177 	     adj_debug('line adjs - others 2 ',3);
1178              l_line_found := 'N';
1179              l_last_line_id := l_line_adj_rec.line_id;
1180              GOTO line_not_in_db;
1181            end;
1182           end if;
1183          end if;
1184        --bug 2721485 End
1185 
1186         ELSIF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE
1187         OR    l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_DELETE
1188         THEN
1189 
1190             l_Line_Adj_rec.db_flag := FND_API.G_TRUE;
1191 
1192             --  Query Old if missing
1193 
1194             IF  l_old_Line_Adj_rec.price_adjustment_id = FND_API.G_MISS_NUM
1195                        OR l_old_Line_Adj_rec.line_id IS NULL
1196             THEN
1197 
1198                  OE_Line_Adj_Util.Query_Row
1199                 (   p_price_adjustment_id         => l_Line_Adj_rec.price_adjustment_id
1200                 ,   x_line_adj_rec =>                 l_old_Line_Adj_rec
1201                 );
1202 
1203                p_x_old_line_adj_tbl(I) := l_old_line_adj_rec;
1204 
1205             ELSE
1206 
1207                 --  Set missing old record elements to NULL.
1208 
1209 --                l_old_Line_Adj_rec :=
1210                 OE_Line_Adj_Util.Convert_Miss_To_Null (l_old_Line_Adj_rec);
1211 
1212             END IF;
1213 
1214             --  Complete new record from old
1215 
1216 --            l_Line_Adj_rec :=
1217             OE_Line_Adj_Util.Complete_Record
1218             (   p_x_Line_Adj_rec                => l_Line_Adj_rec
1219             ,   p_old_Line_Adj_rec            => l_old_Line_Adj_rec
1220             );
1221 
1222             OE_MSG_PUB.update_msg_context(
1223 		 p_entity_code			=> 'LINE_ADJ'
1224   		,p_entity_id         		=> l_line_adj_rec.price_adjustment_id
1225     		,p_header_id         		=> l_line_adj_rec.header_id
1226     		,p_line_id           		=> l_line_adj_rec.line_id);
1227 
1228         END IF;
1229 
1230 
1231         IF I = p_x_line_adj_tbl.FIRST THEN
1232 	       IF NOT oe_order_pvt.Valid_Upgraded_Order(l_line_adj_rec.header_id) THEN
1233                  RAISE FND_API.G_EXC_ERROR;
1234             END IF;
1235         END IF;
1236 
1237    -- Check security
1238    IF l_control_rec.check_security
1239       AND (l_line_adj_rec.operation = OE_GLOBALS.G_OPR_CREATE
1240          OR l_line_adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
1241    THEN
1242 
1243         adj_debug('Check Attributes Security',2);
1244         -- check if this operation is allowed
1245         -- on all the changed attributes
1246            OE_Line_Adj_Security.Attributes
1247                 (p_line_Adj_rec   	=> l_line_adj_rec
1248                 , p_old_line_adj_rec	=> l_old_line_adj_rec
1249                 , x_result      	=> l_sec_result
1250                 , x_return_status 	=> l_return_status
1251                 );
1252 
1253             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1254                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1255             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1256                 RAISE FND_API.G_EXC_ERROR;
1257             END IF;
1258 
1259            IF l_sec_result = OE_PC_GLOBALS.YES THEN
1260                 RAISE FND_API.G_EXC_ERROR;
1261            END IF;
1262 
1263     END IF;
1264 
1265         --  Attribute level validation.
1266 
1267             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
1268 
1269 	       adj_debug('Before OE_Validate_Line_Adj.Attributes . ' ||
1270 			' adj_id = '|| To_char(l_line_adj_rec.price_adjustment_id), 2);
1271 
1272                 OE_Validate_Line_Adj.Attributes
1273                 (   x_return_status               => l_return_status
1274                 ,   p_Line_Adj_rec                => l_Line_Adj_rec
1275                 ,   p_old_Line_Adj_rec            => l_old_Line_Adj_rec
1276                 );
1277 
1278                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1279                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1280                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1281                     RAISE FND_API.G_EXC_ERROR;
1282                 END IF;
1283 
1284 
1285             END IF;
1286 
1287 
1288             --  Clear dependent attributes.
1289 
1290         IF  l_control_rec.clear_dependents THEN
1291 
1292             OE_Line_Adj_Util.Clear_Dependent_Attr
1293             (   p_x_Line_Adj_rec                => l_Line_Adj_rec
1294             ,   p_old_Line_Adj_rec            => l_old_Line_Adj_rec
1295             --,   x_Line_Adj_rec                => l_Line_Adj_rec
1296             );
1297 
1298         END IF;
1299 
1300         --  Default missing attributes
1301 
1302         IF  l_control_rec.default_attributes
1303         THEN
1304 
1305             OE_Default_Line_Adj.Attributes
1306             (   p_x_Line_Adj_rec                => l_Line_Adj_rec
1307 	    ,   p_old_line_adj_rec            => l_old_line_adj_rec
1308             --,   x_Line_Adj_rec                => l_Line_Adj_rec
1309             );
1310 
1311 /*	    adj_debug('After OE_Default_Line_Adj.Attributes . ' ||
1312 			     'discount_id = ' || To_char(l_line_adj_rec.discount_id)
1313 			     || ' discount_line_id = '||
1314 			     To_char(l_line_adj_rec.discount_line_id)
1315 			     || ' percent = '|| To_char(l_line_adj_rec.percent), 2);
1316 */
1317 
1318         END IF;
1319 
1320         --  Apply attribute changes
1321 
1322         IF  l_control_rec.change_attributes
1323         THEN
1324 
1325 	   -- This will also log request/s to check duplicity/fixed_price
1326 	   -- check of price adjustment entered
1327 		  adj_debug('Before OE_Line_Adj_Util.Apply_Attribute_Changes ',2);
1328             OE_Line_Adj_Util.Apply_Attribute_Changes
1329             (   p_x_Line_Adj_rec                => l_Line_Adj_rec
1330             ,   p_old_Line_Adj_rec            => l_old_Line_Adj_rec
1331             --,   x_Line_Adj_rec                => l_Line_Adj_rec
1332             );
1333 		  adj_debug('After OE_Line_Adj_Util.Apply_Attribute_Changes ',2);
1334 
1335         END IF;
1336 
1337 
1338 	-- If there has any activity causing a change in any attribute
1339 	-- log a request for repricing
1340 /*	IF l_control_rec.change_attributes
1341 	  THEN
1342 	   oe_line_adj_util.log_adj_requests(l_return_status,
1343 						l_line_adj_rec,
1344 						l_old_line_adj_rec);
1345 
1346 	   IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1347 	      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1348 	    ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1349 	      RAISE FND_API.G_EXC_ERROR;
1350 	   END IF;
1351 
1352 	END IF; */
1353 
1354 
1355 
1356         --  Entity level validation.
1357 
1358         IF l_control_rec.validate_entity THEN
1359 
1360             IF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
1361 
1362                 OE_Validate_Line_Adj.Entity_Delete
1363                 (   x_return_status               => l_return_status
1364                 ,   p_Line_Adj_rec                => l_Line_Adj_rec
1365                 );
1366 
1367 			 adj_debug('After OE_Validate_Line_Adj.delete ',2);
1368             ELSE
1369 
1370 	       -- logs maximum percentage request check also
1371 			 adj_debug('Before OE_Validate_Line_Adj.Entity ',2);
1372                 OE_Validate_Line_Adj.Entity
1373                 (   x_return_status               => l_return_status
1374                 ,   p_Line_Adj_rec                => l_Line_Adj_rec
1375                 ,   p_old_Line_Adj_rec            => l_old_Line_Adj_rec
1376                 );
1377 			 adj_debug('After OE_Validate_Line_Adj.Entity ',2);
1378 
1379             END IF;
1380 
1381 		  adj_debug('Stt '||l_return_status,3);
1382             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1383                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1384             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1385                 RAISE FND_API.G_EXC_ERROR;
1386             END IF;
1387 
1388         END IF;
1389 		adj_debug('Before Check_security..',2);
1390 
1391     -- Check entity level security again as some attributes
1392     -- may have changed due to defaulting.
1393     IF l_control_rec.check_security THEN
1394 
1395         adj_debug('Check Entity Security',2);
1396 
1397            OE_Line_Adj_Security.Entity
1398                 (p_line_adj_rec   	=> l_line_adj_rec
1399                 , x_result      	=> l_sec_result
1400                 , x_return_status 	=> l_return_status
1401                 );
1402 
1403         adj_debug('After Check Entity Security',2);
1404 
1405             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1406                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1407             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1408                 RAISE FND_API.G_EXC_ERROR;
1409             END IF;
1410 
1411            IF l_sec_result = OE_PC_GLOBALS.YES THEN
1412                 RAISE FND_API.G_EXC_ERROR;
1413            END IF;
1414 
1415     END IF;
1416 
1417         --  Step 4. Write to DB
1418 
1419 	   adj_debug('Before write_to_db',2);
1420         IF l_control_rec.write_to_db THEN
1421 
1422            /* Start AuditTrail */
1423            OE_DEBUG_PUB.add('OEXVADJB:calling to insert audit history for line adj from  pre_write_process', 2);
1424 
1425 	       Oe_LINE_ADJ_Util.Pre_Write_Process
1426 		    (p_x_line_adj_rec => l_line_adj_rec,
1427 			p_old_line_adj_rec => l_old_line_adj_rec);
1428            OE_DEBUG_PUB.add('OEXVADJB:After calling to insert audit history for line adj from  pre_write_process', 2);
1429            /* End AuditTrail */
1430 
1431             IF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
1432 
1433                 OE_Line_Adj_Util.Delete_Row
1434                 (   p_price_adjustment_id         => l_Line_Adj_rec.price_adjustment_id
1435                 );
1436 
1437 		-- Log a delayed request to cause repricing due to deleted
1438 		-- record
1439 		-- NOTE: Requesting entity is line, not line adj. as the adj. itself
1440 		-- has been deleted and this request should be deleted when the line gets
1441 		-- deleted. Should be revisited if the entity logged against is changed
1442 		-- to line.
1443 		  	IF OE_Globals.G_RECURSION_MODE <> 'Y' and
1444 			   l_Line_adj_rec.list_line_type_code NOT IN ('COST','TAX')
1445                THEN
1446 
1447 				/* 1905650 - G_PRICE_ADJ request should be logged against LINE entity,
1448 	    			   not against LINE_ADJ entity
1449 				   1503357 - Minor change to handle header level adjustments
1450 	 			*/
1451 				--CC Reversal ER#16014135 Start
1452                                 IF OE_VERIFY_PAYMENT_PUB.Get_CC_Rev_Reauth_Code(l_Line_adj_rec.header_id) IS NOT NULL THEN
1453 				  OE_delayed_requests_Pvt.log_request
1454                                    (p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
1455                                     p_entity_id              => l_Line_adj_rec.header_id,
1456                                     p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1457                                     p_requesting_entity_id   =>l_Line_adj_rec.header_id,
1458                                     p_request_type           => OE_GLOBALS.G_VERIFY_PAYMENT,
1459                                     x_return_status          => l_return_status);
1460   				  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1461 				    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1462 				  ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1463 				    RAISE FND_API.G_EXC_ERROR;
1464 				  END IF;
1465                                 END IF;
1466 				--CC Reversal ER#16014135 End
1467 
1468 			        if (l_line_adj_rec.line_id is NULL) Then
1469 				   oe_delayed_requests_pvt.log_request(
1470 					p_entity_code     => OE_GLOBALS.G_ENTITY_ALL,
1471 					p_entity_id              => l_Line_adj_rec.header_id,
1472 					p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
1473 					p_requesting_entity_id   => l_Line_adj_rec.header_id,
1474 					p_request_type           => OE_GLOBALS.G_PRICE_ADJ,
1475 					x_return_status          => l_return_status);
1476 					-- sol_ord_er #16014165 start
1477 					IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1478 					   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1479 					ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1480 					   RAISE FND_API.G_EXC_ERROR;
1481 					END IF;
1482 					oe_delayed_requests_pvt.log_request(
1483 								 p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
1484 								 p_entity_id              => l_Line_adj_rec.Header_Id,
1485 								 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
1486 								 p_requesting_entity_id   => l_Line_adj_rec.Header_Id,
1487 								 p_request_type           => OE_GLOBALS.G_SERVICE_FIRST_PERIOD_BILL,
1488 								 p_request_unique_key1 => 'ORDER',
1489 								 p_param1                 => l_Line_adj_rec.Header_Id,
1490 								 x_return_status          => l_return_status);
1491 					-- sol_ord_er #16014165 end
1492 				else
1493 		    	 	  If OE_GLOBALS.G_UI_FLAG and nvl(l_Line_adj_rec.automatic_flag,'Y') = 'N' Then
1494                                       oe_delayed_requests_pvt.log_request(
1495 	                                  p_entity_code                => OE_GLOBALS.G_ENTITY_LINE,
1496 	                                  p_entity_id                     => l_Line_adj_rec.Line_id,
1497 	                                  p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE_ADJ,
1498                                	          p_requesting_entity_id   => l_Line_adj_rec.Line_id,
1499 	                                  p_request_type           => OE_GLOBALS.G_PRICE_ADJ,
1500                                           p_param1                 => 'UI',
1501 	                                  x_return_status          => l_return_status);
1502 
1503 				  else
1504 		    	 	        oe_delayed_requests_pvt.log_request(
1505 					p_entity_code     => OE_GLOBALS.G_ENTITY_LINE,
1506 					p_entity_id              => l_Line_adj_rec.Line_id,
1507 					p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1508 					p_requesting_entity_id   => l_Line_adj_rec.Line_id,
1509 					p_request_type           => OE_GLOBALS.G_PRICE_ADJ,
1510 					x_return_status          => l_return_status);
1511 				  end if;
1512 				  -- sol_ord_er #16014165
1513 				  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1514 				   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1515 				  ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1516 				   RAISE FND_API.G_EXC_ERROR;
1517 				  END IF;
1518 				  oe_delayed_requests_pvt.log_request(
1519 							 p_entity_code            => OE_GLOBALS.G_ENTITY_LINE,
1520 							 p_entity_id              => l_Line_adj_rec.line_id,
1521 							 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_LINE,
1522 							 p_requesting_entity_id   => l_Line_adj_rec.line_id,
1523 							 p_request_type           => OE_GLOBALS.G_SERVICE_FIRST_PERIOD_BILL,
1524 							 p_request_unique_key1    => 'LINE',
1525 							 p_param1                 => l_Line_adj_rec.line_id,
1526 							 x_return_status          => l_return_status);
1527 				-- sol_ord_er #16014165 end
1528 				end if;
1529 			End If;
1530 
1531 		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1532 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1533 		 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1534 		   RAISE FND_API.G_EXC_ERROR;
1535 		END IF;
1536 
1537 
1538             ELSE
1539 
1540                 --  Get Who Information
1541 
1542                 l_Line_Adj_rec.last_update_date := SYSDATE;
1543                 l_Line_Adj_rec.last_updated_by := FND_GLOBAL.USER_ID;
1544                 l_Line_Adj_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
1545 
1546                 IF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
1547                     oe_debug_pub.add(' updating list line id:'||l_Line_Adj_rec.list_line_id);
1548                     oe_debug_pub.add(' l_line_adj_rec adjusted_amount:'||l_Line_Adj_rec.adjusted_amount);
1549                     oe_debug_pub.add(' line_id:'||l_Line_Adj_rec.line_id);
1550                     OE_Line_Adj_Util.Update_Row (l_Line_Adj_rec);
1551 
1552                 ELSIF l_Line_Adj_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1553 
1554                     l_Line_Adj_rec.creation_date   := SYSDATE;
1555                     l_Line_Adj_rec.created_by      := FND_GLOBAL.USER_ID;
1556 
1557        			 adj_debug('Before  insert row',2);
1558                     OE_Line_Adj_Util.Insert_Row (l_Line_Adj_rec);
1559        			 adj_debug('After  insert row',2);
1560 
1561                 END IF;
1562 
1563             END IF;
1564 
1565         END IF;
1566 
1567         --  Load tables.
1568 
1569         p_x_Line_Adj_tbl(I)              := l_Line_Adj_rec;
1570         p_x_old_Line_Adj_tbl(I)          := l_old_Line_Adj_rec;
1571 
1572     	OE_Line_Adj_Security.g_check_all_cols_constraint := 'Y';
1573         OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1574 	-- Check return status and rollaback
1575 
1576 	IF l_line_adj_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1577 		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1578          ELSIF l_line_adj_rec.return_status = FND_API.G_RET_STS_ERROR THEN
1579 		   RAISE FND_API.G_EXC_ERROR;
1580 		END IF;
1581 
1582     --  loop exception handler.
1583 
1584 /*
1585 -- Bug 6838610 below Code is comented to Imporve Performance
1586 --
1587 -- Start : Changes made as a part of DBI ER # 4185227
1588 --
1589     IF l_debug_level  > 0 THEN
1590         oe_debug_pub.add(  'CALLING OE_DBI_UTIL FOR ORDER LINE PRICE ADJUSTMENTS' , 1 ) ;
1591         oe_debug_pub.add(  'CACHED VALUE' || OE_ORDER_CACHE.G_HEADER_REC.BOOKED_FLAG ) ;
1592         oe_debug_pub.add(  'RECURSION VALUE' || OE_ORDER_UTIL.G_RECURSION_WITHOUT_EXCEPTION ) ;
1593         oe_debug_pub.add(  'PROFILE VALUE' || FND_PROFILE.VALUE ( 'ONT_DBI_INSTALLED' ) ) ;
1594     END IF;
1595 
1596     IF  NVL(FND_PROFILE.VALUE('ONT_DBI_INSTALLED'), 'N') = 'Y' AND
1597         oe_order_cache.g_header_rec.booked_flag = 'Y' AND
1598         oe_order_util.g_recursion_without_exception = 'N' AND
1599         l_control_rec.write_to_db
1600     THEN
1601       OE_DBI_UTIL.Update_DBI_Log( x_return_status  => l_return_status);
1602 
1603      IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1604         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1605      ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1606         RAISE FND_API.G_EXC_ERROR;
1607      END IF;
1608     END IF;
1609 
1610 --
1611 -- End : Changes made as a part of DBI ER # 4185227
1612 --
1613 
1614 */
1615 --End of changes for 6838610
1616 
1617 
1618 
1619 
1620 
1621     EXCEPTION
1622 
1623         WHEN FND_API.G_EXC_ERROR THEN
1624 
1625             l_Line_Adj_rec.return_status   := FND_API.G_RET_STS_ERROR;
1626             p_x_Line_Adj_tbl(I)              := l_Line_Adj_rec;
1627             p_x_old_Line_Adj_tbl(I)          := l_old_Line_Adj_rec;
1628     	    OE_Line_Adj_Security.g_check_all_cols_constraint := 'Y';
1629             OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1630 oe_delayed_requests_pvt.delete_request(p_entity_code =>OE_GLOBALS.G_ENTITY_LINE_ADJ,
1631 		  	   p_entity_id => l_line_adj_rec.Price_adjustment_id,
1632 	                   p_request_type => NULL,
1633 	                   x_return_status => l_return_status);
1634 	    IF l_control_rec.Process_Partial THEN
1635 		ROLLBACK TO SAVEPOINT Line_Adjs;
1636 	    ELSE
1637 		   RAISE FND_API.G_EXC_ERROR;
1638 	    END IF;
1639 
1640         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1641 
1642             l_Line_Adj_rec.return_status   := FND_API.G_RET_STS_UNEXP_ERROR;
1643             p_x_Line_Adj_tbl(I)              := l_Line_Adj_rec;
1644             p_x_old_Line_Adj_tbl(I)          := l_old_Line_Adj_rec;
1645     	    OE_Line_Adj_Security.g_check_all_cols_constraint := 'Y';
1646             OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1647 oe_delayed_requests_pvt.delete_request(p_entity_code =>OE_GLOBALS.G_ENTITY_LINE_ADJ,
1648 		  	   p_entity_id => l_line_adj_rec.Price_adjustment_id,
1649 	                   p_request_type => NULL,
1650 	                   x_return_status => l_return_status);
1651             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1652 
1653         WHEN OTHERS THEN
1654 
1655             l_Line_Adj_rec.return_status   := FND_API.G_RET_STS_UNEXP_ERROR;
1656             p_x_Line_Adj_tbl(I)              := l_Line_Adj_rec;
1657             p_x_old_Line_Adj_tbl(I)          := l_old_Line_Adj_rec;
1658     	    OE_Line_Adj_Security.g_check_all_cols_constraint := 'Y';
1659 oe_delayed_requests_pvt.delete_request(p_entity_code =>OE_GLOBALS.G_ENTITY_LINE_ADJ,
1660 		  	   p_entity_id => l_line_adj_rec.Price_adjustment_id,
1661 	                   p_request_type => NULL,
1662 	                   x_return_status => l_return_status);
1663 
1664             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1665             THEN
1666                 OE_MSG_PUB.Add_Exc_Msg
1667                 (   G_PKG_NAME
1668                 ,   'Line_Adjs'
1669                 );
1670             END IF;
1671 
1672             OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1673             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1674 
1675     END;
1676         <<line_not_in_db>>  --bug 2721485
1677 		I := p_x_Line_Adj_tbl.NEXT(I);
1678     END LOOP;
1679 
1680     --  Load OUT parameters
1681 
1682     OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1683 
1684     oe_order_pvt.set_recursion_mode(p_Entity_Code => 6,
1685                                    p_In_out  => 0);
1686 
1687 EXCEPTION
1688 
1689     WHEN FND_API.G_EXC_ERROR THEN
1690 
1691     oe_order_pvt.set_recursion_mode(p_Entity_Code => 6,
1692                                    p_In_out  => 0);
1693 
1694         adj_debug('Exiting oe_order_Adj_pvt.LINE_ADJS', 1);
1695         OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1696         RAISE;
1697 
1698     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1699     oe_order_pvt.set_recursion_mode(p_Entity_Code => 6,
1700                                    p_In_out  => 0);
1701 
1702 
1703         OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1704         RAISE;
1705 
1706     WHEN OTHERS THEN
1707     oe_order_pvt.set_recursion_mode(p_Entity_Code => 6,
1708                                    p_In_out  => 0);
1709 
1710         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1711         THEN
1712             OE_MSG_PUB.Add_Exc_Msg
1713             (   G_PKG_NAME
1714             ,   'Line_Adjs'
1715             );
1716         END IF;
1717 
1718 
1719         OE_MSG_PUB.reset_msg_context('LINE_ADJ');
1720         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1721 
1722 END Line_Adjs;
1723 
1724 PROCEDURE HEader_Price_Atts
1725 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
1726 ,   p_validation_level              IN  NUMBER
1727 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
1728 ,   p_x_HEader_Price_Att_tbl        IN OUT NOCOPY  OE_Order_PUB.HEader_Price_Att_Tbl_Type
1729 ,   p_x_old_HEader_Price_Att_tbl    IN OUT NOCOPY  OE_Order_PUB.HEader_Price_Att_Tbl_Type
1730 )
1731 is
1732 l_return_status               VARCHAR2(1);
1733 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
1734 l_Header_Price_Att_rec        OE_Order_PUB.Header_Price_Att_Rec_Type;
1735 l_old_Header_Price_Att_rec    OE_Order_PUB.Header_Price_Att_Rec_Type;
1736 -- local variables to store OUT parameters from security check procedures
1737 l_sec_result            NUMBER;
1738 l_on_operation_action   NUMBER;
1739 I 				    pls_integer; -- Used as index for while loop
1740 l_booked_flag			varchar2(1);
1741 l_Shipped_quantity		number;
1742 l_pricing_event                 varchar2(30);
1743 
1744 --
1745 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1746 --
1747   l_order_source_id           NUMBER;
1748   l_orig_sys_document_ref     VARCHAR2(50);
1749   l_change_sequence           VARCHAR2(50);
1750   l_source_document_type_id   NUMBER;
1751   l_source_document_id        NUMBER;
1752 
1753 BEGIN
1754 
1755     l_control_rec := p_control_rec;  -- Added for Bug #5679839
1756 
1757     IF FND_API.to_Boolean(p_init_msg_list) THEN
1758         OE_MSG_PUB.initialize;
1759     END IF;
1760 
1761 IF l_control_rec.Process_Partial THEN
1762 	SAVEPOINT Header_Price_Atts;
1763 END IF;
1764 
1765     --  Init local table variables.
1766 
1767         --dbms_output.put_line('Entering oe_order_Adj_pvt.HEader_Price_Atts');
1768         oe_debug_pub.add('Entering oe_order_Adj_pvt.HEader_Price_Atts', 1);
1769 
1770 
1771     I := p_x_Header_Price_Att_tbl.FIRST;
1772 
1773     WHILE I IS NOT NULL LOOP
1774     BEGIN
1775 
1776         --  Load local records.
1777 
1778         l_Header_Price_Att_rec := p_x_Header_Price_Att_tbl(I);
1779 
1780         IF p_x_old_Header_Price_Att_tbl.EXISTS(I) THEN
1781             l_old_Header_Price_Att_rec := p_x_old_Header_Price_Att_tbl(I);
1782         ELSE
1783             l_old_Header_Price_Att_rec := OE_Order_PUB.G_MISS_HEADER_Price_Att_REC;
1784         END IF;
1785 
1786     if l_old_header_Price_Att_rec.Order_price_attrib_id = FND_API.G_MISS_NUM  then
1787       IF l_header_Price_Att_rec.header_Id IS NOT NULL AND
1788          l_header_Price_Att_rec.header_Id <> FND_API.G_MISS_NUM THEN
1789          BEGIN
1790                IF l_debug_level  > 0 THEN
1791                   oe_debug_pub.add('Getting reference data for header_id:'||l_header_Price_Att_rec.header_Id);
1792                END IF;
1793                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1794                source_document_type_id, source_document_id
1795                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1796                l_source_document_type_id, l_source_document_id
1797                FROM   OE_ORDER_HEADERS_ALL
1798                WHERE  header_id = l_header_Price_Att_rec.header_Id;
1799          EXCEPTION
1800                WHEN NO_DATA_FOUND THEN
1801                    l_order_source_id := null;
1802                    l_orig_sys_document_ref := null;
1803                    l_change_sequence := null;
1804                    l_source_document_type_id := null;
1805                    l_source_document_id := null;
1806                WHEN OTHERS THEN
1807                    l_order_source_id := null;
1808                    l_orig_sys_document_ref := null;
1809                    l_change_sequence := null;
1810                    l_source_document_type_id := null;
1811                    l_source_document_id := null;
1812          END;
1813       END IF;
1814 
1815       OE_MSG_PUB.set_msg_context(
1816 	 p_entity_code			=> 'HEADER_PATTS'
1817   	,p_entity_id         		=> l_header_Price_Att_rec.Order_price_attrib_id
1818     	,p_header_id         		=> l_header_Price_Att_rec.header_Id
1819         ,p_line_id                      => null
1820         ,p_order_source_id              => l_order_source_id
1821         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
1822         ,p_orig_sys_document_line_ref   => null
1823         ,p_change_sequence              => l_change_sequence
1824         ,p_source_document_type_id      => l_source_document_type_id
1825         ,p_source_document_id           => l_source_document_id
1826         ,p_source_document_line_id      => null );
1827 
1828     else
1829 
1830       IF l_old_header_Price_Att_rec.header_Id IS NOT NULL AND
1831          l_old_header_Price_Att_rec.header_Id <> FND_API.G_MISS_NUM THEN
1832 
1833             BEGIN
1834                IF l_debug_level  > 0 THEN
1835                   oe_debug_pub.add('Getting reference data for old header_id:'||l_old_header_Price_Att_rec.header_Id);
1836                END IF;
1837                SELECT order_source_id, orig_sys_document_ref, change_sequence,
1838                source_document_type_id, source_document_id
1839                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
1840                l_source_document_type_id, l_source_document_id
1841                FROM   OE_ORDER_HEADERS_ALL
1842                WHERE  header_id = l_old_header_Price_Att_rec.header_Id;
1843             EXCEPTION
1844                WHEN NO_DATA_FOUND THEN
1845                    l_order_source_id := null;
1846                    l_orig_sys_document_ref := null;
1847                    l_change_sequence := null;
1848                    l_source_document_type_id := null;
1849                    l_source_document_id := null;
1850                WHEN OTHERS THEN
1851                    l_order_source_id := null;
1852                    l_orig_sys_document_ref := null;
1853                    l_change_sequence := null;
1854                    l_source_document_type_id := null;
1855                    l_source_document_id := null;
1856             END;
1857       END IF;
1858 
1859       OE_MSG_PUB.set_msg_context(
1860 	 p_entity_code			=> 'HEADER_PATTS'
1861   	,p_entity_id         		=> l_old_header_Price_Att_rec.Order_price_attrib_id
1862     	,p_header_id         		=> l_old_header_Price_Att_rec.header_Id
1863         ,p_line_id                      => null
1864         ,p_order_source_id              => l_order_source_id
1865         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
1866         ,p_orig_sys_document_line_ref   => null
1867         ,p_change_sequence              => l_change_sequence
1868         ,p_source_document_type_id      => l_source_document_type_id
1869         ,p_source_document_id           => l_source_document_id
1870         ,p_source_document_line_id      => null );
1871 
1872     end if;
1873 
1874         --  Load API control record
1875 
1876         l_control_rec := OE_GLOBALS.Init_Control_Rec
1877         (   p_operation     => l_Header_Price_Att_rec.operation
1878         ,   p_control_rec   => p_control_rec
1879         );
1880 
1881         --  Set record return status.
1882 
1883         l_Header_Price_Att_rec.return_status := FND_API.G_RET_STS_SUCCESS;
1884 
1885         oe_debug_pub.add('  After initializing record,operation:'||l_Header_Price_Att_rec.operation);
1886         --  Prepare record.
1887 
1888         IF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
1889 
1890             l_Header_Price_Att_rec.db_flag := FND_API.G_FALSE;
1891 
1892             --  Set missing old record elements to NULL.
1893 
1894    		 oe_debug_pub.add('Entering OE_Header_Price_Att_Util.Convert_Miss_To_Null', 2);
1895 --            l_old_Header_Price_Att_rec :=
1896             OE_Header_PAttr_Util.Convert_Miss_To_Null (l_old_Header_Price_Att_rec);
1897 
1898         ELSIF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_UPDATE
1899         OR    l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE
1900         THEN
1901 
1902             l_Header_Price_Att_rec.db_flag := FND_API.G_TRUE;
1903 
1904             --  Query Old if missing
1905 
1906             IF  l_old_Header_Price_Att_rec.order_price_attrib_id = FND_API.G_MISS_NUM
1907             THEN
1908 
1909 
1910                 OE_Header_PAttr_Util.Query_Row
1911                 (   p_order_price_attrib_id => l_Header_Price_Att_rec.order_price_attrib_id
1912                 ,   x_Header_Price_Att_rec =>  l_old_Header_Price_Att_rec
1913                 );
1914 
1915             ELSE
1916 
1917                 --  Set missing old record elements to NULL.
1918 
1919 --                l_old_Header_Price_Att_rec :=
1920                 OE_Header_PAttr_Util.Convert_Miss_To_Null (l_old_Header_Price_Att_rec);
1921 
1922             END IF;
1923 
1924             --  Complete new record from old
1925 
1926 --            l_Header_Price_Att_rec :=
1927             OE_Header_PAttr_Util.Complete_Record
1928             (   p_x_Header_Price_Att_rec              => l_Header_Price_Att_rec
1929             ,   p_old_Header_Price_Att_rec          => l_old_Header_Price_Att_rec
1930             );
1931 
1932       	   OE_MSG_PUB.update_msg_context(
1933 	 	 p_entity_code			=> 'HEADER_ADJ'
1934   		,p_entity_id         		=> l_header_Price_Att_rec.order_price_attrib_id
1935     		,p_header_id         		=> l_header_Price_Att_rec.header_Id);
1936 
1937         END IF;
1938 
1939 
1940         IF I = p_x_header_Price_Att_tbl.FIRST THEN
1941 	       IF NOT oe_order_pvt.Valid_Upgraded_Order(l_header_Price_Att_rec.header_id) THEN
1942                  RAISE FND_API.G_EXC_ERROR;
1943             END IF;
1944         END IF;
1945 
1946 
1947         --  Attribute level validation.
1948 
1949             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
1950                 oe_debug_pub.add('  In OE_Validate_Header_Pattr.Attributes');
1951                 OE_Validate_Header_Pattr.Attributes
1952                 (   x_return_status               => l_return_status
1953                 ,   p_Header_Price_Attr_rec       => l_Header_Price_Att_rec
1954                 ,   p_old_Header_Price_Attr_rec   => l_old_Header_Price_Att_rec
1955 			 ,   p_validation_level			=> p_validation_level
1956                 );
1957 
1958                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1959                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1960                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
1961                     RAISE FND_API.G_EXC_ERROR;
1962                 END IF;
1963 
1964             END IF;
1965 
1966             --  Clear dependent attributes.
1967 
1968         IF  l_control_rec.clear_dependents THEN
1969 
1970             OE_Header_PAttr_Util.Clear_Dependent_Attr
1971             (   p_x_Header_Price_Att_rec              => l_Header_Price_Att_rec
1972             ,   p_old_Header_Price_Att_rec          => l_old_Header_Price_Att_rec
1973             --,   x_Header_Price_Att_rec              => l_Header_Price_Att_rec
1974             );
1975 
1976         END IF;
1977 
1978         --  Default missing attributes
1979         IF  l_control_rec.default_attributes
1980         THEN
1981 
1982            OE_Default_Header_Pattr.Attributes
1983             (   p_x_Header_Price_Att_rec              => l_Header_Price_Att_rec
1984             --,   p_old_header_Price_Att_rec	      => l_old_header_Price_Att_rec
1985             --,   x_Header_Price_Att_rec              => l_Header_Price_Att_rec
1986             );
1987 
1988         END IF;
1989 
1990         --  Apply attribute changes
1991 
1992         IF  l_control_rec.change_attributes
1993         THEN
1994 
1995 	   -- This will also log request/s to check duplicity of
1996 	   -- price adjustment entered
1997             oe_debug_pub.add('  In apply attribute changes');
1998             OE_Header_PAttr_Util.Apply_Attribute_Changes
1999             (   p_x_Header_Price_Att_rec              => l_Header_Price_Att_rec
2000             ,   p_old_Header_Price_Att_rec          => l_old_Header_Price_Att_rec
2001             );
2002 
2003         END IF;
2004 
2005 	-- If there has any activity causing a change in any attribute
2006 	-- log a request for repricing
2007 
2008         --  Entity level validation.
2009 
2010         IF l_control_rec.validate_entity THEN
2011 
2012             IF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
2013 
2014                 OE_Validate_Header_Pattr.Entity_Delete
2015                 (   x_return_status               => l_return_status
2016                 ,   p_Header_Price_Attr_rec              => l_Header_Price_Att_rec
2017                 );
2018 
2019             ELSE
2020 
2021                 /*OE_Validate_Header_Pattr.Entity
2022                 (   x_return_status               => l_return_status
2023                 ,   p_Header_Price_Attr_rec              => l_Header_Price_Att_rec
2024                 ,   p_old_Header_Price_Attr_rec          => l_old_Header_Price_Att_rec
2025                 );*/
2026 
2027                 null;
2028 
2029             END IF;
2030 
2031             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2032                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2033             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2034                 RAISE FND_API.G_EXC_ERROR;
2035             END IF;
2036 
2037         END IF;
2038 
2039         --  Step 4. Write to DB
2040 
2041         IF l_control_rec.write_to_db THEN
2042 
2043             IF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
2044 
2045                 OE_Header_PAttr_Util.Delete_Row
2046                 (   p_order_price_attrib_id         => l_Header_Price_Att_rec.order_price_attrib_id
2047                 );
2048 
2049 		-- Log a delayed request to cause repricing due to deleted
2050 		-- record
2051 --2442012
2052 
2053    /*     		OE_delayed_requests_Pvt.log_request(
2054 				p_entity_code 			=> OE_GLOBALS.G_ENTITY_HEader_Price_Att,
2055 				p_entity_id         	=> l_Header_Price_Att_Rec.Header_Id,
2056 				p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEader_Price_Att,
2057 				p_requesting_entity_id   => l_Header_Price_Att_Rec.Header_Id,
2058 		 		p_param1                 => l_Header_Price_Att_Rec.Header_Id,
2059                  	        p_param2                 => 'LINE',
2060 		 		p_request_type           => OE_GLOBALS.G_PRICE_ORDER,
2061 		 		x_return_status          => l_return_status);
2062 
2063         		OE_delayed_requests_Pvt.log_request(
2064 				p_entity_code 			=> OE_GLOBALS.G_ENTITY_ALL,
2065 				p_entity_id         	=> l_Header_Price_Att_Rec.Header_Id,
2066 				p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2067 				p_requesting_entity_id   => l_Header_Price_Att_Rec.Header_Id,
2068 		 		p_param1                 => l_Header_Price_Att_Rec.Header_Id,
2069                  	        p_param2                 => 'ORDER',
2070 		 		p_request_type           => OE_GLOBALS.G_PRICE_ORDER,
2071 		 		x_return_status          => l_return_status);
2072 */
2073 				Begin
2074 				   -- use order_header cache instead of sql : bug 4200055
2075 				   if ( OE_Order_Cache.g_header_rec.header_id <> FND_API.G_MISS_NUM
2076 					and OE_Order_Cache.g_header_rec.header_id IS NOT NULL
2077 					and OE_Order_Cache.g_header_rec.header_id = l_header_price_att_rec.header_id ) then
2078 				            l_booked_flag := OE_Order_Cache.g_header_rec.booked_flag ;
2079 				  else
2080 				           OE_ORDER_CACHE.Load_Order_Header(l_header_price_att_rec.header_id);
2081 					   l_booked_flag := OE_Order_Cache.g_header_rec.booked_flag ;
2082 				 end if ;
2083 					/*Select booked_flag	Into
2084 						l_booked_flag
2085 					From OE_Order_Headers where
2086 					Header_id =	l_Header_Price_Att_Rec.Header_Id;
2087 					Exception when no_data_found then
2088 						Null;
2089                                          -- we shouldn't supress no_data_found error.
2090                                          */
2091 				 --end bug 4200055
2092 				End;
2093 
2094 	    			If l_booked_flag='Y' Then
2095                                  l_pricing_event := 'BATCH,BOOK,SHIP';
2096     /*       				OE_delayed_requests_Pvt.log_request(
2097 								p_entity_code 			=> OE_GLOBALS.G_ENTITY_ALL,
2098 								p_entity_id         	=> l_Header_Price_Att_Rec.Header_Id,
2099 								p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2100 								p_requesting_entity_id   => l_Header_Price_Att_Rec.Header_Id,
2101 		 						p_param1                 => l_Header_Price_Att_Rec.Header_Id,
2102                  					p_param2                 => 'BOOK',
2103 		 						p_request_type           => OE_GLOBALS.G_PRICE_ORDER,
2104 		 						x_return_status          => l_return_status);
2105   */
2106                                 Else
2107                                  l_pricing_event := 'BATCH';
2108 				End If;
2109 
2110           		OE_delayed_requests_Pvt.log_request(
2111 						p_entity_code 			=> OE_GLOBALS.G_ENTITY_ALL,
2112 						p_entity_id         	=> l_Header_Price_Att_Rec.Header_Id,
2113 						p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
2114 						p_requesting_entity_id   => l_Header_Price_Att_Rec.Header_Id,
2115                                                 p_request_unique_key1    => l_pricing_event,
2116 		 				p_param1                 => l_Header_Price_Att_Rec.Header_Id,
2117                  			p_param2                 => l_pricing_event,
2118 		 				p_request_type           => OE_GLOBALS.G_PRICE_ORDER,
2119 		 				x_return_status          => l_return_status);
2120 
2121 
2122 				IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2123 		   				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2124 		 		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2125 		   				RAISE FND_API.G_EXC_ERROR;
2126 				END IF;
2127 --2442012
2128             ELSE
2129 
2130                 --  Get Who Information
2131 
2132                 l_Header_Price_Att_rec.last_update_date := SYSDATE;
2133                 l_Header_Price_Att_rec.last_updated_by := FND_GLOBAL.USER_ID;
2134                 l_Header_Price_Att_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
2135 
2136                 IF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
2137 
2138                     OE_Header_PAttr_Util.Update_Row (l_Header_Price_Att_rec);
2139 
2140                 ELSIF l_Header_Price_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2141 
2142                     l_Header_Price_Att_rec.creation_date := SYSDATE;
2143                     l_Header_Price_Att_rec.created_by    := FND_GLOBAL.USER_ID;
2144                     oe_debug_pub.add('  Before calling pattr_util.insert_row');
2145 
2146                     select OE_ORDER_PRICE_ATTRIBS_S.nextval
2147                     into   l_header_price_att_rec.order_price_attrib_id
2148                     from dual;
2149 
2150                     OE_Header_PAttr_Util.Insert_Row (l_Header_Price_Att_rec);
2151 
2152                 END IF;
2153 
2154             END IF;
2155 
2156         END IF;
2157 
2158         --  Load tables.
2159 
2160         p_x_Header_Price_Att_tbl(I)            := l_Header_Price_Att_rec;
2161         p_x_old_Header_Price_Att_tbl(I)        := l_old_Header_Price_Att_rec;
2162 
2163          IF l_header_Price_Att_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2164                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2165          ELSIF l_header_Price_Att_rec.return_status = FND_API.G_RET_STS_ERROR THEN
2166                 RAISE FND_API.G_EXC_ERROR;
2167          END IF;
2168 /*
2169 
2170     OE_Header_PAttr_Security.g_check_all_cols_constraint := 'Y';
2171 */
2172         OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
2173     --   loop exception handler.
2174 
2175     EXCEPTION
2176 
2177         WHEN FND_API.G_EXC_ERROR THEN
2178 
2179             l_Header_Price_Att_rec.return_status := FND_API.G_RET_STS_ERROR;
2180             p_x_Header_Price_Att_tbl(I)            := l_Header_Price_Att_rec;
2181             p_x_old_Header_Price_Att_tbl(I)        := l_old_Header_Price_Att_rec;
2182 	    /*
2183     	    OE_Header_PAttr_Security.g_check_all_cols_constraint := 'Y';
2184             OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
2185 			oe_delayed_requests_pvt.delete_request
2186 			(p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_ADJ,
2187 		  	   p_entity_id => l_header_Price_Att_rec.order_price_attrib_id,
2188 	                   p_request_type => NULL,
2189 	                   x_return_status => l_return_status);
2190 				    */
2191 		IF l_control_rec.Process_Partial THEN
2192 			ROLLBACK TO SAVEPOINT Header_Price_Atts;
2193 		ELSE
2194                 RAISE FND_API.G_EXC_ERROR;
2195 	        END IF;
2196 
2197 
2198         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2199 
2200             l_Header_Price_Att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2201             p_x_Header_Price_Att_tbl(I)            := l_Header_Price_Att_rec;
2202             p_x_old_Header_Price_Att_tbl(I)        := l_old_Header_Price_Att_rec;
2203 	    /*
2204     	    OE_Header_PAttr_Security.g_check_all_cols_constraint := 'Y';
2205             OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
2206 			oe_delayed_requests_pvt.delete_request
2207 				(p_entity_code =>OE_GLOBALS.G_ENTITY_HEADER_ADJ,
2208 		  	   p_entity_id => l_header_Price_Att_rec.order_price_attrib_id,
2209 	                   p_request_type => NULL,
2210 	                   x_return_status => l_return_status);
2211 				    */
2212             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2213 
2214         WHEN OTHERS THEN
2215 
2216             l_Header_Price_Att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2217             p_x_Header_Price_Att_tbl(I)            := l_Header_Price_Att_rec;
2218             p_x_old_Header_Price_Att_tbl(I)        := l_old_Header_Price_Att_rec;
2219 
2220             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2221             THEN
2222                 OE_MSG_PUB.Add_Exc_Msg
2223                 (   G_PKG_NAME
2224                 ,   'Header_Price_Atts'
2225                 );
2226             END IF;
2227 
2228             OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
2229             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2230 
2231     END;
2232     I := p_x_Header_Price_Att_tbl.NEXT(I);
2233     END LOOP;
2234 
2235     --  Load OUT parameters
2236 
2237 
2238       oe_debug_pub.add('Exiting oe_order_Price_Att_pvt.HEADER_Price_Atts', 1);
2239       OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
2240 
2241 EXCEPTION
2242 
2243     WHEN FND_API.G_EXC_ERROR THEN
2244 
2245       OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
2246       RAISE;
2247 
2248     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2249 
2250       OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
2251       RAISE;
2252 
2253     WHEN OTHERS THEN
2254 
2255         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2256         THEN
2257             OE_MSG_PUB.Add_Exc_Msg
2258             (   G_PKG_NAME
2259             ,   'Header_Price_Atts'
2260             );
2261         END IF;
2262 
2263 
2264         OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
2265         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2266         adj_debug('Exiting oe_order_Adj_pvt.HEader_Price_Atts', 1);
2267 
2268 end HEader_Price_Atts;
2269 
2270 PROCEDURE Header_Adj_Atts
2271 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
2272 ,   p_validation_level              IN  NUMBER
2273 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
2274 ,   p_x_Header_Adj_Att_tbl          IN OUT NOCOPY OE_Order_PUB.Header_Adj_Att_Tbl_Type
2275 ,   p_x_old_Header_Adj_Att_tbl      IN OUT NOCOPY  OE_Order_PUB.Header_Adj_Att_Tbl_Type
2276 )
2277 is
2278 l_return_status               VARCHAR2(1);
2279 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
2280 l_Header_Adj_Att_rec        	OE_Order_PUB.Header_Adj_Att_Rec_Type;
2281 l_old_Header_Adj_Att_rec    	OE_Order_PUB.Header_Adj_Att_Rec_Type;
2282 -- local variables to store OUT parameters from security check procedures
2283 I 				    pls_integer; -- Used as index for while loop
2284 BEGIN
2285 
2286     IF FND_API.to_Boolean(p_init_msg_list) THEN
2287         OE_MSG_PUB.initialize;
2288     END IF;
2289 
2290 
2291 IF l_control_rec.Process_Partial THEN
2292 	SAVEPOINT Header_price_atts;
2293 END IF;
2294 
2295     --  Init local table variables.
2296 
2297 	   --dbms_output.put_line('Entering oe_order_Adj_pvt.Header_price_atts');
2298         adj_debug('Enetring oe_order_Adj_pvt.HEader_Adj_Atts', 1);
2299 
2300     I := p_x_Header_Adj_Att_tbl.FIRST;
2301 
2302     WHILE I IS NOT NULL LOOP
2303     BEGIN
2304 
2305         --  Load local records.
2306 
2307         l_Header_Adj_Att_rec := p_x_Header_Adj_Att_tbl(I);
2308 
2309         IF p_x_old_Header_Adj_Att_tbl.EXISTS(I) THEN
2310             l_old_Header_Adj_Att_rec := p_x_old_Header_Adj_Att_tbl(I);
2311         ELSE
2312             l_old_Header_Adj_Att_rec := OE_Order_PUB.G_MISS_Header_Adj_Att_REC;
2313         END IF;
2314 
2315     if l_old_Header_Adj_Att_rec.Price_Adj_attrib_id = FND_API.G_MISS_NUM  then
2316 
2317       OE_MSG_PUB.set_msg_context(
2318 	 p_entity_code			=> 'ADJ_ATTS'
2319   	,p_entity_id         		=> l_Header_Adj_Att_rec.Price_adj_attrib_id);
2320 
2321     else
2322 
2323       OE_MSG_PUB.set_msg_context(
2324 	 p_entity_code			=> 'ADJ_ATTS'
2325   	,p_entity_id         		=> l_old_Header_Adj_Att_rec.Price_adj_attrib_id);
2326 
2327     end if;
2328 
2329         --  Load API control record
2330 
2331         l_control_rec := OE_GLOBALS.Init_Control_Rec
2332         (   p_operation     => l_Header_Adj_Att_rec.operation
2333         ,   p_control_rec   => p_control_rec
2334         );
2335 
2336         --  Set record return status.
2337 
2338         l_Header_Adj_Att_rec.return_status := FND_API.G_RET_STS_SUCCESS;
2339 
2340         --  Prepare record.
2341 
2342         IF l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2343 
2344             l_Header_Adj_Att_rec.db_flag := FND_API.G_FALSE;
2345 
2346             --  Set missing old record elements to NULL.
2347 
2348    		 adj_debug('Entering OE_Header_Adj_Att_Util.Convert_Miss_To_Null', 1);
2349 --            l_old_Header_Adj_Att_rec :=
2350             Oe_Header_Price_Aattr_util.Convert_Miss_To_Null (l_old_Header_Adj_Att_rec);
2351 
2352         ELSIF l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2353         OR    l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE
2354         THEN
2355 
2356             l_Header_Adj_Att_rec.db_flag := FND_API.G_TRUE;
2357 
2358             --  Query Old if missing
2359 
2360             IF  l_old_Header_Adj_Att_rec.Price_adj_attrib_id = FND_API.G_MISS_NUM
2361             THEN
2362 
2363 
2364                 Oe_Header_Price_Aattr_util.Query_Row
2365                 (   p_Price_Adj_Attrib_id => l_Header_Adj_Att_rec.Price_adj_attrib_id
2366                 ,   x_Header_Adj_Att_rec  => l_old_Header_Adj_Att_rec
2367                 );
2368 
2369             ELSE
2370 
2371                 --  Set missing old record elements to NULL.
2372 
2373 --                l_old_Header_Adj_Att_rec :=
2374                 Oe_Header_Price_Aattr_util.Convert_Miss_To_Null (l_old_Header_Adj_Att_rec);
2375 
2376             END IF;
2377 
2378             --  Complete new record from old
2379 
2380 --            l_Header_Adj_Att_rec :=
2381             Oe_Header_Price_Aattr_util.Complete_Record
2382             (   p_x_Header_Adj_Att_rec              => l_Header_Adj_Att_rec
2383             ,   p_old_Header_Adj_Att_rec          => l_old_Header_Adj_Att_rec
2384             );
2385 
2386       	   OE_MSG_PUB.update_msg_context(
2387 	 	 p_entity_code			=> 'ADJ_ATTS'
2388   		,p_entity_id         		=> l_Header_Adj_Att_rec.Price_adj_attrib_id);
2389 
2390         END IF;
2391 
2392         --  Default missing attributes
2393         IF  l_control_rec.default_attributes
2394         THEN
2395 
2396            OE_DEfault_Header_Aattr.Attributes
2397             (   p_Header_Adj_Att_rec              => l_Header_Adj_Att_rec
2398             --,   x_Header_Adj_Att_rec              => l_Header_Adj_Att_rec
2399             );
2400 
2401         END IF;
2402 
2403         --  Apply attribute changes
2404 
2405         IF  l_control_rec.change_attributes
2406         THEN
2407 
2408 	   -- This will also log request/s to check duplicity of
2409 	   -- price adjustment entered
2410             Oe_Header_Price_Aattr_util.Apply_Attribute_Changes
2411             (   p_x_Header_Adj_Att_rec              => l_Header_Adj_Att_rec
2412             ,   p_old_Header_Adj_Att_rec          => l_old_Header_Adj_Att_rec
2413             --,   x_Header_Adj_Att_rec              => l_Header_Adj_Att_rec
2414             );
2415 
2416         END IF;
2417 
2418 	-- If there has any activity causing a change in any attribute
2419 	-- log a request for repricing
2420 
2421         --  Entity level validation.
2422 
2423         --  Step 4. Write to DB
2424 
2425         IF l_control_rec.write_to_db THEN
2426 
2427             IF l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
2428 
2429                 Oe_Header_Price_Aattr_util.Delete_Row
2430                 (   p_Price_Adj_Attrib_id         => l_Header_Adj_Att_rec.Price_adj_attrib_id
2431                 );
2432 
2433             ELSE
2434 
2435                 --  Get Who Information
2436 
2437                 l_Header_Adj_Att_rec.last_update_date := SYSDATE;
2438                 l_Header_Adj_Att_rec.last_updated_by := FND_GLOBAL.USER_ID;
2439                 l_Header_Adj_Att_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
2440 
2441                 IF l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
2442 
2443                     Oe_Header_Price_Aattr_util.Update_Row (l_Header_Adj_Att_rec);
2444 
2445                 ELSIF l_Header_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2446 
2447                     l_Header_Adj_Att_rec.creation_date := SYSDATE;
2448                     l_Header_Adj_Att_rec.created_by    := FND_GLOBAL.USER_ID;
2449 
2450                     Oe_Header_Price_Aattr_util.Insert_Row (l_Header_Adj_Att_rec);
2451 
2452                 END IF;
2453 
2454             END IF;
2455 
2456         END IF;
2457 
2458         --  Load tables.
2459 
2460         p_x_Header_Adj_Att_tbl(I)            := l_Header_Adj_Att_rec;
2461         p_x_old_Header_Adj_Att_tbl(I)        := l_old_Header_Adj_Att_rec;
2462 
2463          IF l_Header_Adj_Att_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2464                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2465          ELSIF l_Header_Adj_Att_rec.return_status = FND_API.G_RET_STS_ERROR THEN
2466                 RAISE FND_API.G_EXC_ERROR;
2467          END IF;
2468 
2469         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2470     --   loop exception handler.
2471 
2472     EXCEPTION
2473 
2474         WHEN FND_API.G_EXC_ERROR THEN
2475 
2476             l_Header_Adj_Att_rec.return_status := FND_API.G_RET_STS_ERROR;
2477             p_x_Header_Adj_Att_tbl(I)            := l_Header_Adj_Att_rec;
2478             p_x_old_Header_Adj_Att_tbl(I)        := l_old_Header_Adj_Att_rec;
2479 
2480 		IF l_control_rec.Process_Partial THEN
2481 			ROLLBACK TO SAVEPOINT Header_price_atts;
2482 		ELSE
2483                 RAISE FND_API.G_EXC_ERROR;
2484 	        END IF;
2485 
2486 
2487         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2488 
2489             l_Header_Adj_Att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2490             p_x_Header_Adj_Att_tbl(I)            := l_Header_Adj_Att_rec;
2491             p_x_old_Header_Adj_Att_tbl(I)        := l_old_Header_Adj_Att_rec;
2492 
2493             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2494 
2495         WHEN OTHERS THEN
2496 
2497             l_Header_Adj_Att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2498             p_x_Header_Adj_Att_tbl(I)            := l_Header_Adj_Att_rec;
2499             p_x_old_Header_Adj_Att_tbl(I)        := l_old_Header_Adj_Att_rec;
2500 
2501             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2502             THEN
2503                 OE_MSG_PUB.Add_Exc_Msg
2504                 (   G_PKG_NAME
2505                 ,   'Header_price_atts'
2506                 );
2507             END IF;
2508 
2509             OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2510             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2511 
2512     END;
2513     I := p_x_Header_Adj_Att_tbl.NEXT(I);
2514     END LOOP;
2515 
2516     --  Load OUT parameters
2517 
2518       adj_debug('Exiting oe_order_Adj_pvt.Header_Adj_Atts', 1);
2519       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2520 
2521 EXCEPTION
2522 
2523     WHEN FND_API.G_EXC_ERROR THEN
2524 
2525       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2526       RAISE;
2527 
2528     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2529 
2530       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2531       RAISE;
2532 
2533     WHEN OTHERS THEN
2534 
2535         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2536         THEN
2537             OE_MSG_PUB.Add_Exc_Msg
2538             (   G_PKG_NAME
2539             ,   'Header_Adj_Atts'
2540             );
2541         END IF;
2542 
2543 
2544         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2545         adj_debug('Exiting oe_order_Adj_pvt.HEader_Adj_Atts', 1);
2546 
2547 end Header_Adj_Atts;
2548 
2549 PROCEDURE Header_Adj_Assocs
2550 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
2551 ,   p_validation_level              IN  NUMBER
2552 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
2553 ,   p_x_Header_Adj_Assoc_tbl        IN OUT NOCOPY  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
2554 ,   p_x_old_Header_Adj_Assoc_tbl    IN OUT NOCOPY  OE_Order_PUB.Header_Adj_Assoc_Tbl_Type
2555 )
2556 is
2557 l_return_status               VARCHAR2(1);
2558 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
2559 l_Header_Adj_Assoc_rec        	OE_Order_PUB.Header_Adj_Assoc_Rec_Type;
2560 l_old_Header_Adj_Assoc_rec    	OE_Order_PUB.Header_Adj_Assoc_Rec_Type;
2561 -- local variables to store OUT parameters from security check procedures
2562 I 				    pls_integer; -- Used as index for while loop
2563 BEGIN
2564 
2565     IF FND_API.to_Boolean(p_init_msg_list) THEN
2566         OE_MSG_PUB.initialize;
2567     END IF;
2568 
2569 IF l_control_rec.Process_Partial THEN
2570 	SAVEPOINT Header_Adj_Assocs;
2571 END IF;
2572 
2573     --  Init local table variables.
2574 
2575 	   --dbms_output.put_line('Entering oe_order_Adj_pvt.HEader_Price_assocs');
2576         adj_debug('Enetring oe_order_Adj_pvt.Header_Adj_Assocs', 1);
2577 
2578 
2579     I := p_x_Header_Adj_Assoc_tbl.FIRST;
2580 
2581     WHILE I IS NOT NULL LOOP
2582     BEGIN
2583 
2584         --  Load local records.
2585 
2586         l_Header_Adj_Assoc_rec := p_x_Header_Adj_Assoc_tbl(I);
2587 
2588         IF p_x_old_Header_Adj_Assoc_tbl.EXISTS(I) THEN
2589             l_old_Header_Adj_Assoc_rec := p_x_old_Header_Adj_Assoc_tbl(I);
2590         ELSE
2591             l_old_Header_Adj_Assoc_rec := OE_Order_PUB.G_MISS_Header_Adj_Assoc_REC;
2592         END IF;
2593 
2594     if l_old_Header_Adj_Assoc_rec.Price_Adj_assoc_id = FND_API.G_MISS_NUM  then
2595 
2596       OE_MSG_PUB.set_msg_context(
2597 	 p_entity_code			=> 'ADJ_ATTS'
2598   	,p_entity_id         		=> l_Header_Adj_Assoc_rec.Price_Adj_assoc_id);
2599 
2600     else
2601 
2602       OE_MSG_PUB.set_msg_context(
2603 	 p_entity_code			=> 'ADJ_ATTS'
2604   	,p_entity_id         		=> l_old_Header_Adj_Assoc_rec.Price_Adj_assoc_id);
2605 
2606     end if;
2607 
2608         --  Load API control record
2609 
2610         l_control_rec := OE_GLOBALS.Init_Control_Rec
2611         (   p_operation     => l_Header_Adj_Assoc_rec.operation
2612         ,   p_control_rec   => p_control_rec
2613         );
2614 
2615         --  Set record return status.
2616 
2617         l_Header_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_SUCCESS;
2618 
2619         --  Prepare record.
2620 
2621         IF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2622 
2623             l_Header_Adj_Assoc_rec.db_flag := FND_API.G_FALSE;
2624 
2625             --  Set missing old record elements to NULL.
2626 
2627    		 adj_debug('Entering OE_Header_Adj_Assoc_Util.Convert_Miss_To_Null', 1);
2628 --            l_old_Header_Adj_Assoc_rec :=
2629             Oe_Header_Adj_Assocs_util.Convert_Miss_To_Null (l_old_Header_Adj_Assoc_rec);
2630 
2631         ELSIF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_UPDATE
2632         OR    l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_DELETE
2633         THEN
2634 
2635             l_Header_Adj_Assoc_rec.db_flag := FND_API.G_TRUE;
2636 
2637             --  Query Old if missing
2638 
2639             IF  l_old_Header_Adj_Assoc_rec.Price_Adj_assoc_id = FND_API.G_MISS_NUM
2640             THEN
2641 
2642 
2643                 Oe_Header_Adj_Assocs_util.Query_Row
2644                 (   p_Price_Adj_assoc_id => l_Header_Adj_Assoc_rec.Price_Adj_assoc_id
2645                 ,   x_header_adj_Assoc_rec =>                 l_old_Header_Adj_Assoc_rec
2646                 );
2647 
2648             ELSE
2649 
2650                 --  Set missing old record elements to NULL.
2651 
2652 --                l_old_Header_Adj_Assoc_rec :=
2653                 Oe_Header_Adj_Assocs_util.Convert_Miss_To_Null (l_old_Header_Adj_Assoc_rec);
2654 
2655             END IF;
2656 
2657             --  Complete new record from old
2658 
2659 --            l_Header_Adj_Assoc_rec :=
2660             Oe_Header_Adj_Assocs_util.Complete_Record
2661             (   p_x_Header_Adj_Assoc_rec              => l_Header_Adj_Assoc_rec
2662             ,   p_old_Header_Adj_Assoc_rec          => l_old_Header_Adj_Assoc_rec
2663             );
2664 
2665       	   OE_MSG_PUB.update_msg_context(
2666 	 	 p_entity_code			=> 'ADJ_ATTS'
2667   		,p_entity_id         		=> l_Header_Adj_Assoc_rec.Price_Adj_assoc_id);
2668 
2669         END IF;
2670 
2671         --  Default missing attributes
2672         IF  l_control_rec.default_attributes
2673         THEN
2674 
2675            OE_DEfault_Header_Adj_Assocs.Attributes
2676             (   p_x_Header_Adj_Assoc_rec              => l_Header_Adj_Assoc_rec
2677             --,   x_Header_Adj_Assoc_rec              => l_Header_Adj_Assoc_rec
2678             );
2679 
2680         END IF;
2681 
2682         --  Apply attribute changes
2683 
2684         IF  l_control_rec.change_attributes
2685         THEN
2686 
2687 	   -- This will also log request/s to check duplicity of
2688 	   -- price adjustment entered
2689             Oe_Header_Adj_Assocs_util.Apply_Attribute_Changes
2690             (   p_x_Header_Adj_Assoc_rec              => l_Header_Adj_Assoc_rec
2691             ,   p_old_Header_Adj_Assoc_rec          => l_old_Header_Adj_Assoc_rec
2692             --,   x_Header_Adj_Assoc_rec              => l_Header_Adj_Assoc_rec
2693             );
2694 
2695         END IF;
2696 
2697 	-- If there has any activity causing a change in any attribute
2698 	-- log a request for repricing
2699 
2700         --  Entity level validation.
2701 
2702         --  Step 4. Write to DB
2703 
2704         IF l_control_rec.write_to_db THEN
2705 
2706             IF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
2707 
2708                 Oe_Header_Adj_Assocs_util.Delete_Row
2709                 (   p_Price_Adj_assoc_id         => l_Header_Adj_Assoc_rec.Price_Adj_assoc_id
2710                 );
2711 
2712             ELSE
2713 
2714                 --  Get Who Information
2715 
2716                 l_Header_Adj_Assoc_rec.last_update_date := SYSDATE;
2717                 l_Header_Adj_Assoc_rec.last_updated_by := FND_GLOBAL.USER_ID;
2718                 l_Header_Adj_Assoc_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
2719 
2720                 IF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
2721 
2722                     Oe_Header_Adj_Assocs_util.Update_Row (l_Header_Adj_Assoc_rec);
2723 
2724                 ELSIF l_Header_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
2725 
2726                     l_Header_Adj_Assoc_rec.creation_date := SYSDATE;
2727                     l_Header_Adj_Assoc_rec.created_by    := FND_GLOBAL.USER_ID;
2728 
2729                     Oe_Header_Adj_Assocs_util.Insert_Row (l_Header_Adj_Assoc_rec);
2730 
2731                 END IF;
2732 
2733             END IF;
2734 
2735         END IF;
2736 
2737         --  Load tables.
2738 
2739         p_x_Header_Adj_Assoc_tbl(I)            := l_Header_Adj_Assoc_rec;
2740         p_x_old_Header_Adj_Assoc_tbl(I)        := l_old_Header_Adj_Assoc_rec;
2741 
2742          IF l_Header_Adj_Assoc_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2743                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2744          ELSIF l_Header_Adj_Assoc_rec.return_status = FND_API.G_RET_STS_ERROR THEN
2745                 RAISE FND_API.G_EXC_ERROR;
2746          END IF;
2747 
2748         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2749     --   loop exception handler.
2750 
2751     EXCEPTION
2752 
2753         WHEN FND_API.G_EXC_ERROR THEN
2754 
2755             l_Header_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_ERROR;
2756             p_x_Header_Adj_Assoc_tbl(I)            := l_Header_Adj_Assoc_rec;
2757             p_x_old_Header_Adj_Assoc_tbl(I)        := l_old_Header_Adj_Assoc_rec;
2758 
2759 		IF l_control_rec.Process_Partial THEN
2760 			ROLLBACK TO SAVEPOINT Header_Price_Assocs;
2761 		ELSE
2762                 RAISE FND_API.G_EXC_ERROR;
2763 	        END IF;
2764 
2765 
2766         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2767 
2768             l_Header_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2769             p_x_Header_Adj_Assoc_tbl(I)            := l_Header_Adj_Assoc_rec;
2770             p_x_old_Header_Adj_Assoc_tbl(I)        := l_old_Header_Adj_Assoc_rec;
2771 
2772             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2773 
2774         WHEN OTHERS THEN
2775 
2776             l_Header_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2777             p_x_Header_Adj_Assoc_tbl(I)            := l_Header_Adj_Assoc_rec;
2778             p_x_old_Header_Adj_Assoc_tbl(I)        := l_old_Header_Adj_Assoc_rec;
2779 
2780             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2781             THEN
2782                 OE_MSG_PUB.Add_Exc_Msg
2783                 (   G_PKG_NAME
2784                 ,   'Header_price_atts'
2785                 );
2786             END IF;
2787 
2788             OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2789             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2790 
2791     END;
2792     I := p_x_Header_Adj_Assoc_tbl.NEXT(I);
2793     END LOOP;
2794 
2795     --  Load OUT parameters
2796 
2797       adj_debug('Exiting oe_order_Adj_pvt.Header_Adj_Assocs', 1);
2798       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2799 
2800 EXCEPTION
2801 
2802     WHEN FND_API.G_EXC_ERROR THEN
2803 
2804       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2805       RAISE;
2806 
2807     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2808 
2809       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2810       RAISE;
2811 
2812     WHEN OTHERS THEN
2813 
2814         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2815         THEN
2816             OE_MSG_PUB.Add_Exc_Msg
2817             (   G_PKG_NAME
2818             ,   'Header_Adj_Assocs'
2819             );
2820         END IF;
2821 
2822 
2823         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
2824         adj_debug('Exiting oe_order_Adj_pvt.Header_Adj_Assocs', 1);
2825 end Header_Adj_Assocs;
2826 
2827 PROCEDURE Line_Price_Atts
2828 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
2829 ,   p_validation_level              IN  NUMBER
2830 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
2831 ,   p_x_Line_Price_Att_tbl          IN OUT NOCOPY  OE_Order_PUB.Line_Price_Att_Tbl_Type
2832 ,   p_x_old_Line_Price_Att_tbl      IN OUT NOCOPY  OE_Order_PUB.Line_Price_Att_Tbl_Type
2833 )
2834 is
2835 l_return_status               VARCHAR2(1);
2836 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
2837 l_Line_price_att_rec        OE_Order_PUB.Line_Price_Att_Rec_Type;
2838 l_old_Line_price_att_rec    OE_Order_PUB.Line_Price_Att_Rec_Type;
2839 -- local variables to store OUT parameters from security check procedures
2840 l_sec_result            NUMBER;
2841 l_on_operation_action   NUMBER;
2842 I 				    pls_integer; -- Used as index for while loop
2843 l_booked_flag			varchar2(1);
2844 l_Shipped_quantity		number;
2845 l_pricing_event                 varchar2(30);
2846 
2847 --
2848 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2849 --
2850 l_order_source_id           NUMBER;
2851 l_orig_sys_document_ref     VARCHAR2(50);
2852 l_orig_sys_line_ref     VARCHAR2(50);
2853 l_orig_sys_shipment_ref     VARCHAR2(50);
2854 l_change_sequence           VARCHAR2(50);
2855 l_source_document_type_id   NUMBER;
2856 l_source_document_id        NUMBER;
2857 l_source_document_line_id        NUMBER;
2858 
2859 BEGIN
2860 l_control_rec := p_control_rec;  -- Added for 1433292
2861     IF FND_API.to_Boolean(p_init_msg_list) THEN
2862         OE_MSG_PUB.initialize;
2863     END IF;
2864 
2865 IF l_control_rec.Process_Partial THEN
2866 	SAVEPOINT Line_price_atts;
2867 END IF;
2868 
2869     --  Init local table variables.
2870 
2871 	   --dbms_output.put_line('Entering oe_order_Adj_pvt.Line_price_atts');
2872         adj_debug('Entering oe_order_Adj_pvt.Line_price_atts', 1);
2873 
2874     I := p_x_Line_price_att_tbl.FIRST;
2875 
2876     WHILE I IS NOT NULL LOOP
2877     BEGIN
2878 
2879         --  Load local records.
2880 
2881         l_Line_price_att_rec := p_x_Line_price_att_tbl(I);
2882 
2883         IF p_x_old_Line_price_att_tbl.EXISTS(I) THEN
2884             l_old_Line_price_att_rec := p_x_old_Line_price_att_tbl(I);
2885         ELSE
2886             l_old_Line_price_att_rec := OE_Order_PUB.G_MISS_Line_Price_Att_REC;
2887         END IF;
2888 
2889     if l_old_Line_price_att_rec.Order_price_attrib_id = FND_API.G_MISS_NUM  then
2890 
2891       IF l_Line_price_att_rec.Line_Id IS NOT NULL AND
2892          l_Line_price_att_rec.Line_Id <> FND_API.G_MISS_NUM THEN
2893          BEGIN
2894             IF l_debug_level  > 0 THEN
2895                oe_debug_pub.add('Getting reference data for line_id:'||l_Line_price_att_rec.Line_Id);
2896             END IF;
2897             SELECT order_source_id, orig_sys_document_ref, change_sequence,
2898             source_document_type_id, source_document_id, orig_sys_line_ref,
2899             source_document_line_id, orig_sys_shipment_ref
2900             INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
2901             l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
2902             l_source_document_line_id, l_orig_sys_shipment_ref
2903             FROM   OE_ORDER_LINES_ALL
2904             WHERE  line_id = l_Line_price_att_rec.Line_Id;
2905          EXCEPTION
2906             WHEN NO_DATA_FOUND THEN
2907                 l_order_source_id := null;
2908                 l_orig_sys_document_ref := null;
2909                 l_change_sequence := null;
2910                 l_source_document_type_id := null;
2911                 l_source_document_id := null;
2912                 l_orig_sys_line_ref := null;
2913                 l_source_document_line_id := null;
2914                 l_orig_sys_shipment_ref := null;
2915             WHEN OTHERS THEN
2916                 l_order_source_id := null;
2917                 l_orig_sys_document_ref := null;
2918                 l_change_sequence := null;
2919                 l_source_document_type_id := null;
2920                 l_source_document_id := null;
2921                 l_orig_sys_line_ref := null;
2922                 l_source_document_line_id := null;
2923                 l_orig_sys_shipment_ref := null;
2924          END;
2925       END IF;
2926 
2927       OE_MSG_PUB.set_msg_context(
2928 	 p_entity_code			=> 'LINE_PATTS'
2929   	,p_entity_id         		=> l_Line_price_att_rec.Order_price_attrib_id
2930     	,p_header_id         		=> l_Line_price_att_rec.header_Id
2931     	,p_line_id           		=> l_Line_price_att_rec.Line_Id
2932         ,p_order_source_id              => l_order_source_id
2933         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
2934         ,p_orig_sys_document_line_ref   => l_orig_sys_line_ref
2935         ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
2936         ,p_change_sequence              => l_change_sequence
2937         ,p_source_document_type_id      => l_source_document_type_id
2938         ,p_source_document_id           => l_source_document_id
2939         ,p_source_document_line_id      => l_source_document_line_id );
2940 
2941     else
2942 
2943       IF l_old_Line_price_att_rec.Line_Id IS NOT NULL AND
2944          l_old_Line_price_att_rec.Line_Id <> FND_API.G_MISS_NUM THEN
2945          BEGIN
2946                IF l_debug_level  > 0 THEN
2947                   oe_debug_pub.add('Getting reference data for old line_id:'||l_old_Line_price_att_rec.Line_Id);
2948                END IF;
2949                SELECT order_source_id, orig_sys_document_ref, change_sequence,
2950                source_document_type_id, source_document_id, orig_sys_line_ref,
2951                source_document_line_id, orig_sys_shipment_ref
2952                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
2953                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
2954                l_source_document_line_id, l_orig_sys_shipment_ref
2955                FROM   OE_ORDER_LINES_ALL
2956                WHERE  line_id = l_old_Line_price_att_rec.Line_Id;
2957          EXCEPTION
2958                WHEN NO_DATA_FOUND THEN
2959                    l_order_source_id := null;
2960                    l_orig_sys_document_ref := null;
2961                    l_change_sequence := null;
2962                    l_source_document_type_id := null;
2963                    l_source_document_id := null;
2964                    l_orig_sys_line_ref := null;
2965                    l_source_document_line_id := null;
2966                    l_orig_sys_shipment_ref := null;
2967                WHEN OTHERS THEN
2968                    l_order_source_id := null;
2969                    l_orig_sys_document_ref := null;
2970                    l_change_sequence := null;
2971                    l_source_document_type_id := null;
2972                    l_source_document_id := null;
2973                    l_orig_sys_line_ref := null;
2974                    l_source_document_line_id := null;
2975                    l_orig_sys_shipment_ref := null;
2976          END;
2977       END IF;
2978 
2979       OE_MSG_PUB.set_msg_context(
2980 	 p_entity_code			=> 'LINE_PATTS'
2981   	,p_entity_id         		=> l_old_Line_price_att_rec.Order_price_attrib_id
2982     	,p_header_id         		=> l_old_Line_price_att_rec.header_Id
2983     	,p_line_id           		=> l_old_Line_price_att_rec.Line_Id
2984         ,p_order_source_id              => l_order_source_id
2985         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
2986         ,p_orig_sys_document_line_ref   => l_orig_sys_line_ref
2987         ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
2988         ,p_change_sequence              => l_change_sequence
2989         ,p_source_document_type_id      => l_source_document_type_id
2990         ,p_source_document_id           => l_source_document_id
2991         ,p_source_document_line_id      => l_source_document_line_id );
2992 
2993     end if;
2994 
2995         --  Load API control record
2996 
2997         l_control_rec := OE_GLOBALS.Init_Control_Rec
2998         (   p_operation     => l_Line_price_att_rec.operation
2999         ,   p_control_rec   => p_control_rec
3000         );
3001 
3002         --  Set record return status.
3003 
3004         l_Line_price_att_rec.return_status := FND_API.G_RET_STS_SUCCESS;
3005 
3006         --  Prepare record.
3007 
3008         IF l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3009 
3010             l_Line_price_att_rec.db_flag := FND_API.G_FALSE;
3011 
3012             --  Set missing old record elements to NULL.
3013 
3014    		 adj_debug('Entering OE_Line_price_att_Util.Convert_Miss_To_Null', 1);
3015 --            l_old_Line_price_att_rec :=
3016             OE_Line_Pattr_Util.Convert_Miss_To_Null (l_old_Line_price_att_rec);
3017 
3018         ELSIF l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_UPDATE
3019         OR    l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_DELETE
3020         THEN
3021 
3022             l_Line_price_att_rec.db_flag := FND_API.G_TRUE;
3023 
3024             --  Query Old if missing
3025 
3026             IF  l_old_Line_price_att_rec.order_price_attrib_id = FND_API.G_MISS_NUM
3027             THEN
3028 
3029                 OE_Line_Pattr_Util.Query_Row
3030                 (   p_order_price_attrib_id => l_Line_price_att_rec.order_price_attrib_id
3031                 ,    x_Line_price_att_rec =>                 l_old_Line_price_att_rec
3032                 );
3033 
3034             ELSE
3035 
3036                 --  Set missing old record elements to NULL.
3037 
3038 --                l_old_Line_price_att_rec :=
3039                 OE_Line_Pattr_Util.Convert_Miss_To_Null (l_old_Line_price_att_rec);
3040 
3041             END IF;
3042 
3043             --  Complete new record from old
3044 
3045 --            l_Line_price_att_rec :=
3046             OE_Line_Pattr_Util.Complete_Record
3047             (   p_x_Line_price_att_rec              => l_Line_Price_Att_rec
3048             ,   p_old_Line_price_att_rec          => l_old_Line_Price_Att_rec
3049             );
3050 
3051       	   OE_MSG_PUB.update_msg_context(
3052 	 	 p_entity_code			=> 'LINE_PATTS'
3053   		,p_entity_id         		=> l_Line_price_att_rec.order_price_attrib_id
3054     		,p_header_id         		=> l_Line_price_att_rec.header_Id
3055     		,p_line_id           		=> l_Line_price_att_rec.line_id);
3056 
3057         END IF;
3058 
3059 
3060         IF I = p_x_line_Price_Att_tbl.FIRST THEN
3061 	       IF NOT oe_order_pvt.Valid_Upgraded_Order(l_line_Price_Att_rec.header_id) THEN
3062                  RAISE FND_API.G_EXC_ERROR;
3063             END IF;
3064         END IF;
3065 
3066 /*
3067    -- Check security
3068    IF l_control_rec.check_security
3069       AND (l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_CREATE
3070          OR l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_UPDATE)
3071    THEN
3072 
3073         adj_debug('Check Attributes Security');
3074         -- check if this operation is allowed
3075         -- on all the changed attributes
3076            OE_Line_price_att_Security.Attributes
3077                 (p_Line_price_att_rec   	=> l_Line_Price_Att_rec
3078                 , p_old_Line_price_att_rec	=> l_old_Line_Price_Att_rec
3079                 , x_result      	=> l_sec_result
3080                 , x_return_status 	=> l_return_status
3081                 );
3082 
3083             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3084                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3085             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3086                 RAISE FND_API.G_EXC_ERROR;
3087             END IF;
3088 
3089            IF l_sec_result = OE_PC_GLOBALS.YES THEN
3090                 RAISE FND_API.G_EXC_ERROR;
3091            END IF;
3092 
3093     END IF;
3094 */
3095         --  Attribute level validation.
3096 
3097             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
3098 
3099                 OE_Validate_Line_Pattr.Attributes
3100                 (   x_return_status               => l_return_status
3101                 ,   p_Line_price_attr_rec         => l_Line_Price_Att_rec
3102                 ,   p_old_Line_price_attr_rec     => l_old_Line_Price_Att_rec
3103 			 ,   p_validation_level			=> p_validation_level
3104                 );
3105 
3106                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3107                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3108                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3109                     RAISE FND_API.G_EXC_ERROR;
3110                 END IF;
3111 
3112             END IF;
3113 
3114             --  Clear dependent attributes.
3115 
3116         IF  l_control_rec.clear_dependents THEN
3117 
3118             OE_Line_Pattr_Util.Clear_Dependent_Attr
3119             (   p_x_Line_price_att_rec              => l_Line_Price_Att_rec
3120             ,   p_old_Line_price_att_rec          => l_old_Line_Price_Att_rec
3121             --,   x_Line_price_att_rec              => l_Line_Price_Att_rec
3122             );
3123 
3124         END IF;
3125 
3126         --  Default missing attributes
3127         IF  l_control_rec.default_attributes
3128         THEN
3129 
3130            OE_Default_Line_Pattr.Attributes
3131             (   p_x_Line_price_att_rec              => l_Line_Price_Att_rec
3132             --,   p_old_Line_price_att_rec	      => l_old_Line_Price_Att_rec
3133             --,   x_Line_price_att_rec              => l_Line_Price_Att_rec
3134             );
3135 
3136         END IF;
3137 
3138         --  Apply attribute changes
3139 
3140         IF  l_control_rec.change_attributes
3141         THEN
3142 
3143 	   -- This will also log request/s to check duplicity of
3144 	   -- price adjustment entered
3145             OE_Line_Pattr_Util.Apply_Attribute_Changes
3146             (   p_x_Line_price_att_rec              => l_Line_Price_Att_rec
3147             ,   p_old_Line_price_att_rec          => l_old_Line_Price_Att_rec
3148             --,   x_Line_price_att_rec              => l_Line_Price_Att_rec
3149             );
3150 
3151         END IF;
3152 
3153 	-- If there has any activity causing a change in any attribute
3154 	-- log a request for repricing
3155 
3156         --  Entity level validation.
3157 
3158         IF l_control_rec.validate_entity THEN
3159 
3160             IF l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
3161 
3162                 OE_Validate_Line_Pattr.Entity_Delete
3163                 (   x_return_status               => l_return_status
3164                 ,   p_Line_price_attr_rec              => l_Line_Price_Att_rec
3165                 );
3166 
3167             ELSE
3168 
3169                 /*OE_Validate_Line_Pattr.Entity
3170                 (   x_return_status               => l_return_status
3171                 ,   p_Line_price_attr_rec              => l_Line_Price_Att_rec
3172                 ,   p_old_Line_price_attr_rec          => l_old_Line_Price_Att_rec
3173                 );*/
3174 
3175                NULL;
3176 
3177             END IF;
3178 
3179             IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3180                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3181             ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3182                 RAISE FND_API.G_EXC_ERROR;
3183             END IF;
3184 
3185         END IF;
3186 
3187         --  Step 4. Write to DB
3188 
3189         IF l_control_rec.write_to_db THEN
3190 
3191             IF l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
3192 
3193                 OE_Line_Pattr_Util.Delete_Row
3194                 (   p_order_price_attrib_id         => l_Line_price_att_rec.order_price_attrib_id
3195                 );
3196 --2442012
3197     /*    		OE_delayed_requests_Pvt.log_request(
3198 				p_entity_code 			=> OE_GLOBALS.G_ENTITY_Line_Price_Att,
3199 				p_entity_id         	=> l_Line_Price_Att_rec.line_id,
3200 				p_requesting_entity_code => OE_GLOBALS.G_ENTITY_Line_Price_Att,
3201 				p_requesting_entity_id   => l_Line_Price_Att_rec.line_id,
3202 		 		p_param1                 => l_Line_Price_Att_rec.header_id,
3203                  	        p_param2                 => 'LINE',
3204 		 		p_request_type           => OE_GLOBALS.G_PRICE_LINE,
3205 		 		x_return_status          => l_return_status);
3206 
3207         		OE_delayed_requests_Pvt.log_request(
3208 				p_entity_code 			=> OE_GLOBALS.G_ENTITY_ALL,
3209 				p_entity_id         	=> l_Line_Price_Att_rec.Header_Id,
3210 				p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
3211 				p_requesting_entity_id   => l_Line_Price_Att_rec.Header_Id,
3212 		 		p_param1                 => l_Line_Price_Att_rec.header_id,
3213                  	p_param2                 => 'ORDER',
3214 		 		p_request_type           => OE_GLOBALS.G_PRICE_ORDER,
3215 		 		x_return_status          => l_return_status);
3216  */
3217 			Begin
3218 				Select booked_flag,Shipped_quantity into
3219 				l_booked_flag,l_Shipped_quantity
3220 				From OE_Order_lines where
3221 				Line_id =	l_Line_Price_Att_rec.Line_Id;
3222 				Exception when no_data_found then
3223 				Null;
3224 			End;
3225 
3226 	    		If l_booked_flag='Y' Then
3227                            l_pricing_event := 'ORDER,BOOK';
3228                         Else
3229                            l_pricing_event := 'ORDER';
3230                         End If;
3231            		OE_delayed_requests_Pvt.log_request(
3232 					p_entity_code 			=> OE_GLOBALS.G_ENTITY_ALL,
3233 					p_entity_id         	=> l_Line_Price_Att_rec.Header_Id,
3234 					p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
3235 					p_requesting_entity_id   => l_Line_Price_Att_rec.Header_Id,
3236                                         p_request_unique_key1    => l_pricing_event,
3237 		 			p_param1                 => l_Line_Price_Att_rec.header_id,
3238                  		        p_param2                 => l_pricing_event,
3239 		 			p_request_type           => OE_GLOBALS.G_PRICE_ORDER,
3240 		 			x_return_status          => l_return_status);
3241 --			End If;
3242 
3243 	    		If l_Shipped_quantity > 0 Then
3244                          l_pricing_event := 'LINE,SHIP';
3245                         Else
3246                          l_pricing_event := 'LINE';
3247                         End if;
3248            		OE_delayed_requests_Pvt.log_request(
3249 					p_entity_code 			=> OE_GLOBALS.G_ENTITY_ALL,
3250 					p_entity_id         	=> l_Line_Price_Att_rec.Line_Id,
3251 					p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
3252 					p_requesting_entity_id   => l_Line_Price_Att_rec.Line_Id,
3253                                         p_request_unique_key1    => l_pricing_event,
3254 		 			p_param1                 => l_Line_Price_Att_rec.header_id,
3255                  		p_param2                 => l_pricing_event,
3256 		 			p_request_type           => OE_GLOBALS.G_PRICE_LINE,
3257 		 			x_return_status          => l_return_status);
3258 --2442012			End If;
3259 
3260 
3261             ELSE
3262 
3263                 --  Get Who Information
3264 
3265 
3266                 l_Line_price_att_rec.last_update_date := SYSDATE;
3267                 l_Line_price_att_rec.last_updated_by := FND_GLOBAL.USER_ID;
3268                 l_Line_price_att_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
3269 
3270                 IF l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
3271 
3272                     OE_Line_Pattr_Util.Update_Row (l_Line_price_att_rec);
3273 
3274                 ELSIF l_Line_price_att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3275 
3276                     l_Line_price_att_rec.creation_date := SYSDATE;
3277                     l_Line_price_att_rec.created_by    := FND_GLOBAL.USER_ID;
3278 
3279                     --BT
3280             --Added the If loop for Bug 3402434
3281             If(l_Line_price_att_rec.order_price_attrib_id is NULL or
3282                l_Line_price_att_rec.order_price_attrib_id=FND_API.G_MISS_NUM)               THEN
3283                     select OE_ORDER_PRICE_ATTRIBS_S.nextval
3284                     into   l_Line_price_att_rec.order_price_attrib_id
3285                     from dual;
3286             End If;
3287                     OE_Line_Pattr_Util.Insert_Row (l_Line_price_att_rec);
3288 
3289                 END IF;
3290 
3291             END IF;
3292 
3293         END IF;
3294 
3295         --  Load tables.
3296 
3297         p_x_Line_price_att_tbl(I)            := l_Line_Price_Att_rec;
3298         p_x_old_Line_price_att_tbl(I)        := l_old_Line_Price_Att_rec;
3299 
3300          IF l_Line_price_att_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3301                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3302          ELSIF l_Line_price_att_rec.return_status = FND_API.G_RET_STS_ERROR THEN
3303                 RAISE FND_API.G_EXC_ERROR;
3304          END IF;
3305 
3306         OE_MSG_PUB.reset_msg_context('HEADER_ADJ');
3307     --   loop exception handler.
3308 
3309     EXCEPTION
3310 
3311         WHEN FND_API.G_EXC_ERROR THEN
3312 
3313             l_Line_price_att_rec.return_status := FND_API.G_RET_STS_ERROR;
3314             p_x_Line_price_att_tbl(I)            := l_Line_Price_Att_rec;
3315             p_x_old_Line_price_att_tbl(I)        := l_old_Line_Price_Att_rec;
3316 
3317 		IF l_control_rec.Process_Partial THEN
3318 			ROLLBACK TO SAVEPOINT Line_price_atts;
3319 		ELSE
3320                 RAISE FND_API.G_EXC_ERROR;
3321 	        END IF;
3322 
3323 
3324         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3325 
3326             l_Line_price_att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3327             p_x_Line_price_att_tbl(I)            := l_Line_Price_Att_rec;
3328             p_x_old_Line_price_att_tbl(I)        := l_old_Line_Price_Att_rec;
3329 
3330             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3331 
3332         WHEN OTHERS THEN
3333 
3334             l_Line_price_att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3335             p_x_Line_price_att_tbl(I)            := l_Line_Price_Att_rec;
3336             p_x_old_Line_price_att_tbl(I)        := l_old_Line_Price_Att_rec;
3337 
3338             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3339             THEN
3340                 OE_MSG_PUB.Add_Exc_Msg
3341                 (   G_PKG_NAME
3342                 ,   'Line_price_atts'
3343                 );
3344             END IF;
3345 
3346             OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
3347             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3348 
3349     END;
3350     I := p_x_Line_price_att_tbl.NEXT(I);
3351     END LOOP;
3352 
3353     --  Load OUT parameters
3354 
3355       adj_debug('Exiting oe_order_Adj_pvt.Line_price_atts', 1);
3356       OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
3357 
3358 EXCEPTION
3359 
3360     WHEN FND_API.G_EXC_ERROR THEN
3361 
3362       OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
3363       RAISE;
3364 
3365     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3366 
3367       OE_MSG_PUB.reset_msg_context('HEADER_PATTS');
3368       RAISE;
3369 
3370     WHEN OTHERS THEN
3371 
3372         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3373         THEN
3374             OE_MSG_PUB.Add_Exc_Msg
3375             (   G_PKG_NAME
3376             ,   'Line_price_atts'
3377             );
3378         END IF;
3379 
3380 
3381         OE_MSG_PUB.reset_msg_context('LINE_PATTS');
3382         adj_debug('Exiting oe_order_Adj_pvt.Line_Price_Atts', 1);
3383 end Line_Price_Atts;
3384 
3385 
3386 PROCEDURE Insert_Adj_Atts
3387 (p_Line_Adj_attribs_tbl          IN OE_Order_PUB.Line_Adj_Att_Tbl_Type
3388 )
3389 is
3390   I PLS_INTEGER;
3391   l_line_dummy_adj_att_tbl OE_Order_PUB.Line_Adj_Att_Tbl_Type;
3392   l_line_adj_att_tbl       OE_Order_PUB.Line_Adj_Att_Tbl_Type;
3393   l_control_rec              OE_GLOBALS.Control_Rec_Type;
3394 Begin
3395  l_line_adj_att_tbl :=  p_Line_Adj_attribs_tbl;
3396 
3397  l_control_rec.private_call         := TRUE;
3398  l_control_rec.controlled_operation := TRUE;
3399  l_control_rec.check_security       := TRUE;
3400  l_control_rec.validate_entity      := FALSE;
3401  l_control_rec.write_to_db          := TRUE;
3402  l_control_rec.change_attributes    := FALSE;
3403 
3404   I :=  p_Line_Adj_attribs_tbl.first;
3405 
3406   While I Is Not Null Loop
3407     --l_line_adj_assoc_tbl(i)            := OE_ORDER_PUB.G_MISS_LINE_ADJ_ASSOC_REC;
3408     l_line_adj_att_tbl(i).Operation  := OE_Globals.G_OPR_CREATE;
3409 
3410     Select OE_PRICE_ADJ_ATTRIBS_S.nextval
3411     Into   l_line_adj_att_tbl(i).price_adj_attrib_id
3412     From   dual;
3413 
3414     I:= p_Line_Adj_attribs_tbl.Next(I);
3415   End Loop;
3416 
3417 Oe_Order_Adj_Pvt.Line_Adj_Atts(  p_validation_level=>FND_API.G_VALID_LEVEL_NONE,
3418                                    p_control_rec=>l_control_rec,
3419                                    p_x_Line_Adj_Att_tbl =>l_line_adj_att_tbl,
3420                                    p_x_old_Line_Adj_Att_tbl=>l_line_dummy_adj_att_tbl);
3421 
3422 End Insert_Adj_Atts;
3423 
3424 
3425 
3426 PROCEDURE Line_Adj_Atts
3427 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
3428 ,   p_validation_level              IN  NUMBER
3429 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
3430 ,   p_x_Line_Adj_Att_tbl            IN OUT NOCOPY  OE_Order_PUB.Line_Adj_Att_Tbl_Type
3431 ,   p_x_old_Line_Adj_Att_tbl        IN OUT NOCOPY  OE_Order_PUB.Line_Adj_Att_Tbl_Type
3432 )
3433 is
3434 l_return_status               VARCHAR2(1);
3435 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
3436 l_Line_Adj_att_rec        	OE_Order_PUB.Line_Adj_Att_Rec_Type;
3437 l_old_Line_Adj_att_rec    	OE_Order_PUB.Line_Adj_Att_Rec_Type;
3438 -- local variables to store OUT parameters from security check procedures
3439 I 				    pls_integer; -- Used as index for while loop
3440 BEGIN
3441 
3442     IF FND_API.to_Boolean(p_init_msg_list) THEN
3443         OE_MSG_PUB.initialize;
3444     END IF;
3445 
3446 IF l_control_rec.Process_Partial THEN
3447 	SAVEPOINT Line_Adj_atts;
3448 END IF;
3449 
3450     --  Init local table variables.
3451 
3452 	   --dbms_output.put_line('Entering oe_order_Adj_pvt.Line_price_atts');
3453         adj_debug('Entering oe_order_Adj_pvt.Line_Adj_atts', 1);
3454 
3455     I := p_x_Line_Adj_Att_tbl.FIRST;
3456 
3457     WHILE I IS NOT NULL LOOP
3458     BEGIN
3459 
3460         --  Load local records.
3461 
3462         l_Line_Adj_Att_rec := p_x_Line_Adj_Att_tbl(I);
3463 
3464         IF p_x_old_Line_Adj_Att_tbl.EXISTS(I) THEN
3465             l_old_Line_Adj_Att_rec := p_x_old_Line_Adj_Att_tbl(I);
3466         ELSE
3467             l_old_Line_Adj_Att_rec := OE_Order_PUB.G_MISS_Line_Adj_Att_REC;
3468         END IF;
3469 
3470     if l_old_Line_Adj_Att_rec.Price_Adj_attrib_id = FND_API.G_MISS_NUM  then
3471 
3472       OE_MSG_PUB.set_msg_context(
3473 	 p_entity_code			=> 'ADJ_ATTS'
3474   	,p_entity_id         		=> l_Line_Adj_Att_rec.Price_adj_attrib_id);
3475 
3476     else
3477 
3478       OE_MSG_PUB.set_msg_context(
3479 	 p_entity_code			=> 'ADJ_ATTS'
3480   	,p_entity_id         		=> l_old_Line_Adj_Att_rec.Price_adj_attrib_id);
3481 
3482     end if;
3483 
3484         --  Load API control record
3485 
3486         l_control_rec := OE_GLOBALS.Init_Control_Rec
3487         (   p_operation     => l_Line_Adj_Att_rec.operation
3488         ,   p_control_rec   => p_control_rec
3489         );
3490 
3491         --  Set record return status.
3492 
3493         l_Line_Adj_Att_rec.return_status := FND_API.G_RET_STS_SUCCESS;
3494 
3495         --  Prepare record.
3496 
3497         IF l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3498 
3499             l_Line_Adj_Att_rec.db_flag := FND_API.G_FALSE;
3500 
3501             --  Set missing old record elements to NULL.
3502 
3503    		 adj_debug('Entering OE_Line_Adj_Att_Util.Convert_Miss_To_Null', 1);
3504 --            l_old_Line_Adj_Att_rec :=
3505             Oe_Line_Price_Aattr_util.Convert_Miss_To_Null (l_old_Line_Adj_Att_rec);
3506 
3507         ELSIF l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_UPDATE
3508         OR    l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE
3509         THEN
3510 
3511             l_Line_Adj_Att_rec.db_flag := FND_API.G_TRUE;
3512 
3513             --  Query Old if missing
3514 
3515             IF  l_old_Line_Adj_Att_rec.Price_adj_attrib_id = FND_API.G_MISS_NUM
3516             THEN
3517 
3518 
3519                 Oe_Line_Price_Aattr_util.Query_Row
3520                 (   p_Price_Adj_Attrib_id => l_Line_Adj_Att_rec.Price_adj_attrib_id
3521                  ,  x_Line_Adj_Att_rec =>                 l_old_Line_Adj_Att_rec
3522                 );
3523 
3524             ELSE
3525 
3526                 --  Set missing old record elements to NULL.
3527 
3528 --                l_old_Line_Adj_Att_rec :=
3529                 Oe_Line_Price_Aattr_util.Convert_Miss_To_Null (l_old_Line_Adj_Att_rec);
3530 
3531             END IF;
3532 
3533             --  Complete new record from old
3534 
3535 --            l_Line_Adj_Att_rec :=
3536             Oe_Line_Price_Aattr_util.Complete_Record
3537             (   p_x_Line_Adj_Att_rec              => l_Line_Adj_Att_rec
3538             ,   p_old_Line_Adj_Att_rec          => l_old_Line_Adj_Att_rec
3539             );
3540 
3541       	   OE_MSG_PUB.update_msg_context(
3542 	 	 p_entity_code			=> 'ADJ_ATTS'
3543   		,p_entity_id         		=> l_Line_Adj_Att_rec.Price_adj_attrib_id);
3544 
3545         END IF;
3546 
3547 	   /*
3548         --  Attribute level validation.
3549 
3550             IF p_validation_level > FND_API.G_VALID_LEVEL_NONE THEN
3551 
3552                 OE_Validate_Line_Pattr.Attributes
3553                 (   x_return_status               => l_return_status
3554                 ,   p_Line_price_attr_rec         => l_Line_Adj_Att_rec
3555                 ,   p_old_Line_price_attr_rec     => l_old_Line_Adj_Att_rec
3556 			 ,   p_validation_level			=> p_validation_level
3557                 );
3558 
3559                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3560                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3561                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
3562                     RAISE FND_API.G_EXC_ERROR;
3563                 END IF;
3564 
3565             END IF;
3566 	*/
3567 
3568         --  Default missing attributes
3569         IF  l_control_rec.default_attributes
3570         THEN
3571 
3572            OE_DEfault_Line_Aattr.Attributes
3573             (   p_Line_Adj_Att_rec              => l_Line_Adj_Att_rec
3574             --,   x_Line_Adj_Att_rec              => l_Line_Adj_Att_rec
3575             );
3576 
3577         END IF;
3578 
3579         --  Apply attribute changes
3580 
3581         IF  l_control_rec.change_attributes
3582         THEN
3583 
3584 	   -- This will also log request/s to check duplicity of
3585 	   -- price adjustment entered
3586             Oe_Line_Price_Aattr_util.Apply_Attribute_Changes
3587             (   p_x_Line_Adj_Att_rec              => l_Line_Adj_Att_rec
3588             ,   p_old_Line_Adj_Att_rec          => l_old_Line_Adj_Att_rec
3589             --,   x_Line_Adj_Att_rec              => l_Line_Adj_Att_rec
3590             );
3591 
3592         END IF;
3593 
3594 	-- If there has any activity causing a change in any attribute
3595 	-- log a request for repricing
3596 
3597         --  Entity level validation.
3598 
3599         --  Step 4. Write to DB
3600 
3601         IF l_control_rec.write_to_db THEN
3602 
3603             IF l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
3604 
3605                 Oe_Line_Price_Aattr_util.Delete_Row
3606                 (   p_Price_Adj_Attrib_id         => l_Line_Adj_Att_rec.Price_adj_attrib_id
3607                 );
3608 
3609             ELSE
3610 
3611                 --  Get Who Information
3612 
3613                 l_Line_Adj_Att_rec.last_update_date := SYSDATE;
3614                 l_Line_Adj_Att_rec.last_updated_by := FND_GLOBAL.USER_ID;
3615                 l_Line_Adj_Att_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
3616 
3617                 IF l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
3618 
3619                     Oe_Line_Price_Aattr_util.Update_Row (l_Line_Adj_Att_rec);
3620 
3621                 ELSIF l_Line_Adj_Att_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3622 
3623                     l_Line_Adj_Att_rec.creation_date := SYSDATE;
3624                     l_Line_Adj_Att_rec.created_by    := FND_GLOBAL.USER_ID;
3625 
3626                     Oe_Line_Price_Aattr_util.Insert_Row (l_Line_Adj_Att_rec);
3627 
3628                 END IF;
3629 
3630             END IF;
3631 
3632         END IF;
3633 
3634         --  Load tables.
3635 
3636         p_x_Line_Adj_Att_tbl(I)            := l_Line_Adj_Att_rec;
3637         p_x_old_Line_Adj_Att_tbl(I)        := l_old_Line_Adj_Att_rec;
3638 
3639          IF l_Line_Adj_Att_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3640                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3641          ELSIF l_Line_Adj_Att_rec.return_status = FND_API.G_RET_STS_ERROR THEN
3642                 RAISE FND_API.G_EXC_ERROR;
3643          END IF;
3644 
3645         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3646     --   loop exception handler.
3647 
3648     EXCEPTION
3649 
3650         WHEN FND_API.G_EXC_ERROR THEN
3651 
3652             l_Line_Adj_Att_rec.return_status := FND_API.G_RET_STS_ERROR;
3653             p_x_Line_Adj_Att_tbl(I)            := l_Line_Adj_Att_rec;
3654             p_x_old_Line_Adj_Att_tbl(I)        := l_old_Line_Adj_Att_rec;
3655 
3656 		IF l_control_rec.Process_Partial THEN
3657 			ROLLBACK TO SAVEPOINT Line_Adj_atts;
3658 		ELSE
3659                 RAISE FND_API.G_EXC_ERROR;
3660 	        END IF;
3661 
3662 
3663         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3664 
3665             l_Line_Adj_Att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3666             p_x_Line_Adj_Att_tbl(I)            := l_Line_Adj_Att_rec;
3667             p_x_old_Line_Adj_Att_tbl(I)        := l_old_Line_Adj_Att_rec;
3668 
3669             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3670 
3671         WHEN OTHERS THEN
3672 
3673             l_Line_Adj_Att_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3674             p_x_Line_Adj_Att_tbl(I)            := l_Line_Adj_Att_rec;
3675             p_x_old_Line_Adj_Att_tbl(I)        := l_old_Line_Adj_Att_rec;
3676 
3677             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3678             THEN
3679                 OE_MSG_PUB.Add_Exc_Msg
3680                 (   G_PKG_NAME
3681                 ,   'Line_Adj_atts'
3682                 );
3683             END IF;
3684 
3685             OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3686             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3687 
3688     END;
3689     I := p_x_Line_Adj_Att_tbl.NEXT(I);
3690     END LOOP;
3691 
3692     --  Load OUT parameters
3693 
3694       adj_debug('Exiting oe_order_Adj_pvt.Line_Adj_atts', 1);
3695       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3696 
3697 EXCEPTION
3698 
3699     WHEN FND_API.G_EXC_ERROR THEN
3700 
3701       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3702       RAISE;
3703 
3704     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3705 
3706       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3707       RAISE;
3708 
3709     WHEN OTHERS THEN
3710 
3711         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3712         THEN
3713             OE_MSG_PUB.Add_Exc_Msg
3714             (   G_PKG_NAME
3715             ,   'Line_Adj_atts'
3716             );
3717         END IF;
3718 
3719 
3720         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3721 
3722         adj_debug('Exiting oe_order_Adj_pvt.Line_Adj_Atts', 1);
3723 end Line_Adj_Atts;
3724 
3725 PROCEDURE Insert_Adj_Assocs
3726 (p_Line_Adj_Assoc_tbl          IN OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
3727 )
3728 is
3729   I PLS_INTEGER;
3730   l_line_dummy_adj_assoc_tbl OE_Order_PUB.Line_Adj_Assoc_Tbl_Type;
3731   l_line_adj_assoc_tbl       OE_Order_PUB.Line_Adj_Assoc_Tbl_Type;
3732   l_control_rec              OE_GLOBALS.Control_Rec_Type;
3733 Begin
3734  l_line_adj_assoc_tbl :=  p_Line_Adj_Assoc_tbl;
3735  l_control_rec.private_call         := TRUE;
3736  l_control_rec.controlled_operation := TRUE;
3737  l_control_rec.check_security       := TRUE;
3738  l_control_rec.validate_entity      := FALSE;
3739  l_control_rec.write_to_db          := TRUE;
3740  l_control_rec.change_attributes    := FALSE;
3741 
3742   I := p_line_adj_assoc_tbl.first;
3743 
3744   While I Is Not Null Loop
3745     --l_line_adj_assoc_tbl(i)            := OE_ORDER_PUB.G_MISS_LINE_ADJ_ASSOC_REC;
3746     l_Line_Adj_Assoc_tbl(i).Operation  := OE_Globals.G_OPR_CREATE;
3747 
3748     Select oe_price_adj_assocs_s.nextval
3749     Into   l_line_adj_assoc_tbl(i).price_adj_assoc_id
3750     From   dual;
3751 
3752     I:= p_line_adj_assoc_tbl.Next(I);
3753   End Loop;
3754 
3755   Oe_Order_Adj_Pvt.Line_Adj_Assocs(p_validation_level=>FND_API.G_VALID_LEVEL_NONE,
3756                                    p_control_rec=>l_control_rec,
3757                                    p_x_line_adj_assoc_tbl=>l_line_adj_assoc_tbl,
3758                                    p_x_old_line_adj_assoc_tbl=>l_line_dummy_adj_assoc_tbl);
3759 
3760 End;
3761 
3762 
3763 PROCEDURE Line_Adj_Assocs
3764 (   p_init_msg_list                 IN VARCHAR2:=FND_API.G_FALSE
3765 ,   p_validation_level              IN  NUMBER
3766 ,   p_control_rec                   IN  OE_GLOBALS.Control_Rec_Type
3767 ,   p_x_Line_Adj_Assoc_tbl          IN OUT NOCOPY  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
3768 ,   p_x_old_Line_Adj_Assoc_tbl      IN OUT NOCOPY  OE_Order_PUB.Line_Adj_Assoc_Tbl_Type
3769 )
3770 is
3771 l_return_status               VARCHAR2(1);
3772 l_control_rec                 OE_GLOBALS.Control_Rec_Type;
3773 l_Line_Adj_Assoc_rec        	OE_Order_PUB.Line_Adj_Assoc_Rec_Type;
3774 l_old_Line_Adj_Assoc_rec    	OE_Order_PUB.Line_Adj_Assoc_Rec_Type;
3775 -- local variables to store OUT parameters from security check procedures
3776 I 				    pls_integer; -- Used as index for while loop
3777 BEGIN
3778 
3779     IF FND_API.to_Boolean(p_init_msg_list) THEN
3780         OE_MSG_PUB.initialize;
3781     END IF;
3782 
3783 IF l_control_rec.Process_Partial THEN
3784 	SAVEPOINT Line_Adj_Assocs;
3785 END IF;
3786 
3787     --  Init local table variables.
3788 
3789 	   --dbms_output.put_line('Entering oe_order_Adj_pvt.Line_price_atts');
3790         adj_debug('Entering oe_order_Adj_pvt.Line_Adj_Assocs', 1);
3791 
3792     I := p_x_Line_Adj_Assoc_tbl.FIRST;
3793 
3794     WHILE I IS NOT NULL LOOP
3795     BEGIN
3796 
3797         --  Load local records.
3798 
3799         l_Line_Adj_Assoc_rec := p_x_Line_Adj_Assoc_tbl(I);
3800 
3801 	   adj_debug('The operation is '||l_Line_Adj_Assoc_rec.operation,2);
3802 	   adj_debug('rltd_Adj '||l_Line_Adj_Assoc_rec.RLTD_PRICE_ADJ_ID,2);
3803 	   adj_debug('price adj '||l_Line_Adj_Assoc_rec.PRICE_ADJUSTMENT_ID,2);
3804         IF p_x_old_Line_Adj_Assoc_tbl.EXISTS(I) THEN
3805             l_old_Line_Adj_Assoc_rec := p_x_old_Line_Adj_Assoc_tbl(I);
3806         ELSE
3807             l_old_Line_Adj_Assoc_rec := OE_Order_PUB.G_MISS_Line_Adj_Assoc_REC;
3808         END IF;
3809 
3810     if l_old_Line_Adj_Assoc_rec.Price_Adj_assoc_id = FND_API.G_MISS_NUM  then
3811 
3812       OE_MSG_PUB.set_msg_context(
3813 	 p_entity_code			=> 'ADJ_ATTS'
3814   	,p_entity_id         		=> l_Line_Adj_Assoc_rec.Price_Adj_assoc_id);
3815 
3816     else
3817 
3818       OE_MSG_PUB.set_msg_context(
3819 	 p_entity_code			=> 'ADJ_ATTS'
3820   	,p_entity_id         		=> l_old_Line_Adj_Assoc_rec.Price_Adj_assoc_id);
3821 
3822     end if;
3823 
3824         --  Load API control record
3825 
3826         l_control_rec := OE_GLOBALS.Init_Control_Rec
3827         (   p_operation     => l_Line_Adj_Assoc_rec.operation
3828         ,   p_control_rec   => p_control_rec
3829         );
3830 
3831         --  Set record return status.
3832 
3833         l_Line_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_SUCCESS;
3834 
3835         --  Prepare record.
3836 
3837 
3838         IF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3839 
3840             l_Line_Adj_Assoc_rec.db_flag := FND_API.G_FALSE;
3841 
3842             --  Set missing old record elements to NULL.
3843 
3844    		 adj_debug('Entering OE_Line_Adj_Assoc_Util.Convert_Miss_To_Null', 1);
3845 --            l_old_Line_Adj_Assoc_rec :=
3846             Oe_Line_Adj_Assocs_util.Convert_Miss_To_Null (l_old_Line_Adj_Assoc_rec);
3847 
3848         ELSIF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_UPDATE
3849         OR    l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_DELETE
3850         THEN
3851 
3852             l_Line_Adj_Assoc_rec.db_flag := FND_API.G_TRUE;
3853 
3854             --  Query Old if missing
3855 
3856             IF  l_old_Line_Adj_Assoc_rec.Price_Adj_assoc_id = FND_API.G_MISS_NUM
3857             THEN
3858 
3859 
3860                 Oe_Line_Adj_Assocs_util.Query_Row
3861                 (   p_Price_Adj_assoc_id => l_Line_Adj_Assoc_rec.Price_Adj_assoc_id
3862                  ,  x_Line_Adj_Assoc_rec =>                 l_old_Line_Adj_Assoc_rec
3863                 );
3864 
3865             ELSE
3866 
3867                 --  Set missing old record elements to NULL.
3868 
3869 --                l_old_Line_Adj_Assoc_rec :=
3870                 Oe_Line_Adj_Assocs_util.Convert_Miss_To_Null (l_old_Line_Adj_Assoc_rec);
3871 
3872             END IF;
3873 
3874             --  Complete new record from old
3875 
3876 --            l_Line_Adj_Assoc_rec :=
3877             Oe_Line_Adj_Assocs_util.Complete_Record
3878             (   p_x_Line_Adj_Assoc_rec              => l_Line_Adj_Assoc_rec
3879             ,   p_old_Line_Adj_Assoc_rec          => l_old_Line_Adj_Assoc_rec
3880             );
3881 
3882       	   OE_MSG_PUB.update_msg_context(
3883 	 	 p_entity_code			=> 'ADJ_ATTS'
3884   		,p_entity_id         		=> l_Line_Adj_Assoc_rec.Price_Adj_assoc_id);
3885 
3886         END IF;
3887 
3888         --  Default missing attributes
3889         IF  l_control_rec.default_attributes
3890         THEN
3891 
3892    	 adj_debug('defaulting line adj attributes',2);
3893            OE_DEfault_Line_Adj_Assocs.Attributes
3894             (   p_x_Line_Adj_Assoc_rec              => l_Line_Adj_Assoc_rec
3895            -- ,   x_Line_Adj_Assoc_rec              => l_Line_Adj_Assoc_rec
3896             );
3897 
3898         END IF;
3899 
3900         --  Apply attribute changes
3901 
3902         IF  l_control_rec.change_attributes
3903         THEN
3904 
3905 	   -- This will also log request/s to check duplicity of
3906 	   -- price adjustment entered
3907             Oe_Line_Adj_Assocs_util.Apply_Attribute_Changes
3908             (   p_x_Line_Adj_Assoc_rec              => l_Line_Adj_Assoc_rec
3909             ,   p_old_Line_Adj_Assoc_rec          => l_old_Line_Adj_Assoc_rec
3910             --,   x_Line_Adj_Assoc_rec              => l_Line_Adj_Assoc_rec
3911             );
3912 
3913         END IF;
3914 
3915 	-- If there has any activity causing a change in any attribute
3916 	-- log a request for repricing
3917 
3918         --  Entity level validation.
3919 
3920         --  Step 4. Write to DB
3921 
3922         IF l_control_rec.write_to_db THEN
3923 
3924             IF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_DELETE THEN
3925 
3926 
3927      	        adj_debug('deleting line adj assocs',2);
3928                 Oe_Line_Adj_Assocs_util.Delete_Row
3929                 (   p_Price_Adj_assoc_id         => l_Line_Adj_Assoc_rec.Price_Adj_assoc_id
3930                 );
3931 
3932             ELSE
3933 
3934                 --  Get Who Information
3935 
3936                 l_Line_Adj_Assoc_rec.last_update_date := SYSDATE;
3937                 l_Line_Adj_Assoc_rec.last_updated_by := FND_GLOBAL.USER_ID;
3938                 l_Line_Adj_Assoc_rec.last_update_login := FND_GLOBAL.LOGIN_ID;
3939 
3940                 IF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_UPDATE THEN
3941      	            adj_debug('updating line adj assocs',2);
3942                     Oe_Line_Adj_Assocs_util.Update_Row (l_Line_Adj_Assoc_rec);
3943 
3944                 ELSIF l_Line_Adj_Assoc_rec.operation = OE_GLOBALS.G_OPR_CREATE THEN
3945      	            adj_debug('inserting into line adj assocs',2);
3946                     l_Line_Adj_Assoc_rec.creation_date := SYSDATE;
3947                     l_Line_Adj_Assoc_rec.created_by    := FND_GLOBAL.USER_ID;
3948 
3949                     Oe_Line_Adj_Assocs_util.Insert_Row (l_Line_Adj_Assoc_rec);
3950 
3951                 END IF;
3952 
3953             END IF;
3954 
3955         END IF;
3956 
3957         --  Load tables.
3958 
3959         p_x_Line_Adj_Assoc_tbl(I)            := l_Line_Adj_Assoc_rec;
3960         p_x_old_Line_Adj_Assoc_tbl(I)        := l_old_Line_Adj_Assoc_rec;
3961 
3962          IF l_Line_Adj_Assoc_rec.return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
3963                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3964          ELSIF l_Line_Adj_Assoc_rec.return_status = FND_API.G_RET_STS_ERROR THEN
3965                 RAISE FND_API.G_EXC_ERROR;
3966          END IF;
3967 
3968         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
3969     --   loop exception handler.
3970 
3971     EXCEPTION
3972 
3973         WHEN FND_API.G_EXC_ERROR THEN
3974 
3975             l_Line_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_ERROR;
3976             p_x_Line_Adj_Assoc_tbl(I)            := l_Line_Adj_Assoc_rec;
3977             p_x_old_Line_Adj_Assoc_tbl(I)        := l_old_Line_Adj_Assoc_rec;
3978 
3979 		IF l_control_rec.Process_Partial THEN
3980 			ROLLBACK TO SAVEPOINT Line_price_atts;
3981 		ELSE
3982                 RAISE FND_API.G_EXC_ERROR;
3983 	        END IF;
3984 
3985 
3986         WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3987 
3988             l_Line_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3989             p_x_Line_Adj_Assoc_tbl(I)            := l_Line_Adj_Assoc_rec;
3990             p_x_old_Line_Adj_Assoc_tbl(I)        := l_old_Line_Adj_Assoc_rec;
3991 
3992             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3993 
3994         WHEN OTHERS THEN
3995 
3996             l_Line_Adj_Assoc_rec.return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3997             p_x_Line_Adj_Assoc_tbl(I)            := l_Line_Adj_Assoc_rec;
3998             p_x_old_Line_Adj_Assoc_tbl(I)        := l_old_Line_Adj_Assoc_rec;
3999 
4000             IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4001             THEN
4002                 OE_MSG_PUB.Add_Exc_Msg
4003                 (   G_PKG_NAME
4004                 ,   'Header_price_atts'
4005                 );
4006             END IF;
4007 
4008             OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
4009             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4010 
4011     END;
4012     I := p_x_Line_Adj_Assoc_tbl.NEXT(I);
4013     END LOOP;
4014 
4015     --  Load OUT parameters
4016 
4017       adj_debug('Exiting oe_order_Adj_pvt.Line_Adj_Assocs', 1);
4018       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
4019 
4020 EXCEPTION
4021 
4022     WHEN FND_API.G_EXC_ERROR THEN
4023 
4024       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
4025       RAISE;
4026 
4027     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4028 
4029       OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
4030       RAISE;
4031 
4032     WHEN OTHERS THEN
4033 
4034         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4035         THEN
4036             OE_MSG_PUB.Add_Exc_Msg
4037             (   G_PKG_NAME
4038             ,   'Line_Adj_Assocs'
4039             );
4040         END IF;
4041 
4042 
4043         OE_MSG_PUB.reset_msg_context('ADJ_ATTS');
4044         adj_debug('Exiting oe_order_Adj_pvt.Line_Adj_Assocs', 1);
4045 end Line_Adj_Assocs;
4046 
4047 Function Enforce_list_Price
4048 return varchar2
4049 is
4050 l_enforce_price_flag	varchar2(1);
4051 begin
4052 	adj_debug('Entering oe_order_Adj_pvt.Enforce_Price_lists_Flag',1);
4053 begin
4054 
4055 	G_STMT_NO := 'Enforce_Price_lists_Flag#10';
4056 	select nvl(enforce_line_prices_flag,'N') into l_enforce_price_flag
4057 	from oe_line_types_v where line_type_id=OE_Order_PUB.G_Line.Line_Type_id;
4058 	exception when no_data_found then
4059 		l_enforce_price_flag := 'N';
4060 end ;
4061 
4062 If l_enforce_price_flag='N' then
4063 begin
4064 	G_STMT_NO := 'Enforce_Price_lists_Flag#20';
4065 	select nvl(enforce_line_prices_flag,'N') into l_enforce_price_flag
4066 	from oe_Order_types_v where Order_type_id=OE_Order_PUB.g_hdr.Order_Type_Id;
4067 	exception when no_data_found then
4068 		l_enforce_price_flag := 'N';
4069 end ;
4070 end if;
4071 
4072 	adj_debug('Exiting oe_order_Adj_pvt.Enforce_Price_lists_Flag',1);
4073 
4074 Return l_enforce_price_flag;
4075 
4076 end Enforce_list_Price;
4077 
4078 Procedure Enforce_list_Price(
4079 p_line_id IN NUMBER,
4080 p_header_id IN NUMBER,
4081 p_line_type_id IN NUMBER,
4082 px_order_enforce_list_price IN OUT NOCOPY VARCHAR2,
4083 x_line_enforce_list_price OUT NOCOPY VARCHAR2)
4084 
4085 is
4086 l_literal_order varchar2(5):='ORDER';
4087 begin
4088   adj_debug('Entering oe_order_Adj_pvt.Enforce_Price_lists_Flag',1);
4089     adj_debug('line id:'||p_line_id||' line type:'||p_line_Type_id);
4090 	G_STMT_NO := 'Enforce_Price_lists_Flag#10';
4091        IF (px_order_enforce_list_price IS NULL) THEN
4092          begin
4093              select /* MOAC_SQL_CHANGE */ nvl(enforce_line_prices_flag,'N') into px_order_enforce_list_price
4094              from oe_transaction_types_all o,oe_order_headers h
4095              where h.header_id=p_header_id and h.order_type_id=o.transaction_type_id
4096              and o.transaction_type_code=l_literal_order;
4097          exception when no_data_found then
4098               px_order_enforce_list_price := 'N';
4099         end;
4100         IF (px_order_enforce_list_price IS NULL) THEN
4101              px_order_enforce_list_price := 'N';
4102         END IF;
4103        END IF;
4104        IF (px_order_enforce_list_price = 'Y') THEN
4105            x_line_enforce_list_price := 'Y';
4106        ELSE
4107         begin
4108   	  select nvl(enforce_line_prices_flag,'N') into x_line_enforce_list_price
4109 	  from oe_line_types_v where line_type_id=p_line_type_id;
4110         exception when no_data_found then
4111 	   x_line_enforce_list_price := 'N';
4112         end ;
4113        END IF;
4114   adj_debug('Exiting oe_order_Adj_pvt.Enforce_Price_lists_Flag',1);
4115 
4116 end Enforce_list_Price;
4117 
4118 Function Get_Rounding_factor(p_list_header_id number)
4119 return number
4120 is
4121 begin
4122 	If g_rounding_factor_rec.list_header_id = p_list_header_id then
4123 		Return g_rounding_factor_rec.rounding_factor;
4124 	Else
4125 		g_rounding_factor_rec.list_header_id := p_list_header_id;
4126 		select rounding_factor into g_rounding_factor_rec.rounding_factor from
4127 		qp_list_headers_b where list_header_id=p_list_header_id;
4128 
4129 		If g_rounding_factor_rec.rounding_factor = fnd_api.g_miss_num then
4130 			g_rounding_factor_rec.rounding_factor:= Null;
4131 		End If;
4132 
4133 		Return g_rounding_factor_rec.rounding_factor;
4134 
4135 	End if;
4136 	Exception when no_data_found then
4137 		Return Null;
4138 end Get_Rounding_factor;
4139 
4140 procedure copy_Header_to_request(
4141  p_header_rec	 	OE_Order_PUB.Header_Rec_Type
4142 ,px_req_line_tbl   in out nocopy	QP_PREQ_GRP.LINE_TBL_TYPE
4143 --,p_pricing_event	varchar2
4144 ,p_Request_Type_Code	varchar2
4145 ,p_calculate_price_flag varchar2
4146 )
4147 is
4148 l_line_index	pls_integer := px_req_line_tbl.count;
4149 begin
4150 	G_STMT_NO := 'copy_Header_to_request#10';
4151 	adj_debug('Entering oe_order_Adj_pvt.copy_Header_to_request',1);
4152 
4153 	l_line_index := l_line_index+1;
4154 	px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE :=p_Request_Type_Code;
4155 	--px_req_line_tbl(l_line_index).PRICING_EVENT :=p_pricing_event;
4156 	--px_req_line_tbl(l_line_index).LIST_LINE_LEVEL_CODE :=p_Request_Type_Code;
4157 	px_req_line_tbl(l_line_index).LINE_INDEX := l_line_index;
4158 	px_req_line_tbl(l_line_index).LINE_TYPE_CODE := 'ORDER';
4159 	-- Hold the header_id in line_id for 'HEADER' Records
4160 	px_req_line_tbl(l_line_index).line_id := p_Header_rec.header_id;
4161 	if  p_header_rec.pricing_date is null or
4162 		 p_header_rec.pricing_date = fnd_api.g_miss_date then
4163 		px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);
4164 	Else
4165 		px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := p_header_rec.pricing_date;
4166 	End If;
4167 	px_req_line_tbl(l_line_index).CURRENCY_CODE := p_Header_rec.transactional_curr_code;
4168 	px_req_line_tbl(l_line_index).PRICE_FLAG := p_calculate_price_flag;
4169 	px_req_line_tbl(l_line_index).Active_date_first_type := 'ORD';
4170 	px_req_line_tbl(l_line_index).Active_date_first := p_Header_rec.Ordered_date;
4171 
4172         If p_Header_rec.transactional_curr_code is Not Null Then
4173          G_ORDER_CURRENCY := p_Header_rec.transactional_curr_code;
4174         Else
4175          G_ORDER_CURRENCY := OE_Order_PUB.g_hdr.transactional_curr_code;
4176         End If;
4177 
4178         --Rounding factor now will be handled by pricing engine.
4179 
4180         px_req_line_tbl(l_line_index).price_request_code := p_header_rec.price_request_code; -- PROMOTIONS SEP/01
4181 	adj_debug('Existing oe_order_Adj_pvt.copy_Header_to_request',1);
4182 
4183 end copy_Header_to_request;
4184 
4185 procedure copy_Line_to_request(
4186  p_Line_rec	 		OE_Order_PUB.Line_Rec_Type
4187 ,px_req_line_tbl   		in out nocopy 	QP_PREQ_GRP.LINE_TBL_TYPE
4188 ,p_pricing_event		varchar2
4189 ,p_Request_Type_Code	varchar2
4190 ,p_honor_price_flag		VARCHAR2 	Default 'Y'
4191 )
4192 is
4193 l_line_index	pls_integer := nvl(px_req_line_tbl.count,0);
4194 l_uom_rate      NUMBER;
4195 v_discounting_privilege VARCHAR2(30);
4196 l_item_type_code VARCHAR2(30);
4197 
4198 l_item_rec                    OE_ORDER_CACHE.item_rec_type; --OPM 2046190
4199 
4200 begin
4201 	G_STMT_NO := 'copy_Line_to_request#10';
4202 	adj_debug('Entering oe_order_Adj_pvt.copy_Line_to_request',1);
4203 	l_line_index := l_line_index+1;
4204 	px_req_line_tbl(l_line_index).Line_id := p_Line_rec.line_id;
4205 	px_req_line_tbl(l_line_index).REQUEST_TYPE_CODE := p_Request_Type_Code;
4206 	--px_req_line_tbl(l_line_index).PRICING_EVENT :=p_pricing_event;
4207 	--px_req_line_tbl(l_line_index).LIST_LINE_LEVEL_CODE :=p_price_level_code;
4208 	px_req_line_tbl(l_line_index).LINE_INDEX := l_line_index;
4209 	px_req_line_tbl(l_line_index).LINE_TYPE_CODE := 'LINE';
4210 	If p_Line_rec.pricing_date is null or
4211 		p_Line_rec.pricing_date = fnd_api.g_miss_date then
4212 		px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := trunc(sysdate);
4213 	Else
4214 		px_req_line_tbl(l_line_index).PRICING_EFFECTIVE_DATE := p_Line_rec.pricing_date;
4215 	End If;
4216 
4217 	px_req_line_tbl(l_line_index).LINE_QUANTITY := p_Line_rec.Ordered_quantity ;
4218 
4219 	/* -- No need to substract cancell quantity
4220 	If p_Line_rec.cancelled_quantity = fnd_api.g_miss_num Then
4221 	else
4222 		px_req_line_tbl(l_line_index).LINE_QUANTITY := p_Line_rec.Ordered_quantity -
4223 								nvl(p_Line_rec.cancelled_quantity,0);
4224 	End If;
4225 	*/
4226 	px_req_line_tbl(l_line_index).LINE_UOM_CODE := p_Line_rec.Order_quantity_uom;
4227 	px_req_line_tbl(l_line_index).PRICED_QUANTITY := p_Line_rec.pricing_quantity; -- OPM 2547940 moved this up to here from below next block
4228 
4229 -- start OPM  2046190
4230 			     -- IF oe_line_util.Process_Characteristics -- INVCONV
4231         	 IF oe_line_util.dual_uom_control  -- INVCONV
4232                         (p_line_rec.inventory_item_id
4233                         ,p_line_rec.ship_from_org_id
4234                         ,l_item_rec) THEN
4235 
4236            IF l_item_rec.ont_pricing_qty_source = 'S'   THEN -- price by quantity 2 -- invconv
4237    		oe_debug_pub.add('OPM - ont_pricing_qty_source = S in OEXVADJB.pls  ');
4238    		        px_req_line_tbl(l_line_index).LINE_QUANTITY := p_Line_rec.Ordered_quantity2 ;
4239 			px_req_line_tbl(l_line_index).LINE_UOM_CODE := p_Line_rec.Ordered_quantity_uom2 ;
4240 				-- OPM 2547940 start
4241 			IF p_line_rec.CALCULATE_PRICE_FLAG in ( 'N', 'P' ) THEN   -- usually split from shipping
4242 			--    below line - need a UOM conversion below if pricing UOM off price list not same as secondary UOM
4243 			--    need check whether split from shipping or not
4244 				IF (p_Line_rec.pricing_quantity_uom = p_Line_rec.Ordered_quantity_uom2) Then
4245         				px_req_line_tbl(l_line_index).PRICED_QUANTITY := nvl(p_Line_rec.shipped_quantity2,p_Line_rec.Ordered_quantity2);
4246   	  			Else
4247         			        adj_debug('OPM in split scenario about to convert ') ;
4248           				INV_CONVERT.INV_UM_CONVERSION(From_Unit => p_Line_rec.Ordered_quantity_uom2
4249                                        ,To_Unit   => p_Line_rec.pricing_quantity_uom
4250                                        ,Item_ID   => p_Line_rec.Inventory_item_id
4251                                        ,Uom_Rate  => l_Uom_rate);
4252         		 	 	px_req_line_tbl(l_line_index).PRICED_QUANTITY := nvl(p_Line_rec.shipped_quantity2,p_Line_rec.Ordered_quantity2) * l_uom_rate;
4253         		 	 	adj_debug('OPM priced quantity after convert is : ' ||px_req_line_tbl(l_line_index).PRICED_QUANTITY) ;
4254         			END IF;
4255 
4256 			END IF;	-- OPM 2547940 end
4257 
4258 
4259 		else
4260 			px_req_line_tbl(l_line_index).LINE_QUANTITY := p_Line_rec.Ordered_quantity ;
4261 	   		px_req_line_tbl(l_line_index).LINE_UOM_CODE := p_Line_rec.Order_quantity_uom ;
4262                	END IF;
4263 
4264         adj_debug('OPM pricing quantity is : ' ||px_req_line_tbl(l_line_index).LINE_QUANTITY) ;
4265 	adj_debug('OPM pricing quantity uom is : ' ||px_req_line_tbl(l_line_index).LINE_UOM_CODE) ;
4266 
4267         END IF;
4268 
4269 -- end OPM 2046190
4270 
4271 
4272 
4273 	px_req_line_tbl(l_line_index).PRICED_UOM_CODE := p_Line_rec.pricing_quantity_uom;
4274 
4275 	px_req_line_tbl(l_line_index).CURRENCY_CODE :=
4276 					OE_Order_PUB.g_hdr.transactional_curr_code;
4277         -- uom begin
4278 	If p_Line_rec.unit_list_price_per_pqty <> FND_API.G_MISS_NUM Then
4279 		px_req_line_tbl(l_line_index).UNIT_PRICE := p_Line_rec.unit_list_price_per_pqty;
4280 
4281 	-- Fix for bug 1834409
4282 	-- Patch 1766558 introduced two new columns in oe_order_lines_all
4283 	-- namely, unit_list_price_per_pqty and unit_selling_price_per_pqty
4284 	-- So, when adding new order lines to upgraded sales orders,
4285         -- pass the values of unit_list_price and unit_selling_price
4286 	-- to pricing engine for the old order lines
4287 
4288 	Elsif p_line_rec.unit_list_price <> FND_API.G_MISS_NUM Then
4289 		px_req_line_tbl(l_line_index).UNIT_PRICE := p_line_rec.unit_list_price;
4290 	else
4291 		 px_req_line_tbl(l_line_index).UNIT_PRICE := Null;
4292 	End If;
4293         -- uom end
4294 
4295 	px_req_line_tbl(l_line_index).PERCENT_PRICE := p_Line_rec.unit_list_percent;
4296 
4297         If (p_Line_rec.service_period = p_Line_rec.Order_quantity_uom) Then
4298   	  px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration;
4299         Else
4300           INV_CONVERT.INV_UM_CONVERSION(From_Unit => p_Line_rec.service_period
4301                                        ,To_Unit   => p_Line_rec.Order_quantity_uom
4302                                        ,Item_ID   => p_Line_rec.Inventory_item_id
4303                                        ,Uom_Rate  => l_Uom_rate);
4304           px_req_line_tbl(l_line_index).UOM_QUANTITY := p_Line_rec.service_duration * l_uom_rate;
4305         End If;
4306 
4307          --Rounding factor is now handled by pricing engine
4308 
4309 	-- modified by lkxu
4310      IF p_honor_price_flag = 'N' THEN
4311 	  IF p_line_rec.CALCULATE_PRICE_FLAG = 'X' THEN
4312 		-- this is service parent line, for information only, so don't price it.
4313 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'N';
4314        ELSE
4315 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y';
4316        END IF;
4317 
4318      ELSE
4319 	  If p_Line_rec.calculate_Price_flag = fnd_api.g_miss_char then
4320 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y';
4321            --included for bug 2046841    Begin
4322           elsif p_line_rec.calculate_price_flag = 'X' then
4323 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'N';
4324            --included for bug 2046841    End
4325 	  else
4326 		px_req_line_tbl(l_line_index).PRICE_FLAG := nvl(p_Line_rec.calculate_Price_flag,'Y');
4327 	  end if;
4328      END IF;
4329 
4330      -- end of modification made by lkxu
4331 
4332         -- Added by JAUTOMO on 20-DEC-00
4333 
4334         -- Get Discounting Privilege Profile Option value
4335         fnd_profile.get('ONT_DISCOUNTING_PRIVILEGE', v_discounting_privilege);
4336 
4337         -- If the profile is set to UNLIMITED, then even if the Order Type
4338         -- restrict price changes, the user can change the price
4339 
4340 	-- If Enforce list price then execute only the PRICE Event
4341 	If p_pricing_event <> 'PRICE' and
4342            Enforce_list_price = 'Y' and
4343            px_req_line_tbl(l_line_index).PRICE_FLAG = 'Y' and
4344            v_discounting_privilege <> 'UNLIMITED' then
4345 
4346 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'P';
4347 
4348 	End If;
4349 
4350 	-- Execute the pricing phase if the list price is null
4351 
4352 	If p_pricing_event = 'PRICE' and
4353 		 px_req_line_tbl(l_line_index).UNIT_PRICE is null then
4354 
4355 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'Y' ;
4356 
4357 	End If;
4358 	-- Do not execute SHIP event for a line if the line is not ship interfaced.
4359 	If px_req_line_tbl(l_line_index).PRICE_FLAG = 'Y' and
4360 		(p_Line_rec.Shipped_quantity is null or
4361 		p_Line_rec.Shipped_quantity = fnd_api.g_miss_num or
4362 		p_Line_rec.Shipped_quantity = 0 ) and
4363                 --cc1
4364 		p_pricing_event ='SHIP' Then
4365 		px_req_line_tbl(l_line_index).PRICE_FLAG := 'N';
4366 	End If;
4367 
4368         l_item_type_code := oe_line_util.Get_Return_Item_Type_Code(p_Line_rec);
4369 
4370         -- Do not fetch the price for Configuration items and Included Items
4371         If l_item_type_code in( 'CONFIG','INCLUDED')
4372 	Then
4373 
4374             IF p_line_rec.calculate_price_flag in ( 'Y', 'P' )
4375             Then
4376                 If ( G_CHARGES_FOR_INCLUDED_ITEM = 'N' and
4377                        l_item_type_code = 'INCLUDED')
4378                 Then
4379                   px_req_line_tbl(l_line_index).PRICE_FLAG := 'N';
4380                 Else
4381                   px_req_line_tbl(l_line_index).PRICE_FLAG := 'P';
4382                 End If;
4383             Else
4384                 px_req_line_tbl(l_line_index).PRICE_FLAG := 'N';
4385 
4386             End IF;
4387 
4388 	End If;
4389 
4390 	px_req_line_tbl(l_line_index).Active_date_first_type := 'ORD';
4391 	px_req_line_tbl(l_line_index).Active_date_first := OE_Order_Pub.G_HDR.Ordered_date;
4392 
4393 	If p_Line_rec.schedule_ship_date is not null then
4394 	  px_req_line_tbl(l_line_index).Active_date_Second_type := 'SHIP';
4395 	  px_req_line_tbl(l_line_index).Active_date_Second := p_Line_rec.schedule_ship_date;
4396 	End If;
4397         px_req_line_tbl(l_line_index).price_request_code := p_line_rec.price_request_code; -- PROMOTIONS  SEP/01
4398         px_req_line_tbl(l_line_index).line_category
4399                := p_line_rec.line_category_code;
4400 
4401 	adj_debug('Existing oe_order_Adj_pvt.copy_Line_to_request',1);
4402 
4403 end copy_Line_to_request;
4404 
4405 procedure copy_adjs_to_request(
4406 p_line_index					pls_integer
4407 ,p_adj_index					pls_integer
4408 ,p_Line_adj_rec	 			OE_Order_PUB.Line_Adj_Rec_Type
4409 ,px_Req_LINE_DETAIL_tbl   	in out nocopy 	QP_PREQ_GRP.LINE_DETAIL_tbl_Type
4410 )
4411 is
4412 l_RLD_Index 		pls_integer	:= p_adj_index;
4413 begin
4414 
4415 			adj_debug('Entering oe_order_Adj_pvt.copy_adjs_to_request',1);
4416 
4417 			G_STMT_NO := 'copy_adjs_to_request#10';
4418 
4419 			--l_RLD_Index := l_RLD_Index +1 ;
4420 
4421 			  -- We want to retain the same index as that of Adj
4422 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).Line_Detail_Index := l_RLD_Index;
4423 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).Line_Detail_Type_Code := 'NULL';
4424 
4425 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).Line_Index := p_line_index;
4426 
4427 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).List_header_id := p_Line_Adj_rec.List_Header_Id;
4428 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).List_Line_Id := p_Line_Adj_rec.List_Line_id;
4429 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).List_Line_type_Code := p_Line_Adj_rec.List_Line_type_Code;
4430                  Begin
4431                     Select list_type_code into
4432                          px_Req_LINE_DETAIL_tbl(l_RLD_Index).created_from_list_type_code
4433                     from qp_list_headers_b where
4434                     list_header_id= p_Line_Adj_rec.List_Header_Id;
4435                     Exception when no_data_found then
4436                     adj_debug('Invalid list header '|| p_Line_Adj_rec.List_Header_Id,1);
4437                  End;
4438 
4439 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).substitution_from := p_Line_Adj_rec.modified_from;
4440 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).substitution_to := p_Line_Adj_rec.modified_to;
4441 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).automatic_flag := p_Line_Adj_rec.automatic_flag;
4442 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).override_flag := p_Line_Adj_rec.update_allowed;
4443 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).Operand_Calculation_Code :=
4444 					  p_Line_Adj_rec.Arithmetic_Operator;
4445 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).Operand_Value := p_Line_Adj_rec.Operand_Per_Pqty;
4446 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).pricing_group_sequence := p_Line_Adj_rec.pricing_group_sequence;
4447 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).price_break_type_code := p_Line_Adj_rec.price_break_type_code;
4448 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).pricing_phase_id := p_Line_Adj_rec.pricing_phase_id;
4449 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).line_quantity := p_Line_Adj_rec.range_break_quantity;
4450 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).adjustment_amount := p_Line_Adj_rec.adjusted_amount_per_pqty;
4451 			  px_Req_LINE_DETAIL_tbl(l_RLD_Index).applied_flag := p_Line_Adj_rec.applied_flag;
4452 
4453 end copy_adjs_to_request;
4454 
4455 procedure copy_attribs_to_Req(
4456 p_line_index				number
4457 ,p_pricing_contexts_Tbl 		QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type
4458 ,p_qualifier_contexts_Tbl 	QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type
4459 ,px_Req_line_attr_tbl		in out nocopy  QP_PREQ_GRP.LINE_ATTR_TBL_TYPE
4460 ,px_Req_qual_tbl			in out  nocopy  QP_PREQ_GRP.QUAL_TBL_TYPE
4461 )
4462 is
4463 i			pls_integer := 0;
4464 l_attr_index	pls_integer := nvl(px_Req_line_attr_tbl.last,0);
4465 l_qual_index	pls_integer := nvl(px_Req_qual_tbl.last,0);
4466 begin
4467 	adj_debug('Entering oe_order_Adj_pvt.copy_attribs_to_Req',1);
4468 	i := p_pricing_contexts_Tbl.First;
4469 	While i is not null loop
4470 		l_attr_index := l_attr_index +1;
4471 		px_Req_line_attr_tbl(l_attr_index).VALIDATED_FLAG := 'N';
4472 		px_Req_line_attr_tbl(l_attr_index).line_index := p_line_index;
4473 
4474 			-- Product and Pricing Contexts go into pricing contexts...
4475 			px_Req_line_attr_tbl(l_attr_index).PRICING_CONTEXT :=
4476 								p_pricing_contexts_Tbl(i).context_name;
4477 			px_Req_line_attr_tbl(l_attr_index).PRICING_ATTRIBUTE :=
4478 							p_pricing_contexts_Tbl(i).Attribute_Name;
4479 			px_Req_line_attr_tbl(l_attr_index).PRICING_ATTR_VALUE_FROM :=
4480 							p_pricing_contexts_Tbl(i).attribute_value;
4481 
4482 		i := p_pricing_contexts_Tbl.Next(i);
4483 	end loop;
4484 -- Copy the qualifiers
4485 	G_STMT_NO := 'copy_attribs_to_Req#20';
4486 	i := p_qualifier_contexts_Tbl.First;
4487 	While i is not null loop
4488 		l_qual_index := l_qual_index +1;
4489 
4490 		If p_qualifier_contexts_Tbl(i).context_name ='MODLIST' and
4491 			p_qualifier_contexts_Tbl(i).Attribute_Name ='QUALIFIER_ATTRIBUTE4' then
4492 
4493 			If OE_Order_PUB.G_Line.agreement_id is not null and
4494 				OE_Order_PUB.G_Line.agreement_id <> fnd_api.g_miss_num then
4495           			px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'Y';
4496                         -- BLANKETS: Start Code Merge
4497                         Elsif OE_Code_Control.Code_Release_Level >= '110509' and
4498                               OE_Order_PUB.G_Line.blanket_number is not null and
4499                               OE_Order_PUB.G_Line.blanket_number <> fnd_api.g_miss_num and
4500                               OE_Order_PUB.G_Line.blanket_line_number is not null and
4501                               OE_Order_PUB.G_Line.blanket_line_number <> fnd_api.g_miss_num
4502                         Then
4503 
4504                            -- Set validated_flag to 'Y' if price list is AGR
4505                            -- type or enforce price list is checked on blanket.
4506                            If Get_List_Type
4507                                (OE_Order_PUB.G_Line.price_list_id) = 'AGR'
4508                               OR Get_Enforce_Price_List
4509                                (OE_Order_PUB.G_Line.blanket_number
4510                                ,OE_Order_PUB.G_Line.blanket_line_number)='Y'
4511                            Then
4512 
4513 				px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'Y';
4514 
4515                            Else
4516 
4517 				px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'N';
4518 
4519                            End If;
4520 
4521                         -- BLANKETS: End Code Merge
4522 
4523 			Else
4524 				px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'N';
4525 			End If;
4526 
4527 		Else
4528           	px_Req_Qual_Tbl(l_qual_index).Validated_Flag := 'N';
4529 		End If;
4530 
4531 		px_Req_qual_tbl(l_qual_index).line_index := p_line_index;
4532 
4533 		px_Req_qual_tbl(l_qual_index).QUALIFIER_CONTEXT :=
4534 					p_qualifier_contexts_Tbl(i).context_name;
4535 		px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTRIBUTE :=
4536 						p_qualifier_contexts_Tbl(i).Attribute_Name;
4537 		px_Req_qual_tbl(l_qual_index).QUALIFIER_ATTR_VALUE_FROM :=
4538 						p_qualifier_contexts_Tbl(i).attribute_value;
4539 
4540 		i := p_qualifier_contexts_Tbl.Next(i);
4541 	end loop;
4542 
4543 	adj_debug('Exiting oe_order_Adj_pvt.copy_attribs_to_Req',1);
4544 
4545 end copy_attribs_to_Req;
4546 
4547 procedure  Append_asked_for(
4548 	p_header_id		number default null
4549 	,p_Line_id			number default null
4550 	,p_line_index				number
4551 	,px_Req_line_attr_tbl		in out nocopy  QP_PREQ_GRP.LINE_ATTR_TBL_TYPE
4552 	,px_Req_qual_tbl			in out  nocopy  QP_PREQ_GRP.QUAL_TBL_TYPE
4553 )
4554 is
4555 i	pls_integer;
4556 -- Using union all to eliminate sort unique
4557 cursor asked_for_cur is
4558 	select flex_title, pricing_context, pricing_attribute1,
4559 	pricing_attribute2 , pricing_attribute3 , pricing_attribute4 , pricing_attribute5 ,
4560 	pricing_attribute6 , pricing_attribute7 , pricing_attribute8 , pricing_attribute9 ,
4561 	pricing_attribute10 , pricing_attribute11 , pricing_attribute12 , pricing_attribute13 ,
4562 	pricing_attribute14 , pricing_attribute15 , pricing_attribute16 , pricing_attribute17 ,
4563 	pricing_attribute18 , pricing_attribute19 , pricing_attribute20 , pricing_attribute21 ,
4564 	pricing_attribute22 , pricing_attribute23 , pricing_attribute24 , pricing_attribute25 ,
4565 	pricing_attribute26 , pricing_attribute27 , pricing_attribute28 , pricing_attribute29 ,
4566 	pricing_attribute30 , pricing_attribute31 , pricing_attribute32 , pricing_attribute33 ,
4567 	pricing_attribute34 , pricing_attribute35 , pricing_attribute36 , pricing_attribute37 ,
4568 	pricing_attribute38 , pricing_attribute39 , pricing_attribute40 , pricing_attribute41 ,
4569 	pricing_attribute42 , pricing_attribute43 , pricing_attribute44 , pricing_attribute45 ,
4570 	pricing_attribute46 , pricing_attribute47 , pricing_attribute48 , pricing_attribute49 ,
4571 	pricing_attribute50 , pricing_attribute51 , pricing_attribute52 , pricing_attribute53 ,
4572 	pricing_attribute54 , pricing_attribute55 , pricing_attribute56 , pricing_attribute57 ,
4573 	pricing_attribute58 , pricing_attribute59 , pricing_attribute60 , pricing_attribute61 ,
4574 	pricing_attribute62 , pricing_attribute63 , pricing_attribute64 , pricing_attribute65 ,
4575 	pricing_attribute66 , pricing_attribute67 , pricing_attribute68 , pricing_attribute69 ,
4576 	pricing_attribute70 , pricing_attribute71 , pricing_attribute72 , pricing_attribute73 ,
4577 	pricing_attribute74 , pricing_attribute75 , pricing_attribute76 , pricing_attribute77 ,
4578 	pricing_attribute78 , pricing_attribute79 , pricing_attribute80 , pricing_attribute81 ,
4579 	pricing_attribute82 , pricing_attribute83 , pricing_attribute84 , pricing_attribute85 ,
4580 	pricing_attribute86 , pricing_attribute87 , pricing_attribute88 , pricing_attribute89 ,
4581 	pricing_attribute90 , pricing_attribute91 , pricing_attribute92 , pricing_attribute93 ,
4582 	pricing_attribute94 , pricing_attribute95 , pricing_attribute96 , pricing_attribute97 ,
4583 	pricing_attribute98 , pricing_attribute99 , pricing_attribute100
4584 	,Override_Flag
4585  from oe_order_price_attribs a
4586  where (a.line_id is null and a.header_id = p_header_id )
4587 union all
4588 	select flex_title, pricing_context, pricing_attribute1,
4589 	pricing_attribute2 , pricing_attribute3 , pricing_attribute4 , pricing_attribute5 ,
4590 	pricing_attribute6 , pricing_attribute7 , pricing_attribute8 , pricing_attribute9 ,
4591 	pricing_attribute10 , pricing_attribute11 , pricing_attribute12 , pricing_attribute13 ,
4592 	pricing_attribute14 , pricing_attribute15 , pricing_attribute16 , pricing_attribute17 ,
4593 	pricing_attribute18 , pricing_attribute19 , pricing_attribute20 , pricing_attribute21 ,
4594 	pricing_attribute22 , pricing_attribute23 , pricing_attribute24 , pricing_attribute25 ,
4595 	pricing_attribute26 , pricing_attribute27 , pricing_attribute28 , pricing_attribute29 ,
4596 	pricing_attribute30 , pricing_attribute31 , pricing_attribute32 , pricing_attribute33 ,
4597 	pricing_attribute34 , pricing_attribute35 , pricing_attribute36 , pricing_attribute37 ,
4598 	pricing_attribute38 , pricing_attribute39 , pricing_attribute40 , pricing_attribute41 ,
4599 	pricing_attribute42 , pricing_attribute43 , pricing_attribute44 , pricing_attribute45 ,
4600 	pricing_attribute46 , pricing_attribute47 , pricing_attribute48 , pricing_attribute49 ,
4601 	pricing_attribute50 , pricing_attribute51 , pricing_attribute52 , pricing_attribute53 ,
4602 	pricing_attribute54 , pricing_attribute55 , pricing_attribute56 , pricing_attribute57 ,
4603 	pricing_attribute58 , pricing_attribute59 , pricing_attribute60 , pricing_attribute61 ,
4604 	pricing_attribute62 , pricing_attribute63 , pricing_attribute64 , pricing_attribute65 ,
4605 	pricing_attribute66 , pricing_attribute67 , pricing_attribute68 , pricing_attribute69 ,
4606 	pricing_attribute70 , pricing_attribute71 , pricing_attribute72 , pricing_attribute73 ,
4607 	pricing_attribute74 , pricing_attribute75 , pricing_attribute76 , pricing_attribute77 ,
4608 	pricing_attribute78 , pricing_attribute79 , pricing_attribute80 , pricing_attribute81 ,
4609 	pricing_attribute82 , pricing_attribute83 , pricing_attribute84 , pricing_attribute85 ,
4610 	pricing_attribute86 , pricing_attribute87 , pricing_attribute88 , pricing_attribute89 ,
4611 	pricing_attribute90 , pricing_attribute91 , pricing_attribute92 , pricing_attribute93 ,
4612 	pricing_attribute94 , pricing_attribute95 , pricing_attribute96 , pricing_attribute97 ,
4613 	pricing_attribute98 , pricing_attribute99 , pricing_attribute100
4614 	,Override_Flag
4615  from oe_order_price_attribs a
4616  where (p_line_id is not null and a.line_id = p_line_id )
4617 	  ;
4618 begin
4619 	G_STMT_NO := 'Append_asked_for#10';
4620 	adj_debug('Entering oe_order_Adj_pvt.Append_asked_for',1);
4621 	for asked_for_rec in asked_for_cur loop
4622 		If asked_for_rec.flex_title = 'QP_ATTR_DEFNS_PRICING' then
4623 		  if asked_for_rec.PRICING_ATTRIBUTE1 is not null then
4624 			i := px_Req_line_attr_tbl.count+1;
4625                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4626                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4627 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4628 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE1';
4629 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE1;
4630 		  end if;
4631 		  if asked_for_rec.PRICING_ATTRIBUTE2 is not null then
4632 			i := px_Req_line_attr_tbl.count+1;
4633                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4634                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4635 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4636 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE2';
4637 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE2;
4638 		  end if;
4639 		  if asked_for_rec.PRICING_ATTRIBUTE3 is not null then
4640 			i := px_Req_line_attr_tbl.count+1;
4641                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4642                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4643 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4644 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE3';
4645 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE3;
4646 		  end if;
4647 		  if asked_for_rec.PRICING_ATTRIBUTE4 is not null then
4648 			i := px_Req_line_attr_tbl.count+1;
4649                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4650                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4651 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4652 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE4';
4653 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE4;
4654 		  end if;
4655 		  if asked_for_rec.PRICING_ATTRIBUTE5 is not null then
4656 			i := px_Req_line_attr_tbl.count+1;
4657                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4658                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4659 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4660 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE5';
4661 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE5;
4662 		  end if;
4663 		  if asked_for_rec.PRICING_ATTRIBUTE6 is not null then
4664 			i := px_Req_line_attr_tbl.count+1;
4665                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4666                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4667 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4668 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE6';
4669 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE6;
4670 		  end if;
4671 		  if asked_for_rec.PRICING_ATTRIBUTE7 is not null then
4672 			i := px_Req_line_attr_tbl.count+1;
4673                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4674                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4675 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4676 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE7';
4677 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE7;
4678 		  end if;
4679 		  if asked_for_rec.PRICING_ATTRIBUTE8 is not null then
4680 			i := px_Req_line_attr_tbl.count+1;
4681                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4682                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4683 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4684 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE8';
4685 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE8;
4686 		  end if;
4687 		  if asked_for_rec.PRICING_ATTRIBUTE9 is not null then
4688 			i := px_Req_line_attr_tbl.count+1;
4689                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4690                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4691 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4692 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE9';
4693 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE9;
4694 		  end if;
4695 
4696 		  if asked_for_rec.PRICING_ATTRIBUTE10 is not null then
4697 			i := px_Req_line_attr_tbl.count+1;
4698                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4699                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4700 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4701 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE10';
4702 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE10;
4703 		  end if;
4704 		  if asked_for_rec.PRICING_ATTRIBUTE11 is not null then
4705 			i := px_Req_line_attr_tbl.count+1;
4706                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4707                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4708 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4709 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE11';
4710 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE11;
4711 		  end if;
4712 		  if asked_for_rec.PRICING_ATTRIBUTE12 is not null then
4713 			i := px_Req_line_attr_tbl.count+1;
4714                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4715                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4716 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4717 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE12';
4718 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE12;
4719 		  end if;
4720 		  if asked_for_rec.PRICING_ATTRIBUTE13 is not null then
4721 			i := px_Req_line_attr_tbl.count+1;
4722                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4723                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4724 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4725 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE13';
4726 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE13;
4727 		  end if;
4728 		  if asked_for_rec.PRICING_ATTRIBUTE14 is not null then
4729 			i := px_Req_line_attr_tbl.count+1;
4730                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4731                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4732 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4733 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE14';
4734 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE14;
4735 		  end if;
4736 		  if asked_for_rec.PRICING_ATTRIBUTE15 is not null then
4737 			i := px_Req_line_attr_tbl.count+1;
4738                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4739                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4740 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4741 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE15';
4742 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE15;
4743 		  end if;
4744 		  if asked_for_rec.PRICING_ATTRIBUTE16 is not null then
4745 			i := px_Req_line_attr_tbl.count+1;
4746                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4747                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4748 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4749 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE16';
4750 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE16;
4751 		  end if;
4752 		  if asked_for_rec.PRICING_ATTRIBUTE17 is not null then
4753 			i := px_Req_line_attr_tbl.count+1;
4754                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4755                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4756 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4757 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE17';
4758 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE17;
4759 		  end if;
4760 		  if asked_for_rec.PRICING_ATTRIBUTE18 is not null then
4761 			i := px_Req_line_attr_tbl.count+1;
4762                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4763                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4764 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4765 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE18';
4766 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE18;
4767 		  end if;
4768 		  if asked_for_rec.PRICING_ATTRIBUTE19 is not null then
4769 			i := px_Req_line_attr_tbl.count+1;
4770                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4771                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4772 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4773 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE19';
4774 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE19;
4775 		  end if;
4776 
4777 		  if asked_for_rec.PRICING_ATTRIBUTE20 is not null then
4778 			i := px_Req_line_attr_tbl.count+1;
4779                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4780                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4781 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4782 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE20';
4783 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE20;
4784 		  end if;
4785 		  if asked_for_rec.PRICING_ATTRIBUTE21 is not null then
4786 			i := px_Req_line_attr_tbl.count+1;
4787                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4788                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4789 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4790 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE21';
4791 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE21;
4792 		  end if;
4793 		  if asked_for_rec.PRICING_ATTRIBUTE22 is not null then
4794 			i := px_Req_line_attr_tbl.count+1;
4795                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4796                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4797 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4798 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE22';
4799 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE22;
4800 		  end if;
4801 		  if asked_for_rec.PRICING_ATTRIBUTE23 is not null then
4802 			i := px_Req_line_attr_tbl.count+1;
4803                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4804                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4805 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4806 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE23';
4807 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE23;
4808 		  end if;
4809 		  if asked_for_rec.PRICING_ATTRIBUTE24 is not null then
4810 			i := px_Req_line_attr_tbl.count+1;
4811                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4812                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4813 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4814 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE24';
4815 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE24;
4816 		  end if;
4817 		  if asked_for_rec.PRICING_ATTRIBUTE25 is not null then
4818 			i := px_Req_line_attr_tbl.count+1;
4819                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4820                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4821 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4822 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE25';
4823 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE25;
4824 		  end if;
4825 		  if asked_for_rec.PRICING_ATTRIBUTE26 is not null then
4826 			i := px_Req_line_attr_tbl.count+1;
4827                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4828                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4829 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4830 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE26';
4831 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE26;
4832 		  end if;
4833 		  if asked_for_rec.PRICING_ATTRIBUTE27 is not null then
4834 			i := px_Req_line_attr_tbl.count+1;
4835                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4836                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4837 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4838 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE27';
4839 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE27;
4840 		  end if;
4841 		  if asked_for_rec.PRICING_ATTRIBUTE28 is not null then
4842 			i := px_Req_line_attr_tbl.count+1;
4843                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4844                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4845 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4846 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE28';
4847 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE28;
4848 		  end if;
4849 		  if asked_for_rec.PRICING_ATTRIBUTE29 is not null then
4850 			i := px_Req_line_attr_tbl.count+1;
4851                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4852                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4853 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4854 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE29';
4855 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE29;
4856 		  end if;
4857 
4858 		  if asked_for_rec.PRICING_ATTRIBUTE30 is not null then
4859 			i := px_Req_line_attr_tbl.count+1;
4860                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4861                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4862 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4863 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE30';
4864 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE30;
4865 		  end if;
4866 		  if asked_for_rec.PRICING_ATTRIBUTE31 is not null then
4867 			i := px_Req_line_attr_tbl.count+1;
4868                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4869                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4870 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4871 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE31';
4872 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE31;
4873 		  end if;
4874 		  if asked_for_rec.PRICING_ATTRIBUTE32 is not null then
4875 			i := px_Req_line_attr_tbl.count+1;
4876                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4877                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4878 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4879 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE32';
4880 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE32;
4881 		  end if;
4882 		  if asked_for_rec.PRICING_ATTRIBUTE33 is not null then
4883 			i := px_Req_line_attr_tbl.count+1;
4884                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4885                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4886 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4887 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE33';
4888 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE33;
4889 		  end if;
4890 		  if asked_for_rec.PRICING_ATTRIBUTE34 is not null then
4891 			i := px_Req_line_attr_tbl.count+1;
4892                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4893                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4894 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4895 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE34';
4896 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE34;
4897 		  end if;
4898 		  if asked_for_rec.PRICING_ATTRIBUTE35 is not null then
4899 			i := px_Req_line_attr_tbl.count+1;
4900                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4901                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4902 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4903 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE35';
4904 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE35;
4905 		  end if;
4906 		  if asked_for_rec.PRICING_ATTRIBUTE36 is not null then
4907 			i := px_Req_line_attr_tbl.count+1;
4908                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4909                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4910 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4911 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE36';
4912 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE36;
4913 		  end if;
4914 		  if asked_for_rec.PRICING_ATTRIBUTE37 is not null then
4915 			i := px_Req_line_attr_tbl.count+1;
4916                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4917                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4918 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4919 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE37';
4920 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE37;
4921 		  end if;
4922 		  if asked_for_rec.PRICING_ATTRIBUTE38 is not null then
4923 			i := px_Req_line_attr_tbl.count+1;
4924                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4925                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4926 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4927 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE38';
4928 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE38;
4929 		  end if;
4930 		  if asked_for_rec.PRICING_ATTRIBUTE39 is not null then
4931 			i := px_Req_line_attr_tbl.count+1;
4932                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4933                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4934 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4935 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE39';
4936 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE39;
4937 		  end if;
4938 
4939 		  if asked_for_rec.PRICING_ATTRIBUTE40 is not null then
4940 			i := px_Req_line_attr_tbl.count+1;
4941                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4942                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4943 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4944 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE40';
4945 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE40;
4946 		  end if;
4947 		  if asked_for_rec.PRICING_ATTRIBUTE41 is not null then
4948 			i := px_Req_line_attr_tbl.count+1;
4949                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4950                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4951 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4952 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE41';
4953 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE41;
4954 		  end if;
4955 		  if asked_for_rec.PRICING_ATTRIBUTE42 is not null then
4956 			i := px_Req_line_attr_tbl.count+1;
4957                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4958                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4959 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4960 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE42';
4961 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE42;
4962 		  end if;
4963 		  if asked_for_rec.PRICING_ATTRIBUTE43 is not null then
4964 			i := px_Req_line_attr_tbl.count+1;
4965                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4966                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4967 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4968 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE43';
4969 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE43;
4970 		  end if;
4971 		  if asked_for_rec.PRICING_ATTRIBUTE44 is not null then
4972 			i := px_Req_line_attr_tbl.count+1;
4973                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4974                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4975 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4976 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE44';
4977 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE44;
4978 		  end if;
4979 		  if asked_for_rec.PRICING_ATTRIBUTE45 is not null then
4980 			i := px_Req_line_attr_tbl.count+1;
4981                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4982                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4983 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4984 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE45';
4985 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE45;
4986 		  end if;
4987 		  if asked_for_rec.PRICING_ATTRIBUTE46 is not null then
4988 			i := px_Req_line_attr_tbl.count+1;
4989                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4990                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4991 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
4992 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE46';
4993 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE46;
4994 		  end if;
4995 		  if asked_for_rec.PRICING_ATTRIBUTE47 is not null then
4996 			i := px_Req_line_attr_tbl.count+1;
4997                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
4998                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
4999 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5000 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE47';
5001 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE47;
5002 		  end if;
5003 		  if asked_for_rec.PRICING_ATTRIBUTE48 is not null then
5004 			i := px_Req_line_attr_tbl.count+1;
5005                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5006                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5007 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5008 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE48';
5009 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE48;
5010 		  end if;
5011 		  if asked_for_rec.PRICING_ATTRIBUTE49 is not null then
5012 			i := px_Req_line_attr_tbl.count+1;
5013                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5014                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5015 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5016 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE49';
5017 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE49;
5018 		  end if;
5019 
5020 		  if asked_for_rec.PRICING_ATTRIBUTE50 is not null then
5021 			i := px_Req_line_attr_tbl.count+1;
5022                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5023                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5024 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5025 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE50';
5026 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE50;
5027 		  end if;
5028 		  if asked_for_rec.PRICING_ATTRIBUTE51 is not null then
5029 			i := px_Req_line_attr_tbl.count+1;
5030                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5031                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5032 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5033 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE51';
5034 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE51;
5035 		  end if;
5036 		  if asked_for_rec.PRICING_ATTRIBUTE52 is not null then
5037 			i := px_Req_line_attr_tbl.count+1;
5038                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5039                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5040 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5041 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE52';
5042 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE52;
5043 		  end if;
5044 		  if asked_for_rec.PRICING_ATTRIBUTE53 is not null then
5045 			i := px_Req_line_attr_tbl.count+1;
5046                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5047                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5048 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5049 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE53';
5050 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE53;
5051 		  end if;
5052 		  if asked_for_rec.PRICING_ATTRIBUTE54 is not null then
5053 			i := px_Req_line_attr_tbl.count+1;
5054                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5055                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5056 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5057 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE54';
5058 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE54;
5059 		  end if;
5060 		  if asked_for_rec.PRICING_ATTRIBUTE55 is not null then
5061 			i := px_Req_line_attr_tbl.count+1;
5062                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5063                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5064 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5065 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE55';
5066 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE55;
5067 		  end if;
5068 		  if asked_for_rec.PRICING_ATTRIBUTE56 is not null then
5069 			i := px_Req_line_attr_tbl.count+1;
5070                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5071                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5072 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5073 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE56';
5074 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE56;
5075 		  end if;
5076 		  if asked_for_rec.PRICING_ATTRIBUTE57 is not null then
5077 			i := px_Req_line_attr_tbl.count+1;
5078                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5079                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5080 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5081 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE57';
5082 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE57;
5083 		  end if;
5084 		  if asked_for_rec.PRICING_ATTRIBUTE58 is not null then
5085 			i := px_Req_line_attr_tbl.count+1;
5086                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5087                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5088 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5089 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE58';
5090 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE58;
5091 		  end if;
5092 		  if asked_for_rec.PRICING_ATTRIBUTE59 is not null then
5093 			i := px_Req_line_attr_tbl.count+1;
5094                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5095                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5096 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5097 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE59';
5098 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE59;
5099 		  end if;
5100 
5101 		  if asked_for_rec.PRICING_ATTRIBUTE60 is not null then
5102 			i := px_Req_line_attr_tbl.count+1;
5103                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5104                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5105 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5106 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE60';
5107 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE60;
5108 		  end if;
5109 		  if asked_for_rec.PRICING_ATTRIBUTE61 is not null then
5110 			i := px_Req_line_attr_tbl.count+1;
5111                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5112                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5113 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5114 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE61';
5115 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE61;
5116 		  end if;
5117 		  if asked_for_rec.PRICING_ATTRIBUTE62 is not null then
5118 			i := px_Req_line_attr_tbl.count+1;
5119                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5120                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5121 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5122 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE62';
5123 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE62;
5124 		  end if;
5125 		  if asked_for_rec.PRICING_ATTRIBUTE63 is not null then
5126 			i := px_Req_line_attr_tbl.count+1;
5127                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5128                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5129 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5130 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE63';
5131 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE63;
5132 		  end if;
5133 		  if asked_for_rec.PRICING_ATTRIBUTE64 is not null then
5134 			i := px_Req_line_attr_tbl.count+1;
5135                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5136                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5137 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5138 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE64';
5139 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE64;
5140 		  end if;
5141 		  if asked_for_rec.PRICING_ATTRIBUTE65 is not null then
5142 			i := px_Req_line_attr_tbl.count+1;
5143                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5144                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5145 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5146 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE65';
5147 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE65;
5148 		  end if;
5149 		  if asked_for_rec.PRICING_ATTRIBUTE66 is not null then
5150 			i := px_Req_line_attr_tbl.count+1;
5151                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5152                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5153 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5154 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE66';
5155 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE66;
5156 		  end if;
5157 		  if asked_for_rec.PRICING_ATTRIBUTE67 is not null then
5158 			i := px_Req_line_attr_tbl.count+1;
5159                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5160                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5161 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5162 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE67';
5163 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE67;
5164 		  end if;
5165 		  if asked_for_rec.PRICING_ATTRIBUTE68 is not null then
5166 			i := px_Req_line_attr_tbl.count+1;
5167                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5168                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5169 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5170 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE68';
5171 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE68;
5172 		  end if;
5173 		  if asked_for_rec.PRICING_ATTRIBUTE69 is not null then
5174 			i := px_Req_line_attr_tbl.count+1;
5175                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5176                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5177 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5178 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE69';
5179 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE69;
5180 		  end if;
5181 
5182 		  if asked_for_rec.PRICING_ATTRIBUTE70 is not null then
5183 			i := px_Req_line_attr_tbl.count+1;
5184                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5185                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5186 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5187 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE70';
5188 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE70;
5189 		  end if;
5190 		  if asked_for_rec.PRICING_ATTRIBUTE71 is not null then
5191 			i := px_Req_line_attr_tbl.count+1;
5192                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5193                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5194 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5195 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE71';
5196 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE71;
5197 		  end if;
5198 		  if asked_for_rec.PRICING_ATTRIBUTE72 is not null then
5199 			i := px_Req_line_attr_tbl.count+1;
5200                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5201                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5202 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5203 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE72';
5204 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE72;
5205 		  end if;
5206 		  if asked_for_rec.PRICING_ATTRIBUTE73 is not null then
5207 			i := px_Req_line_attr_tbl.count+1;
5208                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5209                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5210 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5211 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE73';
5212 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE73;
5213 		  end if;
5214 		  if asked_for_rec.PRICING_ATTRIBUTE74 is not null then
5215 			i := px_Req_line_attr_tbl.count+1;
5216                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5217                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5218 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5219 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE74';
5220 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE74;
5221 		  end if;
5222 		  if asked_for_rec.PRICING_ATTRIBUTE75 is not null then
5223 			i := px_Req_line_attr_tbl.count+1;
5224                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5225                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5226 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5227 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE75';
5228 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE75;
5229 		  end if;
5230 		  if asked_for_rec.PRICING_ATTRIBUTE76 is not null then
5231 			i := px_Req_line_attr_tbl.count+1;
5232                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5233                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5234 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5235 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE76';
5236 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE76;
5237 		  end if;
5238 		  if asked_for_rec.PRICING_ATTRIBUTE77 is not null then
5239 			i := px_Req_line_attr_tbl.count+1;
5240                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5241                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5242 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5243 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE77';
5244 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE77;
5245 		  end if;
5246 		  if asked_for_rec.PRICING_ATTRIBUTE78 is not null then
5247 			i := px_Req_line_attr_tbl.count+1;
5248                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5249                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5250 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5251 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE78';
5252 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE78;
5253 		  end if;
5254 		  if asked_for_rec.PRICING_ATTRIBUTE79 is not null then
5255 			i := px_Req_line_attr_tbl.count+1;
5256                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5257                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5258 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5259 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE79';
5260 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE79;
5261 		  end if;
5262 
5263 		  if asked_for_rec.PRICING_ATTRIBUTE80 is not null then
5264 			i := px_Req_line_attr_tbl.count+1;
5265                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5266                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5267 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5268 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE80';
5269 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE80;
5270 		  end if;
5271 		  if asked_for_rec.PRICING_ATTRIBUTE81 is not null then
5272 			i := px_Req_line_attr_tbl.count+1;
5273                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5274                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5275 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5276 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE81';
5277 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE81;
5278 		  end if;
5279 		  if asked_for_rec.PRICING_ATTRIBUTE82 is not null then
5280 			i := px_Req_line_attr_tbl.count+1;
5281                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5282                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5283 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5284 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE82';
5285 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE82;
5286 		  end if;
5287 		  if asked_for_rec.PRICING_ATTRIBUTE83 is not null then
5288 			i := px_Req_line_attr_tbl.count+1;
5289                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5290                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5291 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5292 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE83';
5293 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE83;
5294 		  end if;
5295 		  if asked_for_rec.PRICING_ATTRIBUTE84 is not null then
5296 			i := px_Req_line_attr_tbl.count+1;
5297                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5298                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5299 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5300 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE84';
5301 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE84;
5302 		  end if;
5303 		  if asked_for_rec.PRICING_ATTRIBUTE85 is not null then
5304 			i := px_Req_line_attr_tbl.count+1;
5305                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5306                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5307 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5308 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE85';
5309 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE85;
5310 		  end if;
5311 		  if asked_for_rec.PRICING_ATTRIBUTE86 is not null then
5312 			i := px_Req_line_attr_tbl.count+1;
5313                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5314                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5315 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5316 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE86';
5317 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE86;
5318 		  end if;
5319 		  if asked_for_rec.PRICING_ATTRIBUTE87 is not null then
5320 			i := px_Req_line_attr_tbl.count+1;
5321                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5322                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5323 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5324 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE87';
5325 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE87;
5326 		  end if;
5327 		  if asked_for_rec.PRICING_ATTRIBUTE88 is not null then
5328 			i := px_Req_line_attr_tbl.count+1;
5329                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5330                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5331 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5332 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE88';
5333 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE88;
5334 		  end if;
5335 		  if asked_for_rec.PRICING_ATTRIBUTE89 is not null then
5336 			i := px_Req_line_attr_tbl.count+1;
5337                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5338                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5339 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5340 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE89';
5341 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE89;
5342 		  end if;
5343 
5344 		  if asked_for_rec.PRICING_ATTRIBUTE90 is not null then
5345 			i := px_Req_line_attr_tbl.count+1;
5346                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5347                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5348 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5349 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE90';
5350 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE90;
5351 		  end if;
5352 		  if asked_for_rec.PRICING_ATTRIBUTE91 is not null then
5353 			i := px_Req_line_attr_tbl.count+1;
5354                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5355                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5356 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5357 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE91';
5358 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE91;
5359 		  end if;
5360 		  if asked_for_rec.PRICING_ATTRIBUTE92 is not null then
5361 			i := px_Req_line_attr_tbl.count+1;
5362                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5363                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5364 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5365 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE92';
5366 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE92;
5367 		  end if;
5368 		  if asked_for_rec.PRICING_ATTRIBUTE93 is not null then
5369 			i := px_Req_line_attr_tbl.count+1;
5370                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5371                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5372 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5373 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE93';
5374 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE93;
5375 		  end if;
5376 		  if asked_for_rec.PRICING_ATTRIBUTE94 is not null then
5377 			i := px_Req_line_attr_tbl.count+1;
5378                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5379                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5380 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5381 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE94';
5382 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE94;
5383 		  end if;
5384 		  if asked_for_rec.PRICING_ATTRIBUTE95 is not null then
5385 			i := px_Req_line_attr_tbl.count+1;
5386                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5387                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5388 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5389 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE95';
5390 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE95;
5391 		  end if;
5392 		  if asked_for_rec.PRICING_ATTRIBUTE96 is not null then
5393 			i := px_Req_line_attr_tbl.count+1;
5394                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5395                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5396 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5397 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE96';
5398 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE96;
5399 		  end if;
5400 		  if asked_for_rec.PRICING_ATTRIBUTE97 is not null then
5401 			i := px_Req_line_attr_tbl.count+1;
5402                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5403                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5404 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5405 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE97';
5406 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE97;
5407 		  end if;
5408 		  if asked_for_rec.PRICING_ATTRIBUTE98 is not null then
5409 			i := px_Req_line_attr_tbl.count+1;
5410                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5411                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5412 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5413 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE98';
5414 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE98;
5415 		  end if;
5416 		  if asked_for_rec.PRICING_ATTRIBUTE99 is not null then
5417 			i := px_Req_line_attr_tbl.count+1;
5418                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5419                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5420 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5421 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE99';
5422 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From :=asked_for_rec.PRICING_ATTRIBUTE99;
5423 		  end if;
5424 		  if asked_for_rec.PRICING_ATTRIBUTE100 is not null then
5425 			i := px_Req_line_attr_tbl.count+1;
5426                px_Req_line_attr_tbl(i).Line_Index := p_Line_Index;
5427                px_Req_line_attr_tbl(i).Validated_Flag := 'N';
5428 		  	px_Req_line_attr_tbl(i).pricing_context := asked_for_rec.pricing_context;
5429 		  	px_Req_line_attr_tbl(i).Pricing_Attribute := 'PRICING_ATTRIBUTE100';
5430 		  	px_Req_line_attr_tbl(i).Pricing_Attr_Value_From:=asked_for_rec.PRICING_ATTRIBUTE100;
5431 		  end if;
5432 
5433 		else -- Copy the Qualifiers
5434 		G_STMT_NO := 'Append_asked_for#20';
5435 		  if asked_for_rec.PRICING_ATTRIBUTE1 is not null and asked_for_rec.PRICING_ATTRIBUTE2 is null then -- Promotion
5436 			i := px_Req_Qual_Tbl.count+1;
5437                px_Req_Qual_Tbl(i).Line_Index := p_Line_Index;
5438                px_Req_Qual_Tbl(i).Validated_Flag := nvl(asked_for_rec.Override_Flag,'N');
5439 		  	px_Req_Qual_Tbl(i).Qualifier_Context := asked_for_rec.pricing_context;
5440 		  	px_Req_Qual_Tbl(i).Qualifier_Attribute := 'QUALIFIER_ATTRIBUTE1';
5441 		  	px_Req_Qual_Tbl(i).Qualifier_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE1;
5442 		  end if;
5443 		  if asked_for_rec.PRICING_ATTRIBUTE2 is not null then --Deal Component
5444 			i := px_Req_Qual_Tbl.count+1;
5445                px_Req_Qual_Tbl(i).Line_Index := p_Line_Index;
5446                px_Req_Qual_Tbl(i).Validated_Flag := nvl(asked_for_rec.Override_Flag,'N');
5447 		  	px_Req_Qual_Tbl(i).Qualifier_Context := asked_for_rec.pricing_context;
5448 		  	px_Req_Qual_Tbl(i).Qualifier_Attribute := 'QUALIFIER_ATTRIBUTE2';
5449 		  	px_Req_Qual_Tbl(i).Qualifier_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE2;
5450 		  end if;
5451 		  if asked_for_rec.PRICING_ATTRIBUTE3 is not null then -- Coupons
5452 			i := px_Req_Qual_Tbl.count+1;
5453                px_Req_Qual_Tbl(i).Line_Index := p_Line_Index;
5454                px_Req_Qual_Tbl(i).Validated_Flag := nvl(asked_for_rec.Override_Flag,'N');
5455 		  	px_Req_Qual_Tbl(i).Qualifier_Context := asked_for_rec.pricing_context;
5456 		  	px_Req_Qual_Tbl(i).Qualifier_Attribute := 'QUALIFIER_ATTRIBUTE3';
5457 		  	px_Req_Qual_Tbl(i).Qualifier_Attr_Value_From := asked_for_rec.PRICING_ATTRIBUTE3;
5458 		  end if;
5459 
5460 		end if;
5461 	end loop;
5462 
5463 	adj_debug('Exiting oe_order_Adj_pvt.Append_asked_for',1);
5464 
5465 end Append_asked_for;
5466 
5467 procedure Get_the_parent_Line(p_Reference_line_Id	Number,
5468 					px_Line_Tbl  in out nocopy OE_Order_Pub.Line_Tbl_Type,
5469 					px_Req_related_lines_tbl  in out nocopy QP_PREQ_GRP.Related_Lines_Tbl_Type,
5470 					p_line_Tbl_index	Number)
5471 is
5472 l_Line_Rec		 OE_Order_Pub.Line_Rec_Type;
5473 line_Tbl_Index			pls_integer;
5474 l_related_lines_Index		pls_integer;
5475 Begin
5476 	G_STMT_NO := 'Get_the_parent_Line#10';
5477 	adj_debug('Entering oe_order_Adj_pvt.Get_the_parent_Line',1);
5478 	line_Tbl_Index := px_Line_Tbl.First;
5479 	While line_Tbl_Index is not null loop
5480 		If px_Line_Tbl(line_Tbl_Index).line_Id = p_Reference_line_Id  Then
5481 			Exit;
5482 		End If;
5483 		line_Tbl_Index := px_Line_Tbl.Next(line_Tbl_Index);
5484 	End Loop;
5485 
5486 	G_STMT_NO := 'Get_the_parent_Line#20';
5487 
5488 	If line_Tbl_Index is null Then
5489 	-- Parent Line is not found in px_line_tbl
5490 		Begin
5491 			line_Tbl_index := px_line_tbl.count+1;
5492 
5493                         oe_line_util.query_row(p_Reference_line_Id,L_Line_Rec );
5494 			px_Line_Tbl(line_Tbl_index) := L_Line_Rec;
5495                         -- Parent Line is only for info purpose, don't calculate price
5496                      -- px_Line_Tbl(line_Tbl_index).calculate_price_flag := 'N';
5497 				 -- modified by lkxu, to be used in repricing
5498                         px_Line_Tbl(line_Tbl_index).calculate_price_flag := 'X';
5499 		Exception when No_Data_Found Then
5500 			Null;
5501 		End;
5502 	End If;
5503 			-- Populate the Relationship
5504 	l_related_lines_Index	:= px_Req_related_lines_tbl.count+1;
5505 	px_Req_related_lines_tbl(l_related_lines_Index).Line_Index := line_Tbl_index;
5506 	px_Req_related_lines_tbl(l_related_lines_Index).Related_Line_Index := p_line_Tbl_index;
5507 	px_Req_related_lines_tbl(l_related_lines_Index).Relationship_Type_Code
5508 											:= QP_PREQ_GRP.G_SERVICE_LINE;
5509 
5510 	adj_debug('Exiting oe_order_Adj_pvt.Get_the_parent_Line',1);
5511 
5512 End Get_the_parent_Line;
5513 
5514 procedure set_item_for_iue(
5515 px_line_rec	 in out nocopy OE_Order_PUB.line_rec_type
5516 ,p_req_line_detail_rec 		QP_PREQ_GRP.line_detail_rec_type
5517 )
5518 is
5519 -- This change is required since we are dropping the profile OE_ORGANIZATION    -- _ID. Change made by Esha.
5520 /*l_org_id                 NUMBER := FND_PROFILE.Value('OE_ORGANIZATION_ID');*/
5521 l_org_id NUMBER := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
5522 l_ordered_item			varchar2(300);
5523 
5524 begin
5525 	 adj_debug('Entering oe_order_Adj_pvt.set_item_for_iue');
5526 
5527 /*begin original item*/
5528 	 oe_debug_pub.ADD('px_line_rec.original_inventory_item_id:'||px_line_rec.INVENTORY_ITEM_ID,1);
5529 	 oe_debug_pub.ADD('px_line_rec.original_inventory_item_id:'||px_line_rec.original_INVENTORY_ITEM_ID,1);
5530 	 oe_debug_pub.ADD('px_line_rec.original_ordered_item_id:'||px_line_rec.ordered_item_id,1);
5531 	 oe_debug_pub.ADD('px_line_rec.original_item_identifier_type:'||px_line_rec.item_identifier_type,1);
5532 	 oe_debug_pub.ADD('px_line_rec.original_ordered_item:'||px_line_rec.ordered_item,1);
5533 
5534 	 IF px_line_rec.original_inventory_item_id IS NULL THEN
5535 	 px_line_rec.original_inventory_item_id :=px_line_rec.INVENTORY_ITEM_ID;
5536 	 px_line_rec.original_ordered_item_id :=px_line_rec.ORDERED_ITEM_ID;
5537 	 px_line_rec.original_item_identifier_type :=px_line_rec.item_identifier_type;
5538 	 px_line_rec.original_ordered_item :=px_line_rec.ordered_item;
5539 	 px_line_rec.item_relationship_type :=14;
5540          END IF;
5541 
5542 /*end original item*/
5543 
5544 	  -- There is an item upgrade for this line
5545 	 px_line_rec.inventory_item_id := p_req_line_detail_rec.RELATED_ITEM_ID;
5546 	 px_line_rec.item_identifier_type := 'INT'; --bug 2281351
5547 	   If px_line_rec.item_identifier_type ='INT' then
5548 	   	px_line_rec.ordered_item_id := p_req_line_detail_rec.RELATED_ITEM_ID;
5549 	   	Begin
5550 			SELECT concatenated_segments
5551 			INTO   px_line_rec.ordered_item
5552 			FROM   mtl_system_items_kfv
5553 			WHERE  inventory_item_id = px_line_rec.inventory_item_id
5554 			AND    organization_id = l_org_id;
5555 			Exception when no_data_found then
5556 		 	Null;
5557 	  	End;
5558 	  End If;
5559 
5560 	 adj_debug('Exiting oe_order_Adj_pvt.set_item_for_iue');
5561 end set_item_for_iue;
5562 
5563 procedure Get_item_for_iue(px_line_rec	 in out nocopy OE_Order_PUB.line_rec_type)
5564 is
5565 -- This change is required since we are dropping the profile OE_ORGANIZATION    -- _ID. Change made by Esha.
5566 l_org_id Number:= OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
5567 /*l_org_id                 NUMBER := FND_PROFILE.Value('OE_ORGANIZATION_ID');*/
5568 l_ordered_item			varchar2(300);
5569 cursor adj_cur is
5570 	select modified_from from oe_price_adjustments
5571 	where line_id=px_line_rec.line_id
5572 		and list_line_type_code='IUE';
5573 begin
5574 	 adj_debug('Entering oe_order_Adj_pvt.Get_item_for_iue',1);
5575 	 For Adj_rec in Adj_cur loop
5576 	  -- There is an item upgrade for this line
5577 	   px_line_rec.inventory_item_id := to_number(Adj_rec.modified_from);
5578 
5579 
5580 	   If px_line_rec.item_identifier_type ='INT' then
5581 	   	px_line_rec.ordered_item_id := to_number(Adj_rec.modified_from);
5582 	     Begin
5583 			SELECT concatenated_segments
5584 			INTO   px_line_rec.ordered_item
5585 			FROM   mtl_system_items_kfv
5586 			WHERE  inventory_item_id = px_line_rec.inventory_item_id
5587 			AND    organization_id = l_org_id;
5588 			Exception when no_data_found then
5589 		 	Null;
5590 	  	End;
5591 	  End If;
5592 	  Exit;
5593 	End Loop;
5594 
5595 	 adj_debug('Exiting oe_order_Adj_pvt.Get_item_for_iue',1);
5596 end Get_item_for_iue;
5597 
5598 procedure calculate_adjustments(
5599 x_return_status out nocopy varchar2,
5600 
5601 p_line_id					number default null,
5602 p_header_id				number Default null,
5603 p_Request_Type_Code			varchar2 ,
5604 p_Control_Rec				QP_PREQ_GRP.CONTROL_RECORD_TYPE,
5605 x_req_line_tbl                out  nocopy QP_PREQ_GRP.LINE_TBL_TYPE,
5606 x_Req_qual_tbl                out  nocopy QP_PREQ_GRP.QUAL_TBL_TYPE,
5607 x_Req_line_attr_tbl           out  nocopy QP_PREQ_GRP.LINE_ATTR_TBL_TYPE,
5608 x_Req_LINE_DETAIL_tbl         out  nocopy QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
5609 x_Req_LINE_DETAIL_qual_tbl    out  nocopy QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE,
5610 x_Req_LINE_DETAIL_attr_tbl    out  nocopy QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE,
5611 x_Req_related_lines_tbl       out  nocopy QP_PREQ_GRP.RELATED_LINES_TBL_TYPE,
5612 p_use_current_header          in   Boolean      Default FALSE
5613 --if use_current_header set to true, it will not set the header info
5614 --and it will use current header information set by the caller.
5615 --It is useful when getting a quote where header_id is not available.
5616 --in this case the caller will need to set Oe_Order_Pub.G_Hdr values
5617 ,p_write_to_db			  Boolean 	Default TRUE
5618 ,x_any_frozen_line out nocopy Boolean
5619 
5620 ,x_Header_Rec out nocopy oe_Order_Pub.Header_REc_Type
5621 
5622 ,x_line_Tbl			   in out nocopy  oe_Order_Pub.Line_Tbl_Type
5623 ,p_honor_price_flag			VARCHAR2 Default 'Y'
5624 ,p_multiple_events                 in   VARCHAR2 Default 'N'
5625 ,p_action_code                in VARCHAR2 Default 'NONE'
5626 )
5627 is
5628 l_return_status	 varchar2(1) := FND_API.G_RET_STS_SUCCESS;
5629 l_return_status_Text	 varchar2(240) ;
5630 l_header_rec		OE_Order_PUB.Header_Rec_Type;
5631 l_Line_Tbl		OE_Order_PUB.Line_Tbl_Type;
5632 l_line_tbl_tmp          OE_Order_PUB.Line_Tbl_Type;
5633 --1472635
5634 l_temp_line_tbl         OE_Order_PUB.Line_Tbl_type;
5635 i2                      PLS_INTEGER;
5636 l_all_lines_from_db         Boolean :=False;
5637 
5638 l_Line_Rec		OE_Order_PUB.Line_Rec_Type;
5639 l_req_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE;
5640 l_Req_qual_tbl                  QP_PREQ_GRP.QUAL_TBL_TYPE;
5641 l_Req_line_attr_tbl             QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
5642 l_Req_LINE_DETAIL_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
5643 l_Req_LINE_DETAIL_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
5644 l_Req_LINE_DETAIL_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
5645 l_Req_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
5646 l_pricing_contexts_Tbl		  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
5647 l_qualifier_contexts_Tbl		  QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
5648 lx_req_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE;
5649 lx_Req_qual_tbl                  QP_PREQ_GRP.QUAL_TBL_TYPE;
5650 lx_Req_line_attr_tbl             QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
5651 lx_Req_LINE_DETAIL_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
5652 lx_Req_LINE_DETAIL_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
5653 lx_Req_LINE_DETAIL_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
5654 lx_Req_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
5655 Process_Service_Lines		   Boolean := FALSE;
5656 l_related_lines_Index		   pls_integer;
5657 line_tbl_index				   pls_integer;
5658 i				   pls_integer;
5659 l_bypass_pricing				varchar2(30) :=  nvl(FND_PROFILE.VALUE('QP_BYPASS_PRICING'),'N');
5660 l_dummy					Varchar2(1);
5661 l_header_id                             NUMBER;
5662 l_any_frozen_line BOOLEAN:=FALSE;
5663 l_calculate_price_flag varchar2(1);
5664 l_message_displayed Boolean:=FALSE;
5665 /* Variables added for bug 1828553 */
5666 l_order_line_id  number;
5667 l_service_reference_line_id  number;
5668 --btea begin
5669 l_Control_Rec				QP_PREQ_GRP.CONTROL_RECORD_TYPE;
5670 --btea end
5671 -- Variable for Bug 2124989
5672 l_agreement_name  varchar2(240);
5673 l_revision        varchar2(50);
5674 OE_AGREEMENT_ERROR  Exception;
5675 -- End of 21249898
5676 
5677 QP_ATTR_MAPPING_ERROR Exception;
5678 l_completely_frozen BOOLEAN := TRUE;
5679 
5680 l_order_status_rec QP_UTIL_PUB.ORDER_LINES_STATUS_REC_TYPE;
5681 l_pass_all_lines	VARCHAR2(30);
5682 l_exists_phase	  	VARCHAR2(1) := 'N';
5683 l_set_of_books Oe_Order_Cache.Set_Of_Books_Rec_Type;
5684 j PLS_INTEGER :=1;
5685 G_INT_CHANGED_LINE_ON Varchar2(3):= nvl(FND_PROFILE.VALUE('ONT_INTERNAL_CHANGED_LINE'),'Y');
5686 l_header_id2 NUMBER;
5687 begin
5688 
5689 
5690 	  adj_debug('Entering oe_line_adj.calulate_adjustments', 1);
5691 
5692 	G_STMT_NO := 'calculate_adjustments#10';
5693 	if (p_line_id is null or p_line_id = FND_API.G_MISS_NUM)
5694 	   and ( p_header_id is null or p_header_id = FND_API.G_MISS_NUM)
5695 	   and  x_line_Tbl.count =0
5696            and  p_use_current_header = FALSE
5697 	then
5698 		   l_return_status := FND_API.G_RET_STS_ERROR;
5699 
5700 		IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
5701 		THEN
5702 
5703 		    FND_MESSAGE.SET_NAME('ONT','OE_ATTRIBUTE_REQUIRED');
5704 		    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','line_id or Header Id ');
5705 		    OE_MSG_PUB.Add;
5706 		END IF;
5707 		RAISE FND_API.G_EXC_ERROR;
5708 	end if;
5709 
5710 	G_STMT_NO := 'calculate_adjustments#20';
5711 	if p_Line_id is not null and p_Header_id is not null then
5712 		IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5713 		THEN
5714 			OE_MSG_PUB.Add_Exc_Msg (   G_PKG_NAME ,
5715 			'oe_line_adj.calulate_adjustments'
5716 			,'Keys are mutually exclusive');
5717 		END IF;
5718 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5719 	end if;
5720 
5721 --	Query the header Record
5722 	if p_header_id is not null  and p_Header_id <> FND_API.G_MISS_NUM then
5723 
5724 	G_STMT_NO := 'calculate_adjustments#30';
5725 
5726 	   Begin
5727 
5728                 oe_Header_util.query_row (p_header_id => p_Header_id
5729                                           ,x_header_rec=>OE_Order_PUB.g_hdr );
5730 		Exception when no_data_found then
5731 			x_return_status := 'NOOP';
5732 			adj_debug(G_STMT_NO||'Invalid header_id '||p_Header_id,1);
5733 			Return;
5734 	   End;
5735 	G_STMT_NO := 'calculate_adjustments#40';
5736 
5737            oe_debug_pub.add('Passed in event code:'||p_control_rec.pricing_event);
5738 
5739        -- bug 9728497 start
5740        -- modified below for p_x_new_line_rec.header_id and p_x_new_line_rec.line_id
5741        -- being passed on to call the overloaded function.
5742 	   --  QP_UTIL_PUB.Get_Order_Lines_Status
5743            --    (p_control_rec.pricing_event,l_order_status_rec);
5744                QP_UTIL_PUB.Get_Order_Lines_Status(p_event_code => p_control_rec.pricing_event,
5745                                             p_header_id => p_header_id,
5746                                             p_line_id => p_Line_id,
5747                                             x_order_status_rec =>l_order_status_rec);
5748        -- bug 9728497 end
5749 
5750            oe_debug_pub.add('Pricing Engine return pass all_lines value:'||l_order_status_rec.ALL_LINES_FLAG);
5751            oe_debug_pub.add('Pricing Engine return pass changed line value:'||l_order_status_rec.Changed_Lines_Flag);
5752            oe_debug_pub.add('Cache header operation:'||oe_order_pub.g_hdr.operation);
5753 
5754 
5755         If  G_INT_CHANGED_LINE_ON = 'Y' Then
5756              If (l_order_status_rec.ALL_LINES_FLAG = 'Y' and nvl(OE_LINE_ADJ_UTIL.G_SEND_ALL_LINES_FOR_DSP,'Y') = 'Y') --bug 2965218
5757              --   or p_multiple_events = 'Y'
5758                 or (OE_GLOBALS.G_RECURSION_MODE <> FND_API.G_TRUE
5759                     and p_control_rec.pricing_event = 'BOOK')
5760                 or p_action_code = 'PRICE_ORDER' --user request to reprice all lines
5761                 or Oe_Line_Adj_Util.has_service_lines(p_header_id)
5762              Then
5763                ----------------------------------------------------------------
5764                --Pricing says pass all lines, use query_lines is more efficient
5765                ----------------------------------------------------------------
5766                adj_debug('Query all_lines');
5767                oe_Line_util.query_rows(p_header_id => p_Header_id, x_line_tbl => l_Line_Tbl);
5768                g_pass_all_lines:='Y';
5769              Elsif l_order_status_rec.CHANGED_LINES_FLAG = 'Y' OR nvl(OE_LINE_ADJ_UTIL.G_SEND_ALL_LINES_FOR_DSP,'Y') = 'N' Then
5770                -------------------------------------------------------------------
5771                --Pricing says pass only changed lines, use query_line
5772                --------------------------------------------------------------------
5773                oe_debug_pub.add('Query individual line');
5774                g_pass_all_lines:='N';
5775                i := Oe_Line_Adj_Util.G_CHANGED_LINE_TBL.FIRST;
5776                While i is Not Null Loop
5777                   Begin
5778    --bug 3020702
5779                oe_debug_pub.add(' header_id:'||Oe_Line_Adj_Util.G_CHANGED_LINE_TBL(i).header_id);
5780      if oe_line_adj_util.G_CHANGED_LINE_TBL(i).header_id = p_header_id then
5781                   oe_debug_pub.add(' trying to query line_id:'||Oe_Line_Adj_Util.G_CHANGED_LINE_TBL(i).line_id);
5782                   l_line_tbl(j):=oe_line_util.query_row(p_line_id =>Oe_Line_Adj_Util.G_CHANGED_LINE_TBL(i).line_id);
5783                   j:=j+1;
5784      end if;
5785                   Exception when no_data_found then
5786                      oe_debug_pub.add('Not found line id:'||Oe_Line_Adj_Util.G_CHANGED_LINE_TBL(i).line_id);
5787                   End;
5788                   i:= Oe_Line_Adj_Util.G_CHANGED_LINE_TBL.Next(i);
5789                End Loop;
5790              End If;
5791 
5792         Else
5793 
5794           If p_multiple_events = 'N' Then
5795              -- bug 2089312, call QP API to determine whether or not to
5796              -- all lines to pricing engine.
5797            If  l_order_status_rec.ALL_LINES_FLAG = 'Y' Or
5798                l_order_status_rec.Changed_Lines_Flag = 'Y' Then
5799                G_PASS_ALL_LINES := 'Y';
5800            End If;
5801           Else  --it is a multiple events we always pass all lines when it is a multiple events call
5802           --  G_PASS_ALL_LINES := 'Y';
5803               null;
5804           End If;
5805 
5806              --temporary fix for bug 2199678 for patchset G, we will need
5807              --to change this later for performacne in book event
5808              If p_control_rec.pricing_event = 'BOOK' or p_action_code = 'PRICE_ORDER' Then
5809                 G_PASS_ALL_LINES := 'Y';
5810              End If;
5811 
5812              adj_debug('in calculate_adjustments, all_lines_flag is: '||G_PASS_ALL_LINES,1);
5813              -- only to pass all lines when the returned all_lines_flag is Y.
5814              IF G_PASS_ALL_LINES = 'Y' THEN
5815 	       Begin
5816                  adj_debug('querying up all lines in header: '||p_Header_id,3);
5817                  oe_Line_util.query_rows(p_header_id => p_Header_id, x_line_tbl => l_Line_Tbl);
5818                  --1472635
5819                  l_all_lines_from_db := True;
5820 	       Exception when no_data_found then
5821 	         -- No need to process this order
5822 		 x_return_status := 'NOOP';
5823 		 adj_debug(G_STMT_NO||'Invalid header_id '||p_Header_id,1);
5824 		 Return;
5825 	       End ;
5826              END IF;
5827 	 End If;  --G_INT_CHANGED_LINE_ON
5828 	else -- Query the line Record
5829 	  G_STMT_NO := 'calculate_adjustments#50';
5830        If x_line_Tbl.count = 0	Then
5831 		Begin
5832 
5833                    oe_line_util.query_rows(p_line_id =>p_line_id, x_line_tbl=>l_Line_Tbl );
5834 
5835 
5836 		   Exception when no_data_found then
5837 		   -- No need to process this line
5838 			x_return_status := 'NOOP';
5839 			adj_debug(G_STMT_NO||'Invalid line_id '||p_line_id,1);
5840 			Return;
5841 		End ;
5842 	  Else
5843 		l_Line_Tbl := x_line_Tbl;
5844 	  End If;
5845 	  G_STMT_NO := 'calculate_adjustments#60';
5846 
5847           If p_use_current_header = FALSE Then
5848 	    Begin
5849 	  	If l_line_tbl.first is not null Then
5850                  oe_Header_util.query_row
5851 		(p_header_id=> l_line_Tbl(l_line_tbl.first).Header_id, x_header_rec => OE_Order_PUB.g_hdr );
5852                 Else
5853                    oe_debug_pub.add(' Error: No line records in l_line_tbl');
5854                 End If;
5855 
5856 		Exception when no_data_found then
5857 		   -- No need to process this order
5858 			x_return_status := 'NOOP';
5859 			adj_debug(G_STMT_NO||'Invalid header_id '||l_line_Tbl(1).Header_id,1);
5860 			Return;
5861 	    End ;
5862           Else
5863              --Do Nothing since the flag says that the global record has been set
5864             NULL;
5865           End If;
5866 	end if;
5867 
5868 	G_STMT_NO := 'calculate_adjustments#110';
5869 	line_Tbl_Index := l_Line_Tbl.First;
5870 	While line_Tbl_Index is not null loop
5871 
5872 -- Added to check if Agreement is Active for Bug#2124989
5873 
5874 
5875             If l_line_tbl(line_Tbl_Index).agreement_id is not null Then
5876            BEGIN
5877                 Select 'x' into l_dummy from dual
5878                 where exists (select 'x' from oe_agreements_vl where
5879                 agreement_id = l_line_tbl(line_Tbl_Index).agreement_id and
5880                ( trunc(nvl(l_line_tbl(line_Tbl_Index).PRICING_DATE,sysdate))
5881                 between
5882                 trunc(nvl(start_date_active, nvl(l_line_tbl(line_Tbl_Index).PRICING_DATE,sysdate)))
5883                 and
5884                 trunc(nvl(end_date_active, nvl(l_line_tbl(line_Tbl_Index).PRICING_DATE, sysdate)))));
5885 
5886                --If l_dummy <>'x' then
5887 
5888               Exception
5889                When no_data_found then
5890                Begin
5891                select name, revision into l_agreement_name, l_revision
5892                from oe_agreements_vl where agreement_id =
5893                l_line_tbl(line_Tbl_Index).agreement_id;
5894 
5895                Exception
5896                When no_data_found then
5897                null;
5898                End;
5899               fnd_message.set_name('ONT','ONT_INVALID_AGR_REVISION');
5900               fnd_message.set_TOKEN('AGREEMENT',l_agreement_name||' : '||l_revision);
5901               fnd_message.set_TOKEN('PRICING_DATE',l_line_tbl(line_Tbl_Index).PRICING_DATE);
5902               OE_MSG_PUB.Add;
5903               RAISE OE_AGREEMENT_ERROR;
5904          END;
5905            End If;
5906 --End 2124989
5907 
5908 		-- Do not price the config items
5909 	   --If oe_line_util.Get_Return_Item_Type_Code(l_Line_Tbl(line_Tbl_Index)) <> 'CONFIG' Then
5910 
5911 
5912 		-- Populate that Global Structure
5913 		OE_Order_PUB.G_LINE := l_Line_Tbl(line_Tbl_Index);
5914                 -- uom begin
5915 		If OE_Order_PUB.G_LINE.unit_list_price_per_pqty = fnd_api.g_miss_num then
5916 			OE_Order_PUB.G_LINE.unit_list_price_per_pqty:= Null;
5917 		End If;
5918                 -- uom end
5919 
5920 		-- Check if the line is service item
5921 
5922 		G_STMT_NO := 'calculate_adjustments#120';
5923 		If  (OE_Order_PUB.G_LINE.Service_Reference_Line_Id <>
5924 				FND_API.G_MISS_NUM and
5925 			 OE_Order_PUB.G_LINE.Service_Reference_Line_Id is not null)
5926 		Then
5927 
5928 /* Added the following if condition for fixing the bug 1828553 */
5929      /* If the service reference context is ORDER, then the service_reference*/
5930      /*line_id is the line_id of the parent. However, if the service ref */
5931      /*context is Customer Product then we need to first retrieve the */
5932      /*original order line id */
5933 
5934      IF l_Line_Tbl(line_Tbl_Index).item_type_code = 'SERVICE' AND
5935         l_Line_Tbl(line_Tbl_Index).service_reference_type_code='CUSTOMER_PRODUCT' AND
5936         l_Line_Tbl(line_Tbl_Index).service_reference_line_id IS NOT NULL THEN
5937                  oe_debug_pub.add('1828553: Line is a customer product');
5938            OE_SERVICE_UTIL.Get_Cust_Product_Line_Id
5939            ( x_return_status    => l_return_status
5940            , p_reference_line_id => l_Line_Tbl(line_Tbl_Index).service_reference_line_id
5941            , p_customer_id       => l_Line_Tbl(line_Tbl_Index).sold_to_org_id
5942            , x_cust_product_line_id => l_order_line_id
5943            );
5944         IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
5945                  oe_debug_pub.add('1828553: Success');
5946                  oe_debug_pub.add('1828553: Service line id is ' || l_order_line_id)
5947 ;
5948            l_service_reference_line_id := l_order_line_id;
5949         ELSE
5950            oe_debug_pub.add('Not able to retrieve cust product line id');
5951                  RAISE NO_DATA_FOUND;
5952         END IF;
5953 
5954      ELSE
5955         l_service_reference_line_id := l_Line_Tbl(line_Tbl_Index).service_reference_line_id;
5956      END IF;
5957 
5958 
5959                  oe_debug_pub.add('1828553: l_Service_Reference_Line_Id: '||l_Service_Reference_Line_Id);
5960 --3273289{
5961             If(l_Service_Reference_Line_Id is NOT NULL) THEN
5962 
5963 		  Get_the_parent_Line(p_Reference_line_Id	=>
5964 					l_Service_Reference_Line_Id,
5965 					p_line_Tbl_Index => line_Tbl_Index,
5966 					px_Req_related_lines_tbl => l_Req_related_lines_tbl,
5967 					px_Line_Tbl => l_Line_Tbl) ;
5968            END IF;
5969 --3273289}
5970 End If;
5971 
5972 		-- Get Line Attributes
5973 		G_STMT_NO := 'calculate_adjustments#130';
5974                 Get_Item_For_Iue(px_line_rec => OE_Order_Pub.G_Line);
5975 
5976 	       If l_bypass_pricing = 'Y' Then
5977 
5978 			adj_debug('Bypassing the qualifier build',1);
5979 		  Else
5980 			  adj_debug('Before QP_Attr_Mapping_PUB.Build_Contexts for line',1);
5981                         Begin
5982 		  	  QP_Attr_Mapping_PUB.Build_Contexts(
5983 			     p_request_type_code => 'ONT',
5984 			     p_pricing_type	=>	'L',
5985 			     x_price_contexts_result_tbl => l_pricing_contexts_Tbl,
5986 			     x_qual_contexts_result_tbl  => l_qualifier_Contexts_Tbl
5987 			     );
5988                          Exception when others then
5989                           Raise QP_ATTR_MAPPING_ERROR;
5990                          End;
5991 		  End if;
5992 
5993 			G_STMT_NO := 'calculate_adjustments#135';
5994 
5995                 --Manual Begin
5996                 If l_line_tbl(line_tbl_index).open_flag = 'N' Then
5997                  l_line_tbl(line_tbl_index).calculate_price_flag := 'N';
5998                 End If;
5999                 --Manaul End
6000 
6001                 --Set a flag if this line has a calculate flag of N or P
6002                 --which is frozen line. This flag will be used later
6003                 --when passing summary line (order level) to pricing engine
6004                 --with calculate_price of N (do not touch the order level amount).
6005 
6006             IF l_line_tbl(line_tbl_index).item_type_code not in ('CONFIG', 'INCLUDED') THEN
6007                 IF ( l_line_tbl(line_tbl_index).calculate_price_flag IN ('N','P') AND
6008 		     l_line_tbl(line_tbl_index).cancelled_flag = 'N') THEN
6009 
6010                    l_any_frozen_line := TRUE;
6011                    x_any_frozen_line := TRUE;
6012                    adj_debug('Any frozen line is true');
6013 
6014                   IF l_line_tbl(line_tbl_index).calculate_price_flag = 'P' THEN
6015                     l_completely_frozen := FALSE;
6016                    END IF;
6017 
6018                 ELSIF l_line_tbl(line_tbl_index).calculate_price_flag = 'Y' THEN
6019                    l_completely_frozen := FALSE;
6020                 END IF;
6021 
6022          END IF;  /* if item_type_code not in config and included */
6023 
6024 		   copy_Line_to_request(
6025  			   p_Line_rec	 		=> l_Line_Tbl(line_Tbl_Index)
6026 			   ,p_pricing_event		=> p_control_rec.pricing_event
6027 	 		   ,px_req_line_tbl   	=> l_req_line_tbl
6028 	 		   ,p_Request_Type_Code 	=> p_Request_Type_Code
6029 			   ,p_honor_price_flag	=> p_honor_price_flag
6030 	 		   );
6031 
6032 		   -- added by lkxu, to set the value back to 'N' after setting price flag.
6033 		   IF l_line_Tbl(line_Tbl_Index).calculate_price_flag = 'X' THEN
6034 		     l_line_Tbl(line_Tbl_Index).calculate_price_flag := 'N';
6035              	   END IF;
6036 
6037 			G_STMT_NO := 'calculate_adjustments#140';
6038 		   copy_attribs_to_Req(
6039 			   p_line_index            => 	l_req_line_tbl.count
6040 			   ,p_pricing_contexts_Tbl 	=> 	l_pricing_contexts_Tbl
6041 			   ,p_qualifier_contexts_Tbl =>	l_qualifier_Contexts_Tbl
6042 			   ,px_Req_line_attr_tbl    =>	l_Req_line_attr_tbl
6043 			   ,px_Req_qual_tbl         =>	l_Req_qual_tbl
6044 				   );
6045 
6046 
6047 			G_STMT_NO := 'calculate_adjustments#150';
6048 		   Begin
6049                         l_header_id2:=nvl(p_header_id,l_line_tbl(line_tbl_index).header_id);
6050 			Select 'x' into l_dummy from dual
6051                         Where exists
6052                         (select 'x' from
6053                         oe_order_price_attribs oopa
6054 			where
6055 		        nvl(oopa.line_id,l_Line_Tbl(line_Tbl_Index).line_id) = l_Line_Tbl(line_Tbl_Index).line_id
6056 		      and oopa.header_id = l_header_id2);
6057 
6058 		   	Append_asked_for(p_header_id	=> l_header_id2,
6059 			   p_line_id 		=> l_Line_Tbl(line_Tbl_Index).line_id,
6060 			   p_line_index            => 	l_req_line_tbl.count ,
6061 			   px_Req_line_attr_tbl => l_Req_line_attr_tbl,
6062 			   px_Req_qual_tbl  	=> l_Req_qual_tbl
6063 			   );
6064 			Exception when no_data_found then null;
6065 		   End;
6066 
6067                    If G_DEBUG Then
6068 		   for i in 1..l_Req_line_attr_tbl.count
6069 		   loop
6070 			   adj_debug('Pricing context '|| l_Req_line_attr_tbl(i).pricing_Context,3);
6071 			   adj_debug('Value '|| l_Req_line_attr_tbl(i).Pricing_Attribute,3);
6072 			   adj_debug('Name '|| l_Req_line_attr_tbl(i).Pricing_attr_value_from,3);
6073 		   end loop;
6074 
6075 		   for i in 1..l_Req_qual_tbl.Count
6076 		   loop
6077 			   adj_debug('qualifier context '|| l_Req_qual_tbl(i).Qualifier_Context,3);
6078 			   adj_debug('Value '|| l_Req_qual_tbl(i).Qualifier_Attribute,3);
6079 			   adj_debug('Name '|| l_Req_qual_tbl(i).Qualifier_Attr_Value_From,3);
6080 		   end loop;
6081                    End If;
6082 
6083 	   --End If; -- Item is not Config
6084 
6085 	   line_Tbl_Index := l_Line_Tbl.Next(line_Tbl_Index);
6086 
6087 	end loop;
6088 
6089 	-- Get Header Attributes
6090 
6091 	G_STMT_NO := 'calculate_adjustments#70';
6092 
6093 	If l_bypass_pricing = 'Y' Then
6094 
6095 		adj_debug('Bypassing the qualifier build',1);
6096 	Else
6097 		adj_debug('Before QP_Attr_Mapping_PUB.Build_Contexts for Header',1);
6098                 Begin
6099 		  QP_Attr_Mapping_PUB.Build_Contexts(
6100 			 p_request_type_code => 'ONT',
6101 			 p_pricing_type	=>	'H',
6102 			 x_price_contexts_result_tbl => l_pricing_contexts_Tbl,
6103 			 x_qual_contexts_result_tbl  => l_qualifier_Contexts_Tbl
6104 			 );
6105                 Exception when others then
6106                           Raise QP_ATTR_MAPPING_ERROR;
6107                 End;
6108 
6109 	end if;
6110 	-- Build header Request
6111 
6112 	G_STMT_NO := 'calculate_adjustments#80';
6113 
6114         IF (l_any_frozen_line=TRUE) THEN
6115 
6116           IF l_completely_frozen = FALSE THEN
6117              l_calculate_price_flag := 'P';
6118           ELSE
6119            l_calculate_price_flag := 'N';
6120           END IF;
6121 
6122 
6123             If Not l_message_displayed Then
6124            --   FND_MESSAGE.SET_NAME('ONT','ONT_LINE_FROZEN');
6125               --need to a method to display message as hint in the future
6126               l_message_displayed := TRUE;
6127             End If;
6128             l_any_frozen_line:=FALSE;
6129             --adj_debug('BCT:ONT_LINE_FROZEN');
6130         Elsif   l_all_lines_from_db = False Then
6131                 --1472635
6132                 --Didn't query from db, need to do that to check if
6133                 --all other previously save lines is frozen
6134                 --adj_debug('BCT all line from db is false');
6135 
6136                 If p_header_id is null then
6137                   --ine_tbl_index := l_line_tbl.first;
6138                   l_header_id := l_line_tbl(l_line_tbl.first).header_id;
6139                 Else
6140                   l_header_id := p_header_id;
6141                 End If;
6142                 --adj_debug('BCT order header id '||l_header_id);
6143 
6144                 /*oe_line_util.query_rows(p_header_id =>l_header_id, x_line_tbl=>l_temp_Line_Tbl );
6145                 i2 := l_temp_line_tbl.first;
6146                 While i2 is not Null Loop
6147                   If l_temp_line_tbl(i2).calculate_price_flag In ('N','P') Then
6148                     --adj_debug('BCT2000 any frozen line found');
6149                     l_any_frozen_line :=True;
6150                     x_any_frozen_line :=True;
6151                     l_calculate_price_flag := 'N';
6152                     Exit;
6153                   End If;
6154                     i2:=l_temp_line_tbl.next(i2);
6155 
6156                 End Loop;*/
6157 
6158                Begin
6159 
6160                   BEGIN
6161 
6162                          Select 'x' into l_dummy
6163                          from dual where
6164                          exists(select 'x' from oe_order_lines
6165                                 Where header_id = l_header_id
6166                                 and   calculate_price_flag in ('Y','P')
6167                                 and item_type_code not in ('CONFIG', 'INCLUDED'));
6168 
6169                          l_completely_frozen := FALSE;
6170 
6171                   EXCEPTION
6172                         WHEN NO_DATA_FOUND THEN
6173                           l_completely_frozen := TRUE;
6174                           l_any_frozen_line :=True;
6175                           x_any_frozen_line :=True;
6176                           l_calculate_price_flag := 'N';
6177                   END;
6178 
6179                   IF l_completely_frozen = FALSE THEN
6180 
6181                      Select 'p' into l_dummy
6182                      from dual where
6183                      exists (select 'x' from oe_order_lines
6184                              where header_id = l_header_id
6185                              and calculate_price_flag in ('N', 'P')
6186 			     and cancelled_flag = 'N'
6187                              and item_type_code not in ('CONFIG', 'INCLUDED') );
6188 
6189                      l_any_frozen_line := TRUE;
6190                      x_any_frozen_line := TRUE;
6191                      l_calculate_price_flag := 'P';
6192 
6193                   END IF;
6194 
6195                Exception when no_data_found then
6196                   null;
6197                End;
6198 
6199            If nvl(l_calculate_price_flag,'X') not in ('N', 'P') Then
6200                     l_calculate_price_flag:='Y';
6201            End If;
6202 
6203         ELSE
6204            l_calculate_price_flag := 'Y';
6205         END IF;
6206 
6207 	  copy_Header_to_request(
6208 		 p_header_rec       => OE_Order_PUB.g_hdr
6209 		 ,px_req_line_tbl   => l_req_line_tbl
6210 		 ,p_Request_Type_Code => p_Request_Type_Code
6211                  ,p_calculate_price_flag =>l_calculate_price_flag
6212 		 );
6213 
6214 	G_STMT_NO := 'calculate_adjustments#90';
6215 	copy_attribs_to_Req(
6216 		p_line_index             => l_req_line_tbl.count
6217 		,p_pricing_contexts_Tbl 	=> 	l_pricing_contexts_Tbl
6218 		,p_qualifier_contexts_Tbl =>	l_qualifier_Contexts_Tbl
6219 		,px_Req_line_attr_tbl    =>	l_Req_line_attr_tbl
6220 		,px_Req_qual_tbl         =>	l_Req_qual_tbl
6221 					);
6222 
6223 	G_STMT_NO := 'calculate_adjustments#100';
6224 	Begin
6225                 -- Modified for bug 3502454
6226 	        --l_header_id2:= nvl(p_header_id,l_line_tbl(l_line_tbl.first).header_id);
6227                 IF ( p_header_id IS NULL ) THEN
6228                   l_header_id2 := l_line_tbl(l_line_tbl.first).header_id;
6229                 ELSE
6230                   l_header_id2 := p_header_id;
6231                 END IF;
6232                 -- End of 3502454
6233 
6234 		  Select 'x' into l_dummy from dual
6235                   where exists(
6236                    Select 'X' from oe_order_price_attribs oopa
6237 		   where oopa.header_id = l_header_id2 and oopa.line_id is null);
6238 
6239 		   Append_asked_for(
6240 			p_header_id		=> l_header_id2
6241 			,p_line_index           => l_req_line_tbl.count
6242 			,px_Req_line_attr_tbl   => l_Req_line_attr_tbl
6243 			,px_Req_qual_tbl        => l_Req_qual_tbl
6244 			);
6245 
6246 	Exception when no_data_found then null;
6247                   when others then
6248                 oe_debug_pub.add(sqlerrm);
6249                 oe_debug_pub.add('l_line_tbl.first'||l_line_tbl.first);
6250 	End;
6251 
6252          G_STMT_NO := 'calculate_adjustments#101';
6253 
6254           If G_Debug Then
6255              for i in 1..l_Req_line_attr_tbl.count
6256 		loop
6257 			adj_debug('Pricing context '|| l_Req_line_attr_tbl(i).pricing_Context,3);
6258 			adj_debug('Value '|| l_Req_line_attr_tbl(i).Pricing_Attribute,3);
6259 			adj_debug('Name '|| l_Req_line_attr_tbl(i).Pricing_attr_value_from,3);
6260 			adj_debug('---------------------------------------------',3);
6261 		end loop;
6262 
6263 		for i in 1..l_Req_qual_tbl.Count
6264 		loop
6265 			adj_debug('qualifier context '|| l_Req_qual_tbl(i).Qualifier_Context,3);
6266 			adj_debug('Value '|| l_Req_qual_tbl(i).Qualifier_Attribute,3);
6267 			adj_debug('Name '|| l_Req_qual_tbl(i).Qualifier_Attr_Value_From,3);
6268 			adj_debug('---------------------------------------------',3);
6269 		end loop;
6270 
6271 
6272 	i:= l_Req_line_tbl.First;
6273 	While i is not null loop
6274 		adj_debug('The Line Index '||l_Req_line_tbl(i).line_index,3);
6275 		adj_debug('The Line_id  '||l_Req_line_tbl(i).line_id,3);
6276 		adj_debug('The Line Type  '||l_Req_line_tbl(i).Line_type_code,3);
6277 		adj_debug('---------------------------------------------',3);
6278 		i:= l_Req_line_tbl.Next(i);
6279 	end loop;
6280 
6281           End If;  --g_debug
6282 
6283 	G_STMT_NO := 'calculate_adjustments#160';
6284 	adj_debug('Before  QP_PREQ_GRP.PRICE_REQUEST',1);
6285 
6286         --btea begin
6287         l_control_rec := p_control_rec;
6288 
6289         --Q means ask pricing engine to determine rounding options.
6290         l_control_rec.rounding_flag := 'Q';
6291         l_control_rec.use_multi_currency:='Y';
6292         l_control_rec.USER_CONVERSION_RATE:= OE_ORDER_PUB.G_HDR.CONVERSION_RATE;
6293         l_control_rec.USER_CONVERSION_TYPE:= OE_ORDER_PUB.G_HDR.CONVERSION_TYPE_CODE;
6294         l_set_of_books := Oe_Order_Cache.Load_Set_Of_Books;
6295         l_control_rec.FUNCTION_CURRENCY   := l_set_of_books.currency_code;
6296 
6297         G_STMT_NO := 'QP_PRICE_REQUEST_GRP';
6298 	QP_PREQ_GRP.PRICE_REQUEST
6299 		(p_control_rec		 => l_control_rec
6300 		,p_line_tbl              => l_Req_line_tbl
6301  		,p_qual_tbl              => l_Req_qual_tbl
6302   		,p_line_attr_tbl         => l_Req_line_attr_tbl
6303 		,p_line_detail_tbl       =>l_req_line_detail_tbl
6304 	 	,p_line_detail_qual_tbl  =>l_req_line_detail_qual_tbl
6305 	  	,p_line_detail_attr_tbl  =>l_req_line_detail_attr_tbl
6306 	   	,p_related_lines_tbl     =>l_req_related_lines_tbl
6307 		,x_line_tbl              =>x_req_line_tbl
6308 	   	,x_line_qual             =>x_Req_qual_tbl
6309 	    	,x_line_attr_tbl         =>x_Req_line_attr_tbl
6310 		,x_line_detail_tbl       =>x_req_line_detail_tbl
6311 	 	,x_line_detail_qual_tbl  =>x_req_line_detail_qual_tbl
6312 	  	,x_line_detail_attr_tbl  =>x_req_line_detail_attr_tbl
6313 	   	,x_related_lines_tbl     =>x_req_related_lines_tbl
6314 	    	,x_return_status         =>l_return_status
6315 	    	,x_return_status_Text         =>l_return_status_Text
6316 		);
6317         --btea end
6318         G_STMT_NO := 'calculate_adjustments#161';
6319 		adj_debug('------------ After the Price_Request CAll -----------');
6320 
6321         If G_DEBUG Then
6322 	i:= x_Req_line_tbl.First;
6323 	While i is not null loop
6324 		adj_debug('The Line Index '||x_Req_line_tbl(i).line_index,3);
6325 		adj_debug('The Line_id  '||x_Req_line_tbl(i).line_id,3);
6326 		adj_debug('The Line Type  '||x_Req_line_tbl(i).Line_type_code,3);
6327 		adj_debug('Status code  '||x_Req_line_tbl(i).status_code,3);
6328 		adj_debug('---------------------------------------------',3);
6329 		i:= x_Req_line_tbl.Next(i);
6330 	end loop;
6331 	i:= x_req_line_detail_tbl.First;
6332 	While i is not null loop
6333 		adj_debug('('||i||')The line Index '||x_req_line_detail_tbl(i).Line_index,3);
6334 		adj_debug('The line Detail Index '||x_req_line_detail_tbl(i).Line_Detail_Index,3);
6335 		adj_debug('The List Line '||x_req_line_detail_tbl(i).List_Line_id,3);
6336 		adj_debug('------------------------------------------------',3);
6337 		i:= x_req_line_detail_tbl.Next(i);
6338 	End Loop;
6339 	i:= x_Req_related_lines_tbl.First;
6340 	While i is not null loop
6341 		adj_debug('Line Detail '||x_Req_related_lines_tbl(i).Line_detail_index,3);
6342 		adj_debug('relation type '||x_Req_related_lines_tbl(i).relationship_type_code,3);
6343 		adj_debug('rltd line detail index '||x_Req_related_lines_tbl(i).related_line_detail_index,3);
6344 	 adj_debug('--------------------------------------------------------',3);
6345 		i:= x_Req_related_lines_tbl.Next(i);
6346 	 end loop;
6347          End If;
6348 
6349 		IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6350 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6351 		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
6352 			RAISE FND_API.G_EXC_ERROR;
6353 		END IF;
6354 
6355 	    	x_return_status         		:= 	l_return_status;
6356 		/*
6357 		x_Req_line_tbl              	:=	l_req_line_tbl;
6358 	   	x_Req_qual_Tbl             	:=	l_Req_qual_tbl;
6359 	    	x_Req_line_attr_tbl         	:=	l_Req_line_attr_tbl;
6360 		x_Req_line_detail_tbl       	:=	l_req_line_detail_tbl;
6361 	 	x_Req_line_detail_qual_tbl  	:=	l_req_line_detail_qual_tbl;
6362 	  	x_Req_line_detail_attr_tbl  	:=	l_req_line_detail_attr_tbl;
6363 	   	x_Req_related_lines_tbl     	:=	l_req_related_lines_tbl;
6364 		*/
6365 
6366 		x_header_Rec				:=   OE_Order_PUB.g_hdr;
6367 		x_line_tbl				:=   l_line_tbl;
6368 
6369                 --reseting global structure after engine call
6370                 OE_Order_PUB.G_LINE := NULL;
6371                 OE_Order_PUB.G_HDR  := NULL;
6372 	  -- Process the lines...
6373 
6374 	  adj_debug('Exiting oe_order_Adj_pvt.calulate_adjustments', 1);
6375 
6376     EXCEPTION
6377 
6378 	    WHEN FND_API.G_EXC_ERROR THEN
6379 
6380 		  FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
6381 		  FND_MESSAGE.SET_TOKEN('ERR_TEXT',l_return_status_Text);
6382 		  OE_MSG_PUB.Add;
6383 		  x_return_status := FND_API.G_RET_STS_ERROR;
6384 
6385 			adj_debug('g_exc_error is '||g_stmt_no||' '||sqlerrm,1);
6386 			adj_debug('g_exc_error is '||l_return_status_Text);
6387 
6388 			RAISE FND_API.G_EXC_ERROR;
6389 
6390                       /* Added for Bug 2124989 */
6391                WHEN OE_AGREEMENT_ERROR Then
6392                  x_return_status := FND_API.G_RET_STS_ERROR;
6393                  oe_debug_pub.add('Error: Invalid AAgreement');
6394                  RAISE FND_API.G_EXC_ERROR;
6395 
6396                /* END 2124989 */
6397                 WHEN QP_ATTR_MAPPING_ERROR THEN
6398                    FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
6399                    FND_MESSAGE.SET_TOKEN('ERR_TEXT','Please make sure Run QP Build Sourcing Rule has completed sucessfully');
6400                    OE_MSG_PUB.Add;
6401                    oe_debug_pub.add(' QP Attr Mapping threw exception');
6402                    RAISE FND_API.G_EXC_ERROR;
6403 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6404 
6405 		  FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
6406 		  FND_MESSAGE.SET_TOKEN('ERR_TEXT',l_return_status_Text);
6407 		  OE_MSG_PUB.Add;
6408 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6409 			adj_debug('G_EXC_UNEXPECTED_ERROR is '||g_stmt_no||' '||sqlerrm,1);
6410 			adj_debug('G_EXC_UNEXPECTED_ERROR is '||l_return_status_Text);
6411 
6412 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6413 
6414 		WHEN OTHERS THEN
6415 
6416 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6417 			--dbms_output.put_line('Error is '||sqlerrm);
6418 			adj_debug('Error Code is '||g_stmt_no||' '||sqlerrm,1);
6419 
6420 			IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6421 			THEN
6422 				OE_MSG_PUB.Add_Exc_Msg
6423 				(   G_PKG_NAME
6424 				,   'oe_line_adj.calulate_adjustments',
6425 					g_stmt_no||' '||sqlerrm
6426 				);
6427 			END IF;
6428 
6429 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6430 
6431 end calculate_adjustments;
6432 
6433 Function Update_Adj_Line_rec(
6434 		p_Line_Adj_Rec		in out nocopy OE_Order_Pub.Line_Adj_Rec_Type
6435 		,p_req_line_detail_Rec   qp_preq_grp.line_detail_rec_type
6436 		)
6437 Return Boolean
6438 is
6439 l_updated_Flag		Boolean := False;
6440 x_return_status            VARCHAR2(240);
6441 x_return_status_txt        VARCHAR2(240);
6442 Begin
6443           /* Start: Added by Manish */
6444           IF p_Line_Adj_Rec.OPERATION <> OE_GLOBALS.G_OPR_CREATE THEN
6445 			p_Line_Adj_Rec.operation := OE_GLOBALS.G_OPR_UPDATE;
6446 		END IF;
6447           /* End: Added by Manish */
6448 
6449 		adj_debug('Entering oe_order_Adj_pvt.Update_Adj_Line_rec',1);
6450 		G_STMT_NO := 'Update_Adj_Line_rec#10';
6451 
6452 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.list_header_id,
6453 					p_req_line_detail_Rec.list_header_id) then
6454 			p_Line_Adj_Rec.list_header_id :=
6455 				p_req_line_detail_Rec.list_header_id;
6456 			l_updated_Flag := True;
6457 		   end If;
6458 
6459 		   If not OE_GLOBALS.Equal(p_Line_Adj_Rec.list_Line_id,
6460 				p_req_line_detail_Rec.list_Line_id) Then
6461 			p_Line_Adj_Rec.list_Line_id :=
6462 				p_req_line_detail_Rec.list_Line_id;
6463 			l_updated_Flag := True;
6464 		   end If;
6465 
6466 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.Automatic_flag,
6467 				p_req_line_detail_Rec.Automatic_flag) Then
6468 			p_Line_Adj_Rec.Automatic_flag :=
6469 					p_req_line_detail_Rec.Automatic_flag;
6470 			l_updated_Flag := True;
6471 		   end If;
6472 
6473 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.list_line_type_code,
6474 					p_req_line_detail_Rec.list_line_type_code) Then
6475 			p_Line_Adj_Rec.list_line_type_code :=
6476 					p_req_line_detail_Rec.list_line_type_code;
6477 			l_updated_Flag := True;
6478 		   end If;
6479 
6480              if not OE_GLOBALS.Equal(p_Line_Adj_Rec.list_line_no, p_req_line_detail_Rec.list_line_no) Then
6481                       if (not l_updated_flag) and p_Line_Adj_Rec.list_line_type_code = 'CIE' Then
6482                        adj_debug('CIE:to delete coupon'||p_req_line_detail_rec.list_line_no);
6483                          -- retain the original coupon number, delete the new number
6484                          QP_COUPON_PVT.Delete_Coupon(p_req_line_detail_Rec.list_line_no,
6485                                                      x_return_status,
6486                                                      x_return_status_txt
6487                                                     );
6488                          IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
6489   		  	   FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
6490 		  	   FND_MESSAGE.SET_TOKEN('ERR_TEXT',x_return_status_txt);
6491  		  	   OE_MSG_PUB.Add;
6492                            RAISE FND_API.G_EXC_ERROR;
6493                          END IF;
6494                       else
6495 			p_Line_Adj_Rec.list_line_no :=  p_req_line_detail_Rec.list_line_no;
6496 			l_updated_Flag := True;
6497                       end If;
6498 		   end If;
6499 
6500 		   if p_Line_Adj_Rec.list_line_type_code = 'TSN' and  -- Terms substitution
6501 		   	not OE_GLOBALS.Equal(p_Line_Adj_Rec.modified_from,
6502 					p_req_line_detail_Rec.substitution_from) Then
6503 
6504 			Begin
6505 				p_Line_Adj_Rec.modified_from := p_req_line_detail_Rec.substitution_from;
6506 				l_updated_Flag := True;
6507 			Exception when value_error then
6508 				adj_debug('Value error , The term is not updated '||p_req_line_detail_Rec.substitution_From);
6509 			End;
6510 
6511 		   end If;
6512 
6513 		   if p_Line_Adj_Rec.list_line_type_code = 'TSN' and  -- Terms substitution
6514 		   	not OE_GLOBALS.Equal(p_Line_Adj_Rec.modified_to,
6515 					p_req_line_detail_Rec.substitution_to) Then
6516 
6517 			Begin
6518 		   		p_Line_Adj_Rec.modified_to := p_req_line_detail_Rec.substitution_to;
6519 			 	l_updated_Flag := True;
6520 			Exception when value_error then
6521 				adj_debug('Value error , The term is not updated '||p_req_line_detail_Rec.substitution_to);
6522 			End;
6523 
6524 		   end If;
6525 
6526 		   if p_Line_Adj_Rec.list_line_type_code = 'IUE' and  -- Terms substitution
6527 		   	not OE_GLOBALS.Equal(p_Line_Adj_Rec.modified_from,
6528 					to_char(p_req_line_detail_Rec.INVENTORY_ITEM_ID)) Then
6529 
6530 		   	p_Line_Adj_Rec.modified_from := to_char(p_req_line_detail_Rec.INVENTORY_ITEM_ID);
6531 			l_updated_Flag := True;
6532 
6533 		   end If;
6534 
6535 		   if p_Line_Adj_Rec.list_line_type_code = 'IUE' and  -- Terms substitution
6536 		   	not OE_GLOBALS.Equal(p_Line_Adj_Rec.modified_to,
6537 					to_char(p_req_line_detail_Rec.RELATED_ITEM_ID)) Then
6538 
6539 		   	p_Line_Adj_Rec.modified_to := to_char(p_req_line_detail_Rec.RELATED_ITEM_ID);
6540 			l_updated_Flag := True;
6541 
6542 		   end If;
6543 
6544 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.arithmetic_operator,
6545 					p_req_line_detail_Rec.Operand_Calculation_Code) Then
6546 			p_Line_Adj_Rec.arithmetic_operator := p_req_line_detail_Rec.Operand_Calculation_Code;
6547 			l_updated_Flag := True;
6548 		   end If;
6549 
6550 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.operand_per_pqty,
6551 					p_req_line_detail_Rec.Operand_Value) Then
6552 			p_Line_Adj_Rec.operand_per_pqty := p_req_line_detail_Rec.Operand_Value;
6553                         If  p_req_line_detail_Rec.Operand_Value is null Then
6554                            Oe_Debug_Pub.add(' Null operand returned by pricing');
6555                            Oe_Debug_pub.add(' List line type:'||p_req_line_detail_Rec.list_line_type_code);
6556                            Oe_debug_pub.add(' list line id:'||p_req_line_detail_Rec.list_line_id);
6557                         End If;
6558 			l_updated_Flag := True;
6559 		   end If;
6560 
6561 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.Applied_flag ,
6562 					p_req_line_detail_Rec.Applied_Flag) or p_Line_Adj_Rec.Applied_flag is null
6563 					Then
6564 			p_Line_Adj_Rec.Applied_flag :=  nvl(p_req_line_detail_Rec.Applied_Flag,'N');
6565 			l_updated_Flag := True;
6566 		   end If;
6567 
6568 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.update_allowed,
6569 					p_req_line_detail_Rec.Override_flag) Then
6570 			p_Line_Adj_Rec.update_allowed :=  p_req_line_detail_Rec.Override_flag;
6571 			l_updated_Flag := True;
6572 		   end If;
6573 
6574 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.Pricing_phase_id,
6575 					p_req_line_detail_Rec.Pricing_phase_id) Then
6576 			p_Line_Adj_Rec.Pricing_phase_id :=  p_req_line_detail_Rec.Pricing_phase_id;
6577 			l_updated_Flag := True;
6578 		   end If;
6579 
6580 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.adjusted_amount_per_pqty,
6581 					p_req_line_detail_Rec.Adjustment_Amount) Then
6582 			p_Line_Adj_Rec.adjusted_amount_per_pqty :=  p_req_line_detail_Rec.Adjustment_Amount;
6583 			l_updated_Flag := True;
6584 		   end If;
6585 
6586 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.pricing_group_sequence,
6587 					p_req_line_detail_Rec.pricing_group_sequence) Then
6588 			p_Line_Adj_Rec.pricing_group_sequence :=  p_req_line_detail_Rec.pricing_group_sequence;
6589 			l_updated_Flag := True;
6590 		   end If;
6591 
6592 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.range_break_quantity,
6593 					p_req_line_detail_Rec.line_quantity) Then
6594 			p_Line_Adj_Rec.range_break_quantity :=  p_req_line_detail_Rec.line_quantity;
6595 			l_updated_Flag := True;
6596 		   end If;
6597 
6598 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.price_break_type_code,
6599 					p_req_line_detail_Rec.price_break_type_code) Then
6600 			p_Line_Adj_Rec.price_break_type_code :=  p_req_line_detail_Rec.price_break_type_code;
6601 			l_updated_Flag := True;
6602 		   end If;
6603 
6604 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.print_on_invoice_flag,
6605 					p_req_line_detail_Rec.print_on_invoice_flag) Then
6606 			p_Line_Adj_Rec.print_on_invoice_flag :=  p_req_line_detail_Rec.print_on_invoice_flag;
6607 			l_updated_Flag := True;
6608 		   end If;
6609 
6610 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.print_on_invoice_flag,
6611 					p_req_line_detail_Rec.print_on_invoice_flag) Then
6612 			p_Line_Adj_Rec.print_on_invoice_flag :=  p_req_line_detail_Rec.print_on_invoice_flag;
6613 			l_updated_Flag := True;
6614 		   end If;
6615 
6616 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.substitution_attribute,
6617 					p_req_line_detail_Rec.substitution_attribute) Then
6618 			p_Line_Adj_Rec.substitution_attribute :=  p_req_line_detail_Rec.substitution_attribute;
6619 			l_updated_Flag := True;
6620 		   end If;
6621 
6622 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.Accrual_flag,
6623 					p_req_line_detail_Rec.Accrual_flag) Then
6624 			p_Line_Adj_Rec.Accrual_flag :=  p_req_line_detail_Rec.Accrual_flag;
6625 			l_updated_Flag := True;
6626 		   end If;
6627 
6628 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.accrual_conversion_rate,
6629 					p_req_line_detail_Rec.accrual_conversion_rate) Then
6630 			p_Line_Adj_Rec.accrual_conversion_rate :=  p_req_line_detail_Rec.accrual_conversion_rate;
6631 			l_updated_Flag := True;
6632 		   end If;
6633 
6634 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.charge_type_code,
6635 					p_req_line_detail_Rec.charge_type_code) Then
6636 			p_Line_Adj_Rec.charge_type_code :=  p_req_line_detail_Rec.charge_type_code;
6637 			l_updated_Flag := True;
6638 		   end If;
6639 
6640 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.charge_subtype_code,
6641 					p_req_line_detail_Rec.charge_subtype_code) Then
6642 			p_Line_Adj_Rec.charge_subtype_code :=  p_req_line_detail_Rec.charge_subtype_code;
6643 			l_updated_Flag := True;
6644 		   end If;
6645 
6646 
6647 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.include_on_returns_flag,
6648 					p_req_line_detail_Rec.include_on_returns_flag) Then
6649 			p_Line_Adj_Rec.include_on_returns_flag :=  p_req_line_detail_Rec.include_on_returns_flag;
6650 			l_updated_Flag := True;
6651 		   end If;
6652 
6653 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.benefit_uom_code,
6654 					p_req_line_detail_Rec.benefit_uom_code) Then
6655 			p_Line_Adj_Rec.benefit_uom_code :=  p_req_line_detail_Rec.benefit_uom_code;
6656 			l_updated_Flag := True;
6657 		   end If;
6658 
6659 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.Benefit_qty, p_req_line_detail_Rec.Benefit_qty) Then
6660 			p_Line_Adj_Rec.Benefit_qty :=  p_req_line_detail_Rec.Benefit_qty;
6661 			l_updated_Flag := True;
6662 		   end If;
6663 
6664 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.proration_type_code,
6665 					p_req_line_detail_Rec.proration_type_code) Then
6666 			p_Line_Adj_Rec.proration_type_code :=  p_req_line_detail_Rec.proration_type_code;
6667 			l_updated_Flag := True;
6668 		   end If;
6669 
6670 /*		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.list_line_no, p_req_line_detail_Rec.list_line_no) Then
6671 			p_Line_Adj_Rec.list_line_no :=  p_req_line_detail_Rec.list_line_no;
6672 			l_updated_Flag := True;
6673 		   end If;
6674 */
6675 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.source_system_code,
6676 					p_req_line_detail_Rec.source_system_code) Then
6677 			p_Line_Adj_Rec.source_system_code :=  p_req_line_detail_Rec.source_system_code;
6678 			l_updated_Flag := True;
6679 		   end If;
6680 
6681 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.expiration_date,
6682 					p_req_line_detail_Rec.expiration_date) Then
6683 			p_Line_Adj_Rec.expiration_date :=  p_req_line_detail_Rec.expiration_date;
6684 			l_updated_Flag := True;
6685 		   end If;
6686 
6687 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.Rebate_transaction_type_code,
6688 					p_req_line_detail_Rec.Rebate_transaction_type_code) Then
6689 			p_Line_Adj_Rec.Rebate_transaction_type_code :=
6690 					p_req_line_detail_Rec.Rebate_transaction_type_code;
6691 			l_updated_Flag := True;
6692 		   end If;
6693 
6694 		   if not OE_GLOBALS.Equal(p_Line_Adj_Rec.modifier_level_code,
6695 					p_req_line_detail_Rec.modifier_level_code) Then
6696 			p_Line_Adj_Rec.modifier_level_code :=
6697 					p_req_line_detail_Rec.modifier_level_code;
6698 			l_updated_Flag := True;
6699 		   end If;
6700              if not OE_GLOBALS.Equal(p_Line_Adj_Rec.group_value,
6701                          p_req_line_detail_Rec.group_value) Then
6702                p_Line_Adj_Rec.group_value :=
6703                          p_req_line_detail_Rec.group_value;
6704                l_updated_Flag := True;
6705              end If;
6706 
6707   /* bug 1915846 */
6708 
6709             IF  (    p_line_adj_rec.list_line_type_code = 'FREIGHT_CHARGE'
6710                  and p_line_adj_rec.modifier_level_code = 'ORDER'
6711                  and p_line_adj_rec.arithmetic_operator = 'LUMPSUM' ) THEN
6712 
6713      p_line_adj_rec.adjusted_amount := p_line_adj_rec.adjusted_amount_per_pqty;
6714 
6715                 p_line_adj_rec.operand := p_line_adj_rec.operand_per_pqty;
6716 
6717             END IF;
6718 
6719       /* end bug 1915846 */
6720 
6721 
6722 		adj_debug('Exiting oe_order_Adj_pvt.Update_Adj_Line_rec',1);
6723 
6724 	Return l_updated_Flag;
6725 
6726 End Update_Adj_Line_rec;
6727 
6728 --Function line_quantity_changed
6729 
6730 Procedure Find_Duplicate_Adj_Lines(
6731 	p_header_Id 			Number default null
6732 	,p_Line_id  			Number default null
6733 	,p_req_line_detail_Rec   qp_preq_grp.line_detail_rec_type
6734 	,px_Line_Adj_Tbl 	in out nocopy	OE_Order_Pub.Line_Adj_Tbl_Type
6735 ,X_Adj_Index out nocopy Number
6736 
6737         ,p_mode         in              Varchar2
6738         ,px_line_key_tbl in out nocopy  key_tbl_type
6739         ,px_header_key_tbl in out nocopy key_tbl_type
6740 	)
6741 is
6742    l_end_index PLS_INTEGER;
6743    l_temp NUMBER;
6744 Begin
6745 
6746 		adj_debug('Entering oe_order_Adj_pvt.Find_Duplicate_Adj_Lines'||p_mode||'line_id'||p_line_id,1);
6747                adj_debug('BCT x_adj_index '||x_adj_index);
6748 		G_STMT_NO := 'Find_Duplicate_Adj_Lines#10';
6749 
6750                   --retrieve start and end index from key_table to save extra scaning
6751 
6752                   IF p_mode = 'L' and px_line_key_tbl.exists(nvl(MOD(p_line_id,G_BINARY_LIMIT),-1)) Then -- Bug 8631297
6753                    x_adj_index := px_line_key_tbl(MOD(p_line_id,G_BINARY_LIMIT)).db_start;               -- Bug 8631297
6754                    l_end_index := px_line_key_tbl(MOD(p_line_id,G_BINARY_LIMIT)).db_end;                 -- Bug 8631297
6755                    adj_debug('BCT line id :'||p_line_id);
6756                    adj_debug('BCT x_adj_index :'||x_adj_index);
6757                    adj_debug('BCT l_end_index :'||l_end_index);
6758                   Elsif  p_mode = 'H' and px_header_key_tbl.exists(nvl(p_header_id,-1)) Then
6759                    x_adj_index := px_header_key_tbl(p_header_id).db_start;
6760                    l_end_index := px_header_key_tbl(p_header_id).db_end;
6761                   Else
6762                    --no record exists in key_tbl
6763                    --reset the index so that it can skip the subsequence loop
6764                    x_adj_index := -1;
6765                    l_end_index := -2;
6766                   End If;
6767 
6768                 --for the freight we need to loop thru everything, no shortcut
6769                   If p_req_line_detail_Rec.list_line_type_code = 'FREIGHT_CHARGE'
6770                      and px_line_adj_tbl.count > 0 Then
6771                     x_adj_index := px_line_adj_tbl.first;
6772                     l_end_index := px_line_adj_tbl.last;
6773                   End If;
6774 
6775 		--G_STMT_NO := 'Find_Duplicate_Adj_Lines#10.5';
6776 
6777 		While nvl(X_Adj_Index,l_end_index + 1) <= l_end_index Loop
6778 			If (px_Line_Adj_Tbl(X_Adj_Index).line_id = p_Line_id
6779 					or
6780 					px_Line_Adj_Tbl(X_Adj_Index).line_index = p_req_line_detail_Rec.line_index
6781 					or -- for header adjustments
6782 					( px_Line_Adj_Tbl(X_Adj_Index).header_id = p_header_id and
6783 					  ( px_Line_Adj_Tbl(X_Adj_Index).line_id is null or
6784 					    px_Line_Adj_Tbl(X_Adj_Index).line_id = fnd_api.g_miss_num ) and
6785 					  ( px_Line_Adj_Tbl(X_Adj_Index).line_index is null or
6786 					    px_Line_Adj_Tbl(X_Adj_Index).line_index = fnd_api.g_miss_num )
6787 					))
6788 			then
6789 
6790 			if px_Line_Adj_Tbl(X_Adj_Index).list_Line_id=p_req_line_detail_Rec.list_Line_id
6791 			Then
6792                                 adj_debug('BCT found duplicate list line id:'||px_line_adj_tbl(x_adj_index).list_line_id);
6793 				Exit;
6794 			End if;
6795 
6796 		--G_STMT_NO := 'Find_Duplicate_Adj_Lines#10.55';
6797                 adj_debug('BCT x_adj_index '||x_adj_index);
6798                IF px_Line_Adj_Tbl(X_Adj_Index).list_line_type_code
6799                           = 'FREIGHT_CHARGE'
6800                   AND px_Line_Adj_Tbl(X_Adj_Index).charge_type_code
6801                           = p_req_line_detail_Rec.charge_type_code
6802                   AND NVL(px_Line_Adj_Tbl(X_Adj_Index).charge_subtype_code
6803                   ,'SUB') = NVL(p_req_line_detail_Rec.charge_subtype_code,'SUB')
6804 			   and
6805 			   nvl(px_Line_Adj_Tbl(X_Adj_Index).applied_flag,'Y') ='Y' and
6806 			   nvl(p_req_line_detail_Rec.Applied_Flag,'Y') = 'Y'
6807 
6808 			 Then
6809                                 adj_debug('BCT found duplicate list line id:'||px_line_adj_tbl(x_adj_index).list_line_id);
6810 				Exit;
6811 			 End If;
6812 
6813 		end if;
6814                         --G_STMT_NO := 'Find_Duplicate_Adj_Lines#10.551';
6815 			x_Adj_Index := px_Line_Adj_Tbl.Next(X_Adj_Index);
6816 		end loop;
6817 
6818              -- IF x_adj_index is not null THEN
6819                 If x_adj_index is Null then x_adj_index := -1;  end if;
6820 
6821 		If x_adj_index= -1 or x_adj_index > l_end_index Then
6822 		-- This is a new Record
6823                     --
6824                     x_Adj_Index := px_line_adj_Tbl.count + 1;
6825                     px_line_adj_tbl(x_adj_index) := OE_ORDER_PUB.G_MISS_LINE_ADJ_REC;
6826       	            px_line_adj_Tbl(x_Adj_Index).operation := OE_GLOBALS.G_OPR_CREATE;
6827       	            px_line_adj_Tbl(x_Adj_Index).Updated_Flag := 'N';
6828 		    px_line_adj_Tbl(x_Adj_Index).adjusted_amount_per_pqty := null;
6829                     --
6830 		elsif px_Line_Adj_Tbl(x_Adj_Index).price_adjustment_id is null or
6831 		      px_Line_Adj_Tbl(x_Adj_Index).price_adjustment_id = FND_API.g_miss_num Then
6832 			--Record is not yet created in the database
6833       	              px_line_adj_Tbl(x_Adj_Index).Updated_Flag := 'N';
6834       	              px_line_adj_Tbl(x_Adj_Index).operation := OE_GLOBALS.G_OPR_CREATE;
6835 /* Taking out nocopy this part to be set in update_adj_line_rec: Manish */
6836 
6837 --		Else
6838 --     	              px_Line_Adj_Tbl(x_Adj_Index).operation := OE_GLOBALS.G_OPR_UPDATE;
6839 		end if;
6840 
6841 		--G_STMT_NO := 'Find_Duplicate_Adj_Lines#10.57';
6842 
6843                 oe_debug_pub.add('list_line_id:'||px_Line_Adj_Tbl(x_Adj_Index).list_line_id);
6844                 oe_debug_pub.add('updated_flag:'||px_Line_Adj_Tbl(x_Adj_Index).updated_Flag);
6845 		if px_Line_Adj_Tbl(x_Adj_Index).updated_Flag = 'Y' Then
6846 				-- User has updated this record Do not touch this
6847 			px_Line_Adj_Tbl(x_Adj_Index).Operation :=  FND_API.G_MISS_CHAR;
6848 
6849 		elsif px_Line_Adj_Tbl(X_Adj_Index).list_line_type_code =
6850 			 'FREIGHT_CHARGE'
6851 			 AND
6852                (NOT OE_GLOBALS.EQUAL(px_Line_Adj_Tbl(X_Adj_Index).list_Line_id,
6853 				p_req_line_detail_Rec.list_Line_id))
6854 			 AND
6855                 px_line_adj_Tbl(X_Adj_Index).operation <>
6856 									OE_GLOBALS.G_OPR_DELETE
6857 		      AND
6858 		      nvl(px_Line_Adj_Tbl(x_Adj_Index).adjusted_amount_per_pqty,0) >=
6859 					nvl(p_req_line_detail_Rec.adjustment_amount,0)
6860 		Then
6861 			-- Retain the freight charge of higher amount.
6862 			Null;
6863 		adj_debug('In Freight Compare',3);
6864 
6865 		elsif Not Update_Adj_Line_rec(
6866 					p_Line_Adj_Rec			=>	px_Line_Adj_Tbl(x_Adj_Index)
6867 					,p_req_line_detail_Rec  	=> p_req_line_detail_Rec
6868 					)
6869 		Then
6870 			-- There is no change in the adjustment record
6871 
6872 			px_Line_Adj_Tbl(x_Adj_Index).Operation := FND_API.G_MISS_CHAR;
6873 
6874                         --fix bug 1461198
6875                         --if pricing engine return a prg line set the operation
6876                         --to update because parent quantity might have changed
6877 
6878 			If p_req_line_detail_rec.list_line_type_code = 'PRG' Then
6879                           px_line_adj_tbl(x_adj_index).operation := OE_GLOBALS.G_OPR_UPDATE;
6880                         End If;
6881 
6882 	     End If; -- Check Updated_Flag
6883 
6884    --END IF;
6885 
6886                 adj_debug(' x_adj_index:'||x_Adj_Index);
6887 		adj_debug('Exiting oe_order_Adj_pvt.Find_Duplicate_Adj_Lines',1);
6888 
6889 
6890 
6891 
6892 
6893 End Find_Duplicate_Adj_Lines;
6894 
6895 Procedure Query_Adj_Assocs(
6896 					p_price_adjustment_id	 Number,
6897 					p_Adj_Index			Number,
6898 					p_Line_Adj_Assoc_Tbl    in out nocopy OE_Order_Pub.line_adj_Assoc_tbl_Type,
6899                                         p_delete_flag           in Varchar2 default 'Y'
6900 					) Is
6901 L_Line_Adj_Assoc_Tbl		OE_Order_Pub.line_adj_Assoc_tbl_Type;
6902 l_index				pls_integer;
6903 i pls_integer;
6904 Begin
6905 	adj_debug('Entering oe_order_Adj_pvt.Query_Adj_Assocs',1);
6906 	G_STMT_NO := 'Query_Adj_Assocs#10';
6907 
6908 	-- Check If the price adjustment has been already queried
6909 
6910 	l_index := p_Line_Adj_Assoc_Tbl.First;
6911 
6912 	While l_index is not null loop
6913 		If p_Line_Adj_Assoc_Tbl(l_index).price_adjustment_id = p_price_adjustment_id then
6914 			Return;
6915 		End If;
6916 		l_index := p_Line_Adj_Assoc_Tbl.Next(l_Index);
6917 
6918 	End Loop;
6919 
6920          adj_debug('query line adj assocs for price adjustment:'||p_price_adjustment_id, 2);
6921          OE_Line_Adj_Assocs_Util.Query_Rows(
6922 				p_price_adjustment_id => p_price_adjustment_id
6923                              ,  x_Line_Adj_Assoc_Tbl => L_Line_Adj_Assoc_Tbl );
6924 
6925 	-- Append to the tbl with Delete flag set.
6926 	-- The row would be removed from this structure if there is a match.
6927 
6928 	G_STMT_NO := 'Query_Adj_Assocs#20';
6929 
6930 	--For i in 1..L_Line_Adj_Assoc_Tbl.count loop
6931           oe_debug_pub.add('zBefore Assoc QUery:');
6932           i:= L_Line_Adj_Assoc_Tbl.FIRST;
6933          WHILE i IS NOT NULL LOOP
6934                 oe_debug_pub.add('zInside Assoc Query i value:'||i);
6935 		l_index := p_Line_Adj_Assoc_Tbl.count+1;
6936                 If p_delete_flag = 'Y' Then
6937 		  p_Line_Adj_Assoc_Tbl(l_index).Operation :=  OE_GLOBALS.G_OPR_DELETE;
6938                 Else
6939                   p_line_adj_assoc_tbl(l_index).Operation :=  FND_API.G_MISS_CHAR;
6940                 End If;
6941                 oe_debug_pub.add('zl_index:'||l_index);
6942 		p_Line_Adj_Assoc_Tbl(l_index).Adj_Index :=  p_Adj_Index;
6943 		p_Line_Adj_Assoc_Tbl(l_index).price_adjustment_id :=  p_price_adjustment_id;
6944 		p_Line_Adj_Assoc_tbl(l_index).Rltd_Price_Adj_Id := l_Line_Adj_Assoc_tbl(i).Rltd_Price_Adj_Id;
6945 		p_Line_Adj_Assoc_tbl(l_index).Line_Id := l_Line_Adj_Assoc_tbl(i).Line_Id;
6946 		p_Line_Adj_Assoc_tbl(l_index).price_adj_assoc_id := l_Line_Adj_Assoc_tbl(i).price_adj_assoc_id;
6947            oe_debug_pub.add('z10');
6948           i:=l_Line_Adj_Assoc_tbl.NEXT(i);
6949            oe_debug_pub.add('z14');
6950           END LOOP;
6951 	--end loop;
6952 
6953 	adj_debug('Exiting oe_order_Adj_pvt.Query_Adj_Assocs',1);
6954 
6955 End Query_Adj_Assocs;
6956 
6957 Procedure Append_Adjustment_Lines(
6958 				p_header_id 		Number default null,
6959 				p_line_id 		Number default null,
6960 				p_Pricing_Event	Varchar2 default null,
6961                                 p_any_frozen_line   Boolean default FALSE,
6962 				p_price_flag		VARCHAR2 default null,
6963 				px_Line_Adj_Tbl in out nocopy OE_Order_Pub.Line_Adj_Tbl_Type,
6964                                 px_line_key_tbl         in out nocopy key_tbl_type,
6965                                 px_header_key_tbl       in out nocopy key_tbl_type,
6966                                 p_mode                  in varchar2 default NULL,
6967                                 px_line_rec             in out nocopy Oe_Order_Pub.Line_Rec_Type,
6968                                 px_line_adj_assoc_tbl   in out nocopy OE_Order_PUB.Line_Adj_Assoc_Tbl_type,
6969 x_updated_flag out nocopy varchar2,
6970 
6971                                 p_multiple_events       in VARCHAR2 Default 'N'
6972                                 )
6973 is
6974 l_Pricing_Phase_id		Index_Tbl_Type;
6975 l_Line_Adj_Tbl			OE_Order_Pub.Line_Adj_Tbl_Type;
6976 i					pls_integer;
6977 J					pls_integer;
6978 p_override_freeze_flag 	VARCHAR2(1) := NULL;
6979 l_visited_flag                  BOOLEAN Default FALSE;
6980 l_dummy               VARCHAR2(1);
6981 l_event_code1 Varchar2(240);
6982 l_mark_for_delete Varchar2(1);
6983 begin
6984 
6985 	adj_debug('Entering oe_order_Adj_pvt.Append_Adjustment_Lines, line_id = ' || p_line_id);
6986         adj_debug('price flag = ' || p_price_flag);
6987 
6988         --If p_any_frozen_line Then l_dummy:='Y'; else l_dummy:='N'; End If;
6989         --adj_debug('BCT p_any_frozen_line '||l_dummy);
6990 	G_STMT_NO := 'Append_Adjustment_Lines#10';
6991 
6992      IF (p_price_flag = 'P') THEN
6993 	  p_override_freeze_flag := 'Y';
6994      END IF;
6995 
6996 
6997 	if p_line_id is not null then
6998 		G_STMT_NO := 'Append_Adjustment_Lines#20';
6999 		adj_debug('BCT p_line_id is not null:'||TO_CHAR(p_line_id));
7000                 OE_Line_Adj_Util.Query_Rows(p_Line_Id => p_line_id,x_line_adj_tbl=>l_Line_Adj_Tbl );
7001 	else
7002                 adj_debug('BCT p_line_id is null');
7003 		G_STMT_NO := 'Append_Adjustment_Lines#25';
7004 
7005                  OE_Line_Adj_Util.Query_Rows(p_header_Id => p_header_id,x_line_adj_tbl=>l_Line_Adj_Tbl);
7006 	End If;
7007 
7008         x_updated_flag := 'N';
7009 	i:= l_Line_Adj_Tbl.First;
7010 	While i is not Null Loop
7011           IF l_Line_Adj_Tbl(i).updated_flag = 'Y' and x_updated_flag = 'N' THEN
7012             x_updated_flag := 'Y';
7013           END IF;
7014 
7015           --The index of  G_Pricing_Phase_Id_Tbl stores pricing phase id
7016           --and the content of this table stores freeze_override_flag
7017           If p_Pricing_Event is Not Null Then
7018 
7019           If l_Line_Adj_Tbl(i).pricing_Phase_id is null
7020               or l_Line_Adj_Tbl(i).pricing_Phase_id = fnd_api.g_miss_num Then
7021              l_mark_for_delete:='Y';
7022           Elsif G_Pricing_Phase_Id_Tbl.Exists(l_Line_Adj_Tbl(i).pricing_Phase_id) Then
7023              If (G_Pricing_Phase_Id_Tbl(l_Line_Adj_Tbl(i).pricing_Phase_id) = 'Y' and p_price_flag = 'P')
7024                or p_price_flag = 'Y'
7025              Then
7026                l_mark_for_delete := 'Y';
7027              Else
7028                l_mark_for_delete := 'N';
7029              End If;
7030           Else
7031              l_mark_for_delete := 'N';
7032           End If;
7033 
7034           adj_debug('Delete ' || l_Line_adj_tbl(i).price_adjustment_id || '? ' || l_mark_for_delete);
7035 
7036           If l_mark_for_delete = 'Y' Then
7037 		G_STMT_NO := 'Append_Adjustment_Lines#30';
7038              if l_Line_Adj_Tbl(i).Modifier_Level_Code= 'ORDER'
7039                 and p_any_frozen_line
7040                 and px_line_rec.ordered_quantity > 0 then
7041 
7042                      --We need to mark it as unchanged for the order level adjustments
7043                      --that have a frozen line
7044 
7045                         L_Line_Adj_Tbl(i).operation :=  FND_API.G_MISS_CHAR;
7046 
7047 	     elsif nvl(l_Line_Adj_Tbl(i).Updated_Flag,'N') = 'N' or
7048 		    l_Line_Adj_Tbl(i).Updated_Flag = fnd_api.g_miss_char then
7049                         adj_debug('BCT'||l_Line_Adj_Tbl(i).price_adjustment_id);
7050 			L_Line_Adj_Tbl(i).operation := OE_GLOBALS.G_OPR_DELETE;
7051 
7052                         --Fix bug 1758251
7053                         If l_line_adj_tbl(i).list_line_type_code = 'IUE' Then
7054                             get_item_for_iue(px_line_rec => px_line_rec);
7055                         End If;
7056 
7057 	     end if;
7058 
7059 	   End if;
7060 
7061 	End If;
7062 
7063           G_STMT_NO := 'Append_Adjustment_Lines#31';
7064 
7065           -- bug 1834409
7066 
7067 	  if ((l_line_adj_tbl(i).operand_per_pqty IS NULL) OR
7068 		(L_line_adj_Tbl(i).operand_per_pqty =  FND_API.G_MISS_NUM))
7069 	  then
7070 		l_line_adj_tbl(i).operand_per_pqty :=
7071 			l_line_adj_tbl(i).operand;
7072 	  end if;
7073 
7074  	if ((l_line_adj_tbl(i).adjusted_amount_per_pqty IS NULL) OR
7075 	     (L_line_adj_Tbl(i).adjusted_amount_per_pqty = FND_API.G_MISS_NUM))
7076 	then
7077 		l_line_adj_tbl(i).adjusted_amount_per_pqty := l_line_adj_tbl(i).adjusted_amount;
7078 	end if;
7079 
7080 	 --  end 1834409
7081 
7082 	  px_line_adj_tbl(px_line_adj_tbl.count+1) := L_Line_Adj_Tbl(i);
7083 
7084           If px_line_adj_tbl(px_line_adj_tbl.count).list_line_type_code In('PBH','PRG','OID','CIE')
7085           Then
7086              If px_line_adj_tbl(px_line_adj_tbl.count).operation = OE_GLOBALS.G_OPR_DELETE
7087       Then
7088              Query_Adj_Assocs(p_price_adjustment_id=>px_line_adj_tbl(px_line_adj_tbl.count).price_adjustment_id,
7089 	  	 p_Adj_Index		=> px_line_adj_tbl.count,
7090 	 	 p_Line_Adj_Assoc_Tbl 	=> px_line_adj_Assoc_tbl,
7091                  p_delete_flag          => 'Y');
7092              Else
7093 
7094                Query_Adj_Assocs(p_price_adjustment_id=>px_line_adj_tbl(px_line_adj_tbl.count).price_adjustment_id,
7095 	  	 p_Adj_Index		=> px_line_adj_tbl.count,
7096 	 	 p_Line_Adj_Assoc_Tbl 	=> px_line_adj_Assoc_tbl,
7097                  p_delete_flag          => 'N');
7098 
7099            End If;
7100           End If;
7101 
7102            --This code is to set the begin and end key of adjustments for a given line
7103            --with this begin and end key find_duplicate_adj_line will find adjustments for
7104            --a given line more effieciently hence improve performance.
7105            adj_debug('BCT *** append list line id'||px_line_adj_tbl(px_line_adj_tbl.count).list_line_id);
7106            If not l_visited_flag Then
7107             If p_mode = 'L' Then
7108               px_line_key_tbl(MOD(p_line_id,G_BINARY_LIMIT)).db_start := px_line_adj_tbl.count;                       -- Bug 8631297
7109               adj_debug('line '||p_line_id||' line key:'||px_line_key_tbl(MOD(p_line_id,G_BINARY_LIMIT)).db_start);   -- Bug 8631297
7110               G_STMT_NO := 'Append_Adjustment_Lines#32';
7111             Elsif p_mode = 'H' Then
7112               px_header_key_tbl(p_header_id).db_start := px_line_adj_tbl.count;
7113               adj_debug('header '||p_header_id||' header key:'||px_header_key_tbl(p_header_id).db_start);
7114               G_STMT_NO := 'Append_Adjustment_Lines#33';
7115             End If;
7116              l_visited_flag := TRUE;
7117            End If;
7118 
7119 	  i:= l_Line_Adj_Tbl.Next(i);
7120 	end loop;
7121 
7122             --record the end index
7123           If l_line_adj_tbl.count > 0 Then  --make sure there are adjustments
7124             If p_mode = 'L' Then
7125               px_line_key_tbl(MOD(p_line_id,G_BINARY_LIMIT)).db_end := px_line_adj_tbl.count;          -- Bug 8631297
7126               adj_debug('line end key: '||px_line_key_tbl(MOD(p_line_id, G_BINARY_LIMIT)).db_end);     -- Bug 8631297
7127 
7128             Elsif p_mode = 'H' Then
7129               px_header_key_tbl(p_header_id).db_end := px_line_adj_tbl.count;
7130             End If;
7131           End if;
7132 
7133 	i:=l_line_adj_tbl.first;
7134 
7135 adj_debug('Exiting oe_order_Adj_pvt.Append_Adjustment_Lines',1);
7136 end Append_Adjustment_Lines;
7137 
7138 Procedure Query_Adj_Attribs(
7139 					p_price_adjustment_id	 Number,
7140 					p_Adj_Index			Number,
7141 					p_Line_Adj_Att_Tbl    in out nocopy OE_Order_Pub.line_adj_att_tbl_Type
7142 					) Is
7143 L_Line_Adj_Att_Tbl		OE_Order_Pub.line_adj_att_tbl_Type;
7144 l_index				pls_integer;
7145 Begin
7146 	adj_debug('Entering oe_order_Adj_pvt.Query_Adj_Attribs',1);
7147 
7148 	G_STMT_NO := 'Query_Adj_Attribs#10';
7149 
7150 	adj_debug('Query for price Adjustment '||p_price_adjustment_id,2);
7151 
7152 	-- Check If the price adjustment has been already queried
7153 
7154 	l_index := p_Line_Adj_Att_Tbl.First;
7155 
7156 	While l_index is not null loop
7157 		If p_Line_Adj_Att_Tbl(l_index).price_adjustment_id = p_price_adjustment_id then
7158 			Return;
7159 		End If;
7160 		l_index := p_Line_Adj_Att_Tbl.Next(l_Index);
7161 
7162 	End Loop;
7163 
7164 	G_STMT_NO := 'Query_Adj_Attribs#15';
7165 
7166 
7167         Oe_Line_Price_Aattr_util.Query_Rows(
7168 				p_price_adjustment_id => p_price_adjustment_id
7169                               , x_Line_Adj_Att_Tbl=>L_Line_Adj_Att_Tbl);
7170 
7171 	-- Append to the tbl with Delete flag set.
7172 	-- The row would be removed from this structure if there is a match.
7173 
7174 	G_STMT_NO := 'Query_Adj_Attribs#20';
7175 
7176 	For i in 1..L_Line_Adj_Att_Tbl.count loop
7177 
7178 		l_index := p_Line_Adj_Att_Tbl.count+1;
7179 		 p_Line_Adj_Att_Tbl(l_index) := l_Line_Adj_Att_tbl(i);
7180 		p_Line_Adj_Att_Tbl(l_index).Operation :=  OE_GLOBALS.G_OPR_DELETE;
7181 		p_Line_Adj_Att_Tbl(l_index).Adj_Index :=  p_Adj_Index;
7182 		p_Line_Adj_Att_Tbl(l_index).price_adjustment_id :=  p_price_adjustment_id;
7183 
7184 	 end loop;
7185 
7186 
7187 	adj_debug('Exiting oe_order_Adj_pvt.Query_Adj_Attribs',1);
7188 
7189 End Query_Adj_Attribs;
7190 
7191 Procedure Find_Duplicate_Adj_Attribs(
7192 			p_Req_Line_Detail_Qual_Rec
7193 							QP_PREQ_GRP.Line_Detail_Qual_Rec_Type,
7194 			p_Req_Line_Detail_Attr_Rec
7195 							QP_PREQ_GRP.Line_Detail_Attr_Rec_Type,
7196 			p_Adj_index 		Number,
7197 			p_Line_Adj_Att_Tbl  in out nocopy OE_Order_Pub.Line_Adj_Att_Tbl_Type,
7198 			p_att_type		Varchar2,
7199 			p_price_adjustment_id	Number
7200 	)
7201 is
7202 l_Index		pls_integer;
7203 I			pls_integer;
7204 Begin
7205 
7206 	adj_debug('Entering oe_order_Adj_pvt.Find_Duplicate_Adj_Attribs',1);
7207 	G_STMT_NO := 'Find_Duplicate_Adj_Attribs#10';
7208 
7209     If p_att_Type='QUALIFIER' and p_Req_Line_Detail_Qual_Rec.Qualifier_Context IS Not Null Then
7210 
7211 	i:= p_Line_Adj_Att_Tbl.First;
7212 	While i is not null loop
7213 	  If  p_Line_Adj_Att_Tbl(i).Adj_Index = p_Adj_index Then
7214 
7215 	   If OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).flex_title ,
7216 								'QP_ATTR_DEFNS_QUALIFIER') and
7217 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_context,
7218 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Context) And
7219 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_attribute ,
7220 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Attribute) And
7221 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_attr_value_from ,
7222 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Attr_Value_From) And
7223 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_attr_value_To ,
7224 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Attr_Value_To) And
7225 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).comparison_operator ,
7226 				p_Req_LINE_DETAIL_qual_Rec.comparison_operator_Code)
7227 	   Then
7228 		-- Do not delete the record from oe_order_Price_adj_Attribs
7229 
7230 		If p_Line_Adj_Att_Tbl(i).Operation = OE_GLobals.g_opr_delete then
7231 			p_Line_Adj_Att_Tbl(i).Operation := FND_API.G_MISS_CHAR;
7232 		End If;
7233 
7234 		Return;
7235 
7236 	   End If;
7237 
7238 	  End if; -- Adj_Index
7239 	  i:= p_Line_Adj_Att_Tbl.Next(i);
7240 	End Loop;
7241 
7242 	G_STMT_NO := 'Find_Duplicate_Adj_Attribs#20';
7243 	-- Create a New Record
7244 	l_index := p_Line_Adj_Att_Tbl.count+1;
7245      p_Line_Adj_Att_Tbl(l_index) := OE_ORDER_PUB.G_MISS_LINE_ADJ_ATT_REC;
7246      p_Line_Adj_Att_Tbl(l_index).operation := OE_GLOBALS.G_OPR_CREATE;
7247 	p_Line_Adj_Att_Tbl(l_index).Adj_index := P_Adj_Index;
7248 	p_Line_Adj_Att_Tbl(l_index).price_adjustment_id := p_price_adjustment_id;
7249 	p_Line_Adj_Att_Tbl(l_index).flex_title := 'QP_ATTR_DEFNS_QUALIFIER';
7250 	p_Line_Adj_Att_Tbl(l_index).pricing_context :=
7251 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Context;
7252 	p_Line_Adj_Att_Tbl(l_index).pricing_attribute :=
7253 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Attribute;
7254 	p_Line_Adj_Att_Tbl(l_index).pricing_attr_value_from :=
7255 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Attr_Value_From;
7256 	p_Line_Adj_Att_Tbl(l_index).pricing_attr_value_To :=
7257 				p_Req_LINE_DETAIL_qual_Rec.Qualifier_Attr_Value_To;
7258 	p_Line_Adj_Att_Tbl(l_index).comparison_operator :=
7259 				p_Req_LINE_DETAIL_qual_Rec.comparison_operator_Code;
7260 
7261    End If; -- Qualifier Contexts
7262 
7263 
7264 	G_STMT_NO := 'Find_Duplicate_Adj_Attribs#30';
7265     If p_att_type='PRICING' and p_Req_Line_Detail_Attr_Rec.Pricing_Context IS Not Null Then
7266 
7267 	i:= p_Line_Adj_Att_Tbl.First;
7268 	While i is not null loop
7269 
7270 	  If p_Line_Adj_Att_Tbl(i).Adj_Index = p_Adj_index Then
7271 
7272 	   If OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).flex_title ,
7273 								'QP_ATTR_DEFNS_PRICING') and
7274 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_context,
7275 				p_Req_Line_Detail_Attr_Rec.Pricing_Context) And
7276 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_attribute ,
7277 				p_Req_Line_Detail_Attr_Rec.Pricing_Attribute) And
7278 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_attr_value_from ,
7279 				p_Req_Line_Detail_Attr_Rec.Pricing_Attr_Value_From) And
7280 		OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).pricing_attr_value_To ,
7281 				p_Req_Line_Detail_Attr_Rec.Pricing_Attr_Value_To)
7282 				--And
7283 		--OE_GLOBALS.Equal(p_Line_Adj_Att_tbl(i).comparison_operator ,
7284 				--p_Req_Line_Detail_Attr_Rec.comparison_operator_Code)
7285 	   Then
7286 		-- Do not delete the record from oe_order_Price_adj_Attribs
7287 
7288 		If p_Line_Adj_Att_Tbl(i).Operation = oe_globals.g_opr_delete Then
7289 			p_Line_Adj_Att_Tbl(i).Operation := FND_API.G_MISS_CHAR;
7290 		End If;
7291 
7292 		Return;
7293 
7294 	   End If;
7295 	  End if; -- Adj_Index
7296 	  i:= p_Line_Adj_Att_Tbl.Next(I);
7297 	End Loop;
7298 
7299 	-- Create a New Record
7300 	l_index := p_Line_Adj_Att_Tbl.count+1;
7301      p_line_adj_att_tbl(l_index) := OE_ORDER_PUB.G_MISS_LINE_ADJ_ATT_REC;
7302      p_Line_Adj_Att_Tbl(l_index).operation := OE_GLOBALS.G_OPR_CREATE;
7303 	p_Line_Adj_Att_Tbl(l_index).Adj_index := P_Adj_Index;
7304 	p_Line_Adj_Att_Tbl(l_index).price_adjustment_id := p_price_adjustment_id;
7305 	p_Line_Adj_Att_Tbl(l_index).flex_title := 'QP_ATTR_DEFNS_PRICING';
7306 	p_Line_Adj_Att_Tbl(l_index).pricing_context :=
7307 				p_Req_Line_Detail_Attr_Rec.Pricing_Context;
7308 	p_Line_Adj_Att_Tbl(l_index).pricing_attribute :=
7309 				p_Req_Line_Detail_Attr_Rec.Pricing_Attribute;
7310 	p_Line_Adj_Att_Tbl(l_index).pricing_attr_value_from :=
7311 				p_Req_Line_Detail_Attr_Rec.Pricing_Attr_Value_From;
7312 	p_Line_Adj_Att_Tbl(l_index).pricing_attr_value_To :=
7313 				p_Req_Line_Detail_Attr_Rec.Pricing_Attr_Value_To;
7314    End If;
7315 
7316 		adj_debug('Exiting oe_order_Adj_pvt.Find_Duplicate_Adj_Attribs',1);
7317 
7318 End Find_Duplicate_Adj_Attribs;
7319 
7320 Function Match_Product_Ids(
7321 		p_price_Adjustment_Id		Number,
7322 		p_Line_Detail_Index			Number ,
7323 		p_Req_line_detail_Attr_Tbl	QP_PREQ_GRP.line_detail_Attr_Tbl_Type
7324 		)
7325 Return Boolean
7326 is
7327 l_inventory_item_id			Varchar2(240);
7328 Begin
7329 	adj_debug('Entering oe_order_Adj_pvt.Match_Product_Ids',1);
7330 	G_STMT_NO := 'Match_Product_Ids#10';
7331 	Begin
7332 	/*
7333 	select PRICING_ATTR_VALUE_FROM into l_inventory_item_id
7334 	from oe_price_adj_attribs opaa
7335 	where price_adjustment_id =p_price_Adjustment_Id and
7336 		Flex_Title ='QP_ATTR_DEFNS_PRICING' and
7337 		Pricing_Context='ITEM' and
7338 		Pricing_attribute='PRICING_ATTRIBUTE1' and
7339 		Rownum < 2;
7340 		*/
7341 
7342 	Select inventory_item_id into l_inventory_item_id
7343 	from oe_price_adjustments opa,oe_order_lines_all ola
7344 	where opa.line_id=ola.line_id and
7345 		opa.price_adjustment_id=p_price_Adjustment_Id;
7346 
7347 	Exception when no_data_found then
7348 		Return False; -- Treat this as new Item
7349 	End;
7350 
7351 	G_STMT_NO := 'Match_Product_Ids#20';
7352 	for i in 1..p_Req_line_detail_Attr_Tbl.count loop
7353 		if p_Req_line_detail_Attr_Tbl(i).line_detail_index = p_Line_Detail_Index and
7354 			 p_Req_line_detail_Attr_Tbl(i).Pricing_Context='ITEM' and
7355 			 p_Req_line_detail_Attr_Tbl(i).Pricing_attribute='PRICING_ATTRIBUTE1' and
7356 			 p_Req_line_detail_Attr_Tbl(i).Pricing_Attr_Value_From = l_inventory_item_id
7357 		Then
7358 		-- Got a match
7359 			adj_debug('Exiting oe_order_Adj_pvt.Match_Product_Ids',1);
7360 			Return True;
7361 		End If;
7362 	End Loop;
7363 	Return False;
7364 
7365 End Match_Product_Ids;
7366 
7367 Procedure Process_Other_Item_Line (
7368 	p_Line_Detail_Index 			Number
7369 	,p_req_line_Tbl 			QP_PREQ_GRP.LINE_TBL_TYPE
7370 	,p_req_line_detail_Tbl 		QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE
7371 	,p_Req_line_detail_Attr_Tbl	QP_PREQ_GRP.line_detail_Attr_Tbl_Type
7372 	,p_Price_Adjustment_Id		Number
7373 	,p_Header_Id				Number
7374 	,p_Parent_Adj_Index			Number
7375 	,p_parent_line_index		Number
7376 	,p_Rltd_line_details_prcd in out nocopy Index_Tbl_Type
7377 	,p_Rltd_lines_prcd		 in out nocopy Index_Tbl_Type
7378 	,p_Line_Tbl			in out nocopy	OE_Order_Pub.Line_Tbl_Type
7379 	,p_Line_Adj_Tbl		in out nocopy	OE_Order_Pub.Line_Adj_Tbl_Type
7380 	,p_Line_Adj_Assoc_Tbl	in out nocopy	OE_Order_Pub.Line_Adj_Assoc_Tbl_Type
7381         ,p_line_detail_replaced       in out nocopy   Index_Tbl_Type
7382         ,p_buy_line_rec         in Oe_Order_Pub.Line_Rec_Type
7383 	)
7384 is
7385 l_line_Adj_Rec			OE_Order_Pub.Line_Adj_Rec_Type;
7386 l_line_Rec			OE_Order_Pub.Line_Rec_Type;
7387 l_Match_Exists			Boolean := False;
7388 l_Req_Line_Index		pls_integer;
7389 l_Adj_Index			pls_integer;
7390 l_assoc_index			pls_integer;
7391 i					Pls_Integer;
7392 j                                       Pls_Integer;
7393 -- Including variables for bug 1820961  begin
7394 l_first          pls_integer;
7395 l_tot_qty        OE_ORDER_LINES_ALL.ordered_quantity%TYPE;
7396 l_tot_price_qty  OE_ORDER_LINES_ALL.pricing_quantity%TYPE;
7397 -- Including variables for bug 1820961  end
7398 l_found_discount_line boolean:=FALSE;
7399 -- This change is required since we are dropping the profile OE_ORGANIZATION    -- _ID. Change made by Esha.
7400 l_org_id Number:= OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
7401 E_CLOSED_PRG_LINE Exception;
7402 l_new_prg_created boolean := FALSE;
7403 Begin
7404 	adj_debug('Entering oe_order_Adj_pvt.Process_Other_Item_Line',1);
7405 	G_STMT_NO := 'Process_Other_Item_Line#10';
7406 
7407 	If p_Price_Adjustment_Id <> FND_API.G_MISS_NUM And
7408 		p_Price_Adjustment_Id is not null Then
7409 		-- The Adjustment Record for OID Adlready exits
7410 		-- That Also means that the "Other Item Line" also exists in the order
7411 		-- Find the "Other Item" Line and update the attributes
7412 
7413 		adj_debug('The PRG already exists '||p_Price_Adjustment_Id);
7414 		-- First find the related Adjustment record
7415 		i:= p_Line_Adj_Assoc_Tbl.First;
7416 -- making changes for bug 1820961   begin
7417                 l_first := i;
7418 -- making changes for bug 1820961   end
7419 		While i is not null loop
7420                 Begin
7421 		 If p_Line_Adj_Assoc_Tbl(i).price_adjustment_id = p_Price_Adjustment_Id
7422 		 Then
7423 			-- Get the Product ID Associated with the adjustment
7424 			IF Match_Product_Ids(
7425 				p_price_Adjustment_Id		=> p_Line_Adj_Assoc_Tbl(i).rltd_Price_Adj_Id,
7426 				p_Line_Detail_Index			=> p_Line_Detail_Index,
7427 				p_Req_line_detail_Attr_Tbl	=> p_Req_line_detail_Attr_Tbl
7428 				)  Then
7429 
7430 			 l_Match_Exists := True;
7431 			 -- Retain the Association Record
7432 				G_STMT_NO := 'Process_Other_Item_Line#15';
7433 
7434 			-- Update The Adjustment Record of the "Other Item"
7435                         -- bug 1843872, find whether the discount line is in memory
7436                         j := p_line_adj_tbl.first;
7437                         while j is not null loop
7438                            if p_line_adj_tbl(j).price_adjustment_id
7439                                = p_line_adj_assoc_tbl(i).rltd_price_adj_id THEN
7440                              l_line_adj_rec := p_line_adj_tbl(j);
7441                              l_found_discount_line := TRUE;
7442                              exit;
7443                            end if;
7444                            j:=p_line_adj_tbl.next(j);
7445                        end loop;
7446                        IF NOT l_found_discount_line THEN
7447                          OE_Line_Adj_Util.Query_Row
7448 			(p_price_Adjustment_Id => p_Line_Adj_Assoc_Tbl(i).rltd_Price_Adj_Id
7449                         , x_line_adj_rec => l_line_adj_rec);
7450                         j:=p_line_adj_tbl.count+1;
7451 			p_Line_Adj_Tbl(p_Line_Adj_Tbl.count+1) := l_Line_Adj_Rec;
7452                        END IF;
7453 
7454 			p_Line_Adj_Assoc_Tbl.delete(i);
7455 
7456     -- Bug 2270949
7457     IF (p_Rltd_line_details_prcd.exists(p_line_detail_index)
7458 and p_line_adj_tbl(p_Rltd_line_details_prcd(p_line_detail_index)).operation = OE_GLOBALS.G_OPR_CREATE) THEN
7459       adj_debug('2270949:replace '||p_Rltd_line_details_prcd(p_line_detail_index)||' with '||j);
7460       p_line_adj_tbl(p_Rltd_line_details_prcd(p_line_detail_index)).operation :=NULL;
7461       p_line_detail_replaced(p_Rltd_line_details_prcd(p_line_detail_index)) := j;
7462     End If;
7463 
7464     p_Rltd_line_Details_prcd(p_Line_detail_Index) := j;
7465     -- End 2270949
7466 
7467 			 If Update_Adj_Line_rec(
7468 					p_Line_Adj_Rec			=>	l_line_Adj_Rec
7469 					,p_req_line_detail_Rec  	=> 	p_req_line_detail_Tbl(p_Line_Detail_Index)
7470 					)
7471 			 Then
7472 				-- There is a Change is the Adjsutment Record
7473       	   		        l_Line_Adj_Rec.operation := OE_GLOBALS.G_OPR_UPDATE;
7474 				p_Line_Adj_Tbl(j) := l_Line_Adj_Rec;
7475 			 End If;
7476 
7477 			 l_Req_Line_Index :=  p_req_line_detail_Tbl(p_Line_Detail_Index).Line_Index;
7478 
7479 			 -- Check If this Related Line Has Already been processed in an earlier loop
7480                          G_STMT_NO := 'Process_Other_Item_Line#18';
7481                          -- 2270949
7482                          If p_Rltd_lines_prcd.exists(l_Req_Line_Index) Then
7483                              adj_debug('req line index'||l_Req_Line_Index||' '||p_Rltd_lines_prcd(l_Req_line_Index));
7484                              adj_debug('operation:'||p_line_tbl(p_Rltd_lines_prcd(l_Req_line_index)).operation);
7485                            if p_line_tbl(p_Rltd_lines_prcd(l_Req_Line_Index)).operation = OE_GLOBALS.G_OPR_CREATE THEN
7486                              -- replace this line with the old line
7487                              adj_debug('delete line'||p_rltd_lines_prcd(l_req_line_index));
7488                             l_new_prg_created := TRUE;
7489 
7490                            End If;
7491                          End If;
7492 
7493                          If l_new_prg_created OR NOT p_Rltd_lines_prcd.exists(l_Req_Line_Index) Then
7494                             -- End 2270949
7495 
7496 				G_STMT_NO := 'Process_Other_Item_Line#20';
7497 
7498                                  OE_Line_Util.Query_Row
7499 		    	  	 (   p_Line_id   => l_line_Adj_Rec.Line_Id
7500                                   ,  x_line_rec  => l_line_rec);
7501 
7502 			   if l_line_rec.operation = FND_API.G_MISS_CHAR then
7503       		   	      l_line_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
7504 			   End If;
7505 
7506                    adj_debug(' GET line, line_id:'||l_line_rec.line_id);
7507                    adj_debug(' GET line, open_flag:'||l_line_rec.open_flag);
7508 
7509                    --Do not process if open_flag set to 'N'
7510                    --BT
7511                    If l_line_rec.open_flag = 'N' Then
7512                       Raise E_Closed_PRG_Line;
7513                    End If;
7514 
7515                    --adj_debug('BCT!!!Adjusted_unit_price:'||p_req_line_tbl(l_Req_Line_Index).adjusted_unit_price);
7516       		   l_line_rec.unit_selling_price_per_pqty := p_req_line_tbl(l_Req_Line_Index).adjusted_unit_price ;
7517       		   l_line_rec.unit_list_price_per_pqty := p_req_line_tbl(l_Req_Line_Index).unit_price ;
7518       		   l_line_rec.unit_list_percent := p_req_line_tbl(l_Req_Line_Index).percent_price ;
7519 	 		   if  nvl(p_req_line_tbl(l_Req_Line_Index).percent_price,0) <> 0 then
7520       			   l_line_rec.unit_selling_percent :=
7521 		  		   ( l_line_rec.unit_selling_price_per_pqty * l_line_rec.unit_list_percent)/
7522 						   p_req_line_tbl(l_Req_Line_Index).percent_price ;
7523                             end if;
7524                     adj_debug('populate change reason!!!',3);
7525 
7526                    -- For bug 1916585, cancellation needs reason
7527                    IF (l_line_rec.change_reason IS NULL
7528                       or l_line_rec.change_reason = fnd_api.g_miss_char) THEN
7529                      l_line_rec.change_reason := 'SYSTEM';
7530                      l_line_rec.change_comments := 'REPRICING';
7531                    END IF;
7532 -- Code included for bug 1820961   begin
7533   -- header_id validation is added for the Bug 2215903
7534    if l_first = i then
7535      begin
7536       select nvl(sum(ordered_quantity),0),nvl(sum(pricing_quantity),0)
7537       into l_tot_qty,l_tot_price_qty
7538       from oe_order_lines
7539       where split_from_line_id = l_line_rec.line_id
7540       and  header_id = l_line_rec.header_id;
7541      exception
7542       when others then
7543        null;
7544      end;
7545      l_line_rec.pricing_quantity :=
7546      p_req_line_tbl(l_req_line_index).priced_quantity - nvl(l_tot_price_qty,0);
7547      l_line_rec.ordered_quantity :=
7548      p_req_line_tbl(l_req_line_index).line_quantity - nvl(l_tot_qty,0);
7549    else
7550     l_line_rec.pricing_quantity :=
7551     p_req_line_tbl(l_Req_Line_Index).priced_quantity ;
7552     l_line_rec.ordered_quantity :=
7553     p_req_line_tbl(l_req_line_index).line_quantity;
7554    end if;
7555 
7556 
7557  l_line_rec.pricing_quantity_uom := p_req_line_tbl(l_Req_Line_Index).priced_uom_code ;
7558  l_line_rec.price_request_code := p_req_line_tbl(l_Req_Line_Index).price_request_code; -- PROMOTIONS SEP/01
7559 
7560       --for bug 2412868  begin
7561          oe_debug_pub.add('bug 2412868 in update1:');
7562         if p_req_line_tbl(l_req_line_index).line_quantity < 0
7563          and ( p_req_line_tbl(l_req_line_index).line_category is null or
7564            p_req_line_tbl(l_req_line_index).line_category  = 'ORDER'
7565            )  then
7566          l_line_rec.line_category_code := 'RETURN' ;
7567          l_line_rec.return_reason_code := 'RETURN' ;
7568          oe_debug_pub.add('bug 2412868 in update:');
7569         elsif p_req_line_tbl(l_req_line_index).line_category = 'RETURN'
7570         then
7571          l_line_rec.line_category_code := 'ORDER' ;
7572         end if;
7573          if l_line_rec.pricing_quantity < 0 and
7574             l_line_rec.ordered_quantity < 0 then
7575             l_line_rec.pricing_quantity :=
7576                abs(p_req_line_tbl(l_Req_Line_Index).priced_quantity);
7577             l_line_rec.ordered_quantity :=
7578                abs(p_req_line_tbl(l_req_line_index).line_quantity);
7579          end if;
7580       --for bug 2412868  end
7581                      IF (l_new_prg_created) THEN
7582                            p_Line_Tbl(p_Rltd_lines_prcd(l_Req_Line_Index)) := l_line_rec;
7583                      Else
7584                            p_Line_Tbl(p_Line_Tbl.last+1) := l_line_rec;
7585 
7586                          p_Rltd_lines_prcd(l_Req_Line_Index) := p_line_Tbl.last;
7587                          -- p_Line_Tbl(p_Line_Tbl.count+1) := l_line_rec;
7588 
7589                           -- p_Rltd_lines_prcd(l_Req_Line_Index) := p_line_Tbl.count;
7590                      End If;
7591 
7592 			 End If; -- p_Rltd_lines_prcd
7593 
7594 		    End If;  -- Match Exists for Item
7595 		  End If;
7596 
7597                   Exception
7598                      When E_Closed_PRG_Line Then
7599                        oe_debug_pub.add('  PRG ignore, Closed line!');
7600                   End; --End for the begin in 'FOR' loop
7601 
7602 		  i:= p_Line_Adj_Assoc_Tbl.Next(i);
7603 		End loop; -- Process Adjustments
7604       End If;
7605 
7606 	G_STMT_NO := 'Process_Other_Item_Line#30';
7607 
7608 	 If Not l_Match_exists Then
7609 
7610 	 adj_debug('There is no existing product match');
7611 	 l_Req_Line_Index :=  p_req_line_detail_Tbl(p_Line_Detail_Index).Line_Index;
7612 
7613 		-- Introduce New Order Line , Order Adjustments and Association Record
7614 		--
7615 		-- Check If this Related Line Has Already been processed in an earlier loop
7616 	   If Not p_Rltd_lines_prcd.exists(l_Req_Line_Index) Then
7617 
7618 		adj_debug('Creating a new line record for header  '||P_Header_Id);
7619         l_line_rec:=OE_ORDER_PUB.G_MISS_LINE_REC;
7620       	l_line_rec.operation := OE_GLOBALS.G_OPR_CREATE;
7621 
7622       	l_line_rec.Header_id := P_Header_Id;
7623    --for bug 2412868  Begin
7624  oe_debug_pub.add('b2412868:'||p_req_line_tbl(l_req_line_index).line_quantity);
7625  oe_debug_pub.add('b2412868:'||p_req_line_tbl(l_req_line_index).priced_quantity);
7626         if p_req_line_tbl(l_req_line_index).line_quantity < 0
7627          and
7628          ( p_req_line_tbl(l_req_line_index).line_category is null or
7629            p_req_line_tbl(l_req_line_index).line_category  = 'ORDER'
7630            )  then
7631          l_line_rec.line_category_code := 'RETURN' ;
7632          l_line_rec.return_reason_code := 'RETURN' ;
7633          oe_debug_pub.add('bug 2412868 in if :');
7634         elsif p_req_line_tbl(l_req_line_index).line_category = 'RETURN' then
7635          l_line_rec.line_category_code := 'ORDER';
7636         end if;
7637    --for bug 2412868  end
7638         -- uom begin
7639       	l_line_rec.unit_selling_price_per_pqty := p_req_line_tbl(l_Req_Line_Index).adjusted_unit_price ;
7640       	l_line_rec.unit_list_price_per_pqty := p_req_line_tbl(l_Req_Line_Index).unit_price ;
7641        --for bug 2412868 begin
7642         if l_line_rec.unit_selling_price_per_pqty < 0
7643         --bug 2992310
7644         and p_req_line_tbl(l_req_line_index).line_quantity < 0  then
7645       	l_line_rec.unit_selling_price_per_pqty :=
7646          abs(p_req_line_tbl(l_Req_Line_Index).adjusted_unit_price ) ;
7647       	l_line_rec.unit_list_price_per_pqty :=
7648          abs(p_req_line_tbl(l_Req_Line_Index).unit_price );
7649         end if;
7650        --for bug 2412868  end
7651         -- uom end
7652       	l_line_rec.unit_list_percent := p_req_line_tbl(l_Req_Line_Index).percent_price ;
7653 	 	if  nvl(p_req_line_tbl(l_Req_Line_Index).percent_price,0) <> 0 then
7654       		l_line_rec.unit_selling_percent :=
7655 		  		 ( l_line_rec.unit_selling_price_per_pqty * l_line_rec.unit_list_percent)/
7656 				p_req_line_tbl(l_Req_Line_Index).percent_price ;
7657 	 	end if;
7658       	l_line_rec.pricing_quantity := p_req_line_tbl(l_Req_Line_Index).priced_quantity ;
7659       	l_line_rec.Ordered_Quantity := p_req_line_tbl(l_Req_Line_Index).priced_quantity ;
7660      --for bug 2412868  begin
7661  if l_line_rec.pricing_quantity < 0 and l_line_rec.Ordered_quantity < 0
7662  then
7663     l_line_rec.pricing_quantity := abs(l_line_rec.pricing_quantity);
7664     l_line_rec.ordered_quantity := abs(l_line_rec.ordered_quantity);
7665   end if;
7666      --for bug 2412868  end
7667       	l_line_rec.pricing_quantity_uom := p_req_line_tbl(l_Req_Line_Index).priced_uom_code ;
7668       	l_line_rec.price_request_code := p_req_line_tbl(l_Req_Line_Index).price_request_code;
7669 
7670         --Why hardcode to INT ?
7671       	l_line_rec.item_identifier_type := 'INT';
7672 
7673         --This is a return, need to copy the return reason code from buy item
7674         If p_buy_line_rec.return_reason_code is Not Null Then
7675             l_line_rec.return_reason_code := p_buy_line_rec.return_reason_code;
7676         End If;
7677 
7678 	/* Fix for Bug 1805134
7679            Set the UOM for the new line created by PRG to be
7680            the same as defined in the modifer
7681            and NOT the base UOM
7682         */
7683 
7684 	oe_debug_pub.add('rlanka: setting ordered quantity UOM');
7685 	oe_debug_pub.add('UOM = ' || p_req_line_tbl(l_Req_Line_Index).line_uom_code);
7686         l_line_rec.order_quantity_uom := p_req_line_tbl(l_Req_Line_Index).line_uom_code;
7687 
7688 	--end Bug 1805134
7689 
7690 	/*
7691 	  Fix for Bug 1729372 : Change calculate_price_flag to 'R'
7692 	  so that charges can be applied to the new line.  This will be
7693 	  handled in OEXULINB.pls
7694 	*/
7695 
7696       	l_line_rec.calculate_price_flag := 'R';
7697 		-- Create the new line in the same ship set as the parent line.
7698       	l_line_rec.ship_set_id := p_line_tbl(p_parent_line_index).ship_set_id;
7699 
7700 		G_STMT_NO := 'Process_Other_Item_Line#35';
7701 		i:= p_req_line_detail_Tbl.First;
7702 		While i is not null loop
7703 			If p_req_line_detail_Tbl(i).line_index = l_Req_Line_Index and
7704 				(p_req_line_detail_Tbl(i).created_from_list_type_code = 'PRL' or
7705 				 p_req_line_detail_Tbl(i).created_from_list_type_code = 'AGR' or
7706 				 p_req_line_detail_Tbl(i).list_line_type_code = 'PLL')
7707 			Then
7708 
7709 				l_line_rec.price_list_id := p_req_line_detail_Tbl(i).list_header_id;
7710 
7711 				exit;
7712 
7713 			End if;
7714 		   i:= p_req_line_detail_Tbl.next(i);
7715 
7716 		End loop;
7717 
7718 		G_STMT_NO := 'Process_Other_Item_Line#135';
7719 		i:= p_Req_line_detail_Attr_Tbl.First;
7720 		While i is not null loop
7721 			if p_Req_line_detail_Attr_Tbl(i).line_detail_index = p_Line_Detail_Index and
7722 				 p_Req_line_detail_Attr_Tbl(i).Pricing_Context='ITEM' and
7723 				 p_Req_line_detail_Attr_Tbl(i).Pricing_attribute='PRICING_ATTRIBUTE1'
7724 			Then
7725 				 adj_debug('The PRG item is '||p_Req_line_detail_Attr_Tbl(i).Pricing_Attr_Value_From);
7726 				 l_line_rec.Inventory_Item_id := p_Req_line_detail_Attr_Tbl(i).Pricing_Attr_Value_From ;
7727 				G_STMT_NO := 'Process_Other_Item_Line#140';
7728 	   			Begin
7729 					SELECT concatenated_segments
7730 					INTO   l_line_rec.ordered_item
7731 					FROM   mtl_system_items_kfv
7732 					WHERE  inventory_item_id = l_line_rec.inventory_item_id
7733 					AND    organization_id = l_org_id;
7734 					Exception when no_data_found then
7735 		 			Null;
7736 	  			End;
7737 
7738 
7739 			Exit;
7740 
7741 			End If;
7742 
7743 		  i := p_Req_line_detail_Attr_Tbl.next(i);
7744 		End Loop;
7745 
7746 		p_Line_Tbl(p_Line_Tbl.last+1) := l_line_rec;
7747 
7748 		 -- Display the PRG Item
7749                  /* 2270949 : delay logging message
7750 		 FND_MESSAGE.SET_NAME('ONT','ONT_CREATED_NEW_LINE');
7751 		 FND_MESSAGE.SET_TOKEN('ITEM',l_line_rec.ordered_item);
7752 		 FND_MESSAGE.SET_TOKEN('QUANTITY',l_line_rec.Ordered_quantity);
7753 		 OE_MSG_PUB.Add('N');
7754                   */
7755                  adj_debug('inside price line: setting cascade');
7756 
7757 		p_Rltd_lines_prcd(l_Req_Line_Index) := p_line_Tbl.last;
7758 
7759 	   End If; -- p_Rltd_lines_prcd
7760 
7761 
7762 		-- Insert Adjustment Records
7763 
7764 		-- Check If this Related Adjustment Line Has Already been processed in an earlier loop
7765 
7766 		G_STMT_NO := 'Process_Other_Item_Line#40';
7767 
7768 	   If Not p_Rltd_line_details_prcd.exists(p_Line_detail_Index) Then
7769 
7770 		   l_Adj_Index := p_line_adj_Tbl.count+1;
7771            p_line_adj_tbl(l_adj_index) := OE_ORDER_PUB.G_MISS_LINE_ADJ_REC;
7772       	   p_line_adj_Tbl(l_Adj_Index).operation := OE_GLOBALS.G_OPR_CREATE;
7773 
7774 			adj_debug('Creating an adjustment record for PRG '||l_Adj_Index);
7775 		  If Update_Adj_Line_rec(
7776 					p_Line_Adj_Rec			=>	p_Line_Adj_Tbl(l_Adj_Index)
7777 					,p_req_line_detail_Rec  	=> p_req_line_detail_Tbl(p_Line_Detail_Index)
7778 					)
7779 		  Then
7780       	   	p_line_adj_Tbl(l_Adj_Index).Updated_Flag := 'N';
7781       	   	p_line_adj_Tbl(l_Adj_Index).Header_id := p_Header_Id;
7782       	   	p_line_adj_Tbl(l_Adj_Index).Line_Index :=  p_Rltd_lines_prcd(l_Req_Line_Index);
7783 		  End If;
7784 
7785 		  p_Rltd_line_Details_prcd(p_Line_detail_Index) := l_Adj_Index;
7786 
7787 	   End If; -- p_Rltd_lines_prcd
7788 
7789 		G_STMT_NO := 'Process_Other_Item_Line#50';
7790 		-- Process the Relationship recordS
7791 
7792                  /* Added following if condition for Bug2211670 */
7793                   If p_Line_Adj_Assoc_tbl.Count > 0 Then
7794 		  l_assoc_index := p_Line_Adj_Assoc_tbl.last+1;
7795                   Else
7796                   l_assoc_index := 1;
7797                   End If;
7798 
7799                      --Commented for Bug2211670
7800 		 -- l_assoc_index := p_Line_Adj_Assoc_tbl.count+1;
7801 
7802                   p_line_adj_assoc_tbl(l_assoc_index) := OE_ORDER_PUB.G_MISS_LINE_ADJ_ASSOC_REC;
7803 		  p_Line_Adj_Assoc_tbl(l_assoc_index).line_index := Null;
7804 		  p_Line_Adj_Assoc_tbl(l_assoc_index).Adj_Index := P_Parent_Adj_Index;
7805 		  p_Line_Adj_Assoc_tbl(l_assoc_index).Rltd_Adj_Index :=
7806 									p_Rltd_line_Details_prcd(p_Line_detail_Index);
7807 		  p_Line_Adj_Assoc_tbl(l_assoc_index).Operation := OE_Globals.G_OPR_CREATE;
7808 
7809 	End If; -- Match_exists
7810 
7811 		adj_debug('Exiting oe_order_Adj_pvt.Process_Other_Item_Line',1);
7812 
7813 End Process_Other_Item_Line;
7814 
7815 Procedure Shell_Sort(p_sorted_tbl in out Nocopy oe_order_adj_pvt.sorted_adjustment_tbl_type) Is
7816 h PLS_INTEGER:=1;
7817 i PLS_INTEGER;
7818 j PLS_INTEGER;
7819 N PLS_INTEGER;
7820 
7821 adj_rec oe_order_adj_pvt.Sorted_Adjustment_Rec_Type;
7822 
7823 Begin
7824 N := p_sorted_tbl.count;
7825 
7826 --DBMS_OUTPUT.PUT_LINE('Determining h step size...');
7827 
7828 For k in 1..N Loop
7829   h:= h*3 + 1;
7830   exit when h*3 + 1 > N;
7831 End Loop;
7832 
7833 --DBMS_OUTPUT.PUT_LINE('h: '||h);
7834 
7835 For k in 1..h Loop
7836 --DBMS_OUTPUT.PUT_LINE('h2:'||h);
7837   i:= h + 1;
7838   For i in h+1..N Loop
7839     adj_rec := p_sorted_tbl(i);
7840     j:=i;
7841 
7842     While ((j > h)
7843            and adj_rec.pricing_group_sequence IS NOT NULL
7844            and (p_sorted_tbl(j-h).pricing_group_sequence IS NULL OR
7845            p_sorted_tbl(j-h).pricing_group_sequence > adj_rec.pricing_group_sequence))
7846       Loop
7847         p_sorted_tbl(j) := p_sorted_tbl(j-h);
7848         j:=j-h;
7849       END Loop;
7850     p_sorted_tbl(j):=adj_rec;
7851   End Loop;
7852 h:= h/3;
7853 Exit When h < 1;
7854 End Loop;
7855 
7856 End;
7857 
7858 Procedure sort_on_pgs(
7859 p_Sorted_Tbl in out nocopy Oe_Order_Adj_Pvt.Sorted_Adjustment_Tbl_Type
7860 ,p_lo		pls_integer
7861 ,p_hi		pls_integer)
7862 is
7863 l_lo		pls_integer := p_lo;
7864 l_hi		pls_integer := p_hi;
7865 l_Sorted_Adjustment_Rec1				 Oe_Order_Adj_Pvt.Sorted_Adjustment_Rec_Type;
7866 l_Sorted_Adjustment_Rec				Oe_Order_Adj_Pvt.Sorted_Adjustment_Rec_Type;
7867 begin
7868   if p_lo >= p_hi Then
7869 	Return;
7870   Elsif p_lo = p_hi -1 then
7871 	if nvl(p_Sorted_Tbl(l_lo).pricing_group_sequence,-1) >
7872 			nvl(p_Sorted_Tbl(l_hi).pricing_group_sequence,-1)
7873 	Then
7874 		l_Sorted_Adjustment_Rec1 := p_Sorted_Tbl(l_lo);
7875 		p_Sorted_Tbl(l_lo) := p_Sorted_Tbl(l_hi);
7876 		p_Sorted_Tbl(l_hi) := l_Sorted_Adjustment_Rec1;
7877 	End If;
7878 	Return;
7879   End If;
7880 
7881   l_Sorted_Adjustment_Rec := p_Sorted_Tbl((l_lo+l_hi)/2);
7882   p_Sorted_Tbl((l_lo+l_hi)/2):= p_Sorted_Tbl(l_hi);
7883   p_Sorted_Tbl(l_hi) :=  l_Sorted_Adjustment_Rec;
7884 
7885   While l_lo < l_hi loop
7886 
7887 	While nvl(p_Sorted_Tbl(l_lo).pricing_group_sequence,fnd_api.g_miss_num) <=
7888 		nvl(l_Sorted_Adjustment_Rec.pricing_group_sequence,fnd_api.g_miss_num)  and
7889 		l_lo < l_hi loop
7890 
7891 		l_lo := l_lo+1;
7892 	end loop;
7893 
7894 	While nvl(l_Sorted_Adjustment_Rec.pricing_group_sequence ,fnd_api.g_miss_num)<=
7895 		nvl(p_Sorted_Tbl(l_hi).pricing_group_sequence,fnd_api.g_miss_num) and
7896 		l_lo < l_hi loop
7897 		l_hi := l_hi-1;
7898 	end loop;
7899 
7900 	If l_lo < l_hi then
7901 		l_Sorted_Adjustment_Rec1 := p_Sorted_Tbl(l_lo);
7902 		p_Sorted_Tbl(l_lo) := p_Sorted_Tbl(l_hi);
7903 		p_Sorted_Tbl(l_hi) := l_Sorted_Adjustment_Rec1;
7904 	end if;
7905 
7906   End loop;
7907 
7908   p_Sorted_Tbl(p_hi) :=  p_Sorted_Tbl(l_hi);
7909   p_Sorted_Tbl(l_hi) :=  l_Sorted_Adjustment_Rec;
7910   l_lo := l_lo -1;
7911   l_hi := l_hi+1;
7912 
7913   sort_on_pgs( p_Sorted_Tbl => p_Sorted_Tbl
7914 		,p_lo			=> p_lo
7915 		,p_hi			=> l_lo);
7916 
7917   sort_on_pgs( p_Sorted_Tbl => p_Sorted_Tbl
7918 		,p_lo			=> l_hi
7919 		,p_hi			=> p_hi);
7920 
7921 End sort_on_pgs;
7922 
7923 Function find_updated_adjustments(
7924 	p_header_id 			number default null
7925 	,p_Line_id 			number default null
7926 	,p_Line_Adj_Tbl 		oe_order_pub.line_adj_tbl_type
7927 	)
7928 Return boolean
7929 is
7930 i		pls_integer;
7931 begin
7932 	i := p_Line_Adj_Tbl.first;
7933 	while i is not null loop
7934 	  If ( p_Line_Adj_Tbl(i).line_id = p_Line_id or
7935 		  p_line_id is null and p_Line_Adj_Tbl(i).header_id = p_header_id ) and
7936 		p_Line_Adj_Tbl(i).updated_flag = 'Y' and
7937 		p_Line_Adj_Tbl(i).Applied_Flag = 'Y' then
7938 		Return True; -- Atleast one adjustment has been updated
7939 	  end if;
7940 	  i := p_Line_Adj_Tbl.Next(i);
7941 	end loop;
7942 	Return False;
7943 end find_updated_adjustments;
7944 
7945 Procedure Gsa_Check(
7946 p_header_id                             Number
7947 ,p_line_id				Number
7948 ,p_inventory_item_id    Varchar2 --bug 2673506
7949 ,p_pricing_date		date
7950 ,p_request_type_code	Varchar2
7951 ,p_unit_selling_price_per_pqty	number
7952 ,p_gsa_violation_action	Varchar2
7953 ,p_price_event1  Varchar2 default null  --for bug 2273446
7954 )
7955 is
7956 l_hold_source_rec			OE_Holds_Pvt.hold_source_rec_type;
7957 l_hold_release_rec  		OE_Holds_Pvt.Hold_Release_REC_Type;
7958 l_return_status			varchar2(30);
7959 l_x_msg_count                   number;
7960 l_x_msg_data                    Varchar2(2000);
7961 l_x_result_out                 Varchar2(30);
7962 l_list_name				varchar2(240);
7963 --for bug 2028480 Begin
7964 l_gsa_released   varchar2(1):= 'N';
7965 --for bug 2028480 end
7966 l_operand					number;
7967 l_msg_text				Varchar2(200);
7968 l_org_id 					Number:= OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID');
7969 
7970 Cursor get_gsa_list_lines is
7971 Select/*+ ordered use_nl(qpq qppa qpll qplh) */ min(qpll.operand)
7972  From
7973       qp_qualifiers qpq
7974  ,    qp_pricing_attributes qppa
7975  ,    qp_list_lines qpll
7976  ,    qp_list_headers_b qplh
7977  ,    qp_price_req_sources qpprs
7978  where
7979  qpq.qualifier_context='CUSTOMER'
7980  and qpq.qualifier_attribute='QUALIFIER_ATTRIBUTE15'
7981  and qpq.qualifier_attr_value='Y'
7982  and qppa.list_header_id=qplh.list_header_id
7983  and qplh.Active_flag='Y'
7984  and qpprs.request_type_code = p_request_type_code
7985  and qpprs.source_system_code=qplh.source_system_code
7986  and    qppa.pricing_phase_id  = 2
7987  and    qppa.qualification_ind = 6
7988  and qppa.product_attribute_context ='ITEM'
7989  and qppa.product_attribute='PRICING_ATTRIBUTE1'
7990  and qppa.product_attr_value= p_inventory_item_id
7991  and qppa.excluder_flag = 'N'
7992  and qppa.list_header_id=qpq.list_header_id
7993  and qppa.list_line_id=qpll.list_line_id
7994  and  p_pricing_date between nvl(trunc(qplh.start_date_active),p_pricing_date)
7995  and nvl(trunc(qplh.End_date_active),p_pricing_date);
7996 
7997 
7998 Begin
7999 
8000 	 G_STMT_NO := 'Gsa_Check#10';
8001 	 open get_gsa_list_lines;
8002 	 fetch get_gsa_list_lines into l_operand;
8003 	 close get_gsa_list_lines;
8004 
8005 	 G_STMT_NO := 'Gsa_Check#20';
8006   	  if p_unit_selling_price_per_pqty <= l_operand then
8007 		--Check if the GSA check needs to be done.
8008 			If p_gsa_violation_action = 'WARNING' then
8009 				Begin
8010 					SELECT concatenated_segments
8011 					INTO   l_msg_text
8012 					FROM   mtl_system_items_kfv
8013 					WHERE  inventory_item_id = p_inventory_item_id
8014 					AND    organization_id = l_org_id;
8015 					Exception when no_data_found then
8016 		 			Null;
8017 				End;
8018                      if nvl(p_price_event1,'N') <> 'PRICE' then --bug 2273446
8019   			FND_MESSAGE.SET_NAME('ONT','OE_GSA_VIOLATION');
8020 			l_msg_text := l_operand||' ( '||l_msg_text||' )';
8021   			FND_MESSAGE.SET_TOKEN('GSA_PRICE',l_msg_text);
8022   			OE_MSG_PUB.Add;
8023                      end if; --bug 2273446
8024 
8025 			Else
8026 	 			G_STMT_NO := 'Gsa_Check#20.15';
8027                                 -- bug 1381660, duplicate holds with type_code='GSA'
8028                                 -- use the seeded hold_id
8029                                 l_hold_source_rec.hold_id := G_SEEDED_GSA_HOLD_ID;
8030 				/*Begin
8031 					Select hold_id into l_hold_source_rec.hold_id
8032 					from oe_hold_definitions where type_code='GSA';
8033 					Exception when no_data_found then
8034 		  			FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
8035 		  			FND_MESSAGE.SET_TOKEN('ERR_TEXT','Missing hold_definition for type_code GSA');
8036 		  			OE_MSG_PUB.Add;
8037 					adj_debug('Missing hold_definition for type_code GSA');
8038 				End;*/
8039 
8040 				If p_line_id is null or
8041 					p_line_id = fnd_api.g_miss_num then
8042 		  			FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
8043 		  			FND_MESSAGE.SET_TOKEN('ERR_TEXT','GSA_INVALID_LINE_ID');
8044 		  			OE_MSG_PUB.Add;
8045 					 RAISE FND_API.G_EXC_ERROR;
8046 				End if;
8047 
8048 	 			G_STMT_NO := 'Gsa_Check#20.20';
8049 				l_hold_source_rec.hold_entity_id := p_header_id;
8050                                 l_hold_source_rec.header_id := p_header_id;
8051                                 l_hold_source_rec.line_id := p_line_id;
8052 				l_hold_source_rec.Hold_Entity_code := 'O';
8053 --for bug 2028480   Begin
8054 --check if hold released earlier for this line , if so, do not go
8055 --thru the holds logic
8056         adj_debug('Hold Id :'||l_hold_source_rec.hold_id);
8057         Begin
8058 --changed select below to fix bug 3039915
8059           select 'Y' into l_gsa_released from
8060           oe_order_holds ooh,oe_hold_sources ohs,oe_hold_releases ohr
8061           where ooh.line_id = p_line_id
8062           and ooh.hold_source_id = ohs.hold_source_id
8063           and ohr.hold_release_id = ooh.hold_release_id
8064           and ohs.hold_id = l_hold_source_rec.hold_id
8065           and ohr.created_by <> 1
8066           and ohr.release_reason_code <> 'PASS_GSA';
8067         exception
8068           when others then
8069             l_gsa_released := 'N';
8070         end;
8071         adj_debug('GSA released value :'||l_gsa_released);
8072 --for bug 2028480   end
8073                         if l_gsa_released = 'N' then --for bug 2028480
8074                -- check if line already on gsa hold, place hold if not
8075   			        OE_Holds_Pub.Check_Holds(
8076 					p_api_version		=> 1.0
8077                                         ,p_header_id            => p_header_id
8078 					,p_line_id		=> p_line_id
8079 					,p_hold_id		=> l_hold_source_rec.Hold_id
8080 					,x_return_status	=> l_return_status
8081 					,x_msg_count		=> l_x_msg_count
8082 					,x_msg_data		=> l_x_msg_data
8083 					,x_result_out		=> l_x_result_out
8084 					);
8085 
8086   			        If  l_x_result_out = FND_API.G_FALSE then
8087                                   adj_debug('hold line with header_id:'||p_header_id||' line_id: '||p_line_id,1);
8088 				  OE_HOLDS_PUB.Apply_Holds(
8089 					p_api_version	=> 1.0
8090 					,p_hold_source_rec	=> l_hold_source_rec
8091 					,x_return_status	=> l_return_status
8092 					,x_msg_count		=> l_x_msg_count
8093 					,x_msg_data		=> l_x_msg_data
8094 					);
8095 
8096 				  If l_return_status = FND_API.g_ret_sts_success then
8097                         if nvl(p_price_event1,'N') <> 'PRICE' then --bug 2273446
8098 
8099 		     	  FND_MESSAGE.SET_NAME('ONT','OE_GSA_HOLD_APPLIED');
8100 		  	  OE_MSG_PUB.Add;
8101                         end if; --bug 2273446
8102 				  Else
8103 		  			FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
8104 		  			FND_MESSAGE.SET_TOKEN('ERR_TEXT','APPLY_GSA_HOLD');
8105 		  			OE_MSG_PUB.Add;
8106 					RAISE FND_API.G_EXC_ERROR;
8107 				  End If;
8108                                 End If; /* check hold */
8109                          End If; --for bug 2028480 end
8110 			End if;  /* violation action */
8111 
8112 	 Else -- Check if a hold was placed before , release the hold
8113 		If p_line_id is not null and
8114 			p_line_id <> fnd_api.g_miss_num then
8115 
8116 			If l_hold_source_rec.hold_id is null or
8117 					l_hold_source_rec.hold_id = fnd_api.g_miss_num then
8118 	 			G_STMT_NO := 'Gsa_Check#20.25';
8119                                 -- bug 1381660, duplicate holds with type_code='GSA'
8120                                 -- use the seeded hold_id
8121                                 l_hold_source_rec.hold_id := G_SEEDED_GSA_HOLD_ID;
8122 				/*Begin
8123 					Select hold_id into l_hold_source_rec.hold_id
8124 					from oe_hold_definitions where type_code='GSA';
8125 					Exception when no_data_found then
8126 		  			FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
8127 		  			FND_MESSAGE.SET_TOKEN('ERR_TEXT','Missing hold_definition for type_code GSA');
8128 		  			OE_MSG_PUB.Add;
8129 					adj_debug('Missing hold_definition for type_code GSA');
8130 				End;*/
8131 
8132 			End if; -- Hold id
8133 	 		G_STMT_NO := 'Gsa_Check#20.30';
8134 
8135 				l_hold_source_rec.hold_entity_id := p_header_id;
8136                                 l_hold_source_rec.header_id := p_header_id;
8137                                 l_hold_source_rec.line_id := p_line_id;
8138 				l_hold_source_rec.Hold_Entity_code := 'O';
8139 
8140 
8141 			OE_Holds_Pub.Check_Holds(
8142 					p_api_version		=> 1.0
8143                                         ,p_header_id            => p_header_id
8144 					,p_line_id		=> p_line_id
8145 					,p_hold_id		=> l_hold_source_rec.Hold_id
8146 					,x_return_status	=> l_return_status
8147 					,x_msg_count		=> l_x_msg_count
8148 					,x_msg_data		=> l_x_msg_data
8149 					,x_result_out		=> l_x_result_out
8150 					);
8151 
8152 
8153 			If  l_x_result_out = FND_API.G_TRUE then
8154 				-- Hold is found , Release the hold.
8155 
8156 	 			G_STMT_NO := 'Gsa_Check#20.35';
8157 			l_hold_release_rec.release_reason_code :='PASS_GSA';
8158   --for bug 3039915 set created_by = 1  to indicate automatic hold release
8159 		l_hold_release_rec.created_by := 1;
8160 
8161 				OE_Holds_Pub.Release_Holds(
8162 					p_api_version	=> 1.0
8163 --					,p_hold_id		=> l_hold_source_rec.Hold_id
8164 --					,p_entity_code 	=> l_hold_source_rec.Hold_entity_code
8165 --					,p_entity_id		=> l_hold_source_rec.Hold_entity_id
8166                                         ,p_hold_source_rec      => l_hold_source_rec
8167 					,p_hold_release_rec	=> l_hold_release_rec
8168 					,x_return_status	=> l_return_status
8169 					,x_msg_count		=> l_x_msg_count
8170 					,x_msg_data		=> l_x_msg_data
8171 					);
8172 
8173 				IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8174 					adj_debug('Error while releasing GSA Hold');
8175 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8176 				ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
8177 					adj_debug('Error while releasing GSA Hold');
8178 					RAISE FND_API.G_EXC_ERROR;
8179 				END IF;
8180 			End if; -- Release Hold
8181 
8182 		End if; -- GSA Check Hold
8183 
8184 	 End If; -- GSA Violation
8185 
8186 
8187 End Gsa_Check;
8188 
8189 Procedure CAlculate_Adjusted_Price(
8190 p_bucketed_price   			Number
8191 ,p_line_category                          Varchar2
8192 ,p_arithmetic_operator			Varchar2
8193 ,p_operand					Number
8194 ,p_Pricing_Quantity				Number
8195 ,p_rounding_Factor				Number
8196 ,p_modifier_level_code                          Varchar2 := NULL
8197 ,p_group_value                                  Number   := NULL
8198 ,x_Adjusted_Amount out nocopy NUMBER
8199 
8200 )
8201 Is
8202 Begin
8203 	adj_debug('Entering oe_order_Adj_pvt.CAlculate_Adjusted_Price');
8204 	If p_arithmetic_operator = 'AMT' Then
8205 		x_Adjusted_Amount := p_operand;
8206 	Elsif p_arithmetic_operator = '%' then
8207                --bug 2764291
8208 		x_Adjusted_Amount := abs(p_bucketed_price) *p_operand /100;
8209 	Elsif p_arithmetic_operator = 'NEWPRICE' Then
8210                 x_Adjusted_Amount := - p_bucketed_price + p_operand;
8211 
8212 	Elsif p_arithmetic_operator = 'LUMPSUM' then
8213      --
8214              IF (p_modifier_level_code  = QP_PREQ_GRP.G_LINE_GROUP) THEN
8215 	        --
8216 		   -- p_modifier_level_code = 'LINEGROUP'
8217 		   --
8218                  adj_debug('LINEGROUP');
8219 			  IF nvl(p_group_value,0) <> 0 THEN
8220                      x_Adjusted_Amount := p_operand / p_group_value;
8221 				 adj_debug('p_group_value');
8222                  ELSE
8223                      --x_Adjusted_Amount := p_operand;
8224                      x_adjusted_amount:=0;
8225                      adj_debug('p_group_value is 0');
8226                  END IF;
8227              ELSE
8228                 If nvl(p_Pricing_Quantity,0) <> 0 then
8229 			    x_Adjusted_Amount := p_operand / p_Pricing_Quantity;
8230 		      Else
8231 			    x_Adjusted_Amount := p_operand;
8232                 END IF;
8233 		   End IF;
8234 	End If;
8235 
8236 
8237 	adj_debug('Exiting oe_order_Adj_pvt.CAlculate_Adjusted_Price');
8238 
8239 end CAlculate_Adjusted_Price;
8240 
8241 Procedure Calculate_Price (
8242 p_Header_Rec					Oe_Order_Pub.Header_Rec_Type
8243 ,p_Line_Tbl		in out nocopy	Oe_Order_Pub.Line_Tbl_Type
8244 ,p_Line_Adj_Tbl	in out nocopy Oe_Order_Pub.Line_Adj_Tbl_Type
8245 ,p_line_adj_assoc_Tbl		Oe_Order_Pub.line_adj_assoc_Tbl_Type
8246 ,p_allow_Negative_Price		Varchar2
8247 ,p_request_Type_Code		Varchar2
8248 ,p_any_line_frozen              Boolean default False
8249 ,p_price_event  Varchar2 default null  --for bug 2273446
8250 ,p_honor_price_flag   Varchar2  default  'Y'   --bug 2503186
8251 )
8252 is
8253 lx_return_status	 varchar2(1) := FND_API.G_RET_STS_SUCCESS;
8254 lx_return_status_Text	 varchar2(240) ;
8255 l_discount_surcharge		Boolean;
8256 i						pls_integer;
8257 J						pls_integer;
8258 J1						pls_integer;
8259 J2						pls_integer;
8260 l_Bucketed_price			Number;
8261 l_pricing_group_sequence		Number := fnd_api.g_miss_num;
8262 l_Total_Quantity			Number;
8263 l_sign					Number;
8264 l_rounding_factor			Number;
8265 l_gsa_violation_action		Varchar2(30); --moac moving the initialization to the body
8266 l_GSA_Enabled_Flag 			Varchar2(30) := FND_PROFILE.VALUE('QP_VERIFY_GSA');
8267 l_Sorted_Adjustment_Tbl		oe_order_Adj_pvt.Sorted_Adjustment_Tbl_Type;
8268 l_Sort_Index				Pls_Integer;
8269 l_pricing_quantity			Number;
8270 l_assoc_exist				Boolean;
8271 l_adjusted_amt_changed                  Boolean;
8272 -- for bug 1717501  Begin
8273 l_gsa_cust_check varchar2(1);
8274 -- for bug 1717501 end
8275 l_status_code Varchar2(5);
8276 
8277 l_item_rec                    OE_ORDER_CACHE.item_rec_type; -- OPM 2547940
8278 l_process		      Boolean; -- OPM 2547940
8279 
8280 Begin
8281 
8282 	adj_debug('Entering oe_order_Adj_pvt.Calculate_Price');
8283 
8284 	--moac
8285         l_gsa_violation_action    := oe_sys_parameters.value('ONT_GSA_VIOLATION_ACTION',p_header_rec.org_id);
8286 
8287 	 --OE_Order_Pub.G_HDR := p_header_rec;
8288 
8289 	G_STMT_NO := 'Calculate_Price#05';
8290 	i := p_Line_Adj_Tbl.First;
8291 
8292 	While i is not null loop
8293 		l_Sorted_Adjustment_Tbl(i).Adj_Index := i;
8294 		l_Sorted_Adjustment_Tbl(i).pricing_group_sequence := p_Line_Adj_Tbl(i).pricing_group_sequence;
8295 		i := p_Line_Adj_Tbl.Next(i);
8296 	End Loop;
8297 
8298 	shell_sort(p_Sorted_Tbl => l_Sorted_Adjustment_Tbl);
8299 
8300 	G_STMT_NO := 'Calculate_Price#10';
8301 	i:= p_Line_Tbl.First;
8302 	 adj_debug('Honor Price flag :'||p_honor_price_flag,2);
8303 	While  i is not null Loop
8304 	l_process := 											-- INVCONV oe_line_util.Process_Characteristics -- OPM 2547940
8305                         oe_line_util.dual_uom_control  -- INVCONV
8306                        (p_line_tbl(i).inventory_item_id
8307                         ,p_line_tbl(i).ship_from_org_id
8308                         ,l_item_rec);
8309 
8310          If p_line_tbl(i).calculate_price_flag in ('Y','P')
8311             OR (p_price_event is NULL and
8312                 p_line_tbl(i).operation = oe_globals.G_OPR_UPDATE)
8313             OR p_honor_price_flag = 'N'  --bug 2503186
8314             OR  -- OPM 2547940 start - for copy of order OR split from shipping - need to re-price as these lines
8315                 -- as may have freeze price for calulate price flag when pricing by quantity2
8316              (
8317                    ( l_process)
8318                    and  (l_item_rec.ont_pricing_qty_source = 1 ) -- price by quantity 2
8319                    and  ( p_line_tbl(i).calculate_price_flag In ('N','P') )
8320 		   and ( p_line_tbl(i).split_by is not null )
8321 		   and ( p_line_tbl(i).split_from_line_id is not null and p_line_tbl(i).split_from_line_id <> FND_API.G_MISS_NUM)
8322              ) --  OPM 2547940 end
8323 
8324 
8325          Then
8326 	 adj_debug('Processing Line id '||p_line_tbl(i).line_id,2);
8327 
8328 	 If p_Line_Tbl(i).operation in (oe_globals.g_opr_delete, oe_globals.g_opr_lock) or
8329             (p_Line_Tbl(i).Unit_list_price is null
8330              and p_Line_Tbl(i).Unit_list_price_per_pqty is null)
8331          Then
8332             adj_debug('Line '||p_line_tbl(i).line_id||' price is not calculated');
8333             adj_debug(' Unit_list_price:'||p_Line_Tbl(i).Unit_list_price);
8334             adj_debug(' Unit_list_price_per_pqty:'||p_Line_Tbl(i).Unit_list_price_per_pqty);
8335             adj_debug(' Line opr '||p_Line_Tbl(i).operation);
8336          Else
8337 
8338 
8339                 adj_debug('selling price before ..'||p_Line_Tbl(i).Unit_Selling_Price_Per_Pqty);
8340 
8341                 --For backward compatiblity, to correct the old data
8342                 If  nvl(p_Line_Tbl(i).unit_list_price_Per_Pqty,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM and
8343                     p_Line_Tbl(i).unit_list_price is Not Null Then
8344                     If nvl(p_line_tbl(i).pricing_quantity,0) <> 0 and
8345                        p_line_tbl(i).pricing_quantity <> FND_API.G_MISS_NUM
8346                     Then
8347                       p_line_tbl(i).unit_list_price_per_pqty :=(p_line_tbl(i).unit_list_price * p_line_tbl(i).ordered_quantity)/p_line_tbl(i).pricing_quantity;
8348                     Else
8349                       p_Line_Tbl(i).unit_list_price_Per_Pqty := p_Line_Tbl(i).unit_list_price;
8350                     End If;
8351                 End If;
8352 
8353                 If nvl(p_Line_Tbl(i).unit_selling_price_per_pqty,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM and
8354                    p_Line_Tbl(i).unit_selling_price Is Not Null Then
8355                      If nvl(p_line_tbl(i).pricing_quantity,0) <> 0 and
8356                         p_line_tbl(i).pricing_quantity <> FND_API.G_MISS_NUM
8357                      Then
8358                       p_line_tbl(i).unit_selling_price_per_pqty :=(p_Line_Tbl(i).unit_selling_price * p_line_tbl(i).ordered_quantity)/p_line_tbl(i).pricing_quantity;
8359                      Else
8360                       p_Line_Tbl(i).unit_selling_price_per_pqty := p_Line_Tbl(i).unit_selling_price;
8361                      End If;
8362                 End If;
8363 
8364                 -- uom begin
8365 		  p_line_tbl(i).Unit_Selling_Price_Per_Pqty := p_Line_Tbl(i).unit_list_price_Per_Pqty;
8366 		  l_bucketed_price := p_line_Tbl(i).unit_list_price_per_pqty;
8367                 -- uom end
8368 
8369 		l_pricing_group_sequence		:= fnd_api.g_miss_num;
8370 
8371 
8372 		adj_debug('No of adjs in Calculate_Price '||p_Line_Adj_Tbl.count);
8373 		l_Sort_Index:= l_Sorted_Adjustment_Tbl.First;
8374 		While l_Sort_Index is not null Loop
8375 
8376 		J := l_Sorted_Adjustment_Tbl(l_Sort_Index).Adj_Index;
8377                 l_adjusted_amt_changed := FALSE;
8378                 oe_debug_pub.add('  Sorted index value:'||J);
8379 		G_STMT_NO := 'Calculate_Price#20';
8380 
8381 		  If ( p_Line_Adj_Tbl(j).Line_Index = i  or
8382 			  (p_Line_Adj_Tbl(j).line_id = p_Line_Tbl(i).line_id and
8383 			 	p_Line_Adj_Tbl(j).line_id <> fnd_api.g_miss_num
8384 			  )or
8385 			  ( ( p_Line_Adj_Tbl(j).line_id is null or
8386 				 p_Line_Adj_Tbl(j).line_id = fnd_api.g_miss_num ) and
8387 				 (p_Line_Adj_Tbl(j).line_index is null or
8388 				 p_Line_Adj_Tbl(j).line_index = fnd_api.g_miss_num) and
8389 				 p_Line_Adj_Tbl(j).Header_Id = p_header_Rec.Header_Id
8390 				 )) and -- Header Level Adjustments
8391 			  p_Line_Adj_Tbl(j).Operation <> OE_Globals.G_OPR_DELETE and
8392 			  nvl(p_Line_Adj_Tbl(j).applied_flag,'N')='Y' and
8393 /* Modified the nvl to 'N' in the above statement to fix the bug 2164508 */
8394 			  p_Line_Adj_Tbl(j).list_line_type_code in ('DIS','SUR','FREIGHT_CHARGE','PBH')
8395 		  then
8396 
8397                         --adj_debug('BCT+fullfilled calculate');
8398 			If p_Line_Adj_Tbl(j).pricing_group_sequence is null then
8399                             If nvl(p_line_Tbl(i).unit_list_price_per_pqty,FND_API.G_MISS_NUM)
8400                                <> FND_API.G_MISS_NUM
8401                             Then
8402                             	l_bucketed_price := p_line_Tbl(i).unit_list_price_per_pqty;
8403                             Else
8404                                 l_bucketed_price := p_line_Tbl(i).unit_list_price;
8405                             End If;
8406 			Elsif p_Line_Adj_Tbl(j).pricing_group_sequence <> l_pricing_group_sequence then
8407                             If nvl(p_line_Tbl(i).unit_selling_price_per_pqty,FND_API.G_MISS_NUM)
8408                                <> FND_API.G_MISS_NUM
8409                             Then
8410                             	l_bucketed_price := p_line_Tbl(i).unit_selling_price_per_pqty;
8411                             Else
8412                                 l_bucketed_price := p_line_Tbl(i).unit_selling_price;
8413                             End If;
8414 			End If;
8415 
8416 			If p_Line_Adj_Tbl(j).List_line_type_code = 'PBH' Then
8417 
8418 			  adj_debug('First Time Adj Amount: ' || p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty,3);
8419                           --reset adj amount for parent PBH.
8420                           --will be recalculated.
8421                           If p_line_adj_tbl(j).price_break_type_code = QP_PREQ_GRP.G_RANGE_BREAK Then
8422                              p_Line_Adj_Tbl(j).adjusted_amount_per_pqty:=0;
8423                           End If;
8424                             oe_debug_pub.add('xNo of assoc in assoc_tbl:'|| p_line_adj_assoc_Tbl.count);
8425 		    	  J1 := p_line_adj_assoc_Tbl.First;
8426 			  l_Total_Quantity := 0;
8427 			  l_assoc_exist := FALSE;
8428 			  While J1 is not null loop
8429 			 	If ( (p_line_adj_assoc_Tbl(j1).Adj_index = J Or
8430 					    (p_line_adj_assoc_Tbl(j1).Price_adjustment_id =
8431 						  p_Line_Adj_Tbl(j).Price_Adjustment_id and
8432 						  p_Line_Adj_Tbl(j).Price_Adjustment_id <> fnd_api.g_miss_num )) and (nvl(p_line_adj_assoc_Tbl(j1).operation,'xxyz') <>  OE_GLOBALS.G_OPR_DELETE)
8433 					)  Then
8434 				  l_assoc_exist := TRUE;
8435 			       p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty := 0;
8436                                l_adjusted_amt_changed := TRUE;
8437 				End If;
8438 			 	J1 := p_line_adj_assoc_Tbl.Next(J1);
8439 			  End Loop;
8440 
8441 			  If (p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty <> 0 and l_assoc_exist = FALSE) Then
8442 			   adj_debug('Adjusted Amount  pqty : ' || nvl(p_line_adj_tbl(j).adjusted_amount_per_pqty,0));
8443                            adj_debug('adjusted amount :'||p_line_adj_tbl(j).adjusted_amount);
8444 			   adj_debug('Unit Selling Price #100 : ' || nvl(p_line_tbl(i).Unit_Selling_Price,0));
8445 
8446 
8447 			   p_line_tbl(i).Unit_Selling_Price_Per_Pqty :=
8448 			   p_line_tbl(i).Unit_Selling_Price_Per_Pqty + nvl(p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty,0);
8449 			   p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty := 0;
8450                            l_adjusted_amt_changed := TRUE;
8451 			  End If;
8452 
8453 		    	  J1 := p_line_adj_assoc_Tbl.First;
8454 			  G_STMT_NO := 'Calculate_Price#30';
8455 
8456 			  adj_debug('Calculate_Price: PBH Line ('||j||')'||
8457 										p_Line_Adj_Tbl(j).price_adjustment_id,2);
8458 			  adj_debug('PBH Adjustment ('||j||')'||
8459 										p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,2);
8460 		    	  While J1 is not null loop
8461 			 	If ( (p_line_adj_assoc_Tbl(j1).Adj_index = J Or
8462 					    (p_line_adj_assoc_Tbl(j1).Price_adjustment_id =
8463 						  p_Line_Adj_Tbl(j).Price_Adjustment_id and
8464 						  p_Line_Adj_Tbl(j).Price_Adjustment_id <> fnd_api.g_miss_num )) And (nvl(p_line_adj_assoc_Tbl(j1).operation,'xxyz') <>  OE_GLOBALS.G_OPR_DELETE)
8465 
8466 					)  Then
8467 
8468 				adj_debug('Got an association Rltd_index '||p_line_adj_assoc_Tbl(j1).Rltd_Adj_index,2);
8469                                 adj_debug('line_adj_assoc_operation:'||p_line_adj_assoc_Tbl(j1).operation);
8470 				-- Get the Related Adj Line
8471 				J2 := p_Line_Adj_Tbl.First;
8472 
8473 				G_STMT_NO := 'Calculate_Price#40';
8474 				  While J2 is not null loop
8475 				  	If ( p_line_adj_assoc_Tbl(j1).Rltd_Adj_index = J2 Or
8476 					  	     ( p_line_adj_assoc_Tbl(j1).Rltd_Price_Adj_Id =
8477 							p_Line_Adj_Tbl(j2).Price_adjustment_id  and
8478 							p_line_adj_assoc_Tbl(j1).Rltd_Price_Adj_Id <> fnd_api.g_miss_num )
8479 							) and
8480 							p_Line_Adj_Tbl(j2).Range_Break_Quantity > 0 and
8481 							p_Line_Adj_Tbl(j2).list_line_type_code in ('DIS','SUR','FREIGHT_CHARGE')
8482 					Then
8483 
8484 						adj_debug(j2||')The Child line is '||p_Line_Adj_Tbl(j2).list_line_type_code,2);
8485 						adj_debug('List line id '||p_Line_Adj_Tbl(j2).list_line_id,2);
8486 						adj_debug('Pricing Qty #150 '||p_Line_Tbl(i).pricing_quantity,2);
8487 						adj_debug('Range Break Qty #151 '||p_Line_adj_Tbl(j2).range_break_quantity,2);
8488 
8489 						If p_Line_Adj_Tbl(j2).list_line_type_code in ('DIS','SUR') Then
8490 							l_discount_surcharge := TRUE;
8491 						Else
8492 							l_discount_surcharge := FALSE;
8493 						End If;
8494 						If p_Line_Adj_Tbl(j2).list_line_type_code = 'DIS'
8495 						   AND p_Line_Adj_Tbl(j2).arithmetic_operator <> 'NEWPRICE' Then
8496 							l_sign	:= -1;
8497 						Else
8498 							l_sign    := +1;
8499 						End If;
8500 
8501                                             IF p_Line_Adj_Tbl(j2).updated_flag = 'Y' and p_Line_Adj_Tbl(j).updated_flag <> 'Y' THEN
8502                                                 p_Line_Adj_Tbl(j).updated_flag := 'Y';
8503                                                 p_Line_Adj_Tbl(j).change_reason_code := p_Line_Adj_Tbl(J2).change_reason_code;
8504                                                 p_Line_Adj_Tbl(j).change_reason_text := p_Line_Adj_Tbl(J2).change_reason_text;
8505 
8506                                             END IF;
8507 
8508 					    G_STMT_NO := 'Calculate_Price#50';
8509 
8510 						If p_Line_Adj_Tbl(j).Price_break_Type_Code = QP_PREQ_GRP.G_RANGE_BREAK Then
8511 						 l_pricing_quantity := p_line_adj_tbl(j2).Range_Break_Quantity;
8512 
8513 					     Else
8514 						 l_pricing_quantity := p_line_tbl(i).pricing_quantity;
8515 					     End If;
8516 
8517 If p_Line_Adj_Tbl(j2).Operand_per_pqty is Null Then
8518    p_Line_Adj_Tbl(j2).Operand_per_pqty := p_Line_Adj_Tbl(j2).Operand;
8519 End If;
8520 
8521                             /* Added for the bug#2647485 */
8522                             IF (
8523                               --p_line_adj_tbl(j).list_line_type_code <> 'FREIGHT_CHARGE' AND ** Commented for bug#3594917 **
8524                                 p_line_tbl(i).calculate_price_flag = 'P' AND
8525                                 p_line_tbl(i).line_category_code = 'RETURN' AND
8526                                 p_Line_Adj_Tbl(j2).Arithmetic_operator = 'LUMPSUM' ) THEN
8527                             	NULL;
8528                             ELSE
8529                                --For bug 2874499.
8530                                If (p_Line_Adj_Tbl(j2).Arithmetic_operator = 'LUMPSUM'
8531                                   and p_line_adj_tbl(j2).modifier_level_code = QP_PREQ_GRP.G_LINE_GROUP and
8532                                   p_line_adj_tbl(j2).automatic_flag = 'N')then
8533                                       p_line_adj_tbl(j2).group_value := 1;
8534                                end if ;
8535 					  CAlculate_Adjusted_Price(
8536 							p_bucketed_price=> l_bucketed_price,
8537                                                         p_line_category=> p_line_tbl(i).line_category_code,
8538 							p_arithmetic_operator=> p_Line_Adj_Tbl(j2).Arithmetic_operator,
8539 							p_operand	=> l_sign*p_Line_Adj_Tbl(j2).Operand_per_pqty,
8540 							p_Pricing_Quantity=> l_pricing_quantity,
8541 							p_rounding_Factor=> l_rounding_FActor,
8542                                    p_modifier_level_code => p_line_adj_tbl(j2).modifier_level_code,
8543                                    p_group_value         => p_line_adj_tbl(j2).group_value,
8544 							x_Adjusted_Amount=> p_Line_Adj_Tbl(j2).Adjusted_Amount_Per_Pqty
8545 							);
8546                             END IF;
8547 
8548 					    G_STMT_NO := 'Calculate_Price#60';
8549 						If p_Line_Adj_Tbl(j).Price_break_Type_Code = QP_PREQ_GRP.G_RANGE_BREAK Then
8550 							 If nvl(p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty,FND_API.G_MISS_NUM)=FND_API.G_MISS_NUM Then
8551                                                             p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty:=0;
8552                                                        End If;
8553 
8554 							p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty	:=
8555 								p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty +
8556 									p_Line_Adj_Tbl(j2).Adjusted_Amount_Per_Pqty * p_Line_Adj_Tbl(j2).Range_break_Quantity;
8557                                                         l_adjusted_amt_changed := TRUE;
8558 							l_total_Quantity := l_total_Quantity + p_Line_Adj_Tbl(j2).Range_break_Quantity;
8559 
8560                          oe_debug_pub.add(' Rounding adj list line ty:'|| p_Line_Adj_Tbl(j).list_line_type_code);
8561                          oe_debug_pub.add(' Rounding adj list line id:'||p_Line_Adj_Tbl(j).list_line_id);
8562                          oe_debug_pub.add(' Rounding adj operand:'||p_Line_Adj_Tbl(j).operand);
8563 
8564 						Else
8565 							p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty := p_Line_Adj_Tbl(j2).Adjusted_Amount_Per_Pqty;
8566                                                         l_adjusted_amt_changed := TRUE;
8567 						End If; -- Break Type
8568 
8569 					adj_debug('Adj Amount '||p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty,2);
8570 
8571 				  	End If; -- Rltd Lines ( Child lines for PBH )
8572 
8573 				     J2:= p_Line_Adj_Tbl.Next(J2);
8574 
8575 				  End Loop; -- J2
8576 
8577 			 	End If; -- J1 if
8578 			 	J1 := p_line_adj_assoc_Tbl.Next(J1);
8579 		       End loop; -- J1
8580 
8581    If  p_Line_Adj_Tbl(j).Price_Break_Type_Code = QP_PREQ_GRP.G_RANGE_BREAK Then
8582 oe_debug_pub.add('xAdj_amt_pqty:'||p_line_adj_tbl(j).adjusted_amount_per_pqty);
8583    if p_line_adj_tbl(j).range_break_quantity is null and l_total_quantity > 0
8584    then --bug 2813670
8585     oe_debug_pub.add('Value of l_tot_qty :'||l_total_quantity);
8586     p_line_adj_tbl(j).adjusted_amount_per_pqty :=
8587     p_line_adj_tbl(j).adjusted_amount_per_pqty/l_total_quantity;
8588    else
8589     p_line_adj_tbl(j).adjusted_amount_per_pqty :=
8590     p_line_adj_tbl(j).adjusted_amount_per_pqty/p_line_adj_tbl(j).range_break_quantity;
8591    end if;
8592 oe_debug_pub.add('xRange break qty:'||p_line_adj_tbl(j).range_break_quantity);
8593 
8594 oe_debug_pub.add('xFinal Range break adj amt:'||p_line_adj_tbl(j).adjusted_amount_per_pqty);
8595    End If;
8596 
8597                         If p_Line_Adj_Tbl(j).operand is not null Then
8598                            QP_UTIL_PUB.round_price
8599                               (p_operand                => p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,
8600 			       p_rounding_factor        => NULL,
8601 			       p_use_multi_currency     => 'Y',
8602 			       p_price_list_id          => p_line_tbl(i).price_list_id,
8603 			       p_currency_code          => g_order_currency,
8604 			       p_pricing_effective_date => p_line_tbl(i).pricing_date,
8605 			       x_rounded_operand        => p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,
8606 			       x_status_code            => l_status_code,
8607                                p_operand_type           => 'A'
8608                                );
8609                          Else
8610                              p_Line_Adj_Tbl(j).adjusted_amount_per_pqty:=nvl(p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,0);
8611                              p_Line_Adj_Tbl(j).operand:=0;
8612                          End if;
8613 
8614 
8615 		     Else -- Not a Price Break Line
8616 
8617 			  G_STMT_NO := 'Calculate_Price#80';
8618 				If p_Line_Adj_Tbl(j).list_line_type_code in ('DIS','SUR') Then
8619 					l_discount_surcharge := TRUE;
8620 				Else
8621 					l_discount_surcharge := FALSE;
8622 				End If;
8623 				If p_Line_Adj_Tbl(j).list_line_type_code = 'DIS'
8624 				   AND p_Line_Adj_Tbl(j).arithmetic_operator <> 'NEWPRICE' Then
8625 					l_sign	:= -1;
8626 				Else
8627 					l_sign    := +1;
8628 				End If;
8629 
8630 			     G_STMT_NO := 'Calculate_Price#90';
8631 
8632 				adj_debug(j||')Line Index '||p_Line_Adj_Tbl(j).line_index,3);
8633 				adj_debug('Operand '||p_Line_Adj_Tbl(j).operand_per_pqty,3);
8634 				adj_debug('Arithmetic op '||p_Line_Adj_Tbl(j).Arithmetic_operator,3);
8635 				adj_debug('Pricing Quantity '||p_line_tbl(i).Pricing_Quantity,3);
8636 				adj_debug('Bucketed price '||l_bucketed_price,3);
8637 				adj_debug('-----------------',3);
8638 
8639                             /* Added for the bug#2647485 */
8640                             IF (
8641                               --p_line_adj_tbl(j).list_line_type_code <> 'FREIGHT_CHARGE' AND ** Commented for bug#3594917 **
8642                                 p_line_tbl(i).calculate_price_flag = 'P' AND
8643                                 p_line_tbl(i).line_category_code = 'RETURN' AND
8644                                 p_Line_Adj_Tbl(j).Arithmetic_operator = 'LUMPSUM' ) THEN
8645 
8646                                 p_Line_Adj_Tbl(j).operand := p_line_tbl(i).Ordered_Quantity
8647                                                            * p_Line_Adj_Tbl(j).Adjusted_Amount
8648                                                            * l_sign;
8649                                 p_Line_Adj_Tbl(j).operand_per_pqty := NULL;
8650 
8651                             ELSE
8652                                --For bug 2874499.
8653                                If (p_Line_Adj_Tbl(j).Arithmetic_operator = 'LUMPSUM'
8654                                   and p_line_adj_tbl(j).modifier_level_code = QP_PREQ_GRP.G_LINE_GROUP and
8655                                   p_line_adj_tbl(j).automatic_flag = 'N')then
8656                                       p_line_adj_tbl(j).group_value := 1;
8657                                end if ;
8658 
8659 				CAlculate_Adjusted_Price(
8660 					p_bucketed_price   			=> l_bucketed_price,
8661                                         p_line_category=> p_line_tbl(i).line_category_code,
8662 					p_arithmetic_operator		=> p_Line_Adj_Tbl(j).Arithmetic_operator,
8663 					p_operand					=>  l_sign*p_Line_Adj_Tbl(j).Operand_per_pqty,
8664 					p_Pricing_Quantity			=>  p_line_tbl(i).pricing_quantity,
8665 					p_rounding_Factor			=>  l_rounding_FActor,
8666 					p_modifier_level_code         => p_line_adj_tbl(j).modifier_level_code,
8667 					p_group_value                 => p_line_adj_tbl(j).group_value,
8668                                         --p_price_list_id               => p_line_tbl(i).price_list_id,
8669                                         --p_pricing_effecitve_date      => p_line_tbl(i).pricing_date,
8670 					x_Adjusted_Amount			=>  p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty
8671 					);
8672                             END IF;
8673                                 l_adjusted_amt_changed := TRUE;
8674 
8675 				adj_debug('+Adjusted_Amount pqty '||p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty,2);
8676                                 adj_debug('+Adjusted_Amount '||p_Line_Adj_Tbl(j).Adjusted_Amount,2);
8677 
8678                        If p_Line_Adj_Tbl(j).operand is not null Then
8679                    --commenting call to round price to fix bug 3043251
8680                          /* QP_UTIL_PUB.round_price
8681                               (p_operand                => p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,
8682 			       p_rounding_factor        => NULL,
8683 			       p_use_multi_currency     => 'Y',
8684 			       p_price_list_id          => p_line_tbl(i).price_list_id,
8685 			       p_currency_code          => g_order_currency,
8686 			       p_pricing_effective_date => p_line_tbl(i).pricing_date,
8687 			       x_rounded_operand        => p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,
8688 			       x_status_code            => l_status_code,
8689                                p_operand_type           => 'A'
8690                                ); */
8691                           NULL;
8692                          Else
8693                              p_Line_Adj_Tbl(j).adjusted_amount_per_pqty:=nvl(p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,0);
8694                              p_Line_Adj_Tbl(j).operand:=0;
8695                          End if;
8696 
8697 		     End If; -- Check list line type for price break
8698 
8699 			     G_STMT_NO := 'Calculate_Price#100';
8700 			If l_discount_surcharge and nvl(p_Line_Adj_Tbl(j).Accrual_Flag,'N') <> 'Y'
8701 			then -- Do not Add Freight charges to the selling price
8702 			 adj_debug('Adjusted Amount : ' || nvl(p_line_adj_tbl(j).adjusted_amount_per_pqty,0),3);
8703 			 adj_debug('Unit Selling Price #100 : ' || nvl(p_line_tbl(i).Unit_Selling_Price_Per_Pqty,0),3);
8704 				p_line_tbl(i).Unit_Selling_Price_Per_Pqty := p_line_tbl(i).Unit_Selling_Price_Per_Pqty + nvl(p_Line_Adj_Tbl(j).Adjusted_Amount_Per_Pqty,0);
8705 			End If;
8706 
8707 		  	l_pricing_group_sequence := p_Line_Adj_Tbl(j).pricing_group_sequence;
8708 		  End If; -- Adj Lines
8709                   If (l_adjusted_amt_changed AND p_Line_Adj_Tbl(j).operation = FND_API.G_MISS_CHAR) Then
8710 
8711                     If not (p_any_line_frozen and p_line_adj_tbl(j).modifier_level_code = 'ORDER') Then
8712                     adj_debug('Calculate Price:'||p_Line_Adj_Tbl(j).list_line_id);
8713                       If p_Line_Adj_Tbl(j).updated_flag = 'N' Then
8714                         p_Line_Adj_Tbl(j).operation := OE_GLOBALS.G_OPR_UPDATE;
8715                       End If;
8716                     End If;
8717                   End If;
8718 		  l_Sort_Index:= l_Sorted_Adjustment_Tbl.Next(l_Sort_Index);
8719 
8720                   -- uom begin
8721                   If p_line_adj_tbl(j).arithmetic_operator IN ('AMT','NEWPRICE') Then
8722                   --bsadri fixed zero division error for cancelled lines
8723                     IF NVL(p_line_tbl(i).ordered_quantity,0) <> 0 AND
8724                      p_line_tbl(i).ordered_quantity <> fnd_api.g_miss_num THEN
8725                       p_Line_Adj_Tbl(j).operand := p_Line_Adj_tbl(j).operand_per_pqty * p_line_tbl(i).pricing_quantity/p_line_tbl(i).ordered_quantity;
8726                     END IF;
8727 
8728                     -- OPM 2547940  start - if pricing by quantity2 then if line is shipped and has shipped qty2 != ordered qty2
8729 --  need to adjust the operand so that invoicing will show correct amount (ordered qty * USP (adjusted) )
8730  		    IF oe_line_util.dual_uom_control  -- INVCONV
8731                    -- Process_Characteristics  invconv
8732               		(p_line_tbl(i).inventory_item_id
8733               		,p_line_tbl(i).ship_from_org_id
8734               		,l_item_rec) THEN
8735                    		oe_debug_pub.add('OPM - this IS a process line in proc calculate_price in OEXVADJB.pls ');
8736                         	IF l_item_rec.ont_pricing_qty_source = 'S'  THEN -- price by quantity 2 INVCONV
8737 
8738    				  	IF (p_line_tbl(i).ordered_quantity2 IS NOT NULL and p_line_tbl(i).ordered_quantity2 <> 0	)
8739                         		AND ( p_line_tbl(i).shipped_quantity2 IS NOT NULL and p_line_tbl(i).shipped_quantity2 <> 0	)
8740                         		AND  (p_line_tbl(i).ordered_quantity2 <> p_line_tbl(i).shipped_quantity2)   THEN
8741                         		 oe_debug_pub.add('OPM Updating operand ' ,5);
8742                        		     p_Line_Adj_Tbl(j).operand := (p_Line_Adj_tbl(j).operand_per_pqty* p_line_tbl(i).pricing_quantity )/p_line_tbl(i).ordered_quantity2
8743                        		      * (p_line_tbl(i).shipped_quantity2/p_line_tbl(i).ordered_quantity);
8744                        		      oe_debug_pub.ADD('OPM NEW operand : '|| to_char(p_Line_Adj_Tbl(j).operand),5);
8745                				 END IF;
8746                			END IF;
8747 		    END IF;  --oe_line_util.dual_uom_control  -- INVCONV
8748 	-- OPM 2547940 end
8749 
8750 
8751                   Else
8752                     --for the % discount and lumpsum there is no difference
8753                     p_line_adj_tbl(j).operand :=  p_Line_Adj_tbl(j).operand_per_pqty;
8754                   End If;
8755 
8756                   IF NVL(p_line_tbl(i).ordered_quantity,0) <> 0 AND
8757                      p_line_tbl(i).ordered_quantity <> FND_API.G_MISS_NUM THEN
8758 
8759                       IF (    p_line_adj_tbl(j).modifier_level_code = 'ORDER'
8760                           and p_line_adj_tbl(j).list_line_type_code = 'FREIGHT_CHARGE'
8761                           and p_line_adj_tbl(j).arithmetic_operator = 'LUMPSUM') THEN    /* bug 1915846 */
8762 
8763                         p_line_adj_tbl(j).adjusted_amount := p_line_adj_tbl(j).adjusted_amount_per_pqty;
8764 
8765                       ELSE   /* bug 1915846 */
8766                        If  p_Line_Adj_Tbl(j).line_id =  p_line_tbl(i).line_id Then
8767                         p_Line_Adj_Tbl(j).adjusted_amount := p_Line_Adj_tbl(j).adjusted_amount_per_pqty * p_line_tbl(i).pricing_quantity/p_line_tbl(i).ordered_quantity;
8768 
8769                       -- OPM 2547940  start - if pricing by quantity2 then if line is shipped and has shipped qty2 != ordered qty2
8770      --  need to adjust the adjusted_amount so that invoicing will show correct amount (ordered qty * USP (adjusted) )
8771 
8772                         IF oe_line_util.dual_uom_control  -- INVCONV  PROCESS_CHAR
8773 
8774               		(p_line_tbl(i).inventory_item_id
8775               		,p_line_tbl(i).ship_from_org_id
8776               		,l_item_rec) THEN
8777                    		IF l_item_rec.ont_pricing_qty_source = 'S'   THEN -- price by quantity 2 -- INVCONV
8778 
8779    				  	IF (p_line_tbl(i).ordered_quantity2 IS NOT NULL and p_line_tbl(i).ordered_quantity2 <> 0	)
8780                         		AND ( p_line_tbl(i).shipped_quantity2 IS NOT NULL and p_line_tbl(i).shipped_quantity2 <> 0	)
8781                         		 AND p_line_tbl(i).ordered_quantity2 <> p_line_tbl(i).shipped_quantity2 THEN
8782 			                   oe_debug_pub.add('OPM Updating adjusted amount ' ,5);
8783                        		     p_Line_Adj_Tbl(j).adjusted_amount := (p_Line_Adj_tbl(j).adjusted_amount_per_pqty* p_line_tbl(i).pricing_quantity )/p_line_tbl(i).ordered_quantity2
8784                        		      * (p_line_tbl(i).shipped_quantity2/p_line_tbl(i).ordered_quantity);
8785                        		   	END IF;
8786                			END IF;
8787 		        END IF;  --oe_line_util.dual_uom_control -- INVCONV
8788     -- OPM 2547940 end
8789 
8790 
8791                         If G_DEBUG Then
8792                          oe_debug_pub.add(' p_line_tbl(i).line_id:'||i||' '||p_line_tbl(i).line_id);
8793                          oe_debug_pub.add(' p_line_tbl(i).pricing_quantity:'||i||': '||p_line_tbl(i).pricing_quantity);
8794                          oe_debug_pub.add(' p_line_tbl(i).ordered_quantity:'||i||': '||p_line_tbl(i).ordered_quantity);
8795                          oe_debug_pub.add(' p_Line_Adj_Tbl(j).adjusted_amount:'||j||': '|| p_Line_Adj_Tbl(j).adjusted_amount);
8796                          oe_debug_pub.add(' p_line_adj_tbl(j).list_line_id:'||j||': '||p_line_adj_tbl(j).list_line_id);
8797                          oe_debug_pub.add(' p_line_adj_tbl(j).adjusted_amount_per_pqty:'||p_line_adj_tbl(j).adjusted_amount_per_pqty);
8798                         End If;
8799                        End If;
8800 
8801                       END IF;
8802 
8803 
8804                   END IF;
8805                   -- uom end
8806                        IF nvl(p_line_adj_tbl(j).adjusted_amount_per_pqty,0) <> 0 Then
8807                               QP_UTIL_PUB.round_price
8808                               (p_operand                => p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,
8809 			       p_rounding_factor        => NULL,
8810 			       p_use_multi_currency     => 'Y',
8811 			       p_price_list_id          => p_line_tbl(i).price_list_id,
8812 			       p_currency_code          => g_order_currency,
8813 			       p_pricing_effective_date => p_line_tbl(i).pricing_date,
8814 			       x_rounded_operand        => p_Line_Adj_Tbl(j).adjusted_amount_per_pqty,
8815 			       x_status_code            => l_status_code,
8816                                p_operand_type           => 'A'
8817                                );
8818 
8819                         END If;
8820 
8821                         IF nvl(p_line_adj_tbl(j).adjusted_amount,0) <> 0 Then
8822                               QP_UTIL_PUB.round_price
8823                               (p_operand                => p_Line_Adj_Tbl(j).adjusted_amount,
8824 			       p_rounding_factor        => NULL,
8825 			       p_use_multi_currency     => 'Y',
8826 			       p_price_list_id          => p_line_tbl(i).price_list_id,
8827 			       p_currency_code          => g_order_currency,
8828 			       p_pricing_effective_date => p_line_tbl(i).pricing_date,
8829 			       x_rounded_operand        => p_Line_Adj_Tbl(j).adjusted_amount,
8830 			       x_status_code            => l_status_code,
8831                                p_operand_type           => 'A'
8832                                );
8833 
8834                         END If;
8835 
8836 		End Loop; -- Adj Lines
8837 
8838 		G_STMT_NO := 'Calculate_Price#200';
8839 		-- Do GSA Check
8840 
8841 		If l_gsa_enabled_flag = 'Y' Then
8842 	-- for bug 1717501 begin
8843         --Added condition to check item type code for bug 2693025
8844           l_gsa_cust_check := oe_gsa_util.check_gsa_indicator(p_line_tbl(i));
8845 	     if l_gsa_cust_check = 'N'
8846              and p_line_tbl(i).item_type_code not in ('INCLUDED','CONFIG')
8847              then
8848 		Gsa_Check(
8849                 p_header_id             => p_line_tbl(i).header_id
8850 		,p_line_id		=> p_line_tbl(i).line_id
8851 		,p_inventory_item_id 	=> to_char(p_line_tbl(i).inventory_item_id) --bug 2673506
8852 		,p_pricing_date		=> p_line_tbl(i).pricing_date
8853 		,p_request_type_code	=> p_request_type_code
8854 ,p_unit_selling_price_per_pqty	=> p_line_tbl(i).unit_selling_price_per_pqty
8855 		,p_gsa_violation_action	=> l_gsa_violation_action
8856                 ,p_price_event1 => p_price_event       --bug 2273446
8857 			);
8858 		 end if;
8859 		End If;
8860 
8861 		-- DO Negative price Check
8862 
8863 		If   p_line_tbl(i).unit_selling_price_per_pqty < 0 And
8864 			p_allow_negative_price = 'N' then
8865 
8866 		 	adj_debug('Negative list price '||p_line_tbl(i).unit_List_price_per_pqty ||
8867 						'Or selling price '||p_line_tbl(i).Unit_Selling_price_per_pqty);
8868 		 	FND_MESSAGE.SET_NAME('ONT','ONT_NEGATIVE_PRICE');
8869 		 	FND_MESSAGE.SET_TOKEN('ITEM',p_line_tbl(i).Ordered_Item);
8870 		 	FND_MESSAGE.SET_TOKEN('LIST_PRICE',p_line_tbl(i).unit_List_price_per_pqty);
8871 		 	FND_MESSAGE.SET_TOKEN('SELLING_PRICE',p_line_tbl(i).Unit_Selling_price_per_pqty);
8872 		  	OE_MSG_PUB.Add;
8873                         FND_MESSAGE.SET_NAME('ONT','ONT_NEGATIVE_MODIFIERS');
8874                         FND_MESSAGE.SET_TOKEN('LIST_LINE_NO',get_list_lines(p_line_tbl(i).line_id));
8875                         OE_MSG_PUB.ADD;
8876 
8877 		 	RAISE FND_API.G_EXC_ERROR;
8878 
8879 		End If; -- Negative Price
8880 
8881 	 End If ; -- Of lines.operation in update or create
8882 	   adj_debug('selling price after ..'||p_Line_Tbl(i).Unit_Selling_Price_Per_Pqty);
8883        End If;  --calculate price flag in ('Y','P');
8884       I := p_Line_Tbl.Next(I);
8885     End Loop; -- Lines
8886 
8887 	adj_debug('Exiting oe_order_Adj_pvt.Calculate_Price');
8888 
8889 End Calculate_Price;
8890 
8891 Function	Get_unit_precision(p_header_id	number)
8892 return Number
8893 is
8894 l_currency_code 	varchar2(30) := 'USD';
8895 l_precision				Number;
8896 l_ext_precision			number;
8897 l_min_acct_unit				number;
8898 begin
8899 	begin
8900 		select nvl(transactional_curr_code,'USD') into l_currency_code from oe_order_headers
8901 		where header_id=p_header_id;
8902 		exception when no_data_found then
8903 		l_currency_code := 'USD';
8904 	end ;
8905 
8906      FND_CURRENCY.Get_Info(l_currency_code,  -- IN variable
8907 		l_precision,
8908 		l_ext_precision,
8909 		l_min_acct_unit);
8910 
8911 	if fnd_profile.value('OE_UNIT_PRICE_PRECISION_TYPE') = 'STANDARD' then
8912 		return l_precision;
8913 	else
8914 		return l_ext_precision;
8915 	end if;
8916 
8917 end Get_unit_precision;
8918 
8919 
8920 /* Bug 1503357
8921    Order no longer qualifies for PRG modifier.  Either delete (or) update
8922    the free goods lines, depending on whether they are shipped or not
8923 */
8924 PROCEDURE change_prg_lines(p_price_adjustment_id IN NUMBER,
8925 			   p_line_tbl            IN OUT NoCopy  OE_Order_PUB.Line_Tbl_Type,
8926 			   p_line_adj_tbl        IN OUT NoCopy  OE_Order_PUB.Line_Adj_Tbl_Type,
8927 			   p_delete_prg_lines    IN OUT NoCopy  index_tbl_type) IS
8928 
8929  Cursor prg_lines is
8930   Select radj.line_id
8931   from oe_price_adjustments radj,
8932   oe_price_adj_assocs assoc
8933   where radj.price_adjustment_id =assoc.rltd_price_adj_id and
8934   assoc.price_adjustment_id = p_price_adjustment_id;
8935 
8936  Cursor ph_ids IS
8937   Select pricing_phase_id
8938   from qp_event_phases
8939   where pricing_event_code like 'BOOK';
8940 
8941  l_prg_line_id         NUMBER;
8942  l_found_prg_line      BOOLEAN;
8943  l_match_phase_id      BOOLEAN := FALSE;
8944  l_line_rec            OE_ORDER_PUB.line_rec_type;
8945  l_phase_id            NUMBER;
8946  pricing_ph_id         NUMBER;
8947  j 		       PLS_INTEGER;
8948  l_return_status       VARCHAR2(30);
8949  l_replaced	       BOOLEAN := FALSE;
8950  l_pricing_event       varchar2(30);
8951 
8952 Begin
8953   adj_debug('Entering VADJB.CHANGE_PRG_LINES');
8954   adj_debug('price_adjustment_id = ' || p_price_adjustment_id);
8955   begin
8956    select pricing_phase_id
8957    into pricing_ph_id
8958    from oe_price_adjustments
8959    where price_adjustment_id = p_price_adjustment_id;
8960    exception when no_data_found Then
8961       adj_debug('No pricing phase id for this price adjustment');
8962       pricing_ph_id := NULL;
8963   end;
8964 
8965   --Determine if modifier is in Book phase
8966   if (pricing_ph_id is not NULL) Then
8967    OPEN ph_ids;
8968    FETCH ph_ids into l_phase_id;
8969     WHILE ph_ids%FOUND Loop
8970       if (l_phase_id = pricing_ph_id) Then
8971         l_match_phase_id := TRUE;
8972         exit;
8973       end if;
8974       FETCH ph_ids into l_phase_id;
8975     End Loop;
8976   End if;
8977   CLOSE ph_ids;
8978 
8979   OPEN prg_lines;
8980   FETCH prg_lines into l_prg_line_id;
8981   while prg_lines%FOUND Loop
8982      adj_debug('PRG Line id = ' || l_prg_line_id);
8983 
8984      IF (l_prg_line_id is not NULL) THEN
8985        l_found_prg_line := FALSE;
8986        j := p_line_tbl.first;
8987        while j is not null Loop
8988           if (p_line_tbl(j).line_id = l_prg_line_id) Then
8989 	    adj_debug('found prg line '||l_prg_line_id);
8990             l_line_rec := p_line_tbl(j);
8991 	    l_found_prg_line := TRUE;
8992 	    exit;
8993 	  end if;
8994           j := p_line_tbl.next(j);
8995        End Loop;
8996      END IF;
8997 
8998      IF NOT l_found_prg_line then
8999        adj_debug('PRG not in p_line_tbl, so query for line '||l_prg_line_id);
9000        OE_Line_Util.Query_Row(p_Line_id   => l_prg_line_id,
9001                               x_line_rec  => l_line_rec);
9002      END IF;
9003 
9004      if (l_line_rec.booked_flag <> 'Y' OR
9005 	 l_line_rec.booked_flag is NULL) Then
9006        adj_debug('Order not booked');
9007        l_line_rec.operation := OE_GLOBALS.G_OPR_DELETE;
9008        p_delete_prg_lines(l_line_rec.line_id) := l_line_rec.line_id;
9009      else
9010        l_line_rec.change_reason := 'SYSTEM';
9011        l_line_rec.change_comments := 'REPRICING';
9012        if (l_line_rec.shipped_quantity is NULL) Then
9013 	 adj_debug('Booked order, line not shipped');
9014 	 l_line_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
9015   	 l_line_rec.ordered_quantity := 0;
9016 	 l_line_rec.pricing_quantity := 0;
9017           p_delete_prg_lines(l_line_rec.line_id) := l_line_rec.line_id;
9018        else
9019 	 adj_debug('Booked order, shipped line');
9020 	 l_line_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
9021 	 l_line_rec.calculate_price_flag := 'Y';
9022        adj_debug('logging delayed request to price line');
9023          l_pricing_event := 'BATCH'; --2442012
9024  /*      OE_delayed_requests_Pvt.log_request(
9025 		p_entity_code 		=> OE_GLOBALS.G_ENTITY_ALL,
9026 		p_entity_id         	=> l_line_rec.line_id,
9027 		p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
9028 		p_requesting_entity_id   => l_line_rec.line_id,
9029 		p_request_unique_key1  	=> 'BATCH',
9030 		p_param1                 => l_line_rec.header_id,
9031                 p_param2                 => 'BATCH',
9032 		p_request_type           => OE_GLOBALS.G_PRICE_LINE,
9033 		x_return_status          => l_return_status);
9034  */
9035 	if (l_match_phase_id) Then
9036 	  -- modifier in BOOK phase
9037              l_pricing_event := 'BATCH,BOOK';
9038         end if;
9039 	  OE_delayed_requests_Pvt.log_request(
9040                 p_entity_code           =>OE_GLOBALS.G_ENTITY_ALL,
9041                 p_entity_id             => l_line_rec.line_Id,
9042                 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
9043                 p_requesting_entity_id   => l_line_rec.line_Id,
9044                 p_request_unique_key1   => l_pricing_event,
9045                 p_param1                 => l_line_rec.header_id,
9046                 p_param2                 => l_pricing_event,
9047                 p_request_type           => OE_GLOBALS.G_PRICE_LINE,
9048                 x_return_status          => l_return_status);
9049    --2442012     end if;
9050        end if;
9051       end if;
9052 
9053       -- Now replace/append this record in p_line_tbl
9054       if (l_found_prg_line) Then
9055 	adj_debug('Replacing line in p_line_tbl ' || l_line_rec.line_id);
9056 	p_line_tbl(j) := l_line_rec;
9057       else
9058         adj_debug('Appended to p_line_tbl ' || l_line_rec.line_id);
9059         p_line_tbl(p_line_tbl.last+1) := l_line_rec;
9060       end if;
9061 
9062       FETCH prg_lines into l_prg_line_id;
9063   End Loop;
9064 
9065   CLOSE prg_lines;
9066   adj_debug('Exiting VADJB.CHANGE_PRG_LINES');
9067 
9068 End change_prg_lines;
9069 
9070 
9071 
9072 procedure process_adjustments
9073 (
9074 p_request_type_code				varchar2,
9075 x_return_status out nocopy Varchar2,
9076 
9077 p_Req_Control_Rec			   QP_PREQ_GRP.Control_record_type,
9078 p_req_line_tbl                   QP_PREQ_GRP.line_tbl_type,
9079 p_Req_qual_tbl                   QP_PREQ_GRP.qual_tbl_type,
9080 p_Req_line_attr_tbl              QP_PREQ_GRP.line_attr_tbl_type,
9081 p_Req_Line_Detail_tbl            QP_PREQ_GRP.line_detail_tbl_type,
9082 p_Req_Line_Detail_Qual_tbl       QP_PREQ_GRP.line_detail_qual_tbl_type,
9083 p_Req_Line_Detail_Attr_tbl       QP_PREQ_GRP.line_detail_attr_tbl_type,
9084 p_Req_related_lines_tbl          QP_PREQ_GRP.related_lines_tbl_type
9085 ,p_write_to_db					Boolean
9086 ,p_any_frozen_line              in              Boolean
9087 ,x_line_Tbl			in out nocopy     oe_Order_Pub.Line_Tbl_Type
9088 ,p_header_rec				   oe_Order_Pub.header_rec_type
9089 ,p_multiple_events  in Varchar2 Default 'N'
9090 ,p_honor_price_flag  in Varchar2 Default 'Y'   --bug 2503186
9091 )
9092 is
9093 l_Req_Line_Detail_qual_Rec      QP_PREQ_GRP.line_detail_qual_rec_type;
9094 l_Req_Line_Detail_attr_Rec       QP_PREQ_GRP.line_detail_attr_rec_type;
9095 l_req_line_rec				qp_preq_grp.line_rec_type;
9096 l_control_rec				Oe_Globals.Control_rec_type;
9097 l_header_rec				   oe_Order_Pub.header_rec_type := p_header_rec;
9098 --l_old_line_rec				oe_order_pub.line_rec_type;
9099 l_line_rec				oe_order_pub.line_rec_type;
9100 l_old_line_tbl                OE_Order_PUB.Line_Tbl_Type;
9101 l_line_tbl                    OE_Order_PUB.Line_Tbl_Type;
9102 l_line_tbl_Final              OE_Order_PUB.Line_Tbl_Type;
9103 l_Line_Adj_rec                OE_Order_PUB.Line_Adj_Rec_Type;
9104 l_Line_Adj_tbl                OE_Order_PUB.Line_Adj_Tbl_Type;
9105 l_Line_Adj_Att_Rec  		OE_Order_PUB.Line_Adj_Att_Rec_type;
9106 l_Line_Adj_Att_tbl  		OE_Order_PUB.Line_Adj_Att_tbl_type;
9107 l_Line_Adj_Assoc_Rec    		OE_Order_PUB.Line_Adj_Assoc_Rec_type;
9108 l_Line_Adj_Assoc_tbl    		OE_Order_PUB.Line_Adj_Assoc_tbl_type;
9109 --l_x_header_rec                OE_Order_PUB.Header_Rec_Type;
9110 l_x_Header_Adj_tbl            OE_Order_PUB.Header_Adj_Tbl_Type;
9111 l_x_Header_Scredit_tbl        OE_Order_PUB.Header_Scredit_Tbl_Type;
9112 --l_x_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
9113 --l_x_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
9114 l_x_Line_Scredit_tbl          OE_Order_PUB.Line_Scredit_Tbl_Type;
9115 l_x_action_request_tbl        OE_Order_PUB.request_tbl_type;
9116 l_x_lot_serial_tbl	      	OE_Order_PUB.lot_serial_tbl_type;
9117 l_x_Header_price_Att_tbl 	OE_Order_PUB.Header_price_Att_tbl_type;
9118 l_x_Header_Adj_Att_tbl 		OE_Order_PUB.Header_Adj_Att_tbl_type;
9119 l_x_Header_Adj_Assoc_tbl	    	OE_Order_PUB.Header_Adj_Assoc_tbl_type;
9120 l_x_Line_price_Att_tbl		OE_Order_PUB.Line_price_Att_tbl_type;
9121 --l_x_Line_Adj_Att_tbl  		OE_Order_PUB.Line_Adj_Att_tbl_type;
9122 --l_x_Line_Adj_Assoc_tbl    	OE_Order_PUB.Line_Adj_Assoc_tbl_type;
9123 l_x_msg_count                   number;
9124 l_x_msg_data                    Varchar2(2000);
9125 l_x_result_out                 Varchar2(30);
9126 l_line_details_prcd			Index_Tbl_Type;
9127 l_Rltd_lines_prcd			Index_Tbl_Type;
9128 l_Rltd_line_details_prcd		Index_Tbl_Type;
9129 l_lines_prcd				Index_Tbl_Type;
9130 l_index					pls_Integer;
9131 l_Adj_index				pls_Integer;
9132 l_assoc_index				pls_Integer;
9133 i						pls_Integer;
9134 j						pls_Integer;
9135 k						pls_Integer;
9136 l                                               pls_Integer;
9137 l_line_term				Boolean := FALSE;
9138 l_price_list				Varchar2(240);
9139 l_price_adjustment_id		number;
9140 l_allow_negative_price		Varchar2(30) := nvl(fnd_profile.value('ONT_NEGATIVE_PRICING'),'N');
9141 l_return_status			varchar2(30);
9142 l_index                         NUMBER;
9143 l_request_id                    NUMBER;
9144 --btea perf begin
9145 l_header_key_tbl key_tbl_type;
9146 l_line_key_tbl   key_tbl_type;
9147 --btea perf end
9148 l_updated_flag varchar2(1);
9149 -- Added by JAUTOMO on 20-DEC-00 (bug# 1303352)
9150 v_discounting_privilege VARCHAR2(30);
9151 -- Added by JAUTOMO on 10-APR-01
9152 l_item_type_code		VARCHAR2(30);
9153 v_order_enforce_list_price varchar2(1):=NULL;
9154 v_line_enforce_list_price varchar2(1);
9155 l_invalid_line Varchar2(1):= 'N';
9156 --Manual begin
9157 l_preinsert_manual_adj  VARCHAR2(1):= Nvl(Fnd_Profile.Value('ONT_PREINSERT_MANUAL_ADJ'),'N');
9158 --Manual end
9159 l_dummy_line_rec Oe_Order_Pub.Line_Rec_Type;
9160 l_limit_hold_action varchar2(30):=NVL(fnd_profile.value('ONT_PROMOTION_LIMIT_VIOLATION_ACTION'), 'NO_HOLD'); -- PROMOTIONS SEP/01
9161 
9162 /* Promotional modifier issues - Bug 1503357 */
9163 l_delete_prg_lines   index_tbl_type;
9164 l_num_changed_lines PLS_INTEGER := 0;
9165 
9166 l_status_code Varchar2(5);
9167 l_line_detail_replaced                        Index_Tbl_Type;
9168 
9169 l_item_rec                    OE_ORDER_CACHE.item_rec_type; -- OPM 2547940
9170 l_process			Boolean; -- OPM 2547940
9171 
9172 --
9173 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
9174 --
9175 l_order_source_id           NUMBER;
9176 l_orig_sys_document_ref     VARCHAR2(50);
9177 l_orig_sys_line_ref     VARCHAR2(50);
9178 l_orig_sys_shipment_ref     VARCHAR2(50);
9179 l_change_sequence           VARCHAR2(50);
9180 l_source_document_type_id   NUMBER;
9181 l_source_document_id        NUMBER;
9182 l_source_document_line_id        NUMBER;
9183 
9184 rec_cnt NUMBER := 0;
9185 --serla begin
9186 l_x_Header_Payment_tbl        OE_Order_PUB.Header_Payment_Tbl_Type;
9187 l_x_Line_Payment_tbl          OE_Order_PUB.Line_Payment_Tbl_Type;
9188 --serla end
9189 begin
9190 
9191 x_return_status :=  FND_API.G_RET_STS_SUCCESS;
9192 adj_debug('Entering oe_order_Adj_pvt.process_adjustments',1);
9193 G_STMT_NO := 'process_adjustments#10';
9194 
9195 i:=  p_req_line_tbl.first;
9196 While I is not null Loop
9197 
9198       If x_Line_Tbl.count = 0 Then
9199       Begin
9200 
9201          OE_Line_Util.Query_Row
9202 	 (   p_Line_id             => p_req_line_tbl(i).line_id
9203          ,   x_line_rec            => l_line_rec);
9204 	Exception when no_data_found then
9205         null;
9206 	adj_debug('process_adjustments OE_Line_Util.Query_Row , no data found');
9207       End;
9208 	 Else
9209 		J:= x_Line_Tbl.First;
9210 		While J is not null loop
9211 			If x_Line_Tbl(j).line_id = p_req_line_tbl(i).line_id or
9212 				J = p_req_line_tbl(i).line_index then
9213 					l_line_rec := x_Line_Tbl(J);
9214 					exit;
9215 			End if;
9216 			J:= x_Line_Tbl.next(j);
9217 		end loop;
9218 	End If;
9219 	adj_debug('The status code '||p_req_line_tbl(i).status_code);
9220         l_invalid_line := 'N';
9221 	if p_req_line_tbl(i).line_Type_code ='LINE' and
9222   	  p_req_line_tbl(i).status_code in ( QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST,
9223 				QP_PREQ_GRP.G_STS_LHS_NOT_FOUND,
9224 				QP_PREQ_GRP.G_STATUS_FORMULA_ERROR,
9225 				QP_PREQ_GRP.G_STATUS_OTHER_ERRORS,
9226 				FND_API.G_RET_STS_UNEXP_ERROR,
9227 				FND_API.G_RET_STS_ERROR,
9228 				QP_PREQ_GRP.G_STATUS_CALC_ERROR,
9229 				QP_PREQ_GRP.G_STATUS_UOM_FAILURE,
9230 				QP_PREQ_GRP.G_STATUS_INVALID_UOM,
9231 				QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST,
9232 				QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV,
9233 				QP_PREQ_GRP.G_STATUS_INVALID_INCOMP,
9234 				QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR)
9235 	then
9236                    OE_MSG_PUB.set_msg_context
9237       			( p_entity_code                => 'LINE'
9238          		,p_entity_id                   => l_line_rec.line_id
9239          		,p_header_id                   => l_line_rec.header_id
9240          		,p_line_id                     => l_line_rec.line_id
9241                         ,p_order_source_id             => l_line_rec.order_source_id
9242                         ,p_orig_sys_document_ref       => l_line_rec.orig_sys_document_ref
9243                         ,p_orig_sys_document_line_ref  => l_line_rec.orig_sys_line_ref
9244                         ,p_orig_sys_shipment_ref       => l_line_rec.orig_sys_shipment_ref
9245                         ,p_change_sequence             => l_line_rec.change_sequence
9246                         ,p_source_document_type_id     => l_line_rec.source_document_type_id
9247                         ,p_source_document_id          => l_line_rec.source_document_id
9248                         ,p_source_document_line_id     => l_line_rec.source_document_line_id
9249          		);
9250 
9251                  l_invalid_line := 'Y';
9252 		 Begin
9253 			Select name into l_price_list
9254 			from qp_list_headers_vl where
9255 			list_header_id = l_line_rec.price_list_id;
9256 			Exception When No_data_found then
9257 			l_price_list := l_line_rec.price_list_id;
9258 		 End;
9259 
9260 		 If p_req_line_tbl(i).status_code  = QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST then
9261 		 	adj_debug('Invalid Item/Price List combination');
9262                         If not G_IPL_ERRORS_TBL.exists(MOD(l_line_rec.line_id, G_BINARY_LIMIT))                    -- Bug 8631297
9263                          or (G_IPL_ERRORS_TBL.exists(MOD(l_line_rec.line_id, G_BINARY_LIMIT))                      -- Bug 8631297
9264                              and
9265                              G_IPL_ERRORS_TBL(MOD(l_line_rec.line_id,G_BINARY_LIMIT))<>l_line_rec.price_list_id)   -- Bug 8631297
9266                         Then
9267 		 	  FND_MESSAGE.SET_NAME('ONT','OE_PRC_NO_LIST_PRICE');
9268 		 	  FND_MESSAGE.SET_TOKEN('ITEM',l_line_rec.Ordered_Item);
9269 		 	  FND_MESSAGE.SET_TOKEN('UNIT',l_line_rec.Order_Quantity_uom);
9270 		 	  FND_MESSAGE.SET_TOKEN('PRICE_LIST',l_Price_List);
9271 		  	  OE_MSG_PUB.Add;
9272                         End If;
9273 
9274                         G_IPL_ERRORS_TBL(MOD(l_line_rec.line_id,G_BINARY_LIMIT)):=l_line_rec.price_list_id;       -- Bug 8631297
9275                          oe_debug_pub.add('Before checking book flag');
9276                          oe_debug_pub.add('Invalid line flag:'||l_invalid_line);
9277 
9278                         If nvl(l_line_rec.booked_flag,'X') = 'Y' Then
9279                             oe_debug_pub.add(' Before setting message');
9280                             FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQD_LINE_ATTRIBUTE');
9281                             oe_debug_pub.add(' Before setting token');
9282                             FND_MESSAGE.SET_TOKEN('ATTRIBUTE','price list');
9283      	                    OE_MSG_PUB.ADD;
9284                             oe_debug_pub.add('Process adjustments before raising g_exc_error');
9285                             RAISE FND_API.G_EXC_ERROR;
9286                         End If;
9287 
9288                         --Fix bug 1650637
9289                         --If l_line_rec.unit_selling_price Is Not Null or
9290                         --l_line_rec.unit_list_price Is Not Null  Then
9291                         /*  Begin
9292                             Update Oe_Order_Lines
9293                             set    Unit_Selling_Price = Null,Unit_list_price = Null
9294                             where  line_id = l_line_rec.line_id;
9295 
9296                             oe_line_adj_util.delete_row(p_line_id => l_line_rec.line_id);
9297                             oe_debug_pub.add('  Updating unit price to null');
9298 
9299                             l_line_rec.unit_selling_price := NULL;
9300                             l_line_rec.unit_list_price:=NULL;
9301                             l_line_rec.unit_selling_price_per_pqty :=NULL;
9302                             l_line_rec.unit_list_price_per_pqty:=NULL;
9303                            Exception When Others Then
9304                             Oe_Debug_Pub.add('Oe_Order_Adj_Pvt:Failed to update price:'||SQLERRM);
9305                            End;*/
9306                         --End If;
9307 
9308                             l_line_rec.unit_selling_price := NULL;
9309                             l_line_rec.unit_list_price:=NULL;
9310                             l_line_rec.unit_selling_price_per_pqty :=NULL;
9311                             l_line_rec.unit_list_price_per_pqty:=NULL;
9312 
9313 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STS_LHS_NOT_FOUND Then
9314 		 	adj_debug('Price List Not found');
9315 		 	FND_MESSAGE.SET_NAME('ONT','ONT_NO_PRICE_LIST_FOUND');
9316 		 	FND_MESSAGE.SET_TOKEN('ITEM',l_line_rec.Ordered_Item);
9317 		 	FND_MESSAGE.SET_TOKEN('UOM',l_line_rec.Order_Quantity_uom);
9318 		  	OE_MSG_PUB.Add;
9319 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_FORMULA_ERROR then
9320 		 	adj_debug('Error in Formula processing');
9321 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRC_ERROR_IN_FORMULA');
9322 		 	FND_MESSAGE.SET_TOKEN('ERR_TEXT',p_req_line_tbl(i).status_text||SQLERRM);
9323 		  	OE_MSG_PUB.Add;
9324 		Elsif p_req_line_tbl(i).status_code in
9325 				( QP_PREQ_GRP.G_STATUS_OTHER_ERRORS , FND_API.G_RET_STS_UNEXP_ERROR,
9326 						FND_API.G_RET_STS_ERROR)
9327 		then
9328 		 	adj_debug('Other errors processing');
9329 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRICING_ERRORS'); --bug#7149497
9330 		 	FND_MESSAGE.SET_TOKEN('ERR_TEXT',p_req_line_tbl(i).status_text||SQLERRM);
9331 		  	OE_MSG_PUB.Add;
9332 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_INVALID_UOM then
9333 		 	adj_debug('Invalid uom');
9334 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRC_INVALID_UOM');
9335 		 	FND_MESSAGE.SET_TOKEN('ITEM',l_line_rec.Ordered_Item);
9336 		 	FND_MESSAGE.SET_TOKEN('UOM',l_line_rec.Order_Quantity_uom);
9337 		  	OE_MSG_PUB.Add;
9338 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST then
9339 		 	adj_debug('Duplicate price list');
9340 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRC_DUPLICATE_PRICE_LIST');
9341 
9342 		 	Begin
9343 				Select name into l_price_list
9344 				from qp_list_headers_vl a,qp_list_lines b where
9345 				b.list_line_id =  to_number(substr(p_req_line_tbl(i).status_text,1,
9346 									instr(p_req_line_tbl(i).status_text,',')-1))
9347 				and a.list_header_id=b.list_header_id
9348 				;
9349 				Exception When No_data_found then
9350 				l_price_list := to_number(substr(p_req_line_tbl(i).status_text,1,
9351 								instr(p_req_line_tbl(i).status_text,',')-1));
9352 				When invalid_number then
9353 				l_price_list := substr(p_req_line_tbl(i).status_text,1,
9354 								instr(p_req_line_tbl(i).status_text,',')-1);
9355 
9356 		 	End;
9357 
9358 		 	FND_MESSAGE.SET_TOKEN('PRICE_LIST1','( '||l_line_rec.Ordered_Item||' ) '||
9359 																	l_price_list);
9360 		 	Begin
9361 				Select name into l_price_list
9362 				from qp_list_headers_vl a,qp_list_lines b where
9363 				b.list_line_id =  to_number(substr(p_req_line_tbl(i).status_text,
9364 									instr(p_req_line_tbl(i).status_text,',')+1))
9365 				and a.list_header_id=b.list_header_id	;
9366 				Exception When No_data_found then
9367 				l_price_list := to_number(substr(p_req_line_tbl(i).status_text,
9368 								instr(p_req_line_tbl(i).status_text,',')+1));
9369 				When invalid_number then
9370 				l_price_list := substr(p_req_line_tbl(i).status_text,
9371 								instr(p_req_line_tbl(i).status_text,',')+1);
9372 
9373 		 	End;
9374 		 	FND_MESSAGE.SET_TOKEN('PRICE_LIST2',l_price_list);
9375 		  	OE_MSG_PUB.Add;
9376 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV then
9377 		 	adj_debug('Invalid UOM Conversion');
9378 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRC_INVALID_UOM_CONVERSION');
9379 		 	FND_MESSAGE.SET_TOKEN('UOM_TEXT','( '||l_line_rec.Ordered_Item||' ) '||
9380 													p_req_line_tbl(i).status_text);
9381 		  	OE_MSG_PUB.Add;
9382 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_INVALID_INCOMP then
9383 		 	adj_debug('Unable to resolve incompatibility');
9384 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRC_INVALID_INCOMP');
9385 		 	FND_MESSAGE.SET_TOKEN('ERR_TEXT','( '||l_line_rec.Ordered_Item||' ) '||
9386 												p_req_line_tbl(i).status_text);
9387 		  	OE_MSG_PUB.Add;
9388 		Elsif p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR then
9389 		 	adj_debug('Error while evaluating the best price');
9390 		 	FND_MESSAGE.SET_NAME('ONT','ONT_PRC_BEST_PRICE_ERROR');
9391 		 	FND_MESSAGE.SET_TOKEN('ITEM',l_line_rec.Ordered_Item);
9392 		 	FND_MESSAGE.SET_TOKEN('ERR_TEXT',p_req_line_tbl(i).status_text);
9393 		  	OE_MSG_PUB.Add;
9394 		End if;
9395 
9396 		 --RAISE FND_API.G_EXC_ERROR;
9397                  --btea begin if do not write to db, we still need to
9398                  --return line and status code to the caller
9399                  If Not p_write_to_db Then
9400                    l_line_rec.Header_id := p_header_rec.Header_id;
9401                    l_line_rec.line_id := p_req_line_tbl(i).line_id;
9402                    -- uom begin
9403                    l_line_rec.unit_selling_price_per_pqty := p_req_line_tbl(i).adjusted_unit_price ;
9404                    l_line_rec.unit_list_price_per_pqty := p_req_line_tbl(i).unit_price ;
9405                    -- uom end
9406                    l_line_rec.pricing_quantity := p_req_line_tbl(i).priced_quantity ;
9407                    l_line_rec.pricing_quantity_uom := p_req_line_tbl(i).priced_uom_code ;
9408                    l_line_rec.price_request_code := p_req_line_tbl(i).price_request_code; -- PROMOTIONS SEP/01
9409                  --use industry_attribute30 as the place holder to hold error status
9410                  --since the line_rec doesn't have the place holder to hold error status
9411                    l_line_rec.industry_attribute30 := p_req_line_tbl(i).status_code;
9412                    l_line_tbl(i) := l_line_rec;
9413                  End If;
9414                  --btea end
9415 
9416 	elsif ( p_req_line_tbl(i).unit_price < 0 or p_req_line_tbl(i).Adjusted_unit_price < 0) and l_allow_negative_price = 'N' then
9417 
9418 		 adj_debug('Negative list price '||p_req_line_tbl(i).unit_price ||'Or selling price '||p_req_line_tbl(i).Adjusted_unit_price);
9419 		 FND_MESSAGE.SET_NAME('ONT','ONT_NEGATIVE_PRICE');
9420 		 FND_MESSAGE.SET_TOKEN('ITEM',l_line_rec.Ordered_Item);
9421 		 FND_MESSAGE.SET_TOKEN('LIST_PRICE',p_req_line_tbl(i).unit_price);
9422 		 FND_MESSAGE.SET_TOKEN('SELLING_PRICE',p_req_line_tbl(i).Adjusted_unit_price);
9423 		 OE_MSG_PUB.Add;
9424                  FND_MESSAGE.SET_NAME('ONT','ONT_NEGATIVE_MODIFIERS');
9425                  FND_MESSAGE.SET_TOKEN('LIST_LINE_NO',get_list_lines(p_req_line_tbl(i).line_id));
9426                  OE_MSG_PUB.Add;
9427 
9428 		 RAISE FND_API.G_EXC_ERROR;
9429 	elsif
9430 	   p_req_line_tbl(i).line_Type_code ='LINE' and
9431 	   p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_OTHER_ERRORS
9432 	Then
9433 
9434 		  	FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
9435 		  	FND_MESSAGE.SET_TOKEN('ERR_TEXT','( '||l_line_rec.Ordered_Item||' ) '||
9436 													p_req_line_tbl(i).STATUS_TEXT);
9437 		  	OE_MSG_PUB.Add;
9438 
9439 	elsif
9440 	   ( p_req_line_tbl(i).line_Type_code ='LINE' and
9441 	   p_req_line_tbl(i).status_code in
9442 				( QP_PREQ_GRP.G_STATUS_UPDATED,
9443                                   QP_PREQ_GRP.G_STATUS_GSA_VIOLATION,
9444                                   QP_PREQ_GRP.G_STATUS_UNCHANGED) and
9445 	   nvl(p_req_line_tbl(i).processed_code,'0') <> QP_PREQ_GRP.G_BY_ENGINE
9446 	   and p_req_line_tbl(i).price_flag IN ('Y','P') )
9447 
9448 	   or  -- OPM 2547940 start
9449 	       -- pricing by quantity2 - this is for case when order line is split from shipping and new line gets generated
9450 	       -- and this line has to be re-priced for catchweight pricing for OPM if pricing in secondary quantity
9451 	   ( ( oe_line_util.dual_uom_control -- INVCONV
9452               (l_line_rec.inventory_item_id
9453               ,l_line_rec.ship_from_org_id
9454               ,l_item_rec) )
9455                    and  p_req_line_tbl(i).line_Type_code ='LINE'
9456                    and  (l_item_rec.ont_pricing_qty_source = 'S' ) -- price by quantity 2 -- INVCONV
9457                    and  ( p_req_line_tbl(i).price_flag In ('N','P') )
9458 		   and ( l_line_rec.split_by is not null )
9459 		   and ( l_line_rec.split_from_line_id is not null and l_line_rec.split_from_line_id <> FND_API.G_MISS_NUM) )
9460                  -- OPM 2547940 end
9461 
9462            --we do not want to go in this loop if price_flag is set up 'N' because
9463            --engine doesn't look at the line and will not return adjustments. In this
9464            --case we DON't want to remove the adjustments that engine doesn't return.
9465 	then
9466 
9467 	 G_STMT_NO := 'process_adjustments11.5';
9468       l_invalid_line := 'N';
9469       l_line_rec.Header_id := p_header_rec.Header_id;
9470       l_line_rec.line_id := p_req_line_tbl(i).line_id;
9471       -- uom begin
9472       l_line_rec.unit_selling_price_per_pqty := p_req_line_tbl(i).adjusted_unit_price ;
9473       l_line_rec.unit_list_price_per_pqty := p_req_line_tbl(i).unit_price ;
9474       -- uom end
9475 
9476       If l_line_rec.item_type_code in ('INCLUDED', 'CONFIG') Then
9477         l_line_rec.pricing_quantity := l_line_rec.ordered_quantity;
9478         l_line_rec.pricing_quantity_uom := l_line_rec.order_quantity_uom;
9479       Else
9480         l_line_rec.pricing_quantity := p_req_line_tbl(i).priced_quantity ;
9481         l_line_rec.pricing_quantity_uom := p_req_line_tbl(i).priced_uom_code ;
9482       End If;
9483 
9484       l_line_rec.price_request_code := p_req_line_tbl(i).price_request_code; -- PROMOTIONS SEP/01
9485 
9486 	 -- Handle the percent Price
9487 
9488 	If nvl(p_req_line_tbl(i).Percent_Price,0) <> 0 and
9489 			p_req_line_tbl(i).Percent_Price <> fnd_api.g_miss_num then
9490 
9491 		l_line_rec.unit_list_percent  := p_req_line_tbl(i).Percent_Price ;
9492 		l_line_rec.unit_percent_base_price := p_req_line_tbl(i).Parent_price;
9493                 -- For bug 1367793, avoid dividing by zero
9494 
9495                 If nvl(l_line_rec.unit_percent_base_price, 0) <> 0 Then
9496   		  l_line_rec.unit_selling_percent  :=
9497 			l_line_rec.Unit_Selling_Price_Per_Pqty * 100 / l_line_rec.unit_percent_base_price;
9498                 Else
9499                         l_line_rec.unit_selling_percent := 0;
9500                 End If;
9501 
9502 	end if;
9503 
9504 
9505 	 -- Query the adjustment Lines for this line
9506 
9507 		G_STMT_NO := 'process_adjustments#30';
9508            --adj_debug('BCT+***L line id: '||p_req_line_tbl(i).line_id);
9509 	   Append_Adjustment_Lines(p_line_id => l_line_rec.line_id,
9510 				p_pricing_event    => p_Req_Control_Rec.Pricing_Event,
9511 				p_price_flag		=> p_req_line_tbl(i).price_flag,
9512                                 p_any_frozen_line  	=> p_any_frozen_line,
9513 				px_Line_Adj_Tbl => l_line_adj_Tbl,
9514                                 px_line_key_tbl    => l_line_key_tbl,
9515                                 px_header_key_tbl  => l_header_key_tbl,
9516                                 p_mode             =>  'L',
9517                                 px_line_rec        => l_line_rec,
9518                                 px_line_adj_assoc_tbl => l_line_adj_assoc_tbl,
9519                                 x_updated_flag => l_updated_flag,
9520                                 p_multiple_events => p_multiple_events);
9521 
9522 	-- Using the same index as that in p_req_line_tbl although there is going to be holes.
9523 
9524       --l_line_tbl(l_line_tbl.count+1) := l_line_rec;
9525       --l_old_line_tbl(l_line_tbl.count) := l_old_line_rec;
9526       adj_debug('Setting l_line_tbl...'||l_line_tbl.count||' '||i||' '||l_line_rec.line_id);
9527       l_line_tbl(i) := l_line_rec;
9528       --l_old_line_tbl(i) := l_old_line_rec;
9529 
9530 	Elsif  -- Process header level adjustments
9531 		 p_req_line_tbl(i).line_type_code ='ORDER' and
9532 		(p_req_line_tbl(i).status_code in ( QP_PREQ_GRP.G_STATUS_UPDATED ,
9533 					QP_PREQ_GRP.G_STATUS_GSA_VIOLATION)
9534                  --btea
9535                  --In this case even engine doesn't update the order (status = UNCHANGED)
9536                  --because of one of the lined is frozen,
9537                  --there can be some order level adjustments in database which
9538                  --need to be pulled out by append_adjustment_lines routine
9539                  or (p_req_line_tbl(i).status_code = QP_PREQ_GRP.G_STATUS_UNCHANGED
9540 --                     and p_any_frozen_line = TRUE -- bug 1675449
9541 				 ))
9542 	Then
9543 		G_STMT_NO := 'Process_Adjustments#35';
9544                 --adj_debug('BCT'||G_STMT_NO);
9545                 --adj_debug('BCT+***H line id: '||p_req_line_tbl(i).line_id);
9546 
9547                 IF (l_header_rec.price_request_code IS NULL OR   		-- PROMOTIONS SEP/01
9548                     l_header_rec.price_request_code = FND_API.G_MISS_CHAR) THEN
9549                    l_header_rec.price_request_code := p_req_line_tbl(i).price_request_code;
9550                    l_header_rec.operation := OE_GLOBALS.G_OPR_UPDATE;
9551                 END IF;
9552 
9553 	 	append_Adjustment_Lines(p_header_id => p_req_line_tbl(i).line_id,
9554 					-- line_id contains header_id for line_type_code='ORDER'
9555 				p_pricing_event	=> p_Req_Control_Rec.Pricing_Event,
9556 				p_price_flag		=> p_req_line_tbl(i).price_flag,
9557                                 p_any_frozen_line  	=> p_any_frozen_line,
9558 				px_Line_Adj_Tbl 	=> l_line_adj_Tbl,
9559                                 px_line_key_tbl    => l_line_key_tbl,
9560                                 px_header_key_tbl  => l_header_key_tbl,
9561                                 p_mode             => 'H',
9562                                 px_line_rec        => l_dummy_line_rec,
9563                                 px_line_adj_assoc_tbl => l_line_adj_assoc_tbl,
9564                                 x_updated_flag     => l_updated_flag,
9565                                 p_multiple_events  => p_multiple_events);
9566 
9567      End If;-- Status_Code
9568 
9569         oe_debug_pub.add('Before Reset_fields');
9570      If l_invalid_line = 'Y' Then
9571         select oe_msg_request_id_s.nextval into l_request_id from dual;
9572         OE_MSG_PUB.INSERT_MESSAGE(OE_MSG_PUB.COUNT_MSG, l_request_id,'U');
9573         Reset_Fields(l_line_rec);
9574         l_invalid_line := 'N';
9575      End If;
9576 
9577      G_STMT_NO := 'Process_Adjustments#36';
9578       --          adj_debug('PAL PROMOTIONS '||G_STMT_NO);
9579  	--	adj_debug('PROMOTIONS - status code is ' ||p_req_line_tbl(i).status_code);
9580 
9581      -- Process header level adjustments     -- PROMOTIONS SEP/01 start
9582       adj_debug('limit profile:'||l_limit_hold_action,3);
9583 
9584         IF (p_req_line_tbl(i).hold_code = QP_PREQ_GRP.G_STATUS_LIMIT_HOLD) or
9585             p_req_line_tbl(i).hold_code = QP_PREQ_GRP.G_STATUS_LIMIT_ADJUSTED THEN
9586           IF (l_limit_hold_action = 'NO_HOLD') THEN
9587             FND_MESSAGE.SET_NAME('ONT','ONT_PROMO_LIMIT_EXCEEDED');
9588             OE_MSG_PUB.ADD;
9589         ELSE
9590 	  IF	( p_req_line_tbl(i).line_type_code = 'LINE' )
9591 		Then
9592 		-- adj_debug('PAL PROMOTIONS - putting entity on HOLD - line type code is ' || p_req_line_tbl(i).line_type_code);
9593 	  	Promotion_Put_Hold (p_header_id   => p_header_rec.Header_id,
9594 			      p_line_id     => p_req_line_tbl(i).line_id);
9595                 IF (l_limit_hold_action = 'ORDER_HOLD') THEN
9596                  Promotion_Put_Hold(p_header_id => p_header_rec.header_id,
9597                                     p_line_id => NULL);
9598                 END IF;
9599 
9600 	  ELSIF  ( p_req_line_tbl(i).line_type_code = 'ORDER' )
9601 	  	Then
9602 		-- adj_debug('PAL PROMOTIONS - putting entity on HOLD - line type code is ' || p_req_line_tbl(i).line_type_code);
9603 	 	Promotion_Put_Hold (p_header_id   => p_req_line_tbl(i).line_id,
9604 			      p_line_id     => NULL) ;
9605 
9606 	  END IF; -- ( p_req_line_tbl(i).line_type_code = 'LINE' )
9607 	 END IF;  -- limit violation action
9608 	END IF; -- (p_req_line_tbl(i).hold_code = QP_PREQ_GRP.G_STATUS_LIMIT_HOLD)
9609         IF p_req_line_tbl(i).line_id IS NOT NULL AND
9610            p_req_line_tbl(i).line_id <> FND_API.G_MISS_NUM THEN
9611            BEGIN
9612                IF l_debug_level  > 0 THEN
9613                   oe_debug_pub.add('Getting reference data for line_id:'||p_req_line_tbl(i).line_id);
9614                END IF;
9615                SELECT order_source_id, orig_sys_document_ref, change_sequence,
9616                source_document_type_id, source_document_id, orig_sys_line_ref,
9617                source_document_line_id, orig_sys_shipment_ref
9618                INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
9619                l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
9620                l_source_document_line_id, l_orig_sys_shipment_ref
9621                FROM   OE_ORDER_LINES_ALL
9622                WHERE  line_id = p_req_line_tbl(i).line_id;
9623            EXCEPTION
9624                WHEN NO_DATA_FOUND THEN
9625                    l_order_source_id := null;
9626                    l_orig_sys_document_ref := null;
9627                    l_change_sequence := null;
9628                    l_source_document_type_id := null;
9629                    l_source_document_id := null;
9630                    l_orig_sys_line_ref := null;
9631                    l_source_document_line_id := null;
9632                    l_orig_sys_shipment_ref := null;
9633                WHEN OTHERS THEN
9634                    l_order_source_id := null;
9635                    l_orig_sys_document_ref := null;
9636                    l_change_sequence := null;
9637                    l_source_document_type_id := null;
9638                    l_source_document_id := null;
9639                    l_orig_sys_line_ref := null;
9640                    l_source_document_line_id := null;
9641                    l_orig_sys_shipment_ref := null;
9642            END;
9643         END IF;
9644 
9645 	OE_MSG_PUB.set_msg_context
9646 	        ( p_entity_code                 => 'LINE'
9647 	         ,p_entity_id                   => p_req_line_tbl(i).line_id
9648 	         ,p_header_id                   => p_req_line_tbl(i).header_id
9649 	         ,p_line_id                     => p_req_line_tbl(i).line_id
9650                  ,p_order_source_id             => l_order_source_id
9651                  ,p_orig_sys_document_ref       => l_orig_sys_document_ref
9652                  ,p_orig_sys_document_line_ref  => l_orig_sys_line_ref
9653                  ,p_orig_sys_shipment_ref       => l_orig_sys_shipment_ref
9654                  ,p_change_sequence             => l_change_sequence
9655                  ,p_source_document_type_id     => l_source_document_type_id
9656                  ,p_source_document_id          => l_source_document_id
9657                  ,p_source_document_line_id     => l_source_document_line_id);   -- PROMOTIONS MAY/01 end
9658 
9659 	i:=  p_req_line_tbl.Next(i);
9660     end loop; -- Req_line_tbl
9661 
9662 	G_STMT_NO := 'process_adjustments#40';
9663 
9664 	 J:= p_req_line_detail_Tbl.First;
9665 	 While J is Not null loop
9666 	   if  p_req_line_tbl( p_req_line_detail_Tbl(j).line_index).status_code in (
9667 				QP_PREQ_GRP.G_STATUS_UPDATED ,QP_PREQ_GRP.G_STATUS_GSA_VIOLATION )
9668 			and nvl(p_req_line_tbl( p_req_line_detail_Tbl(j).line_index).processed_code,'0')
9669 			    <> QP_PREQ_GRP.G_BY_ENGINE
9670 
9671                         --only process/insert automatic adjustments, with freight charge as exception
9672                         and (p_req_line_detail_Tbl(j).automatic_flag = 'Y' or
9673                              (p_req_line_detail_Tbl(j).automatic_flag = 'N' and (p_req_line_detail_Tbl(j).list_line_type_code = 'FREIGHT_CHARGE' or l_preinsert_manual_adj = 'Y' )))
9674 			and (
9675 				((
9676                                   ( l_line_tbl.exists( p_req_line_detail_Tbl(j).line_index)
9677                                     and
9678 				    oe_line_util.Get_Return_Item_Type_Code
9679                                     (l_line_tbl( p_req_line_detail_Tbl(j).line_index))<> 'INCLUDED'
9680                                   )
9681 				  Or not l_line_tbl.exists (p_req_line_detail_Tbl(j).line_index )
9682 
9683                                   )
9684                                   And
9685                                   G_CHARGES_FOR_INCLUDED_ITEM = 'N'
9686                                 )
9687                                 Or
9688                                 G_CHARGES_FOR_INCLUDED_ITEM = 'Y'
9689 			     )
9690 
9691 
9692 	   then
9693                 --adj_debug('BCT+Engine returned status fullfilled');
9694                 --adj_debug('BCT+list_line_type_code+'||p_req_line_detail_Tbl(j).list_line_type_code);
9695 		if p_req_line_detail_Tbl(j).created_from_list_type_code = 'PRL' or
9696 		   p_req_line_detail_Tbl(j).created_from_list_type_code = 'AGR' or
9697 		   p_req_line_detail_Tbl(j).list_line_type_code = 'PLL'
9698 		then
9699 			If l_line_tbl.exists( p_req_line_detail_Tbl(j).line_index) then
9700 				l_line_tbl( p_req_line_detail_Tbl(j).line_index).price_list_id :=
9701 						p_req_line_detail_Tbl(j).list_header_id;
9702 			End if;
9703 
9704 		else
9705 			G_STMT_NO := 'process_adjustments#50';
9706 
9707 		     If p_req_line_tbl( p_req_line_detail_Tbl(j).line_index).line_type_code =  'LINE' Then
9708 
9709                   -- Changes by JAUTOMO on 20-DEC-00 (bug# 1303352)
9710 
9711                   -- Get Discounting Privilege Profile Option value
9712                   fnd_profile.get('ONT_DISCOUNTING_PRIVILEGE', v_discounting_privilege);
9713 
9714                   IF (v_order_enforce_list_price = 'Y') THEN
9715                       v_line_enforce_list_price := 'Y';
9716                   ELSE
9717                                  enforce_list_price(
9718                                        p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id,
9719                                        l_line_tbl(p_req_line_detail_tbl(j).line_index).header_id,
9720                                        l_line_tbl(p_req_line_detail_tbl(j).line_index).line_type_id,
9721                                        v_order_enforce_list_price,
9722                                        v_line_enforce_list_price);
9723                   END IF;
9724 
9725                   adj_debug('2441779 line_id '||p_req_line_detail_tbl(j).line_index||' '||p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id);
9726                   adj_debug('2441779'||l_line_tbl(p_req_line_detail_tbl(j).line_index).line_id);
9727                   IF      (nvl(v_line_enforce_list_price,'N') <> 'Y'
9728                            AND p_req_line_detail_Tbl(j).automatic_flag = 'Y')
9729                            OR
9730                            p_req_line_detail_tbl(j).list_line_type_code = 'FREIGHT_CHARGE' THEN
9731 
9732 			   If p_req_line_detail_Tbl(j).list_line_type_code ='TSN' then
9733 			   	adj_debug('Before Terms-- Line Level');
9734 			   	-- Updated the Terms at Line Level
9735 			   	If p_req_line_detail_Tbl(j).Substitution_Attribute ='QUALIFIER_ATTRIBUTE1' Then
9736 				   	adj_debug('Payment_term updated to '||p_req_line_detail_Tbl(j).Substitution_to);
9737 				   	l_line_tbl( p_req_line_detail_Tbl(j).line_index).payment_term_id :=
9738 							p_req_line_detail_Tbl(j).Substitution_to;
9739 			   	elsIf p_req_line_detail_Tbl(j).Substitution_Attribute ='QUALIFIER_ATTRIBUTE11' Then
9740 				   	adj_debug('shipping_method_code updated to '||p_req_line_detail_Tbl(j).Substitution_to);
9741 				   	l_line_tbl( p_req_line_detail_Tbl(j).line_index).shipping_method_code :=
9742 							p_req_line_detail_Tbl(j).Substitution_to;
9743 			   	elsIf p_req_line_detail_Tbl(j).Substitution_Attribute ='QUALIFIER_ATTRIBUTE10' Then
9744 				   	adj_debug('freight_terms_code updated to '||p_req_line_detail_Tbl(j).Substitution_to);
9745 				   	l_line_tbl( p_req_line_detail_Tbl(j).line_index).freight_terms_code :=
9746 							p_req_line_detail_Tbl(j).Substitution_to;
9747 			   	End If;
9748 
9749 			   End If; -- TSN
9750 
9751 
9752 			-- Check If the List_Header/ Line  Combination Exists
9753                                 l_adj_index := NULL;
9754 				Find_Duplicate_Adj_Lines(
9755 				p_Line_id   	=>
9756 					l_line_tbl( p_req_line_detail_Tbl(j).line_index).line_id,
9757 				p_req_line_detail_Rec =>  p_req_line_detail_Tbl(j),
9758 				px_Line_Adj_Tbl => 	l_line_adj_Tbl,
9759 				x_Adj_Index	=>   l_Adj_Index,
9760 			        p_mode          =>   'L',
9761                                 px_line_key_tbl =>   l_line_key_tbl,
9762                                 px_header_key_tbl => l_header_key_tbl) ;
9763 
9764                           END IF; -- For Unlimited Discouting Privilege
9765  adj_debug('2441779:'||l_line_tbl(p_req_line_detail_tbl(j).line_index).line_id);
9766 
9767 		     Else -- HEader Level
9768 
9769 			   If p_req_line_detail_Tbl(j).list_line_type_code ='TSN' then
9770 			   	adj_debug('Before Terms-- Header Level');
9771 			   	-- Updated the Terms at Line Level
9772 			   	If p_req_line_detail_Tbl(j).Substitution_Attribute ='QUALIFIER_ATTRIBUTE1' Then
9773 				   	adj_debug('Payment_term updated to '||p_req_line_detail_Tbl(j).Substitution_to);
9774 				   	l_header_rec.payment_term_id :=  p_req_line_detail_Tbl(j).Substitution_to;
9775 			   	elsIf p_req_line_detail_Tbl(j).Substitution_Attribute ='QUALIFIER_ATTRIBUTE11' Then
9776 				   	adj_debug('shipping_method_code updated to '||p_req_line_detail_Tbl(j).Substitution_to);
9777 				   	l_header_rec.shipping_method_code :=  p_req_line_detail_Tbl(j).Substitution_to;
9778 			   	elsIf p_req_line_detail_Tbl(j).Substitution_Attribute ='QUALIFIER_ATTRIBUTE10' Then
9779 				   	adj_debug('freight_terms_code updated to '||p_req_line_detail_Tbl(j).Substitution_to);
9780 				   	l_header_rec.freight_terms_code :=  p_req_line_detail_Tbl(j).Substitution_to;
9781 			   	End If;
9782 
9783 				   	l_header_rec.operation :=  OE_GLOBALS.G_OPR_UPDATE;
9784 
9785 			   End If; -- TSN
9786 
9787 
9788 			-- Check If the List_Header/ header  Combination Exists
9789 
9790 				G_STMT_NO := 'process_adjustments#55';
9791                                 l_adj_index:=NULL;
9792 				Find_Duplicate_Adj_Lines(
9793 				p_header_Id 	=>
9794 					 p_req_line_tbl(p_req_line_detail_Tbl(j).line_index).line_id,
9795 							-- line_id hold header_id for 'HEADER'
9796 				p_req_line_detail_Rec =>  p_req_line_detail_Tbl(j),
9797 				px_Line_Adj_Tbl => 	l_line_adj_Tbl,
9798 				x_Adj_Index	=>   l_Adj_Index,
9799                                 p_mode          =>   'H',
9800                                 px_line_key_tbl =>   l_line_key_tbl,
9801                                 px_header_key_tbl => l_header_key_tbl
9802 					) ;
9803 
9804 		     End if;  --header_level
9805 
9806                         If nvl(l_adj_index,-1) > 0 Then
9807 			-- Populate the line_details processed table
9808 			l_line_details_prcd(j) := l_Adj_Index;
9809 
9810                         adj_debug('details_prcd: ('||J||')'||l_Adj_Index,2);
9811 
9812 			-- Mark Adjustment Attributes and Adjustment Associations to
9813 			-- Delete
9814 			-- Subsequently these rows would be reinstated
9815 			-- Delete is cascaded to children when adjustment is deleted.
9816 
9817 
9818 			G_STMT_NO := 'process_adjustments#60';
9819 
9820 			   Query_Adj_Attribs(
9821 					p_price_adjustment_id=>
9822 					l_line_adj_Tbl(l_Adj_Index).price_adjustment_id,
9823 					p_Adj_Index		=> l_Adj_Index,
9824 					p_Line_Adj_Att_Tbl 	=> l_line_adj_att_tbl);
9825 
9826 				G_STMT_NO := 'process_adjustments#70';
9827 
9828 
9829 
9830 			--adj_debug('BCT+operation:'||l_line_adj_Tbl(l_Adj_Index).operation);
9831 			if  l_line_adj_Tbl(l_Adj_Index).operation in ( OE_GLOBALS.G_OPR_CREATE,
9832 							 OE_GLOBALS.G_OPR_UPDATE ) Then
9833 				-- This Record Needs to be processed
9834 		    	  if p_req_line_tbl( p_req_line_detail_Tbl(j).line_index).line_type_code =  'LINE'
9835 			  Then
9836 
9837 			   if  p_req_line_detail_Tbl(j).list_line_type_code ='IUE' then
9838 			   -- Do not give item upgrades to config items.
9839 				If l_line_tbl( p_req_line_detail_Tbl(j).line_index).top_model_line_id is null
9840 				or  l_line_tbl( p_req_line_detail_Tbl(j).line_index).top_model_line_id= fnd_api.g_miss_num
9841 				then
9842 				If  -- Allow Item upgrade only if the order is not booked.
9843 				nvl(l_line_tbl( p_req_line_detail_Tbl(j).line_index).booked_flag,'N')
9844 							= 'N'
9845 		          then
9846 
9847 			     -- Set the Line Item to the new item
9848 
9849 				   Set_item_for_iue(
9850 					px_line_rec   => l_line_tbl( p_req_line_detail_Tbl(j).line_index)
9851 					,p_req_line_detail_rec => p_req_line_detail_Tbl(j)
9852 					);
9853 
9854 
9855 				Elsif to_char(l_line_tbl( p_req_line_detail_Tbl(j).line_index).Inventory_item_id ) <>
9856 										p_req_line_detail_Tbl(j).RELATED_ITEM_ID Then
9857 
9858 		  			FND_MESSAGE.SET_NAME('ONT','ONT_ITEM_UPGRADE_NOT_ALLOWED');
9859 		  			OE_MSG_PUB.Add;
9860 				   adj_debug('Item Upgrade not allowed after booking...');
9861 				   l_line_adj_Tbl(l_Adj_Index).operation := fnd_api.g_miss_char;
9862 
9863 				End If; -- Booked_Flag
9864 
9865 			   End if ; -- Config item
9866 		 	   end if;	 -- IUE
9867 
9868 			   l_line_adj_Tbl(l_Adj_Index).line_id :=
9869 					l_line_tbl( p_req_line_detail_Tbl(j).line_index).line_id;
9870 			   l_line_adj_Tbl(l_Adj_Index).Header_id :=
9871 					l_line_tbl( p_req_line_detail_Tbl(j).line_index).Header_id;
9872 			   l_line_adj_Tbl(l_Adj_Index).Line_index := p_req_line_detail_Tbl(j).line_index;
9873 
9874 			 else -- HEADER Level
9875 
9876 			   l_line_adj_Tbl(l_Adj_Index).line_id :=  null;
9877 			   l_line_adj_Tbl(l_Adj_Index).Header_id :=
9878 					p_req_line_tbl(p_req_line_detail_Tbl(j).line_index).line_id;
9879 							-- line_id hold header_id for 'HEADER'
9880 			   l_line_adj_Tbl(l_Adj_Index).Line_index := null;
9881 
9882 				--OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
9883 
9884 			 End If ; -- list_line_level
9885 
9886 
9887 			 -- Process "Other Item Discounts" (Including Free goods)
9888 
9889 				G_STMT_NO := 'process_adjustments#80';
9890 
9891 
9892 			 -- Process Promotional Goods
9893 
9894 			 If p_req_line_detail_Tbl(j).list_line_type_code ='PRG' Then
9895 				adj_debug('The Detail is a PRG '||p_req_line_detail_Tbl(j).line_detail_index);
9896 
9897 				i:= p_Req_Related_Lines_Tbl.First;
9898 				While i is not null loop
9899 
9900 				  if p_Req_Related_Lines_Tbl(i).Line_Detail_Index =
9901 									p_req_line_detail_Tbl(j).line_detail_index and
9902 					p_Req_Related_Lines_Tbl(i).Relationship_Type_Code
9903 						=QP_PREQ_GRP.G_GENERATED_LINE Then
9904 
9905 					adj_debug('The related line is '||p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index);
9906 				    -- Process the "Other Item"
9907 
9908 				    If p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index is not Null
9909 				    Then
9910 					-- Inserts Rows into Line_Tbl and Adjustments
9911 
9912 					G_STMT_NO := 'process_adjustments#90';
9913 
9914                                         Begin
9915                                           oe_debug_pub.add('Line id:'||
9916                                           l_line_tbl(p_req_line_detail_Tbl(p_req_related_lines_tbl(i).line_detail_index).line_index).line_id);
9917 
9918                                           oe_debug_pub.add('Reason:'||
9919                                           l_line_tbl(p_req_line_detail_Tbl(p_req_related_lines_tbl(i).line_detail_index).line_index).return_reason_code);
9920                                         Exception when others then
9921                                           oe_debug_pub.add(SQLERRM||G_STMT_NO);
9922                                         End;
9923 
9924 					Process_Other_Item_Line
9925 					(p_Line_Detail_Index 			=>
9926 							p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index,
9927 					 p_req_line_Tbl 		=> p_req_line_Tbl,
9928 					 p_req_line_detail_Tbl 	=> p_req_line_detail_Tbl,
9929 					 p_req_line_detail_Attr_Tbl 	=> p_req_line_detail_Attr_Tbl,
9930 					 p_Price_Adjustment_Id	=> l_line_adj_Tbl(l_Adj_Index).Price_Adjustment_Id,
9931 					 p_Header_id			=> p_header_rec.Header_id,
9932 					 p_Parent_Adj_Index		=> l_Adj_Index,
9933 					 p_parent_line_index	=>  p_req_line_detail_Tbl(j).line_index,
9934 					 p_Rltd_line_details_prcd=> l_Rltd_line_details_prcd,
9935 					 --p_Rltd_line_details_prcd=> l_line_details_prcd,
9936 					 p_Rltd_lines_prcd		=> l_Rltd_lines_prcd,
9937 					 p_Line_Tbl			=> l_Line_Tbl,
9938 					 p_Line_Adj_Tbl		=> l_line_adj_Tbl,
9939 					 p_Line_Adj_Assoc_Tbl	=> l_line_adj_Assoc_Tbl,
9940                                          p_line_detail_replaced => l_line_detail_replaced,
9941                                          p_buy_line_rec         =>  l_line_tbl(p_req_line_detail_Tbl(p_req_related_lines_tbl(i).line_detail_index).line_index));
9942 
9943 				    End If; -- RelationShips
9944 				  End If;
9945 				  i:= p_Req_Related_Lines_Tbl.next(i);
9946 				End Loop;
9947 
9948 			 End If; -- PRG
9949 
9950 		   end if; -- Duplicate list lines in the adjustments
9951 			-- Process the Qualifiers
9952   		end if; -- for list_line_type
9953 
9954 	   end if;  -- Status_code = Updated.
9955 
9956 	   If ( (p_req_line_detail_Tbl(j).limit_code = QP_PREQ_GRP.G_STATUS_LIMIT_EXCEEDED ) -- PROMOTIONS SEP/01 START
9957             or (p_req_line_detail_Tbl(j).limit_code = QP_PREQ_GRP.G_STATUS_LIMIT_ADJUSTED ) )
9958    	     then
9959 	      --  adj_debug('PAL PROMOTIONS - G_STATUS_LIMIT_EXCEEDED or G_STATUS_LIMIT_ADJUSTED IN _Adj_pvt.process_adjustments',1);
9960 		IF (p_req_line_tbl(p_req_line_detail_tbl(j).line_index).LINE_TYPE_CODE='ORDER') THEN
9961 			OE_MSG_PUB.set_msg_context
9962       			( p_entity_code                 => 'HEADER'
9963          		,p_entity_id                   => p_header_rec.header_id--p_req_line_tbl(j).line_id
9964          		,p_header_id                   => p_header_rec.header_id
9965          		,p_line_id                     => NULL--p_req_line_tbl(j).line_id
9966          		,p_orig_sys_document_ref       => p_header_rec.orig_sys_document_ref
9967          		,p_orig_sys_document_line_ref  => NULL
9968          		,p_change_sequence             => p_header_rec.change_sequence
9969          		,p_source_document_id          => p_header_rec.source_document_id
9970          		,p_source_document_line_id     => NULL
9971          		,p_order_source_id             => p_header_rec.order_source_id
9972          		,p_source_document_type_id     => p_header_rec.source_document_type_id);
9973 		ELSE
9974                   IF p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id IS NOT NULL AND
9975                      p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id <> FND_API.G_MISS_NUM THEN
9976                      BEGIN
9977                        IF l_debug_level  > 0 THEN
9978                           oe_debug_pub.add('Getting reference data for line_id:'||p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id);
9979                        END IF;
9980                        SELECT order_source_id, orig_sys_document_ref, change_sequence,
9981                        source_document_type_id, source_document_id, orig_sys_line_ref,
9982                        source_document_line_id, orig_sys_shipment_ref
9983                        INTO l_order_source_id, l_orig_sys_document_ref, l_change_sequence,
9984                        l_source_document_type_id, l_source_document_id, l_orig_sys_line_ref,
9985                        l_source_document_line_id, l_orig_sys_shipment_ref
9986                        FROM   OE_ORDER_LINES_ALL
9987                        WHERE  line_id = p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id;
9988                      EXCEPTION
9989                        WHEN NO_DATA_FOUND THEN
9990                            l_order_source_id := null;
9991                            l_orig_sys_document_ref := null;
9992                            l_change_sequence := null;
9993                            l_source_document_type_id := null;
9994                            l_source_document_id := null;
9995                            l_orig_sys_line_ref := null;
9996                            l_source_document_line_id := null;
9997                            l_orig_sys_shipment_ref := null;
9998                        WHEN OTHERS THEN
9999                            l_order_source_id := null;
10000                            l_orig_sys_document_ref := null;
10001                            l_change_sequence := null;
10002                            l_source_document_type_id := null;
10003                            l_source_document_id := null;
10004                            l_orig_sys_line_ref := null;
10005                            l_source_document_line_id := null;
10006                            l_orig_sys_shipment_ref := null;
10007                      END;
10008                   END IF;
10009                		OE_MSG_PUB.set_msg_context
10010       			( p_entity_code                 => 'LINE'
10011          		,p_entity_id                   => p_req_line_tbl(p_req_line_detail_tbl(j).line_index).LINE_ID
10012          		,p_header_id                   => p_header_rec.header_id
10013          		,p_line_id                     => p_req_line_tbl(p_req_line_detail_tbl(j).line_index).line_id
10014                         ,p_order_source_id              => l_order_source_id
10015                         ,p_orig_sys_document_ref        => l_orig_sys_document_ref
10016                         ,p_orig_sys_document_line_ref   => l_orig_sys_line_ref
10017                         ,p_orig_sys_shipment_ref        => l_orig_sys_shipment_ref
10018                         ,p_change_sequence              => l_change_sequence
10019                         ,p_source_document_type_id      => l_source_document_type_id
10020                         ,p_source_document_id           => l_source_document_id
10021                         ,p_source_document_line_id      => l_source_document_line_id);
10022 		END IF;
10023 
10024 		FND_MESSAGE.SET_NAME('ONT','ONT_PROMO_LIMIT_EXCEEDED');
10025 		FND_MESSAGE.SET_TOKEN('ERR_TEXT', p_req_line_detail_tbl(j).LIMIT_TEXT);
10026 		OE_MSG_PUB.Add;
10027    		IF (OE_GLOBALS.G_UI_FLAG ) THEN
10028        			IF (G_REQUEST_ID IS NULL) THEN
10029          			select oe_msg_request_id_s.nextval into g_request_id from dual;
10030        			END IF;
10031       			OE_MSG_PUB.INSERT_MESSAGE(OE_MSG_PUB.COUNT_MSG, G_REQUEST_ID,'U');
10032       			OE_MSG_PUB.DELETE_MSG(OE_MSG_PUB.COUNT_MSG);
10033   		END IF;
10034 
10035  	    end if; --PROMOTIONS SEP/01 end
10036 
10037            end if; --l_adj_line_index is either postive of 0 nvl(l_adj_index,-1)
10038 
10039 	   J:=p_req_line_detail_Tbl.Next(j);
10040 
10041 	 end loop; -- p_req_line_detail_Tbl
10042 
10043 	G_STMT_NO := 'process_adjustments#100';
10044 
10045 --No adjustment records, or relationsip,attributes record need to be looked at becasue
10046 --enforce list price is set to 'Y'
10047 If nvl(v_line_enforce_list_price,'N') <> 'Y' Then
10048 	-- Process Price Break Lines
10049 		i:= p_Req_Related_Lines_Tbl.First;
10050 		While i is not null loop
10051 			if
10052 			p_Req_Related_Lines_Tbl(i).Relationship_Type_Code in (
10053 				QP_PREQ_GRP.G_PBH_LINE ,QP_PREQ_GRP.G_GENERATED_LINE ) and
10054 				p_Req_Related_Lines_Tbl(i).Line_Detail_Index is not null and
10055 				p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index is not null and
10056 				l_line_details_prcd.exists(p_Req_Related_Lines_Tbl(i).Line_Detail_Index) and
10057 				l_line_details_prcd.exists(p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index)
10058   and l_line_adj_tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Line_Detail_Index)).updated_flag = 'N'
10059 			Then
10060                                 If G_DEBUG Then
10061 				adj_debug('RLTD: line detail '||p_Req_Related_Lines_Tbl(i).Line_Detail_Index,2);
10062 				adj_debug('RLTD: rltd line detail '||p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index,2);
10063 				adj_debug('RLTD: Relationship type '||p_Req_Related_Lines_Tbl(i).Relationship_Type_Code,2);
10064                                 End If;
10065 
10066 			-- Process the Relationship records
10067 			--	l_assoc_index := l_Line_Adj_Assoc_tbl.count+1;
10068 /* Commented the above line and added following 5 lines to fix the bug 2312402 */
10069                                 IF (l_Line_Adj_Assoc_tbl.count > 0) THEN
10070                                   l_assoc_index := l_Line_Adj_Assoc_tbl.last+1;
10071                                 ELSE
10072                                   l_assoc_index := 1;
10073                                 END IF;
10074                                 l_Line_Adj_Assoc_tbl(l_assoc_index) := OE_ORDER_PUB.G_MISS_LINE_ADJ_ASSOC_REC;
10075 				l_Line_Adj_Assoc_tbl(l_assoc_index).Line_Index := Null;
10076 				l_Line_Adj_Assoc_tbl(l_assoc_index).Adj_Index :=
10077 					l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Line_Detail_Index);
10078 				l_Line_Adj_Assoc_tbl(l_assoc_index).Rltd_Adj_Index :=
10079 					l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index);
10080 				l_Line_Adj_Assoc_tbl(l_assoc_index).Operation := OE_Globals.G_OPR_CREATE;
10081 
10082 				If  l_line_adj_Tbl.exists(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).line_detail_Index))
10083 				and l_line_adj_Tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).line_detail_Index)).price_adjustment_id <> FND_API.G_MISS_NUM and
10084 				l_line_adj_Tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).line_detail_Index)).price_adjustment_id is not null then
10085 
10086 					l_Line_Adj_Assoc_tbl(l_assoc_index).price_adjustment_id :=
10087 					l_line_adj_Tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).line_detail_Index)).price_adjustment_id ;
10088 				End If; -- Populate Adjustment_id
10089 				If  l_line_adj_Tbl.exists(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index))
10090 				and l_line_adj_Tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index)).price_adjustment_id <> FND_API.G_MISS_NUM and
10091 				l_line_adj_Tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index)).price_adjustment_id is not null then
10092 
10093 					l_Line_Adj_Assoc_tbl(l_assoc_index).rltd_price_adj_id :=
10094 					l_line_adj_Tbl(l_line_details_prcd(p_Req_Related_Lines_Tbl(i).Related_Line_Detail_Index)).price_adjustment_id ;
10095 				End If; -- Populate Adjustment_id
10096 
10097 			End If; -- RelationShips
10098 			i:= p_Req_Related_Lines_Tbl.Next(i);
10099 		End Loop;
10100 
10101 	 -- Process Qualifier Attributes
10102 
10103 	 i:= p_Req_LINE_DETAIL_qual_tbl.First;
10104 	 While i is not null Loop
10105 	 --For i in  1..p_Req_LINE_DETAIL_qual_tbl.count loop
10106         if l_line_details_prcd.exists(p_Req_LINE_DETAIL_qual_tbl(i).line_detail_index)
10107 	   --or l_Rltd_line_details_prcd.exists(p_Req_LINE_DETAIL_qual_tbl(i).line_detail_index)
10108 		then
10109 
10110 		G_STMT_NO := 'process_adjustments#110';
10111 		If  l_line_adj_Tbl.exists(l_line_details_prcd(p_Req_LINE_DETAIL_qual_tbl(i).line_detail_Index))
10112 			and l_line_adj_Tbl(l_line_details_prcd(p_Req_LINE_DETAIL_qual_tbl(i).line_detail_Index)).price_adjustment_id <> FND_API.G_MISS_NUM and
10113 			l_line_adj_Tbl(l_line_details_prcd(p_Req_LINE_DETAIL_qual_tbl(i).line_detail_Index)).price_adjustment_id is not null then
10114 
10115 			l_price_adjustment_id :=
10116 			l_line_adj_Tbl(l_line_details_prcd(p_Req_LINE_DETAIL_qual_tbl(i).line_detail_Index)).price_adjustment_id ;
10117                 Else
10118                   l_price_adjustment_id := NULL;
10119 		End If; -- Populate Adjustment_id
10120 
10121 		adj_debug('In Qual loop',2);
10122 		Find_Duplicate_Adj_Attribs(
10123 			p_Req_LINE_DETAIL_qual_Rec 	=> p_Req_LINE_DETAIL_qual_tbl(i),
10124 			p_Req_Line_Detail_Attr_Rec    => l_Req_Line_Detail_Attr_Rec,
10125 			p_Adj_index 				=>
10126 					l_line_details_prcd(
10127 						p_Req_LINE_DETAIL_qual_tbl(i).line_detail_Index),
10128 			p_Line_Adj_Att_Tbl 			=> l_Line_Adj_Att_tbl,
10129 			p_Att_Type		=> 'QUALIFIER',
10130 			p_price_adjustment_id	=> l_price_adjustment_id
10131 				);
10132 
10133 	   End If;
10134 	   i:= p_Req_LINE_DETAIL_qual_tbl.next(i);
10135 	 end loop;
10136 
10137 	 -- Process Pricing Attributes
10138 
10139 	 i:= p_Req_LINE_DETAIL_Attr_tbl.First;
10140 	 While i is not null Loop
10141 	 --For i in  1..p_Req_LINE_DETAIL_Attr_tbl.count loop
10142 
10143         if l_line_details_prcd.exists(p_Req_LINE_DETAIL_Attr_tbl(i).line_detail_index)
10144 	   --or l_Rltd_line_details_prcd.exists(p_Req_LINE_DETAIL_Attr_tbl(i).line_detail_index)
10145 	   Then
10146 
10147 		If  l_line_adj_Tbl.exists(l_line_details_prcd(p_Req_LINE_DETAIL_attr_tbl(i).line_detail_Index))
10148 			and l_line_adj_Tbl(l_line_details_prcd(p_Req_LINE_DETAIL_attr_tbl(i).line_detail_Index)).price_adjustment_id <> FND_API.G_MISS_NUM and
10149 			l_line_adj_Tbl(l_line_details_prcd(p_Req_LINE_DETAIL_attr_tbl(i).line_detail_Index)).price_adjustment_id is not null
10150 			then
10151 
10152 			l_price_adjustment_id :=
10153 			l_line_adj_Tbl(l_line_details_prcd(p_Req_LINE_DETAIL_attr_tbl(i).line_detail_Index)).price_adjustment_id ;
10154                 Else
10155                   l_price_adjustment_id := NULL;
10156 		End If; -- Populate Adjustment_id
10157 
10158 		G_STMT_NO := 'process_adjustments#120';
10159 		adj_debug('In Attr loop Index '||p_Req_LINE_DETAIL_Attr_tbl(i).line_detail_index,2);
10160 		Find_Duplicate_Adj_Attribs(
10161 			p_Req_LINE_DETAIL_qual_Rec 	=> l_Req_LINE_DETAIL_qual_Rec,
10162 			p_Req_LINE_DETAIL_Attr_Rec 	=> p_Req_LINE_DETAIL_Attr_tbl(i),
10163 			p_Adj_index 				=>
10164 					l_line_details_prcd(
10165 						p_Req_LINE_DETAIL_Attr_tbl(i).line_detail_Index),
10166 			p_Line_Adj_Att_Tbl 			=> l_Line_Adj_Att_tbl,
10167 			p_Att_Type		=> 'PRICING',
10168 			p_price_adjustment_id	=> l_price_adjustment_id
10169 				);
10170 	   End If;
10171 	   i:= p_Req_LINE_DETAIL_Attr_tbl.Next(i);
10172 	 end loop;
10173 
10174 	adj_debug('Before cal #adjs '||l_Line_Adj_Tbl.count);
10175 
10176 	--If p_Req_Control_Rec.Calculate_Flag = QP_PREQ_GRP.G_SEARCH_ONLY Then
10177 	-- The calculation Engine was not called , when the price request was made
10178 		G_STMT_NO := 'process_adjustments#130';
10179 
10180                 i:=l_line_adj_tbl.first;
10181 		adj_debug('before calling calculate_price');
10182                 while i is not null loop
10183                     adj_debug('line_index:'||l_line_adj_tbl(i).line_index);
10184                     adj_debug('list line id:'||l_line_adj_tbl(i).list_line_id);
10185 		    adj_debug('operation : ' || l_line_adj_tbl(i).operation);
10186  		    IF (l_line_adj_tbl(i).operation = oe_globals.g_opr_delete
10187 			  and l_line_adj_tbl(i).list_line_type_code='PRG') THEN
10188 
10189                         adj_debug('Need to delete/update free goods line');
10190 		        /* 1503357 */
10191                         OE_ORDER_ADJ_PVT.change_prg_lines(
10192 		           p_price_adjustment_id => l_line_adj_tbl(i).price_adjustment_id,
10193                            p_line_tbl            => l_line_tbl,
10194                            p_line_adj_tbl        => l_line_adj_tbl,
10195                            p_delete_prg_lines    => l_delete_prg_lines);
10196 		     END IF;
10197                      i:=l_line_adj_tbl.next(i);
10198                   End loop;
10199 
10200 end if;  ---enforce list price flag checked
10201 
10202 		Calculate_Price (
10203 			p_Header_Rec            => p_Header_Rec
10204 			,p_Line_Tbl         	=> l_line_Tbl
10205 			,p_Line_Adj_Tbl     	=> l_Line_Adj_Tbl
10206 			,p_line_adj_assoc_Tbl   => l_line_adj_assoc_Tbl
10207 			,p_allow_negative_price => l_allow_negative_price
10208 			,p_request_Type_Code	=> p_request_Type_Code
10209                         ,p_any_line_frozen      => p_any_frozen_line
10210    ,p_price_event   => p_req_control_rec.pricing_event  --bug 2273446
10211    ,p_honor_price_flag  => p_honor_price_flag   --bug 2503186
10212 			);
10213 
10214 
10215 	adj_debug('After cal #adjs '||l_Line_Adj_Tbl.count);
10216 
10217 
10218 	G_STMT_NO := 'process_adjustments#161';
10219    I:= l_line_tbl.First;
10220    while i is not null loop
10221 
10222         If G_DEBUG Then
10223     	 adj_debug('--------------------------------------',2);
10224     	 adj_debug('index '||i,2);
10225     	 adj_debug('The list price before call'||l_line_tbl(i).unit_list_price_per_pqty,2);
10226      	 adj_debug('The selling price before call'||l_line_tbl(i).unit_Selling_price_per_pqty,2);
10227     	 adj_debug('The line id'||l_line_tbl(i).Line_id,2);
10228     	 adj_debug('The Inventory_item_id '||l_line_tbl(i).Inventory_item_id,2);
10229     	 adj_debug('The header id'||l_line_tbl(i).header_id,2);
10230          adj_debug('Payment_term , before process order '||l_line_tbl(i).payment_term_id,2);
10231         End If;
10232 
10233         -- uom begin
10234 	If oe_line_util.Get_Return_Item_Type_Code(l_line_tbl(i)) in ('INCLUDED', 'CONFIG') then
10235 		l_line_tbl(i).unit_list_price_per_pqty := 0;
10236 	end if;
10237 
10238 	If l_line_tbl(i).unit_Selling_price_per_pqty is null  or
10239 	oe_line_util.Get_Return_Item_Type_Code(l_line_tbl(i)) in ('INCLUDED', 'CONFIG')
10240 	then
10241 		l_line_tbl(i).unit_Selling_price_per_pqty := l_line_tbl(i).unit_list_price_per_pqty;
10242 	end if;
10243 
10244         If l_line_tbl(i).ordered_quantity IS NOT NULL and l_line_tbl(i).ordered_quantity <> 0
10245         then
10246           l_line_tbl(i).unit_selling_price := l_line_tbl(i).unit_selling_price_per_pqty * l_line_tbl(i).pricing_quantity/l_line_tbl(i).ordered_quantity;
10247 
10248           l_line_tbl(i).unit_list_price := l_line_tbl(i).unit_list_price_per_pqty * l_line_tbl(i).pricing_quantity/l_line_tbl(i).ordered_quantity;
10249         end if;
10250 
10251       -- OPM 2547940  start - if pricing by quantity2 then if line is shipped and has shipped qty2 != ordered qty2
10252    --  need to adjust the unit selling price so that invoicing will show correct amount (ordered qty * USP (adjusted) )
10253 
10254 	IF oe_line_util.dual_uom_control -- INVCONV
10255               (l_line_tbl(i).inventory_item_id
10256               ,l_line_tbl(i).ship_from_org_id
10257               ,l_item_rec) THEN
10258                    		IF l_item_rec.ont_pricing_qty_source = 'S'   THEN -- price by quantity 2 -- INVCONV
10259                 		  	IF (l_line_tbl(i).ordered_quantity2 IS NOT NULL and l_line_tbl(i).ordered_quantity2 <> 0	)
10260                         		AND ( l_line_tbl(i).shipped_quantity2 IS NOT NULL and l_line_tbl(i).shipped_quantity2 <> 0	)
10261                         		 AND l_line_tbl(i).ordered_quantity2 <> l_line_tbl(i).shipped_quantity2 THEN
10262 			              l_line_tbl(i).unit_selling_price := (l_line_tbl(i).unit_selling_price_per_pqty * l_line_tbl(i).pricing_quantity )/l_line_tbl(i).ordered_quantity2
10263                        		      * (l_line_tbl(i).shipped_quantity2/l_line_tbl(i).ordered_quantity);
10264                        		      l_line_tbl(i).unit_list_price := (l_line_tbl(i).unit_list_price_per_pqty * l_line_tbl(i).pricing_quantity )/l_line_tbl(i).ordered_quantity2
10265                        		      * (l_line_tbl(i).shipped_quantity2/l_line_tbl(i).ordered_quantity);
10266                				oe_debug_pub.ADD('OPM NEW USP : '|| to_char(l_line_tbl(i).unit_selling_price),5);
10267                				 END IF;
10268                	                END IF;
10269 	END IF;  --oe_line_util.dual_uom_control -- INVCONV
10270 -- OPM 2547940 end
10271 
10272 
10273         -- uom end
10274 
10275 
10276        adj_debug(' Values passed into QP_UTIL_PUB.round_price api:');
10277        adj_debug('  p_operand:'||l_line_tbl(i).unit_selling_price);
10278        adj_debug('  price_list_id:'||l_line_tbl(i).price_list_id);
10279        adj_debug('  currency_code:'||g_order_currency);
10280        adj_debug('  pricing_effective_date:'||l_line_tbl(i).pricing_date);
10281        If l_line_tbl(i).unit_selling_price is not null Then
10282         QP_UTIL_PUB.round_price(p_operand                => l_line_tbl(i).unit_selling_price,
10283 			       p_rounding_factor        => NULL,
10284 			       p_use_multi_currency     => 'Y',
10285 			       p_price_list_id          => l_line_tbl(i).price_list_id,
10286 			       p_currency_code          => g_order_currency,
10287 			       p_pricing_effective_date => l_line_tbl(i).pricing_date,
10288 			       x_rounded_operand        => l_line_tbl(i).unit_selling_price,
10289 			       x_status_code            => l_status_code);
10290         adj_debug(' Rounded Unit Selling Price Returned By pricing API:'||l_line_tbl(i).unit_selling_price);
10291         adj_debug(' x_status_code:'||l_status_code);
10292        End If;
10293 
10294 
10295     -- If a service reference line of different order is present set the operation.
10296      If l_line_tbl(i).header_id <> l_header_rec.header_id then
10297 		l_line_tbl(i).operation := oe_globals.g_opr_none;
10298      End If;
10299 
10300 
10301 	-- Remove the holes in the structure.
10302 	l_lines_prcd(i) := l_Line_Tbl_Final.Count+1;
10303 
10304     l_Line_Tbl_Final(l_lines_prcd(i)) := l_line_tbl(i);
10305 
10306     J:= x_line_tbl.First;
10307     While J is not null loop
10308 	If x_line_tbl(j).line_id = l_line_tbl(i).line_id and
10309 		l_line_tbl(i).line_id <> fnd_api.g_miss_num then
10310 		l_old_line_tbl(l_Line_Tbl_Final.Count) := x_line_tbl(j);
10311 		Exit;
10312 	end if;
10313 
10314 	j:= x_line_tbl.next(j);
10315     End Loop;
10316 
10317    l := l_line_tbl_final.count;
10318    adj_debug('operation'||l_line_tbl_final(l).operation,1);
10319      -- 2270949: logging message about free goods line
10320      if (l_line_Tbl_final(l).operation = OE_GLOBALS.G_OPR_CREATE) and p_write_to_db = TRUE then
10321                  -- Display the PRG Item
10322                  FND_MESSAGE.SET_NAME('ONT','ONT_CREATED_NEW_LINE');
10323               FND_MESSAGE.SET_TOKEN('ITEM',l_line_tbl_final(l).ordered_item);
10324    --bug 2412868  begin
10325   if l_line_tbl_final(l).line_category_code = 'RETURN' then
10326   FND_MESSAGE.SET_TOKEN('QUANTITY',(-1) * l_line_tbl_final(l).Ordered_quantity);
10327   else
10328    --bug 2412868  end
10329    FND_MESSAGE.SET_TOKEN('QUANTITY',l_line_tbl_final(l).Ordered_quantity);
10330   end if;
10331                  OE_MSG_PUB.Add('N');
10332                  OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
10333      end if;
10334      -- end 2270949
10335 
10336      -- only Lock the lines that needs to be updated
10337 	 if (l_line_tbl_final(l).operation = FND_API.G_MISS_CHAR or
10338 		l_line_tbl_final(l).operation = OE_GLOBALS.G_OPR_NONE or
10339 		l_line_tbl_final(l).operation is null )
10340                 and p_write_to_db = TRUE then
10341 
10342 
10343 	/* Fix for bug 1889762
10344 	   Added condition to check if the old and new unit selling price are the same
10345 	*/
10346         /* Added an extra condition in the following If condition to check price_list has changed.
10347            This is done to fix the bug 2242256 */
10348        If (l_line_tbl_final(l).unit_selling_price_per_pqty = l_old_line_tbl(l).unit_selling_price_per_pqty AND
10349            l_line_tbl_final(l).unit_list_price_per_pqty = l_old_line_tbl(l).unit_list_price_per_pqty AND
10350 	   l_line_tbl_final(l).unit_selling_price = l_old_line_tbl(l).unit_selling_price AND
10351            l_line_tbl_final(l).price_list_id = l_old_line_tbl(l).price_list_id AND
10352            l_line_tbl_final(l).pricing_quantity = l_old_line_tbl(l).pricing_quantity AND
10353            l_line_tbl_final(l).pricing_quantity_uom = l_old_line_tbl(l).pricing_quantity_uom AND
10354            l_line_tbl_final(l).inventory_item_id = l_old_line_tbl(l).inventory_item_id AND
10355            ((l_line_tbl_final(l).payment_term_id IS NULL AND l_old_line_tbl(l).payment_term_id IS NULL) OR
10356             l_line_tbl_final(l).payment_term_id = l_old_line_tbl(l).payment_term_id) AND
10357            ((l_line_tbl_final(l).shipping_method_code IS NULL AND l_old_line_tbl(l).shipping_method_code IS NULL) OR
10358             l_line_tbl_final(l).shipping_method_code = l_old_line_tbl(l).shipping_method_code) AND
10359            ((l_line_tbl_final(l).freight_terms_code IS NULL AND l_old_line_tbl(l).freight_terms_code IS NULL) OR
10360             l_line_tbl_final(l).freight_terms_code = l_old_line_tbl(l).freight_terms_code)
10361            )AND
10362           ((l_line_tbl_final(l).price_request_code IS NULL AND l_old_line_tbl(l).price_request_code IS NULL) OR
10363             l_line_tbl_final(l).price_request_code =l_old_line_tbl(l).price_request_code)
10364 
10365        then
10366            l_line_tbl_final(l).operation := OE_GLOBALS.G_OPR_NONE;
10367        adj_debug('do nothing to '||i||' '||l_old_line_tbl(l).line_id,1);
10368        Else
10369       	l_line_tbl_final(l).operation := OE_GLOBALS.G_OPR_UPDATE;
10370         l_num_changed_lines := l_num_changed_lines + 1;
10371        adj_debug('lock row '||i||' '||l_old_line_tbl(l).line_id,1);
10372          OE_LINE_UTIL.Lock_Row(x_return_status => x_return_status,
10373                                  p_x_line_rec => l_old_line_tbl(l)
10374                                 );
10375 
10376         IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10377 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10378 	ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
10379 		RAISE FND_API.G_EXC_ERROR;
10380 	END IF;
10381 
10382        End If;
10383      ELSIF p_write_to_db = TRUE THEN
10384         adj_debug('original operation'||l_line_tbl_final(l).operation);
10385         l_num_changed_lines := l_num_changed_lines + 1;
10386      End If;
10387 
10388     i:= l_line_tbl.next(i);
10389   end loop;
10390 adj_debug('number of changed lines'||l_num_changed_lines||' out nocopy of'||l_line_tbl_final.count);
10391 
10392 
10393    -- Delete the record with operation not set
10394 	G_STMT_NO := 'process_adjustments#140';
10395 
10396    --currently for NOT write to db mode,  which is getting-a-quote mode
10397    --this procedure is not returning adjustments details. Will
10398    --need to implement it in the later version where will return
10399    --adustment detail even if it is only a getting-a-quote mode.
10400    If p_write_to_db Then
10401 
10402    i := l_line_adj_tbl.First;
10403 
10404    While i is not null loop
10405 
10406         If G_DEBUG Then
10407 	 adj_debug('----------------------',3);
10408 	 adj_debug('The Adjustment_id '||l_Line_Adj_Tbl(i).price_adjustment_id,3);
10409 	 adj_debug('The list_line_id '||l_Line_Adj_Tbl(i).list_line_id,3);
10410 	 adj_debug('The line_id '||l_Line_Adj_Tbl(i).line_id,3);
10411 	 adj_debug('The line_typ '||l_Line_Adj_Tbl(i).list_line_type_code,3);
10412 	 adj_debug('The operation '||l_Line_Adj_Tbl(i).operation,3);
10413          adj_debug('The adjusted amount '||l_Line_Adj_Tbl(i).adjusted_amount);
10414         End If;
10415 
10416 	-- Assign the new line index
10417 	If l_line_adj_tbl(i).Line_Index is not null and
10418 				l_line_adj_tbl(i).Line_Index <> fnd_api.g_miss_num and
10419 				l_lines_prcd.exists(l_line_adj_tbl(i).Line_Index) then
10420 		l_line_adj_tbl(i).Line_Index := l_lines_prcd(l_line_adj_tbl(i).Line_Index);
10421 	End If;
10422 
10423         adj_debug(' The line_index:'||l_line_adj_tbl(i).Line_Index);
10424         -- bug 2089312
10425         -- to check if it is a Header Level Adjustment
10426         IF (l_Line_Adj_Tbl(i).line_id is null or
10427 	    l_Line_Adj_Tbl(i).line_id = fnd_api.g_miss_num)
10428 	    AND (l_Line_Adj_Tbl(i).line_index is null or
10429 	         l_Line_Adj_Tbl(i).line_index = fnd_api.g_miss_num)
10430 	    AND l_Line_Adj_Tbl(i).Header_Id = p_header_Rec.Header_Id
10431             AND l_Line_Adj_Tbl(i).operation IN (OE_GLOBALS.G_OPR_CREATE, OE_GLOBALS.G_OPR_UPDATE, OE_GLOBALS.G_OPR_DELETE)
10432             AND l_Line_Adj_Tbl(i).list_line_type_code NOT IN ('FREIGHT_CHARGE','TAX','COST')
10433             AND nvl(g_pass_all_lines,'N') <> 'Y' THEN
10434 	    -- This is a header level adjustments, and not a freight charge.
10435             -- Need to log a delayed request to apply this header level adjustment
10436             -- to all lines on this order if not all lines were passed to pricing engine.
10437 
10438             adj_debug('Logging request to update all lines for header level adjustment.', 1);
10439 	    OE_DELAYED_REQUESTS_PVT.LOG_REQUEST(
10440 			p_entity_code     	 => OE_GLOBALS.G_ENTITY_ALL,
10441 			p_entity_id              => l_Line_adj_tbl(i).header_id,
10442 			p_requesting_entity_code => OE_GLOBALS.G_ENTITY_HEADER,
10443 			p_requesting_entity_id   => l_Line_adj_tbl(i).header_id,
10444 			p_request_type           => OE_GLOBALS.G_PRICE_ADJ,
10445 			x_return_status          => l_return_status);
10446 			-- sol_ord_er #16014165
10447         -- If a manual Header Adjustment gets cascaded
10448 		oe_delayed_requests_pvt.log_request(
10449 								 p_entity_code            => OE_GLOBALS.G_ENTITY_ALL,
10450 								 p_entity_id              => l_Line_adj_tbl(i).Header_Id,
10451 								 p_requesting_entity_code => OE_GLOBALS.G_ENTITY_ALL,
10452 								 p_requesting_entity_id   => l_Line_adj_tbl(i).Header_Id,
10453 								 p_request_type           => OE_GLOBALS.G_SERVICE_FIRST_PERIOD_BILL,
10454 								 p_request_unique_key1 => 'ORDER',
10455 								 p_param1                 => l_Line_adj_tbl(i).Header_Id,
10456 								 x_return_status          => l_return_status);
10457 			IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10458 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10459 			ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
10460 				RAISE FND_API.G_EXC_ERROR;
10461 			END IF;
10462 		-- sol_ord_er #16014165 end
10463 
10464         END IF;
10465 
10466 
10467 	G_STMT_NO := 'process_adjustments#140.1';
10468 	-- Update the Header Level TERM Substitution on all Lines.
10469 	If l_header_rec.operation = oe_globals.g_opr_update then
10470 	  If l_line_adj_tbl(i).list_line_type_code = 'TSN' and
10471 		l_line_adj_tbl(i).modifier_level_code ='ORDER'
10472 	  then
10473 		adj_debug('In Header TSN ');
10474 		adj_debug('Attribute '||l_line_adj_tbl(i).substitution_attribute);
10475 		-- Loop through all the lines and update
10476 		j:= l_Line_Tbl_Final.first;
10477 		while j is not null loop
10478 			-- Check if there is a line level term substitution
10479 			l_Line_Term := FALSE;
10480 			k:= l_line_adj_tbl.First;
10481 			while k is not null loop
10482 				If l_line_adj_tbl(k).line_index =  J and
10483 					l_line_adj_tbl(k).list_line_type_code = 'TSN' and
10484 					l_line_adj_tbl(k).substitution_attribute = l_line_adj_tbl(i).substitution_attribute
10485 				Then
10486 					l_line_term := TRUE;
10487 					Exit;
10488 				End If;
10489 				k:= l_line_adj_tbl.Next(k);
10490 			End Loop; -- line_adj K
10491 
10492 			If not l_line_term then
10493 
10494 			   	If l_line_adj_tbl(i).Substitution_Attribute ='QUALIFIER_ATTRIBUTE1' Then
10495 					adj_debug('Updating Payment term '||l_line_adj_tbl(i).Modified_to);
10496 				   	l_Line_Tbl_Final(j).payment_term_id :=  l_line_adj_tbl(i).Modified_to;
10497 			   	elsIf l_line_adj_tbl(i).Substitution_Attribute ='QUALIFIER_ATTRIBUTE11' Then
10498 					adj_debug('Updating shipping_method_code '||l_line_adj_tbl(i).Modified_to);
10499 				   	l_Line_Tbl_Final(j).shipping_method_code :=  l_line_adj_tbl(i).Modified_to;
10500 
10501 			   	elsIf l_line_adj_tbl(i).Substitution_Attribute ='QUALIFIER_ATTRIBUTE10' Then
10502 					adj_debug('Updating freight_terms_code '||l_line_adj_tbl(i).Modified_to);
10503 				   	l_Line_Tbl_Final(j).freight_terms_code :=  l_line_adj_tbl(i).Modified_to;
10504 
10505 			   	End If;
10506                                 If (l_Line_Tbl_Final(j).operation = OE_GLOBALS.G_OPR_NONE) Then
10507                                         l_Line_Tbl_Final(j).operation := OE_GLOBALS.G_OPR_UPDATE;
10508                                 End If;
10509 				--adj_debug('----------------------');
10510 			End If;
10511 
10512                         --
10513                         IF l_Line_Tbl_Final(j).booked_flag = 'Y' THEN
10514                           --
10515                           IF l_Line_Tbl_Final(j).unit_selling_price IS NULL
10516                              OR l_line_tbl_final(j).unit_list_price IS NULL
10517                              OR l_line_tbl_final(j).price_list_id IS NULL THEN
10518                             --
10519                             l_item_type_code := oe_line_util.Get_Return_Item_Type_Code(l_Line_Tbl_Final(j));
10520                             --
10521                             IF (l_item_type_code <> 'CONFIG'
10522                                AND l_item_type_code <> 'INCLUDED') THEN
10523                               --
10524                               --
10525                               If l_Line_Tbl_Final(j).unit_selling_price IS NULL Then
10526                                FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQD_LINE_ATTRIBUTE');
10527 	                       FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
10528 	                         OE_Order_UTIL.Get_Attribute_Name('UNIT_SELLING_PRICE'));
10529      	                       OE_MSG_PUB.ADD;
10530                               End If;
10531 
10532                               If l_line_tbl_final(j).unit_list_price IS NULL Then
10533                                 FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQD_LINE_ATTRIBUTE');
10534 	                        FND_MESSAGE.SET_TOKEN('ATTRIBUTE',
10535 	                        OE_Order_UTIL.Get_Attribute_Name('UNIT_LIST_PRICE'));
10536      	                        OE_MSG_PUB.ADD;
10537                               End If;
10538 
10539                               If l_line_tbl_final(j).price_list_id IS NULL Then
10540                                 FND_MESSAGE.SET_NAME('ONT','OE_BOOK_REQD_LINE_ATTRIBUTE');
10541 	                        FND_MESSAGE.SET_TOKEN('ATTRIBUTE','LIST PRICE');
10542      	                        OE_MSG_PUB.ADD;
10543                               End If;
10544 
10545                               RAISE FND_API.G_EXC_ERROR;
10546                               --
10547                             END IF;
10548                             --
10549                           END IF;
10550                           --
10551                         END IF;
10552                         --
10553 
10554 		 j:= l_Line_Tbl_Final.next(j);
10555 		end loop;
10556 
10557 	  End If;
10558 	end if;
10559 	G_STMT_NO := 'process_adjustments#140.2';
10560 	if l_line_adj_tbl(i).operation = fnd_api.g_miss_char  or
10561 		l_Line_Adj_Tbl(i).list_line_type_code in ('TAX','COST')
10562 		or l_line_adj_tbl(i).operation is null
10563 		or l_line_adj_tbl(i).operation =oe_globals.g_opr_none then
10564 		l_line_adj_tbl.delete(i);
10565 	Elsif l_line_adj_tbl(i).operation = oe_globals.g_opr_update and
10566 		( l_line_adj_tbl(i).price_adjustment_id is null or
10567 		l_line_adj_tbl(i).price_adjustment_id = fnd_api.g_miss_num ) then
10568 		l_line_adj_tbl(i).operation := oe_globals.g_opr_Create;
10569   	ELsif l_line_adj_tbl(i).line_id IS NOT NULL and
10570 	      l_line_adj_tbl(i).line_id <> FND_API.G_MISS_NUM and
10571 	      l_delete_prg_lines.exists(l_line_adj_tbl(i).line_id) THEN
10572               l_line_adj_tbl.delete(i);
10573 	End if;
10574 
10575 
10576 	i:= l_line_adj_tbl.next(i);
10577    End loop;
10578 
10579    G_STMT_NO := 'process_adjustments#150';
10580    i:= l_line_adj_att_tbl.First;
10581 
10582    while i is not null loop
10583                 If G_DEBUG Then
10584 		 adj_debug('Adj Index '||l_line_adj_Att_tbl(i).Adj_Index,3);
10585 		 Adj_Debug('The Price Adj '||l_line_adj_Att_tbl(i).price_adjustment_id,3);
10586 		 Adj_Debug('Operation '||l_line_adj_Att_tbl(i).operation,3);
10587 		 Adj_Debug('flex_title '||l_line_adj_Att_tbl(i).flex_title,3);
10588 		 Adj_Debug('pricing_context '||l_line_adj_Att_tbl(i).pricing_context,3);
10589 		 Adj_Debug('pricing_attribute '||l_line_adj_Att_tbl(i).pricing_attribute,3);
10590 		 Adj_Debug('pricing_attr_value_from '||l_line_adj_Att_tbl(i).pricing_attr_value_from,3);
10591 		 Adj_Debug('pricing_attr_value_To '||l_line_adj_Att_tbl(i).pricing_attr_value_To,3);
10592 		 Adj_Debug('comparison_operator '||l_line_adj_Att_tbl(i).comparison_operator,3);
10593 		 Adj_Debug('------------------------------',3);
10594                 End If;
10595 
10596 	if l_line_adj_Att_tbl(i).operation = fnd_api.g_miss_char then
10597 		l_line_adj_Att_tbl.delete(i);
10598 	Elsif l_line_adj_Att_tbl(i).price_adjustment_id = fnd_api.g_miss_num or
10599 		l_line_adj_Att_tbl(i).price_adjustment_id is null Then
10600 
10601 		-- Check if the adjustment record exists
10602 		If l_line_adj_Att_tbl(i).Adj_Index = fnd_api.g_miss_num Then
10603 			l_line_adj_Att_tbl.delete(i);
10604 		ElsIf Not l_line_adj_tbl.exists(l_line_adj_Att_tbl(i).Adj_Index) Then
10605 			l_line_adj_Att_tbl.delete(i);
10606 		End If;
10607 
10608 	end if;
10609 
10610 	i:= l_line_adj_att_tbl.next(i);
10611 
10612    End loop;
10613 
10614 
10615    G_STMT_NO := 'process_adjustments#160';
10616   i:= l_Line_Adj_Assoc_tbl.First;
10617   While i is not null loop
10618         If G_Debug Then
10619 	 adj_debug('Assocs: adj index '||l_Line_Adj_Assoc_tbl(i).adj_index,3);
10620 	 adj_debug('Assocs: rltd adj index '||l_Line_Adj_Assoc_tbl(i).Rltd_Adj_Index,3);
10621 	 adj_debug('Assocs: price adj '||l_Line_Adj_Assoc_tbl(i).price_adjustment_id,3);
10622 	 adj_debug('Assocs: rltd price adj '||l_Line_Adj_Assoc_tbl(i).rltd_Price_Adj_Id,3);
10623 	 adj_debug('---------------------------',3);
10624         End If;
10625 	If l_Line_Adj_Assoc_tbl(i).operation = Fnd_Api.g_Miss_Char Then
10626 		l_Line_Adj_Assoc_tbl.delete(i);
10627 	Else
10628 		if l_Line_Adj_Assoc_tbl(i).Price_Adjustment_Id = fnd_Api.g_miss_num and
10629 			l_Line_Adj_Assoc_tbl(i).adj_index = fnd_Api.g_miss_num Then
10630 					l_Line_Adj_Assoc_tbl.delete(i);
10631 		Elsif   l_Line_Adj_Assoc_tbl(i).Adj_Index <> fnd_Api.g_miss_num and
10632 				Not l_line_adj_tbl.exists(l_Line_Adj_Assoc_tbl(i).Adj_Index) Then
10633 			l_Line_Adj_Assoc_tbl.delete(i);
10634 		Elsif	l_Line_Adj_Assoc_tbl(i).rltd_Price_Adj_Id = fnd_Api.g_miss_num and
10635 			l_Line_Adj_Assoc_tbl(i).Rltd_Adj_Index = fnd_Api.g_miss_num Then
10636 			l_Line_Adj_Assoc_tbl.delete(i);
10637 		Elsif l_Line_Adj_Assoc_tbl(i).Rltd_Adj_Index <> fnd_Api.g_miss_num and
10638 			Not l_line_adj_tbl.exists(l_Line_Adj_Assoc_tbl(i).Rltd_Adj_Index) Then
10639                 IF l_line_detail_replaced.exists(l_line_adj_assoc_tbl(i).rltd_adj_index) THEN
10640                       l_line_adj_assoc_tbl(i).rltd_adj_index
10641                           := l_line_detail_replaced(l_line_adj_assoc_tbl(i).rltd_adj_index);
10642                  ELSE
10643                     l_Line_Adj_Assoc_tbl.delete(i);
10644                  END IF;
10645 		End If;
10646 	End If;
10647 	i:= l_Line_Adj_Assoc_tbl.next(i);
10648   End Loop;
10649 
10650    G_STMT_NO := 'process_adjustments#170.0';
10651         If G_Debug Then
10652 	 adj_debug('Header id '||l_header_rec.header_id);
10653 	 adj_debug('payment term '||l_header_rec.payment_term_id);
10654 	 adj_debug('Ship term '||l_header_rec.shipping_method_code);
10655 	 adj_debug('Freight  term '||l_header_rec.freight_terms_code);
10656 	 adj_debug('operantion  '||l_header_rec.operation);
10657 	 adj_debug('---------------------------');
10658         End If;
10659 
10660    G_STMT_NO := 'process_adjustments#170';
10661 End If;  --end if for p_write_to_db mode
10662 
10663   -- Audit Trail reason code passed #3006072 */
10664 
10665   adj_debug('Line final table count is : '||l_line_tbl_final.count);
10666 
10667   IF l_line_tbl_final.count > 0 THEN
10668 
10669      FOR rec_cnt in l_line_tbl_final.first..l_line_tbl_final.last LOOP
10670 
10671          adj_debug('Line ID processed : '||l_line_tbl_final(rec_cnt).line_id);
10672 
10673          l_line_tbl_final(rec_cnt).change_reason := 'SYSTEM';
10674          l_line_tbl_final(rec_cnt).change_comments := 'PRICING';
10675 
10676      END LOOP;
10677 
10678   END IF;
10679 
10680   -- bug 2404990 begin
10681   x_line_tbl := l_line_tbl_final;
10682   IF (p_write_to_db and l_num_changed_lines<1+l_line_tbl_final.count/2) THEN
10683                 j:= l_Line_Tbl_Final.first;
10684                 while j is not null loop
10685                    IF (l_line_tbl_final(j).operation = OE_GLOBALS.G_OPR_NONE) THEN
10686                      l_line_tbl_Final.delete(j);
10687                    END IF;
10688                  j:= l_Line_Tbl_Final.next(j);
10689                 end loop;
10690 
10691   End If;  --end if for p_write_to_db mode
10692   -- bug 2404990 end
10693 
10694 
10695   If p_Write_To_Db  and
10696 	(	l_line_tbl_Final.count > 0 or
10697 		l_Line_Adj_tbl.count > 0 or
10698 		l_Line_Adj_att_tbl.count > 0 or
10699 		l_Line_Adj_Assoc_tbl.count > 0
10700 	 )
10701 	Then
10702 
10703 
10704    -- set control record
10705    l_control_rec.controlled_operation := TRUE;
10706    l_control_rec.write_to_DB          := TRUE;
10707    l_control_rec.change_attributes    := TRUE;
10708    l_control_rec.default_attributes   := TRUE;
10709    l_control_rec.validate_entity      := TRUE;
10710    l_control_rec.clear_dependents     := TRUE;
10711    --change made for bug 2351099    Begin
10712    --2366123: execute delayed requests if not from UI
10713    if (NOT OE_GLOBALS.G_UI_FLAG ) then
10714     l_control_rec.process   := TRUE;
10715    else
10716      l_control_rec.process  := FALSE;
10717    end if;
10718    --change made for bug 2351099    End
10719    l_control_rec.clear_api_cache      := FALSE;
10720    l_control_rec.clear_api_requests   := FALSE;
10721 
10722 
10723     --  Call OE_Order_PVT.Process_order
10724 
10725 	adj_debug('Before OE_Order_PVT.Process_order',1);
10726    IF (oe_globals.G_CASCADING_REQUEST_LOGGED) THEN
10727      adj_debug('inside price line: cascading set');
10728    ELSE
10729      adj_debug('inside price line: cascading not set');
10730    END IF;
10731 	--  OE_Globals.G_RECURSION_MODE := 'Y';
10732 	 OE_Globals.G_PRICING_RECURSION := 'Y';
10733 
10734 		G_STMT_NO := 'Failure in Process_Order API Call';
10735   --cc1
10736   IF (p_Req_Control_Rec.pricing_event = 'PRICE' AND
10737      l_Line_Adj_tbl.count = 0 AND
10738      l_Line_Adj_att_tbl.count = 0 AND
10739      l_Line_Adj_Assoc_tbl.count = 0
10740    ) THEN
10741     OE_ORDER_PVT.Lines
10742     (   p_validation_level            => FND_API.G_VALID_LEVEL_FULL
10743     ,   p_control_rec                 => l_control_rec
10744     ,   p_x_line_tbl                    => l_line_tbl_Final
10745     ,   p_x_old_line_tbl                => l_old_line_tbl
10746     ,   x_return_status                => x_return_status
10747     );
10748 
10749     IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10750 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10751 	ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
10752 		RAISE FND_API.G_EXC_ERROR;
10753 	END IF;
10754 
10755   ELSE
10756     OE_Order_PVT.Process_order
10757     (   p_api_version_number          => 1.0
10758     ,   x_return_status               => x_return_status
10759     ,   x_msg_count                   => l_x_msg_count
10760     ,   x_msg_data                    => l_x_msg_data
10761     ,   p_control_rec                 => l_control_rec
10762     ,   p_x_Header_rec                    => l_header_rec
10763     ,   p_x_line_tbl                    => l_line_tbl_Final
10764     ,   p_x_Line_Adj_tbl                => l_Line_Adj_tbl
10765     ,   p_x_Line_Adj_att_tbl            => l_Line_Adj_att_tbl
10766     ,   p_x_Line_Adj_Assoc_tbl          => l_Line_Adj_Assoc_tbl
10767     ,   p_old_line_tbl                => l_old_line_tbl
10768 --    ,   x_header_rec                  => l_x_header_rec
10769     ,   p_x_Header_Adj_tbl              => l_x_Header_Adj_tbl
10770     ,   p_x_header_price_att_tbl        => l_x_header_price_att_tbl
10771     ,   p_x_Header_Adj_att_tbl          => l_x_Header_Adj_att_tbl
10772     ,   p_x_Header_Adj_Assoc_tbl        => l_x_Header_Adj_Assoc_tbl
10773     ,   p_x_Header_Scredit_tbl          => l_x_Header_Scredit_tbl
10774 --serla begin
10775     ,   p_x_Header_Payment_tbl          => l_x_Header_Payment_tbl
10776 --serla end
10777 --    ,   x_line_tbl                    => l_x_line_tbl
10778 --    ,   x_Line_Adj_tbl                => l_x_Line_Adj_tbl
10779     ,   p_x_Line_Price_att_tbl          => l_x_Line_Price_att_tbl
10780 --    ,   x_Line_Adj_att_tbl            => l_x_Line_Adj_att_tbl
10781 --    ,   x_Line_Adj_Assoc_tbl          => l_x_Line_Adj_Assoc_tbl
10782     ,   p_x_Line_Scredit_tbl            => l_x_Line_Scredit_tbl
10783 --serla begin
10784     ,   p_x_Line_Payment_tbl            => l_x_Line_Payment_tbl
10785 --serla end
10786     ,   p_x_Lot_Serial_tbl              => l_x_Lot_Serial_Tbl
10787     ,   p_x_action_request_tbl	      => l_x_Action_Request_tbl
10788     );
10789 
10790      -- OE_Globals.G_RECURSION_MODE := 'N';
10791      OE_Globals.G_PRICING_RECURSION := 'N';
10792 
10793     IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10794 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10795 	ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
10796 		RAISE FND_API.G_EXC_ERROR;
10797     END IF;
10798 
10799 END IF;
10800 
10801  G_STMT_NO := 'process_adjustments#140';
10802 /*
10803  -- Process Requests for Pricing line (for new line created for PRG)
10804     OE_DELAYED_REQUESTS_PVT.Process_Request_for_Reqtype
10805          (p_request_type   =>OE_GLOBALS.G_PRICE_LINE
10806           ,p_delete        => FND_API.G_TRUE
10807           ,x_return_status => x_return_status
10808           );
10809     IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10810           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10811     ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
10812           RAISE FND_API.G_EXC_ERROR;
10813     END IF;
10814 */
10815   End If;
10816 
10817 --	x_Line_Tbl	 := l_Line_Tbl_Final;
10818 	G_STMT_NO := 'process_adjustments#150';
10819 
10820          -- Performance change for Legato
10821          -- Not refresh order when no attributes changed
10822          -- Freight charge change doesn't result in line change
10823          If p_req_control_rec.pricing_event in ('ORDER','SHIP','BOOK', 'BATCH') then
10824            IF (l_num_changed_lines > 0) THEN
10825             adj_debug('setting cascading flag to refresh order');
10826             OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
10827            END IF;
10828          Elsif INSTR(p_req_control_rec.pricing_event,'ORDER') > 0  or
10829                INSTR(p_req_control_rec.pricing_event,'BOOK')  > 0  or
10830                INSTR(p_req_control_rec.pricing_event,'BATCH')  > 0  or
10831                INSTR(p_req_control_rec.pricing_event,'SHIP')  > 0  then
10832            IF (l_num_changed_lines > 0) THEN
10833             adj_debug(' multiple events setting cascading flag to refresh order');
10834             OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
10835            END IF;
10836          End if;
10837 
10838 	adj_debug('Exiting oe_order_Adj_pvt.process_adjustments',1);
10839 
10840 
10841     EXCEPTION
10842 
10843 	    WHEN FND_API.G_EXC_ERROR THEN
10844 
10845 		  x_return_status := FND_API.G_RET_STS_ERROR;
10846 			adj_debug('		exc_error'||g_stmt_no||' '||sqlerrm||' '||l_x_msg_data,1);
10847                         -- OE_Globals.G_RECURSION_MODE := 'N';
10848                         OE_Globals.G_PRICING_RECURSION := 'N';
10849 
10850 			RAISE FND_API.G_EXC_ERROR;
10851 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10852 
10853 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10854 			adj_debug('		'||g_stmt_no||' '||sqlerrm||' '||l_x_msg_data,1);
10855 
10856                         -- OE_Globals.G_RECURSION_MODE := 'N';
10857                         OE_Globals.G_PRICING_RECURSION := 'N';
10858 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10859 
10860 		WHEN OTHERS THEN
10861 
10862 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10863 			--dbms_output.put_line('Error is '||sqlerrm);
10864 			adj_debug('Error in oe_order_Adj_pvt.process_adjustments',1);
10865 			adj_debug('		'||g_stmt_no||' '||sqlerrm,1);
10866 
10867 			IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10868 			THEN
10869 				OE_MSG_PUB.Add_Exc_Msg
10870 				(   G_PKG_NAME
10871 				,   'oe_order_Adj_pvt.process_adjustments',
10872 					g_stmt_no||' '||sqlerrm
10873 				);
10874 			END IF;
10875 
10876                         -- OE_Globals.G_RECURSION_MODE := 'N';
10877                         OE_Globals.G_PRICING_RECURSION := 'N';
10878 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10879 
10880 end process_adjustments;
10881 
10882 Procedure Populate_Pricing_Phases(p_pricing_event in Varchar2) Is
10883 
10884 Cursor get_phases(l_event_code1 in Varchar2) Is
10885  Select e.Pricing_Phase_Id,nvl(p.user_freeze_override_flag,p.freeze_override_flag) freeze_override_flag
10886 		   from qp_event_Phases e, qp_pricing_phases p
10887 		   where e.pricing_phase_id = p.pricing_phase_id and
10888 		   trunc(sysdate) between Trunc(nvl(start_date_active,sysdate)) and
10889 			 trunc(nvl(End_Date_Active,sysdate))
10890                        and e.pricing_event_code IN
10891                     (SELECT decode(rownum
10892           ,1 ,substr(p_pricing_event,1,instr(l_event_code1,',',1,1)-1)
10893           ,2 ,substr(p_pricing_event , instr(l_event_code1,',',1,rownum-1) + 1,
10894              instr(l_event_code1,',',1,rownum)-1 - instr(l_event_code1,',',1,rownum-1))
10895           ,3 ,substr(p_pricing_event , instr(l_event_code1,',',1,rownum-1) + 1,
10896               instr(l_event_code1,',',1,rownum)-1 - instr(l_event_code1,',',1,rownum-1))
10897           ,4 ,substr(p_pricing_event , instr(l_event_code1,',',1,rownum-1) + 1,
10898               instr(l_event_code1,',',1,rownum)-1 - instr(l_event_code1,',',1,rownum-1))
10899           ,5 ,substr(p_pricing_event , instr(l_event_code1,',',1,rownum-1) + 1,
10900               instr(l_event_code1,',',1,rownum)-1 - instr(l_event_code1,',',1,rownum-1))
10901           ,6 ,substr(p_pricing_event , instr(l_event_code1,',',1,rownum-1) + 1,
10902               instr(l_event_code1,',',1,rownum)-1 - instr(l_event_code1,',',1,rownum-1)))
10903          FROM  qp_event_phases
10904          WHERE rownum < 7);
10905 Begin
10906 
10907 G_Pricing_Phase_Id_Tbl.delete;
10908   --null;
10909  For i in get_phases(p_pricing_event||',') Loop
10910   G_Pricing_Phase_id_Tbl(i.pricing_phase_id):=i.freeze_override_flag;
10911   adj_debug('Pricing Phase:'||i.pricing_phase_id);
10912   adj_debug('Freeze Override:'||i.freeze_override_flag);
10913  End Loop;
10914 End;
10915 
10916 Function Bypass_Performance_Path(
10917   p_Header_id        Number Default Null
10918 , p_Line_id          Number Default Null
10919 , px_line_tbl         IN OUT NOCOPY OE_Order_Pub.Line_Tbl_Type
10920 ) Return Boolean
10921 IS
10922 l_source_document_type_id NUMBER;
10923 l_booked_flag Varchar2(1);
10924 l_header_rec OE_Order_PUB.Header_Rec_Type;
10925 l_header_id NUMBER;
10926 l_tmp_no number;
10927 Begin
10928 
10929   IF OE_GLOBALS.G_GMI_INSTALLED IS NULL THEN -- OPM 2547940 start GMA = OPM
10930       OE_GLOBALS.G_GMI_INSTALLED := OE_GLOBALS.CHECK_PRODUCT_INSTALLED(550);
10931   END IF;
10932 
10933   If (OE_GLOBALS.G_GMI_INSTALLED = 'Y')
10934                 and nvl(OE_LINE_ADJ_UTIL.G_OPM_ITEM_CATCHWEIGHT_USED,'N') = 'Y'   -- bug 2965218
10935   Then
10936       adj_debug('OPM - GMA installed');
10937       RETURN TRUE;
10938   End If;   -- OPM 2547940 end
10939 
10940 
10941   IF OE_GLOBALS.G_ASO_INSTALLED IS NULL THEN
10942       OE_GLOBALS.G_ASO_INSTALLED := OE_GLOBALS.CHECK_PRODUCT_INSTALLED(697);
10943   END IF;
10944 
10945   If (OE_GLOBALS.G_ASO_INSTALLED = 'N') Then
10946     adj_debug('aso not installed');
10947     RETURN FALSE;
10948   End If;
10949 
10950   IF (nvl(fnd_profile.value('ONT_ALWAYS_PERF_PATH'), 'N') = 'Y') THEN
10951     adj_debug('always use performance path');
10952     RETURN FALSE;
10953   END IF;
10954 
10955   -- ASO installed; check whether it's a CRM order
10956   If (p_Header_id Is Not Null AND p_header_id <> FND_API.G_MISS_NUM) Then
10957       adj_debug('query source document type for header :'||p_header_id);
10958      OE_Header_Util.Query_Row(p_header_id => p_header_id
10959                             , x_header_rec => l_header_rec);
10960       l_source_document_type_id := l_header_rec.source_document_type_id;
10961       l_booked_flag := l_header_rec.booked_flag;
10962       l_header_id := p_header_id;
10963   Else
10964     if (px_line_tbl.count = 0 and (p_line_id is Null OR p_line_id = FND_API.G_MISS_NUM)) Then
10965 
10966 		IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_ERROR)
10967 		THEN
10968 
10969 		    FND_MESSAGE.SET_NAME('ONT','OE_ATTRIBUTE_REQUIRED');
10970 		    FND_MESSAGE.SET_TOKEN('ATTRIBUTE','line_id or Header Id ');
10971 		    OE_MSG_PUB.Add;
10972 		END IF;
10973 		RAISE FND_API.G_EXC_ERROR;
10974     elsif (px_line_Tbl.count = 0) Then
10975      OE_Line_Util.Query_Rows(p_line_id => p_line_id
10976                             , x_line_tbl => px_line_tbl);
10977     end if;
10978     adj_debug('lines count'||px_line_tbl.count);
10979     l_source_document_type_id := px_line_Tbl(1).source_document_type_id;
10980     l_booked_flag := px_line_Tbl(1).booked_flag;
10981     l_header_id := px_line_tbl(1).header_id;
10982   End If;
10983 
10984   adj_debug('source_document_type:'||l_source_document_type_id);
10985   If (nvl(l_booked_flag, 'N') = 'Y'
10986       and nvl(l_source_document_type_id, 0) IN (1, 3, 4, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18 , 19))
10987   Then
10988       adj_debug('booked CRM order');
10989       Return TRUE;
10990   Elsif (nvl(l_booked_flag, 'N') = 'Y')  --begin 2608577
10991   Then
10992      -- check whether there is an AMS modifier defined
10993       adj_debug('in ams mod check ');
10994      BEGIN
10995        SELECT 1 into l_tmp_no from dual where exists (
10996         select 1 from qp_list_headers_b qh
10997         , oe_order_headers_all oh
10998         where qh.currency_code = oh.transactional_curr_code
10999         and oh.header_id =  l_header_id
11000         and qh.source_system_code='AMS'
11001         and qh.active_flag = 'Y');
11002      EXCEPTION
11003        WHEN NO_DATA_FOUND THEN
11004          RETURN FALSE;
11005        WHEN OTHERS THEN
11006          NULL;
11007      END;
11008      RETURN TRUE;    -- end 2608577
11009   Else
11010       Return FALSE;
11011   End If;
11012 EXCEPTION
11013   WHEN FND_API.G_EXC_ERROR THEN
11014     RAISE FND_API.G_EXC_ERROR;
11015   WHEN OTHERS THEN
11016    adj_debug('error in bypass_performance_path'||sqlerrm);
11017    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11018 End Bypass_Performance_Path;
11019 
11020 Procedure Price_line(
11021 X_Return_Status out nocopy Varchar2
11022 
11023 		,p_Line_id          	Number	Default Null
11024 		,p_Header_id        	Number 	Default Null
11025 		,p_Request_Type_code	Varchar2
11026 		,p_Control_Rec			QP_PREQ_GRP.control_record_type
11027 		,p_write_to_db			Boolean 	Default TRUE
11028 		,p_request_rec          OE_Order_PUB.request_rec_type default oe_order_pub.G_MISS_REQUEST_REC
11029 		,x_line_Tbl		in out nocopy oe_Order_Pub.Line_Tbl_Type
11030 		,p_honor_price_flag		VARCHAR2	Default 'Y'
11031                 ,p_multiple_events       in Varchar2 default 'N'
11032                 ,p_action_code          in Varchar2 default Null
11033 		)
11034 is
11035 l_return_status 			varchar2(10);
11036 l_Control_Rec                 QP_PREQ_GRP.CONTROL_RECORD_TYPE;
11037 l_req_line_tbl                QP_PREQ_GRP.LINE_TBL_TYPE;
11038 l_Req_qual_tbl                QP_PREQ_GRP.QUAL_TBL_TYPE;
11039 l_Req_line_attr_tbl           QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
11040 l_Req_LINE_DETAIL_tbl         QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
11041 l_Req_LINE_DETAIL_qual_tbl    QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
11042 l_Req_LINE_DETAIL_attr_tbl    QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
11043 l_Req_related_lines_tbl       QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
11044 lx_Header_Rec				oe_Order_Pub.Header_REc_Type;
11045 l_dummy varchar2(1);
11046 l_any_frozen_line Boolean;
11047 l_price_control_rec           OE_ORDER_PRICE_pvt.control_rec_type;
11048 --For bug#2675212
11049 i pls_integer;
11050 l_call_process_adjustments varchar2(1) := 'N';
11051 cursor check_lines is
11052   select 'x' from qp_event_phases ep
11053   where ep.pricing_event_code = p_control_rec.pricing_event
11054   and trunc(sysdate) between trunc(nvl(start_date_active, sysdate)) and
11055 				  trunc(nvl(end_date_active, sysdate));
11056 /*cursor check_lines2 is
11057   select 'x' from qp_event_phases ep
11058   where ep.pricing_event_code IN ('BATCH','BOOK','SHIP')
11059   and trunc(sysdate) between trunc(nvl(start_date_active, sysdate)) and
11060 				  trunc(nvl(end_date_active, sysdate));*/
11061 
11062 cursor check_lines2 is
11063   select 'x' from qp_event_phases ep
11064   where instr(p_control_rec.pricing_event||',',
11065 ep.pricing_event_code||',') > 0
11066   and trunc(sysdate) between trunc(nvl(start_date_active, sysdate)) and
11067                                   trunc(nvl(end_date_active, sysdate));
11068 
11069 l_multiple_events VARCHAR2(1);
11070 cursor unfrozen_lines is
11071   select 'x' from dual where
11072    exists (select 'x' from oe_order_lines where header_id = p_header_id
11073            and calculate_price_flag in ('Y','P'));
11074 begin
11075    x_return_status := FND_API.G_RET_STS_SUCCESS;
11076 
11077    --btea perf begin
11078    If OE_DEBUG_PUB.G_DEBUG = FND_API.G_TRUE Then
11079     G_DEBUG := TRUE;
11080     adj_debug('Entering  oe_order_Adj_pvt.Price_line',1);
11081     adj_debug('Version:'||get_version);
11082    Else
11083     G_DEBUG := FALSE;
11084    End If;
11085    --btea perf end
11086 
11087 
11088 Populate_Pricing_Phases(p_control_rec.pricing_event);
11089 
11090 IF (INSTR(p_control_rec.pricing_event, ',') > 0) THEN
11091  l_multiple_events := 'Y';
11092 ELSE
11093  l_multiple_events := 'N';
11094 END IF;
11095 
11096 If l_multiple_events = 'N' Then
11097   open check_lines;
11098   fetch check_lines into l_dummy;
11099   IF check_lines%NOTFOUND THEN
11100     close check_lines;
11101     RETURN;
11102   End If;
11103 Else
11104   Oe_Debug_Pub.add('In Multiple events');
11105   open check_lines2;
11106   fetch check_lines2 into l_dummy;
11107   IF check_lines2%NOTFOUND THEN
11108     close check_lines2;
11109     RETURN;
11110   End If;
11111 END IF;
11112 
11113   -- 2378843: check the existence of any line with 'Partial Price' or 'Calculate Price'
11114   IF (p_header_id IS NOT NULL and p_honor_price_flag = 'Y' and p_control_rec.pricing_event <> 'SHIP') THEN
11115     open unfrozen_lines;
11116     fetch unfrozen_lines into l_dummy;
11117     IF unfrozen_lines%NOTFOUND THEN
11118       close unfrozen_lines;
11119       adj_debug('all lines frozen, returning from price_line');
11120       RETURN;
11121     END IF;
11122     close unfrozen_lines;
11123   END IF;
11124   -- End 2378843
11125 
11126   IF (G_11IG_PERFORMANCE = 'Y' AND QP_UTIL_PUB.Basic_Pricing_Setup = 'Y'
11127   AND Not Bypass_Performance_Path(  p_header_id => p_header_id
11128                                   , p_line_id   => p_line_id
11129                                   , px_line_Tbl  => x_line_tbl))
11130    OR OE_CODE_CONTROL.Get_Code_Release_Level >= '110509' THEN
11131   l_price_control_rec.p_request_type_code:=p_request_type_code;
11132   l_Price_control_rec.p_write_to_db:=p_write_to_db;
11133   l_price_control_rec.p_honor_price_flag:=p_honor_price_flag;
11134   l_price_control_rec.p_multiple_events:=l_multiple_events;
11135   l_price_control_rec.p_get_freight_flag := p_Control_rec.get_freight_flag;
11136 
11137   oe_order_price_pvt.price_line
11138                  (p_Header_id    => p_Header_id
11139                  ,p_Line_id             =>p_Line_id
11140                  ,px_line_Tbl           =>x_line_tbl
11141                  ,p_Control_Rec         =>l_price_control_rec
11142                  ,p_action_code         =>p_action_code
11143                  ,p_Pricing_Events      =>p_Control_rec.pricing_event
11144                  ,p_request_rec          =>p_request_rec
11145                  ,x_Return_Status       =>l_return_status
11146                  );
11147 
11148   If nvl(l_return_status,'x-x') NOT IN (FND_API.G_RET_STS_UNEXP_ERROR,FND_API.G_RET_STS_ERROR) Then
11149      l_return_status:=FND_API.G_RET_STS_SUCCESS;
11150   End If;
11151 
11152 -- added for HVOP Tax project
11153  IF OE_BULK_ORDER_PVT.G_HEADER_REC.HEADER_ID.COUNT > 0 THEN
11154      OE_BULK_PRICE_PVT.Update_Pricing_Attributes(p_line_tbl => x_line_tbl);
11155  END IF;
11156 
11157 
11158   x_return_status := l_return_status;
11159   RETURN;
11160 END IF;
11161 
11162 
11163 adj_debug('Exiting oe_order_Adj_pvt.Price_line',1);
11164 
11165 
11166 
11167 	Exception
11168 	    WHEN FND_API.G_EXC_ERROR THEN
11169 
11170 		  x_return_status := FND_API.G_RET_STS_ERROR;
11171 
11172                 --Bug 7566697
11173                 adj_debug('Setting prcing error flag for mass change');
11174                 OE_MASS_CHANGE_PVT.G_PRICING_ERROR := 'Y';
11175 
11176 		adj_debug('Exiting oe_order_Adj_pvt.Price_line',1);
11177 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11178 
11179 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11180 
11181                         --Bug 7566697
11182                         adj_debug('Setting prcing error flag for mass change');
11183                         OE_MASS_CHANGE_PVT.G_PRICING_ERROR := 'Y';
11184 
11185 			adj_debug('Exiting oe_order_Adj_pvt.Price_line',1);
11186 	    WHEN OTHERS THEN
11187 
11188 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11189 			adj_debug('Error in oe_order_Adj_pvt.Price_line',1);
11190 			adj_debug(sqlerrm,1);
11191 
11192 			IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
11193 			THEN
11194 				OE_MSG_PUB.Add_Exc_Msg
11195 				(   G_PKG_NAME
11196 				,   'Price_line',
11197 					sqlerrm
11198 				);
11199 			END IF;
11200 
11201                         --Bug 7566697
11202                         adj_debug('Setting prcing error flag for mass change');
11203                         OE_MASS_CHANGE_PVT.G_PRICING_ERROR := 'Y';
11204 
11205 			adj_debug('Exiting oe_order_Adj_pvt.Price_line',1);
11206 			--RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11207 
11208 End Price_line;
11209 
11210 Procedure Price_Adjustments(
11211 X_Return_Status out nocopy Varchar2
11212 
11213 	,p_Header_id             Number    DEfault null
11214 	,p_Line_id               Number    DEfault null
11215 	,p_request_type_code	varchar2
11216 	,p_request_rec          OE_Order_PUB.request_rec_type default oe_order_pub.G_MISS_REQUEST_REC
11217 
11218 )
11219 is
11220 l_Req_Control_Rec             QP_PREQ_GRP.CONTROL_RECORD_TYPE;
11221 l_control_rec				Oe_Globals.Control_rec_type;
11222 l_Line_tbl            		OE_Order_PUB.Line_tbl_type;
11223 l_old_Line_tbl                  OE_Order_PUB.Line_tbl_type;
11224 l_Line_tbl1            		OE_Order_PUB.Line_tbl_type;
11225 l_Line_Adj_Att_tbl            OE_Order_PUB.Line_Adj_Att_tbl_type;
11226 l_Line_Adj_tbl                OE_Order_PUB.Line_Adj_Tbl_Type;
11227 l_Old_Line_Adj_tbl            OE_Order_PUB.Line_Adj_Tbl_Type;
11228 l_Line_Adj_Assoc_tbl          OE_Order_PUB.Line_Adj_Assoc_tbl_type;
11229 l_dummy_adj_assoc_tbl         OE_Order_PUB.line_adj_assoc_tbl_type;
11230 l_header_rec                  OE_Order_PUB.Header_Rec_Type;
11231 l_x_header_rec                OE_Order_PUB.Header_Rec_Type;
11232 l_x_Header_Adj_tbl            OE_Order_PUB.Header_Adj_Tbl_Type;
11233 l_x_Header_Scredit_tbl        OE_Order_PUB.Header_Scredit_Tbl_Type;
11234 --l_x_line_tbl                  OE_Order_PUB.Line_Tbl_Type;
11235 --l_x_Line_Adj_tbl              OE_Order_PUB.Line_Adj_Tbl_Type;
11236 l_x_Line_Scredit_tbl          OE_Order_PUB.Line_Scredit_Tbl_Type;
11237 l_x_action_request_tbl        OE_Order_PUB.request_tbl_type;
11238 l_x_lot_serial_tbl            OE_Order_PUB.lot_serial_tbl_type;
11239 l_x_Header_price_Att_tbl      OE_Order_PUB.Header_price_Att_tbl_type;
11240 l_x_Header_Adj_Att_tbl        OE_Order_PUB.Header_Adj_Att_tbl_type;
11241 l_x_Header_Adj_Assoc_tbl      OE_Order_PUB.Header_Adj_Assoc_tbl_type;
11242 l_x_Line_price_Att_tbl        OE_Order_PUB.Line_price_Att_tbl_type;
11243 l_x_Line_Adj_Att_tbl          OE_Order_PUB.Line_Adj_Att_tbl_type;
11244 l_x_Line_Adj_Assoc_tbl        OE_Order_PUB.Line_Adj_Assoc_tbl_type;
11245 l_x_msg_count                   number;
11246 l_x_msg_data                    Varchar2(2000);
11247 i						pls_integer;
11248 l_line_index				pls_integer;
11249 l_allow_negative_price		Varchar2(30) := nvl(fnd_profile.value('ONT_NEGATIVE_PRICING'),'N');
11250 --Manual Begin
11251 --Set calculate price flag to 'P'  when manual adjustment is applied
11252 l_set_price_flag_on_manual   Varchar2(30) := nvl(fnd_profile.value('ONT_SET_PRICE_FLAG_ON_MANUAL'),'N');
11253 --Manual End
11254 l_dummy key_tbl_type;
11255 l_updated_flag varchar2(1);
11256 l_dummy_line_rec Oe_Order_Pub.Line_Rec_Type;
11257 l_price_control_rec OE_ORDER_PRICE_PVT.CONTROL_REC_TYPE;
11258 x_line_tbl oe_order_pub.line_tbl_type;
11259 l_status_code Varchar2(5);
11260 l_item_rec                    OE_ORDER_CACHE.item_rec_type; -- OPM 2547940
11261 --serla begin
11262 l_x_Header_Payment_tbl        OE_Order_PUB.Header_Payment_Tbl_Type;
11263 l_x_Line_Payment_tbl          OE_Order_PUB.Line_Payment_Tbl_Type;
11264 --serla end
11265 begin
11266 
11267 	adj_debug('Entering oe_order_Adj_pvt.Price_adjustments',1);
11268 
11269    --btea perf begin
11270    If OE_DEBUG_PUB.G_DEBUG = FND_API.G_TRUE Then
11271     G_DEBUG := TRUE;
11272     adj_debug('BCT G_DEBUG IS:'||OE_DEBUG_PUB.G_DEBUG );
11273    Else
11274     G_DEBUG := FALSE;
11275    End If;
11276    --btea perf end
11277 
11278 
11279 
11280   IF OE_GLOBALS.G_ASO_INSTALLED IS NULL THEN
11281       OE_GLOBALS.G_ASO_INSTALLED := OE_GLOBALS.CHECK_PRODUCT_INSTALLED(697);
11282   END IF;
11283 
11284    IF OE_GLOBALS.G_GMI_INSTALLED IS NULL THEN -- OPM 2547940
11285       OE_GLOBALS.G_GMI_INSTALLED := OE_GLOBALS.CHECK_PRODUCT_INSTALLED(550);
11286    END IF;
11287 
11288 
11289   IF (OE_GLOBALS.G_ASO_INSTALLED = 'N'    AND
11290      OE_GLOBALS.G_GMI_INSTALLED = 'N'     AND -- OPM 2547940
11291     G_11IG_PERFORMANCE = 'Y'              AND
11292     QP_UTIL_PUB.Basic_Pricing_Setup = 'Y' AND
11293     nvl(p_request_rec.param1,'XX') <> 'UI') OR
11294 OE_CODE_CONTROL.Get_Code_Release_Level >= '110509'
11295   THEN
11296   l_price_control_rec.p_request_type_code:=p_request_type_code;
11297   l_price_control_rec.p_calculate_flag := QP_PREQ_GRP.G_CALCULATE_ONLY;
11298   IF (p_line_id IS NOT NULL and nvl(p_request_rec.param1,'XX') = 'UI') THEN
11299     l_price_control_rec.p_honor_price_flag := 'N';
11300   END IF;
11301   oe_order_price_pvt.price_line
11302                  (p_Header_id    => p_Header_id
11303                 ,p_Line_id             =>p_Line_id
11304                 ,px_line_Tbl           =>x_line_tbl
11305                 ,p_Control_Rec         =>l_price_control_rec
11306                 ,p_Pricing_Events      =>NULL
11307                 ,x_Return_Status       =>x_return_status
11308                 );
11309   RETURN;
11310 END IF;
11311 	-- Query Line Record
11312 
11313 l_Req_Control_Rec.Simulation_Flag := 'N';
11314 
11315 	If p_header_id is null then
11316 
11317                oe_line_util.query_rows(
11318                  p_line_id => p_line_id
11319                , x_line_tbl => l_line_tbl1
11320                );
11321 
11322                OE_Header_Util.Query_Row(
11323                    p_header_id => l_Line_Tbl1(1).header_id
11324                 ,  x_header_rec => l_header_rec
11325                 );
11326 	Else
11327 
11328                 OE_Header_Util.Query_Row(
11329                    p_header_id => p_header_id
11330                 ,  x_header_rec  => l_header_rec
11331                 );
11332 
11333               oe_line_util.query_rows(
11334                  p_header_id => p_header_id
11335               ,  x_line_tbl => l_Line_Tbl1
11336               );
11337 	end if;
11338  g_order_currency := l_header_rec.transactional_curr_code; --bug 2595626
11339 
11340         oe_debug_pub.add(' Param1 UI Flag value:'|| p_request_rec.param1);
11341 	l_line_index := l_Line_Tbl1.First;
11342 	While l_line_index is not null loop  -- Retain the ones with calculate_price_flag=Y'
11343                /* Added elsif condition so that price is calculated even if price flag is N
11344                   when request is logged for a line */
11345 		If nvl(l_Line_Tbl1(l_line_index).calculate_price_flag,'Y') in ('Y','P') then
11346 			l_Line_Tbl(l_Line_Tbl.count+1) := l_Line_Tbl1(l_line_index);
11347                 Elsif p_line_id is not NULL
11348                       and l_Line_Tbl1(l_line_index).line_id = p_line_id
11349                       and p_request_rec.param1 = 'UI' Then  --bug 2354465
11350                       l_Line_Tbl(l_Line_Tbl.count+1) :=l_Line_Tbl1(l_line_index);
11351 		end if;
11352 		l_line_index := l_Line_Tbl1.Next(l_line_index);
11353 	end loop;
11354 
11355 	l_line_index := l_Line_Tbl.First;
11356 
11357 	While l_line_index is not null loop
11358 	-- Query the Adjustments
11359 
11360          -- added by lkxu
11361 	    l_line_tbl(l_line_index).operation := OE_GLOBALS.G_OPR_UPDATE;
11362 
11363 		append_Adjustment_lines(p_line_id	=> l_Line_Tbl(l_line_index).line_id,
11364 				px_line_adj_tbl	=>	l_Line_Adj_Tbl
11365                                 ,px_line_key_tbl        => l_dummy
11366                                 ,px_header_key_tbl      => l_dummy
11367                                 ,px_line_adj_assoc_tbl  =>l_dummy_adj_assoc_tbl
11368                                 ,px_line_rec            => l_line_tbl(l_line_index)
11369                                 , x_updated_flag        =>l_updated_flag);
11370 
11371                  If (l_updated_flag = 'Y' and l_line_tbl(l_line_index).calculate_price_flag = 'Y') THEN
11372                     If l_set_price_flag_on_manual = 'Y' Then
11373                      l_line_tbl(l_line_index).calculate_price_flag := 'P';
11374                    End If;
11375                  End if;
11376 	l_line_index := l_Line_Tbl.next(l_line_index);
11377 	End loop;
11378 
11379 	append_Adjustment_Lines(p_header_id => l_header_rec.header_id
11380 				,px_Line_Adj_Tbl 	=> l_line_adj_Tbl
11381                                 ,px_line_key_tbl        => l_dummy
11382                                 ,px_header_key_tbl      => l_dummy
11383                                 ,px_line_adj_assoc_tbl  => l_dummy_adj_assoc_tbl
11384                                 ,px_line_rec            => l_dummy_line_rec
11385                                 ,x_updated_flag => l_updated_flag);
11386 
11387 	l_old_line_adj_tbl := l_line_adj_tbl;
11388 
11389 	-- Query the assocs
11390 	i:= l_Line_Adj_Tbl.First;
11391 	While I is not null loop
11392 		Query_Adj_Assocs(
11393 			p_price_adjustment_id=> l_line_adj_Tbl(i).price_adjustment_id,
11394 			p_Adj_Index         => i,
11395 			p_Line_Adj_Assoc_Tbl     => l_line_adj_Assoc_tbl,
11396                         p_delete_flag  =>  'N');
11397 
11398                 oe_debug_pub.add('xPrice_Adj query assocs-adj_id:'|| l_line_adj_Tbl(i).price_adjustment_id);
11399                 oe_debug_pub.add('xAdj asso count:'||l_line_adj_Assoc_tbl.count);
11400 		i:= l_Line_Adj_Tbl.Next(i);
11401 	End loop;
11402 
11403         --Performance change: To update only changed lines
11404         l_old_line_tbl := l_line_tbl;
11405 
11406 	--Return;
11407 	Calculate_Price (
11408 		p_Header_Rec            => l_Header_Rec
11409 		,p_Line_Tbl         	=> l_line_Tbl
11410 		,p_Line_Adj_Tbl     	=> l_Line_Adj_Tbl
11411 		,p_line_adj_assoc_Tbl   	=> l_line_adj_assoc_Tbl
11412 		,p_allow_negative_price  => l_allow_negative_price
11413 		,p_request_Type_Code	=> p_request_Type_Code
11414 		)	 ;
11415 
11416      -- lkxu, only retain those records with changed adjusted_amount
11417 	i:= l_Line_Adj_Tbl.First;
11418 	While i is not Null Loop
11419 	  IF OE_GLOBALS.Equal(l_Old_Line_Adj_Tbl(i).adjusted_amount_per_pqty,
11420 				l_Line_Adj_Tbl(i).adjusted_amount_per_pqty) THEN
11421 	    l_Line_Adj_Tbl.delete(i);
11422        ELSE
11423             oe_debug_pub.add(' price adj amount:'|| L_Line_Adj_Tbl(i).adjusted_amount);
11424             L_Line_Adj_Tbl(i).operation := OE_GLOBALS.G_OPR_UPDATE;
11425        END IF;
11426 	  i:= l_Line_Adj_Tbl.next(i);
11427      END LOOP;
11428 
11429 
11430    -- set control record
11431    l_control_rec.controlled_operation := TRUE;
11432    l_control_rec.write_to_DB          := TRUE;
11433    l_control_rec.change_attributes    := TRUE;
11434    l_control_rec.default_attributes   := TRUE;
11435    l_control_rec.validate_entity      := TRUE;
11436    l_control_rec.clear_dependents     := TRUE;
11437 
11438    l_control_rec.process              := FALSE;
11439    l_control_rec.clear_api_cache      := FALSE;
11440    l_control_rec.clear_api_requests   := FALSE;
11441 
11442 
11443     --  Call OE_Order_PVT.Process_order
11444 
11445 	 -- OE_Globals.G_RECURSION_MODE := 'Y';
11446 	 OE_Globals.G_PRICING_RECURSION := 'Y';
11447 
11448 
11449     I:= l_line_tbl.First;
11450     While I is not null loop
11451 
11452          -- 3129046
11453          adj_debug('Line ID processed : '||l_line_tbl(i).line_id,1);
11454          l_line_tbl(i).change_reason := 'SYSTEM';
11455          l_line_tbl(i).change_comments := 'PRICING';
11456          adj_debug('Audit Reason passed as '||l_line_tbl(i).change_reason,1);
11457 
11458         -- uom begin
11459 	If oe_line_util.Get_Return_Item_Type_Code(l_line_tbl(i)) in ('INCLUDED', 'CONFIG') then
11460 		l_line_tbl(i).unit_list_price_per_pqty := 0;
11461                 l_line_tbl(i).pricing_quantity := l_line_tbl(i).ordered_quantity;
11462                 l_line_tbl(i).pricing_quantity_uom := l_line_tbl(i).order_quantity_uom;
11463 	end if;
11464 
11465 	If l_line_tbl(i).unit_Selling_price_per_pqty is null  or
11466 	oe_line_util.Get_Return_Item_Type_Code(l_line_tbl(i)) in ('INCLUDED', 'CONFIG')
11467 	then
11468 		l_line_tbl(i).unit_Selling_price_per_pqty := l_line_tbl(i).unit_list_price_per_pqty;
11469 
11470 	End If;
11471 
11472         If l_line_tbl(i).ordered_quantity IS NOT NULL and l_line_tbl(i).ordered_quantity <> 0
11473         then
11474         l_line_tbl(i).unit_selling_price := l_line_tbl(i).unit_selling_price_per_pqty * l_line_tbl(i).pricing_quantity/l_line_tbl(i).ordered_quantity;
11475 
11476         l_line_tbl(i).unit_list_price := l_line_tbl(i).unit_list_price_per_pqty * l_line_tbl(i).pricing_quantity/l_line_tbl(i).ordered_quantity;
11477         end if;
11478 
11479 	  -- OPM 2547940  start - if pricing by quantity2 then if line is shipped and has shipped qty2 != ordered qty2
11480         --  need to adjust the adjusted_amount so that invoicing will show correct amount (ordered qty * USP (adjusted) )
11481 
11482         IF oe_line_util.dual_uom_control -- invconv
11483               (l_line_tbl(i).inventory_item_id
11484               ,l_line_tbl(i).ship_from_org_id
11485               ,l_item_rec) THEN
11486                               	IF l_item_rec.ont_pricing_qty_source = 'S'   THEN -- price by quantity 2 -- INVCONV
11487 
11488    				  	IF (l_line_tbl(i).ordered_quantity2 IS NOT NULL and l_line_tbl(i).ordered_quantity2 <> 0	)
11489                         		AND ( l_line_tbl(i).shipped_quantity2 IS NOT NULL and l_line_tbl(i).shipped_quantity2 <> 0	)
11490                         		 AND l_line_tbl(i).ordered_quantity2 <> l_line_tbl(i).shipped_quantity2 THEN
11491 
11492                        		     l_line_tbl(i).unit_selling_price := (l_line_tbl(i).unit_selling_price_per_pqty * l_line_tbl(i).pricing_quantity )/l_line_tbl(i).ordered_quantity2
11493                        		      * (l_line_tbl(i).shipped_quantity2/l_line_tbl(i).ordered_quantity);
11494                        		      l_line_tbl(i).unit_list_price := (l_line_tbl(i).unit_list_price_per_pqty * l_line_tbl(i).pricing_quantity )/l_line_tbl(i).ordered_quantity2
11495                        		      * (l_line_tbl(i).shipped_quantity2/l_line_tbl(i).ordered_quantity);
11496 
11497                				 END IF;
11498                			     END IF;
11499 	END IF;  --oe_line_util.dual_uom_control -- INVCONV
11500 	-- OPM 2547940 end
11501 
11502     oe_debug_pub.add('unit price'||l_line_tbl(i).unit_list_price||'+'||l_line_tbl(i).unit_selling_price,1);
11503     oe_debug_pub.add('unit price per pqty'||l_line_tbl(i).unit_list_price_per_pqty||'+'||l_line_tbl(i).unit_selling_price_per_pqty,1);
11504 
11505         -- uom end
11506 
11507  -- commented the assigment below and included above to fix bug 2595626
11508  -- g_order_currency := l_header_rec.transactional_curr_code;
11509 
11510 
11511        adj_debug('  Values passed into QP_UTIL_PUB.round_price api:');
11512        adj_debug('  p_operand:'||l_line_tbl(i).unit_selling_price);
11513        adj_debug('  price_list_id:'||l_line_tbl(i).price_list_id);
11514        adj_debug('  currency_code:'||l_header_rec.transactional_curr_code);
11515        adj_debug('  pricing_effective_date:'||l_line_tbl(i).pricing_date);
11516        QP_UTIL_PUB.round_price(p_operand                => l_line_tbl(i).unit_selling_price,
11517 			       p_rounding_factor        => NULL,
11518 			       p_use_multi_currency     => 'Y',
11519 			       p_price_list_id          => l_line_tbl(i).price_list_id,
11520 			       p_currency_code          => l_header_rec.transactional_curr_code,
11521 			       p_pricing_effective_date => l_line_tbl(i).pricing_date,
11522 			       x_rounded_operand        => l_line_tbl(i).unit_selling_price,
11523 			       x_status_code            => l_status_code);
11524        adj_debug(' Rounded Unit Selling Price Returned By pricing API:'||l_line_tbl(i).unit_selling_price);
11525        adj_debug(' x_status_code:'||l_status_code);
11526 
11527 
11528       -- Performance change: not update line if no change
11529       IF (OE_GLOBALS.Equal(l_line_tbl(i).unit_list_price, l_old_line_tbl(i).unit_list_price) AND
11530           OE_GLOBALS.Equal(l_line_tbl(i).unit_selling_price, l_old_line_tbl(i).unit_selling_price) AND
11531           OE_GLOBALS.Equal(l_line_tbl(i).unit_list_price_per_pqty, l_old_line_tbl(i).unit_list_price_per_pqty) AND
11532           OE_GLOBALS.Equal(l_line_tbl(i).unit_selling_price_per_pqty, l_old_line_tbl(i).unit_selling_price_per_pqty)) THEN
11533           adj_debug('not updating '||l_line_tbl(i).line_id);
11534           -- l_line_tbl(i).operation := OE_GLOBALS.G_OPR_NONE;
11535           l_line_tbl.delete(i);
11536       ELSE
11537         OE_GLOBALS.G_CASCADING_REQUEST_LOGGED := TRUE;
11538       END IF;
11539 
11540      i:= l_line_tbl.next(i);
11541     end loop;
11542 
11543 	adj_debug('Before OE_Order_PVT.Process_order',1);
11544 
11545     OE_Order_PVT.Process_order
11546     (   p_api_version_number          => 1.0
11547     ,   x_return_status               => x_return_status
11548     ,   x_msg_count                   => l_x_msg_count
11549     ,   x_msg_data                    => l_x_msg_data
11550     ,   p_control_rec                 => l_control_rec
11551     ,   p_x_line_tbl                    => l_line_tbl
11552     ,   p_x_Line_Adj_tbl                => l_Line_Adj_tbl
11553     ,   p_x_header_rec                  => l_x_header_rec
11554     ,   p_x_Header_Adj_tbl              => l_x_Header_Adj_tbl
11555     ,   p_x_header_price_att_tbl        => l_x_header_price_att_tbl
11556     ,   p_x_Header_Adj_att_tbl          => l_x_Header_Adj_att_tbl
11557     ,   p_x_Header_Adj_Assoc_tbl        => l_x_Header_Adj_Assoc_tbl
11558     ,   p_x_Header_Scredit_tbl          => l_x_Header_Scredit_tbl
11559 --serla begin
11560     ,   p_x_Header_Payment_tbl          => l_x_Header_Payment_tbl
11561 --serla end
11562 --    ,   p_x_line_tbl                    => l_x_line_tbl
11563 --    ,   p_x_Line_Adj_tbl                => l_x_Line_Adj_tbl
11564     ,   p_x_Line_Price_att_tbl          => l_x_Line_Price_att_tbl
11565     ,   p_x_Line_Adj_att_tbl            => l_x_Line_Adj_att_tbl
11566     ,   p_x_Line_Adj_Assoc_tbl          => l_x_Line_Adj_Assoc_tbl
11567     ,   p_x_Line_Scredit_tbl            => l_x_Line_Scredit_tbl
11568 --serla begin
11569     ,   p_x_Line_Payment_tbl            => l_x_Line_Payment_tbl
11570 --serla end
11571     ,   p_x_Lot_Serial_tbl              => l_x_Lot_Serial_Tbl
11572     ,   p_x_action_request_tbl	      => l_x_Action_Request_tbl
11573     );
11574 
11575 
11576    -- OE_Globals.G_RECURSION_MODE := 'N';
11577    OE_Globals.G_PRICING_RECURSION := 'N';
11578 
11579     IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11580 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11581 	ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
11582 		RAISE FND_API.G_EXC_ERROR;
11583 	END IF;
11584 
11585 	adj_debug('Exiting oe_order_Adj_pvt.Price_adjustments',1);
11586 
11587 
11588     EXCEPTION
11589 
11590 	    WHEN FND_API.G_EXC_ERROR THEN
11591 
11592 		  x_return_status := FND_API.G_RET_STS_ERROR;
11593 			adj_debug('		'||g_stmt_no||' '||sqlerrm||' '||l_x_msg_data,1);
11594 
11595 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11596 
11597 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11598 			adj_debug('		'||g_stmt_no||' '||sqlerrm||' '||l_x_msg_data,1);
11599 
11600 		WHEN OTHERS THEN
11601 
11602 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11603 			--dbms_output.put_line('Error is '||sqlerrm);
11604 			adj_debug('Error in oe_order_Adj_pvt.Price_adjustments',1);
11605 			adj_debug('		'||g_stmt_no||' '||sqlerrm,1);
11606 
11607 End Price_Adjustments;
11608 
11609 procedure price_action
11610 		(
11611 		 p_selected_records	       Oe_Globals.Selected_Record_Tbl
11612 		,P_price_level	               varchar2
11613                 ,p_header_id                   Number  default null
11614 ,x_Return_Status out nocopy varchar2
11615 
11616 ,x_msg_count out nocopy number
11617 
11618 ,x_msg_data out nocopy varchar2
11619 
11620 		)
11621 is
11622 l_Price_Control_rec		QP_PREQ_GRP.control_record_type;
11623 l_return_status		varchar2(1);
11624 l_x_line_tbl			oe_order_pub.line_tbl_type;
11625 l_line_id				number;
11626 l_header_id			number;
11627 l_delimiter1			number;
11628 l_delimiter2			number;
11629 l_delimiter			number;
11630 l_booked_flag			varchar2(1);
11631 l_multiple_events               Varchar2(1);
11632 l_order_status_rec QP_UTIL_PUB.ORDER_LINES_STATUS_REC_TYPE;
11633 l_prev_line_hdr_id              Number;
11634 l_locked_header_rec         OE_ORDER_PUB.Header_Rec_Type;  --13727700
11635 
11636 cursor has_prg_lines(p_line_id IN NUMBER) is
11637 Select 'Y'
11638 From OE_PRICE_ADJUSTMENTS a,  OE_ORDER_LINES_ALL b
11639 Where b.line_id = p_line_id
11640 AND   b.header_id = a.header_id
11641 And   a.list_line_type_code = 'PRG';
11642 
11643 l_has_prg_lines varchar2(1):= 'Q';
11644 --MOAC PI
11645 J                               Number := 1;
11646 L_org_id                        Number;
11647 L_prev_org_id                   Number;
11648 L_prev_hdr_id                   Number;
11649 L_call_pricing                  varchar2(1) := 'N';
11650 last_record_line_id             Number := p_selected_records(p_selected_records.count).id1;
11651 L_new_header                    Boolean;
11652 L_ID3                           Boolean := TRUE;
11653 i                               Number;
11654 --MOAC PI
11655 
11656 begin
11657 	adj_debug('Performing Price Action for level '||P_price_level);
11658 
11659 	If P_price_level ='LINE' then
11660 
11661 		l_Price_Control_Rec.pricing_event := 'LINE';
11662 		l_Price_Control_Rec.calculate_flag := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
11663 		l_Price_Control_Rec.Simulation_Flag := 'N';
11664                 l_has_prg_lines := 'Q';
11665 
11666                 --MOAC PI BEGIN
11667                 oe_debug_pub.add('p_header_id : ' || p_header_id);
11668                 IF p_header_id is not null THEN
11669                    oe_debug_pub.add('before the loop');
11670                    i := p_selected_records.first;
11671                    while I is not null loop
11672                        L_line_id := p_selected_records(i).id1;
11673                    --Bug 7330561
11674   			l_has_prg_lines := 'Q';
11675 			Begin
11676                    	  open  has_prg_lines(L_line_id);
11677                    	  fetch has_prg_lines into l_has_prg_lines;
11678                    	  close has_prg_lines;
11679                    	Exception
11680                    	  When no_data_found Then
11681                    	   l_has_prg_lines:='N';
11682                    	  When others Then
11683                    	   l_has_prg_lines:='Y';
11684                    	End;
11685                     oe_debug_pub.add('Lalit calling Price Line with l_has_prg_lines-' || l_has_prg_lines );
11686 			    IF l_has_prg_lines = 'Y' THEN
11687                               oe_order_Adj_pvt.Price_line(
11688                                     X_Return_Status     => l_Return_Status
11689                                     ,p_Request_Type_code=> 'ONT'
11690                                     ,p_Control_rec      => l_Price_Control_Rec
11691                                     ,p_Write_To_Db      => TRUE
11692                                     ,p_Line_id          => l_line_id
11693                                     ,x_Line_Tbl         => l_x_Line_Tbl
11694                               );
11695 			     -- Bug 11075538 - Clearing the contents of the l_x_Line_Tbl once the Price_line is completed
11696 			     l_x_Line_Tbl.delete;
11697                        ELSE
11698                               adj_debug('Old price_action way, order has no prg');
11699                               Begin
11700                                     l_x_line_tbl(i).Line_id := l_Line_id;
11701                                     oe_Line_util.query_row(
11702                                           p_Line_id => l_Line_id
11703                                        ,  x_line_rec => l_x_Line_Tbl(i)
11704                                     );
11705                               Exception when no_data_found then
11706                                 null;
11707                               End;
11708 
11709                        END IF;
11710                        i := p_selected_records.next(i);
11711                    End Loop;
11712                    IF l_has_prg_lines IN ('N','Q') THEN
11713                           oe_order_Adj_pvt.Price_line(
11714                                 X_Return_Status     => l_Return_Status
11715                                ,p_Request_Type_code=> 'ONT'
11716                                ,p_Control_rec      => l_Price_Control_Rec
11717                                ,p_Write_To_Db      => TRUE
11718                                ,x_Line_Tbl         => l_x_Line_Tbl
11719                            );
11720                    END IF;
11721 
11722                 ELSE
11723                    i := p_selected_records.first;
11724                    while i is not null loop
11725                           oe_debug_pub.add('id1 : ' || p_selected_records(i).id1);
11726                           oe_debug_pub.add('org_id : ' || p_selected_records(i).org_id);
11727                           oe_debug_pub.add('id3 : ' || p_selected_records(i).id3);
11728                           l_line_id := p_selected_records(i).id1;
11729                           l_org_id := p_selected_records(i).org_id;
11730                           L_header_id := p_selected_records(i).id3;
11731                           If  l_prev_org_id is null or l_prev_org_id <> l_org_id Then
11732                               MO_GLOBAL.set_policy_context(p_access_mode => 'S',  p_org_id => l_Org_Id);
11733                               l_prev_org_id := l_org_id;
11734                           End If;
11735                           L_new_header := FALSE;
11736                           IF l_prev_hdr_id Is Null Or l_prev_hdr_id <> l_header_id Then
11737                              L_new_header := TRUE;
11738                              l_has_prg_lines:='Q';
11739                              j := 1;
11740                              l_prev_hdr_id := l_header_id;
11741                              Begin
11742                                 open  has_prg_lines(l_header_id);
11743                                 fetch has_prg_lines into l_has_prg_lines;
11744                                 close has_prg_lines;
11745                              Exception
11746                                 When no_data_found Then
11747                                   l_has_prg_lines:='N';
11748                                 When others Then
11749                                   l_has_prg_lines:='Y';
11750                              End;
11751                           End If;
11752 
11753                           IF l_has_prg_lines = 'Y' THEN
11754                                 oe_order_Adj_pvt.Price_line(
11755                                     X_Return_Status     => l_Return_Status
11756                                     ,p_Request_Type_code=> 'ONT'
11757                                     ,p_Control_rec      => l_Price_Control_Rec
11758                                     ,p_Write_To_Db      => TRUE
11759                                     ,p_Line_id          => l_line_id
11760                                     ,x_Line_Tbl         => l_x_Line_Tbl
11761                                 );
11762                           ELSE
11763                              IF (l_new_header or last_record_line_id = l_line_id) and l_x_line_tbl.count > 0 THEN
11764                                 IF last_record_line_id = l_line_id and l_prev_line_hdr_id = l_header_id THEN
11765                                    Begin
11766                                               l_x_line_tbl(j).Line_id := l_Line_id;
11767                                               oe_Line_util.query_row(
11768                                                     p_Line_id => l_Line_id
11769                                                  ,  x_line_rec => l_x_Line_Tbl(j)
11770                                               );
11771                                    Exception when no_data_found then
11772                                               null;
11773                                    End;
11774                                 END IF;
11775 
11776                                 oe_order_Adj_pvt.Price_line(
11777                                             X_Return_Status     => l_Return_Status
11778                                            ,p_Request_Type_code=> 'ONT'
11779                                            ,p_Control_rec      => l_Price_Control_Rec
11780                                            ,p_Write_To_Db      => TRUE
11781                                            ,x_Line_Tbl         => l_x_Line_Tbl
11782                                        );
11783 
11784                                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11785                                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11786                                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
11787                                         RAISE FND_API.G_EXC_ERROR;
11788                                 END IF;
11789 
11790                                 L_x_line_tbl.delete;
11791                              END IF;
11792 
11793                              adj_debug('Old price_action way, order has no prg');
11794                              Begin
11795                                       l_x_line_tbl(j).Line_id := l_Line_id;
11796                                       oe_Line_util.query_row(
11797                                            p_Line_id => l_Line_id
11798                                         ,  x_line_rec => l_x_Line_Tbl(j)
11799                                      );
11800                                      j := j + 1;
11801                              Exception when no_data_found then
11802                                      null;
11803                              End;
11804                           END IF;
11805                           l_prev_line_hdr_id := l_header_id;
11806                           i := p_selected_records.next(i);
11807                    End Loop;
11808                    IF l_x_line_tbl.count > 0 THEN
11809                                 oe_order_Adj_pvt.Price_line(
11810                                             X_Return_Status     => l_Return_Status
11811                                            ,p_Request_Type_code=> 'ONT'
11812                                            ,p_Control_rec      => l_Price_Control_Rec
11813                                            ,p_Write_To_Db      => TRUE
11814                                            ,x_Line_Tbl         => l_x_Line_Tbl
11815                                        );
11816 
11817                                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11818                                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11819                                 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
11820                                         RAISE FND_API.G_EXC_ERROR;
11821                                 END IF;
11822 
11823                                 L_x_line_tbl.delete;
11824                    END IF;
11825 
11826                 END IF;
11827         ELSE
11828                 IF p_selected_records(1).id3 IS NULL THEN
11829                    L_id3 := FALSE;
11830                 END IF;
11831                 IF NOT L_id3 THEN
11832                    i := p_selected_records.first;
11833                    while i is not null loop
11834                        l_header_id := p_selected_records(i).id1;
11835                        l_org_id := p_selected_records(i).org_id;
11836                        IF l_prev_org_id Is Null or l_prev_org_id <> l_org_id Then
11837                           MO_GLOBAL.set_policy_context(p_access_mode => 'S',  p_org_id => l_Org_Id);
11838                           l_prev_org_id := l_org_id;
11839                        END IF;
11840                        adj_debug('Price Action Header_id :'||l_HEader_id);
11841 
11842 		        -- use order_header cache instead of sql : bug 4200055
11843 		       if ( OE_Order_Cache.g_header_rec.header_id <> FND_API.G_MISS_NUM
11844 			    and OE_Order_Cache.g_header_rec.header_id IS NOT NULL
11845 			    and OE_Order_Cache.g_header_rec.header_id = l_header_id ) then
11846 			        l_booked_flag := OE_Order_Cache.g_header_rec.booked_flag ;
11847 		       else
11848 			        OE_ORDER_CACHE.Load_Order_Header(l_header_id);
11849 				l_booked_flag := OE_Order_Cache.g_header_rec.booked_flag ;
11850 		       end if ;
11851                        /*Select booked_flag into l_booked_flag from oe_order_headers_all
11852                        where header_id=l_header_id; */
11853 		       --end bug 4200055
11854 
11855                        If l_booked_flag <> 'Y' Then
11856                           l_price_control_rec.pricing_event := 'BATCH';
11857                           l_multiple_events := 'N';
11858                        Elsif  l_booked_flag = 'Y' Then
11859                           l_price_control_rec.pricing_event  := 'BATCH,BOOK,SHIP';
11860                           l_multiple_events := 'Y';
11861                        End If;
11862 
11863                        l_Price_Control_Rec.calculate_flag := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
11864                        l_Price_Control_Rec.Simulation_Flag := 'N';
11865 
11866                         --13727700 start
11867                         OE_Header_Util.Lock_Row
11868                         (p_header_id                    => l_header_id
11869                         ,p_x_header_rec         => l_locked_header_rec
11870                         ,x_return_status                => l_return_status
11871                         );
11872                         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
11873                           RAISE FND_API.G_EXC_ERROR;
11874                         ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
11875                         THEN
11876                           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11877                         END IF;
11878                         --13727700 end
11879 
11880                        oe_order_Adj_pvt.Price_line(
11881                         X_Return_Status     => l_Return_Status
11882                         ,p_header_id            => l_header_id
11883                         ,p_Request_Type_code=> 'ONT'
11884                         ,p_Control_rec      => l_Price_Control_Rec
11885                         ,p_Write_To_Db      => TRUE
11886                         ,x_Line_Tbl         => l_x_Line_Tbl
11887                         ,p_multiple_events  => l_multiple_events
11888                         ,p_action_code      => 'PRICE_ORDER');
11889 
11890                        IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11891                           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11892                        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
11893                           RAISE FND_API.G_EXC_ERROR;
11894                        END IF;
11895                        i := p_selected_records.next(i);
11896                    end loop;
11897                 ELSE
11898                    i := p_selected_records.first;
11899                    while i is not null loop
11900                        l_header_id := p_selected_records(i).id3;
11901                        l_org_id := p_selected_records(i).org_id;
11902                        IF l_prev_org_id Is Null or l_prev_org_id <> l_org_id Then
11903                           MO_GLOBAL.set_policy_context(p_access_mode => 'S',  p_org_id => l_Org_Id);
11904                           l_prev_org_id := l_org_id;
11905                        END IF;
11906                        IF l_prev_hdr_id IS NULL OR l_prev_hdr_id <> l_header_id THEN
11907                           adj_debug('Price Action Header_id :'||l_HEader_id);
11908                           Select booked_flag into l_booked_flag from oe_order_headers_all
11909                           where header_id=l_header_id;
11910                           If l_booked_flag <> 'Y' Then
11911                              l_price_control_rec.pricing_event := 'BATCH';
11912                              l_multiple_events := 'N';
11913                           Elsif  l_booked_flag = 'Y' Then
11914                              l_price_control_rec.pricing_event  := 'BATCH,BOOK,SHIP';
11915                              l_multiple_events := 'Y';
11916                           End If;
11917 
11918                           l_Price_Control_Rec.calculate_flag := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
11919                           l_Price_Control_Rec.Simulation_Flag := 'N';
11920 
11921                         --13727700 start
11922                         OE_Header_Util.Lock_Row
11923                         (p_header_id                    => l_header_id
11924                         ,p_x_header_rec         => l_locked_header_rec
11925                         ,x_return_status                => l_return_status
11926                         );
11927                         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
11928                           RAISE FND_API.G_EXC_ERROR;
11929                         ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
11930                         THEN
11931                           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11932                         END IF;
11933                         --13727700 end
11934 
11935 
11936                           oe_order_Adj_pvt.Price_line(
11937                              X_Return_Status     => l_Return_Status
11938                             ,p_header_id            => l_header_id
11939                             ,p_Request_Type_code=> 'ONT'
11940                             ,p_Control_rec      => l_Price_Control_Rec
11941                             ,p_Write_To_Db      => TRUE
11942                             ,x_Line_Tbl         => l_x_Line_Tbl
11943                             ,p_multiple_events  => l_multiple_events
11944                             ,p_action_code      => 'PRICE_ORDER');
11945 
11946                           IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11947                              RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11948                           ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
11949                              RAISE FND_API.G_EXC_ERROR;
11950                           END IF;
11951                           l_prev_hdr_id := l_header_id;
11952                        END IF;
11953                        i := p_selected_records.next(i);
11954                    end loop;
11955                 END IF;
11956 
11957         END IF;
11958 
11959         --MOAC PI END
11960 
11961      OE_MSG_PUB.Count_And_Get
11962      (   p_count                       => x_msg_count
11963      ,   p_data                        => x_msg_data
11964      );
11965 
11966         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11967 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11968 	ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
11969 		RAISE FND_API.G_EXC_ERROR;
11970 	END IF;
11971 
11972 	x_Return_Status := FND_API.G_RET_STS_SUCCESS;
11973 
11974 	adj_debug('Exiting oe_order_Adj_pvt.Price_adjustments',1);
11975 
11976 
11977     EXCEPTION
11978 
11979 	    WHEN FND_API.G_EXC_ERROR THEN
11980 		  x_return_status := FND_API.G_RET_STS_ERROR;
11981      	  OE_MSG_PUB.Count_And_Get
11982      	  ( p_count                       => x_msg_count
11983     		   ,p_data                        => x_msg_data
11984      	   );
11985 
11986 	   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11987 		  x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11988      	  OE_MSG_PUB.Count_And_Get
11989      	  ( p_count                       => x_msg_count
11990      	   ,p_data                        => x_msg_data
11991      	  );
11992 
11993 	   WHEN OTHERS THEN
11994 		  x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11995 		  adj_debug('		'||sqlerrm,1);
11996      	  OE_MSG_PUB.Count_And_Get
11997      	  (  p_count                       => x_msg_count
11998      	   , p_data                        => x_msg_data
11999      	  );
12000 
12001 end price_action;
12002 
12003 
12004 /* For Backward Compatibility */
12005 
12006 procedure price_action
12007                 (p_Header_count                 Number
12008                 ,p_Header_list                  varchar2
12009                 ,p_line_count                   number
12010                 ,p_line_List                    Varchar2
12011                 ,P_price_level                  varchar2
12012 ,x_Return_Status out nocopy varchar2
12013 
12014 ,x_msg_count out nocopy number
12015 
12016 ,x_msg_data out nocopy varchar2
12017 
12018                 )
12019 is
12020 l_Price_Control_rec             QP_PREQ_GRP.control_record_type;
12021 l_return_status         varchar2(1);
12022 l_x_line_tbl                    oe_order_pub.line_tbl_type;
12023 l_line_list                     varchar2(32000) := p_line_list;
12024 l_Header_list                   varchar2(32000) := p_Header_list;
12025 l_line_id                               number;
12026 l_header_id                     number;
12027 l_delimiter1                    number;
12028 l_delimiter2                    number;
12029 l_delimiter                     number;
12030 l_booked_flag                   varchar2(1);
12031 l_multiple_events               Varchar2(1);
12032 l_order_status_rec QP_UTIL_PUB.ORDER_LINES_STATUS_REC_TYPE;
12033 
12034 cursor has_prg_lines(p_line_id IN NUMBER) is
12035 Select 'Y'
12036 From OE_PRICE_ADJUSTMENTS a,  OE_ORDER_LINES_ALL b
12037 Where b.line_id = p_line_id
12038 AND   b.header_id = a.header_id
12039 And   a.list_line_type_code = 'PRG';
12040 
12041 l_has_prg_lines varchar2(1):= 'Q';
12042 l_locked_header_rec         OE_ORDER_PUB.Header_Rec_Type;  --14647325
12043 
12044 begin
12045         adj_debug('Performing Price Action for level '||P_price_level);
12046 
12047         If P_price_level ='LINE' then
12048 
12049                 l_Price_Control_Rec.pricing_event := 'LINE';
12050                 l_Price_Control_Rec.calculate_flag := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
12051                 l_Price_Control_Rec.Simulation_Flag := 'N';
12052                 l_has_prg_lines := 'Q';
12053 
12054                 -- Made changes to get line_id from p_line_list for Bug 2532740
12055 
12056                   l_delimiter2 := 0;
12057                 for i in 1..p_line_count loop
12058                    l_delimiter1     := l_delimiter2;
12059                    l_delimiter2     := INSTR(p_line_list,',',l_delimiter1+1);
12060 
12061                    If l_delimiter2 = 0 Then
12062                      l_line_id := to_number(substr(p_line_list,l_delimiter1+1));
12063                    else
12064                    -- 2665650 fix
12065                      l_line_id := to_number(substr(p_line_list,l_delimiter1+1,l_delimiter2-1-l_delimiter1));
12066                    end if;
12067 
12068                    IF  l_has_prg_lines = 'Q' THEN
12069                     Begin
12070                      open  has_prg_lines(l_line_id);
12071                      fetch has_prg_lines into l_has_prg_lines;
12072                      close has_prg_lines;
12073                     Exception
12074                      When no_data_found Then
12075                       l_has_prg_lines:='N';
12076                      When others Then
12077                       l_has_prg_lines:='Y';
12078                     End;
12079                    END IF;
12080 
12081                    adj_debug('Price Action Line_Id:'||l_line_id);
12082                 -- End of changes for 2532740
12083 
12084                      adj_debug('all_lines_flag from pricing api:'|| l_order_status_rec.ALL_LINES_FLAG);
12085                      IF l_has_prg_lines = 'Y' THEN
12086                         --fix bug 2788649,if PRG exists we will need to do price_line line per line                         --Need to call price_line line by line because PRG exists
12087                        adj_debug('New price action, line by line because the order has prg');
12088 
12089                        oe_order_Adj_pvt.Price_line(
12090                            X_Return_Status     => l_Return_Status
12091                            ,p_Request_Type_code=> 'ONT'
12092                            ,p_Control_rec      => l_Price_Control_Rec
12093                            ,p_Write_To_Db      => TRUE
12094                            ,p_Line_id          => l_line_id
12095                            ,x_Line_Tbl         => l_x_Line_Tbl
12096                            );
12097 
12098                      ELSE
12099                         --Regular old way,prepare all lines in one pl/sql table
12100                        adj_debug('Old price_action way, order has no prg');
12101                        Begin
12102 
12103                              l_x_line_tbl(i).Line_id := l_Line_id;
12104                              oe_Line_util.query_row(
12105                                 p_Line_id => l_Line_id
12106                              ,  x_line_rec => l_x_Line_Tbl(i)
12107                              );
12108                        Exception when no_data_found then
12109                                 null;
12110                        End;
12111 
12112                      END IF;
12113 
12114                 End loop;
12115 
12116                 IF l_has_prg_lines IN ('N','Q') THEN
12117                   oe_order_Adj_pvt.Price_line(
12118                         X_Return_Status     => l_Return_Status
12119                         ,p_Request_Type_code=> 'ONT'
12120                         ,p_Control_rec      => l_Price_Control_Rec
12121                         ,p_Write_To_Db      => TRUE
12122                         ,x_Line_Tbl         => l_x_Line_Tbl
12123                         );
12124                 END IF;
12125 
12126                  IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
12127                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
12128                  ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
12129                    RAISE FND_API.G_EXC_ERROR;
12130                  END IF;
12131 
12132 
12133 
12134         Else
12135                  -- Made changes to get Header Id from p_Header_list for Bug 2532740
12136 
12137                   l_delimiter2 := 0;
12138                 for i in 1..p_Header_count loop
12139                   l_delimiter1     := l_delimiter2;
12140                   l_delimiter2     := INSTR(p_Header_list,',',l_delimiter1+1);
12141 
12142                   If l_delimiter2 = 0 Then
12143                   l_HEader_id := to_number(substr(p_Header_list,l_delimiter1+1));
12144                   else
12145                   -- 2665650 fix
12146                   l_HEader_id := to_number(substr(p_Header_list,l_delimiter1+1,l_delimiter2-1-l_delimiter1));
12147                   end if;
12148 
12149                   adj_debug('Price Action Header_id :'||l_HEader_id);
12150                   -- End of changes for 2532740
12151 
12152                   Select booked_flag into l_booked_flag from oe_order_headers_all
12153                         where header_id=l_header_id;
12154 
12155                   --Following code are commented out due to unresolved dependencies issue
12156                   --with Oracle Pricing.  However, this code will greatly improve performance
12157                   --of action-->price_order if restored.
12158                   --In order for this commented code to work pricing patch
12159                   --1802580,1806021 and 1796034 must get applied.
12160 
12161                   If l_booked_flag <> 'Y' Then
12162                     l_price_control_rec.pricing_event := 'BATCH';
12163                     l_multiple_events := 'N';
12164                   Elsif  l_booked_flag = 'Y' Then
12165                     l_price_control_rec.pricing_event  := 'BATCH,BOOK,SHIP';
12166                     l_multiple_events := 'Y';
12167                   End If;
12168 
12169                     l_Price_Control_Rec.calculate_flag := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
12170                     l_Price_Control_Rec.Simulation_Flag := 'N';
12171 
12172 					--14647325  start
12173                         OE_Header_Util.Lock_Row
12174                         (p_header_id                    => l_header_id
12175                         ,p_x_header_rec         => l_locked_header_rec
12176                         ,x_return_status                => l_return_status
12177                         );
12178                         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
12179                           RAISE FND_API.G_EXC_ERROR;
12180                         ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
12181                         THEN
12182                           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
12183                         END IF;
12184                         --14647325  end
12185 
12186                     oe_order_Adj_pvt.Price_line(
12187                         X_Return_Status     => l_Return_Status
12188                         ,p_header_id            => l_header_id
12189                         ,p_Request_Type_code=> 'ONT'
12190                         ,p_Control_rec      => l_Price_Control_Rec
12191                         ,p_Write_To_Db      => TRUE
12192                         ,x_Line_Tbl         => l_x_Line_Tbl
12193                         ,p_multiple_events  => l_multiple_events
12194                         ,p_action_code      => 'PRICE_ORDER');
12195 
12196                     IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
12197                      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
12198                     ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
12199                      RAISE FND_API.G_EXC_ERROR;
12200                     END IF;
12201 
12202                 end loop; -- Headers
12203 
12204         End If;
12205 
12206      OE_MSG_PUB.Count_And_Get
12207      (   p_count                       => x_msg_count
12208      ,   p_data                        => x_msg_data
12209      );
12210 
12211         IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
12212                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
12213         ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
12214                 RAISE FND_API.G_EXC_ERROR;
12215         END IF;
12216 
12217         x_Return_Status := FND_API.G_RET_STS_SUCCESS;
12218 
12219         adj_debug('Exiting oe_order_Adj_pvt.Price_adjustments',1);
12220 
12221 
12222     EXCEPTION
12223 
12224             WHEN FND_API.G_EXC_ERROR THEN
12225                   x_return_status := FND_API.G_RET_STS_ERROR;
12226           OE_MSG_PUB.Count_And_Get
12227           ( p_count                       => x_msg_count
12228                    ,p_data                        => x_msg_data
12229            );
12230 
12231            WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
12232                   x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
12233           OE_MSG_PUB.Count_And_Get
12234           ( p_count                       => x_msg_count
12235            ,p_data                        => x_msg_data
12236           );
12237 
12238            WHEN OTHERS THEN
12239                   x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
12240                   adj_debug('           '||sqlerrm,1);
12241           OE_MSG_PUB.Count_And_Get
12242           (  p_count                       => x_msg_count
12243            , p_data                        => x_msg_data
12244           );
12245 
12246 end price_action;
12247 
12248 
12249 Procedure Set_Header(p_header IN quote_header_rec_type) As
12250 Begin
12251 oe_order_pub.g_hdr.accounting_rule_id            :=p_header.accounting_rule_id          ;
12252 oe_order_pub.g_hdr.agreement_id                  :=p_header.agreement_id                ;
12253 oe_order_pub.g_hdr.booked_flag                   :=p_header.booked_flag                 ;
12254 oe_order_pub.g_hdr.cancelled_flag                :=p_header.cancelled_flag              ;
12255 oe_order_pub.g_hdr.context                       :=p_header.context                     ;
12256 oe_order_pub.g_hdr.conversion_rate               :=p_header.conversion_rate             ;
12257 oe_order_pub.g_hdr.conversion_rate_date          :=p_header.conversion_rate_date        ;
12258 oe_order_pub.g_hdr.conversion_type_code          :=p_header.conversion_type_code        ;
12259 oe_order_pub.g_hdr.customer_preference_set_code  :=p_header.customer_preference_set_code;
12260 oe_order_pub.g_hdr.cust_po_number                :=p_header.cust_po_number              ;
12261 oe_order_pub.g_hdr.deliver_to_contact_id         :=p_header.deliver_to_contact_id       ;
12262 oe_order_pub.g_hdr.deliver_to_org_id             :=p_header.deliver_to_org_id           ;
12263 oe_order_pub.g_hdr.demand_class_code             :=p_header.demand_class_code           ;
12264 oe_order_pub.g_hdr.expiration_date               :=p_header.expiration_date             ;
12265 oe_order_pub.g_hdr.fob_point_code                :=p_header.fob_point_code              ;
12266 oe_order_pub.g_hdr.freight_carrier_code          :=p_header.freight_carrier_code        ;
12267 oe_order_pub.g_hdr.freight_terms_code            :=p_header.freight_terms_code          ;
12268 oe_order_pub.g_hdr.invoice_to_contact_id         :=p_header.invoice_to_contact_id       ;
12269 oe_order_pub.g_hdr.invoice_to_org_id             :=p_header.invoice_to_org_id           ;
12270 oe_order_pub.g_hdr.invoicing_rule_id             :=p_header.invoicing_rule_id           ;
12271 oe_order_pub.g_hdr.order_category_code           :=p_header.order_category_code         ;
12272 oe_order_pub.g_hdr.ordered_date                  :=p_header.ordered_date                ;
12273 oe_order_pub.g_hdr.order_date_type_code          :=p_header.order_date_type_code        ;
12274 oe_order_pub.g_hdr.order_number                  :=p_header.order_number                ;
12275 oe_order_pub.g_hdr.order_source_id               :=p_header.order_source_id             ;
12276 oe_order_pub.g_hdr.order_type_id                 :=p_header.order_type_id               ;
12277 oe_order_pub.g_hdr.org_id                        :=p_header.org_id                      ;
12278 oe_order_pub.g_hdr.payment_term_id               :=p_header.payment_term_id             ;
12279 oe_order_pub.g_hdr.price_list_id                 :=p_header.price_list_id               ;
12280 oe_order_pub.g_hdr.pricing_date                  :=p_header.pricing_date                ;
12281 oe_order_pub.g_hdr.request_date                  :=p_header.request_date                ;
12282 oe_order_pub.g_hdr.request_id                    :=p_header.request_id                  ;
12283 oe_order_pub.g_hdr.salesrep_id                   :=p_header.salesrep_id                 ;
12284 oe_order_pub.g_hdr.sales_channel_code            :=p_header.sales_channel_code          ;
12285 oe_order_pub.g_hdr.shipment_priority_code        :=p_header.shipment_priority_code      ;
12286 oe_order_pub.g_hdr.shipping_method_code          :=p_header.shipping_method_code        ;
12287 oe_order_pub.g_hdr.ship_from_org_id              :=p_header.ship_from_org_id            ;
12288 oe_order_pub.g_hdr.ship_to_contact_id            :=p_header.ship_to_contact_id          ;
12289 oe_order_pub.g_hdr.ship_to_org_id                :=p_header.ship_to_org_id              ;
12290 oe_order_pub.g_hdr.sold_from_org_id              :=p_header.sold_from_org_id            ;
12291 oe_order_pub.g_hdr.sold_to_contact_id            :=p_header.sold_to_contact_id          ;
12292 oe_order_pub.g_hdr.sold_to_org_id                :=p_header.sold_to_org_id              ;
12293 oe_order_pub.g_hdr.source_document_id            :=p_header.source_document_id          ;
12294 oe_order_pub.g_hdr.source_document_type_id       :=p_header.source_document_type_id     ;
12295 oe_order_pub.g_hdr.transactional_curr_code       :=p_header.transactional_curr_code     ;
12296 oe_order_pub.g_hdr.drop_ship_flag                :=p_header.drop_ship_flag              ;
12297 oe_order_pub.g_hdr.customer_payment_term_id      :=p_header.customer_payment_term_id    ;
12298 oe_order_pub.g_hdr.payment_type_code             :=p_header.payment_type_code           ;
12299 oe_order_pub.g_hdr.payment_amount                :=p_header.payment_amount              ;
12300 oe_order_pub.g_hdr.credit_card_code              :=p_header.credit_card_code            ;
12301 oe_order_pub.g_hdr.credit_card_holder_name       :=p_header.credit_card_holder_name     ;
12302 oe_order_pub.g_hdr.credit_card_number            :=p_header.credit_card_number          ;
12303 oe_order_pub.g_hdr.marketing_source_code_id      :=p_header.marketing_source_code_id    ;
12304 
12305 End Set_Header;
12306 
12307 Procedure Load_Line_Tbl(p_quote_line_tbl in  quote_line_tbl_type,
12308 x_line_tbl out nocopy Oe_Order_Pub.line_tbl_type) As
12309 
12310 i PLS_INTEGER;
12311 Begin
12312   --DBMS_OUTPUT.PUT_LINE('In load line tbl');
12313   i := p_quote_line_tbl.First;
12314   While i Is Not Null Loop
12315      x_line_tbl(i).actual_arrival_date        :=p_quote_line_tbl(i).actual_arrival_date        ;
12316      x_line_tbl(i).actual_shipment_date       :=p_quote_line_tbl(i).actual_shipment_date       ;
12317      x_line_tbl(i).agreement_id               :=p_quote_line_tbl(i).agreement_id               ;
12318      x_line_tbl(i).cancelled_quantity         :=p_quote_line_tbl(i).cancelled_quantity         ;
12319      x_line_tbl(i).cust_po_number             :=p_quote_line_tbl(i).cust_po_number             ;
12320      x_line_tbl(i).deliver_to_contact_id      :=p_quote_line_tbl(i).deliver_to_contact_id      ;
12321      x_line_tbl(i).deliver_to_org_id          :=p_quote_line_tbl(i).deliver_to_org_id          ;
12322      x_line_tbl(i).freight_carrier_code       :=p_quote_line_tbl(i).freight_carrier_code       ;
12323      x_line_tbl(i).freight_terms_code         :=p_quote_line_tbl(i).freight_terms_code         ;
12324      x_line_tbl(i).intermed_ship_to_org_id    :=p_quote_line_tbl(i).intermed_ship_to_org_id    ;
12325      x_line_tbl(i).intermed_ship_to_contact_id:=p_quote_line_tbl(i).intermed_ship_to_contact_id;
12326      x_line_tbl(i).inventory_item_id          :=p_quote_line_tbl(i).inventory_item_id          ;
12327      x_line_tbl(i).invoice_interface_status_code:=p_quote_line_tbl(i).invoice_interface_status_code;
12328      x_line_tbl(i).invoice_to_contact_id      :=p_quote_line_tbl(i).invoice_to_contact_id      ;
12329      x_line_tbl(i).invoice_to_org_id          :=p_quote_line_tbl(i).invoice_to_org_id          ;
12330      x_line_tbl(i).ordered_item               :=p_quote_line_tbl(i).ordered_item               ;
12331      x_line_tbl(i).item_type_code             :=p_quote_line_tbl(i).item_type_code             ;
12332      x_line_tbl(i).line_type_id               :=p_quote_line_tbl(i).line_type_id               ;
12333      x_line_tbl(i).ordered_quantity           :=p_quote_line_tbl(i).ordered_quantity           ;
12334      x_line_tbl(i).ordered_quantity2          :=p_quote_line_tbl(i).ordered_quantity2          ;
12335      x_line_tbl(i).order_quantity_uom         :=p_quote_line_tbl(i).order_quantity_uom         ;
12336      x_line_tbl(i).ordered_quantity_uom2      :=p_quote_line_tbl(i).ordered_quantity_uom2      ;
12337      x_line_tbl(i).org_id                     :=p_quote_line_tbl(i).org_id                     ;
12338      x_line_tbl(i).payment_term_id            :=p_quote_line_tbl(i).payment_term_id            ;
12339      x_line_tbl(i).price_list_id              :=p_quote_line_tbl(i).price_list_id              ;
12340      x_line_tbl(i).pricing_context            :=p_quote_line_tbl(i).pricing_context            ;
12341      x_line_tbl(i).pricing_date               :=p_quote_line_tbl(i).pricing_date               ;
12342      x_line_tbl(i).pricing_quantity           :=p_quote_line_tbl(i).pricing_quantity           ;
12343      x_line_tbl(i).pricing_quantity_uom       :=p_quote_line_tbl(i).pricing_quantity_uom       ;
12344      x_line_tbl(i).project_id                 :=p_quote_line_tbl(i).project_id                 ;
12345      x_line_tbl(i).promise_date               :=p_quote_line_tbl(i).promise_date               ;
12346      x_line_tbl(i).salesrep_id                :=p_quote_line_tbl(i).salesrep_id                ;
12347      x_line_tbl(i).schedule_arrival_date      :=p_quote_line_tbl(i).schedule_arrival_date      ;
12348      x_line_tbl(i).schedule_ship_date         :=p_quote_line_tbl(i).schedule_ship_date         ;
12349      x_line_tbl(i).ship_from_org_id           :=p_quote_line_tbl(i).ship_from_org_id           ;
12350      x_line_tbl(i).ship_to_org_id             :=p_quote_line_tbl(i).ship_to_org_id             ;
12351      x_line_tbl(i).sold_to_org_id             :=p_quote_line_tbl(i).sold_to_org_id             ;
12352      x_line_tbl(i).sold_from_org_id           :=p_quote_line_tbl(i).sold_from_org_id           ;
12353      x_line_tbl(i).source_document_type_id    :=p_quote_line_tbl(i).source_document_type_id    ;
12354      x_line_tbl(i).task_id                    :=p_quote_line_tbl(i).task_id                    ;
12355      x_line_tbl(i).tax_code                   :=p_quote_line_tbl(i).tax_code                   ;
12356      x_line_tbl(i).unit_list_price_per_pqty   :=p_quote_line_tbl(i).unit_list_price            ;
12357      x_line_tbl(i).unit_selling_price_per_pqty:=p_quote_line_tbl(i).unit_selling_price         ;
12358      x_line_tbl(i).order_source_id            :=p_quote_line_tbl(i).order_source_id            ;
12359      x_line_tbl(i).customer_payment_term_id   :=p_quote_line_tbl(i).customer_payment_term_id   ;
12360      x_line_tbl(i).ordered_item_id            :=p_quote_line_tbl(i).ordered_item_id            ;
12361      x_line_tbl(i).item_identifier_type       :=p_quote_line_tbl(i).item_identifier_type       ;
12362      x_line_tbl(i).unit_list_percent          :=p_quote_line_tbl(i).unit_list_percent          ;
12363      x_line_tbl(i).unit_selling_percent       :=p_quote_line_tbl(i).unit_selling_percent       ;
12364      x_line_tbl(i).unit_percent_base_price    :=p_quote_line_tbl(i).unit_percent_base_price    ;
12365      x_line_tbl(i).service_number             :=p_quote_line_tbl(i).service_number             ;
12366      x_line_tbl(i).revenue_amount             :=p_quote_line_tbl(i).revenue_amount             ;
12367      x_line_tbl(i).line_id                    :=p_quote_line_tbl(i).line_id                    ;
12368     i :=p_quote_line_tbl.Next(i);
12369     /*if i > 100 then DBMS_OUTPUT.PUT_LINE('Inf Loop2'); end if;
12370     exit when i > 100; */
12371   End Loop;
12372 
12373 End;
12374 
12375 Procedure Load_Out_Quote_Line (p_line_tbl       In  Oe_Order_Pub.Line_tbl_Type,
12376                                p_req_line_tbl   In  QP_PREQ_GRP.LINE_TBL_TYPE,
12377 x_quote_line_tbl out nocopy quote_line_tbl_type) As
12378 
12379 i PLS_INTEGER;
12380 Begin
12381  --DBMS_OUTPUT.PUT_LINE('In load out quote');
12382  i := p_line_tbl.First;
12383  While i Is Not Null Loop
12384      x_quote_line_tbl(i).actual_arrival_date        :=p_line_tbl(i).actual_arrival_date        ;
12385      x_quote_line_tbl(i).actual_shipment_date       :=p_line_tbl(i).actual_shipment_date       ;
12386      x_quote_line_tbl(i).agreement_id               :=p_line_tbl(i).agreement_id               ;
12387      x_quote_line_tbl(i).cancelled_quantity         :=p_line_tbl(i).cancelled_quantity         ;
12388      x_quote_line_tbl(i).cust_po_number             :=p_line_tbl(i).cust_po_number             ;
12389      x_quote_line_tbl(i).deliver_to_contact_id      :=p_line_tbl(i).deliver_to_contact_id      ;
12390      x_quote_line_tbl(i).deliver_to_org_id          :=p_line_tbl(i).deliver_to_org_id          ;
12391      x_quote_line_tbl(i).freight_carrier_code       :=p_line_tbl(i).freight_carrier_code       ;
12392      x_quote_line_tbl(i).freight_terms_code         :=p_line_tbl(i).freight_terms_code         ;
12393      x_quote_line_tbl(i).intermed_ship_to_org_id    :=p_line_tbl(i).intermed_ship_to_org_id    ;
12394      x_quote_line_tbl(i).intermed_ship_to_contact_id:=p_line_tbl(i).intermed_ship_to_contact_id;
12395      x_quote_line_tbl(i).inventory_item_id          :=p_line_tbl(i).inventory_item_id          ;
12396      x_quote_line_tbl(i).invoice_interface_status_code:=p_line_tbl(i).invoice_interface_status_code;
12397      x_quote_line_tbl(i).invoice_to_contact_id      :=p_line_tbl(i).invoice_to_contact_id      ;
12398      x_quote_line_tbl(i).invoice_to_org_id          :=p_line_tbl(i).invoice_to_org_id          ;
12399      x_quote_line_tbl(i).ordered_item               :=p_line_tbl(i).ordered_item               ;
12400      x_quote_line_tbl(i).item_type_code             :=p_line_tbl(i).item_type_code             ;
12401      x_quote_line_tbl(i).line_type_id               :=p_line_tbl(i).line_type_id               ;
12402      x_quote_line_tbl(i).ordered_quantity           :=p_line_tbl(i).ordered_quantity           ;
12403      x_quote_line_tbl(i).ordered_quantity2          :=p_line_tbl(i).ordered_quantity2          ;
12404      x_quote_line_tbl(i).order_quantity_uom         :=p_line_tbl(i).order_quantity_uom         ;
12405      x_quote_line_tbl(i).ordered_quantity_uom2      :=p_line_tbl(i).ordered_quantity_uom2      ;
12406      x_quote_line_tbl(i).org_id                     :=p_line_tbl(i).org_id                     ;
12407      x_quote_line_tbl(i).payment_term_id            :=p_line_tbl(i).payment_term_id            ;
12408      x_quote_line_tbl(i).price_list_id              :=p_line_tbl(i).price_list_id              ;
12409      x_quote_line_tbl(i).pricing_context            :=p_line_tbl(i).pricing_context            ;
12410      x_quote_line_tbl(i).pricing_date               :=p_line_tbl(i).pricing_date               ;
12411      x_quote_line_tbl(i).pricing_quantity           :=p_line_tbl(i).pricing_quantity           ;
12412      x_quote_line_tbl(i).pricing_quantity_uom       :=p_line_tbl(i).pricing_quantity_uom       ;
12413      x_quote_line_tbl(i).project_id                 :=p_line_tbl(i).project_id                 ;
12414      x_quote_line_tbl(i).promise_date               :=p_line_tbl(i).promise_date               ;
12415      x_quote_line_tbl(i).salesrep_id                :=p_line_tbl(i).salesrep_id                ;
12416      x_quote_line_tbl(i).schedule_arrival_date      :=p_line_tbl(i).schedule_arrival_date      ;
12417      x_quote_line_tbl(i).schedule_ship_date         :=p_line_tbl(i).schedule_ship_date         ;
12418      x_quote_line_tbl(i).ship_from_org_id           :=p_line_tbl(i).ship_from_org_id           ;
12419      x_quote_line_tbl(i).ship_to_org_id             :=p_line_tbl(i).ship_to_org_id             ;
12420      x_quote_line_tbl(i).sold_to_org_id             :=p_line_tbl(i).sold_to_org_id             ;
12421      x_quote_line_tbl(i).sold_from_org_id           :=p_line_tbl(i).sold_from_org_id           ;
12422      x_quote_line_tbl(i).source_document_type_id    :=p_line_tbl(i).source_document_type_id    ;
12423      x_quote_line_tbl(i).task_id                    :=p_line_tbl(i).task_id                    ;
12424      x_quote_line_tbl(i).tax_code                   :=p_line_tbl(i).tax_code                   ;
12425      x_quote_line_tbl(i).unit_list_price            :=p_line_tbl(i).unit_list_price_per_pqty   ;
12426      x_quote_line_tbl(i).unit_selling_price         :=p_line_tbl(i).unit_selling_price_per_pqty;
12427      x_quote_line_tbl(i).order_source_id            :=p_line_tbl(i).order_source_id            ;
12428      x_quote_line_tbl(i).customer_payment_term_id   :=p_line_tbl(i).customer_payment_term_id   ;
12429      x_quote_line_tbl(i).ordered_item_id            :=p_line_tbl(i).ordered_item_id            ;
12430      x_quote_line_tbl(i).item_identifier_type       :=p_line_tbl(i).item_identifier_type       ;
12431      x_quote_line_tbl(i).unit_list_percent          :=p_line_tbl(i).unit_list_percent          ;
12432      x_quote_line_tbl(i).unit_selling_percent       :=p_line_tbl(i).unit_selling_percent       ;
12433      x_quote_line_tbl(i).unit_percent_base_price    :=p_line_tbl(i).unit_percent_base_price    ;
12434      x_quote_line_tbl(i).service_number             :=p_line_tbl(i).service_number             ;
12435      x_quote_line_tbl(i).revenue_amount             :=p_line_tbl(i).revenue_amount             ;
12436      x_quote_line_tbl(i).line_id                    :=p_line_tbl(i).line_id                    ;
12437      --use this attribute for place holder of status code. Because there are
12438      --no place holder for status on line_rec record type
12439      If (p_line_tbl(i).industry_attribute30) In
12440                                (QP_PREQ_GRP.G_STATUS_INVALID_PRICE_LIST,
12441 				QP_PREQ_GRP.G_STS_LHS_NOT_FOUND,
12442 				QP_PREQ_GRP.G_STATUS_FORMULA_ERROR,
12443 				QP_PREQ_GRP.G_STATUS_OTHER_ERRORS,
12444 				FND_API.G_RET_STS_UNEXP_ERROR,
12445 				FND_API.G_RET_STS_ERROR,
12446 				QP_PREQ_GRP.G_STATUS_CALC_ERROR,
12447 				QP_PREQ_GRP.G_STATUS_UOM_FAILURE,
12448 				QP_PREQ_GRP.G_STATUS_INVALID_UOM,
12449 				QP_PREQ_GRP.G_STATUS_DUP_PRICE_LIST,
12450 				QP_PREQ_GRP.G_STATUS_INVALID_UOM_CONV,
12451 				QP_PREQ_GRP.G_STATUS_INVALID_INCOMP,
12452 				QP_PREQ_GRP.G_STATUS_BEST_PRICE_EVAL_ERROR
12453                                 ) Then
12454 
12455        x_quote_line_tbl(i).Status_Code:= p_line_tbl(i).industry_attribute30;
12456         --DBMS_OUTPUT.PUT_LINE('+++F++:'||x_quote_line_tbl(i).Status_Code);
12457      Else
12458         x_quote_line_tbl(i).Status_Code:=FND_API.G_RET_STS_SUCCESS;
12459         --DBMS_OUTPUT.PUT_LINE('+++S++:'|| x_quote_line_tbl(i).Status_Code);
12460      End If;
12461 
12462      i:= p_line_tbl.Next(i);
12463 
12464  End Loop;
12465 
12466 End;
12467 
12468 Procedure Get_Quote(p_quote_header       in  quote_header_rec_type,
12469                     p_quote_line_tbl     in  quote_line_tbl_type,
12470                     p_request_type_code  in  Varchar2,  --'ONT','QP' etc
12471                     p_event              in  varchar2 default 'BATCH',
12472 x_quote_line_tbl out nocopy quote_line_tbl_type,
12473 
12474 x_return_status out nocopy Varchar2,
12475 
12476 x_return_status_text out nocopy Varchar2) As
12477 
12478 
12479 l_line_tbl Oe_Order_Pub.line_tbl_type;
12480 l_control_rec Qp_Preq_Grp.control_record_type;
12481 l_req_line_tbl                 QP_PREQ_GRP.LINE_TBL_TYPE;
12482 l_Req_qual_tbl                 QP_PREQ_GRP.QUAL_TBL_TYPE;
12483 l_Req_line_attr_tbl            QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
12484 l_Req_LINE_DETAIL_tbl          QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
12485 l_Req_LINE_DETAIL_qual_tbl     QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
12486 l_Req_LINE_DETAIL_attr_tbl     QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
12487 l_Req_related_lines_tbl        QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
12488 l_any_frozen_line              Boolean;
12489 l_hdr_rec                      Oe_Order_Pub.Header_Rec_Type;
12490 l_stmt                         Varchar2(50);
12491 i PLS_INTEGER;
12492 Begin
12493 
12494  Set_Header(p_quote_header);
12495  Load_line_Tbl(p_quote_line_tbl,l_line_tbl);
12496 
12497  --getting a quote is always a batch event
12498  l_control_rec.pricing_event := p_event;
12499 
12500  l_control_rec.calculate_flag  := QP_PREQ_GRP.G_SEARCH_N_CALCULATE;
12501  l_control_rec.simulation_Flag := 'N';
12502            l_stmt := 'quote 1';
12503            calculate_adjustments
12504                        (x_return_status		     =>x_return_status             ,
12505                         p_Request_Type_Code	     =>p_request_type_code         ,
12506                         p_Control_Rec		     =>l_control_rec               ,
12507                         x_req_line_tbl               =>l_req_line_tbl              ,
12508                         x_Req_qual_tbl               =>l_Req_qual_tbl              ,
12509                         x_Req_line_attr_tbl          =>l_Req_line_attr_tbl         ,
12510                         x_Req_LINE_DETAIL_tbl        =>l_Req_LINE_DETAIL_tbl       ,
12511                         x_Req_LINE_DETAIL_qual_tbl   =>l_Req_LINE_DETAIL_qual_tbl  ,
12512                         x_Req_LINE_DETAIL_attr_tbl   =>l_Req_LINE_DETAIL_attr_tbl  ,
12513                         x_Req_related_lines_tbl      =>l_Req_related_lines_tbl     ,
12514                         p_use_current_header         =>TRUE,
12515                         p_write_to_db		     =>FALSE,
12516                         x_any_frozen_line            =>l_any_frozen_line,
12517                         x_Header_Rec		     =>l_hdr_rec,
12518                         x_line_Tbl                   =>l_line_tbl);
12519 
12520            l_stmt := 'quote 2';
12521 
12522           process_adjustments
12523 	  (
12524 	  p_Request_Type_Code 	           => p_request_type_code,
12525 	  x_return_status         	   => x_Return_Status,
12526 	  p_Req_Control_Rec                => l_control_rec,
12527 	  p_req_line_tbl                   => l_req_line_tbl,
12528 	  p_Req_qual_tbl                   => l_Req_qual_tbl,
12529 	  p_Req_line_attr_tbl              => l_Req_line_attr_tbl,
12530 	  p_Req_Line_Detail_tbl            => l_Req_LINE_DETAIL_tbl,
12531 	  p_Req_Line_Detail_Qual_tbl       => l_Req_LINE_DETAIL_qual_tbl,
12532 	  p_Req_Line_Detail_Attr_tbl       => l_Req_LINE_DETAIL_attr_tbl,
12533 	  p_Req_related_lines_tbl          => l_Req_related_lines_tbl,
12534 	  p_write_to_db			   => FALSE,
12535           p_any_frozen_line                => l_any_frozen_line,
12536 	  p_Header_Rec			   => l_Hdr_Rec,
12537 	  x_line_Tbl			   => l_Line_Tbl,
12538           p_honor_price_flag    => 'Y'  --bug 2503186
12539 	  );
12540 
12541          Load_Out_Quote_Line(l_Line_Tbl,l_req_line_tbl,x_quote_line_tbl);
12542 
12543 Exception
12544   When Others Then
12545   x_return_status := FND_API.G_RET_STS_ERROR;
12546   x_return_status_text := 'Oe_Order_Adj_Pvt.Get_Quote: '||l_stmt||': '||SQLERRM;
12547 
12548 End get_quote;
12549 
12550 /***************************************************************************************************
12551 Procedure Create_Manual_Adjustments
12552 Purpose     : Insert manual overriable adjustment into Oe_Price_Adjustments
12553 Called by   : Mass Change pld
12554 Known Issues: Doesn't handle order level manual overriable adjustment
12555 ****************************************************************************************************/
12556 Procedure Create_Manual_Adjustments(p_line_id In Number)
12557 As
12558 l_return_stauts   Varchar2(15);
12559 l_manual_adj_tbl  Oe_Order_Adj_Pvt.Manual_Adj_Tbl_Type;
12560 l_line_adj_tbl    Oe_Order_Pub.line_adj_tbl_type;
12561 l_dummy_tbl       Oe_Order_Pub.line_adj_tbl_type;
12562 l_control_rec     OE_GLOBALS.Control_Rec_Type;
12563 i PLS_INTEGER;
12564 k PLS_INTEGER:=1;
12565 l_return_status Varchar2(15);
12566 l_found Varchar2(1):='N';
12567 stmt Varchar2(240);
12568 l_header_id NUMBER;
12569 
12570 
12571 Begin
12572   l_control_rec.private_call         := TRUE;
12573   l_control_rec.controlled_operation := TRUE;
12574   l_control_rec.check_security       := FALSE;
12575   l_control_rec.validate_entity      := FALSE;
12576   l_control_rec.write_to_db          := TRUE;
12577   l_control_rec.change_attributes    := FALSE;
12578 
12579   Oe_Debug_Pub.add('Mass Change line id: '||p_line_id);
12580   stmt:='1';
12581 
12582   --For mass change it could be different order headers for lines therefore p_cross_order = 'Y'
12583   Get_Manual_Adjustments(p_line_id        => p_line_id,
12584                          p_cross_order    => 'Y',
12585                          x_manual_adj_tbl => l_manual_adj_tbl,
12586                          x_return_status  => l_return_status,
12587                          x_header_id      => l_header_id,
12588                          p_called_from    => 'SO');
12589   stmt:='2';
12590   i := l_manual_adj_tbl.First;
12591   While i Is Not Null Loop
12592     If l_manual_adj_tbl(i).override_flag = 'Y' Then
12593       --check if such modifier list exists in Oe_Price_Adjustments
12594       --If it is there don't insert a new one
12595       Oe_debug_Pub.add('  Override_flag:'||l_manual_adj_tbl(i).override_flag);
12596       Begin
12597        Select 'Y' Into l_found
12598        From Dual
12599        Where exists (Select 'X' From Oe_Price_Adjustments
12600                      Where  line_id = p_line_id
12601                      and    list_line_id = l_manual_adj_tbl(i).list_line_id);
12602        l_found:='Y';
12603       Exception
12604          When No_Data_Found Then
12605          l_found := 'N';
12606       End;
12607          stmt:='10';
12608         --Insert only if no modifier list line found.
12609         If l_found = 'N' Then
12610          oe_debug_pub.add(' Creating overridable manual in oe_price_adjustments');
12611          l_line_adj_tbl(1).list_line_no          := l_manual_adj_tbl(i).modifier_number; /* Bug #3738023 */
12612          l_line_adj_tbl(1).list_header_id        := l_manual_adj_tbl(i).list_header_id;
12613          l_line_adj_tbl(1).list_line_id          := l_manual_adj_tbl(i).list_line_id;
12614          l_line_adj_tbl(1).list_line_type_code   := l_manual_adj_tbl(i).list_line_type_code;
12615          l_line_adj_tbl(1).modifier_level_code   := l_manual_adj_tbl(i).modifier_level_code;
12616          l_line_adj_tbl(1).operand               := l_manual_adj_tbl(i).operand;
12617          l_line_adj_tbl(1).arithmetic_operator   := l_manual_adj_tbl(i).operator;
12618          l_line_adj_tbl(1).update_allowed        := l_manual_adj_tbl(i).override_flag;
12619          l_line_adj_tbl(k).header_id             := l_header_id;
12620          l_line_adj_tbl(1).line_id               := p_line_id;
12621          l_line_adj_tbl(1).applied_flag          := 'N';
12622          l_line_adj_tbl(1).updated_flag          := 'N';
12623          l_line_adj_tbl(1).automatic_flag        := 'N';
12624          l_line_adj_tbl(1).operation             := OE_GLOBALS.G_OPR_CREATE;
12625          Select Oe_Price_Adjustments_S.Nextval
12626          Into   l_line_adj_tbl(1).price_adjustment_id
12627          From   dual;
12628           stmt:='20';
12629          Line_Adjs(p_validation_level => FND_API.G_VALID_LEVEL_NONE,
12630                    p_control_rec              => l_control_rec,
12631                    p_x_line_adj_tbl           => l_line_adj_tbl,
12632                    p_x_old_line_adj_tbl       => l_dummy_tbl);
12633            stmt:='30';
12634        End If;
12635       --k:=k+1;
12636     End If;
12637    i:= l_manual_adj_tbl.Next(i);
12638   End Loop;
12639 
12640 Exception When Others Then
12641   Oe_Debug_Pub.Add('Error occured in oe_order_adj_pvt.create_manual_adjustments:'||stmt||':'||SQLERRM);
12642   Raise;
12643 End Create_Manual_Adjustments;
12644 
12645 
12646 
12647 /******************************************************************************************************
12648  Procedure Get_Manual_Adjustments
12649  Called by: Unit selling price lov
12650  Purpose: Return manual adjustments
12651  Input:
12652  p_header_id: For the case of linegroup manual adjustment, all lines will need to pass to engine
12653               for evaluation.
12654  p_line_rec:  For the case of no linegroup manual adjustment, one line rec is sufficient
12655 *******************************************************************************************************/
12656 
12657 Procedure Get_Manual_Adjustments (
12658 p_header_id        in  number                     Default Null,
12659 p_line_id          in  number                     Default Null,
12660 p_line_rec         in  oe_Order_Pub.Line_Rec_Type Default oe_order_pub.g_miss_line_rec,
12661 p_level            in  Varchar2 default 'LINE',
12662 p_pbh_mode         in  Varchar2 default 'CHILD',
12663 p_cross_order      in  Varchar2 Default 'N',
12664 p_line_level       in  Varchar2 Default 'N',
12665 x_manual_adj_tbl   out Nocopy  Oe_Order_Adj_Pvt.Manual_Adj_Tbl_Type,
12666 x_return_status out nocopy Varchar2,
12667 
12668 x_header_id out nocopy Number,
12669 p_freight_flag     in boolean default false,
12670 p_called_from      in varchar2 default null
12671 
12672  --if no header id passed in this procedure it will return header id based on line id passed in
12673 )
12674 As
12675 l_profile_value                 Varchar2(1):= Nvl(Fnd_Profile.Value('ONT_MANUAL_LINEGROUP'),'Y');
12676 l_line_tbl                      oe_Order_Pub.Line_tbl_Type;
12677 l_line_rec                      oe_order_pub.line_rec_type;
12678 l_pricing_contexts_Tbl		QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
12679 l_qualifier_contexts_Tbl	QP_Attr_Mapping_PUB.Contexts_Result_Tbl_Type;
12680 l_Req_qual_tbl                  QP_PREQ_GRP.QUAL_TBL_TYPE;
12681 l_Req_line_attr_tbl             QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
12682 l_req_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE;
12683 l_Req_LINE_DETAIL_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
12684 l_Req_LINE_DETAIL_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
12685 l_Req_LINE_DETAIL_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
12686 l_Req_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
12687 lx_Req_qual_tbl                  QP_PREQ_GRP.QUAL_TBL_TYPE;
12688 lx_Req_line_attr_tbl             QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
12689 lx_req_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE;
12690 lx_Req_LINE_DETAIL_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
12691 lx_Req_LINE_DETAIL_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
12692 lx_Req_LINE_DETAIL_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
12693 lx_Req_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
12694 l_Control_Rec			QP_PREQ_GRP.CONTROL_RECORD_TYPE;
12695 l_event                         Varchar2(30) Default 'BATCH';
12696 l_return_status                 Varchar2(10);
12697 l_return_status_text            Varchar2(240);
12698 i PLS_INTEGER;
12699 j PLS_INTEGER;
12700 k PLS_INTEGER;
12701 line_tbl_index PLS_INTEGER;
12702 QP_ATTR_MAPPING_ERRORS Exception;
12703 
12704 l_ask_for_profile              Varchar2(1):=NVL(Fnd_Profile.Value('ONT_ASK_FOR_PROMOTION'),'Y');
12705 l_dummy                        Varchar2(1);
12706 
12707 l_header_id Number;
12708 --indicates whether line has already been written to DB
12709 l_posted_to_DB BOOLEAN := FALSE;
12710 l_header_id2 NUMBER;
12711 --bucket man
12712 l_pass_line varchar2(1);
12713 l_check_line_flag varchar2(1); --5598523
12714 l_line_index NUMBER := 0;
12715 l_line_attr_index number:=0;
12716 --bug 3531938
12717 l_order_status_rec QP_UTIL_PUB.ORDER_LINES_STATUS_REC_TYPE;
12718 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
12719 
12720 l_manual_all_lines_status         Varchar2(1); --bug 7600510
12721 
12722 cursor man_adj is
12723        select ld.automatic_flag, ld.line_index, ld.modifier_level_code,
12724        ld.line_quantity, ld.line_detail_type_code,
12725        ld.CREATED_FROM_LIST_LINE_TYPE list_line_type_code,
12726        ld.list_line_no, ld.operand_value,
12727        ld.CREATED_FROM_LIST_LINE_ID list_line_id,
12728        ld.CREATED_FROM_LIST_HEADER_ID list_header_id,
12729        ld.pricing_phase_id, ll.override_flag, ld.operand_calculation_code,
12730        ld.ADJUSTMENT_AMOUNT, ll.CHARGE_TYPE_CODE, ll.CHARGE_SUBTYPE_CODE,
12731        l.line_type_code, l.line_id, ld.PRICE_BREAK_TYPE_CODE,
12732        ld.pricing_group_sequence
12733        from QP_PREQ_LINES_TMP l, QP_PREQ_LDETS_TMP ld, QP_LIST_LINES ll
12734        where l.line_index = ld.line_index
12735          and ld.CREATED_FROM_LIST_LINE_ID = ll.LIST_LINE_ID
12736          and ld.PRICING_STATUS_CODE = QP_PREQ_GRP.G_STATUS_NEW
12737        ORDER BY ld.list_line_no; -- bug 6323362
12738 
12739 --bucket man
12740 Begin
12741     if p_freight_flag then
12742        oe_debug_pub.add('freight flag is true');
12743     else
12744        oe_debug_pub.add('freight flag is false');
12745     end if;
12746    x_return_status:=FND_API.G_RET_STS_SUCCESS;
12747    --l_profile_value := Fnd_Profile.Value('QP_MANUAL_LINEGROUP');
12748    oe_debug_pub.add('Entering Get Manual Adj');
12749  --bucket man
12750    IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
12751         oe_order_price_pvt.reset_all_tbls;
12752         qp_price_request_context.set_request_id;
12753    END IF;
12754  -- bucket man
12755 
12756    G_STMT_NO := 'Get_manual_adjustment#0';
12757 
12758 
12759    --this profile_value is to indicate if want to pass all the lines or just one line
12760    --to pricing engine
12761    --In the case of order level manual adjustments we will always pass in
12762    --all the lines regardless of profile_value
12763    --bug 3531938 calling qp api to determine whether to pass all lines
12764        -- bug 9728497 start
12765        -- modified below for p_x_new_line_rec.header_id and p_x_new_line_rec.line_id
12766        -- being passed on to call the overloaded function.
12767        -- QP_UTIL_PUB.Get_Order_Lines_Status('BATCH',l_order_status_rec);
12768           QP_UTIL_PUB.Get_Order_Lines_Status(p_event_code => 'BATCH',
12769                                         p_header_id => p_header_id,
12770                                         p_line_id => p_Line_id,
12771                                         x_order_status_rec =>l_order_status_rec);
12772        -- bug 9728497 end
12773 
12774 
12775                 oe_debug_pub.add('  All_lines_flag returned from pricing:'||l_order_status_rec.all_lines_flag);
12776 -- bug 6817566
12777     oe_debug_pub.add(' manual_adv_modifier '||OE_GLOBALS.G_MANUAL_ADV_MODIFIER);
12778 
12779    IF (OE_GLOBALS.G_MANUAL_ADV_MODIFIER IS NULL AND (p_level = 'ORDER' or l_order_status_rec.ALL_LINES_FLAG = 'Y')) THEN
12780         oe_debug_pub.add(' manual_adv_modifier 1 '||OE_GLOBALS.G_MANUAL_ADV_MODIFIER);
12781         oe_debug_pub.add(' p_level '||p_level);
12782         oe_debug_pub.add(' Check for Manual Advanced modifiers ',3);
12783         --- bug# 7600510  Start
12784 --        GET_MANUAL_ADV_STATUS('BATCH');
12785         QP_UTIL_PUB.Get_Manual_All_Lines_Status ('BATCH', l_manual_all_lines_status ) ;
12786         OE_GLOBALS.G_MANUAL_ADV_MODIFIER := l_manual_all_lines_status;
12787         --- bug# 7600510  End
12788         oe_debug_pub.add(' manual_adv_modifier 2 '||OE_GLOBALS.G_MANUAL_ADV_MODIFIER);
12789    END IF;
12790 
12791    IF (((p_level = 'ORDER' or l_order_status_rec.ALL_LINES_FLAG = 'Y')
12792    AND(p_level = 'ORDER' or  OE_GLOBALS.G_MANUAL_ADV_MODIFIER = 'Y')) -- 6851818
12793    AND p_header_id Is Not Null) Then
12794 
12795     if  not (p_level = 'ORDER' and p_freight_flag) then --- bug 7655559
12796 	      --passing all lines under this header
12797 	      oe_debug_pub.add('  Query Rows under same header');
12798 
12799 	      oe_Line_util.query_rows(p_header_id => p_Header_id, x_line_tbl => l_Line_Tbl);
12800 	      oe_debug_pub.add('#of rows returned='|| to_char(l_line_tbl.count));
12801 	      oe_debug_pub.add('no.rows in l_line_tbl = '|| to_char(l_line_tbl.count));
12802 
12803 	      -- Bug 1713035
12804 	      -- Loop through all the lines in database
12805 	      -- Replace with the line in memory if found
12806 	      -- else append
12807 
12808 	      oe_debug_pub.add('Get line currently in memory');
12809 	      OE_OE_FORM_LINE.get_line(p_line_id => p_line_id,
12810 				       x_line_rec => l_line_rec);
12811 	      For i in 1..l_line_tbl.count Loop
12812 		if (l_line_tbl(i).line_id = l_line_rec.line_id) then
12813 			oe_debug_pub.add('Line already posted to DB, so replace');
12814 			l_posted_to_db := TRUE;
12815 			l_line_tbl(i) := l_line_rec;
12816 			exit;
12817 		end if;
12818 	      end loop;
12819 
12820 	      if NOT l_posted_to_db then
12821 		oe_debug_pub.add('line not in DB, new line');
12822 		oe_debug_pub.add('appending line with line_id '
12823 				|| to_char(p_line_id) ||
12824 				' to l_line_tbl');
12825 		/*Bug 3280291*/
12826 		IF l_line_rec.line_id is not NULL THEN
12827 		   l_line_tbl(l_line_tbl.count + 1) := l_line_rec;
12828 		END IF;
12829 	      end if;
12830     end if;--- bug 7655559
12831 
12832    Elsif p_line_id is not null Then
12833       --just pass one line
12834       oe_debug_pub.add('  Query Rows under for line line id:'||p_line_id);
12835       --oe_line_util.query_row(p_line_id =>p_line_id,x_line_rec=>l_line_rec);
12836 
12837       -- Bug 1713035
12838       -- Use oe_oe_form_line.get_line instead of query_rows
12839       oe_debug_pub.add('calling get_line in oe_oe_form_line');
12840       OE_OE_FORM_LINE.get_line(
12841 			p_line_id => p_line_id,
12842 			x_line_rec => l_line_rec);
12843 
12844       l_line_tbl(1):=l_line_rec;
12845    Else
12846       l_line_tbl(1):= p_line_rec;
12847    End If;
12848 
12849    OE_Order_PUB.G_LINE := NULL;
12850    OE_Order_PUB.G_HDR  := NULL;
12851 
12852    If p_header_id is Not Null and p_cross_order = 'N' Then
12853      oe_Header_util.query_row(p_header_id=>p_header_id,x_header_rec => OE_Order_PUB.g_hdr );
12854    End If;
12855 
12856 
12857    G_STMT_NO := 'Get_manual_adjustment#1';
12858    line_tbl_index := l_line_tbl.First;
12859    While line_Tbl_Index is not null loop
12860 
12861      --Cross order lines, lines may not came from same header need to query header for each line
12862      If p_cross_order = 'Y' and  p_header_id Is  Null Then
12863        oe_Header_util.query_row(p_header_id=>l_line_tbl(line_tbl_index).header_id,
12864                                 x_header_rec => OE_Order_PUB.g_hdr );
12865        oe_debug_pub.add('  Currency Code:'||OE_Order_PUB.g_hdr.transactional_curr_code);
12866        x_header_id := l_line_tbl(line_tbl_index).header_id;
12867      End If;
12868 
12869       --Populate global structure since attribute mapping only read global structure
12870        OE_Order_PUB.G_LINE := l_Line_Tbl(line_Tbl_Index);
12871      Begin
12872        IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
12873               --5598523
12874           IF l_line_tbl(line_tbl_index).line_id=p_line_id THEN
12875 		l_check_line_flag := 'N';
12876 	  ELSE
12877 		l_check_line_flag := 'Y';
12878           END IF;
12879 
12880     	   l_line_index := l_line_index + 1; --added for BUG#8945171
12881 	   /* will increment the index by 1 initially, un-conditionally and will retain it or decrement it
12882 	   based on the the o/p for its Build Context.
12883 	   If -- QP says pass this line we will retain the index else we will decrement it. */
12884 
12885            QP_Attr_Mapping_PUB.Build_Contexts(p_request_type_code => 'ONT',
12886                                        p_pricing_type_code      =>      'L',
12887                                        --p_line_index => line_Tbl_Index, commeneted for BUG#8945171 --l_line_tbl(line_tbl_index).header_id + l_line_tbl(line_tbl_index).line_id,
12888                                        p_line_index => l_line_index, --added for BUG#8945171 from now on we will use  l_line_index instead of line_Tbl_Index to build context for lines as this is the index we use to build the context for header also.
12889                                        p_check_line_flag         => l_check_line_flag,  --5598523
12890                                        p_pricing_event           => l_event,
12891                                        x_pass_line               => l_pass_line);
12892        ELSE
12893            QP_Attr_Mapping_PUB.Build_Contexts(p_request_type_code => 'ONT',
12894 			               p_pricing_type	=>	'L',
12895 			               x_price_contexts_result_tbl => l_pricing_contexts_Tbl,
12896 			               x_qual_contexts_result_tbl  => l_qualifier_Contexts_Tbl);
12897        END IF;
12898        OE_Order_PUB.G_LINE := NULL;
12899      Exception
12900          When Others then
12901            oe_debug_pub.add('  QP ATTR MAPPING ERRORS 1');
12902          Raise QP_ATTR_MAPPING_ERRORS;
12903      End;
12904     G_STMT_NO := 'Get_manual_adjustment#2';
12905 
12906      -- Fix for bug 1807636
12907      -- Pass 'N' as the value of the p_honor_price_flag
12908      -- so that manual modifiers can be applied to RMA
12909      -- which is a copy of an order
12910 -- bucket man
12911      IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
12912       IF l_pass_line='Y' OR l_check_line_flag = 'N' THEN  --5598523
12913         --l_line_index := l_line_index + 1; --commented for BUG#8945171. we are now handling this above build context for lines.
12914         oe_order_price_pvt.copy_Line_to_request( p_Line_rec
12915 => l_Line_Tbl(line_Tbl_Index)
12916                            ,p_pricing_events            => l_event
12917                            ,px_req_line_tbl             => l_req_line_tbl
12918                            ,p_Request_Type_Code         => 'ONT'
12919                            ,p_honor_price_flag          => 'N'
12920                            ,px_line_index       => l_line_index
12921                            );
12922         ELSE --added for BUG#8945171
12923         -- if pricing says not to pass the line we will decrement the index
12924         l_line_index := l_line_index - 1;--added fpr BUG#8945171
12925 	END IF; --5598523
12926      ELSE
12927         copy_Line_to_request( p_Line_rec	 		=> l_Line_Tbl(line_Tbl_Index)
12928 			   ,p_pricing_event		=> l_event
12929 	 		   ,px_req_line_tbl   	        => l_req_line_tbl
12930 	 		   ,p_Request_Type_Code 	=> 'ONT'
12931 			   ,p_honor_price_flag		=> 'N'
12932 			   );
12933      END IF;
12934 /* --5598523 No need for this code as change done by this logic is not reflected while inserting data
12935    --into qp tables because direct insert is done using global str and hence changes made here are not used.
12936       --In the case of Order level manual adjustments we will need to set calculate price
12937       --flag for all the lines to 'N'and summary line to 'Y'
12938      If p_level = 'ORDER' or l_profile_value = 'Y' Then
12939        l_req_line_tbl(l_req_line_tbl.count).price_flag := 'N';
12940        null;
12941      End If;
12942 
12943      If l_profile_value = 'Y' and l_req_line_tbl(l_req_line_tbl.count).line_id = p_line_id Then
12944         --set the current line to 'Y' in the case of linegroup option.  We need to pass all other lines
12945         --to pricing engine with N.
12946         l_req_line_tbl(l_req_line_tbl.count).price_flag := 'Y';
12947      End If;
12948 */
12949  -- bucket man
12950      IF OE_CODE_CONTROL.Get_Code_Release_Level < '110510' THEN
12951         copy_attribs_to_Req(   p_line_index            => 	l_req_line_tbl.count
12952 			   ,p_pricing_contexts_Tbl 	=> 	l_pricing_contexts_Tbl
12953 			   ,p_qualifier_contexts_Tbl =>	l_qualifier_Contexts_Tbl
12954 			   ,px_Req_line_attr_tbl    =>	l_Req_line_attr_tbl
12955 			   ,px_Req_qual_tbl         =>	l_Req_qual_tbl );
12956      END IF;
12957 
12958      If l_ask_for_profile = 'Y' Then
12959      Begin
12960        l_header_id2:=nvl(p_header_id,l_line_tbl(line_tbl_index).header_id);
12961 
12962          Select 'x' into l_dummy from dual
12963          Where exists
12964          (select 'x' from
12965          oe_order_price_attribs oopa
12966          where
12967          nvl(oopa.line_id,l_Line_Tbl(line_Tbl_Index).line_id) = l_Line_Tbl(line_Tbl_Index).line_id
12968          and oopa.header_id = l_header_id2);
12969 
12970  -- bucket man
12971         IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
12972 		IF l_pass_line='Y' THEN  --5598523
12973            oe_order_price_pvt.Append_asked_for(p_header_id    => l_header_id2,
12974 
12975               p_line_id            => l_Line_Tbl(line_Tbl_Index).line_id,
12976 
12977               p_line_index            =>   l_line_index,
12978 
12979               px_line_attr_index => l_line_attr_index
12980               );
12981 	    END IF; --5598523
12982 
12983         ELSE
12984            Append_asked_for(p_header_id    => l_header_id2,
12985               p_line_id            => l_Line_Tbl(line_Tbl_Index).line_id,
12986               p_line_index            =>   l_req_line_tbl.count ,
12987               px_Req_line_attr_tbl => l_Req_line_attr_tbl,
12988               px_Req_qual_tbl      => l_Req_qual_tbl
12989               );
12990         END IF;
12991      Exception when no_data_found then null;
12992      End;
12993      End If;
12994 
12995 
12996 
12997      line_Tbl_Index := l_Line_Tbl.Next(line_Tbl_Index);
12998 
12999    End Loop;
13000    G_STMT_NO := 'Get_manual_adjustment#3';
13001 
13002    Begin
13003 -- bucket man
13004     IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13005        QP_Attr_Mapping_PUB.Build_Contexts(
13006                         p_request_type_code => 'ONT',
13007                         p_pricing_type_code     =>      'H',
13008                         p_line_index=> l_line_index + 1 --oe_order_pub.g_hdr.header_id
13009                         );
13010     ELSE
13011        QP_Attr_Mapping_PUB.Build_Contexts(
13012 			p_request_type_code => 'ONT',
13013 			p_pricing_type	=>	'H',
13014 			x_price_contexts_result_tbl => l_pricing_contexts_Tbl,
13015 			x_qual_contexts_result_tbl  => l_qualifier_Contexts_Tbl
13016 			);
13017     END IF;
13018    Exception
13019          --when no_data_found then
13020           --('  QP ATTR MAPPING ERRORS 2');
13021          When Others then
13022            Oe_Debug_Pub.Add('  QP ATTR MAPPING ERRORS 2');
13023          Raise QP_ATTR_MAPPING_ERRORS;
13024 
13025   End;
13026 
13027    -- bucket man
13028   IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13029      oe_order_price_pvt.copy_Header_to_request(
13030                  p_header_rec       => OE_Order_PUB.g_hdr
13031                  ,px_req_line_tbl   => l_req_line_tbl
13032                  ,p_Request_Type_Code => 'ONT'
13033                  ,p_calculate_price_flag =>'Y'
13034                  ,px_line_index => l_line_index
13035                  );
13036   ELSE
13037      copy_Header_to_request(
13038 		 p_header_rec       => OE_Order_PUB.g_hdr
13039 		 ,px_req_line_tbl   => l_req_line_tbl
13040 		 ,p_Request_Type_Code => 'ONT'
13041                  ,p_calculate_price_flag =>'Y'
13042 		 );
13043   END IF;
13044 
13045 	G_STMT_NO := 'Get_manual_adjustment#90';
13046   IF OE_CODE_CONTROL.Get_Code_Release_Level < '110510' THEN
13047 	copy_attribs_to_Req(
13048 		p_line_index             => l_req_line_tbl.count
13049 		,p_pricing_contexts_Tbl 	=> 	l_pricing_contexts_Tbl
13050 		,p_qualifier_contexts_Tbl =>	l_qualifier_Contexts_Tbl
13051 		,px_Req_line_attr_tbl    =>	l_Req_line_attr_tbl
13052 		,px_Req_qual_tbl         =>	l_Req_qual_tbl
13053 					);
13054   END IF;
13055 
13056        If l_ask_for_profile = 'Y' Then
13057         Begin
13058 	        --Modified for bug 3502454
13059                 --l_header_id2:=nvl(p_header_id,l_line_tbl(l_line_tbl.first).header_id);
13060                 IF ( p_header_id IS NULL ) THEN
13061                   l_header_id2 := l_line_tbl(l_line_tbl.first).header_id;
13062                 ELSE
13063                   l_header_id2 := p_header_id;
13064                 END IF;
13065                 -- End of 3502454
13066 		Select 'x' into l_dummy from dual
13067                 where exists(
13068                   Select 'X' from oe_order_price_attribs oopa
13069 		where oopa.header_id = l_header_id2 and oopa.line_id is null);
13070 
13071                 IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13072                    oe_order_price_pvt.Append_asked_for(
13073                         p_header_id                     => l_header_id2
13074                         , p_line_id                       => NULL
13075                         ,p_line_index             => l_line_index
13076                         , px_line_attr_index => l_line_attr_index
13077                         );
13078                 ELSE
13079                    Append_asked_for(
13080 			p_header_id			=> l_header_id2
13081 			,p_line_index             => l_req_line_tbl.count
13082 			,px_Req_line_attr_tbl    =>	l_Req_line_attr_tbl
13083 			,px_Req_qual_tbl         =>	l_Req_qual_tbl
13084 			);
13085                 END IF;
13086 	 Exception when no_data_found then null;
13087 	 End;
13088         End If;
13089 
13090    If l_req_line_tbl(l_req_line_tbl.count).line_type_code = 'ORDER' and
13091       p_level = 'ORDER' Then
13092         l_req_line_tbl(l_req_line_tbl.count).price_flag := 'Y';
13093    End If;
13094 
13095    IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13096       IF l_line_index > 0 THEN
13097          If l_debug_level > 0 Then
13098              oe_debug_pub.add('before Populate_Temp_Table');
13099          End If;
13100          oe_order_price_pvt.Populate_Temp_Table;
13101       END IF;
13102       l_control_rec.request_type_code := 'ONT';
13103       l_control_rec.temp_table_insert_flag := 'N';
13104    END IF;
13105 l_control_rec.pricing_event := l_event;
13106 l_control_rec.calculate_flag:= qp_preq_grp.G_SEARCH_N_CALCULATE;
13107 l_control_rec.manual_adjustments_call_flag:=qp_preq_grp.G_YES;
13108  --Will need to do the same thing for header level manual adjustment
13109 -- sgowtham
13110 if( p_freight_flag = TRUE) then
13111 l_control_rec.GET_FREIGHT_FLAG := 'Y';
13112 else
13113 l_control_rec.GET_FREIGHT_FLAG := 'N';
13114 end if;
13115 
13116    IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13117       QP_PREQ_PUB.PRICE_REQUEST
13118                 (p_control_rec           => l_control_rec
13119                 ,x_return_status         =>l_return_status
13120                 ,x_return_status_Text    =>l_return_status_Text
13121                 );
13122    ELSE
13123       QP_PREQ_GRP.PRICE_REQUEST
13124 		(p_control_rec		 => l_control_rec
13125 		,p_line_tbl              => l_Req_line_tbl
13126  		,p_qual_tbl              => l_Req_qual_tbl
13127   		,p_line_attr_tbl         => l_Req_line_attr_tbl
13128 		,p_line_detail_tbl       =>l_req_line_detail_tbl
13129 	 	,p_line_detail_qual_tbl  =>l_req_line_detail_qual_tbl
13130 	  	,p_line_detail_attr_tbl  =>l_req_line_detail_attr_tbl
13131 	   	,p_related_lines_tbl     =>l_req_related_lines_tbl
13132 		,x_line_tbl              =>lx_req_line_tbl
13133 	   	,x_line_qual             =>lx_Req_qual_tbl
13134 	    	,x_line_attr_tbl         =>lx_Req_line_attr_tbl
13135 		,x_line_detail_tbl       =>lx_req_line_detail_tbl
13136 	 	,x_line_detail_qual_tbl  =>lx_req_line_detail_qual_tbl
13137 	  	,x_line_detail_attr_tbl  =>lx_req_line_detail_attr_tbl
13138 	   	,x_related_lines_tbl     =>lx_req_related_lines_tbl
13139 	    	,x_return_status         =>l_return_status
13140 	    	,x_return_status_Text    =>l_return_status_Text
13141 		);
13142    END IF;
13143 
13144                 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
13145 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
13146 		ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
13147 			RAISE FND_API.G_EXC_ERROR;
13148 		END IF;
13149                 g_stmt_no :='Get Manual Adj#5';
13150       IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13151          i := 1;
13152                 g_stmt_no :='Get Manual Adj#5.5';
13153                 for k In man_adj Loop
13154                   If k.automatic_flag = 'N' Then
13155                     If l_debug_level > 0 Then
13156                        Oe_Debug_Pub.Add('+Line_type_code:'||k.line_type_code);
13157                        Oe_Debug_Pub.Add('+List_line_no:'||k.list_line_no);
13158                     End If;
13159 
13160                    --Only return 1 set of lov per line id or per header id
13161                    If (p_level In ('ORDER') and
13162                       (k.line_type_code = 'ORDER' or
13163                       k.modifier_level_code = 'LINEGROUP'))
13164                       Or
13165                       (p_level in ('LINE','LINEGROUP') and
13166                        k.line_type_code = 'LINE' and
13167                        k.line_id=p_line_id)
13168                       Or
13169                        (p_level = 'ALL' and
13170                        ((k.line_type_code = 'LINE' and
13171                         k.line_id=p_line_id)
13172                         or
13173                         k.line_type_code = 'ORDER')
13174                         )
13175 
13176                    Then
13177                      If (p_pbh_mode = 'CHILD' and nvl(k.line_quantity,0) > 0
13178                         and k.line_detail_type_code = QP_PREQ_GRP.G_CHILD_DETAIL_TYPE)
13179                         --Regular discount lines
13180                         or (k.list_line_type_code <> 'PBH' AND
13181                             k.line_detail_type_code <> QP_PREQ_GRP.G_CHILD_DETAIL_TYPE)
13182                         --Price break header (parent)
13183                         or (p_pbh_mode = 'PARENT' and k.list_line_type_code = 'PBH')
13184                      Then
13185                       If p_called_from = 'SO' Then
13186                        If k.pricing_group_sequence is null then
13187                         x_manual_adj_tbl(i).modifier_number:=k.list_line_no;
13188                         x_manual_adj_tbl(i).list_line_type_code :=k.list_line_type_code;
13189                         x_manual_adj_tbl(i).operand := k.operand_value;
13190                         x_manual_adj_tbl(i).list_line_id     :=k.list_line_id;
13191                         x_manual_adj_tbl(i).list_header_id   :=k.list_header_id;
13192                         x_manual_adj_tbl(i).pricing_phase_id :=k.pricing_phase_id;
13193                         x_manual_adj_tbl(i).automatic_flag   :=k.automatic_flag;
13194                         x_manual_adj_tbl(i).modifier_level_code:=k.modifier_level_code;
13195                         x_manual_adj_tbl(i).override_flag   :=k.override_flag;
13196                         x_manual_adj_tbl(i).operator        :=k.operand_calculation_code;
13197                         x_manual_adj_tbl(i).adjusted_amount :=k.ADJUSTMENT_AMOUNT;
13198                         x_manual_adj_tbl(i).charge_type_code :=k.CHARGE_TYPE_CODE;
13199                         x_manual_adj_tbl(i).CHARGE_SUBTYPE_CODE :=k.CHARGE_SUBTYPE_CODE;
13200                         x_manual_adj_tbl(i).PRICE_BREAK_TYPE_CODE := k.PRICE_BREAK_TYPE_CODE;
13201                         i := i + 1;
13202                        End If;
13203                       Else
13204                         x_manual_adj_tbl(i).modifier_number:=k.list_line_no;
13205                         x_manual_adj_tbl(i).list_line_type_code :=k.list_line_type_code;
13206                         x_manual_adj_tbl(i).operand := k.operand_value;
13207                         x_manual_adj_tbl(i).list_line_id     :=k.list_line_id;
13208                         x_manual_adj_tbl(i).list_header_id   :=k.list_header_id;                        x_manual_adj_tbl(i).pricing_phase_id :=k.pricing_phase_id;
13209                         x_manual_adj_tbl(i).automatic_flag   :=k.automatic_flag;                        x_manual_adj_tbl(i).modifier_level_code:=k.modifier_level_code;
13210                         x_manual_adj_tbl(i).override_flag   :=k.override_flag;
13211                         x_manual_adj_tbl(i).operator        :=k.operand_calculation_code;
13212                         x_manual_adj_tbl(i).adjusted_amount :=k.ADJUSTMENT_AMOUNT;
13213                         x_manual_adj_tbl(i).charge_type_code :=k.CHARGE_TYPE_CODE;
13214                          x_manual_adj_tbl(i).CHARGE_SUBTYPE_CODE :=k.CHARGE_SUBTYPE_CODE;
13215                         x_manual_adj_tbl(i).PRICE_BREAK_TYPE_CODE := k.PRICE_BREAK_TYPE_CODE;
13216                         x_manual_adj_tbl(i).PRICING_GROUP_SEQUENCE := k.PRICING_GROUP_SEQUENCE;
13217                         i := i + 1;
13218                       End If;
13219                      End If;
13220 
13221                    End If;
13222                   End If;
13223 
13224 
13225                 End Loop;
13226       ELSE
13227 	    	i:=lx_req_line_detail_tbl.first;
13228                 g_stmt_no :='Get Manual Adj#5.5';
13229 	        While i Is not Null Loop
13230                   If lx_req_line_detail_tbl(i).automatic_flag = 'N' Then
13231                   Oe_Debug_Pub.Add('+Line_type_code:'||l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_type_code);
13232                   Oe_Debug_Pub.Add('+List_line_no:'||lx_req_line_detail_tbl(i).list_line_no);
13233 
13234                    --Only return 1 set of lov per line id or per header id
13235                    If (p_level In ('ORDER') and
13236                       (l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_type_code = 'ORDER' or
13237                       lx_req_line_detail_tbl(i).modifier_level_code = 'LINEGROUP'))
13238                       Or
13239                       (p_level in ('LINE','LINEGROUP') and
13240                        l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_type_code = 'LINE' and
13241                        l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_id=p_line_id)
13242                       Or
13243                        (p_level = 'ALL' and
13244                         ((l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_type_code = 'LINE' and
13245                         l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_id=p_line_id)
13246                         or
13247                         l_req_line_tbl(lx_req_line_detail_tbl(i).line_index).line_type_code = 'ORDER')
13248                         )
13249 
13250                    Then
13251                      If (p_pbh_mode = 'CHILD' and nvl(lx_req_line_detail_tbl(i).line_quantity,0) > 0
13252                         and lx_req_line_detail_tbl(i).line_detail_type_code = QP_PREQ_GRP.G_CHILD_DETAIL_TYPE)
13253                         --Regular discount lines
13254                         or (lx_req_line_detail_tbl(i).list_line_type_code <> 'PBH' AND
13255                             lx_req_line_detail_tbl(i).line_detail_type_code <> QP_PREQ_GRP.G_CHILD_DETAIL_TYPE)
13256                         --Price break header (parent)
13257                         or (p_pbh_mode = 'PARENT' and lx_req_line_detail_tbl(i).list_line_type_code = 'PBH')
13258                      Then
13259                        x_manual_adj_tbl(i).modifier_number:=lx_req_line_detail_tbl(i).list_line_no;
13260                        x_manual_adj_tbl(i).list_line_type_code :=lx_req_line_detail_tbl(i).list_line_type_code;
13261                        x_manual_adj_tbl(i).operand          :=lx_req_line_detail_tbl(i).operand_value;
13262                        x_manual_adj_tbl(i).list_line_id     :=lx_req_line_detail_tbl(i).list_line_id;
13263                        x_manual_adj_tbl(i).list_header_id   :=lx_req_line_detail_tbl(i).list_header_id;
13264                        x_manual_adj_tbl(i).pricing_phase_id :=lx_req_line_detail_tbl(i).pricing_phase_id;
13265                        x_manual_adj_tbl(i).automatic_flag   :=lx_req_line_detail_tbl(i).automatic_flag;
13266                        x_manual_adj_tbl(i).modifier_level_code:=lx_req_line_detail_tbl(i).modifier_level_code;
13267                        x_manual_adj_tbl(i).override_flag   :=lx_req_line_detail_tbl(i).override_flag;
13268                        x_manual_adj_tbl(i).operator        :=lx_req_line_detail_tbl(i).operand_calculation_code;
13269                        x_manual_adj_tbl(i).adjusted_amount :=round(lx_req_line_detail_tbl(i).ADJUSTMENT_AMOUNT,6);
13270 oe_debug_pub.add('get manual adj:after round:'||x_manual_adj_tbl(i).adjusted_amount);
13271                        x_manual_adj_tbl(i).charge_type_code :=lx_req_line_detail_tbl(i).CHARGE_TYPE_CODE;
13272                        x_manual_adj_tbl(i).CHARGE_SUBTYPE_CODE :=lx_req_line_detail_tbl(i).CHARGE_SUBTYPE_CODE;
13273                      End If;
13274 
13275                    End If;
13276                   End If;
13277 
13278 
13279                   i:=lx_req_line_detail_tbl.next(i);
13280                 End Loop;
13281 
13282       END IF;
13283 	  -- Bug 1713035
13284           -- if p_line_level='Y', then we want
13285           -- only line/linegroup level manual adjustments
13286           -- Loop through x_manual_adj_tbl and delete all ORDER
13287           -- level adjustments in case p_line_level='Y'
13288 
13289 
13290          if (p_line_level = 'Y') then
13291 	   j:=x_manual_adj_tbl.first;
13292  	   while j is NOT NULL Loop
13293             IF OE_CODE_CONTROL.Get_Code_Release_Level >= '110510' THEN
13294               if (x_manual_adj_tbl(j).modifier_level_code   = 'ORDER' or
13295                  (x_manual_adj_tbl(j).price_break_type_code = 'RANGE' --bucket man
13296                   and p_pbh_mode <> 'PARENT'
13297                   )
13298                  ) then
13299                     oe_debug_pub.add(' Manual adj call: deleting order level adjustment');
13300                  oe_debug_pub.add(' Manual adj call: remove RANGE break');
13301                  x_manual_adj_tbl.delete(j);
13302              end if;
13303             ELSE
13304 	     if (x_manual_adj_tbl(j).modifier_level_code   = 'ORDER' or
13305                  (lx_req_line_detail_tbl(j).price_break_type_code = 'RANGE'
13306                   and p_pbh_mode <> 'PARENT'
13307                   )
13308                  ) then
13309 
13310                  --we do not support range break from 'LINE' tab of sales order form.
13311                  --because due to the fact that in 'LINE' tab we only shows
13312                  --eligible child break.  And, 'RANGE' break goes across multiple
13313                  --children. We support manual range break from view adjustments form
13314                  --because in view adjustments, it is the parent PBH a user get to choose
13315                  --and the system will insert all range break children.
13316 
13317                  oe_debug_pub.add(' Manual adj call: deleting order level adjustment');
13318                  oe_debug_pub.add(' Manual adj call: remove RANGE break');
13319 		 x_manual_adj_tbl.delete(j);
13320              end if;
13321             END IF;
13322 	     j := x_manual_adj_tbl.next(j);
13323            End loop;
13324 	  end if;
13325 
13326           Oe_Debug_Pub.add('Exiting Get manual adj');
13327 
13328     EXCEPTION
13329 
13330 	      WHEN FND_API.G_EXC_ERROR THEN
13331 
13332 		  FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
13333 		  FND_MESSAGE.SET_TOKEN('ERR_TEXT',l_return_status_Text);
13334 		  OE_MSG_PUB.Add;
13335 		  x_return_status := FND_API.G_RET_STS_ERROR;
13336 
13337 			Oe_Debug_Pub.add('g_exc_error is '||g_stmt_no||' '||sqlerrm,1);
13338 			Oe_Debug_Pub.add('g_exc_error is '||l_return_status_Text);
13339                         --DBMS_OUTPUT.PUT_LINE('g_exc_error is '||l_return_status_Text);
13340 			RAISE FND_API.G_EXC_ERROR;
13341 
13342 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
13343 
13344 		  FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
13345 		  FND_MESSAGE.SET_TOKEN('ERR_TEXT',l_return_status_Text);
13346 		  OE_MSG_PUB.Add;
13347 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13348 			Oe_Debug_Pub.add('G_EXC_UNEXPECTED_ERROR is '||g_stmt_no||' '||sqlerrm,1);
13349 			Oe_Debug_Pub.add('G_EXC_UNEXPECTED_ERROR is '||l_return_status_Text);
13350                         --DBMS_OUTPUT.PUT_LINE('G_EXC_UNEXPECTED_ERROR is '||l_return_status_Text);
13351 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
13352                 WHEN QP_ATTR_MAPPING_ERRORS Then
13353                   FND_MESSAGE.SET_NAME('ONT','OE_PRICING_ERROR');
13354 		  FND_MESSAGE.SET_TOKEN('ERR_TEXT','Errors return from QP_Attr_Mapping_PUB.Build_Context');
13355 		  OE_MSG_PUB.Add;
13356 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13357 			Oe_Debug_Pub.add('G_EXC_UNEXPECTED_ERROR is: QP_Attr_Mapping_PUB.Build_Context'||sqlerrm,1);
13358 			Oe_Debug_Pub.add('G_EXC_UNEXPECTED_ERROR is '||l_return_status_Text);
13359                         Oe_Debug_Pub.add('QP_ATTR_MAPPING_ERRORS');
13360 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
13361 		WHEN OTHERS THEN
13362 
13363 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13364 			Oe_Debug_Pub.add('Error is '||sqlerrm);
13365 			Oe_Debug_Pub.add('Error Code is '||g_stmt_no||' '||sqlerrm,1);
13366 
13367 			IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
13368 			THEN
13369 				OE_MSG_PUB.Add_Exc_Msg
13370 				(   G_PKG_NAME
13371 				,   'oe_line_adj.calulate_adjustments',
13372 					g_stmt_no||' '||sqlerrm
13373 				);
13374 			END IF;
13375 
13376 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
13377 
13378 End Get_Manual_Adjustments;
13379 
13380 -- PROMOTIONS SEP/01
13381 Procedure Promotion_Put_Hold(
13382 p_header_id                             Number
13383 ,p_line_id				Number
13384 )
13385 is
13386 l_hold_source_rec		OE_Holds_Pvt.hold_source_rec_type;
13387 l_hold_release_rec  		OE_Holds_Pvt.Hold_Release_REC_Type;
13388 l_return_status			varchar2(30);
13389 l_x_msg_count                   number;
13390 l_x_msg_data                    Varchar2(2000);
13391 l_x_result_out                  Varchar2(30);
13392 l_list_name			varchar2(240);
13393 l_operand			number;
13394 l_msg_text			Varchar2(200);
13395 
13396 Begin
13397 
13398 adj_debug('PROMOTIONS - start of procedure Promotion_Put_Hold ');
13399 
13400 		-- use the seeded hold_id
13401   IF (p_line_id IS NULL) THEN
13402       adj_debug('putting header '||p_header_id||' on hold',3);
13403 
13404       l_hold_source_rec.hold_id := G_SEEDED_PROM_ORDER_HOLD_ID;
13405   ELSE
13406       adj_debug('putting line '||p_line_id||' on hold',3);
13407       l_hold_source_rec.hold_id := G_SEEDED_PROM_LINE_HOLD_ID;
13408   END IF;
13409 
13410 --adj_debug('PAL PROMOTIONS - after select in procedure Promotion_Put_Hold ');
13411 --adj_debug('PAL PROMOTIONS - hold id is '|| l_hold_source_rec.hold_id,2);
13412 --adj_debug('PAL PROMOTIONS - header_id is '|| p_header_id,2);
13413 --adj_debug('PAL PROMOTIONS - line_id is '|| p_line_id,2);
13414 
13415 
13416 	l_hold_source_rec.hold_entity_id := p_header_id;
13417         l_hold_source_rec.header_id := p_header_id;
13418         l_hold_source_rec.line_id := p_line_id;
13419 	l_hold_source_rec.Hold_Entity_code := 'O';
13420 
13421        -- check if line already on PROMOTION hold, place hold if not
13422 
13423   			        OE_Holds_Pub.Check_Holds(
13424 					p_api_version		=> 1.0
13425                                         ,p_header_id            => p_header_id
13426 					,p_line_id		=> p_line_id
13427 					,p_hold_id		=> l_hold_source_rec.Hold_id
13428 					,x_return_status	=> l_return_status
13429 					,x_msg_count		=> l_x_msg_count
13430 					,x_msg_data		=> l_x_msg_data
13431 					,x_result_out		=> l_x_result_out
13432 					);
13433 
13434 --adj_debug('PAL PROMOTIONS - hold_entity_code is '|| l_hold_source_rec.Hold_Entity_code||l_x_result_out,2);
13435 
13436            IF (l_return_status <> FND_API.g_ret_sts_success) THEN
13437               RAISE FND_API.G_EXC_ERROR;
13438            END IF;
13439   	        If  l_x_result_out = FND_API.G_FALSE then
13440                                   adj_debug('PAL PROMOTIONS - apply holds in procedure Promotion_Put_Hold ');
13441                                   adj_debug('hold line with header_id:'||p_header_id||' line_id: '||p_line_id,1);
13442 				  OE_HOLDS_PUB.Apply_Holds(
13443 					p_api_version		=> 1.0
13444 					,p_hold_source_rec	=> l_hold_source_rec
13445 					,x_return_status	=> l_return_status
13446 					,x_msg_count		=> l_x_msg_count
13447 					,x_msg_data		=> l_x_msg_data
13448 					);
13449 
13450 	  If l_return_status = FND_API.g_ret_sts_success then
13451              IF (p_line_id IS NULL) THEN
13452 		FND_MESSAGE.SET_NAME('ONT','ONT_PROMO_HOLD_APPLIED');
13453              ELSE
13454                 FND_MESSAGE.SET_NAME('ONT', 'ONT_LINE_PROMO_HOLD_APPLIED');
13455              END IF;
13456 		OE_MSG_PUB.Add;
13457 	  Else
13458                 adj_debug('error applying hold',3);
13459 		RAISE FND_API.G_EXC_ERROR;
13460 	  End If;
13461        End If; /* check hold */
13462 
13463 -- adj_debug('PROMOTIONS - end of procedure Promotion_Put_Hold ');
13464 end Promotion_Put_Hold; -- PROMOTIONS SEP/01
13465 
13466 PROCEDURE GET_MANUAL_ADV_STATUS(p_event_code IN VARCHAR2) AS
13467 
13468 CURSOR l_send_all_lines_cur(p_event_code1 VARCHAR2) IS
13469 SELECT 'X'
13470 FROM
13471          qp_list_headers_b qh,
13472          qp_list_lines ql,
13473          qp_pricing_attributes qppr
13474 WHERE  ql.list_line_id = qppr.list_line_id
13475 AND    ql.automatic_flag = 'N'
13476 AND    qh.list_header_id = ql.list_header_id
13477 AND    qh.active_flag = 'Y'
13478 AND    qh.list_type_code not in ('AGR','PRL')
13479 AND    ql.list_line_type_code <> 'PLL'
13480 AND    (ql.list_line_type_code IN ('PRG','OID') OR ql.modifier_level_code =
13481 'LINEGROUP')
13482 AND    qppr.product_attribute_context='ITEM'     -- bug#7488440
13483 AND    qppr.product_attribute='PRICING_ATTRIBUTE3'  -- bug#7488440
13484 AND    qppr.product_attr_value='ALL'    -- bug#7488440
13485 AND    qppr.pricing_phase_id
13486          IN ( SELECT  distinct a.pricing_phase_id
13487               FROM qp_pricing_phases a , qp_event_phases b
13488               WHERE
13489               a.pricing_phase_id = b.pricing_phase_id
13490 --              AND (a.oid_exists = 'Y' OR a.line_group_exists = 'Y' OR a.rltd_exists = 'Y')  -- bug#7488440
13491               AND    b.pricing_event_code in (SELECT decode(rownum
13492           ,1 ,substr(p_event_code,1,instr(p_event_code1,',',1,1)-1)
13493           ,2 ,substr(p_event_code , instr(p_event_code1,',',1,rownum-1) + 1,
13494              instr(p_event_code1,',',1,rownum)-1 -
13495 instr(p_event_code1,',',1,rownum-1))
13496           ,3 ,substr(p_event_code , instr(p_event_code1,',',1,rownum-1) + 1,
13497               instr(p_event_code1,',',1,rownum)-1 -
13498 instr(p_event_code1,',',1,rownum-1))
13499           ,4 ,substr(p_event_code , instr(p_event_code1,',',1,rownum-1) + 1,
13500               instr(p_event_code1,',',1,rownum)-1 -
13501 instr(p_event_code1,',',1,rownum-1))
13502           ,5 ,substr(p_event_code , instr(p_event_code1,',',1,rownum-1) + 1,
13503               instr(p_event_code1,',',1,rownum)-1 -
13504 instr(p_event_code1,',',1,rownum-1))
13505           ,6 ,substr(p_event_code , instr(p_event_code1,',',1,rownum-1) + 1,
13506               instr(p_event_code1,',',1,rownum)-1 -
13507 instr(p_event_code1,',',1,rownum-1)))
13508          FROM  qp_event_phases
13509          WHERE rownum < 7))
13510 AND    ROWNUM = 1;
13511 
13512 x_get_manual_adv VARCHAR2(1);
13513 
13514 BEGIN
13515 oe_debug_pub.add(' Inside GET_MANUAL_ADV_STATUS ',3);
13516 x_get_manual_adv := NULL;
13517 
13518 OPEN l_send_all_lines_cur(p_event_code || ',') ;
13519 FETCH l_send_all_lines_cur INTO x_get_manual_adv;
13520 CLOSE l_send_all_lines_cur;
13521 
13522         If x_get_manual_adv = 'X' THEN
13523         oe_debug_pub.add('Manual adv modifiers exist');
13524         OE_GLOBALS.G_MANUAL_ADV_MODIFIER := 'Y';
13525         ELSE
13526         oe_debug_pub.add('Manual adv modifiers do not exist');
13527         OE_GLOBALS.G_MANUAL_ADV_MODIFIER := 'N';
13528         END IF;
13529 
13530 
13531 oe_debug_pub.add('return_value '||OE_GLOBALS.G_MANUAL_ADV_MODIFIER,3);
13532 oe_debug_pub.add(' Leaving GET_MANUAL_ADV_STATUS ',3);
13533 END GET_MANUAL_ADV_STATUS;
13534 
13535 end Oe_Order_Adj_Pvt;