DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSH_WV_UTILS

Source


1 PACKAGE BODY WSH_WV_UTILS as
2 /* $Header: WSHWVUTB.pls 120.23.12010000.2 2008/08/04 12:34:13 suppal ship $ */
3 
4 
5 --
6 G_PKG_NAME CONSTANT VARCHAR2(50) := 'WSH_WV_UTILS';
7 --
8 -- HW OPMCONV - Added lot_number and org_id parameters
9 c_wms_code_present VARCHAR2(2) := 'Y';
10 
11 -- MDC keep track of the parent consol LPN to prevent double counting
12 g_consol_lpn NUMBER;
13 
14 -- OTM R12 : packing ECO
15 -- default to 'Y' so only specific flow will use this to update delivery
16 G_DELIVERY_TMS_IMPACT  VARCHAR2(1) := 'Y';
17 -- End of OTM R12 : packing ECO
18 
19 --OTM R12, header include for the prorate procedure
20 
21 PROCEDURE Prorate_weight_actual(
22             p_entity_type	    IN         VARCHAR2,
23             p_entity_id		    IN         NUMBER,
24             p_old_gross_wt	    IN         NUMBER,
25 	    p_new_gross_wt	    IN         NUMBER,
26             p_old_net_wt	    IN         NUMBER,
27 	    p_new_net_wt	    IN         NUMBER,
28             p_weight_uom_code       IN         VARCHAR2,
29 	    x_return_status         OUT NOCOPY VARCHAR2,
30             p_call_level            IN         NUMBER);
31 --
32 
33 FUNCTION convert_uom(from_uom IN VARCHAR2,
34 		     to_uom IN VARCHAR2,
35 		     quantity IN NUMBER,
36 		     item_id IN NUMBER DEFAULT NULL,
37 		     p_max_decimal_digits IN NUMBER DEFAULT 5, -- RV DEC_QTY
38 		     lot_number VARCHAR2 DEFAULT NULL,
39 		     org_id IN NUMBER DEFAULT NULL)
40 RETURN NUMBER
41 IS
42   this_item     NUMBER;
43   to_rate       NUMBER;
44   from_rate     NUMBER;
45   result        NUMBER;
46 
47 --
48 --
49 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CONVERT_UOM';
50 --
51 BEGIN
52   --
53   --
54   IF quantity is NULL THEN
55     result := NULL;
56   ELSE
57     IF from_uom = to_uom THEN
58        result := round(quantity,p_max_decimal_digits);
59     ELSIF    from_uom IS NULL
60           OR to_uom   IS NULL THEN
61        result := 0;
62     ELSE
63        --
64        --
65        -- RV DEC_QTY
66        -- p_max_decimal_digits has a default value of 5.  Therefore
67        -- for all the outbound transactions, it will be passed as 5.
68        -- But for inbound data the value will be 38.
69 -- HW OPMCONV - Check for specific values to call the correct
70 -- procedure
71       IF (lot_number is NOT NULL OR org_id is NOT NULL ) THEN
72 -- Inventory has an overloaded procedure to perform
73 -- the UOM conversion
74 
75 -- RV DEC_QTY
76        -- p_max_decimal_digits has a default value of 5.  Therefore
77        -- for all the outbound transactions, it will be passed as 5.
78        -- But for inbound data the value will be 38.
79 
80        result := INV_CONVERT.inv_um_convert(item_id,
81                                             lot_number,
82                                             org_id,
83                                             p_max_decimal_digits, -- Bug 1842481 : precision digits changed to 5
84                                             quantity,
85                                             from_uom,
86                                             to_uom,
87                                             NULL,
88                                             NULL
89                                             );
90 -- Use old call
91     ELSE
92        result := INV_CONVERT.inv_um_convert(item_id,
93                                             p_max_decimal_digits, -- Bug 1842481 : precision digits changed to 5
94                                             quantity,
95                                             from_uom,
96                                             to_uom,
97                                             NULL,
98                                             NULL);
99 
100        --
101        --
102     END IF;
103 
104        -- hard-coded value that means undefined conversion
105        --  For example, conversion of FT2 to FT3 doesn't make sense...
106        -- Reset the result to 0 to preserve compatibility before
107        -- the bug fix made above (namely, always call inv_um_convert).
108        if result = -99999 then
109           result := 0;
110           FND_MESSAGE.SET_NAME('WSH','WSH_UNDEF_UOM_CONVERSION');
111      FND_MESSAGE.SET_TOKEN('FROM_UOM',from_uom);
112      FND_MESSAGE.SET_TOKEN('TO_UOM',to_uom);
113        end if;
114     END IF;
115   END IF;
116 
117   --
118   RETURN result;
119 
120 END convert_uom;
121 
122 FUNCTION convert_uom_core(from_uom IN VARCHAR2,
123 		     to_uom IN VARCHAR2,
124 		     quantity IN NUMBER,
125 		     item_id IN NUMBER DEFAULT NULL,
126 		     p_max_decimal_digits IN NUMBER DEFAULT 5, -- RV DEC_QTY
127 		     lot_number VARCHAR2 DEFAULT NULL,
128 		     org_id IN NUMBER DEFAULT NULL,
129                      x_return_status OUT NOCOPY VARCHAR2)
130 RETURN NUMBER
131 IS
132   this_item     NUMBER;
133   to_rate       NUMBER;
134   from_rate     NUMBER;
135   result        NUMBER;
136   l_ignore_wtvol  VARCHAR2(5);
137 
138 --
139 --
140 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CONVERT_UOM_CORE';
141 --
142 BEGIN
143   --
144   --
145   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
146   IF quantity is NULL THEN
147     result := NULL;
148   ELSE
149     IF from_uom = to_uom THEN
150        result := round(quantity,p_max_decimal_digits);
151     ELSIF    from_uom IS NULL
152           OR to_uom   IS NULL THEN
153        result := 0;
154     ELSE
155        --
156        --
157        -- RV DEC_QTY
158        -- p_max_decimal_digits has a default value of 5.  Therefore
159        -- for all the outbound transactions, it will be passed as 5.
160        -- But for inbound data the value will be 38.
161 -- HW OPMCONV - Check for specific values to call the correct
162 -- procedure
163       IF (lot_number is NOT NULL OR org_id is NOT NULL ) THEN
164 -- Inventory has an overloaded procedure to perform
165 -- the UOM conversion
166 
167 -- RV DEC_QTY
168        -- p_max_decimal_digits has a default value of 5.  Therefore
169        -- for all the outbound transactions, it will be passed as 5.
170        -- But for inbound data the value will be 38.
171 
172        result := INV_CONVERT.inv_um_convert(item_id,
173                                             lot_number,
174                                             org_id,
175                                             p_max_decimal_digits, -- Bug 1842481 : precision digits changed to 5
176                                             quantity,
177                                             from_uom,
178                                             to_uom,
179                                             NULL,
180                                             NULL
181                                             );
182 -- Use old call
183     ELSE
184        result := INV_CONVERT.inv_um_convert(item_id,
185                                             p_max_decimal_digits, -- Bug 1842481 : precision digits changed to 5
186                                             quantity,
187                                             from_uom,
188                                             to_uom,
189                                             NULL,
190                                             NULL);
191 
192        --
193        --
194     END IF;
195 
196        -- hard-coded value that means undefined conversion
197        --  For example, conversion of FT2 to FT3 doesn't make sense...
198        -- Reset the result to 0 to preserve compatibility before
199        -- the bug fix made above (namely, always call inv_um_convert).
200 
201           if result = -99999 then
202              fnd_profile.get('WSH_IGNORE_WT_VOL',l_ignore_wtvol);
203              IF NVL(l_ignore_wtvol,'Y') = 'N' THEN
204                 x_return_status := wsh_util_core.g_ret_sts_error;
205                 FND_MESSAGE.SET_NAME('WSH','WSH_UNDEF_UOM_CONVERSION');
206                 FND_MESSAGE.SET_TOKEN('FROM_UOM',from_uom);
207                 FND_MESSAGE.SET_TOKEN('TO_UOM',to_uom);
208                 WSH_UTIL_CORE.add_message (x_return_status);
209              END IF;
210              result := 0;
211           end if;
212     END IF;
213   END IF;
214 
215   --
216   RETURN result;
217 
218 EXCEPTION
219     WHEN OTHERS THEN
220       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
221       wsh_util_core.default_handler('WSH_WV_UTILS.convert_uom_core');
222       --
223 
224 END convert_uom_core;
225 
226 PROCEDURE get_default_uoms ( p_organization_id IN NUMBER,
227             x_weight_uom_code  OUT NOCOPY  VARCHAR2,
228             x_volume_uom_code  OUT NOCOPY  VARCHAR2,
229             x_return_status    OUT NOCOPY  VARCHAR2) IS
230 
231 CURSOR cur_get_uom (x_uom_class IN VARCHAR2) IS
232   SELECT UOM_CODE
233   FROM mtl_units_of_measure
234   WHERE base_uom_flag = 'Y' AND
235       uom_class = x_uom_class;
236 
237 CURSOR get_class IS
238   SELECT weight_uom_class, volume_uom_class
239   FROM   wsh_shipping_parameters
240   WHERE  organization_id = p_organization_id;
241 
242 l_weight_uom_class VARCHAR2(10);
243 l_volume_uom_class VARCHAR2(10);
244 
245 --
246 l_debug_on BOOLEAN;
247 --
248 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'GET_DEFAULT_UOMS';
249 --
250 BEGIN
251 
252     --
253     -- Debug Statements
254     --
255     --
256     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
257     --
258     IF l_debug_on IS NULL
259     THEN
260         l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
261     END IF;
262     --
263     IF l_debug_on THEN
264         WSH_DEBUG_SV.push(l_module_name);
265         --
266         WSH_DEBUG_SV.log(l_module_name,'P_ORGANIZATION_ID',P_ORGANIZATION_ID);
267     END IF;
268     --
269     if ( p_organization_id is NULL ) Then
270     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
271       --
272       -- Debug Statements
273       --
274       IF l_debug_on THEN
275           WSH_DEBUG_SV.pop(l_module_name);
276       END IF;
277       --
278       Return;
279     end if;
280 
281     OPEN get_class;
282     FETCH get_class INTO l_weight_uom_class, l_volume_uom_class;
283     CLOSE get_class;
284 
285     IF (l_weight_uom_class IS NOT NULL) THEN
286 
287        OPEN cur_get_uom(l_weight_uom_class);
288        FETCH cur_get_uom INTO x_weight_uom_code;
289        CLOSE cur_get_uom;
290 
291     END IF;
292     IF (l_volume_uom_class IS NOT NULL) THEN
293 
294        OPEN cur_get_uom(l_volume_uom_class);
295        FETCH cur_get_uom INTO x_volume_uom_code;
296        CLOSE cur_get_uom;
297 
298     END IF;
299 
300     --
301     -- Debug Statements
302     --
303     IF l_debug_on THEN
304         WSH_DEBUG_SV.pop(l_module_name);
305     END IF;
306     --
307 EXCEPTION
308     WHEN Others THEN
309      WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.GET_DEFAULT_UOMS');
310      x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
311 
312 --
313 -- Debug Statements
314 --
315 IF l_debug_on THEN
316     WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
317     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
318 END IF;
319 --
320 END get_default_uoms;
321 
322 
323 -- J: W/V Changes
324 
325 -- Start of comments
326 -- API name : Detail_Weight_Volume
327 -- Type     : Public
328 -- Pre-reqs : None.
329 -- Function : Calculates Weight and Volume of Delivery Detail
330 --            If p_update_flag is 'Y' then the calculated W/V is updated on Delivery Detail
331 --            Otherwise, the API returns the calculated W/V
332 --            OTM R12 : packing ECO
333 --                      This procedure is modified to keep track of delivery
334 --                      detail wt/vol updates. Changed because it contains the
335 --                      actual update on the wsh_delivery_detail table.
336 -- Parameters :
337 -- IN:
338 --    p_delivery_detail_id IN NUMBER Required
339 --    p_update_flag        IN VARCHAR2
340 --      'Y' if the detail needs to be updated with the calculated W/V
341 --    p_calc_wv_if_frozen  IN VARCHAR2
342 --      'Y' if manual W/V can be overriden
343 -- OUT:
344 --    x_net_weight OUT NUMBER
345 --       gives the net weight of delivery detail
346 --    x_volume OUT NUMBER
347 --       gives the volume of delivery detail
348 --    x_return_status OUT VARCHAR2 Required
349 --       give the return status of API
350 -- Version : 1.0
351 -- End of comments
352 
353 PROCEDURE Detail_Weight_Volume (
354   p_delivery_detail_id IN NUMBER,
355   p_update_flag        IN VARCHAR2,
356   p_calc_wv_if_frozen  IN VARCHAR2 DEFAULT 'Y',
357   x_net_weight         OUT NOCOPY  NUMBER,
358   x_volume             OUT NOCOPY  NUMBER,
359   x_return_status      OUT NOCOPY  VARCHAR2) AS
360 
361 
362   CURSOR Item_Net_Wt_Vol(v_delivery_detail_id NUMBER) IS
363   SELECT convert_uom(
364            msi.weight_uom_code,
365            NVL(wdd.weight_uom_code,msi.weight_uom_code),
366            (NVL(wdd.unit_weight,msi.unit_weight) *
367               convert_uom(
368                 wdd.requested_quantity_uom,
369                 msi.primary_uom_code,
370                 nvl(wdd.received_quantity, nvl(wdd.shipped_quantity, NVL(wdd.picked_quantity, wdd.requested_quantity))),
371                 wdd.inventory_item_id) ),
372             wdd.inventory_item_id ) WEIGHT,
373           convert_uom(
374             msi.volume_uom_code,
375             NVL(wdd.volume_uom_code,msi.volume_uom_code),
376             (NVL(wdd.unit_volume,msi.unit_volume) *
377                convert_uom(
378                  wdd.requested_quantity_uom,
379                  msi.primary_uom_code,
380                  nvl(wdd.received_quantity, nvl(wdd.shipped_quantity, NVL(wdd.picked_quantity, wdd.requested_quantity))),
381                  wdd.inventory_item_id) ),
382             wdd.inventory_item_id ) VOLUME,
383           msi.weight_uom_code,
384           msi.volume_uom_code,
385           msi.unit_weight,
386           msi.unit_volume
387   FROM    wsh_delivery_details wdd,
388           mtl_system_items     msi
389   WHERE   wdd.delivery_detail_id = v_delivery_detail_id
390   AND     msi.inventory_item_id = wdd.inventory_item_id
391   AND     msi.organization_id = wdd.organization_id;
392 
393 
394   /* Bug 2177410, for non item just return the net weight and
395      volume of the delivery detail  */
396   CURSOR get_detail_wv (v_delivery_detail_id NUMBER ) IS
397   select wdd.inventory_item_id,
398          wdd.organization_id,
399          wdd.net_weight,
400          wdd.volume,
401          wdd.gross_weight ,
402          wdd.unit_weight,
403          wdd.unit_volume,
404          nvl(wdd.received_quantity, nvl(wdd.shipped_quantity, NVL(wdd.picked_quantity, wdd.requested_quantity))) qty,
405          wdd.weight_uom_code,
406          wdd.volume_uom_code,
407          --lpn conv
408          wdd.container_flag,
409          NVL(wdd.wv_frozen_flag,'Y'),
410          nvl(line_direction,'O') line_direction -- LPN CONV. rv
411   from   wsh_delivery_details wdd
412   where  wdd.delivery_detail_id = v_delivery_detail_id;
413 
414   l_debug_on BOOLEAN;
415   l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DETAIL_WEIGHT_VOLUME';
416   l_inventory_item_id NUMBER;
417   l_organization_id   NUMBER;
418   l_net_weight        NUMBER;
419   l_volume            NUMBER;
420   l_gross_weight      NUMBER;
421   l_dd_wt_code        VARCHAR(100);
422   l_dd_vol_code       VARCHAR(100);
423   l_wv_frozen_flag    VARCHAR2(1);
424   l_unit_wt           NUMBER;
425   l_unit_vol          NUMBER;
426   l_qty               NUMBER;
427   l_item_wt_code      VARCHAR(100);
428   l_item_vol_code     VARCHAR(100);
429   l_item_unit_wt      NUMBER;
430   l_item_unit_vol     NUMBER;
431   l_frozen_flag       VARCHAR2(1);
432   l_return_status     VARCHAR2(1);
433   l_detail_tab        WSH_UTIL_CORE.Id_Tab_Type;
434   --lpn conv
435   l_container_flag    VARCHAR2(10);
436   l_wms_org           VARCHAR2(10) := 'N';
437   -- LPN CONV. rv
438   l_sync_tmp_rec    wsh_glbl_var_strct_grp.sync_tmp_rec_type;
439   -- LPN CONV. rv
440   l_line_direction    VARCHAR2(10);
441   l_num_warnings      NUMBER := 0;
442   mark_reprice_error  EXCEPTION;
443 
444 BEGIN
445 
446       l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
447       IF l_debug_on IS NULL THEN
448           l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
449       END IF;
450       IF l_debug_on THEN
451           WSH_DEBUG_SV.push(l_module_name);
452           WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_DETAIL_ID',P_DELIVERY_DETAIL_ID);
453           WSH_DEBUG_SV.log(l_module_name,'P_UPDATE_FLAG',P_UPDATE_FLAG);
454           WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
455       END IF;
456 
457       x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
458 
459       -- Get the original W/V of the delivery detail
460       OPEN  get_detail_wv (p_delivery_detail_id);
461       FETCH get_detail_wv
462       INTO  l_inventory_item_id,
463             l_organization_id,
464             l_net_weight,
465             l_volume,
466             l_gross_weight,
467             l_unit_wt,
468             l_unit_vol,
469             l_qty,
470             l_dd_wt_code,
471             l_dd_vol_code,
472             -- lpn conv
473             l_container_flag,
474             l_wv_frozen_flag,
475             l_line_direction; -- LPN CONV. rv
476       IF get_detail_wv%NOTFOUND THEN
477         FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_INVALID_DETAIL');
478         FND_MESSAGE.SET_TOKEN('DETAIL_ID',p_delivery_detail_id);
479         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
480         CLOSE get_detail_wv;
481         IF l_debug_on THEN
482           WSH_DEBUG_SV.pop(l_module_name);
483         END IF;
484         return;
485       END IF;
486       CLOSE get_detail_wv;
487 
488       --lpn conv
489       IF l_container_flag IN ('Y', 'C')  THEN
490          l_wms_org := wsh_util_validate.check_wms_org(l_organization_id);
491          IF l_wms_org = 'Y' THEN
492             l_wv_frozen_flag := 'N';
493          END IF;
494       END IF;
495 
496       IF l_debug_on THEN
497         WSH_DEBUG_SV.logmsg(l_module_name,'Item Id '||l_inventory_item_id||' Org '||l_organization_id||' Wt Code '||l_dd_wt_code||' Vol Code '||l_dd_vol_code||' Qty '||l_qty);
498         WSH_DEBUG_SV.logmsg(l_module_name,'Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume||' U Wt '||l_unit_wt||' U Vol '||l_unit_vol||' Frozen '||l_wv_frozen_flag);
499       END IF;
500 
501       -- Return the original W/V if the W/V is manually entered and p_calc_wv_if_frozen is 'N'
502       IF p_calc_wv_if_frozen = 'N' and l_wv_frozen_flag ='Y' THEN
503         x_net_weight := l_net_weight;
504         x_volume     := l_volume;
505         IF l_debug_on THEN
506           WSH_DEBUG_SV.logmsg(l_module_name,'Detail weights are Frozen. Skipping W/V calculation');
507           WSH_DEBUG_SV.pop(l_module_name);
508         END IF;
509         RETURN;
510       END IF;
511 
512       --  If the delivery details has one time item then
513       --    If the delivery detail doesn't have unit wt or volume specified then
514       --       do not calculate W/V.
515       --    Else
516       --       calculate the W/V.
517       --  Else calculate the W/V.
518       --       If p_update_flag is 'Y' then update the W/V info on delivery detail
519       IF l_inventory_item_id is NULL THEN
520         IF l_unit_wt is NULL AND l_unit_vol is NULL THEN
521           x_net_weight := l_net_weight;
522           x_volume     := l_volume;
523         ELSE
524           x_net_weight := l_qty * l_unit_wt;
525           x_volume     := l_qty * l_unit_vol;
526           l_frozen_flag := 'N';
527         END IF;
528 
529       ELSE
530 
531         OPEN  Item_Net_Wt_Vol (p_delivery_detail_id);
532 
533         FETCH Item_Net_Wt_Vol
534         INTO  x_net_weight,
535               x_volume,
536               l_item_wt_code,
537               l_item_vol_code,
538               l_item_unit_wt,
539               l_item_unit_vol;
540 
541         IF Item_Net_Wt_Vol%NOTFOUND THEN
542           FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_INVALID_DETAIL');
543           FND_MESSAGE.SET_TOKEN('DETAIL_ID',p_delivery_detail_id);
544           x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
545           CLOSE Item_Net_Wt_Vol;
546           IF l_debug_on THEN
547             WSH_DEBUG_SV.pop(l_module_name);
548            END IF;
549            return;
550         END IF;
551         CLOSE Item_Net_Wt_Vol;
552         l_frozen_flag := 'N';
553       END IF;
554 
555       IF p_update_flag = 'Y' THEN
556 
557          --lpn conv
558          IF NVL(l_frozen_flag,'Y') = 'Y' THEN
559             IF l_wms_org = 'Y' AND l_container_flag IN ('Y', 'C') THEN
560                l_frozen_flag := 'N';
561             END IF;
562          END IF;
563          -- LPN CONV. rv
564          --
565          --
566          IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
567          AND l_line_direction IN ('O','IO')
568          AND l_container_flag IN ('Y','C')
569          AND
570          (
571            ((WSH_WMS_LPN_GRP.GK_WMS_UPD_WV or WSH_WMS_LPN_GRP.GK_WMS_UPD_ITEM) and l_wms_org = 'Y')
572            OR
573            ((WSH_WMS_LPN_GRP.GK_INV_UPD_WV or WSH_WMS_LPN_GRP.GK_INV_UPD_ITEM) and l_wms_org = 'N')
574          )
575          THEN
576          --{
577              l_sync_tmp_rec.delivery_detail_id := p_delivery_detail_id;
578              l_sync_tmp_rec.operation_type := 'UPDATE';
579              --
580              -- Debug Statements
581              --
582              IF l_debug_on THEN
583                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WMS_SYNC_TMP_PKG.MERGE',WSH_DEBUG_SV.C_PROC_LEVEL);
584              END IF;
585              --
586 
587              WSH_WMS_SYNC_TMP_PKG.MERGE
588              (
589                p_sync_tmp_rec      => l_sync_tmp_rec,
590                x_return_status     => l_return_status
591              );
592 
593              IF l_debug_on THEN
594                WSH_DEBUG_SV.log(l_module_name,'Return Status after calling WSH_WMS_SYNC_TMP_PKG.MERGE',l_return_status);
595              END IF;
596              --
597              IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
598                --
599                x_return_status := l_return_status;
600                --
601                IF l_debug_on THEN
602                  WSH_DEBUG_SV.logmsg(l_module_name,'WSH_WMS_SYNC_TMP_PKG.MERGE completed with an error');
603                  WSH_DEBUG_SV.pop(l_module_name);
604                END IF;
605                --
606                RETURN;
607              ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
608                l_num_warnings := l_num_warnings + 1;
609              END IF;
610          --}
611          END IF;
612          -- K LPN CONV. rv
613          --
614          UPDATE WSH_DELIVERY_DETAILS
615          SET net_weight        = x_net_weight,
616              volume            = x_volume,
617              gross_weight      = x_net_weight,
618              weight_uom_code   = nvl(weight_uom_code,l_item_wt_code),
619              volume_uom_code   = nvl(volume_uom_code,l_item_vol_code),
620              unit_weight       = NVL(unit_weight,l_item_unit_wt),
621              unit_volume       = NVL(unit_volume,l_item_unit_vol),
622              wv_frozen_flag    = decode(l_frozen_flag,NULL,wv_frozen_flag,l_frozen_flag),
623              last_update_date  = SYSDATE,
624              last_updated_by   = FND_GLOBAL.user_id,
625              last_update_login = FND_GLOBAL.login_id
626          WHERE delivery_detail_id = p_delivery_detail_id;
627 
628          IF SQL%NOTFOUND THEN
629            x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
630            FND_MESSAGE.SET_NAME('WSH','WSH_DET_INVALID_DETAIL');
631            FND_MESSAGE.SET_TOKEN('DETAIL_ID',p_delivery_detail_id);
632            IF l_debug_on THEN
633              WSH_DEBUG_SV.pop(l_module_name);
634            END IF;
635            return;
636          END IF;
637 
638          -- bug 3711017 mark reprice required only when weight volume have changed
639          IF ((l_dd_wt_code is NULL and l_item_wt_code is not NULL )
640            or (l_dd_vol_code is NULL and l_item_vol_code is not NULL)
641            or nvl(x_net_weight, 0) <> nvl(l_net_weight, 0)
642            or nvl(x_volume, 0) <> nvl(l_volume, 0 )
643            or nvl(x_net_weight, 0) <> nvl(l_gross_weight,0)) THEN
644             l_detail_tab(1) := p_delivery_detail_id;
645             WSH_DELIVERY_LEGS_ACTIONS.Mark_Reprice_Required(
646 	     p_entity_type => 'DELIVERY_DETAIL',
647 	     p_entity_ids   => l_detail_tab,
648 	     x_return_status => l_return_status);
649 	    IF l_debug_on THEN
650 	     WSH_DEBUG_SV.log(l_module_name,'Mark_Reprice_Required l_return_status',l_return_status);
651 	    END IF;
652 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
653 	     raise mark_reprice_error;
654             END IF;
655          END IF;
656          -- end of bug 3711017
657 
658          -- OTM R12 : packing ECO
659          -- after update wsh_delivery_details sql
660          -- if any weight/vol changed, mark the global variable
661          IF (G_DELIVERY_TMS_IMPACT = 'N' AND
662              (NVL(l_net_weight, -1) <> NVL(x_net_weight, -1) OR
663               NVL(l_volume, -1) <> NVL(x_volume, -1) OR
664               NVL(l_dd_wt_code, '@@') <>
665               NVL(l_dd_wt_code, NVL(l_item_wt_code, '@@')) OR
666               NVL(l_gross_weight, -1) <> NVL(x_net_weight, -1) OR
667               NVL(l_dd_vol_code, '@@') <>
668               NVL(l_dd_vol_code, NVL(l_item_vol_code, '@@')))) THEN
669            G_DELIVERY_TMS_IMPACT := 'Y';
670 
671 	   IF l_debug_on THEN
672 	     WSH_DEBUG_SV.log(l_module_name,'G_DELIVERY_TMS_IMPACT', G_DELIVERY_TMS_IMPACT);
673 	   END IF;
674          END IF;
675          -- End of OTM R12 : packing ECO
676       END IF; -- p_update_flag
677 
678 
679       -- LPN CONV. rv
680       IF (l_num_warnings > 0 AND x_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
681         --
682         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
683         --
684       ELSE
685         --
686         x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
687         --
688       END IF;
689       -- LPN CONV. rv
690 
691       IF l_debug_on THEN
692         WSH_DEBUG_SV.log(l_module_name,'x_net_weight '||x_net_weight||' x_volume '||x_volume||' x_return_status '||x_return_status);
693         WSH_DEBUG_SV.pop(l_module_name);
694       END IF;
695 
696 EXCEPTION
697 
698   WHEN mark_reprice_error then
699 
700    FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
701    x_return_status := l_return_status;
702    WSH_UTIL_CORE.add_message (x_return_status);
703    --
704    -- Debug Statements
705    --
706    IF l_debug_on THEN
707        WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
708        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
709    END IF;
710 
711 
712    WHEN others THEN
713 
714       wsh_util_core.default_handler ('WSH_WV_UTILS.DETAIL_WEIGHT_VOLUME');
715       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
716       IF l_debug_on THEN
717           WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
718           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
719       END IF;
720 
721 END Detail_Weight_Volume;
722 
723 -- J: W/V changes
724 
725 -- Start of comments
726 -- API name : Adjust_parent_WV
727 -- Type     : Private
728 -- Pre-reqs : None.
729 -- Function : Adjusts W/V on parent(container, delivery, stop) recursively
730 -- Parameters :
731 -- IN:
732 --    p_entity_type   IN VARCHAR2 Required
733 --      Valid values are  STOP, DELIVERY, CONTAINER, DETAIL
734 --    p_entity_id     IN VARCHAR2 Required
735 --      Id of the p_entity_type
736 --    p_gross_weight  IN NUMBER
737 --      Gross weight to be adjusted on p_entity_id
738 --    p_net_weight    IN NUMBER
739 --      Net weight to be adjusted on p_entity_id
740 --    p_volume        IN NUMBER
741 --      Volume to be adjusted on p_entity_id
742 --    p_filled_volume IN NUMBER
743 --      Filled Volume to be adjusted on p_entity_id
744 --    p_wt_uom_code   IN VARCHAR2
745 --      Wt UOM code of the Weight
746 --    p_vol_uom_code  IN VARCHAR2
747 --      Vol UOM code of the Volume
748 --    p_inv_item_id  IN VARCHAR2
749 --      Item Id of the child entity
750 -- OUT:
751 --    x_return_status OUT VARCHAR2 Required
752 --       give the return status of API
753 -- Version : 1.0
754 -- End of comments
755 
756 PROCEDURE Adjust_parent_WV (
757               p_entity_type             IN VARCHAR2,
758               p_entity_id               IN NUMBER,
759               p_gross_weight            IN NUMBER,
760               p_net_weight              IN NUMBER,
761               p_volume                  IN NUMBER DEFAULT null,
762               p_filled_volume           IN NUMBER DEFAULT null,
763               p_wt_uom_code             IN VARCHAR2,
764               p_vol_uom_code            IN VARCHAR2,
765               p_inv_item_id             IN NUMBER,
766               x_return_status           OUT NOCOPY VARCHAR2,
767               p_stop_type               IN VARCHAR2 DEFAULT NULL)
768 IS
769 
770 
771   -- MDC: Update the stop wt/vol for delivery only
772   --      if the delivery is directly attached to
773   --      the delivery_leg.
774 
775   CURSOR trip_info IS
776   SELECT wts.trip_id,
777          wdl.pick_up_stop_id,
778          wdl.drop_off_stop_id,
779          wdl.parent_delivery_leg_id
780   FROM   wsh_trip_stops wts,
781          wsh_delivery_legs wdl
782   WHERE  wdl.delivery_id = p_entity_id
783   AND    wdl.pick_up_stop_id = wts.stop_id;
784 
785   CURSOR c_stops(c_trip_id IN NUMBER, c_pkup_stop_id IN NUMBER, c_dpoff_stop_id IN NUMBER) IS
786   SELECT wts.stop_id,
787          wts.departure_gross_weight,
788          wts.departure_net_weight,
789          wts.departure_volume
790   FROM   wsh_trip_stops wts
791   WHERE  wts.trip_id = c_trip_id
792   AND    wts.stop_sequence_number < (
793            select wts1.stop_sequence_number
794            from   wsh_trip_stops wts1
795            where  wts1.stop_id = c_dpoff_stop_id)
796   AND    wts.stop_sequence_number >= (
797            select wts2.stop_sequence_number
798            from   wsh_trip_stops wts2
799            where  wts2.stop_id = c_pkup_stop_id)
800   FOR    UPDATE NOWAIT -- BugFix 3570954 Added NOWAIT
801   ORDER  BY wts.stop_id, wts.planned_departure_date ASC;
802 
803   -- MDC: Update the parent delivery's wt/vol
804   --      when updating the child wt/vol
805 
806   CURSOR c_consol_delivery(p_delivery_leg_id IN NUMBER) IS
807   SELECT delivery_id
808   FROM wsh_delivery_legs
809   WHERE delivery_leg_id = p_delivery_leg_id;
810 
811 
812   -- BugFix 3570954
813   -- Added lock_detected exception
814   lock_detected	EXCEPTION;
815   PRAGMA EXCEPTION_INIT( lock_detected, -00054);
816 
817 l_debug_on              BOOLEAN;
818 l_module_name CONSTANT  VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'ADJUST_PARENT_WV';
819 l_gross_weight          number;
820 l_net_weight            number;
821 l_volume                number;
822 l_wt_uom_code           VARCHAR2(3);
823 l_vol_uom_code          VARCHAR2(3);
824 l_status_code           VARCHAR2(2);
825 l_shipment_type_flag    VARCHAR2(1);
826 l_shipment_direction    wsh_new_deliveries.shipment_direction%TYPE;
827 l_frozen_flag           VARCHAR2(1);
828 l_inv_item_id           number;
829 l_org_gross_wt          number;
830 l_org_net_wt            number;
831 l_org_vol               number;
832 l_org_fill_vol          number;
833 l_filled_volume         number;
834 l_container_id          number;
835 l_delivery_id           number;
836 l_return_status         VARCHAR2(100);
837 l_num_warnings          number;
838 l_cont_fill_pc          number;
839 l_fill_percent          number;
840 
841 -- MDC
842 l_parent_delivery_id    number;
843 l_wda_type              VARCHAR2(30);
844 
845 e_wt_mismatch           exception;
846 e_abort                 exception;
847 e_wt_vol_fail           exception;
848 record_locked           exception;
849 PRAGMA EXCEPTION_INIT(record_locked, -54);
850 
851 --Bugfix 4070732
852 l_num_errors            NUMBER;
853 l_entity_id             NUMBER;
854 l_container_flag        VARCHAR2(10);
855 l_organization_id       NUMBER;
856 l_wms_org               VARCHAR2(10) := 'N';
857 
858 --R12 MDC
859 l_pick_up_weight  number;
860 l_pick_up_volume number;
861 l_drop_off_weight number;
862 l_drop_off_volume number;
863 l_line_direction VARCHAR2(10);
864 l_update_wms_org            varchar2(10) := 'N';
865 
866 
867 BEGIN
868 
869   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
870   IF l_debug_on IS NULL THEN
871     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
872   END IF;
873 
874   IF l_debug_on THEN
875     WSH_DEBUG_SV.push(l_module_name);
876     WSH_DEBUG_SV.log(l_module_name,'p_entity_type',p_entity_type);
877     WSH_DEBUG_SV.log(l_module_name,'p_entity_id',p_entity_id);
878     WSH_DEBUG_SV.log(l_module_name,'p_gross_weight',p_gross_weight);
879     WSH_DEBUG_SV.log(l_module_name,'p_net_weight',p_net_weight);
880     WSH_DEBUG_SV.log(l_module_name,'p_volume',p_volume);
881     WSH_DEBUG_SV.log(l_module_name,'p_filled_volume',p_filled_volume);
882     WSH_DEBUG_SV.log(l_module_name,'p_wt_uom_code',p_wt_uom_code);
883     WSH_DEBUG_SV.log(l_module_name,'p_vol_uom_code',p_vol_uom_code);
884     WSH_DEBUG_SV.log(l_module_name,'p_inv_item_id',p_inv_item_id);
885     WSH_DEBUG_SV.log(l_module_name,'p_stop_type',p_stop_type);
886   END IF;
887   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
888   l_num_errors := 0;
889   l_num_warnings := 0;
890 
891   -- Check if the values of input W/V are > 0
892   -- IF ((NVL(p_gross_weight,0) <> 0) OR (NVL(p_net_weight,0) <> 0) OR (NVL(p_volume,0) <> 0) OR
893   --    (p_entity_type in ('CONTAINER','DETAIL') AND NVL(p_filled_volume,0) <> 0)) THEN
894 
895     --  For Stop
896     IF (p_entity_type = 'STOP') THEN
897 
898       -- Get the orginal W/V info of the stop
899       BEGIN
900         SELECT departure_gross_weight,
901                departure_net_weight,
902                departure_volume,
903                weight_uom_code,
904                volume_uom_code,
905                status_code,
906                NVL(shipments_type_flag,'O'),
907                NVL(wv_frozen_flag,'Y'),
908                pick_up_weight,
909                pick_up_volume,
910                drop_off_weight,
911                drop_off_volume
912         INTO   l_gross_weight,
913                l_net_weight,
914                l_volume,
915                l_wt_uom_code,
916                l_vol_uom_code,
917                l_status_code,
918                l_shipment_type_flag,
919                l_frozen_flag,
920                l_pick_up_weight,
921                l_pick_up_volume,
922                l_drop_off_weight,
923                l_drop_off_volume
924         FROM   wsh_trip_stops
925         WHERE  stop_id = p_entity_id
926         FOR UPDATE NOWAIT;
927       EXCEPTION
928         WHEN record_locked THEN
929           IF l_debug_on THEN
930             WSH_DEBUG_SV.logmsg(l_module_name,'Error: '||p_entity_type||' Id '||p_entity_id||'could not be locked');
931           END IF;
932           raise e_abort;
933       END;
934 
935 
936       IF l_debug_on THEN
937         WSH_DEBUG_SV.logmsg(l_module_name,p_entity_type||' has Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume||' Wt-Uom '||l_wt_uom_code||' Vol-Uom '||l_vol_uom_code ||' Status '||l_status_code||' Frozen '||l_frozen_flag);
938       END IF;
939 
940       IF (NVL(l_shipment_type_flag, ' ') = 'O' AND NVL(l_status_code , ' ') in ('IT','CL'))
941       OR (l_frozen_flag = 'Y' and p_stop_type NOT IN ('PICKUP','DROPOFF')) THEN
942         IF l_debug_on THEN
943           WSH_DEBUG_SV.logmsg(l_module_name,'W/V propogation not allowed');
944           WSH_DEBUG_SV.pop(l_module_name);
945         END IF;
946 
947         return;
948       END IF;
949 
950       -- If the W/V UOM on stop and the input differ then convert the input W/V to the stop UOMs
951       IF (l_wt_uom_code <> p_wt_uom_code) THEN
952         l_org_gross_wt := convert_uom(p_wt_uom_code, l_wt_uom_code, NVL(p_gross_weight,0), p_inv_item_id);
953         l_org_net_wt   := convert_uom(p_wt_uom_code, l_wt_uom_code, NVL(p_net_weight,0), p_inv_item_id);
954       ELSE
955         l_org_gross_wt := p_gross_weight;
956         l_org_net_wt   := p_net_weight;
957       END IF;
958 
959       IF (l_vol_uom_code <> p_vol_uom_code) THEN
960         l_org_vol := convert_uom(p_vol_uom_code, l_vol_uom_code, NVL(p_volume,0), p_inv_item_id);
961       ELSE
962         l_org_vol := p_volume;
963       END IF;
964 
965       IF l_debug_on THEN
966         WSH_DEBUG_SV.logmsg(l_module_name,'Parameter Values after UOM conversions are Gross '||l_org_gross_wt||' Net '||l_org_net_wt||' Vol '||l_org_vol);
967       END IF;
968 
969       -- Sum up the input W/V and Stop's original W/V
970       IF NOT (l_gross_weight IS NULL and l_org_gross_wt IS NULL) THEN
971         l_gross_weight := GREATEST(nvl(l_gross_weight,0) + nvl(l_org_gross_wt,0),0);
972       END IF;
973       IF NOT (l_net_weight IS NULL and l_org_net_wt IS NULL) THEN
974         l_net_weight := GREATEST(nvl(l_net_weight,0) + nvl(l_org_net_wt,0),0);
975       END IF;
976       IF NOT (l_volume IS NULL and l_org_vol IS NULL) THEN
977         l_volume := GREATEST(nvl(l_volume,0) + nvl(l_org_vol,0),0);
978       END IF;
979       IF (nvl(l_gross_weight,0) < nvl(l_net_weight,0)) THEN
980         -- raise e_wt_mismatch;
981         l_gross_weight := l_net_weight;
982       END IF;
983 
984       --R12 MDC
985       If p_stop_type = 'PICKUP' Then
986 
987          -- Add the input (converted UOM if necessary)gross weight to l_pick_up_weight
988          IF NOT (l_pick_up_weight IS NULL and l_org_gross_wt IS NULL) THEN
989             l_pick_up_weight := GREATEST(nvl(l_pick_up_weight,0) + nvl(l_org_gross_wt,0),0);
990          END IF;
991 
992         --Add the input (converted UOM if necessary)volume  to l_pick_up_volume
993         IF NOT (l_pick_up_volume IS NULL and l_org_vol IS NULL) THEN
994            l_pick_up_volume := GREATEST(nvl(l_pick_up_volume,0) + nvl(l_org_vol,0),0);
995         END IF;
996 
997      Elsif p_stop_type = 'DROPOFF' Then
998 
999        --Add the input (converted UOM if necessary)gross weight to l_drop_off_weight
1000        IF NOT (l_drop_off_weight IS NULL and l_org_gross_wt IS NULL) THEN
1001 	 l_drop_off_weight := GREATEST(nvl(l_drop_off_weight,0) + nvl(l_org_gross_wt ,0),0);
1002        END IF;
1003 
1004        --Add the input (converted UOM if necessary)gross weight to l_drop_off_volume
1005        IF NOT (l_drop_off_volume IS NULL and l_org_vol IS NULL) THEN
1006          l_drop_off_volume := GREATEST(nvl(l_drop_off_volume,0) + nvl(l_org_vol,0),0);
1007        END IF;
1008      END IF;
1009 
1010       -- Calculate Stop fill%
1011       IF l_debug_on THEN
1012         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TRIPS_ACTIONS.Stop_Fill_Percent',WSH_DEBUG_SV.C_PROC_LEVEL);
1013       END IF;
1014       WSH_TRIPS_ACTIONS.Calc_Stop_Fill_Percent(
1015         p_stop_id           => p_entity_id,
1016         p_gross_weight      => l_gross_weight,
1017         p_volume            => l_volume,
1018         x_stop_fill_percent => l_fill_percent,
1019         x_return_status     => l_return_status);
1020 
1021       IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1022         x_return_status := l_return_status;
1023         IF l_debug_on THEN
1024           WSH_DEBUG_SV.pop(l_module_name);
1025         END IF;
1026         RETURN;
1027       END IF;
1028 
1029       IF WSH_UTIL_CORE.FTE_IS_INSTALLED = 'Y' THEN
1030         --Bugfix 4070732
1031         IF WSH_UTIL_CORE.G_CALL_FTE_LOAD_TENDER_API THEN --{
1032 
1033            IF l_debug_on THEN
1034               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TRIPS_ACTIONS.Fte_Load_Tender',WSH_DEBUG_SV.C_PROC_LEVEL);
1035            END IF;
1036            WSH_TRIPS_ACTIONS.Fte_Load_Tender(
1037               p_stop_id       => p_entity_id,
1038               p_gross_weight  => l_gross_weight,
1039               p_net_weight    => l_net_weight,
1040               p_volume        => l_volume,
1041               p_fill_percent  => l_fill_percent,
1042               x_return_status => l_return_status);
1043 
1044            IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1045               x_return_status := l_return_status;
1046              IF l_debug_on THEN
1047                 WSH_DEBUG_SV.pop(l_module_name);
1048              END IF;
1049              RETURN;
1050            END IF;
1051 
1052         ELSE --{ }
1053 
1054           IF l_debug_on THEN
1055               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.GET_CACHED_VALUE',WSH_DEBUG_SV.C_PROC_LEVEL);
1056           END IF;
1057 
1058 	  l_entity_id := p_entity_id;
1059 	  wsh_util_core.get_cached_value
1060              (
1061               p_cache_tbl         => WSH_UTIL_CORE.G_STOP_IDS_STOP_IDS_CACHE,
1062               p_cache_ext_tbl     => WSH_UTIL_CORE.G_STOP_IDS_STOP_IDS_EXT_CACHE,
1063               p_key               => l_entity_id,
1064               p_value             => l_entity_id,
1065               p_action            => 'PUT',
1066               x_return_status     => l_return_status
1067              );
1068 
1069 	  IF l_debug_on THEN
1070               WSH_DEBUG_SV.log(l_module_name,'l_return_status',l_return_status);
1071               WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_UTIL_CORE.API_POST_CALL',WSH_DEBUG_SV.C_PROC_LEVEL);
1072           END IF;
1073 
1074           wsh_util_core.api_post_call
1075               (
1076                 p_return_status => l_return_status,
1077                 x_num_warnings  => l_num_warnings,
1078                 x_num_errors    => l_num_errors
1079               );
1080 
1081         END IF; -- }
1082 
1083       END IF;
1084 
1085       -- Update the new W/V on the stop
1086       IF l_debug_on THEN
1087         WSH_DEBUG_SV.logmsg(l_module_name,'Updating '||p_entity_id||' with Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume);
1088         WSH_DEBUG_SV.logmsg(l_module_name,'l_frozen_flag '||l_frozen_flag||'p_stop_type '||p_stop_type);
1089       END IF;
1090       --R12 MDC
1091       --Included update for new wt/vol columns
1092       IF p_stop_type = 'DROPOFF' THEN
1093          update wsh_trip_stops
1094          set    last_update_date  = SYSDATE,
1095                 last_updated_by   = FND_GLOBAL.user_id,
1096                 last_update_login = FND_GLOBAL.login_id,
1097                 drop_off_weight = l_drop_off_weight,
1098                 drop_off_volume = l_drop_off_volume
1099          where  stop_id = p_entity_id;
1100 
1101       ELSIF l_frozen_flag = 'Y' AND p_stop_type = 'PICKUP' THEN
1102          update wsh_trip_stops
1103          set    last_update_date  = SYSDATE,
1104                 last_updated_by   = FND_GLOBAL.user_id,
1105                 last_update_login = FND_GLOBAL.login_id,
1106                 pick_up_weight = l_pick_up_weight,
1107                 pick_up_volume = l_pick_up_volume
1108          where  stop_id = p_entity_id;
1109       ELSIF NVL(l_frozen_flag, 'N') = 'N' THEN
1110          IF  p_stop_type = 'PICKUP' THEN
1111              update wsh_trip_stops
1112              set    departure_gross_weight = l_gross_weight,
1113                     departure_net_weight   = l_net_weight,
1114                     departure_volume       = l_volume,
1115                     departure_fill_percent = l_fill_percent,
1116                     last_update_date  = SYSDATE,
1117                     last_updated_by   = FND_GLOBAL.user_id,
1118                     last_update_login = FND_GLOBAL.login_id,
1119                     pick_up_weight = l_pick_up_weight,
1120                     pick_up_volume = l_pick_up_volume
1121              where  stop_id = p_entity_id;
1122          ELSE
1123              update wsh_trip_stops
1124              set    departure_gross_weight = l_gross_weight,
1125                     departure_net_weight   = l_net_weight,
1126                     departure_volume       = l_volume,
1127                     departure_fill_percent = l_fill_percent,
1128                     last_update_date  = SYSDATE,
1129                     last_updated_by   = FND_GLOBAL.user_id,
1130                     last_update_login = FND_GLOBAL.login_id
1131              where  stop_id = p_entity_id;
1132          END IF;
1133       END IF;
1134 
1135 
1136 
1137     -- For Delivery
1138     ELSIF (p_entity_type in ('DELIVERY')) THEN
1139 
1140       -- Get the orginal W/V info of the delivery
1141       BEGIN
1142         SELECT gross_weight,
1143                net_weight,
1144                volume,
1145                weight_uom_code,
1146                volume_uom_code,
1147                status_code,
1148                NVL(shipment_direction,'O'),
1149                NVL(wv_frozen_flag,'Y')
1150         INTO   l_gross_weight,
1151                l_net_weight,
1152                l_volume,
1153                l_wt_uom_code,
1154                l_vol_uom_code,
1155                l_status_code,
1156                l_shipment_direction,
1157                l_frozen_flag
1158         FROM   wsh_new_deliveries
1159         WHERE  delivery_id = p_entity_id
1160 	AND    NVL(wv_frozen_flag, 'Y') <> 'Y' -- BugFix 3570954
1161         FOR UPDATE NOWAIT;
1162       EXCEPTION
1163         WHEN NO_DATA_FOUND THEN
1164           IF l_debug_on THEN
1165 	    WSH_DEBUG_SV.logmsg(l_module_name, p_entity_type||' Id '||p_entity_id||'has wv_frozen_flag Y');
1166           END IF;
1167           l_frozen_flag := 'Y';
1168         WHEN record_locked THEN
1169           IF l_debug_on THEN
1170             WSH_DEBUG_SV.logmsg(l_module_name,'Error: '||p_entity_type||' Id '||p_entity_id||'could not be locked');
1171           END IF;
1172           raise e_abort;
1173       END;
1174 
1175       IF l_debug_on THEN
1176         WSH_DEBUG_SV.logmsg(l_module_name,p_entity_type||' has Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume||' Wt-Uom '||l_wt_uom_code||' Vol-Uom '||l_vol_uom_code||' Status '||l_status_code||' Frozen '||l_frozen_flag);
1177       END IF;
1178 
1179       IF (NVL(l_shipment_direction, ' ') in ('O','IO') AND NVL(l_status_code, ' ') IN ('IT','CL','SR')) OR l_frozen_flag = 'Y' THEN
1180         IF l_debug_on THEN
1181           WSH_DEBUG_SV.logmsg(l_module_name,'W/V propogation not allowed');
1182           WSH_DEBUG_SV.pop(l_module_name);
1183         END IF;
1184 
1185         return;
1186       END IF;
1187 
1188       -- If the W/V UOM on delivery and the input differ then convert the input W/V to the delivery UOMs
1189       IF (l_wt_uom_code <> p_wt_uom_code) THEN
1190         l_org_gross_wt := convert_uom(p_wt_uom_code, l_wt_uom_code, NVL(p_gross_weight,0), p_inv_item_id);
1191         l_org_net_wt   := convert_uom(p_wt_uom_code, l_wt_uom_code, NVL(p_net_weight,0), p_inv_item_id);
1192       ELSE
1193         l_org_gross_wt := p_gross_weight;
1194         l_org_net_wt   := p_net_weight;
1195       END IF;
1196 
1197       IF (l_vol_uom_code <> p_vol_uom_code) THEN
1198         l_org_vol := convert_uom(p_vol_uom_code, l_vol_uom_code, NVL(p_volume,0), p_inv_item_id);
1199       ELSE
1200         l_org_vol := p_volume;
1201       END IF;
1202 
1203       IF l_debug_on THEN
1204         WSH_DEBUG_SV.logmsg(l_module_name,'Parameter Values after UOM conversions are Gross '||l_org_gross_wt||' Net '||l_org_net_wt||' Vol '||l_org_vol);
1205       END IF;
1206 
1207       -- -- Sum up the input W/V and Delivery's original W/V
1208       IF NOT (l_gross_weight IS NULL and l_org_gross_wt IS NULL) THEN
1209         l_gross_weight := GREATEST(nvl(l_gross_weight,0) + nvl(l_org_gross_wt,0),0);
1210       END IF;
1211       IF NOT (l_net_weight IS NULL and l_org_net_wt IS NULL) THEN
1212         l_net_weight := GREATEST(nvl(l_net_weight,0) + nvl(l_org_net_wt,0),0);
1213       END IF;
1214       IF NOT (l_volume IS NULL and l_org_vol IS NULL) THEN
1215         l_volume := GREATEST(nvl(l_volume,0) + nvl(l_org_vol,0),0);
1216       END IF;
1217       IF l_debug_on THEN
1218         WSH_DEBUG_SV.logmsg(l_module_name,'Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume);
1219       END IF;
1220       IF (nvl(l_gross_weight,0) < nvl(l_net_weight,0)) THEN
1221         -- raise e_wt_mismatch;
1222         l_gross_weight := l_net_weight;
1223       END IF;
1224 
1225       -- Update the new W/V on the delivery
1226       IF l_debug_on THEN
1227         WSH_DEBUG_SV.logmsg(l_module_name,'Updating '||p_entity_id||' with Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume);
1228       END IF;
1229       update wsh_new_deliveries
1230       set    gross_weight = l_gross_weight,
1231              net_weight   = l_net_weight,
1232              volume       = l_volume,
1233              last_update_date  = SYSDATE,
1234              last_updated_by   = FND_GLOBAL.user_id,
1235              last_update_login = FND_GLOBAL.login_id
1236       where  delivery_id = p_entity_id;
1237 
1238       -- Call Adjust_parent_WV recursively to adjust W/V on parent stops, if any
1239       --
1240 
1241       FOR crec in trip_info LOOP
1242           IF l_debug_on THEN
1243             WSH_DEBUG_SV.logmsg(l_module_name,'Processing Trip '||crec.trip_id||' Pickup '||crec.pick_up_stop_id||' Drop off '||crec.drop_off_stop_id);
1244             WSH_DEBUG_SV.logmsg(l_module_name,'Processing Trip '||crec.trip_id|| 'parent_delivery_leg'||crec.parent_delivery_leg_id);
1245           END IF;
1246 
1247           IF (crec.parent_delivery_leg_id is not NULL) THEN
1248 
1249              -- MDC: This delivery is assigned to a parent. Update its parents wv
1250              -- The stop wv would get updated when the parent wv gets updated.
1251              -- If p_entity_type = 'DELIVERY_NO_RECURSE' this delivery is assigned to a
1252              -- parent LPN and Delivery. Parent delivery and trip/stops will get updated
1253              -- when the parent LPN's weight volume gets updated.
1254 
1255              IF l_debug_on THEN
1256               WSH_DEBUG_SV.logmsg(l_module_name,'Parent Delivery Leg '||crec.parent_delivery_leg_id);
1257              END IF;
1258              OPEN c_consol_delivery(crec.parent_delivery_leg_id);
1259              FETCH c_consol_delivery INTO l_parent_delivery_id;
1260              CLOSE c_consol_delivery;
1261 
1262              IF l_debug_on THEN
1263                 WSH_DEBUG_SV.logmsg(l_module_name,'Parent Delivery '||l_parent_delivery_id);
1264              END IF;
1265 
1266              Adjust_parent_WV(
1267                p_entity_type   => 'DELIVERY',
1268                p_entity_id     => l_parent_delivery_id,
1269                p_gross_weight  => p_gross_weight,
1270                p_net_weight    => p_net_weight,
1271                p_volume        => p_volume,
1272                p_wt_uom_code   => p_wt_uom_code,
1273                p_vol_uom_code  => p_vol_uom_code,
1274                p_inv_item_id   => NULL,
1275                x_return_status => l_return_status);
1276 
1277               IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1278                 IF l_debug_on THEN
1279                   WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV has returned Error for delivery '||l_parent_delivery_id);
1280                 END IF;
1281                 raise e_abort;
1282               END IF;
1283 
1284           ELSE
1285           -- Update the stop wt/vol
1286 
1287             FOR crec1 in c_stops(crec.trip_id, crec.pick_up_stop_id, crec.drop_off_stop_id) LOOP
1288               IF l_debug_on THEN
1289                 WSH_DEBUG_SV.logmsg(l_module_name,'Processing Stop '||crec1.stop_id);
1290                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Adjust_parent_WV',WSH_DEBUG_SV.C_PROC_LEVEL);
1291               END IF;
1292 
1293               Adjust_parent_WV(
1294                 p_entity_type   => 'STOP',
1295                 p_entity_id     => crec1.stop_id,
1296                 p_gross_weight  => p_gross_weight,
1297                 p_net_weight    => p_net_weight,
1298                 p_volume        => p_volume,
1299                 p_wt_uom_code   => p_wt_uom_code,
1300                 p_vol_uom_code  => p_vol_uom_code,
1301                 p_inv_item_id   => null,
1302                 x_return_status => l_return_status);
1303 
1304               IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1305                 IF l_debug_on THEN
1306                   WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV has returned Error for Stop '||crec1.stop_id);
1307                 END IF;
1308                 raise e_abort;
1309               END IF;
1310             END LOOP;
1311 
1312           END IF;
1313       END LOOP;
1314       --END IF; -- p_entity_type
1315 
1316     -- For Container or Delivery Detail
1317     ELSIF (p_entity_type IN ('CONTAINER', 'DETAIL'))THEN
1318 
1319       -- Get the orginal W/V info
1320       BEGIN
1321         SELECT gross_weight,
1322                net_weight,
1323                volume,
1324                filled_volume,
1325                parent_delivery_detail_id,
1326                delivery_id,
1327                wdd.weight_uom_code,
1328                wdd.volume_uom_code,
1329                wdd.inventory_item_id,
1330                wdd.container_flag,
1331                wdd.organization_id,
1332                nvl(wdd.wv_frozen_flag,'Y'),
1333                NVL(wda.type, 'S'),
1334                wdd.line_direction
1335         INTO   l_gross_weight,
1336                l_net_weight,
1337                l_volume,
1338                l_filled_volume,
1339                l_container_id,
1340                l_delivery_id,
1341                l_wt_uom_code,
1342                l_vol_uom_code,
1343                l_inv_item_id,
1344                --lpn conv
1345                l_container_flag,
1346                l_organization_id,
1347                l_frozen_flag,
1348                -- MDC
1349                l_wda_type,
1350                l_line_direction
1351         FROM   wsh_delivery_details wdd,
1352                wsh_delivery_assignments wda
1353         WHERE  wdd.delivery_detail_id = p_entity_id
1354         AND    wdd.delivery_detail_id = wda.delivery_detail_id
1355         AND    NVL(wda.type, 'S') in ('S', 'C')
1356         FOR UPDATE NOWAIT;
1357       EXCEPTION
1358         WHEN NO_DATA_FOUND THEN
1359           IF l_debug_on THEN
1360             WSH_DEBUG_SV.logmsg(l_module_name,'Error: '||p_entity_type||' Id '||p_entity_id||'doesn not exist');
1361           END IF;
1362           raise e_abort;
1363         WHEN record_locked THEN
1364           IF l_debug_on THEN
1365             WSH_DEBUG_SV.logmsg(l_module_name,'Error: '||p_entity_type||' Id '||p_entity_id||'could not be locked');
1366           END IF;
1367           raise e_abort;
1368       END;
1369 
1370       --lpn conv
1371       IF l_container_flag IN ('Y', 'C')  THEN
1372          l_wms_org := wsh_util_validate.check_wms_org(l_organization_id);
1373          IF l_wms_org = 'Y'  THEN
1374             l_frozen_flag := 'N';
1375          END IF;
1376       END IF;
1377 
1378 
1379       IF l_debug_on THEN
1380         WSH_DEBUG_SV.logmsg(l_module_name,p_entity_type||' has Gross '||l_gross_weight||' Net '||l_net_weight||' Vol '||l_volume||' Fill-Vol '||l_filled_volume||' Wt-Uom '||l_wt_uom_code||' Vol-Uom '||l_vol_uom_code||' Frozen '||l_frozen_flag);
1381       END IF;
1382 
1383       IF l_frozen_flag = 'Y' THEN
1384         IF l_debug_on THEN
1385           WSH_DEBUG_SV.logmsg(l_module_name,'W/V propogation not allowed');
1386           WSH_DEBUG_SV.pop(l_module_name);
1387         END IF;
1388         return;
1389       END IF;
1390 
1391       -- If the W/V UOM on DD and the input differ then convert the input W/V to the DD UOMs
1392       IF (l_wt_uom_code <> p_wt_uom_code) THEN
1393         l_org_gross_wt := convert_uom(p_wt_uom_code, l_wt_uom_code, NVL(p_gross_weight,0), p_inv_item_id);
1394         l_org_net_wt   := convert_uom(p_wt_uom_code, l_wt_uom_code, NVL(p_net_weight,0), p_inv_item_id);
1395       ELSE
1396         l_org_gross_wt := p_gross_weight;
1397         l_org_net_wt   := p_net_weight;
1398       END IF;
1399 
1400       IF (l_vol_uom_code <> p_vol_uom_code) THEN
1401         l_org_vol := convert_uom(p_vol_uom_code, l_vol_uom_code, NVL(p_volume,0), p_inv_item_id);
1402         l_org_fill_vol := convert_uom(p_vol_uom_code, l_vol_uom_code, NVL(p_filled_volume,0), p_inv_item_id);
1403       ELSE
1404         l_org_vol := p_volume;
1405         l_org_fill_vol := p_filled_volume;
1406       END IF;
1407 
1408       IF l_debug_on THEN
1409         WSH_DEBUG_SV.logmsg(l_module_name,'Parameter Values after UOM conversions are Gross '||l_org_gross_wt||' Net '||l_org_net_wt||' Vol '||l_org_vol);
1410       END IF;
1411 
1412        -- Sum up the input W/V and DD's original W/V
1413       IF NOT (l_gross_weight IS NULL and l_org_gross_wt IS NULL) THEN
1414         l_gross_weight := GREATEST(nvl(l_gross_weight,0) + nvl(l_org_gross_wt,0),0);
1415       END IF;
1416       IF NOT (l_net_weight IS NULL and l_org_net_wt IS NULL) THEN
1417         l_net_weight := GREATEST(nvl(l_net_weight,0) + nvl(l_org_net_wt,0),0);
1418         IF l_net_weight = 0 THEN
1419           l_net_weight := NULL;
1420         END IF;
1421       END IF;
1422       IF NOT (l_filled_volume IS NULL and l_org_fill_vol IS NULL) THEN
1423         l_filled_volume := GREATEST(nvl(l_filled_volume,0) + nvl(l_org_fill_vol,0),0);
1424       END IF;
1425       IF NOT (l_volume IS NULL and l_org_vol IS NULL) THEN
1426         l_volume := GREATEST(nvl(l_volume,0) + nvl(l_org_vol,0),0);
1427       END IF;
1428       IF (nvl(l_gross_weight,0) < nvl(l_net_weight,0)) THEN
1429         -- raise e_wt_mismatch;
1430         l_gross_weight := l_net_weight;
1431       END IF;
1432 
1433       -- Call update_container_wt_vol to update new W/V on container
1434       IF l_debug_on THEN
1435         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit UPDATE_CONTAINER_WT_VOL',WSH_DEBUG_SV.C_PROC_LEVEL);
1436       END IF;
1437       update_container_wt_vol(
1438         p_container_instance_id =>   p_entity_id,
1439         p_gross_weight  => l_gross_weight,
1440         p_net_weight    => l_net_weight,
1441         p_volume        => l_volume,
1442         p_filled_volume => l_filled_volume,
1443         p_fill_pc_flag  => 'Y',
1444         x_cont_fill_pc  => l_cont_fill_pc,
1445         x_return_status => l_return_status);
1446 
1447       IF l_return_status NOT IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS, WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
1448           RAISE e_wt_vol_fail;
1449       ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
1450         l_num_warnings := l_num_warnings + 1;
1451       END IF;
1452 
1453       -- Call Adjust_parent_WV recursively to adjust W/V on parent container/delivery, if any
1454       IF ((l_container_id IS NOT NULL)) THEN
1455     --lpn conv
1456 
1457         IF l_debug_on THEN
1458           WSH_DEBUG_SV.log(l_module_name,'l_wms_org',l_wms_org);
1459         END IF;
1460         IF l_wms_org = 'Y' THEN --{
1461 
1462            IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
1463             AND l_line_direction IN ('O', 'IO') THEN
1464 
1465               IF ( WSH_WMS_LPN_GRP.GK_WMS_UPD_WV) THEN --{
1466                  WSH_WMS_LPN_GRP.g_update_to_containers := 'Y';
1467               END IF; --}
1468            END IF;
1469 
1470         ELSE --}{
1471            IF l_debug_on THEN
1472              WSH_DEBUG_SV.logmsg(l_module_name,p_entity_type||' '||p_entity_id||' has parent container '||l_container_id);
1473              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Adjust_parent_WV',WSH_DEBUG_SV.C_PROC_LEVEL);
1474            END IF;
1475 
1476            Adjust_parent_WV(
1477              p_entity_type   => 'CONTAINER',
1478              p_entity_id     => l_container_id,
1479              p_gross_weight  => p_gross_weight,
1480              p_net_weight    => p_net_weight,
1481              p_volume        => p_volume,
1482              p_filled_volume => p_filled_volume,
1483              p_wt_uom_code   => p_wt_uom_code,
1484              p_vol_uom_code  => p_vol_uom_code,
1485              p_inv_item_id   => l_inv_item_id,
1486              x_return_status => l_return_status);
1487 
1488            IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1489              IF l_debug_on THEN
1490                WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV has returned Error for Container '||l_container_id);
1491              END IF;
1492              raise e_abort;
1493            END IF;
1494          END IF; --}
1495 
1496          -- R12: MDC we need to make sure that the child deliveries get updated as well
1497          IF l_wda_type = 'C' THEN
1498             g_consol_lpn := l_container_id;
1499 
1500             Adjust_parent_WV(
1501              p_entity_type   => 'DELIVERY',
1502              p_entity_id     => l_delivery_id,
1503              p_gross_weight  => p_gross_weight,
1504              p_net_weight    => p_net_weight,
1505              p_volume        => p_volume,
1506              p_wt_uom_code   => p_wt_uom_code,
1507              p_vol_uom_code  => p_vol_uom_code,
1508              p_inv_item_id   => l_inv_item_id,
1509              x_return_status => l_return_status);
1510            IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1511              IF l_debug_on THEN
1512                WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV has returned Error for Delivery '||l_delivery_id);
1513              END IF;
1514              raise e_abort;
1515            END IF;
1516 
1517          END IF;
1518 
1519 
1520       ELSIF (l_delivery_id IS NOT NULL) AND (l_container_flag <> 'C') THEN
1521         -- MDC: Do not propagate wt/vol to the consol delivery through the
1522         -- consol LPN since the wt/vols to the consol delivery will be propagated
1523         -- through the child delivery.
1524 
1525         IF l_debug_on THEN
1526           WSH_DEBUG_SV.logmsg(l_module_name,p_entity_type||' '||p_entity_id||' is in delivery '||l_delivery_id);
1527           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Adjust_parent_WV',WSH_DEBUG_SV.C_PROC_LEVEL);
1528         END IF;
1529 
1530 
1531         Adjust_parent_WV(
1532              p_entity_type   => 'DELIVERY',
1533              p_entity_id     => l_delivery_id,
1534              p_gross_weight  => p_gross_weight,
1535              p_net_weight    => p_net_weight,
1536              p_volume        => p_volume,
1537              p_wt_uom_code   => p_wt_uom_code,
1538              p_vol_uom_code  => p_vol_uom_code,
1539              p_inv_item_id   => l_inv_item_id,
1540              x_return_status => l_return_status);
1541         IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1542            IF l_debug_on THEN
1543              WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV has returned Error for Delivery '||l_delivery_id);
1544            END IF;
1545            raise e_abort;
1546         END IF;
1547 
1548       END IF;
1549     END IF;
1550   --END IF;
1551   IF l_num_warnings > 0 THEN
1552      x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
1553   END IF;
1554   IF l_debug_on THEN
1555     WSH_DEBUG_SV.log(l_module_name,'x_return_status '||x_return_status);
1556     WSH_DEBUG_SV.pop(l_module_name);
1557   END IF;
1558 
1559 EXCEPTION
1560   WHEN  e_wt_vol_fail THEN
1561     FND_MESSAGE.Set_Name('WSH','WSH_UPDATE_WTVOL_FAIL');
1562     FND_MESSAGE.Set_Token('LPN', p_entity_id);
1563     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1564     WSH_UTIL_CORE.add_message (x_return_status);
1565    IF l_debug_on THEN
1566        WSH_DEBUG_SV.logmsg(l_module_name,'E_WT_VOL_FAIL exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
1567        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:E_WT_VOL_FAIL');
1568    END IF;
1569 
1570   WHEN e_abort THEN
1571     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1572     IF l_debug_on THEN
1573       WSH_DEBUG_SV.pop(l_module_name);
1574     END IF;
1575 
1576   WHEN e_wt_mismatch THEN
1577     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1578 
1579     IF l_debug_on THEN
1580       WSH_DEBUG_SV.logmsg(l_module_name,'Error: Adjusted Net Weight is greater than Adjusted Gross Weight');
1581       WSH_DEBUG_SV.pop(l_module_name);
1582     END IF;
1583 
1584   WHEN lock_detected THEN -- BugFix 3570954
1585       FND_MESSAGE.SET_NAME('WSH','WSH_NO_LOCK');
1586       x_return_status := WSH_UTIL_CORE.g_ret_sts_error;
1587       wsh_util_core.add_message(WSH_UTIL_CORE.g_ret_sts_error,l_module_name);
1588 
1589       IF l_debug_on THEN
1590          WSH_DEBUG_SV.log(l_module_name,'Cannot lock delivery for update',l_delivery_id);
1591       END IF;
1592 
1593  WHEN Others THEN
1594     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.Adjust_parent_WV');
1595     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1596 
1597     IF l_debug_on THEN
1598       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1599       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
1600     END IF;
1601 End Adjust_parent_WV;
1602 
1603 -- J: W/V Changes
1604 
1605 -- Start of comments
1606 -- API name : DD_WV_Post_Process
1607 -- Type     : Public
1608 -- Pre-reqs : None.
1609 -- Function : API to do post processing(Log exceptions in manual mode and
1610 --            adjust W/V on parents in automatic mode)  for a delivery detail or container
1611 -- Parameters :
1612 -- IN:
1613 --    p_delivery_detail_id IN NUMBER Required
1614 --    p_diff_gross_wt      IN NUMBER
1615 --      Gross Wt that needs to be adjusted on parent entities
1616 --    p_diff_net_wt        IN NUMBER
1617 --      Net Wt that needs to be adjusted on parent entities
1618 --    p_diff_volume        IN NUMBER
1619 --      Volume that needs to be adjusted on parent entities
1620 --    p_diff_fill_volume   IN NUMBER
1621 --      Filled Volume that needs to be adjusted on parent entities
1622 --    p_check_for_empty    IN VARCHAR2
1623 --      Check if the parent of p_delivery_detail_id becomes empty
1624 --      without p_delivery_detail_id
1625 -- OUT:
1626 --    x_return_status OUT VARCHAR2 Required
1627 --       give the return status of API
1628 -- Version : 1.0
1629 -- End of comments
1630 
1631 PROCEDURE DD_WV_Post_Process(
1632             p_delivery_detail_id    IN NUMBER,
1633             p_diff_gross_wt         IN NUMBER,
1634             p_diff_net_wt           IN NUMBER,
1635             p_diff_volume           IN NUMBER   DEFAULT null,
1636             p_diff_fill_volume      IN NUMBER   DEFAULT null,
1637             p_check_for_empty       IN VARCHAR2 DEFAULT 'N',
1638             x_return_status         OUT NOCOPY VARCHAR2) IS
1639 
1640   CURSOR C1 IS
1641   SELECT wda.parent_delivery_detail_id,
1642          wda.delivery_id,
1643          wdd.organization_id,
1644          wdd.container_flag,
1645          wdd.weight_uom_code,
1646          wdd.volume_uom_code,
1647          wdd.inventory_item_id,
1648 --lpn conv
1649          wdd.line_direction,
1650 -- MDC
1651          NVL(wda.type, 'S')
1652   FROM   wsh_delivery_assignments wda,
1653          wsh_delivery_details wdd
1654   WHERE  wdd.delivery_detail_id = p_delivery_detail_id
1655   AND    NVL(wda.type, 'S') in ('S', 'C')
1656   AND    wdd.delivery_detail_id = wda.delivery_detail_id;
1657 
1658   CURSOR C2(c_container_id IN NUMBER) IS
1659   SELECT wda.delivery_detail_id
1660   FROM   wsh_delivery_assignments_v wda
1661   WHERE  wda.parent_delivery_detail_id = c_container_id
1662   AND    wda.delivery_detail_id <> p_delivery_detail_id;
1663 
1664   CURSOR C3(c_delivery_id IN NUMBER) IS
1665   SELECT wda.delivery_detail_id
1666   FROM   wsh_delivery_assignments_v wda
1667   WHERE  wda.delivery_id = c_delivery_id
1668   AND    wda.delivery_detail_id <> p_delivery_detail_id;
1669 
1670   CURSOR C4(c_container_id IN NUMBER) IS
1671   SELECT unit_weight,
1672          unit_volume,
1673          gross_weight,
1674          net_weight,
1675          volume,
1676          filled_volume
1677   FROM   wsh_delivery_details
1678   WHERE  delivery_detail_id = c_container_id;
1679 
1680   CURSOR C5(c_delivery_id IN NUMBER) IS
1681   SELECT gross_weight,
1682          net_weight,
1683          volume
1684   FROM   wsh_new_deliveries
1685   WHERE  delivery_id = c_delivery_id
1686   FOR UPDATE NOWAIT; --BugFix 3570954;
1687 
1688   -- BugFix 3570954
1689   -- Added lock_detected exception
1690   lock_detected	EXCEPTION;
1691   PRAGMA EXCEPTION_INIT( lock_detected, -00054);
1692 
1693   l_parent_container_id       NUMBER;
1694   l_delivery_id               NUMBER;
1695   l_organization_id           NUMBER;
1696   l_container_flag            VARCHAR2(1);
1697   l_wt_uom_code               VARCHAR2(3);
1698   l_vol_uom_code              VARCHAR2(3);
1699   l_inv_item_id               number;
1700   -- MDC
1701   l_wda_type                  VARCHAR2(30);
1702 
1703   l_return_status             VARCHAR2(100);
1704 
1705   l_cont_empty                BOOLEAN;
1706   l_del_empty                 BOOLEAN;
1707   l_tmp_unit_wt               NUMBER;
1708   l_tmp_unit_vol              NUMBER;
1709   l_tmp_gross_wt              NUMBER;
1710   l_tmp_net_wt                NUMBER;
1711   l_tmp_vol                   NUMBER;
1712   l_tmp_fill_vol              NUMBER;
1713   l_tmp_fill_pc               NUMBER;
1714   l_dummy_id                  NUMBER;
1715   l_detail_count              NUMBER;
1716   l_debug_on                  BOOLEAN;
1717   l_module_name CONSTANT      VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DD_WV_POST_PROCESS';
1718 
1719   l_num_warnings          number := 0;
1720   l_num_errors            number := 0;
1721   l_update_wms_org            varchar2(10) := 'N';
1722   l_line_direction        varchar2(10) ;
1723   l_cont_fill_pc          NUMBER;
1724   l_item_id               NUMBER;
1725 
1726   cursor  c_get_item_id (v_delivery_detail_id number) IS
1727   SELECT inventory_item_id
1728   FROM wsh_delivery_details
1729   WHERE delivery_detail_id = v_delivery_detail_id;
1730 
1731   e_abort                     exception;
1732 
1733 
1734 BEGIN
1735 
1736   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
1737   IF l_debug_on IS NULL THEN
1738     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
1739   END IF;
1740 
1741   IF l_debug_on THEN
1742     WSH_DEBUG_SV.push(l_module_name);
1743     WSH_DEBUG_SV.log(l_module_name,'p_delivery_detail_id',p_delivery_detail_id);
1744     WSH_DEBUG_SV.log(l_module_name,'p_diff_gross_wt',p_diff_gross_wt);
1745     WSH_DEBUG_SV.log(l_module_name,'p_diff_net_wt',p_diff_net_wt);
1746     WSH_DEBUG_SV.log(l_module_name,'p_diff_volume',p_diff_volume);
1747     WSH_DEBUG_SV.log(l_module_name,'p_diff_fill_volume',p_diff_fill_volume);
1748     WSH_DEBUG_SV.log(l_module_name,'p_check_for_empty',p_check_for_empty);
1749   END IF;
1750   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1751 
1752   -- Get the delivery detail information
1753   OPEN  C1;
1754   FETCH C1
1755   INTO  l_parent_container_id,
1756         l_delivery_id,
1757         l_organization_id,
1758         l_container_flag,
1759         l_wt_uom_code,
1760         l_vol_uom_code,
1761         l_inv_item_id,
1762         l_line_direction,
1763         l_wda_type;
1764   IF C1%NOTFOUND THEN
1765     CLOSE C1;
1766     RETURN;
1767   END IF;
1768   CLOSE C1;
1769 
1770   -- For Container
1771   IF ((l_parent_container_id IS NOT NULL)) THEN
1772     IF l_debug_on THEN
1773       WSH_DEBUG_SV.logmsg(l_module_name,'The parent container id is '||l_parent_container_id);
1774     END IF;
1775 
1776     --lpn conv
1777     IF l_container_flag IN ('Y', 'C') AND l_line_direction IN ('O', 'IO')  THEN
1778        l_update_wms_org := wsh_util_validate.Check_Wms_Org(l_organization_id);
1779     END IF;
1780 
1781     OPEN c_get_item_id(l_parent_container_id);
1782     FETCH c_get_item_id INTO l_item_id;
1783     CLOSE c_get_item_id;
1784 
1785     IF l_debug_on THEN
1786       WSH_DEBUG_SV.log(l_module_name,'l_item_id',l_item_id);
1787     END IF;
1788 
1789     IF c_wms_code_present = 'Y'
1790      AND  l_update_wms_org = 'Y' THEN --{
1791         IF l_item_id IS NOT NULL THEN --{
1792            WSH_TPA_CONTAINER_PKG.Calc_Cont_Fill_Pc (
1793                  p_container_instance_id =>
1794                                    l_parent_container_id,
1795                  p_update_flag           => 'Y',
1796                  p_fill_pc_basis         => NULL,
1797                  x_fill_percent          => l_cont_fill_pc,
1798                  x_return_status         => l_return_status
1799            );
1800            wsh_util_core.api_post_call
1801            (
1802              p_return_status => l_return_status,
1803              x_num_warnings  => l_num_warnings,
1804              x_num_errors    => l_num_errors
1805            );
1806        END IF; --}
1807     ELSE --}{
1808 
1809        -- Check if container becomes empty without delivery detail
1810        l_cont_empty := FALSE;
1811        IF p_check_for_empty = 'Y' THEN
1812          OPEN  C2(l_parent_container_id);
1813          FETCH C2 INTO l_dummy_id;
1814          IF C2%NOTFOUND THEN
1815            IF l_debug_on THEN
1816              WSH_DEBUG_SV.logmsg(l_module_name,'Container will become empty without this dd');
1817            END IF;
1818            l_cont_empty := TRUE;
1819          END IF;
1820          CLOSE C2;
1821        END IF;
1822 
1823        -- If container becomes empty then
1824        --   reset the W/V on container to unit w/v and call DD_WV_POST_PROCESS API for the container
1825        -- else
1826        --   call adjust_parent_wv for the delivery detail
1827        IF l_cont_empty THEN
1828          OPEN  C4(l_parent_container_id);
1829          FETCH C4
1830          INTO  l_tmp_unit_wt,
1831                l_tmp_unit_vol,
1832                l_tmp_gross_wt,
1833                l_tmp_net_wt,
1834                l_tmp_vol,
1835                l_tmp_fill_vol;
1836          CLOSE C4;
1837 
1838          IF l_debug_on THEN
1839            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Update_Container_Wt_Vol',WSH_DEBUG_SV.C_PROC_LEVEL);
1840          END IF;
1841          WSH_WV_UTILS.update_container_wt_vol(
1842            p_container_instance_id => l_parent_container_id,
1843            p_gross_weight  => l_tmp_unit_wt,
1844            p_net_weight    => null,
1845            p_volume        => l_tmp_unit_vol,
1846            p_filled_volume => null,
1847            p_fill_pc_flag  => 'Y',
1848            x_cont_fill_pc  => l_tmp_fill_pc,
1849            x_return_status => l_return_status);
1850          IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1851            x_return_status := l_return_status;
1852            IF l_debug_on THEN
1853              WSH_DEBUG_SV.pop(l_module_name);
1854            END IF;
1855            RETURN;
1856          ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
1857            l_num_warnings := l_num_warnings + 1;
1858          END IF;
1859 
1860          IF l_debug_on THEN
1861            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.DD_WV_Post_Process',WSH_DEBUG_SV.C_PROC_LEVEL);
1862          END IF;
1863 
1864          DD_WV_Post_Process(
1865                p_delivery_detail_id => l_parent_container_id,
1866                p_diff_gross_wt      => NVL(l_tmp_unit_wt,0) - NVL(l_tmp_gross_wt,0),
1867                p_diff_net_wt        => -1 * NVL(l_tmp_net_wt,0),
1868                p_diff_volume        => NVL(l_tmp_unit_vol,0) - NVL(l_tmp_vol,0),
1869                p_diff_fill_volume   => NVL(l_tmp_unit_vol,0) - NVL(l_tmp_vol,0),
1870                x_return_status      => l_return_status);
1871 
1872        ELSE -- NOT l_cont_empty
1873          -- Call Adjust_parent_WV to adjust W/V
1874          IF l_debug_on THEN
1875            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.Adjust_parent_WV',WSH_DEBUG_SV.C_PROC_LEVEL);
1876          END IF;
1877          Adjust_parent_WV(
1878            p_entity_type   => 'CONTAINER',
1879            p_entity_id     => l_parent_container_id,
1880            p_gross_weight  => p_diff_gross_wt,
1881            p_net_weight    => p_diff_net_wt,
1882            p_filled_volume => p_diff_fill_volume,
1883            p_wt_uom_code   => l_wt_uom_code,
1884            p_vol_uom_code  => l_vol_uom_code,
1885            p_inv_item_id   => l_inv_item_id,
1886            x_return_status => l_return_status);
1887        END IF;
1888 
1889 
1890        IF l_wda_type = 'C' THEN
1891        -- R12: MDC: if this detail is assigned to a consol LPN, then
1892        -- we need to update the child deliveries...
1893 
1894        Adjust_parent_WV(
1895           p_entity_type   => 'DELIVERY',
1896           p_entity_id     => l_delivery_id,
1897           p_gross_weight  => p_diff_gross_wt,
1898           p_net_weight    => p_diff_net_wt,
1899           p_volume        => p_diff_volume,
1900           p_wt_uom_code   => l_wt_uom_code,
1901           p_vol_uom_code  => l_vol_uom_code,
1902           p_inv_item_id   => l_inv_item_id,
1903           x_return_status => l_return_status);
1904 
1905 
1906        END IF;
1907 
1908      END IF; --}
1909   -- For Delivery
1910   ELSIF (l_delivery_id IS NOT NULL) THEN
1911     IF l_debug_on THEN
1912       WSH_DEBUG_SV.log(l_module_name,'The Delivery id is '||l_delivery_id);
1913     END IF;
1914 
1915     -- Check if delivery becomes empty without delivery detail
1916     l_del_empty := FALSE;
1917     IF p_check_for_empty = 'Y' THEN
1918       OPEN  C3(l_delivery_id);
1919       FETCH C3 INTO l_dummy_id;
1920       IF C3%NOTFOUND THEN
1921         IF l_debug_on THEN
1922           WSH_DEBUG_SV.logmsg(l_module_name,'Delivery will become empty without this dd');
1923         END IF;
1924         l_del_empty := TRUE;
1925       END IF;
1926       CLOSE C3;
1927     END IF;
1928 
1929     -- If delivery becomes empty then
1930     --   reset the W/V on delivery to null and call Del_WV_POST_PROCESS API for the delivery
1931     -- else
1932     --   call adjust_parent_wv for the delivery detail
1933     IF l_del_empty THEN
1934       OPEN  C5(l_delivery_id);
1935       FETCH C5
1936       INTO  l_tmp_gross_wt,
1937             l_tmp_net_wt,
1938             l_tmp_vol;
1939 
1940       UPDATE wsh_new_deliveries
1941       SET    gross_weight = null,
1942              net_weight   = null,
1943              volume       = null,
1944              wv_frozen_flag = 'N',
1945              last_update_date  = SYSDATE,
1946              last_updated_by   = FND_GLOBAL.user_id,
1947              last_update_login = FND_GLOBAL.login_id
1948       WHERE  delivery_id = l_delivery_id;
1949 
1950       CLOSE C5;
1951 
1952       IF l_debug_on THEN
1953         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.Del_WV_Post_Process',WSH_DEBUG_SV.C_PROC_LEVEL);
1954       END IF;
1955 
1956       Del_WV_Post_Process(
1957             p_delivery_id   => l_delivery_id,
1958             p_diff_gross_wt => -1 * l_tmp_gross_wt,
1959             p_diff_net_wt   => -1 * l_tmp_net_wt,
1960             p_diff_volume   => -1 * l_tmp_vol,
1961             x_return_status => l_return_status);
1962 
1963       ELSE -- NOT l_del_empty
1964 
1965       -- Call Adjust_parent_WV to adjust W/V
1966       IF l_debug_on THEN
1967         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.Adjust_parent_WV',WSH_DEBUG_SV.C_PROC_LEVEL);
1968       END IF;
1969       IF (l_container_flag = 'Y') OR ((l_container_flag = 'C')
1970       AND (NVL(g_consol_lpn, 0) <> p_delivery_detail_id)) THEN
1971         Adjust_parent_WV(
1972           p_entity_type   => 'DELIVERY',
1973           p_entity_id     => l_delivery_id,
1974           p_gross_weight  => p_diff_gross_wt,
1975           p_net_weight    => p_diff_net_wt,
1976           p_volume        => p_diff_volume,
1977           p_wt_uom_code   => l_wt_uom_code,
1978           p_vol_uom_code  => l_vol_uom_code,
1979           p_inv_item_id   => l_inv_item_id,
1980           x_return_status => l_return_status);
1981       ELSIF l_container_flag = 'N' THEN
1982         Adjust_parent_WV(
1983           p_entity_type   => 'DELIVERY',
1984           p_entity_id     => l_delivery_id,
1985           p_gross_weight  => p_diff_gross_wt,
1986           p_net_weight    => p_diff_net_wt,
1987           p_volume        => p_diff_fill_volume,
1988           p_wt_uom_code   => l_wt_uom_code,
1989           p_vol_uom_code  => l_vol_uom_code,
1990           p_inv_item_id   => l_inv_item_id,
1991           x_return_status => l_return_status);
1992       END IF;
1993       g_consol_lpn := NULL;
1994 
1995     END IF;
1996   END IF;
1997   IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1998      IF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
1999         x_return_status := l_return_status;
2000      ELSE
2001         x_return_status := l_return_status;
2002         IF l_debug_on THEN
2003            WSH_DEBUG_SV.logmsg(l_module_name,'API returned '||l_return_status);
2004         END IF;
2005         raise e_abort;
2006      END IF;
2007   END IF;
2008 
2009   IF l_num_warnings > 0 THEN
2010      x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
2011   END IF;
2012 
2013   IF l_debug_on THEN
2014     WSH_DEBUG_SV.logmsg(l_module_name,'x_return_status '||x_return_status);
2015     WSH_DEBUG_SV.pop(l_module_name);
2016   END IF;
2017 
2018 EXCEPTION
2019 
2020    WHEN lock_detected THEN -- BugFix 3570954
2021       FND_MESSAGE.SET_NAME('WSH','WSH_NO_LOCK');
2022       x_return_status := WSH_UTIL_CORE.g_ret_sts_error;
2023       wsh_util_core.add_message(WSH_UTIL_CORE.g_ret_sts_error,l_module_name);
2024 
2025       IF l_debug_on THEN
2026          WSH_DEBUG_SV.log(l_module_name,'Cannot lock delivery for update',l_delivery_id);
2027       END IF;
2028 
2029   WHEN e_abort THEN
2030    x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2031    IF l_debug_on THEN
2032      WSH_DEBUG_SV.pop(l_module_name);
2033    END IF;
2034 
2035   WHEN Others THEN
2036     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.DD_WV_POST_PROCESS');
2037     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2038 
2039     IF l_debug_on THEN
2040       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2041       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2042     END IF;
2043 
2044 END DD_WV_Post_Process;
2045 
2046 -- Start of comments
2047 -- API name : Del_WV_Post_Process
2048 -- Type     : Public
2049 -- Pre-reqs : None.
2050 -- Function : API to do post processing (adjust W/V on parents) for a delivery
2051 -- Parameters :
2052 -- IN:
2053 --    p_delivery_id IN NUMBER Required
2054 --    p_diff_gross_wt      IN NUMBER
2055 --      Gross Wt that needs to be adjusted on parent entities
2056 --    p_diff_net_wt        IN NUMBER
2057 --      Net Wt that needs to be adjusted on parent entities
2058 --    p_diff_volume        IN NUMBER
2059 --      Volume that needs to be adjusted on parent entities
2060 --    p_check_for_empty    IN VARCHAR2
2061 --      Check if the parent of p_delivery_id becomes empty
2062 --      without p_delivery_id
2063 --    p_leg_id IN VARCHAR2
2064 --      Do Post Processing only for the specified delivery/delivery leg
2065 -- OUT:
2066 --    x_return_status OUT VARCHAR2 Required
2067 --       give the return status of API
2068 -- Version : 1.0
2069 -- End of comments
2070 
2071 PROCEDURE Del_WV_Post_Process(
2072             p_delivery_id     IN NUMBER,
2073             p_diff_gross_wt   IN NUMBER,
2074             p_diff_net_wt     IN NUMBER,
2075             p_diff_volume     IN NUMBER,
2076             p_check_for_empty IN VARCHAR2 DEFAULT 'N',
2077             p_leg_id          IN NUMBER DEFAULT NULL,
2078             x_return_status   OUT NOCOPY VARCHAR2) IS
2079 
2080   CURSOR c_stops(c_trip_id IN NUMBER, c_pkup_stop_id IN NUMBER, c_dpoff_stop_id IN NUMBER) IS
2081   SELECT wts.stop_id,
2082          wts.departure_gross_weight,
2083          wts.departure_net_weight,
2084          wts.departure_volume
2085   FROM   wsh_trip_stops wts
2086   WHERE  wts.trip_id = c_trip_id
2087   AND    wts.stop_sequence_number <= (
2088            select wts1.stop_sequence_number
2089            from   wsh_trip_stops wts1
2090            where  wts1.stop_id = c_dpoff_stop_id)
2091   AND    wts.stop_sequence_number >= (
2092            select wts2.stop_sequence_number
2093            from   wsh_trip_stops wts2
2094            where  wts2.stop_id = c_pkup_stop_id)
2095   FOR    UPDATE NOWAIT
2096   ORDER  BY wts.stop_id, wts.planned_departure_date ASC;
2097 
2098   -- BugFix 3570954
2099   -- Added lock_detected exception
2100   lock_detected	EXCEPTION;
2101   PRAGMA EXCEPTION_INIT( lock_detected, -00054);
2102 
2103   CURSOR trip_info IS
2104   SELECT wts.trip_id,
2105          wdl.pick_up_stop_id,
2106          wdl.drop_off_stop_id,
2107          wdl.parent_delivery_leg_id
2108   FROM   wsh_trip_stops wts,
2109          wsh_delivery_legs wdl
2110   WHERE  wdl.delivery_leg_id = p_leg_id
2111   AND    wdl.pick_up_stop_id = wts.stop_id
2112   AND    p_leg_id is not null
2113   UNION
2114   SELECT wts.trip_id,
2115          wdl.pick_up_stop_id,
2116          wdl.drop_off_stop_id,
2117          wdl.parent_delivery_leg_id
2118   FROM   wsh_trip_stops wts,
2119          wsh_delivery_legs wdl
2120   WHERE  wdl.delivery_id = p_delivery_id
2121   AND    wdl.pick_up_stop_id = wts.stop_id
2122   AND    p_leg_id is null;
2123 
2124   CURSOR C1(c_trip_id IN NUMBER) IS
2125   SELECT delivery_id
2126   FROM   wsh_delivery_legs wdl,
2127          wsh_trip_stops wts
2128   WHERE  wts.trip_id = c_trip_id
2129   AND    wdl.pick_up_stop_id = wts.stop_id
2130   AND    wdl.parent_delivery_leg_id is NULL
2131   AND    wdl.delivery_id <> p_delivery_id;
2132 
2133   CURSOR c_parent_delivery (p_delivery_leg_id IN NUMBER) IS
2134   SELECT delivery_id from wsh_delivery_legs
2135   WHERE  delivery_leg_id = p_delivery_leg_id;
2136 
2137   --R12 MDC
2138   CURSOR c_check_pickup(p_stop_id IN NUMBER) IS
2139   SELECT delivery_leg_id
2140   FROM wsh_delivery_legs wdl
2141   WHERE wdl.delivery_id = p_delivery_id
2142   AND wdl.pick_up_stop_id = p_stop_id;
2143 
2144   CURSOR c_check_dropoff(p_stop_id IN NUMBER) IS
2145   SELECT delivery_leg_id
2146   FROM wsh_delivery_legs wdl
2147   WHERE wdl.delivery_id = p_delivery_id
2148   AND wdl.drop_off_stop_id = p_stop_id;
2149 
2150   l_stop_type VARCHAR2(100);
2151 
2152   l_wt_uom_code               VARCHAR2(3);
2153   l_vol_uom_code              VARCHAR2(3);
2154   l_return_status             VARCHAR2(100);
2155   l_status_code               VARCHAR2(2);
2156   l_shipment_direction        wsh_new_deliveries.shipment_direction%TYPE;
2157   l_frozen_flag               VARCHAR2(1);
2158   l_dummy                     NUMBER;
2159   l_trip_empty                BOOLEAN;
2160   l_parent_delivery_id        NUMBER;
2161   l_debug_on                  BOOLEAN;
2162   l_del_tab                   wsh_util_core.id_tab_type;
2163   l_module_name CONSTANT      VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DEL_WV_POST_PROCESS';
2164 
2165   e_abort                     exception;
2166   mark_reprice_error          exception;
2167 
2168 BEGIN
2169 
2170   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2171   IF l_debug_on IS NULL THEN
2172     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2173   END IF;
2174 
2175   IF l_debug_on THEN
2176     WSH_DEBUG_SV.push(l_module_name);
2177     WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_ID',p_delivery_id);
2178     WSH_DEBUG_SV.log(l_module_name,'P_DIFF_GROSS_WT',p_diff_gross_wt);
2179     WSH_DEBUG_SV.log(l_module_name,'P_DIFF_NET_WT',p_diff_net_wt);
2180     WSH_DEBUG_SV.log(l_module_name,'P_DIFF_VOLUME',p_diff_volume);
2181     WSH_DEBUG_SV.log(l_module_name,'P_LEG_ID',p_leg_id);
2182     WSH_DEBUG_SV.log(l_module_name,'P_CHECK_FOR_EMPTY',P_CHECK_FOR_EMPTY);
2183   END IF;
2184   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2185 
2186   -- Get the delivery information
2187   BEGIN
2188     SELECT weight_uom_code,
2189            volume_uom_code,
2190            status_code,
2191            NVL(shipment_direction,'O'),
2192            NVL(wv_frozen_flag,'Y')
2193     INTO   l_wt_uom_code,
2194            l_vol_uom_code,
2195            l_status_code,
2196            l_shipment_direction,
2197            l_frozen_flag
2198     FROM   wsh_new_deliveries
2199     WHERE  delivery_id = p_delivery_id;
2200 
2201   EXCEPTION
2202       WHEN NO_DATA_FOUND THEN
2203         FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_DELIVERY');
2204         FND_MESSAGE.SET_TOKEN('DELIVERY',p_delivery_id);
2205         wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_ERROR);
2206         IF l_debug_on THEN
2207           WSH_DEBUG_SV.log(l_module_name,'Delivery '||p_delivery_id||' not found');
2208           WSH_DEBUG_SV.pop(l_module_name);
2209         END IF;
2210         return;
2211   END;
2212 
2213   -- If delivery status is 'IT','CL','SR' and shipment direction is 'O','IO' then Post processing is not allowed
2214   IF l_shipment_direction in ('O','IO') AND l_status_code IN ('IT','CL','SR') THEN
2215     IF l_debug_on THEN
2216       WSH_DEBUG_SV.logmsg(l_module_name,'Status Code is '||l_status_code||'. Post Processing is not allowed');
2217       WSH_DEBUG_SV.pop(l_module_name);
2218     END IF;
2219     return;
2220   END IF;
2221 
2222   -- for all trips assigned to the delivery leg/delivery
2223   FOR crec in trip_info LOOP
2224 
2225     IF l_debug_on THEN
2226       WSH_DEBUG_SV.logmsg(l_module_name,'Processing Trip '||crec.trip_id||' Pickup '||crec.pick_up_stop_id||' Drop off '||crec.drop_off_stop_id);
2227     END IF;
2228 
2229     -- if p_check_for_empty is 'Y' and if the trip will become empty without delivery
2230     -- then set W/V to null for all stops in this trip
2231     l_trip_empty := FALSE;
2232     IF p_check_for_empty = 'Y' THEN
2233       OPEN  C1(crec.trip_id);
2234       FETCH C1 INTO l_dummy;
2235       IF C1%NOTFOUND THEN
2236         l_trip_empty := TRUE;
2237 
2238         IF l_debug_on THEN
2239           WSH_DEBUG_SV.logmsg(l_module_name,'Trip '||crec.trip_id||' will become empty without this delivery');
2240         END IF;
2241 
2242       --R12 MDC
2243       --Included update for new wt/vol columns
2244         UPDATE wsh_trip_stops
2245         SET    departure_gross_weight = null,
2246                departure_net_weight   = null,
2247                departure_volume       = null,
2248                departure_fill_percent = null,
2249                wv_frozen_flag = 'N',
2250                last_update_date  = SYSDATE,
2251                last_updated_by   = FND_GLOBAL.user_id,
2252                last_update_login = FND_GLOBAL.login_id,
2253                pick_up_weight = null,
2254                pick_up_volume = null,
2255                drop_off_weight = null,
2256                drop_off_volume = null
2257         WHERE  trip_id = crec.trip_id;
2258       END IF;
2259       CLOSE C1;
2260     END IF;
2261 
2262     IF NOT l_trip_empty THEN
2263 
2264       -- Adjust all stops W/V which are between pickup stop and dropoff stop
2265       FOR crec1 in c_stops(crec.trip_id, crec.pick_up_stop_id, crec.drop_off_stop_id) LOOP
2266         --R12 MDC
2267         l_stop_type := NULL;
2268 
2269         IF l_debug_on THEN
2270           WSH_DEBUG_SV.logmsg(l_module_name,'Processing Stop '||crec1.stop_id);
2271           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Adjust_parent_WV',WSH_DEBUG_SV.C_PROC_LEVEL);
2272         END IF;
2273 
2274         OPEN c_check_pickup(crec1.stop_id);
2275         FETCH c_check_pickup INTO l_dummy;
2276         IF c_check_pickup%FOUND THEN
2277            l_stop_type := 'PICKUP';
2278         ELSE
2279            OPEN c_check_dropoff(crec1.stop_id);
2280            FETCH c_check_dropoff INTO l_dummy;
2281            IF c_check_dropoff%FOUND THEN
2282              l_stop_type := 'DROPOFF';
2283            END IF;
2284            CLOSE c_check_dropoff;
2285         END IF;
2286         CLOSE c_check_pickup;
2287 
2288         IF (crec.parent_delivery_leg_id IS NOT NULL) AND (l_stop_type = 'PICKUP') THEN
2289 
2290            OPEN c_parent_delivery(crec.parent_delivery_leg_id);
2291            FETCH c_parent_delivery
2292            INTO l_parent_delivery_id;
2293            CLOSE c_parent_delivery;
2294 
2295            Adjust_parent_WV(
2296              p_entity_type   => 'DELIVERY',
2297              p_entity_id     => l_parent_delivery_id,
2298              p_gross_weight  => p_diff_gross_wt,
2299              p_net_weight    => p_diff_net_wt,
2300              p_volume        => p_diff_volume,
2301              p_wt_uom_code   => l_wt_uom_code,
2302              p_vol_uom_code  => l_vol_uom_code,
2303              p_inv_item_id   => null,
2304              x_return_status => l_return_status);
2305 
2306            IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2307              IF l_debug_on THEN
2308                WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV returned '||l_return_status);
2309              END IF;
2310              raise e_abort;
2311            END IF;
2312         ELSIF crec.parent_delivery_leg_id IS NULL THEN
2313 
2314            Adjust_parent_WV(
2315              p_entity_type   => 'STOP',
2316              p_entity_id     => crec1.stop_id,
2317              p_gross_weight  => p_diff_gross_wt,
2318              p_net_weight    => p_diff_net_wt,
2319              p_volume        => p_diff_volume,
2320              p_wt_uom_code   => l_wt_uom_code,
2321              p_vol_uom_code  => l_vol_uom_code,
2322              p_inv_item_id   => null,
2323              x_return_status => l_return_status,
2324              p_stop_type  => l_stop_type);
2325 
2326            IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2327              IF l_debug_on THEN
2328                WSH_DEBUG_SV.logmsg(l_module_name,'Adjust_parent_WV returned '||l_return_status);
2329              END IF;
2330              raise e_abort;
2331            END IF;
2332         END IF;
2333       END LOOP;
2334 
2335     END IF;
2336 
2337   END LOOP;
2338 
2339   -- BugFix 5518613, changed > to <>
2340   IF (p_diff_gross_wt <> 0) or (p_diff_net_wt <> 0) THEN
2341 
2342      l_del_tab(1) := p_delivery_id;
2343 
2344      IF l_debug_on THEN
2345         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_LEGS_ACTIONS.MARK_REPRICE_REQUIRED',WSH_DEBUG_SV.C_PROC_LEVEL);
2346      END IF;
2347      --
2348      WSH_DELIVERY_LEGS_ACTIONS.Mark_Reprice_Required(
2349        p_entity_type => 'DELIVERY',
2350        p_entity_ids   => l_del_tab,
2351        x_return_status => l_return_status);
2352      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2353         raise mark_reprice_error;
2354      END IF;
2355 
2356   END IF;
2357 
2358   IF l_debug_on THEN
2359     WSH_DEBUG_SV.pop(l_module_name);
2360   END IF;
2361 
2362 EXCEPTION
2363 
2364   WHEN lock_detected THEN -- BugFix 3570954
2365       FND_MESSAGE.SET_NAME('WSH','WSH_NO_LOCK');
2366       x_return_status := WSH_UTIL_CORE.g_ret_sts_error;
2367       wsh_util_core.add_message(WSH_UTIL_CORE.g_ret_sts_error,l_module_name);
2368 
2369   WHEN e_abort THEN
2370    x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2371    IF l_debug_on THEN
2372      WSH_DEBUG_SV.pop(l_module_name);
2373    END IF;
2374 
2375   WHEN mark_reprice_error then
2376     FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
2377     x_return_status := l_return_status;
2378     WSH_UTIL_CORE.add_message (x_return_status,l_module_name);
2379     --
2380     IF l_debug_on THEN
2381         WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2382         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
2383     END IF;
2384 
2385   WHEN Others THEN
2386     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.DEL_WV_POST_PROCESS');
2387     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2388 
2389     IF l_debug_on THEN
2390       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2391       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2392     END IF;
2393 
2394 END DEL_WV_Post_Process;
2395 
2396 -- J: W/V changes
2397 
2398 -- Start of comments
2399 -- API name : Detail_Weight_Volume
2400 -- Type     : Public
2401 -- Pre-reqs : None.
2402 -- Function : Calculates Weight and Volume of Delivery Detail
2403 --            If p_update_flag is 'Y' then the calculated W/V is updated on Delivery Detail
2404 --            Otherwise, the API returns the calculated W/V
2405 -- Parameters :
2406 -- IN:
2407 --    p_delivery_detail_id IN NUMBER Required
2408 --    p_update_flag        IN VARCHAR2
2409 --      'Y' if the detail needs to be updated with the calculated W/V
2410 --    p_post_process_flag  IN VARCHAR2
2411 --      'Y' if W/V post processing is required
2412 --    p_calc_wv_if_frozen  IN VARCHAR2
2413 --      'N' if W/V should not be calculated if W/V is frozen
2414 -- OUT:
2415 --    x_net_weight OUT NUMBER
2416 --       gives the net weight of delivery detail
2417 --    x_volume OUT NUMBER
2418 --       gives the volume of delivery detail
2419 --    x_return_status OUT VARCHAR2 Required
2420 --       give the return status of API
2421 -- Version : 1.0
2422 -- End of comments
2423 
2424 PROCEDURE Detail_Weight_Volume (
2425   p_delivery_detail_id  IN NUMBER,
2426   p_update_flag         IN VARCHAR2,
2427   p_post_process_flag   IN VARCHAR2,
2428   p_calc_wv_if_frozen   IN VARCHAR2 DEFAULT 'Y',
2429   x_net_weight          OUT NOCOPY  NUMBER,
2430   x_volume              OUT NOCOPY  NUMBER,
2431   x_return_status       OUT NOCOPY  VARCHAR2) IS
2432 
2433   l_org_gross_wt number;
2434   l_org_net_wt   number;
2435   l_org_vol      number;
2436   l_frozen_flag  VARCHAR2(1);
2437   l_return_status VARCHAR2(100);
2438 
2439   l_debug_on     BOOLEAN;
2440   l_module_name  CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DETAIL_WEIGHT_VOLUME';
2441 
2442   e_abort        exception;
2443 
2444 BEGIN
2445 
2446   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2447   IF l_debug_on IS NULL
2448   THEN
2449       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2450   END IF;
2451   IF l_debug_on THEN
2452       WSH_DEBUG_SV.push(l_module_name);
2453       WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_DETAIL_ID',P_DELIVERY_DETAIL_ID);
2454       WSH_DEBUG_SV.log(l_module_name,'P_UPDATE_FLAG',P_UPDATE_FLAG);
2455       WSH_DEBUG_SV.log(l_module_name,'P_POST_PROCESS_FLAG',P_POST_PROCESS_FLAG);
2456       WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',p_CALC_WV_IF_FROZEN);
2457   END IF;
2458   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2459 
2460   -- Get the DD info
2461   BEGIN
2462     SELECT gross_weight,
2463            net_weight,
2464            volume,
2465            NVL(wv_frozen_flag,'Y')
2466     INTO   l_org_gross_wt,
2467            l_org_net_wt,
2468            l_org_vol,
2469            l_frozen_flag
2470     FROM   wsh_delivery_details
2471     WHERE  delivery_detail_id = p_delivery_detail_id
2472     AND    container_flag = 'N';
2473   EXCEPTION
2474     WHEN NO_DATA_FOUND THEN
2475       FND_MESSAGE.SET_NAME('WSH','WSH_DET_INVALID_DETAIL');
2476       FND_MESSAGE.SET_TOKEN('DETAIL_ID',p_delivery_detail_id);
2477       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2478       IF l_debug_on THEN
2479         WSH_DEBUG_SV.logmsg(l_module_name,'DD '||p_delivery_detail_id||' not found');
2480         WSH_DEBUG_SV.pop(l_module_name);
2481       END IF;
2482       return;
2483   END;
2484 
2485   IF (P_CALC_WV_IF_FROZEN = 'N' AND l_frozen_flag = 'Y') THEN
2486     x_net_weight := l_org_net_wt;
2487     x_volume     := l_org_vol;
2488     IF l_debug_on THEN
2489       WSH_DEBUG_SV.logmsg(l_module_name,'WV calculation not allowed on '||p_delivery_detail_id||'. Returning existing W/V');
2490       WSH_DEBUG_SV.pop(l_module_name);
2491     END IF;
2492     return;
2493   END IF;
2494 
2495   IF l_debug_on THEN
2496     WSH_DEBUG_SV.logmsg(l_module_name,'DD original wts are Gross '||l_org_gross_wt||' Net '||l_org_net_wt||' Vol '||l_org_vol);
2497   END IF;
2498 
2499   -- Call Detail_Weight_Volume API
2500   IF l_debug_on THEN
2501     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit DETAIL_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
2502   END IF;
2503 
2504   Detail_Weight_Volume(
2505     p_delivery_detail_id  => p_delivery_detail_id,
2506     p_update_flag         => p_update_flag,
2507     p_calc_wv_if_frozen   => p_calc_wv_if_frozen,
2508     x_net_weight          => x_net_weight,
2509     x_volume              => x_volume,
2510     x_return_status       => l_return_status);
2511 
2512   IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2513     x_return_status := l_return_status;
2514     IF l_debug_on THEN
2515       WSH_DEBUG_SV.pop(l_module_name,'Detail_Weight_Volume returned '||l_return_status);
2516       WSH_DEBUG_SV.pop(l_module_name);
2517      END IF;
2518      return;
2519   END IF;
2520 
2521   -- If p_update_flag is 'Y and ((p_post_process_flag is 'Y' and the new and old W/V differ)
2522   -- then call DD_WV_Post_Process API
2523   IF (p_update_flag = 'Y' AND p_post_process_flag = 'Y' AND
2524        (  (NVL(x_net_weight,0)   <> NVL(l_org_gross_wt,0)) OR
2525           (NVL(x_net_weight,0)   <> NVL(l_org_net_wt,0)) OR
2526           (NVL(x_volume,0)       <> NVL(l_org_vol,0))
2527        )) THEN
2528     IF l_debug_on THEN
2529       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit DD_WV_Post_Process',WSH_DEBUG_SV.C_PROC_LEVEL);
2530     END IF;
2531 
2532     DD_WV_Post_Process(
2533       p_delivery_detail_id => p_delivery_detail_id,
2534       p_diff_gross_wt      => NVL(x_net_weight,0) - NVL(l_org_gross_wt,0),
2535       p_diff_net_wt        => NVL(x_net_weight,0) - NVL(l_org_net_wt,0),
2536       p_diff_fill_volume   => NVL(x_volume,0) - NVL(l_org_vol,0),
2537       x_return_status      => l_return_status);
2538 
2539     IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2540       x_return_status := l_return_status;
2541       IF l_debug_on THEN
2542         WSH_DEBUG_SV.logmsg(l_module_name,'DD_WV_Post_Process returned '||l_return_status);
2543         WSH_DEBUG_SV.pop(l_module_name);
2544       END IF;
2545       return;
2546     END IF;
2547   END IF;
2548 
2549   IF l_debug_on THEN
2550     WSH_DEBUG_SV.logmsg(l_module_name,'x_return_status '||x_return_status);
2551     WSH_DEBUG_SV.pop(l_module_name);
2552   END IF;
2553 
2554 EXCEPTION
2555 
2556   WHEN e_abort THEN
2557     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2558     IF l_debug_on THEN
2559       WSH_DEBUG_SV.pop(l_module_name);
2560     END IF;
2561 
2562   WHEN Others THEN
2563     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.Detail_Weight_Volume');
2564     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2565     IF l_debug_on THEN
2566       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL)
2567 ;
2568       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2569     END IF;
2570 
2571 END Detail_Weight_Volume;
2572 
2573 /* This procedure is no longer used */
2574 -- THIS PROCEDURE IS OBSOLETE
2575 PROCEDURE Add_Container_Wt_Vol (
2576   p_container_instance_id IN NUMBER,
2577   p_detail_id     IN NUMBER,
2578   p_detail_type   IN VARCHAR2,
2579   p_fill_pc_flag  IN VARCHAR2,
2580   x_gross_weight  OUT NOCOPY  NUMBER,
2581   x_net_weight    OUT NOCOPY  NUMBER,
2582   x_volume        OUT NOCOPY  NUMBER,
2583   x_cont_fill_pc  OUT NOCOPY  NUMBER,
2584   x_return_status OUT NOCOPY  VARCHAR2) IS
2585 
2586 BEGIN
2587   x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2588 
2589 END Add_Container_Wt_Vol;
2590 
2591 -- J: W/V Changes
2592 -- OTM R12 : packing ECO
2593 --           modified to keep track of container wt/vol updates
2594 PROCEDURE Update_Container_Wt_Vol(
2595    p_container_instance_id IN NUMBER,
2596    p_gross_weight IN NUMBER,
2597    p_net_weight IN NUMBER,
2598    p_volume IN NUMBER,
2599    p_filled_volume IN NUMBER,
2600    p_fill_pc_flag IN VARCHAR2,
2601    p_unit_weight IN NUMBER DEFAULT -99,
2602    p_unit_volume IN NUMBER DEFAULT -99,
2603    x_cont_fill_pc OUT NOCOPY  NUMBER,
2604    x_return_status OUT NOCOPY  VARCHAR2) IS
2605 
2606    CURSOR c_get_detail_wv IS
2607    SELECT net_weight,
2608           gross_weight,
2609           volume,
2610           filled_volume,
2611           container_flag,
2612           nvl(line_direction, 'O') line_direction, -- LPN CONV. rv
2613           organization_id                          -- LPN CONV. rv
2614    FROM   wsh_delivery_details
2615    WHERE  delivery_detail_id = p_container_instance_id;
2616 
2617 l_net_weight       NUMBER := 0;
2618 l_gross_weight     NUMBER := 0;
2619 l_volume           NUMBER := 0;
2620 l_filled_volume    NUMBER := 0;
2621 l_container_flag   VARCHAR2(1):='N';
2622 l_details_marked   WSH_UTIL_CORE.Id_Tab_Type;
2623 l_return_status    VARCHAR2(1);
2624 
2625 mark_reprice_error EXCEPTION;
2626 -- LPN CONV. rv
2627 l_line_direction  VARCHAR2(10);
2628 l_organization_id NUMBER;
2629 l_wms_org         VARCHAR2(10) := 'N';
2630 l_sync_tmp_rec    wsh_glbl_var_strct_grp.sync_tmp_rec_type;
2631 l_num_warnings    NUMBER := 0;
2632 -- LPN CONV. rv
2633 
2634 l_debug_on    BOOLEAN;
2635 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'UPDATE_CONTAINER_WT_VOL';
2636 
2637 BEGIN
2638 
2639    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
2640    IF l_debug_on IS NULL
2641    THEN
2642        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
2643    END IF;
2644 
2645    IF l_debug_on THEN
2646        WSH_DEBUG_SV.push(l_module_name);
2647        WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_INSTANCE_ID',P_CONTAINER_INSTANCE_ID);
2648        WSH_DEBUG_SV.log(l_module_name,'P_GROSS_WEIGHT',P_GROSS_WEIGHT);
2649        WSH_DEBUG_SV.log(l_module_name,'P_NET_WEIGHT',P_NET_WEIGHT);
2650        WSH_DEBUG_SV.log(l_module_name,'P_VOLUME',P_VOLUME);
2651        WSH_DEBUG_SV.log(l_module_name,'P_FILLED_VOLUME',P_FILLED_VOLUME);
2652        WSH_DEBUG_SV.log(l_module_name,'P_FILL_PC_FLAG',P_FILL_PC_FLAG);
2653    END IF;
2654 
2655    OPEN  c_get_detail_wv;
2656    FETCH c_get_detail_wv
2657    INTO  l_net_weight,
2658          l_gross_weight,
2659          l_volume,
2660          l_filled_volume,
2661          l_container_flag,
2662          l_line_direction,   -- LPN CONV. rv
2663          l_organization_id;  -- LPN CONV. rv
2664    IF l_debug_on THEN
2665        WSH_DEBUG_SV.log(l_module_name,'Original l_net_weight '||l_net_weight||' l_gross_weight '||l_gross_weight||' l_volume '||l_volume||' l_filled_volume '||l_filled_volume||' l_container_flag '||l_container_flag);
2666    END IF;
2667    IF c_get_detail_wv%NOTFOUND THEN
2668      CLOSE c_get_detail_wv;
2669      x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2670      FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_CONTAINER');
2671 
2672      IF l_debug_on THEN
2673          WSH_DEBUG_SV.pop(l_module_name);
2674      END IF;
2675      return;
2676    END IF;
2677    CLOSE c_get_detail_wv;
2678 
2679    -- K LPN CONV. rv
2680    IF l_debug_on THEN
2681        WSH_DEBUG_SV.log(l_module_name,'line direction', l_line_direction);
2682        WSH_DEBUG_SV.log(l_module_name,'Organization Id', l_organization_id);
2683    END IF;
2684    --
2685    l_wms_org := wsh_util_validate.check_wms_org(l_organization_id);
2686    --
2687    IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
2688    AND l_line_direction IN ('O','IO')
2689    AND l_container_flag IN ('Y', 'C')
2690    AND
2691    (
2692      ((WSH_WMS_LPN_GRP.GK_WMS_UPD_WV or WSH_WMS_LPN_GRP.GK_WMS_UPD_ITEM) and l_wms_org = 'Y')
2693      OR
2694      ((WSH_WMS_LPN_GRP.GK_INV_UPD_WV or WSH_WMS_LPN_GRP.GK_INV_UPD_ITEM) and l_wms_org = 'N')
2695    )
2696    THEN
2697    --{
2698        l_sync_tmp_rec.delivery_detail_id := p_container_instance_id;
2699        l_sync_tmp_rec.operation_type := 'UPDATE';
2700        --
2701        -- Debug Statements
2702        --
2703        IF l_debug_on THEN
2704          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WMS_SYNC_TMP_PKG.MERGE',WSH_DEBUG_SV.C_PROC_LEVEL);
2705        END IF;
2706        --
2707        WSH_WMS_SYNC_TMP_PKG.MERGE
2708        (
2709          p_sync_tmp_rec      => l_sync_tmp_rec,
2710          x_return_status     => l_return_status
2711        );
2712 
2713        IF l_debug_on THEN
2714          WSH_DEBUG_SV.log(l_module_name,'Return Status after calling WSH_WMS_SYNC_TMP_PKG.MERGE',l_return_status);
2715        END IF;
2716        --
2717        IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
2718          --
2719          x_return_status := l_return_status;
2720          --
2721          IF l_debug_on THEN
2722            WSH_DEBUG_SV.logmsg(l_module_name,'WSH_WMS_SYNC_TMP_PKG.MERGE completed with an error');
2723            WSH_DEBUG_SV.pop(l_module_name);
2724          END IF;
2725          --
2726          RETURN;
2727          --
2728        ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2729          --
2730          l_num_warnings := l_num_warnings + 1;
2731          --
2732        END IF;
2733 
2734    --}
2735    END IF;
2736    -- K LPN CONV. rv
2737 
2738    UPDATE WSH_DELIVERY_DETAILS
2739    SET    net_weight   = p_net_weight,
2740           gross_weight = p_gross_weight,
2741           volume       = p_volume,
2742           filled_volume= p_filled_volume,
2743           unit_weight  = NVL(unit_weight,decode(p_unit_weight,-99,NULL,p_unit_weight)),
2744           unit_volume  = NVL(unit_volume,decode(p_unit_volume,-99,NULL,p_unit_volume)),
2745           wv_frozen_flag  = 'N',
2746           last_update_date  = SYSDATE,
2747           last_updated_by   = FND_GLOBAL.user_id,
2748           last_update_login = FND_GLOBAL.login_id
2749    WHERE delivery_detail_id = p_container_instance_id;
2750 
2751    IF SQL%NOTFOUND THEN
2752      x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
2753      FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_CONTAINER');
2754 
2755      IF l_debug_on THEN
2756          WSH_DEBUG_SV.pop(l_module_name);
2757      END IF;
2758      return;
2759    END IF;
2760 
2761    /* H projects : pricing integration csun */
2762    IF  (NVL(l_net_weight,-99)   <> NVL(p_net_weight,-99) OR
2763         NVL(l_gross_weight,-99) <> NVL(p_gross_weight,-99) OR
2764         NVL(NVL(l_filled_volume,l_volume),-99) <> NVL(p_filled_volume,-99) ) THEN
2765 
2766      l_details_marked.delete;
2767      l_details_marked(1) := p_container_instance_id;
2768      IF l_debug_on THEN
2769        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_LEGS_ACTIONS.MARK_REPRICE_REQUIRED',WSH_DEBUG_SV.C_PROC_LEVEL);
2770      END IF;
2771 
2772      WSH_DELIVERY_LEGS_ACTIONS.Mark_Reprice_Required(
2773        p_entity_type => 'DELIVERY_DETAIL',
2774        p_entity_ids   => l_details_marked,
2775        x_return_status => l_return_status);
2776      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2777        raise mark_reprice_error;
2778      END IF;
2779 
2780    END IF;
2781 
2782    IF p_fill_pc_flag = 'Y' THEN
2783 
2784      IF l_debug_on THEN
2785          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TPA_CONTAINER_PKG.CALC_CONT_FILL_PC',WSH_DEBUG_SV.C_PROC_LEVEL);
2786      END IF;
2787 
2788      WSH_TPA_CONTAINER_PKG.Calc_Cont_Fill_Pc (
2789         p_container_instance_id,
2790         'Y',
2791         NULL,
2792         x_cont_fill_pc,
2793         x_return_status);
2794 
2795      IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2796        IF l_debug_on THEN
2797          WSH_DEBUG_SV.pop(l_module_name);
2798        END IF;
2799        return;
2800      END IF;
2801 
2802    END IF;
2803 
2804    -- OTM R12 : packing ECO
2805    -- after update wsh_delivery_details sql
2806    -- if any weight/vol changed, mark the global variable
2807    IF (G_DELIVERY_TMS_IMPACT = 'N' AND
2808        (NVL(l_net_weight, -1) <> NVL(p_net_weight, -1) OR
2809         NVL(l_gross_weight, -1) <> NVL(p_gross_weight, -1) OR
2810         NVL(l_volume, -1) <> NVL(p_volume, -1))) THEN
2811      G_DELIVERY_TMS_IMPACT := 'Y';
2812      IF l_debug_on THEN
2813        WSH_DEBUG_SV.log(l_module_name,'G_DELIVERY_TMS_IMPACT', G_DELIVERY_TMS_IMPACT);
2814      END IF;
2815    END IF;
2816    -- End of OTM R12 : packing ECO
2817 
2818    -- LPN CONV. rv
2819    IF (l_num_warnings > 0 AND x_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
2820      --
2821      x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
2822      --
2823    ELSE
2824      --
2825      x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2826      --
2827    END IF;
2828    -- LPN CONV. rv
2829 
2830    IF l_debug_on THEN
2831        WSH_DEBUG_SV.pop(l_module_name);
2832    END IF;
2833 
2834 EXCEPTION
2835    WHEN mark_reprice_error then
2836      FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
2837      x_return_status := l_return_status;
2838      WSH_UTIL_CORE.add_message (x_return_status);
2839      IF l_debug_on THEN
2840          WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
2841          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
2842      END IF;
2843 
2844    WHEN others THEN
2845      IF l_debug_on THEN
2846        WSH_DEBUG_SV.logmsg(l_module_name, 'EXCEPTION: OTHERS ' || SQLERRM  );
2847      END IF;
2848      wsh_util_core.default_handler('WSH_WV_UTIL.update_container_wt_vol');
2849      x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2850 
2851      IF l_debug_on THEN
2852        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2853        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
2854      END IF;
2855 
2856 END update_container_wt_vol;
2857 
2858 -- J: W/V Changes
2859 
2860 -- Start of comments
2861 -- API name : Container_Weight_Volume
2862 -- Type     : Private
2863 -- Pre-reqs : None.
2864 -- Function : Calculates Weight and Volume of Container
2865 --            If p_overrideFlag is 'Y' then the calculated W/V is updated on Container
2866 --            Otherwise, the API returns the calculated W/V
2867 --            OTM R12 : packing ECO
2868 --                      This procedure is modified to keep track of detail
2869 --                      wt/vol updates. Changed because it contains the actual
2870 --                      update on the wsh_delivery_detail table.
2871 -- Parameters :
2872 -- IN:
2873 --    p_containerInstanceId IN NUMBER Required
2874 --    p_overrideFlag        IN VARCHAR2
2875 --      'Y' if the detail needs to be updated with the calculated W/V
2876 --    p_calcWVIfFrozen      IN VARCHAR2
2877 --      ''Y' if manual W/V can be overriden
2878 --    p_fillPcFlag          IN  VARCHAR2
2879 --      'Y' if fill% needs to be calculated
2880 --    p_masterWeightUomCode IN  VARCHAR2
2881 --      Return the calculated Wt info in p_masterWeightUomCode UOM
2882 --    p_masterVolumeUomCode IN  VARCHAR2
2883 --      Return the calculated Vol info in p_masterVolumeUomCode UOM
2884 -- OUT:
2885 --    x_grossWeight OUT NUMBER
2886 --       gives the gross weight of container
2887 --    x_netWeight OUT NUMBER
2888 --       gives the net weight of container
2889 --    x_filledVolume OUT NUMBER
2890 --       gives the filled volume of container
2891 --    x_volume OUT NUMBER
2892 --       gives the volume of container
2893 --    x_contFillPc  OUT NUMBER
2894 --       gives the Fill% of container
2895 --    x_return_status OUT VARCHAR2 Required
2896 --       give the return status of API
2897 -- Version : 1.0
2898 -- End of comments
2899 
2900 PROCEDURE Container_Weight_Volume
2901             (
2902               p_containerInstanceId     IN  NUMBER,
2903               p_overrideFlag            IN  VARCHAR2,
2904               p_calcWVIfFrozen          IN  VARCHAR2,
2905               p_fillPcFlag              IN  VARCHAR2,
2906               p_masterWeightUomCode     IN  VARCHAR2 DEFAULT NULL,
2907               p_masterVolumeUomCode     IN  VARCHAR2 DEFAULT NULL,
2908               x_grossWeight             OUT NOCOPY  NUMBER,
2909               x_netWeight               OUT NOCOPY  NUMBER,
2910               x_filledVolume            OUT NOCOPY  NUMBER,
2911               x_volume                  OUT NOCOPY  NUMBER,
2912               x_contFillPc              OUT NOCOPY  NUMBER,
2913               x_returnStatus            OUT NOCOPY  VARCHAR2
2914             )
2915 IS
2916 --{
2917     --
2918     -- Parameters p_masterWeightUomCode, p_masterVolumeUomCode will be NULL
2919     -- when this procedure is called for the topmost container.
2920     -- It will be set during the first call and will be passed on to any
2921     -- recursive calls.
2922     --
2923     --
2924     -- x_volume indicates volume of a line i.e. volume of an item/container itself.
2925     -- x_filledVolume indicate filled volume of a line
2926     -- In case of a container, it will indicate total volume of all its contents
2927     -- In case of other items(non-container), it will be same as x_volume.
2928     -- Same holds true for local variables
2929     --   - l_volume and l_filledVolume
2930     --   - l_line_volume and l_line_filledVolume
2931     --
2932     l_netWeight              NUMBER;
2933     l_grossWeight            NUMBER;
2934     l_volume                 NUMBER;
2935     l_filledVolume           NUMBER;
2936     l_contFillPc             number;
2937     --
2938     --
2939     l_line_grossWeight        NUMBER;
2940     l_line_netWeight          NUMBER;
2941     l_line_volume             NUMBER;
2942     l_line_grossWeight_orig   NUMBER;
2943     l_line_netWeight_orig     NUMBER;
2944     l_line_volume_orig        NUMBER;
2945     l_line_filledVolume       NUMBER;
2946     l_line_contFillPc         NUMBER;
2947     l_returnStatus            VARCHAR2(32767);
2948     --
2949     --
2950     l_masterWeightUomCode    VARCHAR2(32767);
2951     l_masterVolumeUomCode    VARCHAR2(32767);
2952     l_masterInvItemId        NUMBER;
2953     --
2954     --
2955     l_dd_grossWt             NUMBER;
2956     l_dd_netWt               NUMBER;
2957     l_dd_vol                 NUMBER;
2958     --
2959     e_wt_vol_fail         EXCEPTION;
2960     e_abort               EXCEPTION;
2961     e_continue            EXCEPTION;
2962     e_invalid_detail      EXCEPTION;
2963 
2964     --
2965     --
2966     -- Following query returns the delivery details ID and its immediate
2967     -- children ( Condition LEVEL <=2 limits itself to only immediate children)
2968     --
2969     CURSOR immediateChildren_cur
2970              (
2971                p_containerInstanceId IN  NUMBER
2972              )
2973     IS
2974     SELECT     delivery_detail_id,
2975                LEVEL
2976     FROM       wsh_delivery_assignments wda
2977     WHERE      LEVEL                   <= 2
2978     AND        NVL(wda.type, 'S')       in ('S', 'C')
2979     START WITH wda.delivery_detail_id       = p_containerInstanceId
2980           AND  NVL(wda.type, 'S')       in ('S', 'C')
2981     CONNECT BY PRIOR delivery_detail_id = parent_delivery_detail_id;
2982     --
2983     --
2984     -- Get Delivery Detail information for each line including its
2985     -- physical attributes from inventory item definition.
2986     --
2987     --
2988     CURSOR childInfo_cur
2989              (
2990                p_deliveryDetailId     IN NUMBER
2991              )
2992     IS
2993     SELECT wdd.container_flag ,
2994            wdd.delivery_detail_id,
2995            wdd.inventory_item_id,
2996            NVL(wdd.wv_frozen_flag,'Y') wv_frozen_flag,
2997            wdd.net_weight,
2998            wdd.gross_weight,
2999            wdd.volume,
3000            wdd.filled_volume,
3001            wdd.weight_uom_code,
3002            wdd.volume_uom_code,
3003            wdd.organization_id ,
3004            nvl(wdd.unit_weight,msi.unit_weight) unit_weight,
3005            nvl(wdd.unit_volume,msi.unit_volume) unit_volume,
3006            WSH_WV_UTILS.convert_uom
3007              (
3008                wdd.requested_quantity_uom,
3009                nvl(msi.primary_uom_code,wdd.requested_quantity_uom), --Bug7165744
3010                nvl(wdd.received_quantity, nvl(wdd.shipped_quantity, NVL(wdd.picked_quantity, wdd.requested_quantity))),
3011                wdd.inventory_item_id
3012              ) qty
3013     FROM   mtl_system_items msi,
3014            wsh_delivery_details wdd
3015     WHERE  msi.inventory_item_id (+)  = wdd.inventory_item_id
3016     AND    msi.organization_id (+)    = wdd.organization_id
3017     AND    wdd.delivery_detail_id = p_deliveryDetailId;
3018     --
3019     childInfo_rec childInfo_cur%ROWTYPE;
3020 --}
3021 
3022 l_details_marked        WSH_UTIL_CORE.Id_Tab_Type;
3023 
3024 l_return_status         VARCHAR2(1);
3025 l_err_container         NUMBER;
3026 mark_reprice_error      EXCEPTION;
3027 invalid_detail          EXCEPTION;
3028 
3029 l_param_info  WSH_SHIPPING_PARAMS_PVT.Parameter_Rec_Typ;
3030 l_num_warnings  NUMBER := 0;
3031 l_unit_wt NUMBER;
3032 l_unit_vol NUMBER;
3033 
3034 l_debug_on BOOLEAN;
3035 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CONTAINER_WEIGHT_VOLUME';
3036 --lpn conv
3037 l_wms_org               VARCHAR2(10) := 'N';
3038 
3039 BEGIN
3040 --{
3041     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
3042     IF l_debug_on IS NULL
3043     THEN
3044         l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
3045     END IF;
3046 
3047     IF l_debug_on THEN
3048         WSH_DEBUG_SV.push(l_module_name);
3049         --
3050         WSH_DEBUG_SV.log(l_module_name,'P_CONTAINERINSTANCEID',P_CONTAINERINSTANCEID);
3051         WSH_DEBUG_SV.log(l_module_name,'P_OVERRIDEFLAG',P_OVERRIDEFLAG);
3052         WSH_DEBUG_SV.log(l_module_name,'P_CALCWVIFFROZEN',P_CALCWVIFFROZEN);
3053         WSH_DEBUG_SV.log(l_module_name,'P_FILLPCFLAG',P_FILLPCFLAG);
3054         WSH_DEBUG_SV.log(l_module_name,'P_MASTERWEIGHTUOMCODE',P_MASTERWEIGHTUOMCODE);
3055         WSH_DEBUG_SV.log(l_module_name,'P_MASTERVOLUMEUOMCODE',P_MASTERVOLUMEUOMCODE);
3056     END IF;
3057     l_returnStatus := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3058 
3059     -- For parent container and all its immediate contents
3060     FOR immediateChildren_rec
3061     IN  immediateChildren_cur ( p_containerInstanceId )
3062     LOOP
3063     --{
3064         BEGIN
3065 
3066         IF l_debug_on THEN
3067             WSH_DEBUG_SV.logmsg(l_module_name,'Processing DD '||immediateChildren_rec.delivery_detail_id);
3068         END IF;
3069 
3070         -- Get the container info
3071         OPEN childInfo_cur ( immediateChildren_rec.delivery_detail_id );
3072         FETCH childInfo_cur INTO childInfo_rec;
3073         IF childInfo_cur%NOTFOUND
3074         THEN
3075         --{
3076             CLOSE childInfo_cur;
3077             RAISE e_continue;
3078         --}
3079         END IF;
3080         CLOSE childInfo_cur;
3081 
3082         --lpn conv
3083         IF childInfo_rec.container_flag IN ('Y', 'C')
3084                           AND NVL(childInfo_rec.wv_frozen_flag,'Y') = 'Y' THEN
3085            l_wms_org :=
3086                wsh_util_validate.check_wms_org(childInfo_rec.organization_id);
3087            IF l_wms_org = 'Y' THEN
3088               childInfo_rec.wv_frozen_flag := 'N';
3089            END IF;
3090         END IF;
3091 
3092         -- Set Master Weight and Volume UOM Code to the UOMs of parent container
3093         IF immediateChildren_rec.LEVEL = 1 THEN
3094           l_masterWeightUomCode := childInfo_rec.weight_uom_code;
3095           l_masterVolumeUomCode := childInfo_rec.volume_uom_code;
3096           l_masterInvItemId     := childInfo_rec.inventory_item_id;
3097 
3098           IF (childInfo_rec.wv_frozen_flag = 'Y' AND p_calcWVIfFrozen = 'N') THEN
3099             IF l_debug_on THEN
3100               WSH_DEBUG_SV.logmsg(l_module_name,'wv_frozen_flag is Y. Skipping the W/V calculation for this container');
3101             END IF;
3102             l_grossWeight  := childInfo_rec.gross_weight;
3103             l_netWeight    := childInfo_rec.net_weight;
3104             l_volume       := childInfo_rec.volume;
3105             l_filledVolume := childInfo_rec.filled_volume;
3106             goto skip_wv_calc;
3107           END IF;
3108 
3109           -- Get the shipping parameters of container organization
3110           IF l_debug_on THEN
3111             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIPPING_PARAMS_PVT.Get',WSH_DEBUG_SV.C_PROC_LEVEL);
3112           END IF;
3113 
3114           WSH_SHIPPING_PARAMS_PVT.Get(
3115             p_organization_id => childInfo_rec.organization_id,
3116             x_param_info      => l_param_info,
3117             x_return_status   => l_return_status);
3118 
3119           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
3120             IF l_debug_on THEN
3121               WSH_DEBUG_SV.logmsg(l_module_name,'WSH_SHIPPING_PARAMS_PVT.Get returned '||l_return_status);
3122             END IF;
3123             FND_MESSAGE.Set_Name('WSH', 'WSH_PARAM_NOT_DEFINED');
3124             FND_MESSAGE.Set_Token('ORGANIZAION_CODE',
3125                      wsh_util_core.get_org_name(childInfo_rec.organization_id));
3126             wsh_util_core.add_message(l_return_status,l_module_name);
3127             raise e_abort;
3128           END IF;
3129 
3130         END IF;
3131 
3132         l_dd_grossWt := childInfo_rec.unit_weight * childInfo_rec.qty;
3133         l_dd_netWt   := l_dd_grossWt;
3134         l_dd_vol     := childInfo_rec.unit_volume * childInfo_rec.qty;
3135 
3136         IF l_debug_on THEN
3137           WSH_DEBUG_SV.logmsg(l_module_name,'l_dd_grossWt '||l_dd_grossWt||' l_dd_netWt '||l_dd_netWt||' l_dd_vol '||l_dd_vol);
3138         END IF;
3139 
3140         -- Convert the W/V if UOMs differ
3141         IF ((l_dd_vol > 0) AND (childInfo_rec.volume_uom_code <> l_masterVolumeUomCode)) THEN
3142             IF l_debug_on THEN
3143                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3144             END IF;
3145             l_line_volume := WSH_WV_UTILS.convert_uom(
3146                                childInfo_rec.volume_uom_code,
3147                                l_masterVolumeUomCode,
3148                                l_dd_vol,
3149                                childInfo_rec.inventory_item_id);
3150 
3151             l_line_volume_orig := l_dd_vol;
3152         ELSE
3153             l_line_volume      := l_dd_vol;
3154             l_line_filledVolume:= l_dd_vol;
3155             l_line_volume_orig := l_line_volume;
3156         END IF;
3157 
3158         IF ((l_dd_grossWt > 0) AND (childInfo_rec.weight_uom_code <> l_masterWeightUomCode)) THEN
3159             IF l_debug_on THEN
3160                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3161             END IF;
3162             l_line_grossWeight := WSH_WV_UTILS.convert_uom(
3163                                     childInfo_rec.weight_uom_code,
3164                                     l_masterWeightUomCode,
3165                                     l_dd_grossWt,
3166                                     childInfo_rec.inventory_item_id);
3167             l_line_grossWeight_orig := l_dd_grossWt;
3168         ELSE
3169           l_line_grossWeight      := l_dd_grossWt;
3170           l_line_grossWeight_orig := l_line_grossWeight;
3171         END IF;
3172 
3173         IF ((l_dd_netWt > 0) AND (childInfo_rec.weight_uom_code <> l_masterWeightUomCode)) THEN
3174             IF l_debug_on THEN
3175                 WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3176             END IF;
3177             l_line_netWeight := WSH_WV_UTILS.convert_uom(
3178                                     childInfo_rec.weight_uom_code,
3179                                     l_masterWeightUomCode,
3180                                     l_dd_netWt,
3181                                     childInfo_rec.inventory_item_id);
3182             l_line_netWeight_orig := l_dd_netWt;
3183         ELSE
3184           l_line_netWeight      := l_dd_netWt;
3185           l_line_netWeight_orig := l_line_netWeight;
3186         END IF;
3187 
3188         IF l_debug_on THEN
3189           WSH_DEBUG_SV.logmsg(l_module_name,'l_line_grossWeight '||l_line_grossWeight||' l_line_netWeight '||l_line_netWeight||' l_line_volume '||l_line_volume);
3190           WSH_DEBUG_SV.logmsg(l_module_name,'l_line_grossWeight_orig '||l_line_grossWeight_orig||' l_line_netWeight_orig '||l_line_netWeight_orig||' l_line_volume_orig '||l_line_volume_orig);
3191         END IF;
3192 
3193         -- Raise warning if delivery detail has null W/V depending on percent_fill_basis_flag
3194         IF (childInfo_rec.container_flag = 'N') THEN
3195           IF (l_param_info.percent_fill_basis_flag = 'W' AND l_line_grossWeight IS NULL) OR
3196              (l_param_info.percent_fill_basis_flag = 'V' AND l_line_volume IS NULL) THEN
3197             FND_MESSAGE.SET_NAME('WSH','WSH_NULL_WEIGHT_VOLUME');
3198             FND_MESSAGE.SET_TOKEN('DELIVERY_DETAIL',childInfo_rec.delivery_detail_id);
3199             wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_WARNING);
3200             l_num_warnings := l_num_warnings + 1;
3201 
3202             IF l_debug_on THEN
3203               WSH_DEBUG_SV.logmsg(l_module_name,'Raising WSH_NULL_WEIGHT_VOLUME Warning for Dd '||immediateChildren_rec.delivery_detail_id);
3204             END IF;
3205           END IF;
3206         END IF;
3207 
3208         -- For parent container
3209         IF immediateChildren_rec.LEVEL = 1
3210         THEN
3211         --{
3212             l_unit_wt      := childInfo_rec.unit_weight;
3213             l_unit_vol     := childInfo_rec.unit_volume;
3214             l_netWeight    := null;
3215             l_volume       := l_line_volume;
3216 
3217             IF childInfo_rec.container_flag IN ('Y', 'C')
3218             THEN
3219             --{
3220                 l_grossWeight  := l_line_grossWeight;
3221             --}
3222             ELSE
3223             --{
3224                 l_grossWeight := null;
3225             --}
3226             END IF;
3227         --}
3228         -- For immediate chidren (container/delivery details)
3229         ELSE  -- immediateChildren_rec.LEVEL = 2, content of a container.
3230         --{
3231             -- For container
3232             IF childInfo_rec.container_flag IN ('Y', 'C')
3233             THEN
3234             --{
3235                 l_line_grossWeight        := NULL;
3236                 l_line_netWeight          := NULL;
3237                 l_line_volume             := NULL;
3238                 l_line_filledVolume       := NULL;
3239                 l_line_contFillPc         := NULL;
3240                 --
3241                 --
3242                 IF l_debug_on THEN
3243                   WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Container_Weight_Volume',WSH_DEBUG_SV.C_PROC_LEVEL);
3244                 END IF;
3245                 Container_Weight_Volume
3246                   (
3247                     p_containerInstanceId  => childInfo_rec.delivery_detail_id,
3248                     p_overrideFlag         => p_overrideFlag,
3249                     p_calcWVIfFrozen       => p_calcWVIfFrozen,
3250                     x_grossWeight          => l_line_grossWeight,
3251                     x_netWeight            => l_line_netWeight,
3252                     x_volume               => l_line_volume,
3253                     p_fillPcFlag           => p_fillPcFlag,
3254                     x_contFillPc           => l_line_contFillPc,
3255                     x_returnStatus         => l_returnStatus,
3256                     x_filledVolume         => l_line_filledVolume,
3257                     p_masterWeightUomCode  => l_masterWeightUomCode,
3258                     p_masterVolumeUomCode  => l_masterVolumeUomCode
3259                   );
3260                 --
3261                 --
3262                 IF l_returnStatus NOT IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS, WSH_UTIL_CORE.G_RET_STS_WARNING)
3263                 THEN
3264                     l_err_container := childInfo_rec.delivery_detail_id;
3265                     RAISE e_wt_vol_fail;
3266                 ELSIF l_returnStatus = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3267                     l_num_warnings := l_num_warnings + 1;
3268                 END IF;
3269                 --
3270             --}
3271             -- For delivery detail
3272             ELSE
3273             --{
3274                 IF p_calcWVIfFrozen = 'N' and childInfo_rec.wv_frozen_flag = 'Y' THEN
3275                   l_line_netWeight    := childInfo_rec.net_weight;
3276                   l_line_grossWeight  := childInfo_rec.gross_weight;
3277                   l_line_volume       := childInfo_rec.volume;
3278                   l_line_FilledVolume := childInfo_rec.volume;
3279                 ELSE
3280                   l_line_netWeight    := l_line_netWeight;
3281                   l_line_grossWeight  := l_line_grossWeight;
3282                   l_line_volume       := l_line_volume;
3283                   l_line_FilledVolume := l_line_volume;
3284                 END IF;
3285 
3286                 IF ((p_overrideFlag = 'Y')  AND
3287                     (NOT (p_calcWVIfFrozen = 'N' and childInfo_rec.wv_frozen_flag = 'Y')) AND
3288                     ((NVL(l_line_grossWeight_orig,-99) <> NVL(childInfo_rec.gross_weight,-99)) OR
3289                      (NVL(l_line_volume_orig,-99) <> NVL(childInfo_rec.volume,-99)))) THEN
3290                   IF l_debug_on THEN
3291                     WSH_DEBUG_SV.logmsg(l_module_name,'Update W/V for DD '||childInfo_rec.delivery_detail_id);
3292                   END IF;
3293                   -- LPN CONV. rv
3294                   -- no call reqd. because this update is for non-container lines
3295                   UPDATE wsh_delivery_details
3296                   SET    net_weight   = l_line_grossWeight_orig,
3297                          gross_weight = l_line_grossWeight_orig,
3298                          volume       = l_line_volume_orig,
3299                          unit_weight  = NVL(unit_weight,childInfo_rec.unit_weight),
3300                          unit_volume  = NVL(unit_volume,childInfo_rec.unit_volume),
3301                          wv_frozen_flag  = 'N',
3302                          last_update_date  = SYSDATE,
3303                          last_updated_by   = FND_GLOBAL.user_id,
3304                          last_update_login = FND_GLOBAL.login_id
3305                   WHERE delivery_detail_id = childInfo_rec.delivery_detail_id;
3306                   --
3307                   --
3308                   IF SQL%NOTFOUND  OR SQL%ROWCOUNT = 0
3309                   THEN
3310                   --{
3311                       FND_MESSAGE.SET_NAME('WSH','WSH_DET_INVALID_DETAIL');
3312                       FND_MESSAGE.SET_TOKEN('DETAIL_ID',childInfo_rec.delivery_detail_id);
3313                       RAISE e_invalid_detail;
3314                   --}
3315                   END IF;
3316 
3317                   l_details_marked.delete;
3318                   l_details_marked(1) := childInfo_rec.delivery_detail_id;
3319 
3320                   IF l_debug_on THEN
3321                     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_LEGS_ACTIONS.MARK_REPRICE_REQUIRED',WSH_DEBUG_SV.C_PROC_LEVEL);
3322                   END IF;
3323 
3324                   WSH_DELIVERY_LEGS_ACTIONS.Mark_Reprice_Required(
3325                     p_entity_type   => 'DELIVERY_DETAIL',
3326                     p_entity_ids    => l_details_marked,
3327                     x_return_status => l_return_status);
3328                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3329                     raise mark_reprice_error;
3330                   END IF;
3331 
3332                   -- OTM R12 : packing ECO
3333                   -- after update wsh_delivery_details sql
3334                   -- if any weight/vol changed, mark the global variable
3335 
3336                   -- G_DELIVERY_TMS_IMPACT is set to Y for the first one
3337                   -- meeting the condition in immediateChildren_rec cursor,
3338                   -- if none of them has different weight, then it stays N
3339                   -- once it's set to Y, it won't be checked again for other
3340                   -- children
3341 
3342                   IF (G_DELIVERY_TMS_IMPACT = 'N' AND
3343                       NVL(l_line_grossWeight_orig,-99) <>
3344                       NVL(childInfo_rec.net_weight,-99)) THEN
3345                     G_DELIVERY_TMS_IMPACT := 'Y';
3346                     IF l_debug_on THEN
3347                       WSH_DEBUG_SV.log(l_module_name,'delivery_detail_id', childInfo_rec.delivery_detail_id);
3348                       WSH_DEBUG_SV.log(l_module_name,'G_DELIVERY_TMS_IMPACT', G_DELIVERY_TMS_IMPACT);
3349                     END IF;
3350                   END IF;
3351                   -- End of OTM R12 : packing ECO
3352                 END IF;
3353 
3354             --}
3355             END IF;
3356             --
3357             -- Accumlate the W/V
3358             IF l_line_netWeight IS NOT NULL THEN
3359               l_netWeight := nvl(l_netWeight,0) + l_line_netWeight;
3360             END IF;
3361             IF (l_line_grossWeight IS NOT NULL) THEN
3362               l_grossWeight := nvl(l_grossWeight,0) + l_line_grossWeight;
3363             END IF;
3364             IF (l_line_volume IS NOT NULL) THEN
3365               l_filledVolume := nvl(l_filledVolume,0) + l_line_volume;
3366             END IF;
3367         --}
3368         END IF;
3369 
3370         IF l_debug_on THEN
3371           WSH_DEBUG_SV.logmsg(l_module_name,'After this iteration LEVEL '||immediateChildren_rec.LEVEL||
3372                                             ' l_grossWeight '||l_grossWeight||' l_netWeight '||l_netWeight||
3373                                             ' l_volume '||l_volume||' l_filledVolume '||l_filledVolume);
3374         END IF;
3375         --
3376         EXCEPTION
3377            when e_continue THEN
3378              NULL;
3379         END;
3380     --}
3381     END LOOP;
3382 
3383     IF l_volume = 0 THEN
3384        l_volume := l_filledVolume;
3385     END IF;
3386     IF l_debug_on THEN
3387        WSH_DEBUG_SV.logmsg(l_module_name,'After LOOP l_grossWeight '||l_grossWeight||' l_netWeight '||l_netWeight||
3388                                          ' l_volume '||l_volume||' l_filledVolume '||l_filledVolume);
3389        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Update_container_Wt_Vol',WSH_DEBUG_SV.C_PROC_LEVEL);
3390     END IF;
3391 
3392     -- IF p_overrideFlag is 'Y' then call update_container_wt_vol to update W/V
3393     IF (p_overrideFlag = 'Y') THEN
3394       update_container_wt_vol(
3395         p_container_instance_id =>   p_containerInstanceId,
3396         p_gross_weight  => l_grossWeight,
3397         p_net_weight    => l_netWeight,
3398         p_volume        => l_volume,
3399         p_filled_volume => l_filledVolume,
3400         p_fill_pc_flag  => p_fillPcFlag,
3401         p_unit_weight   => l_unit_wt,
3402         p_unit_volume   => l_unit_vol,
3403         x_cont_fill_pc  => x_contFillPc,
3404         x_return_status => l_returnStatus);
3405 
3406       IF l_returnStatus NOT IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS, WSH_UTIL_CORE.G_RET_STS_WARNING)
3407       THEN
3408           l_err_container := p_containerInstanceId;
3409           RAISE e_wt_vol_fail;
3410       ELSIF l_returnStatus = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3411         l_num_warnings := l_num_warnings + 1;
3412       END IF;
3413 
3414     END IF;
3415     --
3416 
3417     <<skip_wv_calc>>
3418 
3419     IF l_debug_on THEN
3420       WSH_DEBUG_SV.logmsg(l_module_name,'p_masterWeightUomCode '||p_masterWeightUomCode||' l_masterWeightUomCode '||l_masterWeightUomCode||' l_masterInvItemId '||l_masterInvItemId);
3421     END IF;
3422 
3423     -- Convert the calculated W/V to p_masterWeightUomCode,p_masterVolumeUomCode UOMs
3424     IF p_masterWeightUomCode <> l_masterWeightUomCode THEN
3425       IF l_debug_on THEN
3426         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3427       END IF;
3428       x_grossWeight := WSH_WV_UTILS.convert_uom(
3429                          l_masterWeightUomCode,
3430                          p_masterWeightUomCode,
3431                          l_grossWeight,
3432                          l_masterInvItemId);
3433       IF l_debug_on THEN
3434         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3435       END IF;
3436       x_netWeight := WSH_WV_UTILS.convert_uom(
3437                        l_masterWeightUomCode,
3438                        p_masterWeightUomCode,
3439                        l_netWeight,
3440                        l_masterInvItemId);
3441     ELSE
3442       x_grossWeight := l_grossWeight;
3443       x_netWeight := l_netWeight;
3444     END IF;
3445 
3446     IF p_masterVolumeUomCode <> l_masterVolumeUomCode THEN
3447       IF l_debug_on THEN
3448         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3449       END IF;
3450       x_volume := WSH_WV_UTILS.convert_uom(
3451                     l_masterVolumeUomCode,
3452                     p_masterVolumeUomCode,
3453                     l_volume,
3454                     l_masterInvItemId);
3455       IF l_debug_on THEN
3456         WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
3457       END IF;
3458       x_filledVolume := WSH_WV_UTILS.convert_uom(
3459                           l_masterVolumeUomCode,
3460                           p_masterVolumeUomCode,
3461                           l_filledVolume,
3462                           l_masterInvItemId);
3463     ELSE
3464       x_volume := l_volume;
3465       x_filledVolume := l_filledVolume;
3466     END IF;
3467     --
3468     IF l_num_warnings > 0 THEN
3469       x_returnStatus := WSH_UTIL_CORE.G_RET_STS_WARNING;
3470     ELSE
3471       x_returnStatus := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3472     END IF;
3473 
3474     IF l_debug_on THEN
3475        WSH_DEBUG_SV.logmsg(l_module_name,'x_grossWeight '||x_grossWeight||' x_netWeight '||x_netWeight||
3476                                          ' x_volume '||x_volume||' x_filledVolume '||x_filledVolume||
3477                                          ' x_contFillPc '||x_contFillPc||' x_returnStatus '||x_returnStatus);
3478     END IF;
3479 --}
3480 IF l_debug_on THEN
3481     WSH_DEBUG_SV.pop(l_module_name);
3482 END IF;
3483 --
3484 EXCEPTION
3485   WHEN mark_reprice_error then
3486    FND_MESSAGE.Set_Name('WSH', 'WSH_REPRICE_REQUIRED_ERR');
3487    x_returnStatus := l_return_status;
3488    WSH_UTIL_CORE.add_message (x_returnStatus);
3489    --
3490    -- Debug Statements
3491    --
3492    IF l_debug_on THEN
3493        WSH_DEBUG_SV.logmsg(l_module_name,'MARK_REPRICE_ERROR exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
3494        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:MARK_REPRICE_ERROR');
3495    END IF;
3496    --
3497   WHEN  e_invalid_detail THEN
3498         x_returnStatus := WSH_UTIL_CORE.G_RET_STS_ERROR;
3499         WSH_UTIL_CORE.add_message (x_returnStatus);
3500    --
3501    -- Debug Statements
3502    --
3503    IF l_debug_on THEN
3504        WSH_DEBUG_SV.logmsg(l_module_name,'E_INVALID_DETAIL exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
3505        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:E_INVALID_DETAIL');
3506    END IF;
3507    --
3508   WHEN  e_wt_vol_fail THEN
3509         FND_MESSAGE.Set_Name('WSH','WSH_UPDATE_WTVOL_FAIL');
3510         FND_MESSAGE.Set_Token('LPN', l_err_container);
3511         x_returnStatus := WSH_UTIL_CORE.G_RET_STS_ERROR;
3512    WSH_UTIL_CORE.add_message (x_returnStatus);
3513    --
3514    -- Debug Statements
3515    --
3516    IF l_debug_on THEN
3517        WSH_DEBUG_SV.logmsg(l_module_name,'E_WT_VOL_FAIL exception has occured.',WSH_DEBUG_SV.C_EXCEP_LEVEL);
3518        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:E_WT_VOL_FAIL');
3519    END IF;
3520    --
3521   WHEN e_abort THEN
3522     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CONTAINER_WEIGHT_VOLUME');
3523     x_returnStatus := WSH_UTIL_CORE.G_RET_STS_ERROR;
3524     --
3525     -- Debug Statements
3526     --
3527     IF l_debug_on THEN
3528         WSH_DEBUG_SV.pop(l_module_name);
3529     END IF;
3530 
3531   WHEN Others THEN
3532     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CONTAINER_WEIGHT_VOLUME');
3533     x_returnStatus := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3534     --
3535     -- Debug Statements
3536     --
3537     IF l_debug_on THEN
3538         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
3539         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
3540     END IF;
3541     --
3542 END Container_Weight_Volume;
3543 
3544 -- Start of comments
3545 -- API name : Container_Weight_Volume
3546 -- Type     : Private
3547 -- Pre-reqs : None.
3548 -- Function : Wrapper for the base Container_Weight_Volume (Called from TPA API)
3549 -- Parameters :
3550 -- IN:
3551 --    p_container_instance_id IN NUMBER Required
3552 --    p_override_flag         IN VARCHAR2
3553 --      'Y' if the detail needs to be updated with the calculated W/V
3554 --    p_calc_wv_if_frozen     IN VARCHAR2
3555 --      'Y' if manual W/V can be overriden
3556 --    p_fill_pc_flag          IN  VARCHAR2
3557 --      'Y' if fill% needs to be calculated
3558 -- OUT:
3559 --    x_gross_weight OUT NUMBER
3560 --       gives the gross weight of container
3561 --    x_net_weight OUT NUMBER
3562 --       gives the net weight of container
3563 --    x_volume OUT NUMBER
3564 --       gives the volume of container
3565 --    x_cont_fill_pc  OUT NUMBER
3566 --       gives the Fill% of container
3567 --    x_return_status OUT VARCHAR2 Required
3568 --       give the return status of API
3569 -- Version : 1.0
3570 -- End of comments
3571 
3572 PROCEDURE Container_Weight_Volume (
3573   p_container_instance_id IN NUMBER,
3574   p_override_flag IN VARCHAR2,
3575   x_gross_weight  OUT NOCOPY  NUMBER,
3576   x_net_weight    OUT NOCOPY  NUMBER,
3577   x_volume        OUT NOCOPY  NUMBER,
3578   p_fill_pc_flag  IN VARCHAR2,
3579   x_cont_fill_pc  OUT NOCOPY  NUMBER,
3580   x_return_status OUT NOCOPY  VARCHAR2,
3581   p_calc_wv_if_frozen IN VARCHAR2) IS
3582 
3583 
3584 l_vol number;
3585 --
3586 l_debug_on BOOLEAN;
3587 --
3588 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CONTAINER_WEIGHT_VOLUME';
3589 --
3590 BEGIN
3591   --
3592   -- Debug Statements
3593   --
3594   --
3595   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
3596   --
3597   IF l_debug_on IS NULL
3598   THEN
3599       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
3600   END IF;
3601   --
3602   IF l_debug_on THEN
3603       WSH_DEBUG_SV.push(l_module_name);
3604       --
3605       WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_INSTANCE_ID',P_CONTAINER_INSTANCE_ID);
3606       WSH_DEBUG_SV.log(l_module_name,'P_OVERRIDE_FLAG',P_OVERRIDE_FLAG);
3607       WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
3608       WSH_DEBUG_SV.log(l_module_name,'P_FILL_PC_FLAG',P_FILL_PC_FLAG);
3609   END IF;
3610   --
3611   Container_Weight_Volume
3612     (
3613       p_containerInstanceId => p_container_instance_id,
3614       p_overrideFlag        => p_override_flag,
3615       p_calcWVIfFrozen      => p_calc_wv_if_frozen,
3616       x_grossWeight         => x_gross_weight,
3617       x_netWeight           => x_net_weight,
3618       x_volume              => x_volume,
3619       p_fillPcFlag          => p_fill_pc_flag,
3620       x_contFillPc          => x_cont_fill_pc,
3621       x_returnStatus        => x_return_status,
3622       x_filledVolume        => l_vol
3623     );
3624 /*
3625 EXCEPTION
3626 
3627   WHEN Others THEN
3628    WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CONTAINER_WEIGHT_VOLUME');
3629    x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3630 */
3631 --
3632 -- Debug Statements
3633 --
3634 IF l_debug_on THEN
3635     WSH_DEBUG_SV.pop(l_module_name);
3636 END IF;
3637 --
3638 END Container_Weight_Volume;
3639 
3640 -- J: W/V changes
3641 
3642 -- Start of comments
3643 -- API name : Container_Weight_Volume
3644 -- Type     : Private
3645 -- Pre-reqs : None.
3646 -- Function : Calculates Weight and Volume of Container
3647 --            If p_override_flag is 'Y' then the calculated W/V is updated on Container
3648 --            Otherwise, the API returns the calculated W/V
3649 --            If p_post_process_flag is 'Y' then calls post processing API
3650 -- Parameters :
3651 -- IN:
3652 --    p_container_instance_id IN NUMBER Required
3653 --    p_override_flag         IN VARCHAR2
3654 --      'Y' if the detail needs to be updated with the calculated W/V
3655 --    p_fill_pc_flag          IN  VARCHAR2
3656 --      'Y' if fill% needs to be calculated
3657 --    p_post_process_flag     IN VARCHAR2
3658 --      'Y' if W/V post processing is required
3659 --    p_calc_wv_if_frozen     IN VARCHAR2
3660 --      'Y' if manual W/V can be overriden
3661 -- OUT:
3662 --    x_gross_weight OUT NUMBER
3663 --       gives the gross weight of container
3664 --    x_net_weight OUT NUMBER
3665 --       gives the net weight of container
3666 --    x_volume OUT NUMBER
3667 --       gives the volume of container
3668 --    x_cont_fill_pc  OUT NUMBER
3669 --       gives the Fill% of container
3670 --    x_return_status OUT VARCHAR2 Required
3671 --       give the return status of API
3672 -- Version : 1.0
3673 -- End of comments
3674 
3675 PROCEDURE Container_Weight_Volume (
3676   p_container_instance_id IN NUMBER,
3677   p_override_flag IN VARCHAR2,
3678   p_fill_pc_flag  IN VARCHAR2,
3679   p_post_process_flag IN VARCHAR2,
3680   p_calc_wv_if_frozen IN VARCHAR2 DEFAULT 'Y',
3681   x_gross_weight  OUT NOCOPY  NUMBER,
3682   x_net_weight    OUT NOCOPY  NUMBER,
3683   x_volume        OUT NOCOPY  NUMBER,
3684   x_cont_fill_pc  OUT NOCOPY  NUMBER,
3685   x_return_status OUT NOCOPY  VARCHAR2) IS
3686 
3687 l_org_gross_wt number;
3688 l_org_net_wt   number;
3689 l_org_vol      number;
3690 l_org_fill_pc  number;
3691 l_organization_id NUMBER;
3692 l_frozen_flag  VARCHAR2(1);
3693 
3694 l_return_status VARCHAR2(100);
3695 l_debug_on     BOOLEAN;
3696 l_module_name  CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CONTAINER_WEIGHT_VOLUME';
3697 --lpn conv
3698 l_wms_org      VARCHAR2(10) := 'N';
3699 
3700 BEGIN
3701 
3702   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
3703   IF l_debug_on IS NULL
3704   THEN
3705       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
3706   END IF;
3707   IF l_debug_on THEN
3708       WSH_DEBUG_SV.push(l_module_name);
3709       WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_INSTANCE_ID',P_CONTAINER_INSTANCE_ID);
3710       WSH_DEBUG_SV.log(l_module_name,'P_OVERRIDE_FLAG',P_OVERRIDE_FLAG);
3711       WSH_DEBUG_SV.log(l_module_name,'P_FILL_PC_FLAG',P_FILL_PC_FLAG);
3712       WSH_DEBUG_SV.log(l_module_name,'P_POST_PROCESS_FLAG',P_POST_PROCESS_FLAG);
3713       WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
3714   END IF;
3715   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3716 
3717   -- Get the container info
3718   BEGIN
3719     SELECT gross_weight,
3720            net_weight,
3721            volume,
3722            fill_percent,
3723            organization_id,
3724            NVL(wv_frozen_flag,'Y')
3725     INTO   l_org_gross_wt,
3726            l_org_net_wt,
3727            l_org_vol,
3728            l_org_fill_pc,
3729            l_organization_id,
3730            l_frozen_flag
3731     FROM   wsh_delivery_details
3732     WHERE  delivery_detail_id = p_container_instance_id
3733     AND    container_flag IN ('Y', 'C');
3734     EXCEPTION
3735       WHEN NO_DATA_FOUND THEN
3736         FND_MESSAGE.SET_NAME('WSH', 'WSH_DET_INVALID_DETAIL');
3737         FND_MESSAGE.SET_TOKEN('DETAIL_ID',p_container_instance_id);
3738         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
3739         IF l_debug_on THEN
3740           WSH_DEBUG_SV.pop(l_module_name);
3741         END IF;
3742         return;
3743   END;
3744 
3745   --lpn conv
3746   IF NVL(l_frozen_flag,'Y') = 'Y' THEN
3747      l_wms_org :=
3748             wsh_util_validate.check_wms_org(l_organization_id);
3749      IF l_wms_org = 'Y' THEN
3750         l_frozen_flag := 'N';
3751      END IF;
3752   END IF;
3753 
3754   IF l_debug_on THEN
3755     WSH_DEBUG_SV.logmsg(l_module_name,'DD original wts are Gross '||l_org_gross_wt||' Net '||l_org_net_wt||' Vol '||l_org_vol||' Frozen '||l_frozen_flag);
3756   END IF;
3757 
3758   IF (P_CALC_WV_IF_FROZEN = 'N' AND l_frozen_flag = 'Y') THEN
3759     x_gross_weight := l_org_gross_wt;
3760     x_net_weight   := l_org_net_wt;
3761     x_volume       := l_org_vol;
3762     x_cont_fill_pc := l_org_fill_pc;
3763 
3764     IF l_debug_on THEN
3765       WSH_DEBUG_SV.log(l_module_name,'WV calculation not allowed on '||p_container_instance_id||'. Returning existing W/V');
3766       WSH_DEBUG_SV.pop(l_module_name);
3767     END IF;
3768     return;
3769   END IF;
3770 
3771   IF l_debug_on THEN
3772       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TPA_CONTAINER_PKG.container_weight_volume',WSH_DEBUG_SV.C_PROC_LEVEL);
3773   END IF;
3774 
3775   -- Call WSH_TPA_CONTAINER_PKG.container_weight_volume to calculate W/V
3776   WSH_TPA_CONTAINER_PKG.container_weight_volume (
3777     p_container_instance_id => p_container_instance_id,
3778     p_override_flag         => p_override_flag,
3779     p_calc_wv_if_frozen     => p_calc_wv_if_frozen,
3780     p_fill_pc_flag          => p_fill_pc_flag,
3781     x_gross_weight          => x_gross_weight,
3782     x_net_weight            => x_net_weight,
3783     x_volume                => x_volume,
3784     x_cont_fill_pc          => x_cont_fill_pc,
3785     x_return_status         => l_return_status);
3786 
3787   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
3788     x_return_status := l_return_status;
3789     IF l_debug_on THEN
3790       WSH_DEBUG_SV.logmsg(l_module_name,'WSH_TPA_CONTAINER_PKG.container_weight_volume returned '||l_return_status);
3791       WSH_DEBUG_SV.pop(l_module_name);
3792      END IF;
3793      return;
3794   END IF;
3795 
3796   -- If p_override_flag is 'Y and ((p_post_process_flag is 'Y' and the new and old W/V differ)
3797   -- then call DD_WV_Post_Process API
3798   IF (p_override_flag = 'Y' AND p_post_process_flag = 'Y' AND
3799       (  (NVL(x_gross_weight,0) <> NVL(l_org_gross_wt,0)) OR
3800          (NVL(x_net_weight,0)   <> NVL(l_org_net_wt,0)) OR
3801          (NVL(x_volume,0)       <> NVL(l_org_vol,0)))) THEN
3802     IF l_debug_on THEN
3803       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit DD_WV_Post_Process',WSH_DEBUG_SV.C_PROC_LEVEL);
3804     END IF;
3805 
3806     DD_WV_Post_Process(
3807       p_delivery_detail_id => p_container_instance_id,
3808       p_diff_gross_wt      => NVL(x_gross_weight,0) - NVL(l_org_gross_wt,0),
3809       p_diff_net_wt        => NVL(x_net_weight,0) - NVL(l_org_net_wt,0),
3810       p_diff_fill_volume   => NVL(x_volume,0) - NVL(l_org_vol,0),
3811       x_return_status      => l_return_status);
3812 
3813     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3814       x_return_status := l_return_status;
3815       IF l_debug_on THEN
3816         WSH_DEBUG_SV.logmsg(l_module_name,'DD_WV_Post_Process returned '||l_return_status);
3817         WSH_DEBUG_SV.pop(l_module_name);
3818       END IF;
3819       return;
3820     END IF;
3821   END IF;
3822 
3823   IF l_debug_on THEN
3824     WSH_DEBUG_SV.logmsg(l_module_name,'x_return_status '||x_return_status);
3825     WSH_DEBUG_SV.pop(l_module_name);
3826   END IF;
3827 
3828 EXCEPTION
3829   WHEN Others THEN
3830     WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CONTAINER_WEIGHT_VOLUME');
3831     x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3832 
3833     IF l_debug_on THEN
3834       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL)
3835 ;
3836       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
3837     END IF;
3838 
3839 END Container_Weight_Volume;
3840 
3841 -- J: W/V changes
3842 
3843 -- Start of comments
3844 -- API name : Detail_Weight_Volume
3845 -- Type     : Public
3846 -- Pre-reqs : None.
3847 -- Function : Calculates Weight and Volume of Multiple Delivery Details
3848 --            If p_update_flag is 'Y' then the calculated W/V is updated on Delivery Detail
3849 --            Otherwise, the API returns the calculated W/V
3850 --            If p_calc_wv_if_frozen is 'N' then W/V will be calculated not be calculated
3851 --            for entities whose W/V is manually entered
3852 --            OTM R12 : packing ECO
3853 --                      This procedure is modified to keep track of delivery
3854 --                      detail wt/vol updates. Called first by WSHDDGPB
3855 --                      (WSH_DELIVERY_DETAILS_GRP.Delivery_Detail_Action),
3856 --                      so the logic of checking G_RESET_WV is here.
3857 -- Parameters :
3858 -- IN:
3859 --    p_detail_rows        IN wsh_util_core.id_tab_type REQUIRED
3860 --    p_update_flag        IN VARCHAR2
3861 --      'Y' if the detail needs to be updated with the calculated W/V
3862 --    p_calc_wv_if_frozen  IN VARCHAR2
3863 --      'Y' if manual W/V can be overriden
3864 -- OUT:
3865 --    x_return_status OUT VARCHAR2 Required
3866 --       gives the return status of API
3867 -- Version : 1.0
3868 -- End of comments
3869 
3870 PROCEDURE Detail_Weight_Volume(
3871            p_detail_rows    IN wsh_util_core.id_tab_type,
3872            p_override_flag  IN VARCHAR2,
3873            p_calc_wv_if_frozen IN VARCHAR2 DEFAULT 'Y',
3874            x_return_status  OUT NOCOPY  VARCHAR2) IS
3875 
3876 CURSOR c_container_flag(x_id NUMBER) IS
3877 SELECT container_flag
3878   FROM wsh_delivery_details
3879  WHERE delivery_detail_id = x_id;
3880 
3881 -- OTM R12 : packing ECO
3882 CURSOR c_get_delivery_info(p_detail_id IN NUMBER) IS
3883 SELECT wda.delivery_id
3884   FROM WSH_DELIVERY_ASSIGNMENTS wda,
3885        WSH_NEW_DELIVERIES wnd
3886 WHERE wda.delivery_detail_id = p_detail_id
3887   AND wda.delivery_id = wnd.delivery_id
3888   AND wnd.tms_interface_flag IN (WSH_NEW_DELIVERIES_PVT.C_TMS_CREATE_IN_PROCESS,
3889                                  WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_IN_PROCESS,
3890                                  WSH_NEW_DELIVERIES_PVT.C_TMS_AWAITING_ANSWER,
3891                                  WSH_NEW_DELIVERIES_PVT.C_TMS_ANSWER_RECEIVED)
3892   AND NVL(wnd.ignore_for_planning, 'N') = 'N';
3893 
3894 l_delivery_id          WSH_NEW_DELIVERIES.DELIVERY_ID%TYPE;
3895 l_delivery_id_tab      WSH_UTIL_CORE.ID_TAB_TYPE;
3896 l_interface_flag_tab   WSH_UTIL_CORE.COLUMN_TAB_TYPE;
3897 l_count                NUMBER;
3898 l_return_status        VARCHAR2(1);
3899 -- End of OTM R12 : packing ECO
3900 
3901 l_net_weight           NUMBER;
3902 l_gross_weight         NUMBER;
3903 l_volume               NUMBER;
3904 l_fill_pc              NUMBER;
3905 l_num_error            NUMBER := 0;
3906 l_flag                 WSH_DELIVERY_DETAILS.CONTAINER_FLAG%TYPE;
3907 
3908 others EXCEPTION;
3909 
3910 l_debug_on BOOLEAN;
3911 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DETAIL_WEIGHT_VOLUME';
3912 --
3913 BEGIN
3914 
3915    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
3916    IF l_debug_on IS NULL
3917    THEN
3918        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
3919    END IF;
3920    IF l_debug_on THEN
3921        WSH_DEBUG_SV.push(l_module_name);
3922        WSH_DEBUG_SV.log(l_module_name,'P_OVERRIDE_FLAG',P_OVERRIDE_FLAG);
3923        WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
3924    END IF;
3925 
3926    IF (p_detail_rows.count = 0) THEN
3927     raise others;
3928    END IF;
3929 
3930    -- OTM R12 : packing ECO
3931    l_count := 0;
3932    -- End of OTM R12 : packing ECO
3933 
3934    FOR i IN 1..p_detail_rows.count LOOP
3935 
3936      -- OTM R12 : packing ECO
3937      -- for each detail in the loop, enable the check for delivery update
3938      IF (WSH_WV_UTILS.G_RESET_WV = 'Y') THEN
3939 
3940        OPEN c_get_delivery_info(p_detail_rows(i));
3941        FETCH c_get_delivery_info INTO l_delivery_id;
3942 
3943        IF (c_get_delivery_info%NOTFOUND) THEN
3944 	 l_delivery_id := NULL;
3945        END IF;
3946        CLOSE c_get_delivery_info;
3947 
3948        IF l_debug_on THEN
3949          WSH_DEBUG_SV.log(l_module_name, 'G_RESET_WV', WSH_WV_UTILS.G_RESET_WV);
3950          WSH_DEBUG_SV.log(l_module_name,'l_delivery_id', l_delivery_id);
3951        END IF;
3952 
3953        -- need to check for update only if delivery is include for planning and
3954        -- tms_interface_flag is in CP UP AW AR state, which will be set to UR
3955        IF l_delivery_id IS NOT NULL THEN
3956          G_DELIVERY_TMS_IMPACT := 'N';
3957        END IF;
3958      END IF;
3959      -- End of OTM R12 : packing ECO
3960 
3961      OPEN c_container_flag(p_detail_rows(i));
3962      FETCH c_container_flag INTO l_flag;
3963      IF c_container_flag%NOTFOUND THEN
3964        CLOSE c_container_flag;
3965        raise others;
3966      END IF;
3967      CLOSE c_container_flag;
3968 
3969      IF l_flag in ('Y', 'C') THEN
3970 
3971        IF l_debug_on THEN
3972          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit CONTAINER_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
3973        END IF;
3974        --
3975        Container_Weight_Volume (
3976          p_container_instance_id => p_detail_rows(i),
3977          p_override_flag         => p_override_flag,
3978          p_fill_pc_flag          => 'Y',
3979          p_post_process_flag     => 'Y',
3980          p_calc_wv_if_frozen     => p_calc_wv_if_frozen,
3981          x_gross_weight          => l_gross_weight,
3982          x_net_weight            => l_net_weight,
3983          x_volume                => l_volume,
3984          x_cont_fill_pc          => l_fill_pc,
3985          x_return_status         => x_return_status);
3986 
3987      ELSE
3988 
3989        IF l_debug_on THEN
3990          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.DETAIL_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
3991        END IF;
3992        --
3993        Detail_Weight_Volume(
3994          p_delivery_detail_id => p_detail_rows(i),
3995          p_update_flag        => p_override_flag,
3996          p_post_process_flag  => 'Y',
3997          p_calc_wv_if_frozen  => p_calc_wv_if_frozen,
3998          x_net_weight         => l_net_weight,
3999          x_volume             => l_volume,
4000          x_return_status      => x_return_status);
4001 
4002      END IF;  -- l_flag = 'Y'
4003 
4004      IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
4005        FND_MESSAGE.SET_NAME('WSH','WSH_DET_WT_VOL_ERROR');
4006        FND_MESSAGE.SET_TOKEN('DET_NAME',p_detail_rows(i));
4007        x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4008        wsh_util_core.add_message(x_return_status);
4009        l_num_error := l_num_error + 1;
4010      END IF;
4011 
4012      -- OTM R12 : packing ECO
4013      -- for the given delivery_id, G_DELIVERY_TMS_IMPACT is changed from N to Y
4014      IF (WSH_WV_UTILS.G_RESET_WV ='Y' AND
4015          G_DELIVERY_TMS_IMPACT = 'Y' AND
4016          l_delivery_id IS NOT NULL) THEN
4017 
4018        l_count := l_count + 1;
4019        l_delivery_id_tab(l_count) := l_delivery_id;
4020        l_interface_flag_tab(l_count) := WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_REQUIRED;
4021        IF l_debug_on THEN
4022          WSH_DEBUG_SV.log(l_module_name, 'l_count', l_count);
4023          WSH_DEBUG_SV.log(l_module_name, 'l_delivery_id_tab', l_delivery_id_tab(l_count));
4024          WSH_DEBUG_SV.log(l_module_name, 'l_interface_flag_tab', l_interface_flag_tab(l_count));
4025        END IF;
4026      END IF;
4027 
4028      --resetting the flag back to default after done with current detail
4029      IF (G_DELIVERY_TMS_IMPACT = 'N') THEN
4030        G_DELIVERY_TMS_IMPACT := 'Y';
4031      END IF;
4032 
4033      -- End of OTM R12 : packing ECO
4034    END LOOP;
4035 
4036    -- OTM R12 : packing ECO
4037    -- There can be the same delivery_id's in l_delivery_id_tab
4038    IF (l_count > 0) THEN
4039      WSH_NEW_DELIVERIES_PVT.update_tms_interface_flag(
4040                             p_delivery_id_tab        => l_delivery_id_tab,
4041                             p_tms_interface_flag_tab => l_interface_flag_tab,
4042                             x_return_status          => l_return_status);
4043 
4044      IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
4045                              WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
4046        x_return_status := l_return_status;
4047        IF l_debug_on THEN
4048          WSH_DEBUG_SV.log(l_module_name, 'l_return_status', l_return_status);
4049          WSH_DEBUG_SV.pop(l_module_name, 'UPDATE_TMS_INTERFACE_FLAG ERROR');
4050        END IF;
4051        RETURN;
4052      END IF;
4053    END IF;
4054    -- End of OTM R12 : packing ECO
4055 
4056    IF (p_detail_rows.count > 1) THEN
4057 
4058     IF (l_num_error > 0) THEN
4059 
4060        FND_MESSAGE.SET_NAME('WSH','WSH_DEL_WT_VOL_SUMMARY');
4061        FND_MESSAGE.SET_TOKEN('NUM_ERROR',l_num_error);
4062        FND_MESSAGE.SET_TOKEN('NUM_SUCCESS',p_detail_rows.count - l_num_error);
4063 
4064        IF (p_detail_rows.count = l_num_error) THEN
4065         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4066        ELSE
4067           x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4068        END IF;
4069 
4070        wsh_util_core.add_message(x_return_status);
4071 
4072     ELSE
4073        x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4074     END IF;
4075 
4076    END IF;
4077 
4078    IF l_debug_on THEN
4079      WSH_DEBUG_SV.pop(l_module_name);
4080    END IF;
4081 
4082 EXCEPTION
4083    WHEN others THEN
4084      -- OTM R12 : packing ECO
4085      IF (c_get_delivery_info%ISOPEN) THEN
4086        CLOSE c_get_delivery_info;
4087      END IF;
4088      -- End of OTM R12 : packing ECO
4089      wsh_util_core.default_handler ('WSH_WV_UTILS.DETAIL_WEIGHT_VOLUME');
4090      x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4091 
4092      IF l_debug_on THEN
4093        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4094        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4095      END IF;
4096 
4097 END Detail_Weight_Volume;
4098 
4099 PROCEDURE Calc_Cont_Fill_Pc (
4100  p_container_instance_id IN NUMBER,
4101  p_update_flag IN VARCHAR2,
4102  p_fill_pc_basis IN VARCHAR2,
4103  x_fill_percent OUT NOCOPY  NUMBER,
4104  x_return_status OUT NOCOPY  VARCHAR2) IS
4105 
4106 
4107  CURSOR Get_Cont_Info (v_cont_instance_id NUMBER) IS
4108  SELECT inventory_item_id, gross_weight, net_weight,
4109  -- J: W/V Changes
4110         filled_volume,
4111         nvl(unit_weight,0),
4112    weight_uom_code, volume_uom_code, organization_id,
4113    maximum_load_weight, maximum_volume, fill_percent, container_flag, container_name,
4114    nvl(line_direction, 'O') line_direction, organization_id
4115  FROM wsh_delivery_details
4116  WHERE delivery_detail_id = v_cont_instance_id;
4117 
4118  CURSOR Get_Cont_Contents (v_cont_instance_id NUMBER, v_org_id NUMBER) IS
4119  SELECT wda.delivery_detail_id,container_flag,
4120       inventory_item_id,
4121       NVL(received_quantity,    -- J-IB-NPARIKH
4122           nvl(shipped_quantity, NVL(picked_quantity, requested_quantity))) pack_qty
4123  FROM wsh_delivery_assignments_v wda,
4124     wsh_delivery_details wdd
4125  WHERE wda.parent_delivery_detail_id = v_cont_instance_id AND
4126      wdd.delivery_detail_id = wda.delivery_detail_id;
4127 
4128 
4129  CURSOR Get_Fill_Basis (v_org_id NUMBER) IS
4130  SELECT percent_fill_basis_flag
4131  FROM wsh_shipping_parameters
4132  WHERE organization_id = v_org_id;
4133 
4134  l_cont_item_id      NUMBER;
4135  l_cont_gross_wt  NUMBER;
4136  l_cont_net_wt    NUMBER;
4137  l_cont_wt_uom    VARCHAR2(3);
4138  l_cont_vol    NUMBER;
4139  l_cont_unit_wt   NUMBER;
4140  l_cont_vol_uom      VARCHAR2(3);
4141  l_cont_max_load  NUMBER;
4142  l_cont_max_vol      NUMBER;
4143  l_cont_org_id       NUMBER;
4144  l_cont_fill_pc      NUMBER;
4145  l_cont_name         VARCHAR2(32767);
4146 
4147  l_dlvb_id     NUMBER;
4148  l_dlvb_det_id    NUMBER;
4149  l_dlvb_cont_id      NUMBER;
4150  l_dlvb_type      VARCHAR2(1);
4151  l_dlvb_del_id    NUMBER;
4152  l_dlvb_inv_id    NUMBER;
4153  l_dlvb_pack_qty  NUMBER;
4154 
4155  l_max_load_qty      NUMBER;
4156  l_cont_qty    NUMBER;
4157  l_fill_pc_basis  VARCHAR2(1);
4158  l_wt_uom      VARCHAR2(3);
4159  l_cont_flag      VARCHAR2(1);
4160 
4161 
4162 -- LPN CONV. rv
4163 l_line_direction  VARCHAR2(10);
4164 l_organization_id NUMBER;
4165 l_wms_org         VARCHAR2(10) := 'N';
4166 l_sync_tmp_rec    wsh_glbl_var_strct_grp.sync_tmp_rec_type;
4167 l_return_status   VARCHAR2(10);
4168 l_num_warnings    NUMBER := 0;
4169 -- LPN CONV. rv
4170 --
4171 l_debug_on BOOLEAN;
4172 --
4173 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CALC_CONT_FILL_PC';
4174 --
4175 BEGIN
4176 
4177  --
4178  -- Debug Statements
4179  --
4180  --
4181  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
4182  --
4183  IF l_debug_on IS NULL
4184  THEN
4185      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
4186  END IF;
4187  --
4188  IF l_debug_on THEN
4189      WSH_DEBUG_SV.push(l_module_name);
4190      --
4191      WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_INSTANCE_ID',P_CONTAINER_INSTANCE_ID);
4192      WSH_DEBUG_SV.log(l_module_name,'P_UPDATE_FLAG',P_UPDATE_FLAG);
4193      WSH_DEBUG_SV.log(l_module_name,'P_FILL_PC_BASIS',P_FILL_PC_BASIS);
4194  END IF;
4195  --
4196  OPEN Get_Cont_Info (p_container_instance_id);
4197 
4198  FETCH Get_Cont_Info INTO
4199    l_cont_item_id,
4200    l_cont_gross_wt,
4201    l_cont_net_wt,
4202    l_cont_vol,
4203    l_cont_unit_wt,
4204    l_cont_wt_uom,
4205    l_cont_vol_uom,
4206    l_cont_org_id,
4207    l_cont_max_load,
4208    l_cont_max_vol,
4209    l_cont_fill_pc,
4210    l_cont_flag,
4211    l_cont_name,
4212    l_line_direction,
4213    l_organization_id;
4214 
4215  IF Get_Cont_Info%NOTFOUND THEN
4216    CLOSE Get_Cont_Info;
4217    FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_CONTAINER');
4218    x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4219    --
4220    -- Debug Statements
4221    --
4222    IF l_debug_on THEN
4223        WSH_DEBUG_SV.pop(l_module_name);
4224    END IF;
4225    --
4226    return;
4227  END IF;
4228 
4229  CLOSE Get_Cont_Info;
4230 
4231  IF l_debug_on THEN
4232    WSH_DEBUG_SV.log(l_module_name,'Cont flag'||l_cont_flag);
4233  END IF;
4234  --
4235  -- Bug 3562797 jckwok
4236  -- Code to get fill percent basis moved up here because we want to check whether
4237  -- it is set to 'N' as early as possible.
4238  --
4239  l_fill_pc_basis := p_fill_pc_basis;
4240 
4241  IF l_fill_pc_basis IS NULL THEN
4242    OPEN Get_Fill_Basis (l_cont_org_id);
4243    FETCH Get_Fill_Basis INTO l_fill_pc_basis;
4244    IF Get_Fill_Basis%NOTFOUND THEN
4245       CLOSE Get_Fill_Basis;
4246       FND_MESSAGE.SET_NAME('WSH','WSH_FILL_BASIS_UNDEFINED');
4247       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4248       --
4249       -- Debug Statements
4250       --
4251       IF l_debug_on THEN
4252          WSH_DEBUG_SV.pop(l_module_name);
4253       END IF;
4254       --
4255       return;
4256    END IF;
4257       CLOSE Get_Fill_Basis;
4258  END IF;
4259  --
4260  -- Debug Statements
4261  --
4262  IF l_debug_on THEN
4263    WSH_DEBUG_SV.log(l_module_name,'fill pc basis',l_fill_pc_basis);
4264  END IF;
4265  --
4266  -- If the Shipping Parameter Fill Basis is set to None, then simply return sucess and log a message.
4267  --
4268  IF (l_fill_pc_basis = 'N') THEN
4269     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4270     --
4271     -- Debug Statements
4272     --
4273     IF l_debug_on THEN
4274        IF l_debug_on THEN
4275           WSH_DEBUG_SV.logmsg(l_module_name, 'Fill PC is not calculated because Fill Percent Basis flag is set to None');
4276        END IF;
4277        WSH_DEBUG_SV.pop(l_module_name);
4278     END IF;
4279     --
4280     return;
4281  END IF;
4282  -- end of bug 3562797 changes
4283 
4284  IF (nvl(l_cont_flag,'N') = 'N') THEN
4285     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4286     --
4287     -- Debug Statements
4288     --
4289     IF l_debug_on THEN
4290         WSH_DEBUG_SV.pop(l_module_name);
4291     END IF;
4292     --
4293     return;
4294  END IF;
4295 
4296  IF l_debug_on THEN
4297    WSH_DEBUG_SV.log(l_module_name,'Cont item '||l_cont_item_id);
4298  END IF;
4299  /* wms change: Return Null if LPN is grouping  */
4300  IF (l_cont_item_id IS NULL) THEN
4301     x_return_status := NULL;
4302     --
4303     -- Debug Statements
4304     --
4305     IF l_debug_on THEN
4306         WSH_DEBUG_SV.pop(l_module_name);
4307     END IF;
4308     --
4309     return;
4310  END IF;
4311 
4312  IF l_fill_pc_basis = 'W' THEN
4313    IF nvl(l_cont_max_load, 0 ) <= 0 THEN
4314      FND_MESSAGE.SET_NAME('WSH', 'WSH_CONT_FILL_PC_ERROR');
4315      FND_MESSAGE.SET_TOKEN('CONT_NAME',l_cont_name);
4316      wsh_util_core.add_message(wsh_util_core.g_ret_sts_warning);
4317      RAISE WSH_UTIL_CORE.G_EXC_WARNING;
4318    END IF;
4319  ELSIF l_fill_pc_basis = 'V' THEN
4320    IF nvl(l_cont_max_vol, 0 ) <= 0 THEN
4321      FND_MESSAGE.SET_NAME('WSH', 'WSH_CONT_FILL_PC_ERROR');
4322      FND_MESSAGE.SET_TOKEN('CONT_NAME',l_cont_name);
4323      wsh_util_core.add_message(wsh_util_core.g_ret_sts_warning);
4324      RAISE WSH_UTIL_CORE.G_EXC_WARNING;
4325    END IF;
4326  END IF;
4327 
4328  IF l_debug_on THEN
4329    WSH_DEBUG_SV.log(l_module_name,'Fill pc basis --'||l_fill_pc_basis);
4330  END IF;
4331 
4332  IF l_fill_pc_basis = 'W' THEN
4333    IF l_debug_on THEN
4334      WSH_DEBUG_SV.log(l_module_name,'max load --'||l_cont_max_load);
4335      WSH_DEBUG_SV.log(l_module_name,'gross wt --'||l_cont_gross_wt);
4336      WSH_DEBUG_SV.log(l_module_name,'net wt --'||l_cont_net_wt);
4337      WSH_DEBUG_SV.log(l_module_name,'Unit wt --'||l_cont_unit_wt);
4338    END IF;
4339    l_cont_fill_pc := (l_cont_gross_wt - l_cont_unit_wt)/l_cont_max_load;
4340  ELSIF l_fill_pc_basis = 'V' THEN
4341    IF l_debug_on THEN
4342      WSH_DEBUG_SV.log(l_module_name,'max vol --'||l_cont_max_vol);
4343      WSH_DEBUG_SV.log(l_module_name,'volume --'||l_cont_vol);
4344    END IF;
4345    l_cont_fill_pc := l_cont_vol/l_cont_max_vol;
4346  ELSIF l_fill_pc_basis = 'Q' THEN
4347 
4348    l_cont_fill_pc := 0;
4349 
4350    FOR dlvb IN Get_Cont_Contents (p_container_instance_id, l_cont_org_id) LOOP
4351 
4352        IF (nvl(dlvb.container_flag,'N') <> 'Y') THEN
4353 
4354 --   WSH_CONTAINER_UTILITIES.Estimate_Detail_Containers (
4355 --   replacing with TPA enabled API..
4356 
4357      --
4358      -- Debug Statements
4359      --
4360      IF l_debug_on THEN
4361          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TPA_CONTAINER_PKG.ESTIMATE_DETAIL_CONTAINERS',WSH_DEBUG_SV.C_PROC_LEVEL);
4362      END IF;
4363      --
4364      WSH_TPA_CONTAINER_PKG.Estimate_Detail_Containers (
4365          p_container_instance_id,
4366          l_cont_item_id,
4367          dlvb.delivery_detail_id,
4368          l_cont_org_id,
4369          l_cont_qty,
4370          x_return_status);
4371 
4372      IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4373       -- dbms_output.put_line('error in estimating detail cont');
4374       --
4375       -- Debug Statements
4376       --
4377       IF l_debug_on THEN
4378           WSH_DEBUG_SV.pop(l_module_name);
4379       END IF;
4380       --
4381       x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4382       return;
4383      END IF;
4384 
4385      l_cont_fill_pc := l_cont_fill_pc + l_cont_qty;
4386 
4387    ELSIF dlvb.container_flag = 'Y' THEN
4388 
4389 --    WSH_CONTAINER_UTILITIES.Estimate_Master_Containers (
4390 --    replacing with TPA enabled API..
4391 
4392      -- dbms_output.put_line('calling estimate master with  ' || p_container_instance_id);
4393 
4394      -- AP Rewrite : Change p_container_instance_id to dlvb.delivery_detail_id
4395      --
4396      -- Debug Statements
4397      --
4398      IF l_debug_on THEN
4399          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_TPA_CONTAINER_PKG.ESTIMATE_MASTER_CONTAINERS',WSH_DEBUG_SV.C_PROC_LEVEL);
4400      END IF;
4401      --
4402      WSH_TPA_CONTAINER_PKG.Estimate_Master_Containers (
4403          dlvb.delivery_detail_id,
4404          l_cont_item_id,
4405          dlvb.inventory_item_id,
4406          l_cont_org_id,
4407          l_cont_qty,
4408          x_return_status);
4409 
4410       IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4411       -- dbms_output.put_line('error in estimating master cont');
4412       --
4413       -- Debug Statements
4414       --
4415       IF l_debug_on THEN
4416           WSH_DEBUG_SV.pop(l_module_name);
4417       END IF;
4418       --
4419       return;
4420       END IF;
4421 
4422      l_cont_fill_pc := l_cont_fill_pc + l_cont_qty;
4423 
4424    END IF;
4425 
4426    END LOOP;
4427 
4428  ELSE
4429 
4430     FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_FILL_BASIS');
4431     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4432     --
4433     -- Debug Statements
4434     --
4435     IF l_debug_on THEN
4436         WSH_DEBUG_SV.pop(l_module_name);
4437     END IF;
4438     --
4439     return;
4440 
4441  END IF;  -- fill pc basis check
4442 
4443   -- bug 1748609: increase precision to improve accuracy
4444   -- of auto-packing and packing workbench with packing
4445   -- partially filled containers.
4446  x_fill_percent := ROUND((100*l_cont_fill_pc),6);
4447 
4448  IF l_debug_on THEN
4449    WSH_DEBUG_SV.log(l_module_name,'Fill pc--'||x_fill_percent);
4450  END IF;
4451 -- dbms_output.put_line('fill percent is ' || x_fill_percent);
4452 
4453  -- J: W/V Changes
4454  IF p_update_flag = 'Y' THEN
4455 
4456    -- K LPN CONV. rv
4457    IF l_debug_on THEN
4458        WSH_DEBUG_SV.log(l_module_name,'line direction', l_line_direction);
4459        WSH_DEBUG_SV.log(l_module_name,'Organization Id', l_organization_id);
4460    END IF;
4461    --
4462    l_wms_org := wsh_util_validate.check_wms_org(l_organization_id);
4463    --
4464    IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
4465    AND l_line_direction IN ('O','IO')
4466    AND l_cont_flag = 'Y'
4467    AND
4468    (
4469      (WSH_WMS_LPN_GRP.GK_WMS_UPD_FILL and l_wms_org = 'Y')
4470      OR
4471      (WSH_WMS_LPN_GRP.GK_INV_UPD_FILL and l_wms_org = 'N')
4472    )
4473    THEN
4474    --{
4475        l_sync_tmp_rec.delivery_detail_id := p_container_instance_id;
4476        l_sync_tmp_rec.operation_type := 'UPDATE';
4477        --
4478        -- Debug Statements
4479        --
4480        IF l_debug_on THEN
4481          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WMS_SYNC_TMP_PKG.MERGE',WSH_DEBUG_SV.C_PROC_LEVEL);
4482        END IF;
4483        --
4484        WSH_WMS_SYNC_TMP_PKG.MERGE
4485        (
4486          p_sync_tmp_rec      => l_sync_tmp_rec,
4487          x_return_status     => l_return_status
4488        );
4489 
4490        IF l_debug_on THEN
4491          WSH_DEBUG_SV.log(l_module_name,'Return Status after calling WSH_WMS_SYNC_TMP_PKG.MERGE',l_return_status);
4492        END IF;
4493        --
4494        IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
4495          --
4496          x_return_status := l_return_status;
4497          --
4498          IF l_debug_on THEN
4499            WSH_DEBUG_SV.logmsg(l_module_name,'WSH_WMS_SYNC_TMP_PKG.MERGE completed with an error');
4500            WSH_DEBUG_SV.pop(l_module_name);
4501          END IF;
4502          --
4503          RETURN;
4504          --
4505        ELSIF l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4506          --
4507          l_num_warnings := l_num_warnings + 1;
4508          --
4509        END IF;
4510    --}
4511    END IF;
4512    -- K LPN CONV. rv
4513    UPDATE WSH_DELIVERY_DETAILS
4514    SET fill_percent = x_fill_percent
4515    WHERE delivery_detail_id = p_container_instance_id;
4516 
4517    IF SQL%NOTFOUND THEN
4518       -- dbms_output.put_line('unexp error while updating fill percent');
4519       FND_MESSAGE.SET_NAME('WSH','WSH_UNEXP_ERROR');
4520       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4521       --
4522       -- Debug Statements
4523       --
4524       IF l_debug_on THEN
4525           WSH_DEBUG_SV.pop(l_module_name);
4526       END IF;
4527       --
4528       return;
4529    END IF;
4530  END IF;
4531 
4532  -- LPN CONV. rv
4533  IF (l_num_warnings > 0 AND x_return_status = WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
4534    --
4535    x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4536    --
4537  ELSE
4538    --
4539    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4540    --
4541  END IF;
4542  -- LPN CONV. rv
4543 
4544 --
4545 -- Debug Statements
4546 --
4547 IF l_debug_on THEN
4548     WSH_DEBUG_SV.pop(l_module_name);
4549 END IF;
4550 --
4551 EXCEPTION
4552       WHEN WSH_UTIL_CORE.G_EXC_WARNING THEN
4553        x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
4554        --
4555        IF l_debug_on THEN
4556          WSH_DEBUG_SV.logmsg(l_module_name,'WSH_UTIL_CORE.G_EXC_WARNING exception has occured ',WSH_DEBUG_SV.C_EXCEP_LEVEL);
4557          WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:WSH_UTIL_CORE.G_EXC_WARNING');
4558       END IF;
4559       --
4560       WHEN Others THEN
4561        WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CALC_CONT_FILL_PC');
4562        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4563 
4564 --
4565 -- Debug Statements
4566 --
4567 IF l_debug_on THEN
4568     WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4569     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4570 END IF;
4571 --
4572 END Calc_Cont_Fill_Pc;
4573 
4574 
4575 PROCEDURE Container_Tare_Weight_Self (
4576  p_container_instance_id IN NUMBER,
4577  p_cont_item_id IN NUMBER,
4578  p_wt_uom IN VARCHAR2,
4579  p_organization_id IN NUMBER,
4580  x_cont_tare_wt OUT NOCOPY  NUMBER,
4581  x_return_status OUT NOCOPY  VARCHAR2) IS
4582 
4583  CURSOR Get_Unit_Weight (v_cont_item_id NUMBER, v_org_id NUMBER) IS
4584  SELECT unit_weight, weight_uom_code
4585  FROM mtl_system_items
4586  WHERE inventory_item_id = v_cont_item_id
4587  AND organization_id = v_org_id;
4588 
4589  CURSOR Get_Cont_Info (v_cont_inst_id NUMBER) IS
4590  SELECT inventory_item_id, weight_uom_code, organization_id
4591  FROM wsh_delivery_details
4592  WHERE delivery_detail_id = v_cont_inst_id AND
4593      container_flag = 'Y';
4594 
4595  l_cont_item_id NUMBER;
4596  l_cont_org_id NUMBER;
4597  l_cont_unit_wt NUMBER;
4598  l_cont_wt_uom VARCHAR2(3);
4599  l_wt_uom VARCHAR2(3);
4600 
4601 --
4602 l_debug_on BOOLEAN;
4603 --
4604 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CONTAINER_TARE_WEIGHT_SELF';
4605 --
4606 BEGIN
4607 
4608  --
4609  -- Debug Statements
4610  --
4611  --
4612  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
4613  --
4614  IF l_debug_on IS NULL
4615  THEN
4616      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
4617  END IF;
4618  --
4619  IF l_debug_on THEN
4620      WSH_DEBUG_SV.push(l_module_name);
4621      --
4622      WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_INSTANCE_ID',P_CONTAINER_INSTANCE_ID);
4623      WSH_DEBUG_SV.log(l_module_name,'P_CONT_ITEM_ID',P_CONT_ITEM_ID);
4624      WSH_DEBUG_SV.log(l_module_name,'P_WT_UOM',P_WT_UOM);
4625      WSH_DEBUG_SV.log(l_module_name,'P_ORGANIZATION_ID',P_ORGANIZATION_ID);
4626  END IF;
4627  --
4628  IF p_container_instance_id IS NOT NULL THEN
4629 
4630      OPEN Get_Cont_Info (p_container_instance_id);
4631 
4632      FETCH Get_Cont_Info INTO l_cont_item_id, l_cont_wt_uom, l_cont_org_id;
4633 
4634      IF Get_Cont_Info%NOTFOUND THEN
4635       FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_CONTAINER');
4636    CLOSE Get_Cont_Info;
4637    x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4638    --
4639    -- Debug Statements
4640    --
4641    IF l_debug_on THEN
4642        WSH_DEBUG_SV.pop(l_module_name);
4643    END IF;
4644    --
4645    return;
4646      END IF;
4647 
4648      CLOSE Get_Cont_Info;
4649 
4650  ELSIF p_cont_item_id IS NULL OR p_organization_id IS NULL THEN
4651 
4652       FND_MESSAGE.SET_NAME('WSH','WSH_NO_CONT_OR_ORG');
4653    x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4654    --
4655    -- Debug Statements
4656    --
4657    IF l_debug_on THEN
4658        WSH_DEBUG_SV.pop(l_module_name);
4659    END IF;
4660    --
4661    return;
4662 
4663  END IF;
4664 
4665  OPEN Get_Unit_Weight (nvl(p_cont_item_id,l_cont_item_id), nvl(p_organization_id,l_cont_org_id));
4666 
4667  FETCH Get_Unit_Weight INTO l_cont_unit_wt, l_wt_uom;
4668 
4669  IF Get_Unit_Weight%NOTFOUND THEN
4670       FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_CONT_ITEM');
4671       CLOSE Get_Unit_Weight;
4672       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4673       --
4674       -- Debug Statements
4675       --
4676       IF l_debug_on THEN
4677           WSH_DEBUG_SV.pop(l_module_name);
4678       END IF;
4679       --
4680       return;
4681  END IF;
4682 
4683  CLOSE Get_Unit_Weight;
4684 
4685  --
4686  -- Debug Statements
4687  --
4688  IF l_debug_on THEN
4689      WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM',WSH_DEBUG_SV.C_PROC_LEVEL);
4690      WSH_DEBUG_SV.log(l_module_name,'wt uom'||l_wt_uom);
4691      WSH_DEBUG_SV.log(l_module_name,'cont unit wt'||l_cont_unit_wt);
4692  END IF;
4693  --
4694  x_cont_tare_wt := WSH_WV_UTILS.Convert_Uom(l_wt_uom, nvl(p_wt_uom,l_cont_wt_uom),l_cont_unit_wt,nvl(p_cont_item_id, l_cont_item_id));
4695 
4696  x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4697 
4698 
4699 --
4700 -- Debug Statements
4701 --
4702 IF l_debug_on THEN
4703     WSH_DEBUG_SV.pop(l_module_name);
4704 END IF;
4705 --
4706 EXCEPTION
4707 
4708       WHEN Others THEN
4709        WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CONTAINER_TARE_WEIGHT_SELF');
4710        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4711 
4712 --
4713 -- Debug Statements
4714 --
4715 IF l_debug_on THEN
4716     WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4717     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4718 END IF;
4719 --
4720 END Container_Tare_Weight_Self;
4721 
4722 --
4723 -- Procedure:   Check Fill PC
4724 -- Parameters:  p_container_instance_id - container instance id of container
4725 --              p_calculation_flag - w/v calculation flag, 'Y' for Automatic and 'N' for Manual
4726 --              x_fill_status - fill status of container - 'Overpacked',
4727 --              'Underpacked',or 'Success' (returns 'O','U' or 'S')
4728 --              x_return_status - status of procedure call
4729 -- Description: This procedure will check the fill status of container by
4730 --              comparing the fill pc with min fill pc. If fill pc < min fill
4731 --              pc then it is underpacked. If fill pc > 100 then overpacked
4732 --              else 'Success'.
4733 --
4734 
4735 PROCEDURE Check_Fill_Pc (
4736       p_container_instance_id IN NUMBER,
4737       p_calc_wt_vol_flag IN VARCHAR2 DEFAULT 'Y', -- bug 2790656
4738       x_fill_status OUT NOCOPY  VARCHAR2,
4739       x_return_status OUT NOCOPY  VARCHAR2) IS
4740 
4741  /* wms - change : to check for LPN grouping, added inventory_item_id */
4742  CURSOR Get_Cont_Info IS
4743  SELECT fill_percent, minimum_fill_percent, inventory_item_id, organization_id
4744  FROM WSH_DELIVERY_DETAILS
4745  WHERE delivery_detail_id = p_container_instance_id AND
4746      container_flag = 'Y';
4747 
4748  l_fill_pc NUMBER;
4749  l_min_fill_pc NUMBER;
4750  l_cont_item_id NUMBER;
4751  l_organization_id NUMBER;
4752  l_param_info  WSH_SHIPPING_PARAMS_PVT.Parameter_Rec_Typ;
4753 
4754  l_gr_wt NUMBER;
4755  l_net_wt NUMBER;
4756  l_vol NUMBER;
4757 
4758 
4759 --
4760 l_debug_on BOOLEAN;
4761 --
4762 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'CHECK_FILL_PC';
4763 --
4764 BEGIN
4765 
4766  --
4767  -- Debug Statements
4768  --
4769  --
4770  l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
4771  --
4772  IF l_debug_on IS NULL
4773  THEN
4774      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
4775  END IF;
4776  --
4777  IF l_debug_on THEN
4778      WSH_DEBUG_SV.push(l_module_name);
4779      --
4780      WSH_DEBUG_SV.log(l_module_name,'P_CONTAINER_INSTANCE_ID',P_CONTAINER_INSTANCE_ID);
4781  END IF;
4782  --
4783  IF p_container_instance_id IS NOT NULL
4784  THEN
4785  --{
4786  OPEN Get_Cont_Info;
4787 
4788  FETCH Get_Cont_Info INTO
4789  l_fill_pc,
4790  l_min_fill_pc,
4791  l_cont_item_id,
4792  l_organization_id;
4793 
4794  IF Get_Cont_Info%NOTFOUND THEN
4795     CLOSE Get_Cont_Info;
4796     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4797     FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_CONTAINER');
4798     WSH_UTIL_CORE.Add_Message (x_return_status);
4799     --
4800     -- Debug Statements
4801     --
4802     IF l_debug_on THEN
4803         WSH_DEBUG_SV.pop(l_module_name);
4804     END IF;
4805     --
4806     return;
4807  END IF;
4808 
4809  /* wms change: if groupin is LPN , always return success */
4810  IF (l_cont_item_id IS NULL) THEN
4811     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4812     --
4813     -- Debug Statements
4814     --
4815     IF l_debug_on THEN
4816         WSH_DEBUG_SV.pop(l_module_name);
4817     END IF;
4818     --
4819     return;
4820  END IF;
4821 
4822  CLOSE Get_Cont_Info;
4823 
4824  --Bug 3562797 jckwok
4825  WSH_SHIPPING_PARAMS_PVT.Get(
4826        p_organization_id => l_organization_id,
4827        x_param_info      => l_param_info,
4828        x_return_status   => x_return_status);
4829  IF x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
4830     FND_MESSAGE.Set_Name('WSH', 'WSH_PARAM_NOT_DEFINED');
4831     FND_MESSAGE.Set_Token('ORGANIZAION_CODE',
4832                           wsh_util_core.get_org_name(l_organization_id));
4833     wsh_util_core.add_message(x_return_status,l_module_name);
4834     IF l_debug_on THEN
4835        WSH_DEBUG_SV.logmsg(l_module_name,'WSH_SHIPPING_PARAMS_PVT.Get returned '||x_return_status);
4836        WSH_DEBUG_SV.pop(l_module_name);
4837     END IF;
4838     return;
4839  END IF;
4840 
4841  --
4842  -- Debug Statements
4843  --
4844  IF l_debug_on THEN
4845    WSH_DEBUG_SV.log(l_module_name,'fill pc basis', l_param_info.percent_fill_basis_flag);
4846  END IF;
4847  --
4848  -- If the Shipping Parameter Fill Basis is set to None, then simply return success and log a message.
4849  --
4850  IF (l_param_info.percent_fill_basis_flag = 'N') THEN
4851     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4852     x_fill_status := 'S';
4853     --
4854     -- Debug Statements
4855     --
4856     IF l_debug_on THEN
4857        WSH_DEBUG_SV.pop(l_module_name);
4858     END IF;
4859     --
4860     return;
4861  END IF;
4862  --Bug 3562797 jckwok
4863 
4864 
4865  IF l_fill_pc < nvl(l_min_fill_pc,0) THEN
4866    x_fill_status := 'U';
4867  ELSIF l_fill_pc > 100 THEN
4868    x_fill_status := 'O';
4869  ELSE
4870    x_fill_status := 'S';
4871  END IF;
4872 
4873  --}
4874  ELSE
4875  --{
4876      x_fill_status := 'S';
4877  --}
4878  END IF;
4879  x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4880 
4881 --
4882 -- Debug Statements
4883 --
4884 IF l_debug_on THEN
4885     WSH_DEBUG_SV.pop(l_module_name);
4886 END IF;
4887 --
4888 EXCEPTION
4889       WHEN Others THEN
4890        WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.CHECK_FILL_PC');
4891        x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4892 
4893 --
4894 -- Debug Statements
4895 --
4896 IF l_debug_on THEN
4897     WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4898     WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
4899 END IF;
4900 --
4901 END Check_Fill_Pc;
4902 
4903 -- J: W/V changes
4904 
4905 -- Start of comments
4906 -- API name : Delivery_Weight_Volume
4907 -- Type     : Public
4908 -- Pre-reqs : None.
4909 -- Function : Calculates Weight and Volume of Delivery
4910 --            If p_update_flag is 'Y' then the calculated W/V is updated on
4911 --            Delivery. Otherwise, the API returns the calculated W/V
4912 --            If p_calc_wv_if_frozen is 'N' then manually entered W/V will not
4913 --            be overwritten with calculated W/V
4914 --            OTM R12 : packing ECO
4915 --                      This procedure is modified to keep track of delivery
4916 --                      detail wt/vol updates.  logic of checking G_RESET_WV
4917 --
4918 -- Parameters :
4919 -- IN:
4920 --    p_delivery_id  IN NUMBER Required
4921 --    p_update_flag  IN VARCHAR2
4922 --      'Y' if the delivery needs to be updated with the calculated W/V
4923 --    p_calc_wv_if_frozen  IN VARCHAR2
4924 --      'Y' if manual W/V can be overriden
4925 -- OUT:
4926 --    x_gross_weight OUT NUMBER
4927 --       gives the gross weight of delivery
4928 --    x_net_weight OUT NUMBER
4929 --       gives the net weight of delivery
4930 --    x_volume OUT NUMBER
4931 --       gives the volume of delivery
4932 --    x_return_status OUT VARCHAR2 Required
4933 --       give the return status of API
4934 -- Version : 1.0
4935 -- End of comments
4936 
4937 PROCEDURE Delivery_Weight_Volume(
4938         p_delivery_id    IN NUMBER,
4939         p_update_flag    IN VARCHAR2,
4940         p_calc_wv_if_frozen IN VARCHAR2,
4941         x_gross_weight   OUT NOCOPY  NUMBER,
4942         x_net_weight     OUT NOCOPY  NUMBER,
4943         x_volume         OUT NOCOPY  NUMBER,
4944         x_return_status  OUT NOCOPY  VARCHAR2) IS
4945 
4946   CURSOR loose_detail_wt_vol IS
4947   SELECT wdd.delivery_detail_id dd_id,
4948          wdd.gross_weight gross_wt,
4949          wdd.net_weight net_wt,
4950          wdd.volume vol,
4951          wdd.inventory_item_id,
4952          wdd.weight_uom_code wt_uom,
4953          wdd.volume_uom_code vol_uom
4954   FROM   wsh_delivery_details     wdd,
4955          wsh_delivery_assignments_v wda
4956   WHERE  wdd.delivery_detail_id = wda.delivery_detail_id AND
4957          wda.delivery_id = p_delivery_id AND
4958          wda.delivery_id IS NOT NULL AND
4959          wdd.container_flag = 'N' AND
4960          wda.parent_delivery_detail_id IS NULL;
4961 
4962   CURSOR del_containers IS
4963   SELECT distinct(dd.delivery_detail_id) c_id,
4964          dd.gross_weight gr_wt,
4965          dd.net_weight   net_wt,
4966          dd.volume vol,
4967          dd.inventory_item_id inventory_item_id,
4968          dd.weight_uom_code wt_uom,
4969          dd.volume_uom_code vol_uom
4970   FROM   wsh_delivery_assignments_v da,
4971          wsh_delivery_details dd
4972   WHERE  da.delivery_id = p_delivery_id AND
4973          da.delivery_id IS NOT NULL AND
4974          da.delivery_detail_id = dd.delivery_detail_id AND
4975          dd.container_flag = 'Y' AND
4976          da.parent_delivery_detail_id IS NULL;
4977 
4978   CURSOR del_uoms IS
4979   SELECT weight_uom_code,
4980          volume_uom_code,
4981          organization_id,
4982          gross_weight,
4983          net_weight,
4984          volume,
4985          NVL(wv_frozen_flag,'Y'),
4986          delivery_type,
4987          NVL(ignore_for_planning, 'N'),    -- OTM R12 : packing ECO
4988          tms_interface_flag                -- OTM R12 : packing ECO
4989   FROM   wsh_new_deliveries
4990   WHERE  delivery_id = p_delivery_id;
4991 
4992 
4993   -- MDC: calculate the wt/vol of the child deliveries
4994 
4995   CURSOR c_child_deliveries(p_delivery_id IN NUMBER) IS
4996   SELECT d.weight_uom_code wt_uom,
4997          d.volume_uom_code vol_uom,
4998          d.delivery_id del_id
4999   FROM   wsh_delivery_legs l1,
5000          wsh_delivery_legs l2,
5001          wsh_new_deliveries d
5002   WHERE  l1.delivery_id = p_delivery_id
5003   AND    l1.delivery_leg_id = l2.parent_delivery_leg_id
5004   AND    l2.delivery_id = d.delivery_id;
5005 
5006   -- MDC: Get the consol LPNs attached to the delivery
5007   CURSOR c_consol_lpns(p_delivery_id in NUMBER) IS
5008   select da.delivery_detail_id,
5009          dd.gross_weight gr_wt,
5010          dd.volume vol,
5011          dd.inventory_item_id inventory_item_id,
5012          dd.weight_uom_code wt_uom,
5013          dd.volume_uom_code vol_uom
5014   from wsh_delivery_details dd, wsh_delivery_assignments da
5015   where dd.delivery_detail_id = da.delivery_detail_id
5016   and   dd.container_flag = 'C'
5017   and   NVL(da.type, 'S') = 'S'
5018   and   da.delivery_id = p_delivery_id
5019   and   da.delivery_id is not null;
5020 
5021 
5022   -- MDC: calculate the wt/vol of the consol LPNs
5023   -- topmost children
5024 
5025   CURSOR c_top_child_lpns(p_consol_lpn in NUMBER) IS
5026   SELECT dd.delivery_detail_id,
5027          dd.gross_weight gr_wt,
5028          dd.net_weight   net_wt,
5029          dd.volume vol,
5030          dd.inventory_item_id inventory_item_id,
5031          dd.weight_uom_code wt_uom,
5032          dd.volume_uom_code vol_uom
5033   FROM   wsh_delivery_assignments da,
5034          wsh_delivery_details dd
5035   WHERE  da.parent_delivery_detail_id = p_consol_lpn AND
5036          da.delivery_detail_id = dd.delivery_detail_id AND
5037          da.type = 'C';
5038 
5039   l_weight_uom_code   VARCHAR2(10);
5040   l_volume_uom_code   VARCHAR2(10);
5041   l_organization_id   NUMBER;
5042   l_del_gross_wt      NUMBER;
5043   l_del_net_wt        NUMBER;
5044   l_del_vol           NUMBER;
5045   l_wv_frozen_flag    VARCHAR2(1);
5046   l_delivery_type     VARCHAR2(30);
5047 
5048   loose_gross_weight  NUMBER;
5049   loose_net_weight    NUMBER;
5050   loose_volume        NUMBER;
5051   l_gross_weight      NUMBER;
5052   l_net_weight        NUMBER;
5053   l_volume            NUMBER;
5054 
5055   l_cont_gross_weight NUMBER;
5056   l_cont_net_weight   NUMBER;
5057   l_cont_volume       NUMBER;
5058   l_cont_fill_pc      NUMBER;
5059 
5060   -- MDC
5061   child_del_gross_weight  NUMBER;
5062   child_del_net_weight    NUMBER;
5063   child_del_volume        NUMBER;
5064 
5065   consol_lpn_gross_weight  NUMBER :=0;
5066   consol_lpn_net_weight    NUMBER :=0;
5067   consol_lpn_tare_weight   NUMBER :=0;
5068   consol_lpn_volume        NUMBER;
5069 
5070   l_num_warnings      NUMBER := 0;
5071   l_return_status     VARCHAR2(100);
5072   l_param_info        WSH_SHIPPING_PARAMS_PVT.Parameter_Rec_Typ;
5073 
5074   l_debug_on          BOOLEAN;
5075   l_module_name       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DELIVERY_WEIGHT_VOLUME';
5076 
5077   e_abort             exception;
5078 
5079   -- OTM R12 : packing ECO
5080   l_ignore_for_planning   WSH_NEW_DELIVERIES.IGNORE_FOR_PLANNING%TYPE;
5081   l_tms_interface_flag    WSH_NEW_DELIVERIES.TMS_INTERFACE_FLAG%TYPE;
5082   l_delivery_id_tab       WSH_UTIL_CORE.ID_TAB_TYPE;
5083   l_interface_flag_tab    WSH_UTIL_CORE.COLUMN_TAB_TYPE;
5084   -- End of OTM R12 : packing ECO
5085 
5086 BEGIN
5087 
5088   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5089   IF l_debug_on IS NULL THEN
5090     l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5091   END IF;
5092 
5093   IF l_debug_on THEN
5094     WSH_DEBUG_SV.push(l_module_name);
5095     WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_ID',P_DELIVERY_ID);
5096     WSH_DEBUG_SV.log(l_module_name,'P_UPDATE_FLAG',P_UPDATE_FLAG);
5097     WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
5098   END IF;
5099   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5100 
5101   -- Get the delivery info
5102   OPEN  del_uoms;
5103   FETCH del_uoms
5104   INTO  l_weight_uom_code,
5105         l_volume_uom_code,
5106         l_organization_id,
5107         l_del_gross_wt,
5108         l_del_net_wt,
5109         l_del_vol,
5110         l_wv_frozen_flag,
5111         l_delivery_type,
5112         l_ignore_for_planning,        -- OTM R12 : packing ECO
5113         l_tms_interface_flag;         -- OTM R12 : packing ECO
5114   IF (del_uoms%NOTFOUND) THEN
5115     CLOSE del_uoms;
5116     FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_DELIVERY');
5117     FND_MESSAGE.SET_TOKEN('DELIVERY',p_delivery_id);
5118     wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_ERROR);
5119     IF l_debug_on THEN
5120       WSH_DEBUG_SV.log(l_module_name,'Delivery '||p_delivery_id||' not found');
5121       WSH_DEBUG_SV.pop(l_module_name);
5122     END IF;
5123     RETURN;
5124   END IF;
5125   CLOSE del_uoms;
5126 
5127   IF l_debug_on THEN
5128     WSH_DEBUG_SV.log(l_module_name,'Delivery original wts are Gross '||l_del_gross_wt||' Net '||l_del_net_wt||' Vol '||l_del_vol||' Frozen '||l_wv_frozen_flag);
5129     WSH_DEBUG_SV.log(l_module_name,'Org '||l_organization_id||' Wt Code '||l_weight_uom_code||' Vol Code '||l_volume_uom_code);
5130     WSH_DEBUG_SV.log(l_module_name, 'Ignore_for_planning '||l_ignore_for_planning);
5131     WSH_DEBUG_SV.log(l_module_name, 'tms_interface_flag '||l_tms_interface_flag);
5132   END IF;
5133 
5134   IF p_calc_wv_if_frozen = 'N' AND l_wv_frozen_flag = 'Y' THEN
5135     x_gross_weight := l_del_gross_wt;
5136     x_net_weight   := l_del_net_wt;
5137     x_volume       := l_del_vol;
5138     IF l_debug_on THEN
5139       WSH_DEBUG_SV.logmsg(l_module_name,'Delivery W/V is frozen. Returning');
5140       WSH_DEBUG_SV.pop(l_module_name);
5141     END IF;
5142     RETURN;
5143   END IF;
5144 
5145   -- Get the Shipping parameters of DD's organization
5146   IF l_debug_on THEN
5147     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_SHIPPING_PARAMS_PVT.Get',WSH_DEBUG_SV.C_PROC_LEVEL);
5148   END IF;
5149 
5150   WSH_SHIPPING_PARAMS_PVT.Get(
5151     p_organization_id => l_organization_id,
5152     x_param_info      => l_param_info,
5153     x_return_status   => l_return_status);
5154 
5155   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
5156     IF l_debug_on THEN
5157       WSH_DEBUG_SV.logmsg(l_module_name,'WSH_SHIPPING_PARAMS_PVT.Get returned '||l_return_status);
5158     END IF;
5159     FND_MESSAGE.Set_Name('WSH', 'WSH_PARAM_NOT_DEFINED');
5160     FND_MESSAGE.Set_Token('ORGANIZAION_CODE',
5161                 wsh_util_core.get_org_name(l_organization_id));
5162     wsh_util_core.add_message(l_return_status,l_module_name);
5163     raise e_abort;
5164   END IF;
5165 
5166 
5167   -- OTM R12 : packing ECO
5168 
5169   -- for the delivery, enable the check for delivery update
5170   -- need to check for update only if delivery is include for planning and
5171   -- tms_interface_flag is in CP UP AW AR state, which will be set to UR
5172   IF (WSH_WV_UTILS.G_RESET_WV ='Y' AND
5173       l_ignore_for_planning = 'N' AND
5174       l_tms_interface_flag IN
5175                           (WSH_NEW_DELIVERIES_PVT.C_TMS_CREATE_IN_PROCESS,
5176                            WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_IN_PROCESS,
5177                            WSH_NEW_DELIVERIES_PVT.C_TMS_AWAITING_ANSWER,
5178                            WSH_NEW_DELIVERIES_PVT.C_TMS_ANSWER_RECEIVED)) THEN
5179     -- setting this will impact the detail_weight_volume,
5180     -- container_weight_volume calls later
5181     G_DELIVERY_TMS_IMPACT := 'N';
5182   END IF;
5183 
5184   IF l_debug_on THEN
5185     WSH_DEBUG_SV.log(l_module_name, 'G_DELIVERY_TMS_IMPACT', G_DELIVERY_TMS_IMPACT);
5186   END IF;
5187   -- End of OTM R12 : packing ECO
5188 
5189 
5190   -- MDC: Calculate wt/vol for consolidation deliveries
5191 
5192   IF l_delivery_type = 'CONSOLIDATION' THEN
5193 
5194      -- For all child_del items in delivery
5195      FOR del IN c_child_deliveries(p_delivery_id) LOOP
5196 
5197        l_gross_weight := NULL;
5198        l_net_weight   := NULL;
5199        l_volume       := NULL;
5200 
5201        IF l_debug_on THEN
5202          WSH_DEBUG_SV.logmsg(l_module_name,'Processing Delivery '||del.del_id);
5203        END IF;
5204 
5205        -- Call Delivery WV API to calculate delivery W/V
5206        IF l_debug_on THEN
5207          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.DELIVERY_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
5208        END IF;
5209 
5210        Delivery_Weight_Volume(
5211         p_delivery_id       => del.del_id,
5212         p_update_flag       => p_update_flag,
5213         p_calc_wv_if_frozen => p_calc_wv_if_frozen,
5214         x_gross_weight      => l_gross_weight,
5215         x_net_weight        => l_net_weight,
5216         x_volume            => l_volume,
5217         x_return_status     => x_return_status);
5218 
5219 
5220        IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
5221          IF l_debug_on THEN
5222            WSH_DEBUG_SV.pop(l_module_name);
5223          END IF;
5224          RETURN;
5225        END IF;
5226 
5227 
5228        -- Convert the W/V if UOMs differ and then accumulate W/V
5229        IF (del.wt_uom <> l_weight_uom_code) THEN
5230          IF (l_gross_weight > 0) THEN
5231            IF l_debug_on THEN
5232              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Gross',WSH_DEBUG_SV.C_PROC_LEVEL);
5233            END IF;
5234            child_del_gross_weight := NVL(child_del_gross_weight,0) +
5235                                  WSH_WV_UTILS.convert_uom(del.wt_uom, l_weight_uom_code, l_gross_weight);
5236          ELSIF (l_gross_weight = 0) THEN
5237            IF l_debug_on THEN
5238              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_gross_wt=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5239            END IF;
5240            child_del_gross_weight := NVL(child_del_gross_weight,0) + l_gross_weight;
5241          END IF;
5242 
5243          IF (l_net_weight > 0) THEN
5244            IF l_debug_on THEN
5245              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Net',WSH_DEBUG_SV.C_PROC_LEVEL);
5246            END IF;
5247            child_del_net_weight := NVL(child_del_net_weight,0) +
5248                                WSH_WV_UTILS.convert_uom(del.wt_uom, l_weight_uom_code, l_net_weight);
5249          ELSIF (l_net_weight = 0) THEN
5250            IF l_debug_on THEN
5251              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_net_wt=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5252            END IF;
5253            child_del_net_weight := NVL(child_del_net_weight,0) + l_net_weight;
5254          END IF;
5255        ELSE
5256          IF (l_gross_weight >= 0) THEN
5257            child_del_gross_weight := NVL(child_del_gross_weight,0) + l_gross_weight;
5258          END IF;
5259          IF (l_net_weight >= 0) THEN
5260            child_del_net_weight := NVL(child_del_net_weight,0) + l_net_weight;
5261          END IF;
5262        END IF;
5263 
5264        IF (del.vol_uom <> l_volume_uom_code) THEN
5265          IF (l_volume > 0) THEN
5266            IF l_debug_on THEN
5267              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Volume',WSH_DEBUG_SV.C_PROC_LEVEL);
5268            END IF;
5269            child_del_volume := NVL(child_del_volume,0) +
5270                            WSH_WV_UTILS.convert_uom(del.vol_uom, l_volume_uom_code, l_volume);
5271          ELSIF (l_volume = 0) THEN
5272            IF l_debug_on THEN
5273              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_volume=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5274            END IF;
5275            child_del_volume := NVL(child_del_volume,0) + l_volume;
5276          END IF;
5277        ELSE
5278          IF (l_volume >= 0) THEN
5279            child_del_volume := NVL(child_del_volume,0) + l_volume;
5280          END IF;
5281        END IF;
5282 
5283        IF l_debug_on THEN
5284          WSH_DEBUG_SV.log(l_module_name,'child_del_net_weight',child_del_net_weight);
5285          WSH_DEBUG_SV.log(l_module_name,'child_del_gross_weight',child_del_gross_weight);
5286          WSH_DEBUG_SV.log(l_module_name,'consol_lpn_tare_weight',consol_lpn_tare_weight);
5287          WSH_DEBUG_SV.log(l_module_name,'consol_lpn_volume',consol_lpn_volume);
5288          WSH_DEBUG_SV.log(l_module_name,'child_del_volume',child_del_volume);
5289        END IF;
5290      END LOOP;
5291 
5292      IF l_debug_on THEN
5293        WSH_DEBUG_SV.log(l_module_name,'after loop for child dels');
5294        WSH_DEBUG_SV.log(l_module_name,'child_del_net_weight',child_del_net_weight);
5295        WSH_DEBUG_SV.log(l_module_name,'child_del_gross_weight',child_del_gross_weight);
5296        WSH_DEBUG_SV.log(l_module_name,'consol_lpn_tare_weight',consol_lpn_tare_weight);
5297        WSH_DEBUG_SV.log(l_module_name,'consol_lpn_volume',consol_lpn_volume);
5298        WSH_DEBUG_SV.log(l_module_name,'child_del_volume',child_del_volume);
5299      END IF;
5300 
5301 
5302      -- K: MDC: We need to calculate the empty tare weight of the consol LPNs.
5303      -- Since the gross weights of the consol LPNs children have already been
5304      -- been added when adding up the weights of the child deliveries, we
5305      -- need to add only the weight of the empty consol LPN to the consol delivery's
5306      -- gross weight here.
5307      -- The consol LPNs net weight for the purpose of calculating its empty tare weight
5308      -- is considered to be the some of the gross weights of its topmost contents.
5309      FOR consol_lpn in c_consol_lpns(p_delivery_id) LOOP
5310 
5311        FOR lpn IN c_top_child_lpns(consol_lpn.delivery_detail_id) LOOP
5312 
5313          l_cont_gross_weight := NULL;
5314          l_cont_net_weight   := NULL;
5315          l_cont_volume       := NULL;
5316 
5317          IF l_debug_on THEN
5318            WSH_DEBUG_SV.logmsg(l_module_name,'Processing Cont '||lpn.delivery_detail_id);
5319          END IF;
5320 
5321 /**
5322          -- Call WSH_TPA_CONTAINER_PKG.container_weight_volume API to calculate Container W/V
5323          IF l_debug_on THEN
5324            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit CONTAINER_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
5325          END IF;
5326          Container_Weight_Volume (
5327          p_container_instance_id => lpn.delivery_detail_id,
5328          p_override_flag         => p_update_flag,
5329          p_fill_pc_flag          => 'Y',
5330          p_post_process_flag     => 'N',
5331          p_calc_wv_if_frozen     => p_calc_wv_if_frozen,
5332          x_gross_weight          => l_cont_gross_weight,
5333          x_net_weight            => l_cont_net_weight,
5334          x_volume                => l_cont_volume,
5335          x_cont_fill_pc          => l_cont_fill_pc,
5336          x_return_status         => x_return_status);
5337 
5338          IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5339            IF l_debug_on THEN
5340              WSH_DEBUG_SV.pop(l_module_name);
5341            END IF;
5342            RETURN;
5343          END IF;
5344 **/
5345 
5346          l_cont_gross_weight := lpn.gr_wt;
5347          l_cont_net_weight := lpn.net_wt;
5348          l_cont_volume := lpn.vol;
5349 
5350          -- Convert the W/V if UOMs differ and then accumulate W/V
5351          IF (lpn.wt_uom <> l_weight_uom_code) THEN
5352            IF (l_cont_gross_weight > 0) THEN
5353              IF l_debug_on THEN
5354                WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Gross',WSH_DEBUG_SV.C_PROC_LEVEL);
5355              END IF;
5356              consol_lpn_net_weight := NVL(consol_lpn_net_weight,0) +
5357                         WSH_WV_UTILS.convert_uom(lpn.wt_uom, l_weight_uom_code, l_cont_gross_weight, lpn.inventory_item_id);
5358            ELSIF (l_cont_gross_weight = 0) THEN
5359              IF l_debug_on THEN
5360                WSH_DEBUG_SV.logmsg(l_module_name,'adding l_cont_gross_weight=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5361              END IF;
5362              consol_lpn_net_weight := NVL(consol_lpn_net_weight,0) + l_cont_gross_weight;
5363            END IF;
5364          ELSE
5365            IF (l_cont_gross_weight >= 0) THEN
5366              consol_lpn_net_weight := NVL(consol_lpn_net_weight,0) + l_cont_gross_weight;
5367            END IF;
5368          END IF;
5369 
5370          IF l_debug_on THEN
5371             WSH_DEBUG_SV.logmsg(l_module_name,'Accumulated Net '||consol_lpn_net_weight);
5372          END IF;
5373 
5374        END LOOP;
5375 
5376        -- MDC: Get the total gross weight of the consol LPN, calculate its empty tare weight
5377 
5378        IF l_debug_on THEN
5379          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit CONTAINER_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
5380        END IF;
5381 
5382        l_cont_gross_weight := NULL;
5383        l_cont_net_weight   := NULL;
5384        l_cont_volume       := NULL;
5385 
5386        Container_Weight_Volume (
5387          p_container_instance_id => consol_lpn.delivery_detail_id,
5388          p_override_flag         => p_update_flag,
5389          p_fill_pc_flag          => 'Y',
5390          p_post_process_flag     => 'N',
5391          p_calc_wv_if_frozen     => p_calc_wv_if_frozen,
5392          x_gross_weight          => l_cont_gross_weight,
5393          x_net_weight            => l_cont_net_weight,
5394          x_volume                => l_cont_volume,
5395          x_cont_fill_pc          => l_cont_fill_pc,
5396          x_return_status         => x_return_status);
5397 
5398        IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5399          IF l_debug_on THEN
5400            WSH_DEBUG_SV.pop(l_module_name);
5401          END IF;
5402          RETURN;
5403        END IF;
5404 
5405        IF (consol_lpn.wt_uom <> l_weight_uom_code) THEN
5406           IF l_debug_on THEN
5407             WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Gross',WSH_DEBUG_SV.C_PROC_LEVEL);
5408           END IF;
5409           IF (l_cont_gross_weight > 0) THEN
5410              consol_lpn_gross_weight := NVL(consol_lpn_gross_weight,0) +
5411                      WSH_WV_UTILS.convert_uom(consol_lpn.wt_uom, l_weight_uom_code, l_cont_gross_weight, consol_lpn.inventory_item_id);
5412           ELSE
5413              consol_lpn_gross_weight := NVL(consol_lpn_gross_weight,0);
5414           END IF;
5415        ELSE
5416          IF (consol_lpn.gr_wt >= 0) THEN
5417            consol_lpn_gross_weight := NVL(consol_lpn_gross_weight,0) + l_cont_gross_weight;
5418          END IF;
5419        END IF;
5420        IF l_debug_on THEN
5421           WSH_DEBUG_SV.logmsg(l_module_name,'Accumulated Gross '||consol_lpn_gross_weight);
5422        END IF;
5423 
5424        consol_lpn_tare_weight := consol_lpn_tare_weight + (consol_lpn_gross_weight - consol_lpn_net_weight);
5425 
5426        IF (consol_lpn.vol_uom <> l_volume_uom_code) THEN
5427          IF (l_cont_volume > 0) THEN
5428            IF l_debug_on THEN
5429              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Volume',WSH_DEBUG_SV.C_PROC_LEVEL);
5430            END IF;
5431            consol_lpn_volume := NVL(consol_lpn_volume,0) +
5432                            WSH_WV_UTILS.convert_uom(consol_lpn.vol_uom, l_volume_uom_code, l_cont_volume);
5433          ELSIF (consol_lpn.vol = 0) THEN
5434            IF l_debug_on THEN
5435              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_volume=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5436            END IF;
5437            consol_lpn_volume := NVL(consol_lpn_volume,0);
5438          END IF;
5439        ELSE
5440          IF (consol_lpn.vol >= 0) THEN
5441            consol_lpn_volume := NVL(consol_lpn_volume,0) + NVL(l_cont_volume, 0);
5442          END IF;
5443        END IF;
5444 
5445        IF l_debug_on THEN
5446          WSH_DEBUG_SV.log(l_module_name,'inside consol lpn loop');
5447          WSH_DEBUG_SV.log(l_module_name,'child_del_net_weight',child_del_net_weight);
5448          WSH_DEBUG_SV.log(l_module_name,'child_del_gross_weight',child_del_gross_weight);
5449          WSH_DEBUG_SV.log(l_module_name,'consol_lpn_tare_weight',consol_lpn_tare_weight);
5450          WSH_DEBUG_SV.log(l_module_name,'consol_lpn_volume',consol_lpn_volume);
5451          WSH_DEBUG_SV.log(l_module_name,'child_del_volume',child_del_volume);
5452        END IF;
5453 
5454      END LOOP;
5455 
5456      -- Since the sum net weights of the child deliveries would already include the
5457      -- net weights of the consol LPNs we need to add up only the tare weight of the
5458      -- consol LPN to the gross weight of the consol delivery.
5459      IF l_debug_on THEN
5460        WSH_DEBUG_SV.log(l_module_name,'after consol lpn loop');
5461        WSH_DEBUG_SV.log(l_module_name,'child_del_net_weight',child_del_net_weight);
5462        WSH_DEBUG_SV.log(l_module_name,'child_del_gross_weight',child_del_gross_weight);
5463        WSH_DEBUG_SV.log(l_module_name,'consol_lpn_tare_weight',consol_lpn_tare_weight);
5464        WSH_DEBUG_SV.log(l_module_name,'consol_lpn_volume',consol_lpn_volume);
5465        WSH_DEBUG_SV.log(l_module_name,'child_del_volume',child_del_volume);
5466      END IF;
5467 
5468      x_net_weight   := child_del_net_weight;
5469      x_gross_weight := child_del_gross_weight + NVL(consol_lpn_tare_weight, 0);
5470      x_volume       := NVL(consol_lpn_volume,child_del_volume);
5471      IF l_debug_on THEN
5472        WSH_DEBUG_SV.logmsg(l_module_name,'After accumulating all child_del items: Gross '||child_del_gross_weight||' Net '||child_del_net_weight||' Vol '||child_del_volume);
5473        WSH_DEBUG_SV.logmsg(l_module_name,'calculated wt/vol for consol delivery');
5474      END IF;
5475 
5476   ELSE  -- IF l_delivery_type = 'STANDARD' THEN
5477 
5478      -- For all loose items in delivery
5479      FOR dt IN loose_detail_wt_vol LOOP
5480 
5481        l_gross_weight := NULL;
5482        l_net_weight   := NULL;
5483        l_volume       := NULL;
5484 
5485        IF l_debug_on THEN
5486          WSH_DEBUG_SV.logmsg(l_module_name,'Processing DD '||dt.dd_id);
5487        END IF;
5488 
5489        -- Call detail_weight_volume API to calculate detail W/V
5490        IF l_debug_on THEN
5491          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.DETAIL_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
5492        END IF;
5493 
5494        WSH_WV_UTILS.detail_weight_volume(
5495          p_delivery_detail_id => dt.dd_id,
5496          p_update_flag        => p_update_flag,
5497          p_calc_wv_if_frozen  => p_calc_wv_if_frozen,
5498          x_net_weight         => l_net_weight,
5499          x_volume             => l_volume,
5500          x_return_status      => x_return_status);
5501 
5502        IF (x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
5503          IF l_debug_on THEN
5504            WSH_DEBUG_SV.pop(l_module_name);
5505          END IF;
5506          RETURN;
5507        END IF;
5508        l_gross_weight := l_net_weight;
5509 
5510         -- Raise warning if delivery detail has null W/V depending on percent_fill_basis_flag
5511        IF (l_param_info.percent_fill_basis_flag = 'W' AND l_net_weight IS NULL) OR
5512           (l_param_info.percent_fill_basis_flag = 'V' AND l_volume IS NULL) THEN
5513          FND_MESSAGE.SET_NAME('WSH','WSH_NULL_WEIGHT_VOLUME');
5514          FND_MESSAGE.SET_TOKEN('DELIVERY_DETAIL',dt.dd_id);
5515          wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_WARNING);
5516          l_num_warnings := l_num_warnings + 1;
5517        END IF;
5518 
5519        -- Convert the W/V if UOMs differ and then accumulate W/V
5520        IF (dt.wt_uom <> l_weight_uom_code) THEN
5521          IF (l_gross_weight > 0) THEN
5522            IF l_debug_on THEN
5523              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Gross',WSH_DEBUG_SV.C_PROC_LEVEL);
5524            END IF;
5525            loose_gross_weight := NVL(loose_gross_weight,0) +
5526                               WSH_WV_UTILS.convert_uom(dt.wt_uom, l_weight_uom_code, l_gross_weight, dt.inventory_item_id);
5527          ELSIF (l_gross_weight = 0) THEN
5528            IF l_debug_on THEN
5529              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_gross_wt=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5530            END IF;
5531            loose_gross_weight := NVL(loose_gross_weight,0) + l_gross_weight;
5532          END IF;
5533 
5534          IF (l_net_weight > 0) THEN
5535            IF l_debug_on THEN
5536              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Net',WSH_DEBUG_SV.C_PROC_LEVEL);
5537            END IF;
5538            loose_net_weight := NVL(loose_net_weight,0) +
5539                                WSH_WV_UTILS.convert_uom(dt.wt_uom, l_weight_uom_code, l_net_weight, dt.inventory_item_id);
5540          ELSIF (l_net_weight = 0) THEN
5541            IF l_debug_on THEN
5542              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_net_wt=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5543            END IF;
5544            loose_net_weight := NVL(loose_net_weight,0) + l_net_weight;
5545          END IF;
5546        ELSE
5547          IF (l_gross_weight >= 0) THEN
5548            loose_gross_weight := NVL(loose_gross_weight,0) + l_gross_weight;
5549          END IF;
5550          IF (l_net_weight >= 0) THEN
5551            loose_net_weight := NVL(loose_net_weight,0) + l_net_weight;
5552          END IF;
5553        END IF;
5554 
5555        IF (dt.vol_uom <> l_volume_uom_code) THEN
5556          IF (l_volume > 0) THEN
5557            IF l_debug_on THEN
5558              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Volume',WSH_DEBUG_SV.C_PROC_LEVEL);
5559            END IF;
5560            loose_volume := NVL(loose_volume,0) +
5561                            WSH_WV_UTILS.convert_uom(dt.vol_uom, l_volume_uom_code, l_volume, dt.inventory_item_id);
5562          ELSIF (l_volume = 0) THEN
5563            IF l_debug_on THEN
5564              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_volume=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5565            END IF;
5566            loose_volume := NVL(loose_volume,0) + l_volume;
5567          END IF;
5568        ELSE
5569          IF (l_volume >= 0) THEN
5570            loose_volume := NVL(loose_volume,0) + l_volume;
5571          END IF;
5572        END IF;
5573 
5574        IF l_debug_on THEN
5575          WSH_DEBUG_SV.logmsg(l_module_name,'Accumulated Gross '||loose_gross_weight||' Net '||loose_net_weight||' Vol '||loose_volume);
5576        END IF;
5577      END LOOP;
5578 
5579      x_net_weight   := loose_net_weight;
5580      x_gross_weight := loose_gross_weight;
5581      x_volume       := loose_volume;
5582      IF l_debug_on THEN
5583        WSH_DEBUG_SV.logmsg(l_module_name,'After accumulating all loose items: Gross '||loose_gross_weight||' Net '||loose_net_weight||' Vol '||loose_volume);
5584      END IF;
5585 
5586      -- For all containers in delivery
5587      FOR wci IN del_containers LOOP
5588 
5589        l_cont_gross_weight := NULL;
5590        l_cont_net_weight   := NULL;
5591        l_cont_volume       := NULL;
5592 
5593        IF l_debug_on THEN
5594          WSH_DEBUG_SV.logmsg(l_module_name,'Processing Cont '||wci.c_id);
5595        END IF;
5596 
5597        -- Call WSH_TPA_CONTAINER_PKG.container_weight_volume API to calculate Container W/V
5598        IF l_debug_on THEN
5599          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit CONTAINER_WEIGHT_VOLUME',WSH_DEBUG_SV.C_PROC_LEVEL);
5600        END IF;
5601 
5602        Container_Weight_Volume (
5603          p_container_instance_id => wci.c_id,
5604          p_override_flag         => p_update_flag,
5605          p_fill_pc_flag          => 'Y',
5606          p_post_process_flag     => 'N',
5607          p_calc_wv_if_frozen     => p_calc_wv_if_frozen,
5608          x_gross_weight          => l_cont_gross_weight,
5609          x_net_weight            => l_cont_net_weight,
5610          x_volume                => l_cont_volume,
5611          x_cont_fill_pc          => l_cont_fill_pc,
5612          x_return_status         => x_return_status);
5613 
5614        IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
5615          IF l_debug_on THEN
5616            WSH_DEBUG_SV.pop(l_module_name);
5617          END IF;
5618          RETURN;
5619        END IF;
5620 
5621        -- Convert the W/V if UOMs differ and then accumulate W/V
5622        IF (wci.wt_uom <> l_weight_uom_code) THEN
5623          IF (l_cont_gross_weight > 0) THEN
5624            IF l_debug_on THEN
5625              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Gross',WSH_DEBUG_SV.C_PROC_LEVEL);
5626            END IF;
5627            x_gross_weight := NVL(x_gross_weight,0) +
5628                         WSH_WV_UTILS.convert_uom(wci.wt_uom, l_weight_uom_code, l_cont_gross_weight, wci.inventory_item_id);
5629          ELSIF (l_cont_gross_weight = 0) THEN
5630            IF l_debug_on THEN
5631              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_cont_gross_weight=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5632            END IF;
5633            x_gross_weight := NVL(x_gross_weight,0) + l_cont_gross_weight;
5634          END IF;
5635 
5636          IF (l_cont_net_weight > 0) THEN
5637            IF l_debug_on THEN
5638              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Net',WSH_DEBUG_SV.C_PROC_LEVEL);
5639            END IF;
5640            x_net_weight := NVL(x_net_weight,0) +
5641                         WSH_WV_UTILS.convert_uom(wci.wt_uom, l_weight_uom_code, l_cont_net_weight, wci.inventory_item_id);
5642          ELSIF (l_cont_net_weight = 0) THEN
5643            IF l_debug_on THEN
5644              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_cont_net_weight=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5645            END IF;
5646            x_net_weight := NVL(x_net_weight,0) + l_cont_net_weight;
5647          END IF;
5648        ELSE
5649          IF (l_cont_gross_weight >= 0) THEN
5650            x_gross_weight := NVL(x_gross_weight,0) + l_cont_gross_weight;
5651          END IF;
5652          IF (l_cont_net_weight >= 0) THEN
5653            x_net_weight := NVL(x_net_weight,0) + l_cont_net_weight;
5654          END IF;
5655        END IF;
5656 
5657        IF (wci.vol_uom <> l_volume_uom_code) THEN
5658          IF (l_cont_volume > 0) THEN
5659            IF l_debug_on THEN
5660              WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WV_UTILS.CONVERT_UOM for converting Volume',WSH_DEBUG_SV.C_PROC_LEVEL);
5661            END IF;
5662            x_volume := NVL(x_volume,0) +
5663                            WSH_WV_UTILS.convert_uom(wci.vol_uom, l_volume_uom_code, l_cont_volume, wci.inventory_item_id);
5664          ELSIF (l_cont_volume = 0) THEN
5665            IF l_debug_on THEN
5666              WSH_DEBUG_SV.logmsg(l_module_name,'adding l_cont_volume=0',WSH_DEBUG_SV.C_PROC_LEVEL);
5667            END IF;
5668            x_volume := NVL(x_volume,0) + l_cont_volume;
5669          END IF;
5670        ELSE
5671          IF (l_cont_volume >= 0) THEN
5672            x_volume := NVL(x_volume,0) + l_cont_volume;
5673          END IF;
5674        END IF;
5675 
5676        IF l_debug_on THEN
5677          WSH_DEBUG_SV.logmsg(l_module_name,'Accumulated Gross '||x_gross_weight||' Net '||x_net_weight||' Vol '||x_volume);
5678        END IF;
5679 
5680      END LOOP;
5681 
5682   END IF; -- IF delivery_type = 'CONSOLIDATION
5683 
5684   -- If p_update_flag is 'Y' then update the delivery with the calculated W/V
5685   IF (p_update_flag = 'Y') THEN
5686     IF l_debug_on THEN
5687       WSH_DEBUG_SV.logmsg(l_module_name,'Updating Del '||p_delivery_id||' With Gross '||x_gross_weight||' Net '||x_net_weight||' Vol '||x_volume);
5688     END IF;
5689 
5690     UPDATE wsh_new_deliveries
5691     SET    net_weight   = x_net_weight,
5692            gross_weight = x_gross_weight,
5693            volume       = x_volume,
5694            wv_frozen_flag  = 'N',
5695            last_update_date  = SYSDATE,
5696            last_updated_by   = FND_GLOBAL.user_id,
5697            last_update_login = FND_GLOBAL.login_id
5698     WHERE  delivery_id = p_delivery_id;
5699 
5700     IF (SQL%NOTFOUND) THEN
5701       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5702       IF l_debug_on THEN
5703         WSH_DEBUG_SV.pop(l_module_name);
5704       END IF;
5705       RETURN;
5706     END IF;
5707 
5708   END IF;
5709 
5710 
5711   -- OTM R12 : packing ECO
5712   -- for the given delivery_id, G_DELIVERY_TMS_IMPACT is changed from N to Y
5713   IF (WSH_WV_UTILS.G_RESET_WV ='Y' AND
5714       G_DELIVERY_TMS_IMPACT = 'Y' AND
5715       l_tms_interface_flag IN (
5716                            WSH_NEW_DELIVERIES_PVT.C_TMS_CREATE_IN_PROCESS,
5717                            WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_IN_PROCESS,
5718                            WSH_NEW_DELIVERIES_PVT.C_TMS_AWAITING_ANSWER,
5719                            WSH_NEW_DELIVERIES_PVT.C_TMS_ANSWER_RECEIVED) AND
5720       l_ignore_for_planning = 'N') THEN
5721     l_delivery_id_tab(1) := p_delivery_id;
5722     l_interface_flag_tab(1) := WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_REQUIRED;
5723     IF l_debug_on THEN
5724       WSH_DEBUG_SV.log(l_module_name, 'l_delivery_id_tab', l_delivery_id_tab(1));
5725       WSH_DEBUG_SV.log(l_module_name, 'l_interface_flag_tab', l_interface_flag_tab(1));
5726     END IF;
5727 
5728     WSH_NEW_DELIVERIES_PVT.update_tms_interface_flag(
5729                          p_delivery_id_tab        => l_delivery_id_tab,
5730                          p_tms_interface_flag_tab => l_interface_flag_tab,
5731                          x_return_status          => l_return_status);
5732 
5733     IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,
5734                           WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
5735       x_return_status := l_return_status;
5736       IF l_debug_on THEN
5737         WSH_DEBUG_SV.log(l_module_name, 'l_return_status', l_return_status);
5738         WSH_DEBUG_SV.pop(l_module_name, 'UPDATE_TMS_INTERFACE_FLAG ERROR');
5739       END IF;
5740       RETURN;
5741     END IF;
5742   END IF;
5743 
5744   --resetting the flag back to default after done with current delivery
5745   IF (G_DELIVERY_TMS_IMPACT = 'N') THEN
5746     G_DELIVERY_TMS_IMPACT := 'Y';
5747   END IF;
5748 
5749   -- End of OTM R12 : packing ECO
5750 
5751 
5752   IF l_num_warnings > 0 THEN
5753     x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
5754   ELSE
5755     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5756   END IF;
5757 
5758   IF l_debug_on THEN
5759     WSH_DEBUG_SV.logmsg(l_module_name,'x_return_status '||x_return_status);
5760     WSH_DEBUG_SV.pop(l_module_name);
5761   END IF;
5762 
5763 EXCEPTION
5764   WHEN e_abort THEN
5765     x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5766     IF l_debug_on THEN
5767       WSH_DEBUG_SV.pop(l_module_name);
5768     END IF;
5769 
5770    WHEN Others THEN
5771      WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.delivery_weight_volume');
5772      x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5773 
5774      IF l_debug_on THEN
5775        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5776        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
5777      END IF;
5778 
5779 END delivery_weight_volume;
5780 
5781 -- J: W/V changes
5782 
5783 -- Start of comments
5784 -- API name : Delivery_Weight_Volume
5785 -- Type     : Public
5786 -- Pre-reqs : None.
5787 -- Function : Calculates Weight and Volume of Delivery
5788 --            If p_update_flag is 'Y' then the calculated W/V is updated on Delivery
5789 --            Otherwise, the API returns the calculated W/V
5790 -- Parameters :
5791 -- IN:
5792 --    p_delivery_detail_id IN NUMBER Required
5793 --    p_update_flag        IN VARCHAR2
5794 --      'Y' if the delivery needs to be updated with the calculated W/V
5795 --    p_post_process_flag  IN VARCHAR2
5796 --      'Y' if W/V post processing is required
5797 --    p_calc_wv_if_frozen  IN VARCHAR2
5798 --      'Y' if manual W/V can be overriden
5799 -- OUT:
5800 --    x_gross_weight OUT NUMBER
5801 --       gives the gross weight of delivery
5802 --    x_net_weight OUT NUMBER
5803 --       gives the net weight of delivery
5804 --    x_volume OUT NUMBER
5805 --       gives the volume of delivery
5806 --    x_return_status OUT VARCHAR2 Required
5807 --       give the return status of API
5808 -- Version : 1.0
5809 -- End of comments
5810 
5811 PROCEDURE Delivery_Weight_Volume (
5812         p_delivery_id    IN NUMBER,
5813         p_update_flag    IN VARCHAR2,
5814         p_post_process_flag IN VARCHAR2,
5815         p_calc_wv_if_frozen IN VARCHAR2 DEFAULT 'Y',
5816         x_gross_weight   OUT NOCOPY  NUMBER,
5817         x_net_weight     OUT NOCOPY  NUMBER,
5818         x_volume         OUT NOCOPY  NUMBER,
5819         x_return_status  OUT NOCOPY  VARCHAR2) IS
5820 
5821 l_org_gross_wt number;
5822 l_org_net_wt   number;
5823 l_org_vol      number;
5824 l_organization_id number;
5825 l_status_code  wsh_new_deliveries.status_code%TYPE;
5826 l_shipment_direction wsh_new_deliveries.shipment_direction%TYPE;
5827 l_wv_frozen_flag wsh_new_deliveries.wv_frozen_flag%TYPE;
5828 
5829 l_return_status VARCHAR2(100);
5830 l_debug_on     BOOLEAN;
5831 l_module_name  CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DELIVERY_WEIGHT_VOLUME';
5832 
5833 BEGIN
5834 
5835   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
5836   IF l_debug_on IS NULL
5837   THEN
5838       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
5839   END IF;
5840   IF l_debug_on THEN
5841       WSH_DEBUG_SV.push(l_module_name);
5842       WSH_DEBUG_SV.log(l_module_name,'P_DELIVERY_ID',P_DELIVERY_ID);
5843       WSH_DEBUG_SV.log(l_module_name,'P_UPDATE_FLAG',P_UPDATE_FLAG);
5844       WSH_DEBUG_SV.log(l_module_name,'P_POST_PROCESS_FLAG',P_POST_PROCESS_FLAG);
5845       WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
5846   END IF;
5847   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5848 
5849   -- Get the delivery info
5850   BEGIN
5851     SELECT gross_weight,
5852            net_weight,
5853            volume,
5854            organization_id,
5855            status_code,
5856            NVL(shipment_direction,'O'),
5857            NVL(wv_frozen_flag,'Y')
5858     INTO   l_org_gross_wt,
5859            l_org_net_wt,
5860            l_org_vol,
5861            l_organization_id,
5862            l_status_code,
5863            l_shipment_direction,
5864            l_wv_frozen_flag
5865     FROM   wsh_new_deliveries
5866     WHERE  delivery_id = p_delivery_id;
5867 
5868   EXCEPTION
5869       WHEN NO_DATA_FOUND THEN
5870         FND_MESSAGE.SET_NAME('WSH','WSH_INVALID_DELIVERY');
5871         FND_MESSAGE.SET_TOKEN('DELIVERY',p_delivery_id);
5872         wsh_util_core.add_message(WSH_UTIL_CORE.G_RET_STS_ERROR);
5873         IF l_debug_on THEN
5874           WSH_DEBUG_SV.logmsg(l_module_name,'Delivery '||p_delivery_id||' not found');
5875           WSH_DEBUG_SV.pop(l_module_name);
5876         END IF;
5877         return;
5878   END;
5879 
5880   IF ((l_shipment_direction in ('O','IO') AND l_status_code IN ('IT','CL','SR')) OR
5881      (p_calc_wv_if_frozen = 'N' AND l_wv_frozen_flag = 'Y')) THEN
5882 
5883     x_gross_weight := l_org_gross_wt;
5884     x_net_weight   := l_org_net_wt;
5885     x_volume       := l_org_vol;
5886 
5887     IF l_debug_on THEN
5888       WSH_DEBUG_SV.logmsg(l_module_name,'Delivery Status is '||l_status_code||' Frozen Flag '||l_wv_frozen_flag||'. Returning delivery weights');
5889       WSH_DEBUG_SV.pop(l_module_name);
5890     END IF;
5891 
5892     RETURN;
5893   END IF;
5894 
5895 
5896   IF l_debug_on THEN
5897     WSH_DEBUG_SV.logmsg(l_module_name,'Del original wts are Gross '||l_org_gross_wt||' Net '||l_org_net_wt||' Vol '||l_org_vol);
5898     WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Delivery_weight_volume',WSH_DEBUG_SV.C_PROC_LEVEL);
5899   END IF;
5900   -- Call Delivery_Weight_Volume API
5901   Delivery_weight_volume (
5902     p_delivery_id    => p_delivery_id,
5903     p_update_flag    => p_update_flag,
5904     p_calc_wv_if_frozen => p_calc_wv_if_frozen,
5905     x_gross_weight   => x_gross_weight,
5906     x_net_weight     => x_net_weight,
5907     x_volume         => x_volume,
5908     x_return_status  => l_return_status);
5909 
5910   IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
5911     x_return_status := l_return_status;
5912     IF l_debug_on THEN
5913       WSH_DEBUG_SV.logmsg(l_module_name,'Delivery_weight_volume returned '||l_return_status);
5914       WSH_DEBUG_SV.pop(l_module_name);
5915      END IF;
5916      return;
5917   END IF;
5918 
5919   -- If p_update_flag is 'Y and ((p_post_process_flag is 'Y' and the new and old W/V differ)
5920   -- then call Del_WV_Post_Process API
5921   IF (p_update_flag = 'Y' AND p_post_process_flag = 'Y' AND
5922       (  (NVL(x_gross_weight,0) <> NVL(l_org_gross_wt,0)) OR
5923          (NVL(x_net_weight,0)   <> NVL(l_org_net_wt,0)) OR
5924          (NVL(x_volume,0)       <> NVL(l_org_vol,0)))) THEN
5925 
5926     IF l_debug_on THEN
5927       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Del_WV_Post_Process',WSH_DEBUG_SV.C_PROC_LEVEL);
5928     END IF;
5929 
5930     Del_WV_Post_Process(
5931       p_delivery_id   => p_delivery_id,
5932       p_diff_gross_wt => NVL(x_gross_weight,0) - NVL(l_org_gross_wt,0),
5933       p_diff_net_wt   => NVL(x_net_weight,0) - NVL(l_org_net_wt,0),
5934       p_diff_volume   => NVL(x_volume,0) - NVL(l_org_vol,0),
5935       x_return_status => l_return_status);
5936 
5937     IF l_return_status in (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
5938       x_return_status := l_return_status;
5939       IF l_debug_on THEN
5940         WSH_DEBUG_SV.logmsg(l_module_name,'Del_WV_Post_Process returned '||l_return_status);
5941         WSH_DEBUG_SV.pop(l_module_name);
5942       END IF;
5943       return;
5944     END IF;
5945   END IF;
5946 
5947   IF l_debug_on THEN
5948     WSH_DEBUG_SV.logmsg(l_module_name,'x_return_status '||x_return_status);
5949     WSH_DEBUG_SV.pop(l_module_name);
5950   END IF;
5951 
5952 EXCEPTION
5953    WHEN Others THEN
5954      WSH_UTIL_CORE.Default_Handler ('WSH_WV_UTILS.delivery_weight_volume');
5955      x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5956 
5957      IF l_debug_on THEN
5958        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5959        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
5960      END IF;
5961 
5962 END Delivery_Weight_Volume;
5963 
5964 -- Start of comments
5965 -- API name : Delivery_Weight_Volume
5966 -- Type     : Public
5967 -- Pre-reqs : None.
5968 -- Function : Calculates Weight and Volume of Multiple Deliveries
5969 --            If p_update_flag is 'Y' then the calculated W/V is updated on Delivery
5970 --            Otherwise, the API returns the calculated W/V
5971 --            If p_calc_wv_if_frozen is 'N' then manually entered W/V will not
5972 --            be overwritten with calculated W/V
5973 -- Parameters :
5974 -- IN:
5975 --    p_delivery_detail_id IN NUMBER Required
5976 --    p_update_flag        IN VARCHAR2
5977 --      'Y' if the delivery needs to be updated with the calculated W/V
5978 --    p_post_process_flag  IN VARCHAR2
5979 --      'Y' if W/V post processing is required
5980 --    p_calc_wv_if_frozen  IN VARCHAR2
5981 --      'Y' if manual W/V can be overriden
5982 -- OUT:
5983 --    x_gross_weight OUT NUMBER
5984 --       gives the gross weight of delivery
5985 --    x_net_weight OUT NUMBER
5986 --       gives the net weight of delivery
5987 --    x_volume OUT NUMBER
5988 --       gives the volume of delivery
5989 --    x_return_status OUT VARCHAR2 Required
5990 --       give the return status of API
5991 -- Version : 1.0
5992 -- End of comments
5993 
5994 PROCEDURE Delivery_Weight_Volume(
5995             p_del_rows       IN wsh_util_core.id_tab_type,
5996             p_update_flag    IN VARCHAR2,
5997             p_calc_wv_if_frozen IN VARCHAR2,
5998             x_return_status  OUT NOCOPY  VARCHAR2) IS
5999 
6000 l_net_weight NUMBER;
6001 l_gross_weight NUMBER;
6002 l_volume NUMBER;
6003 l_num_error NUMBER := 0;
6004 
6005 others EXCEPTION;
6006 
6007 l_debug_on BOOLEAN;
6008 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'DELIVERY_WEIGHT_VOLUME';
6009 
6010 BEGIN
6011 
6012    l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6013    IF l_debug_on IS NULL
6014    THEN
6015        l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6016    END IF;
6017    IF l_debug_on THEN
6018        WSH_DEBUG_SV.push(l_module_name);
6019        WSH_DEBUG_SV.log(l_module_name,'P_UPDATE_FLAG',P_UPDATE_FLAG);
6020        WSH_DEBUG_SV.log(l_module_name,'P_CALC_WV_IF_FROZEN',P_CALC_WV_IF_FROZEN);
6021    END IF;
6022 
6023    IF (p_del_rows.count = 0) THEN
6024     raise others;
6025    END IF;
6026 
6027    FOR i IN 1..p_del_rows.count LOOP
6028 
6029     IF l_debug_on THEN
6030       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit Delivery_Weight_Volume',WSH_DEBUG_SV.C_PROC_LEVEL);
6031     END IF;
6032 
6033     Delivery_Weight_Volume(
6034       p_delivery_id       => p_del_rows(i),
6035       p_update_flag       => p_update_flag,
6036       p_post_process_flag => 'Y',
6037       p_calc_wv_if_frozen => p_calc_wv_if_frozen,
6038       x_gross_weight      => l_gross_weight,
6039       x_net_weight        => l_net_weight,
6040       x_volume            => l_volume,
6041       x_return_status     => x_return_status);
6042 
6043     IF (x_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR) THEN
6044        FND_MESSAGE.SET_NAME('WSH','WSH_DEL_WT_VOL_ERROR');
6045        IF l_debug_on THEN
6046            WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERIES_PVT.GET_NAME',WSH_DEBUG_SV.C_PROC_LEVEL);
6047        END IF;
6048        FND_MESSAGE.SET_TOKEN('DEL_NAME',wsh_new_deliveries_pvt.get_name(p_del_rows(i)));
6049        x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
6050        wsh_util_core.add_message(x_return_status);
6051        WSH_NEW_DELIVERY_ACTIONS.g_error_level := 'E';
6052        l_num_error := l_num_error + 1;
6053       END IF;
6054 
6055    END LOOP;
6056 
6057    IF (p_del_rows.count > 1) THEN
6058 
6059     IF (l_num_error > 0) THEN
6060 
6061        FND_MESSAGE.SET_NAME('WSH','WSH_DEL_WT_VOL_SUMMARY');
6062        FND_MESSAGE.SET_TOKEN('NUM_ERROR',l_num_error);
6063        FND_MESSAGE.SET_TOKEN('NUM_SUCCESS',p_del_rows.count - l_num_error);
6064 
6065        IF (p_del_rows.count = l_num_error) THEN
6066         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
6067        ELSE
6068           x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
6069        END IF;
6070 
6071        wsh_util_core.add_message(x_return_status);
6072 
6073     ELSE
6074        x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6075     END IF;
6076 
6077    END IF;
6078 
6079    IF l_debug_on THEN
6080      WSH_DEBUG_SV.pop(l_module_name);
6081    END IF;
6082 
6083 EXCEPTION
6084    WHEN others THEN
6085 
6086      wsh_util_core.default_handler ('WSH_WV_UTILS.DELIVERY_WEIGHT_VOLUME');
6087      x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6088 
6089      IF l_debug_on THEN
6090        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6091        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6092    END IF;
6093 
6094 END Delivery_Weight_Volume;
6095 
6096 
6097 -- HW OPMCONV - New routine to check item deviation
6098 -- Function:	within_deviation
6099 -- Parameters:	p_organization_id     - organization id
6100 -- 		p_inventory_item_id   - Inventory Item id
6101 --              p_lot_number          - Lot number
6102 --              p_precision           - Precision - default 5
6103 --              p_quantity            - Primary Qty
6104 --              p_uom1                - Uom code to convert from
6105 --              p_quantity2           - Secondary Qty
6106 --              p_uom2                - Uom code to convert to
6107 -- Description: This function calls new INV routine INV_CONVERT.within_deviation
6108 --              to check if Qtys are within deviation for item types 'D' and 'N'
6109 
6110 FUNCTION within_deviation (
6111       p_organization_id         IN   NUMBER,
6112       p_inventory_item_id       IN   NUMBER,
6113       p_lot_number              IN   VARCHAR2,
6114       p_precision               IN   NUMBER default 5,
6115       p_quantity                IN   NUMBER,
6116       p_uom1                    IN   VARCHAR2,
6117       p_quantity2               IN   NUMBER,
6118       p_uom2                    IN   VARCHAR2) RETURN NUMBER
6119 IS
6120 
6121 result        NUMBER;
6122 
6123 l_debug_on BOOLEAN;
6124 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'WITHIN_DEVIATION';
6125 
6126 BEGIN
6127 
6128 -- INV API will validate item, org, UOMs and deviations and will raise
6129 -- errors where applicable
6130 
6131     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6132     --
6133     IF l_debug_on IS NULL
6134     THEN
6135         l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6136     END IF;
6137 
6138    IF l_debug_on THEN
6139       WSH_DEBUG_SV.push(l_module_name);
6140       WSH_DEBUG_SV.log(l_module_name,'p_organization_id',p_organization_id);
6141       WSH_DEBUG_SV.log(l_module_name,'p_inventory_item_id',p_inventory_item_id);
6142       WSH_DEBUG_SV.log(l_module_name,'p_lot_number',p_lot_number);
6143       WSH_DEBUG_SV.log(l_module_name,'p_quantity',p_quantity);
6144       WSH_DEBUG_SV.log(l_module_name,'p_quantity2',p_quantity2);
6145       WSH_DEBUG_SV.log(l_module_name,'p_uom1',p_lot_number);
6146       WSH_DEBUG_SV.log(l_module_name,'p_uom2',p_uom2);
6147       WSH_DEBUG_SV.log(l_module_name,'p_precision',p_precision);
6148    END IF;
6149 
6150 
6151      result := INV_CONVERT.within_deviation(
6152           p_organization_id,
6153           p_inventory_item_id,
6154           p_lot_number,
6155           p_precision,
6156           p_quantity ,
6157           p_uom1,
6158           p_quantity2,
6159           p_uom2 );
6160 
6161 
6162        IF ( result = 1 ) THEN
6163          result := 1;
6164        ELSE
6165          result := 0;
6166        END IF;
6167 
6168       RETURN result;
6169 
6170 
6171 EXCEPTION
6172    WHEN others THEN
6173      wsh_util_core.default_handler ('WSH_WV_UTILS.within_deviation');
6174 
6175      IF l_debug_on THEN
6176        WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6177        WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6178      END IF;
6179 END within_deviation;
6180 
6181 --OTM R12, creating wrapper for prorate_weight_actual so we only update delivery tms flag once
6182 -- Procedure name : Prorate_weight
6183 -- Pre-reqs       : Prorate_wt_flag should be 'Y' for the delivery.
6184 -- Description    : Prorates weight of the given delivery/container to its immediate children
6185 --
6186 -- Parameters :
6187 --    p_entity_type  	- DELIVERY or CONTAINER
6188 --    p_entity_id       - Delivery_id or Container_id
6189 --    p_old_gross_wt	- Original Gross Weight of the entity
6190 --    p_new_gross_wt	- New Gross Weight of the entity
6191 --    p_old_net_wt      - Original Net Weight of the entity
6192 --    p_net_net_wt	- New Net Weight of the entity
6193 --    p_weight_uom_code - Weight UOM of the entity
6194 
6195 PROCEDURE Prorate_weight(
6196             p_entity_type	    IN         VARCHAR2,
6197             p_entity_id		    IN         NUMBER,
6198             p_old_gross_wt	    IN         NUMBER,
6199 	    p_new_gross_wt	    IN         NUMBER,
6200             p_old_net_wt	    IN         NUMBER,
6201 	    p_new_net_wt	    IN         NUMBER,
6202             p_weight_uom_code       IN         VARCHAR2,
6203 	    x_return_status         OUT NOCOPY VARCHAR2,
6204             p_call_level            IN         NUMBER) IS
6205 
6206   CURSOR c_get_delivery_info_cont(p_detail_id IN NUMBER) IS
6207     SELECT wda.delivery_id,
6208            wnd.weight_uom_code
6209     FROM   WSH_DELIVERY_ASSIGNMENTS wda,
6210            WSH_NEW_DELIVERIES wnd
6211     WHERE  wda.delivery_detail_id = p_detail_id
6212     AND    wda.delivery_id = wnd.delivery_id
6213     AND    wda.delivery_id IS NOT NULL
6214     AND    NVL(wnd.ignore_for_planning, 'N') = 'N'
6215     AND    NVL(wnd.tms_interface_flag, WSH_NEW_DELIVERIES_PVT.C_TMS_NOT_TO_BE_SENT)
6216            IN (WSH_NEW_DELIVERIES_PVT.C_TMS_CREATE_IN_PROCESS,
6217                WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_IN_PROCESS,
6218                WSH_NEW_DELIVERIES_PVT.C_TMS_AWAITING_ANSWER,
6219                WSH_NEW_DELIVERIES_PVT.C_TMS_ANSWER_RECEIVED);
6220 
6221   CURSOR c_get_delivery_info_del(p_delivery_id IN NUMBER) IS
6222     SELECT delivery_id,
6223            weight_uom_code
6224     FROM   WSH_NEW_DELIVERIES
6225     WHERE  delivery_id = p_delivery_id
6226     AND    NVL(ignore_for_planning, 'N') = 'N'
6227     AND    NVL(tms_interface_flag, WSH_NEW_DELIVERIES_PVT.C_TMS_NOT_TO_BE_SENT)
6228            IN (WSH_NEW_DELIVERIES_PVT.C_TMS_CREATE_IN_PROCESS,
6229                WSH_NEW_DELIVERIES_PVT.C_TMS_UPDATE_IN_PROCESS,
6230                WSH_NEW_DELIVERIES_PVT.C_TMS_AWAITING_ANSWER,
6231                WSH_NEW_DELIVERIES_PVT.C_TMS_ANSWER_RECEIVED);
6232 
6233   l_delivery_id 	   WSH_NEW_DELIVERIES.DELIVERY_ID%TYPE;
6234   l_delivery_id_tab        WSH_UTIL_CORE.ID_TAB_TYPE;
6235   l_interface_flag_tab     WSH_UTIL_CORE.COLUMN_TAB_TYPE;
6236   l_gc3_is_installed       VARCHAR2(1);
6237   l_weight_uom_code        WSH_NEW_DELIVERIES.WEIGHT_UOM_CODE%TYPE;
6238   api_return_fail          EXCEPTION;
6239 
6240   l_return_status          VARCHAR2(1);
6241   l_debug_on               BOOLEAN;
6242 
6243   l_module_name  CONSTANT  VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'PRORATE_WEIGHT';
6244 
6245   BEGIN
6246     --
6247     -- Debug Statements
6248     --
6249     --
6250     l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6251     --
6252     IF l_debug_on IS NULL  THEN
6253       l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6254     END IF;
6255     --
6256     --
6257     -- Debug Statements
6258     --
6259     IF l_debug_on THEN
6260 
6261       wsh_debug_sv.push(l_module_name);
6262       --
6263       wsh_debug_sv.LOG(l_module_name, 'P_ENTITY_TYPE', p_entity_type);
6264       wsh_debug_sv.LOG(l_module_name, 'P_ENTITY_ID', p_entity_id );
6265       wsh_debug_sv.LOG(l_module_name, 'P_OLD_GROSS_WT',p_old_gross_wt  );
6266       wsh_debug_sv.LOG(l_module_name, 'P_NEW_GROSS_WT', p_new_gross_wt);
6267       wsh_debug_sv.LOG(l_module_name, 'P_OLD_NET_WT',p_old_net_wt  );
6268       wsh_debug_sv.LOG(l_module_name, 'P_NEW_NET_WT', p_new_net_wt);
6269       wsh_debug_sv.LOG(l_module_name, 'P_WEIGHT_UOM_CODE', p_weight_uom_code);
6270       wsh_debug_sv.LOG(l_module_name, 'p_call_level', p_call_level);
6271     END IF;
6272 
6273     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6274 
6275     l_gc3_is_installed := WSH_UTIL_CORE.G_GC3_IS_INSTALLED; -- this is global variable
6276 
6277     IF l_gc3_is_installed IS NULL THEN
6278       l_gc3_is_installed := WSH_UTIL_CORE.GC3_IS_INSTALLED; -- this is actual function
6279     END IF;
6280 
6281     --first call real prorate procedure to prorate the delivery/container
6282     IF l_debug_on THEN
6283       WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit prorate_weight_actual',WSH_DEBUG_SV.C_PROC_LEVEL);
6284     END IF;
6285 
6286     prorate_weight_actual(
6287             p_entity_type     => p_entity_type,
6288             p_entity_id       => p_entity_id,
6289             p_old_gross_wt    => p_old_gross_wt,
6290             p_new_gross_wt    => p_new_gross_wt,
6291             p_old_net_wt      => p_old_net_wt,
6292             p_new_net_wt      => p_new_net_wt,
6293             p_weight_uom_code => p_weight_uom_code,
6294             x_return_status   => l_return_status,
6295             p_call_level      => p_call_level);
6296 
6297     IF l_debug_on THEN
6298       WSH_DEBUG_SV.logmsg(l_module_name, 'return status from prorate_weight_actual: ' || l_return_status);
6299     END IF;
6300 
6301     x_return_status := l_return_status;
6302 
6303     IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR, WSH_UTIL_CORE.G_RET_STS_ERROR)) THEN
6304       RAISE api_return_fail;
6305     END IF;
6306 
6307     --after prorate, details are changed, so check if the weights have changed
6308     --then call update for delivery tms_interface_flag.
6309     IF (l_gc3_is_installed = 'Y') THEN
6310 
6311       l_delivery_id := NULL;
6312       l_weight_uom_code := NULL;
6313 
6314       IF p_entity_type = 'DELIVERY' THEN
6315         OPEN c_get_delivery_info_del(p_entity_id);
6316         FETCH c_get_delivery_info_del INTO l_delivery_id,
6317                                            l_weight_uom_code;
6318         IF (c_get_delivery_info_del%NOTFOUND) THEN
6319           l_delivery_id := NULL;
6320         END IF;
6321         CLOSE c_get_delivery_info_del;
6322       ELSIF p_entity_type = 'CONTAINER' THEN
6323         OPEN c_get_delivery_info_cont(p_entity_id);
6324         FETCH c_get_delivery_info_cont INTO l_delivery_id,
6325                                             l_weight_uom_code;
6326         IF (c_get_delivery_info_cont%NOTFOUND) THEN
6327           l_delivery_id := NULL;
6328         END IF;
6329         CLOSE c_get_delivery_info_cont;
6330       END IF;
6331 
6332       IF (l_delivery_id IS NOT NULL
6333           AND ((NVL(p_weight_uom_code, '!@#$%') <> NVL(l_weight_uom_code,  '!@#$%'))
6334                OR (NVL(p_old_net_wt, -99) <> NVL(p_new_net_wt, -99))
6335                OR (NVL(p_old_gross_wt, -99) <> NVL(p_new_gross_wt, -99)))) THEN
6336 
6337         l_delivery_id_tab(1) := l_delivery_id;
6338         l_interface_flag_tab(1) := 'UR';
6339 
6340         IF l_debug_on THEN
6341           WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_NEW_DELIVERIES_PVT.UPDATE_TMS_INTERFACE_FLAG',WSH_DEBUG_SV.C_PROC_LEVEL);
6342         END IF;
6343 
6344         WSH_NEW_DELIVERIES_PVT.update_tms_interface_flag(
6345                  p_delivery_id_tab        => l_delivery_id_tab,
6346                  p_tms_interface_flag_tab => l_interface_flag_tab,
6347                  x_return_status          => l_return_status);
6348 
6349         IF l_debug_on THEN
6350           WSH_DEBUG_SV.logmsg(l_module_name, 'return status from WSH_NEW_DELIVERIES_PVT.UPDATE_TMS_INTERFACE_FLAG: ' || l_return_status);
6351         END IF;
6352 
6353         IF (l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR, WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR)) THEN
6354           RAISE api_return_fail;
6355         ELSIF (l_return_status = WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
6356           x_return_status := l_return_status;
6357         END IF;
6358 
6359       END IF; -- delivery id not null
6360     END IF;  --gc3 installed
6361 
6362     --
6363     -- Debug Statements
6364     --
6365     IF l_debug_on THEN
6366       WSH_DEBUG_SV.log(l_module_name, 'x_return_status', x_return_status);
6367       WSH_DEBUG_SV.pop(l_module_name);
6368     END IF;
6369     --
6370     EXCEPTION
6371       WHEN api_return_fail THEN
6372         x_return_status := l_return_status;
6373         IF l_debug_on THEN
6374           WSH_DEBUG_SV.log(l_module_name, 'x_return_status', x_return_status);
6375           WSH_DEBUG_SV.pop(l_module_name);
6376         END IF;
6377       WHEN OTHERS THEN
6378         x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6379 
6380         IF (c_get_delivery_info_del%ISOPEN) THEN
6381           CLOSE c_get_delivery_info_del;
6382         END IF;
6383 
6384         IF (c_get_delivery_info_cont%ISOPEN) THEN
6385           CLOSE c_get_delivery_info_cont;
6386         END IF;
6387 
6388         WSH_UTIL_CORE.default_handler('WSH_WV_UTILS.Prorate_weight' );
6389         --
6390         -- Debug Statements
6391         --
6392         IF l_debug_on THEN
6393           WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6394           WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
6395         END IF;
6396         --
6397   END Prorate_weight;
6398 
6399 --END OTM R12
6400 
6401 --OTM R12, for this procedure, changed the name to prorate_weight_actual so the wrapper prorate_weight
6402 --can be used without changing any caller code, so the old prorate_weight calls in this procedure is all changed to
6403 --prorate_weight_actual
6404 
6405 -- Bug#4254552:"Proration of weight from Delivery to delivery lines" Project.
6406 -- Procedure name : Prorate_weight_actual
6407 -- Pre-reqs       : Prorate_wt_flag should be 'Y' for the delivery.
6408 -- Description    : Prorates weight of the given delivery/container to its immediate children
6409 --
6410 -- Parameters :
6411 --    p_entity_type  	- DELIVERY or CONTAINER
6412 --    p_entity_id       - Delivery_id or Container_id
6413 --    p_old_gross_wt	- Original Gross Weight of the entity
6414 --    p_new_gross_wt	- New Gross Weight of the entity
6415 --    p_old_net_wt      - Original Net Weight of the entity
6416 --    p_net_net_wt	- New Net Weight of the entity
6417 --    p_weight_uom_code - Weight UOM of the entity
6418 
6419 PROCEDURE Prorate_weight_actual(
6420             p_entity_type	    IN  VARCHAR2,
6421             p_entity_id		    IN  NUMBER,
6422             p_old_gross_wt	    IN  NUMBER,
6423 	    p_new_gross_wt	    IN  NUMBER,
6424             p_old_net_wt	    IN  NUMBER,
6425 	    p_new_net_wt	    IN  NUMBER,
6426             p_weight_uom_code       IN  VARCHAR2,
6427 	    x_return_status    	OUT NOCOPY VARCHAR2,
6428             p_call_level            IN NUMBER) IS
6429 
6430 -- Get immediate container/delivery line information for the given delivery_id
6431 
6432 CURSOR immediate_details_del(p_delivery_id IN NUMBER, p_wt_uom IN VARCHAR2) IS
6433 SELECT wdd.delivery_detail_id,
6434        nvl(wdd.net_weight,0) net_wt,
6435        nvl(wdd.gross_weight,0) gross_wt,
6436        nvl(wdd.gross_weight,0) - nvl(wdd.net_weight,0) tare_wt,
6437        decode(wdd.weight_uom_code,p_wt_uom,nvl(wdd.net_weight,0),wsh_wv_utils.convert_uom(wdd.weight_uom_code,p_wt_uom,nvl(wdd.net_weight,0),wdd.inventory_item_id)) net_wt_in_parent_uom,
6438        decode(wdd.weight_uom_code,p_wt_uom,nvl(wdd.gross_weight,0)-nvl(wdd.net_weight,0),wsh_wv_utils.convert_uom(wdd.weight_uom_code,p_wt_uom,(nvl(wdd.gross_weight,0)-nvl(wdd.net_weight,0)),wdd.inventory_item_id)) tare_wt_in_parent_uom,
6439        wdd.weight_uom_code,
6440        wdd.inventory_item_id,
6441        wdd.container_flag,
6442        nvl(wdd.line_direction, 'O') line_direction, -- LPN CONV. rv
6443        wdd.organization_id organization_id          -- LPN CONV. rv
6444 FROM  wsh_delivery_assignments_v wda,
6445       wsh_delivery_details wdd
6446 WHERE wda.delivery_id = p_delivery_id
6447 AND   wda.parent_delivery_detail_id IS NULL
6448 AND   wda.delivery_detail_id = wdd.delivery_detail_id
6449 AND   nvl(wdd.gross_weight,0) > 0
6450 FOR UPDATE NOWAIT;
6451 
6452 -- Get immediate container/delivery line information for the given container_id
6453 CURSOR immediate_details_cont(p_container_id IN NUMBER, p_wt_uom IN VARCHAR2) IS
6454 SELECT wdd.delivery_detail_id,
6455        nvl(wdd.net_weight,0)   net_wt,
6456        nvl(wdd.gross_weight,0) gross_wt,
6457        nvl(wdd.gross_weight,0) - nvl(wdd.net_weight,0) tare_wt,
6458        decode(wdd.weight_uom_code,p_wt_uom,nvl(wdd.net_weight,0),wsh_wv_utils.convert_uom(wdd.weight_uom_code,p_wt_uom,nvl(wdd.net_weight,0),wdd.inventory_item_id)) net_wt_in_parent_uom,
6459        decode(wdd.weight_uom_code,p_wt_uom,nvl(wdd.gross_weight,0)-nvl(wdd.net_weight,0),wsh_wv_utils.convert_uom(wdd.weight_uom_code,p_wt_uom,(nvl(wdd.gross_weight,0)-nvl(wdd.net_weight,0)),wdd.inventory_item_id)) tare_wt_in_parent_uom,
6460        wdd.weight_uom_code,
6461        wdd.inventory_item_id,
6462        wdd.container_flag,
6463        nvl(wdd.line_direction, 'O') line_direction, -- LPN CONV. rv
6464        wdd.organization_id organization_id          -- LPN CONV. rv
6465 FROM  wsh_delivery_assignments_v wda,
6466       wsh_delivery_details wdd
6467 WHERE wda.parent_delivery_detail_id IS NOT NULL
6468 AND   wda.parent_delivery_detail_id = p_container_id
6469 AND   wda.delivery_detail_id = wdd.delivery_detail_id
6470 AND   nvl(wdd.gross_weight,0) > 0
6471 FOR UPDATE NOWAIT;
6472 
6473 TYPE Prorate_Rec_Type IS RECORD (
6474 	delivery_detail_id	NUMBER,
6475 	old_gross_weight	NUMBER,
6476 	new_gross_weight	NUMBER,
6477 	old_net_weight		NUMBER,
6478 	new_net_weight		NUMBER,
6479 	wt_uom_code		VARCHAR2(3));
6480 
6481 TYPE Prorate_Tab_Type IS TABLE OF Prorate_Rec_Type index by binary_integer;
6482 
6483 l_lpn_tab	        Prorate_Tab_Type;
6484 -- Used to store the immediate Container's info to call the API recursively
6485 immediate_detail_rec	immediate_details_del%ROWTYPE;
6486 -- Used to store immediate delivery detail lines information
6487 TYPE immediate_detail_rec_tab IS TABLE OF immediate_details_del%ROWTYPE INDEX BY binary_integer;
6488 l_detail_rec_tab    immediate_detail_rec_tab;
6489 
6490 -- Following variables are used to store the immediate container/delivery lines' info
6491 l_dd_upd_tbl            WSH_UTIL_CORE.Id_Tab_Type; -- Stores all immediate child delivery detail ids'
6492 l_dd_upd_net_wt_tbl 	WSH_UTIL_CORE.Id_Tab_Type; -- Stores Net weights(in entity's UOM) of all immediate children
6493 l_dd_upd_gross_wt_tbl	WSH_UTIL_CORE.Id_Tab_Type; -- Stores Tare weights(in entity's UOM) of all immediate children
6494 --
6495 
6496 l_new_tare_wt		NUMBER := 0;
6497 l_new_gross_wt		NUMBER := 0;
6498 l_new_net_wt		NUMBER := 0;
6499 
6500 l_new_tare_wt_in_parent_uom NUMBER;
6501 l_new_net_wt_in_parent_uom  NUMBER;
6502 
6503 l_entity_tare_change	NUMBER;		-- Change in Tare Weight of the passed entity
6504 l_entity_net_change	NUMBER;		-- Change in Net Weight of the passed entity
6505 l_total_tare_wt		NUMBER := 0;	-- Stores the total Tare Weight of all immediate Containers/Delivery lines.
6506 l_total_net_wt		NUMBER := 0;	-- Stores the total Net Weight of all immediate Containers/Delivery lines.
6507 
6508 
6509 l_lpn_count             NUMBER := 0;
6510 
6511 -- LPN CONV. rv
6512 l_wms_org VARCHAR2(10);
6513 l_sync_tmp_wms_recTbl wsh_glbl_var_strct_grp.sync_tmp_recTbl_type;
6514 l_sync_tmp_inv_recTbl wsh_glbl_var_strct_grp.sync_tmp_recTbl_type;
6515 
6516 l_child_cnt_counter NUMBER;
6517 l_cnt_wms_counter NUMBER;
6518 l_cnt_inv_counter NUMBER;
6519 -- LPN CONV. rv
6520 
6521 
6522 -- Standard call to check for call compatibility
6523 l_return_status               VARCHAR2(30) := NULL;
6524 l_num_errors            NUMBER := 0;
6525 l_num_warnings          NUMBER := 0;
6526 l_debug_on              BOOLEAN;
6527 
6528 l_update_to_containers VARCHAR2(2) := WSH_WMS_LPN_GRP.g_update_to_containers;
6529 l_call_group_api      VARCHAR2(2) := WSH_WMS_LPN_GRP.g_call_group_api;
6530 l_lpn_in_sync_comm_rec WSH_GLBL_VAR_STRCT_GRP.lpn_sync_comm_in_rec_type;
6531 l_lpn_out_sync_comm_rec WSH_GLBL_VAR_STRCT_GRP.lpn_sync_comm_out_rec_type;
6532 l_call_level          NUMBER;
6533 
6534 l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'PRORATE_WEIGHT_ACTUAL';
6535 
6536 BEGIN
6537   --
6538   -- Debug Statements
6539   --
6540   --
6541   l_debug_on := WSH_DEBUG_INTERFACE.g_debug;
6542   --
6543   IF l_debug_on IS NULL  THEN
6544   --{
6545      l_debug_on := WSH_DEBUG_SV.is_debug_enabled;
6546   --}
6547   END IF;
6548   --
6549   --
6550   -- Debug Statements
6551   --
6552   IF l_debug_on THEN
6553   --{
6554      wsh_debug_sv.push(l_module_name);
6555      --
6556      wsh_debug_sv.LOG(l_module_name, 'P_ENTITY_TYPE', p_entity_type);
6557      wsh_debug_sv.LOG(l_module_name, 'P_ENTITY_ID', p_entity_id );
6558      wsh_debug_sv.LOG(l_module_name, 'P_OLD_GROSS_WT',p_old_gross_wt  );
6559      wsh_debug_sv.LOG(l_module_name, 'P_NEW_GROSS_WT', p_new_gross_wt);
6560      wsh_debug_sv.LOG(l_module_name, 'P_OLD_NET_WT',p_old_net_wt  );
6561      wsh_debug_sv.LOG(l_module_name, 'P_NEW_NET_WT', p_new_net_wt);
6562      wsh_debug_sv.LOG(l_module_name, 'P_WEIGHT_UOM_CODE', p_weight_uom_code);
6563      wsh_debug_sv.LOG(l_module_name, 'p_call_level', p_call_level);
6564   --}
6565   END IF;
6566 
6567   x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6568 
6569   -- Find the change in net and tare wts
6570   l_entity_tare_change   := ( nvl(p_new_gross_wt,0) - nvl(p_new_net_wt,0) ) - ( nvl(p_old_gross_wt,0) - nvl(p_old_net_wt,0) );
6571   l_entity_net_change    := nvl(p_new_net_wt,0) - nvl(p_old_net_wt,0);
6572 
6573 
6574   --
6575   IF l_debug_on THEN
6576     WSH_DEBUG_SV.logmsg(l_module_name,'Change in Net: '||l_entity_net_change||', Change in Tare: '||l_entity_tare_change);
6577   END IF;
6578   --
6579   -- Do proration only when there is a change in tare/net.
6580   IF l_entity_tare_change  <> 0 OR l_entity_net_change <> 0 THEN
6581   --{
6582      IF p_entity_type = 'DELIVERY' THEN
6583         OPEN immediate_details_del(p_entity_id,p_weight_uom_code);
6584      ELSIF p_entity_type = 'CONTAINER' THEN
6585         OPEN immediate_details_cont(p_entity_id,p_weight_uom_code);
6586      END IF;
6587 
6588      -- Calculating the total Net and Tare Weight of all immediate delivery lines which are
6589      -- required later to find out the proportional weight.
6590      --
6591      IF l_debug_on THEN
6592         WSH_DEBUG_SV.logmsg(l_module_name,'Calculating the total Net and Tare Weight of all immediate delivery lines');
6593      END IF;
6594      --
6595      LOOP
6596      --{ Looping thru' all immediate children for the delivery/container
6597         IF p_entity_type = 'DELIVERY' THEN
6598            FETCH immediate_details_del INTO immediate_detail_rec;
6599 	   EXIT WHEN immediate_details_del%NOTFOUND;
6600         ELSIF p_entity_type = 'CONTAINER' THEN
6601            FETCH immediate_details_cont INTO immediate_detail_rec;
6602 	   EXIT WHEN immediate_details_cont%NOTFOUND;
6603         END IF;
6604         -- Cache the Weights of immediate Containers/Delivery lines of the Delivery
6605         l_detail_rec_tab(l_detail_rec_tab.COUNT + 1) := immediate_detail_rec;
6606 
6607         l_total_net_wt := l_total_net_wt + immediate_detail_rec.net_wt_in_parent_uom;
6608         l_total_tare_wt := l_total_tare_wt + immediate_detail_rec.tare_wt_in_parent_uom;
6609      --} Looping thru' all immediate children for the delivery/container
6610      END LOOP;
6611 
6612      IF immediate_details_del%ISOPEN THEN
6613         CLOSE immediate_details_del;
6614      END IF;
6615      IF immediate_details_cont%ISOPEN THEN
6616         CLOSE immediate_details_cont;
6617      END IF;
6618      --
6619      IF l_debug_on THEN
6620        WSH_DEBUG_SV.logmsg(l_module_name,'Total Tare Weight: '||l_total_tare_wt||', Total Net Weight: ' ||l_total_net_wt);
6621      END IF;
6622      --
6623      IF ( l_total_net_wt = 0 AND l_total_tare_wt = 0 ) THEN
6624      --{
6625         --
6626         IF l_debug_on THEN
6627            WSH_DEBUG_SV.logmsg(l_module_name,'There is no proration required as the total Tare and Net weights are zero, ');
6628         END IF;
6629         --
6630         RETURN;
6631      --}
6632      END IF;
6633 
6634      l_call_level := NVL(p_call_level,0) + 1;
6635 
6636      IF p_call_level IS NULL THEN --{
6637         --bmso call out for WMS to flush all the record prior to prorating.
6638        IF l_debug_on THEN
6639          WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
6640        END IF;
6641        --
6642        WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS
6643          (
6644            p_in_rec             => l_lpn_in_sync_comm_rec,
6645            x_return_status      => l_return_status,
6646            x_out_rec            => l_lpn_out_sync_comm_rec
6647          );
6648        --
6649        IF l_debug_on THEN
6650            WSH_DEBUG_SV.log(l_module_name,  'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_LPNS_TO_WMS', l_return_status);
6651        END IF;
6652 
6653        WSH_UTIL_CORE.API_POST_CALL
6654          (
6655            p_return_status => l_return_status,
6656            x_num_warnings  => l_num_warnings,
6657            x_num_errors    => l_num_errors
6658          );
6659 
6660      END IF; --}
6661 
6662      -- Calculate the change in Weights of Delivery detail.
6663      -- change in Weight of DD = (DD's original weight/total weight of all the children) * change in entity's weight;
6664      --
6665      -- LPN CONV. rv
6666      l_cnt_wms_counter := 1;
6667      l_cnt_inv_counter := 1;
6668      -- LPN CONV. rv
6669      --
6670      FOR i IN 1..l_detail_rec_tab.COUNT
6671      LOOP
6672      --{
6673 
6674         l_new_tare_wt := 0;
6675         l_new_net_wt  := 0;
6676         --
6677         -- Debug Statements
6678         --
6679         IF l_debug_on THEN
6680            WSH_DEBUG_SV.log(l_module_name,'********* Processing the Delivery Detail Id:',l_detail_rec_tab(i).delivery_detail_id);
6681            WSH_DEBUG_SV.logmsg(l_module_name, 'Current Wts are, Gross '||l_detail_rec_tab(i).gross_wt|| ' Net '||l_detail_rec_tab(i).net_wt||' Tare '||l_detail_rec_tab(i).tare_wt|| ' Weight UOM '||l_detail_rec_tab(i).weight_uom_code);
6682         END IF;
6683         --
6684         -- Calculate the change in Tare Weight
6685         IF ( l_entity_tare_change <> 0 ) THEN
6686          --{ tare wt change
6687             IF (p_weight_uom_code <> l_detail_rec_tab(i).weight_uom_code ) THEN
6688             --{ UOM's are different
6689                IF l_detail_rec_tab(i).tare_wt_in_parent_uom <> 0 THEN
6690                --{
6691                   l_new_tare_wt_in_parent_uom :=l_detail_rec_tab(i).tare_wt_in_parent_uom + (l_detail_rec_tab(i).tare_wt_in_parent_uom/l_total_tare_wt) * l_entity_tare_change;
6692                   l_new_tare_wt    := WSH_WV_UTILS.convert_uom(
6693 					            p_weight_uom_code,
6694 	              		                    l_detail_rec_tab(i).weight_uom_code,
6695 				                    l_new_tare_wt_in_parent_uom,
6696   			                            l_detail_rec_tab(i).inventory_item_id);
6697                --}
6698                END IF;
6699 	    ELSE
6700                IF l_detail_rec_tab(i).tare_wt <> 0 THEN
6701                   l_new_tare_wt := l_detail_rec_tab(i).tare_wt+(l_detail_rec_tab(i).tare_wt/l_total_tare_wt) * l_entity_tare_change;
6702                END IF;
6703             --} UOM's are different
6704             END IF;
6705             -- Final Tare weight
6706             l_new_tare_wt   := ROUND(l_new_tare_wt,5);
6707         ELSE
6708            l_new_tare_wt := l_detail_rec_tab(i).tare_wt;
6709         --} tare wt change
6710         END IF;
6711 
6712         -- Calculate the change in Net Weight
6713         IF  ( l_entity_net_change <> 0 ) THEN
6714          --{ net weight change
6715             IF (p_weight_uom_code <> l_detail_rec_tab(i).weight_uom_code ) THEN
6716              --{ UOM's are different
6717                 IF l_detail_rec_tab(i).net_wt_in_parent_uom <> 0 THEN
6718                 --{
6719                    l_new_net_wt_in_parent_uom :=l_detail_rec_tab(i).net_wt_in_parent_uom + (l_detail_rec_tab(i).net_wt_in_parent_uom/l_total_net_wt) * l_entity_net_change;
6720                    l_new_net_wt    := WSH_WV_UTILS.convert_uom(
6721 	 		                     p_weight_uom_code,
6722 	           		             l_detail_rec_tab(i).weight_uom_code,
6723 		                             l_new_net_wt_in_parent_uom,
6724   			                     l_detail_rec_tab(i).inventory_item_id);
6725                 --}
6726                 END IF;
6727 	    ELSE
6728                IF l_detail_rec_tab(i).net_wt <> 0 THEN
6729                   l_new_net_wt := l_detail_rec_tab(i).net_wt+(l_detail_rec_tab(i).net_wt/l_total_net_wt) * l_entity_net_change;
6730                END IF;
6731             --} UOM's are different
6732             END IF;
6733             -- Final Net weight
6734             l_new_net_wt    := ROUND(l_new_net_wt ,5);
6735         ELSE
6736            l_new_net_wt := l_detail_rec_tab(i).net_wt ;
6737         --} net weight change
6738         END IF;
6739 
6740         -- Wt should not be -ve
6741         IF l_new_net_wt < 0 THEN
6742            l_new_net_wt := 0;
6743         END IF;
6744 
6745         IF l_new_tare_wt < 0 THEN
6746            l_new_tare_wt := 0;
6747         END IF;
6748 
6749         l_new_gross_wt  := l_new_net_wt + l_new_tare_wt;
6750 
6751         -- Make the new Gross Weight equal to Net Weight, if the Gross Weight is lesser than Net Weight due to precision loss
6752         IF l_new_gross_wt  < l_new_net_wt THEN
6753            l_new_gross_wt := l_new_net_wt;
6754         END IF;
6755         --
6756         IF l_debug_on THEN
6757 	       WSH_DEBUG_SV.logmsg(l_module_name,'New Weights are, Gross ' || l_new_gross_wt ||' Net '||l_new_net_wt ||' Tare '||l_new_tare_wt);
6758         END IF;
6759         --
6760         -- Cache the new weights of the Containers to pass them to recursive call
6761         -- If immediate child of the Delivery is a Container, cache it to call the prorate api recursively
6762         IF nvl(l_detail_rec_tab(i).container_flag, 'N') = 'Y' THEN
6763         --{
6764                l_lpn_count := l_lpn_count + 1;
6765 	       l_lpn_tab(l_lpn_count).delivery_detail_id := l_detail_rec_tab(i).delivery_detail_id;
6766 	       l_lpn_tab(l_lpn_count).old_gross_weight := l_detail_rec_tab(i).gross_wt;
6767 	       l_lpn_tab(l_lpn_count).old_net_weight := l_detail_rec_tab(i).net_wt;
6768 	       l_lpn_tab(l_lpn_count).wt_uom_code := l_detail_rec_tab(i).weight_uom_code;
6769                l_lpn_tab(l_lpn_count).new_gross_weight := l_new_gross_wt;
6770 	       l_lpn_tab(l_lpn_count).new_net_weight   := l_new_net_wt;
6771 
6772                -- LPN CONV. rv
6773                IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
6774                THEN
6775                --{
6776                    --
6777                    -- need to check the wms org value for each record because the parent LPN
6778                    -- can be a consol. LPN.
6779                    l_wms_org := wsh_util_validate.check_wms_org(l_detail_rec_tab(i).organization_id);
6780                    --
6781                    IF l_debug_on THEN
6782                      WSH_DEBUG_SV.log(l_module_name,'l_wms_org value is', l_wms_org);
6783                    END IF;
6784                    --
6785                    IF(l_wms_org = 'Y'
6786                       AND l_detail_rec_tab(i).line_direction in ('O', 'IO')
6787                      )
6788                    THEN
6789                      l_sync_tmp_wms_recTbl.delivery_detail_id_tbl(l_cnt_wms_counter) := l_detail_rec_tab(i).delivery_detail_id;
6790                      l_sync_tmp_wms_recTbl.operation_type_tbl(l_cnt_wms_counter) := 'UPDATE';
6791                      l_sync_tmp_wms_recTbl.call_level(l_cnt_wms_counter) := l_call_level;
6792                      l_cnt_wms_counter := l_cnt_wms_counter +1;
6793                    ELSIF (l_wms_org = 'N'
6794                           AND l_detail_rec_tab(i).line_direction in ('O', 'IO')
6795                          )
6796                    THEN
6797                      l_sync_tmp_inv_recTbl.delivery_detail_id_tbl(l_cnt_inv_counter) := l_detail_rec_tab(i).delivery_detail_id;
6798                      l_sync_tmp_inv_recTbl.operation_type_tbl(l_cnt_inv_counter) := 'UPDATE';
6799                      l_sync_tmp_inv_recTbl.call_level(l_cnt_inv_counter) := l_call_level;
6800                      l_cnt_inv_counter := l_cnt_inv_counter +1;
6801                    END IF;
6802                    --
6803                --}
6804                END IF;
6805                -- LPN CONV. rv
6806         --}
6807         END IF;
6808 
6809         -- Store delivery detail id,new gross and new net weight for doing BULK update later.
6810         l_dd_upd_tbl(l_dd_upd_tbl.COUNT + 1)                 := l_detail_rec_tab(i).delivery_detail_id;
6811         l_dd_upd_net_wt_tbl(l_dd_upd_net_wt_tbl.COUNT+1)     := l_new_net_wt;
6812         l_dd_upd_gross_wt_tbl(l_dd_upd_gross_wt_tbl.COUNT+1) := l_new_gross_wt;
6813      --}
6814      END LOOP;
6815 
6816      -- LPN CONV. rv
6817      --
6818      IF l_debug_on THEN
6819        wsh_debug_sv.LOG(l_module_name, 'Count of l_sync_tmp_wms_recTbl', l_sync_tmp_wms_recTbl.delivery_detail_id_tbl.count);
6820        wsh_debug_sv.LOG(l_module_name, 'Count of l_sync_tmp_inv_recTbl', l_sync_tmp_inv_recTbl.delivery_detail_id_tbl.count);
6821      END IF;
6822      --
6823      --
6824      IF WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y'
6825      THEN
6826      --{
6827          IF  WSH_WMS_LPN_GRP.GK_WMS_UPD_WV
6828          AND l_sync_tmp_wms_recTbl.delivery_detail_id_tbl.count > 0
6829          THEN
6830          --{
6831              --
6832              -- Debug Statements
6833              --
6834              IF l_debug_on THEN
6835                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WMS_SYNC_TMP_PKG.MERGE_BULK',WSH_DEBUG_SV.C_PROC_LEVEL);
6836              END IF;
6837              --
6838              WSH_WMS_SYNC_TMP_PKG.MERGE_BULK
6839                (
6840                  p_sync_tmp_recTbl   => l_sync_tmp_wms_recTbl,
6841                  x_return_status     => l_return_status
6842                );
6843              --
6844              IF l_debug_on THEN
6845                wsh_debug_sv.log(l_module_name, 'Return status after the call to WSH_WMS_SYNC_TMP_PKG.MERGE_BULK is ', l_return_status);
6846              END IF;
6847              --
6848              WSH_UTIL_CORE.API_POST_CALL
6849                (
6850                  p_return_status => l_return_status,
6851                  x_num_warnings  => l_num_warnings,
6852                  x_num_errors    => l_num_errors
6853                );
6854          --}
6855          ELSIF WSH_WMS_LPN_GRP.GK_INV_UPD_WV
6856          AND l_sync_tmp_inv_recTbl.delivery_detail_id_tbl.count > 0
6857          THEN
6858          --{
6859              --
6860              -- Debug Statements
6861              --
6862              IF l_debug_on THEN
6863                  WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_WMS_SYNC_TMP_PKG.MERGE_BULK',WSH_DEBUG_SV.C_PROC_LEVEL);
6864              END IF;
6865              --
6866              WSH_WMS_SYNC_TMP_PKG.MERGE_BULK
6867                (
6868                  p_sync_tmp_recTbl   => l_sync_tmp_inv_recTbl,
6869                  x_return_status     => l_return_status
6870                );
6871 
6872              --
6873              IF l_debug_on THEN
6874                wsh_debug_sv.log(l_module_name, 'Return status after the call to WSH_WMS_SYNC_TMP_PKG.MERGE_BULK is ', l_return_status);
6875              END IF;
6876              --
6877              WSH_UTIL_CORE.API_POST_CALL
6878                (
6879                  p_return_status => l_return_status,
6880                  x_num_warnings  => l_num_warnings,
6881                  x_num_errors    => l_num_errors
6882                );
6883          --}
6884          END IF;
6885      --}
6886      END IF;
6887      -- LPN CONV. rv
6888 
6889      -- Update all effected delivery details with  resultant gross
6890      -- and net weight. Also update wv_frozen_flag to 'Y' for all.
6891      --
6892      IF l_debug_on THEN
6893         WSH_DEBUG_SV.logmsg(l_module_name,'Updating the Weights of Delivery Details');
6894      END IF;
6895      --
6896      FORALL i IN 1..l_dd_upd_tbl.COUNT
6897      UPDATE wsh_delivery_details
6898      SET    gross_weight      = l_dd_upd_gross_wt_tbl(i),
6899             net_weight        = l_dd_upd_net_wt_tbl(i),
6900             wv_frozen_flag    = 'Y',
6901             last_update_date  = SYSDATE,
6902             last_updated_by   = FND_GLOBAL.user_id,
6903             last_update_login = FND_GLOBAL.login_id
6904      WHERE  delivery_detail_id = l_dd_upd_tbl(i);
6905 
6906      -- Make the recursive call to prorate the weights further down.
6907      IF l_lpn_tab.COUNT > 0 THEN
6908      --{
6909        FOR i IN 1..l_lpn_tab.COUNT
6910        LOOP
6911        --{
6912           --
6913           IF l_debug_on THEN
6914 	         WSH_DEBUG_SV.logmsg(l_module_name,'Calling the Prorate API recursively for the Containers');
6915           END IF;
6916           --
6917 	  Prorate_weight_actual(
6918 	            p_entity_type   => 'CONTAINER',
6919                     p_entity_id     => l_lpn_tab(i).delivery_detail_id,
6920                     p_old_gross_wt  => l_lpn_tab(i).old_gross_weight,
6921 	            p_new_gross_wt  => l_lpn_tab(i).new_gross_weight,
6922                     p_old_net_wt    => l_lpn_tab(i).old_net_weight,
6923 	            p_new_net_wt    => l_lpn_tab(i).new_net_weight,
6924                     p_weight_uom_code => l_lpn_tab(i).wt_uom_code,
6925 	            x_return_status => l_return_status,
6926                     p_call_level    => l_call_level);
6927 
6928 	 x_return_status :=  l_return_status;
6929 
6930 	 IF l_debug_on THEN
6931 	    wsh_debug_sv.log(l_module_name,'Return Status After Calling Prorate_weight_actual',l_return_status);
6932 	 END IF;
6933          --
6934          wsh_util_core.api_post_call(
6935 	     p_return_status    => l_return_status,
6936 	     x_num_warnings     => l_num_warnings,
6937 	     x_num_errors       => l_num_errors,
6938              p_raise_error_flag => TRUE );
6939          --
6940        --}
6941        END LOOP;
6942      --}
6943      END IF;
6944   --}
6945   END IF;
6946 
6947   IF (p_call_level IS NULL)
6948    AND (WSH_WMS_LPN_GRP.G_CALLBACK_REQUIRED = 'Y')
6949    AND (l_wms_org = 'Y')
6950   THEN --{
6951 
6952      WSH_WMS_LPN_GRP.g_update_to_containers := 'N';
6953      WSH_WMS_LPN_GRP.g_call_group_api := 'N' ;
6954      --call the new API
6955      IF l_debug_on THEN
6956        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_LPN_SYNC_COMM_PKG.SYNC_PRORATED_LPNS_TO_WMS',WSH_DEBUG_SV.C_PROC_LEVEL);
6957      END IF;
6958      WSH_LPN_SYNC_COMM_PKG.SYNC_PRORATED_LPNS_TO_WMS
6959      (
6960        p_in_rec             => l_lpn_in_sync_comm_rec,
6961        x_return_status      => l_return_status,
6962        x_out_rec            => l_lpn_out_sync_comm_rec
6963      );
6964 
6965      IF l_debug_on THEN
6966          WSH_DEBUG_SV.log(l_module_name,  'Return status after calling WSH_LPN_SYNC_COMM_PKG.SYNC_PRORATED_LPNS_TO_WMS', l_return_status);
6967      END IF;
6968 
6969      WSH_UTIL_CORE.API_POST_CALL
6970        (
6971          p_return_status => l_return_status,
6972          x_num_warnings  => l_num_warnings,
6973          x_num_errors    => l_num_errors
6974        );
6975      WSH_WMS_LPN_GRP.g_call_group_api := l_call_group_api;
6976      WSH_WMS_LPN_GRP.g_update_to_containers := l_update_to_containers;
6977 
6978   END IF; --}
6979 
6980   IF l_num_errors > 0
6981   THEN
6982        x_return_status     := WSH_UTIL_CORE.G_RET_STS_ERROR;
6983   ELSIF l_num_warnings > 0
6984   THEN
6985        x_return_status     := WSH_UTIL_CORE.G_RET_STS_WARNING;
6986   ELSE
6987        x_return_status     := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6988   END IF;
6989 
6990   --
6991   -- Debug Statements
6992   --
6993   IF l_debug_on THEN
6994      WSH_DEBUG_SV.pop(l_module_name);
6995   END IF;
6996   --
6997   EXCEPTION
6998        WHEN OTHERS THEN
6999          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7000          WSH_WMS_LPN_GRP.g_call_group_api := l_call_group_api;
7001          WSH_WMS_LPN_GRP.g_update_to_containers := l_update_to_containers;
7002 
7003 	   IF immediate_details_del%ISOPEN THEN
7004 	      CLOSE immediate_details_del;
7005 	   END IF;
7006 	   IF immediate_details_cont%ISOPEN THEN
7007 	       CLOSE immediate_details_cont;
7008            END IF;
7009          WSH_UTIL_CORE.default_handler('WSH_WV_UTILS.Prorate_weight_actual' );
7010          --
7011          -- Debug Statements
7012          --
7013          IF l_debug_on THEN
7014             WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7015             WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:OTHERS');
7016          END IF;
7017           --
7018 END Prorate_weight_actual;
7019 
7020 END WSH_WV_UTILS;