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