DBA Data[Home] [Help]

PACKAGE BODY: APPS.QP_CALCULATE_PRICE_PUB

Source


4   l_debug VARCHAR2(3);
1 PACKAGE BODY QP_Calculate_Price_PUB AS
2   /* $Header: QPXPCLPB.pls 120.28.12020000.5 2013/01/22 07:09:44 smbalara ship $ */
3 
5   l_line_index NUMBER; -- for accum range break
6   l_prev_list_line_id NUMBER; -- accum range break
7   l_accum_global NUMBER; -- accum range break
8   l_prev_order_id NUMBER; -- accum range break
9   l_prev_line_index NUMBER; -- accum range break
10   l_accum_context_cache QP_LIST_LINES.ACCUM_CONTEXT%TYPE; -- accum range break
11   l_accum_attrib_cache QP_LIST_LINES.ACCUM_ATTRIBUTE%TYPE; -- accum range break
12   l_accum_flag_cache QP_LIST_LINES.ACCUM_ATTR_RUN_SRC_FLAG%TYPE; -- accum range break
13   l_accum_list_line_no_cache QP_LIST_LINES.LIST_LINE_NO%TYPE; -- accum range break
14 
15 
16   --4900095
17   G_Lumpsum_Qty NUMBER;
18   --private function to return service quantity
19   FUNCTION Get_lumpsum_qty(p_line_index NUMBER, p_line_detail_index NUMBER
20                            , p_modifier_level_code VARCHAR2)
21   RETURN NUMBER IS
22   x_lumpsum_qty NUMBER;
23   BEGIN
24     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
25     IF l_debug = FND_API.G_TRUE THEN
26       QP_PREQ_GRP.engine_debug('In Get_Lumpsum_Qty ..., QPXPCLPB.pls');
27       QP_PREQ_GRP.engine_debug('line_index '|| p_line_index
28                                ||' line_dtl_index '|| p_line_detail_index
29                                ||' level '|| p_modifier_level_code);
30       IF QP_PREQ_GRP.G_service_line_qty_tbl.EXISTS(p_line_index) THEN
31         QP_PREQ_GRP.engine_debug('line_index qty '
32                                  || QP_PREQ_GRP.G_service_line_qty_tbl(p_line_index));
33       END IF; --QP_PREQ_GRP.G_service_line_qty_tbl
34       IF QP_PREQ_GRP.G_service_line_qty_tbl.EXISTS(p_line_detail_index) THEN
35         QP_PREQ_GRP.engine_debug('line_detail_index qty '
36                                  || QP_PREQ_GRP.G_service_line_qty_tbl(p_line_detail_index));
37       END IF; --QP_PREQ_GRP.G_service_line_qty_tbl
38     END IF;
39     --4900095
40     IF (QP_PREQ_GRP.G_service_line_qty_tbl.EXISTS(p_line_index)
41         OR QP_PREQ_GRP.G_service_ldet_qty_tbl.EXISTS(p_line_detail_index)) THEN
42       IF p_modifier_level_code = QP_PREQ_GRP.G_LINE_GROUP THEN
43         x_lumpsum_qty :=
44         nvl(QP_PREQ_PUB.G_Service_pbh_lg_amt_qty(p_line_detail_index),
45             QP_PREQ_GRP.G_service_ldet_qty_tbl(p_line_detail_index));
46       ELSIF p_modifier_level_code = QP_PREQ_GRP.G_LINE_LEVEL THEN
47         x_lumpsum_qty :=
48         QP_PREQ_GRP.G_service_line_qty_tbl(p_line_index);
49       END IF; --p_modifier_level_code
50     END IF; --QP_PREQ_GRP.G_service_line_qty_tbl
51 
52     IF l_debug = FND_API.G_TRUE THEN
53       QP_PREQ_GRP.engine_debug('Get_Lumpsum_Qty '|| x_lumpsum_qty);
54     END IF;
55 
56     RETURN x_lumpsum_qty;
57   EXCEPTION
58     WHEN OTHERS THEN
59       RETURN NULL;
60   END Get_lumpsum_qty;
61 
62   -- Public Calculate_List_Price
63   PROCEDURE Calculate_List_Price
64   (p_operand_calc_code VARCHAR2,
65    p_operand_value NUMBER,
66    p_request_qty NUMBER,
67    p_rltd_item_price NUMBER,
68    p_service_duration NUMBER,
69    p_rounding_flag VARCHAR2,
70    p_rounding_factor NUMBER,
71    x_list_price OUT NOCOPY NUMBER,
72    x_percent_price OUT NOCOPY NUMBER,
73    x_return_status OUT NOCOPY VARCHAR2,
74    x_return_status_txt OUT NOCOPY VARCHAR2) AS
75 
76   v_routine_name CONSTANT VARCHAR2(240) := 'Routine:QP_Calculate_Price_PUB.Calculate_List_Price';
77   v_price_round_options VARCHAR2(30) := NULL; --shu, new rounding
78 
82     IF l_debug = FND_API.G_TRUE THEN
79   BEGIN
80     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
81     x_return_status := FND_API.G_RET_STS_SUCCESS;
83       QP_PREQ_GRP.engine_debug('In Calculate_List_Price ..., QPXPCLPB.pls');
84     END IF;
85     IF (p_operand_calc_code = QP_PREQ_GRP.G_UNIT_PRICE) THEN
86       x_list_price := p_operand_value * p_service_duration;
87     ELSIF(p_operand_calc_code = QP_PREQ_GRP.G_BLOCK_PRICE) THEN -- block pricing
88       IF (p_request_qty = 0) THEN
89         x_list_price := 0;
90       ELSE
91         IF l_debug = FND_API.G_TRUE THEN
92           qp_preq_grp.engine_debug('In Calculate_List_Price #1');
93         END IF;
94         x_list_price := (p_operand_value / p_request_qty);
95         IF l_debug = FND_API.G_TRUE THEN
96           qp_preq_grp.engine_debug('Request Qty: ' || p_request_qty);
97           qp_preq_grp.engine_debug('List Price: ' || x_list_price);
98         END IF;
99       END IF;
100     ELSIF(p_operand_calc_code = QP_PREQ_GRP.G_PERCENT_PRICE) THEN
101       x_list_price := (p_operand_value / 100) * p_rltd_item_price * p_service_duration;
102       x_percent_price := p_operand_value; -- service duration is not applicable here.Discussion with Alison
103     END IF;
104 
105     -- ravi passed (-1)*request_line.rounding_factor when calling this procedure, therefore needs to *(-1)
106     -- to print the original rounding_factor
107     IF l_debug = FND_API.G_TRUE THEN
108       QP_PREQ_GRP.engine_debug('In procedure Calculate_List_Price ...');
109       QP_PREQ_GRP.engine_debug('G_ROUNDING_FLAG: '|| QP_PREQ_GRP.G_ROUNDING_FLAG); -- aso rounding, shu, 2457629
110       QP_PREQ_GRP.engine_debug('rounding_factor: '|| ( - 1) * p_rounding_factor); -- ravi passed (-1)*request_line.rounding_factor
111 
112     END IF;
113     IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN
114 
115       x_list_price := ROUND(x_list_price, p_rounding_factor);
116       x_percent_price := ROUND(x_percent_price, p_rounding_factor);
117 
118     ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check v_selling_price_rounding_options profile
119       IF l_debug = FND_API.G_TRUE THEN
120         QP_PREQ_GRP.engine_debug('are we here 2?');
121       END IF;
122       v_price_round_options := nvl(FND_PROFILE.VALUE('QP_SELLING_PRICE_ROUNDING_OPTIONS'), QP_Calculate_Price_PUB.G_NO_ROUND); --shu, new rounding
123       IF l_debug = FND_API.G_TRUE THEN
124         QP_PREQ_GRP.engine_debug('selling_price_rounding_options: '|| v_price_round_options );
125       END IF;
126       IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN
127         x_list_price := ROUND(x_list_price, p_rounding_factor);
128         x_percent_price := ROUND(x_percent_price, p_rounding_factor);
129       END IF;
130     END IF;
131 
132     IF l_debug = FND_API.G_TRUE THEN
133       QP_PREQ_GRP.engine_debug('x_list_price' || x_list_price);
134     END IF;
135     -- end shu new rounding
136   EXCEPTION
137     WHEN OTHERS THEN
138       IF l_debug = FND_API.G_TRUE THEN
139         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || SQLERRM);
140       END IF;
141       x_return_status := FND_API.G_RET_STS_ERROR;
142       x_return_status_txt := v_routine_name || ' ' || SQLERRM;
143   END Calculate_List_Price;
144 
145   -- Local to the calculation Engine
146   PROCEDURE Calculate_List_Price_PVT
147   (p_operand_calc_code VARCHAR2,
148    p_operand_value NUMBER,
149    p_recurring_value NUMBER,  -- block pricing
150    p_request_qty NUMBER,
151    p_rltd_item_price NUMBER,
152    p_service_duration NUMBER,
153    p_rounding_flag VARCHAR2,
154    p_rounding_factor NUMBER,
155    x_list_price OUT NOCOPY NUMBER,
156    x_percent_price OUT NOCOPY NUMBER,
157    x_extended_price OUT NOCOPY NUMBER,  -- block pricing
158    x_return_status OUT NOCOPY VARCHAR2,
159    x_return_status_txt OUT NOCOPY VARCHAR2) AS
160 
161   v_routine_name CONSTANT VARCHAR2(240) := 'Routine:QP_Calculate_Price_PUB.Calculate_List_Price_PVT';
162   v_price_round_options VARCHAR2(30) := NULL; --shu, new rounding
163 
164   BEGIN
165     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
166     x_return_status := FND_API.G_RET_STS_SUCCESS;
167     IF l_debug = FND_API.G_TRUE THEN
168       QP_PREQ_GRP.engine_debug('In Calculate_List_Price_PVT..., QPXPCLPB.pls');
169     END IF;
170     IF (p_operand_calc_code IN (QP_PREQ_GRP.G_UNIT_PRICE, QP_PREQ_GRP.G_BREAKUNIT_PRICE)) THEN
171       x_list_price := p_operand_value * p_service_duration;
172     ELSIF(p_operand_calc_code = QP_PREQ_GRP.G_BLOCK_PRICE) THEN -- block pricing
173       IF (p_request_qty = 0) THEN
174         x_list_price := 0;
175         x_extended_price := p_operand_value;
176       ELSE
177         IF (p_recurring_value IS NULL) THEN
178           IF l_debug = FND_API.G_TRUE THEN
179             qp_preq_grp.engine_debug('In Calculate_List_Price_PVT #1');
180           END IF;
181           x_list_price := (p_operand_value / p_request_qty);
182           x_extended_price := p_operand_value;
183           IF l_debug = FND_API.G_TRUE THEN
184             qp_preq_grp.engine_debug('Extended Price #1 : ' || x_extended_price);
185             qp_preq_grp.engine_debug('Request Qty: ' || p_request_qty);
186             qp_preq_grp.engine_debug('List Price: ' || x_list_price);
187           END IF;
188         ELSE
189           IF l_debug = FND_API.G_TRUE THEN
190             qp_preq_grp.engine_debug('In Calculate_List_Price_PVT #2');
191           END IF;
192           x_list_price := p_operand_value / p_recurring_value;
193           x_extended_price := x_list_price * p_request_qty;
194           IF l_debug = FND_API.G_TRUE THEN
195             qp_preq_grp.engine_debug('Extended Price #2: ' || x_extended_price);
196           END IF;
200       x_list_price := (p_operand_value / 100) * p_rltd_item_price * p_service_duration;
197         END IF;
198       END IF;
199     ELSIF(p_operand_calc_code = QP_PREQ_GRP.G_PERCENT_PRICE) THEN
201       x_percent_price := p_operand_value; -- service duration is not applicable here.Discussion with Alison
202     END IF;
203 
204     -- ravi passed (-1)*request_line.rounding_factor when calling this procedure, therefore needs to *(-1)
205     -- to print the original rounding_factor
206     IF l_debug = FND_API.G_TRUE THEN
207       QP_PREQ_GRP.engine_debug('In procedure Calculate_List_Price_PVT...');
208       QP_PREQ_GRP.engine_debug('G_ROUNDING_FLAG: '|| QP_PREQ_GRP.G_ROUNDING_FLAG); -- aso rounding, shu, 2457629
209       QP_PREQ_GRP.engine_debug('rounding_factor: '|| ( - 1) * p_rounding_factor); -- ravi passed (-1)*request_line.rounding_factor
210 
211     END IF;
212     IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN
213 
214       x_list_price := ROUND(x_list_price, p_rounding_factor);
215       x_percent_price := ROUND(x_percent_price, p_rounding_factor);
216 
217     ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check v_selling_price_rounding_options profile
218 
219       v_price_round_options := nvl(FND_PROFILE.VALUE('QP_SELLING_PRICE_ROUNDING_OPTIONS'), QP_Calculate_Price_PUB.G_NO_ROUND); --shu, new rounding
220       IF l_debug = FND_API.G_TRUE THEN
221         QP_PREQ_GRP.engine_debug('selling_price_rounding_options: '|| v_price_round_options );
222       END IF;
223 
224       IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN
225         x_list_price := ROUND(x_list_price, p_rounding_factor);
226         x_percent_price := ROUND(x_percent_price, p_rounding_factor);
227       END IF;
228     END IF; -- end rounding stuff
229 
230     IF l_debug = FND_API.G_TRUE THEN
231       QP_PREQ_GRP.engine_debug('x_list_price' || x_list_price);
232     END IF;
233     -- end shu new rounding
234   EXCEPTION
235     WHEN OTHERS THEN
236       IF l_debug = FND_API.G_TRUE THEN
237         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || SQLERRM);
238       END IF;
239       x_return_status := FND_API.G_RET_STS_ERROR;
240       x_return_status_txt := v_routine_name || ' ' || SQLERRM;
241   END Calculate_List_Price_PVT;
242 
243   PROCEDURE Calculate_Adjusted_Price
244   (p_list_price NUMBER,
245    p_discounted_price NUMBER,
246    p_old_pricing_sequence NUMBER,
247    p_new_pricing_sequence NUMBER,
248    p_operand_calc_code VARCHAR2,
249    p_operand_value NUMBER,
250    p_list_line_type VARCHAR2,
251    p_request_qty NUMBER,
252    p_accrual_flag VARCHAR2,
253    p_rounding_flag VARCHAR2,
254    p_rounding_factor NUMBER,
255    p_orig_unit_price NUMBER,
256    x_discounted_price OUT NOCOPY NUMBER,
257    x_adjusted_amount OUT NOCOPY NUMBER,
258    x_list_price OUT NOCOPY NUMBER,
259    x_return_status OUT NOCOPY VARCHAR2,
260    x_return_status_txt OUT NOCOPY VARCHAR2) AS
261 
262   v_list_price NUMBER;
263   v_routine_name CONSTANT VARCHAR2(240) := 'Routine:QP_Calculate_Price_PUB.Calculate_Adjusted_Price';
264   v_price_round_options VARCHAR2(30) := NULL; --shu, new rounding
265 
266   BEGIN
267     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
268     IF l_debug = FND_API.G_TRUE THEN
269       QP_PREQ_GRP.engine_debug('In Calculate_Adjusted_Price...');
270     END IF;
271     v_price_round_options := FND_PROFILE.VALUE('QP_SELLING_PRICE_ROUNDING_OPTIONS'); --shu, new rounding
272     IF l_debug = FND_API.G_TRUE THEN
273       QP_PREQ_GRP.engine_debug('selling_price_rounding_options: '|| v_price_round_options );
274       QP_PREQ_GRP.engine_debug('G_ROUNDING_FLAG: '|| QP_PREQ_GRP.G_ROUNDING_FLAG); -- aso rounding, shu, 2457629
275     END IF;
276     -- ravi passed (-1)*request_line.rounding_factor when calling this procedure, therefore needs to *(-1)
277     -- to print the original rounding_factor
278     IF l_debug = FND_API.G_TRUE THEN
279       QP_PREQ_GRP.engine_debug('rounding_factor: '|| ( - 1) * p_rounding_factor); -- ravi passed (-1)*request_line.rounding_factor
280     END IF;
281 
282     x_return_status := FND_API.G_RET_STS_SUCCESS;
283     IF (p_old_pricing_sequence = p_new_pricing_sequence AND p_new_pricing_sequence IS NOT NULL) THEN
284       IF l_debug = FND_API.G_TRUE THEN
285         QP_PREQ_GRP.engine_debug('I am in Calculate Adjusted Price');
286       END IF;
287 
288       -- G_BREAKUNIT_PRICE added for FTE breakunit
289       IF (p_operand_calc_code IN (QP_PREQ_GRP.G_AMOUNT_DISCOUNT, QP_PREQ_GRP.G_BREAKUNIT_PRICE)) THEN
290 
291         IF (p_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
292           x_adjusted_amount :=  - (p_operand_value);
293           IF (p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
294             x_discounted_price := p_discounted_price;
295           ELSE
296             x_discounted_price := p_discounted_price - p_operand_value;
297           END IF; -- end if p_accrual_flag
298 
299         ELSIF (p_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
300           x_adjusted_amount := p_operand_value;
301           x_discounted_price := p_discounted_price + p_operand_value;
302 
303         ELSIF (p_list_line_type = QP_PREQ_GRP.G_FREIGHT_CHARGE) THEN
304           x_discounted_price := p_discounted_price;
305           x_adjusted_amount := p_operand_value;
306         END IF; -- end if p_list_line_type
307 
308       ELSIF (p_operand_calc_code = QP_PREQ_GRP.G_PERCENT_DISCOUNT) THEN
309 
310         IF (p_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
311           IF (p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
312             x_discounted_price := p_discounted_price;
313             x_adjusted_amount :=  - (abs(p_list_price) * (p_operand_value / 100));
314           ELSE
318             ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
315             --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
316             IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
317               x_discounted_price := p_discounted_price - ROUND((abs(p_list_price) * (p_operand_value / 100)), p_rounding_factor);
319               IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
320                 x_discounted_price := p_discounted_price - ROUND((abs(p_list_price) * (p_operand_value / 100)), p_rounding_factor);
321 	      ELSE
322 		x_discounted_price := p_discounted_price - (abs(p_list_price) * (p_operand_value/100)); --8521107
323               END IF;
324             ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
325               x_discounted_price := p_discounted_price - (abs(p_list_price) * (p_operand_value / 100));
326             END IF; -- end if QP_PREQ_GRP.G_ROUNDING_FLAG
327 
328             x_adjusted_amount :=  - (abs(p_list_price) * (p_operand_value / 100));
329           END IF; -- end if p_accrual_flag
330 
331         ELSIF (p_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
332 
333           --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
334           IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
335             x_discounted_price := p_discounted_price + ROUND((abs(p_list_price) * (p_operand_value / 100)), p_rounding_factor);
336           ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
337             IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
338               x_discounted_price := p_discounted_price + ROUND((abs(p_list_price) * (p_operand_value / 100)), p_rounding_factor);
339 	    ELSE
340 	      x_discounted_price := p_discounted_price + (abs(p_list_price) * (p_operand_value/100)); --8521107
341             END IF;
342           ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
343             x_discounted_price := p_discounted_price + (abs(p_list_price) * (p_operand_value / 100));
344           END IF; -- end if QP_PREQ_GRP.G_ROUNDING_FLAG
345 
346           x_adjusted_amount := abs(p_list_price) * (p_operand_value / 100);
347 
348         ELSIF (p_list_line_type = QP_PREQ_GRP.G_FREIGHT_CHARGE) THEN
349           x_discounted_price := p_discounted_price;
350           x_adjusted_amount := abs(p_list_price) * (p_operand_value / 100);
351         END IF; -- end if p_list_line_type
352 
353       ELSIF(p_operand_calc_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT) THEN
354 
355         -- For NewPrice Calculation is same for Discount and Surcharge
356         IF (p_list_line_type IN (QP_PREQ_GRP.G_DISCOUNT, QP_PREQ_GRP.G_SURCHARGE)) THEN
357           x_discounted_price := p_operand_value;
358           x_adjusted_amount :=  - (p_list_price - p_operand_value);
359           --fix bug 2353905
360           --Negative list price can get correct adjusted_amount
361         END IF;
362 
363       ELSIF (p_operand_calc_code = QP_PREQ_GRP.G_LUMPSUM_DISCOUNT) THEN
364 
365         IF (p_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
366 
367           IF (p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
368             x_discounted_price := p_discounted_price;
369             IF (p_request_qty <> 0) THEN -- ask ravi, how about null?
370               x_adjusted_amount :=  - (p_operand_value / p_request_qty);
371             ELSE
372               x_adjusted_amount := 0; -- bug2385874, should be 0 instead of -p_operand_value
373             END IF; -- end if p_request_qty
374           ELSE -- else if p_accural_flag
375 
376             IF (p_request_qty = 0) THEN -- ask ravi how about null??
377               x_discounted_price := p_discounted_price;
378               x_adjusted_amount := 0; --bug2385874, should be 0 instead of p_operand_value
379             ELSE
380 
381               --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
382               IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
383                 --4900095 added nvl to G_Lumpsum_qty
384                 x_discounted_price := p_discounted_price - ROUND((p_operand_value / nvl(G_Lumpsum_qty, p_request_qty)), p_rounding_factor);
385               ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
386                 IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
387                   --4900095 added nvl to G_Lumpsum_qty
388                   x_discounted_price := p_discounted_price - ROUND((p_operand_value / nvl(G_Lumpsum_qty, p_request_qty)), p_rounding_factor);
389                 ELSE
390 		  x_discounted_price := p_discounted_price - (abs(p_list_price) * (p_operand_value/100)); --8521107
391                 END IF;
392               ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
393                 --4900095 added nvl to G_Lumpsum_qty
394                 x_discounted_price := p_discounted_price - (p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty));
395               END IF; -- end if QP_PREQ_GRP.G_ROUNDING_FLAG
396               --4900095 added nvl to G_Lumpsum_qty
397               x_adjusted_amount :=  - (p_operand_value / nvl(G_Lumpsum_qty, p_request_qty));
398 
399             END IF; -- end if p_request_qty
400           END IF; -- end if p_accural_flag
401 
402         ELSIF (p_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
403 
404           IF (p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
405 
406             x_discounted_price := p_discounted_price;
410             ELSE
407             IF (p_request_qty <> 0) THEN -- ask ravi, how about null?
408               --4900095 added nvl to G_Lumpsum_qty
409               x_adjusted_amount := (p_operand_value / nvl(G_Lumpsum_qty, p_request_qty));
411               --x_adjusted_amount := p_operand_value;
412               x_adjusted_amount := 0; --bug2385874, should be 0 instead of p_operand_value
413             END IF;
414 
415           ELSE -- else if p_accrual_flag
416 
417             IF (p_request_qty = 0) THEN
418               x_discounted_price := p_discounted_price;
419               --x_adjusted_amount := p_operand_value;
420               x_adjusted_amount := 0; --bug2385874, should be 0 instead of p_operand_value
421             ELSE
422               --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
423               IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
424                 --4900095 added nvl to G_Lumpsum_qty
425                 x_discounted_price := p_discounted_price + ROUND((p_operand_value / nvl(G_Lumpsum_qty, p_request_qty)), p_rounding_factor);
426               ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
427                 IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
428                   --4900095 added nvl to G_Lumpsum_qty
429                   x_discounted_price := p_discounted_price + ROUND((p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty)), p_rounding_factor);
430 		ELSE
431 		  x_discounted_price := p_discounted_price + (abs(p_list_price) * (p_operand_value/100)); --8521107
432                 END IF;
433               ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
434                 --4900095 added nvl to G_Lumpsum_qty
435                 x_discounted_price := p_discounted_price + (p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty));
436               END IF; -- end if QP_PREQ_GRP.G_ROUNDING_FLAG
437 
438               --4900095 added nvl to G_Lumpsum_qty
439               x_adjusted_amount := (p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty));
440             END IF; -- end if p_request_qty
441           END IF; -- end if p_accrual_flag
442 
443         ELSIF (p_list_line_type = QP_PREQ_GRP.G_FREIGHT_CHARGE) THEN
444 
445           IF l_debug = FND_API.G_TRUE THEN
446             QP_PREQ_GRP.engine_debug('Freight Charge');
447             QP_PREQ_GRP.engine_debug('Discounted Price : ' || p_discounted_price);
448           END IF;
449           x_discounted_price := p_discounted_price;
450 
451           IF (p_request_qty = 0) THEN
452             x_adjusted_amount := p_operand_value;
453           ELSE
454             --4900095 added nvl to G_Lumpsum_qty
455             x_adjusted_amount := p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty);
456             IF l_debug = FND_API.G_TRUE THEN
457               QP_PREQ_GRP.engine_debug('Adjusted Amount: ' || x_adjusted_amount);
458             END IF;
459           END IF; -- end IF p_request_qty
460 
461         END IF; -- end if p_list_line_type = G_FREIGHT_CHARGE
462 
463       END IF; -- end if p_operand_calc_code
464 
465       x_list_price := p_list_price;
466 
467     ELSE -- else IF (p_old_pricing_sequence = p_new_pricing_sequence AND p_new_pricing_sequence IS NOT NULL)
468       -- On Sequence Change , the base price changes to the current discount price
469 
470       IF (p_new_pricing_sequence IS NULL) THEN
471         v_list_price := p_orig_unit_price;
472       ELSE
473         v_list_price := p_discounted_price;
474       END IF;
475 
476       -- G_BREAKUNIT_PRICE added for FTE breakunit
477       IF (p_operand_calc_code IN (QP_PREQ_GRP.G_AMOUNT_DISCOUNT, QP_PREQ_GRP.G_BREAKUNIT_PRICE)) THEN
478 
479         IF (p_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
480 
481           IF(p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
482             x_discounted_price := p_discounted_price;
483             x_adjusted_amount :=  - (p_operand_value) ;
484           ELSE
485             x_discounted_price := p_discounted_price - p_operand_value;
486             x_adjusted_amount :=  - (p_operand_value) ;
487           END IF; -- end if p_accrual_flag
488 
489         ELSIF (p_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
490 
491           x_discounted_price := p_discounted_price + p_operand_value;
492           x_adjusted_amount := p_operand_value;
493 
494         ELSIF (p_list_line_type = QP_PREQ_GRP.G_FREIGHT_CHARGE) THEN
495           x_discounted_price := p_discounted_price;
496           x_adjusted_amount := p_operand_value;
497         END IF; -- end if p_list_line_type
498 
499       ELSIF (p_operand_calc_code = QP_PREQ_GRP.G_PERCENT_DISCOUNT) THEN
500 
501         IF (p_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
502 
503           IF(p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
504             x_discounted_price := p_discounted_price;
505             x_adjusted_amount :=  - (abs(v_list_price) * (p_operand_value / 100));
506           ELSE
507             --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
508             IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
509               x_discounted_price := p_discounted_price - ROUND((abs(v_list_price) * (p_operand_value / 100)), p_rounding_factor);
510             ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
511               IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
512                 x_discounted_price := p_discounted_price - ROUND((abs(v_list_price) * (p_operand_value / 100)), p_rounding_factor);
516             END IF; -- end if QP_PREQ_GRP.G_ROUNDING_FLAG
513               END IF;
514             ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
515               x_discounted_price := p_discounted_price - (abs(v_list_price) * (p_operand_value / 100));
517 
518             --x_discounted_price := p_discounted_price - (abs(v_list_price) *(p_operand_value/100));
519             x_adjusted_amount :=  - (abs(v_list_price) * (p_operand_value / 100));
520 
521           END IF; -- end if p_accrual_flag
522 
523         ELSIF (p_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN -- the sign along with value
524 
525           --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
526           IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
527             x_discounted_price := p_discounted_price + ROUND((abs(v_list_price) * (p_operand_value / 100)), p_rounding_factor);
528           ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
529             IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
530               x_discounted_price := p_discounted_price + ROUND((abs(v_list_price) * (p_operand_value / 100)), p_rounding_factor);
531             END IF;
532           ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
533             x_discounted_price := p_discounted_price + (abs(v_list_price) * (p_operand_value / 100));
534           END IF;
535 
536           --x_discounted_price := p_discounted_price + (abs(v_list_price) *(p_operand_value/100));
537           x_adjusted_amount := abs(v_list_price) * (p_operand_value / 100);
538 
539         ELSIF (p_list_line_type = QP_PREQ_GRP.G_FREIGHT_CHARGE) THEN
540           x_discounted_price := p_discounted_price;
541           x_adjusted_amount := abs(v_list_price) * (p_operand_value / 100);
542         END IF; -- end if p_list_line_type
543 
544       ELSIF (p_operand_calc_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT) THEN
545 
546         IF (p_list_line_type IN (QP_PREQ_GRP.G_DISCOUNT, QP_PREQ_GRP.G_SURCHARGE)) THEN
547           x_discounted_price := p_operand_value;
548           x_adjusted_amount :=  - (v_list_price - p_operand_value);
549           --fix bug 2353905
550           --Negative list price can get correct adjusted_amount
551         END IF;
552 
553       ELSIF (p_operand_calc_code = QP_PREQ_GRP.G_LUMPSUM_DISCOUNT) THEN
554 
555         IF (p_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
556 
557           IF(p_accrual_flag = QP_PREQ_GRP.G_YES) THEN
558             x_discounted_price := p_discounted_price;
559             IF (p_request_qty = 0) THEN
560               --x_adjusted_amount := p_operand_value;
561               x_adjusted_amount := 0; --bug2385874, should be 0 instead of p_operand_value
562             ELSE
563               --4900095 added nvl to G_Lumpsum_qty
564               x_adjusted_amount :=  - (p_operand_value / nvl(G_Lumpsum_qty, p_request_qty));
565             END IF; -- end if p_request_qty
566           ELSE
567             IF (p_request_qty = 0) THEN
568               x_discounted_price := p_discounted_price;
569               --x_adjusted_amount := p_operand_value;
570               x_adjusted_amount := 0; --bug2385874, should be 0 instead of p_operand_value
571             ELSE
572               --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
573               IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
574                 --4900095 added nvl to G_Lumpsum_qty
575                 x_discounted_price := p_discounted_price - ROUND((p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty)), p_rounding_factor);
576               ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
577                 IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
578                   --4900095 added nvl to G_Lumpsum_qty
579                   x_discounted_price := p_discounted_price - ROUND((p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty)), p_rounding_factor);
580                 END IF;
581               ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
582                 --4900095 added nvl to G_Lumpsum_qty
583                 x_discounted_price := p_discounted_price - (p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty));
584               END IF;
585 
586               --4900095 added nvl to G_Lumpsum_qty
587               -- x_discounted_price := p_discounted_price - (p_operand_value/nvl(G_Lumpsum_Qty,p_request_qty));
588               --4900095 added nvl to G_Lumpsum_qty
589               x_adjusted_amount :=  - (p_operand_value / nvl(G_Lumpsum_qty, p_request_qty));
590             END IF; -- end if p_request_qty
591 
592           END IF; -- end if p_accrual_flag
593 
594         ELSIF (p_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
595 
596           IF (p_request_qty = 0) THEN
597             x_discounted_price := p_discounted_price;
598             --x_adjusted_amount := p_operand_value;
599             x_adjusted_amount := 0; --bug2385874, should be 0 instead of p_operand_value
600           ELSE
601             --IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
602             IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
603               --4900095 added nvl to G_Lumpsum_qty
604               x_discounted_price := p_discounted_price + ROUND((p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty)), p_rounding_factor);
605             ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
609               END IF;
606               IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
607                 --4900095 added nvl to G_Lumpsum_qty
608                 x_discounted_price := p_discounted_price + ROUND((p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty)), p_rounding_factor);
610             ELSE -- QP_PREQ_GRP.G_ROUNDING_FLAG ='N' or 'U', un-round adjs
611               --4900095 added nvl to G_Lumpsum_qty
612               x_discounted_price := p_discounted_price + (p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty));
613             END IF; -- end if p_request_qty
614 
615             --4900095 added nvl to G_Lumpsum_qty
616             -- x_discounted_price := p_discounted_price + (p_operand_value/nvl(G_Lumpsum_Qty,p_request_qty));
617             x_adjusted_amount := p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty);
618 
619           END IF; -- end if p_request_qty
620 
621         ELSIF (p_list_line_type = QP_PREQ_GRP.G_FREIGHT_CHARGE) THEN
622           x_discounted_price := p_discounted_price;
623 
624           IF (p_request_qty = 0) THEN
625             x_adjusted_amount := p_operand_value;
626           ELSE
627             --4900095 added nvl to G_Lumpsum_qty
628             x_adjusted_amount := p_operand_value / nvl(G_Lumpsum_Qty, p_request_qty);
629           END IF;
630         END IF; -- end if p_list_line_type
631       END IF; -- end if p_operand_calc_code
632 
633       x_list_price := v_list_price;
634 
635     END IF; -- end IF (p_old_pricing_sequence = p_new_pricing_sequence AND p_new_pricing_sequence IS NOT NULL)
636 
637     -- round it all
638     -- IF (v_round_individual_adj_flag = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu
639     IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN -- shu, new rounding
640       x_adjusted_amount := ROUND(x_adjusted_amount, p_rounding_factor);
641     ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile
642       IF (v_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN -- do not round if profile is null
643         x_adjusted_amount := ROUND(x_adjusted_amount, p_rounding_factor);
644       END IF;
645     END IF;
646 
647   EXCEPTION
648 
649     WHEN OTHERS THEN
650       IF l_debug = FND_API.G_TRUE THEN
651         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || SQLERRM);
652       END IF;
653       x_return_status := FND_API.G_RET_STS_ERROR;
654       x_return_status_txt := v_routine_name || ' ' || SQLERRM;
655   END Calculate_Adjusted_Price;
656 
657   PROCEDURE Process_Price_Break(
658                                 p_list_line_id NUMBER,  -- list line id, used for accum range break
659                                 p_list_line_index NUMBER,  -- PBH Line Detail Index
660                                 p_operand_calc_code VARCHAR, -- PBH arithmetic operator
661                                 p_list_line_qty NUMBER,  -- Ordered Qty
662                                 p_actual_line_qty NUMBER,  -- Line Qty, 2388011 pbh_grp_amt
663                                 p_pbh_type VARCHAR2,
664                                 p_list_price NUMBER,  -- Applicable when it is discount break
665                                 p_discounted_price NUMBER,
666                                 p_old_pricing_grp_seq NUMBER,
667                                 p_related_item_price NUMBER,  -- Applicable in case of service item
668                                 p_service_duration NUMBER,
669                                 p_related_request_lines l_related_request_lines_tbl,
670                                 p_rounding_flag VARCHAR2,
671                                 p_rounding_factor NUMBER,
672                                 p_group_value NUMBER := 0,  -- LINEGROUP, 2388011 pbh_grp_amt
673                                 x_pbh_list_price OUT NOCOPY NUMBER,
674                                 x_pbh_extended_price OUT NOCOPY NUMBER,  -- block pricing
675                                 x_adjustment_amount OUT NOCOPY NUMBER,
676                                 x_related_request_lines_tbl OUT NOCOPY l_related_request_lines_tbl,
677                                 x_return_status OUT NOCOPY VARCHAR2,
678                                 x_return_status_txt OUT NOCOPY VARCHAR2) AS
679 
680   v_temp NUMBER := 0;
681   v_ord_qty NUMBER;
682   v_count NUMBER := 0;
683   v_index NUMBER := 0;
684   v_total_amount NUMBER := 0;
685   v_discounted_price NUMBER;
686   v_operand_calc_code VARCHAR2(30);
687   v_operand_value NUMBER;
688   v_old_pricing_sequence NUMBER;
689   v_zero_count NUMBER;
690   x_discounted_price NUMBER;
691   x_list_price NUMBER;
692   x_percent_price NUMBER;
693   x_extended_price NUMBER; -- block pricing
694   x_adjusted_amount NUMBER;
695   v_related_request_lines l_related_request_lines_tbl;
696   x_ret_status VARCHAR2(30);
697   x_ret_status_txt VARCHAR2(240);
698   k NUMBER;
699   l_precision NUMBER;
700   l_value_from_precision NUMBER;
701   l_value_to_precision NUMBER;
702   l_difference NUMBER;
703   l_satisfied_value NUMBER;
704   l_qualifier_value NUMBER; -- 2388011, 2388011 pbh_grp_amt
705   v_attribute_value_per_unit NUMBER; --2388011_latest
706   v_calculate_per_unit_flag VARCHAR2(1);
707   l_price_round_options VARCHAR2(30) := NULL;
708 
709   -- 4061138, 5183755 continuous price breaks
710   CURSOR get_continuous_flag_cur IS
711     SELECT nvl(continuous_price_break_flag, 'N')
712     FROM   qp_list_lines
713     WHERE  list_line_id = p_list_line_id;
714 
715   l_continuous_flag VARCHAR2(1) := 'N';
716   l_prorated_flag VARCHAR2(1) := 'N';
717 
718   v_routine_name CONSTANT VARCHAR2(240) := 'Routine:QP_Calculate_Price_PUB.Process_Price_Break';
719 
720   BEGIN
721 
725     v_old_pricing_sequence := p_old_pricing_grp_seq;
722     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
723     x_return_status := FND_API.G_RET_STS_SUCCESS;
724     v_related_request_lines := p_related_request_lines;
726 
727     -- 4061138, 5183755
728     OPEN get_continuous_flag_cur;
729     FETCH get_continuous_flag_cur INTO l_continuous_flag;
730     CLOSE get_continuous_flag_cur;
731 
732     k := p_related_request_lines.FIRST;
733     WHILE (k IS NOT NULL)
734       LOOP
735       IF (p_related_request_lines(k).LINE_DETAIL_INDEX = p_list_line_index) THEN
736         IF l_debug = FND_API.G_TRUE THEN
737           IF l_continuous_flag = 'Y' THEN
738             QP_PREQ_GRP.engine_debug ('<-------- CONTINUOUS PRICE BREAK -------->');
739           ELSE
740             QP_PREQ_GRP.engine_debug ('<---------------------------------------->');
741           END IF;
742           QP_PREQ_GRP.engine_debug ('p_list_line_id: '|| p_list_line_id);
743           QP_PREQ_GRP.engine_debug ('p_list_line_index: '|| p_list_line_index);
744         END IF; -- END IF l_debug = FND_API.G_TRUE
745 
746         -- 4061138
747         -- check if PBH is prorated, important for continuous processing later
748         IF l_continuous_flag = 'Y' AND QP_PREQ_GRP.G_BREAK_UOM_PRORATION = 'Y'
749           THEN
750           BEGIN
751             SELECT 'Y' INTO l_prorated_flag
752             FROM qp_npreq_ldets_tmp
753             WHERE line_detail_index = p_list_line_index
754             AND break_uom_code IS NOT NULL;
755           EXCEPTION
756             WHEN NO_DATA_FOUND THEN
757               l_prorated_flag := 'N';
758           END;
759         END IF;
760 
761         IF (p_related_request_lines(k).PRICE_BREAK_TYPE_CODE = QP_PREQ_GRP.G_POINT_BREAK) THEN
762           IF l_debug = FND_API.G_TRUE THEN
763             QP_PREQ_GRP.engine_debug ('i am in Point break'); -- shu dbg 2388011
764             QP_PREQ_GRP.engine_debug ('p_group_value: '|| p_group_value); -- shu dbg 2388011
765             QP_PREQ_GRP.engine_debug ('p_list_line_qty: '|| p_list_line_qty); -- shu dbg 2388011
766           END IF; -- END IF l_debug = FND_API.G_TRUE
767 
768           -- 2388011, Applicable for group of lines based PBH
769           v_ord_qty := p_list_line_qty; -- Store the ordered qty
770           --IF (p_group_value > - 1) THEN --[julin/5158413]
771 	  IF (p_group_value > 0) THEN --6896139 undoing changes done as part of bug 5158413
772             v_temp := p_group_value;
773           ELSE
774             v_temp := p_list_line_qty;
775           END IF;
776 
777           IF l_debug = FND_API.G_TRUE THEN
778             QP_PREQ_GRP.engine_debug ('v_temp, for evaluation (either p_group_value or p_list_line_qty): '|| v_temp); -- shu dbg 2388011
779           END IF; -- END IF l_debug = FND_API.G_TRUE
780 
781           -- If it falls in the range
782           /* rewritten for 4061138
783 	 IF (v_temp >= p_related_request_lines(k).VALUE_FROM AND  --2388011
784            v_temp <= nvl(p_related_request_lines(k).VALUE_TO,v_temp)) THEN --2388011, 2 changes
785          */
786           IF ((l_continuous_flag <> 'Y' AND
787                v_temp BETWEEN p_related_request_lines(k).VALUE_FROM AND nvl(p_related_request_lines(k).VALUE_TO, v_temp))
788               OR
789               (l_continuous_flag = 'Y' AND
790                p_related_request_lines(k).VALUE_FROM < v_temp AND
791                v_temp <= nvl(p_related_request_lines(k).VALUE_TO, v_temp)) )
792             THEN
793             v_related_request_lines(k).LINE_QTY := v_temp; -- PBH line qty/v_ord_qty, 2388011
794 
795             IF l_debug = FND_API.G_TRUE THEN
796               QP_PREQ_GRP.engine_debug ('PBH operand Calc Code : ' || p_operand_calc_code);
797             END IF;
798 
799             -- Do not calculate per unit satisfied value if it is BLOCK_PRICING
800             IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
801               IF (p_operand_calc_code = 'BLOCK_PRICE') THEN
802                 v_calculate_per_unit_flag := 'N';
803               ELSE
804                 v_calculate_per_unit_flag := 'Y';
805               END IF;
806             ELSE
807               v_calculate_per_unit_flag := 'Y';
808             END IF;
809             -- for FTE breakunit
810             -- also do not calculate per unit value if line is BREAKUNIT_PRICE
811             IF (p_related_request_lines(k).OPERAND_CALCULATION_CODE = QP_PREQ_GRP.G_BREAKUNIT_PRICE) THEN
812               v_calculate_per_unit_flag := 'N';
813             END IF;
814 
815             IF l_debug = FND_API.G_TRUE THEN
816               QP_PREQ_GRP.engine_debug ('Calculate Per Unit Flag : ' || v_calculate_per_unit_flag);
817             END IF;
818 
819             -- This happens only if it is line group based Applicable for both Linegroup Amount and Item Amount
820             -- 2388011_new
821             IF (p_group_value > 0 AND v_calculate_per_unit_flag = 'Y') THEN
822               v_attribute_value_per_unit := p_group_value / p_list_line_qty; -- 2388011_latest
823               v_related_request_lines(k).LINE_QTY := v_temp / v_attribute_value_per_unit; -- 2388011_latest
824             ELSE
825               v_related_request_lines(k).LINE_QTY := v_temp;
826             END IF;
827 
828 
829             IF l_debug = FND_API.G_TRUE THEN
830               QP_PREQ_GRP.engine_debug('List Line Quantity: ' || v_related_request_lines(k).LINE_QTY );
831               QP_PREQ_GRP.engine_debug('PBH Type: ' || p_pbh_type);
832             END IF; -- END IF l_debug = FND_API.G_TRUE
833 
834             -- Call the Calculate List Price Function
835             IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
836               Calculate_List_Price_PVT(
840                                        v_ord_qty,  -- 2388011_new, for calculation
837                                        p_related_request_lines(k).OPERAND_CALCULATION_CODE,
838                                        p_related_request_lines(k).OPERAND_VALUE,
839                                        p_related_request_lines(k).RECURRING_VALUE,  -- block pricing
841                                        p_related_item_price,
842                                        p_service_duration,
843                                        QP_PREQ_GRP.G_ROUNDING_FLAG,
844                                        p_rounding_factor,
845                                        x_list_price,
846                                        x_percent_price,
847                                        x_extended_price,
848                                        x_ret_status,
849                                        x_ret_status_txt);
850 
851               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
852                 RAISE FND_API.G_EXC_ERROR;
853               END IF;
854 
855               -- This is the final list price after break evaluation
856               -- changed for block pricing
857               IF (p_related_request_lines(k).OPERAND_CALCULATION_CODE = qp_preq_grp.G_BLOCK_PRICE) THEN
858                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_extended_price;
859               ELSE
860                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_list_price;
861               END IF;
862 
863               x_pbh_list_price := x_list_price;
864               x_pbh_extended_price := x_extended_price; -- block pricing
865 
866               IF l_debug = FND_API.G_TRUE THEN
867                 QP_PREQ_GRP.engine_debug('final list price after break evaluation..');
868                 QP_PREQ_GRP.engine_debug('List Line Price: ' || v_related_request_lines(k).ADJUSTMENT_AMOUNT );
869                 QP_PREQ_GRP.engine_debug('List Line Price: ' || x_pbh_list_price );
870               END IF; -- END IF l_debug = FND_API.G_TRUE
871 
872             ELSE -- DIS/SUR/FREIGHT_CHARGE
873 
874               IF l_debug = FND_API.G_TRUE THEN
875                 QP_PREQ_GRP.engine_debug('I am in Discount Break');
876                 QP_PREQ_GRP.engine_debug('List Price: ' || p_list_price);
877                 QP_PREQ_GRP.engine_debug('Discounted Price: ' || p_discounted_price);
878                 QP_PREQ_GRP.engine_debug('Old Pricing Seq: ' || v_old_pricing_sequence);
879                 QP_PREQ_GRP.engine_debug('New Pricing Seq: ' || v_related_request_lines(k).PRICING_GROUP_SEQUENCE);
880               END IF; -- END IF l_debug = FND_API.G_TRUE
881 
882               Calculate_Adjusted_Price(p_list_price => p_list_price,  -- List Price
883                                        p_discounted_price => p_discounted_price,
884                                        p_old_pricing_sequence => nvl(v_old_pricing_sequence,
885                                                                      v_related_request_lines(k).PRICING_GROUP_SEQUENCE),
886                                        p_new_pricing_sequence => v_related_request_lines(k).PRICING_GROUP_SEQUENCE,
887                                        p_operand_calc_code => v_related_request_lines(k).OPERAND_CALCULATION_CODE,
888                                        p_operand_value => v_related_request_lines(k).OPERAND_VALUE,
889                                        p_list_line_type => v_related_request_lines(k).RELATED_LIST_LINE_TYPE,
890                                        --p_request_qty          => v_related_request_lines(k).LINE_QTY, -- 2388011,
891                                        p_request_qty => p_list_line_qty,  -- 2388011_new
892                                        p_accrual_flag => v_related_request_lines(k).ACCRUAL_FLAG,
893                                        p_rounding_flag => QP_PREQ_GRP.G_ROUNDING_FLAG,
894                                        p_rounding_factor => p_rounding_factor,
895                                        p_orig_unit_price => p_list_price,
896                                        x_discounted_price => x_discounted_price,  -- Output Discounted Price
897                                        x_adjusted_amount => x_adjusted_amount,  -- Discount amount for this line
898                                        x_list_price => x_list_price,  -- Output List Price
899                                        x_return_status => x_ret_status,
900                                        x_return_status_txt => x_ret_status_txt);
901 
902               v_old_pricing_sequence := v_related_request_lines(k).PRICING_GROUP_SEQUENCE;
903 
904               IF (x_ret_status = FND_API.G_RET_STS_ERROR) THEN
905                 RAISE FND_API.G_EXC_ERROR;
906               END IF;
907 
908               -- This is the final selling price after break evaluation for this discount line
909               v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_adjusted_amount;
910 
911               IF l_debug = FND_API.G_TRUE THEN
912                 QP_PREQ_GRP.engine_debug('Adjusted Line Amount: ' || v_related_request_lines(k).ADJUSTMENT_AMOUNT);
913               END IF; -- END IF l_debug = FND_API.G_TRUE
914             END IF; -- END IF (p_pbh_type in (QP_PREQ_GRP.G_PRICE_LIST_HEADER,QP_PREQ_GRP.G_AGR_LIST_HEADER))
915 
916             -- ELSE IF (v_temp >= p_related_request_lines(k).VALUE_FROM AND...
917           ELSE -- Store the break line which did not satisfy with qty 0,for other related lines
918             v_related_request_lines(k).LINE_QTY := 0;
919             -- This is the final list price or selling price after break evaluation
920             IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
921 
922               Calculate_List_Price_PVT(
923                                        p_related_request_lines(k).OPERAND_CALCULATION_CODE,
927                                        p_related_item_price,
924                                        p_related_request_lines(k).OPERAND_VALUE,
925                                        p_related_request_lines(k).RECURRING_VALUE,  -- block pricing
926                                        0,  -- p_request_qty = 0
928                                        p_service_duration,
929                                        QP_PREQ_GRP.G_ROUNDING_FLAG,
930                                        p_rounding_factor,
931                                        x_list_price,
932                                        x_percent_price,
933                                        x_extended_price,  -- block pricing
934                                        x_ret_status,
935                                        x_ret_status_txt);
936 
937               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
938                 IF l_debug = FND_API.G_TRUE THEN
939                   QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || x_ret_status_txt);
940                 END IF;
941                 RAISE FND_API.G_EXC_ERROR;
942               END IF; -- END IF(x_ret_status = FND_API.G_RET_STS_ERROR)
943 
944               -- This is the final list price after break evaluation
945               -- modified for block pricing
946               IF (p_related_request_lines(k).OPERAND_CALCULATION_CODE = qp_preq_grp.G_BLOCK_PRICE) THEN
947                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_extended_price;
948               ELSE
949                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_list_price;
950               END IF;
951 
952               IF l_debug = FND_API.G_TRUE THEN
953                 QP_PREQ_GRP.engine_debug('List Line Price: ' || v_related_request_lines(k).ADJUSTMENT_AMOUNT );
954               END IF;
955 
956             ELSE --DIS/SUR/FREIGHT_CHARGE
957 
958               Calculate_Adjusted_Price(p_list_price => p_list_price,  -- List Price
959                                        p_discounted_price => p_discounted_price,
960                                        p_old_pricing_sequence => nvl(v_old_pricing_sequence,
961                                                                      v_related_request_lines(k).PRICING_GROUP_SEQUENCE),
962                                        p_new_pricing_sequence => v_related_request_lines(k).PRICING_GROUP_SEQUENCE,
963                                        p_operand_calc_code => v_related_request_lines(k).OPERAND_CALCULATION_CODE,
964                                        p_operand_value => v_related_request_lines(k).OPERAND_VALUE,
965                                        p_list_line_type => v_related_request_lines(k).RELATED_LIST_LINE_TYPE,
966                                        p_request_qty => 0,  -- p_request_qty
967                                        p_accrual_flag => v_related_request_lines(k).ACCRUAL_FLAG,
968                                        p_rounding_flag => QP_PREQ_GRP.G_ROUNDING_FLAG,
969                                        p_rounding_factor => p_rounding_factor,
970                                        p_orig_unit_price => p_list_price,
971                                        x_discounted_price => x_discounted_price,  -- Output Discounted Price
972                                        x_adjusted_amount => x_adjusted_amount,  -- Discount amount for this line
973                                        x_list_price => x_list_price,  -- Output List Price
974                                        x_return_status => x_ret_status,
975                                        x_return_status_txt => x_ret_status_txt);
976 
977               v_old_pricing_sequence := v_related_request_lines(k).PRICING_GROUP_SEQUENCE;
978 
979               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
980                 RAISE FND_API.G_EXC_ERROR;
981               END IF;
982 
983               -- This is the final selling price after break evaluation for this discount line
984               v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_adjusted_amount;
985 
986               IF l_debug = FND_API.G_TRUE THEN
987                 QP_PREQ_GRP.engine_debug('Adjusted Line Amount: ' || x_adjustment_amount);
988               END IF; -- END IF l_debug = FND_API.G_TRUE
989             END IF; -- END IF (p_pbh_type in (QP_PREQ_GRP.G_PRICE_LIST_HEADER
990           END IF; -- END IF (v_temp >= p_related_request_lines(k).VALUE_FROM AND
991 
992           -- RANGE BREAK
993         ELSIF (p_related_request_lines(k).PRICE_BREAK_TYPE_CODE = QP_PREQ_GRP.G_RANGE_BREAK) THEN
994 
995           IF l_debug = FND_API.G_TRUE THEN
996             QP_PREQ_GRP.engine_debug('I am in Range Break');
997             QP_PREQ_GRP.engine_debug('The value of v_count is:' || v_count );
998           END IF;
999 
1000           IF (v_count = 0) THEN
1001             -- begin 2388011, grp_lines_pbh
1002             IF (p_group_value <> 0 ) THEN -- Ravi Change --bug#15895472
1003               l_qualifier_value := p_group_value;
1004               v_temp := p_group_value;
1005             ELSE
1006               l_qualifier_value := p_list_line_qty;
1007               v_temp := p_list_line_qty;
1008             END IF;
1009             -- end 2388011
1010             v_ord_qty := p_list_line_qty;
1011           END IF; -- end IF (v_count = 0)
1012 
1013           IF l_debug = FND_API.G_TRUE THEN
1014             QP_PREQ_GRP.engine_debug('p_group_value: ' || p_group_value); -- shu debug, 2388011
1015             QP_PREQ_GRP.engine_debug('p_list_line_qty (v_ord_qty): ' || p_list_line_qty); -- shu debug, 2388011
1016             QP_PREQ_GRP.engine_debug('l_qualifier_value (either p_group_value or p_list_line_qty): ' || l_qualifier_value); -- shu debug, 2388011
1017             QP_PREQ_GRP.engine_debug('v_temp (either p_group_value or p_list_line_qty): ' || v_temp); -- shu debug, 2388011
1018           END IF; -- END IF l_debug = FND_API.G_TRUE
1019 
1020           -- The check to see if the ordered quantity falls in the range needs to be done only once
1024             v_temp := 0;
1021           -- Ex: If Ord Qty = 50 and 100-null then u do not get it
1022 
1023           IF (p_related_request_lines(k).VALUE_FROM > v_temp AND v_count = 0) THEN --2388011
1025           END IF;
1026 
1027           IF (v_temp <> 0) THEN	--bug#15895472
1028 
1029             -- Ex: 100-NULL
1030             IF (p_related_request_lines(k).VALUE_TO IS NULL) THEN
1031               v_related_request_lines(k).LINE_QTY := v_temp;
1032             ELSE
1033               IF l_debug = FND_API.G_TRUE THEN
1034                 QP_PREQ_GRP.engine_debug('C100# value from: ' || p_related_request_lines(k).value_from);
1035                 QP_PREQ_GRP.engine_debug('C200# value to: ' || p_related_request_lines(k).value_to);
1036                 QP_PREQ_GRP.engine_debug('C300# Qualifier Value: ' || l_qualifier_value); --2388011
1037                 QP_PREQ_GRP.engine_debug('C400# Group Amount: ' || p_group_value); --2388011
1038               END IF; -- END IF l_debug = FND_API.G_TRUE
1039 
1040               Get_Satisfied_Range(
1041                                   p_related_request_lines(k).value_from,
1042                                   p_related_request_lines(k).value_to,
1043                                   l_qualifier_value,  --2388011
1044                                   p_list_line_id,  -- for accum range break
1045                                   l_continuous_flag,  -- 4061138
1046                                   l_prorated_flag,  -- 4061138
1047                                   l_satisfied_value);
1048 
1049               IF l_debug = FND_API.G_TRUE THEN
1050                 QP_PREQ_GRP.engine_debug('C500#: ' || l_satisfied_value);
1051                 QP_PREQ_GRP.engine_debug('C600# list price : ' || p_list_price);
1052               END IF; -- END IF l_debug = FND_API.G_TRUE
1053 
1054               IF l_debug = FND_API.G_TRUE THEN
1055                 QP_PREQ_GRP.engine_debug ('PBH operand Calc Code : ' || p_operand_calc_code);
1056               END IF;
1057 
1058               -- Do not calculate the per unit satisfied value if it is BLOCK_PRICING
1059               IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
1060                 IF (p_operand_calc_code = 'BLOCK_PRICE') THEN
1061                   v_calculate_per_unit_flag := 'N';
1062                 ELSE
1063                   v_calculate_per_unit_flag := 'Y';
1064                 END IF;
1065               ELSE
1066                 v_calculate_per_unit_flag := 'Y';
1067               END IF;
1068               -- for FTE breakunit
1069               -- also do not calculate per unit value if line is BREAKUNIT_PRICE
1070               IF (p_related_request_lines(k).OPERAND_CALCULATION_CODE = QP_PREQ_GRP.G_BREAKUNIT_PRICE) THEN
1071                 v_calculate_per_unit_flag := 'N';
1072               END IF;
1073 
1074               IF l_debug = FND_API.G_TRUE THEN
1075                 QP_PREQ_GRP.engine_debug ('Calculate Per Unit Flag : ' || v_calculate_per_unit_flag);
1076               END IF;
1077 
1078               -- 2388011_new
1079               -- Ravi Change Applicable for both linegroup Group Amount and Line Item Amt
1080               IF (p_group_value > 0 AND v_calculate_per_unit_flag = 'Y') THEN
1081                 v_attribute_value_per_unit := p_group_value / p_list_line_qty; -- 2388011_latest
1082                 v_related_request_lines(k).LINE_QTY := l_satisfied_value / v_attribute_value_per_unit; -- 2388011_latest
1083               ELSE
1084                 v_related_request_lines(k).LINE_QTY := l_satisfied_value;
1085               END IF;
1086 
1087               v_temp := v_temp - l_satisfied_value;
1088 
1089               -- shu, fix bug 2372064
1090               -- l_satisfied_value is 0 have 2 cases: 1) no more to satisfied 2) from=to such as 0-0 break
1091               -- only for case 1) should reset v_temp
1092               -- for accum range break, case 1 should take into account accum_value
1093               -- to determine if no more need to be satisfied:
1094               --    if (stored accum value + l_qualifier) < value_to
1095               --    then no more satisfied
1096               IF (l_satisfied_value = 0
1097                   AND p_related_request_lines(k).value_from <> p_related_request_lines(k).value_to
1098                   AND l_accum_global + l_qualifier_value < p_related_request_lines(k).value_to)
1099                 THEN
1100                 v_temp := 0;
1101               END IF; -- END IF (l_satisfied_value = 0
1102 
1103             END IF; -- END IF (p_related_request_lines(k).VALUE_TO IS NULL)
1104 
1105             IF l_debug = FND_API.G_TRUE THEN
1106               QP_PREQ_GRP.engine_debug('List Line Quantity: ' || v_related_request_lines(k).LINE_QTY );
1107               QP_PREQ_GRP.engine_debug('Temp: ' || v_temp );
1108             END IF;
1109 
1110             IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
1111               -- Call the Calculate List Price Function
1112               Calculate_List_Price_PVT(
1113                                        p_related_request_lines(k).OPERAND_CALCULATION_CODE,
1114                                        p_related_request_lines(k).OPERAND_VALUE,
1115                                        p_related_request_lines(k).RECURRING_VALUE,  -- block pricing
1116                                        --v_ord_qty, -- 2388011_new
1117                                        v_related_request_lines(k).LINE_QTY,  -- new fix, error found in block pricing
1118                                        p_related_item_price,
1119                                        p_service_duration,
1120                                        QP_PREQ_GRP.G_ROUNDING_FLAG,
1121                                        NULL,  -- fix bug 2724697, null rounding_factor so operand does not get rounded, it will be rounded later at Average Out PBH Lines
1122                                        x_list_price,
1123                                        x_percent_price,
1127 
1124                                        x_extended_price,  -- block pricing
1125                                        x_ret_status,
1126                                        x_ret_status_txt);
1128               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
1129                 RAISE FND_API.G_EXC_ERROR;
1130               END IF;
1131 
1132               -- This is the final list price after break evaluation
1133               -- modified for block pricing
1134               IF (p_related_request_lines(k).OPERAND_CALCULATION_CODE = qp_preq_grp.G_BLOCK_PRICE) THEN
1135                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_extended_price;
1136               ELSE
1137                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_list_price;
1138               END IF;
1139 
1140             ELSE -- DIS/SUR/FREIGHT_CHARGE
1141               IF l_debug = FND_API.G_TRUE THEN
1142                 QP_PREQ_GRP.engine_debug('I am in Discount Break (RANGE BLOCK)');
1143                 QP_PREQ_GRP.engine_debug('OPERAND_VALUE: '|| v_related_request_lines(k).OPERAND_VALUE); --shu debug 2388011
1144                 QP_PREQ_GRP.engine_debug('LINE_QTY: '|| v_related_request_lines(k).LINE_QTY); --shu debug 2388011
1145                 QP_PREQ_GRP.engine_debug('l_qualifier_value (p_request_qty)'|| l_qualifier_value); --shu debug 2388011
1146               END IF;
1147 
1148               --p_request_qty          => l_qualifier_value,
1149               -- 2388011, range break should be total amount not l_satisfied_value
1150               --p_request_qty          => p_list_line_qty,
1151               -- group quantity,group value or item quantity 2388011_new
1152 
1153               Calculate_Adjusted_Price(
1154                                        p_list_price => p_list_price,  -- List Price
1155                                        p_discounted_price => p_discounted_price,
1156                                        p_old_pricing_sequence => nvl(v_old_pricing_sequence,
1157                                                                      v_related_request_lines(k).PRICING_GROUP_SEQUENCE),
1158                                        p_new_pricing_sequence => v_related_request_lines(k).PRICING_GROUP_SEQUENCE,
1159                                        p_operand_calc_code => v_related_request_lines(k).OPERAND_CALCULATION_CODE,
1160                                        p_operand_value => v_related_request_lines(k).OPERAND_VALUE,
1161                                        p_list_line_type => v_related_request_lines(k).RELATED_LIST_LINE_TYPE,
1162                                        p_request_qty => v_related_request_lines(k).LINE_QTY,  --always satisfied qty
1163                                        p_accrual_flag => v_related_request_lines(k).ACCRUAL_FLAG,
1164                                        p_rounding_flag => QP_PREQ_GRP.G_ROUNDING_FLAG,
1165                                        p_rounding_factor => p_rounding_factor,
1166                                        p_orig_unit_price => p_list_price,
1167                                        x_discounted_price => x_discounted_price,  -- Output Discounted Price
1168                                        x_adjusted_amount => x_adjusted_amount,  -- Discount amount for this line
1169                                        x_list_price => x_list_price,  -- Output List Price
1170                                        x_return_status => x_ret_status,
1171                                        x_return_status_txt => x_ret_status_txt);
1172 
1173               v_old_pricing_sequence := v_related_request_lines(k).PRICING_GROUP_SEQUENCE;
1174 
1175               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
1176                 RAISE FND_API.G_EXC_ERROR;
1177               END IF;
1178 
1179               -- This is the final list price after break evaluation
1180               v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_adjusted_amount;
1181               IF l_debug = FND_API.G_TRUE THEN
1182                 QP_PREQ_GRP.engine_debug('Adjusted Line Amount: ' || x_adjusted_amount);
1183               END IF;
1184             END IF;
1185 
1186             v_count := v_count + 1;
1187           ELSE -- v_temp > 0
1188 
1189             -- Store the break line which did not satisfy with qty 0
1190             v_related_request_lines(k).LINE_QTY := 0;
1191             -- This is the final list price or selling price after break evaluation
1192             IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
1193 
1194               Calculate_List_Price_PVT(p_related_request_lines(k).OPERAND_CALCULATION_CODE,
1195                                        p_related_request_lines(k).OPERAND_VALUE,
1196                                        p_related_request_lines(k).RECURRING_VALUE,  -- block pricing
1197                                        0,
1198                                        p_related_item_price,
1199                                        p_service_duration,
1200                                        QP_PREQ_GRP.G_ROUNDING_FLAG,
1201                                        NULL,  -- fix bug 2724697, null rounding_factor so operand does not get rounded, it will be rounded later at Average Out PBH Lines
1202                                        x_list_price,
1203                                        x_percent_price,
1204                                        x_extended_price,
1205                                        x_ret_status,
1206                                        x_ret_status_txt);
1207 
1208               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
1209                 RAISE FND_API.G_EXC_ERROR;
1210               END IF;
1211 
1212               -- This is the final list price after break evaluation
1213               -- modified for block pricing
1214               IF (p_related_request_lines(k).OPERAND_CALCULATION_CODE = qp_preq_grp.G_BLOCK_PRICE) THEN
1215                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_extended_price;
1216               ELSE
1217                 v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_list_price;
1218               END IF;
1222               END IF;
1219 
1220               IF l_debug = FND_API.G_TRUE THEN
1221                 QP_PREQ_GRP.engine_debug('List Line Price: ' || x_list_price);
1223 
1224             ELSE -- DIS/SUR/FREIGHT_CHARGE
1225 
1226               Calculate_Adjusted_Price(
1227                                        p_list_price => p_list_price,  -- List Price
1228                                        p_discounted_price => p_discounted_price,
1229                                        p_old_pricing_sequence => nvl(v_old_pricing_sequence
1230                                                                      , v_related_request_lines(k).PRICING_GROUP_SEQUENCE),
1231                                        p_new_pricing_sequence => v_related_request_lines(k).PRICING_GROUP_SEQUENCE,
1232                                        p_operand_calc_code =>
1233                                        v_related_request_lines(k).OPERAND_CALCULATION_CODE,
1234                                        p_operand_value => v_related_request_lines(k).OPERAND_VALUE,
1235                                        p_list_line_type => v_related_request_lines(k).RELATED_LIST_LINE_TYPE,
1236                                        p_request_qty => 0,
1237                                        p_accrual_flag => v_related_request_lines(k).ACCRUAL_FLAG,
1238                                        p_rounding_flag => QP_PREQ_GRP.G_ROUNDING_FLAG,
1239                                        p_rounding_factor => p_rounding_factor,
1240                                        p_orig_unit_price => p_list_price,
1241                                        x_discounted_price => x_discounted_price,  -- Output Discounted Price
1242                                        x_adjusted_amount => x_adjusted_amount,  -- Discount amount for this line
1243                                        x_list_price => x_list_price,  -- Output List Price
1244                                        x_return_status => x_ret_status,
1245                                        x_return_status_txt => x_ret_status_txt);
1246 
1247               v_old_pricing_sequence := v_related_request_lines(k).PRICING_GROUP_SEQUENCE;
1248 
1249               IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
1250                 RAISE FND_API.G_EXC_ERROR;
1251               END IF;
1252 
1253               -- This is the final list price after break evaluation
1254               v_related_request_lines(k).ADJUSTMENT_AMOUNT := x_adjusted_amount;
1255               IF l_debug = FND_API.G_TRUE THEN
1256                 QP_PREQ_GRP.engine_debug('Adjusted Line Amount: ' || x_adjusted_amount);
1257               END IF;
1258             END IF;
1259 
1260             v_count := v_count + 1;
1261           END IF; -- v_temp >0
1262         END IF; -- POINT or RANGE Break
1263       END IF; -- p_line_detail_index match
1264 
1265       EXIT WHEN k = v_related_request_lines.LAST;
1266       k := v_related_request_lines.NEXT(k);
1267     END LOOP; -- END WHILE (k IS NOT NULL)
1268 
1269     -- This needs to be done only to get the averaged out value for the PBH Line
1270     IF (v_related_request_lines.COUNT > 0) THEN
1271       IF l_debug = FND_API.G_TRUE THEN
1272         QP_PREQ_GRP.engine_debug('.........Average out value for the PBH line........ ' );
1273       END IF;
1274       v_index := v_related_request_lines.FIRST;
1275       WHILE (v_index IS NOT NULL)
1276         LOOP
1277         IF (v_related_request_lines(v_index).LINE_DETAIL_INDEX = p_list_line_index) THEN
1278           IF l_debug = FND_API.G_TRUE THEN
1279             QP_PREQ_GRP.engine_debug('p_list_line_index '|| p_list_line_index ); -- shu debug 2388011
1280             QP_PREQ_GRP.engine_debug('p_list_line_qty: '|| p_list_line_qty ); -- shu debug 2388011
1281             QP_PREQ_GRP.engine_debug('p_actual_line_qty: '|| p_actual_line_qty ); -- shu debug 2388011
1282           END IF;
1283 
1284           IF (p_pbh_type IN (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
1285             -- modified for block pricing
1286             IF (v_related_request_lines(v_index).OPERAND_CALCULATION_CODE = QP_PREQ_GRP.G_BLOCK_PRICE) THEN
1287               IF (v_related_request_lines(v_index).LINE_QTY <> 0) THEN
1288                 v_total_amount := v_total_amount + v_related_request_lines(v_index).ADJUSTMENT_AMOUNT;
1289 
1290                 -- fix for OM Pricing/Availability
1291                 IF (v_related_request_lines(v_index).RECURRING_VALUE > 0) THEN
1292                   v_related_request_lines(v_index).ADJUSTMENT_AMOUNT :=
1293                   v_related_request_lines(v_index).ADJUSTMENT_AMOUNT / v_related_request_lines(v_index).LINE_QTY;
1294                 END IF;
1295               ELSE
1296                 -- fix for OM Pricing/Availability
1297                 IF (v_related_request_lines(v_index).RECURRING_VALUE > 0) THEN
1298                   v_related_request_lines(v_index).ADJUSTMENT_AMOUNT :=
1299                   v_related_request_lines(v_index).ADJUSTMENT_AMOUNT / v_related_request_lines(v_index).RECURRING_VALUE;
1300                 END IF;
1301               END IF;
1302             ELSE
1303               v_total_amount := v_total_amount + (v_related_request_lines(v_index).LINE_QTY *
1304                                                   v_related_request_lines(v_index).ADJUSTMENT_AMOUNT);
1305             END IF;
1306 
1307             -- begin 2388011_new, grp_lines_pbh,
1308             -- fix 2724697, round here after average out PBH lines
1309 
1310             IF (p_list_line_qty <> 0 ) THEN
1311 
1312               x_pbh_list_price := v_total_amount / p_list_line_qty; -- Divide by grp amount/unit or group quantity
1313               x_pbh_extended_price := v_total_amount; -- block pricing
1314 
1315             ELSE -- bug 3075286 discussed the solution with rtata
1316 
1317               x_pbh_list_price := v_total_amount;
1318               x_pbh_extended_price := 0; -- block pricing
1319 
1320             END IF;
1321 
1325               l_price_round_options := nvl(FND_PROFILE.VALUE('QP_SELLING_PRICE_ROUNDING_OPTIONS'), QP_Calculate_Price_PUB.G_NO_ROUND);
1322             IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES AND p_rounding_factor IS NOT NULL) THEN
1323               x_pbh_list_price := ROUND (x_pbh_list_price, p_rounding_factor); -- Divide by grp amount/unit or group quantity
1324             ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check v_selling_price_rounding_options profile
1326               IF (l_price_round_options = G_ROUND_ADJ AND p_rounding_factor IS NOT NULL) THEN
1327                 x_pbh_list_price := ROUND (x_pbh_list_price, p_rounding_factor); -- Divide by grp amount/unit or group quantity
1328               END IF; -- end if G_ROUND_ADJ
1329             END IF; --end if rounding stuff
1330 
1331             IF l_debug = FND_API.G_TRUE THEN
1332               QP_PREQ_GRP.engine_debug('x_pbh_list_price: '|| x_pbh_list_price);
1333             END IF; -- END IF l_debug
1334 
1335 
1336           ELSE
1337             v_total_amount := v_total_amount + (v_related_request_lines(v_index).LINE_QTY *
1338                                                 v_related_request_lines(v_index).ADJUSTMENT_AMOUNT);
1339             IF l_debug = FND_API.G_TRUE THEN
1340               QP_PREQ_GRP.engine_debug ('v_index: '|| v_index); --2388011
1341               QP_PREQ_GRP.engine_debug ('LINE_QTY : '|| v_related_request_lines(v_index).LINE_QTY ); --2388011
1342               QP_PREQ_GRP.engine_debug ('ADJUSTMENT_AMOUNT for the line: '|| v_related_request_lines(v_index).ADJUSTMENT_AMOUNT); --2388011
1343               QP_PREQ_GRP.engine_debug ('v_total_amount for now: '|| v_total_amount); --2388011
1344             END IF; -- END IF l_debug = FND_API.G_TRUE
1345 
1346             -- begin 2388011_new, grp_lines_pbh,
1347 
1348 
1349             IF (p_list_line_qty <> 0 ) THEN
1350 
1351               x_adjustment_amount := v_total_amount / p_list_line_qty; -- Divide by grp amount/unit or group quantity
1352 
1353             ELSE -- bug 3075286
1354 
1355               x_adjustment_amount := v_total_amount;
1356 
1357             END IF;
1358 
1359             IF l_debug = FND_API.G_TRUE THEN
1360               QP_PREQ_GRP.engine_debug ('p_list_line_qty: '|| p_list_line_qty); --2388011
1361               QP_PREQ_GRP.engine_debug ('x_adjustment_amount: '|| x_adjustment_amount); --2388011
1362             END IF; -- END IF l_debug = FND_API.G_TRUE
1363             -- end 2388011, grp_lines_pbh
1364 
1365           END IF; -- END IF (p_pbh_type in (QP_PREQ_GRP.G_PRICE_LIST_HEADER...
1366 
1367           IF l_debug = FND_API.G_TRUE THEN
1368             QP_PREQ_GRP.engine_debug ('Total Amount : ' || v_total_amount);
1369             QP_PREQ_GRP.engine_debug ('Total Qty : ' || v_ord_qty);
1370             QP_PREQ_GRP.engine_debug ('Total Adjustment : ' || x_adjustment_amount);
1371           END IF; -- END IF l_debug = FND_API.G_TRUE THEN
1372         END IF;
1373 
1374         EXIT WHEN v_index = v_related_request_lines.LAST;
1375         v_index := v_related_request_lines.NEXT(v_index);
1376       END LOOP;
1377     END IF;
1378     x_related_request_lines_tbl := v_related_request_lines;
1379   EXCEPTION
1380     WHEN FND_API.G_EXC_ERROR THEN
1381       IF l_debug = FND_API.G_TRUE THEN
1382         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || x_ret_status_txt);
1383       END IF;
1384       x_return_status := FND_API.G_RET_STS_ERROR;
1385       x_return_status_txt := x_ret_status_txt;
1386     WHEN OTHERS THEN
1387       IF l_debug = FND_API.G_TRUE THEN
1388         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || SQLERRM);
1389       END IF;
1390       x_return_status := FND_API.G_RET_STS_ERROR;
1391       x_return_status_txt := v_routine_name || ' ' || SQLERRM;
1392   END Process_Price_Break;
1393 
1394   PROCEDURE Calculate_Adjustment(p_price NUMBER
1395                                  , p_operand_calculation_code VARCHAR2
1396                                  , p_operand_value NUMBER
1397                                  , p_priced_quantity NUMBER
1398                                  , x_calc_adjustment OUT NOCOPY NUMBER
1399                                  , x_return_status OUT NOCOPY VARCHAR2
1400                                  , x_return_status_text OUT NOCOPY VARCHAR2) IS
1401 
1402   l_routine VARCHAR2(50) := 'QP_Calculate_Price_PUB.Calculate_Adjustment';
1403 
1404   BEGIN
1405     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
1406     IF l_debug = FND_API.G_TRUE THEN
1407       QP_PREQ_GRP.ENGINE_DEBUG('In Routine: ' || l_routine);
1408 
1409       -- begin 2892848
1410       QP_PREQ_GRP.ENGINE_DEBUG('p_price: ' || p_price);
1411       QP_PREQ_GRP.ENGINE_DEBUG('p_operand_calculation_code: ' || p_operand_calculation_code);
1412       QP_PREQ_GRP.ENGINE_DEBUG('p_operand_value: ' || p_operand_value);
1413       QP_PREQ_GRP.ENGINE_DEBUG('p_priced_quantity: ' || p_priced_quantity);
1414       -- end 2892848
1415 
1416     END IF;
1417     IF p_operand_calculation_code = QP_PREQ_GRP.G_PERCENT_DISCOUNT THEN
1418      -- x_calc_adjustment := abs(p_price) * p_operand_value / 100; bug 6122488
1419      x_calc_adjustment := p_price * p_operand_value / 100;
1420     ELSIF p_operand_calculation_code = QP_PREQ_GRP.G_AMOUNT_DISCOUNT THEN
1421       x_calc_adjustment := p_operand_value;
1422     ELSIF p_operand_calculation_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT THEN
1423       x_calc_adjustment := (abs(p_price) - p_operand_value);
1424     ELSIF p_operand_calculation_code = QP_PREQ_GRP.G_LUMPSUM_DISCOUNT THEN
1425       -- [julin/4571612/4671446] explicitly set FND_API.G_NULL_NUM qty means infinity; this qty and zero qty yield no adj
1426       IF (p_priced_quantity = FND_API.G_NULL_NUM OR p_priced_quantity = 0) THEN
1427         x_calc_adjustment := 0;
1428       ELSE
1429         x_calc_adjustment := p_operand_value / p_priced_quantity;
1430       END IF;
1431     ELSIF p_operand_calculation_code = QP_PREQ_GRP.G_BREAKUNIT_PRICE THEN
1435     x_return_status := FND_API.G_RET_STS_SUCCESS;
1432       x_calc_adjustment := p_operand_value; -- FTE breakunit
1433     END IF;
1434 
1436     x_return_status_text := l_routine ||' SUCCESS';
1437 
1438     IF l_debug = FND_API.G_TRUE THEN
1439       QP_PREQ_GRP.ENGINE_DEBUG('Out of Routine: ' || l_routine);
1440 
1441     END IF;
1442   EXCEPTION
1443     WHEN OTHERS THEN
1444       IF l_debug = FND_API.G_TRUE THEN
1445         QP_PREQ_GRP.ENGINE_DEBUG('Error in calculating bucket price '|| SQLERRM);
1446       END IF;
1447       x_return_status := FND_API.G_RET_STS_ERROR;
1448       x_return_status_text := l_routine ||' '|| SQLERRM;
1449   END Calculate_Adjustment;
1450 
1451   PROCEDURE Get_Satisfied_Range(p_value_from NUMBER,
1452                                 p_value_to NUMBER,
1453                                 p_qualifier_value NUMBER,
1454                                 p_list_line_id NUMBER,  -- for accum range break
1455                                 p_continuous_flag VARCHAR,  -- 4061138, continuous price break
1456                                 p_prorated_flag VARCHAR,  -- 4061138
1457                                 x_satisfied_value OUT NOCOPY NUMBER) AS
1458   l_value_from NUMBER;
1459   l_precision NUMBER;
1460   l_difference NUMBER;
1461   l_value_from_precision NUMBER;
1462   l_value_to_precision NUMBER;
1463 
1464   -- variables for accumulated range break
1465   l_new_qualifier NUMBER;
1466   l_accum NUMBER; -- accumulated value
1467   l_accum_context VARCHAR2(30);
1468   l_accum_attrib VARCHAR2(240);
1469   l_accum_flag VARCHAR2(1);
1470   v_list_line_no QP_LIST_LINES.LIST_LINE_NO%TYPE;
1471   v_price_eff_date DATE;
1472   v_line_id NUMBER;
1473   l_req_attrs_tbl QP_RUNTIME_SOURCE.accum_req_line_attrs_tbl;
1474   l_accum_rec QP_RUNTIME_SOURCE.accum_record_type;
1475   counter PLS_INTEGER := 1;
1476   l_valid_line_id number; --added for 14783146
1477   -- for accum range break
1478   -- gets request line attributes to pass to the custom API call
1479   -- (only the attributes that qualified for the price break in question)
1480   CURSOR l_req_line_attrs_cur(p_list_line_id NUMBER) IS
1481     SELECT line_index, attribute_type, context, attribute, value_from, grouping_number
1482     FROM qp_npreq_line_attrs_tmp
1483     WHERE list_line_id = p_list_line_id
1484     AND pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW;
1485 
1486   BEGIN
1487 
1488     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
1489     IF l_debug = FND_API.G_TRUE THEN
1490       QP_PREQ_GRP.engine_debug('In Procedure : Get_Satisfied_Range');
1491       QP_PREQ_GRP.engine_debug('               continuous_flag = '|| p_continuous_flag);
1492       QP_PREQ_GRP.engine_debug('               prorated_flag   = '|| p_prorated_flag);
1493     END IF;
1494     l_value_from_precision := power(10, - (length(to_char(abs(p_value_from) - trunc(abs(p_value_from)))) - 1));
1495 
1496     l_value_to_precision := power(10, - (length(to_char(abs(p_value_to) - trunc(abs(p_value_to)))) - 1));
1497 
1498     l_difference := least(l_value_from_precision, l_value_to_precision);
1499 
1500     -- 4061138, precision not needed if continuous break
1501     IF p_continuous_flag <> 'Y' THEN
1502       -- if break is prorated, only consider the from precision
1503       IF p_prorated_flag = 'Y' THEN
1504         l_precision := l_value_from_precision;
1505       ELSE
1506         l_precision := power(10, - (length(to_char(abs(l_difference) - trunc(abs(l_difference)))) - 1));
1507       END IF;
1508     ELSE
1509       l_precision := 0;
1510     END IF;
1511 
1512     -- 4061138, added p_continuous_flag condition to prevent remapping of a zero-value value_from
1513     IF (p_value_from = 0 AND p_continuous_flag <> 'Y') THEN
1514       l_value_from := l_difference;
1515     ELSE
1516       l_value_from := p_value_from;
1517     END IF;
1518 
1519     IF (nvl(FND_PROFILE.VALUE('QP_ACCUM_ATTR_ENABLED'), QP_PREQ_GRP.G_NO) = QP_PREQ_GRP.G_YES AND
1520         p_list_line_id IS NOT NULL AND
1521         nvl(QP_PREQ_PUB.G_CALL_FROM_PRICE_BOOK, QP_PREQ_GRP.G_NO) <> QP_PREQ_GRP.G_YES) -- price book
1522       THEN
1523       -- fetch accumulation attribute
1524       -- these are "cached" on the basis of list_line_id
1525       -- if list_line_id changes, then need to retrieve values from temp table
1526       -- else use previously cached values
1527       IF (p_list_line_id = l_prev_list_line_id) THEN
1528         IF l_debug = FND_API.G_TRUE THEN
1529           QP_PREQ_GRP.engine_debug('   list_line_id = '|| p_list_line_id ||', prev = '|| l_prev_list_line_id);
1530         END IF;
1531         l_accum_context := l_accum_context_cache;
1532         l_accum_attrib := l_accum_attrib_cache;
1533         l_accum_flag := l_accum_flag_cache;
1534         v_list_line_no := l_accum_list_line_no_cache;
1535         IF l_debug = FND_API.G_TRUE THEN
1536           QP_PREQ_GRP.engine_debug('   using cached values for accum context, attribute, etc.');
1537         END IF;
1538       ELSE
1539         BEGIN
1540           SELECT accum_context, accum_attribute, accum_attr_run_src_flag, list_line_no
1541           INTO l_accum_context, l_accum_attrib, l_accum_flag, v_list_line_no
1542           FROM qp_list_lines
1543           WHERE list_line_id = p_list_line_id;
1544           --   from qp_npreq_ldets_tmp
1545           --   where created_from_list_line_id = p_list_line_id
1546           --   and rownum = 1;
1547         EXCEPTION
1548           WHEN NO_DATA_FOUND THEN
1549             IF l_debug = FND_API.G_TRUE THEN
1550               QP_PREQ_GRP.engine_debug('   No rows returned for list line ID '|| p_list_line_id);
1551             END IF;
1552         END;
1553 
1554         IF l_debug = FND_API.G_TRUE THEN
1555           QP_PREQ_GRP.engine_debug('   accum context, attribute, etc. not cached');
1556         END IF;
1557         -- cache the values
1561         l_accum_list_line_no_cache := v_list_line_no;
1558         l_accum_context_cache := l_accum_context;
1559         l_accum_attrib_cache := l_accum_attrib;
1560         l_accum_flag_cache := l_accum_flag;
1562         l_prev_list_line_id := p_list_line_id;
1563       END IF;
1564       IF (l_accum_attrib IS NULL) THEN
1565         -- conceptually, this means no accumulation processing
1566         -- in this code, we set accum=0 and let accumulation processing fall through
1567         l_accum := 0;
1568         IF l_debug = FND_API.G_TRUE THEN
1569           QP_PREQ_GRP.engine_debug('   no accum attribute specified.');
1570         END IF;
1571       ELSE
1572         IF l_debug = FND_API.G_TRUE THEN
1573           QP_PREQ_GRP.engine_debug('   accum attribute = '|| l_accum_attrib);
1574           QP_PREQ_GRP.engine_debug('   line index = '|| l_line_index);
1575         END IF;
1576 
1577         -- try to get accum value from request line
1578         BEGIN
1579           SELECT DISTINCT value_from
1580           INTO l_accum
1581           FROM qp_npreq_line_attrs_tmp
1582           WHERE line_index = l_line_index -- (l_line_index is a global package variable)
1583           AND context = l_accum_context
1584           AND attribute = l_accum_attrib
1585           AND pricing_status_code = QP_PREQ_GRP.G_STATUS_UNCHANGED;
1586 
1587           IF l_debug = FND_API.G_TRUE THEN
1588             QP_PREQ_GRP.engine_debug('   accum value '|| l_accum ||' passed on request line.');
1589           END IF;
1590         EXCEPTION
1591           WHEN NO_DATA_FOUND THEN
1592             IF l_debug = FND_API.G_TRUE THEN
1593               QP_PREQ_GRP.engine_debug('   accum value not passed on request line.');
1594             END IF;
1595             -- accum value was not passed on request line
1596             IF l_accum_flag = 'Y'
1597               THEN
1598               ------------------------------------------------------
1599               -- call the custom API
1600               -- 1. construct the table of request line attributes
1601               -- 2. construct the accumulation record
1602               -- 3. call function Get_numeric_attribute_value
1603               --
1604               -- For performance reasons, the code does not follow steps 1,2,3 in order.
1605               -- One select statement (a cursor) needed for step 1.
1606               -- Another select needed for steps 2 and 3.
1607               -- Last select needed to get order id.
1608               ------------------------------------------------------
1609               IF l_debug = FND_API.G_TRUE THEN
1610                 QP_PREQ_GRP.engine_debug(' * Calling Custom API for accumulation *');
1611                 QP_PREQ_GRP.engine_debug('   request line attr(s):');
1612               END IF;
1613               FOR attrs IN l_req_line_attrs_cur(p_list_line_id) LOOP
1614                 l_req_attrs_tbl(counter).line_index := attrs.line_index;
1615                 l_req_attrs_tbl(counter).attribute_type := attrs.attribute_type;
1616                 l_req_attrs_tbl(counter).context := attrs.context;
1617                 l_req_attrs_tbl(counter).attribute := attrs.attribute;
1618                 l_req_attrs_tbl(counter).VALUE := attrs.value_from;
1619                 l_req_attrs_tbl(counter).grouping_no := attrs.grouping_number;
1620                 IF l_debug = FND_API.G_TRUE THEN
1621                   QP_PREQ_GRP.engine_debug('   '|| counter ||': line index '|| attrs.line_index ||', '|| attrs.attribute_type
1622                                            ||', '|| attrs.context ||', '|| attrs.attribute ||', '|| attrs.value_from
1623                                            ||', '|| attrs.grouping_number);
1624                 END IF;
1625                 counter := counter + 1;
1626               END LOOP;
1627 
1628               -- get the order (header) ID if it's null
1629               -- this should never happen, though
1630               IF QP_PREQ_GRP.G_ORDER_ID IS NULL THEN
1631                 BEGIN
1632                   SELECT line_id
1633                   INTO QP_PREQ_GRP.G_ORDER_ID
1634                   FROM qp_npreq_lines_tmp
1635                   WHERE line_type_code = QP_PREQ_GRP.G_ORDER_LEVEL;
1636                 EXCEPTION
1637                   WHEN NO_DATA_FOUND THEN
1638                     IF l_debug = FND_API.G_TRUE THEN
1639                       QP_PREQ_GRP.engine_debug(' - summary line not present; cannot get order ID');
1640                     END IF;
1641                 END;
1642                 IF l_debug = FND_API.G_TRUE THEN
1643                   QP_PREQ_GRP.engine_debug(' ^ G_ORDER_ID was null, select statement got value '|| QP_PREQ_GRP.G_ORDER_ID);
1644                 END IF;
1645               END IF;
1646 
1647               -- get order line ID and pricing effective date
1648               -- these values are "cached" on the basis of order_id and line_index
1649               -- if the composite line_index+order_id changes, then need to retrieve new line_id/eff date
1650               -- else use the previously cached values
1651               /*IF (QP_PREQ_GRP.G_LINE_ID IS NULL OR
1652                   QP_PREQ_GRP.G_PRICE_EFF_DATE IS NULL OR
1653                   -- 4613884 bugfix
1654                   TO_CHAR(l_line_index || QP_PREQ_GRP.G_ORDER_ID) <> TO_CHAR(l_prev_line_index || l_prev_order_id))
1655                 THEN*/
1656                 IF l_debug = FND_API.G_TRUE THEN
1657                   QP_PREQ_GRP.engine_debug('   need to cache line_id, price_eff_date!');
1658                   QP_PREQ_GRP.engine_debug('    - order_id ('|| qp_preq_grp.G_ORDER_ID ||'), prev_order_id ('|| l_prev_order_id || ')');
1659                   QP_PREQ_GRP.engine_debug('    - line_index ('|| l_line_index ||'), prev_line_index ('|| l_prev_line_index || ')');
1660                 END IF;
1661                 SELECT lines.line_id, lines.pricing_effective_date
1662                 INTO v_line_id, v_price_eff_date
1666                 QP_PREQ_GRP.G_LINE_ID := v_line_id;
1663                 FROM qp_npreq_lines_tmp lines
1664                 WHERE lines.line_index = l_line_index;
1665 
1667                 QP_PREQ_GRP.G_PRICE_EFF_DATE := v_price_eff_date;
1668                 l_prev_order_id := QP_PREQ_GRP.G_ORDER_ID;
1669                 l_prev_line_index := l_line_index;
1670               /*ELSE
1671                 IF l_debug = FND_API.G_TRUE THEN
1672                   QP_PREQ_GRP.engine_debug('   using cached line_id, price_eff_date');
1673                 END IF;
1674                 v_line_id := QP_PREQ_GRP.G_LINE_ID;
1675                 v_price_eff_date := QP_PREQ_GRP.G_PRICE_EFF_DATE;
1676               END IF;*/
1677 
1678               IF l_debug = FND_API.G_TRUE THEN
1679                 QP_PREQ_GRP.engine_debug('   order ID '|| QP_PREQ_GRP.G_ORDER_ID ||
1680                                          ', line ID '|| QP_PREQ_GRP.G_LINE_ID);
1681               END IF;
1682 
1683               l_accum_rec.p_request_type_code := QP_PREQ_GRP.G_REQUEST_TYPE_CODE;
1684               l_accum_rec.context := l_accum_context;
1685               l_accum_rec.attribute := l_accum_attrib;
1686               IF (l_accum_context = 'VOLUME' AND l_accum_attrib = 'PRICING_ATTRIBUTE19') THEN
1687 	      --added for 14783146
1688 		BEGIN
1689 			SELECT 1 INTO l_valid_line_id
1690 			FROM oe_order_lines_all
1691 			WHERE line_id=v_line_id
1692 			AND rownum=1;
1693 		l_accum := QP_TM_RUNTIME_SOURCE.Get_numeric_attribute_value(p_list_line_id,
1694                                                                             v_list_line_no,
1695                                                                             QP_PREQ_GRP.G_ORDER_ID,
1696                                                                             v_line_id,
1697                                                                             v_price_eff_date,
1698                                                                             l_req_attrs_tbl,
1699                                                                             l_accum_rec
1700                                                                             );
1701 		EXCEPTION
1702 		WHEN OTHERS THEN
1703 		QP_PREQ_GRP.engine_debug(' in exception of QP_TM_RUNTIME_SOURCE ');
1704 		l_accum :=0;
1705 		END;
1706               ELSE
1707                 l_accum := QP_RUNTIME_SOURCE.Get_numeric_attribute_value(p_list_line_id,
1708                                                                          v_list_line_no,
1709                                                                          QP_PREQ_GRP.G_ORDER_ID,
1710                                                                          v_line_id,
1711                                                                          v_price_eff_date,
1712                                                                          l_req_attrs_tbl,
1713                                                                          l_accum_rec
1714                                                                          );
1715               END IF;
1716               IF l_debug = FND_API.G_TRUE THEN
1717                 QP_PREQ_GRP.engine_debug('   accum value returned from custom API = '|| l_accum);
1718               END IF;
1719             ELSE
1720               -- this case should almost never happen, but if it does, set accum=0
1721               IF l_debug = FND_API.G_TRUE THEN
1722                 QP_PREQ_GRP.engine_debug('***oops.  this should not be here!');
1723                 QP_PREQ_GRP.engine_debug('   Profile Value = '|| FND_PROFILE.VALUE('QP_ACCUM_ATTR_ENABLED'));
1724               END IF;
1725               l_accum := 0;
1726             END IF;
1727         END;
1728 
1729       END IF; -- if (l_accum_attrib is null)
1730     ELSE
1731       IF l_debug = FND_API.G_TRUE THEN
1732         QP_PREQ_GRP.engine_debug(' - Accumulation Profile is not enabled');
1733       END IF;
1734       l_accum := 0;
1735     END IF; -- if ACCUM_ATTR_ENABLED profile...
1736 
1737     -- save accumulation value into global variable for Process_Price_Break to use
1738     l_accum_global := l_accum;
1739 
1740     -- accumulation processing:
1741     -- if accumulation value, then remap the value_from and offset qualifier value as necessary
1742     IF l_debug = FND_API.G_TRUE THEN
1743       QP_PREQ_GRP.engine_debug(' * begin accumulation processing (if necessary) *');
1744     END IF;
1745     l_new_qualifier := l_accum + p_qualifier_value; --bug#15895472
1746 
1747     IF (p_value_to <= l_accum AND p_qualifier_value > 0) OR (p_value_to <= l_new_qualifier AND p_qualifier_value < 0) THEN --bug#15895472
1748       -- skip this break because no quantity is satisfied
1749       x_satisfied_value := 0;
1750       l_accum_global := nvl(l_accum_global, 0);
1751       IF l_debug = FND_API.G_TRUE THEN
1752         QP_PREQ_GRP.engine_debug(' - skipping this break');
1753       END IF;
1754       RETURN;
1755     ELSE
1756       IF l_accum <> 0 THEN
1757         -- remap value_from
1758 	IF p_qualifier_value > 0 THEN --bug#15895472
1759         l_value_from := greatest(l_value_from, l_accum + l_precision);
1760 	ELSE --bug#15895472
1761         l_value_from := greatest(l_value_from, l_new_qualifier + l_precision); --bug#15895472
1762 	END IF; --bug#15895472
1763       END IF;
1764       -- when l_accum=0, it means that either
1765       -- 1. no accumulation processing needed, or
1766       -- 2. accum has just started
1767       -- so no need to remap value_from
1768     END IF;
1769     -- offset qualifier value if necessary
1770    -- l_new_qualifier := l_accum + p_qualifier_value; --bug#15895472
1771     IF l_debug = FND_API.G_TRUE THEN
1772       QP_PREQ_GRP.engine_debug('   l_accum = '|| l_accum);
1773       QP_PREQ_GRP.engine_debug('   l_value_from = '|| l_value_from);
1774       QP_PREQ_GRP.engine_debug('   l_new_qualifier = '|| l_new_qualifier);
1778     -- 4999377, restrict shulin's fix to only 0-0 case
1775     END IF;
1776 
1777     -- shulin, fix bug 2372064
1779     IF (p_value_from = p_value_to AND p_value_from = 0) THEN -- for cases like 0-0, 2-2, 0.5-0.5
1780       IF l_debug = FND_API.G_TRUE THEN
1781         QP_PREQ_GRP.engine_debug('value_from is the same as value_to, x_satisfied_value is 0');
1782       END IF;
1783       x_satisfied_value := 0;
1784     ELSIF (l_new_qualifier - l_value_from + l_precision > 0) THEN
1785       x_satisfied_value := least(l_new_qualifier - l_value_from + l_precision, p_value_to - l_value_from + l_precision);
1786     ELSIF (p_qualifier_value < 0 AND l_accum - l_value_from + l_precision > 0 ) THEN  --bug#15895472
1787       x_satisfied_value := -1*(least(l_accum - l_value_from + l_precision, p_value_to - l_value_from + l_precision)); --bug#15895472
1788     ELSE
1789       x_satisfied_value := 0;
1790     END IF;
1791 
1792     IF l_debug = FND_API.G_TRUE THEN
1793       QP_PREQ_GRP.engine_debug('Out of Procedure :  Get_Satisfied_Range');
1794 
1795     END IF;
1796   END Get_Satisfied_Range;
1797 
1798 
1799   -- this procedure is used by QPXPPREB.pls to perform price_break_Calculation
1800 
1801   PROCEDURE Price_Break_Calculation(p_list_line_id NUMBER,
1802                                     p_break_type VARCHAR2,
1803                                     p_line_index NUMBER,
1804                                     p_req_value_per_unit NUMBER,  -- Item qty,group qty,group value
1805                                     p_applied_req_value_per_unit NUMBER,  -- [julin/4112395/4220399]
1806                                     p_total_value NUMBER,  -- Total value (Group amount or item amount)
1807                                     p_list_price NUMBER,
1808                                     p_line_quantity NUMBER,  -- remove default 0, Acutal quantity on order line
1809                                     p_bucketed_adjustment NUMBER,
1810                                     p_bucketed_flag VARCHAR2,
1811                                     p_automatic_flag VARCHAR2,  -- 5413797
1812                                     x_adjustment_amount OUT NOCOPY NUMBER,  --2388011_latest
1813                                     x_return_status OUT NOCOPY VARCHAR2,  --2388011_latest
1814                                     x_return_status_text OUT NOCOPY VARCHAR2) AS --2388011_latest
1815 
1816   -- 2388011_latest1
1817   CURSOR get_price_break_details IS
1818     SELECT  rltd.related_line_detail_index
1819           , rltd.list_line_id -- for accum range break
1820           , rltd.related_list_line_id
1821           , rltd.related_list_line_type
1822           , rltd.operand_calculation_code
1823           , rltd.operand
1824           , rltd.pricing_group_sequence
1825           , rltd.relationship_type_detail price_break_type
1826           , rltd.setup_value_from value_from
1827           , rltd.setup_value_to   value_to
1828           , rltd.qualifier_value
1829           , line.line_quantity ordered_qty
1830           , line.priced_quantity priced_qty
1831           , line.catchweight_qty catchweight_qty
1832           , line.actual_order_quantity actual_order_qty
1833 	  , line.PRICE_REQUEST_CODE PRICE_REQUEST_CODE   --bug#12916970
1834     FROM  qp_npreq_rltd_lines_tmp rltd, qp_npreq_lines_tmp line
1835     WHERE rltd.list_line_id = p_list_line_id
1836     AND   rltd.line_index = p_line_index
1837     AND   line.line_index = p_line_index
1838     AND   rltd.pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW
1839     AND   rltd.line_index = line.line_index -- sql repos
1840     UNION
1841     SELECT  rltd.related_line_detail_index
1842           , rltd.list_line_id -- for accum range break
1843           , rltd.related_list_line_id
1844           , rltd.related_list_line_type
1845           , rltd.operand_calculation_code
1846           , rltd.operand
1847           , rltd.pricing_group_sequence
1848           , rltd.relationship_type_detail price_break_type
1849           , rltd.setup_value_from value_from
1850           , rltd.setup_value_to   value_to
1851           , rltd.qualifier_value
1852           , line.line_quantity ordered_qty
1853           , line.priced_quantity priced_qty
1857     FROM  qp_npreq_rltd_lines_tmp rltd, qp_npreq_lines_tmp line
1854           , line.catchweight_qty catchweight_qty
1855           , line.actual_order_quantity actual_order_qty
1856 	  , line.PRICE_REQUEST_CODE PRICE_REQUEST_CODE   -- bug#12916970
1858     WHERE QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_YES
1859     AND   rltd.line_index = p_line_index
1860     AND   line_detail_index = p_list_line_id
1861     AND   line.line_index = p_line_index
1862     AND   rltd.pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW
1863     AND   rltd.line_index = line.line_index -- sql repos
1864     ORDER BY 7, 9;
1865   -- 5169222 added order by 9 to sort breaks by ascending value from
1866 
1867   pbh_child_rec get_price_break_details%ROWTYPE;
1868 
1869   cursor get_available_amount(l_PRICE_REQUEST_CODE varchar2) is   -- bug#12916970
1870   select qpltr.amount
1871   from qp_limit_transactions qpltr
1872   where qpltr.PRICE_REQUEST_CODE = l_PRICE_REQUEST_CODE;
1873 
1874 
1875   l_available_amount get_available_amount%ROWTYPE;   -- bug#12916970
1876 
1877   l_sign NUMBER;
1878   l_adjustment_amount NUMBER;
1879   l_return_status VARCHAR2(30);
1880   l_return_status_text VARCHAR2(240);
1881 
1882   TYPE pbh_adjustment_rec IS RECORD (
1883                                      l_related_list_line_id NUMBER,
1884                                      l_related_line_detail_index NUMBER,
1885                                      l_adjustment_amount NUMBER,
1886                                      l_satisfied_value NUMBER,
1887                                      l_raw_satisfied_value NUMBER); -- 5335689
1888 
1889   TYPE pbh_adjustment_tab IS TABLE OF pbh_adjustment_rec INDEX BY BINARY_INTEGER;
1890   TYPE pbh_child_tbl IS TABLE OF get_price_break_details%ROWTYPE INDEX BY BINARY_INTEGER;
1891 
1892   pbh_adjustments pbh_adjustment_tab;
1893   pbh_child_dtl_tbl pbh_child_tbl;
1894 
1895   i NUMBER := 0;
1896   l_qualifier_value NUMBER := 0;
1897   l_total_value NUMBER := 0;
1898   l_satisfied_value NUMBER;
1899   l_range_adjustment NUMBER := 0;
1900   l_ord_qty_operand NUMBER := 0;
1901   l_ord_qty_adj_amt NUMBER := 0;
1902   v_attribute_value_per_unit NUMBER := 0; --2388011_latest
1903   l_priced_quantity NUMBER := 0; -- fte breakunit
1904   l_routine VARCHAR2(50) := 'QP_Calculate_Price_PUB.Price_Break_Calculation';
1905 
1906   -- 4061138, 5183755 continuous price breaks
1907   CURSOR get_continuous_flag_cur IS
1908     SELECT nvl(qpll.continuous_price_break_flag, 'N')
1909     FROM   qp_list_lines qpll, qp_npreq_rltd_lines_tmp rltd
1910     WHERE  rltd.line_index = p_line_index
1911     AND    rltd.line_detail_index = p_list_line_id
1912     AND    rltd.pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW
1913     AND    rltd.list_line_id = qpll.list_line_id
1914     AND    ROWNUM = 1;
1915 
1916   l_continuous_flag VARCHAR2(1) := 'N';
1917   l_break_qualified VARCHAR2(1) := 'N';
1918   l_del_index_tbl QP_PREQ_GRP.NUMBER_TYPE;
1919 
1920   BEGIN
1921 
1922     x_adjustment_amount := 0;
1923     l_line_index := p_line_index; -- accum range break
1924 
1925     -- 4061138, 5183755
1926     OPEN get_continuous_flag_cur;
1927     FETCH get_continuous_flag_cur INTO l_continuous_flag;
1928     CLOSE get_continuous_flag_cur;
1929 
1930     IF l_debug = FND_API.G_TRUE THEN
1931       QP_PREQ_GRP.engine_debug('In Procedure '|| l_routine || '...');
1932       IF l_continuous_flag = 'Y' THEN
1933         QP_PREQ_GRP.engine_debug('---------- CONTINUOUS PRICE BREAK ----------');
1934       END IF;
1935       QP_PREQ_GRP.engine_debug('SL with net_amt changes.'); -- 2892848
1936       QP_PREQ_GRP.engine_debug('p_list_line_id: '|| p_list_line_id);
1937       QP_PREQ_GRP.engine_debug('p_line_index: '|| p_line_index);
1938       QP_PREQ_GRP.engine_debug('p_req_value_per_unit: '|| p_req_value_per_unit);
1939       QP_PREQ_GRP.engine_debug('p_total_value: '|| p_total_value);
1940       QP_PREQ_GRP.engine_debug('p_list_price: '|| p_list_price); -- 2892848
1941       QP_PREQ_GRP.engine_debug('p_line_quantity: '|| p_line_quantity);
1942       QP_PREQ_GRP.engine_debug('p_bucketed_adjustment: '|| p_bucketed_adjustment);
1943       QP_PREQ_GRP.engine_debug('p_bucketed_flag: '|| p_bucketed_flag);
1944     END IF;
1945 
1946     OPEN get_price_break_details;
1947 
1948     LOOP
1949       i := i + 1;
1950 
1951       FETCH get_price_break_details INTO pbh_child_rec;
1952       EXIT WHEN get_price_break_details%NOTFOUND;
1953 
1954       IF (p_bucketed_flag = 'Y') THEN
1955         --pbh_child_rec.qualifier_value := p_total_value + nvl(p_bucketed_adjustment*p_line_quantity,0);
1956         pbh_child_rec.qualifier_value := p_bucketed_adjustment; -- 2892848
1957       ELSE
1958         IF (p_total_value <> 0) THEN -- ravi_new --bug#15895472
1959           pbh_child_rec.qualifier_value := p_total_value;
1960         ELSE
1961 	   --bug#12916970
1962 	   QP_PREQ_GRP.engine_debug('PRICE_REQUEST_CODE-DK-'||pbh_child_rec.PRICE_REQUEST_CODE);
1966 	    if get_available_amount%notfound then
1963 	    open get_available_amount(pbh_child_rec.PRICE_REQUEST_CODE);
1964 	    fetch get_available_amount into l_available_amount;
1965 	    QP_PREQ_GRP.engine_debug('l_available_amount.amount-DK-'||l_available_amount.amount);
1967 	      pbh_child_rec.qualifier_value := p_req_value_per_unit;
1968 	    else
1969 	      pbh_child_rec.qualifier_value := nvl(l_available_amount.amount,p_req_value_per_unit);
1970 	    end if;
1971 	    close get_available_amount;
1972 	    --bug#12916970
1973         END IF;
1974       END IF;
1975 
1976       IF l_debug = FND_API.G_TRUE THEN
1977         QP_PREQ_GRP.engine_debug('PBH Qualifier Value : ' || pbh_child_rec.qualifier_value);
1978         QP_PREQ_GRP.engine_debug('PBH Value From : ' || pbh_child_rec.value_from);
1979         QP_PREQ_GRP.engine_debug('PBH Value To : ' || pbh_child_rec.value_to);
1980         QP_PREQ_GRP.engine_debug('PBH Break Type : ' || p_break_type);
1981       END IF;
1982 
1983       IF (p_break_type = QP_PREQ_GRP.G_POINT_BREAK) THEN
1984         IF l_debug = FND_API.G_TRUE THEN
1985           QP_PREQ_GRP.engine_debug('i am in POINT block...');
1986           QP_PREQ_GRP.engine_debug('Before PBH List Line Type : ' || pbh_child_rec.related_list_line_type);
1987         END IF;
1988 
1989         -- rewritten for 4061138
1990         IF ((l_continuous_flag <> 'Y' AND
1991              pbh_child_rec.qualifier_value BETWEEN pbh_child_rec.value_from AND pbh_child_rec.value_to)
1992             OR
1993             (l_continuous_flag = 'Y' AND
1994              pbh_child_rec.value_from < pbh_child_rec.qualifier_value AND
1995              pbh_child_rec.qualifier_value <= pbh_child_rec.value_to)
1996             )
1997           THEN
1998 
1999           l_break_qualified := 'Y'; --[julin/4671446]
2000 
2001           IF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
2002             l_sign := 1;
2003           ELSIF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
2004             l_sign :=  - 1;
2005           END IF;
2006 
2007           IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT) THEN
2008             l_sign := 1; -- new price discount/surcharge are the same
2009           END IF;
2010 
2011           IF l_debug = FND_API.G_TRUE THEN
2012             QP_PREQ_GRP.engine_debug('l sign: '|| l_sign);
2013           END IF;
2014           -- fte breakunit
2015           IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_BREAKUNIT_PRICE AND
2016               p_total_value <> 0) --bug#15895472
2017             THEN
2018             IF l_debug = FND_API.G_TRUE THEN
2019               QP_PREQ_GRP.engine_debug('fte breakunit price, using p_total_value = '|| p_total_value);
2020             END IF;
2021             l_priced_quantity := p_total_value;
2022           ELSIF (p_applied_req_value_per_unit > 0) THEN -- [julin/4112395/4220399]
2023             l_priced_quantity := p_applied_req_value_per_unit;
2024           ELSE
2025             l_priced_quantity := p_req_value_per_unit;
2026           END IF;
2027 
2028           IF l_debug = FND_API.G_TRUE THEN
2029             QP_PREQ_GRP.engine_debug('l_priced_quantity '|| l_priced_quantity);
2030           END IF; --l_debug
2031 
2032           --4900095 lumpsum
2033           IF pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_LUMPSUM_DISCOUNT
2034             AND QP_PREQ_GRP.G_service_line_ind_tbl.EXISTS(p_line_index) THEN
2035             IF QP_PREQ_PUB.G_PBH_MOD_LEVEL_CODE.EXISTS(p_list_line_id)
2036               AND QP_PREQ_PUB.G_PBH_MOD_LEVEL_CODE(p_list_line_id) = 'LINE' THEN
2037               l_priced_quantity := nvl(p_applied_req_value_per_unit,
2038                                        QP_PREQ_GRP.G_service_line_qty_tbl(p_line_index));
2039               IF l_debug = FND_API.G_TRUE THEN
2040                 QP_PREQ_GRP.engine_debug('service line pbh with line level');
2041               END IF; --l_debug
2042               --p_request_qty * l_parent_qty;
2043             ELSIF QP_PREQ_PUB.G_PBH_MOD_LEVEL_CODE.EXISTS(p_list_line_id)
2044               AND QP_PREQ_PUB.G_PBH_MOD_LEVEL_CODE(p_list_line_id) = 'LINEGROUP' THEN
2045               l_priced_quantity := nvl(p_applied_req_value_per_unit,
2046                                        QP_PREQ_GRP.G_service_ldet_qty_tbl(p_list_line_id));
2047               IF l_debug = FND_API.G_TRUE THEN
2048                 QP_PREQ_GRP.engine_debug('service line pbh with linegrp level');
2049               END IF; --l_debug
2050             ELSE
2051               l_priced_quantity := nvl(p_applied_req_value_per_unit, p_req_value_per_unit);
2052               IF l_debug = FND_API.G_TRUE THEN
2053                 QP_PREQ_GRP.engine_debug('non-service line pbh with linegrp level');
2054               END IF; --l_debug
2055             END IF; --QP_PREQ_GRP.G_service_line_ind_tbl.exists
2056 
2057             IF l_debug = FND_API.G_TRUE THEN
2058               QP_PREQ_GRP.engine_debug('lumpsum qty '|| l_priced_quantity);
2059             END IF; --l_debug
2060           END IF; --pbh_child_rec.operand_calculation_code
2061 
2062           Calculate_Adjustment(p_list_price,
2063                                pbh_child_rec.operand_calculation_code,
2064                                pbh_child_rec.operand * l_sign,
2065                                --pbh_child_rec.qualifier_value ,
2066                                --p_req_value_per_unit, -- ravi_new
2067                                l_priced_quantity,  -- fte breakunit
2068                                l_adjustment_amount,
2069                                l_return_status,
2070                                l_return_status_text);
2071 
2072           IF l_debug = FND_API.G_TRUE THEN
2073             QP_PREQ_GRP.engine_debug('PBH Adjustment : ' || l_adjustment_amount);
2074           END IF;
2075 
2079           IF (p_bucketed_flag = 'Y') THEN
2076           pbh_adjustments(i).l_adjustment_amount := l_adjustment_amount;
2077 
2078           -- begin 2892848
2080             pbh_adjustments(i).l_satisfied_value := pbh_child_rec.qualifier_value;
2081             IF l_debug = FND_API.G_TRUE THEN
2082               QP_PREQ_GRP.engine_debug('POINT net amount break l_satisfied_value: '|| pbh_adjustments(i).l_satisfied_value);
2083             END IF; -- END IF l_debug
2084           ELSE -- end 2892848
2085 
2086             -- ravi_new
2087             IF (p_total_value <> 0 AND p_req_value_per_unit <> 0) THEN --6896139 added to avoid divide by zero error --bug#15895472
2088               v_attribute_value_per_unit := p_total_value / p_req_value_per_unit; --2388011_latest
2089               -- bug 3603096 - commented if..else
2090               --IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_BREAKUNIT_PRICE) THEN
2091               pbh_adjustments(i).l_satisfied_value := pbh_child_rec.qualifier_value; -- fte breakunit
2092               --ELSE
2093               -- pbh_adjustments(i).l_satisfied_value := pbh_child_rec.qualifier_value/v_attribute_value_per_unit; --2388011_latest
2094               --END IF;
2095               IF l_debug = FND_API.G_TRUE THEN
2096                 QP_PREQ_GRP.engine_debug('p_total_value > 0');
2097                 QP_PREQ_GRP.engine_debug('v_attribute_value_per_unit (p_total_value/p_req_value_per_unit): ' || v_attribute_value_per_unit);
2098                 QP_PREQ_GRP.engine_debug('l_satisfied_value (qualifier_value/v_attribute_value_per_unit): '|| pbh_adjustments(i).l_satisfied_value);
2099               END IF; -- END IF l_debug
2100             ELSE
2101               pbh_adjustments(i).l_satisfied_value := pbh_child_rec.qualifier_value;
2102               IF l_debug = FND_API.G_TRUE THEN
2103                 QP_PREQ_GRP.engine_debug('POINT break l_satisfied_value: '|| pbh_adjustments(i).l_satisfied_value);
2104               END IF; -- END IF l_debug
2105             END IF; -- END IF (p_total_value > 0)
2106           END IF; -- END IF (p_bucketed_flag = 'Y') 2892848
2107 
2108           x_adjustment_amount := l_adjustment_amount;
2109           IF l_debug = FND_API.G_TRUE THEN
2110             QP_PREQ_GRP.engine_debug('POINT break x_adjustment_amount: '|| x_adjustment_amount);
2111           END IF; -- END IF l_debug
2112           -- fte breakunit
2113           -- Normally, point breaks assume the adj amt on the header is the same as
2114           -- the single qualifying child line.  This is true for regular breaks, but
2115           -- for block pricing (breakunit), the header and line quantity may not be
2116           -- the same UOM, so need to calculate a different adj amt for the PBH.
2117           IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_BREAKUNIT_PRICE AND
2118               p_total_value <> 0) --bug#15895472
2119             THEN
2123             END IF;
2120             x_adjustment_amount := l_adjustment_amount * l_priced_quantity / p_req_value_per_unit;
2121             IF l_debug = FND_API.G_TRUE THEN
2122               QP_PREQ_GRP.engine_debug('fte breakunit, PBH x_adjustment_amount: '|| x_adjustment_amount);
2124           END IF;
2125         ELSE
2126           pbh_adjustments(i).l_adjustment_amount := NULL;
2127           pbh_adjustments(i).l_satisfied_value := 0;
2128         END IF;
2129 
2130         pbh_adjustments(i).l_related_list_line_id := pbh_child_rec.related_list_line_id;
2131         pbh_adjustments(i).l_related_line_detail_index := pbh_child_rec.related_line_detail_index;
2132         pbh_child_dtl_tbl(i) := pbh_child_rec;
2133 
2134       ELSIF (p_break_type = QP_PREQ_GRP.G_RANGE_BREAK) THEN
2135 
2136         IF l_debug = FND_API.G_TRUE THEN
2137           QP_PREQ_GRP.engine_debug('i am in RANGE block...');
2138         END IF; -- END IF l_debug
2139 
2140         IF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
2141           l_sign := 1;
2142         ELSIF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
2143           l_sign :=  - 1;
2144         END IF;
2145 
2146         IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT) THEN
2147           l_sign := 1; -- new price discount/surcharge are the same
2148         END IF;
2149 
2150         IF l_debug = FND_API.G_TRUE THEN
2151           QP_PREQ_GRP.engine_debug('l sign: '|| l_sign);
2152         END IF; -- END IF l_debug
2153 
2154         IF l_debug = FND_API.G_TRUE THEN
2155           QP_PREQ_GRP.engine_debug('l_total_value now: '|| l_total_value || ' is used to get_satisfied_range.');
2156         END IF; -- END IF l_debug
2157 
2158         Get_Satisfied_Range(pbh_child_rec.value_from, pbh_child_rec.value_to, pbh_child_rec.qualifier_value,
2159                             pbh_child_rec.list_line_id, l_continuous_flag, 'N', l_satisfied_value);
2160 
2161         IF l_debug = FND_API.G_TRUE THEN
2162           QP_PREQ_GRP.engine_debug('l_satisfied_range from Get_Satisfied_Range: '|| l_satisfied_value);
2163         END IF; -- END IF l_debug
2164         pbh_adjustments(i).l_raw_satisfied_value := l_satisfied_value; -- 5335689
2165         IF (pbh_child_rec.qualifier_value > 0 AND l_satisfied_value > 0) OR (pbh_child_rec.qualifier_value < 0 AND l_satisfied_value < 0)THEN --bug#15895472
2166           l_break_qualified := 'Y'; --[julin/4671446]
2167         END IF;
2168 
2169         IF (p_bucketed_flag = 'Y') THEN
2170           pbh_adjustments(i).l_satisfied_value := l_satisfied_value / p_list_price; -- this is the p_price_qty for Calculate_Adjustment
2171         ELSE
2172           -- ravi_new
2173           IF (p_total_value <> 0) THEN --bug#15895472
2174             v_attribute_value_per_unit := p_total_value / p_req_value_per_unit; --2388011_latest
2175             --pbh_adjustments(i).l_satisfied_value  := pbh_child_rec.qualifier_value/v_attribute_value_per_unit; --2388011_latest
2176             pbh_adjustments(i).l_satisfied_value := l_satisfied_value / v_attribute_value_per_unit; -- SHU diff RAVI
2177             IF l_debug = FND_API.G_TRUE THEN
2178               QP_PREQ_GRP.engine_debug('p_total_value >= 0');
2179               QP_PREQ_GRP.engine_debug('v_attribute_value_per_unit (p_total_value/p_req_value_per_unit): ' || v_attribute_value_per_unit);
2180               QP_PREQ_GRP.engine_debug('l_raw_satisfied_value: ' || pbh_adjustments(i).l_raw_satisfied_value);
2181               QP_PREQ_GRP.engine_debug('l_satisfied_value assigned back to this child break: '|| pbh_adjustments(i).l_satisfied_value);
2182             END IF; -- END IF l_debug
2183           ELSE
2184             pbh_adjustments(i).l_satisfied_value := l_satisfied_value;
2185             IF l_debug = FND_API.G_TRUE THEN
2186               QP_PREQ_GRP.engine_debug('l_satisfied_value assigned back to this child break: '|| pbh_adjustments(i).l_satisfied_value);
2187             END IF; -- END IF l_debug
2188           END IF; -- END IF (p_total_value > 0)
2189         END IF; -- END IF (p_bucketed_flag = 'Y') THEN
2190 
2191         --If operator is lumpsum and l_satisfied_value is zero do not calculate
2192         IF l_satisfied_value = 0 THEN
2193           l_adjustment_amount := NULL;
2194         ELSE
2195           Calculate_Adjustment(p_list_price,
2196                                pbh_child_rec.operand_calculation_code,
2197                                pbh_child_rec.operand * l_sign,
2198                                pbh_adjustments(i).l_satisfied_value,  -- SL, p_priced_qty
2199                                l_adjustment_amount,
2200                                l_return_status,
2201                                l_return_status_text);
2202         END IF;
2203 
2204         pbh_adjustments(i).l_related_list_line_id := pbh_child_rec.related_list_line_id;
2205         pbh_adjustments(i).l_related_line_detail_index := pbh_child_rec.related_line_detail_index;
2206         pbh_adjustments(i).l_adjustment_amount := l_adjustment_amount;
2207         pbh_child_dtl_tbl(i) := pbh_child_rec;
2208 
2209         IF l_debug = FND_API.G_TRUE THEN
2210           QP_PREQ_GRP.engine_debug('Adjustment : (' || i || ') ' || l_adjustment_amount);
2211           QP_PREQ_GRP.engine_debug('Satisfied Value : (' || i || ') ' || l_satisfied_value);
2212           QP_PREQ_GRP.engine_debug('Total Value for next child line: (' || i || ') ' || l_total_value);
2213         END IF; -- END IF l_debug
2214 
2215       END IF; -- END IF (p_break_type = POINT or RANGE
2216 
2217     END LOOP;
2218 
2219     CLOSE get_price_break_details;
2220 
2224 
2221 -- IF (p_break_type = QP_PREQ_GRP.G_RANGE_BREAK) THEN   --bug#12916970
2222       FOR i IN 1 .. pbh_adjustments.COUNT
2223         LOOP
2225         l_range_adjustment := l_range_adjustment + nvl(pbh_adjustments(i).l_adjustment_amount *
2226                                                        pbh_adjustments(i).l_satisfied_value, 0);
2227 
2228         IF l_debug = FND_API.G_TRUE THEN
2229           QP_PREQ_GRP.engine_debug('--- '||'break child '|| i ||' ---');
2230           QP_PREQ_GRP.engine_debug('l_adjustment_amount: '|| pbh_adjustments(i).l_adjustment_amount);
2231           QP_PREQ_GRP.engine_debug('l_satisfied_value: '|| nvl(pbh_adjustments(i).l_raw_satisfied_value,
2232                                                                pbh_adjustments(i).l_satisfied_value));
2233           QP_PREQ_GRP.engine_debug('l_range_adjustment total: '|| l_range_adjustment);
2234         END IF; -- END IF l_debug
2235       END LOOP;
2236 --      x_adjustment_amount := l_range_adjustment / p_req_value_per_unit; -- ravi_new
2237 --bug#13776174
2238       IF (p_total_value > 0 ) AND (p_break_type = QP_PREQ_GRP.G_POINT_BREAK) THEN
2239       x_adjustment_amount := l_range_adjustment / p_total_value; -- ravi_new
2240       ELSE
2241       x_adjustment_amount := l_range_adjustment / p_req_value_per_unit;
2242       END IF;
2243 --bug#13776174
2244       IF l_debug = FND_API.G_TRUE THEN
2245         QP_PREQ_GRP.engine_debug('Range Break Averaged Adjustment : ' || x_adjustment_amount);
2246       END IF; -- END IF l_debug
2247 
2248 -- END IF;  --bug#12916970
2249 
2250     -- Update the adjustments/satisfied ranges info on line details
2251     IF (QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_YES) THEN
2252       IF (pbh_adjustments.COUNT > 0) THEN
2253         IF l_debug = FND_API.G_TRUE THEN
2254           QP_PREQ_GRP.engine_debug('updating child pbh lines '|| pbh_adjustments.COUNT);
2255           QP_PREQ_GRP.engine_debug('l_break_qualified=' || l_break_qualified);
2256         END IF; -- END IF l_debug
2257         IF l_break_qualified = 'Y' THEN
2258           FOR i IN pbh_adjustments.FIRST .. pbh_adjustments.LAST LOOP
2259             l_ord_qty_operand := 0;
2260             l_ord_qty_adj_amt := 0;
2261 
2262             BEGIN
2263               QP_PREQ_PUB.GET_ORDERQTY_VALUES(p_ordered_qty =>
2264                                               pbh_child_dtl_tbl(i).ordered_qty,
2265                                               p_priced_qty =>
2266                                               pbh_child_dtl_tbl(i).priced_qty,
2267                                               p_catchweight_qty =>
2268                                               pbh_child_dtl_tbl(i).catchweight_qty,
2269                                               p_actual_order_qty =>
2270                                               pbh_child_dtl_tbl(i).actual_order_qty,
2271                                               p_operand => pbh_child_dtl_tbl(i).operand,
2272                                               p_adjustment_amt =>
2273                                               pbh_adjustments(i).l_adjustment_amount,
2274                                               p_operand_calculation_code =>
2275                                               pbh_child_dtl_tbl(i).operand_calculation_code,
2276                                               p_input_type => 'OPERAND',
2280                                               x_return_status_text => x_return_status_text);
2277                                               x_ordqty_output1 => l_ord_qty_operand,
2278                                               x_ordqty_output2 => l_ord_qty_adj_amt,
2279                                               x_return_status => x_return_status,
2281             EXCEPTION
2282               WHEN OTHERS THEN
2283                 NULL;
2284             END;
2285             IF l_debug = FND_API.G_TRUE THEN
2286               QP_PREQ_GRP.engine_debug('child dtl adj amt '
2287                                        || pbh_adjustments(i).l_adjustment_amount
2288                                        ||' l_satisfied_value '|| pbh_adjustments(i).l_satisfied_value
2289                                        ||' ordqtyadjamt '|| l_ord_qty_adj_amt
2290                                        ||' order_qty_operand '|| l_ord_qty_operand
2291                                        ||' dtl index '|| pbh_adjustments(i).l_related_line_detail_index);
2292             END IF; -- END IF l_debug
2293 
2294             UPDATE qp_npreq_ldets_tmp
2295                  --changes for bug 2264566 update adjamt on child lines of manualpbh
2296             SET adjustment_amount =  - (pbh_adjustments(i).l_adjustment_amount),
2297             --SET adjustment_amount  = l_sign * pbh_adjustments(i).l_adjustment_amount,
2298                 line_quantity = nvl(pbh_adjustments(i).l_raw_satisfied_value,  -- 5335689
2299                                     pbh_adjustments(i).l_satisfied_value)
2300                 , order_qty_adj_amt =  - (l_ord_qty_adj_amt) -- bug 3285662
2301                 , order_qty_operand = l_ord_qty_operand
2302             WHERE line_detail_index = pbh_adjustments(i).l_related_line_detail_index
2303             AND   pricing_status_code IN (QP_PREQ_GRP.G_STATUS_NEW,
2304                                           --changes for bug 2264566 update adjamt on child lines of manualpbh
2305                                           QP_PREQ_GRP.G_STATUS_UNCHANGED);
2306           END LOOP;
2307         ELSE
2308           IF p_automatic_flag <> QP_PREQ_PUB.G_NO THEN -- 5413797
2309             l_del_index_tbl(1) := p_list_line_id;
2310             QP_Resolve_Incompatability_PVT.Delete_Ldets_Complete(
2311                                                                  l_del_index_tbl, 'No breaks qualified', x_return_status, x_return_status_text);
2312           END IF;
2313         END IF;
2314       END IF;
2315     END IF;
2316 
2317 
2318   EXCEPTION
2319     WHEN OTHERS THEN
2320       IF l_debug = FND_API.G_TRUE THEN
2321         QP_PREQ_GRP.ENGINE_DEBUG('Error in price break calculation: '|| SQLERRM);
2322       END IF; -- END IF l_debug
2323       x_return_status := FND_API.G_RET_STS_ERROR;
2324       x_return_status_text := l_routine ||' '|| SQLERRM;
2325   END Price_Break_Calculation;
2326 
2327   PROCEDURE Price_Break_Calculation(p_list_line_id NUMBER,
2328                                     p_break_type VARCHAR2,
2329                                     p_line_index NUMBER,
2330                                     p_request_qty NUMBER,
2331                                     p_list_price NUMBER,
2332                                     x_adjustment_amount OUT NOCOPY NUMBER,
2333                                     x_return_status OUT NOCOPY VARCHAR2,
2334                                     x_return_status_text OUT NOCOPY VARCHAR2) AS
2335 
2336   CURSOR get_price_break_details IS
2337     SELECT  related_line_detail_index
2338           , related_list_line_id
2339           , related_list_line_type
2340           , list_line_id -- for accum range break
2341           , operand_calculation_code
2342           , operand
2343           , pricing_group_sequence
2344           , relationship_type_detail price_break_type
2345           , setup_value_from value_from
2346           , setup_value_to   value_to
2347           , qualifier_value
2348     FROM  qp_npreq_rltd_lines_tmp
2349     WHERE QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_NO
2350     AND list_line_id = p_list_line_id
2351     AND   line_index = p_line_index
2352     AND   pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW
2353     --fix for bug 2515762 added the union clause to distinguish between
2354     --the passed-in rltd lines of PBH modifier versus the engine-inserted
2355     --when called from public API
2356     --made corresponding changes in the public API to pass the dtl_index
2357     UNION
2358     SELECT  related_line_detail_index
2359           , related_list_line_id
2360           , related_list_line_type
2361           , list_line_id -- for accum range break
2362           , operand_calculation_code
2363           , operand
2364           , pricing_group_sequence
2365           , relationship_type_detail price_break_type
2366           , setup_value_from value_from
2367           , setup_value_to   value_to
2368           , qualifier_value
2369     FROM  qp_npreq_rltd_lines_tmp
2370     WHERE QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_YES
2371     AND   line_index = p_line_index
2372     AND line_detail_index = p_list_line_id
2373     AND   pricing_status_code = QP_PREQ_GRP.G_STATUS_NEW
2374     ORDER BY 7 ;
2375 
2376   pbh_child_rec get_price_break_details%ROWTYPE;
2377 
2378   l_sign NUMBER;
2379   l_adjustment_amount NUMBER;
2380   l_return_status VARCHAR2(30);
2381   l_return_status_text VARCHAR2(240);
2382 
2383   TYPE pbh_adjustment_rec IS RECORD (
2384                                      l_related_list_line_id NUMBER,
2385                                      l_related_line_detail_index NUMBER,
2386                                      l_adjustment_amount NUMBER,
2387                                      l_satisfied_value NUMBER);
2388 
2389   TYPE pbh_adjustment_tab IS TABLE OF pbh_adjustment_rec INDEX BY BINARY_INTEGER;
2390 
2394   l_qualifier_value NUMBER := 0;
2391   pbh_adjustments pbh_adjustment_tab;
2392 
2393   i NUMBER := 0;
2395   l_total_value NUMBER;
2396   l_satisfied_value NUMBER;
2397   l_range_adjustment NUMBER := 0;
2398   l_routine VARCHAR2(50) := 'QP_Calculate_Price_PUB.Price_Break_Calculation';
2399 
2400   -- 4061138, 5183755 continuous price breaks
2401   CURSOR get_continuous_flag_cur IS
2402     SELECT nvl(continuous_price_break_flag, 'N')
2403     FROM   qp_list_lines
2404     WHERE  QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_NO
2405     AND    list_line_id = p_list_line_id
2406     AND    ROWNUM = 1
2407     UNION
2408     SELECT nvl(qpll.continuous_price_break_flag, 'N')
2409     FROM   qp_list_lines qpll, qp_npreq_rltd_lines_tmp rltd
2410     WHERE  QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_YES
2411     AND    rltd.line_index = p_line_index
2412     AND    rltd.line_detail_index = p_list_line_id
2413     AND    rltd.list_line_id = qpll.list_line_id
2414     AND    ROWNUM = 1;
2415 
2416   l_continuous_flag VARCHAR2(1) := 'N';
2417 
2418   BEGIN
2419 
2420     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
2421     IF l_debug = FND_API.G_TRUE THEN
2422       QP_PREQ_GRP.engine_debug('#90 p_id '|| p_list_line_id ||' pub_api_call_flg '
2423                                || QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG);
2424     END IF;
2425     x_adjustment_amount := 0;
2426     l_line_index := p_line_index; -- accum range break
2427     IF l_debug = FND_API.G_TRUE THEN
2428       QP_PREQ_GRP.engine_debug('#100');
2429 
2430     END IF;
2431 
2432     -- 4061138, 5183755
2433     OPEN get_continuous_flag_cur;
2434     FETCH get_continuous_flag_cur INTO l_continuous_flag;
2435     CLOSE get_continuous_flag_cur;
2436 
2437     OPEN get_price_break_details;
2438 
2439     IF l_debug = FND_API.G_TRUE THEN
2440       QP_PREQ_GRP.engine_debug('#101');
2441 
2442     END IF;
2443     LOOP
2444 
2445       IF l_debug = FND_API.G_TRUE THEN
2446         QP_PREQ_GRP.engine_debug('#102');
2447       END IF;
2448 
2449       i := i + 1;
2450 
2451       FETCH get_price_break_details INTO pbh_child_rec;
2452       EXIT WHEN get_price_break_details%NOTFOUND;
2453 
2454       IF (QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_YES) THEN
2455         pbh_child_rec.qualifier_value := p_request_qty;
2456       END IF;
2457 
2458       IF l_debug = FND_API.G_TRUE THEN
2459         QP_PREQ_GRP.engine_debug('PBH Qualifier Value : ' || pbh_child_rec.qualifier_value);
2460         QP_PREQ_GRP.engine_debug('PBH Value From : ' || pbh_child_rec.value_from);
2461         QP_PREQ_GRP.engine_debug('PBH Value To : ' || pbh_child_rec.value_to);
2462         QP_PREQ_GRP.engine_debug('PBH Break Type : ' || p_break_type);
2463 
2464       END IF;
2465 
2466       IF (p_break_type = QP_PREQ_GRP.G_POINT_BREAK) THEN
2467 
2468         IF l_debug = FND_API.G_TRUE THEN
2469           QP_PREQ_GRP.engine_debug('Before PBH List Line Type : ' || pbh_child_rec.related_list_line_type);
2470         END IF;
2471         -- rewritten for 4061138
2472         IF ((l_continuous_flag <> 'Y' AND
2473              pbh_child_rec.qualifier_value BETWEEN pbh_child_rec.value_from AND pbh_child_rec.value_to)
2474             OR
2475             (l_continuous_flag = 'Y' AND
2476              pbh_child_rec.value_from < pbh_child_rec.qualifier_value AND
2477              pbh_child_rec.qualifier_value <= pbh_child_rec.value_to) )
2478           THEN
2479           IF l_debug = FND_API.G_TRUE THEN
2480             QP_PREQ_GRP.engine_debug('In PBH List Line Type : ' || pbh_child_rec.related_list_line_type);
2481 
2482           END IF;
2483           IF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
2484             l_sign := 1;
2485           ELSIF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
2486             l_sign :=  - 1;
2487           END IF;
2488 
2489           IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT) THEN
2490             l_sign := 1; -- new price discount/surcharge are the same
2491           END IF;
2492           IF l_debug = FND_API.G_TRUE THEN
2493             QP_PREQ_GRP.engine_debug('l sign: '|| l_sign);
2494 
2495           END IF;
2496           Calculate_Adjustment(p_list_price,
2497                                pbh_child_rec.operand_calculation_code,
2498                                pbh_child_rec.operand * l_sign,
2499                                p_request_qty,
2500                                l_adjustment_amount,
2501                                l_return_status,
2502                                l_return_status_text);
2503 
2504           IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2505             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2506           END IF;
2507           IF l_debug = FND_API.G_TRUE THEN
2508             QP_PREQ_GRP.engine_debug('PBH Adjustment : ' || l_adjustment_amount);
2509 
2510           END IF;
2511           pbh_adjustments(i).l_adjustment_amount := l_adjustment_amount;
2512           pbh_adjustments(i).l_satisfied_value := pbh_child_rec.qualifier_value;
2513 
2514           x_adjustment_amount := l_adjustment_amount;
2515         ELSE
2516           pbh_adjustments(i).l_adjustment_amount := NULL;
2517           pbh_adjustments(i).l_satisfied_value := 0;
2518         END IF;
2519 
2520         pbh_adjustments(i).l_related_list_line_id := pbh_child_rec.related_list_line_id;
2524 
2521         pbh_adjustments(i).l_related_line_detail_index := pbh_child_rec.related_line_detail_index;
2522 
2523       ELSIF (p_break_type = QP_PREQ_GRP.G_RANGE_BREAK) THEN
2525         IF (l_qualifier_value = 0) THEN
2526           IF l_debug = FND_API.G_TRUE THEN
2527             QP_PREQ_GRP.engine_debug('Range Break');
2528           END IF;
2529           l_qualifier_value := pbh_child_rec.qualifier_value;
2530           l_total_value := pbh_child_rec.qualifier_value;
2531         END IF;
2532 
2533         IF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_DISCOUNT) THEN
2534           l_sign := 1;
2535         ELSIF (pbh_child_rec.related_list_line_type = QP_PREQ_GRP.G_SURCHARGE) THEN
2536           l_sign :=  - 1;
2537         END IF;
2538 
2539         IF (pbh_child_rec.operand_calculation_code = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT) THEN
2540           l_sign := 1; -- new price discount/surcharge are the same
2541         END IF;
2542         IF l_debug = FND_API.G_TRUE THEN
2543           QP_PREQ_GRP.engine_debug('l sign: '|| l_sign);
2544 
2545         END IF;
2546         -- 3943868: was passing p_list_line_id instead of pbh_child_rec.list_line_id
2547         Get_Satisfied_Range(pbh_child_rec.value_from, pbh_child_rec.value_to,
2548                             l_total_value, pbh_child_rec.list_line_id, l_continuous_flag, 'N', l_satisfied_value);
2549         pbh_adjustments(i).l_satisfied_value := l_satisfied_value;
2550 
2551         --If operator is lumpsum and l_satisfied_value is zero do not calculate
2552         IF l_satisfied_value = 0
2553           THEN
2554           l_adjustment_amount := NULL;
2555         ELSE
2556           Calculate_Adjustment(p_list_price,
2557                                pbh_child_rec.operand_calculation_code,
2558                                pbh_child_rec.operand * l_sign,
2559                                pbh_adjustments(i).l_satisfied_value,
2560                                --l_total_value,
2561                                l_adjustment_amount,
2562                                l_return_status,
2563                                l_return_status_text);
2564           IF l_return_status = FND_API.G_RET_STS_ERROR THEN
2565             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2566           END IF;
2567         END IF;
2568 
2569         pbh_adjustments(i).l_related_list_line_id := pbh_child_rec.related_list_line_id;
2570         pbh_adjustments(i).l_related_line_detail_index := pbh_child_rec.related_line_detail_index;
2571         pbh_adjustments(i).l_adjustment_amount := l_adjustment_amount;
2572 
2573         --IF (l_total_value > 0) THEN
2574         --l_total_value := l_total_value - l_satisfied_value;  -- this is correct to be commented out
2575 
2576         IF l_debug = FND_API.G_TRUE THEN
2577           QP_PREQ_GRP.engine_debug('Adjustment : (' || i || ') ' || l_adjustment_amount);
2578           QP_PREQ_GRP.engine_debug('Satisfied Value : (' || i || ') ' || l_satisfied_value);
2579           QP_PREQ_GRP.engine_debug('Total Value : (' || i || ') ' || l_total_value);
2580         END IF;
2581         --ELSE
2582         -- pbh_adjustments(i).l_satisfied_value  := 0;
2583         --END IF;
2584 
2585       END IF;
2586 
2587     END LOOP;
2588 
2589     CLOSE get_price_break_details;
2590 
2591     IF (p_break_type = QP_PREQ_GRP.G_RANGE_BREAK) THEN
2592       FOR i IN 1 .. pbh_adjustments.COUNT
2593         LOOP
2594         l_range_adjustment := l_range_adjustment + nvl(pbh_adjustments(i).l_adjustment_amount * pbh_adjustments(i).l_satisfied_value, 0);
2595       END LOOP;
2596       x_adjustment_amount := l_range_adjustment / l_qualifier_value;
2597 
2598       IF l_debug = FND_API.G_TRUE THEN
2599         QP_PREQ_GRP.engine_debug('Averaged Adjustment : ' || x_adjustment_amount);
2600 
2601       END IF;
2602     END IF;
2603 
2604     -- Update the adjustments/satisfied ranges info on line details
2605     IF (QP_PREQ_GRP.G_PUBLIC_API_CALL_FLAG = QP_PREQ_GRP.G_YES) THEN
2606       IF (pbh_adjustments.COUNT > 0) THEN
2607         IF l_debug = FND_API.G_TRUE THEN
2608           QP_PREQ_GRP.engine_debug('updating child pbh lines '
2609                                    || pbh_adjustments.COUNT);
2610         END IF;
2611         FOR i IN pbh_adjustments.FIRST .. pbh_adjustments.LAST LOOP
2612           IF l_debug = FND_API.G_TRUE THEN
2613             QP_PREQ_GRP.engine_debug('child dtl adj amt '
2614                                      || pbh_adjustments(i).l_adjustment_amount
2615                                      ||' qty '|| pbh_adjustments(i).l_satisfied_value
2616                                      ||' dtl index '|| pbh_adjustments(i).l_related_line_detail_index);
2617           END IF;
2618           UPDATE qp_npreq_ldets_tmp
2619                --changes for bug 2264566 update adjamt on child lines of manualpbh
2620           SET adjustment_amount =  - (pbh_adjustments(i).l_adjustment_amount),
2621           --SET adjustment_amount  = l_sign * pbh_adjustments(i).l_adjustment_amount,
2622               line_quantity = pbh_adjustments(i).l_satisfied_value
2623           WHERE line_detail_index = pbh_adjustments(i).l_related_line_detail_index
2624           AND   pricing_status_code IN (QP_PREQ_GRP.G_STATUS_NEW,
2625                                         --changes for bug 2264566 update adjamt on child lines of manualpbh
2626                                         QP_PREQ_GRP.G_STATUS_UNCHANGED);
2627         END LOOP;
2628       END IF;
2629     END IF;
2630 
2631 
2632   EXCEPTION
2633     WHEN OTHERS THEN
2634       IF l_debug = FND_API.G_TRUE THEN
2635         QP_PREQ_GRP.ENGINE_DEBUG('Error in price break calculation: '|| SQLERRM);
2636       END IF;
2637       x_return_status := FND_API.G_RET_STS_ERROR;
2638       x_return_status_text := l_routine ||' '|| SQLERRM;
2642                                    p_line_index NUMBER,
2639   END Price_Break_Calculation;
2640 
2641   PROCEDURE GSA_Max_Discount_Check(p_adjusted_unit_price NUMBER,
2643                                    p_pricing_date DATE,
2644                                    x_return_status OUT NOCOPY VARCHAR2,
2645                                    x_return_status_txt OUT NOCOPY VARCHAR2) AS
2646 
2647   v_list_line_id NUMBER;
2648   v_operand NUMBER;
2649   v_routine_name CONSTANT VARCHAR2(240) := 'Routine:QP_Calculate_Price_PUB.GSA_Max_Discount_Check';
2650   v_source_system_code VARCHAR2(30);
2651 
2652   GSA_VIOLATION EXCEPTION;
2653 
2654   CURSOR get_source_system_code IS
2655     SELECT b.SOURCE_SYSTEM_CODE
2656     FROM  qp_npreq_ldets_tmp a, QP_LIST_HEADERS_B b
2657     WHERE a.CREATED_FROM_LIST_HEADER_ID = b.LIST_HEADER_ID
2658     AND   a.LINE_INDEX = p_line_index
2659     AND   a.CREATED_FROM_LIST_LINE_TYPE = 'PLL'
2660     AND   a.PRICING_STATUS_CODE = QP_PREQ_GRP.G_STATUS_NEW;
2661 
2662   CURSOR get_list_details_cur(p_source_system_code VARCHAR2) IS
2663     SELECT /*+ ORDERED USE_NL(a b c d e) */ c.LIST_LINE_ID, c.OPERAND
2664     FROM
2665      qp_npreq_line_attrs_tmp a, QP_PRICING_ATTRIBUTES b, QP_LIST_LINES c, QP_LIST_HEADERS_B d, QP_QUALIFIERS e
2666     WHERE  a.LINE_INDEX = p_line_index
2667     AND    a.CONTEXT = b.PRODUCT_ATTRIBUTE_CONTEXT
2668     AND    a.ATTRIBUTE = b.PRODUCT_ATTRIBUTE
2669     AND    a.VALUE_FROM = b.PRODUCT_ATTR_VALUE
2670     AND    b.PRICING_ATTRIBUTE_CONTEXT IS NULL
2671     AND    b.LIST_LINE_ID = c.LIST_LINE_ID
2672     AND    c.ARITHMETIC_OPERATOR = QP_PREQ_GRP.G_NEWPRICE_DISCOUNT
2673     AND    c.LIST_HEADER_ID = d.LIST_HEADER_ID
2674     AND    trunc(p_pricing_date) BETWEEN nvl(TRUNC(c.START_DATE_ACTIVE), trunc(p_pricing_date))
2675                           AND     nvl(TRUNC(c.END_DATE_ACTIVE), trunc(p_pricing_date))
2676     AND    d.SOURCE_SYSTEM_CODE = p_source_system_code
2677     AND    d.ACTIVE_FLAG = QP_PREQ_GRP.G_YES
2678     AND    d.LIST_HEADER_ID = e.LIST_HEADER_ID
2679     AND    e.QUALIFIER_CONTEXT = QP_PREQ_GRP.G_CUSTOMER_CONTEXT
2680     AND    e.QUALIFIER_ATTRIBUTE = QP_PREQ_GRP.G_GSA_ATTRIBUTE
2681     AND    e.QUALIFIER_ATTR_VALUE = QP_PREQ_GRP.G_YES
2682     ORDER  BY 2;
2683 
2684   BEGIN
2685     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
2686     x_return_status := FND_API.G_RET_STS_SUCCESS;
2687 
2688     OPEN get_source_system_code;
2689     FETCH get_source_system_code INTO v_source_system_code;
2690     CLOSE get_source_system_code;
2691 
2692     OPEN get_list_details_cur(v_source_system_code);
2693     FETCH get_list_details_cur INTO v_list_line_id, v_operand;
2694     CLOSE get_list_details_cur;
2695 
2696     IF l_debug = FND_API.G_TRUE THEN
2697       QP_PREQ_GRP.engine_debug ('GSA List Line : ' || v_list_line_id);
2698       QP_PREQ_GRP.engine_debug ('GSA Price : ' || v_operand);
2699       QP_PREQ_GRP.engine_debug('GSA List Line : ' || v_list_line_id);
2700       QP_PREQ_GRP.engine_debug('GSA Price : ' || v_operand);
2701 
2702     END IF;
2703     IF (v_operand IS NOT NULL)
2704       --changes made by spgopal for ASO bug 1898927
2705       AND (p_adjusted_unit_price <= v_operand)
2706       THEN
2707       RAISE GSA_VIOLATION;
2708     END IF;
2709 
2710   EXCEPTION
2711     WHEN GSA_VIOLATION THEN
2712       IF l_debug = FND_API.G_TRUE THEN
2713         QP_PREQ_GRP.engine_debug(v_routine_name || ' GSA Violation. GSA Price: ' || v_operand || 'List Line: ' || v_list_line_id);
2714       END IF;
2715       x_return_status := QP_PREQ_GRP.G_STATUS_GSA_VIOLATION;
2716       x_return_status_txt := v_operand ;
2717     WHEN OTHERS THEN
2718       IF l_debug = FND_API.G_TRUE THEN
2719         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || SQLERRM);
2720       END IF;
2721       x_return_status := FND_API.G_RET_STS_ERROR;
2722       x_return_status_txt := v_routine_name || ' ' || SQLERRM;
2723   END GSA_Max_Discount_Check;
2724 
2725   PROCEDURE Calculate_Price(p_request_line IN OUT NOCOPY l_request_line_rec,
2726                             p_request_line_details IN OUT NOCOPY l_request_line_details_tbl,
2727                             p_related_request_lines IN OUT NOCOPY l_related_request_lines_tbl,
2728                             x_return_status OUT NOCOPY VARCHAR2,
2729                             x_return_status_txt OUT NOCOPY VARCHAR2) AS
2730 
2731   x_related_request_lines_tbl l_related_request_lines_tbl;
2732 
2733   x_pbh_list_price NUMBER;
2734   x_list_price NUMBER;
2735   x_adjusted_amount NUMBER;
2736   x_percent_price NUMBER;
2737   x_extended_price NUMBER; -- block pricing
2738   x_discounted_price NUMBER;
2739   x_benefit_line_qty NUMBER;
2740 
2741   --v_request_line_rec            l_request_line_rec;
2742   --v_request_line_details_tbl    l_request_line_details_tbl;
2743   --v_related_request_lines       l_related_request_lines_tbl;
2744   v_list_line_id NUMBER;
2745   v_list_line_index NUMBER;
2746   v_ord_qty NUMBER;
2747   v_discounted_price NUMBER;
2748   v_old_pricing_sequence NUMBER;
2749   v_list_price NUMBER;
2750   v_total_adj_amt NUMBER;
2751   v_operand_calc_code VARCHAR2(30);
2752   v_operand_value NUMBER;
2753   v_related_item_price NUMBER := 0;
2754   v_index NUMBER := 0;
2755   v_orig_list_price NUMBER;
2756   v_service_duration NUMBER;
2757   v_actual_line_qty NUMBER; -- begin 2388011, grp_lines_pbh,
2758   v_bucketed_value NUMBER := NULL; -- IT bucket
2759   v_bucketed_qty NUMBER := NULL; -- IT bucket
2760   v_total_value NUMBER; -- end 2388011, LINEGROUP PBH
2761   x_ret_status VARCHAR2(30);
2762   x_ret_status_txt VARCHAR2(240);
2763   l_pbh_rounding_fact NUMBER;    --10093463
2764   v_routine_name CONSTANT VARCHAR2(240) := 'Routine:QP_Calculate_Price_PUB.Calculate_Price';
2765   --v_round_individual_adj_flag varchar2(3); --shu
2766   v_price_round_options VARCHAR2(30) := FND_PROFILE.VALUE('QP_SELLING_PRICE_ROUNDING_OPTIONS'); --shu, new rounding
2767 
2768   BEGIN
2769     -- Get the records from the l_request_line_details_tbl in the order
2770     --of pricing sequence(this cannot be done
2771     -- using PL/SQL table. I am assuming that I would get the records in ordered sequence
2772 
2773     l_debug := QP_PREQ_GRP.G_DEBUG_ENGINE;
2774     IF l_debug = FND_API.G_TRUE THEN
2775       QP_PREQ_GRP.engine_debug ('In Procedure Calculate_Price...'); -- shu, aso rounding, 2457629
2776       QP_PREQ_GRP.engine_debug ('selling price rounding options : ' || v_price_round_options); -- shu
2777       QP_PREQ_GRP.engine_debug ('Rounding Flag  : ' || QP_PREQ_GRP.G_ROUNDING_FLAG); -- aso rounding, 2457629
2778       QP_PREQ_GRP.engine_debug ('Rounding Factor  : ' || p_request_line.rounding_factor);
2779     END IF;
2780 
2781     IF (p_request_line.rounding_flag = 'Y' AND p_request_line.rounding_factor IS NULL) THEN -- shu
2782       IF l_debug = FND_API.G_TRUE THEN
2783         QP_PREQ_GRP.engine_debug ('WARNING: rounding_flag is Y, but rounding_factor is NULL!!!');
2784       END IF;
2785     END IF;
2786 
2787     -- For accum range break
2788     l_line_index := p_request_line.line_index;
2789 
2790     -- Loop through the p_request_line_details
2791 
2792     IF l_debug = FND_API.G_TRUE THEN
2793       QP_PREQ_GRP.engine_debug('The request line tables count is: ' || p_request_line_details.COUNT);
2794     END IF;
2795 
2796     v_index := p_request_line_details.FIRST;
2797     WHILE (v_index IS NOT NULL )
2798       LOOP
2799 
2800       IF l_debug = FND_API.G_TRUE THEN
2801         QP_PREQ_GRP.engine_debug('LOOPing through p_request_line_details........');
2802         QP_PREQ_GRP.engine_debug('The request line index is: ' || v_index);
2803         QP_PREQ_GRP.engine_debug('PBH Type123:' || p_request_line_details(v_index).CREATED_FROM_LIST_TYPE);
2804       END IF;
2805 
2806       -- Store the ordered qty
2807       v_ord_qty := nvl(p_request_line_details(v_index).line_quantity, 0); -- 2388011_latest
2808 
2809       -- begin 2388011
2810       -- Store the total group amount , applicable for LINEGROUP PBH Ravi Change
2811       --[julin/5158413] defaulting to -1 (instead of 0) to distinguish null qual value from 0 qual value
2812       --v_total_value := nvl(p_request_line_details(v_index).qualifier_value,  - 1); -- 2388011_latest
2813       v_total_value := nvl(p_request_line_details(v_index).qualifier_value,  0); --6896139 undoing changes done as part of bug 5158413
2814 
2815       IF l_debug = FND_API.G_TRUE THEN
2816         QP_PREQ_GRP.engine_debug('ldets.qualifier_value, (v_ord_qty) : ' || v_ord_qty);
2817         QP_PREQ_GRP.engine_debug('ldets.line_quqntity, (v_total_value) : ' || v_total_value);
2818         -- If bucketed net amount flag is set to 'Y'
2819         QP_PREQ_GRP.engine_debug('Bucketed Old PGS  : ' || v_old_pricing_sequence);
2820         QP_PREQ_GRP.engine_debug('Bucketed New PGS  : ' || p_request_line_details(v_index).PRICING_GROUP_SEQUENCE);
2821       END IF; -- END IF l_debug = FND_API.G_TRUE
2822 
2823       IF (nvl(v_old_pricing_sequence, - 9999) <> p_request_line_details(v_index).PRICING_GROUP_SEQUENCE AND
2824           p_request_line_details(v_index).bucketed_flag = 'Y') THEN
2825         IF l_debug = FND_API.G_TRUE THEN
2826           QP_PREQ_GRP.engine_debug('Before Bucketed Group Amount : ' || v_bucketed_value);
2827           QP_PREQ_GRP.engine_debug('Before Bucketed Line Amount : ' || v_bucketed_qty);
2828           QP_PREQ_GRP.engine_debug('Bucket Adjustment Amount: ' || nvl(v_total_adj_amt, 0));
2829         END IF; -- END IF l_debug = FND_API.G_TRUE
2830 
2831         IF (v_total_value > 0) THEN
2832           v_bucketed_value := v_total_value + nvl(v_total_adj_amt * v_actual_line_qty, 0); -- Net Group Amount
2833           v_bucketed_qty := NULL;
2834         ELSE -- Only needed when group amount is not passed
2835           v_bucketed_qty := v_ord_qty + nvl(v_total_adj_amt * v_actual_line_qty, 0); -- Net Item Amount
2836           v_bucketed_value := NULL;
2837         END IF; -- END IF (v_total_value > 0)
2838 
2839         IF l_debug = FND_API.G_TRUE THEN
2840           QP_PREQ_GRP.engine_debug('Net Bucketed Group Amount : ' || v_bucketed_value);
2841           QP_PREQ_GRP.engine_debug('Net Bucketed Line Amount : ' || v_bucketed_qty);
2842         END IF; -- END IF l_debug = FND_API.G_TRUE
2843       END IF; -- END IF (nvl(v_old_pricing_sequence,-9999)
2844 
2845       -- end fix 2388011, grp_lines_pbh, IT bucket
2846 
2847       IF (v_ord_qty = 0) THEN
2848         v_ord_qty := nvl(p_request_line.qualifier_value, 0);
2849       END IF;
2850 
2851       -- fix 2388011, grp_lines_pbh
2852       -- Actual quantity on the order line
2853       v_actual_line_qty := nvl(p_request_line.qualifier_value, 0);
2854 
2855       -- Store the related item price
2856       v_related_item_price := p_request_line.RELATED_ITEM_PRICE;
2857       v_service_duration := nvl(p_request_line.SERVICE_DURATION, 1);
2858 
2859       IF l_debug = FND_API.G_TRUE THEN
2860         QP_PREQ_GRP.engine_debug('Service Duration : ' || v_service_duration);
2861 
2862       END IF;
2863 
2864       -- Store the list line id
2865       v_list_line_index := p_request_line_details(v_index).LINE_DETAIL_INDEX;
2866 
2867       -- Store the operand calc code for the PBH line
2868       v_operand_calc_code := p_request_line_details(v_index).operand_calculation_code;
2869 
2870       -- Calculate List Price for Pricing Sequence 0 for a PBH line
2871       -- Process PBH for Getting List Price(if exists)
2872 
2873       -- Null Bucket
2874       IF (p_request_line_details(v_index).PRICING_GROUP_SEQUENCE IS NULL) THEN
2875         v_orig_list_price := p_request_line.UNIT_PRICE;
2876       ELSE
2877         IF (v_list_price IS NULL) THEN
2878           IF l_debug = FND_API.G_TRUE THEN
2879             QP_PREQ_GRP.engine_debug ('V_List_Price is null');
2880           END IF;
2881           v_list_price := p_request_line.UNIT_PRICE;
2882 
2883           IF nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, 'Y') = QP_PREQ_GRP.G_YES AND -- shu, aso debug 2457629
2884             p_request_line_details(v_index).ROUNDING_FACTOR IS NOT NULL THEN  -- 10093463
2885             v_list_price := ROUND(v_list_price, p_request_line_details(v_index).ROUNDING_FACTOR * ( - 1));
2886             p_request_line.UNIT_PRICE := v_list_price;
2887           ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check v_selling_price_rounding_options profile
2888 
2889             IF (v_price_round_options = G_ROUND_ADJ AND p_request_line_details(v_index).ROUNDING_FACTOR IS NOT NULL) THEN
2890               v_list_price := ROUND(v_list_price, p_request_line_details(v_index).ROUNDING_FACTOR * ( - 1));
2891               p_request_line.UNIT_PRICE := v_list_price;
2892             END IF;
2893           END IF; -- end IF  nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, 'Y')
2894           v_discounted_price := nvl(p_request_line.ADJUSTED_UNIT_PRICE, v_list_price);
2895 
2896         END IF; -- END IF (v_list_price IS NULL)
2897         v_orig_list_price := v_list_price;
2898       END IF; -- END IF (p_request_line_details(v_index).PRICING_GROUP_SEQUENCE IS NULL)
2899 
2900       IF (p_request_line_details(v_index).CREATED_FROM_LIST_LINE_TYPE =
2901           QP_PREQ_GRP.G_PRICE_BREAK_TYPE) THEN
2902         IF l_debug = FND_API.G_TRUE THEN
2903           QP_PREQ_GRP.engine_debug('PBH Type:' || p_request_line_details(v_index).CREATED_FROM_LIST_TYPE);
2904           QP_PREQ_GRP.engine_debug('PBH Unit Price:' || p_request_line.UNIT_PRICE);
2905           QP_PREQ_GRP.engine_debug('Old PGS:' || v_old_pricing_sequence);
2906         END IF;
2907 
2908 	IF (p_request_line_details(v_index).CREATED_FROM_LIST_TYPE='PRL') THEN     --10093463
2909           l_pbh_rounding_fact:=p_request_line_details(v_index).ROUNDING_FACTOR;
2910         ELSE                                                                                 --10093463
2911           l_pbh_rounding_fact:=p_request_line.ROUNDING_FACTOR;
2912         END IF;
2913 
2914 	-- 2388011, pbh_grp_amt
2915         Process_Price_Break(
2916                             p_request_line_details(v_index).created_from_list_line_id,  -- PBH list line ID, for accum range break
2917                             v_list_line_index,  -- PBH Line Id
2918                             v_operand_calc_code,  -- PBH Line arithmetic operator
2919                             v_ord_qty,  -- 2388011_new
2920                             v_actual_line_qty,  -- 2388011,
2921                             p_request_line_details(v_index).CREATED_FROM_LIST_TYPE,  -- Prc/Dis Break
2922                             nvl(v_orig_list_price, p_request_line.UNIT_PRICE),  -- Unit Price(for discount break)
2923                             nvl(v_discounted_price, p_request_line.UNIT_PRICE),
2924                             v_old_pricing_sequence,
2925                             v_related_item_price,  -- Related Item Price
2926                             v_service_duration,  -- Service Duration for service line pricing
2927                             p_related_request_lines,  -- Children of PBH Lines
2928                             nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, 'Y'), -- shu, aso debug 2457629
2929                             ( - 1) * l_pbh_rounding_fact, --10093463
2930                             nvl(v_bucketed_value, v_total_value),  -- 2388011, PBH LINEGROUP Ravi Change
2931                             x_pbh_list_price,  -- List Price for the Request Line
2932                             x_extended_price,  -- block pricing
2933                             x_adjusted_amount,  -- Adjustment Amount for the PBH Line
2934                             x_related_request_lines_tbl,  -- Related Request Lines Detail Table
2935                             x_ret_status,
2936                             x_ret_status_txt);
2937         v_old_pricing_sequence := p_request_line_details(v_index).PRICING_GROUP_SEQUENCE;
2938 
2939         IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
2940           RAISE FND_API.G_EXC_ERROR;
2941         END IF;
2942 
2943         IF (p_request_line_details(v_index).CREATED_FROM_LIST_TYPE IN
2944                                  (QP_PREQ_GRP.G_PRICE_LIST_HEADER, QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
2945 
2946           -- Update the list price on the p_request_line_details structure for the PBH line
2947           p_request_line.UNIT_PRICE := x_pbh_list_price;
2948           p_request_line.EXTENDED_PRICE := x_extended_price; -- block pricing
2949           p_request_line_details(v_index).ADJUSTMENT_AMOUNT := nvl(x_pbh_list_price, 0);
2950           p_request_line_details(v_index).LINE_QUANTITY := v_ord_qty;
2951           -- Init the price list values for input to the Calculate_Adjusted_Price function
2952           v_list_price := x_pbh_list_price;
2953           v_discounted_price := x_pbh_list_price;
2954           IF l_debug = FND_API.G_TRUE THEN
2955             QP_PREQ_GRP.engine_debug('Unit Price:' || x_pbh_list_price);
2956             QP_PREQ_GRP.engine_debug('Extended Price on the Line: ' || p_request_line.EXTENDED_PRICE);
2957             QP_PREQ_GRP.engine_debug('Related Request Lines Table Count:'|| x_related_request_lines_tbl.COUNT);
2958           END IF;
2959         ELSE
2960           -- Update the adjustment amount on the p_request_line_details
2961           p_request_line_details(v_index).ADJUSTMENT_AMOUNT := nvl(x_adjusted_amount, 0);
2962           p_request_line_details(v_index).LINE_QUANTITY := v_ord_qty;
2963           -- Update the adjusted unit price
2964           -- Total Adjusted amount is not calculated on Freight Charges and manual price breaks which will have
2965           -- automatic_flag = 'N'
2966 
2967           IF (p_request_line_details(v_index).CREATED_FROM_LIST_LINE_TYPE <> QP_PREQ_GRP.G_FREIGHT_CHARGE AND
2968               p_request_line_details(v_index).AUTOMATIC_FLAG <> QP_PREQ_GRP.G_NO) THEN
2969             IF (nvl(p_request_line_details(v_index).ACCRUAL_FLAG, QP_PREQ_GRP.G_NO) <> QP_PREQ_GRP.G_YES) THEN
2970               v_total_adj_amt := nvl(v_total_adj_amt, 0) + nvl(x_adjusted_amount, 0);
2971             END IF;
2972             p_request_line.ADJUSTED_UNIT_PRICE := p_request_line.UNIT_PRICE + nvl(v_total_adj_amt, 0);
2973           END IF;
2974           v_discounted_price := p_request_line.ADJUSTED_UNIT_PRICE;
2975 
2976           IF l_debug = FND_API.G_TRUE THEN
2977             QP_PREQ_GRP.engine_debug('Adjusted Amount:' || x_adjusted_amount);
2978             QP_PREQ_GRP.engine_debug('Unit Price:' || p_request_line.UNIT_PRICE );
2979             QP_PREQ_GRP.engine_debug('Adjusted Unit Price:' || v_discounted_price);
2980           END IF;
2981 
2982         END IF; -- END IF (p_request_line_details(v_index).CREATED_FROM_LIST_TYPE...
2983 
2984         -- Update the passed in p_related_request_lines with new structure, which has the
2985         -- LIST_QTY and LIST_PRICE
2986         -- and SELLING PRICE for each PBH Line
2987         p_related_request_lines := x_related_request_lines_tbl;
2988       END IF;
2989 
2990       -- Calculate List Price for Pricing Sequence 0 for a PLL Line
2991       --IF (p_request_line_details(v_index).CREATED_FROM_LIST_TYPE in
2992       --	(QP_PREQ_GRP.G_PRICE_LIST_HEADER,QP_PREQ_GRP.G_AGR_LIST_HEADER)) THEN
2993       IF (p_request_line_details(v_index).CREATED_FROM_LIST_LINE_TYPE = QP_PREQ_GRP.G_PRICE_LIST_TYPE) THEN
2994         IF l_debug = FND_API.G_TRUE THEN
2995           QP_PREQ_GRP.engine_debug('I am in PLL');
2996         END IF;
2997         Calculate_List_Price_PVT(p_request_line_details(v_index).OPERAND_CALCULATION_CODE,
2998                                  p_request_line_details(v_index).OPERAND_VALUE,
2999                                  0,  -- block pricing
3000                                  v_ord_qty,
3001                                  v_related_item_price,
3002                                  v_service_duration,
3003                                  --nvl(p_request_line.ROUNDING_FLAG,'Y'),
3004                                  nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, 'Y'),  -- shu, aso debug 2457629
3005                                  ( - 1) * p_request_line_details(v_index).ROUNDING_FACTOR, --10093463
3006                                  x_list_price,
3007                                  x_percent_price,
3008                                  x_extended_price,  -- block pricing
3009                                  x_ret_status,
3010                                  x_ret_status_txt);
3011         IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
3012           RAISE FND_API.G_EXC_ERROR;
3013         END IF;
3014 
3015         p_request_line.UNIT_PRICE := x_list_price;
3016         p_request_line.PERCENT_PRICE := x_percent_price;
3017         p_request_line_details(v_index).ADJUSTMENT_AMOUNT := nvl(x_list_price, 0);
3018         p_request_line_details(v_index).LINE_QUANTITY := v_ord_qty;
3019 
3020         -- Init the price list values for input to the Calculate_Adjusted_Price function
3021         v_list_price := x_list_price;
3022         v_discounted_price := x_list_price;
3023         IF l_debug = FND_API.G_TRUE THEN
3024           QP_PREQ_GRP.engine_debug('The List Price23 is: ' || v_list_price);
3025 
3026         END IF;
3027       END IF;
3028 
3029       -- Set the list price and discounted price if they are null
3030       -- This can be the case if pll lines are not passed
3031       -- nvl , if the caller wants the adjustments to be applied to an already
3032       -- discounted line
3033       IF (v_list_price IS NULL) THEN
3034         IF l_debug = FND_API.G_TRUE THEN
3035           QP_PREQ_GRP.engine_debug ('V_List_Price is null');
3036         END IF;
3037         v_list_price := p_request_line.UNIT_PRICE;
3038 
3039         IF nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, 'Y') = QP_PREQ_GRP.G_YES AND -- shu, aso debug 2457629
3040           p_request_line_details(v_index).ROUNDING_FACTOR IS NOT NULL THEN
3041           v_list_price := ROUND(p_request_line.UNIT_PRICE, p_request_line_details(v_index).ROUNDING_FACTOR * ( - 1)); -- 10093463
3042           p_request_line.UNIT_PRICE := v_list_price;
3043           -- shu, aso debug 2457629
3044         ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- shu, check v_selling_price_rounding_options profile
3045           IF (v_price_round_options = G_ROUND_ADJ AND p_request_line_details(v_index).ROUNDING_FACTOR IS NOT NULL) THEN
3046             v_list_price := ROUND(p_request_line.UNIT_PRICE, p_request_line_details(v_index).ROUNDING_FACTOR * ( - 1)); -- 10093463
3047             p_request_line.UNIT_PRICE := v_list_price;
3048           END IF;
3049 
3050         END IF;
3051         v_discounted_price := nvl(p_request_line.ADJUSTED_UNIT_PRICE, v_list_price);
3052       END IF;
3053 
3054       -- Calculate Adjusted Price
3055       IF (p_request_line_details(v_index).CREATED_FROM_LIST_LINE_TYPE
3056           IN (QP_PREQ_GRP.G_DISCOUNT, QP_PREQ_GRP.G_SURCHARGE, QP_PREQ_GRP.G_FREIGHT_CHARGE)) THEN
3057         IF l_debug = FND_API.G_TRUE THEN
3058           QP_PREQ_GRP.engine_debug('I am in DIS');
3059           QP_PREQ_GRP.engine_debug('The List Price is: ' || v_list_price);
3060           QP_PREQ_GRP.engine_debug('The Discounted Price is: ' || v_discounted_price);
3061           QP_PREQ_GRP.engine_debug('Old Pricing Seq: ' || v_old_pricing_sequence);
3062           QP_PREQ_GRP.engine_debug('New Pricing Seq: ' || p_request_line_details(v_index).PRICING_GROUP_SEQUENCE);
3063           QP_PREQ_GRP.engine_debug('Operand Calc Code: ' || p_request_line_details(v_index).OPERAND_CALCULATION_CODE);
3064           QP_PREQ_GRP.engine_debug('Operand Calc Value: ' || p_request_line_details(v_index).OPERAND_VALUE);
3065           QP_PREQ_GRP.engine_debug('List Line Type: ' || p_request_line_details(v_index).CREATED_FROM_LIST_LINE_TYPE);
3066 
3067         END IF;
3068 
3069 /* [julin/5529345] recurring logic moved to QP_PREQ_GRP.PRICE_REQUEST
3070         -- Recurring flag check
3071         IF (p_request_line_details(v_index).PRICE_BREAK_TYPE_CODE = QP_PREQ_GRP.G_RECURRING_BREAK AND
3072             QP_PREQ_GRP.G_LIMITS_CODE_EXECUTED = QP_PREQ_GRP.G_NO) THEN
3073           IF l_debug = FND_API.G_TRUE THEN
3074             QP_PREQ_GRP.engine_debug('In Recurring Routine --- #1');
3075             QP_PREQ_GRP.engine_debug('List Line Id: ' || p_request_line_details(v_index).CREATED_FROM_LIST_LINE_ID );
3076             QP_PREQ_GRP.engine_debug('List Line Index: ' || p_request_line.LINE_INDEX );
3077           END IF;
3078           -- Call Recurring Routine
3079           QP_Process_Other_Benefits_PVT.Calculate_Recurring_Quantity(
3080                                                                      p_request_line_details(v_index).CREATED_FROM_LIST_LINE_ID,
3081                                                                      p_request_line_details(v_index).CREATED_FROM_LIST_HEADER_ID,
3082                                                                      p_request_line.LINE_INDEX,
3083                                                                      NULL,
3084                                                                      x_benefit_line_qty,
3085                                                                      x_ret_status,
3086                                                                      x_ret_status_txt);
3087           IF l_debug = FND_API.G_TRUE THEN
3088             QP_PREQ_GRP.engine_debug('Return Status Text : ' || x_ret_status_txt);
3089 
3090           END IF;
3091           IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
3092             RAISE FND_API.G_EXC_ERROR;
3093           END IF;
3094           p_request_line_details(v_index).OPERAND_VALUE := x_benefit_line_qty;
3095 
3096           IF l_debug = FND_API.G_TRUE THEN
3097             QP_PREQ_GRP.engine_debug('Limits Code Not Executed.Did call Recurring Qty Routine');
3098             QP_PREQ_GRP.engine_debug('After Recurring Routine Value --- #2 : ' || x_benefit_line_qty);
3099 
3100           END IF;
3101         END IF;
3102 
3103         IF (p_request_line_details(v_index).PRICE_BREAK_TYPE_CODE = QP_PREQ_GRP.G_RECURRING_BREAK AND
3104             QP_PREQ_GRP.G_LIMITS_CODE_EXECUTED = QP_PREQ_GRP.G_YES) THEN
3105           IF l_debug = FND_API.G_TRUE THEN
3106             QP_PREQ_GRP.engine_debug('Limits Code Executed.Do not calculate OPERAND value 2nd time.');
3107             QP_PREQ_GRP.engine_debug('List Line Id: ' || p_request_line_details(v_index).CREATED_FROM_LIST_LINE_ID );
3108             QP_PREQ_GRP.engine_debug('List Line Index: ' || p_request_line.LINE_INDEX );
3109             QP_PREQ_GRP.engine_debug('Recurring Value: ' || p_request_line_details(v_index).OPERAND_VALUE );
3110           END IF;
3111         END IF;
3112 */
3113 
3114         IF (nvl(p_request_line_details(v_index).ACCRUAL_FLAG, QP_PREQ_GRP.G_NO) = QP_PREQ_GRP.G_YES) THEN
3115           IF l_debug = FND_API.G_TRUE THEN
3116             QP_PREQ_GRP.engine_debug('OPERAND_CALCULATION_CODE is ' || p_request_line_details(v_index).OPERAND_CALCULATION_CODE);
3117             QP_PREQ_GRP.engine_debug('v_ord_qty is ' || v_ord_qty);
3118           END IF;
3119           -- bug 4002891 - benefit_qty should be multiplied by ordered_qty for application_method other than LUMPSUM
3120           IF p_request_line_details(v_index).OPERAND_CALCULATION_CODE = QP_PREQ_GRP.G_LUMPSUM_DISCOUNT THEN
3121             p_request_line_details(v_index).BENEFIT_QTY :=
3122             p_request_line_details(v_index).OPERAND_VALUE *
3123             1 / nvl(p_request_line_details(v_index).ACCRUAL_CONVERSION_RATE, 1) *
3124             nvl(p_request_line_details(v_index).ESTIM_ACCRUAL_RATE, 100) / 100;
3125           ELSE
3126             p_request_line_details(v_index).BENEFIT_QTY :=
3127             (p_request_line_details(v_index).OPERAND_VALUE *
3128              1 / nvl(p_request_line_details(v_index).ACCRUAL_CONVERSION_RATE, 1) *
3129              nvl(p_request_line_details(v_index).ESTIM_ACCRUAL_RATE, 100) / 100) * v_ord_qty;
3130           END IF;
3131         END IF;
3132 
3133         --4900095
3134         --calculate lumpsum qty for svc lines
3135         IF p_request_line_details(v_index).modifier_level_code
3136           IN (QP_PREQ_GRP.G_LINE_LEVEL
3137               , QP_PREQ_GRP.G_LINE_GROUP)
3138           AND p_request_line_details(v_index).operand_calculation_code
3139           = QP_PREQ_GRP.G_LUMPSUM_DISCOUNT THEN
3140           --G_Lumpsum_qty will be not null only for service items
3141           --when uom_quantity is passed as null,
3142           -- and contract_start/end_dates are passed
3143           --and for a line/linegroup lumpsum DIS/PBH/SUR/FREIGHT
3144           G_Lumpsum_qty := Get_lumpsum_qty(l_line_index,
3145                                            p_request_line_details(v_index).line_detail_index,
3146                                            p_request_line_details(v_index).modifier_level_code);
3147           IF l_debug = FND_API.G_TRUE THEN
3148             QP_PREQ_GRP.engine_debug('Lumpsum_qty '
3149                                      || G_Lumpsum_qty);
3150           END IF;
3151         END IF; --p_request_line_details(v_index).modifier_level_code
3152 
3153         Calculate_Adjusted_Price(p_list_price => v_orig_list_price,
3154                                  p_discounted_price => v_discounted_price,  -- Discounted Price
3155                                  p_old_pricing_sequence => nvl(v_old_pricing_sequence,
3156                                                                p_request_line_details(v_index).PRICING_GROUP_SEQUENCE),
3157                                  p_new_pricing_sequence => p_request_line_details(v_index).PRICING_GROUP_SEQUENCE,
3158                                  p_operand_calc_code => p_request_line_details(v_index).OPERAND_CALCULATION_CODE,
3159                                  p_operand_value => p_request_line_details(v_index).OPERAND_VALUE,
3160                                  p_list_line_type => p_request_line_details(v_index).CREATED_FROM_LIST_LINE_TYPE,
3161                                  p_request_qty => v_ord_qty,
3162                                  p_accrual_flag => p_request_line_details(v_index).ACCRUAL_FLAG,
3163                                  --p_rounding_flag	     => nvl(p_request_line.ROUNDING_FLAG,'Y'),
3164                                  p_rounding_flag => nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, 'Y'),  -- shu, aso debug 2457629
3165                                  p_rounding_factor => ( - 1) * p_request_line.ROUNDING_FACTOR,
3166                                  p_orig_unit_price => p_request_line.UNIT_PRICE,
3167                                  x_discounted_price => x_discounted_price,  -- Output Discounted Price
3168                                  x_adjusted_amount => x_adjusted_amount,
3169                                  x_list_price => x_list_price, -- Output List Price
3170                                  x_return_status => x_ret_status,
3171                                  x_return_status_txt => x_ret_status_txt);
3172 
3173         IF(x_ret_status = FND_API.G_RET_STS_ERROR) THEN
3174           RAISE FND_API.G_EXC_ERROR;
3175         END IF;
3176 
3177         v_old_pricing_sequence := p_request_line_details(v_index).PRICING_GROUP_SEQUENCE;
3178         v_discounted_price := x_discounted_price;
3179         v_list_price := x_List_price;
3180 
3181         IF l_debug = FND_API.G_TRUE THEN
3182           QP_PREQ_GRP.engine_debug('Adjusted Amount: ' || x_adjusted_amount);
3183 
3184         END IF;
3185         -- Update the adjusted amount on the request line
3186         p_request_line_details(v_index).ADJUSTMENT_AMOUNT := nvl(x_adjusted_amount, 0);
3187         p_request_line_details(v_index).LINE_QUANTITY := v_ord_qty;
3188 
3189         -- Update the adjusted unit price(the adjusted_unit_price gets updated for
3190         -- every dis/sur line,which
3191         -- is same as updating once, because the adjusted_unit_price value gets overwritten
3192         -- Total Adjustment amount is not calculated for freight charges
3193 
3194         IF (p_request_line_details(v_index).CREATED_FROM_LIST_TYPE <>
3195             QP_PREQ_GRP.G_CHARGES_HEADER) THEN
3196           IF (nvl(p_request_line_details(v_index).ACCRUAL_FLAG, QP_PREQ_GRP.G_NO) <> QP_PREQ_GRP.G_YES AND
3197               p_request_line_details(v_index).AUTOMATIC_FLAG <> QP_PREQ_GRP.G_NO) THEN
3198             v_total_adj_amt := nvl(v_total_adj_amt, 0) + nvl(x_adjusted_amount, 0);
3199           END IF;
3200           --[prarasto:Post Round]removed rounding of unit selling price, the unrounded value will be
3201           --sent from calculation engine and it will be rounded in QP_PREQ_GRP.Call_Calculation_Engine
3202           /*
3203 
3204 		        -- DO UNIT SELLING PRICE ROUNDING HERE, shu
3205 
3206 			--IF (( nvl(p_request_line.rounding_flag, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES OR p_request_line.rounding_flag = G_CHAR_U) and p_request_line.rounding_factor IS NOT NULL) THEN -- shu
3207 			IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG,'Y')='Y' OR QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_U) and p_request_line.rounding_factor IS NOT NULL THEN-- aso rounding, 2457629, shu
3208 		      		p_request_line.ADJUSTED_UNIT_PRICE := ROUND ((p_request_line.UNIT_PRICE + nvl(v_total_adj_amt,0)), (-1) * p_request_line.rounding_factor);
3209 		      	ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- check qp_selling_price_rounding_options profile -- shu, new rounding
3210 		      		IF ((v_price_round_options = G_ROUND_ADJ OR v_price_round_options = G_NO_ROUND_ADJ) AND p_request_line.rounding_factor IS NOT NULL) THEN -- do not round if profile is null
3211 					p_request_line.ADJUSTED_UNIT_PRICE := ROUND ((p_request_line.UNIT_PRICE + nvl(v_total_adj_amt,0)), (-1) * p_request_line.rounding_factor);
3212 				ELSE -- NO_ROUND
3213 					p_request_line.ADJUSTED_UNIT_PRICE := p_request_line.UNIT_PRICE + nvl(v_total_adj_amt,0);
3214 				END IF;
3215 
3216 		      	ELSE -- rounding_flag is 'N'
3217 		      		p_request_line.ADJUSTED_UNIT_PRICE := p_request_line.UNIT_PRICE + nvl(v_total_adj_amt,0);
3218 		      	END IF; -- end rounding
3219 		      	-- end shu fix
3220 */
3221           p_request_line.ADJUSTED_UNIT_PRICE := p_request_line.UNIT_PRICE + nvl(v_total_adj_amt, 0);
3222           --[prarasto:Post Round] End post round fix
3223 
3224         END IF;
3225 
3226         IF l_debug = FND_API.G_TRUE THEN
3227           QP_PREQ_GRP.engine_debug('The Adjusted Amount is: ' || v_total_adj_amt);
3228           QP_PREQ_GRP.engine_debug('The Unit Price: ' || p_request_line.UNIT_PRICE );
3229           QP_PREQ_GRP.engine_debug('The Adjusted Price: ' || p_request_line.ADJUSTED_UNIT_PRICE );
3230 
3231         END IF;
3232       END IF;
3233       EXIT WHEN v_index = p_request_line_details.LAST;
3234       v_index := p_request_line_details.NEXT(v_index);
3235     END LOOP;
3236 
3237     -- If price list is not passed , round the unit price and adjusted unit price
3238     IF (v_list_price IS NULL) THEN
3239       IF l_debug = FND_API.G_TRUE THEN
3240         QP_PREQ_GRP.engine_debug ('V_List_Price is null');
3241       END IF;
3242       v_list_price := p_request_line.UNIT_PRICE ;
3243       IF l_debug = FND_API.G_TRUE THEN
3244         QP_PREQ_GRP.engine_debug ('List Price after rounding: ' || v_list_price);
3245       END IF;
3246 
3247       -- shu new rounding
3248       IF (nvl(QP_PREQ_GRP.G_ROUNDING_FLAG, QP_PREQ_GRP.G_YES) = QP_PREQ_GRP.G_YES -- aso rounding, shu, 2457629
3249           AND p_request_line.rounding_factor IS NOT NULL) THEN -- shu new rounding
3250 
3251         p_request_line.UNIT_PRICE := ROUND(v_list_price, p_request_line.ROUNDING_FACTOR * ( - 1));
3252         v_list_price := ROUND(v_list_price, p_request_line.ROUNDING_FACTOR * ( - 1));
3253 
3254       ELSIF (QP_PREQ_GRP.G_ROUNDING_FLAG = G_CHAR_Q) THEN -- aso rounding, shu, 2457629
3255         -- no round if rounding_flag is Q bug QP profile is null
3256         IF v_price_round_options = G_ROUND_ADJ AND p_request_line.rounding_factor IS NOT NULL THEN -- bug 2415571
3257           p_request_line.UNIT_PRICE := ROUND(v_list_price, p_request_line.ROUNDING_FACTOR * ( - 1));
3258           v_list_price := ROUND(v_list_price, p_request_line.ROUNDING_FACTOR * ( - 1));
3259         END IF;
3260 
3261       END IF;
3262 
3263       IF l_debug = FND_API.G_TRUE THEN
3264         QP_PREQ_GRP.engine_debug ('List Price after rounding1: ' || p_request_line.UNIT_PRICE);
3265         QP_PREQ_GRP.engine_debug ('List Price after rounding2: ' || v_list_price);
3266       END IF;
3267       v_discounted_price := nvl(p_request_line.ADJUSTED_UNIT_PRICE, v_list_price);
3268     END IF;
3269 
3270     -- Call GSA Check only for non-gsa customers(where GSA_QUALIFIER_FLAG IS NULL)
3271     IF (p_request_line.GSA_QUALIFIER_FLAG IS NULL AND nvl(QP_PREQ_GRP.G_GSA_CHECK_FLAG, 'Y') = QP_PREQ_GRP.G_YES AND
3272         p_request_line.GSA_ENABLED_FLAG = QP_PREQ_GRP.G_YES AND
3273         QP_PREQ_GRP.G_GSA_DUP_CHECK_FLAG = QP_PREQ_GRP.G_YES ) THEN
3274       GSA_Max_Discount_Check(p_request_line.ADJUSTED_UNIT_PRICE,
3275                              p_request_line.LINE_INDEX,
3276                              p_request_line.PRICING_EFFECTIVE_DATE,
3277                              x_ret_status,
3278                              x_ret_status_txt);
3279       IF(x_ret_status = QP_PREQ_GRP.G_STATUS_GSA_VIOLATION) THEN
3280         x_return_status := QP_PREQ_GRP.G_STATUS_GSA_VIOLATION;
3281         x_return_status_txt := x_ret_status_txt;
3282       END IF;
3283     END IF;
3284     IF l_debug = FND_API.G_TRUE THEN
3285       QP_PREQ_GRP.engine_debug ('Before Update List Price after rounding1: ' || p_request_line.UNIT_PRICE);
3286 
3287     END IF;
3288     -- Populate the Output records
3289     --p_request_line := p_request_line;
3290     --p_request_line_details := p_request_line_details;
3291     --p_related_request_lines := p_related_request_lines;
3292   EXCEPTION
3293     WHEN FND_API.G_EXC_ERROR THEN
3294       IF l_debug = FND_API.G_TRUE THEN
3295         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || x_ret_status_txt);
3296       END IF;
3297       x_return_status := FND_API.G_RET_STS_ERROR;
3298       x_return_status_txt := v_routine_name || ' ' || x_ret_status_txt;
3299     WHEN OTHERS THEN
3300       IF l_debug = FND_API.G_TRUE THEN
3301         QP_PREQ_GRP.engine_debug(v_routine_name || ' ' || SQLERRM);
3302       END IF;
3303       x_return_status := FND_API.G_RET_STS_ERROR;
3304       x_return_status_txt := v_routine_name || ' ' || SQLERRM;
3305 
3306   END Calculate_Price;
3307 
3308 END QP_Calculate_Price_PUB;