DBA Data[Home] [Help]

PACKAGE BODY: APPS.FTE_FREIGHT_PRICING_SPECIAL

Source


1 PACKAGE BODY FTE_FREIGHT_PRICING_SPECIAL AS
2 /* $Header: FTEFRPSB.pls 120.6 2005/11/04 16:30:56 susurend noship $ */
3 
4 -- Private Package level Variables
5 g_hash_base NUMBER := 1;
6 g_hash_size NUMBER := power(2, 25);
7 
8 G_CONTAINER_BASIS    NUMBER := 1;
9 G_VOLUME_BASIS       NUMBER := 2;
10 G_WEIGHT_BASIS       NUMBER := 3;
11 
12    g_finished_success		EXCEPTION;
13    g_finished_warning		EXCEPTION;
14 
15   TYPE rule_value_rec_type IS RECORD
16        ( name                    VARCHAR2(40),
17          value                   VARCHAR2(40),
18          def_value               VARCHAR2(40));
19 
20   TYPE rule_value_tab_type IS TABLE OF rule_value_rec_type INDEX BY BINARY_INTEGER;
21 
22   TYPE bumped_rolledup_line_rec_type IS RECORD
23         (line_quantity                          NUMBER);
24 
25   TYPE bumped_rolledup_line_tab_type IS TABLE OF bumped_rolledup_line_rec_type INDEX BY BINARY_INTEGER;
26 
27   -- bug2803178 for parcel hundred wt loose item only
28   g_bumped_rolledup_lines         bumped_rolledup_line_tab_type;
29 
30 CURSOR get_uom_for_each
31 IS
32 SELECT uom_for_num_of_units
33 FROM wsh_global_parameters;
34 
35 -- prints contents of the global parameter table
36 PROCEDURE print_params IS
37  i    NUMBER;
38 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
39 l_method_name VARCHAR2(50) := 'print_params';
40  BEGIN
41    i := g_lane_parameters.FIRST;
42       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'g_lane_parameters ====> ');
43    IF (i IS NOT NULL) THEN
44    LOOP
45       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'lane_id               = '||g_lane_parameters(i).lane_id);
46       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  parameter_instance_id = '||g_lane_parameters(i).parameter_instance_id);
47       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  lane_function         = '||g_lane_parameters(i).lane_function);
48       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  parameter_sub_type    = '||g_lane_parameters(i).parameter_sub_type);
49       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  parameter_name        = '||g_lane_parameters(i).parameter_name);
50       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  value_from            = '||g_lane_parameters(i).value_from);
51       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  value_to              = '||g_lane_parameters(i).value_to);
52       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  uom_class             = '||g_lane_parameters(i).uom_class);
53       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  uom_code              = '||g_lane_parameters(i).uom_code);
54       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  currency_code         = '||g_lane_parameters(i).currency_code);
55       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  ');
56    EXIT WHEN (i >= g_lane_parameters.LAST );
57        i := g_lane_parameters.NEXT(i);
58    END LOOP;
59    END IF;
60 
61 END print_params;
62 
63 PROCEDURE print_special_flags IS
64  i    NUMBER;
65 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
66 l_method_name VARCHAR2(50) := 'print_special_flags';
67  BEGIN
68 
69    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'g_special_flags  ===>');
70    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'dim_wt_flag           = '||g_special_flags.dim_wt_flag);
71    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'lane_function         = '||g_special_flags.lane_function);
72    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'minimum_charge_flag   = '||g_special_flags.minimum_charge_flag);
73    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'parcel_hundredwt_flag = '||g_special_flags.parcel_hundredwt_flag);
74    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'deficit_wt_flag       = '||g_special_flags.deficit_wt_flag);
75    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'flat_containerwt_flag       = '||g_special_flags.flat_containerwt_flag);
76 
77 END print_special_flags;
78 
79 PROCEDURE print_rules IS
80  i    NUMBER;
81 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
82 l_method_name VARCHAR2(50) := 'print_rules';
83  BEGIN
84    i := g_lane_rules_tab.FIRST;
85       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'g_lane_rules_tab ====> ');
86    IF (i IS NOT NULL) THEN
87    LOOP
88       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  lane_function         = '||g_lane_rules_tab(i).lane_function);
89       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  pattern_name          = '||g_lane_rules_tab(i).pattern_name);
90       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  grouping_level        = '||g_lane_rules_tab(i).grouping_level);
91       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  commodity_aggregation = '||g_lane_rules_tab(i).commodity_aggregation);
92       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'  pricing_objective     = '||g_lane_rules_tab(i).pricing_objective);
93    EXIT WHEN (i >= g_lane_rules_tab.LAST );
94        i := g_lane_rules_tab.NEXT(i);
95    END LOOP;
96    END IF;
97 
98 END print_rules;
99 
100 PROCEDURE load_rules(p_lane_id         IN NUMBER,
101                      p_lane_function   IN VARCHAR2,
102                      x_return_status   OUT NOCOPY  VARCHAR2)
103 IS
104 
105     CURSOR     c_lane_rules(c_lane_id IN NUMBER, c_lane_function IN VARCHAR2, c_pattern_name IN VARCHAR2) IS
106     SELECT     fpp.lane_id,
107                fppd.lane_function,
108                fppd.parameter_sub_type,
109                fppd.parameter_name,
110                fpp.value_from,
111                fppd.default_value_from
112     FROM       fte_prc_parameter_defaults fppd, fte_prc_parameters fpp
113     WHERE      fppd.parameter_id = fpp.parameter_id (+)
114     AND        fpp.lane_id (+) = c_lane_id
115     AND        fppd.lane_function = c_lane_function
116     AND        fppd.parameter_type = 'RULE'
117     AND        fppd.parameter_sub_type = c_pattern_name
118     ORDER BY   fppd.parameter_sub_type, fppd.parameter_name;
119 
120    CURSOR      c_patterns(c_lane_function IN VARCHAR2) IS
121    SELECT      DISTINCT fppd.parameter_sub_type pattern_name
122    FROM        fte_prc_parameter_defaults fppd
123    WHERE       fppd.lane_function = c_lane_function
124      AND       fppd.parameter_type = 'RULE'
125    ORDER BY    1;
126 
127     l_lane_rule_rec          c_lane_rules%rowtype;
128     l_def_values             rule_value_tab_type;
129     l_pattern_name           VARCHAR2(30);
130     l_return_status          VARCHAR2(1);
131     i                        NUMBER :=1;
132     j                        NUMBER :=1;
133     k                        NUMBER :=1;
134     l_counter                NUMBER :=0;
135 
136 
137 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
138 l_method_name VARCHAR2(50) := 'load_rules';
139  BEGIN
140    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
141    l_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
142 
143    fte_freight_pricing_util.reset_dbg_vars;
144    fte_freight_pricing_util.set_method(l_log_level,'load_rules');
145 
146    g_lane_rules_tab.DELETE;
147 
148   OPEN c_patterns(p_lane_function);
149   LOOP
150     FETCH c_patterns INTO l_pattern_name;
151     EXIT WHEN c_patterns%NOTFOUND;
152     l_counter := 0;
153     i := 1;
154     l_def_values.delete;
155 
156        OPEN c_lane_rules(p_lane_id,p_lane_function,l_pattern_name);
157        LOOP
158           FETCH  c_lane_rules INTO l_lane_rule_rec;
159           EXIT WHEN c_lane_rules%NOTFOUND;
160 
161           IF l_lane_rule_rec.value_from IS NOT NULL THEN
162              l_counter := l_counter + 1;
163           END IF;
164 
165           l_def_values(i).name := l_lane_rule_rec.parameter_name;
166           l_def_values(i).def_value := l_lane_rule_rec.default_value_from;
167           l_def_values(i).value := l_lane_rule_rec.value_from;
168           i := i+1;
169 
170        END LOOP;
171        CLOSE c_lane_rules;
172 
173        IF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_1_NAME THEN
174           k := FTE_FREIGHT_PRICING.G_PATTERN_1;
175        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_2_NAME THEN
176           k := FTE_FREIGHT_PRICING.G_PATTERN_2;
177        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_3_NAME THEN
178           k := FTE_FREIGHT_PRICING.G_PATTERN_3;
179        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_4_NAME THEN
180           k := FTE_FREIGHT_PRICING.G_PATTERN_4;
181        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_5_NAME THEN
182           k := FTE_FREIGHT_PRICING.G_PATTERN_5;
183        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_5_NAME THEN
184           k := FTE_FREIGHT_PRICING.G_PATTERN_5;
185        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_6_NAME THEN
186           k := FTE_FREIGHT_PRICING.G_PATTERN_6;
187        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_7_NAME THEN
188           k := FTE_FREIGHT_PRICING.G_PATTERN_7;
189        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_8_NAME THEN
190           k := FTE_FREIGHT_PRICING.G_PATTERN_8;
191        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_9_NAME THEN
192           k := FTE_FREIGHT_PRICING.G_PATTERN_9;
193        ELSIF l_pattern_name = FTE_FREIGHT_PRICING.G_PATTERN_10_NAME THEN
194           k := FTE_FREIGHT_PRICING.G_PATTERN_10;
195        END IF;
196 
197       IF (l_def_values.COUNT > 0) THEN
198        g_lane_rules_tab(k).lane_function := p_lane_function;
199        g_lane_rules_tab(k).pattern_name  := l_pattern_name;
200 
201        j := l_def_values.FIRST;
202        IF (j IS NOT NULL) THEN
203        LOOP
204           IF l_def_values(j).name = 'GROUPING_LEVEL' THEN
205              IF l_counter > 0 THEN
206                g_lane_rules_tab(k).grouping_level := l_def_values(j).value;
207              ELSE
208                g_lane_rules_tab(k).grouping_level := l_def_values(j).def_value;
209              END IF;
210           ELSIF l_def_values(j).name = 'COMMODITY_AGGREGATION' THEN
211              IF l_counter > 0 THEN
212                g_lane_rules_tab(k).commodity_aggregation := l_def_values(j).value;
213              ELSE
214                g_lane_rules_tab(k).commodity_aggregation := l_def_values(j).def_value;
215              END IF;
216           ELSIF l_def_values(j).name = 'PRICING_OBJECTIVE' THEN
217              IF l_counter > 0 THEN
218                g_lane_rules_tab(k).pricing_objective := l_def_values(j).value;
219              ELSE
220                g_lane_rules_tab(k).pricing_objective := l_def_values(j).def_value;
221              END IF;
222           END IF;
223 
224 	  IF p_lane_function = 'LTL' and
225 	    (g_lane_rules_tab(k).grouping_level <> 'SHIPMENT'
226 	     or g_lane_rules_tab(k).commodity_aggregation <> 'WITHIN') THEN
227 
228 	    FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'Invalid parttern for LTL');
229 	    FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'grouping_level='||g_lane_rules_tab(k).grouping_level);
230 	    FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'commodity_aggregation='||g_lane_rules_tab(k).commodity_aggregation);
231   	    l_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
232 
233 	  END IF;
234 
235           EXIT WHEN j = l_def_values.LAST;
236           j := l_def_values.NEXT(j);
237 
238        END LOOP;
239        END IF;
240       END IF;
241   END LOOP;
242   CLOSE c_patterns;
243 
244   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
245     RAISE FND_API.G_EXC_ERROR;
246   END IF;
247 
248  fte_freight_pricing_util.unset_method(l_log_level,'load_rules');
249  EXCEPTION
250    WHEN FND_API.G_EXC_ERROR THEN
251         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
252         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'FND_API.G_EXC_ERROR');
253         fte_freight_pricing_util.unset_method(l_log_level,'load_rules');
254    WHEN others THEN
255         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
256         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
257         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
258         fte_freight_pricing_util.unset_method(l_log_level,'load_rules');
259 END load_rules;
260 
261 -- This procedure initializes global data for use by special pricing.
262 -- Currently, this procedure loads parameters for the lane into the global plsql table.
263 PROCEDURE initialize(p_lane_id         IN NUMBER,
264                      x_lane_function   OUT NOCOPY  VARCHAR2,
265                      x_return_status   OUT NOCOPY  VARCHAR2)
266 IS
267 
268     CURSOR     c_lane_param(c_lane_id IN NUMBER ) IS
269     SELECT     fpp.parameter_instance_id,fpp.lane_id,
270                fppd.lane_function,fppd.parameter_sub_type, fppd.parameter_name,
271                nvl(fpp.value_from,fppd.default_value_from),
272                nvl(fpp.value_to,fppd.default_value_to),
273                fpp.uom_class, fpp.uom_code, fpp.currency_code
274     FROM       fte_prc_parameter_defaults fppd, fte_prc_parameters fpp
275     WHERE      fppd.parameter_id = fpp.parameter_id (+)
276     AND        fpp.lane_id (+) = c_lane_id
277     AND        fppd.parameter_type = 'PARAMETER'
278     ORDER BY   fppd.parameter_type, fppd.parameter_sub_type, fppd.parameter_name;
279 
280     l_lane_param_rec         lane_parameter_rec_type;
281     l_return_status          VARCHAR2(1);
282     i                        NUMBER :=1;
283     l_log_level  NUMBER := fte_freight_pricing_util.G_LOG;
284     l_method_name VARCHAR2(50) := 'initialize';
285 
286 /*
287    ---- Local Module ----
288    -- This procedure checks for any applicable conditions within the loaded parameters,
289    -- and sets flags in a global record.
290    -- This global record is checked later (at various points) to decide on the course of action.
291 
292    PROCEDURE check_for_special_conditions(p_param_rec IN lane_parameter_rec_type) IS
293    l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
294    l_method_name VARCHAR2(50) := 'check_for_special_conditions';
295  BEGIN
296       fte_freight_pricing_util.set_method(l_log_level,'check_for_special_conditions');
297         g_special_flags.lane_id := p_param_rec.lane_id;
298         IF (p_param_rec.lane_function = 'NONE' AND p_param_rec.parameter_name = 'LANE_FUNCTION') THEN
299                g_special_flags.lane_function := nvl(p_param_rec.value_from,'NONE');
300         END IF;
301         --IF (p_param_rec.lane_function = 'NONE' AND p_param_rec.parameter_sub_type = 'DIM_WT'
302         --    AND p_param_rec.parameter_name = 'ENABLED') THEN
303         --       g_special_flags.dim_wt_flag := nvl(p_param_rec.value_from,'N');
304         --END IF;
305 
306         IF (p_param_rec.lane_function = 'NONE' and p_param_rec.parameter_sub_type = 'MIN_CHARGE' AND
307             p_param_rec.parameter_name = 'MIN_CHARGE_AMT') THEN
308                --g_special_flags.minimum_charge_flag := decode(nvl(p_param_rec.value_from,0),0,'N','Y');
309                IF (nvl(fnd_number.canonical_to_number(p_param_rec.value_from),0) = 0
310                     OR p_param_rec.currency_code IS NULL) THEN
311                    g_special_flags.minimum_charge_flag := 'N';
312                ELSE
313                    g_special_flags.minimum_charge_flag := 'Y';
314                END IF;
315         END IF;
316         IF (p_param_rec.lane_function = 'LTL' AND p_param_rec.parameter_sub_type = 'DEFICIT_WT'
317             AND p_param_rec.parameter_name = 'ENABLED') THEN
318                g_special_flags.deficit_wt_flag := nvl(p_param_rec.value_from,'N');
319         END IF;
320         IF (p_param_rec.lane_function = 'PARCEL' AND p_param_rec.parameter_sub_type = 'HUNDREDWT'
321             AND p_param_rec.parameter_name = 'ENABLED') THEN
322                g_special_flags.parcel_hundredwt_flag := nvl(p_param_rec.value_from,'N');
323         END IF;
324       fte_freight_pricing_util.unset_method(l_log_level,'check_for_special_conditions');
325    END check_for_special_conditions;
326  ---- End Local Module ---
327 */
328  ---- Local Module ----
329   -- validate lane parameters and set special flags
330   PROCEDURE validate_parameters(x_return_status OUT NOCOPY  VARCHAR2) IS
331     i  NUMBER;
332     l_wt_break_cnt       NUMBER := 0;
333     l_last_df_wt_uom     VARCHAR2(30);
334     l_invalid_df_wt_break_found BOOLEAN := false;
335     l_dim_wt_factor_ok   BOOLEAN := false;
336     l_dim_wt_wt_uom_ok   BOOLEAN := false;
337     l_dim_wt_vol_uom_ok   BOOLEAN := false;
338     l_dim_wt_dim_uom_ok   BOOLEAN := false;
339     l_return_status   VARCHAR2(1);
340   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
341   l_method_name VARCHAR2(50) := 'validate_parameters';
342  BEGIN
343       fte_freight_pricing_util.set_method(l_log_level,'validate_parameters');
344       x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
345 /*
346       --validate deficit wt params
347       IF (g_special_flags.deficit_wt_flag = 'Y') THEN
348          --check if weight breaks have been defined.
349          i := g_lane_parameters.FIRST;
350          IF (i is NOT NULL) THEN
351             LOOP
352                IF (g_lane_parameters(i).parameter_name = 'WT_BREAK_POINT') THEN
353 
354                       IF ( g_lane_parameters(i).value_from IS NULL
355                            OR g_lane_parameters(i).uom_code IS NULL) THEN
356                              raise fte_freight_pricing_util.g_invalid_wt_break;
357                       END IF;
358 
359                       IF (l_last_df_wt_uom IS NULL) THEN
360                           l_last_df_wt_uom := g_lane_parameters(i).uom_code;
361                       ELSE
362                           IF (l_last_df_wt_uom <> g_lane_parameters(i).uom_code ) THEN
363                              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'All deficit weight break points are not in the same uom');
364                              raise fte_freight_pricing_util.g_invalid_wt_break;
365                           END IF;
366                       END IF;
367 
368                     l_wt_break_cnt := l_wt_break_cnt + 1;
369                END IF;
370             EXIT WHEN i >=g_lane_parameters.LAST;
371             i := g_lane_parameters.NEXT(i);
372             END LOOP;
373          END IF;
374          IF (l_wt_break_cnt = 0) THEN
375             raise fte_freight_pricing_util.g_weight_break_not_found;
376          END IF;
377 
378       END IF;  --validate deficit wt params
379 */
380 
381       fte_freight_pricing_util.print_msg(l_log_level,'before loop --1');
382       i := g_lane_parameters.FIRST;
383       IF (i is NOT NULL) THEN
384          LOOP
385              fte_freight_pricing_util.print_msg(l_log_level,'in loop i='||i);
386 	     IF (g_lane_parameters(i).lane_function = 'NONE'
387                  AND g_lane_parameters(i).parameter_sub_type = 'LANE'
388                  AND g_lane_parameters(i).parameter_name = 'LANE_FUNCTION') THEN
389                IF (g_lane_parameters(i).value_from is null) THEN
390                  g_special_flags.lane_function := 'NONE';
391                ELSIF (g_lane_parameters(i).value_from = 'PARCEL'
392 		      OR g_lane_parameters(i).value_from = 'FLAT'
393 		      OR g_lane_parameters(i).value_from = 'LTL') THEN
394                  g_special_flags.lane_function := g_lane_parameters(i).value_from;
395 	       ELSE
396                  g_special_flags.lane_function := 'NONE';
397                END IF;
398              END IF;
399 
400 	     IF (g_lane_parameters(i).lane_function = 'FLAT'
401                  AND g_lane_parameters(i).parameter_sub_type = 'INCLUDE_CONTAINER_WEIGHT'
402                  AND g_lane_parameters(i).parameter_name = 'ENABLED') THEN
403                IF (g_lane_parameters(i).value_from is null) THEN
404                  g_special_flags.flat_containerwt_flag := 'Y';
405                ELSIF (g_lane_parameters(i).value_from = 'N') THEN
406                  g_special_flags.flat_containerwt_flag := 'N';
407 	       ELSE
408                  g_special_flags.flat_containerwt_flag := 'Y';
409                END IF;
410              END IF;
411 
412 	     IF (g_lane_parameters(i).lane_function = 'LTL'
413                  AND g_lane_parameters(i).parameter_sub_type = 'DEFICIT_WT'
414                  AND g_lane_parameters(i).parameter_name = 'ENABLED') THEN
415                IF (g_lane_parameters(i).value_from is null) THEN
416                  g_special_flags.deficit_wt_flag := 'N';
417                ELSIF (g_lane_parameters(i).value_from = 'Y') THEN
418                  g_special_flags.deficit_wt_flag := 'Y';
419 	       ELSE
420                  g_special_flags.deficit_wt_flag := 'N';
421                END IF;
422              END IF;
423 
424 	     IF (g_lane_parameters(i).lane_function = 'LTL'
425                  AND g_lane_parameters(i).parameter_sub_type = 'DEFICIT_WT'
426                  AND g_lane_parameters(i).parameter_name = 'WT_BREAK_POINT') THEN
427 	       IF (g_lane_parameters(i).value_from is null) THEN
428                  fte_freight_pricing_util.print_msg(l_log_level,'deficit wt break point null');
429 		 l_invalid_df_wt_break_found := true;
430                  --raise fte_freight_pricing_util.g_invalid_wt_break;
431 	       ELSIF (fnd_number.canonical_to_number(g_lane_parameters(i).value_from) < 0) THEN
432                  fte_freight_pricing_util.print_msg(l_log_level,'deficit wt break point '||g_lane_parameters(i).value_from);
433 		 l_invalid_df_wt_break_found := true;
434                  --raise fte_freight_pricing_util.g_invalid_wt_break;
435                ELSE
436 		 IF (g_lane_parameters(i).uom_code is null) THEN
437                    fte_freight_pricing_util.print_msg(l_log_level,'deficit wt break point uom null');
438   		   l_invalid_df_wt_break_found := true;
439                    --raise fte_freight_pricing_util.g_invalid_wt_break;
440  		 ELSE
441                    IF (l_last_df_wt_uom IS NULL) THEN
442                      l_last_df_wt_uom := g_lane_parameters(i).uom_code;
443                    ELSE
444                      IF (l_last_df_wt_uom <> g_lane_parameters(i).uom_code ) THEN
445                        fte_freight_pricing_util.print_msg(l_log_level,'All deficit weight break points are not in the same uom');
446 		       l_invalid_df_wt_break_found := true;
447                        --raise fte_freight_pricing_util.g_invalid_wt_break;
448                      END IF;
449                    END IF;
450                    l_wt_break_cnt := l_wt_break_cnt + 1;
451 		 END IF;
452                END IF;
453              END IF;
454 
455 	     IF (g_lane_parameters(i).lane_function = 'PARCEL'
456                  AND g_lane_parameters(i).parameter_sub_type = 'HUNDREDWT'
457                  AND g_lane_parameters(i).parameter_name = 'ENABLED') THEN
458                IF (g_lane_parameters(i).value_from is null) THEN
459                  g_special_flags.parcel_hundredwt_flag := 'N';
460                ELSIF (g_lane_parameters(i).value_from = 'Y') THEN
461                  g_special_flags.parcel_hundredwt_flag := 'Y';
462 	       ELSE
463                  g_special_flags.parcel_hundredwt_flag := 'N';
464                END IF;
465              END IF;
466 
467 	     IF (g_lane_parameters(i).lane_function = 'PARCEL'
468                  AND g_lane_parameters(i).parameter_sub_type = 'HUNDREDWT'
469                  AND g_lane_parameters(i).parameter_name = 'MIN_PACKAGE_WT') THEN
470                    IF (g_lane_parameters(i).value_from IS NULL) THEN
471 		     g_lane_parameters(i).value_from := 0;
472                    ELSIF (fnd_number.canonical_to_number(g_lane_parameters(i).value_from) <= 0) THEN
473                      fte_freight_pricing_util.print_msg(l_log_level,'parcel hundredwt min_package_wt '||g_lane_parameters(i).value_from||' set to 0');
474 		     g_lane_parameters(i).value_from := 0;
475                    ELSE
476 		     IF (g_lane_parameters(i).uom_code is null) THEN
477                         fte_freight_pricing_util.print_msg(l_log_level,'parcel hundredwt min_package_wt uom_code null');
478                         raise fte_freight_pricing_util.g_invalid_uom_code;
479                      END IF;
480                    END IF;
481              END IF;
482 
483 	     IF (g_lane_parameters(i).lane_function = 'NONE'
484                  AND g_lane_parameters(i).parameter_sub_type = 'MIN_CHARGE'
485                  AND g_lane_parameters(i).parameter_name = 'MIN_CHARGE_AMT') THEN
486                IF (g_lane_parameters(i).value_from is not null) THEN
487                  IF (fnd_number.canonical_to_number(g_lane_parameters(i).value_from) > 0 AND g_lane_parameters(i).currency_code is not null) THEN
488                    g_special_flags.minimum_charge_flag := 'Y';
489                  END IF;
490                END IF;
491              END IF;
492 
493              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
494                  AND g_lane_parameters(i).parameter_name = 'FACTOR'
495                  AND g_lane_parameters(i).value_from IS NOT NULL) THEN
496                    IF (fnd_number.canonical_to_number(g_lane_parameters(i).value_from) > 0) THEN
497                       l_dim_wt_factor_ok := true;
498                    END IF;
499              END IF;
500 
501              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
502                  AND g_lane_parameters(i).parameter_name = 'WT_UOM'
503                  AND g_lane_parameters(i).value_from IS NOT NULL) THEN
504                       l_dim_wt_wt_uom_ok := true;
505              END IF;
506 
507              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
508                  AND g_lane_parameters(i).parameter_name = 'VOL_UOM'
509                  AND g_lane_parameters(i).value_from IS NOT NULL) THEN
510                       l_dim_wt_vol_uom_ok := true;
511              END IF;
512 
513              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
514                  AND g_lane_parameters(i).parameter_name = 'DIM_UOM'
515                  AND g_lane_parameters(i).value_from IS NOT NULL) THEN
516                       l_dim_wt_dim_uom_ok := true;
517              END IF;
518 
519              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
520                  AND g_lane_parameters(i).parameter_name = 'MIN_PACKAGE_VOLUME') THEN
521                    IF (g_lane_parameters(i).value_from IS NULL) THEN
522 		     g_lane_parameters(i).value_from := '0';
523                    ELSIF (fnd_number.canonical_to_number(g_lane_parameters(i).value_from) <= 0) THEN
524                      fte_freight_pricing_util.print_msg(l_log_level,'dim_wt min_package_volume '||g_lane_parameters(i).value_from||' set to 0');
525 		     g_lane_parameters(i).value_from := '0';
526                    ELSE
527 		     IF (g_lane_parameters(i).uom_code is null) THEN
528                         fte_freight_pricing_util.print_msg(l_log_level,'dim_wt min_package_volume uom_code null');
529                         raise fte_freight_pricing_util.g_invalid_uom_code;
530                      END IF;
531                    END IF;
532              END IF;
533 
534             fte_freight_pricing_util.print_msg(l_log_level,'end loop i='||i);
535             EXIT WHEN i >=g_lane_parameters.LAST;
536             i := g_lane_parameters.NEXT(i);
537          END LOOP;
538       END IF;
539       fte_freight_pricing_util.print_msg(l_log_level,'after loop --2 ');
540 
541       IF (l_dim_wt_factor_ok AND l_dim_wt_wt_uom_ok AND l_dim_wt_vol_uom_ok AND l_dim_wt_dim_uom_ok ) THEN
542           g_special_flags.dim_wt_flag :='Y';
543      -- ELSE
544 --          load_carrier_dim_weight_params(p_lane_id => l_lane_id ,
545 --                                         p_service_code => p_service_code,
546 --                                         x_carrier_dim_weight_rec => l_carrier_dim_weight_rec ,
547 --                                         x_return_status => l_return_status
548 --                                         );
549 --
550       END IF;
551 
552       fte_freight_pricing_util.print_msg(l_log_level,'after loop --3 ');
553 
554       IF (g_special_flags.deficit_wt_flag = 'Y') THEN
555          IF (l_wt_break_cnt = 0) THEN
556             raise fte_freight_pricing_util.g_weight_break_not_found;
557          END IF;
558          IF (l_invalid_df_wt_break_found) THEN
559            raise fte_freight_pricing_util.g_invalid_wt_break;
560 	 END IF;
561       END IF;
562 
563       fte_freight_pricing_util.print_msg(l_log_level,'after loop --4 ');
564 
565       fte_freight_pricing_util.unset_method(l_log_level,'validate_parameters');
566    EXCEPTION
567       WHEN fte_freight_pricing_util.g_invalid_uom_code THEN
568            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
569            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_invalid_uom_code');
570            fte_freight_pricing_util.unset_method(l_log_level,'validate_parameters');
571       WHEN fte_freight_pricing_util.g_weight_break_not_found THEN
572            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
573            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_weight_break_not_found');
574            fte_freight_pricing_util.unset_method(l_log_level,'validate_parameters');
575       WHEN fte_freight_pricing_util.g_invalid_wt_break THEN
576            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
577            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_invalid_wt_break');
578            fte_freight_pricing_util.unset_method(l_log_level,'validate_parameters');
579       WHEN others THEN
580            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
581            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
582            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
583            fte_freight_pricing_util.unset_method(l_log_level,'validate_parameters');
584   END validate_parameters;
585 
586  -- End local module --
587 
588  BEGIN
589    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
590    fte_freight_pricing_util.reset_dbg_vars;
591    fte_freight_pricing_util.set_method(l_log_level,'initialize');
592    fte_freight_pricing_util.print_msg(l_log_level,'p_lane_id: '||p_lane_id);
593 
594    fte_freight_pricing_util.set_location(p_loc=>'load_parameters');
595 
596    g_lane_parameters.DELETE;
597 
598    OPEN c_lane_param(p_lane_id);
599    LOOP
600      FETCH  c_lane_param INTO l_lane_param_rec;
601      EXIT WHEN c_lane_param%NOTFOUND;
602      --g_lane_parameters(l_lane_param_rec.parameter_instance_id) := l_lane_param_rec;
603      g_lane_parameters(i) := l_lane_param_rec;
604      --check_for_special_conditions(l_lane_param_rec);
605      i := i +1;
606    END LOOP;
607    CLOSE c_lane_param;
608 
609    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'parameters before validation');
610    print_params;
611    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'===>g_lane_parameters.COUNT = '||g_lane_parameters.COUNT);
612 
613    g_special_flags.lane_id               := p_lane_id;
614    g_special_flags.lane_function         := 'NONE';
615    g_special_flags.dim_wt_flag           := 'N';
616    g_special_flags.minimum_charge_flag   := 'N';
617    g_special_flags.parcel_hundredwt_flag := 'N';
618    g_special_flags.flat_containerwt_flag := 'Y';
619    g_special_flags.deficit_wt_flag       := 'N';
620 
621    validate_parameters(x_return_status => l_return_status);
622 
623    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
624        l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
625                raise fte_freight_pricing_util.g_param_validation_failed;
626    END IF;
627 
628    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'parameters after validation');
629    print_params;
630    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_INF,'===>g_lane_parameters.COUNT = '||g_lane_parameters.COUNT);
631    print_special_flags;
632 
633    fte_freight_pricing_util.set_location(p_loc=>'load_rules');
634    load_rules(
635           p_lane_id    =>  p_lane_id,
636           p_lane_function  =>  g_special_flags.lane_function,
637           x_return_status  =>  l_return_status);
638 
639           IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
640                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
641                        raise fte_freight_pricing_util.g_load_rules_failed;
642           END IF;
643 
644    print_rules;
645 
646    x_lane_function   := g_special_flags.lane_function;
647 
648    FTE_QP_ENGINE.clear_qp_input(x_return_status => l_return_status);
649    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
650        l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
651                raise fte_freight_pricing_util.g_clear_qp_input_failed;
652    END IF;
653 
654    fte_freight_pricing_util.unset_method(l_log_level,'initialize');
655   EXCEPTION
656     WHEN fte_freight_pricing_util.g_clear_qp_input_failed THEN
657          x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
658          fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_clear_qp_input_failed');
659          fte_freight_pricing_util.unset_method(l_log_level,'initialize');
660     WHEN fte_freight_pricing_util.g_param_validation_failed THEN
661          x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
662          fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_param_validation_failed');
663          fte_freight_pricing_util.unset_method(l_log_level,'initialize');
664     WHEN fte_freight_pricing_util.g_load_rules_failed THEN
665          x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
666          fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_load_rules_failed');
667          fte_freight_pricing_util.unset_method(l_log_level,'initialize');
668     WHEN others THEN
669         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
670         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
671         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
672         fte_freight_pricing_util.unset_method(l_log_level,'initialize');
673 
674 END initialize;
675 
676 
677 PROCEDURE calc_gross_weight (p_top_level_rec  IN fte_freight_pricing.shpmnt_content_rec_type,
678                             p_target_uom   IN  VARCHAR2  DEFAULT NULL,
679                             x_gross_wt     OUT NOCOPY  NUMBER,
680                             x_rolledup_wt  OUT NOCOPY  NUMBER,
681                             x_cont_tare_wt OUT NOCOPY  NUMBER,
682                             x_uom          OUT NOCOPY  VARCHAR2,
683                             x_return_status   OUT NOCOPY  VARCHAR2)
684   IS
685     j                NUMBER;
686     l_target_uom     VARCHAR2(30);
687     l_temp_wt        NUMBER :=0;
688     l_temp_tare_wt   NUMBER :=0;
689     l_temp_uom       VARCHAR2(30);
690     l_gross_wt       NUMBER;
691     l_gross_wt_uom   VARCHAR2(30);
692     l_return_status  VARCHAR2(1);
693   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
694   l_method_name VARCHAR2(50) := 'calc_gross_weight';
695  BEGIN
696    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
697    fte_freight_pricing_util.reset_dbg_vars;
698    fte_freight_pricing_util.set_method(l_log_level,'calc_gross_weight');
699 
700         l_target_uom  := p_target_uom;
701 
702         IF (p_top_level_rec.container_flag = 'N') THEN
703           IF (l_target_uom IS NOT NULL) THEN
704                l_temp_wt  := WSH_WV_UTILS.convert_uom( p_top_level_rec.wdd_weight_uom_code,
705                                                       l_target_uom,
706                                                       p_top_level_rec.wdd_gross_weight,
707                                                       0);  -- Within same UOM class
708                --l_temp_wt  := WSH_WV_UTILS.convert_uom( p_top_level_rec.weight_uom,
709                  --                                     l_target_uom,
710                    --                                   p_top_level_rec.gross_weight,
711                      --                                 0);  -- Within same UOM class
712                l_temp_uom := l_target_uom;
713 
714           ELSE
715                l_temp_wt  := p_top_level_rec.wdd_gross_weight;
716                --l_temp_wt  := p_top_level_rec.gross_weight;
717                l_temp_uom := p_top_level_rec.weight_uom;
718           END IF;
719                x_rolledup_wt  := null;
720                x_gross_wt     := l_temp_wt;
721                x_uom          := l_temp_uom;
722         ELSE
723             --  This is a container item
724             j := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
725             IF (j IS NOT NULL) THEN
726             LOOP
727                 IF (FTE_FREIGHT_PRICING.g_rolledup_lines(j).master_container_id
728                                     = p_top_level_rec.content_id) THEN
729 
730                      fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'j ='||j);
731                       IF (l_target_uom IS NULL) THEN
732                            l_target_uom  := FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom;
733                       END IF;
734 
735                       IF (FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom <> l_target_uom ) THEN
736                           l_temp_wt   :=  l_temp_wt + WSH_WV_UTILS.convert_uom(FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom,
737                                                                                l_target_uom,
738                                                                                FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity,
739                                                                                0);  -- Within same UOM class
740                       ELSE
741                           l_temp_wt   := l_temp_wt + FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity;
742                       END IF;
743                       l_temp_uom := l_target_uom;
744                 END IF;
745             EXIT WHEN j >= FTE_FREIGHT_PRICING.g_rolledup_lines.LAST;
746                       j := FTE_FREIGHT_PRICING.g_rolledup_lines.NEXT(j);
747             END LOOP;
748             END IF;
749 
750             x_rolledup_wt  := l_temp_wt;
751             x_uom          := l_temp_uom;
752 
753             -- Now calculate the gross weight for the container
754 
755             l_gross_wt      := p_top_level_rec.wdd_gross_weight;
756             l_gross_wt_uom  := p_top_level_rec.wdd_weight_uom_code;
757             --l_gross_wt      := fte_freight_pricing.g_shipment_line_rows(p_top_level_rec.content_id).gross_weight;
758             --l_gross_wt_uom  := fte_freight_pricing.g_shipment_line_rows(p_top_level_rec.content_id).weight_uom_code;
759 
760                 IF ( l_temp_uom <> p_top_level_rec.weight_uom ) THEN
761                      l_temp_tare_wt     := WSH_WV_UTILS.convert_uom( p_top_level_rec.weight_uom,
762                                                                       l_temp_uom,
763                                                                       p_top_level_rec.gross_weight,
764                                                                       0);  -- Within same UOM class
765                 ELSE
766                      l_temp_tare_wt     := p_top_level_rec.gross_weight;
767                 END IF;
768 
769             IF (l_gross_wt IS NOT NULL) THEN
770                 IF (l_gross_wt_uom <> l_temp_uom) THEN
771                       x_gross_wt     := WSH_WV_UTILS.convert_uom(l_gross_wt_uom,
772                                                                  l_temp_uom,
773                                                                  l_gross_wt,
774                                                                  0);  -- Within same UOM class
775                 ELSE
776                       x_gross_wt    := l_gross_wt;
777                 END IF;
778 
779             ELSE
780 
781                 /*
782                 IF ( l_temp_uom <> p_top_level_rec.weight_uom ) THEN
783                      x_gross_wt     := l_temp_wt + WSH_WV_UTILS.convert_uom( p_top_level_rec.weight_uom,
784                                                                       l_temp_uom,
785                                                                       p_top_level_rec.gross_weight,
786                                                                       0);  -- Within same UOM class
787                 ELSE
788                      x_gross_wt     := l_temp_wt + p_top_level_rec.gross_weight;
789                 END IF;
790                 */
791                 x_gross_wt     := l_temp_wt + l_temp_tare_wt;
792 
793             END IF;
794             x_cont_tare_wt := l_temp_tare_wt;
795 
796         END IF;
797 
798        fte_freight_pricing_util.unset_method(l_log_level,'calc_gross_weight');
799 
800       EXCEPTION
801       WHEN others THEN
802            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
803            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
804            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
805            fte_freight_pricing_util.unset_method(l_log_level,'calc_gross_weight');
806   END calc_gross_weight;
807 
808 
809 
810 -- This function is used while pattern processing to check if certain unsupported patterns exist
811 -- for the selected lane function.
812 -- This function checks the pattern number and the special flags. It returns 'OK' or 'NOT_OK'.
813 -- TODO : throw a standard error code which can be translated to a message.
814 -- FUNCTION detect_function_ineligible (pattern  IN NUMBER,
815 --                                     x_return_status OUT VARCHAR2 ) RETURN VARCHAR2;
816 
817 -- Used to check for and calculate dimensional wt. for a given top level row.
818 -- If dimensional wt is greater than gross wt of top level row, replace gross wt with dimensional wt.
819 -- Also prorate new gross wt. across rollup lines (ie. bump up line wt. appropriately)
820 -- NOTE : dimensional wt calc. is not supported for loose items.
821 
822 
823 PROCEDURE apply_dimensional_weight (
824           p_lane_id              IN NUMBER,
825           p_carrier_id           IN NUMBER,
826           p_service_code         IN VARCHAR2,
827           p_top_level_rec        IN OUT NOCOPY   fte_freight_pricing.shpmnt_content_rec_type,
828           p_rolledup_rows        IN OUT NOCOPY   fte_freight_pricing.rolledup_line_tab_type,
829           x_return_status        OUT NOCOPY              VARCHAR2 )
830 IS
831     i  NUMBER;
832     j  NUMBER;
833 
834     dim_wt_enabled  VARCHAR2(1) := NULL;
835     dim_wt_factor   NUMBER :=0;
836     wt_uom_param    VARCHAR2(30);
837     vol_uom_param   VARCHAR2(30);
838     dim_uom_param   VARCHAR2(30);
839     min_vol_param   NUMBER ;
840     min_vol_uom     VARCHAR2(30);
841     dim_wt          NUMBER :=0;
842     converted_wt    NUMBER :=0;
843     converted_vol   NUMBER :=0;
844     original_gross_wt  NUMBER :=0;
845     converted_length  NUMBER :=0;
846     converted_width NUMBER :=0;
847     converted_height NUMBER :=0;
848     l_return_status   VARCHAR2(1);
849     l_gross_wt       NUMBER :=0;
850     l_rolledup_wt    NUMBER :=0;
851     l_cont_tare_wt   NUMBER :=0;
852     l_cont_volume    NUMBER :=0;
853     l_wt_uom         VARCHAR2(30);
854     l_parcel_flag    VARCHAR2(1) := 'N';
855     l_lane_id    NUMBER;
856     l_carrier_dim_weight_rec carrier_dim_weight_rec_type;
857     l_log_level  NUMBER := fte_freight_pricing_util.G_LOG;
858     l_method_name VARCHAR2(50) := 'apply_dimensional_weight';
859 
860   -- local module --
861   PROCEDURE prorate_rolledup_weights(p_content_id    IN  NUMBER,
862                                      --p_ratio         IN  NUMBER,
863                                      p_ratio_num     IN  NUMBER,
864                                      p_ratio_denom   IN  NUMBER,
865                                      x_rolledup_rows IN OUT NOCOPY   fte_freight_pricing.rolledup_line_tab_type,
866                                      x_return_status        OUT NOCOPY   VARCHAR2 )
867   IS
868      i NUMBER;
869 
870   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
871   l_return_status VARCHAR2(1);
872 
873  BEGIN
874    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
875    fte_freight_pricing_util.reset_dbg_vars;
876    fte_freight_pricing_util.set_method(l_log_level,'prorate_rolledup_weights');
877         i := x_rolledup_rows.FIRST;
878         IF (i IS NOT NULL) THEN
879           LOOP
880              IF (x_rolledup_rows(i).master_container_id = p_content_id
881                   AND x_rolledup_rows(i).rate_basis = fte_freight_pricing.G_WEIGHT_BASIS ) THEN
882                  --x_rolledup_rows(i).line_quantity := x_rolledup_rows(i).line_quantity * p_ratio;
883                  x_rolledup_rows(i).line_quantity := (x_rolledup_rows(i).line_quantity * p_ratio_num)/p_ratio_denom;
884              END IF;
885           EXIT WHEN i >= x_rolledup_rows.LAST;
886            i := x_rolledup_rows.NEXT(i);
887           END LOOP;
888         END IF;
889 
890 
891         i := fte_freight_pricing.g_rolledup_lines.FIRST;
892         IF (i IS NOT NULL) THEN
893           LOOP
894              IF (fte_freight_pricing.g_rolledup_lines(i).master_container_id = p_content_id
895                   AND x_rolledup_rows(i).rate_basis = fte_freight_pricing.G_WEIGHT_BASIS ) THEN
896                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Old wt ='||fte_freight_pricing.g_rolledup_lines(i).line_quantity);
897                  --fte_freight_pricing.g_rolledup_lines(i).line_quantity := fte_freight_pricing.g_rolledup_lines(i).line_quantity * p_ratio;
898                  fte_freight_pricing.g_rolledup_lines(i).line_quantity := (fte_freight_pricing.g_rolledup_lines(i).line_quantity * p_ratio_num)/p_ratio_denom;
899                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'New wt ='||fte_freight_pricing.g_rolledup_lines(i).line_quantity);
900              END IF;
901           EXIT WHEN i >= fte_freight_pricing.g_rolledup_lines.LAST;
902            i := fte_freight_pricing.g_rolledup_lines.NEXT(i);
903           END LOOP;
904         END IF;
905    fte_freight_pricing_util.unset_method(l_log_level,'prorate_rolledup_weights');
906 
907    EXCEPTION
908       WHEN others THEN
909            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
910            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
911            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
912            fte_freight_pricing_util.unset_method(l_log_level,'prorate_rolledup_weights');
913 
914   END prorate_rolledup_weights;
915   -- end local module --
916 
917 
918  BEGIN
919    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
920    fte_freight_pricing_util.reset_dbg_vars;
921    fte_freight_pricing_util.set_method(l_log_level,'apply_dimensional_weight');
922 
923      --exception point : NO_PARAMS_FOUND
924      IF (g_lane_parameters.COUNT = 0) THEN
925         raise fte_freight_pricing_util.g_no_params_found;
926      END IF;
927 
928     --Need to remove this check as part of R12.
929     --Lane parameters can be defined at Carrier or Carrier service level
930     --So this check, which verifies flag set at Lane Parameters level stops
931     --from loading those carrier/service level parameters
932     /*IF (g_special_flags.dim_wt_flag <> 'Y') THEN
933          dim_wt_enabled := 'N';
934          fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'dimensional weight is NOT enabled ');
935          fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
936          RETURN;
937      ELSE*/
938          dim_wt_enabled := 'Y';
939          fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'dimensional weight is enabled ');
940      --END IF;
941 
942      -- get dimensional wt specific parameters
943      IF (g_special_flags.dim_wt_flag = 'Y') THEN
944          i := g_lane_parameters.FIRST;
945          IF (i IS NOT NULL) THEN
946          LOOP
947              l_lane_id := g_lane_parameters(i).lane_id;
948              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
949                  AND g_lane_parameters(i).parameter_name = 'FACTOR') THEN
950                  dim_wt_factor := nvl(fnd_number.canonical_to_number(g_lane_parameters(i).value_from),194);
951                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt_factor = '||dim_wt_factor);
952              END IF;
953              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
954                  AND g_lane_parameters(i).parameter_name = 'WT_UOM') THEN
955                  wt_uom_param := g_lane_parameters(i).value_from;
956                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'wt_uom_param = '||wt_uom_param);
957              END IF;
958              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
959                  AND g_lane_parameters(i).parameter_name = 'VOL_UOM') THEN
960                  vol_uom_param := g_lane_parameters(i).value_from;
961                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'vol_uom_param = '||vol_uom_param);
962              END IF;
963              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
964                  AND g_lane_parameters(i).parameter_name = 'DIM_UOM') THEN
965                  dim_uom_param := g_lane_parameters(i).value_from;
966                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_uom_param = '||dim_uom_param);
967              END IF;
968              IF (g_lane_parameters(i).parameter_sub_type = 'DIM_WT'
969                  AND g_lane_parameters(i).parameter_name = 'MIN_PACKAGE_VOLUME') THEN
970                  min_vol_param := fnd_number.canonical_to_number(g_lane_parameters(i).value_from);
971                  min_vol_uom   := g_lane_parameters(i).uom_code;
972                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'min_vol_param = '||min_vol_param);
973                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'min_vol_uom = '||min_vol_uom);
974              END IF;
975              min_vol_uom   := g_lane_parameters(i).uom_code;
976          EXIT WHEN (i >= g_lane_parameters.LAST );
977              i := g_lane_parameters.NEXT(i);
978          END LOOP;
979          END IF;
980     END IF;
981      -- Added for 12i. Check if any of the dim params is null at lane level then load the params
982      -- from carrier/carrier service levels.
983      IF ( (dim_wt_factor IS NULL) OR (wt_uom_param IS NULL) OR (vol_uom_param IS NULL) OR
984          (dim_uom_param IS NULL)  ) THEN
985 
986           --  OR (min_vol_uom IS NULL)
987 
988 	--R12 Hiding Project
989 	dim_wt_enabled := 'N';
990 
991 	--R12 Hiding Project
992 	/*
993           load_carrier_dim_weight_params(p_lane_id => l_lane_id ,
994                                          p_carrier_id => p_carrier_id,
995                                          p_service_code => p_service_code,
996                                          x_carrier_dim_weight_rec => l_carrier_dim_weight_rec ,
997                                          x_return_status => l_return_status
998                                          );
999           IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
1000              l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
1001              raise fte_freight_pricing_util.g_no_params_found;
1002           END IF;
1003 
1004           IF ( (l_carrier_dim_weight_rec.dim_factor IS NOT NULL) AND
1005               (l_carrier_dim_weight_rec.dim_weight_uom IS NOT NULL) AND
1006               (l_carrier_dim_weight_rec.dim_volume_uom IS NOT NULL) AND
1007               (l_carrier_dim_weight_rec.dim_dimension_uom IS NOT NULL)
1008                ) THEN
1009                 dim_wt_factor := nvl(l_carrier_dim_weight_rec.dim_factor,194);
1010                 wt_uom_param  := l_carrier_dim_weight_rec.dim_weight_uom;
1011                 vol_uom_param := l_carrier_dim_weight_rec.dim_volume_uom;
1012                 dim_uom_param := l_carrier_dim_weight_rec.dim_dimension_uom;
1013                 min_vol_param := l_carrier_dim_weight_rec.dim_min_volume;
1014                 dim_wt_enabled := 'Y';
1015           ELSE
1016                dim_wt_enabled := 'N';
1017           END IF;
1018 	  */
1019       END IF ;
1020 
1021 
1022       fte_freight_pricing_util.print_msg(l_log_level,'After loading . dim_wt_enabled='||dim_wt_enabled);
1023       fte_freight_pricing_util.print_msg(l_log_level,'p_top_level_rec.length='||p_top_level_rec.length);
1024       fte_freight_pricing_util.print_msg(l_log_level,'p_top_level_rec.width ='||p_top_level_rec.width );
1025       fte_freight_pricing_util.print_msg(l_log_level,'p_top_level_rec.height='||p_top_level_rec.height);
1026       fte_freight_pricing_util.print_msg(l_log_level,'min_vol_param='||min_vol_param);
1027 
1028      --check if container/loose item volume is greater than min package volume parameter.
1029      --if volume is null and length-width-height are not null
1030      --then L*W*H should be used instead AG 5/29
1031 
1032      --IF (dim_wt_enabled = 'Y' AND p_top_level_rec.volume IS NOT NULL
1033       --      AND nvl(min_vol_param,0) >0 AND min_vol_uom IS NOT NULL ) THEN
1034      --IF (dim_wt_enabled = 'Y' AND nvl(min_vol_param,0) >0 AND min_vol_uom IS NOT NULL ) THEN
1035 
1036      IF (dim_wt_enabled = 'Y' AND  nvl(min_vol_param,0) >= 0  ) THEN
1037 
1038      fte_freight_pricing_util.print_msg(l_log_level,'dim_wt_enabled and min_vol_param is='||min_vol_param||' and min_vol_uom is='||min_vol_uom);
1039      fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'p_top_level_rec.volume = '||p_top_level_rec.volume);
1040 
1041       IF p_top_level_rec.volume IS NOT NULL THEN
1042      fte_freight_pricing_util.print_msg(l_log_level,'use volume');
1043         -- Use volume
1044            IF (p_top_level_rec.volume_uom <> min_vol_uom ) THEN
1045               --convert input vol uom to param vol uom
1046                converted_vol := WSH_WV_UTILS.convert_uom(p_top_level_rec.volume_uom,
1047                                                        min_vol_uom,
1048                                                        p_top_level_rec.volume,
1049                                                        0);  -- Within same UOM class
1050            ELSE
1051                 converted_vol := p_top_level_rec.volume;
1052            END IF;
1053 
1054       ELSIF (p_top_level_rec.length IS NOT NULL AND p_top_level_rec.width IS NOT NULL AND p_top_level_rec.height IS NOT NULL) THEN
1055      fte_freight_pricing_util.print_msg(l_log_level,'use L*W*H');
1056         -- use L*W*H
1057            IF (p_top_level_rec.dim_uom <> dim_uom_param ) THEN
1058               --convert input wt uom to param wt uom
1059                converted_length := WSH_WV_UTILS.convert_uom(p_top_level_rec.dim_uom,
1060                                                        dim_uom_param,
1061                                                        nvl(p_top_level_rec.length,0),
1062                                                        0);  -- Within same UOM class
1063                converted_width := WSH_WV_UTILS.convert_uom(p_top_level_rec.dim_uom,
1064                                                        dim_uom_param,
1065                                                        nvl(p_top_level_rec.width,0),
1066                                                        0);  -- Within same UOM class
1067 
1068                converted_height := WSH_WV_UTILS.convert_uom(p_top_level_rec.dim_uom,
1069                                                        dim_uom_param,
1070                                                        nvl(p_top_level_rec.height,0),
1071                                                        0);  -- Within same UOM class
1072            ELSE
1073                converted_length := p_top_level_rec.length;
1074                converted_width  := p_top_level_rec.width;
1075                converted_height := p_top_level_rec.height;
1076 
1077            END IF;
1078            l_cont_volume := converted_length*converted_width*converted_height;
1079 
1080            -- The assumption here is that dim_uom and vol_uom parameter for dim_wt are in synch.
1081 
1082            IF ( vol_uom_param <> min_vol_uom ) THEN
1083                 --convert input vol uom to param vol uom
1084                 converted_vol := WSH_WV_UTILS.convert_uom(vol_uom_param,
1085                                               min_vol_uom,
1086                                               l_cont_volume,
1087                                               --converted_length*converted_width*converted_height,
1088                                               0);  -- Within same UOM class
1089            ELSE
1090                 --converted_vol := converted_length*converted_width*converted_height;
1091                 converted_vol := l_cont_volume;
1092            END IF;
1093 
1094       END IF;
1095      END IF;
1096 
1097      fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'converted_vol = '||converted_vol);
1098 
1099       IF (converted_vol <= min_vol_param) THEN
1100          --fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'dimensional weight is less than min package wt ');
1101          fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Package volume is less than minimum package volume parameter for dimensional wt ');
1102          fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1103          RETURN;
1104       END IF;
1105 
1106 IF (dim_wt_enabled = 'Y' ) THEN
1107 
1108      --calculate gross_wt and rolledup wt converted to wt_uom_param
1109      calc_gross_weight (p_top_level_rec   => p_top_level_rec,
1110                         p_target_uom      => wt_uom_param,
1111                         x_gross_wt        => l_gross_wt,
1112                         x_rolledup_wt     => l_rolledup_wt,
1113                         x_cont_tare_wt    => l_cont_tare_wt,
1114                         x_uom             => l_wt_uom,
1115                         x_return_status   => l_return_status);
1116 
1117      fte_freight_pricing_util.set_location(p_loc=>'after calc_gross_weight ');
1118            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
1119                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
1120                         raise fte_freight_pricing_util.g_calc_gross_wt_failed;
1121            ELSE
1122                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_gross_wt = '||l_gross_wt);
1123                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_rolledup_wt = '||l_rolledup_wt);
1124                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_wt_uom = '||l_wt_uom);
1125            END IF;
1126 
1127      -- Now calculate the dimensional wt from the lane parameters
1128 
1129      IF (p_top_level_rec.volume IS NOT NULL) THEN
1130         -- Use volume
1131            IF (p_top_level_rec.volume_uom <> vol_uom_param ) THEN
1132               --convert input vol uom to param vol uom
1133                converted_vol := WSH_WV_UTILS.convert_uom(p_top_level_rec.volume_uom,
1134                                                        vol_uom_param,
1135                                                        p_top_level_rec.volume,
1136                                                        0);  -- Within same UOM class
1137                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'converted_vol = '||converted_vol);
1138                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'vol_uom_param = '||vol_uom_param);
1139                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt_factor = '||dim_wt_factor);
1140                dim_wt := (converted_vol)/dim_wt_factor;
1141            ELSE
1142                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'vol = '||p_top_level_rec.volume);
1143                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'vol_uom_param = '||vol_uom_param);
1144                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt_factor = '||dim_wt_factor);
1145                dim_wt := (p_top_level_rec.volume)/dim_wt_factor;
1146            END IF;
1147            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt = '||dim_wt);
1148      ELSIF (p_top_level_rec.length IS NOT NULL AND p_top_level_rec.width IS NOT NULL AND p_top_level_rec.height IS NOT NULL) THEN
1149         -- use L*W*H
1150            IF (p_top_level_rec.dim_uom <> dim_uom_param ) THEN
1151               --convert input wt uom to param wt uom
1152                converted_length := WSH_WV_UTILS.convert_uom(p_top_level_rec.dim_uom,
1153                                                        dim_uom_param,
1154                                                        nvl(p_top_level_rec.length,0),
1155                                                        0);  -- Within same UOM class
1156                converted_width := WSH_WV_UTILS.convert_uom(p_top_level_rec.dim_uom,
1157                                                        dim_uom_param,
1158                                                        nvl(p_top_level_rec.width,0),
1159                                                        0);  -- Within same UOM class
1160 
1161                converted_height := WSH_WV_UTILS.convert_uom(p_top_level_rec.dim_uom,
1162                                                        dim_uom_param,
1163                                                        nvl(p_top_level_rec.height,0),
1164                                                        0);  -- Within same UOM class
1165 
1166                dim_wt := (converted_length*converted_width*converted_height)/dim_wt_factor;
1167            ELSE
1168                dim_wt := (p_top_level_rec.length * p_top_level_rec.width * p_top_level_rec.height)/dim_wt_factor;
1169            END IF;
1170 
1171      ELSE
1172         -- Can't process. No volume or L-W-H found.
1173         raise fte_freight_pricing_util.g_no_volume_found;
1174      END IF;
1175 
1176      IF (p_top_level_rec.container_flag = 'N') THEN
1177         --the gross wt is the original wt
1178          fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'content_id = '||p_top_level_rec.content_id);
1179          fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt = '||dim_wt);
1180          fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_gross_wt = '||l_gross_wt);
1181 
1182          IF ( dim_wt > l_gross_wt) THEN
1183             -- increase the top level gross wt by the ratio of dim_wt to l_gross_wt (original weight)
1184             -- dim_wt and l_gross_wt should already be in the same uom
1185             fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Applying dimensional wt');
1186             fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Old wt ='||p_top_level_rec.gross_weight);
1187             p_top_level_rec.gross_weight := (p_top_level_rec.gross_weight * dim_wt)/l_gross_wt;
1188             p_top_level_rec.wdd_gross_weight := (p_top_level_rec.wdd_gross_weight * dim_wt)/l_gross_wt;
1189             fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'New wt ='||p_top_level_rec.gross_weight);
1190 
1191          ELSE
1192             fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'No need to apply dimensional wt ');
1193          END IF;
1194 
1195     ELSE
1196          -- this is a container
1197 
1198          l_parcel_flag := isParcel;
1199          IF (l_parcel_flag = 'Y') THEN
1200              --for parcel we need to consider the gross weight calculated above
1201              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'this is a parcel case');
1202              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'content_id = '||p_top_level_rec.content_id);
1203              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt = '||dim_wt);
1204              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_gross_wt = '||l_gross_wt);
1205              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_rolledup_wt = '||l_rolledup_wt);
1206 
1207              IF ( dim_wt > l_gross_wt) THEN
1208                 fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Applying dimensional wt');
1209                 -- increase the rolled up lines and the top level gross wt by the ratio
1210                 -- l_rolledup_wt and dim_wt should already be in the same uom
1211 
1212                 fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Old wt ='||p_top_level_rec.gross_weight);
1213                 p_top_level_rec.gross_weight := (p_top_level_rec.gross_weight * dim_wt)/l_gross_wt;
1214          	p_top_level_rec.wdd_gross_weight := (p_top_level_rec.wdd_gross_weight * dim_wt)/l_gross_wt;
1215                 fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'New wt ='||p_top_level_rec.gross_weight);
1216 
1217                 --loop over the rolled up lines and prorate
1218                 prorate_rolledup_weights(p_content_id    => p_top_level_rec.content_id,
1219                                      --p_ratio             => (dim_wt/l_gross_wt),
1220                                      p_ratio_num         => dim_wt,
1221                                      p_ratio_denom       => l_gross_wt,
1222                                      x_rolledup_rows     => p_rolledup_rows,
1223                                      x_return_status     => l_return_status);
1224 
1225                 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
1226                      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
1227                          raise fte_freight_pricing_util.g_prorate_failed;
1228                 END IF;
1229 
1230              ELSE
1231                 fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'No need to apply dimensional wt ');
1232              END IF;
1233 
1234          ELSE
1235              --for other than parcel we need to consider the rolled up wt only
1236              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'this is not a parcel case');
1237              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'content_id = '||p_top_level_rec.content_id);
1238              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'dim_wt = '||dim_wt);
1239              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_gross_wt = '||l_gross_wt);
1240 
1241              --IF ( dim_wt > l_rolledup_wt) THEN
1242              IF ( dim_wt > l_gross_wt) THEN
1243                 fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Applying dimensional wt');
1244                 -- increase the rolled up lines by the ration
1245                 -- l_rolledup_wt and dim_wt should already be in the same uom
1246 
1247          	p_top_level_rec.wdd_gross_weight := (p_top_level_rec.wdd_gross_weight * dim_wt)/l_gross_wt;
1248 
1249                 --loop over the rolled up lines and prorate
1250                 prorate_rolledup_weights(p_content_id    => p_top_level_rec.content_id,
1251                                      --p_ratio             => (dim_wt/l_rolledup_wt),
1252                                      --p_ratio             => (dim_wt/l_gross_wt),
1253                                      p_ratio_num         => dim_wt,
1254                                      p_ratio_denom       => l_gross_wt,
1255                                      --p_ratio             => (dim_wt/l_cont_tare_wt),
1256                                      x_rolledup_rows     => p_rolledup_rows,
1257                                      x_return_status     => l_return_status);
1258 
1259                 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
1260                      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
1261                          raise fte_freight_pricing_util.g_prorate_failed;
1262                 END IF;
1263 
1264              ELSE
1265                 fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'No need to apply dimensional wt ');
1266              END IF;
1267 
1268          END IF;
1269    END IF;
1270 ELSE
1271    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,' dim_wt_enabled is N .No need to apply dimensional wt ');
1272 END IF;
1273 
1274    fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1275 
1276    EXCEPTION
1277       WHEN fte_freight_pricing_util.g_no_params_found THEN
1278            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1279            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'no_parameters found');
1280            fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1281       WHEN fte_freight_pricing_util.g_no_weights_found THEN
1282            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1283            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_weights_found ');
1284            fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1285       WHEN fte_freight_pricing_util.g_no_volume_found THEN
1286            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1287            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_volume_found ');
1288            fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1289       WHEN fte_freight_pricing_util.g_calc_gross_wt_failed THEN
1290            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1291            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_calc_gross_wt_failed ');
1292            fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1293       WHEN fte_freight_pricing_util.g_prorate_failed THEN
1294            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1295            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_volume_found ');
1296            fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1297       WHEN others THEN
1298            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1299            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
1300            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
1301            fte_freight_pricing_util.unset_method(l_log_level,'apply_dimensional_weight');
1302 
1303 
1304 END apply_dimensional_weight;
1305 
1306 
1307 FUNCTION isLTL RETURN VARCHAR2 IS
1308 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1309  BEGIN
1310      IF (g_special_flags.lane_function = 'LTL') THEN
1311         RETURN 'Y';
1312      ELSE
1313         RETURN 'N';
1314      END IF;
1315 END;
1316 
1317 FUNCTION isParcel RETURN VARCHAR2 IS
1318 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1319  BEGIN
1320      IF (g_special_flags.lane_function = 'PARCEL') THEN
1321         RETURN 'Y';
1322      ELSE
1323         RETURN 'N';
1324      END IF;
1325 END;
1326 
1327 --Added for 12i to support dim weights are carrier service and carrier level
1328 PROCEDURE load_carrier_dim_weight_params(p_lane_id                IN  NUMBER ,
1329                                          p_carrier_id             IN  NUMBER,
1330                                          p_service_code           IN  VARCHAR2,
1331                                          x_carrier_dim_weight_rec OUT NOCOPY carrier_dim_weight_rec_type ,
1332                                          x_return_status          OUT NOCOPY VARCHAR2
1333                                          )
1334 IS
1335   CURSOR c_carrier_dim_params(c_carrier_id IN NUMBER)  IS
1336   SELECT
1337   wc.dim_dimensional_factor,
1338   wc.dim_weight_uom,
1339   wc.dim_volume_uom,
1340   wc.dim_dimension_uom,
1341   wc.dim_min_pack_vol
1342   FROM
1343     wsh_carriers wc
1344   WHERE
1345    wc.carrier_id=p_carrier_id;
1346 
1347   CURSOR c_carrier_service_dim_params(c_carrier_id IN NUMBER, c_service_code IN VARCHAR2 ) IS
1348   SELECT
1349   wcs.dim_dimensional_factor,
1350   wcs.dim_weight_uom,
1351   wcs.dim_volume_uom,
1352   wcs.dim_dimension_uom,
1353   wcs.dim_min_pack_vol
1354   FROM
1355     wsh_carrier_services wcs
1356   WHERE
1357       wcs.carrier_id = p_carrier_id
1358   AND wcs.service_level = p_service_code;
1359 
1360   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1361   l_method_name VARCHAR2(50) := 'load_carrier_dim_weight_params';
1362   l_carrier_dim_factors carrier_dim_weight_rec_type;
1363 
1364 BEGIN
1365     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1366     fte_freight_pricing_util.set_method(l_log_level,l_method_name);
1367 
1368     fte_freight_pricing_util.print_msg(l_log_level,'p_carrier_id='||p_carrier_id);
1369     fte_freight_pricing_util.print_msg(l_log_level,'p_service_code='||p_service_code);
1370 
1371     IF ( (p_carrier_id IS NOT NULL) AND (p_service_code IS NOT NULL) ) THEN
1372       OPEN c_carrier_service_dim_params (p_carrier_id , p_service_code);
1373       FETCH c_carrier_service_dim_params INTO l_carrier_dim_factors;
1374       -- IF Parameters not found, load them from carrier
1375       IF( ( c_carrier_service_dim_params%NOTFOUND ) OR
1376           (l_carrier_dim_factors.dim_factor IS NULL) OR (l_carrier_dim_factors.dim_weight_uom IS NULL) OR
1377           (l_carrier_dim_factors.dim_volume_uom IS NULL) OR (l_carrier_dim_factors.dim_dimension_uom IS NULL)
1378 
1379          ) THEN
1380              fte_freight_pricing_util.print_msg(l_log_level,'Service Level params not found. Loading from Carrier Level');
1381 
1382              OPEN c_carrier_dim_params (p_carrier_id);
1383              FETCH c_carrier_dim_params INTO l_carrier_dim_factors;
1384              IF c_carrier_dim_params%NOTFOUND THEN
1385                raise fte_freight_pricing_util.g_no_params_found;
1386              END IF;
1387              CLOSE c_carrier_dim_params;
1388       END IF;
1389       CLOSE c_carrier_service_dim_params;
1390     END IF;
1391 
1392     fte_freight_pricing_util.print_msg(l_log_level,'l_carrier_dim_factors.dim_factor ='||l_carrier_dim_factors.dim_factor);
1393     fte_freight_pricing_util.print_msg(l_log_level,'l_carrier_dim_factors.dim_weight_uom ='||l_carrier_dim_factors.dim_weight_uom);
1394     fte_freight_pricing_util.print_msg(l_log_level,'l_carrier_dim_factors.dim_dimension_uom ='||l_carrier_dim_factors.dim_dimension_uom);
1395     fte_freight_pricing_util.print_msg(l_log_level,'l_carrier_dim_factors.dim_volume_uom ='||l_carrier_dim_factors.dim_volume_uom);
1396     fte_freight_pricing_util.print_msg(l_log_level,'l_carrier_dim_factors.dim_min_volume ='||l_carrier_dim_factors.dim_min_volume);
1397 
1398     x_carrier_dim_weight_rec := l_carrier_dim_factors;
1399 
1400 
1401    fte_freight_pricing_util.unset_method(l_log_level,'load_carrier_dim_weight_params');
1402 
1403   EXCEPTION
1404       WHEN fte_freight_pricing_util.g_no_params_found THEN
1405            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1406            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'no_dim_parameters found');
1407            fte_freight_pricing_util.unset_method(l_log_level,'load_carrier_dim_weight_params');
1408 
1409 END load_carrier_dim_weight_params;
1410 
1411 -- This procedure is used to calculate the total wt of the top level rows
1412 -- get total shipment wt. Should take care of conversions.
1413 -- Considers the wt. of the rollup lines instead of the gross wt of the container.
1414 -- used for LTL
1415 PROCEDURE  get_total_shipment_weight(p_top_level_rows    IN   fte_freight_pricing.shpmnt_content_tab_type,
1416                                          x_total_wt          OUT NOCOPY   NUMBER,
1417                                          x_wt_uom            OUT NOCOPY   VARCHAR2,
1418                                          x_return_status     OUT NOCOPY   VARCHAR2)
1419 IS
1420   i                    NUMBER;
1421   j                    NUMBER;
1422   l_temp_wt            NUMBER :=0;
1423   l_target_uom         VARCHAR2(30) := NULL;
1424   l_cnt                NUMBER :=0;
1425   l_content_id         NUMBER;
1426   l_return_status      VARCHAR2(1);
1427 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1428   l_method_name VARCHAR2(50) := 'get_total_shipment_weight';
1429  BEGIN
1430     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1431     fte_freight_pricing_util.reset_dbg_vars;
1432     fte_freight_pricing_util.set_method(l_log_level,'get_total_shipment_weight');
1433 
1434     -- loop over all top level rows
1435     -- get the top level row
1436     --     for the top level row, loop through all rollup lines and add up line_quantities
1437     --      convert the uoms if lines have different uoms
1438     --      the first wt uom encountered becomes the source uom for conversions
1439 
1440 
1441     -- first figure out the target uom
1442     l_target_uom := NULL;
1443     i := p_top_level_rows.FIRST;
1444     --j := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
1445     l_temp_wt :=0;
1446     IF (i IS NOT NULL) THEN
1447     LOOP
1448         l_content_id := p_top_level_rows(i).content_id;
1449         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Top level Id : '||l_content_id);
1450 
1451         -- if top level row is not a container, use its gross wt
1452         IF (p_top_level_rows(i).container_flag = 'N') THEN
1453 
1454              IF (l_target_uom IS NULL) THEN
1455                  l_target_uom  := p_top_level_rows(i).weight_uom;
1456              END IF;
1457 
1458              IF (p_top_level_rows(i).weight_uom <> l_target_uom) THEN
1459                  l_temp_wt   :=  l_temp_wt + WSH_WV_UTILS.convert_uom(p_top_level_rows(i).weight_uom,
1460                                                                       l_target_uom,
1461                                                                       p_top_level_rows(i).gross_weight,
1462                                                                       0);  -- Within same UOM class
1463              ELSE
1464                  l_temp_wt := l_temp_wt + p_top_level_rows(i).gross_weight;
1465              END IF;
1466         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Gross wt in loose item : '||p_top_level_rows(i).gross_weight);
1467         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Temp wt in loose item : '||l_temp_wt);
1468 
1469 
1470         ELSE
1471              -- top level row is a container, so get its rolledup lines
1472 
1473             j := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
1474             IF (j IS NOT NULL) THEN
1475             LOOP
1476         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'g_rolledup_line id : '||FTE_FREIGHT_PRICING.g_rolledup_lines(j).delivery_detail_id);
1477                  IF (FTE_FREIGHT_PRICING.g_rolledup_lines(j).master_container_id = l_content_id) THEN
1478 
1479                       IF (l_target_uom IS NULL) THEN
1480                            l_target_uom  := FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom;
1481                       END IF;
1482 
1483                       IF (FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom <> l_target_uom ) THEN
1484                           l_temp_wt   :=  l_temp_wt + WSH_WV_UTILS.convert_uom(FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom,
1485                                                                                l_target_uom,
1486                                                                                FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity,
1487                                                                                0);  -- Within same UOM class
1488                       ELSE
1489                           l_temp_wt   := l_temp_wt + FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity;
1490                       END IF;
1491         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Gross wt in container item : '||FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity);
1492         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Temp wt in container item : '||l_temp_wt);
1493                  END IF;
1494             EXIT WHEN j >= FTE_FREIGHT_PRICING.g_rolledup_lines.LAST;
1495                 j := FTE_FREIGHT_PRICING.g_rolledup_lines.NEXT(j);
1496            END LOOP;
1497            END IF;
1498         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Temp wt afterloop container item : '||l_temp_wt);
1499 
1500        END IF;  -- container_flag
1501 
1502     EXIT WHEN i >= p_top_level_rows.LAST;
1503         i := p_top_level_rows.NEXT(i);
1504     END LOOP;
1505     END IF;
1506 
1507         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Temp wt afterloop : '||l_temp_wt);
1508 
1509     IF (l_target_uom IS NULL ) THEN
1510         raise fte_freight_pricing_util.g_weight_uom_not_found;
1511     END IF;
1512 
1513     IF (l_temp_wt = 0) THEN
1514           -- something wrong
1515           raise fte_freight_pricing_util.g_total_shipment_weight_failed;
1516     END IF;
1517 
1518     x_total_wt := l_temp_wt;
1519     x_wt_uom   := l_target_uom;
1520 
1521  fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight');
1522  EXCEPTION
1523       WHEN fte_freight_pricing_util.g_weight_uom_not_found THEN
1524            x_return_status :=  WSH_UTIL_CORE.G_RET_STS_ERROR;
1525            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_weight_uom_not_found');
1526            fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight');
1527       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
1528            x_return_status :=  WSH_UTIL_CORE.G_RET_STS_ERROR;
1529            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
1530            fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight');
1531       WHEN others THEN
1532            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1533            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
1534            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
1535            fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight');
1536 
1537 END get_total_shipment_weight;
1538 
1539 -- This procedure is used to calculate the total wt of the top level rows
1540 -- get total shipment wt. Should take care of conversions. This overloaded method bumps up individual
1541 -- package wts to the min. package wt before getting the total.
1542 -- used for parcel hundred wt.
1543 
1544 PROCEDURE  get_total_shipment_weight  (p_top_level_rows    IN   fte_freight_pricing.shpmnt_content_tab_type,
1545                                        p_min_package_wt    IN   NUMBER,
1546                                        p_min_wt_uom        IN   VARCHAR2,
1547                                        x_total_wt          OUT NOCOPY   NUMBER,
1548                                        x_wt_uom            OUT NOCOPY   VARCHAR2,
1549                                        x_return_status     OUT NOCOPY   VARCHAR2)
1550  IS
1551 
1552    l_rolledup_wt      NUMBER;
1553    l_rolledup_uom     VARCHAR2(30);
1554    l_curr_wt          NUMBER;
1555    l_curr_uom         VARCHAR2(30);
1556    l_highest_wt          NUMBER;
1557    l_highest_uom         VARCHAR2(30);
1558    l_cum_wt           NUMBER;
1559    l_cum_uom          VARCHAR2(30);
1560    l_content_id         NUMBER;
1561    i     NUMBER;
1562    l_return_status  VARCHAR2(1);
1563 
1564    l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1565    l_method_name VARCHAR2(50) := 'get_total_shipment_weight';
1566    -- Local module
1567    PROCEDURE add_weights ( p_orig_wt      IN NUMBER,
1568                            p_orig_uom     IN VARCHAR2,
1569                            p_add_wt       IN NUMBER,
1570                            p_add_uom      IN VARCHAR2,
1571                            p_target_uom   IN VARCHAR2 DEFAULT NULL,
1572                            x_new_wt       OUT NOCOPY  NUMBER,
1573                            x_new_uom      OUT NOCOPY  VARCHAR2)
1574   IS
1575       l_temp_wt NUMBER :=0;
1576       l_new_wt   NUMBER;
1577       l_new_uom  VARCHAR2(30);
1578 
1579   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1580   l_method_name VARCHAR2(50) := 'add_weights';
1581  BEGIN
1582 
1583       fte_freight_pricing_util.set_method(l_log_level,'add_weights');
1584       IF (p_orig_uom = p_add_uom) THEN
1585          l_new_wt  := p_orig_wt + p_add_wt;
1586          l_new_uom := p_orig_uom;
1587       ELSE
1588          l_new_wt  := p_orig_wt + WSH_WV_UTILS.convert_uom(p_add_uom,  --from
1589                                                            p_orig_uom, --to
1590                                                            p_add_wt,
1591                                                            0);  -- Within same UOM class
1592          l_new_uom := p_orig_uom;
1593       END IF;
1594 
1595       IF (p_target_uom IS NOT NULL AND p_target_uom <> l_new_uom) THEN
1596          x_new_wt  := WSH_WV_UTILS.convert_uom(l_new_uom,  --from
1597                                                p_target_uom, --to
1598                                                l_new_wt,
1599                                                0);  -- Within same UOM class
1600          x_new_uom := p_target_uom;
1601       ELSE
1602          x_new_wt := l_new_wt;
1603          x_new_uom := l_new_uom;
1604       END IF;
1605 
1606       fte_freight_pricing_util.unset_method(l_log_level,'add_weights');
1607   END ;
1608 
1609   PROCEDURE highest_of  (p_wt_1           IN NUMBER,
1610                          p_uom_1          IN VARCHAR2,
1611                          p_wt_2           IN NUMBER,
1612                          p_uom_2          IN VARCHAR2,
1613                          p_target_uom     IN VARCHAR2,
1614                          x_wt             OUT NOCOPY  NUMBER,
1615                          x_uom            OUT NOCOPY  VARCHAR2)
1616   IS
1617       l_new_wt_2    NUMBER :=0;
1618   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1619   l_method_name VARCHAR2(50) := 'highest_of';
1620  BEGIN
1621       fte_freight_pricing_util.set_method(l_log_level,'highest_of');
1622       IF (p_uom_1 = p_uom_2) THEN
1623             x_wt  := GREATEST(p_wt_1,p_wt_2);
1624             x_uom := p_uom_1;
1625       ELSE
1626            l_new_wt_2   :=  WSH_WV_UTILS.convert_uom(p_uom_2,
1627                                                      p_uom_1,
1628                                                      p_wt_2,
1629                                                      0);  -- Within same UOM class
1630            IF (p_wt_1 >= l_new_wt_2 ) THEN
1631                 x_wt  := p_wt_1;
1632                 x_uom := p_uom_1;
1633            ELSE
1634                 x_wt  := p_wt_2;
1635                 x_uom := p_uom_2;
1636            END IF;
1637 
1638       END IF;
1639 
1640       IF (p_target_uom IS NOT NULL AND p_target_uom <> x_uom) THEN
1641            x_wt     :=  WSH_WV_UTILS.convert_uom(x_uom,
1642                                                  p_target_uom,
1643                                                  x_wt,
1644                                                  0);  -- Within same UOM class
1645            x_uom    := p_target_uom;
1646 
1647       END IF;
1648 
1649       fte_freight_pricing_util.unset_method(l_log_level,'highest_of');
1650   END highest_of;
1651 
1652 
1653   PROCEDURE get_rolledup_wts (p_content_id   IN NUMBER,
1654                               p_target_uom  IN  VARCHAR2  DEFAULT NULL,
1655                               x_wt          OUT NOCOPY  NUMBER,
1656                               x_uom         OUT NOCOPY  VARCHAR2)
1657   IS
1658     j                NUMBER;
1659     l_target_uom     VARCHAR2(30);
1660     l_temp_wt        NUMBER :=0;
1661     l_temp_uom       VARCHAR2(30);
1662   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1663   l_method_name VARCHAR2(50) := 'get_rolledup_wts';
1664  BEGIN
1665         fte_freight_pricing_util.set_method(l_log_level,'get_rolledup_wts');
1666         l_target_uom  := p_target_uom;
1667         j := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
1668         IF ( j IS NOT NULL) THEN
1669         LOOP
1670             IF (FTE_FREIGHT_PRICING.g_rolledup_lines(j).master_container_id = p_content_id) THEN
1671 
1672                     fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'j ='||j);
1673                       IF (l_target_uom IS NULL) THEN
1674                            l_target_uom  := FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom;
1675                       END IF;
1676 
1677                       IF (FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom <> l_target_uom ) THEN
1678                           l_temp_wt   :=  l_temp_wt + WSH_WV_UTILS.convert_uom(FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_uom,
1679                                                                                l_target_uom,
1680                                                                                FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity,
1681                                                                                0);  -- Within same UOM class
1682                       ELSE
1683                           l_temp_wt   := l_temp_wt + FTE_FREIGHT_PRICING.g_rolledup_lines(j).line_quantity;
1684                       END IF;
1685             END IF;
1686        EXIT WHEN j >= FTE_FREIGHT_PRICING.g_rolledup_lines.LAST;
1687                  j := FTE_FREIGHT_PRICING.g_rolledup_lines.NEXT(j);
1688        END LOOP;
1689        END IF;
1690 
1691        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_temp_wt ='||l_temp_wt);
1692        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_target_uom = '||l_target_uom);
1693        x_wt  := l_temp_wt;
1694        x_uom := l_target_uom;
1695 
1696        fte_freight_pricing_util.unset_method(l_log_level,'get_rolledup_wts');
1697   EXCEPTION
1698     WHEN others THEN
1699       fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
1700       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
1701       fte_freight_pricing_util.unset_method(l_log_level, l_method_name);
1702   END get_rolledup_wts;
1703 
1704 
1705  BEGIN
1706     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1707     fte_freight_pricing_util.reset_dbg_vars;
1708     fte_freight_pricing_util.set_method(l_log_level,'get_total_shipment_weight-2');
1709 
1710    -- TODO :  if this is a container  -->
1711    --         if g_shipment_line_rows(toplevel content_id).gross_wt is null
1712    --         total_wt  = total wt + sum of rolledup lines net wt + top level row.grosswt   --(1)
1713    --        end if
1714    --       if g_shipment_line_rows(toplevel content_id).gross_wt is not null
1715    --            choose highest of this gross_wt and the total calculated from the rollup line as in (1)
1716    --       end if
1717    --       if this is a loose item -->
1718    --          total_wt = total_wt + top level row.gross wt
1719    --       end if
1720    --       take care of uom conversions at all points
1721    --   IMP NOTE : top_level_row.grosswt is always the actual wt of the detail. So for container, this is actually
1722    --          the item wt from msi.
1723    --          The user changeable gross weight of the container has to be obtained from the g_shipment_line_rows.
1724    --  This will make the total wt calculation consistent with engine row creation.
1725 
1726 
1727     i := p_top_level_rows.FIRST;
1728 
1729     IF (p_min_wt_uom IS NULL) THEN
1730        l_cum_uom   := p_top_level_rows(i).weight_uom;
1731     ELSE
1732        l_cum_uom   := p_min_wt_uom;
1733     END IF;
1734 
1735 
1736     IF (l_cum_uom IS NULL) THEN
1737         raise fte_freight_pricing_util.g_weight_uom_not_found;
1738     END IF;
1739 
1740     i          := p_top_level_rows.FIRST;
1741     l_curr_wt  := 0;
1742     l_cum_wt   := 0;
1743     LOOP
1744         l_content_id := p_top_level_rows(i).content_id;
1745         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_content_id = '||l_content_id);
1746 
1747         IF (p_top_level_rows(i).container_flag = 'N') THEN
1748             IF (l_cum_uom <> p_top_level_rows(i).weight_uom ) THEN
1749                l_curr_wt  := WSH_WV_UTILS.convert_uom(p_top_level_rows(i).weight_uom,
1750                                                       l_cum_uom,
1751                                                       p_top_level_rows(i).gross_weight,
1752                                                       0);  -- Within same UOM class
1753                l_curr_uom := l_cum_uom;
1754             ELSE
1755                l_curr_wt  := p_top_level_rows(i).gross_weight;
1756                l_curr_uom := l_cum_uom;
1757             END IF;
1758 
1759         ELSE
1760              -- get rolledup wt converted to l_cum_uom
1761              get_rolledup_wts(l_content_id,
1762                               l_cum_uom,
1763                               l_rolledup_wt, l_rolledup_uom);
1764              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'       l_rolledup_wt = '||l_rolledup_wt);
1765 
1766              --  add weights : l_curr_wt := l_rolledup_wt + p_top_level_rows(i).gross_weight;
1767              add_weights(p_orig_wt=>l_rolledup_wt,p_orig_uom=>l_cum_uom,
1768                          p_add_wt=>p_top_level_rows(i).gross_weight, p_add_uom=>p_top_level_rows(i).weight_uom,
1769                          x_new_wt=>l_curr_wt,x_new_uom=>l_curr_uom);
1770 
1771              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'       l_curr_wt = '||l_curr_wt);
1772 
1773             IF (FTE_FREIGHT_PRICING.g_shipment_line_rows(l_content_id).gross_weight IS NOT NULL) THEN
1774 
1775               -- choose the higher of the g_shipment_row.gross_wt and the above wt.
1776                  highest_of (FTE_FREIGHT_PRICING.g_shipment_line_rows(l_content_id).gross_weight,
1777                              FTE_FREIGHT_PRICING.g_shipment_line_rows(l_content_id).weight_uom_code,
1778                              l_curr_wt,
1779                              l_cum_uom,
1780                              l_cum_uom,  --target uom
1781                              l_highest_wt,
1782                              l_highest_uom);
1783                              --l_curr_wt,
1784                              --l_curr_uom);
1785 
1786 		l_curr_wt := l_highest_wt;
1787 		l_curr_uom := l_highest_uom;
1788              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'       highest :l_curr_wt = '||l_curr_wt);
1789 
1790             END IF;
1791         END IF;
1792 
1793         --bump up wt if less than p_min_package_wt (take highest of curr wt and min package wt )
1794          IF (p_min_package_wt IS NOT NULL AND p_min_package_wt > 0) THEN
1795                  highest_of (l_curr_wt,
1796                              l_cum_uom,
1797                              p_min_package_wt,
1798                              p_min_wt_uom,
1799                              l_cum_uom,  --target uom
1800                              l_highest_wt,
1801                              l_highest_uom);
1802                              --l_curr_wt,
1803                              --l_curr_uom);
1804 
1805 		l_curr_wt := l_highest_wt;
1806 		l_curr_uom := l_highest_uom;
1807              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'       highest :l_curr_wt = '||l_curr_wt);
1808         END IF;
1809 
1810         l_cum_wt := l_cum_wt + l_curr_wt;
1811 
1812     EXIT WHEN i >= p_top_level_rows.LAST;
1813        i := p_top_level_rows.NEXT(i);
1814     END LOOP;
1815 
1816 
1817     IF (l_cum_wt = 0) THEN
1818           -- something wrong
1819           raise fte_freight_pricing_util.g_total_shipment_weight_failed;
1820     END IF;
1821 
1822     x_total_wt := l_cum_wt;
1823     x_wt_uom   := l_cum_uom;
1824 
1825  fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight-2');
1826  EXCEPTION
1827       WHEN fte_freight_pricing_util.g_weight_uom_not_found THEN
1828            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1829            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_weight_uom_not_found');
1830            fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight-2');
1831       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
1832            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1833            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
1834            fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight-2');
1835       WHEN others THEN
1836            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1837            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
1838            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
1839            fte_freight_pricing_util.unset_method(l_log_level,'get_total_shipment_weight-2');
1840 END get_total_shipment_weight;
1841 
1842 
1843 PROCEDURE  get_bumped_up_package_weight  (p_wt                IN   NUMBER,
1844                                           p_wt_uom            IN   VARCHAR2,
1845                                           p_min_package_wt    IN   NUMBER,
1846                                           p_min_wt_uom        IN   VARCHAR2,
1847                                           x_new_wt            OUT NOCOPY   NUMBER,
1848                                           x_new_wt_uom        OUT NOCOPY   VARCHAR2,
1849                                           x_bump              OUT NOCOPY   VARCHAR2,
1850                                           x_return_status     OUT NOCOPY   VARCHAR2)
1851 IS
1852   i     NUMBER;
1853   l_temp_min_wt   NUMBER;
1854   l_temp_min_uom  VARCHAR2(30);
1855   l_return_status  VARCHAR2(1);
1856 
1857 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1858   l_method_name VARCHAR2(50) := 'get_bumped_up_package_weight';
1859  BEGIN
1860     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1861     fte_freight_pricing_util.reset_dbg_vars;
1862     fte_freight_pricing_util.set_method(l_log_level,'get_bumped_up_package_weight');
1863 
1864     IF (p_min_wt_uom IS NULL OR p_wt_uom IS NULL) THEN
1865         --raise fte_freight_pricing_util.g_weight_uom_not_found;
1866 
1867 	-- since it's been decided later on that hundredwt enabling is not controled
1868 	-- by the parameter, instead is controled by whether top level row count is
1869 	-- is greater than 1, we cannot always assume that p_min_package_wt and
1870 	-- p_min_wt_uom is set
1871 	-- if the parameter is not setup, we just assume that the min_package weight is 0
1872 	-- and min_wt_uom is the same as line wt uom
1873 	-- so the new wt is the same as line wt
1874 	x_new_wt := p_wt;
1875 	x_new_wt_uom := p_wt_uom;
1876 
1877 	fte_freight_pricing_util.unset_method(l_log_level,'get_bumped_up_package_weight');
1878 
1879 	return;
1880     END IF;
1881 
1882     if (p_wt_uom <> p_min_wt_uom) THEN
1883       --convert min wt uom to current uom
1884                 l_temp_min_wt   :=  WSH_WV_UTILS.convert_uom(p_min_wt_uom,
1885                                                          p_wt_uom,
1886                                                          p_min_package_wt,
1887                                                          0);  -- Within same UOM class
1888                 l_temp_min_uom  := p_wt_uom;
1889     else
1890                 l_temp_min_wt   := p_min_package_wt;
1891                 l_temp_min_uom  := p_wt_uom;
1892     end if;
1893 
1894     if (p_wt < l_temp_min_wt) then
1895                 x_new_wt        := l_temp_min_wt;
1896                 x_new_wt_uom    := l_temp_min_uom;
1897                 x_bump          := 'Y';
1898     else
1899                 x_new_wt        := p_wt;
1900                 x_new_wt_uom    := p_wt_uom;
1901                 x_bump          := 'N';
1902     end if;
1903 
1904  fte_freight_pricing_util.unset_method(l_log_level,'get_bumped_up_package_weight');
1905  EXCEPTION
1906       WHEN fte_freight_pricing_util.g_weight_uom_not_found THEN
1907            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1908            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_weight_uom_not_found');
1909            fte_freight_pricing_util.unset_method(l_log_level,'get_bumped_up_package_weight');
1910       WHEN others THEN
1911            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1912            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
1913            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
1914            fte_freight_pricing_util.unset_method(l_log_level,'get_bumped_up_package_weight');
1915 END get_bumped_up_package_weight;
1916 
1917 
1918 -- Get the next higher wt. break. The wt. break is converted to the uom on the total wt.
1919 PROCEDURE get_next_weight_break       (p_total_wt                IN NUMBER,
1920                                        p_total_wt_uom            IN VARCHAR2,
1921                                        x_next_weight_break       OUT NOCOPY  NUMBER,
1922                                        x_weight_break_uom        OUT NOCOPY  VARCHAR2,
1923                                        x_return_status           OUT NOCOPY  VARCHAR2)
1924 IS
1925 i              NUMBER;
1926 l_curr_break   NUMBER;
1927 l_curr_diff    NUMBER := 99999999999 ;
1928 l_least_diff   NUMBER := 99999999999 ;
1929 l_best_break   NUMBER := 0;
1930 l_return_status  VARCHAR2(1);
1931 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
1932   l_method_name VARCHAR2(50) := 'get_next_weight_break';
1933  BEGIN
1934      x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1935      fte_freight_pricing_util.reset_dbg_vars;
1936      fte_freight_pricing_util.set_method(l_log_level,'get_next_weight_break');
1937 
1938      -- in the loop the wt break points may not be in any particular order
1939      -- so we have to get the weight break point which gives the smallest positive difference
1940      -- from the total wt
1941      -- all wt break points are first converted to the uom of the total wt
1942      i := g_lane_parameters.FIRST;
1943      IF (i IS NOT NULL) THEN
1944      LOOP
1945          IF (g_lane_parameters(i).parameter_sub_type = 'DEFICIT_WT'
1946              AND g_lane_parameters(i).parameter_name = 'WT_BREAK_POINT') THEN
1947                IF (p_total_wt_uom <> g_lane_parameters(i).uom_code) THEN
1948 
1949                     l_curr_break   :=    INV_CONVERT.inv_um_convert(
1950                                           --item_id,
1951                                           0,-- Within same UOM class
1952                                           --5,
1953                                           nvl(FND_PROFILE.Value ('QP_INV_DECIMAL_PRECISION'),10),
1954                                           -- Bug 2360273 : precision same as QP's precision
1955                                           fnd_number.canonical_to_number(g_lane_parameters(i).value_from),
1956                                           g_lane_parameters(i).uom_code,
1957                                           p_total_wt_uom,
1958                                           NULL,
1959                                           NULL);
1960 
1961                     IF l_curr_break = -99999 then
1962                        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,' Undefined UOM conversion for def. wt. break from '||g_lane_parameters(i).uom_code||' to uom '||p_total_wt_uom);
1963                        --raise others;
1964                        raise fte_freight_pricing_util.g_invalid_uom_conversion;
1965                     END IF;
1966 
1967                                          /*
1968                                          WSH_WV_UTILS.convert_uom(g_lane_parameters(i).uom_code,
1969                                                                 p_total_wt_uom,
1970                                                                 g_lane_parameters(i).value_from,
1971                                                                 0);  -- Within same UOM class
1972                                          */
1973                ELSE
1974                     l_curr_break   := fnd_number.canonical_to_number(g_lane_parameters(i).value_from);
1975                END IF;
1976 
1977                l_curr_diff := l_curr_break - p_total_wt;
1978                IF (l_curr_diff < l_least_diff AND l_curr_diff >= 0) THEN
1979                    l_least_diff  := l_curr_diff;
1980                    l_best_break  := l_curr_break;
1981                END IF;
1982          END IF;
1983      EXIT WHEN (i >= g_lane_parameters.LAST );
1984          i := g_lane_parameters.NEXT(i);
1985      END LOOP;
1986      END IF;
1987 
1988      -- Should not error out
1989      -- If next break point is not found should ideally proceed with one set as standard LTL
1990      -- For this release will throw error and a descriptive message AG 05/08
1991      /*
1992      -- if next break point is not found, the calling procedure will just send one set to QP
1993      IF (l_best_break <= 0) THEN
1994           --raise fte_freight_pricing_util.g_weight_break_not_found;
1995           raise fte_freight_pricing_util.g_def_wt_break_not_found;
1996      END IF;
1997      */
1998      -- This will never happen as the calling procedure handles this
1999      /*
2000      IF (p_total_wt_uom IS NULL ) THEN
2001           raise fte_freight_pricing_util.g_weight_uom_not_found;
2002      END IF;
2003      */
2004 
2005      -- There is a potential problem here in case of uom conversion
2006      -- because of the decimal discontinuity
2007      -- on a pricebreak line which can give us an IPL
2008      -- for the line which is going with the next break value as Total_Item_quantity  AG  05/09
2009      x_next_weight_break := l_best_break;
2010      x_weight_break_uom  := p_total_wt_uom;
2011 
2012  fte_freight_pricing_util.unset_method(l_log_level,'get_next_weight_break');
2013  EXCEPTION
2014       /*
2015       --WHEN fte_freight_pricing_util.g_weight_break_not_found THEN
2016       WHEN fte_freight_pricing_util.g_def_wt_break_not_found THEN
2017            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2018            --x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
2019            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_def_wt_break_not_found');
2020            fte_freight_pricing_util.unset_method(l_log_level,'get_next_weight_break');
2021       */
2022       WHEN fte_freight_pricing_util.g_invalid_uom_conversion THEN
2023            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2024            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_invalid_uom_conversion');
2025            fte_freight_pricing_util.unset_method(l_log_level,'get_next_weight_break');
2026       /*
2027       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
2028            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2029            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
2030            fte_freight_pricing_util.unset_method(l_log_level,'get_next_weight_break');
2031       */
2032       WHEN others THEN
2033            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2034            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
2035            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
2036            fte_freight_pricing_util.unset_method(l_log_level,'get_next_weight_break');
2037 END get_next_weight_break;
2038 
2039 
2040 -- This function is used to calculate the deficit wt for the given shipment
2041 -- The total wt and wt break are assumed to be in the same uom
2042 FUNCTION get_deficit_weight  ( p_total_wt      IN NUMBER,
2043                                p_next_wt_break IN NUMBER)
2044 RETURN NUMBER IS
2045 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
2046  BEGIN
2047         RETURN (p_next_wt_break - p_total_wt);
2048 END;
2049 
2050 
2051 
2052 -- call after a qp call
2053 -- can be called only after pricing objective has been resolved
2054 -- in parameters include processed rows from qp call
2055 -- out parameters include massaged qp processed rows.
2056 -- analyses engine output to verify if min. charge should apply. If shipment qualifies for min. charge, then
2057 -- prorate the min. charge across all lines.
2058 PROCEDURE apply_min_charge (p_event_num        IN  NUMBER,
2059                             p_set_num          IN  NUMBER DEFAULT 1,
2060                             p_comp_with_price  IN  NUMBER DEFAULT NULL,
2061                             x_charge_applied   OUT NOCOPY  VARCHAR2,  -- Y/N
2062                             x_return_status    OUT NOCOPY  VARCHAR2)
2063 IS
2064 
2065   l_total_base_price       NUMBER;
2066   l_priced_curr            VARCHAR2(30);
2067   l_return_status          VARCHAR2(1);
2068   l_min_charge_amt         NUMBER;
2069   l_min_charge_curr        VARCHAR2(30);
2070   l_log_level  NUMBER := fte_freight_pricing_util.G_LOG;
2071   l_method_name VARCHAR2(50) := 'apply_min_charge';
2072 
2073   -- local module --
2074   PROCEDURE get_min_charge_parameter (x_min_charge_amt  OUT NOCOPY  NUMBER,
2075                                       x_currency        OUT NOCOPY  VARCHAR2)
2076   IS
2077        i                NUMBER;
2078        min_charge_amt   NUMBER := 0;
2079        currency         VARCHAR2(30) := NULL;
2080   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
2081   l_method_name VARCHAR2(50) := 'apply_min_charge';
2082  BEGIN
2083      fte_freight_pricing_util.set_method(l_log_level,'get_min_charge_parameter');
2084        i := g_lane_parameters.FIRST;
2085      IF (i IS NOT NULL) THEN
2086      LOOP
2087          IF (g_lane_parameters(i).parameter_sub_type = 'MIN_CHARGE'
2088              AND g_lane_parameters(i).parameter_name = 'MIN_CHARGE_AMT') THEN
2089                 min_charge_amt  := fnd_number.canonical_to_number(g_lane_parameters(i).value_from);
2090                 currency        := g_lane_parameters(i).currency_code;
2091          END IF;
2092 
2093      EXIT WHEN (i >= g_lane_parameters.LAST);
2094          i := g_lane_parameters.NEXT(i);
2095      END LOOP;
2096      END IF;
2097      x_min_charge_amt := min_charge_amt;
2098      x_currency       := currency;
2099      fte_freight_pricing_util.unset_method(l_log_level,'get_min_charge_parameter');
2100   EXCEPTION
2101     WHEN others THEN
2102       fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
2103       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
2104       fte_freight_pricing_util.unset_method(l_log_level, l_method_name);
2105   END  get_min_charge_parameter;
2106   -- end local module --
2107 
2108  BEGIN
2109 
2110      x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2111      fte_freight_pricing_util.reset_dbg_vars;
2112      fte_freight_pricing_util.set_method(l_log_level,'apply_min_charge');
2113      x_charge_applied := 'N';
2114 
2115     IF (g_special_flags.minimum_charge_flag <> 'Y') THEN
2116         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'minimum charge is disabled ');
2117         fte_freight_pricing_util.unset_method(l_log_level,'apply_min_charge');
2118         RETURN;
2119     END IF;
2120 
2121     IF p_comp_with_price IS NULL THEN
2122     -- now calculate the total base price of the shipment (for the given set)
2123     fte_qp_engine.get_total_base_price(p_set_num          => p_set_num, -- Have to pass set number as otherwise
2124                                                                         -- the correct remaining set
2125                                                                         -- would not be picked up eg. deficit wt.
2126                                                                         -- with min. charge or hundred wt
2127                                                                         -- with min. charge would not work
2128                                                                         -- AG 5/10
2129                                        --p_set_num          => p_set_num,
2130                                        --x_priced_currency  => l_priced_curr,
2131                                        x_price            => l_total_base_price,
2132                                        x_return_status    => l_return_status);
2133 
2134            fte_freight_pricing_util.set_location(p_loc=>'after get_total_base_price ');
2135            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2136                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2137                         raise fte_freight_pricing_util.g_total_base_price_failed;
2138            /*
2139            ELSE
2140                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_base_price = '||l_total_base_price);
2141            */
2142            END IF;
2143 
2144     ELSE
2145       l_total_base_price := p_comp_with_price;
2146     END IF;
2147     fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_base_price = '||l_total_base_price);
2148     -- call the local module
2149     get_min_charge_parameter (l_min_charge_amt, l_min_charge_curr);
2150 
2151      -- TODO : implement x_priced_currency in fte_qp_engine.get_total_base_price. the following lines
2152      --        are commented out for now
2153     --IF (l_min_charge_curr <> l_priced_curr ) THEN
2154        -- error
2155      --  RETURN;
2156     -- END IF;
2157 
2158     -- For deficit wt. there is a third component here which should be part of the comparison
2159     -- AG 5/10
2160 
2161     IF (l_min_charge_amt > l_total_base_price ) THEN
2162        -- should apply min. charge
2163        -- prorate min. charge across all engine output lines by wt.
2164        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'min charge will be applied');
2165        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'min charge amount : '||l_min_charge_amt);
2166        fte_qp_engine.apply_new_base_price(--p_set_num         => p_set_num,
2167                                           p_set_num         => p_set_num,   -- AG 5/10
2168                                           p_new_total_price => l_min_charge_amt,
2169                                           x_return_status   => l_return_status);
2170 
2171            fte_freight_pricing_util.set_location(p_loc=>'after apply_new_base_price ');
2172            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2173                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2174                         raise fte_freight_pricing_util.g_apply_new_base_price_failed;
2175            ELSE
2176                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'applied min charge amt = '||l_min_charge_amt);
2177            END IF;
2178 
2179        x_charge_applied := 'Y';
2180 
2181     ELSE
2182        -- do nothing
2183        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'No need to apply min charge ');
2184        fte_freight_pricing_util.unset_method(l_log_level,'apply_min_charge');
2185        RETURN;
2186     END IF;
2187 
2188  fte_freight_pricing_util.unset_method(l_log_level,'apply_min_charge');
2189  EXCEPTION
2190       WHEN fte_freight_pricing_util.g_total_base_price_failed THEN
2191            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2192            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'total_base_price_failed');
2193            fte_freight_pricing_util.unset_method(l_log_level,'apply_min_charge');
2194       WHEN fte_freight_pricing_util.g_apply_new_base_price_failed THEN
2195            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2196            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_apply_new_base_price_failed');
2197            fte_freight_pricing_util.unset_method(l_log_level,'apply_min_charge');
2198       WHEN others THEN
2199            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2200            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
2201            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
2202            fte_freight_pricing_util.unset_method(l_log_level,'apply_min_charge');
2203 
2204 
2205 END  apply_min_charge;
2206 
2207 
2208 
2209 
2210 PROCEDURE  process_LTL_with_deficit_wt (
2211         p_pricing_control_rec     IN               fte_freight_pricing.pricing_control_input_rec_type,
2212         p_top_level_rows          IN               fte_freight_pricing.shpmnt_content_tab_type,
2213         p_pricing_engine_rows     IN OUT NOCOPY    fte_freight_pricing.pricing_engine_input_tab_type,
2214         p_pricing_dual_instances  IN               fte_freight_pricing.pricing_dual_instance_tab_type,
2215         p_pattern_rows            IN               fte_freight_pricing.top_level_pattern_tab_type,
2216         p_pricing_attribute_rows  IN OUT NOCOPY    fte_freight_pricing.pricing_attribute_tab_type,
2217         x_deficit_wt_applied      OUT NOCOPY               VARCHAR2,    -- Added AG 5/10
2218         x_min_charge_comp_price   OUT NOCOPY               NUMBER,      -- AG 5/10
2219         x_qp_output_line_rows     OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
2220         x_qp_output_detail_rows   OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
2221         x_return_status           OUT NOCOPY     VARCHAR2 )
2222 IS
2223    l_return_status         VARCHAR2(1);
2224    l_total_wt              NUMBER;
2225    l_total_wt_uom          VARCHAR2(30);
2226    l_event_num             NUMBER;
2227    l_set_num               NUMBER;
2228    i                       NUMBER;
2229    j                       NUMBER;
2230    l_attr_rec              fte_freight_pricing.pricing_attribute_rec_type;
2231    l_temp_wt               NUMBER;
2232    l_charge_applied        VARCHAR2(1);
2233    l_next_weight_break     NUMBER;
2234    l_next_weight_break_uom VARCHAR2(30);
2235    l_curr_last_idx         NUMBER;
2236    l_curr_input_idx        NUMBER;
2237    l_set_one_max_input_idx NUMBER;
2238    l_engine_input_rec      fte_freight_pricing.pricing_engine_input_rec_type;
2239    l_attr_row              fte_freight_pricing.pricing_attribute_rec_type;
2240    l_new_index             NUMBER;
2241 
2242    l_deficit_wt                 NUMBER:=0;
2243    l_converted_def_wt           NUMBER:=0;
2244    l_deficit_wt_uom             VARCHAR2(30);
2245 
2246    l_comm_price_rec        fte_qp_engine.commodity_price_rec_type;
2247    l_comm_price_rows_set1  fte_qp_engine.commodity_price_tbl_type;
2248    l_comm_price_rows_set2  fte_qp_engine.commodity_price_tbl_type;
2249 
2250    x_price                 NUMBER;
2251    y_price                 NUMBER;
2252    l_lowest_unit_price     NUMBER;
2253    l_lowest_unit_price_cat NUMBER;
2254    l_lowest_up_line_index  NUMBER:=0;
2255    l_lowest_up_priced_uom       VARCHAR2(30);
2256    l_lowest_up_tot_qty          NUMBER:=0;
2257    l_lowest_up_line_priced_qty    NUMBER:=0;
2258    l_adjustment_amount     NUMBER;
2259    l_qp_output_dfw_detail_row   QP_PREQ_GRP.LINE_DETAIL_REC_TYPE;
2260 
2261    l_deficit_wt_enabled   BOOLEAN;
2262 
2263 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
2264   l_method_name VARCHAR2(50) := 'process_LTL_with_deficit_wt';
2265  BEGIN
2266 
2267    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2268    x_deficit_wt_applied  :=  'N';
2269    x_min_charge_comp_price := 0;  -- AG 5/10 required for minimum charge with deficit wt
2270 
2271    l_deficit_wt_enabled := false;
2272 
2273    fte_freight_pricing_util.reset_dbg_vars;
2274    fte_freight_pricing_util.set_method(l_log_level,'process_LTL_with_deficit_wt');
2275        -- process deficit wt.
2276        -- prepare engine input  (also make appropriate additions to original engine input rows)
2277             -- 1st Set (for y): send total_item_quantity = actual total
2278             -- 2nd Set (for x): send total_item_quantity = next wt. break
2279        -- call qp api
2280        -- (how does min charge mix with deficit wt.?)
2281        -- do deficit wt. calc and comparision
2282        -- delete unused set from engine rows and from qp input and output tables
2283 
2284        -- get total shipment wt. Should take care of conversions.
2285        get_total_shipment_weight (p_top_level_rows => p_top_level_rows,
2286                                   x_total_wt       => l_total_wt,
2287                                   x_wt_uom         => l_total_wt_uom,
2288                                   x_return_status  => l_return_status);
2289 
2290            fte_freight_pricing_util.set_location(p_loc=>'after get_total_shipment_weight ');
2291            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2292                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2293                         raise fte_freight_pricing_util.g_total_shipment_weight_failed;
2294            ELSE
2295                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_wt = '||l_total_wt);
2296                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_wt_uom = '||l_total_wt_uom);
2297            END IF;
2298 
2299        l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
2300        fte_qp_engine.create_control_record(p_event_num => l_event_num,
2301                                            x_return_status => l_return_status );
2302 
2303            fte_freight_pricing_util.set_location(p_loc=>'after create_control_record ');
2304            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2305                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2306                         raise fte_freight_pricing_util.g_create_control_record_failed;
2307            END IF;
2308 
2309        ---- set I : actual total wt. ----
2310        l_set_num   := 1;
2311        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'In set = '||l_set_num);
2312        i := p_pricing_engine_rows.FIRST;
2313        IF (i IS NOT NULL) THEN
2314        LOOP
2315             fte_qp_engine.create_line_record (p_pricing_control_rec       => p_pricing_control_rec,
2316                                               p_pricing_engine_input_rec  => p_pricing_engine_rows(i),
2317                                               x_return_status             => l_return_status);
2318 
2319            fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
2320            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2321                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2322                         raise fte_freight_pricing_util.g_create_line_record_failed;
2323            END IF;
2324 
2325             fte_qp_engine.prepare_qp_line_qualifiers(
2326                                               p_event_num               => l_event_num,
2327                                               p_pricing_control_rec       => p_pricing_control_rec,
2328                                               p_input_index             => p_pricing_engine_rows(i).input_index,
2329                                               x_return_status           => l_return_status);
2330 
2331            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
2332            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2333                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2334                         raise fte_freight_pricing_util.g_create_qualifiers_failed;
2335            END IF;
2336 
2337             fte_qp_engine.prepare_qp_line_attributes (
2338                                               p_event_num               => l_event_num,
2339                                               p_input_index             => p_pricing_engine_rows(i).input_index,
2340                                               p_attr_rows               => p_pricing_attribute_rows,
2341                                               x_return_status           => l_return_status);
2342 
2343             fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
2344             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2345                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2346                          raise fte_freight_pricing_util.g_create_attr_failed;
2347             END IF;
2348            -- Now create additional attributes
2349 
2350             l_attr_rec.attribute_index  := p_pricing_attribute_rows.LAST + 1;
2351             l_attr_rec.input_index      := p_pricing_engine_rows(i).input_index;
2352             l_attr_rec.attribute_name   := 'TOTAL_ITEM_QUANTITY';
2353 
2354             IF (p_pricing_engine_rows(i).line_uom <> l_total_wt_uom ) THEN
2355                 l_temp_wt   :=  WSH_WV_UTILS.convert_uom(l_total_wt_uom,
2356                                                          p_pricing_engine_rows(i).line_uom,
2357                                                          l_total_wt,
2358                                                          0);  -- Within same UOM class
2359                 l_attr_rec.attribute_value  := to_char(l_temp_wt);
2360             ELSE
2361                 l_attr_rec.attribute_value  := to_char(l_total_wt);
2362             END IF;
2363 
2364             fte_qp_engine.create_attr_record         (p_event_num               => l_event_num,
2365                                                       p_attr_rec                => l_attr_rec,
2366                                                       x_return_status           => l_return_status);
2367 
2368             fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
2369             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2370                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2371                          raise fte_freight_pricing_util.g_create_attr_failed;
2372             END IF;
2373 
2374           -- Also add it to the original pricing attribute rows;
2375           -- p_pricing_attribute_rows(p_pricing_attribute_rows.LAST + 1) := l_attr_rec;
2376 
2377        EXIT WHEN i >= p_pricing_engine_rows.LAST;
2378        i := p_pricing_engine_rows.NEXT(i);
2379        END LOOP;
2380        END IF;
2381 
2382        ---- set II : next break weight ----
2383        -- get the next weight break converted to the total wt uom
2384        l_set_num   := 2;
2385        fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'In set = '||l_set_num);
2386        fte_freight_pricing_util.print_msg(l_log_level,'get the next weight break for total_wt: '||l_total_wt||' uom: '||l_total_wt_uom);
2387        get_next_weight_break (p_total_wt                => l_total_wt,
2388                               p_total_wt_uom            => l_total_wt_uom,
2389                               x_next_weight_break       => l_next_weight_break,
2390                               x_weight_break_uom        => l_next_weight_break_uom,
2391                               x_return_status           => l_return_status);
2392 
2393            fte_freight_pricing_util.set_location(p_loc=>'after get_next_weight_break ');
2394 
2395            --IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2396            --      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2397 
2398            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2399                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2400                         raise fte_freight_pricing_util.g_get_next_weight_break_failed;
2401                  END IF;
2402            ELSE
2403 	     IF (l_next_weight_break is null OR l_next_weight_break <= 0) THEN
2404                fte_freight_pricing_util.print_msg(l_log_level,'not able to find next weight break, so do not use deficit weight pricing, continue as standard LTL.');
2405              ELSE
2406               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Found applicable weight break : '||l_next_weight_break||' '||l_next_weight_break_uom);
2407                l_deficit_wt_enabled := true;
2408              END IF;
2409            END IF;
2410 
2411            -- Should never happen AG 05/08
2412            /*
2413            IF (l_next_weight_break = 0 OR l_next_weight_break_uom = null ) THEN
2414                         raise fte_freight_pricing_util.g_weight_break_not_found;
2415            END IF;
2416            */
2417 
2418        IF l_deficit_wt_enabled THEN
2419        -- {
2420        -- get the deficit wt.
2421        -- uom conversion taken care in get_next_weight_break to
2422        -- convert deficit wt breaks to the total wt uom
2423        l_deficit_wt     := get_deficit_weight(p_total_wt         => l_total_wt,
2424                                               p_next_wt_break    => l_next_weight_break);
2425        --l_deficit_wt_uom := l_total_wt_uom;
2426        l_deficit_wt_uom := l_next_weight_break_uom;
2427 
2428 
2429        --l_set_num   := 2;
2430        --fte_qp_engine.get_max_input_index(p_event_num      => fte_qp_engine.G_LINE_EVENT_NUM,
2431        --                                  p_set_num        => 1,
2432        --                                  p_max_line_index => l_set_one_max_input_idx,
2433        --                                  x_return_status  => l_return_status);
2434 
2435        i := p_pricing_engine_rows.FIRST; -- counter for set 1 engine rows
2436        l_curr_last_idx  := p_pricing_engine_rows.LAST;
2437        l_new_index := l_curr_last_idx + 1;
2438        IF (i IS NOT NULL) THEN
2439        LOOP
2440             l_curr_input_idx                     := p_pricing_engine_rows(i).input_index; --should be the same as i
2441 
2442             -- copy current row to new row with set = 2 and line index as max line index + 1
2443             l_engine_input_rec                   := p_pricing_engine_rows(i);
2444             l_engine_input_rec.input_index       := l_new_index;
2445             l_engine_input_rec.input_set_number  := l_set_num;
2446 
2447             p_pricing_engine_rows(l_new_index)   := l_engine_input_rec;
2448 
2449 
2450             -- prepare line rec
2451             fte_qp_engine.create_line_record (p_pricing_control_rec       => p_pricing_control_rec,
2452                                               p_pricing_engine_input_rec  => l_engine_input_rec,
2453                                               x_return_status             => l_return_status);
2454 
2455            fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
2456            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2457                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2458                         raise fte_freight_pricing_util.g_create_line_record_failed;
2459            END IF;
2460 
2461             --prepare qualifiers
2462             fte_qp_engine.prepare_qp_line_qualifiers(
2463                                               p_event_num               => l_event_num,
2464                                               p_pricing_control_rec       => p_pricing_control_rec,
2465                                               p_input_index             => l_new_index,
2466                                               x_return_status           => l_return_status);
2467 
2468            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
2469            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2470                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2471                         raise fte_freight_pricing_util.g_create_qualifiers_failed;
2472            END IF;
2473 
2474             -- prepare attributes from the attr rows. line indexes need to be changed
2475             j := p_pricing_attribute_rows.FIRST;
2476             IF (j IS NOT NULL) THEN
2477             LOOP
2478                 IF (p_pricing_attribute_rows(j).input_index = l_curr_input_idx ) THEN
2479                     l_attr_rec                 := p_pricing_attribute_rows(j);
2480                     l_attr_rec.input_index     := l_new_index;
2481                     l_attr_rec.attribute_index := p_pricing_attribute_rows(p_pricing_attribute_rows.COUNT).attribute_index + 1;
2482 
2483                     p_pricing_attribute_rows(p_pricing_attribute_rows.COUNT + 1) := l_attr_rec;
2484 
2485                     fte_qp_engine.create_attr_record (     p_event_num              => l_event_num,
2486                                              p_attr_rec               => l_attr_rec,
2487                                              x_return_status          => l_return_status);
2488 
2489                     fte_freight_pricing_util.set_location(p_loc=>'after create attr record . i='||i);
2490                     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2491                           l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2492                                  raise fte_freight_pricing_util.g_create_attr_failed;
2493                     END IF;
2494                 END IF;
2495             EXIT WHEN j = p_pricing_attribute_rows.LAST;
2496             j := p_pricing_attribute_rows.NEXT(j);
2497             END LOOP;
2498             END IF;
2499 
2500             -- add other default attributes
2501             l_attr_rec.attribute_index  := p_pricing_attribute_rows(p_pricing_attribute_rows.COUNT).attribute_index + 1;
2502             l_attr_rec.input_index      := l_new_index;
2503             l_attr_rec.attribute_name   := 'ITEM_ALL';
2504             l_attr_rec.attribute_value  := 'ALL';
2505 
2506             fte_qp_engine.create_attr_record(  p_event_num              => l_event_num,
2507                                                p_attr_rec               => l_attr_rec,
2508                                                x_return_status          => l_return_status);
2509 
2510             fte_freight_pricing_util.set_location(p_loc=>'after create attr record . i='||i);
2511             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2512                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2513                          raise fte_freight_pricing_util.g_create_attr_failed;
2514             END IF;
2515 
2516             -- add other new attributes
2517             l_attr_rec.attribute_index  := p_pricing_attribute_rows.LAST + 1;
2518             l_attr_rec.input_index      := l_new_index;
2519             l_attr_rec.attribute_name   := 'TOTAL_ITEM_QUANTITY';
2520 
2521             IF (p_pricing_engine_rows(i).line_uom <> l_next_weight_break_uom ) THEN
2522                 l_temp_wt   :=  WSH_WV_UTILS.convert_uom(l_next_weight_break_uom,
2523                                                          p_pricing_engine_rows(i).line_uom,
2524                                                          l_next_weight_break,
2525                                                          0);  -- Within same UOM class
2526                 l_attr_rec.attribute_value  := to_char(l_temp_wt);
2527             ELSE
2528                 l_attr_rec.attribute_value  := to_char(l_next_weight_break);
2529             END IF;
2530 
2531             fte_qp_engine.create_attr_record(p_event_num               => l_event_num,
2532                                              p_attr_rec                => l_attr_rec,
2533                                              x_return_status           => l_return_status);
2534             fte_freight_pricing_util.set_location(p_loc=>'after create attr record . i='||i);
2535             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2536                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2537                          raise fte_freight_pricing_util.g_create_attr_failed;
2538             END IF;
2539 
2540        EXIT WHEN i >= l_curr_last_idx;
2541        i := p_pricing_engine_rows.NEXT(i);
2542        l_new_index := l_new_index + 1;
2543        END LOOP;  -- engine rows
2544        END IF;
2545 
2546        -- }
2547        END IF; --l_deficit_wt_enabled
2548 
2549        -- call qp api
2550        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => x_qp_output_line_rows,
2551                                       x_qp_output_detail_rows  => x_qp_output_detail_rows,
2552                                       x_return_status          => l_return_status);
2553 
2554            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 1');
2555            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2556                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2557                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
2558                  END IF;
2559            END IF;
2560 
2561        --check for errors in the output
2562            fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
2563            fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
2564            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2565                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2566                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
2567                  END IF;
2568            END IF;
2569 
2570 
2571        -- now analyse output
2572          -- find total price per set  (do we need this?)
2573          -- find deficit wt.
2574          -- find commodity with lowest unit price in set 2.
2575 
2576       -- get me unit price for each individual commodity for each set
2577       -- get me total wt. for each individual commodity
2578       -- give me all weights in the deficit wt uom
2579        l_set_num := 1;  -- set 1 uses original total weight
2580        fte_qp_engine.analyse_output_for_deficit_wt (p_set_num     => l_set_num,
2581                                                     p_wt_uom      => l_deficit_wt_uom,
2582                                                     x_commodity_price_rows  => l_comm_price_rows_set1,
2583                                                     x_return_status   => l_return_status);
2584 
2585             fte_freight_pricing_util.set_location(p_loc=>'after analyse_output_for_deficit_wt. set= '||l_set_num);
2586             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2587                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2588                          raise fte_freight_pricing_util.g_analyse_deficit_failed;
2589             END IF;
2590 
2591        IF l_deficit_wt_enabled THEN
2592        -- {
2593        l_set_num := 2;  -- set 2 uses next higher break weight
2594        fte_qp_engine.analyse_output_for_deficit_wt (
2595                                       p_set_num     => l_set_num,
2596                                       p_wt_uom      => l_deficit_wt_uom,
2597                                       x_commodity_price_rows  => l_comm_price_rows_set2,
2598                                       x_return_status   => l_return_status);
2599 
2600             fte_freight_pricing_util.set_location(p_loc=>'after analyse_output_for_deficit_wt. set= '||l_set_num);
2601             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2602                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2603                          raise fte_freight_pricing_util.g_analyse_deficit_failed;
2604             END IF;
2605        -- }
2606        END IF; --l_deficit_wt_enabled
2607 
2608 
2609       -- y (set 1) = A*rwb-a + B*rwb-b
2610       -- x (set 2) = A*r-a + B*r-b + DFW*r-a  (assuming a=lowest rate )
2611       -- compare x and y
2612       y_price := 0;
2613       i := l_comm_price_rows_set1.FIRST;
2614       IF (i IS NOT NULL) THEN
2615       LOOP
2616             y_price := y_price + (l_comm_price_rows_set1(i).total_wt * l_comm_price_rows_set1(i).unit_price);
2617       EXIT WHEN  i >= l_comm_price_rows_set1.LAST;
2618       i := l_comm_price_rows_set1.NEXT(i);
2619       END LOOP;
2620       END IF;
2621 
2622       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'y_price = '||y_price);
2623 
2624        IF l_deficit_wt_enabled THEN
2625        -- {
2626       x_price := 0;
2627       l_lowest_unit_price := 0;  -- to find lowest unit price across commodities
2628       i := l_comm_price_rows_set2.FIRST;
2629       IF (i IS NOT NULL) THEN
2630       LOOP
2631             --l_lowest_up             := FALSE;  --  Keep track of whether the current row is lowest
2632             x_price := x_price + (l_comm_price_rows_set2(i).total_wt * l_comm_price_rows_set2(i).unit_price);
2633             IF ( i = l_comm_price_rows_set2.FIRST) THEN
2634                l_lowest_unit_price     := l_comm_price_rows_set2(i).unit_price;
2635                l_lowest_unit_price_cat := l_comm_price_rows_set2(i).category_id;
2636                l_lowest_up_priced_uom  := l_comm_price_rows_set2(i).priced_uom;
2637                --l_lowest_up             := TRUE;
2638                l_lowest_up_tot_qty     := l_comm_price_rows_set2(i).total_wt;  --  This assumes that
2639                                        -- there is only one commodity row with lowest up
2640                                        -- and if there were multiple qp output lines resulting from
2641                                        -- QP engine for that commodity, that was taken into account
2642                                        -- when commodity rows were created   AG 5/13
2643                                        -- It will be in def wt uom
2644                l_lowest_up_line_index  := l_comm_price_rows_set2(i).output_line_index;
2645                l_lowest_up_line_priced_qty := l_comm_price_rows_set2(i).output_line_priced_quantity;  --  xizhang 11/22/02
2646             ELSE
2647                --l_lowest_unit_price := LEAST(l_comm_price_rows_set2(i).unit_price,l_lowest_unit_price);
2648                -- This is a problem AG 5/10
2649                -- Should do a comparison and then choose l_lowest_unit_price_cat
2650                IF l_comm_price_rows_set2(i).unit_price < l_lowest_unit_price THEN
2651                --IF l_lowest_unit_price = l_comm_price_rows_set2(i).unit_price THEN
2652                   l_lowest_unit_price     := l_comm_price_rows_set2(i).unit_price;
2653                   l_lowest_unit_price_cat := l_comm_price_rows_set2(i).category_id;
2654                   l_lowest_up_priced_uom  := l_comm_price_rows_set2(i).priced_uom;
2655                   --l_lowest_up             := TRUE;
2656                   l_lowest_up_tot_qty     := l_comm_price_rows_set2(i).total_wt;
2657                   l_lowest_up_line_index  := l_comm_price_rows_set2(i).output_line_index;
2658                   l_lowest_up_line_priced_qty := l_comm_price_rows_set2(i).output_line_priced_quantity;  --  xizhang 11/22/02
2659                END IF;
2660             END IF;
2661             /*
2662             IF l_lowest_up THEN
2663                l_lowest_up_tot_qty := l_lowest_up_tot_qty + l_comm_price_rows_set2(i).total_wt;
2664             END IF;
2665             */
2666       EXIT WHEN  i >= l_comm_price_rows_set1.LAST;
2667       i := l_comm_price_rows_set1.NEXT(i);
2668       END LOOP;
2669       END IF;
2670 
2671       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_deficit_wt = '||l_deficit_wt);
2672       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_lowest_unit_price = '||l_lowest_unit_price);
2673 
2674       x_price := x_price + (l_deficit_wt * l_lowest_unit_price );
2675 
2676       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'x_price = '||x_price);
2677 
2678        -- }
2679        END IF; --l_deficit_wt_enabled
2680 
2681       -- now compare x_price and y_price
2682      -- TO DO : this needs to be '<' ******
2683       IF (l_deficit_wt_enabled AND x_price < y_price ) THEN
2684              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,' deficit wt got applied ');
2685              x_deficit_wt_applied  :=  'Y';
2686              x_min_charge_comp_price := x_price;  -- AG 5/10 required for minimum charge with deficit wt
2687              -- deficit wt got applied
2688              -- select set 2, delete set 1
2689              l_set_num :=1; --set to delete
2690              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Deleting set ='||l_set_num);
2691              fte_qp_engine.delete_set_from_line_event( p_set_num       => l_set_num,
2692                                                       x_return_status => l_return_status);
2693             fte_freight_pricing_util.set_location(p_loc=>'after delete_set_from_line_event. set= '||l_set_num);
2694             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2695                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2696                          raise fte_freight_pricing_util.g_delete_set_failed;
2697             END IF;
2698       ELSE
2699              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,' deficit wt did not get applied ');
2700              x_deficit_wt_applied  :=  'N';
2701              x_min_charge_comp_price := y_price;  -- AG 5/10 required for minimum charge with deficit wt
2702        IF l_deficit_wt_enabled THEN
2703        -- {
2704             -- select set 1, delete set 2
2705             -- no deficit wt applied
2706              l_set_num :=2; --set to delete
2707              fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'Deleting set ='||l_set_num);
2708              fte_qp_engine.delete_set_from_line_event( p_set_num       => l_set_num,
2709                                                       x_return_status => l_return_status);
2710             fte_freight_pricing_util.set_location(p_loc=>'after delete_set_from_line_event. set= '||l_set_num);
2711             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2712                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2713                          raise fte_freight_pricing_util.g_delete_set_failed;
2714             END IF;
2715 
2716        -- }
2717        END IF; --l_deficit_wt_enabled
2718       END IF;
2719 
2720    IF x_deficit_wt_applied = 'Y' THEN
2721 
2722       -- Need to take care of the third component of side x_price ie. DFW
2723       -- As per the requirement it was part of the calculation to make the choice and
2724       -- the carrier should display that to the shipper AG 5/10
2725 
2726       -- We will be using the deficit wt. amount in the line qty uom as the qty of this record
2727       -- As the deficit wt qty gets the lowest rate among the output lines, we have to put that rate
2728       -- in adjustment amount
2729       -- As we also assume that the line detail records (all of them) have the same
2730       -- quantity as the parent line's line quantity, we will have to make the necessary proration
2731       -- to the adjustment amount eg. if line qty of lowest unit price line is 300 Lbs
2732       -- and the unit price is 30 / Lbs, and the deficit wt. for the shipment is 100 Lbs
2733       -- then the adjustment amount becomes 30 * (100/300) / Lbs
2734       -- Also adjustment amount should be in priced_uom
2735 
2736       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'deficit wt uom : '||l_deficit_wt_uom);
2737       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'lowest priced uom : '||l_lowest_up_priced_uom);
2738       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'lowest priced qty : '||l_lowest_up_tot_qty);
2739 
2740       IF l_deficit_wt_uom <> l_lowest_up_priced_uom THEN
2741         l_converted_def_wt := WSH_WV_UTILS.convert_uom(l_deficit_wt_uom,
2742                                                        l_lowest_up_priced_uom,
2743                                                        l_deficit_wt,
2744                                                        0);  -- Within same UOM class
2745         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'converted def wt : '||l_converted_def_wt);
2746         --l_adjustment_amount    := l_lowest_unit_price*(l_deficit_wt/l_lowest_up_tot_qty)*(l_deficit_wt/l_converted_def_wt);
2747         l_adjustment_amount    := l_lowest_unit_price*(l_deficit_wt/l_lowest_up_line_priced_qty)*(l_deficit_wt/l_converted_def_wt); -- xizhang 11/22/02
2748 
2749       ELSE
2750         --l_adjustment_amount    := l_lowest_unit_price*(l_deficit_wt/l_lowest_up_tot_qty);
2751         l_adjustment_amount    := l_lowest_unit_price*(l_deficit_wt/l_lowest_up_line_priced_qty); -- xizhang 11/22/02
2752 
2753       END IF;
2754       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'def wt adjustment_amount : '||l_adjustment_amount);
2755 
2756 
2757       FTE_QP_ENGINE.add_qp_output_detail(
2758 	p_line_index 		=> l_lowest_up_line_index,
2759 	p_list_line_type_code	=> 'SUR',
2760 	p_charge_subtype_code	=> 'DEFICIT WEIGHT SURCHARGE',
2761 	p_adjustment_amount	=> l_adjustment_amount,
2762 	x_return_status		=> l_return_status);
2763 
2764       IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2765           l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2766              raise fte_freight_pricing_util.g_add_qp_output_detail_failed;
2767       END IF;
2768    END IF;
2769 
2770    -- TO DO : check that we are assigning x_ at the end everywhere
2771    FTE_QP_ENGINE.get_qp_output(
2772      x_qp_output_line_rows    	=> x_qp_output_line_rows,
2773      x_qp_output_detail_rows  	=> x_qp_output_detail_rows,
2774      x_return_status		=> l_return_status);
2775 
2776    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2777        l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2778          raise fte_freight_pricing_util.g_get_qp_output_failed;
2779    END IF;
2780 
2781  fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2782  EXCEPTION
2783       WHEN fte_freight_pricing_util.g_add_qp_output_detail_failed THEN
2784            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2785            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_add_qp_output_detail_failed');
2786            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2787       WHEN fte_freight_pricing_util.g_get_qp_output_failed THEN
2788            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2789            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_get_qp_output_failed');
2790            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2791       WHEN fte_freight_pricing_util.g_create_control_record_failed THEN
2792            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2793            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_control_record_failed');
2794            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2795       WHEN fte_freight_pricing_util.g_create_line_record_failed THEN
2796            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2797            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_line_record_failed');
2798            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2799       WHEN fte_freight_pricing_util.g_create_qualifiers_failed THEN
2800            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2801            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_qualifiers_failed');
2802            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2803       WHEN fte_freight_pricing_util.g_create_attr_failed THEN
2804            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2805            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_attr_failed');
2806            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2807       WHEN fte_freight_pricing_util.g_delete_set_failed THEN
2808            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2809            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_delete_set_failed');
2810            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2811       WHEN fte_freight_pricing_util.g_analyse_deficit_failed THEN
2812            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2813            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_analyse_deficit_failed');
2814            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2815       WHEN fte_freight_pricing_util.g_weight_break_not_found THEN
2816            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2817            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_weight_break_not_found');
2818            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2819       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
2820            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2821            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
2822            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2823       WHEN fte_freight_pricing_util.g_qp_price_request_failed_2 THEN
2824            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2825            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_qp_price_request_failed_2');
2826            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2827       WHEN others THEN
2828            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2829            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
2830            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
2831            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL_with_deficit_wt');
2832 
2833 END process_LTL_with_deficit_wt;
2834 
2835 -- post process for LTL, parcel and others
2836 --   resolve pricing objective
2837 --   apply minimum charges
2838 --     prepare second qp call
2839 --     call qp (second call)
2840 PROCEDURE post_process(
2841   p_event_num               IN NUMBER,
2842   p_set_num                 IN NUMBER,
2843   p_comp_with_price         IN  NUMBER DEFAULT NULL,
2844   p_pricing_engine_rows     IN OUT NOCOPY     fte_freight_pricing.pricing_engine_input_tab_type,
2845   p_pricing_dual_instances  IN                fte_freight_pricing.pricing_dual_instance_tab_type,
2846   x_qp_output_line_rows     IN OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
2847   x_qp_output_detail_rows   IN OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
2848   x_return_status           OUT NOCOPY                VARCHAR2 )
2849 IS
2850    l_event_num NUMBER;
2851    l_charge_applied        VARCHAR2(1);
2852    l_return_status    VARCHAR2(1);
2853    l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
2854    l_method_name VARCHAR2(50) := 'post_process';
2855 BEGIN
2856   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2857   fte_freight_pricing_util.reset_dbg_vars;
2858   fte_freight_pricing_util.set_method(l_log_level,l_method_name);
2859 
2860   --call resolve pricing objective here --
2861   fte_freight_pricing.resolve_pricing_objective(
2862     p_pricing_dual_instances   =>p_pricing_dual_instances,
2863     x_pricing_engine_input     =>p_pricing_engine_rows,
2864     x_qp_output_line_rows      =>x_qp_output_line_rows,
2865     x_qp_output_line_details   =>x_qp_output_detail_rows,
2866     x_return_status            =>l_return_status);
2867 
2868   fte_freight_pricing_util.set_location(p_loc=>'after resolve_pricing_objective');
2869   IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2870       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2871         raise fte_freight_pricing_util.g_resolve_pricing_objective;
2872   END IF;
2873 
2874   -- apply min charge
2875     -- prepare second qp call
2876     -- call qp (second call)
2877 
2878   -- min charge can be called only after pricing objective has been resolved
2879   IF (g_special_flags.minimum_charge_flag = 'Y') THEN
2880 
2881     apply_min_charge(
2882 	p_event_num      => p_event_num,
2883         p_set_num        => p_set_num,  -- try to get rid of this
2884         p_comp_with_price => p_comp_with_price,
2885         x_charge_applied => l_charge_applied,
2886         x_return_status  => l_return_status);
2887 
2888     fte_freight_pricing_util.set_location(p_loc=>'after apply_min_charge ');
2889     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2890         l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2891           raise fte_freight_pricing_util.g_apply_min_charge;
2892     END IF;
2893   END IF;
2894 
2895   -- create request lines for the next event and call qp engine
2896   IF (l_charge_applied = 'Y') THEN
2897        l_event_num := fte_qp_engine.G_CHARGE_EVENT_NUM;
2898        fte_qp_engine.prepare_next_event_request ( x_return_status           => l_return_status);
2899 
2900             fte_freight_pricing_util.set_location(p_loc=>'after prepare_next_event_request');
2901             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
2902                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
2903                          raise fte_freight_pricing_util.g_prepare_next_event_failed;
2904             END IF;
2905 
2906        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => x_qp_output_line_rows,
2907                                       x_qp_output_detail_rows  => x_qp_output_detail_rows,
2908                                       x_return_status          => l_return_status);
2909 
2910            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 2');
2911            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2912                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2913                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
2914                  END IF;
2915            END IF;
2916 
2917        --check for errors in the output
2918            fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
2919            fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
2920            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2921                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2922                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
2923                  END IF;
2924            END IF;
2925 
2926   END IF;
2927 
2928   fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
2929 EXCEPTION
2930       WHEN fte_freight_pricing_util.g_resolve_pricing_objective THEN
2931            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2932            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_resolve_pricing_objective');
2933            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
2934       WHEN fte_freight_pricing_util.g_apply_min_charge THEN
2935            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2936            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_apply_min_charge');
2937            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
2938       WHEN fte_freight_pricing_util.g_prepare_next_event_failed THEN
2939            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2940            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_prepare_next_event_failed');
2941            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
2942       WHEN fte_freight_pricing_util.g_qp_price_request_failed_2 THEN
2943            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2944            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_qp_price_request_failed_2');
2945            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
2946       WHEN others THEN
2947            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2948            FTE_FREIGHT_PRICING_UTIL.set_exception(l_method_name,l_log_level,'g_others');
2949            FTE_FREIGHT_PRICING_UTIL.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
2950            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
2951 END post_process;
2952 
2953 -- This is called for LTL
2954 PROCEDURE process_LTL (
2955         p_pricing_control_rec     IN               fte_freight_pricing.pricing_control_input_rec_type,
2956         p_top_level_rows          IN               fte_freight_pricing.shpmnt_content_tab_type,
2957         p_pricing_engine_rows     IN OUT NOCOPY    fte_freight_pricing.pricing_engine_input_tab_type,
2958         p_pricing_dual_instances  IN               fte_freight_pricing.pricing_dual_instance_tab_type,
2959         p_pattern_rows            IN               fte_freight_pricing.top_level_pattern_tab_type,
2960         p_pricing_attribute_rows  IN OUT NOCOPY    fte_freight_pricing.pricing_attribute_tab_type,
2961         x_qp_output_line_rows     OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
2962         x_qp_output_detail_rows   OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
2963         x_return_status           OUT NOCOPY               VARCHAR2 )
2964  IS
2965 l_return_status         VARCHAR2(1);
2966 l_total_wt              NUMBER;
2967 l_total_wt_uom          VARCHAR2(30);
2968 l_event_num             NUMBER;
2969 l_set_num               NUMBER;
2970 i                       NUMBER;
2971 l_attr_rec              fte_freight_pricing.pricing_attribute_rec_type;
2972 l_temp_wt               NUMBER;
2973 l_charge_applied        VARCHAR2(1);
2974 l_deficit_wt_applied    VARCHAR2(1);
2975 l_min_charge_comp_price NUMBER := NULL;
2976 l_log_level  NUMBER := fte_freight_pricing_util.G_LOG;
2977   l_method_name VARCHAR2(50) := 'process_LTL';
2978 
2979 --- Local Module ----
2980 -- This procedure is to be called by process_LTL to check if we shipment satisfies conditions for LTL
2981 FUNCTION check_LTL_eligible        (p_pattern_rows  IN fte_freight_pricing.top_level_pattern_tab_type)
2982 RETURN VARCHAR2
2983 IS
2984  i NUMBER;
2985  ret_value VARCHAR2(30);
2986 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
2987  BEGIN
2988     fte_freight_pricing_util.set_method(l_log_level,'check_LTL_eligible');
2989     ret_value := 'Y';  -- Y = OK, N = NO OK
2990     i := p_pattern_rows.FIRST;
2991     IF (i IS NOT NULL) THEN
2992     LOOP
2993       --only SC_WB and MC_WB are ok for LTL
2994       --IF NOT (p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_2
2995       --    OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_5 ) THEN
2996       -- loose items now have patterns too
2997       IF NOT (p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_2
2998           OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_5
2999           OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_9
3000           OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_10 ) THEN
3001            ret_value := 'N';
3002       END IF;
3003     EXIT WHEN ( i >= p_pattern_rows.LAST OR ret_value = 'N');
3004     i := p_pattern_rows.NEXT(i);
3005     END LOOP;
3006     END IF;
3007     fte_freight_pricing_util.unset_method(l_log_level,'check_LTL_eligible');
3008     RETURN ret_value;
3009 END check_LTL_eligible;
3010 
3011 --- End Local Module --
3012 
3013  BEGIN
3014     -- check if only patterns : SC_WB and MC_WB are present. Throw error if not.
3015     -- calculate the total wt. of the shipment by summing up wts. of top level items
3016     -- call deficit wt billing logic
3017     -- prepare request (lines, attributes and qualifiers)
3018     -- Attribute Total Item Quantity  uom for a line rec should match with that
3019     -- of the line ordered uom -- AG 05/05
3020     -- call qp engine
3021     -- call min charge logic
3022     -- prepare for second qp call
3023     -- call qp engine
3024     -- any post processing
3025     -- return control to main code
3026    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3027    fte_freight_pricing_util.reset_dbg_vars;
3028    fte_freight_pricing_util.set_method(l_log_level,'process_LTL');
3029 
3030     -- Its ok for loose items not to have pattern rows. And loose items should always be eligible for LTL
3031     IF (p_pattern_rows.COUNT >0) THEN
3032        IF ( check_LTL_eligible (p_pattern_rows) = 'N') THEN
3033            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'LTL Not eligible');
3034            raise fte_freight_pricing_util.g_not_eligible_for_LTL;
3035        END IF;
3036     END IF;
3037 
3038 
3039     IF (g_special_flags.deficit_wt_flag = 'Y') THEN
3040        -- process deficit wt.
3041        -- prepare engine input  (also make appropriate additions to original engine input rows)
3042             -- 1st Set (for y): send total_item_quantity = actual total
3043             -- 2nd Set (for x): send total_item_quantity = next wt. break
3044        -- call qp api
3045        -- (how does min charge mix with deficit wt.?)
3046        -- do deficit wt. calc and comparision
3047        -- delete unused set from engine rows and from qp input and output tables
3048        l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
3049        l_set_num   := 1;
3050 
3051        process_LTL_with_deficit_wt(
3052                   p_pricing_control_rec     => p_pricing_control_rec,
3053                   p_top_level_rows          => p_top_level_rows,
3054                   p_pricing_engine_rows     => p_pricing_engine_rows,
3055                   p_pricing_dual_instances  => p_pricing_dual_instances,
3056                   p_pattern_rows            => p_pattern_rows,
3057                   p_pricing_attribute_rows  => p_pricing_attribute_rows,
3058                   x_deficit_wt_applied      => l_deficit_wt_applied,    -- Added AG 5/10
3059                   x_min_charge_comp_price   => l_min_charge_comp_price, -- AG 5/10
3060                   x_qp_output_line_rows     => x_qp_output_line_rows,
3061                   x_qp_output_detail_rows   => x_qp_output_detail_rows,
3062                   x_return_status           => l_return_status);
3063 
3064 
3065             fte_freight_pricing_util.set_location(p_loc=>'after process_LTL_with_deficit_wt ');
3066             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3067                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3068                          raise fte_freight_pricing_util.g_process_LTL_deficit_failed;
3069             END IF;
3070             IF nvl(l_deficit_wt_applied,'N') = 'Y' THEN
3071                l_set_num   := 2;
3072             END IF;
3073 
3074     ELSE
3075 
3076         fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'===> Running Standard LTL ');
3077 
3078        -- get total shipment wt. Should take care of conversions.
3079        get_total_shipment_weight (p_top_level_rows => p_top_level_rows,
3080                                x_total_wt       => l_total_wt,
3081                                x_wt_uom         => l_total_wt_uom,
3082                                x_return_status  => l_return_status);
3083 
3084            fte_freight_pricing_util.set_location(p_loc=>'after get_total_shipment_weight ');
3085            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3086                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3087                         raise fte_freight_pricing_util.g_total_shipment_weight_failed;
3088            ELSE
3089                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_wt = '||l_total_wt);
3090                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_wt_uom = '||l_total_wt_uom);
3091            END IF;
3092 
3093 
3094        -- standard LTL
3095        -- prepare engine input
3096        -- add Total_Item_Quantity attributes
3097        -- call qp
3098        l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
3099        l_set_num   := 1;
3100        fte_qp_engine.create_control_record(p_event_num => l_event_num,
3101                                            x_return_status => l_return_status );
3102        i := p_pricing_engine_rows.FIRST;
3103        IF (i IS NOT NULL) THEN
3104        LOOP
3105 
3106             fte_qp_engine.create_line_record (p_pricing_control_rec       => p_pricing_control_rec,
3107                                               p_pricing_engine_input_rec  => p_pricing_engine_rows(i),
3108                                               x_return_status             => l_return_status);
3109 
3110            fte_freight_pricing_util.set_location(p_loc=>'after create_control_record ');
3111            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3112                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3113                         raise fte_freight_pricing_util.g_create_control_record_failed;
3114            END IF;
3115 
3116 
3117             fte_qp_engine.prepare_qp_line_qualifiers(
3118                                               p_event_num               => l_event_num,
3119                                               p_pricing_control_rec       => p_pricing_control_rec,
3120                                               p_input_index             => p_pricing_engine_rows(i).input_index,
3121                                               x_return_status           => l_return_status);
3122 
3123            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
3124            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3125                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3126                         raise fte_freight_pricing_util.g_create_qualifiers_failed;
3127            END IF;
3128 
3129             fte_qp_engine.prepare_qp_line_attributes (
3130                                               p_event_num               => l_event_num,
3131                                               p_input_index             => p_pricing_engine_rows(i).input_index,
3132                                               p_attr_rows               => p_pricing_attribute_rows,
3133                                               x_return_status           => l_return_status);
3134 
3135             fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
3136             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3137                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3138                          raise fte_freight_pricing_util.g_create_attr_failed;
3139             END IF;
3140 
3141            -- Now create additional attributes
3142 
3143             l_attr_rec.attribute_index  := p_pricing_attribute_rows.LAST + 1;
3144             l_attr_rec.input_index      := p_pricing_engine_rows(i).input_index;
3145             l_attr_rec.attribute_name   := 'TOTAL_ITEM_QUANTITY';
3146 
3147             IF (p_pricing_engine_rows(i).line_uom <> l_total_wt_uom ) THEN
3148                 l_temp_wt   :=  WSH_WV_UTILS.convert_uom(l_total_wt_uom,
3149                                                          p_pricing_engine_rows(i).line_uom,
3150                                                          l_total_wt,
3151                                                          0);  -- Within same UOM class
3152                 l_attr_rec.attribute_value  := to_char(l_temp_wt);
3153             ELSE
3154                 l_attr_rec.attribute_value  := to_char(l_total_wt);
3155             END IF;
3156 
3157             fte_qp_engine.create_attr_record(p_event_num               => l_event_num,
3158                                              p_attr_rec                => l_attr_rec,
3159                                              x_return_status           => l_return_status);
3160 
3161             fte_freight_pricing_util.set_location(p_loc=>'after create attr record i='||i);
3162             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3163                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3164                          raise fte_freight_pricing_util.g_create_attr_failed;
3165             END IF;
3166 
3167           -- Also add it to the original pricing attribute rows;
3168             p_pricing_attribute_rows(p_pricing_attribute_rows.LAST + 1) := l_attr_rec;
3169 
3170 
3171        EXIT WHEN i >= p_pricing_engine_rows.LAST;
3172        i := p_pricing_engine_rows.NEXT(i);
3173        END LOOP;
3174        END IF;
3175 
3176        -- call qp api
3177        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => x_qp_output_line_rows,
3178                                       x_qp_output_detail_rows  => x_qp_output_detail_rows,
3179                                       x_return_status          => l_return_status);
3180 
3181            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 1');
3182            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3183                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3184                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
3185                  END IF;
3186            END IF;
3187 
3188        --check for errors in the output
3189            fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
3190            fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
3191            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3192                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3193                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
3194                  END IF;
3195            END IF;
3196 
3197     END IF; -- standard LTL
3198 
3199     post_process(
3200       p_event_num		=> l_event_num,
3201       p_set_num			=> l_set_num,
3202       p_comp_with_price		=> l_min_charge_comp_price,
3203       p_pricing_engine_rows	=> p_pricing_engine_rows,
3204       p_pricing_dual_instances	=> p_pricing_dual_instances,
3205       x_qp_output_line_rows	=> x_qp_output_line_rows,
3206       x_qp_output_detail_rows	=> x_qp_output_detail_rows,
3207       x_return_status		=> l_return_status);
3208 
3209     fte_freight_pricing_util.set_location(p_loc=>'after post_process');
3210     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3211         l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3212       raise fte_freight_pricing_util.g_post_process_failed;
3213     END IF;
3214 
3215  fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3216  EXCEPTION
3217       WHEN fte_freight_pricing_util.g_post_process_failed THEN
3218            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3219            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_post_process_failed');
3220            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
3221       WHEN fte_freight_pricing_util.g_not_eligible_for_LTL THEN
3222            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3223            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_not_eligible_for_LTL') ;
3224            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3225       WHEN fte_freight_pricing_util.g_create_control_record_failed THEN
3226            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3227            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_control_record_failed');
3228            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3229       WHEN fte_freight_pricing_util.g_create_line_record_failed THEN
3230            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3231            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_line_record_failed');
3232            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3233       WHEN fte_freight_pricing_util.g_create_qualifiers_failed THEN
3234            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3235            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_qualifiers_failed');
3236            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3237       WHEN fte_freight_pricing_util.g_create_attr_failed THEN
3238            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3239            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_attr_failed');
3240            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3241       WHEN fte_freight_pricing_util.g_process_LTL_deficit_failed THEN
3242            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3243            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_process_LTL_deficit_failed');
3244            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3245       WHEN fte_freight_pricing_util.g_resolve_pricing_objective THEN
3246            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3247            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_resolve_pricing_objective');
3248            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3249       WHEN fte_freight_pricing_util.g_apply_min_charge THEN
3250            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3251            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_apply_min_charge');
3252            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3253       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
3254            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3255            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
3256            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3257       WHEN fte_freight_pricing_util.g_qp_price_request_failed_2 THEN
3258            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3259            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_qp_price_request_failed_2');
3260            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3261       WHEN fte_freight_pricing_util.g_prepare_next_event_failed THEN
3262            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3263            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_prepare_next_event_failed');
3264            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3265       WHEN others THEN
3266            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3267            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
3268            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
3269            fte_freight_pricing_util.unset_method(l_log_level,'process_LTL');
3270 
3271 END process_LTL;
3272 
3273 PROCEDURE print_rolledup_lines (
3274         p_rolledup_lines          IN    fte_freight_pricing.rolledup_line_tab_type,
3275         x_return_status           OUT NOCOPY    VARCHAR2 )
3276 IS
3277 
3278        i     NUMBER:=0;
3279 
3280 BEGIN
3281 
3282    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3283 
3284    IF p_rolledup_lines.COUNT > 0 THEN
3285    FTE_FREIGHT_PRICING_UTIL.print_tag(p_msg => '<ROLLEDUP_LINES>');
3286    i := p_rolledup_lines.FIRST;
3287    LOOP
3288 
3289       FTE_FREIGHT_PRICING_UTIL.print_msg(p_msg => 'delivery_detail_id : '||p_rolledup_lines(i).delivery_detail_id||' category_id : '||p_rolledup_lines(i).category_id||' rate_basis : '||
3290    p_rolledup_lines(i).rate_basis||'container_id : '||p_rolledup_lines(i).container_id||' master_container_id : '||p_rolledup_lines(i).master_container_id||'line_quantity : '||
3291    p_rolledup_lines(i).line_quantity||' line_uom : '||p_rolledup_lines(i).line_uom);
3292 
3293       EXIT WHEN i=p_rolledup_lines.LAST;
3294       i := p_rolledup_lines.NEXT(i);
3295    END LOOP;
3296    FTE_FREIGHT_PRICING_UTIL.print_tag(p_msg => '</ROLLEDUP_LINES>');
3297    END IF;
3298 
3299    IF g_bumped_rolledup_lines.COUNT > 0 THEN
3300    FTE_FREIGHT_PRICING_UTIL.print_tag(p_msg => '<BUMPED_ROLLEDUP_LINES>');
3301    i := g_bumped_rolledup_lines.FIRST;
3302    LOOP
3303 
3304       FTE_FREIGHT_PRICING_UTIL.print_msg(p_msg => 'index : '||i||' line_quantity : '||g_bumped_rolledup_lines(i).line_quantity);
3305 
3306       EXIT WHEN i=g_bumped_rolledup_lines.LAST;
3307       i := g_bumped_rolledup_lines.NEXT(i);
3308    END LOOP;
3309    FTE_FREIGHT_PRICING_UTIL.print_tag(p_msg => '</BUMPED_ROLLEDUP_LINES>');
3310    END IF;
3311 
3312    EXCEPTION
3313    WHEN others THEN
3314         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3315         FTE_FREIGHT_PRICING_UTIL.set_exception('print_rolledup_lines',FTE_FREIGHT_PRICING_UTIL.G_ERR,'g_others');
3316         FTE_FREIGHT_PRICING_UTIL.print_msg(FTE_FREIGHT_PRICING_UTIL.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
3317 END print_rolledup_lines;
3318 
3319 -- new for loose items
3320 PROCEDURE bumpup_rolledup_lines (
3321         p_pricing_engine_input_rec  IN              fte_freight_pricing.pricing_engine_input_rec_type,
3322         p_pricing_dual_instances  IN                fte_freight_pricing.pricing_dual_instance_tab_type,
3323         p_pattern_rows            IN                fte_freight_pricing.top_level_pattern_tab_type,
3324         p_orig_line_qty           IN                NUMBER,
3325         p_orig_uom                IN                VARCHAR2,
3326         p_new_line_qty            IN                NUMBER,
3327         p_new_uom                 IN                VARCHAR2,
3328         x_return_status           OUT NOCOPY                VARCHAR2 )
3329 IS
3330    i                     NUMBER;
3331    l_content_id          NUMBER;
3332    l_instance_idx        NUMBER;
3333    l_temp_qty            NUMBER;
3334    l_temp_uom            VARCHAR2(10);
3335    l_ratio_num           NUMBER;
3336    l_ratio_den           NUMBER;
3337    l_aggregation         VARCHAR2(30);
3338 
3339    l_return_status         VARCHAR2(1);
3340    l_engine_input_rec      fte_freight_pricing.pricing_engine_input_rec_type;
3341    l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
3342    l_method_name VARCHAR2(50) := 'bumpup_rolledup_lines';
3343 BEGIN
3344    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3345    fte_freight_pricing_util.reset_dbg_vars;
3346    -- find ratio of new qty to orig qty for pricing engine input row
3347    -- make sure we are dealing with loose item only
3348    -- get instance id from engine row
3349    -- find pattern rows for engine row
3350    -- for each pattern row, get content_id
3351    -- for each content id get rolledup rows (same as content id for loose items)
3352    -- only get rollup lines which match category and basis on engine row
3353    -- bump up each rolledup row
3354 
3355    IF (p_new_uom <> p_orig_uom) THEN
3356       l_temp_qty    :=  WSH_WV_UTILS.convert_uom(p_new_uom,
3357                                               p_orig_uom,
3358                                               p_new_line_qty,
3359                                               0);  -- Within same UOM class
3360 
3361       l_temp_uom    := p_orig_uom;
3362    ELSE
3363       l_temp_qty    := p_new_line_qty;
3364       l_temp_uom    := p_new_uom;
3365    END IF;
3366 
3367    l_ratio_num   := l_temp_qty;       -- converted new line qty
3368    l_ratio_den   := p_orig_line_qty;  -- original line qty
3369 
3370 
3371    IF (p_pricing_engine_input_rec.loose_item_flag = 'Y') THEN
3372       l_instance_idx := p_pricing_engine_input_rec.instance_index;
3373       l_aggregation := p_pricing_dual_instances(l_instance_idx).aggregation;
3374       i := p_pattern_rows.FIRST;
3375       IF (i IS NOT NULL) THEN
3376       LOOP
3377         IF (p_pattern_rows(i).instance_index = l_instance_idx ) THEN
3378           l_content_id := p_pattern_rows(i).content_id;
3379 
3380 	  IF (l_aggregation = 'ACROSS') THEN
3381 
3382           IF  (nvl(fte_freight_pricing.g_rolledup_lines(l_content_id).rate_basis,-1)
3383                       = nvl(p_pricing_engine_input_rec.basis,-1) ) THEN
3384               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_content_id='||l_content_id);
3385               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'orig->'||fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity);
3386 
3387               --fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity :=
3388                      --(fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity * l_ratio_num) / l_ratio_den;
3389               --bug2803178 keep both the original and  bumped rolledup line quantity
3390               -- if hundred wt rate is chosed, bumped rolledup line quantity is used later
3391               -- if standard rate is chosed, original rolledup line quantity is used later
3392               g_bumped_rolledup_lines(l_content_id).line_quantity :=
3393                      (fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity * l_ratio_num) / l_ratio_den;
3394 
3395               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'bumpedup->'||g_bumped_rolledup_lines(l_content_id).line_quantity);
3396           END IF;
3397 
3398 	  ELSE -- 'WITHIN'
3399 
3400           IF ( nvl(fte_freight_pricing.g_rolledup_lines(l_content_id).category_id,-1)
3401                       = nvl(p_pricing_engine_input_rec.category_id,-1)
3402             AND nvl(fte_freight_pricing.g_rolledup_lines(l_content_id).rate_basis,-1)
3403                       = nvl(p_pricing_engine_input_rec.basis,-1) ) THEN
3404               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_content_id='||l_content_id);
3405               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'orig->'||fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity);
3406 
3407               --fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity :=
3408                      --(fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity * l_ratio_num) / l_ratio_den;
3409               --bug2803178 keep both the original and  bumped rolledup line quantity
3410               -- if hundred wt rate is chosed, bumped rolledup line quantity is used later
3411               -- if standard rate is chosed, original rolledup line quantity is used later
3412               g_bumped_rolledup_lines(l_content_id).line_quantity :=
3413                      (fte_freight_pricing.g_rolledup_lines(l_content_id).line_quantity * l_ratio_num) / l_ratio_den;
3414 
3415               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'bumpedup->'||g_bumped_rolledup_lines(l_content_id).line_quantity);
3416           END IF;
3417 
3418 	  END IF; -- aggregation
3419 
3420         END IF;
3421       EXIT WHEN ( i >= p_pattern_rows.LAST );
3422       i := p_pattern_rows.NEXT(i);
3423       END LOOP;
3424       END IF;
3425 
3426    END IF;
3427 
3428  EXCEPTION
3429  WHEN others THEN
3430            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3431            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
3432            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
3433            fte_freight_pricing_util.unset_method(l_log_level,'bumpup_rolledup_lines');
3434 END bumpup_rolledup_lines;
3435 
3436 
3437 -- This is called for Parcel
3438 PROCEDURE process_Parcel (
3439         p_pricing_control_rec     IN                fte_freight_pricing.pricing_control_input_rec_type,
3440         p_top_level_rows          IN                fte_freight_pricing.shpmnt_content_tab_type,
3441         p_pricing_engine_rows     IN OUT NOCOPY     fte_freight_pricing.pricing_engine_input_tab_type,
3442         p_pricing_dual_instances  IN                fte_freight_pricing.pricing_dual_instance_tab_type,
3443         p_pattern_rows            IN                fte_freight_pricing.top_level_pattern_tab_type,
3444         p_pricing_attribute_rows  IN OUT NOCOPY     fte_freight_pricing.pricing_attribute_tab_type,
3445         --p_pricing_qualifier       IN                fte_qual_rec_type,
3446         --x_qp_output_line_rows     IN OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
3447         --x_qp_output_detail_rows   IN OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
3448         x_qp_output_line_rows     OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
3449         x_qp_output_detail_rows   OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
3450         x_return_status           OUT NOCOPY                VARCHAR2 )
3451 IS
3452 
3453    l_return_status         VARCHAR2(1);
3454    l_total_wt              NUMBER;
3455    l_total_wt_uom          VARCHAR2(30);
3456    l_min_package_wt        NUMBER;
3457    l_min_wt_uom            VARCHAR2(30);
3458    l_event_num             NUMBER;
3459    l_set_num               NUMBER;
3460    i                       NUMBER;
3461    j                       NUMBER;
3462    l_attr_rec              fte_freight_pricing.pricing_attribute_rec_type;
3463    l_temp_wt               NUMBER;
3464    l_charge_applied        VARCHAR2(1);
3465    l_next_weight_break     NUMBER;
3466    l_next_weight_break_uom VARCHAR2(30);
3467    l_curr_last_idx         NUMBER;
3468    l_curr_input_idx        NUMBER;
3469    l_set_one_max_input_idx NUMBER;
3470    l_engine_input_rec      fte_freight_pricing.pricing_engine_input_rec_type;
3471    l_attr_row              fte_freight_pricing.pricing_attribute_rec_type;
3472    l_new_index             NUMBER;
3473 
3474    l_standard_price        NUMBER;
3475    l_hundredwt_price       NUMBER;
3476    l_bumped_up_wt          NUMBER;
3477    l_bumped_up_wt_uom      VARCHAR2(30);
3478    l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
3479    l_method_name VARCHAR2(50) := 'process_Parcel';
3480    l_op_ret_code           NUMBER;
3481    l_letter_flag           VARCHAR2(1) := 'N';
3482    l_parcel_elig_flag      VARCHAR2(1);
3483    l_bump                  VARCHAR2(1);
3484 --- Local Module ----
3485 -- This procedure is to be called by process_Parcel to check if we shipment satisfies conditions for Parcel
3486 FUNCTION check_parcel_eligible        (p_pattern_rows  IN fte_freight_pricing.top_level_pattern_tab_type)
3487 RETURN VARCHAR2
3488 IS
3489  i NUMBER;
3490  ret_value VARCHAR2(30);
3491 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
3492   l_method_name VARCHAR2(50) := 'check_parcel_eligible';
3493  BEGIN
3494    fte_freight_pricing_util.set_method(l_log_level,'check_parcel_eligible');
3495     ret_value := 'Y';  -- Y = OK, N = NOT OK, L = Letter
3496     i := p_pattern_rows.FIRST;
3497     IF (i IS NOT NULL) THEN
3498     LOOP
3499       --only SC_WB and MC_WB are ok for Parcel (except Letter - SC_CB or MC_CB )
3500       -- currently you cannot have a mix of Letter and standard parcel because they are
3501       -- separate service types. A parcel lane can have only one service type.
3502       -- fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'i='||i||' pattern='||p_pattern_rows(i).pattern_no);
3503       -- IF NOT (p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_2
3504       --    OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_5
3505       -- Loose items now have patterns
3506       IF NOT (p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_2
3507           OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_5
3508           OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_9
3509           OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_10 ) THEN
3510               IF (p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_1
3511                  OR p_pattern_rows(i).pattern_no = FTE_FREIGHT_PRICING.G_PATTERN_4 ) THEN
3512                     ret_value := 'L';
3513               ELSE
3514                     ret_value := 'N';
3515               END IF;
3516       END IF;
3517       -- fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'i='||i||' ret_value ='||ret_value);
3518     EXIT WHEN ( i >= p_pattern_rows.LAST OR ret_value = 'N');
3519     i := p_pattern_rows.NEXT(i);
3520     END LOOP;
3521     END IF;
3522    fte_freight_pricing_util.unset_method(l_log_level,'check_parcel_eligible');
3523     RETURN ret_value;
3524 END check_parcel_eligible;
3525 
3526 --- End Local Module --
3527 
3528   -- local module --
3529   -- get the min package wt parameter
3530   PROCEDURE get_min_package_wt (x_min_package_wt  OUT NOCOPY  NUMBER,
3531                                 x_min_wt_uom      OUT NOCOPY  VARCHAR2)
3532   IS
3533        i                NUMBER;
3534        min_package_wt   NUMBER := 0;
3535        min_wt_uom       VARCHAR2(30) := NULL;
3536   l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
3537   l_method_name VARCHAR2(50) := 'get_min_package_wt';
3538  BEGIN
3539      fte_freight_pricing_util.set_method(l_log_level,'get_min_package_wt');
3540      i := g_lane_parameters.FIRST;
3541      IF (i IS NOT NULL) THEN
3542      LOOP
3543          IF (g_lane_parameters(i).parameter_sub_type = 'HUNDREDWT'
3544              AND g_lane_parameters(i).lane_function = 'PARCEL'
3545              AND g_lane_parameters(i).parameter_name = 'MIN_PACKAGE_WT') THEN
3546                 min_package_wt  := fnd_number.canonical_to_number(g_lane_parameters(i).value_from);
3547                 min_wt_uom      := g_lane_parameters(i).uom_code;
3548          END IF;
3549 
3550      EXIT WHEN (i >= g_lane_parameters.LAST);
3551          i := g_lane_parameters.NEXT(i);
3552      END LOOP;
3553      END IF;
3554      x_min_package_wt   := min_package_wt;
3555      x_min_wt_uom       := min_wt_uom;
3556      fte_freight_pricing_util.unset_method(l_log_level,'get_min_package_wt');
3557   EXCEPTION
3558     WHEN others THEN
3559       fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
3560       fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
3561       fte_freight_pricing_util.unset_method(l_log_level, l_method_name);
3562   END  get_min_package_wt;
3563   -- end local module --
3564 
3565 
3566  BEGIN
3567 
3568     -- check if only patterns : SC_WB and MC_WB are present. Throw error if not.
3569     -- calculate the total wt. of the shipment by summing up wts. of top level items in the same uom.
3570     -- we need to check for multi-piece only if shipment has more than 1 container
3571     -- create set 1 : for standard parcel rates
3572             -- create standard lines
3573             -- create standard pricing attributes and qualifiers
3574     -- calculate total shipment wt (here the individual packages are bumped up to the min package wts. if required )
3575     -- create set 2 (if needed) : for hundred wt
3576             -- create standard lines
3577             -- need to bump up individual package wt to min wt.***
3578             -- create standard pricing attributes and qualifiers
3579             -- create attributes for total shipment wt (with bump ups)
3580     -- call qp engine
3581     -- calculate total price of set. Choose the least price i.e. delete the set which has higher price.
3582     -- call pricing objective resolution if needed
3583     -- call min charge logic if needed
3584     -- prepare for second qp call
3585     -- call qp engine
3586     -- any post processing
3587     -- return control to main code
3588 
3589    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3590    fte_freight_pricing_util.reset_dbg_vars;
3591    fte_freight_pricing_util.set_method(l_log_level,'process_Parcel');
3592 
3593     -- Its ok for loose items not to have pattern rows. And loose items should always be eligible for LTL
3594     IF (p_pattern_rows.COUNT >0) THEN
3595        l_parcel_elig_flag := check_parcel_eligible (p_pattern_rows);
3596        IF ( l_parcel_elig_flag  = 'N') THEN
3597            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Parcel Not eligible');
3598            raise fte_freight_pricing_util.g_parcel_not_eligible;
3599        END IF;
3600 
3601        IF ( l_parcel_elig_flag  = 'L') THEN
3602            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_LOG,'Parcel Letter eligible');
3603                  process_others(p_pricing_control_rec     => p_pricing_control_rec,
3604                                 p_pricing_engine_rows     => p_pricing_engine_rows,
3605                                 p_top_level_rows          => p_top_level_rows,
3606                                 p_pricing_dual_instances  => p_pricing_dual_instances,
3607                                 p_pattern_rows            => p_pattern_rows,
3608                                 p_pricing_attribute_rows  => p_pricing_attribute_rows,
3609                                 --p_pricing_qualifier     => p_pricing_qualifier,
3610                                 x_qp_output_line_rows     => x_qp_output_line_rows,
3611                                 x_qp_output_detail_rows   => x_qp_output_detail_rows,
3612                                 x_return_status           => l_return_status );
3613             fte_freight_pricing_util.set_location(p_loc=>'after process_others ');
3614             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3615                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3616                          raise fte_freight_pricing_util.g_process_others_failed;
3617             END IF;
3618             fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
3619             RETURN;
3620        END IF;
3621 
3622     END IF;
3623 
3624 /*
3625     -- get total shipment wt (with package wts bumped up to a min. wt)
3626     get_total_shipment_weight(         p_top_level_rows    =>   p_top_level_rows,
3627                                        p_min_package_wt    =>   l_min_package_wt,
3628                                        p_min_wt_uom        =>   l_min_wt_uom,
3629                                        x_total_wt          =>   l_total_wt,
3630                                        x_wt_uom            =>   l_total_wt_uom,
3631                                        x_return_status     =>   l_return_status);
3632 
3633            fte_freight_pricing_util.set_location(p_loc=>'after get_total_shipment_weight ');
3634            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3635                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3636                         raise fte_freight_pricing_util.g_total_shipment_weight_failed;
3637            ELSE
3638                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_wt = '||l_total_wt);
3639                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_total_wt_uom = '||l_total_wt_uom);
3640            END IF;
3641 */
3642        l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
3643        fte_qp_engine.create_control_record(p_event_num => l_event_num,
3644                                            x_return_status => l_return_status );
3645 
3646            fte_freight_pricing_util.set_location(p_loc=>'after create_control_record ');
3647            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3648                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3649                         raise fte_freight_pricing_util.g_create_control_record_failed;
3650            END IF;
3651 
3652      -- create set I ( for standard rate checking ) --
3653        l_set_num   := 1;
3654        i := p_pricing_engine_rows.FIRST;
3655        IF (i IS NOT NULL) THEN
3656        LOOP
3657             -- The original package quantity (wt) is ceil-ed to the next higher integer
3658             -- eg. 10.2 Lbs becomes 11 Lbs
3659 
3660 	    --4720306
3661             --p_pricing_engine_rows(i).line_quantity  := ceil(p_pricing_engine_rows(i).line_quantity);
3662 
3663             fte_qp_engine.create_line_record (p_pricing_control_rec       => p_pricing_control_rec,
3664                                               p_pricing_engine_input_rec  => p_pricing_engine_rows(i),
3665                                               x_return_status             => l_return_status);
3666 
3667            fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
3668            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3669                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3670                         raise fte_freight_pricing_util.g_create_line_record_failed;
3671            END IF;
3672 
3673             fte_qp_engine.prepare_qp_line_qualifiers(
3674                                               p_event_num               => l_event_num,
3675                                               p_pricing_control_rec       => p_pricing_control_rec,
3676                                               p_input_index             => p_pricing_engine_rows(i).input_index,
3677                                               x_return_status           => l_return_status);
3678 
3679            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
3680            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3681                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3682                         raise fte_freight_pricing_util.g_create_qualifiers_failed;
3683            END IF;
3684 
3685             fte_qp_engine.prepare_qp_line_attributes (
3686                                               p_event_num               => l_event_num,
3687                                               p_input_index             => p_pricing_engine_rows(i).input_index,
3688                                               p_attr_rows               => p_pricing_attribute_rows,
3689                                               x_return_status           => l_return_status);
3690 
3691             fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
3692             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3693                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3694                          raise fte_freight_pricing_util.g_create_attr_failed;
3695             END IF;
3696 
3697 
3698            /* TEST MULTIPIECE FLAG  --BEGIN*/
3699 
3700             l_attr_rec.attribute_index  := p_pricing_attribute_rows(p_pricing_attribute_rows.COUNT).attribute_index + 1;
3701             l_attr_rec.input_index      := i;
3702             l_attr_rec.attribute_name   := 'MULTIPIECE_FLAG';
3703             l_attr_rec.attribute_value  := 'N';
3704 
3705             fte_qp_engine.create_attr_record(  p_event_num              => l_event_num,
3706                                                p_attr_rec               => l_attr_rec,
3707                                                x_return_status          => l_return_status);
3708 
3709             fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record ');
3710             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3711                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3712                          raise fte_freight_pricing_util.g_create_attr_failed;
3713             END IF;
3714 
3715            /* TEST MULTIPIECE FLAG  --END*/
3716 
3717 
3718        EXIT WHEN i >= p_pricing_engine_rows.LAST;
3719        i := p_pricing_engine_rows.NEXT(i);
3720        END LOOP;
3721        END IF;
3722 
3723 
3724     IF g_special_flags.parcel_hundredwt_flag = 'Y' THEN
3725 
3726       -- create set II ( for hundred wt rate checking ) --
3727       -- only if multipiece
3728 
3729     -- get min. package wt. parameter
3730     get_min_package_wt(l_min_package_wt, l_min_wt_uom);
3731    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_min_package_wt '||l_min_package_wt);
3732    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_min_wt_uom '||l_min_wt_uom);
3733 
3734        l_set_num   := 2;
3735        i := p_pricing_engine_rows.FIRST; -- counter for set 1 engine rows
3736        l_curr_last_idx  := p_pricing_engine_rows.LAST; --last set 1 engine row (because only set1 should exist now)
3737        l_new_index := l_curr_last_idx + 1;
3738        IF (i IS NOT NULL) THEN
3739        LOOP
3740             l_curr_input_idx                     := p_pricing_engine_rows(i).input_index; --should be the same as i
3741 
3742             -- copy current row to new row with set = 2 starting with line index as max line index + 1
3743             l_engine_input_rec                   := p_pricing_engine_rows(i);
3744             l_engine_input_rec.input_index       := l_new_index;
3745             l_engine_input_rec.input_set_number  := l_set_num;
3746 
3747 
3748             --bump up ind. package wts to min package wt.
3749             get_bumped_up_package_weight  (p_wt                =>  l_engine_input_rec.line_quantity,
3750                                           p_wt_uom             =>  l_engine_input_rec.line_uom,
3751                                           p_min_package_wt     =>  l_min_package_wt,
3752                                           p_min_wt_uom         =>  l_min_wt_uom,
3753                                           x_new_wt             =>  l_bumped_up_wt,
3754                                           x_new_wt_uom         =>  l_bumped_up_wt_uom,
3755                                           x_bump               =>  l_bump,
3756                                           x_return_status      =>  l_return_status);
3757 
3758             fte_freight_pricing_util.set_location(p_loc=>'after get_bumped_up_package_weight');
3759             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3760                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3761                          raise fte_freight_pricing_util.g_get_bumped_up_wt_failed;
3762             END IF;
3763 
3764 	    -- calculate the total shipment weight
3765 	    IF (l_total_wt is null OR l_total_wt <= 0) THEN
3766 		l_total_wt     := l_bumped_up_wt;
3767 	   	l_total_wt_uom := l_bumped_up_wt_uom;
3768 	    ELSE
3769 
3770               IF (l_bumped_up_wt_uom <> l_total_wt_uom ) THEN
3771                 l_temp_wt   :=  WSH_WV_UTILS.convert_uom(l_bumped_up_wt_uom,
3772 							 l_total_wt_uom,
3773                                                          l_bumped_up_wt,
3774                                                          0);  -- Within same UOM class
3775 		l_total_wt := l_total_wt + l_temp_wt;
3776               ELSE
3777 		l_total_wt := l_total_wt + l_bumped_up_wt;
3778               END IF;
3779 
3780 	    END IF; -- calculate total shipment weight
3781 
3782             fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_engine_input_rec.loose_item_flag='||l_engine_input_rec.loose_item_flag);
3783             fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_bump='||l_bump);
3784 
3785             -- new for loose item
3786             -- bump up rolled up lines - prorate
3787             IF (l_engine_input_rec.loose_item_flag = 'Y' AND l_bump = 'Y') THEN
3788               --bump up
3789               fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'bump up rolled up');
3790               bumpup_rolledup_lines (
3791                  p_pricing_engine_input_rec  =>l_engine_input_rec,
3792                  p_pricing_dual_instances    =>p_pricing_dual_instances,
3793                  p_pattern_rows              => p_pattern_rows,
3794                  p_orig_line_qty             => l_engine_input_rec.line_quantity,
3795                  p_orig_uom                  => l_engine_input_rec.line_uom,
3796                  p_new_line_qty              => l_bumped_up_wt,
3797                  p_new_uom                   => l_bumped_up_wt_uom,
3798                  x_return_status             => l_return_status);
3799 
3800                  fte_freight_pricing_util.set_location(p_loc=>'after bumpup_rolledup_lines');
3801                  IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3802                       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3803                              raise fte_freight_pricing_util.g_get_bumped_up_wt_failed;
3804                  END IF;
3805 
3806 		print_rolledup_lines(
3807 		  p_rolledup_lines => fte_freight_pricing.g_rolledup_lines,
3808 		  x_return_status  => l_return_status);
3809             END IF;
3810 
3811             l_engine_input_rec.line_quantity      := l_bumped_up_wt;
3812             l_engine_input_rec.line_uom           := l_bumped_up_wt_uom;
3813 
3814             p_pricing_engine_rows(l_new_index)   := l_engine_input_rec;
3815 
3816             -- prepare line rec
3817             fte_qp_engine.create_line_record (p_pricing_control_rec       => p_pricing_control_rec,
3818                                               p_pricing_engine_input_rec  => l_engine_input_rec,
3819                                               x_return_status             => l_return_status);
3820 
3821            fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
3822            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3823                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3824                         raise fte_freight_pricing_util.g_create_line_record_failed;
3825            END IF;
3826 
3827             --prepare qualifiers
3828             fte_qp_engine.prepare_qp_line_qualifiers(
3829                                               p_event_num               => l_event_num,
3830                                               p_pricing_control_rec     => p_pricing_control_rec,
3831                                               p_input_index             => l_new_index,
3832                                               x_return_status           => l_return_status);
3833 
3834            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
3835            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3836                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3837                         raise fte_freight_pricing_util.g_create_qualifiers_failed;
3838            END IF;
3839 
3840             -- prepare attributes from the attr rows. line indexes need to be changed
3841             j := p_pricing_attribute_rows.FIRST;
3842             IF (j IS NOT NULL) THEN
3843             LOOP
3844                 IF (p_pricing_attribute_rows(j).input_index = l_curr_input_idx ) THEN
3845                     l_attr_rec                 := p_pricing_attribute_rows(j);
3846                     l_attr_rec.input_index     := l_new_index;
3847                     l_attr_rec.attribute_index := p_pricing_attribute_rows(p_pricing_attribute_rows.COUNT).attribute_index + 1;
3848 
3849                     p_pricing_attribute_rows(l_attr_rec.attribute_index) := l_attr_rec;
3850 
3851                     fte_qp_engine.create_attr_record (     p_event_num              => l_event_num,
3852                                                            p_attr_rec               => l_attr_rec,
3853                                                            x_return_status          => l_return_status);
3854 
3855                     fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record');
3856                     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3857                           l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3858                                  raise fte_freight_pricing_util.g_create_attr_failed;
3859                     END IF;
3860 
3861                 END IF;
3862             EXIT WHEN j = p_pricing_attribute_rows.LAST;
3863             j := p_pricing_attribute_rows.NEXT(j);
3864             END LOOP;
3865             END IF;
3866 
3867             -- add other default attributes --
3868             l_attr_rec.attribute_index  := p_pricing_attribute_rows(p_pricing_attribute_rows.COUNT).attribute_index + 1;
3869             l_attr_rec.input_index      := l_new_index;
3870             l_attr_rec.attribute_name   := 'ITEM_ALL';
3871             l_attr_rec.attribute_value  := 'ALL';
3872 
3873             fte_qp_engine.create_attr_record(  p_event_num              => l_event_num,
3874                                                p_attr_rec               => l_attr_rec,
3875                                                x_return_status          => l_return_status);
3876 
3877             fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record ');
3878             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3879                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3880                          raise fte_freight_pricing_util.g_create_attr_failed;
3881             END IF;
3882 	    /*
3883             -- add other new attributes --
3884             -- VOLUME:TOTAL_ITEM_QUANTITY
3885             l_attr_rec.attribute_index  := p_pricing_attribute_rows.LAST + 1;
3886             l_attr_rec.input_index      := l_new_index;
3887             l_attr_rec.attribute_name   := 'TOTAL_ITEM_QUANTITY';
3888 
3889             IF (p_pricing_engine_rows(i).line_uom <> l_total_wt_uom ) THEN
3890                 l_temp_wt   :=  WSH_WV_UTILS.convert_uom(l_total_wt_uom,
3891                                                          p_pricing_engine_rows(i).line_uom,
3892                                                          l_total_wt,
3893                                                          0);  -- Within same UOM class
3894                 l_attr_rec.attribute_value  := to_char(l_temp_wt);
3895             ELSE
3896                 l_attr_rec.attribute_value  := to_char(l_total_wt);
3897             END IF;
3898 
3899             fte_qp_engine.create_attr_record(p_event_num               => l_event_num,
3900                                              p_attr_rec                => l_attr_rec,
3901                                              x_return_status           => l_return_status);
3902 
3903             fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record ');
3904             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3905                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3906                          raise fte_freight_pricing_util.g_create_attr_failed;
3907             END IF;
3908             */
3909            /* TEST MULTIPIECE FLAG  --BEGIN*/
3910 
3911             l_attr_rec.attribute_index  :=  p_pricing_attribute_rows.LAST + 1;
3912             l_attr_rec.input_index      := l_new_index;
3913             l_attr_rec.attribute_name   := 'MULTIPIECE_FLAG';
3914             l_attr_rec.attribute_value  := 'Y';
3915 
3916             fte_qp_engine.create_attr_record(  p_event_num              => l_event_num,
3917                                                p_attr_rec               => l_attr_rec,
3918                                                x_return_status          => l_return_status);
3919 
3920             fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record ');
3921             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3922                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3923                          raise fte_freight_pricing_util.g_create_attr_failed;
3924             END IF;
3925 
3926            /* TEST MULTIPIECE FLAG  --END*/
3927 
3928            /*
3929             -- LOGISTICS:TOTAL_SHIPMENT_QUANTITY
3930             l_attr_rec.attribute_index  := p_pricing_attribute_rows.LAST + 1;
3931             l_attr_rec.input_index      := l_new_index;
3932             l_attr_rec.attribute_name   := 'TOTAL_SHIPMENT_QUANTITY';
3933 
3934             IF (p_pricing_engine_rows(i).line_uom <> l_total_wt_uom ) THEN
3935                 l_attr_rec.attribute_value  := to_char(l_temp_wt);
3936             ELSE
3937                 l_attr_rec.attribute_value  := to_char(l_total_wt);
3938             END IF;
3939 
3940             fte_qp_engine.create_attr_record(p_event_num               => l_event_num,
3941                                              p_attr_rec                => l_attr_rec,
3942                                              x_return_status           => l_return_status);
3943 
3944             fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record ');
3945             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3946                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3947                          raise fte_freight_pricing_util.g_create_attr_failed;
3948             END IF;
3949            */
3950 
3951 
3952        EXIT WHEN i >= l_curr_last_idx;
3953        i := p_pricing_engine_rows.NEXT(i);
3954        l_new_index := l_new_index + 1;
3955        END LOOP;  -- engine rows
3956        END IF;
3957 
3958        fte_freight_pricing_util.print_msg(l_log_level,'l_total_wt: '||l_total_wt);
3959        fte_freight_pricing_util.print_msg(l_log_level,'l_total_wt_uom: '||l_total_wt_uom);
3960 
3961        -- add TOTAL_ITEM_QUANTITY attribute for second set
3962        i := l_curr_last_idx;
3963        IF (i IS NOT NULL) THEN
3964 	 i := i + 1;
3965        LOOP
3966 
3967             -- add other new attributes --
3968             -- VOLUME:TOTAL_ITEM_QUANTITY
3969             l_attr_rec.attribute_index  := p_pricing_attribute_rows.LAST + 1;
3970             l_attr_rec.input_index      := p_pricing_engine_rows(i).input_index;
3971             l_attr_rec.attribute_name   := 'TOTAL_ITEM_QUANTITY';
3972 
3973             IF (p_pricing_engine_rows(i).line_uom <> l_total_wt_uom ) THEN
3974                 l_temp_wt   :=  WSH_WV_UTILS.convert_uom(l_total_wt_uom,
3975                                                          p_pricing_engine_rows(i).line_uom,
3976                                                          l_total_wt,
3977                                                          0);  -- Within same UOM class
3978                 l_attr_rec.attribute_value  := to_char(l_temp_wt);
3979             ELSE
3980                 l_attr_rec.attribute_value  := to_char(l_total_wt);
3981             END IF;
3982 
3983             fte_qp_engine.create_attr_record(p_event_num               => l_event_num,
3984                                              p_attr_rec                => l_attr_rec,
3985                                              x_return_status           => l_return_status);
3986 
3987             fte_freight_pricing_util.set_location(p_loc=>'after create_attr_record ');
3988             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
3989                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
3990                          raise fte_freight_pricing_util.g_create_attr_failed;
3991             END IF;
3992 
3993        EXIT WHEN i >= p_pricing_engine_rows.LAST;
3994        i := p_pricing_engine_rows.NEXT(i);
3995        END LOOP;  -- engine rows
3996        END IF;
3997 
3998     END IF;  -- g_special_flags.parcel_hundredwt_flag
3999        -- call qp api
4000        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => x_qp_output_line_rows,
4001                                       x_qp_output_detail_rows  => x_qp_output_detail_rows,
4002                                       x_return_status          => l_return_status);
4003 
4004            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api');
4005            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4006                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4007                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
4008                  END IF;
4009            END IF;
4010 
4011        --check for errors in the output
4012            --fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
4013 
4014              fte_qp_engine.check_parcel_output_errors (p_event_num   => l_event_num,
4015                                                        x_return_code => l_op_ret_code,
4016                                                        x_return_status  => l_return_status);
4017 
4018            fte_freight_pricing_util.set_location(p_loc=>'after check_parcel_output_errors: Event '||l_event_num);
4019            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_return_status = '||l_return_status);
4020            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_op_ret_code = '||l_op_ret_code);
4021 
4022            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4023                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4024                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
4025                  END IF;
4026            END IF;
4027 
4028      IF g_special_flags.parcel_hundredwt_flag = 'Y' THEN
4029 
4030        IF (l_op_ret_code = fte_qp_engine.G_PAR_NO_MP_PRICE) THEN
4031           --multipiece prices not found.
4032           --standard rates apply
4033           --delete any set=2 lines that may exist
4034                 l_set_num :=2; --set to delete
4035                 fte_qp_engine.delete_set_from_line_event( p_set_num       => l_set_num,
4036                                                           x_return_status => l_return_status);
4037 
4038                 fte_freight_pricing_util.set_location(p_loc=>'after delete_set_from_line_event. set= '||l_set_num);
4039                 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4040                       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4041                              raise fte_freight_pricing_util.g_delete_set_failed;
4042                 END IF;
4043 
4044                 --bug2803178
4045 		g_bumped_rolledup_lines.DELETE;
4046 
4047                 l_set_num :=1; -- remaining set apply_min_charge to be called with this
4048        ELSIF (l_op_ret_code = fte_qp_engine.G_PAR_NO_SP_PRICE) THEN
4049           --singlepiece prices not found.
4050           --use hundred wt rates
4051           --delete any set=1 lines that may exist
4052                 l_set_num :=1; --set to delete
4053                 fte_qp_engine.delete_set_from_line_event( p_set_num       => l_set_num,
4054                                                           x_return_status => l_return_status);
4055 
4056                 fte_freight_pricing_util.set_location(p_loc=>'after delete_set_from_line_event. set= '||l_set_num);
4057                 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4058                       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4059                              raise fte_freight_pricing_util.g_delete_set_failed;
4060                 END IF;
4061 
4062                 --bug2803178
4063                 i := g_bumped_rolledup_lines.FIRST;
4064 		IF (i is not null) THEN
4065 		LOOP
4066 		  fte_freight_pricing.g_rolledup_lines(i).line_quantity
4067 		    := g_bumped_rolledup_lines(i).line_quantity;
4068 		EXIT WHEN i>= g_bumped_rolledup_lines.LAST;
4069 		i := g_bumped_rolledup_lines.NEXT(i);
4070 		END LOOP; -- g_bumped_rolledup_lines
4071 		END IF;
4072 		g_bumped_rolledup_lines.DELETE;
4073 
4074                 l_set_num :=2; -- remaining set apply_min_charge to be called with this
4075        ELSE -- l_op_ret_code = 0
4076          -- singlepiece and multipiece rates are both found
4077          -- compare the rates and use the lower rates
4078            l_set_num :=1;
4079            fte_qp_engine.get_total_base_price(p_set_num           => l_set_num,
4080                                           x_price  => l_standard_price ,
4081                                           x_return_status  => l_return_status);
4082 
4083            fte_freight_pricing_util.set_location(p_loc=>'after get_total_base_price for set='||l_set_num);
4084            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4085                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4086                         raise FTE_FREIGHT_PRICING_UTIL.g_total_base_price_failed;
4087                  END IF;
4088            ELSE
4089                  fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_standard_price = '||l_standard_price);
4090            END IF;
4091 
4092            l_set_num :=2;
4093            fte_qp_engine.get_total_base_price(p_set_num           => l_set_num,
4094                                               x_price  => l_hundredwt_price,
4095                                               x_return_status  => l_return_status);
4096 
4097            fte_freight_pricing_util.set_location(p_loc=>'after get_total_base_price for set='||l_set_num);
4098            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4099                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4100                             raise fte_freight_pricing_util.g_total_base_price_failed;
4101                      END IF;
4102            ELSE
4103                      fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'l_hundredwt_price= '||l_hundredwt_price);
4104            END IF;
4105 
4106            IF (l_standard_price <= l_hundredwt_price) THEN
4107               -- standard rates apply. delete set 2
4108                  l_set_num :=2; --set to delete
4109                  fte_qp_engine.delete_set_from_line_event( p_set_num       => l_set_num,
4110                                                           x_return_status => l_return_status);
4111 
4112                 fte_freight_pricing_util.set_location(p_loc=>'after delete_set_from_line_event. set= '||l_set_num);
4113                 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4114                       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4115                              raise fte_freight_pricing_util.g_delete_set_failed;
4116                 END IF;
4117 
4118                 --bug2803178
4119 		g_bumped_rolledup_lines.DELETE;
4120 
4121                 l_set_num :=1; -- remaining set apply_min_charge to be called with this
4122            ELSE
4123               -- hundredwt rates apply. delete set 1
4124                  l_set_num :=1; --set to delete
4125                  fte_qp_engine.delete_set_from_line_event( p_set_num       => l_set_num,
4126                                                           x_return_status => l_return_status);
4127 
4128                 fte_freight_pricing_util.set_location(p_loc=>'after delete_set_from_line_event. set= '||l_set_num);
4129                 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4130                       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4131                              raise fte_freight_pricing_util.g_delete_set_failed;
4132                 END IF;
4133 
4134                 --bug2803178
4135                 i := g_bumped_rolledup_lines.FIRST;
4136 		IF (i is not null) THEN
4137 		LOOP
4138 		  fte_freight_pricing.g_rolledup_lines(i).line_quantity
4139 		    := g_bumped_rolledup_lines(i).line_quantity;
4140 		EXIT WHEN i>= g_bumped_rolledup_lines.LAST;
4141 		i := g_bumped_rolledup_lines.NEXT(i);
4142 		END LOOP; -- g_bumped_rolledup_lines
4143 		END IF;
4144 		g_bumped_rolledup_lines.DELETE;
4145 
4146                 l_set_num :=2; -- remaining set apply_min_charge to be called with this
4147            END IF;
4148        END IF; -- l_op_ret_code
4149 
4150      END IF;  -- g_special_flags.parcel_hundredwt_flag
4151 
4152      print_rolledup_lines(
4153 	p_rolledup_lines => fte_freight_pricing.g_rolledup_lines,
4154 	x_return_status  => l_return_status);
4155 
4156      --*** IMP ---
4157    FTE_QP_ENGINE.get_qp_output(
4158      x_qp_output_line_rows    	=> x_qp_output_line_rows,
4159      x_qp_output_detail_rows  	=> x_qp_output_detail_rows,
4160      x_return_status		=> l_return_status);
4161 
4162    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4163        l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4164          raise fte_freight_pricing_util.g_get_qp_output_failed;
4165    END IF;
4166 
4167     post_process(
4168       p_event_num		=> l_event_num,
4169       p_set_num			=> l_set_num,
4170       p_pricing_engine_rows	=> p_pricing_engine_rows,
4171       p_pricing_dual_instances	=> p_pricing_dual_instances,
4172       x_qp_output_line_rows	=> x_qp_output_line_rows,
4173       x_qp_output_detail_rows	=> x_qp_output_detail_rows,
4174       x_return_status		=> l_return_status);
4175 
4176     fte_freight_pricing_util.set_location(p_loc=>'after resolve_pricing_objective');
4177     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4178         l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4179       raise fte_freight_pricing_util.g_post_process_failed;
4180     END IF;
4181 
4182    fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4183  EXCEPTION
4184       WHEN fte_freight_pricing_util.g_post_process_failed THEN
4185            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4186            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_post_process_failed');
4187            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4188       WHEN fte_freight_pricing_util.g_get_qp_output_failed THEN
4189            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4190            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_get_qp_output_failed');
4191            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4192       WHEN fte_freight_pricing_util.g_total_base_price_failed THEN
4193            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4194            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'total_base_price_failed');
4195            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4196       WHEN fte_freight_pricing_util.g_apply_new_base_price_failed THEN
4197            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4198            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_apply_new_base_price_failed');
4199            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4200       WHEN fte_freight_pricing_util.g_delete_set_failed THEN
4201            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4202            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_delete_set_failed');
4203            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4204       WHEN fte_freight_pricing_util.g_resolve_pricing_objective THEN
4205            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4206            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_resolve_pricing_objective');
4207            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4208       WHEN fte_freight_pricing_util.g_apply_min_charge THEN
4209            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4210            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_apply_min_charge');
4211            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4212       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
4213            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4214            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
4215            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4216       WHEN fte_freight_pricing_util.g_qp_price_request_failed_2 THEN
4217            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4218            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_qp_price_request_failed_2');
4219            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4220       WHEN fte_freight_pricing_util.g_prepare_next_event_failed THEN
4221            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4222            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_prepare_next_event_failed');
4223            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4224       WHEN fte_freight_pricing_util.g_get_bumped_up_wt_failed THEN
4225            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4226            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_get_bumped_up_wt_failed');
4227            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4228       WHEN fte_freight_pricing_util.g_parcel_not_eligible THEN
4229            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4230            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_parcel_not_eligible');
4231            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4232       WHEN fte_freight_pricing_util.g_create_control_record_failed THEN
4233            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4234            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_control_record_failed');
4235            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4236       WHEN fte_freight_pricing_util.g_create_line_record_failed THEN
4237            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4238            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_line_record_failed');
4239            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4240       WHEN fte_freight_pricing_util.g_create_qualifiers_failed THEN
4241            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4242            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_qualifiers_failed');
4243            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4244       WHEN fte_freight_pricing_util.g_create_attr_failed THEN
4245            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4246            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_attr_failed');
4247            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4248       WHEN fte_freight_pricing_util.g_process_others_failed THEN
4249            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4250            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_process_others_failed');
4251            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4252       WHEN others THEN
4253            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4254            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
4255            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
4256            fte_freight_pricing_util.unset_method(l_log_level,'process_Parcel');
4257 
4258 
4259 END process_parcel;
4260 
4261 
4262 -- This is called if neither parcel nor LTL
4263 -- create engine lines
4264 -- call qp engine
4265 -- check for min. charge logic
4266 -- make second qp call
4267 PROCEDURE process_others (
4268         p_pricing_control_rec     IN                fte_freight_pricing.pricing_control_input_rec_type,
4269         p_top_level_rows          IN                fte_freight_pricing.shpmnt_content_tab_type,
4270         p_pricing_engine_rows     IN OUT NOCOPY     fte_freight_pricing.pricing_engine_input_tab_type,
4271         p_pricing_dual_instances  IN                fte_freight_pricing.pricing_dual_instance_tab_type,
4272         p_pattern_rows            IN                fte_freight_pricing.top_level_pattern_tab_type,
4273         p_pricing_attribute_rows  IN OUT NOCOPY     fte_freight_pricing.pricing_attribute_tab_type,
4274         --p_pricing_qualifier       IN                fte_qual_rec_type,
4275         x_qp_output_line_rows     OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
4276         x_qp_output_detail_rows   OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
4277         x_return_status           OUT NOCOPY                VARCHAR2 )
4278  IS
4279 
4280    l_return_status         VARCHAR2(1);
4281    l_event_num             NUMBER;
4282    l_set_num               NUMBER;
4283    i                       NUMBER;
4284    j                       NUMBER;
4285    l_attr_rec              fte_freight_pricing.pricing_attribute_rec_type;
4286    l_engine_input_rec      fte_freight_pricing.pricing_engine_input_rec_type;
4287    l_attr_row              fte_freight_pricing.pricing_attribute_rec_type;
4288    l_charge_applied        VARCHAR2(1);
4289 
4290  l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
4291   l_method_name VARCHAR2(50) := 'process_others';
4292  BEGIN
4293    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4294    fte_freight_pricing_util.reset_dbg_vars;
4295    fte_freight_pricing_util.set_method(l_log_level,'process_others');
4296 
4297        -- create standard engine line and attributes (default stuff created by pattern matching)
4298        l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
4299        fte_qp_engine.create_control_record(p_event_num => l_event_num,
4300                                            x_return_status => l_return_status );
4301 
4302            fte_freight_pricing_util.set_location(p_loc=>'after create_control_record ');
4303            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4304                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4305                         raise fte_freight_pricing_util.g_create_control_record_failed;
4306            END IF;
4307 
4308        l_set_num   := 1;
4309        i := p_pricing_engine_rows.FIRST;
4310        IF (i IS NOT NULL) THEN
4311        LOOP
4312             fte_qp_engine.create_line_record (p_pricing_control_rec       => p_pricing_control_rec,
4313                                               p_pricing_engine_input_rec  => p_pricing_engine_rows(i),
4314                                               x_return_status             => l_return_status);
4315 
4316            fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
4317            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4318                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4319                         raise fte_freight_pricing_util.g_create_line_record_failed;
4320            END IF;
4321 
4322             fte_qp_engine.prepare_qp_line_qualifiers(
4323                                               p_event_num               => l_event_num,
4324                                               p_pricing_control_rec       => p_pricing_control_rec,
4325                                               p_input_index             => p_pricing_engine_rows(i).input_index,
4326                                               x_return_status           => l_return_status);
4327 
4328            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
4329            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4330                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4331                         raise fte_freight_pricing_util.g_create_qualifiers_failed;
4332            END IF;
4333 
4334             fte_qp_engine.prepare_qp_line_attributes (
4335                                               p_event_num               => l_event_num,
4336                                               p_input_index             => p_pricing_engine_rows(i).input_index,
4337                                               p_attr_rows               => p_pricing_attribute_rows,
4338                                               x_return_status           => l_return_status);
4339 
4340             fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
4341             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4342                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4343                          raise fte_freight_pricing_util.g_create_attr_failed;
4344             END IF;
4345 
4346        EXIT WHEN i >= p_pricing_engine_rows.LAST;
4347        i := p_pricing_engine_rows.NEXT(i);
4348        END LOOP;
4349        END IF;
4350 
4351 
4352        -- fte_qp_engine.print_qp_input_lines(1);
4353 
4354        -- call qp api
4355        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => x_qp_output_line_rows,
4356                                       x_qp_output_detail_rows  => x_qp_output_detail_rows,
4357                                       x_return_status          => l_return_status);
4358 
4359            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 1');
4360            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4361                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4362                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
4363                  END IF;
4364            END IF;
4365 
4366        --check for errors in the output
4367            fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
4368            fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
4369            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4370                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4371                         raise fte_freight_pricing_util.g_qp_price_request_failed_2;
4372                  END IF;
4373            END IF;
4374 
4375        fte_qp_engine.print_qp_output();
4376 
4377     post_process(
4378       p_event_num		=> l_event_num,
4379       p_set_num			=> l_set_num,
4380       p_pricing_engine_rows	=> p_pricing_engine_rows,
4381       p_pricing_dual_instances	=> p_pricing_dual_instances,
4382       x_qp_output_line_rows	=> x_qp_output_line_rows,
4383       x_qp_output_detail_rows	=> x_qp_output_detail_rows,
4384       x_return_status		=> l_return_status);
4385 
4386     fte_freight_pricing_util.set_location(p_loc=>'after resolve_pricing_objective');
4387     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4388         l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4389       raise fte_freight_pricing_util.g_post_process_failed;
4390     END IF;
4391 
4392    fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4393  EXCEPTION
4394       WHEN fte_freight_pricing_util.g_post_process_failed THEN
4395            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4396            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_post_process_failed');
4397            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4398       WHEN fte_freight_pricing_util.g_create_control_record_failed THEN
4399            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4400            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_control_record_failed');
4401            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4402       WHEN fte_freight_pricing_util.g_create_line_record_failed THEN
4403            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4404            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_line_record_failed');
4405            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4406       WHEN fte_freight_pricing_util.g_create_qualifiers_failed THEN
4407            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4408            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_qualifiers_failed');
4409            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4410       WHEN fte_freight_pricing_util.g_create_attr_failed THEN
4411            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4412            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_attr_failed');
4413            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4414       WHEN fte_freight_pricing_util.g_resolve_pricing_objective THEN
4415            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4416            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_resolve_pricing_objective');
4417            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4418       WHEN fte_freight_pricing_util.g_apply_min_charge THEN
4419            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4420            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_apply_min_charge');
4421            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4422       WHEN fte_freight_pricing_util.g_total_shipment_weight_failed THEN
4423            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4424            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_total_shipment_weight_failed');
4425            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4426       WHEN fte_freight_pricing_util.g_qp_price_request_failed_2 THEN
4427            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4428            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_qp_price_request_failed_2');
4429            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4430       WHEN fte_freight_pricing_util.g_prepare_next_event_failed THEN
4431            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4432            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_prepare_next_event_failed');
4433            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4434       WHEN others THEN
4435            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4436            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
4437            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
4438            fte_freight_pricing_util.unset_method(l_log_level,'process_others');
4439 
4440  END process_others;
4441 
4442 
4443 
4444 -- Is called by the main code after searching for patterns and creating standard engine rows and attributes
4445 -- Checks process flags.
4446 -- Depending upon the mix of conditions it calls other internal procedures to process the input lines.
4447 -- If no special conditions apply, standard code is executed (process_others). It still needs to check for min. charges
4448 -- if enabled.
4449 
4450 PROCEDURE process_special_conditions(
4451         p_pricing_control_rec     IN                fte_freight_pricing.pricing_control_input_rec_type,
4452         p_top_level_rows          IN                fte_freight_pricing.shpmnt_content_tab_type,
4453         p_pattern_rows            IN                fte_freight_pricing.top_level_pattern_tab_type,
4454         p_pricing_dual_instances  IN                fte_freight_pricing.pricing_dual_instance_tab_type,
4455         x_pricing_engine_rows     IN OUT NOCOPY     fte_freight_pricing.pricing_engine_input_tab_type,
4456         x_pricing_attribute_rows  IN OUT NOCOPY     fte_freight_pricing.pricing_attribute_tab_type,
4457         x_qp_output_line_rows     OUT NOCOPY     QP_PREQ_GRP.LINE_TBL_TYPE,
4458         x_qp_output_detail_rows   OUT NOCOPY     QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE,
4459         x_return_status           OUT NOCOPY                VARCHAR2 )
4460 IS
4461 
4462 l_return_status                      VARCHAR2(1);
4463 
4464 l_log_level  NUMBER := fte_freight_pricing_util.G_DBG;
4465 l_method_name VARCHAR2(50) := 'process_special_conditions';
4466  BEGIN
4467 
4468    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4469    fte_freight_pricing_util.reset_dbg_vars;
4470    fte_freight_pricing_util.set_method(l_log_level,l_method_name);
4471      -- check if lane function is LTL or PARCEL.
4472 
4473    fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_DBG,'p_pricing_control_rec.currency_code = '||p_pricing_control_rec.currency_code);
4474 
4475    IF (p_pricing_control_rec.currency_code IS NULL) THEN
4476        raise fte_freight_pricing_util.g_no_currency_found;
4477    END IF;
4478 
4479    IF (p_pricing_control_rec.lane_id IS NULL) THEN
4480        raise fte_freight_pricing_util.g_no_lane_found;
4481    END IF;
4482 
4483    --IF (p_pricing_control_rec.lane_id IS NULL) THEN
4484    IF (p_pricing_control_rec.price_list_id IS NULL) THEN
4485        raise fte_freight_pricing_util.g_no_price_list_on_lane;
4486    END IF;
4487 
4488    IF (p_pricing_control_rec.party_id IS NULL) THEN
4489        raise fte_freight_pricing_util.g_no_party_id_found;
4490    END IF;
4491 
4492 
4493 
4494      IF ( isLTL = 'Y') THEN
4495         process_LTL(p_pricing_control_rec     => p_pricing_control_rec,
4496                    p_top_level_rows           => p_top_level_rows,
4497                    p_pricing_engine_rows     => x_pricing_engine_rows,
4498                    p_pricing_dual_instances  => p_pricing_dual_instances,
4499                    p_pattern_rows            => p_pattern_rows,
4500                    p_pricing_attribute_rows  => x_pricing_attribute_rows,
4501                    x_qp_output_line_rows     => x_qp_output_line_rows,
4502                    x_qp_output_detail_rows   => x_qp_output_detail_rows,
4503                    x_return_status           => l_return_status );
4504 
4505             fte_freight_pricing_util.set_location(p_loc=>'after process_LTL ');
4506             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4507                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4508                          raise fte_freight_pricing_util.g_process_LTL_failed;
4509             END IF;
4510 
4511      ELSIF ( isParcel = 'Y') THEN
4512          process_Parcel(p_pricing_control_rec     => p_pricing_control_rec,
4513                    p_pricing_engine_rows     => x_pricing_engine_rows,
4514                    p_top_level_rows           => p_top_level_rows,
4515                    p_pricing_dual_instances  => p_pricing_dual_instances,
4516                    p_pattern_rows            => p_pattern_rows,
4517                    p_pricing_attribute_rows  => x_pricing_attribute_rows,
4518                    x_qp_output_line_rows     => x_qp_output_line_rows,
4519                    x_qp_output_detail_rows   => x_qp_output_detail_rows,
4520                    x_return_status           => l_return_status );
4521 
4522             fte_freight_pricing_util.set_location(p_loc=>'after process_Parcel ');
4523             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4524                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4525                          raise fte_freight_pricing_util.g_process_Parcel_failed;
4526             END IF;
4527      ELSE
4528         --
4529         -- 03/08/02 : None : need to call standard qp call + chekc for min. charge + new call if applicable
4530                  process_others(p_pricing_control_rec     => p_pricing_control_rec,
4531                                 p_pricing_engine_rows     => x_pricing_engine_rows,
4532                                 p_top_level_rows          => p_top_level_rows,
4533                                 p_pricing_dual_instances  => p_pricing_dual_instances,
4534                                 p_pattern_rows            => p_pattern_rows,
4535                                 p_pricing_attribute_rows  => x_pricing_attribute_rows,
4536                                 x_qp_output_line_rows     => x_qp_output_line_rows,
4537                                 x_qp_output_detail_rows   => x_qp_output_detail_rows,
4538                                 x_return_status           => l_return_status );
4539 
4540             fte_freight_pricing_util.set_location(p_loc=>'after process_others ');
4541             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4542                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4543                          raise fte_freight_pricing_util.g_process_others_failed;
4544             END IF;
4545 
4546      END IF;
4547 
4548  fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4549  EXCEPTION
4550       WHEN fte_freight_pricing_util.g_no_party_id_found THEN
4551            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4552            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_party_id_found');
4553            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4554       WHEN fte_freight_pricing_util.g_no_price_list_on_lane THEN
4555            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4556            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_price_list_on_lane');
4557            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4558       WHEN fte_freight_pricing_util.g_no_lane_found THEN
4559            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4560            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_lane_found');
4561            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4562       WHEN fte_freight_pricing_util.g_no_currency_found THEN
4563            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4564            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_no_currency_found');
4565            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4566       WHEN fte_freight_pricing_util.g_process_LTL_failed THEN
4567            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4568            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_process_LTL_failed');
4569            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4570       WHEN fte_freight_pricing_util.g_process_Parcel_failed THEN
4571            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4572            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_process_Parcel_failed');
4573            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4574       WHEN fte_freight_pricing_util.g_process_others_failed THEN
4575            x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4576            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_create_attr_failed');
4577            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4578       WHEN others THEN
4579            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4580            fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'g_others');
4581            fte_freight_pricing_util.print_msg(fte_freight_pricing_util.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
4582            fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
4583 
4584 END process_special_conditions;
4585 
4586 -- J+ enhancement for container_all rate basis
4587 -- this procedure is called by shipment_pricing to rate container_all basis
4588 PROCEDURE rate_container_all(
4589         p_lane_info		     	IN fte_freight_pricing.lane_info_rec_type,
4590         p_top_level_rows          	IN fte_freight_pricing.shpmnt_content_tab_type,
4591         p_save_flag               	IN VARCHAR2,
4592         p_currency_code			IN VARCHAR2 ,
4593         x_freight_cost_main_price  	OUT NOCOPY fte_freight_pricing.Freight_Cost_Main_Tab_Type,
4594         x_freight_cost_temp_price  	OUT NOCOPY fte_freight_pricing.Freight_Cost_Temp_Tab_Type,
4595         x_freight_cost_main_charge 	OUT NOCOPY fte_freight_pricing.Freight_Cost_Main_Tab_Type,
4596         x_freight_cost_temp_charge 	OUT NOCOPY fte_freight_pricing.Freight_Cost_Temp_Tab_Type,
4597         x_fc_main_update_rows     	OUT NOCOPY fte_freight_pricing.Freight_Cost_Main_Tab_Type,
4598         x_summary_lanesched_price      	OUT NOCOPY NUMBER,
4599         x_summary_lanesched_price_uom  	OUT NOCOPY VARCHAR2,
4600         x_return_status           	OUT NOCOPY VARCHAR2 )
4601 IS
4602   l_log_level NUMBER := fte_freight_pricing_util.G_DBG;
4603   l_method_name VARCHAR2(50) := 'rate_container_all';
4604   l_return_status VARCHAR2(1);
4605 
4606   l_pricing_control_rec fte_freight_pricing.pricing_control_input_rec_type;
4607   l_pricing_engine_rows fte_freight_pricing.pricing_engine_input_tab_type;
4608   l_engine_row_count NUMBER;
4609   l_pricing_attribute_rows fte_freight_pricing.pricing_attribute_tab_type;
4610 
4611   l_qp_output_line_rows QP_PREQ_GRP.LINE_TBL_TYPE;
4612   l_qp_output_detail_rows QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
4613 
4614   l_uom_ea VARCHAR2(30);
4615   i NUMBER;
4616   j NUMBER;
4617   l_event_num NUMBER;
4618   l_currency_code VARCHAR2(30);
4619   l_lane_function VARCHAR2(30);
4620   l_charge_applied VARCHAR2(1);
4621 
4622   l_fc_rec                      fte_freight_pricing.top_level_fc_rec_type;
4623   l_fc_charge_rec               fte_freight_pricing.top_level_fc_rec_type;
4624   n NUMBER;
4625   l_line_price_amount NUMBER;
4626   l_line_charge_amount NUMBER;
4627   l_line_discount_amount NUMBER;
4628   l_summary_amount NUMBER;
4629   l_price_count            NUMBER;
4630   l_charge_count           NUMBER;
4631 
4632   l_leg_id NUMBER;
4633   l_delivery_id NUMBER;
4634 
4635   l_leg_id_array dbms_utility.number_array;
4636   l_delivery_id_array  dbms_utility.number_array;
4637   l_delivery_summary dbms_utility.number_array;
4638 
4639   l_freight_cost_type_id NUMBER;
4640 
4641 BEGIN
4642   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4643 
4644   FTE_FREIGHT_PRICING_UTIL.reset_dbg_vars;
4645   FTE_FREIGHT_PRICING_UTIL.set_method(l_log_level,l_method_name);
4646 
4647   -- group top level containers into pricing engine input lines by container_type
4648   -- set up the pricing attributes for each input line
4649   -- call QP
4650   -- check min charge parameter
4651   -- if need to apply minimum charge
4652   --    prepare second call to qp
4653   -- process qp output
4654   --   distribute qp output back to top level containers
4655 
4656   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_top_level_rows.COUNT='||p_top_level_rows.COUNT);
4657   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_save_flag='||p_save_flag);
4658 
4659   OPEN get_uom_for_each;
4660   FETCH get_uom_for_each INTO l_uom_ea;
4661   CLOSE get_uom_for_each;
4662 
4663   IF l_uom_ea is null THEN
4664     FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'uom for each is null');
4665     raise FND_API.G_EXC_ERROR;
4666   END IF;
4667 
4668   -- Modified for 12i for Multi currency support.
4669   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_currency_code '|| p_currency_code);
4670 
4671   IF p_currency_code IS NOT NULL THEN
4672         l_currency_code := p_currency_code;
4673   ELSE
4674      fte_freight_pricing.get_currency_code(
4675        p_carrier_id      =>   p_lane_info.carrier_id,
4676        x_currency_code   =>   l_currency_code,
4677        x_return_status   =>   l_return_status );
4678   END IF;
4679 
4680   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS and
4681         l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4682     FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'get currency code failed');
4683       raise FND_API.G_EXC_ERROR;
4684   END IF;
4685 
4686   -- group top level rows by container type into pricing engine rows
4687   l_engine_row_count := 0;
4688 
4689   i := p_top_level_rows.FIRST;
4690   IF (i is not null) THEN
4691   LOOP
4692     IF ((p_top_level_rows(i).container_flag IS NULL) OR (p_top_level_rows(i).container_flag = 'N')) THEN
4693       FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'top level loose item cannot be rated in rate basis CONTAINER_ALL');
4694       raise FND_API.G_EXC_ERROR;
4695     END IF;
4696     IF p_top_level_rows(i).container_type_code is null THEN
4697       FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'top level container type code is null, cannot be rated in rate basis CONTAINER_ALL');
4698       raise FND_API.G_EXC_ERROR;
4699     END IF;
4700 
4701     IF l_engine_row_count = 0 THEN
4702       l_engine_row_count := 1;
4703       l_pricing_engine_rows(l_engine_row_count).input_index := 1;
4704       l_pricing_engine_rows(l_engine_row_count).line_quantity  := 1;
4705       l_pricing_engine_rows(l_engine_row_count).line_uom := l_uom_ea;
4706       l_pricing_engine_rows(l_engine_row_count).container_type_code := p_top_level_rows(i).container_type_code;
4707     ELSE
4708 
4709       j := 1;
4710       LOOP
4711 	IF p_top_level_rows(i).container_type_code = l_pricing_engine_rows(j).container_type_code THEN
4712       	  l_pricing_engine_rows(j).line_quantity  := l_pricing_engine_rows(j).line_quantity + 1;
4713 	  EXIT;
4714 	END IF;
4715 
4716 	j := j + 1;
4717 
4718 	IF j > l_engine_row_count THEN
4719       	  l_engine_row_count := j;
4720       	  l_pricing_engine_rows(j).input_index := j;
4721       	  l_pricing_engine_rows(j).line_quantity  := 1;
4722       	  l_pricing_engine_rows(j).line_uom := l_uom_ea;
4723       	  l_pricing_engine_rows(j).container_type_code := p_top_level_rows(i).container_type_code;
4724 	  EXIT;
4725 	END IF;
4726 
4727       END LOOP; -- l_pricing_engine_rows(j)
4728 
4729     END IF; -- l_engine_row_count > 0
4730 
4731   EXIT WHEN (i >= p_top_level_rows.LAST);
4732   i := p_top_level_rows.NEXT(i);
4733   END LOOP;
4734   END IF;
4735 
4736   fte_freight_pricing.print_engine_rows (
4737         p_engine_rows             =>    l_pricing_engine_rows,
4738         x_return_status           =>    l_return_status );
4739 
4740   initialize(
4741     p_lane_id         => p_lane_info.lane_id,
4742     x_lane_function   => l_lane_function,
4743     x_return_status   => l_return_status);
4744 
4745   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4746      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4747     raise FND_API.G_EXC_ERROR;
4748   END IF;
4749 
4750   -- set up data structure to call QP
4751   -- call QP
4752   -- check qp output for any errors
4753 
4754   l_pricing_control_rec.pricing_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
4755   l_pricing_control_rec.currency_code     := l_currency_code;
4756   l_pricing_control_rec.lane_id           := p_lane_info.lane_id;
4757   l_pricing_control_rec.price_list_id     := p_lane_info.pricelist_id;
4758   l_pricing_control_rec.party_id          := p_lane_info.carrier_id;
4759 
4760   i := l_pricing_engine_rows.FIRST;
4761   j := l_pricing_attribute_rows.COUNT;
4762   LOOP
4763 
4764       j := j + 1;
4765          l_pricing_attribute_rows(j).attribute_index := j;
4766          l_pricing_attribute_rows(j).input_index     := i;
4767          l_pricing_attribute_rows(j).attribute_name  := 'ORIGIN_ZONE';
4768          l_pricing_attribute_rows(j).attribute_value := TO_CHAR(p_lane_info.origin_id);
4769       j := j + 1;
4770          l_pricing_attribute_rows(j).attribute_index := j;
4771          l_pricing_attribute_rows(j).input_index     := i;
4772          l_pricing_attribute_rows(j).attribute_name  := 'DESTINATION_ZONE';
4773          l_pricing_attribute_rows(j).attribute_value := TO_CHAR(p_lane_info.destination_id);
4774       j := j + 1;
4775          l_pricing_attribute_rows(j).attribute_index := j;
4776          l_pricing_attribute_rows(j).input_index     := i;
4777          l_pricing_attribute_rows(j).attribute_name  := 'CONTAINER_TYPE';
4778          l_pricing_attribute_rows(j).attribute_value := l_pricing_engine_rows(i).container_type_code;
4779 
4780       IF p_lane_info.service_type_code IS NOT NULL THEN
4781 
4782       j := j + 1;
4783          l_pricing_attribute_rows(j).attribute_index := j;
4784          l_pricing_attribute_rows(j).input_index     := i;
4785          l_pricing_attribute_rows(j).attribute_name  := 'SERVICE_TYPE';  --  Is it required always
4786          l_pricing_attribute_rows(j).attribute_value := p_lane_info.service_type_code;
4787 
4788       END IF;
4789 
4790 
4791       EXIT WHEN i = l_pricing_engine_rows.LAST;
4792       i := l_pricing_engine_rows.NEXT(i);
4793 
4794   END LOOP;
4795 
4796        -- create standard engine line and attributes (default stuff created by pattern matching)
4797        l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
4798        fte_qp_engine.create_control_record(p_event_num => l_event_num,
4799                                            x_return_status => l_return_status );
4800 
4801            fte_freight_pricing_util.set_location(p_loc=>'after create_control_record ');
4802            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4803                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4804       		raise FND_API.G_EXC_ERROR;
4805            END IF;
4806 
4807        --l_set_num   := 1;
4808        i := l_pricing_engine_rows.FIRST;
4809        IF (i IS NOT NULL) THEN
4810        LOOP
4811             fte_qp_engine.create_line_record (p_pricing_control_rec       => l_pricing_control_rec,
4812                                               p_pricing_engine_input_rec  => l_pricing_engine_rows(i),
4813                                               x_return_status             => l_return_status);
4814 
4815            fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
4816            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4817                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4818       		raise FND_API.G_EXC_ERROR;
4819            END IF;
4820 
4821             fte_qp_engine.prepare_qp_line_qualifiers(
4822                                               p_event_num               => l_event_num,
4823                                               p_pricing_control_rec       => l_pricing_control_rec,
4824                                               p_input_index             => l_pricing_engine_rows(i).input_index,
4825                                               x_return_status           => l_return_status);
4826 
4827            fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
4828            IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4829                  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4830       		raise FND_API.G_EXC_ERROR;
4831            END IF;
4832 
4833             fte_qp_engine.prepare_qp_line_attributes (
4834                                               p_event_num               => l_event_num,
4835                                               p_input_index             => l_pricing_engine_rows(i).input_index,
4836                                               p_attr_rows               => l_pricing_attribute_rows,
4837                                               x_return_status           => l_return_status);
4838 
4839             fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
4840             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4841                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4842       		raise FND_API.G_EXC_ERROR;
4843             END IF;
4844 
4845        EXIT WHEN i >= l_pricing_engine_rows.LAST;
4846        i := l_pricing_engine_rows.NEXT(i);
4847        END LOOP;
4848        END IF;
4849 
4850        -- call qp api
4851        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => l_qp_output_line_rows,
4852                                       x_qp_output_detail_rows  => l_qp_output_detail_rows,
4853                                       x_return_status          => l_return_status);
4854 
4855            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 1');
4856            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4857               l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4858       		raise FND_API.G_EXC_ERROR;
4859            END IF;
4860 
4861        --check for errors in the output
4862            fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
4863            fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
4864            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4865               l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4866       		raise FND_API.G_EXC_ERROR;
4867            END IF;
4868 
4869        fte_qp_engine.print_qp_output();
4870 
4871   IF (g_special_flags.minimum_charge_flag = 'Y') THEN
4872 
4873     apply_min_charge(
4874 	p_event_num      => l_event_num,
4875         x_charge_applied => l_charge_applied,
4876         x_return_status  => l_return_status);
4877 
4878     fte_freight_pricing_util.set_location(p_loc=>'after apply_min_charge ');
4879     IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4880         l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4881       raise FND_API.G_EXC_ERROR;
4882     END IF;
4883   END IF;
4884 
4885   -- create request lines for the next event and call qp engine
4886   IF (l_charge_applied = 'Y') THEN
4887        l_event_num := fte_qp_engine.G_CHARGE_EVENT_NUM;
4888        fte_qp_engine.prepare_next_event_request ( x_return_status           => l_return_status);
4889 
4890             fte_freight_pricing_util.set_location(p_loc=>'after prepare_next_event_request');
4891             IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4892                   l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
4893       		raise FND_API.G_EXC_ERROR;
4894             END IF;
4895 
4896        fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => l_qp_output_line_rows,
4897                                       x_qp_output_detail_rows  => l_qp_output_detail_rows,
4898                                       x_return_status          => l_return_status);
4899 
4900            fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 2');
4901            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4902                l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4903       		raise FND_API.G_EXC_ERROR;
4904            END IF;
4905 
4906        --check for errors in the output
4907            fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
4908            fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
4909            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4910               l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4911       		raise FND_API.G_EXC_ERROR;
4912            END IF;
4913 
4914        fte_qp_engine.print_qp_output();
4915 
4916   END IF; -- l_charge_applied = 'Y'
4917 
4918   -- process qp output
4919 
4920   l_price_count := 0;
4921   l_charge_count := 0;
4922   l_summary_amount := 0;
4923 
4924   i := l_qp_output_line_rows.FIRST;
4925   IF (i is not null) THEN
4926   LOOP
4927 
4928     l_fc_rec.quantity := l_pricing_engine_rows(l_qp_output_line_rows(i).line_index).line_quantity;
4929     l_fc_rec.uom := l_pricing_engine_rows(l_qp_output_line_rows(i).line_index).line_uom;
4930     l_fc_rec.currency_code := l_currency_code;
4931 
4932     l_line_charge_amount := 0;
4933     l_line_discount_amount := 0;
4934 
4935     j := l_qp_output_detail_rows.FIRST;
4936     IF (j is not null) THEN
4937     LOOP
4938 
4939       IF (l_qp_output_detail_rows(j).list_line_type_code = 'SUR' OR
4940      	 l_qp_output_detail_rows(j).list_line_type_code = 'DIS' )
4941 	AND (l_qp_output_line_rows(i).line_index =
4942 	     l_qp_output_detail_rows(j).line_index ) THEN
4943 
4944 	l_fc_charge_rec.total_amount :=
4945 	  ABS( l_qp_output_detail_rows(j).adjustment_amount )
4946 	  * l_qp_output_line_rows(i).priced_quantity;
4947 	l_fc_charge_rec.charge_unit_value:= l_fc_charge_rec.total_amount / l_fc_rec.quantity;
4948 
4949 	IF l_qp_output_detail_rows(j).list_line_type_code = 'SUR' THEN
4950 	  l_line_charge_amount := l_line_charge_amount + l_fc_charge_rec.total_amount;
4951 	  l_fc_charge_rec.unit_amount := l_fc_charge_rec.total_amount;
4952 
4953 	  l_fc_charge_rec.line_type_code := 'CHARGE';
4954 
4955           fte_freight_pricing.get_fc_type_id(
4956                       p_line_type_code => 'FTECHARGE',
4957                       p_charge_subtype_code  => l_qp_output_detail_rows(j).charge_subtype_code,
4958                       x_freight_cost_type_id  => l_fc_charge_rec.freight_cost_type_id,
4959                       x_return_status  =>  l_return_status);
4960           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4961                l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4962       		raise FND_API.G_EXC_ERROR;
4963           END IF;
4964 	ELSE -- l_qp_output_detail_rows(j).list_line_type_code = 'DIS'
4965 	  l_line_discount_amount := l_line_discount_amount + l_fc_charge_rec.total_amount;
4966 
4967 	  l_fc_charge_rec.line_type_code := 'DISCOUNT';
4968 
4969           fte_freight_pricing.get_fc_type_id(
4970                       p_line_type_code => 'FTEDISCOUNT',
4971                       p_charge_subtype_code  => 'DISCOUNT',
4972                       x_freight_cost_type_id  => l_fc_charge_rec.freight_cost_type_id,
4973                       x_return_status  =>  l_return_status);
4974           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
4975                l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4976       		raise FND_API.G_EXC_ERROR;
4977           END IF;
4978 	END IF;
4979 
4980     	--distribute SUR/DIS into top level containers
4981 	n := p_top_level_rows.FIRST;
4982     	IF (n is not null) THEN
4983     	LOOP
4984 
4985 	 IF p_top_level_rows(n).container_type_code =
4986 	  l_pricing_engine_rows(l_qp_output_line_rows(i).line_index).container_type_code THEN
4987 
4988 	  l_charge_count := l_charge_count + 1;
4989 	  IF p_save_flag = 'M' THEN
4990 	    x_freight_cost_main_charge(l_charge_count).delivery_detail_id := p_top_level_rows(n).content_id;
4991 	    x_freight_cost_main_charge(l_charge_count).delivery_leg_id := p_top_level_rows(n).delivery_leg_id;
4992 	    x_freight_cost_main_charge(l_charge_count).delivery_id :=
4993 		fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
4994 	    x_freight_cost_main_charge(l_charge_count).uom := l_fc_rec.uom;
4995 	    x_freight_cost_main_charge(l_charge_count).quantity := 1;
4996 	    x_freight_cost_main_charge(l_charge_count).line_type_code := l_fc_charge_rec.line_type_code;
4997 	    x_freight_cost_main_charge(l_charge_count).freight_cost_type_id := l_fc_charge_rec.freight_cost_type_id;
4998 	    x_freight_cost_main_charge(l_charge_count).charge_unit_value :=
4999 		l_fc_charge_rec.charge_unit_value;
5000 	    IF l_fc_charge_rec.unit_amount > 0 THEN
5001 	      x_freight_cost_main_charge(l_charge_count).unit_amount :=
5002 		round(l_fc_charge_rec.unit_amount / l_fc_rec.quantity, 2);
5003 	    END IF;
5004 	    x_freight_cost_main_charge(l_charge_count).total_amount :=
5005 		round(l_fc_charge_rec.total_amount / l_fc_rec.quantity, 2);
5006 	    x_freight_cost_main_charge(l_charge_count).currency_code := l_currency_code;
5007 	    x_freight_cost_main_charge(l_charge_count).charge_source_code := 'PRICING_ENGINE';
5008 	    x_freight_cost_main_charge(l_charge_count).estimated_flag := 'Y';
5009 	  ELSE
5010 	    x_freight_cost_temp_charge(l_charge_count).delivery_detail_id := p_top_level_rows(n).content_id;
5011 	    x_freight_cost_temp_charge(l_charge_count).delivery_id :=
5012 		fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
5013 	    x_freight_cost_temp_charge(l_charge_count).uom := l_fc_rec.uom;
5014 	    x_freight_cost_temp_charge(l_charge_count).quantity := 1;
5015 	    x_freight_cost_temp_charge(l_charge_count).line_type_code := l_fc_charge_rec.line_type_code;
5016 	    x_freight_cost_temp_charge(l_charge_count).freight_cost_type_id := l_fc_charge_rec.freight_cost_type_id;
5017 	    x_freight_cost_temp_charge(l_charge_count).charge_unit_value :=
5018 		l_fc_charge_rec.charge_unit_value;
5019 	    IF l_fc_charge_rec.unit_amount > 0 THEN
5020 	      x_freight_cost_temp_charge(l_charge_count).unit_amount :=
5021 		round(l_fc_charge_rec.unit_amount / l_fc_rec.quantity, 2);
5022 	    END IF;
5023 	    x_freight_cost_temp_charge(l_charge_count).total_amount :=
5024 		round(l_fc_charge_rec.total_amount / l_fc_rec.quantity, 2);
5025 	    x_freight_cost_temp_charge(l_charge_count).currency_code := l_currency_code;
5026 	    x_freight_cost_temp_charge(l_charge_count).charge_source_code := 'PRICING_ENGINE';
5027 	    x_freight_cost_temp_charge(l_charge_count).estimated_flag := 'Y';
5028 	  END IF;
5029 
5030 	 END IF; -- container_type compare
5031 
5032     	EXIT WHEN (n >= p_top_level_rows.LAST);
5033     	n := p_top_level_rows.NEXT(n);
5034     	END LOOP;
5035     	END IF;
5036 
5037       END IF; -- l_qp_output_detail_rows(j).list_line_type_code = 'SUR' or 'DIS'
5038 
5039     EXIT WHEN (j >= l_qp_output_detail_rows.LAST);
5040     j := l_qp_output_detail_rows.NEXT(j);
5041     END LOOP;
5042     END IF;
5043 
5044     l_line_price_amount := l_qp_output_line_rows(i).unit_price *
5045 	l_qp_output_line_rows(i).priced_quantity;
5046     l_fc_rec.charge_unit_value := l_line_price_amount / l_fc_rec.quantity;
5047     l_fc_rec.unit_amount := l_line_price_amount - l_line_discount_amount;
5048     l_fc_rec.total_amount := l_fc_rec.unit_amount + l_line_charge_amount;
5049     l_fc_rec.line_type_code := 'PRICE';
5050 
5051     fte_freight_pricing.get_fc_type_id(
5052                       p_line_type_code => 'FTEPRICE',
5053                       p_charge_subtype_code  => 'PRICE',
5054                       x_freight_cost_type_id  => l_fc_rec.freight_cost_type_id,
5055                       x_return_status  =>  l_return_status);
5056     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5057                l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5058       		raise FND_API.G_EXC_ERROR;
5059     END IF;
5060 
5061     l_summary_amount := l_summary_amount + l_fc_rec.total_amount;
5062 
5063     --distribute PRICE into top level containers
5064     n := p_top_level_rows.FIRST;
5065     IF (n is not null) THEN
5066     LOOP
5067 
5068 	 IF p_top_level_rows(n).container_type_code =
5069 	  l_pricing_engine_rows(l_qp_output_line_rows(i).line_index).container_type_code THEN
5070 
5071 	  l_price_count := l_price_count + 1;
5072 
5073 	  --4294663
5074 	  l_delivery_id :=
5075 	      fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
5076 
5077 	  IF (NOT(l_delivery_id_array.EXISTS(l_delivery_id)))
5078 	  THEN
5079 	  	l_delivery_id_array(l_delivery_id):=l_delivery_id;
5080 	  	l_leg_id_array(l_delivery_id):=p_top_level_rows(n).delivery_leg_id;
5081 	  END IF;
5082 
5083 	  IF (l_delivery_summary.EXISTS(l_delivery_id))
5084 	  THEN
5085 	 	l_delivery_summary(l_delivery_id):=l_delivery_summary(l_delivery_id)+round(l_fc_rec.total_amount / l_fc_rec.quantity, 2);
5086 	  ELSE
5087 		l_delivery_summary(l_delivery_id):=round(l_fc_rec.total_amount / l_fc_rec.quantity, 2);
5088 	  END IF;
5089 
5090 
5091 
5092 
5093 	  IF p_save_flag = 'M' THEN
5094 	    x_freight_cost_main_price(l_price_count).delivery_detail_id := p_top_level_rows(n).content_id;
5095 	    x_freight_cost_main_price(l_price_count).delivery_leg_id := p_top_level_rows(n).delivery_leg_id;
5096 	    x_freight_cost_main_price(l_price_count).delivery_id :=
5097 	      	fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
5098 	    x_freight_cost_main_price(l_price_count).uom := l_fc_rec.uom;
5099 	    x_freight_cost_main_price(l_price_count).quantity := 1;
5100 	    x_freight_cost_main_price(l_price_count).line_type_code := l_fc_rec.line_type_code;
5101 	    x_freight_cost_main_price(l_price_count).freight_cost_type_id := l_fc_rec.freight_cost_type_id;
5102 	    x_freight_cost_main_price(l_price_count).charge_unit_value :=
5103 		l_fc_rec.charge_unit_value;
5104 	    x_freight_cost_main_price(l_price_count).unit_amount :=
5105 		round(l_fc_rec.unit_amount / l_fc_rec.quantity, 2);
5106 	    x_freight_cost_main_price(l_price_count).total_amount :=
5107 		round(l_fc_rec.total_amount / l_fc_rec.quantity, 2);
5108 	    x_freight_cost_main_price(l_price_count).currency_code := l_currency_code;
5109 	    x_freight_cost_main_price(l_price_count).charge_source_code := 'PRICING_ENGINE';
5110 	    x_freight_cost_main_price(l_price_count).estimated_flag := 'Y';
5111 	  ELSE
5112 	    x_freight_cost_temp_price(l_price_count).delivery_detail_id := p_top_level_rows(n).content_id;
5113 	    --x_freight_cost_temp_price(l_price_count).delivery_leg_id := p_top_level_rows(n).delivery_leg_id;
5114 	    x_freight_cost_temp_price(l_price_count).delivery_id :=
5115 	      	fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
5116 	    x_freight_cost_temp_price(l_price_count).uom := l_fc_rec.uom;
5117 	    x_freight_cost_temp_price(l_price_count).quantity := 1;
5118 	    x_freight_cost_temp_price(l_price_count).line_type_code := l_fc_rec.line_type_code;
5119 	    x_freight_cost_temp_price(l_price_count).freight_cost_type_id := l_fc_rec.freight_cost_type_id;
5120 	    x_freight_cost_temp_price(l_price_count).charge_unit_value :=
5121 		l_fc_rec.charge_unit_value;
5122 	    x_freight_cost_temp_price(l_price_count).unit_amount :=
5123 		round(l_fc_rec.unit_amount / l_fc_rec.quantity, 2);
5124 	    x_freight_cost_temp_price(l_price_count).total_amount :=
5125 		round(l_fc_rec.total_amount / l_fc_rec.quantity, 2);
5126 	    x_freight_cost_temp_price(l_price_count).currency_code := l_currency_code;
5127 	    x_freight_cost_temp_price(l_price_count).charge_source_code := 'PRICING_ENGINE';
5128 	    x_freight_cost_temp_price(l_price_count).estimated_flag := 'Y';
5129 	  END IF;
5130 
5131 	 END IF; -- container_type compare
5132 
5133     EXIT WHEN (n >= p_top_level_rows.LAST);
5134     n := p_top_level_rows.NEXT(n);
5135     END LOOP;
5136     END IF;
5137 
5138   EXIT WHEN (i >= l_qp_output_line_rows.LAST);
5139   i := l_qp_output_line_rows.NEXT(i);
5140   END LOOP;
5141   END IF;
5142 
5143   -- create the summary record
5144 
5145   fte_freight_pricing.get_fc_type_id(
5146            p_line_type_code => 'FTESUMMARY',
5147            p_charge_subtype_code  => 'SUMMARY',
5148            x_freight_cost_type_id  =>  l_freight_cost_type_id,
5149            x_return_status  =>  l_return_status);
5150   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5151                l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5152       		raise FND_API.G_EXC_ERROR;
5153   END IF;
5154 
5155   IF p_save_flag = 'M' THEN
5156 
5157     --4294663
5158     i:=l_delivery_id_array.FIRST;
5159     j:=1;
5160     WHILE(i IS NOT NULL)
5161     LOOP
5162 
5163 	    x_fc_main_update_rows(j).delivery_leg_id := l_leg_id_array(i);
5164 	    x_fc_main_update_rows(j).delivery_id := l_delivery_id_array(i);
5165 	    x_fc_main_update_rows(j).freight_cost_id := fte_freight_pricing.get_fc_id_from_dleg(l_leg_id_array(i));
5166 	    x_fc_main_update_rows(j).line_type_code := 'SUMMARY';
5167 	    x_fc_main_update_rows(j).freight_cost_type_id := l_freight_cost_type_id;
5168 	    x_fc_main_update_rows(j).unit_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
5169 	    x_fc_main_update_rows(j).total_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
5170 	    x_fc_main_update_rows(j).currency_code := l_currency_code;
5171 	    x_fc_main_update_rows(j).charge_source_code := 'PRICING_ENGINE';
5172 	    x_fc_main_update_rows(j).estimated_flag := 'Y';
5173 
5174 
5175 
5176 
5177 	j:=j+1;
5178 	i:=l_delivery_id_array.NEXT(i);
5179     END LOOP;
5180 
5181   ELSE
5182 
5183     i:=l_delivery_id_array.FIRST;
5184 
5185     WHILE(i IS NOT NULL)
5186     LOOP
5187 	    --4294663
5188 	    l_price_count := l_price_count + 1;
5189 	    x_freight_cost_temp_price(l_price_count).delivery_id := l_delivery_id_array(i);
5190 	    x_freight_cost_temp_price(l_price_count).line_type_code := 'SUMMARY';
5191 	    x_freight_cost_temp_price(l_price_count).freight_cost_type_id :=  l_freight_cost_type_id;
5192 	    x_freight_cost_temp_price(l_price_count).unit_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
5193 	    x_freight_cost_temp_price(l_price_count).total_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
5194 	    x_freight_cost_temp_price(l_price_count).currency_code := l_currency_code;
5195 	    x_freight_cost_temp_price(l_price_count).charge_source_code := 'PRICING_ENGINE';
5196 	    x_freight_cost_temp_price(l_price_count).estimated_flag := 'Y';
5197 	i:=l_delivery_id_array.NEXT(i);
5198     END LOOP;
5199 
5200 
5201   END IF;
5202 
5203   x_summary_lanesched_price := round(l_summary_amount,2);
5204   x_summary_lanesched_price_uom := l_currency_code;
5205 
5206   FTE_FREIGHT_PRICING_UTIL.unset_method(l_log_level,l_method_name);
5207 
5208 EXCEPTION
5209 
5210    WHEN FND_API.G_EXC_ERROR THEN
5211         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5212         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'FND_API.G_EXC_ERROR');
5213         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5214    WHEN others THEN
5215         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5216         FTE_FREIGHT_PRICING_UTIL.set_exception(l_method_name,FTE_FREIGHT_PRICING_UTIL.G_ERR,'g_others');
5217         FTE_FREIGHT_PRICING_UTIL.print_msg(FTE_FREIGHT_PRICING_UTIL.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
5218         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5219 END;
5220 
5221 -- J+ enhancement for LTL rating to include container weight
5222 -- this procedure is called by distribute_LTL_container_wt to get the LTL container weight
5223 -- container weight to be included in LTL rating is the top level container's tare weight
5224 PROCEDURE get_LTL_container_weight(
5225         p_top_level_rows          	IN fte_freight_pricing.shpmnt_content_tab_type,
5226 	x_total_container_weight	OUT NOCOPY NUMBER,
5227 	x_weight_uom			OUT NOCOPY VARCHAR2,
5228         x_return_status           	OUT NOCOPY VARCHAR2 )
5229 IS
5230   l_log_level NUMBER := fte_freight_pricing_util.G_DBG;
5231   l_method_name VARCHAR2(50) := 'get_LTL_container_weight';
5232   l_return_status VARCHAR2(1);
5233   i NUMBER;
5234   l_tmp		NUMBER;
5235 BEGIN
5236   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5237 
5238   FTE_FREIGHT_PRICING_UTIL.reset_dbg_vars;
5239   FTE_FREIGHT_PRICING_UTIL.set_method(l_log_level,l_method_name);
5240 
5241   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_top_level_rows.COUNT='||p_top_level_rows.COUNT);
5242 
5243   x_total_container_weight := 0;
5244   x_weight_uom := null;
5245 
5246   i := p_top_level_rows.FIRST;
5247   IF (i is not null) THEN
5248   LOOP
5249     IF (((p_top_level_rows(i).container_flag = 'Y') OR (p_top_level_rows(i).container_flag = 'C')) and (p_top_level_rows(i).wdd_tare_weight > 0)) THEN
5250 
5251       IF p_top_level_rows(i).wdd_weight_uom_code is null THEN
5252   	FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'top level container tare weight > 0 and weight uom is null');
5253     	raise FND_API.G_EXC_ERROR;
5254       END IF;
5255 
5256       IF x_weight_uom is NULL THEN
5257 	x_weight_uom := p_top_level_rows(i).wdd_weight_uom_code;
5258       END IF;
5259 
5260       IF x_weight_uom = p_top_level_rows(i).wdd_weight_uom_code THEN
5261 	x_total_container_weight := x_total_container_weight + p_top_level_rows(i).wdd_tare_weight;
5262       ELSE
5263    	l_tmp := WSH_WV_UTILS.convert_uom(
5264 					p_top_level_rows(i).wdd_weight_uom_code,
5265 					x_weight_uom,
5266 					p_top_level_rows(i).wdd_tare_weight,
5267 					NULL,0);
5268 	IF l_tmp <= 0 THEN
5269   	  FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'WSH_WV_UTILS.convert_uom return 0');
5270     	  raise FND_API.G_EXC_ERROR;
5271 	ELSE
5272 	  x_total_container_weight := x_total_container_weight + l_tmp;
5273 	END IF;
5274       END IF;
5275 
5276     END IF;
5277 
5278   EXIT WHEN (i >= p_top_level_rows.LAST);
5279   i := p_top_level_rows.NEXT(i);
5280   END LOOP;
5281   END IF;
5282 
5283   FTE_FREIGHT_PRICING_UTIL.unset_method(l_log_level,l_method_name);
5284 
5285 EXCEPTION
5286    WHEN FND_API.G_EXC_ERROR THEN
5287         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5288         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'FND_API.G_EXC_ERROR');
5289         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5290    WHEN others THEN
5291         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5292         FTE_FREIGHT_PRICING_UTIL.set_exception(l_method_name,FTE_FREIGHT_PRICING_UTIL.G_ERR,'g_others');
5293         FTE_FREIGHT_PRICING_UTIL.print_msg(FTE_FREIGHT_PRICING_UTIL.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
5294         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5295 END;
5296 
5297 -- J+ enhancement for LTL rating to include container weight
5298 -- this procedure is called by process_shipment_patterns to distribute LTL container weight to
5299 -- pricing_engine_rows and g_rolledup_lines
5300 PROCEDURE distribute_LTL_container_wt(
5301         p_top_level_rows        IN fte_freight_pricing.shpmnt_content_tab_type,
5302         x_pricing_engine_rows	IN OUT NOCOPY fte_freight_pricing.pricing_engine_input_tab_type,
5303         x_return_status         OUT NOCOPY VARCHAR2 )
5304 IS
5305   l_log_level NUMBER := fte_freight_pricing_util.G_DBG;
5306   l_method_name VARCHAR2(50) := 'distribute_LTL_container_wt';
5307   l_return_status VARCHAR2(1);
5308 
5309   l_total_container_weight NUMBER;
5310   l_container_weight_uom VARCHAR2(3);
5311 
5312   l_segment2 NUMBER;
5313   l_lowest_fc_segment2 NUMBER;
5314   l_lowest_fc_category_id NUMBER;
5315   l_lowest_fc_input_index1 NUMBER;
5316   l_lowest_fc_input_index2 NUMBER;
5317   l_lowest_fc_old_line_quantity NUMBER;
5318   l_bumpup_ratio NUMBER;
5319 
5320   i NUMBER;
5321 
5322   CURSOR get_category_segment2(c_category_id NUMBER)
5323   IS
5324   SELECT TO_NUMBER(segment2)
5325   FROM mtl_categories
5326   WHERE category_id = c_category_id;
5327 
5328 BEGIN
5329   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5330 
5331   FTE_FREIGHT_PRICING_UTIL.reset_dbg_vars;
5332   FTE_FREIGHT_PRICING_UTIL.set_method(l_log_level,l_method_name);
5333 
5334   -- get the LTL container weight
5335   -- calculate the bumpup ratio
5336   -- bumpup pricing engine rows
5337   -- bumpup g_rolledup_lines
5338 
5339   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_top_level_rows.COUNT='||p_top_level_rows.COUNT);
5340   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'x_pricing_engine_rows.COUNT='||x_pricing_engine_rows.COUNT);
5341 
5342   get_LTL_container_weight(
5343     p_top_level_rows => p_top_level_rows,
5344     x_total_container_weight => l_total_container_weight,
5345     x_weight_uom => l_container_weight_uom,
5346     x_return_status => l_return_status);
5347 
5348   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_total_container_weight='||l_total_container_weight);
5349   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_container_weight_uom='||l_container_weight_uom);
5350 
5351   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5352     raise FND_API.G_EXC_ERROR;
5353   END IF;
5354 
5355   IF l_total_container_weight <= 0 THEN
5356     raise g_finished_success;
5357   END IF;
5358 
5359   -- after process shipment patterns for LTL, it could come up with two pricing engine lines
5360   -- for the same commodity. one from items inside container, one from loose items
5361   -- this code can handle all the scinerio
5362   -- commodity from only loose item
5363   -- commodity from only container items
5364   -- commodity from both loose item and container items
5365   l_lowest_fc_segment2 := -1;
5366   l_lowest_fc_category_id := -1;
5367   l_lowest_fc_input_index1 := -1;
5368   l_lowest_fc_input_index2 := -1;
5369 
5370   i := x_pricing_engine_rows.FIRST;
5371   IF (i is not null) THEN
5372   LOOP
5373 
5374     IF l_lowest_fc_category_id <> -1 and
5375 	l_lowest_fc_category_id = x_pricing_engine_rows(i).category_id THEN
5376       	l_lowest_fc_input_index2 := i;
5377     ELSE
5378       l_segment2 := -1;
5379       OPEN get_category_segment2(x_pricing_engine_rows(i).category_id);
5380       FETCH get_category_segment2 INTO l_segment2;
5381       CLOSE get_category_segment2;
5382 
5383       IF l_segment2 is null or l_segment2 < 0 THEN
5384         FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'cannot get valid numeric segment2 from category id '
5385 	||x_pricing_engine_rows(i).category_id);
5386         raise FND_API.G_EXC_ERROR;
5387       END IF;
5388 
5389       IF l_lowest_fc_segment2 = -1 THEN
5390         l_lowest_fc_segment2 := l_segment2;
5391         l_lowest_fc_category_id := x_pricing_engine_rows(i).category_id;
5392         l_lowest_fc_input_index1 := i;
5393       ELSE
5394         IF l_lowest_fc_segment2 > l_segment2 THEN
5395       	  l_lowest_fc_segment2 := l_segment2;
5396       	  l_lowest_fc_category_id := x_pricing_engine_rows(i).category_id;
5397       	  l_lowest_fc_input_index1 := i;
5398       	  l_lowest_fc_input_index2 := -1;
5399         ELSIF l_lowest_fc_segment2 = l_segment2 THEN
5400       	  l_lowest_fc_input_index2 := i;
5401         END IF;
5402       END IF;
5403     END IF;
5404 
5405   EXIT WHEN (i >= x_pricing_engine_rows.LAST);
5406   i := x_pricing_engine_rows.NEXT(i);
5407   END LOOP;
5408   END IF;
5409 
5410   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_lowest_fc_segment2='||l_lowest_fc_segment2);
5411   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_lowest_fc_category_id='||l_lowest_fc_category_id);
5412   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_lowest_fc_input_index1='||l_lowest_fc_input_index1);
5413   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_lowest_fc_input_index2='||l_lowest_fc_input_index2);
5414 
5415   IF l_lowest_fc_input_index1 = -1 and l_lowest_fc_input_index2 = -1 THEN
5416     raise g_finished_success;
5417   END IF;
5418 
5419   IF l_container_weight_uom = x_pricing_engine_rows(l_lowest_fc_input_index1).line_uom THEN
5420       l_lowest_fc_old_line_quantity := x_pricing_engine_rows(l_lowest_fc_input_index1).line_quantity;
5421   ELSE
5422       l_lowest_fc_old_line_quantity := WSH_WV_UTILS.convert_uom(
5423 					x_pricing_engine_rows(l_lowest_fc_input_index1).line_uom,
5424 					l_container_weight_uom,
5425 					x_pricing_engine_rows(l_lowest_fc_input_index1).line_quantity,
5426 					NULL,0);
5427   END IF;
5428 
5429   IF l_lowest_fc_input_index2 <> -1 THEN
5430     IF l_container_weight_uom = x_pricing_engine_rows(l_lowest_fc_input_index2).line_uom THEN
5431       l_lowest_fc_old_line_quantity := l_lowest_fc_old_line_quantity
5432 					+ x_pricing_engine_rows(l_lowest_fc_input_index2).line_quantity;
5433     ELSE
5434       l_lowest_fc_old_line_quantity := l_lowest_fc_old_line_quantity
5435 					+ WSH_WV_UTILS.convert_uom(
5436 					x_pricing_engine_rows(l_lowest_fc_input_index2).line_uom,
5437 					l_container_weight_uom,
5438 					x_pricing_engine_rows(l_lowest_fc_input_index2).line_quantity,
5439 					NULL,0);
5440     END IF;
5441   END IF;
5442   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_lowest_fc_old_line_quantity='||l_lowest_fc_old_line_quantity);
5443 
5444   l_bumpup_ratio := ( l_lowest_fc_old_line_quantity + l_total_container_weight )
5445 		     / l_lowest_fc_old_line_quantity;
5446   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'l_bumpup_ratio='||l_bumpup_ratio);
5447 
5448   -- bumpup pricing engine rows
5449   x_pricing_engine_rows(l_lowest_fc_input_index1).line_quantity :=
5450     x_pricing_engine_rows(l_lowest_fc_input_index1).line_quantity * l_bumpup_ratio;
5451 
5452   IF l_lowest_fc_input_index2 <> -1 THEN
5453     x_pricing_engine_rows(l_lowest_fc_input_index2).line_quantity :=
5454       x_pricing_engine_rows(l_lowest_fc_input_index2).line_quantity * l_bumpup_ratio;
5455   END IF;
5456 
5457   -- bumpup g_rolledup_lines
5458   i := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
5459   IF (i is not null) THEN
5460   LOOP
5461     IF FTE_FREIGHT_PRICING.g_rolledup_lines(i).category_id = l_lowest_fc_category_id THEN
5462       FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity :=
5463 	FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity * l_bumpup_ratio;
5464     END IF;
5465   EXIT WHEN (i >= FTE_FREIGHT_PRICING.g_rolledup_lines.LAST);
5466   i := FTE_FREIGHT_PRICING.g_rolledup_lines.NEXT(i);
5467   END LOOP;
5468   END IF;
5469 
5470   FTE_FREIGHT_PRICING_UTIL.unset_method(l_log_level,l_method_name);
5471 
5472 EXCEPTION
5473    WHEN g_finished_success THEN
5474         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5475    WHEN FND_API.G_EXC_ERROR THEN
5476         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5477         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'FND_API.G_EXC_ERROR');
5478         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5479    WHEN others THEN
5480         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5481         FTE_FREIGHT_PRICING_UTIL.set_exception(l_method_name,FTE_FREIGHT_PRICING_UTIL.G_ERR,'g_others');
5482         FTE_FREIGHT_PRICING_UTIL.print_msg(FTE_FREIGHT_PRICING_UTIL.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
5483         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
5484 END;
5485 
5486 PROCEDURE process_shipment_flatrate(
5487         p_lane_info		     	IN fte_freight_pricing.lane_info_rec_type,
5488         p_top_level_rows          	IN fte_freight_pricing.shpmnt_content_tab_type,
5489         p_save_flag               	IN VARCHAR2,
5490         p_currency_code             IN VARCHAR2,
5491         x_freight_cost_main_price  	OUT NOCOPY fte_freight_pricing.Freight_Cost_Main_Tab_Type,
5492         x_freight_cost_temp_price  	OUT NOCOPY fte_freight_pricing.Freight_Cost_Temp_Tab_Type,
5493         x_freight_cost_main_charge 	OUT NOCOPY fte_freight_pricing.Freight_Cost_Main_Tab_Type,
5494         x_freight_cost_temp_charge 	OUT NOCOPY fte_freight_pricing.Freight_Cost_Temp_Tab_Type,
5495         x_fc_main_update_rows     	OUT NOCOPY fte_freight_pricing.Freight_Cost_Main_Tab_Type,
5496         x_summary_lanesched_price      	OUT NOCOPY NUMBER,
5497         x_summary_lanesched_price_uom  	OUT NOCOPY VARCHAR2,
5498         x_return_status           	OUT NOCOPY VARCHAR2 )
5499 IS
5500   l_log_level NUMBER := fte_freight_pricing_util.G_DBG;
5501   l_method_name VARCHAR2(50) := 'process_shipment_flatrate';
5502   l_return_status VARCHAR2(1);
5503 
5504   l_pricing_control_rec fte_freight_pricing.pricing_control_input_rec_type;
5505   l_pricing_engine_rows fte_freight_pricing.pricing_engine_input_tab_type;
5506   l_engine_row_count NUMBER;
5507   l_pricing_attribute_rows fte_freight_pricing.pricing_attribute_tab_type;
5508 
5509   l_qp_output_line_rows QP_PREQ_GRP.LINE_TBL_TYPE;
5510   l_qp_output_detail_rows QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
5511 
5512   l_uom_ea VARCHAR2(30);
5513   i NUMBER;
5514   j NUMBER;
5515   k NUMBER;
5516   l_event_num NUMBER;
5517   l_currency_code VARCHAR2(30);
5518   l_lane_function VARCHAR2(30);
5519   l_charge_applied VARCHAR2(1);
5520 
5521   l_fc_rec                      fte_freight_pricing.top_level_fc_rec_type;
5522   l_fc_charge_rec               fte_freight_pricing.top_level_fc_rec_type;
5523   n NUMBER;
5524   l_line_price_amount NUMBER;
5525   l_line_charge_amount NUMBER;
5526   l_line_discount_amount NUMBER;
5527   l_summary_amount NUMBER;
5528   l_price_count            NUMBER;
5529   l_charge_count           NUMBER;
5530 
5531   l_leg_id NUMBER;
5532   l_delivery_id NUMBER;--indexed by delivery id/parent delivery id
5533   l_freight_cost_type_id NUMBER;
5534   l_tmp		NUMBER;
5535   l_delivery_id_array  dbms_utility.number_array;
5536   l_temp_delivery_id NUMBER;
5537   l_temp_parent_delivery_id NUMBER;
5538   l_trip_summary_amount NUMBER;
5539   l_leg_id_array dbms_utility.number_array;
5540 
5541 
5542 
5543   l_delivery_summary dbms_utility.number_array;
5544 
5545   l_main_update_count NUMBER;
5546 
5547 BEGIN
5548   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5549 
5550   FTE_FREIGHT_PRICING_UTIL.reset_dbg_vars;
5551   FTE_FREIGHT_PRICING_UTIL.set_method(l_log_level,l_method_name);
5552 
5553   -- sum up top level rows quantity and generate one pricing engine input line
5554   -- set up the pricing attributes for input line
5555   -- call QP
5556   -- check min charge parameter
5557   -- if need to apply minimum charge
5558   --    prepare second call to qp
5559   -- process qp output
5560   --   distribute qp output back to top level rows
5561 
5562   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_top_level_rows.COUNT='||p_top_level_rows.COUNT);
5563   FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'p_save_flag='||p_save_flag);
5564 
5565   FTE_FREIGHT_PRICING.print_top_level_detail (
5566         p_first_level_rows        =>    p_top_level_rows,
5567         x_return_status           =>    l_return_status );
5568 
5569     -- Added for 12i for multi currency support
5570     IF p_currency_code IS NOT NULL THEN
5571         l_currency_code := p_currency_code;
5572     ELSE
5573       fte_freight_pricing.get_currency_code(
5574       p_carrier_id      =>   p_lane_info.carrier_id,
5575       x_currency_code   =>   l_currency_code,
5576       x_return_status   =>   l_return_status );
5577       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS and
5578           l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5579           FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'get currency code failed');
5580           raise FND_API.G_EXC_ERROR;
5581       END IF;
5582     END IF;
5583 
5584   --4294663
5585 
5586   l_price_count := 0;
5587   l_charge_count := 0;
5588   l_main_update_count:=0;
5589   l_trip_summary_amount:=0;
5590 
5591   k:= p_top_level_rows.FIRST;
5592   WHILE (k is not null)
5593   LOOP
5594 
5595   	l_temp_delivery_id:=fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(k).content_id).delivery_id;
5596 
5597 	--MDC
5598 	l_temp_parent_delivery_id:=fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(k).content_id).parent_delivery_id;
5599   	IF(l_temp_parent_delivery_id IS NOT NULL)
5600   	THEN
5601   		l_delivery_id_array(l_temp_parent_delivery_id):=l_temp_parent_delivery_id;
5602 
5603 	ELSE
5604   		l_delivery_id_array(l_temp_delivery_id):=l_temp_delivery_id;
5605   	END IF;
5606 
5607 
5608 
5609 
5610 
5611   	k:= p_top_level_rows.NEXT(k);
5612   END LOOP;
5613 
5614   k:=l_delivery_id_array.FIRST;
5615   WHILE(k is not null)
5616   LOOP
5617 
5618 
5619 	 FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,' Delivery:'||l_delivery_id_array(k));
5620 
5621 
5622 
5623 
5624 	  -- sum up top level rows line quantity and generate one pricing engine input line
5625 	  l_pricing_engine_rows.DELETE;
5626 	  FTE_FREIGHT_PRICING.g_rolledup_lines.DELETE;
5627 
5628 	  l_pricing_engine_rows(1).input_index := 1;
5629 	  l_pricing_engine_rows(1).line_quantity  := 0;
5630 	  l_pricing_engine_rows(1).line_uom := null;
5631 
5632 	  i := p_top_level_rows.FIRST;
5633 	  IF (i is not null) THEN
5634 	  LOOP
5635 	     IF((fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(i).content_id).parent_delivery_id = l_delivery_id_array(k)) OR (fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(i).content_id).delivery_id = l_delivery_id_array(k)))
5636 	     THEN
5637 
5638 		     IF p_top_level_rows(i).wdd_gross_weight is null
5639 			OR p_top_level_rows(i).wdd_gross_weight <= 0
5640 			OR p_top_level_rows(i).wdd_weight_uom_code is null THEN
5641 		      FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,
5642 			'top level detail id: '||p_top_level_rows(i).content_id
5643 			||' wdd_gross_weight: '||p_top_level_rows(i).wdd_gross_weight
5644 			||' '||p_top_level_rows(i).wdd_weight_uom_code);
5645 		      FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'top level detail gross weight invalid');
5646 		      raise FND_API.G_EXC_ERROR;
5647 		    END IF;
5648 
5649 		    FTE_FREIGHT_PRICING.g_rolledup_lines(i).delivery_detail_id := p_top_level_rows(i).content_id;
5650 		    FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity := p_top_level_rows(i).wdd_gross_weight;
5651 		    FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_uom := p_top_level_rows(i).wdd_weight_uom_code;
5652 
5653 		    IF l_pricing_engine_rows(1).line_quantity = 0 THEN
5654 		      l_pricing_engine_rows(1).line_quantity  := FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity;
5655 		      l_pricing_engine_rows(1).line_uom := FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_uom;
5656 		    ELSE
5657 		      IF l_pricing_engine_rows(1).line_uom = FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_uom THEN
5658 			l_pricing_engine_rows(1).line_quantity  := l_pricing_engine_rows(1).line_quantity
5659 			  + FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity;
5660 		      ELSE
5661 			l_tmp := WSH_WV_UTILS.convert_uom(
5662 							FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_uom,
5663 							l_pricing_engine_rows(1).line_uom,
5664 							FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity,
5665 							NULL,0);
5666 			IF l_tmp <= 0 THEN
5667 			  FTE_FREIGHT_PRICING_UTIL.print_msg(l_log_level,'WSH_WV_UTILS.convert_uom return 0');
5668 			  raise FND_API.G_EXC_ERROR;
5669 			ELSE
5670 			  FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_quantity := l_tmp;
5671 			  FTE_FREIGHT_PRICING.g_rolledup_lines(i).line_uom := l_pricing_engine_rows(1).line_uom;
5672 			  l_pricing_engine_rows(1).line_quantity  :=
5673 			    l_pricing_engine_rows(1).line_quantity + l_tmp;
5674 			END IF;
5675 		      END IF;
5676 		    END IF; -- l_pricing_engine_rows(1).line_quantity > 0
5677 
5678 	       END IF;
5679 
5680 	  EXIT WHEN (i >= p_top_level_rows.LAST);
5681 	  i := p_top_level_rows.NEXT(i);
5682 	  END LOOP;
5683 	  END IF;
5684 
5685 	  fte_freight_pricing.print_rolledup_lines (
5686 		p_rolledup_lines          =>   FTE_FREIGHT_PRICING.g_rolledup_lines,
5687 		x_return_status           =>   l_return_status );
5688 
5689 	  fte_freight_pricing.print_engine_rows (
5690 		p_engine_rows             =>    l_pricing_engine_rows,
5691 		x_return_status           =>    l_return_status );
5692 
5693 	  -- set up data structure to call QP
5694 	  -- call QP
5695 	  -- check qp output for any errors
5696 
5697 	  l_pricing_control_rec.pricing_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
5698 	  l_pricing_control_rec.currency_code     := l_currency_code;
5699 	  l_pricing_control_rec.lane_id           := p_lane_info.lane_id;
5700 	  l_pricing_control_rec.price_list_id     := p_lane_info.pricelist_id;
5701 	  l_pricing_control_rec.party_id          := p_lane_info.carrier_id;
5702 
5703 	  i := 1;
5704 	  j := 0;
5705 	  l_pricing_attribute_rows.DELETE;
5706 
5707 	      j := j + 1;
5708 		 l_pricing_attribute_rows(j).attribute_index := j;
5709 		 l_pricing_attribute_rows(j).input_index     := i;
5710 		 l_pricing_attribute_rows(j).attribute_name  := 'ORIGIN_ZONE';
5711 		 l_pricing_attribute_rows(j).attribute_value := TO_CHAR(p_lane_info.origin_id);
5712 	      j := j + 1;
5713 		 l_pricing_attribute_rows(j).attribute_index := j;
5714 		 l_pricing_attribute_rows(j).input_index     := i;
5715 		 l_pricing_attribute_rows(j).attribute_name  := 'DESTINATION_ZONE';
5716 		 l_pricing_attribute_rows(j).attribute_value := TO_CHAR(p_lane_info.destination_id);
5717 
5718 	      IF p_lane_info.service_type_code IS NOT NULL THEN
5719 
5720 	      j := j + 1;
5721 		 l_pricing_attribute_rows(j).attribute_index := j;
5722 		 l_pricing_attribute_rows(j).input_index     := i;
5723 		 l_pricing_attribute_rows(j).attribute_name  := 'SERVICE_TYPE';  --  Is it required always
5724 		 l_pricing_attribute_rows(j).attribute_value := p_lane_info.service_type_code;
5725 
5726 	      END IF;
5727 
5728 
5729 
5730 	       -- create standard engine line and attributes (default stuff created by pattern matching)
5731 	       l_event_num := fte_qp_engine.G_LINE_EVENT_NUM;
5732 	       fte_qp_engine.create_control_record(p_event_num => l_event_num,
5733 						   x_return_status => l_return_status );
5734 
5735 		   fte_freight_pricing_util.set_location(p_loc=>'after create_control_record ');
5736 		   IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5737 			 l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
5738 			raise FND_API.G_EXC_ERROR;
5739 		   END IF;
5740 
5741 	       --l_set_num   := 1;
5742 	       i := l_pricing_engine_rows.FIRST;
5743 	       IF (i IS NOT NULL) THEN
5744 	       LOOP
5745 		    fte_qp_engine.create_line_record (p_pricing_control_rec       => l_pricing_control_rec,
5746 						      p_pricing_engine_input_rec  => l_pricing_engine_rows(i),
5747 						      x_return_status             => l_return_status);
5748 
5749 		   fte_freight_pricing_util.set_location(p_loc=>'after create_line_record. i='||i);
5750 		   IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5751 			 l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
5752 			raise FND_API.G_EXC_ERROR;
5753 		   END IF;
5754 
5755 		    fte_qp_engine.prepare_qp_line_qualifiers(
5756 						      p_event_num               => l_event_num,
5757 						      p_pricing_control_rec       => l_pricing_control_rec,
5758 						      p_input_index             => l_pricing_engine_rows(i).input_index,
5759 						      x_return_status           => l_return_status);
5760 
5761 		   fte_freight_pricing_util.set_location(p_loc=>'after create qp line qualifiers. i='||i);
5762 		   IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5763 			 l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
5764 			raise FND_API.G_EXC_ERROR;
5765 		   END IF;
5766 
5767 		    fte_qp_engine.prepare_qp_line_attributes (
5768 						      p_event_num               => l_event_num,
5769 						      p_input_index             => l_pricing_engine_rows(i).input_index,
5770 						      p_attr_rows               => l_pricing_attribute_rows,
5771 						      x_return_status           => l_return_status);
5772 
5773 		    fte_freight_pricing_util.set_location(p_loc=>'after create qp line attributes. i='||i);
5774 		    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5775 			  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
5776 			raise FND_API.G_EXC_ERROR;
5777 		    END IF;
5778 
5779 	       EXIT WHEN i >= l_pricing_engine_rows.LAST;
5780 	       i := l_pricing_engine_rows.NEXT(i);
5781 	       END LOOP;
5782 	       END IF;
5783 
5784 	       -- call qp api
5785 	       fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => l_qp_output_line_rows,
5786 					      x_qp_output_detail_rows  => l_qp_output_detail_rows,
5787 					      x_return_status          => l_return_status);
5788 
5789 		   fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 1');
5790 		   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5791 		      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5792 			raise FND_API.G_EXC_ERROR;
5793 		   END IF;
5794 
5795 	       --check for errors in the output
5796 		   fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
5797 		   fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
5798 		   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5799 		      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5800 			raise FND_API.G_EXC_ERROR;
5801 		   END IF;
5802 
5803 	       fte_qp_engine.print_qp_output();
5804 
5805 	  IF (g_special_flags.minimum_charge_flag = 'Y') THEN
5806 
5807 	    apply_min_charge(
5808 		p_event_num      => l_event_num,
5809 		x_charge_applied => l_charge_applied,
5810 		x_return_status  => l_return_status);
5811 
5812 	    fte_freight_pricing_util.set_location(p_loc=>'after apply_min_charge ');
5813 	    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5814 		l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
5815 	      raise FND_API.G_EXC_ERROR;
5816 	    END IF;
5817 	  END IF;
5818 
5819 	  -- create request lines for the next event and call qp engine
5820 	  IF (l_charge_applied = 'Y') THEN
5821 	       l_event_num := fte_qp_engine.G_CHARGE_EVENT_NUM;
5822 	       fte_qp_engine.prepare_next_event_request ( x_return_status           => l_return_status);
5823 
5824 		    fte_freight_pricing_util.set_location(p_loc=>'after prepare_next_event_request');
5825 		    IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5826 			  l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING ) THEN
5827 			raise FND_API.G_EXC_ERROR;
5828 		    END IF;
5829 
5830 	       fte_qp_engine.call_qp_api    ( x_qp_output_line_rows    => l_qp_output_line_rows,
5831 					      x_qp_output_detail_rows  => l_qp_output_detail_rows,
5832 					      x_return_status          => l_return_status);
5833 
5834 		   fte_freight_pricing_util.set_location(p_loc=>'after call_qp_api: Event 2');
5835 		   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5836 		       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5837 			raise FND_API.G_EXC_ERROR;
5838 		   END IF;
5839 
5840 	       --check for errors in the output
5841 		   fte_qp_engine.check_qp_output_errors (x_return_status   => l_return_status);
5842 		   fte_freight_pricing_util.set_location(p_loc=>'after check_qp_output_errors: Event '||l_event_num);
5843 		   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5844 		      l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5845 			raise FND_API.G_EXC_ERROR;
5846 		   END IF;
5847 
5848 	       fte_qp_engine.print_qp_output();
5849 
5850 	  END IF; -- l_charge_applied = 'Y'
5851 
5852 	  -- process qp output
5853 	  --4294663
5854 	  l_summary_amount := 0;
5855 
5856 	  i := l_qp_output_line_rows.FIRST;
5857 	  IF (i is not null) THEN
5858 	  LOOP
5859 
5860 	    l_fc_rec.quantity := l_pricing_engine_rows(l_qp_output_line_rows(i).line_index).line_quantity;
5861 	    l_fc_rec.uom := l_pricing_engine_rows(l_qp_output_line_rows(i).line_index).line_uom;
5862 	    l_fc_rec.currency_code := l_currency_code;
5863 
5864 	    l_line_charge_amount := 0;
5865 	    l_line_discount_amount := 0;
5866 
5867 	    j := l_qp_output_detail_rows.FIRST;
5868 	    IF (j is not null) THEN
5869 	    LOOP
5870 
5871 	      IF (l_qp_output_detail_rows(j).list_line_type_code = 'SUR' OR
5872 		 l_qp_output_detail_rows(j).list_line_type_code = 'DIS' )
5873 		AND (l_qp_output_line_rows(i).line_index =
5874 		     l_qp_output_detail_rows(j).line_index ) THEN
5875 
5876 		l_fc_charge_rec.total_amount :=
5877 		  ABS( l_qp_output_detail_rows(j).adjustment_amount )
5878 		  * l_qp_output_line_rows(i).priced_quantity;
5879 		l_fc_charge_rec.charge_unit_value:= l_fc_charge_rec.total_amount / l_fc_rec.quantity;
5880 
5881 		IF l_qp_output_detail_rows(j).list_line_type_code = 'SUR' THEN
5882 		  l_line_charge_amount := l_line_charge_amount + l_fc_charge_rec.total_amount;
5883 		  l_fc_charge_rec.unit_amount := l_fc_charge_rec.total_amount;
5884 
5885 		  l_fc_charge_rec.line_type_code := 'CHARGE';
5886 
5887 		  fte_freight_pricing.get_fc_type_id(
5888 			      p_line_type_code => 'FTECHARGE',
5889 			      p_charge_subtype_code  => l_qp_output_detail_rows(j).charge_subtype_code,
5890 			      x_freight_cost_type_id  => l_fc_charge_rec.freight_cost_type_id,
5891 			      x_return_status  =>  l_return_status);
5892 		  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5893 		       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5894 			raise FND_API.G_EXC_ERROR;
5895 		  END IF;
5896 		ELSE -- l_qp_output_detail_rows(j).list_line_type_code = 'DIS'
5897 		  l_line_discount_amount := l_line_discount_amount + l_fc_charge_rec.total_amount;
5898 
5899 		  l_fc_charge_rec.line_type_code := 'DISCOUNT';
5900 
5901 		  fte_freight_pricing.get_fc_type_id(
5902 			      p_line_type_code => 'FTEDISCOUNT',
5903 			      p_charge_subtype_code  => 'DISCOUNT',
5904 			      x_freight_cost_type_id  => l_fc_charge_rec.freight_cost_type_id,
5905 			      x_return_status  =>  l_return_status);
5906 		  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5907 		       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5908 			raise FND_API.G_EXC_ERROR;
5909 		  END IF;
5910 		END IF;
5911 
5912 		--distribute SUR/DIS into top level details
5913 		n := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
5914 		IF (n is not null) THEN
5915 		LOOP
5916 
5917 		  l_charge_count := l_charge_count + 1;
5918 		  IF p_save_flag = 'M' THEN
5919 		    x_freight_cost_main_charge(l_charge_count).delivery_detail_id := FTE_FREIGHT_PRICING.g_rolledup_lines(n).delivery_detail_id;
5920 		    x_freight_cost_main_charge(l_charge_count).delivery_leg_id := p_top_level_rows(n).delivery_leg_id;
5921 		    x_freight_cost_main_charge(l_charge_count).delivery_id :=
5922 			fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
5923 		    x_freight_cost_main_charge(l_charge_count).uom := l_fc_rec.uom;
5924 		    x_freight_cost_main_charge(l_charge_count).quantity := FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity;
5925 		    x_freight_cost_main_charge(l_charge_count).line_type_code := l_fc_charge_rec.line_type_code;
5926 		    x_freight_cost_main_charge(l_charge_count).freight_cost_type_id := l_fc_charge_rec.freight_cost_type_id;
5927 		    x_freight_cost_main_charge(l_charge_count).charge_unit_value :=
5928 			l_fc_charge_rec.charge_unit_value;
5929 		    IF l_fc_charge_rec.unit_amount > 0 THEN
5930 		      x_freight_cost_main_charge(l_charge_count).unit_amount :=
5931 			round(l_fc_charge_rec.unit_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
5932 		    END IF;
5933 		    x_freight_cost_main_charge(l_charge_count).total_amount :=
5934 			round(l_fc_charge_rec.total_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
5935 		    x_freight_cost_main_charge(l_charge_count).currency_code := l_currency_code;
5936 		    x_freight_cost_main_charge(l_charge_count).charge_source_code := 'PRICING_ENGINE';
5937 		    x_freight_cost_main_charge(l_charge_count).estimated_flag := 'Y';
5938 		  ELSE
5939 		    x_freight_cost_temp_charge(l_charge_count).delivery_detail_id := p_top_level_rows(n).content_id;
5940 		    x_freight_cost_temp_charge(l_charge_count).delivery_id :=
5941 			fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
5942 		    x_freight_cost_temp_charge(l_charge_count).uom := l_fc_rec.uom;
5943 		    x_freight_cost_temp_charge(l_charge_count).quantity := FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity;
5944 		    x_freight_cost_temp_charge(l_charge_count).line_type_code := l_fc_charge_rec.line_type_code;
5945 		    x_freight_cost_temp_charge(l_charge_count).freight_cost_type_id := l_fc_charge_rec.freight_cost_type_id;
5946 		    x_freight_cost_temp_charge(l_charge_count).charge_unit_value :=
5947 			l_fc_charge_rec.charge_unit_value;
5948 		    IF l_fc_charge_rec.unit_amount > 0 THEN
5949 		      x_freight_cost_temp_charge(l_charge_count).unit_amount :=
5950 			round(l_fc_charge_rec.unit_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
5951 		    END IF;
5952 		    x_freight_cost_temp_charge(l_charge_count).total_amount :=
5953 			round(l_fc_charge_rec.total_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
5954 		    x_freight_cost_temp_charge(l_charge_count).currency_code := l_currency_code;
5955 		    x_freight_cost_temp_charge(l_charge_count).charge_source_code := 'PRICING_ENGINE';
5956 		    x_freight_cost_temp_charge(l_charge_count).estimated_flag := 'Y';
5957 		  END IF;
5958 
5959 		EXIT WHEN (n >= FTE_FREIGHT_PRICING.g_rolledup_lines.LAST);
5960 		n := FTE_FREIGHT_PRICING.g_rolledup_lines.NEXT(n);
5961 		END LOOP;
5962 		END IF;
5963 
5964 	      END IF; -- l_qp_output_detail_rows(j).list_line_type_code = 'SUR' or 'DIS'
5965 
5966 	    EXIT WHEN (j >= l_qp_output_detail_rows.LAST);
5967 	    j := l_qp_output_detail_rows.NEXT(j);
5968 	    END LOOP;
5969 	    END IF;
5970 
5971 	    l_line_price_amount := l_qp_output_line_rows(i).unit_price *
5972 		l_qp_output_line_rows(i).priced_quantity;
5973 	    l_fc_rec.charge_unit_value := l_line_price_amount / l_fc_rec.quantity;
5974 	    l_fc_rec.unit_amount := l_line_price_amount - l_line_discount_amount;
5975 	    l_fc_rec.total_amount := l_fc_rec.unit_amount + l_line_charge_amount;
5976 	    l_fc_rec.line_type_code := 'PRICE';
5977 
5978 	    fte_freight_pricing.get_fc_type_id(
5979 			      p_line_type_code => 'FTEPRICE',
5980 			      p_charge_subtype_code  => 'PRICE',
5981 			      x_freight_cost_type_id  => l_fc_rec.freight_cost_type_id,
5982 			      x_return_status  =>  l_return_status);
5983 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
5984 		       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5985 			raise FND_API.G_EXC_ERROR;
5986 	    END IF;
5987 
5988 	    l_summary_amount := l_summary_amount + l_fc_rec.total_amount;
5989 
5990 	    --distribute PRICE into top level containers
5991 
5992 	    --4294663
5993 	    l_leg_id:=NULL;
5994 
5995 	    n := FTE_FREIGHT_PRICING.g_rolledup_lines.FIRST;
5996 	    IF (n is not null) THEN
5997 	    LOOP
5998 
5999 		  l_price_count := l_price_count + 1;
6000 		  IF l_leg_id is null THEN
6001 
6002 		    IF(fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).parent_delivery_id IS NULL)
6003 		    THEN
6004 
6005 			    l_leg_id := p_top_level_rows(n).delivery_leg_id;
6006 			    l_delivery_id :=
6007 			      fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
6008 		    ELSE
6009 		    --MDC if there are parent deliveries then
6010 		    -- quantities for all the children are summed and sent to QP. The amounts are stored at the parent delivery level.
6011 		    --The parent delivery id, dleg are captured
6012 			    l_delivery_id :=
6013 			      fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).parent_delivery_id;
6014 			    l_leg_id :=fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).parent_delivery_leg_id;
6015 
6016 		    END IF;
6017 
6018 		  END IF;
6019 
6020 		  IF p_save_flag = 'M' THEN
6021 		    x_freight_cost_main_price(l_price_count).delivery_detail_id := p_top_level_rows(n).content_id;
6022 		    x_freight_cost_main_price(l_price_count).delivery_leg_id := p_top_level_rows(n).delivery_leg_id;
6023 		    x_freight_cost_main_price(l_price_count).delivery_id :=
6024 			fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
6025 		    x_freight_cost_main_price(l_price_count).uom := l_fc_rec.uom;
6026 		    x_freight_cost_main_price(l_price_count).quantity := FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity;
6027 		    x_freight_cost_main_price(l_price_count).line_type_code := l_fc_rec.line_type_code;
6028 		    x_freight_cost_main_price(l_price_count).freight_cost_type_id := l_fc_rec.freight_cost_type_id;
6029 		    x_freight_cost_main_price(l_price_count).charge_unit_value :=
6030 			l_fc_rec.charge_unit_value;
6031 		    x_freight_cost_main_price(l_price_count).unit_amount :=
6032 			round(l_fc_rec.unit_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
6033 		    x_freight_cost_main_price(l_price_count).total_amount :=
6034 			round(l_fc_rec.total_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
6035 		    x_freight_cost_main_price(l_price_count).currency_code := l_currency_code;
6036 		    x_freight_cost_main_price(l_price_count).charge_source_code := 'PRICING_ENGINE';
6037 		    x_freight_cost_main_price(l_price_count).estimated_flag := 'Y';
6038 		  ELSE
6039 		    x_freight_cost_temp_price(l_price_count).delivery_detail_id := p_top_level_rows(n).content_id;
6040 		    --x_freight_cost_temp_price(l_price_count).delivery_leg_id := p_top_level_rows(n).delivery_leg_id;
6041 		    x_freight_cost_temp_price(l_price_count).delivery_id :=
6042 			fte_freight_pricing.g_shipment_line_rows(p_top_level_rows(n).content_id).delivery_id;
6043 		    x_freight_cost_temp_price(l_price_count).uom := l_fc_rec.uom;
6044 		    x_freight_cost_temp_price(l_price_count).quantity := FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity;
6045 		    x_freight_cost_temp_price(l_price_count).line_type_code := l_fc_rec.line_type_code;
6046 		    x_freight_cost_temp_price(l_price_count).freight_cost_type_id := l_fc_rec.freight_cost_type_id;
6047 		    x_freight_cost_temp_price(l_price_count).charge_unit_value :=
6048 			l_fc_rec.charge_unit_value;
6049 		    x_freight_cost_temp_price(l_price_count).unit_amount :=
6050 			round(l_fc_rec.unit_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
6051 		    x_freight_cost_temp_price(l_price_count).total_amount :=
6052 			round(l_fc_rec.total_amount * FTE_FREIGHT_PRICING.g_rolledup_lines(n).line_quantity / l_fc_rec.quantity, 2);
6053 		    x_freight_cost_temp_price(l_price_count).currency_code := l_currency_code;
6054 		    x_freight_cost_temp_price(l_price_count).charge_source_code := 'PRICING_ENGINE';
6055 		    x_freight_cost_temp_price(l_price_count).estimated_flag := 'Y';
6056 		  END IF;
6057 
6058 	    EXIT WHEN (n >= FTE_FREIGHT_PRICING.g_rolledup_lines.LAST);
6059 	    n := FTE_FREIGHT_PRICING.g_rolledup_lines.NEXT(n);
6060 	    END LOOP;
6061 	    END IF;
6062 
6063 	  EXIT WHEN (i >= l_qp_output_line_rows.LAST);
6064 	  i := l_qp_output_line_rows.NEXT(i);
6065 	  END LOOP;
6066 	  END IF;
6067 
6068 	  -- create the summary record
6069 
6070 	  fte_freight_pricing.get_fc_type_id(
6071 		   p_line_type_code => 'FTESUMMARY',
6072 		   p_charge_subtype_code  => 'SUMMARY',
6073 		   x_freight_cost_type_id  =>  l_freight_cost_type_id,
6074 		   x_return_status  =>  l_return_status);
6075 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND
6076 		       l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6077 			raise FND_API.G_EXC_ERROR;
6078 	  END IF;
6079 
6080 
6081 	l_leg_id_array(l_delivery_id):=l_leg_id;
6082 	l_delivery_summary(l_delivery_id):=l_summary_amount;
6083 
6084 	l_trip_summary_amount:=l_trip_summary_amount+l_summary_amount;
6085   	k:= l_delivery_id_array.NEXT(k);
6086 
6087 
6088   END LOOP;
6089 
6090 
6091 
6092   -- Add the summary rows at the end
6093 
6094   IF p_save_flag = 'M' THEN
6095 
6096     --4294663
6097     i:=l_delivery_id_array.FIRST;
6098     j:=1;
6099     WHILE(i IS NOT NULL)
6100     LOOP
6101 
6102 	    x_fc_main_update_rows(j).delivery_leg_id := l_leg_id_array(i);
6103 	    x_fc_main_update_rows(j).delivery_id := l_delivery_id_array(i);
6104 	    x_fc_main_update_rows(j).freight_cost_id := fte_freight_pricing.get_fc_id_from_dleg(l_leg_id_array(i));
6105 	    x_fc_main_update_rows(j).line_type_code := 'SUMMARY';
6106 	    x_fc_main_update_rows(j).freight_cost_type_id := l_freight_cost_type_id;
6107 	    x_fc_main_update_rows(j).unit_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
6108 	    x_fc_main_update_rows(j).total_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
6109 	    x_fc_main_update_rows(j).currency_code := l_currency_code;
6110 	    x_fc_main_update_rows(j).charge_source_code := 'PRICING_ENGINE';
6111 	    x_fc_main_update_rows(j).estimated_flag := 'Y';
6112 
6113 
6114 
6115 
6116 	j:=j+1;
6117 	i:=l_delivery_id_array.NEXT(i);
6118     END LOOP;
6119 
6120   ELSE
6121 
6122     i:=l_delivery_id_array.FIRST;
6123 
6124     WHILE(i IS NOT NULL)
6125     LOOP
6126 
6127 	    --4294663
6128 	    l_price_count := l_price_count + 1;
6129 	    x_freight_cost_temp_price(l_price_count).delivery_id := l_delivery_id_array(i);
6130 	    x_freight_cost_temp_price(l_price_count).line_type_code := 'SUMMARY';
6131 	    x_freight_cost_temp_price(l_price_count).freight_cost_type_id :=  l_freight_cost_type_id;
6132 	    x_freight_cost_temp_price(l_price_count).unit_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
6133 	    x_freight_cost_temp_price(l_price_count).total_amount := round(l_delivery_summary(l_delivery_id_array(i)),2);
6134 	    x_freight_cost_temp_price(l_price_count).currency_code := l_currency_code;
6135 	    x_freight_cost_temp_price(l_price_count).charge_source_code := 'PRICING_ENGINE';
6136 	    x_freight_cost_temp_price(l_price_count).estimated_flag := 'Y';
6137 
6138 
6139 
6140 	i:=l_delivery_id_array.NEXT(i);
6141     END LOOP;
6142 
6143 
6144   END IF;
6145 
6146 
6147   x_summary_lanesched_price := round(l_trip_summary_amount,2);
6148   x_summary_lanesched_price_uom := l_currency_code;
6149 
6150   FTE_FREIGHT_PRICING_UTIL.unset_method(l_log_level,l_method_name);
6151 
6152 EXCEPTION
6153    WHEN FND_API.G_EXC_ERROR THEN
6154         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
6155         fte_freight_pricing_util.set_exception(l_method_name,l_log_level,'FND_API.G_EXC_ERROR');
6156         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
6157    WHEN others THEN
6158         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6159         FTE_FREIGHT_PRICING_UTIL.set_exception(l_method_name,FTE_FREIGHT_PRICING_UTIL.G_ERR,'g_others');
6160         FTE_FREIGHT_PRICING_UTIL.print_msg(FTE_FREIGHT_PRICING_UTIL.G_ERR,'Unexpected Error : '||SQLCODE||' : '||SQLERRM);
6161         fte_freight_pricing_util.unset_method(l_log_level,l_method_name);
6162 END;
6163 
6164 END FTE_FREIGHT_PRICING_SPECIAL;