[Home] [Help]
PACKAGE BODY: APPS.WMS_SHIPPING_TRANSACTION_PUB
Source
1 PACKAGE BODY WMS_SHIPPING_TRANSACTION_PUB AS
2 /* $Header: WMSPSHPB.pls 120.35.12010000.3 2008/09/30 09:21:36 shrmitra ship $ */
3 G_Debug NUMBER;
4
5 G_RET_STS_SUCCESS VARCHAR2(1) := FND_API.g_ret_sts_success;
6 G_RET_STS_ERROR VARCHAR2(1) := FND_API.g_ret_sts_error;
7 G_RET_STS_UNEXP_ERROR VARCHAR2(1) := FND_API.G_RET_STS_UNEXP_ERROR;
8 G_FALSE VARCHAR2(1) := FND_API.G_FALSE;
9 G_TRUE VARCHAR2(1) := FND_API.G_TRUE;
10
11 --Inline branching
12 G_WMS_CURRENT_RELEASE_LEVEL NUMBER := wms_control.g_current_release_level;
13 G_J_RELEASE_LEVEL NUMBER := inv_release.g_j_release_level;
14 G_PACKAGE_VERSION VARCHAR2(100) :=
15 '$Header: WMSPSHPB.pls 120.35.12010000.3 2008/09/30 09:21:36 shrmitra ship $' ;
16
17 PROCEDURE DEBUG(p_message IN VARCHAR2,
18 p_module IN VARCHAR2) IS
19 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
20 BEGIN
21 if g_debug IS NULL THEN
22 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
23 end if;
24 if( g_debug = 1 ) then
25 inv_trx_util_pub.trace(p_message, 'WMS_SHPTRX.'||p_module, 1);
26 end if;
27 END;
28
29 PROCEDURE process_mobile_msg IS
30 l_msg_data VARCHAR2(2000);
31 l_msg_count NUMBER;
32 l_dummy_number NUMBER;
33
34 l_app_short_name VARCHAR2(20);
35 l_msg_name VARCHAR2(50);
36 BEGIN
37 debug('Entered procedure','process_mobile_msg');
38
39 l_msg_count := fnd_msg_pub.count_msg;
40 debug('Msg Count: ' || l_msg_count,'process_mobile_msg');
41
42 FOR i IN 1..l_msg_count LOOP
43 fnd_msg_pub.get(p_msg_index => i,
44 p_data => l_msg_data,
45 p_msg_index_out => l_dummy_number);
46
47 debug('i: ' || i || ' index_out: ' || l_dummy_number || ' encoded_data: ' || l_msg_data,'process_mobile_msg');
48
49 fnd_message.parse_encoded(ENCODED_MESSAGE => l_msg_data,
50 APP_SHORT_NAME => l_app_short_name,
51 MESSAGE_NAME => l_msg_name);
52
53 debug('App_short_name: ' || l_app_short_name || ' Msg_name: ' || l_msg_name,'process_mobile_msg');
54
55 IF (l_msg_name <> 'WSH_DET_INV_INT_SUBMITTED') THEN
56 fnd_msg_pub.delete_msg(p_msg_index=>i);
57 debug('Deleted message at position: ' || i,'process_mobile_msg');
58 END IF;
59 END LOOP;
60 EXCEPTION
61 WHEN OTHERS THEN
62 debug('Exception raised!','process_mobile_msg');
63 NULL;
64 END process_mobile_msg;
65
66 --Patchset J LPN hierarchy
67 --This procedure will populate Shipping with the LPN hierarchy.
68 --It can be broken down into 3 major steps:
69 --1. Create container records in Shipping. Reuse existing container
70 --records if possible.
71 --2. Create the nesting of these containers just created
72 --3. Update the attribute of these newly created containers
73 --Assumptions:
74 --1. When this procedure is called, Shipping knows of only inner most LPN
75
76 -- Release 12: lpn_hierarchy_actions is removed because it is not needed.
77 -- LPN hierarchy information will be in sync before the shipping stage.
78 /* PROCEDURE lpn_hierarchy_actions
79 (x_return_status OUT nocopy VARCHAR2,
80 x_msg_count OUT nocopy NUMBER,
81 x_msg_data OUT nocopy VARCHAR2,
82 p_organization_id IN NUMBER,
83 p_outermost_lpn_id IN NUMBER,
84 p_inner_most_lpn_wdd IN NUMBER DEFAULT NULL)
85 IS*/
86
87 FUNCTION IS_LOADED(p_organization_id IN NUMBER,
88 p_dock_door_id IN NUMBER,
89 p_dock_appoint_flag IN VARCHAR2,
90 p_direct_ship_flag IN VARCHAR2 DEFAULT 'N')
91 RETURN VARCHAR2 IS
92 lpn_loaded VARCHAR2(1) := 'N';
93 BEGIN
94 select 'Y'
95 into lpn_loaded
96 from dual
97 where exists (select 1
98 from wms_shipping_transaction_temp
99 where dock_door_id = p_dock_door_id
100 and dock_appoint_flag = p_dock_appoint_flag
101 and organization_id = p_organization_id
102 and nvl(direct_ship_flag,'N') = p_direct_ship_flag );
103 return lpn_loaded;
104 EXCEPTION
105 WHEN NO_DATA_FOUND then
106 return 'N';
107 END IS_LOADED;
108
109 PROCEDURE GET_DOCK_DOORS(x_dock_door_LOV OUT NOCOPY t_genref,
110 p_txn_dock_app IN VARCHAR2,
111 p_organization_id in NUMBER,
112 p_dock_door IN VARCHAR2) IS
113
114 --Bug#6018835.Added following cursor.
115 --cursor to check if any apptmts within the current time window.
116 CURSOR current_schedule_cur IS
117 SELECT 1
118 FROM wms_dock_appointments_b wda, mtl_item_locations_kfv milk,
119 wsh_delivery_legs_ob_grp_v wdl, wsh_Trip_stops_ob_grp_v wts, mtl_item_locations_kfv milk1,wsh_trips wt
120 WHERE wda.dock_id = milk.inventory_location_id (+)
121 and wda.organization_id = milk.organization_id (+)
122 and wda.trip_stop = wdl.pick_up_stop_id (+)
123 and wdl.pick_up_stop_id = wts.stop_id (+)
124 and wt.trip_id (+) = wts.trip_id
125 and wda.start_time <= SYSDATE
126 and wda.end_time > SYSDATE
127 and wts.status_code = 'OP'
128 and milk.organization_id = p_organization_id
129 and milk1.organization_id (+) = wda.organization_id
130 and milk1.inventory_location_id (+) = wda.staging_Lane_Id
131 and inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
132 and nvl(milk.disable_date,sysdate+1) > sysdate
133 and rownum<2; --We need to just make sure that there exists a row, atleast.
134
135 --Bug#6018835.Added following cursor.
136 --cursor to check if any apptmts missed to be used in the past.
137 CURSOR last_recent_schedule_cur IS
138 SELECT 1
139 FROM wms_dock_appointments_b wda, mtl_item_locations_kfv milk,
140 wsh_delivery_legs_ob_grp_v wdl,wsh_Trip_stops_ob_grp_v wts, mtl_item_locations_kfv milk1,wsh_trips wt
141 WHERE wda.dock_id = milk.inventory_location_id (+)
142 and wda.organization_id = milk.organization_id (+)
143 and wda.trip_stop = wdl.pick_up_stop_id (+)
144 and wdl.pick_up_stop_id = wts.stop_id (+)
145 and wt.trip_id (+) = wts.trip_id
146 and wda.end_time <= SYSDATE
147 and wts.status_code = 'OP'
148 and milk.organization_id = p_organization_id
149 and milk1.organization_id (+) = wda.organization_id
150 and milk1.inventory_location_id (+) = wda.staging_Lane_Id
151 and inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
152 AND nvl(milk.disable_date,sysdate+1) > sysdate
153 ANd rownum<2; --Just Checking the existance.
154
155 l_available_appt NUMBER := 0 ;
156
157 BEGIN
158 -- 4539200 dherring: trip name added to following query. SELECT,FROM and WHERE affected.
159 -- need to modify to check if the dock door has the valid status.
160 if (p_txn_dock_app = 'Y') then
161
162 --Bug#6018835.Need to check if there is a row
163 OPEN current_schedule_cur;
164 FETCH current_schedule_cur into l_available_appt;
165 CLOSE current_schedule_cur;
166
167 IF (l_available_appt = 1 ) then --There is an apptmt in the current time window.
168 --Bug# 2780663:
169 -- Dock Door LOV should show only physical locators. (.)s at the positions of Project and Task
170 -- segments should be suppressed from the KFV in the LOV. Alias "milk_concatenated_segments"
171 -- is used to avoid "unambiguous column name" error
172 open x_dock_door_lov for
173 select distinct
174 wda.dock_id
175 , inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id)
176 milk_concatenated_segments
177 , wda.dock_appointment_id
178 , wda.organization_id
179 , wda.trip_stop
180 , wts.trip_id
181 , milk1.subinventory_code
182 , milk1.concatenated_segments
183 , is_loaded(p_organization_id,wda.dock_id,'Y')
184 , wt.name trip_name
185 from wms_dock_appointments_b wda
186 , mtl_item_locations_kfv milk
187 , wsh_delivery_legs_ob_grp_v wdl
188 , wsh_Trip_stops_ob_grp_v wts
189 , mtl_item_locations_kfv milk1
190 ,wsh_trips wt
191 where wda.dock_id = milk.inventory_location_id (+)
192 and wda.organization_id = milk.organization_id (+)
193 and wda.trip_stop = wdl.pick_up_stop_id (+)
194 and wdl.pick_up_stop_id = wts.stop_id (+)
195 and wt.trip_id (+) = wts.trip_id
196 and wda.start_time <= SYSDATE
197 and wda.end_time > SYSDATE
198 and wts.status_code = 'OP'
199 and milk.organization_id = p_organization_id
200 and milk1.organization_id (+) = wda.organization_id
201 and milk1.inventory_location_id (+) = wda.staging_Lane_Id
202 and inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
203 AND nvl(milk.disable_date,sysdate+1) > sysdate
204 order by milk_concatenated_segments;
205
206 --Bug#6018835.Ends.
207 ELSE
208 OPEN last_recent_schedule_cur;
209 FETCH last_recent_schedule_cur INTO l_available_appt;
210 CLOSE last_recent_schedule_cur;
211
212 IF (l_available_appt=1) THEN --There is an unused apptmt in the past.
213
214 OPEN x_dock_door_lov FOR
215 SELECT dock_id , milk_concatenated_segments, dock_appointment_id,organization_id,
216 trip_stop, trip_id, subinventory_code,concatenated_segments , is_loaded , trip_name
217 FROM (
218 SELECT distinct wda.dock_id,
219 inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) milk_concatenated_segments,
220 wda.dock_appointment_id, wda.organization_id, wda.trip_stop, wts.trip_id,
221 milk1.subinventory_code, milk1.concatenated_segments ,
222 WMS_SHIPPING_TRANSACTION_PUB.is_loaded(p_organization_id,wda.dock_id,'Y') is_loaded ,
223 wt.name trip_name , ( SYSDATE - wda.end_time ) last_schedule_time_diff
224 FROM wms_dock_appointments_b wda, mtl_item_locations_kfv milk, wsh_delivery_legs_ob_grp_v wdl,
225 wsh_Trip_stops_ob_grp_v wts, mtl_item_locations_kfv milk1,wsh_trips wt
226 WHERE wda.dock_id = milk.inventory_location_id (+)
227 and wda.organization_id = milk.organization_id (+)
228 and wda.trip_stop = wdl.pick_up_stop_id (+)
229 and wdl.pick_up_stop_id = wts.stop_id (+)
230 and wt.trip_id (+) = wts.trip_id
231 and wda.end_time <= SYSDATE
232 and wts.status_code = 'OP'
233 and milk.organization_id = p_organization_id
234 and milk1.organization_id (+) = wda.organization_id
235 and milk1.inventory_location_id (+) = wda.staging_Lane_Id
236 and inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
237 and nvl(milk.disable_date,sysdate+1) > sysdate
238 ORDER BY 11 ASC
239 )
240 WHERE ROWNUM<2; --We need only the last recent apptmt.
241
242 ELSE --No apptmt in the past , so look for the furture ones.
243 OPEN x_dock_door_lov FOR
244 SELECT dock_id , milk_concatenated_segments, dock_appointment_id,organization_id,
245 trip_stop, trip_id, subinventory_code,concatenated_segments , is_loaded , trip_name
246 FROM (
247 SELECT distinct wda.dock_id,
248 inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) milk_concatenated_segments,
249 wda.dock_appointment_id, wda.organization_id, wda.trip_stop, wts.trip_id,
250 milk1.subinventory_code, milk1.concatenated_segments ,
251 WMS_SHIPPING_TRANSACTION_PUB.is_loaded(p_organization_id,wda.dock_id,'Y') is_loaded ,
252 wt.name trip_name , ( wda.start_time - SYSDATE) next_schedule_time_diff
253 FROM wms_dock_appointments_b wda, mtl_item_locations_kfv milk, wsh_delivery_legs_ob_grp_v wdl,
254 wsh_Trip_stops_ob_grp_v wts, mtl_item_locations_kfv milk1,wsh_trips wt
255 WHERE wda.dock_id = milk.inventory_location_id (+)
256 and wda.organization_id = milk.organization_id (+)
257 and wda.trip_stop = wdl.pick_up_stop_id (+)
258 and wdl.pick_up_stop_id = wts.stop_id (+)
259 and wt.trip_id (+) = wts.trip_id
260 and wda.start_time > SYSDATE
261 and wts.status_code = 'OP'
262 and milk.organization_id = p_organization_id
263 and milk1.organization_id (+) = wda.organization_id
264 and milk1.inventory_location_id (+) = wda.staging_Lane_Id
265 and inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
266 and nvl(milk.disable_date,sysdate+1) > sysdate
267 ORDER BY 11 ASC
268 )
269 WHERE ROWNUM<2; --We need only one (the immediate next apptmt).
270 END IF;
271 END IF;
272 --Bug#6018835.Ends.
273 else
274 --Bug# 2780663:
275 -- Dock Door LOV should show only physical locators. (.)s at the positions of Project and Task
276 -- segments should be suppressed from the KFV in the LOV. Alias "milk_concatenated_segments"
277 -- is used to avoid "unambiguous column name" error
278 open x_dock_door_lov for
279 select milk.inventory_location_id,
280 inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id)
281 milk_concatenated_segments
282 ,0, milk.organization_id,
283 0,0,'','',is_loaded(p_organization_id,milk.inventory_location_id,'N')
284 ,''
285 from mtl_item_locations_kfv milk
286 where inventory_location_type = 1
287 AND milk.organization_id = p_organization_id
288 AND inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
289 --AND segment19 IS NULL -- Bug 5336849, As a release policy
290 -- the code should not depend on FF view during patch installation
291 -- so changing the logic
292 AND nvl(milk.physical_location_id,milk.inventory_location_id) = milk.inventory_location_id
293 AND nvl(milk.disable_date,sysdate+1) > sysdate
294 ORDER BY milk_concatenated_segments;
295 end if;
296
297 END GET_DOCK_DOORS;
298
299 PROCEDURE validate_lpn_status
300 (x_result OUT NOCOPY NUMBER,
301 x_msg_code OUT NOCOPY VARCHAR2,
302 p_trip_id IN NUMBER,
303 p_organization_id IN NUMBER,
304 p_lpn_id IN NUMBER ) IS
305
306 l_delivery_detail_id NUMBER;
307 l_transaction_Type_id NUMBER := -1;
308 l_transaction_source_type_id NUMBER;
309 l_transaction_action_id NUMBER;
310 l_return_status VARCHAR2(1);
311 l_result NUMBER;
312 l_lpn_status VARCHAR2(1);
313 l_wms_installed VARCHAR2(10);
314 l_wms_installed_flag boolean;
315 l_inventory_item_id number;
316 l_subinventory varchar2(10);
317 l_locator_id number;
318 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
319 l_lot_number varchar2(80);
320 l_serial_number varchar2(30);
321 l_transaction_temp_id NUMBER;
322 l_trx_status_enabled number := 1;
323 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
324 l_debug number;
325
326 CURSOR serial_numbers(p_transaction_temp_id NUMBER) IS
327 SELECT msnt.fm_serial_number
328 FROM mtl_serial_numbers_temp msnt
329 WHERE transaction_temp_id = p_transaction_temp_id;
330
331 cursor delivery_details(p_lpn_id NUMBER) is
332 select wdd.delivery_detail_id
333 , wdd.inventory_item_id
334 , wdd.subinventory
335 , wdd.locator_id
336 , wdd.lot_number
337 , wdd.serial_number
338 , wdd.transaction_temp_id
339 from wms_license_plate_numbers wlpn
340 , wsh_delivery_details_ob_grp_v wdd
341 , wsh_delivery_assignments_v wda
342 , wsh_delivery_details_ob_grp_v wdd2
343 where wlpn.lpn_id = wdd2.lpn_id
344 and wlpn.outermost_lpn_id = p_lpn_id
345 and wdd2.lpn_id is not null -- for performance, bug 2418639
346 and wda.parent_delivery_detail_id = wdd2.delivery_detail_id
347 and wda.delivery_detail_id = wdd.delivery_detail_id;
348
349 BEGIN
350 if g_debug IS NULL THEN
351 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
352 end if;
353 l_debug := g_debug;
354
355 -- validate the status of item, sub, locator of the content of the lpn
356 IF (l_debug = 1) THEN
357 debug('In validate_lpn_status', 'ValidateLPN');
358 debug('p_trip_id : ' || p_trip_id, 'ValidateLPN');
359 debug('p_organization_id : ' || p_organization_id, 'ValidateLPN');
360 debug('p_lpn_id : ' || p_lpn_id, 'ValidateLPN');
361 END IF;
362
363 x_result := 0;
364 l_result := 0;
365 open delivery_details(p_lpn_id);
366 <<delivery_line_item_loop>>
367 LOOP
368 fetch delivery_details into l_delivery_detail_id,l_inventory_item_id,l_subinventory,l_locator_id
369 ,l_lot_number, l_serial_number, l_transaction_temp_id;
370 exit when delivery_details%NOTFOUND;
371
372 IF (l_debug = 1) THEN
373 debug('In validate_lpn_status', 'ValidateLPN');
374 debug( 'l_delivery_detail_id is ' || l_delivery_detail_id, 'ValidateLPN');
375 END IF;
376 if (l_transaction_type_id = -1) then
377 l_transaction_type_id :=
378 INV_SHIPPING_TRANSACTION_PUB.GET_DELIVERY_TRANSACTION_TYPE(
379 l_delivery_detail_id,
380 l_transaction_source_type_id,
381 l_transaction_action_id,
382 l_return_status);
383 IF (l_debug = 1) THEN
384 debug( 'l_transaction_type_id is ' || l_transaction_type_id, 'ValidateLPN');
385 debug( 'l_return_status is ' || l_return_status, 'ValidateLPN');
386 END IF;
387 if( l_return_Status <> 'C' ) then
388 IF (l_debug = 1) THEN
389 debug( 'inv_shipping_transaction.get_Delivery_transaction_type', 'ValidateLPN');
390 END IF;
391 x_result := 1;
392 x_msg_code := 'INV_INT_TRXTYPCODE';
393 return;
394 end if;
395
396 -- check if the transaction_type is status control enabled
397 select status_control_flag
398 into l_trx_status_enabled
399 from mtl_transaction_types
400 where transaction_type_id = l_transaction_type_id;
401 if l_trx_status_enabled = 2 then x_result := 0; return; end if;
402
403 end if;
404
405
406 IF l_transaction_temp_id IS NULL THEN
407 -- If the serial number is stamped on the WDD or the item is not serial controlled
408
409 -- call is_status_applicable directly
410 IF (l_debug = 1) THEN
411 debug( 'call inv_material_status_grp.is_status_applicable', 'ValidateLPN');
412 END IF;
413 l_lpn_status := inv_material_status_grp.is_status_applicable
414 (p_wms_installed => 'TRUE',
415 p_trx_status_enabled => l_trx_status_enabled,
416 p_trx_type_id => l_transaction_type_id,
417 p_organization_id => p_organization_id,
418 p_inventory_item_id => l_inventory_item_id,
419 p_sub_code => l_subinventory,
420 p_locator_id => l_locator_id,
421 p_lot_number => l_lot_number,
422 p_serial_number => l_serial_number,
423 p_object_type => 'A');
424 IF (l_debug = 1) THEN
425 debug( 'l_lpn_status is ' || l_lpn_status, 'ValidateLPN');
426 END IF;
427
428 IF l_lpn_status = 'Y' then
429 l_result := 0;
430 x_msg_code := 'NULL';
431 ELSE
432 l_result := 1;
433 x_msg_code := 'WMS_CONT_INVALID_LPN';
434 EXIT delivery_line_item_loop;
435 -- populate error message accordingly
436 END IF;
437 ELSE
438 -- If the serial numbers are stored in MSNT
439 FOR l_serial_rec IN serial_numbers(l_transaction_temp_id) LOOP
440 l_serial_number := l_serial_rec.fm_serial_number;
441 IF (l_debug = 1) THEN
442 debug( 'call inv_material_status_grp.is_status_applicable', 'ValidateLPN');
443 END IF;
444
445 l_lpn_status := inv_material_status_grp.is_status_applicable
446 (p_wms_installed => 'TRUE',
447 p_trx_status_enabled => l_trx_status_enabled,
448 p_trx_type_id => l_transaction_type_id,
449 p_organization_id => p_organization_id,
450 p_inventory_item_id => l_inventory_item_id,
451 p_sub_code => l_subinventory,
452 p_locator_id => l_locator_id,
453 p_lot_number => l_lot_number,
454 p_serial_number => l_serial_number,
455 p_object_type => 'A');
456 IF (l_debug = 1) THEN
457 debug( 'l_lpn_status is ' || l_lpn_status, 'ValidateLPN');
458 END IF;
459
460 IF l_lpn_status = 'Y' then
461 l_result := 0;
462 x_msg_code := 'NULL';
463 ELSE
464 l_result := 1;
465 x_msg_code := 'WMS_CONT_INVALID_LPN';
466 EXIT delivery_line_item_loop;
467 -- populate error message accordingly
468 END IF;
469 END LOOP;
470
471 END IF;
472
473 END LOOP;
474 close delivery_details;
475
476 IF (l_debug = 1) THEN
477 debug( 'l_result is ' || l_result, 'ValidateLPN');
478 END IF;
479 x_result := l_result;
480 END validate_lpn_status;
481
482 procedure get_deliveries( x_delivery_lov OUT NOCOPY t_genref,
483 p_trip_id IN NUMBER) IS
484 BEGIN
485 open x_delivery_lov FOR
486 select wdl.delivery_id
487 from wsh_delivery_legs_ob_grp_v wdl
488 , wsh_trip_stops_ob_grp_v pickup_stop
489 , wsh_trip_stops_ob_grp_v dropoff_stop
490 where wdl.pick_up_stop_id = pickup_stop.stop_id
491 and wdl.drop_off_stop_id = dropoff_stop.stop_id
492 and pickup_stop.trip_id = dropoff_stop.trip_id
493 and pickup_stop.trip_id = p_trip_id;
494 END get_deliveries;
495
496 procedure get_delivery_info(x_delivery_info OUT NOCOPY t_genref,
497 p_delivery_id IN NUMBER) IS
498 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
499 l_debug number;
500 BEGIN
501 IF g_debug IS NULL THEN
502 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
503 END IF;
504 l_debug := g_debug;
505
506 IF (l_debug = 1) THEN
507 debug( 'inside get_delivery_info', 'Get_Delivery_Info');
508 debug(' p_delivery_id is ' || p_delivery_id, 'Get_Delivery_Info');
509 END IF;
510 open x_delivery_info for
511 SELECT wnd.name
512 , wnd.delivery_id
513 , nvl(wnd.gross_weight, 0)
514 , wnd.weight_uom_code
515 , wnd.waybill
516 , ' ' trip_name,
517 INV_SHIPPING_TRANSACTION_PUB.GET_SHIPMETHOD_MEANING(wnd.ship_method_code)
518 FROM wsh_new_deliveries_ob_grp_v wnd
519 WHERE wnd.delivery_id = p_delivery_id;
520 END get_delivery_info;
521
522 PROCEDURE GET_STAGING_LANE(x_staging_lane_LOV OUT NOCOPY t_genref,
523 p_txn_dock IN VARCHAR2,
524 p_organization_id IN NUMBER,
525 p_sub_code IN VARCHAR2,
526 p_dock_appointment_id IN NUMBER,
527 p_staging_lane IN VARCHAR2) IS
528 BEGIN
529 if( p_txn_dock = 'Y' ) then
530 open x_staging_lane_lov for
531 select distinct wda.staging_lane_id, milk.concatenated_segments
532 from wms_dock_appointments_b wda
533 , mtl_item_locations_kfv milk
534 , wsh_trip_Stops_ob_grp_v pickup_stop
535 where milk.inventory_location_id(+) = wda.staging_lane_id
536 and milk.organization_id(+) = wda.organization_id
537 and milk.organization_id = p_organization_id
538 and milk.subinventory_code = p_sub_code
539 and wda.dock_appointment_id = p_dock_appointment_id
540 and wda.trip_stop = pickup_stop.stop_id(+)
541 and milk.concatenated_segments like (p_staging_lane);
542 elsif( p_txn_dock = 'N' ) then
543 open x_staging_lane_lov for
544 select distinct milk.inventory_location_id, milk.concatenated_segments
545 from mtl_item_locations_kfv milk
546 , wms_license_plate_numbers lpn
547 where milk.inventory_location_id (+) = lpn.locator_id
548 and milk.organization_id (+) = lpn.organization_id
549 and milk.organization_id = p_organization_id
550 and milk.subinventory_code = p_sub_code
551 and (lpn.lpn_context = wms_globals.lpn_context_inv OR lpn.lpn_context = wms_globals.lpn_context_picked)
552 and milk.concatenated_segments like (p_staging_lane);
553 end if;
554 END GET_STAGING_LANE;
555
556
557 PROCEDURE GET_DELIVERY_DETAIL_ID(x_delivery_detail_id OUT NOCOPY t_genref,
558 p_organization_id IN NUMBER,
559 p_locator_id IN NUMBER,
560 p_trip_id IN NUMBER) IS
561 BEGIN
562 open x_delivery_detail_id for
563 select wdd.delivery_detail_id, wdd.lpn_id
564 from wsh_delivery_details_ob_grp_v wdd
565 , wsh_delivery_assignments_v wda
566 , wsh_delivery_legs_ob_grp_v wdl
567 , wsh_trip_stops_ob_grp_v pickup_stop
568 , wsh_trip_stops_ob_grp_v dropoff_stop
569 where wdd.delivery_detail_id = wda.delivery_detail_id
570 and wda.delivery_id = wdl.delivery_id
571 and wdl.pick_up_stop_id = pickup_stop.stop_id
572 and wdl.drop_off_Stop_id = dropoff_stop.stop_id
573 and pickup_stop.trip_id = dropoff_Stop.trip_id
574 and pickup_stop.trip_id = p_trip_id
575 and wdd.locator_id = p_locator_id
576 and wdd.organization_id = p_organization_id
577 and wdd.released_status = 'Y';
578 END GET_DELIVERY_DETAIL_ID;
579
580 PROCEDURE POPULATE_WSTT(x_return OUT NOCOPY NUMBER,
581 x_msg_code OUT NOCOPY VARCHAR2,
582 p_organization_id IN NUMBER,
583 p_lpn_id IN NUMBER,
584 p_trip_id IN NUMBER,
585 p_dock_door_id IN NUMBER,
586 p_direct_ship_flag IN VARCHAR2 DEFAULT 'N') IS
587 cursor delivery_details(p_lpn_id NUMBER) is
588 select wdd.delivery_detail_id
589 , lpn.lpn_id
590 , wdd.inventory_item_id
591 , wdd.requested_quantity
592 , wda.delivery_id
593 , lpn.license_plate_number
594 , wdd.locator_id
595 , wdd.released_status
596 from wsh_delivery_details_ob_grp_v wdd
597 , wsh_delivery_assignments_v wda
598 , wms_license_plate_numbers lpn
599 , wsh_delivery_details_ob_grp_v wdd2
600 where wdd2.lpn_id = lpn.lpn_id
601 and wdd2.lpn_id is not null
602 and wdd2.released_status = 'X' -- For LPN reuse ER : 6845650
603 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
604 and wdd.delivery_detail_id = wda.delivery_detail_id
605 AND nvl(wdd.container_flag,'N')='N'
606 AND lpn.outermost_lpn_id = p_lpn_id;
607
608 /* Bug: 4691277:
609 * Added the join between wnd and wda to check the status of the delivery.
610 * We should load only those deliveries that are still open */
611
612 l_delivery_detail_id NUMBER;
613 l_parent_lpn_id NUMBER;
614 l_parent_lpn VARCHAR2(30);
615 l_outermost_lpn_id NUMBER;
616 l_outermost_lpn VARCHAR2(30);
617 l_trip_name VARCHAR2(30);
618 l_delivery_id NUMBER;
619 l_delivery_name VARCHAR2(30);
620 l_inventory_item_id NUMBER;
621 l_requested_quantity NUMBER;
622 l_locator_id NUMBER;
623 l_return_Status VARCHAR2(1);
624 l_trip_id NUMBER;
625 l_dock_appoint_flag VARCHAR2(1);
626 l_released_status VARCHAR2(1);
627 l_delivery_status_code VARCHAR2(2);
628
629 l_msg_count NUMBER;
630 l_msg_data VARCHAR2(2000);
631 l_action_prms wsh_interface_ext_grp.del_action_parameters_rectype;
632 l_delivery_id_tab wsh_util_core.id_tab_type;
633 l_delivery_out_rec wsh_interface_ext_grp.del_action_out_rec_type;
634
635 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
636 l_debug number;
637 BEGIN
638 IF g_debug IS NULL THEN
639 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
640 END IF;
641 l_debug := g_debug;
642
643 IF (l_debug = 1) THEN
644 debug( 'INSIDE populate_wstt', 'Populate_WSTT');
645 debug('open delivery_details', 'Populate_WSTT');
646 debug('p_organization_id = ' || p_organization_id, 'Populate_WSTT');
647 debug('P_trip_id ' || p_trip_id, 'Populate_WSTT');
648 debug('p_lpn_id ' || p_lpn_id, 'Populate_WSTT');
649 END IF;
650
651 open delivery_details(p_lpn_id);
652
653 if p_trip_id <> 0 then
654 l_trip_id := p_trip_id;
655 l_dock_appoint_flag := 'Y';
656 else
657 l_dock_appoint_flag := 'N';
658 end if;
659 LOOP
660 FETCH delivery_details
661 INTO l_delivery_detail_id
662 , l_parent_lpn_id
663 , l_inventory_item_id
664 , l_requested_quantity
665 , l_delivery_id
666 , l_parent_lpn
667 , l_locator_id
668 , l_released_status;
669 EXIT WHEN delivery_details%NOTFOUND;
670
671 l_released_status := 'R';
672 -- Direct Ship
673 -- Since Shipping is logging exception when staging a delivery line which is already packed
674 -- I changed a call to stage during packing itself, so at the time of call populate_wstt
675 -- delivery_line would have got staged. So hardcoding ORIG_RELEASE_STATUS = 'R' for now
676 -- Aslam
677
678
679 IF (l_debug = 1) THEN
680 debug( 'l_delivery_detail_id is ' || l_delivery_detail_id, 'Populate_WSTT');
681 debug( 'l_inventory_item_id is ' || l_inventory_item_id, 'Populate_WSTT');
682 debug( 'l_requested_quantity is ' || l_requested_quantity, 'Populate_WSTT');
683 debug( 'l_delivery_id is ' || l_delivery_id, 'Populate_WSTT');
684 debug( 'l_parent_lpn_id is ' || l_parent_lpn_id, 'Populate_WSTT');
685 debug( 'l_parent_lpn is ' || l_parent_lpn, 'Populate_WSTT');
686 END IF;
687
688
689 select outermost_lpn_id
690 into l_outermost_lpn_id
691 from wms_license_plate_numbers
692 where lpn_id = l_parent_lpn_id;
693
694 IF (l_debug = 1) THEN
695 debug( 'l_outermost_lpn_id is ' || l_outermost_lpn_id, 'Populate_WSTT');
696 END IF;
697 BEGIN
698 select license_plate_number
699 into l_outermost_lpn
700 from wms_license_plate_numbers
701 where lpn_id = l_outermost_lpn_id;
702 EXCEPTION
703 when no_data_found then
704 IF (l_debug = 1) THEN
705 debug('GOT Error: WMS_CONT_INVALID_LPN', 'Populate_WSTT');
706 END IF;
707 x_msg_code := 'WMS_CONT_INVALID_LPN';
708 END;
709 IF (l_debug = 1) THEN
710 debug( 'l_outermost_lpn is ' || l_outermost_lpn, 'Populate_WSTT');
711 END IF;
712
713 BEGIN
714 IF (l_delivery_id is not null) then
715 SELECT name, status_code
716 INTO l_delivery_name, l_delivery_status_code
717 FROM wsh_new_deliveries_ob_grp_v
718 WHERE delivery_id = l_delivery_id;
719 ELSE
720 l_delivery_name := NULL;
721 l_delivery_status_code := NULL;
722 END IF;
723
724 EXCEPTION
725 WHEN no_data_found then
726 RAISE no_data_found;
727 END;
728
729 IF (l_debug = 1) THEN
730 debug( 'l_delivery_name: ' || l_delivery_name, 'Populate_WSTT');
731 debug( 'l_delivery_status_code: ' || l_delivery_status_code, 'Populate_WSTT');
732 END IF;
733
734 l_trip_id := null;
735 IF (l_delivery_id IS NOT NULL AND
736 (l_delivery_status_code = 'OP' OR
737 l_delivery_status_code = 'PA'))
738 THEN
739 -- get the trip id if there is a trip associated with the delivery
740 BEGIN
741 SELECT wts.trip_id
742 INTO l_trip_id
743 FROM wsh_delivery_legs_ob_grp_v wdl
744 , wsh_trip_stops_ob_grp_v wts
745 WHERE wdl.delivery_id = l_delivery_id
746 AND wdl.pick_up_stop_id = wts.stop_id;
747
748 EXCEPTION
749 WHEN no_data_found THEN
750 l_trip_id := NULL;
751 END;
752
753 IF (l_debug = 1) THEN
754 debug( 'l_trip_id : ' || l_trip_id, 'Populate_WSTT');
755 END IF;
756 END IF;
757
758 IF (l_delivery_id IS NULL)
759 OR
760 ((l_delivery_id IS NOT NULL)
761 AND
762 (l_delivery_status_code = 'OP' OR
763 l_delivery_status_code = 'PA'))
764 THEN
765 IF (l_debug = 1) THEN
766 debug( 'inserting WSTT.. ', 'Populate_WSTT');
767 END IF;
768
769 INSERT INTO wms_shipping_transaction_temp
770 (organization_id,
771 dock_door_id,
772 trip_id,
773 trip_name,
774 delivery_id,
775 delivery_name,
776 delivery_detail_id,
777 parent_lpn_id,
778 parent_lpn,
779 outermost_lpn_id,
780 outermost_lpn,
781 inventory_item_id,
782 staging_lane_id,
783 requested_quantity,
784 dock_appoint_flag,
785 CREATION_DATE,
786 CREATED_BY,
787 LAST_UPDATE_DATE,
788 LAST_UPDATED_BY,
789 LAST_UPDATE_LOGIN,
790 ORIG_RELEASE_STATUS,
791 DIRECT_SHIP_FLAG
792 ) values
793 (
794 p_organization_id,
795 p_dock_door_id,
796 l_trip_id,
797 null,
798 l_delivery_id,
799 l_delivery_name,
800 l_delivery_detail_id,
801 l_parent_lpn_id,
802 l_parent_lpn,
803 l_outermost_lpn_id,
804 l_outermost_lpn,
805 l_inventory_item_id,
806 l_locator_id,
807 l_requested_quantity,
808 l_dock_appoint_flag,
809 sysdate,
810 FND_GLOBAL.USER_ID,
811 sysdate,
812 FND_GLOBAL.USER_ID,
813 FND_GLOBAL.LOGIN_ID,
814 l_released_status,
815 p_direct_ship_flag
816 );
817 -- Mrana : 8/30/06: No need to call delivery merge, if the delivery is not open anymore
818 --- <Changes for Delivery Merge>
819 IF g_wms_current_release_level >= g_j_release_level AND
820 l_delivery_id IS NOT NULL THEN -- mrana: 8/30/06: added this condition
821 IF (l_debug = 1) THEN
822 debug( 'Delivery merge call..wsh_interface_ext_grp.delivery_action ',
823 'Populate_WSTT');
824 END IF;
825 l_action_prms.caller := 'WMS_DLMG';
826 l_action_prms.event := wsh_interface_ext_grp.g_start_of_shipping;
827 l_action_prms.action_code := 'ADJUST-PLANNED-FLAG';
828
829 l_delivery_id_tab(1) := l_delivery_id;
830
831 wsh_interface_ext_grp.delivery_action
832 (p_api_version_number => 1.0,
833 p_init_msg_list => fnd_api.g_false,
834 p_commit => fnd_api.g_false,
835 p_action_prms => l_action_prms,
836 p_delivery_id_tab => l_delivery_id_tab,
837 x_delivery_out_rec => l_delivery_out_rec,
838 x_return_status => l_return_status,
839 x_msg_count => l_msg_count,
840 x_msg_data => l_msg_data);
841 IF (l_debug = 1) THEN
842 debug( 'x_return_status : ' || l_return_status, 'Populate_WSTT');
843 debug( 'x_msg_count : ' || l_msg_count, 'Populate_WSTT');
844 debug( 'x_msg_data : ' || l_msg_data, 'Populate_WSTT');
845 END IF;
846
847 --Do not error out even if the API returns an error.
848 END IF;
849 -- </Changes for delivery merge>
850 ELSE
851 IF (l_debug = 1) THEN
852 debug( 'Delivery status is not open ..not insertingWSTT ', 'Populate_WSTT');
853 END IF;
854 END IF;
855
856 END LOOP;
857 close delivery_details;
858 x_return := 0;
859 x_msg_code := 'NULL';
860 EXCEPTION
861 when others then
862 x_return := 1;
863 x_msg_code := 'WMS_ERROR_POPULATE_TEMP';
864 -- populate error message
865 END POPULATE_WSTT;
866
867 FUNCTION GET_DELIVERY_NAME(p_delivery_id IN NUMBER)
868 RETURN VARCHAR2 IS
869 p_name VARCHAR2(30);
870 BEGIN
871 if p_delivery_id is null then return ' ';
872 else
873 select name
874 into p_name
875 from wsh_new_deliveries_ob_grp_v
876 where delivery_id = p_delivery_id;
877 end if;
878 return p_name;
879 EXCEPTION
880 when no_data_found then
881 return ' ';
882 END GET_DELIVERY_NAME;
883
884 PROCEDURE GET_LPN_LOV(x_lpn_lov out NOCOPY t_genref,
885 p_organization_id IN NUMBER,
886 p_locator_id IN NUMBER,
887 p_trip_id IN NUMBER,
888 p_trip_stop_id IN NUMBER,
889 p_lpn IN VARCHAR2) is
890
891 l_count NUMBER;
892 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
893 l_debug number;
894 BEGIN
895 IF g_debug IS NULL THEN
896 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
897 END IF;
898 l_debug := g_debug;
899
900 IF (l_debug = 1) THEN
901 debug( 'Entered..opening the x_lpn_lov', 'GET_LPN_LOV');
902 debug( 'p_organization_id is ' || p_organization_id, 'GET_LPN_LOV');
903 debug( 'p_locator_id is ' || p_locator_id, 'GET_LPN_LOV');
904 debug( 'p_trip_id is ' || p_trip_id, 'GET_LPN_LOV');
905 debug( 'p_trip_stop_id is ' || p_trip_stop_id, 'GET_LPN_LOV');
906 debug( 'p_lpn is ' || p_lpn, 'GET_LPN_LOV');
907 END IF;
908
909 --Start Added for bug 6717052
910 IF WMS_CONTROL.G_CURRENT_RELEASE_LEVEL >= 120001 THEN
911 if (p_trip_id <> 0) then
912 -- to support loading while picking
913 open x_lpn_lov for
914 select distinct lpn.outermost_lpn_id
915 , wlpn.license_plate_number
916 , wnd.delivery_id,wnd.name
917 , nvl(wdd.load_seq_number,0) as load_seq_num
918 from wms_license_plate_numbers lpn
919 , wms_license_plate_numbers wlpn
920 , wsh_new_deliveries_ob_grp_v wnd
921 , wsh_delivery_legs_ob_grp_v wdl
922 , wsh_delivery_details_ob_grp_v wdd
923 , wsh_delivery_assignments_v wda
924 , wsh_delivery_details_ob_grp_v wdd2
925 where wdl.pick_up_stop_id = p_trip_stop_id
926 and wdl.delivery_id = wnd.delivery_id
927 and wnd.status_code in ('OP', 'PA')
928 and wnd.delivery_id = wda.delivery_id
929 and wdd.delivery_detail_id = wda.delivery_detail_id
930 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
931 and wdd2.lpn_id is not null -- for performance, bug 2418639
932 and wdd2.lpn_id = lpn.lpn_id
933 and lpn.outermost_lpn_id = wlpn.lpn_id
934 and ( wlpn.lpn_context = wms_container_pvt.lpn_context_picked
935 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
936 and wnd.status_code in ('OP', 'PA')
937 and wdd.released_status = 'Y'
938 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
939 and wlpn.license_plate_number like (p_lpn)
940 order by load_seq_num, wlpn.license_plate_number;
941
942 else
943 open x_lpn_lov for
944 select distinct lpn.outermost_lpn_id
945 , wlpn.license_plate_number as license_plate_number
946 , nvl(wda.delivery_id,0)
947 , get_delivery_name(wda.delivery_id)
948 , nvl(wdd.load_seq_number,0) as load_seq_num
949 from wsh_delivery_details_ob_grp_v wdd
950 , wsh_delivery_assignments_v wda
951 , wms_license_plate_numbers lpn
952 ,wms_license_plate_numbers wlpn
953 ,wsh_new_deliveries_ob_grp_v wndv
954 where wdd.delivery_detail_id = wda.delivery_detail_id
955 and wdd.lpn_id is not null
956 and wdd.lpn_id = lpn.outermost_lpn_id
957 and wdd.released_status = 'X' -- For LPN reuse ER : 6845650
958 and lpn.outermost_lpn_id = wlpn.lpn_id
959 and (wlpn.lpn_context = wms_container_pvt.lpn_context_picked
960 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
961 and lpn.organization_id = p_organization_id
962 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
963 and wlpn.license_plate_number like (p_lpn)
964 and wda.delivery_id IS NOT NULL
965 and wda.delivery_id = wndv.delivery_id
966 and wndv.status_code in ('OP', 'PA')
967
968 UNION
969 select distinct lpn.outermost_lpn_id
970 , wlpn.license_plate_number as license_plate_number
971 , nvl(wda.delivery_id,0)
972 , get_delivery_name(wda.delivery_id)
973 , nvl(wdd.load_seq_number,0) as load_seq_num
974 from wsh_delivery_details_ob_grp_v wdd
975 , wsh_delivery_assignments_v wda
976 , wms_license_plate_numbers lpn
977 , wms_license_plate_numbers wlpn
978 where wdd.delivery_detail_id = wda.delivery_detail_id
979 and wdd.lpn_id is not null
980 and wdd.lpn_id = lpn.outermost_lpn_id
981 and wdd.released_status = 'X' -- For LPN reuse ER : 6845650
982 and lpn.outermost_lpn_id = wlpn.lpn_id
983 and (wlpn.lpn_context = wms_container_pvt.lpn_context_picked
984 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
985 and lpn.organization_id = p_organization_id
986 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
987 and wlpn.license_plate_number like (p_lpn)
988 and wda.delivery_id IS NULL
989
990 UNION
991 select distinct lpn.outermost_lpn_id
992 , wlpn.license_plate_number as license_plate_number
993 , nvl(wda.delivery_id,0)
994 , get_delivery_name(wda.delivery_id)
995 , nvl(wdd.load_seq_number,0) as load_seq_num
996 from wsh_delivery_details_ob_grp_v wdd
997 , wsh_delivery_assignments_v wda
998 , wms_license_plate_numbers lpn
999 ,wms_license_plate_numbers wlpn
1000 ,wsh_new_deliveries_ob_grp_v wndv
1001 where wdd.delivery_detail_id = wda.delivery_detail_id
1002 and wdd.lpn_id is not null
1003 and wdd.lpn_id = lpn.lpn_id
1004 and wdd.released_status = 'X' -- For LPN reuse ER : 6845650
1005 and lpn.outermost_lpn_id = wlpn.lpn_id
1006 and (wlpn.lpn_context = wms_container_pvt.lpn_context_picked
1007 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
1008 and lpn.organization_id = p_organization_id
1009 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
1010 and wlpn.license_plate_number like (p_lpn)
1011 and wda.delivery_id IS NOT NULL
1012 and wda.delivery_id = wndv.delivery_id
1013 and wndv.status_code in ('OP', 'PA')
1014
1015 UNION
1016 select distinct lpn.outermost_lpn_id
1017 , wlpn.license_plate_number as license_plate_number
1018 , nvl(wda.delivery_id,0)
1019 , get_delivery_name(wda.delivery_id)
1020 , nvl(wdd.load_seq_number,0) as load_seq_num
1021 from wsh_delivery_details_ob_grp_v wdd
1022 , wsh_delivery_assignments_v wda
1023 , wms_license_plate_numbers lpn
1024 ,wms_license_plate_numbers wlpn
1025 where wdd.delivery_detail_id = wda.delivery_detail_id
1026 and wdd.lpn_id is not null
1027 and wdd.lpn_id = lpn.lpn_id
1028 and wdd.released_status = 'X' -- For LPN reuse ER : 6845650
1029 and lpn.outermost_lpn_id = wlpn.lpn_id
1030 and (wlpn.lpn_context = wms_container_pvt.lpn_context_picked
1031 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
1032 and lpn.organization_id = p_organization_id
1033 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
1034 and wlpn.license_plate_number like (p_lpn)
1035 and wda.delivery_id IS NULL
1036 order by load_seq_num, license_plate_number;
1037 end if;
1038 ELSE
1039 --END Added for bug 6717052
1040 if (p_trip_id <> 0) then
1041 -- to support loading while picking
1042 open x_lpn_lov for
1043 select distinct lpn.outermost_lpn_id
1044 , wlpn.license_plate_number
1045 , wnd.delivery_id,wnd.name
1046 from wms_license_plate_numbers lpn
1047 , wms_license_plate_numbers wlpn
1048 , wsh_new_deliveries_ob_grp_v wnd
1049 , wsh_delivery_legs_ob_grp_v wdl
1050 , wsh_delivery_details_ob_grp_v wdd
1051 , wsh_delivery_assignments_v wda
1052 , wsh_delivery_details_ob_grp_v wdd2
1053 where wdl.pick_up_stop_id = p_trip_stop_id
1054 and wdl.delivery_id = wnd.delivery_id
1055 --and wdl.PARENT_DELIVERY_LEG_ID IS NULL -- Added for MDC : if delivery
1056 --is associated to a consol delivery, do not allow to select here
1057 and wnd.status_code in ('OP', 'PA')
1058 and wnd.delivery_id = wda.delivery_id
1059 and wdd.delivery_detail_id = wda.delivery_detail_id
1060 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
1061 and wdd2.lpn_id is not null -- for performance, bug 2418639
1062 and wdd2.lpn_id = lpn.lpn_id
1063 and lpn.outermost_lpn_id = wlpn.lpn_id
1064 --MR-MDC wlpn.lpn_context <> wms_globals.lpn_loaded_for_shipment
1065 and ( wlpn.lpn_context = wms_container_pvt.lpn_context_picked
1066 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
1067 -- 5582189 dherring additional criteria added to ensure ship confirmed deliveries
1068 -- do not appear in the lov
1069 and wnd.status_code in ('OP', 'PA')
1070 and wdd.released_status = 'Y'
1071 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
1072 and wlpn.license_plate_number like (p_lpn)
1073 order by wlpn.license_plate_number;
1074
1075 else
1076 open x_lpn_lov for
1077 select distinct lpn.outermost_lpn_id
1078 , wlpn.license_plate_number as license_plate_number
1079 , nvl(wda.delivery_id,0)
1080 , get_delivery_name(wda.delivery_id)
1081 from wsh_delivery_details_ob_grp_v wdd
1082 , wsh_delivery_assignments_v wda
1083 , wms_license_plate_numbers lpn
1084 ,wms_license_plate_numbers wlpn
1085 ,wsh_new_deliveries_ob_grp_v wndv
1086 where wdd.delivery_detail_id = wda.delivery_detail_id
1087 and wdd.lpn_id is not null -- for performance, bug 2418639
1088 and wdd.lpn_id = lpn.outermost_lpn_id
1089 and wdd.released_status = 'X' -- For LPN reuse ER : 6845650
1090 and lpn.outermost_lpn_id = wlpn.lpn_id
1091 and (wlpn.lpn_context = wms_container_pvt.lpn_context_picked
1092 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
1093 and lpn.organization_id = p_organization_id
1094 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
1095 and wlpn.license_plate_number like (p_lpn)
1096 -- 5582189 dherring UNION introduced to avoid cartesian join
1097 and wda.delivery_id IS NOT NULL
1098 and wda.delivery_id = wndv.delivery_id
1099 and wndv.status_code in ('OP', 'PA')
1100
1101 UNION
1102 select distinct lpn.outermost_lpn_id
1103 , wlpn.license_plate_number as license_plate_number
1104 , nvl(wda.delivery_id,0)
1105 , get_delivery_name(wda.delivery_id)
1106 from wsh_delivery_details_ob_grp_v wdd
1107 , wsh_delivery_assignments_v wda
1108 , wms_license_plate_numbers lpn
1109 ,wms_license_plate_numbers wlpn
1110 where wdd.delivery_detail_id = wda.delivery_detail_id
1111 and wdd.lpn_id is not null -- for performance, bug 2418639
1112 and wdd.lpn_id = lpn.outermost_lpn_id
1113 and wdd.released_status = 'X' -- For LPN reuse ER : 6845650
1114 and lpn.outermost_lpn_id = wlpn.lpn_id
1115 and (wlpn.lpn_context = wms_container_pvt.lpn_context_picked
1116 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
1117 and lpn.organization_id = p_organization_id
1118 and (wdd.inv_interfaced_flag <> 'Y' or wdd.inv_interfaced_flag is null )
1119 and wlpn.license_plate_number like (p_lpn)
1120 -- 5582189 dherring UNION introduced to avoid cartesian join
1121 and wda.delivery_id IS NULL
1122 order by license_plate_number;
1123 end if;
1124 --Start Added for bug 6717052
1125 END IF;
1126 --END Added for bug 6717052
1127
1128 END get_lpn_lov;
1129
1130 procedure nested_serial_check(x_result OUT NOCOPY NUMBER,
1131 x_outermost_lpn OUT NOCOPY VARCHAR2,
1132 x_outermost_lpn_id OUT NOCOPY NUMBER,
1133 x_parent_lpn_id OUT NOCOPY NUMBER,
1134 x_parent_lpn OUT NOCOPY VARCHAR2,
1135 x_inventory_item_id OUT NOCOPY NUMBER,
1136 x_quantity OUT NOCOPY NUMBER,
1137 x_requested_quantity OUT NOCOPY NUMBER,
1138 x_delivery_detail_id OUT NOCOPY NUMBER,
1139 x_transaction_Temp_id OUT NOCOPY NUMBER,
1140 x_item_name OUT NOCOPY VARCHAR2,
1141 x_subinventory_code OUT NOCOPY VARCHAR2,
1142 x_revision OUT NOCOPY VARCHAR2,
1143 x_locator_id OUT NOCOPY NUMBER,
1144 x_lot_number OUT NOCOPY VARCHAR2,
1145 p_trip_id IN NUMBER,
1146 p_outermost_lpn_id IN NUMBER) IS
1147 cursor delivery_details(p_outermost_lpn_id IN NUMBER) is
1148 /* select wstt.trip_id, wstt.delivery_id, wstt.delivery_detail_id, wstt.inventory_item_id, wstt.quantity, wstt.outermost_lpn,
1149 wstt.parent_lpn_id, wstt.parent_lpn, wdd.serial_number,
1150 msik.concatenated_segments, msik.serial_number_control_code, wdd.requested_quantity,
1151 wdd.subinventory, wdd.revision, wdd.locator_id, wdd.lot_number
1152 from wms_shipping_transaction_temp wstt, wsh_delivery_details_ob_grp_v wdd, mtl_system_items_kfv msik
1153 where wstt.delivery_detail_id = wdd.delivery_detail_id
1154 and wstt.outermost_lpn_id = p_outermost_lpn_id
1155 and msik.inventory_item_id = wdd.inventory_item_id
1156 and msik.organization_id = wdd.organization_id
1157 and msik.serial_number_control_code = 6; */
1158 -- The above cursor is very time consuming, so replace it with the following one.
1159 select 0,wda.delivery_id, wdd.delivery_detail_id, wdd.inventory_item_id,wdd.requested_quantity,
1160 wlpn2.license_plate_number,wlpn.lpn_id, wlpn.license_plate_number,wdd.serial_number,
1161 msik.concatenated_segments,
1162 msik.serial_number_control_code, wdd.requested_quantity,wdd.subinventory, wdd.revision,
1163 wdd.locator_id, wdd.lot_number,wdd.picked_quantity
1164 from wms_license_plate_numbers wlpn, wms_license_plate_numbers wlpn2, wsh_delivery_details_ob_grp_v wdd,
1165 mtl_system_items_kfv msik,
1166 wsh_delivery_assignments_v wda, wsh_delivery_details_ob_grp_v wdd2
1167 where wlpn.outermost_lpn_id = p_outermost_lpn_id
1168 and wlpn.lpn_id = wdd2.lpn_id
1169 and wdd2.lpn_id is not null -- for performance, bug 2418639
1170 and wdd2.released_status = 'X' -- For LPN reuse ER : 6845650
1171 and wlpn.outermost_lpn_id = wlpn2.lpn_id
1172 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
1173 and wda.delivery_detail_id = wdd.delivery_detail_id
1174 and wdd.organization_id = msik.organization_id
1175 and wdd.inventory_item_id = msik.inventory_item_id
1176 and msik.serial_number_control_code = 6
1177 and wdd.transaction_temp_id is null;
1178
1179 l_transaction_temp_id NUMBER;
1180 l_trip_id NUMBER := p_trip_id;
1181 l_delivery_id NUMBER := 0;
1182 l_delivery_detail_id NUMBER := 0;
1183 l_inventory_item_id NUMBER := 0;
1184 l_quantity NUMBER := 0;
1185 l_outermost_lpn VARCHAR2(30) := null;
1186 l_parent_lpn_id NUMBER := 0;
1187 l_parent_lpn VARCHAR2(30) := null;
1188 l_serial_number varchar2(30) := null;
1189 l_serial_number_control_code NUMBER := 0;
1190 l_result NUMBER := 1;
1191 l_requested_quantity NUMBER := 0;
1192 l_item_name VARCHAR2(80);
1193 l_outermost_lpn_id NUMBER := p_outermost_lpn_id;
1194 l_subinventory_code VARCHAR2(30);
1195 l_revision VARCHAR2(10);
1196 l_locator_id NUMBER;
1197 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
1198 l_lot_number VARCHAR2(80);
1199 l_picked_quantity NUMBER := 0;
1200
1201 l_detail_attributes wsh_interface.ChangedAttributeTabType;
1202 l_InvPCInRecType wsh_integration.InvPCInRecType;
1203 l_return_status VARCHAR2(1);
1204 l_msg_count NUMBER;
1205 l_msg_data VARCHAR2(2000);
1206
1207 BEGIN
1208 debug('inside nested_serial_check', 'NESTED_SERIAL_CHECK');
1209 debug( 'p_trip_id is ' || p_trip_id, 'NESTED_SERIAL_CHECK');
1210 debug( 'p_outermost_lpn_id is ' || p_outermost_lpn_id, 'NESTED_SERIAL_CHECK');
1211 debug( 'openning delivery_details cursor', 'NESTED_SERIAL_CHECK');
1212
1213 --patchset J. Shipping API cleanup
1214 --initalizing l_InvPCInRecType to use for updating wdd with transaction_temp_id
1215 l_InvPCInRecType.transaction_id := NULL;
1216 l_InvPCInRecType.transaction_temp_id := NULL;
1217 l_InvPCInRecType.source_code :='INV';
1218 l_InvPCInRecType.api_version_number :=1.0;
1219 --\Shipping API cleanup
1220
1221 open delivery_details( p_outermost_lpn_id);
1222
1223 <<delivery_details_loop>>
1224 LOOP
1225 fetch delivery_details into l_trip_id, l_delivery_id, l_delivery_detail_id,
1226 l_inventory_item_id, l_quantity, l_outermost_lpn, l_parent_lpn_id,
1227 l_parent_lpn, l_serial_number, l_item_name, l_serial_number_control_code,
1228 l_requested_quantity,
1229 l_subinventory_code, l_revision, l_locator_id, l_lot_number,l_picked_quantity;
1230 exit when delivery_details%NOTFOUND;
1231
1232 debug('l_serial_control_code is ' || l_serial_number_control_code, 'NESTED_SERIAL_CHECK');
1233 debug('l_requested_quantity is ' || l_quantity,'NESTED_SERIAL_CHECK');
1234 debug('l_picked_quantity is ' || l_picked_quantity,'NESTED_SERIAL_CHECK');
1235
1236 if( l_serial_number_control_code = 6 AND l_serial_number is NULL) then
1237 l_result := 0;
1238
1239 select transaction_temp_id
1240 into l_transaction_temp_id
1241 from wsh_delivery_details_ob_grp_v
1242 where delivery_detail_id = l_delivery_detail_id;
1243
1244 if( l_transaction_temp_id is null ) then
1245 select mtl_material_Transactions_s.nextval
1246 into l_InvPCInRecType.transaction_temp_id
1247 from dual;
1248
1249 l_transaction_temp_id := l_InvPCInRecType.transaction_temp_id;
1250
1251 debug('About to call wsh_integration.Set_Inv_PC_Attributes','nested_serial_check');
1252 debug('transaction_temp_id set to: ' ||
1253 l_InvPCInRecType.transaction_temp_id,
1254 'nested_serial_check');
1255
1256 --patchset J. Shipping API cleanup
1257 --call to set the global variable in preparation to update transaction_temp_id
1258 wsh_integration.Set_Inv_PC_Attributes
1259 (p_in_attributes => l_InvPCInRecType,
1260 x_return_status => l_return_status,
1261 x_msg_count => l_msg_count,
1262 x_msg_data => l_msg_data);
1263
1264 IF l_return_status IN (G_RET_STS_ERROR, G_RET_STS_UNEXP_ERROR) THEN
1265 debug('wsh_integration.set_inv_pc_attributes failed'
1266 || ' with status: ' || l_return_status,'nested_serial_check');
1267 --check where to handle this error
1268 RAISE fnd_api.g_exc_unexpected_error;
1269 END IF;
1270
1271
1272 l_detail_attributes(1).delivery_detail_id :=
1273 l_delivery_detail_id;
1274 l_detail_attributes(1).action_flag := 'U';
1275 --Passing picked_quantity also because wsh_interface.update_shipping_attributes
1276 --will null it out if we do not
1277 l_detail_attributes(1).picked_quantity := l_picked_quantity;
1278
1279 debug('About to call wsh_interface.update_shipping_attributes','nested_serial_check');
1280 debug('delivery_detail_id : ' ||
1281 l_detail_attributes(1).delivery_detail_id,
1282 'nested_serial_check');
1283
1284 --update transaction_temp_id in WDD
1285 wsh_interface.update_shipping_attributes
1286 (x_return_status => l_return_status,
1287 p_changed_attributes => l_detail_attributes,
1288 p_source_code => 'INV');
1289 --\Shipping API cleanup
1290 IF l_return_status IN (G_RET_STS_ERROR, G_RET_STS_UNEXP_ERROR) THEN
1291 debug('wsh_interface.update_shipping_attributes failed'
1292 || ' with status: ' || l_return_status,'nested_serial_check');
1293 --check where to handle this error
1294 RAISE fnd_api.g_exc_unexpected_error;
1295 END IF;
1296 END IF;
1297 exit delivery_details_loop;
1298
1299 elsif( l_serial_number_control_code <> 6
1300 OR (l_serial_number_control_code = 6 AND l_serial_number is not null )) then
1301 l_result := 1;
1302 end if;
1303 END LOOP;
1304
1305 x_result := l_result;
1306 x_outermost_lpn := l_outermost_lpn;
1307 x_outermost_lpn_id := l_outermost_lpn_id;
1308 x_parent_lpn_id := l_parent_lpn_id;
1309 x_parent_lpn := l_parent_lpn;
1310 x_inventory_item_id := l_inventory_item_id;
1311 --The number of serial numbers expected should be the picked_quantity
1312 --as user could have overpicked.
1313 x_quantity := l_picked_quantity;
1314 x_requested_quantity := l_requested_quantity;
1315 x_delivery_detail_id := l_delivery_detail_id;
1316 x_item_name := l_item_name;
1317 x_transaction_temp_id := l_transaction_Temp_id;
1318 x_subinventory_code := l_subinventory_code;
1319 x_locator_id := l_locator_id;
1320 x_revision := l_revision;
1321 x_lot_number := l_lot_number;
1322
1323 Debug( 'l_result is ' || x_result, 'NESTED_SERIAL_CHECK');
1324
1325 END NESTED_SERIAL_CHECK;
1326
1327 /* the following procedure will not be used any more */
1328 PROCEDURE LPN_DISCREPANCY_CHECK( x_result OUT NOCOPY NUMBER,
1329 x_parent_lpn_id OUT NOCOPY NUMBER,
1330 x_parent_lpn OUT NOCOPY VARCHAR2,
1331 x_inventory_item_id OUT NOCOPY NUMBER,
1332 x_quantity OUT NOCOPY NUMBER,
1333 x_requested_quantity OUT NOCOPY NUMBER,
1334 x_item_name OUT NOCOPY VARCHAR2,
1335 p_trip_id IN NUMBER,
1336 p_delivery_id IN NUMBER,
1337 p_outermost_lpn_id IN NUMBER) IS
1338
1339 cursor sum_delivery_details(p_outermost_lpn_id IN NUMBER, p_delivery_id IN NUMBER) is
1340 select sum(wdd.requested_quantity), sum(wlc.quantity), wda.delivery_id, wlc.inventory_item_id, wlc.parent_lpn_id
1341 from wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda, wsh_delivery_details_ob_grp_v wdd2,
1342 wms_license_plate_numbers lpn, wms_lpn_contents wlc
1343 where wdd.delivery_detail_id = wda.delivery_detail_id
1344 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
1345 and wdd2.lpn_id = lpn.lpn_id
1346 and wdd2.released_status = 'X' -- For LPN reuse ER : 6845650
1347 and wlc.parent_lpn_id = lpn.lpn_id
1348 and lpn.outermost_lpn_id = p_outermost_lpn_id
1349 and wlc.inventory_item_id = wdd.inventory_item_id
1350 -- and (wda.delivery_id = p_delivery_id or wda.delivery_id is null)
1351 group by wda.delivery_id, wlc.inventory_item_id, wlc.parent_lpn_id;
1352
1353 l_delivery_detail_id NUMBER;
1354 l_inventory_item_id NUMBER;
1355 l_sum_quantity NUMBER;
1356 l_parent_lpn_id NUMBER;
1357 l_parent_lpn VARCHAR2(30);
1358 l_result NUMBER;
1359 l_sum_requested_quantity NUMBER;
1360 l_item_name VARCHAR2(80);
1361 l_delivery_id NUMBER;
1362 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1363 l_debug number;
1364 BEGIN
1365 IF g_debug IS NULL THEN
1366 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1367 END IF;
1368 l_debug := g_debug;
1369
1370 IF (l_debug = 1) THEN
1371 Debug( 'inside lpn_discrency_check', 'LPN_DISCREPANCY_CHECK');
1372 END IF;
1373 open sum_delivery_details(p_outermost_lpn_id, p_delivery_id);
1374
1375 <<sum_delivery_details_loop>>
1376 LOOP
1377 fetch sum_delivery_details into l_sum_requested_quantity, l_sum_quantity,
1378 l_delivery_id, l_inventory_item_id, l_parent_lpn_id;
1379 IF (l_debug = 1) THEN
1380 Debug( 'l_sum_quantity is ' || l_sum_quantity, 'LPN_DISCREPANCY_CHECK');
1381 Debug( 'l_sum_requested_quantity is ' || l_sum_requested_quantity, 'LPN_DISCREPANCY_CHECK');
1382 END IF;
1383 exit when sum_delivery_details%NOTFOUND;
1384
1385 if( l_sum_quantity < l_sum_requested_quantity ) then
1386 l_result := 0;
1387 select distinct wstt.parent_lpn
1388 into l_parent_lpn
1389 from wms_shipping_transaction_Temp wstt
1390 where wstt.parent_lpn_id = l_parent_lpn_id
1391 and wstt.inventory_item_id = l_inventory_item_id;
1392
1393 select distinct msik.concatenated_segments
1394 into l_item_name
1395 from mtl_system_items_kfv msik
1396 where msik.inventory_item_id = l_inventory_item_id;
1397
1398 exit sum_delivery_details_loop;
1399 else
1400 l_result := 1;
1401 end if;
1402
1403 END LOOP;
1404
1405 x_result := l_result;
1406 x_parent_lpn_id := l_parent_lpn_id;
1407 x_parent_lpn := l_parent_lpn;
1408 x_inventory_item_id := l_inventory_item_id;
1409 x_quantity := l_sum_quantity;
1410 x_requested_quantity := l_sum_requested_quantity;
1411 x_item_name := l_item_name;
1412 END LPN_DISCREPANCY_CHECK;
1413
1414 PROCEDURE check_lpn_in_diff_ship_method(p_outermost_lpn_id IN NUMBER,
1415 p_organization_id IN NUMBER,
1416 x_result OUT NOCOPY NUMBER) IS
1417 l_delivery_id NUMBER;
1418 l_trip_id NUMBER;
1419 cursor deliveries_in_lpn is
1420 select distinct wda.delivery_id
1421 from wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda, wms_license_plate_numbers lpn,
1422 wsh_delivery_details_ob_grp_v wdd2
1423 where lpn.outermost_lpn_id = p_outermost_lpn_id
1424 and wdd2.lpn_id = lpn.lpn_id
1425 and wdd2.released_status = 'X' -- For LPN reuse ER : 6845650
1426 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
1427 and wdd.delivery_detail_id = wda.delivery_detail_id;
1428
1429 BEGIN
1430 x_result := 0;
1431 Debug( 'Entered check_lpn_in_diff_ship_method : ' , 'check_lpn_in_diff_ship_method');
1432 Debug( 'p_outermost_lpn_id: ' || p_outermost_lpn_id, 'check_lpn_in_diff_ship_method');
1433 Debug( 'p_organization_id: ' || p_organization_id, 'check_lpn_in_diff_ship_method');
1434 OPEN deliveries_in_lpn;
1435 LOOP
1436 fetch deliveries_in_lpn into l_delivery_id;
1437 exit When deliveries_in_lpn%NOTFOUND;
1438
1439 BEGIN
1440 select 1
1441 into x_result
1442 from dual
1443 where exists (select 1
1444 from wms_shipping_transaction_temp
1445 where delivery_id = l_delivery_id
1446 and direct_ship_flag='Y');
1447 EXCEPTION
1448 WHEN NO_DATA_FOUND THEN
1449 Debug( 'No delivery id data for direct_ship_flag=Y in WSTT: ' , 'check_lpn_in_diff_ship_method');
1450 BEGIN
1451 -- check the trip
1452 select wts.trip_id
1453 into l_trip_id
1454 from wsh_delivery_legs_ob_grp_v wdl, wsh_trip_stops_ob_grp_v wts
1455 where wdl.delivery_id = l_delivery_id
1456 and wdl.pick_up_stop_id = wts.stop_id;
1457
1458 select 1
1459 into x_result
1460 from dual
1461 where exists (select 1
1462 from wms_shipping_transaction_temp
1463 where trip_id = l_trip_id
1464 and direct_ship_flag='Y');
1465 EXCEPTION
1466 WHEN NO_DATA_FOUND THEN
1467 Debug( 'No Trip data for direct_ship_flag=Y in WSTT: ' , 'check_lpn_in_diff_ship_method');
1468 null;
1469 END;
1470 END;
1471 END LOOP;
1472 close deliveries_in_lpn;
1473
1474 Debug( ' x_result : ' || x_result , 'check_lpn_in_diff_ship_method');
1475 EXCEPTION
1476 when others then null;
1477 END check_lpn_in_diff_ship_method;
1478
1479
1480 PROCEDURE check_lpn_in_same_trip(p_outermost_lpn_id IN NUMBER,
1481 p_organization_id IN NUMBER,
1482 p_dock_door_id IN NUMBER,
1483 x_result OUT NOCOPY NUMBER,
1484 x_loaded_dock_door OUT NOCOPY VARCHAR2,
1485 x_delivery_name OUT NOCOPY VARCHAR2,
1486 x_trip_name OUT NOCOPY VARCHAR2) IS
1487 l_delivery_id NUMBER;
1488 l_trip_id NUMBER;
1489 cursor deliveries_in_lpn is
1490 select distinct wda.delivery_id
1491 from wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda, wms_license_plate_numbers lpn,
1492 wsh_delivery_details_ob_grp_v wdd2
1493 where lpn.outermost_lpn_id = p_outermost_lpn_id
1494 and wdd2.lpn_id = lpn.lpn_id
1495 and wdd2.released_status = 'X' -- For LPN reuse ER : 6845650
1496 and wdd2.lpn_id is not null -- for performance, bug 2418639
1497 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
1498 and wdd.delivery_detail_id = wda.delivery_detail_id;
1499
1500 cursor lpn_in_other_dock(p_delivery_id NUMBER) is
1501 select distinct milk.concatenated_segments
1502 from mtl_item_locations_kfv milk,wms_shipping_transaction_temp wstt
1503 where wstt.delivery_id = p_delivery_id
1504 and wstt.organization_id = p_organization_id
1505 and wstt.dock_appoint_flag = 'N'
1506 and wstt.dock_door_id <> p_dock_door_id
1507 and milk.organization_id = p_organization_id
1508 and milk.inventory_location_id =wstt.dock_door_id;
1509
1510 cursor lpn_in_other_dock2(p_trip_id NUMBER) is
1511 select distinct milk.concatenated_segments
1512 from mtl_item_locations_kfv milk,wms_shipping_transaction_temp wstt
1513 where wstt.trip_id = p_trip_id
1514 and wstt.organization_id = p_organization_id
1515 and wstt.dock_appoint_flag = 'N'
1516 and wstt.dock_door_id <> p_dock_door_id
1517 and milk.organization_id = p_organization_id
1518 and milk.inventory_location_id =wstt.dock_door_id;
1519
1520 BEGIN
1521 x_result := 0;
1522 x_delivery_name := '';
1523 x_trip_name := '';
1524
1525 OPEN deliveries_in_lpn;
1526 LOOP
1527 fetch deliveries_in_lpn into l_delivery_id;
1528 exit When deliveries_in_lpn%NOTFOUND;
1529 if l_delivery_id is not null then
1530 -- First check if this delivery have trip which is scheduled
1531 BEGIN
1532 select wt.name, milk.concatenated_segments
1533 into x_trip_name, x_loaded_dock_door
1534 from wsh_delivery_legs_ob_grp_v wdl, wsh_trip_stops_ob_grp_v wts,wms_dock_appointments_b wda,
1535 mtl_item_locations_kfv milk, wsh_trips_ob_grp_v wt
1536 where wdl.delivery_id = l_delivery_id
1537 and wdl.pick_up_stop_id = wts.stop_id
1538 and wda.trip_stop = wts.stop_id
1539 and wda.organization_id = p_organization_id
1540 and wda.organization_id = milk.organization_id
1541 and wda.dock_id = milk.inventory_location_id
1542 and wt.trip_id = wts.trip_id;
1543 x_result := 2;
1544 close deliveries_in_lpn;
1545 return;
1546
1547 EXCEPTION
1548 WHEN NO_DATA_FOUND THEN null;
1549 END;
1550
1551 -- check if there are LPNs loaded from the same delivery
1552 OPEN lpn_in_other_dock(l_delivery_id);
1553 fetch lpn_in_other_dock into x_loaded_dock_door;
1554 if lpn_in_other_dock%FOUND then
1555 select name
1556 into x_delivery_name
1557 from wsh_new_deliveries_ob_grp_v
1558 where delivery_id = l_delivery_id;
1559 x_result := 1;
1560 close lpn_in_other_dock;
1561 close deliveries_in_lpn;
1562 return;
1563 end if;
1564 close lpn_in_other_dock;
1565
1566 -- check the corresponding trip if any
1567 BEGIN
1568 select wts.trip_id
1569 into l_trip_id
1570 from wsh_delivery_legs_ob_grp_v wdl, wsh_trip_stops_ob_grp_v wts
1571 where wdl.delivery_id = l_delivery_id
1572 and wdl.pick_up_stop_id = wts.stop_id;
1573
1574 OPEN lpn_in_other_dock2(l_trip_id);
1575 fetch lpn_in_other_dock2 into x_loaded_dock_door;
1576 if lpn_in_other_dock2%FOUND then
1577 select name
1578 into x_trip_name
1579 from wsh_trips_ob_grp_v
1580 where trip_id = l_trip_id;
1581 x_result := 1;
1582 close lpn_in_other_dock2;
1583 close deliveries_in_lpn;
1584 return;
1585 end if;
1586 close lpn_in_other_dock2;
1587
1588 EXCEPTION
1589 when no_data_found then
1590 null;
1591 END;
1592 end if;
1593 END LOOP;
1594 close deliveries_in_lpn;
1595
1596 EXCEPTION
1597 when others then null;
1598
1599 END check_lpn_in_same_trip;
1600
1601 procedure check_credit_hold(x_result OUT NOCOPY NUMBER,
1602 x_delivery_detail_ids OUT NOCOPY VARCHAR2,
1603 p_outermost_lpn_id IN NUMBER) IS
1604
1605 l_delivery_detail_id NUMBER;
1606 l_source_header_id NUMBER;
1607 l_source_line_id NUMBER;
1608 l_delivery_detail_ids VARCHAR2(1024):= NULL;
1609 l_return_status VARCHAR2(1);
1610 l_prev_hdr_id NUMBER;
1611 l_prev_line_id NUMBER;
1612 cursor delivery_details( p_outermost_lpn_id NUMBER) is
1613 select wdd.delivery_detail_id, wdd.source_header_id, wdd.source_line_id
1614 from wms_license_plate_numbers wlpn, wsh_delivery_details_ob_grp_v wdd0, wsh_delivery_assignments_v wda,
1615 wsh_delivery_details_ob_grp_v wdd
1616 where
1617 wlpn.outermost_lpn_id = p_outermost_lpn_id
1618 and wlpn.lpn_id = wdd0.lpn_id
1619 and wdd0.released_status = 'X' -- For LPN reuse ER : 6845650
1620 and wdd0.delivery_detail_id = wda.parent_delivery_detail_id
1621 and wdd.delivery_detail_id = wda.delivery_detail_id
1622 and wdd.lpn_id is null
1623 order by wdd.source_header_id, wdd.source_line_id;
1624 -- Bug 4559904, WDD line with lpn does not have source_header_id and source_line_id
1625 -- populated correctly, do credit hold check will fail with those WDD lines.
1626 -- Added above to not pickup WDD records with lpn_id
1627 -- Also added order by so that the check_credit_holds only needs to be called when
1628 -- header or line is different.
1629 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1630 l_debug number;
1631
1632 begin
1633 IF g_debug IS NULL THEN
1634 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1635 END IF;
1636 l_debug := g_debug;
1637 x_result := 0;
1638 l_prev_hdr_id := -999;
1639 l_prev_line_id := -999;
1640 FOR a_delivery_detail IN delivery_details(p_outermost_lpn_id) LOOP
1641 IF (l_prev_hdr_id <> nvl(a_delivery_detail.source_header_id, -999)) OR
1642 (l_prev_line_id <> nvl(a_delivery_detail.source_line_id, -999)) THEN
1643 IF (l_debug = 1) THEN
1644 Debug('Prev Header ID '||l_prev_hdr_id||' different from current Header ID '
1645 ||a_delivery_detail.source_header_id||' OR', 'check_credit_hold');
1646 Debug('Prev Line ID '||l_prev_line_id||' different from current Line ID '
1647 ||a_delivery_detail.source_line_id, 'check_credit_hold');
1648 Debug('Calling wsh_details_validations.check_credit_holds with ', 'check_credit_hold');
1649 Debug(' p_detail_id = '||a_delivery_detail.delivery_detail_id, 'check_credit_hold');
1650 Debug(' p_source_line_id = '||a_delivery_detail.source_line_id, 'check_credit_hold');
1651 Debug(' p_source_header_id = '||a_delivery_detail.source_header_id, 'check_credit_hold');
1652 END IF;
1653 wsh_details_validations.check_credit_holds
1654 (p_detail_id => a_delivery_detail.delivery_detail_id,
1655 p_activity_type => 'SHIP',
1656 p_source_line_id => a_delivery_detail.source_line_id,
1657 p_source_header_id => a_delivery_detail.source_header_id,
1658 p_source_code => 'OE',
1659 p_init_flag => 'Y',
1660 x_return_status => l_return_status);
1661
1662 IF (l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS) THEN
1663 x_result := 1;
1664 l_delivery_detail_ids := l_delivery_detail_ids || ' ' || a_delivery_detail.delivery_detail_id;
1665 END IF;
1666
1667 l_prev_hdr_id := a_delivery_detail.source_header_id;
1668 l_prev_line_id := a_delivery_detail.source_line_id;
1669 ELSE
1670 IF (l_debug = 1) THEN
1671 Debug('Prev Header ID '||l_prev_hdr_id||' equals to current Header ID '
1672 ||a_delivery_detail.source_header_id||' AND', 'check_credit_hold');
1673 Debug('Prev Line ID '||l_prev_line_id||' equals to current Line ID '
1674 ||a_delivery_detail.source_line_id||', no need to call ' ||
1675 ' wsh_details_validations.check_credit_holds', 'check_credit_hold');
1676 END IF;
1677 END IF;
1678 END LOOP;
1679 x_delivery_detail_ids := l_delivery_detail_ids;
1680
1681 end check_credit_hold;
1682
1683
1684 PROCEDURE LPN_SUBMIT(
1685 p_outermost_lpn_id IN NUMBER,
1686 p_trip_id IN NUMBER,
1687 p_organization_id IN NUMBER,
1688 p_dock_door_id IN NUMBER,
1689 x_error_code OUT NOCOPY NUMBER,
1690 x_outermost_lpn OUT NOCOPY VARCHAR2,
1691 x_outermost_lpn_id OUT NOCOPY NUMBER,
1692 x_parent_lpn_id OUT NOCOPY NUMBER,
1693 x_parent_lpn OUT NOCOPY VARCHAR2,
1694 x_inventory_item_id OUT NOCOPY NUMBER,
1695 x_quantity OUT NOCOPY NUMBER,
1696 x_requested_quantity OUT NOCOPY NUMBER,
1697 x_delivery_detail_id OUT NOCOPY NUMBER,
1698 x_transaction_Temp_id OUT NOCOPY NUMBER,
1699 x_item_name OUT NOCOPY VARCHAR2,
1700 x_subinventory_code OUT NOCOPY VARCHAR2,
1701 x_revision OUT NOCOPY VARCHAR2,
1702 x_locator_id OUT NOCOPY NUMBER,
1703 x_lot_number OUT NOCOPY VARCHAR2,
1704 x_loaded_dock_door OUT NOCOPY VARCHAR2,
1705 x_delivery_name OUT NOCOPY VARCHAR2,
1706 x_trip_name OUT NOCOPY VARCHAR2,
1707 x_delivery_detail_ids OUT NOCOPY VARCHAR2,
1708 p_is_rfid_call IN VARCHAR2 DEFAULT 'N'
1709 ) IS
1710
1711 cursor delivery_details( p_outermost_lpn_id NUMBER) is
1712 select delivery_detail_id, requested_quantity
1713 from wms_shipping_transaction_Temp
1714 where
1715 outermost_lpn_id = p_outermost_lpn_id;
1716
1717 CURSOR nested_children_lpn_cursor IS
1718 SELECT lpn_id
1719 FROM WMS_LICENSE_PLATE_NUMBERS
1720 START WITH lpn_id = p_outermost_lpn_id
1721 CONNECT BY parent_lpn_id = PRIOR lpn_id;
1722
1723 l_delivery_detail_id NUMBER;
1724 l_outer_cont_instance_id NUMBER;
1725 l_quantity NUMBER;
1726 l_load_before NUMBER := 0;
1727 l_result NUMBER;
1728 l_msg_code VARCHAR2(248);
1729 l_loaded_dock_door VARCHAR2(2000);
1730 l_delivery_count NUMBER;
1731 l_delivery_detail_ids VARCHAR2(1024);
1732
1733 l_detail_attributes wsh_delivery_details_pub.ChangedAttributeTabType;
1734
1735 l_index NUMBER := 1;
1736 l_return_status VARCHAR2(1);
1737 l_msg_count NUMBER;
1738 l_msg_data VARCHAR2(2000);
1739
1740 l_consol_delivery_id NUMBER; --mdc
1741 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1742 l_debug number;
1743 BEGIN
1744 IF g_debug IS NULL THEN
1745 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1746 END IF;
1747 l_debug := g_debug;
1748 x_error_code := 0;
1749 IF (l_debug = 1) THEN
1750 Debug( 'Entered lpn_submit ' , 'LPN_SUBMIT');
1751 Debug( 'p_outermost_lpn_id : ' || p_outermost_lpn_id, 'LPN_SUBMIT');
1752 Debug( 'p_trip_id : ' || p_trip_id, 'LPN_SUBMIT');
1753 Debug( 'p_organization_id : ' || p_organization_id, 'LPN_SUBMIT');
1754 Debug( 'p_dock_door_id : ' || p_dock_door_id, 'LPN_SUBMIT');
1755 Debug( 'p_is_rfid_call : ' || p_is_rfid_call, 'LPN_SUBMIT');
1756 END IF;
1757
1758
1759 -- First check if the lpn has been loaded before
1760 BEGIN
1761 select 1
1762 into l_load_before
1763 from DUAL
1764 where exists (
1765 select 1
1766 from wms_shipping_transaction_temp
1767 where outermost_lpn_id = p_outermost_lpn_id
1768 );
1769
1770 if l_load_before = 1 then
1771 x_error_code := 1;
1772 return;
1773 end if;
1774
1775 EXCEPTION
1776 WHEN NO_DATA_FOUND THEN null;
1777 END;
1778
1779 IF (l_debug = 1) THEN
1780 Debug('Check if any other LPNs in the same delivery is loaded by other ship ' ||
1781 'method such as direct ship','LPN_SUBMIT');
1782 END IF;
1783 check_lpn_in_diff_ship_method(p_outermost_lpn_id,
1784 p_organization_id,
1785 l_result);
1786 if l_result = 1 then
1787 x_error_code := 8;
1788 return;
1789 end if;
1790
1791 IF (l_debug = 1) THEN
1792 Debug('Check if any other LPNs in teh same delivery or same trip is ' ||
1793 'loaded to another dock door', 'LPN_SUBMIT');
1794 END IF;
1795 -- check if any other LPNs in teh same delivery or same trip is loaded to another dock door
1796 -- Only need to check for LPN Ship Page
1797 if (p_trip_id = 0) then
1798 check_lpn_in_same_trip(p_outermost_lpn_id,
1799 p_organization_id,
1800 p_dock_door_id,
1801 l_result,
1802 l_loaded_dock_door,
1803 x_delivery_name,
1804 x_trip_name);
1805 if l_result = 1 then
1806 x_error_code := 5;
1807 x_loaded_dock_door := l_loaded_dock_door;
1808 return;
1809 elsif l_result = 2 then
1810 x_error_code := 6;
1811 x_loaded_dock_door := l_loaded_dock_door;
1812 IF p_is_rfid_call = 'N' then--we do want to proceed for RFID call
1813 return;
1814 END IF;
1815 end if;
1816
1817 end if;
1818
1819 IF (l_debug = 1) THEN
1820 Debug('check if there is any delivery line on credit check hold, p_outer_most_lpn_id='
1821 ||p_outermost_lpn_id,'LPN_SUBMIT');
1822 END IF;
1823 check_credit_hold(l_result,
1824 l_delivery_detail_ids,
1825 p_outermost_lpn_id);
1826 if l_result = 1 then
1827 x_error_code := 9;
1828 x_delivery_detail_ids := l_delivery_detail_ids;
1829 return;
1830 end if;
1831
1832
1833 IF (l_debug = 1) THEN
1834 Debug('Check LPN STATUS','LPN_SUBMIT');
1835 END IF;
1836 -- Second check if the LPN's status is correct
1837 Validate_LPN_Status(l_result,
1838 l_msg_code,
1839 p_trip_id,
1840 p_organization_id,
1841 p_outermost_lpn_id);
1842 if l_result = 1 then
1843 x_error_code := 2;
1844 return;
1845 end if;
1846
1847 /* R12 MDC : This is not required any more
1848 -- check if the outermost LPN contains multiple delivery
1849 if p_trip_id = 0 then
1850 select count(distinct wda.delivery_id)
1851 into l_delivery_count
1852 from wsh_delivery_assignments_v wda, wsh_delivery_details_ob_grp_v wdd
1853 , wms_license_plate_numbers wlpn
1854 where wlpn.outermost_lpn_id = p_outermost_lpn_id
1855 and wlpn.lpn_id = wdd.lpn_id
1856 and wdd.lpn_id is not null -- for performance, bug 2418639
1857 and wda.parent_delivery_detail_id = wdd.delivery_detail_id
1858 and wda.delivery_id is not null;
1859 if l_delivery_count >1 then
1860 x_error_code := 7;
1861 return;
1862 end if;
1863 end if; */
1864
1865 IF (l_debug = 1) THEN
1866 Debug('Populate record','LPN_SUBMIT');
1867 END IF;
1868 -- Populate the lpn info to the temp table
1869 POPULATE_WSTT(l_result,
1870 l_msg_code,
1871 p_organization_id,
1872 p_outermost_lpn_id,
1873 p_trip_id,
1874 p_dock_door_id);
1875 if l_result = 1 then
1876 x_error_code := 3;
1877 return;
1878 end if;
1879
1880 IF (l_debug = 1) THEN
1881 debug('Returned successfully from populate_wstt','LPN_SUBMIT');
1882 END IF;
1883
1884 --MRANA : MDC :
1885 IF (l_debug = 1) THEN
1886 debug('About to delete mmtt/wdt with task type=7 and LPN: ' ||
1887 p_outermost_lpn_id,'LPN_SUBMIT');
1888 END IF;
1889
1890 BEGIN
1891 DELETE wms_dispatched_tasks wdt
1892 WHERE task_type = 7
1893 AND organization_id = p_organization_id
1894 AND transfer_lpn_id = p_outermost_lpn_id;
1895 IF (l_debug = 1) THEN debug('DELETED WDT FOR LPN: ' || p_outermost_lpn_id,'LPN_SUBMIT'); END IF;
1896
1897 DELETE mtl_material_transactions_temp mmtt
1898 WHERE wms_task_type = 7
1899 AND organization_id = p_organization_id
1900 AND content_lpn_id = p_outermost_lpn_id;
1901 IF (l_debug = 1) THEN debug('DELETED WDT FOR LPN: ' || p_outermost_lpn_id,'LPN_SUBMIT'); END IF;
1902 EXCEPTION
1903 WHEN NO_DATA_FOUND THEN
1904 IF (l_debug = 1) THEN debug('NO Data found to delete MMTT/WDT : ','LPN_SUBMIT' ); END IF;
1905 NULL;
1906 END ;
1907
1908
1909 --patchset J. Shipping API cleanup
1910 -- Update the shipping quantity
1911 l_index :=1;
1912 l_detail_attributes.DELETE;
1913 open delivery_details(p_outermost_lpn_id);
1914 LOOP
1915 fetch delivery_details
1916 into l_delivery_detail_id,l_quantity;
1917
1918 exit when delivery_details%NOTFOUND;
1919
1920 l_detail_attributes(l_index).delivery_detail_id :=
1921 l_delivery_detail_id;
1922 l_detail_attributes(l_index).shipped_quantity := l_quantity;
1923
1924 IF (l_debug = 1) THEN
1925 Debug( 'Update line '||l_detail_attributes(l_index).delivery_detail_id||
1926 ' with shipped quantity '|| l_detail_attributes(l_index).shipped_quantity,
1927 'LPN_SUBMIT');
1928 END IF;
1929
1930 l_index := l_index + 1;
1931 END LOOP;
1932 close delivery_details;
1933
1934 IF (l_debug = 1) THEN
1935 debug('l_detail_attributes count : ' || l_detail_attributes.COUNT ,
1936 'LPN_SUBMIT');
1937 Debug('About to call Shipping API to update the shipped quantity','LPN_SUBMIT');
1938 END IF;
1939
1940 wsh_delivery_details_pub.update_shipping_attributes
1941 (p_api_version_number => 1.0,
1942 p_init_msg_list => G_TRUE,
1943 p_commit => G_FALSE,
1944 x_return_status => l_return_status,
1945 x_msg_count => l_msg_count,
1946 x_msg_data => l_msg_data,
1947 p_changed_attributes => l_detail_attributes,
1948 p_source_code => 'OE');
1949
1950 IF l_return_status <> G_RET_STS_SUCCESS THEN
1951 IF l_debug = 1 THEN
1952 debug('wsh_delivery_details_pub.update_shipping_attributes failed'
1953 || ' with status: ' || l_return_status, 'LPN_SUBMIT');
1954 debug('l_msg_count: ' || l_msg_count,'LPN_SUBMIT');
1955 debug('l_msg_data: ' || l_msg_data,'LPN_SUBMIT');
1956 END IF;
1957 RAISE fnd_api.g_exc_unexpected_error;
1958 END IF;
1959 --\Shipping API cleanup
1960
1961 -- change the LPN context
1962 UPDATE WMS_LICENSE_PLATE_NUMBERS
1963 SET lpn_context = WMS_Container_PUB.LPN_LOADED_FOR_SHIPMENT,
1964 last_update_date = SYSDATE,
1965 last_updated_by = FND_GLOBAL.USER_ID
1966 where lpn_id = p_outermost_lpn_id;
1967
1968 -- update the lpn context for all children lpns
1969 FOR l_lpn_id IN nested_children_lpn_cursor LOOP
1970 UPDATE WMS_LICENSE_PLATE_NUMBERS
1971 SET lpn_context = WMS_Container_PUB.LPN_LOADED_FOR_SHIPMENT,
1972 last_update_date = SYSDATE,
1973 last_updated_by = FND_GLOBAL.USER_ID
1974 where lpn_id = l_lpn_id.lpn_id;
1975 END LOOP;
1976
1977 --Patchset J LPN hierarchy
1978 --Populate Shipping with LPN hierarchy
1979
1980 --Release 12: LPN Synchronize
1981 -- The following code of populating shipping with LPN hierarchy
1982 -- is not necessary because LPN hierarchy is in sync between WMS and WSH
1983 -- Removed the call to lpn_hierarchy_actions
1984
1985 -- check serial numbers at sale order issue
1986 nested_serial_check(l_result,
1987 x_outermost_lpn,
1988 x_outermost_lpn_id,
1989 x_parent_lpn_id,
1990 x_parent_lpn,
1991 x_inventory_item_id,
1992 x_quantity,
1993 x_requested_quantity,
1994 x_delivery_detail_id,
1995 x_transaction_Temp_id,
1996 x_item_name,
1997 x_subinventory_code,
1998 x_revision,
1999 x_locator_id,
2000 x_lot_number,
2001 p_trip_id,
2002 p_outermost_lpn_id);
2003 if l_result = 0 then
2004 x_error_code := 4;
2005 return;
2006 end if;
2007
2008 -- to let other people know this LPN is loaded
2009 commit;
2010 EXCEPTION
2011 WHEN fnd_api.g_exc_unexpected_error THEN
2012 --if keep current structure of returning error_code
2013 --no need to get message from stack as java side does it
2014 fnd_msg_pub.count_and_get(p_count => l_msg_count,
2015 p_data => l_msg_data);
2016 IF l_debug = 1 THEN
2017 debug('LPN_SUBMIT raised unexpected error','LPN_SUBMIT');
2018 debug('msg_stack: ' || l_msg_data,'LPN_SUBMIT');
2019 END IF;
2020 x_error_code := 9999; --check what java side does with this error_code
2021 WHEN OTHERS THEN
2022 IF l_debug = 1 THEN
2023 debug('Other exception raised: ' || SQLERRM, 'LPN_SUBMIT');
2024 END IF;
2025 x_error_code := 9999;
2026 END LPN_SUBMIT;
2027
2028 PROCEDURE CHECK_LPN_DELIVERIES(p_trip_id IN NUMBER,
2029 p_organization_id IN NUMBER,
2030 p_dock_door_id IN NUMBER,
2031 p_outermost_lpn_id IN NUMBER,
2032 p_delivery_id IN NUMBER,
2033 x_error_code OUT NOCOPY NUMBER,
2034 x_missing_item OUT NOCOPY t_genref,
2035 x_missing_lpns OUT NOCOPY t_genref,
2036 x_ship_set OUT NOCOPY VARCHAR2,
2037 x_delivery_info OUT NOCOPY t_genref,
2038 x_deli_count OUT NOCOPY NUMBER,
2039 p_rfid_call IN VARCHAR2 DEFAULT 'N')
2040 IS
2041 l_missing_exists NUMBER;
2042 l_return_status VARCHAR2(1);
2043 l_error_msg VARCHAR2(240);
2044 l_delivery_id NUMBER;
2045 l_dock_appoint_flag VARCHAR2(1);
2046 temp_val NUMBER;
2047
2048 l_action_prms wsh_interface_ext_grp.del_action_parameters_rectype; --g-log
2049 l_delivery_id_tab wsh_util_core.id_tab_type;
2050 l_delivery_out_rec wsh_interface_ext_grp.del_action_out_rec_type;
2051 l_msg_count NUMBER;
2052 l_msg_data VARCHAR2(2000);
2053
2054 /**********************************
2055 * variable to hold the ignore_for_planning flag of WDD.
2056 * Added for g-log changes
2057 **********************************/
2058
2059
2060 l_ignore_for_planning wsh_delivery_details.ignore_for_planning%type;
2061 l_tms_interface_flag wsh_new_deliveries.TMS_INTERFACE_FLAG%TYPE;
2062
2063
2064 cursor delivery_for_trip is
2065 select distinct delivery_id
2066 from WMS_SHIPPING_TRANSACTION_TEMP
2067 where organization_id = p_organization_id
2068 and dock_door_id = p_dock_door_id
2069 and trip_id = p_trip_id
2070 AND nvl(direct_ship_flag,'N')='N';
2071
2072 cursor delivery_for_dock is
2073 select distinct delivery_id
2074 from WMS_SHIPPING_TRANSACTION_TEMP
2075 where organization_id = p_organization_id
2076 and dock_door_id = p_dock_door_id
2077 and dock_appoint_flag = 'N'
2078 AND nvl(direct_ship_flag,'N')='N';
2079
2080 CURSOR c_get_otm_flags IS
2081 SELECT ignore_for_planning, tms_interface_flag
2082 FROM wsh_new_deliveries_ob_grp_v
2083 WHERE delivery_id = l_delivery_id;
2084
2085 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2086 l_debug number;
2087
2088 l_delivery_type VARCHAR2(30); -- MDC : 5239774
2089 BEGIN
2090 IF g_debug IS NULL THEN
2091 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2092 END IF;
2093 l_debug := g_debug;
2094
2095 x_error_code := 0;
2096
2097 IF (l_debug = 1) THEN
2098 DEbug('Entered LPN CHECK ....with ','LPN_CHECK');
2099 DEbug('p_trip_id : ' || p_trip_id , 'LPN_CHECK');
2100 DEbug('p_dock_door_id: ' || p_dock_door_id, 'LPN_CHECK');
2101 DEbug('p_outermost_lpn_id: ' || p_outermost_lpn_id, 'LPN_CHECK');
2102 DEbug('p_delivery_id: ' || p_delivery_id, 'LPN_CHECK');
2103 DEbug('p_rfid_call : ' || p_rfid_call , 'LPN_CHECK');
2104 END IF;
2105 IF p_rfid_call = 'N' then
2106 -- check if there is anything loaded
2107 if (p_trip_id = 0) then l_dock_appoint_flag := 'N';
2108 else l_dock_appoint_flag := 'Y'; end if;
2109
2110 if (is_loaded(p_organization_id,p_dock_door_id,l_dock_appoint_flag) = 'N') then
2111 x_error_code := 5;
2112 return;
2113 end if;
2114 ELSE
2115 IF (l_debug = 1) THEN
2116 DEbug('No Check of Dock-appointment for RFID','LPN_CHECK');
2117 END IF;
2118 END IF;
2119
2120 -- check missing item first
2121 IF (l_debug = 1) THEN
2122 DEbug('Checking missing items','LPN_CHECK');
2123 END IF;
2124 MISSING_ITEM_CHECK( x_missing_item,
2125 p_trip_id,
2126 p_dock_door_id,
2127 p_organization_id,
2128 l_missing_exists);
2129 if (l_missing_exists > 0) then
2130 x_error_code := 1;
2131 return;
2132 end if;
2133
2134 -- check missing LPNs
2135 IF (l_debug = 1) THEN
2136 DEbug('Checking missing LPNs','LPN_CHECK');
2137 END IF;
2138 MISSING_LPN_CHECK( x_missing_lpns,
2139 p_trip_id,
2140 p_dock_door_id,
2141 p_organization_id,
2142 l_missing_exists);
2143 IF (l_debug = 1) THEN
2144 DEbug('l_missing_exists: ' || l_missing_exists,'LPN_CHECK');
2145 end if;
2146 if (l_missing_exists > 0) then
2147 x_error_code := 2;
2148 return;
2149 end if;
2150
2151 -- check ship set
2152 SHIP_SET_CHECK(p_trip_id,
2153 p_dock_door_id,
2154 p_organization_id,
2155 x_ship_set,
2156 l_return_status,
2157 l_error_msg);
2158 IF (l_debug = 1) THEN
2159 DEbug('x_ship_set: ' || x_ship_set,'LPN_CHECK');
2160 DEbug('l_return_status: ' || l_return_status,'LPN_CHECK');
2161 DEbug('l_error_msg: ' || l_error_msg,'LPN_CHECK');
2162 end if;
2163 if l_return_status = 'E' then
2164 x_error_code := 3;
2165 -- return;
2166 end if;
2167
2168
2169 -- Locked the record first to avoid conccurent process error
2170
2171 BEGIN
2172 if p_trip_id >0 then
2173 select 1
2174 into temp_val
2175 from WMS_SHIPPING_TRANSACTION_TEMP
2176 where organization_id = p_organization_id
2177 and dock_door_id = p_dock_door_id
2178 and trip_id = p_trip_id
2179 and rownum = 1
2180 for update NOWAIT;
2181 else
2182 select 1
2183 into temp_val
2184 from WMS_SHIPPING_TRANSACTION_TEMP
2185 where organization_id = p_organization_id
2186 and dock_door_id = p_dock_door_id
2187 and dock_appoint_flag = 'N'
2188 and rownum = 1
2189 for update NOWAIT;
2190 end if;
2191 EXCEPTION WHEN others THEN
2192 x_error_code := 6;
2193 return;
2194 END;
2195 IF (l_debug = 1) THEN
2196 DEbug('temp_val: ' || temp_val,'LPN_CHECK');
2197 end if;
2198
2199 -- create delviery for LPNs without delivery
2200 l_return_status := 'S';
2201 if p_trip_id = 0 then
2202 CREATE_DELIVERY(p_outermost_lpn_id,
2203 p_trip_id,
2204 p_organization_id,
2205 p_dock_door_id,
2206 l_delivery_id,
2207 l_return_status,
2208 l_error_msg);
2209 if ( l_return_status <> 'S') then
2210 x_error_code := 4;
2211 return;
2212 end if;
2213 IF (l_debug = 1) THEN
2214 DEbug('l_delivery_id: ' || l_delivery_id,'LPN_CHECK');
2215 DEbug('l_return_status: ' || l_return_status,'LPN_CHECK');
2216 DEbug('l_error_msg: ' || l_error_msg,'LPN_CHECK');
2217 end if;
2218
2219
2220 --Add G-log code here -START
2221 IF l_delivery_id > 0 AND WSH_UTIL_CORE.GC3_IS_INSTALLED = 'Y' THEN
2222 IF (l_debug = 1) THEN
2223 debug('G-Log Changes: G-Log installed', 'LPN_CHECK');
2224 END IF;
2225
2226
2227 OPEN c_get_otm_flags;
2228 FETCH c_get_otm_flags INTO l_ignore_for_planning, l_tms_interface_flag ;
2229
2230 IF (c_get_otm_flags%NOTFOUND) THEN
2231 IF (l_debug = 1) THEN
2232 debug('No WDDs found for the delivery created ', 'LPN_CHECK');
2233 END IF;
2234 END IF;
2235 CLOSE c_get_otm_flags;
2236
2237 --Important Note: Irrespective of the severity level of 'CR' exception for the delivery just
2238 --created, we have to mark the delivery to ignore_for_planning so that the
2239 --transaction goes through fine.
2240 -- Hence there is no call to WSH_INTERFACE_EXT_GRP.OTM_PRE_SHIP_CONFIRM().
2241 -- Here delivery was created in the backend for the line that the use
2242 -- chose to ship confirm. it IS ALL happening in the backend.
2243
2244
2245 IF l_ignore_for_planning = 'N' AND l_tms_interface_flag = 'CR' THEN
2246 IF (l_debug = 1) THEN
2247 debug('ignore_for_planning of WDD is N ', 'LPN_CHECK');
2248 END IF;
2249 l_delivery_id_tab(1) := l_delivery_id;
2250 l_action_prms.caller := 'WMS_LPNSHP';
2251 l_action_prms.event := wsh_interface_ext_grp.g_start_of_shipping;
2252 l_action_prms.action_code := 'IGNORE_PLAN';
2253 wsh_interface_ext_grp.delivery_action
2254 (p_api_version_number => 1.0,
2255 p_init_msg_list => fnd_api.g_false,
2256 p_commit => fnd_api.g_false,
2257 p_action_prms => l_action_prms,
2258 p_delivery_id_tab => l_delivery_id_tab,
2259 x_delivery_out_rec => l_delivery_out_rec,
2260 x_return_status => l_return_status,
2261 x_msg_count => l_msg_count,
2262 x_msg_data => l_msg_data);
2263
2264 IF (l_debug = 1) THEN
2265 debug('Called wsh_interface_ext_grp.delivery_action with action_code IGNORE_PLAN and return status: ' || l_return_status, 'LPN_CHECK');
2266 END IF;
2267 IF l_return_status = fnd_api.g_ret_sts_error THEN
2268 x_error_code := 7;
2269 return;
2270 END IF;
2271 END IF;
2272 END IF;
2273 --Add G-log code here -END
2274
2275 end if;
2276
2277 l_delivery_type := NULL;
2278 if p_delivery_id >0 then
2279
2280 /* Bug: 5239774 : If p_delivery_id is a Consolidation_delivery (MDC)
2281 * then, we should not use this as the first delivery displayed
2282 * on ship confirm page . We will use the one returned from
2283 * create_delvery API for the LastLPN*/
2284 SELECT wnd.delivery_type
2285 INTO l_delivery_type
2286 FROM wsh_new_deliveries_ob_grp_v wnd
2287 WHERE wnd.delivery_id = p_delivery_id;
2288
2289 IF l_delivery_type = 'CONSOLIDATION' THEN
2290 NULL ; --we will pick up the first delivery of the outermost LPN
2291 ELSE
2292 l_delivery_id := p_delivery_id;
2293 END IF;
2294 IF (l_debug = 1) THEN
2295 Debug('l_delivery_type: ' || l_delivery_type,'LPN_CHECK');
2296 Debug('l_delivery_id: ' || l_delivery_id,'LPN_CHECK');
2297 END IF;
2298 elsif p_outermost_lpn_id = 0 then
2299 if p_trip_id >0 then
2300 open delivery_for_trip;
2301 fetch delivery_for_trip into l_delivery_id;
2302 close delivery_for_trip;
2303 else
2304 open delivery_for_dock;
2305 fetch delivery_for_dock into l_delivery_id;
2306 close delivery_for_dock;
2307 end if;
2308 end if;
2309 IF (l_debug = 1) THEN
2310 DEbug('l_delivery_id: ' || l_delivery_id,'LPN_CHECK');
2311 end if;
2312
2313
2314 x_deli_count := 0;
2315 if p_trip_id >0 then
2316 select count(distinct delivery_id)
2317 into x_deli_count
2318 from WMS_SHIPPING_TRANSACTION_TEMP
2319 where organization_id = p_organization_id
2320 and dock_door_id = p_dock_door_id
2321 and trip_id = p_trip_id
2322 AND nvl(direct_ship_flag,'N')='N';
2323 else
2324 select count(distinct delivery_id)
2325 into x_deli_count
2326 from WMS_SHIPPING_TRANSACTION_TEMP
2327 where organization_id = p_organization_id
2328 and dock_door_id = p_dock_door_id
2329 and dock_appoint_flag = 'N'
2330 AND nvl(direct_ship_flag,'N')='N';
2331 end if;
2332 IF (l_debug = 1) THEN
2333 DEbug('l_delivery_id: ' || l_delivery_id,'LPN_CHECK');
2334 DEbug('x_deli_count: ' || x_deli_count,'LPN_CHECK');
2335 end if;
2336
2337
2338 -- Query the delivery
2339 get_delivery_info(x_delivery_info,
2340 l_delivery_id);
2341 EXCEPTION
2342 WHEN OTHERS THEN
2343 x_error_code := 9999;
2344 END CHECK_LPN_DELIVERIES;
2345
2346
2347
2348
2349 PROCEDURE CREATE_DELIVERY(p_outermost_lpn_id IN NUMBER,
2350 p_trip_id IN NUMBER,
2351 p_organization_id IN NUMBER,
2352 p_dock_door_id IN NUMBER,
2353 x_delivery_id OUT NOCOPY NUMBER,
2354 x_return_status OUT NOCOPY VARCHAR2,
2355 x_message OUT NOCOPY VARCHAR2,
2356 p_direct_ship_flag IN VARCHAR2 DEFAULT 'N') IS
2357
2358 cursor delivery_details is
2359 select delivery_detail_id,OUTERMOST_LPN_ID
2360 from WMS_SHIPPING_TRANSACTION_TEMP
2361 where organization_id = p_organization_id
2362 and dock_door_id = p_dock_door_id
2363 and dock_appoint_flag = 'N'
2364 and delivery_id is null
2365 and nvl(direct_ship_flag,'N') = p_direct_ship_flag
2366 ORDER BY OUTERMOST_LPN_ID;
2367
2368 cursor delivery_for_lpn(p_lpn_id NUMBER) is
2369 select distinct delivery_id
2370 from WMS_SHIPPING_TRANSACTION_TEMP
2371 where outermost_lpn_id = p_lpn_id;
2372
2373 cursor open_deliveries_cur is
2374 select DISTINCT WSTT.delivery_id
2375 from WMS_SHIPPING_TRANSACTION_TEMP wstt
2376 ,wsh_new_deliveries_ob_grp_v wnd
2377 where wstt.delivery_id = wnd.delivery_id
2378 AND wnd.status_code ='OP'
2379 AND WSTT.organization_id = p_organization_id
2380 and WSTT.dock_door_id = p_dock_door_id
2381 and wstt.dock_appoint_flag = 'N'
2382 and nvl(wstt.direct_ship_flag,'N') = 'Y';
2383
2384 l_open_deliveries_cur open_deliveries_cur%ROWTYPE;
2385 k NUMBER:=0;
2386
2387 l_delivery_id NUMBER;
2388 l_delivery_name VARCHAR2(30);
2389 l_delivery_detail_id NUMBER;
2390 l_del_rows WSH_UTIL_CORE.ID_TAB_TYPE;
2391 l_delivery_ids WSH_UTIL_CORE.ID_TAB_TYPE;
2392 l_open_del_ids WSH_UTIL_CORE.ID_TAB_TYPE;
2393 l_new_del_id WSH_UTIL_CORE.ID_TAB_TYPE;
2394 l_del_detail_id WSH_DELIVERY_DETAILS_PUB.ID_TAB_TYPE;
2395 l_return_Status VARCHAR2(1);
2396 l_grouping_rows WSH_UTIL_CORE.ID_TAB_TYPE;
2397 l_del_index NUMBER;
2398 l_del_count NUMBER;
2399 l_msg_count NUMBER;
2400 l_msg_data VARCHAR2(2000);
2401 l_previous_lpn_id NUMBER;
2402 l_outermost_lpn_id NUMBER;
2403
2404 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2405 l_debug number;
2406 BEGIN
2407 IF g_debug IS NULL THEN
2408 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2409 END IF;
2410 l_debug := g_debug;
2411
2412 x_return_status:= 'S';
2413 IF (l_debug = 1) THEN
2414 debug( 'Entering Create_Delivery ' , 'Create_Delivery');
2415 debug( 'p_outermost_lpn_id : ' || p_outermost_lpn_id , 'Create_Delivery');
2416 debug( 'p_trip_id : ' || p_trip_id , 'Create_Delivery');
2417 debug( 'p_organization_id : ' || p_organization_id , 'Create_Delivery');
2418 debug( 'p_dock_door_id : ' || p_dock_door_id , 'Create_Delivery');
2419 debug( 'p_direct_ship_flag : ' || p_direct_ship_flag , 'Create_Delivery');
2420 END IF;
2421 open delivery_details;
2422 l_del_index := 1;
2423 LOOP
2424 fetch delivery_details into l_delivery_detail_id,l_outermost_lpn_id;
2425 exit when delivery_details%NOTFOUND;
2426 IF (l_debug = 1) THEN
2427 debug( 'l_delivery_detail_id is ' || l_delivery_detail_id,'Create_Delivery');
2428 END IF;
2429 BEGIN
2430 -- Add the following code in case user created delivery manually from
2431 -- desktop
2432 select wda.delivery_id, wnd.name
2433 into l_delivery_id, l_delivery_name
2434 from wsh_delivery_assignments_v wda, wsh_new_deliveries_ob_grp_v wnd
2435 where wda.delivery_id = wnd.delivery_id
2436 and wda.delivery_detail_id = l_delivery_detail_id;
2437
2438 update wms_shipping_transaction_temp
2439 set delivery_id = l_delivery_id,
2440 delivery_name = l_delivery_name,
2441 last_update_date = SYSDATE,
2442 last_updated_by = FND_GLOBAL.USER_ID
2443 where delivery_detail_id = l_delivery_detail_id;
2444
2445 EXCEPTION
2446 WHEN NO_DATA_FOUND THEN
2447 IF (l_debug = 1) THEN
2448 DEBUG('In no data found '||l_previous_lpn_id,'CREATE_DELIVERY');
2449 END IF;
2450 IF nvl(l_previous_lpn_id,0) <>l_outermost_lpn_id THEN
2451 IF l_previous_lpn_id is null THEN
2452 l_previous_lpn_id := l_outermost_lpn_id;
2453 END IF;
2454 IF (l_debug = 1) THEN
2455 debug('Outermost_LPN has changed. Previous LPN id was '||l_previous_lpn_id,'CREATE_DELIVERY');
2456 DEBUG('Outermost LPN id is '||l_outermost_lpn_id,'CREATE_DELIVERY');
2457 DEBUG('tHE VALUE OD DELIVERY_DETAIL_ID IS '||l_delivery_detail_id,'CREATE_DELIVERY');
2458 END IF;
2459 l_del_rows(l_del_index) := l_delivery_detail_id;
2460 l_del_index := l_del_index + 1;
2461 END IF;
2462 END;
2463 l_previous_lpn_id := l_outermost_lpn_id;
2464 END LOOP;
2465 close delivery_details;
2466
2467 -- commit the update for the delivery
2468 IF p_direct_ship_flag<>'Y' THEN
2469 commit;
2470 END IF;
2471
2472 IF l_del_rows.count >0 THEN
2473 OPEN open_deliveries_cur;
2474 LOOP
2475 FETCH open_deliveries_cur INTO l_open_deliveries_cur;
2476 EXIT WHEN open_deliveries_cur%notfound;
2477 l_open_del_ids(open_deliveries_cur%rowcount) :=l_open_deliveries_cur.delivery_id ;
2478 END LOOP;
2479 CLOSE open_deliveries_cur;
2480 END IF;
2481
2482 if( l_del_rows.COUNT > 0 ) then
2483 IF (l_debug = 1) THEN
2484 debug('The number of open deliveries are '||l_open_del_ids.count,'MOB_SHIP');
2485 END IF;
2486 FOR i IN 1..l_del_rows.COUNT LOOP
2487 FOR j IN 1..l_open_del_ids.count LOOP
2488 l_del_detail_id.DELETE;
2489 l_del_detail_id(1) := l_del_rows(i);
2490 IF (l_debug = 1) THEN
2491 DEBUG('The value of del_row is '||l_del_detail_id(1),'mob_ship');
2492 DEBUG('The value of del_id is '||l_open_del_ids(j),'mob_ship');
2493 END IF;
2494 WSH_DELIVERY_DETAILS_PUB.detail_to_delivery
2495 (p_api_version =>1.0
2496 ,x_return_status =>l_return_status
2497 ,x_msg_count =>l_msg_count
2498 ,x_msg_data =>l_msg_data
2499 ,p_TabOfDelDets => l_del_detail_id
2500 ,p_action =>'ASSIGN'
2501 ,p_delivery_id => l_open_del_ids(j));
2502
2503 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
2504 IF (l_debug = 1) THEN
2505 DEBUG('Found an open delivery satisfying '||l_open_del_ids(j),'MOB_SHIP');
2506 END IF;
2507 EXIT;
2508 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2509 IF (l_debug = 1) THEN
2510 DEBUG('expected error','MOB_SHIP');
2511 END IF;
2512 NULL;
2513 ELSIF l_return_status =FND_API.G_RET_STS_UNEXP_ERROR THEN
2514 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2515 EXIT;
2516 END IF;
2517 END LOOP;
2518 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2519 x_message := l_msg_data;
2520 IF (l_debug = 1) THEN
2521 DEBUG('Failed while assigning the delivery lines to the delivery '||l_del_rows(i)||' - '||l_msg_data,'MOB_SHIP');
2522 END IF;
2523 RETURN;
2524 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2525 k := k+1;
2526 l_new_del_id(k) :=l_del_rows(i);
2527 END IF;
2528 END LOOP;
2529 IF (l_debug = 1) THEN
2530 debug('Calling shipping api to create deliveries.','MOB_SHIP');
2531 END IF;
2532
2533 -- Call Shipping's public API
2534 IF (l_new_del_id.count >0 ) THEN
2535 IF (l_debug = 1) THEN
2536 DEBUG('Calling Auto Create Deliveries - ASSIGNMENT UNSUCCESSFUL','mob_ship');
2537 END IF;
2538
2539 WSH_DELIVERY_DETAILS_PUB.autocreate_deliveries
2540 (p_api_version_number =>1.0
2541 , p_init_msg_list =>FND_API.G_FALSE
2542 , p_commit =>FND_API.G_FALSE
2543 , x_return_status =>l_return_status
2544 , x_msg_count =>l_msg_count
2545 , x_msg_data =>l_msg_data
2546 , p_line_rows =>l_new_del_id
2547 , x_del_rows =>l_delivery_ids);
2548 ELSIF l_open_del_ids.count =0 THEN
2549 IF (l_debug = 1) THEN
2550 DEBUG('cALLING aUTO CREATE DELIVIERIES -No open deliveries','mob_ship');
2551 END IF;
2552 WSH_DELIVERY_DETAILS_PUB.autocreate_deliveries
2553 (p_api_version_number =>1.0
2554 , p_init_msg_list =>FND_API.G_FALSE
2555 , p_commit =>FND_API.G_FALSE
2556 , x_return_status =>l_return_status
2557 , x_msg_count =>l_msg_count
2558 , x_msg_data =>l_msg_data
2559 , p_line_rows =>l_del_rows
2560 , x_del_rows =>l_delivery_ids);
2561 END IF;
2562
2563 x_return_status := l_return_status;
2564
2565 IF( l_return_status = 'W' ) then
2566 IF (l_debug = 1) THEN
2567 debug('Warning from creating deliveries API.','MOB_SHIP');
2568 debug('Warning:'||l_msg_data,'MOB_SHIP');
2569 END IF;
2570
2571 x_message := l_msg_data;
2572 ELSIF ( l_return_status in ('E','U') ) then
2573 IF (l_debug = 1) THEN
2574 debug('Failed from creating deliveries API.','MOB_SHIP');
2575 debug('Error:'||l_msg_data,'MOB_SHIP');
2576 END IF;
2577
2578 x_message := l_msg_data;
2579 return;
2580 END IF;
2581
2582 IF (l_debug = 1) THEN
2583 debug('Updating the temp table','MOB_SHIP');
2584 END IF;
2585
2586 for l_del_count in 1..l_del_rows.COUNT LOOP
2587 select wda.delivery_id, wnd.name
2588 into l_delivery_id, l_delivery_name
2589 from wsh_delivery_assignments_v wda, wsh_new_deliveries_ob_grp_v wnd
2590 where wda.delivery_id = wnd.delivery_id
2591 and wda.delivery_detail_id = l_del_rows(l_del_count);
2592
2593 update wms_shipping_transaction_temp
2594 set delivery_id = l_delivery_id,
2595 delivery_name = l_delivery_name,
2596 last_update_date = SYSDATE,
2597 last_updated_by = FND_GLOBAL.USER_ID
2598 where outermost_lpn_id = (SELECT outermost_lpn_id FROM wms_shipping_transaction_temp
2599 WHERE delivery_detail_id = l_del_rows(l_del_count));
2600 end loop;
2601 end if;
2602
2603 IF (l_debug = 1) THEN
2604 debug('get the delivery for the current LPN','MOB_SHIP');
2605 END IF;
2606
2607 -- get the first delivery for the current lpn
2608 open delivery_for_lpn(p_outermost_lpn_id);
2609 fetch delivery_for_lpn into l_delivery_id;
2610 if delivery_for_lpn%NOTFOUND then l_delivery_id := -1; end if;
2611 close delivery_for_lpn;
2612 x_delivery_id := l_delivery_id;
2613 IF (l_debug = 1) THEN
2614 debug('The delivery is '||to_char(l_delivery_id),'MOB_SHIP');
2615 END IF;
2616
2617 EXCEPTION
2618 When others then
2619 IF (l_debug = 1) THEN
2620 debug('Exception in creating deliveries','MOB_SHIP');
2621 END IF;
2622
2623 x_return_status :='U';
2624
2625 END CREATE_DELIVERY;
2626
2627 PROCEDURE GET_LPN_DELIVERY(x_deliveryLOV OUT NOCOPY t_genref,
2628 p_trip_id IN NUMBER,
2629 p_organization_id IN NUMBER,
2630 p_dock_door_id IN NUMBER,
2631 p_delivery_name IN VARCHAR2) IS
2632 BEGIN
2633 if p_trip_id <> 0 then
2634 OPEN x_deliveryLOV for
2635 SELECT distinct wstt.delivery_name, wnd.delivery_id, wnd.gross_weight, wnd.weight_uom_code,
2636 wnd.waybill,
2637 INV_SHIPPING_TRANSACTION_PUB.GET_SHIPMETHOD_MEANING(wnd.ship_method_code)
2638 FROM wsh_new_deliveries wnd,wms_shipping_transaction_temp wstt
2639 WHERE wnd.delivery_id = wstt.delivery_id
2640 and wstt.trip_id = p_trip_id
2641 and wstt.dock_door_id = p_dock_door_id
2642 and wstt.organization_id = p_organization_id
2643 and nvl(wstt.direct_ship_flag,'N') = 'N'
2644 and wstt.delivery_name like (p_delivery_name)
2645 order by wstt.delivery_name;
2646 else
2647 OPEN x_deliveryLOV for
2648 SELECT distinct wstt.delivery_name, wnd.delivery_id, wnd.gross_weight, wnd.weight_uom_code,
2649 wnd.waybill,
2650 INV_SHIPPING_TRANSACTION_PUB.GET_SHIPMETHOD_MEANING(wnd.ship_method_code)
2651 FROM wsh_new_deliveries wnd,wms_shipping_transaction_temp wstt
2652 WHERE wnd.delivery_id = wstt.delivery_id
2653 and wstt.dock_appoint_flag = 'N'
2654 and nvl(wstt.direct_ship_flag,'N') = 'N'
2655 and wstt.dock_door_id = p_dock_door_id
2656 and wstt.organization_id = p_organization_id
2657 and wstt.delivery_name like (p_delivery_name)
2658 order by wstt.delivery_name;
2659 end if;
2660 END GET_LPN_DELIVERY;
2661
2662 PROCEDURE update_trip(p_delivery_id IN NUMBER DEFAULT NULL
2663 ,p_trip_id IN NUMBER DEFAULT NULL
2664 ,p_ship_method_code IN VARCHAR2
2665 ,x_return_status OUT nocopy VARCHAR2
2666 ,x_msg_data OUT nocopy VARCHAR2
2667 ,x_msg_count OUT nocopy number) IS
2668
2669 l_trip_id NUMBER := null;
2670 l_trip_name VARCHAR2(30);
2671 l_trip_info WSH_TRIPS_PUB.Trip_Pub_Rec_Type;
2672 BEGIN
2673 x_return_status := 'S';
2674
2675 debug('p_delivery_id: ' || p_delivery_id
2676 || ' p_trip_id: ' || p_trip_id
2677 || ' p_ship_method_code: ' || p_ship_method_code,'update_trip');
2678
2679 IF p_delivery_id IS NULL AND p_trip_id IS NULL THEN
2680 x_return_status := 'E';
2681
2682 debug('delivery_id and trip_id both null. Need one of them to update a trip','update_trip');
2683
2684 RETURN;
2685 END IF;
2686
2687 IF p_ship_method_code IS NOT NULL THEN
2688 IF p_trip_id IS NULL OR
2689 p_trip_id = 0 THEN
2690 begin
2691 SELECT wts.trip_id
2692 INTO l_trip_id
2693 FROM wsh_delivery_legs_ob_grp_v wdl,
2694 wsh_trip_stops_ob_grp_v wts
2695 WHERE wdl.delivery_id=p_delivery_id
2696 AND wdl.pick_up_stop_id=wts.stop_id
2697 AND ROWNUM=1;
2698 EXCEPTION
2699 WHEN no_data_found THEN
2700 debug('Cannot find trip to update','update_trip');
2701
2702 x_return_status := 'E';
2703 RETURN;
2704 END;
2705 ELSE
2706 l_trip_id := p_trip_id;
2707 END IF;
2708
2709 debug('Trip id to be updated: ' || l_trip_id,'update_trip');
2710 debug('ship method code: ' || p_ship_method_code,'update_trip');
2711 debug('Calling WSH_TRIPS_PUB.create_update_trip','update_trip');
2712
2713 l_trip_info.trip_id := l_trip_id;
2714 l_trip_info.last_update_date := SYSDATE;
2715 l_trip_info.last_updated_by :=FND_GLOBAL.USER_ID;
2716 l_trip_info.last_update_login :=FND_GLOBAL.USER_ID;
2717 l_trip_info.ship_method_code :=p_ship_method_code;
2718
2719 WSH_TRIPS_PUB.Create_Update_Trip
2720 (p_api_version_number => 1.0
2721 ,p_init_msg_list => FND_API.G_TRUE
2722 ,x_return_status => x_return_status
2723 ,x_msg_count => x_msg_count
2724 ,x_msg_data => x_msg_data
2725 ,p_action_code => 'UPDATE'
2726 ,p_trip_info => l_trip_info
2727 ,x_trip_id => l_trip_id
2728 ,x_trip_name => l_trip_name);
2729
2730 debug('return status from WSH_TRIPS_PUB.create_update_trip: ' || x_return_status,'update_trip');
2731
2732 IF x_return_status NOT IN ('S','W') THEN
2733 debug('Shipping msg count: ' || x_msg_count,'update_trip');
2734 debug('Shipping error msg: ' || x_msg_data,'update_trip');
2735 ELSE
2736 debug('Committing change','update_trip');
2737 COMMIT;
2738 END IF;
2739 END IF;
2740 EXCEPTION
2741 WHEN OTHERS THEN
2742 debug('Other exceptions raised!','update_trip');
2743 debug('SQLERRM: ' || SQLERRM,'update_trip');
2744 x_return_status := 'U';
2745 END update_trip;
2746
2747 --patchset J. Shipping API cleanup
2748 --previously, this procedure updated shipping table directly
2749 --For Ship Method, this procedure will first determine if the delivery belongs to a trip
2750 --If it does:
2751 -- 1. Determine if ship method = ship method on trip
2752 -- 2. Update trip's ship method if it was null before
2753 -- 3. Return 'W' as return status if trip's ship method different from one passed in
2754 PROCEDURE UPDATE_DELIVERY(p_delivery_id IN NUMBER,
2755 p_gross_weight IN NUMBER,
2756 p_weight_uom IN VARCHAR2,
2757 p_waybill IN VARCHAR2,
2758 p_bol IN VARCHAR2,
2759 p_ship_method_code IN VARCHAR2,
2760 x_return_status OUT NOCOPY VARCHAR2) IS
2761
2762 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2763 l_debug number;
2764
2765 l_delivery_info wsh_deliveries_pub.delivery_pub_rec_type;
2766 l_delivery_id NUMBER;
2767 l_delivery_name VARCHAR2(30);
2768
2769 l_trip_id NUMBER := null;
2770 l_trip_ship_method_code VARCHAR2(30) := null;
2771 l_trip_name VARCHAR2(30);
2772 l_trip_info WSH_TRIPS_PUB.Trip_Pub_Rec_Type;
2773
2774 l_msg_count NUMBER;
2775 l_msg_data VARCHAR2(2000);
2776 l_summary_buffer VARCHAR2(2000);
2777
2778 l_ignore_for_planning wsh_delivery_details.ignore_for_planning%TYPE;
2779 l_tms_interface_flag wsh_new_deliveries.TMS_INTERFACE_FLAG%TYPE;
2780
2781 CURSOR c_get_otm_flags is
2782 SELECT ignore_for_planning, tms_interface_flag
2783 FROM wsh_new_deliveries_ob_grp_v
2784 WHERE delivery_id = p_delivery_id;
2785
2786
2787
2788 BEGIN
2789 IF g_debug IS NULL THEN
2790 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2791 END IF;
2792 l_debug := g_debug;
2793
2794 IF l_debug = 1 THEN
2795 debug('Inside update_delivery','UPDATE_DELIVERY');
2796 END IF;
2797
2798 x_return_status := 'S';
2799
2800 IF p_gross_weight IS NOT NULL then
2801 l_delivery_info.gross_weight := p_gross_weight;
2802 END IF;
2803
2804 IF p_weight_uom IS NOT NULL then
2805 l_delivery_info.weight_uom_code := p_weight_uom;
2806 END IF;
2807
2808 IF p_waybill IS NOT NULL then
2809 l_delivery_info.waybill := p_waybill;
2810 END IF;
2811
2812
2813 /* G-LOG integration Starts
2814 * Cases where G-LOG is installed, and the delivery is planned,
2815 * We cannot update the ship method.
2816 * For non-G-LOG cases also,
2817 * We need not pass the new ship method to this API for an UPDATE,
2818 * instead we will pass it to the ship confirm API and that will take care of
2819 * updating it at all levels, as the case may be.
2820 * BUT, we need to update it at delivery level for LPN Ship, where
2821 * API: SHIP_CONFIRM_LPN_DELIVERIES depends on the delivery level shipmenthod
2822 */
2823
2824 IF wsh_util_core.gc3_is_installed = 'Y' THEN
2825 IF (l_debug = 1) THEN
2826 debug('G-Log Changes: G-Log installed', 'update_delivery');
2827 END IF;
2828
2829 OPEN c_get_otm_flags;
2830 FETCH c_get_otm_flags INTO l_ignore_for_planning, l_tms_interface_flag ;
2831
2832 IF (c_get_otm_flags%NOTFOUND) THEN
2833 IF (l_debug = 1) THEN
2834 debug('No WDDs found for the delivery created ', 'update_delivery');
2835 END IF;
2836 END IF;
2837
2838 CLOSE c_get_otm_flags;
2839
2840 END IF ;
2841 IF (l_debug = 1) THEN
2842 debug('l_ignore_for_planning : ' || l_ignore_for_planning, 'update_delivery');
2843 debug('l_tms_interface_flag : ' || l_tms_interface_flag, 'update_delivery');
2844 END IF;
2845
2846 IF l_ignore_for_planning IS NULL OR l_ignore_for_planning = 'Y' THEN
2847 l_delivery_info.ship_method_code := p_ship_method_code;
2848 l_delivery_info.ship_method_name := p_ship_method_code;
2849 END IF;
2850
2851 IF l_debug = 1 THEN
2852 debug('l_delivery_info.ship_method_code ' || l_delivery_info.ship_method_code,'UPDATE_DELIVERY');
2853 debug('l_delivery_info.ship_method_name ' || l_delivery_info.ship_method_name,'UPDATE_DELIVERY');
2854 END IF;
2855
2856 /* G-LOG integration Starts Ends */
2857
2858
2859 IF p_ship_method_code IS NOT NULL then
2860 BEGIN
2861
2862 SELECT wts.trip_id,wt.ship_method_code
2863 INTO l_trip_id,l_trip_ship_method_code
2864 FROM wsh_delivery_legs_ob_grp_v wdl,
2865 wsh_trip_stops_ob_grp_v wts,
2866 wsh_trips_ob_grp_v wt
2867 WHERE wdl.delivery_id=p_delivery_id
2868 AND wdl.pick_up_stop_id=wts.stop_id
2869 AND wt.trip_id=wts.trip_id
2870 AND ROWNUM=1;
2871 EXCEPTION
2872 WHEN no_data_found THEN
2873 IF l_debug = 1 THEN
2874 debug('Delivery does not belong to any trip','UPDATE_DELIVERY');
2875 END IF;
2876 END;
2877 END IF;
2878
2879 l_delivery_info.delivery_id := p_delivery_id;
2880
2881 IF (l_debug=1) THEN
2882 debug('About to call wsh_deliveries_pub.create_update_delivery with'
2883 || ' gross_weight: ' || l_delivery_info.gross_weight
2884 || ' waybill : ' || l_delivery_info.waybill
2885 || ' ship method code: ' || l_delivery_info.ship_method_code
2886 || ' weight uom code: ' || l_delivery_info.weight_uom_code
2887 || ' delivery ID: ' || l_delivery_info.delivery_id, 'UPDATE_DELIVERY');
2888 END IF;
2889
2890 wsh_deliveries_pub.create_update_delivery
2891 (p_api_version_number => 1.0,
2892 p_init_msg_list => fnd_api.g_false,
2893 x_return_status => x_return_status,
2894 x_msg_count => l_msg_count,
2895 x_msg_data => l_msg_data,
2896 p_action_code => 'UPDATE',
2897 p_delivery_info => l_delivery_info,
2898 x_delivery_id => l_delivery_id,
2899 x_name => l_delivery_name);
2900
2901 IF l_debug = 1 then
2902 debug('return_status from WSH_DELIVERIES_PUB.create_update_delivery: '
2903 || x_return_status,'UPDATE_DELIVERY');
2904 END IF;
2905
2906
2907 IF x_return_status IN ('E','U') THEN
2908 --no need to proceed to update trip if update to delivery failed
2909 RETURN;
2910 ELSE
2911 -- commit for each delivery, so that we will not lose any data
2912 debug('commiting...','UPDATE_DELIVERY');
2913 commit;
2914 END IF;
2915
2916 --delivery belongs to a trip. see if we can propagate the ship method
2917 IF l_trip_id IS NOT NULL THEN
2918 debug('Delivery belongs to trip: ' || l_trip_id
2919 || ' trip ship method: ' || l_trip_ship_method_code,'UPDATE_DELIVERY');
2920
2921
2922 IF l_trip_ship_method_code IS NULL THEN
2923 debug('Calling update_trip','UPDATE_DELIVERY');
2924
2925 update_trip(p_trip_id => l_trip_id
2926 ,p_ship_method_code => p_ship_method_code
2927 ,x_return_status => x_return_status
2928 ,x_msg_count => l_msg_count
2929 ,x_msg_data => l_msg_data);
2930
2931 debug('return status from update_trip: ' || x_return_status,'UPDATE_DELIVERY');
2932
2933 IF x_return_status NOT IN ('S','W') THEN
2934 debug('Shipping msg count: ' || l_msg_count,'UPDATE_DELIVERY');
2935 debug('Shipping error msg: ' || l_msg_data,'UPDATE_DELIVERY');
2936 END IF;
2937
2938 ELSIF l_trip_ship_method_code <> p_ship_method_code THEN
2939 x_return_status := 'W';
2940 debug('Dlvy belong to trip with different ship method.'
2941 || ' Returning W so user can be prompted if necessary.','UPDATE_DELIVERY');
2942 END IF;
2943 END IF;
2944
2945
2946 EXCEPTION
2947 WHEN others THEN
2948 x_return_status := 'E';
2949 END UPDATE_DELIVERY;
2950 --\Shipping API cleanup
2951
2952 PROCEDURE GET_MISSING_LPN_LOV(x_lpn_lov out NOCOPY t_genref,
2953 p_organization_id IN NUMBER,
2954 p_dock_door_id IN NUMBER,
2955 p_trip_id IN NUMBER,
2956 p_lpn IN VARCHAR2) IS
2957
2958 BEGIN
2959 if (p_trip_id <> 0 ) then
2960 open x_lpn_lov for
2961 select DISTINCT wlpn.license_plate_number,
2962 lpn.subinventory_code,
2963 milk.concatenated_segments,
2964 wnd.name
2965 from wms_license_plate_numbers lpn, mtl_item_locations_kfv milk,wsh_trip_stops_ob_grp_v pickup_stop,
2966 wsh_delivery_legs_ob_grp_v wdl,wsh_delivery_assignments_v wda,wsh_delivery_details_ob_grp_v wdd,
2967 wsh_delivery_details_ob_grp_v wdd2,wsh_new_deliveries_ob_grp_v wnd,wms_license_plate_numbers wlpn
2968 where wdd.delivery_detail_id = wda.delivery_detail_id
2969 and wdd.released_status = 'Y'
2970 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
2971 and wda.delivery_id = wdl.delivery_id
2972 and wdl.delivery_id = wnd.delivery_id
2973 and wdl.pick_up_stop_id = pickup_stop.stop_id
2974 and pickup_stop.trip_id = p_trip_id
2975 and lpn.lpn_id = wdd2.lpn_id
2976 and lpn.outermost_lpn_id = wlpn.lpn_id
2977 and wlpn.lpn_context <> wms_globals.lpn_loaded_for_shipment
2978 and lpn.locator_id = milk.inventory_location_id
2979 and lpn.organization_id = milk.organization_id
2980 and wlpn.license_plate_number like (p_lpn)
2981 order by wlpn.license_plate_number;
2982 else
2983 open x_lpn_lov for
2984 select DISTINCT wlpn.license_plate_number,
2985 lpn.subinventory_code,
2986 milk.concatenated_segments,
2987 wnd.name
2988 from wms_license_plate_numbers lpn, mtl_item_locations_kfv milk,
2989 wsh_delivery_assignments_v wda,wsh_delivery_details_ob_grp_v wdd,
2990 wsh_delivery_details_ob_grp_v wdd2,wsh_new_deliveries_ob_grp_v wnd,wms_license_plate_numbers wlpn
2991 where wdd.delivery_detail_id = wda.delivery_detail_id
2992 and wdd.released_status = 'Y'
2993 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
2994 and wda.delivery_id in ( select distinct delivery_id
2995 from wms_shipping_transaction_temp
2996 where organization_id = p_organization_id
2997 and dock_appoint_flag = 'N'
2998 and dock_door_id = p_dock_door_id
2999 and delivery_id is not null
3000 UNION
3001 select distinct wdl.delivery_id
3002 from wsh_delivery_legs_ob_grp_v wdl,wms_shipping_transaction_temp wstt,
3003 wsh_trip_stops_ob_grp_v wts
3004 where wdl.pick_up_stop_id = wts.stop_id
3005 and wts.trip_id = wstt.trip_id
3006 and wstt.dock_door_id = p_dock_door_id
3007 and wstt.organization_id = p_organization_id
3008 and wstt.dock_appoint_flag = 'N' )
3009 and wda.delivery_id = wnd.delivery_id
3010 and lpn.lpn_id = wdd2.lpn_id
3011 and lpn.outermost_lpn_id = wlpn.lpn_id
3012 and wlpn.lpn_context <> wms_globals.lpn_loaded_for_shipment
3013 and lpn.locator_id = milk.inventory_location_id
3014 and lpn.organization_id = milk.organization_id
3015 and wlpn.license_plate_number like (p_lpn)
3016 order by wlpn.license_plate_number;
3017 end if;
3018 END GET_MISSING_LPN_LOV;
3019
3020 PROCEDURE MISSING_LPN_CHECK(x_missing_lpns OUT NOCOPY t_genref,
3021 p_trip_id IN NUMBER,
3022 p_dock_door_id IN NUMBER,
3023 p_organization_id IN NUMBER,
3024 x_missing_count OUT NOCOPY NUMBER) IS
3025 l_count NUMBER;
3026 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3027 l_debug number;
3028 BEGIN
3029 IF g_debug IS NULL THEN
3030 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3031 END IF;
3032 l_debug := g_debug;
3033
3034 IF (l_debug = 1) THEN
3035 Debug( 'in missing lpn_check', 'MISSING_LPN_CHECK');
3036 Debug( 'p_trip_id is ' || p_trip_id, 'MISSING_LPN_CHECK');
3037 Debug( 'p_dock_door_id is ' || p_dock_door_id, 'MISSING_LPN_CHECK');
3038 Debug( 'p_organization_id is ' || p_organization_id, 'MISSING_LPN_CHECK');
3039 END IF;
3040 x_missing_count := 0;
3041 l_count := 0;
3042 if (p_trip_id <> 0) then
3043 BEGIN
3044 select count(distinct lpn.outermost_lpn_id)
3045 into l_count
3046 from wsh_trip_stops_ob_grp_v pickup_stop
3047 ,wsh_delivery_legs_ob_grp_v wdl
3048 ,wsh_delivery_assignments_v wda
3049 ,wsh_delivery_details_ob_grp_v wdd
3050 ,wsh_delivery_details_ob_grp_v wdd2
3051 ,wms_license_plate_numbers lpn
3052 ,wms_license_plate_numbers wlpn
3053 -- 5582189 dherring added table in from clause so that
3054 -- the status code can be checked
3055 ,wsh_new_deliveries_ob_grp_v wnd
3056 Where pickup_stop.trip_id = p_trip_id
3057 and wdl.pick_up_stop_id = pickup_stop.stop_id
3058 and wda.delivery_id = wdl.delivery_id
3059 and wdd.delivery_detail_id = wda.delivery_detail_id
3060 and wdd.released_status = 'Y'
3061 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
3062 and wdd2.lpn_id = lpn.lpn_id
3063 and lpn.outermost_lpn_id = wlpn.lpn_id
3064 AND wdd.organization_id = p_organization_id
3065 and ( wlpn.lpn_context = wms_container_pvt.lpn_context_picked
3066 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
3067 -- 5582189 dherring changed code to select picked lpns
3068 and wnd.status_code in ('OP', 'PA');
3069 --and wlpn.lpn_context <> 9;
3070 if l_count > 0 then
3071 x_missing_count := l_count;
3072 end if;
3073 EXCEPTION
3074 WHEN NO_DATA_FOUND THEN
3075 open x_missing_lpns FOR select 1 from dual;
3076 return;
3077 END;
3078 open x_missing_lpns FOR
3079 select wlpn.license_plate_number
3080 , wlpn.lpn_id
3081 , wdd.delivery_detail_id
3082 , lpn.subinventory_code
3083 , lpn.locator_id
3084 , milk.concatenated_segments
3085 , wnd.name
3086 from wms_license_plate_numbers lpn
3087 , mtl_item_locations_kfv milk
3088 , wsh_trip_stops_ob_grp_v pickup_stop
3089 , wsh_delivery_legs_ob_grp_v wdl
3090 , wsh_delivery_assignments_v wda
3091 , wsh_delivery_details_ob_grp_v wdd
3092 , wsh_delivery_details_ob_grp_v wdd2
3093 , wsh_new_deliveries_ob_grp_v wnd
3094 , wms_license_plate_numbers wlpn
3095 where wdd.delivery_detail_id = wda.delivery_detail_id
3096 and wdd.released_status = 'Y'
3097 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
3098 and wda.delivery_id = wdl.delivery_id
3099 and wdl.delivery_id = wnd.delivery_id
3100 and wdl.pick_up_stop_id = pickup_stop.stop_id
3101 and pickup_stop.trip_id = p_trip_id
3102 and lpn.lpn_id = wdd2.lpn_id
3103 and lpn.outermost_lpn_id = wlpn.lpn_id
3104 and ( wlpn.lpn_context = wms_container_pvt.lpn_context_picked
3105 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
3106 --and wlpn.lpn_context <> 9
3107 -- 5582189 dherring changed code to select picked lpns
3108 and wnd.status_code in ('OP', 'PA')
3109 and lpn.locator_id = milk.inventory_location_id
3110 AND wdd.organization_id = p_organization_id
3111 and lpn.organization_id = milk.organization_id;
3112 else
3113 BEGIN
3114 select count(distinct lpn.outermost_lpn_id)
3115 into l_count
3116 from wsh_delivery_assignments_v wda
3117 ,wsh_new_deliveries_ob_grp_v wnd
3118 ,wsh_delivery_details_ob_grp_v wdd
3119 ,wsh_delivery_details_ob_grp_v wdd2
3120 ,wms_license_plate_numbers lpn
3121 ,wms_license_plate_numbers wlpn
3122 where
3123 wdd.delivery_detail_id = wda.delivery_detail_id
3124 and wdd.released_status = 'Y'
3125 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
3126 and wda.delivery_id in ( select distinct delivery_id
3127 from wms_shipping_transaction_temp
3128 where organization_id = p_organization_id
3129 and dock_appoint_flag = 'N'
3130 and dock_door_id = p_dock_door_id
3131 and delivery_id is not null
3132 UNION
3133 select distinct wdl.delivery_id
3134 from wsh_delivery_legs_ob_grp_v wdl
3135 ,wms_shipping_transaction_temp wstt
3136 ,wsh_trip_stops_ob_grp_v wts
3137 where wdl.pick_up_stop_id = wts.stop_id
3138 and wts.trip_id = wstt.trip_id
3139 and wstt.dock_door_id = p_dock_door_id
3140 and wstt.organization_id = p_organization_id
3141 and wstt.dock_appoint_flag = 'N')
3142 and wdd2.lpn_id = lpn.lpn_id
3143 and wlpn.lpn_id = lpn.outermost_lpn_id
3144 AND wdd.organization_id = p_organization_id
3145 and ( wlpn.lpn_context =
3146 wms_container_pvt.lpn_context_picked
3147 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
3148 -- 5582189 dherring changed code to select picked lpns
3149 and wda.delivery_id = wnd.delivery_id
3150 and wnd.status_code in ('OP', 'PA');
3151 --and wlpn.lpn_context <> 9;
3152 if l_count > 0 then
3153 x_missing_count := l_count;
3154 end if;
3155 EXCEPTION
3156 WHEN NO_DATA_FOUND THEN
3157 open x_missing_lpns FOR select 1 from dual;
3158 return;
3159 END;
3160
3161
3162 open x_missing_lpns FOR
3163 select wlpn.license_plate_number
3164 , wlpn.lpn_id
3165 , wdd.delivery_detail_id
3166 , lpn.subinventory_code
3167 , lpn.locator_id
3168 , milk.concatenated_segments
3169 , wnd.name
3170 from wms_license_plate_numbers lpn
3171 , mtl_item_locations_kfv milk
3172 , wsh_delivery_assignments_v wda
3173 , wsh_delivery_details_ob_grp_v wdd
3174 , wsh_delivery_details_ob_grp_v wdd2
3175 , wsh_new_deliveries_ob_grp_v wnd
3176 , wms_license_plate_numbers wlpn
3177 where wdd.delivery_detail_id = wda.delivery_detail_id
3178 and wdd.released_status = 'Y'
3179 and wdd2.delivery_detail_id = wda.parent_delivery_detail_id
3180 and wda.delivery_id in ( select distinct delivery_id
3181 from wms_shipping_transaction_temp
3182 where organization_id = p_organization_id
3183 and dock_appoint_flag = 'N'
3184 and nvl(direct_ship_flag,'N') = 'N'
3185 and dock_door_id = p_dock_door_id
3186 and delivery_id is not null
3187 UNION
3188 select distinct wdl.delivery_id
3189 from wsh_delivery_legs_ob_grp_v wdl
3190 ,wms_shipping_transaction_temp wstt
3191 ,wsh_trip_stops_ob_grp_v wts
3192 where wdl.pick_up_stop_id = wts.stop_id
3193 and wts.trip_id = wstt.trip_id
3194 and wstt.dock_door_id = p_dock_door_id
3195 and wstt.organization_id = p_organization_id
3196 and wstt.dock_appoint_flag = 'N'
3197 and nvl(direct_ship_flag,'N') = 'N')
3198 and wda.delivery_id = wnd.delivery_id
3199 and lpn.lpn_id = wdd2.lpn_id
3200 and lpn.outermost_lpn_id = wlpn.lpn_id
3201 and ( wlpn.lpn_context = wms_container_pvt.lpn_context_picked
3202 OR wlpn.lpn_context = wms_container_pvt.lpn_loaded_in_stage)
3203 --and wlpn.lpn_context <> 9
3204 -- 5582189 dherring changed code to select picked lpns
3205 and wnd.status_code in ('OP', 'PA')
3206 and lpn.locator_id = milk.inventory_location_id
3207 AND wdd.organization_id = p_organization_id
3208 and lpn.organization_id = milk.organization_id;
3209 end if;
3210
3211 END MISSING_LPN_CHECK;
3212
3213 PROCEDURE MISSING_ITEM_CHECK( x_missing_item OUT NOCOPY t_genref,
3214 p_trip_id IN NUMBER,
3215 p_dock_door_id IN NUMBER,
3216 p_organization_id IN NUMBER,
3217 x_missing_count OUT NOCOPY NUMBER) IS
3218 l_count NUMBER;
3219 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3220 l_debug number;
3221 BEGIN
3222 IF g_debug IS NULL THEN
3223 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3224 END IF;
3225 l_debug := g_debug;
3226
3227 IF (l_debug = 1) THEN
3228 Debug( ' in missing_item_check', 'MISSING_ITEM_CHECK');
3229 Debug( 'p_trip_id is ' || p_trip_id, 'MISSING_ITEM_CHECK');
3230 Debug( 'p_dock_door_id is ' || p_dock_door_id, 'MISSING_ITEM_CHECK');
3231 Debug( 'p_organization_id is ' || p_organization_id, 'MISSING_ITEM_CHECK');
3232 END IF;
3233 x_missing_count := 0;
3234 l_count := 0;
3235
3236 if( p_trip_id <> 0 ) then
3237 BEGIN
3238 select count(*)
3239 into l_count
3240 from wsh_delivery_details_ob_grp_v wdd
3241 , wsh_delivery_assignments_v wda
3242 , wsh_delivery_legs_ob_grp_v wdl
3243 , wsh_Trip_stops_ob_grp_v pickup_stop
3244 , mtl_system_items_kfv msik
3245 where
3246 wda.delivery_id = wdl.delivery_id
3247 AND wda.delivery_detail_id = wdd.delivery_detail_id
3248 and wdl.pick_up_stop_id = pickup_stop.stop_id
3249 and pickup_stop.trip_id = p_trip_id
3250 AND wdd.inventory_item_id = msik.inventory_item_id
3251 AND wdd.organization_id = msik.organization_id
3252 AND wdd.organization_id = p_organization_id
3253 and wdd.lpn_id is null
3254 and ((wda.parent_delivery_detail_id is null
3255 AND msik.mtl_transactions_enabled_flag <> 'N')
3256 OR wdd.released_status is null
3257 OR wdd.released_status NOT IN ('X', 'Y'));
3258 if l_count > 0 then
3259 x_missing_count := l_count;
3260 end if;
3261 EXCEPTION
3262 WHEN NO_DATA_FOUND THEN
3263 open x_missing_item FOR select 1 from dual;
3264 return;
3265 END;
3266 open x_missing_item FOR
3267 select wnd.name
3268 ,wdd.delivery_detail_id
3269 , wdd.inventory_item_id
3270 , wdd.requested_quantity
3271 , msik.concatenated_segments
3272 , msik.description
3273 from wsh_delivery_details_ob_grp_v wdd
3274 , wsh_delivery_assignments_v wda
3275 , wsh_new_deliveries_ob_grp_v wnd
3276 , wsh_delivery_legs_ob_grp_v wdl
3277 , wsh_trip_Stops_ob_grp_v pickup_stop
3278 , mtl_system_items_kfv msik
3279 where wnd.delivery_id = wda.delivery_id
3280 AND wda.delivery_id = wdl.delivery_id
3281 AND wda.delivery_detail_id = wdd.delivery_detail_id
3282 and wdl.pick_up_stop_id = pickup_stop.stop_id
3283 and pickup_stop.trip_id = p_trip_id
3284 and wdd.lpn_id is null
3285 and wdd.inventory_item_id = msik.inventory_item_id
3286 AND wdd.organization_id = p_organization_id
3287 and wdd.organization_id = msik.organization_id
3288 and ((wda.parent_delivery_detail_id is null
3289 AND msik.mtl_transactions_enabled_flag <> 'N')
3290 OR wdd.released_status is null
3291 OR wdd.released_status NOT IN ('X', 'Y'));
3292 else
3293 BEGIN
3294 select count(*)
3295 into l_count
3296 from wsh_delivery_details_ob_grp_v wdd
3297 , wsh_delivery_assignments_v wda
3298 , mtl_system_items_kfv msik
3299 where
3300 wda.delivery_detail_id = wdd.delivery_detail_id
3301 and wda.delivery_id in (select distinct delivery_id
3302 from wms_shipping_transaction_temp
3303 where dock_door_id = p_dock_door_id
3304 and organization_id = p_organization_id
3305 and dock_appoint_flag = 'N'
3306 and nvl(direct_ship_flag,'N') = 'N'
3307 and delivery_id is not null
3308 UNION
3309 select distinct wdl.delivery_id
3310 from wsh_delivery_legs_ob_grp_v wdl
3311 ,wms_shipping_transaction_temp wstt
3312 ,wsh_trip_stops_ob_grp_v wts
3313 where wdl.pick_up_stop_id = wts.stop_id
3314 and wts.trip_id = wstt.trip_id
3315 and wstt.dock_door_id = p_dock_door_id
3316 and wstt.organization_id = p_organization_id
3317 and wstt.dock_appoint_flag = 'N'
3318 and nvl(direct_ship_flag,'N') = 'N')
3319 and wdd.lpn_id is NULL
3320 AND wdd.inventory_item_id = msik.inventory_item_id
3321 AND wdd.organization_id = msik.organization_id
3322 AND wdd.organization_id = p_organization_id
3323 and ((wda.parent_delivery_detail_id is null
3324 AND msik.mtl_transactions_enabled_flag <> 'N')
3325 OR wdd.released_status is null
3326 OR wdd.released_status NOT IN ('X', 'Y'));
3327 if l_count >0 then
3328 x_missing_count := l_count;
3329 end if;
3330 EXCEPTION
3331 WHEN NO_DATA_FOUND THEN
3332 open x_missing_item FOR select 1 from dual;
3333 return;
3334 END;
3335
3336 /*Bug#5612236. In the below query, replaced 'MTL_SYSTEM_ITEMS_KFV' with
3337 'MTL_SYSTEM_ITEMS_VL'.*/
3338 open x_missing_item FOR
3339 select wnd.name
3340 ,wdd.delivery_detail_id
3341 , wdd.inventory_item_id
3342 , wdd.requested_quantity
3343 , msiv.concatenated_segments
3344 , msiv.description
3345 from wsh_delivery_details_ob_grp_v wdd
3346 , wsh_delivery_assignments_v wda
3347 , mtl_system_items_vl msiv
3348 , wsh_new_deliveries_ob_grp_v wnd
3349 where wda.delivery_detail_id = wdd.delivery_detail_id
3350 and wdd.lpn_id is null
3351 and wda.delivery_id in (select distinct delivery_id
3352 from wms_shipping_transaction_temp
3353 where dock_door_id = p_dock_door_id
3354 and organization_id = p_organization_id
3355 and dock_appoint_flag = 'N'
3356 and nvl(direct_ship_flag,'N') = 'N'
3357 and delivery_id is not null
3358 UNION
3359 select distinct wdl.delivery_id
3360 from wsh_delivery_legs_ob_grp_v wdl
3361 ,wms_shipping_transaction_temp wstt
3362 ,wsh_trip_stops_ob_grp_v wts
3363 where wdl.pick_up_stop_id = wts.stop_id
3364 and wts.trip_id = wstt.trip_id
3365 and wstt.dock_door_id = p_dock_door_id
3366 and wstt.organization_id = p_organization_id
3367 and wstt.dock_appoint_flag = 'N'
3368 and nvl(direct_ship_flag,'N') = 'N')
3369 and wda.delivery_id = wnd.delivery_id
3370 and wdd.organization_id = p_organization_id
3371 and wdd.inventory_item_id = msiv.inventory_item_id
3372 and wdd.organization_id = msiv.organization_id
3373 AND wdd.organization_id = p_organization_id
3374 and ((wda.parent_delivery_detail_id IS NULL
3375 AND msiv.mtl_transactions_enabled_flag <> 'N')
3376 OR wdd.released_status is NULL
3377 OR wdd.released_status NOT IN ('X', 'Y'));
3378 END IF;
3379 END MISSING_ITEM_CHECK;
3380
3381 PROCEDURE SHIP_SET_CHECK( p_trip_id IN NUMBER,
3382 p_dock_door_id IN NUMBER,
3383 p_organization_id IN NUMBER,
3384 x_ship_set OUT NOCOPY VARCHAR2,
3385 x_return_Status OUT NOCOPY VARCHAR2,
3386 x_error_msg OUT NOCOPY VARCHAR2,
3387 p_direct_ship_flag IN varchar2 default 'N') IS
3388 l_ship_set VARCHAR2(2000) := NULL;
3389 l_ship_set_id NUMBER;
3390 l_ship_set_name VARCHAR2(30);
3391 unshipped_count NUMBER := 0;
3392 l_source_header_id NUMBER;
3393 CURSOR ship_set_in_trip(p_trip_id NUMBER) IS
3394 SELECT distinct wdd.ship_set_id
3395 FROM wsh_delivery_details_ob_grp_v wdd,wms_shipping_transaction_temp wstt
3396 WHERE wdd.delivery_detail_id = wstt.delivery_detail_id
3397 AND wdd.ship_set_id is not null
3398 AND wstt.organization_id = p_organization_id
3399 AND wstt.trip_id = p_trip_id
3400 AND wstt.dock_door_id = p_dock_door_id
3401 AND nvl(wstt.direct_ship_flag,'N') = 'N';
3402
3403 CURSOR delivered_ship_set IS
3404 SELECT distinct wdd.ship_set_id, wdd.source_header_id
3405 FROM wsh_delivery_details_ob_grp_v wdd,wms_shipping_transaction_temp wstt
3406 WHERE wdd.delivery_detail_id = wstt.delivery_detail_id
3407 AND wdd.ship_set_id is not null
3408 AND wstt.organization_id = p_organization_id
3409 AND wstt.dock_appoint_flag = 'N'
3410 AND nvl(wstt.direct_ship_flag,'N') = p_direct_ship_flag
3411 AND wstt.dock_door_id = p_dock_door_id;
3412
3413 CURSOR c_unshipped_count (p_ship_set_id NUMBER)
3414 IS
3415 SELECT 1
3416 FROM wsh_delivery_details_ob_grp_v wdd,
3417 oe_order_lines_all oel
3418 WHERE oel.ship_set_id = p_ship_set_id
3419 AND wdd.source_line_id = oel.line_id
3420 AND wdd.source_header_id = oel.header_id
3421 AND wdd.ship_set_id = p_ship_set_id
3422 AND wdd.shipped_quantity is null;
3423
3424 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3425 l_debug number;
3426 BEGIN
3427 IF g_debug IS NULL THEN
3428 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3429 END IF;
3430 l_debug := g_debug;
3431
3432 x_return_status := 'C';
3433 if (p_trip_id <> 0) THEN
3434 IF l_debug = 1 THEN
3435 debug('Check ship set for delivery in trip','SHIP_SET_CHECK');
3436 END IF;
3437
3438 OPEN ship_set_in_trip(p_trip_id);
3439 loop
3440 FETCH ship_set_in_trip INTO l_ship_set_id;
3441 EXIT WHEN ship_set_in_trip%NOTFOUND;
3442
3443 BEGIN
3444 OPEN c_unshipped_count(l_ship_set_id);
3445 FETCH c_unshipped_count INTO unshipped_count;
3446 CLOSE c_unshipped_count;
3447
3448 if (unshipped_count >0 ) THEN
3449 IF l_debug = 1 THEN
3450 debug('Ship set: ' || l_ship_set_id || ' is broken','SHIP_SET_CHECK');
3451 END IF;
3452 select set_name
3453 into l_ship_set_name
3454 from oe_sets
3455 where set_id = l_ship_set_id;
3456 if (l_ship_set is null) then
3457 l_ship_set := l_ship_set_name;
3458 else l_ship_set := l_ship_set ||', '||l_ship_set_name;
3459 end if;
3460 end if;
3461 EXCEPTION
3462 WHEN NO_DATA_FOUND THEN null;
3463 END;
3464 end loop;
3465 close ship_set_in_trip;
3466 else -- p_trip_id <> 0
3467 IF l_debug = 1 THEN
3468 debug('Query for ship set','SHIP_SET_CHECK');
3469 END IF;
3470 OPEN delivered_ship_set;
3471 loop
3472 FETCH delivered_ship_set INTO l_ship_set_id,l_source_header_id;
3473 EXIT WHEN delivered_ship_set%NOTFOUND;
3474 BEGIN
3475 /* SELECT 1
3476 INTO unshipped_count
3477 FROM DUAL
3478 WHERE exists (
3479 SELECT 1
3480 FROM wsh_delivery_details_ob_grp_v wdd
3481 WHERE
3482 wdd.source_header_id = l_source_header_id
3483 AND wdd.ship_set_id = l_ship_set_id
3484 AND nvl(wdd.shipped_quantity,wdd.picked_quantity) is null
3485 );
3486 */
3487 -- Bug DHERRING 5758304 changes the way unshipped lines
3488 -- are determined for deliveries without a trip.
3489 -- The code excludes lines with the status:
3490 -- 'C' Already shipped
3491 -- 'X' Not Applicable
3492 -- 'D' Cancelled
3493 -- Lines already loaded onto the dock door do not raise the
3494 -- unshipped_count flag.
3495 -- Only lines within the same SO are considered.
3496 -- Cases where the ship set is split within the same
3497 -- delivery will be caught by the missing lpn procedure.
3498 SELECT count(delivery_detail_id)
3499 INTO unshipped_count
3500 FROM wsh_delivery_details wdd
3501 WHERE wdd.released_status NOT IN ('C','X','D')
3502 AND NOT EXISTS (select 1
3503 FROM wms_shipping_transaction_temp wstt
3504 WHERE wstt.delivery_detail_id = wdd.delivery_detail_id)
3505 AND wdd.source_header_id = l_source_header_id
3506 AND wdd.ship_set_id = l_ship_set_id
3507 AND wdd.container_flag <> 'Y'
3508 AND wdd.organization_id = p_organization_id;
3509
3510 if (unshipped_count >0 ) THEN
3511 IF l_debug = 1 THEN
3512 debug('Ship set: ' || l_ship_set_id || ' is broken.','SHIP_SET_CHECK');
3513 END IF;
3514 select set_name
3515 into l_ship_set_name
3516 from oe_sets
3517 where set_id = l_ship_set_id;
3518 if (l_ship_set is null) then
3519 l_ship_set := l_ship_set_name;
3520 else l_ship_set := l_ship_set ||', '||l_ship_set_name;
3521 end if;
3522 end if;
3523 EXCEPTION
3524 WHEN NO_DATA_FOUND THEN null;
3525 END;
3526 end loop;
3527 close delivered_ship_set;
3528 end if;
3529
3530 if l_ship_set is null then
3531 x_return_status := 'C';
3532 else
3533 x_return_status := 'E';
3534 x_ship_set := l_ship_set;
3535 end if;
3536 EXCEPTION
3537 WHEN OTHERS THEN
3538 x_return_status := 'U';
3539 END SHIP_SET_CHECK;
3540
3541
3542 PROCEDURE PRINT_LABEL(p_del_rows IN wsh_util_core.id_tab_type,
3543 x_return_status OUT NOCOPY VARCHAR2) IS
3544 /*
3545 cursor Delivery_Details(p_delivery_id NUMBER) is
3546 select wdd.delivery_detail_id
3547 from wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda
3548 where wda.delivery_id = p_delivery_id
3549 and wda.delivery_detail_id = wdd.delivery_detail_id
3550 and wdd.lpn_id is NULL;
3551 */
3552 l_delivery_detail_id NUMBER;
3553 l_delivery_details_tab INV_LABEL.transaction_id_rec_type;
3554 l_msg_count NUMBER;
3555 l_msg_data VARCHAR2(2000);
3556 l_label_status varchar2(300);
3557
3558 BEGIN
3559 x_return_status := 'S';
3560 IF (p_del_rows.count = 0) THEN return; END IF;
3561 FOR i IN 1..p_del_rows.count LOOP
3562 l_delivery_details_tab(i) := p_del_rows(i);
3563 END LOOP;
3564
3565 inv_label.print_label
3566 (x_return_status => x_return_status
3567 , x_msg_count => l_msg_count
3568 , x_msg_data => l_msg_data
3569 , x_label_status => l_label_status
3570 , p_api_version => 1.0
3571 , p_print_mode => 1
3572 , p_business_flow_code => 21
3573 , p_transaction_id => l_delivery_details_tab
3574 );
3575 END PRINT_LABEL;
3576
3577 PROCEDURE SHIP_CONFIRM_ALL(p_delivery_id IN NUMBER,
3578 p_organization_id IN NUMBER,
3579 p_delivery_name IN VARCHAR2,
3580 p_carrier_id IN NUMBER,
3581 p_ship_method_code IN VARCHAR2,
3582 p_gross_weight IN NUMBER,
3583 p_gross_weight_uom IN VARCHAR2,
3584 p_bol IN VARCHAR2,
3585 p_waybill IN VARCHAR2,
3586 p_action_flag IN VARCHAR2,
3587 x_return_status OUT NOCOPY VARCHAR2,
3588 x_msg_data OUT NOCOPY VARCHAR2,
3589 x_msg_count OUT NOCOPY NUMBER) IS
3590 l_del_rows WSH_UTIL_CORE.ID_TAB_TYPE;
3591 l_report_set_id NUMBER;
3592
3593 l_actual_dep_date DATE := SYSDATE;
3594 l_bol_flag VARCHAR2(1) := 'Y';
3595 l_return_status VARCHAR2(1);
3596
3597 l_autocreate_flag VARCHAR2(1);
3598 l_report_set_name VARCHAR2(80);
3599 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3600 l_debug number;
3601
3602 l_count NUMBER;
3603 l_tmp_out NUMBER;
3604 l_tmp_buffer VARCHAR2(2000);
3605
3606 --Message related variables
3607 l_dummy_number NUMBER;
3608 l_summary VARCHAR2(2000);
3609 l_msg_count NUMBER;
3610
3611 --Variables added as part of shipping API cleanup project for patchset J
3612 l_delivery_info wsh_deliveries_pub.delivery_pub_rec_type;
3613 l_msg_data VARCHAR2(2000);
3614 l_delivery_id NUMBER;
3615 l_delivery_name VARCHAR2(30);
3616 l_trip_id VARCHAR2(30);
3617 l_trip_name VARCHAR2(30);
3618
3619 l_wms_enabled_flag VARCHAR2(1);
3620 l_outer_cont_instance_id NUMBER;
3621
3622 CURSOR outer_lpn(p_delivery_id number) IS
3623 SELECT DISTINCT wda.parent_delivery_detail_id inner_lpn_wdd,
3624 wlpn.outermost_lpn_id outermost_lpn_id
3625 FROM wsh_delivery_details_ob_grp_v wdd,
3626 wsh_delivery_assignments_v wda,
3627 wms_license_plate_numbers wlpn
3628 WHERE wda.delivery_id = p_delivery_id
3629 AND wda.parent_delivery_detail_id = wdd.delivery_detail_id
3630 AND wdd.lpn_id = wlpn.lpn_id;
3631
3632
3633 BEGIN
3634 IF g_debug IS NULL THEN
3635 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3636 END IF;
3637 l_debug := g_debug;
3638
3639 l_del_rows(1) := p_delivery_id;
3640
3641 -- get the document set id
3642 if( nvl(l_report_set_id, -1) = -1) then
3643 BEGIN
3644 select delivery_report_set_id
3645 into l_report_set_id
3646 from wsh_shipping_parameters
3647 where organization_id = p_organization_id;
3648 EXCEPTION
3649 when no_data_found then
3650 BEGIN
3651 select report_set_id
3652 into l_report_set_id
3653 from wsh_report_sets
3654 where usage_code = 'SHIP_CONFIRM'
3655 and name = 'Ship Confirm Documents';
3656 EXCEPTION
3657 when no_data_found then
3658 -- put message in the message stack
3659 rollback to ship_confirm;
3660 raise FND_API.G_EXC_UNEXPECTED_ERROR;
3661 when TOO_MANY_ROWS then
3662 rollback to ship_confirm;
3663 -- put message in the message stack
3664 raise FND_API.G_EXC_UNEXPECTED_ERROR;
3665 END;
3666 END;
3667 end if;
3668
3669 --patchet J. Shipping API cleanup
3670 UPDATE_DELIVERY(p_delivery_id => p_delivery_id,
3671 p_gross_weight => p_gross_weight,
3672 p_weight_uom => p_gross_weight_uom,
3673 p_waybill => p_waybill,
3674 p_bol => p_bol,
3675 p_ship_method_code => p_ship_method_code,
3676 x_return_status => l_return_status);
3677
3678 IF l_return_status NOT IN ('S','W') THEN
3679 debug('update_delivery failed with status: '
3680 || l_return_status, 'SHIP_CONFIRM_ALL');
3681 raise FND_API.G_EXC_UNEXPECTED_ERROR;
3682 END IF;
3683 --\Shipping API cleanup
3684
3685 --patchset J. LPN hierarchy
3686 --Populate Shipping with LPN hierarchy.
3687
3688 --Release 12: LPN Synchronize
3689 -- The following code of populating shipping with LPN hierarchy
3690 -- is not necessary because LPN hierarchy is in sync between WMS and WSH
3691 -- Removed the call to lpn_hiearchy_actions
3692
3693
3694
3695
3696 IF (l_debug = 1) THEN
3697 debug('About to call wsh_deliveries_pub.delivery_action',
3698 'SHIP_CONFIRM_ALL');
3699 debug('delivery_id : ' || p_delivery_id,'SHIP_CONFIRM_ALL');
3700 END IF;
3701 --patchset J. Shipping API cleanup
3702 wsh_deliveries_pub.delivery_action
3703 (p_api_version_number => 1.0,
3704 p_init_msg_list => G_TRUE,
3705 x_return_status => l_return_status,
3706 x_msg_count => l_msg_count,
3707 x_msg_data => l_msg_data,
3708 p_action_code => 'CONFIRM',
3709 p_delivery_id => p_delivery_id,
3710 p_sc_action_flag => p_action_flag,
3711 p_sc_intransit_flag => 'Y',
3712 p_sc_close_trip_flag => 'Y',
3713 p_sc_create_bol_flag => l_bol_flag, -- BUG 5158964
3714 p_sc_stage_del_flag => 'Y',
3715 p_sc_trip_ship_method => p_ship_method_code,
3716 p_sc_actual_dep_date => l_actual_dep_date,
3717 p_sc_report_set_id => l_report_set_id,
3718 p_sc_defer_interface_flag => 'N',
3719 x_trip_id => l_trip_id,
3720 x_trip_name => l_trip_name);
3721 --\Shipping API cleanup
3722
3723 IF l_debug = 1 THEN
3724 debug('wsh_deliveries_pub.delivery_action finished with status: '
3725 || l_return_status,'SHIP_CONFIRM_ALL');
3726 END IF;
3727
3728 if( l_return_status not in ('S', 'W') ) then
3729 IF (l_debug = 1) THEN
3730 debug('l_return_status is ' || l_return_status, 'Ship_Confirm');
3731 END IF;
3732 rollback;
3733 raise FND_API.G_EXC_UNEXPECTED_ERROR;
3734 else
3735 x_return_status := l_return_status;
3736 print_label(l_del_rows, l_return_status);
3737 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3738 debug('print_label failed','ship_confirm_all');
3739 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
3740 FND_MSG_PUB.ADD;
3741 x_return_status := 'W';
3742 END IF;
3743 end if;
3744
3745 process_mobile_msg;
3746 x_msg_count := fnd_msg_pub.count_msg;
3747 x_msg_data := '';
3748 FOR i IN 1..x_msg_count LOOP
3749 fnd_msg_pub.get(p_encoded=>'F'
3750 ,p_msg_index => i
3751 ,p_data => l_msg_data
3752 ,p_msg_index_out => l_dummy_number);
3753 x_msg_data := x_msg_data || l_msg_data;
3754 END LOOP;
3755 debug('Actual message pass back to java: ' || x_msg_data,'SHIP_CONFIRM_ALL');
3756 debug('Msg count passed back: ' || x_msg_count,'SHIP_CONFIRM_ALL');
3757
3758 EXCEPTION
3759 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3760 ROLLBACK;
3761 x_return_status := l_return_status;
3762
3763 --DHERRING Bug#5651219. Fix starts
3764 x_msg_count := FND_MSG_PUB.Count_msg;
3765 FOR i in 1..x_msg_count LOOP
3766 FND_MSG_PUB.get(p_encoded => FND_API.G_FALSE, p_msg_index => i, p_data=> l_tmp_buffer,
3767 p_msg_index_out => l_tmp_out);
3768 x_msg_data:=x_msg_data ||'|'|| l_tmp_buffer;
3769 END LOOP;
3770
3771 IF (l_debug = 1) THEN
3772 debug('inside EXCEPTION, x_msg_count is ' || x_msg_count, 'SHIP_CONFIRM_ALL');
3773 debug('inside EXCEPTION, x_msg_data is ' || x_msg_data, 'SHIP_CONFIRM_ALL');
3774 END IF;
3775
3776 /* commented DHERRING Bug#5651219
3777 wsh_util_core.get_messages
3778 (p_init_msg_list => 'Y',
3779 x_summary => l_summary,
3780 x_details => l_msg_data,
3781 x_count => l_msg_count); */
3782
3783 --DHERRING Bug#5651219.Fix Ends
3784
3785 IF l_debug = 1 THEN
3786 debug('SHIP_CONFIRM_ALL raised exception with summary: '
3787 || l_summary, 'SHIP_CONFIRM_ALL');
3788 debug('SHIP_CONFIRM_ALL raised exception with messages: '
3789 || l_msg_data, 'SHIP_CONFIRM_ALL');
3790 debug('SHIP_CONFIRM_ALL raised exception with msg_count: '
3791 || l_msg_count, 'SHIP_CONFIRM_ALL');
3792 END IF;
3793
3794 WHEN OTHERS THEN
3795 IF l_debug = 1 THEN
3796 debug('Others exception raised!','SHIP_CONFIRM_ALL');
3797 debug(SQLERRM,'SHIP_CONFIRM_ALL');
3798 END IF;
3799 ROLLBACK;
3800 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3801 END SHIP_CONFIRM_ALL;
3802
3803 PROCEDURE SHIP_CONFIRM(p_delivery_id IN NUMBER,
3804 p_organization_id IN NUMBER,
3805 p_delivery_name IN VARCHAR2,
3806 p_carrier_id IN NUMBER,
3807 p_ship_method_code IN VARCHAR2,
3808 p_gross_weight IN NUMBER,
3809 p_gross_weight_uom IN VARCHAR2,
3810 p_bol IN VARCHAR2,
3811 p_waybill IN VARCHAR2,
3812 p_action_flag IN VARCHAR2,
3813 x_return_status OUT NOCOPY VARCHAR2,
3814 x_msg_data OUT NOCOPY VARCHAR2,
3815 x_msg_count OUT NOCOPY NUMBER) IS
3816
3817 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3818 l_debug number;
3819 BEGIN
3820 IF g_debug IS NULL THEN
3821 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3822 END IF;
3823 l_debug := g_debug;
3824
3825 -- call ship confirm
3826 WMS_SHIPPING_TRANSACTION_PUB.ship_confirm_all
3827 (p_delivery_id,
3828 p_organization_id,
3829 p_delivery_name,
3830 p_carrier_id,
3831 p_ship_method_code,
3832 p_gross_weight,
3833 p_gross_weight_uom,
3834 p_bol,
3835 p_waybill,
3836 p_action_flag,
3837 x_return_status,
3838 x_msg_data,
3839 x_msg_count);
3840 if( x_return_status not in ('S','W') ) THEN
3841 IF (l_debug = 1) THEN
3842 debug('error from confirm_delivery', 'Ship_Confirm');
3843 debug('return_status is ' || x_return_status, 'Ship_Confirm');
3844 END IF;
3845 end if;
3846
3847 END SHIP_CONFIRM;
3848
3849 PROCEDURE SHIP_CONFIRM_LPN_DELIVERIES(x_return_status OUT NOCOPY VARCHAR2,
3850 x_msg_data OUT NOCOPY VARCHAR2,
3851 x_msg_count OUT NOCOPY NUMBER,
3852 p_trip_stop_id IN NUMBER,
3853 p_trip_id IN NUMBER,
3854 p_dock_door_id IN NUMBER,
3855 p_organization_id IN NUMBER,
3856 p_verify_only IN VARCHAR2,
3857 p_close_trip_flag IN VARCHAR2 DEFAULT 'N',
3858 p_allow_ship_set_break IN VARCHAR2 DEFAULT 'N') IS
3859 cursor Deliveries_in_trip is
3860 select distinct wstt.delivery_id, wnd.ship_method_code
3861 from wms_shipping_transaction_temp wstt,wsh_new_deliveries_ob_grp_v wnd
3862 where wstt.trip_id = p_trip_id
3863 and wstt.dock_door_id = p_dock_door_id
3864 and wstt.organization_id = p_organization_id
3865 and nvl(wstt.direct_ship_flag,'N') = 'N'
3866 AND wstt.delivery_id = wnd.delivery_id;
3867
3868 cursor Deliveries is
3869 select distinct wstt.delivery_id,wnd.ship_method_code
3870 from wms_shipping_transaction_temp wstt,wsh_new_deliveries_ob_grp_v wnd
3871 where wstt.dock_appoint_flag = 'N'
3872 and nvl(wstt.direct_ship_flag,'N') = 'N'
3873 and wstt.dock_door_id = p_dock_door_id
3874 and wstt.organization_id = p_organization_id
3875 AND wstt.delivery_id = wnd.delivery_id;
3876
3877 cursor outermost_lpn_for_trip is
3878 select distinct outermost_lpn_id
3879 from wms_shipping_transaction_temp
3880 where trip_id = p_trip_id
3881 and nvl(direct_ship_flag,'N') = 'N'
3882 and organization_id = p_organization_id;
3883
3884 cursor outermost_lpn_for_dock is
3885 select distinct outermost_lpn_id
3886 from wms_shipping_transaction_temp
3887 where organization_id = p_organization_id
3888 and dock_door_id = p_dock_door_id
3889 and dock_appoint_flag = 'N'
3890 and nvl(direct_ship_flag,'N') = 'N';
3891
3892 CURSOR nested_children_lpn_cursor(l_outermost_lpn_id NUMBER) is
3893 SELECT lpn_id
3894 FROM WMS_LICENSE_PLATE_NUMBERS
3895 START WITH lpn_id = l_outermost_lpn_id
3896 CONNECT BY parent_lpn_id = PRIOR lpn_id;
3897
3898 cursor Deliveries_without_trip is
3899 select distinct wstt.delivery_id,wnd.ship_method_code
3900 from wms_shipping_transaction_temp wstt,wsh_new_deliveries_ob_grp_v wnd
3901 where wstt.dock_appoint_flag = 'N'
3902 and nvl(wstt.direct_ship_flag,'N') = 'N'
3903 and wstt.dock_door_id = p_dock_door_id
3904 and wstt.trip_id is null
3905 and wstt.organization_id = p_organization_id
3906 AND wstt.delivery_id = wnd.delivery_id ;
3907
3908 cursor Deliveries_with_trip is
3909 select distinct wstt.delivery_id,wnd.ship_method_code
3910 from wms_shipping_transaction_temp wstt, wsh_new_deliveries_ob_grp_v wnd
3911 where wstt.dock_appoint_flag = 'N'
3912 and nvl(wstt.direct_ship_flag,'N') = 'N'
3913 and wstt.dock_door_id = p_dock_door_id
3914 and wstt.trip_id is not null
3915 and wstt.organization_id = p_organization_id
3916 AND wstt.delivery_id = wnd.delivery_id;
3917
3918 cursor pick_up_stops is
3919 select distinct wdl.pick_up_stop_id,wts.stop_sequence_number
3920 from wsh_delivery_legs_ob_grp_v wdl,wms_shipping_transaction_temp wstt,
3921 wsh_trip_stops_ob_grp_v wts
3922 where wdl.pick_up_stop_id = wts.stop_id
3923 and wts.trip_id = wstt.trip_id
3924 and wstt.dock_door_id = p_dock_door_id
3925 and wstt.organization_id = p_organization_id
3926 and wstt.dock_appoint_flag = 'N'
3927 and nvl(direct_ship_flag,'N') = 'N'
3928 AND wts.status_code = 'OP'
3929 ORDER BY wts.stop_sequence_number asc;
3930
3931 cursor drop_off_stops(p_dock_appoint_flag varchar2) is
3932 select distinct wdl.drop_off_stop_id
3933 from wsh_delivery_legs wdl,wms_shipping_transaction_temp wstt,
3934 wsh_trip_stops wts
3935 where wdl.drop_off_stop_id = wts.stop_id
3936 and wts.trip_id = wstt.trip_id
3937 and wstt.dock_door_id = p_dock_door_id
3938 and wstt.organization_id = p_organization_id
3939 and wstt.dock_appoint_flag = p_dock_appoint_flag
3940 and nvl(direct_ship_flag,'N') = 'N';
3941
3942
3943 CURSOR c_get_trip_ship_method(l_delivery_id NUMBER)IS
3944 SELECT wts.trip_id,
3945 wt.ship_method_code
3946 FROM wsh_delivery_legs_ob_grp_v wdl,
3947 wsh_trip_stops_ob_grp_v wts,
3948 wsh_trips_ob_grp_v wt
3949 WHERE wdl.delivery_id = l_delivery_id
3950 AND wdl.pick_up_stop_id = wts.stop_id
3951 AND wt.trip_id = wts.trip_id
3952 AND ROWNUM = 1;
3953
3954 CURSOR C_Ship_Confirm_Parameters IS
3955 SELECT wsp.ship_confirm_rule_id, wscr.ac_intransit_flag, wscr.ac_close_trip_flag, wscr.ac_defer_interface_flag
3956 FROM wsh_shipping_parameters wsp, wsh_ship_confirm_rules wscr
3957 WHERE wsp.organization_id = p_organization_id
3958 AND wscr.ship_confirm_rule_id = wsp.ship_confirm_rule_id;
3959
3960 CURSOR Check_Last_Trip (l_delivery_id NUMBER) IS
3961 SELECT wdt1.trip_id
3962 FROM wsh_delivery_trips_v wdt1,
3963 wsh_new_deliveries wnd
3964 WHERE wdt1.delivery_id <> l_delivery_id
3965 AND wdt1.delivery_id = wnd.delivery_id
3966 AND wnd.status_code = 'OP'
3967 AND wdt1.trip_id IN (SELECT wdt2.trip_id
3968 FROM wsh_delivery_trips_v wdt2
3969 WHERE wdt2.delivery_id = l_delivery_id)
3970 AND rownum = 1;
3971
3972 l_delivery_id NUMBER;
3973 l_del_index NUMBER;
3974 l_del_rows WSH_UTIL_CORE.ID_TAB_TYPE;
3975 l_stop_rows WSH_UTIL_CORE.ID_TAB_TYPE;
3976 l_drop_off_stops wsh_util_core.id_tab_type;
3977 l_report_set_id NUMBER;
3978
3979 l_sc_rule_id NUMBER;
3980 l_intransit_flag VARCHAR2(1);
3981 l_close_trip_flag VARCHAR2(1);
3982 l_defer_interface_flag VARCHAR2(1);
3983 l_sc_intransit_flag VARCHAR2(1);
3984 l_sc_close_trip_flag VARCHAR2(1);
3985 l_sc_defer_interface_flag VARCHAR2(1);
3986 l_open_delivery_id NUMBER;
3987
3988 TYPE ship_method_tbl_type IS TABLE OF wsh_new_deliveries.ship_method_code%TYPE INDEX BY BINARY_INTEGER;
3989 l_ship_method_tbl ship_method_tbl_type;
3990 l_ship_method VARCHAR2(30);
3991
3992 l_actual_dep_date DATE := SYSDATE;
3993 l_bol_flag VARCHAR2(1) := 'Y';
3994 l_return_status VARCHAR2(1);
3995 l_num_warnings NUMBER := 0;
3996
3997 l_autocreate_flag VARCHAR2(1);
3998 l_report_set_name VARCHAR2(80);
3999 l_org_id NUMBER;
4000 l_outermost_lpn_id NUMBER;
4001 l_pick_up_stop_id NUMBER;
4002 l_drop_off_stop_id NUMBER;
4003 l_stop_sequence_number NUMBER;
4004 l_pick_up_count NUMBER := 0;
4005
4006 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4007 l_debug number;
4008
4009 l_count NUMBER;
4010 l_tmp_out NUMBER;
4011 l_tmp_buffer VARCHAR2(2000);
4012
4013 l_msg_count NUMBER;
4014 l_dummy_number NUMBER;
4015 l_summary VARCHAR2(2000);
4016
4017 --variables added for Shipping API cleanup for patchset J
4018 l_trip_id VARCHAR2(30);
4019 l_trip_name VARCHAR2(30);
4020 l_msg_data VARCHAR2(2000);
4021
4022 l_trip_trip_id NUMBER;
4023 l_trip_ship_method_code wsh_trips_ob_grp_v.ship_method_code%type := null;
4024
4025 BEGIN
4026 savepoint ship_confirm;
4027
4028 x_return_status := FND_API.G_RET_STS_SUCCESS;
4029
4030 IF g_debug IS NULL THEN
4031 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4032 END IF;
4033 l_debug := g_debug;
4034
4035 IF l_debug = 1 THEN
4036 debug('p_verify_only : ' || p_verify_only
4037 || ' , p_trip_id : ' || p_trip_id
4038 || ' , p_trip_stop_id : '|| p_trip_stop_id
4039 || ' , p_dock_door_id : '|| p_dock_door_id
4040 || ' , p_organization_id : '|| p_organization_id, 'LPN_SHIP');
4041 debug('Parameter p_close_trip_flag: ' || p_close_trip_flag,'LPN_SHIP');
4042
4043 debug('Parameter p_allow_ship_set_break: ' || p_allow_ship_set_break,'LPN_SHIP');
4044 END IF;
4045 wms_shipping_transaction_pub.g_allow_ship_set_break := p_allow_ship_set_break;
4046
4047 IF p_close_trip_flag = 'N' THEN
4048 OPEN C_Ship_Confirm_Parameters;
4049 FETCH C_Ship_Confirm_Parameters INTO l_sc_rule_id, l_intransit_flag, l_close_trip_flag, l_defer_interface_flag;
4050 IF l_debug=1 then
4051 debug('Ship Confirm Rule ID : '||l_sc_rule_id
4052 ||' , Intransit Flag : '||l_intransit_flag
4053 ||' , Close Trip Flag : '||l_close_trip_flag
4054 ||' , Defer Interface Flag : '||l_defer_interface_flag ,'ship_confirm_lpn_deliveries');
4055 END IF;
4056 CLOSE C_Ship_Confirm_Parameters;
4057 END IF;
4058
4059 l_del_index := 1;
4060 if (p_trip_id <> 0 ) THEN
4061 IF l_debug = 1 then
4062 debug('p_trip_id: ' || p_trip_id,'ship_confirm_lpn_deliveries');
4063 END IF;
4064
4065 open Deliveries_in_trip;
4066 LOOP
4067 fetch Deliveries_in_trip into l_delivery_id,l_ship_method;
4068 EXIT WHEN Deliveries_in_trip%NOTFOUND;
4069
4070 l_del_rows(l_del_index) := l_delivery_id;
4071 l_ship_method_tbl(l_del_index) := l_ship_method;
4072
4073 IF l_debug = 1 then
4074 debug('delivery id: ' || l_delivery_id || ' ship_method_code: '
4075 || l_ship_method,'ship_confirm_lpn_deliveries');
4076 END IF;
4077
4078 l_del_index := l_del_index +1;
4079 END LOOP;
4080 close Deliveries_in_trip;
4081 ELSE -- p_trip_id <> 0
4082
4083 IF l_debug = 1 THEN
4084 debug('no trip id','ship_confirm_lpn_deliveries');
4085 END IF;
4086
4087 open Deliveries;
4088 LOOP
4089 fetch Deliveries into l_delivery_id,l_ship_method;
4090 EXIT WHEN Deliveries%NOTFOUND;
4091
4092 l_del_rows(l_del_index) := l_delivery_id;
4093 l_ship_method_tbl(l_del_index) := l_ship_method;
4094
4095 IF l_debug = 1 then
4096 debug('delivery id: ' || l_delivery_id || ' ship_method_code: '
4097 || l_ship_method,'ship_confirm_lpn_deliveries');
4098 END IF;
4099
4100 l_del_index := l_del_index +1;
4101 END LOOP;
4102 close Deliveries;
4103 end if;
4104
4105 -- get the document set id
4106 select organization_id
4107 into l_org_id
4108 from wsh_new_deliveries_ob_grp_v
4109 where delivery_id = l_delivery_id;
4110
4111 if( nvl(l_report_set_id, -1) = -1) then
4112 BEGIN
4113 select delivery_report_set_id
4114 into l_report_set_id
4115 from wsh_shipping_parameters
4116 where organization_id = l_org_id;
4117 EXCEPTION
4118 when no_data_found then
4119 BEGIN
4120 select report_set_id
4121 into l_report_set_id
4122 from wsh_report_sets
4123 where usage_code = 'SHIP_CONFIRM'
4124 and name = 'Ship Confirm Documents';
4125 EXCEPTION
4126 when no_data_found then
4127 -- put message in the message stack
4128 rollback to ship_confirm;
4129 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4130 when TOO_MANY_ROWS then
4131 rollback to ship_confirm;
4132 -- put message in the message stack
4133 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4134 END;
4135 END;
4136 end if;
4137
4138 IF (l_debug = 1) THEN
4139 debug('calling wsh_new_delivery_actions.confirm_delivery', 'Ship_Confirm');
4140 END IF;
4141
4142 if p_verify_only = 'Y' then
4143 x_return_status := 'S';
4144 -- delete the records from the temp table after ship confirm
4145 if (p_trip_id <> 0 ) then
4146 -- update the lpn context back to resides in inventory
4147 open outermost_lpn_for_trip;
4148 LOOP
4149 fetch outermost_lpn_for_trip into l_outermost_lpn_id;
4150 exit when outermost_lpn_for_trip%NOTFOUND;
4151 UPDATE WMS_LICENSE_PLATE_NUMBERS
4152 SET lpn_context = 11, --WMS_Container_PUB.LPN_CONTEXT_INV,
4153 last_update_date = SYSDATE,
4154 last_updated_by = FND_GLOBAL.USER_ID
4155 where lpn_id = l_outermost_lpn_id;
4156
4157 -- update the lpn context for all children lpns
4158 FOR l_lpn_id IN nested_children_lpn_cursor(l_outermost_lpn_id) LOOP
4159 UPDATE WMS_LICENSE_PLATE_NUMBERS
4160 SET lpn_context = 11, --WMS_Container_PUB.LPN_CONTEXT_INV,
4161 last_update_date = SYSDATE,
4162 last_updated_by = FND_GLOBAL.USER_ID
4163 where lpn_id = l_lpn_id.lpn_id;
4164 END LOOP;
4165 END LOOP;
4166 close outermost_lpn_for_trip;
4167
4168 -- delete the record from the temp table
4169
4170 -- bug 2760062
4171
4172 DELETE FROM mtl_material_transactions_temp
4173 WHERE wms_task_type = 7
4174 AND organization_id = p_organization_id
4175 AND content_lpn_id IN
4176 (SELECT outermost_lpn_id
4177 FROM wms_shipping_transaction_temp
4178 WHERE organization_id = p_organization_id
4179 AND trip_id = p_trip_id);
4180
4181 delete from wms_shipping_transaction_temp where trip_id = p_trip_id
4182 and organization_id = p_organization_id;
4183 ELSE -- p_trip_id <> 0
4184
4185 -- update the lpn context back to resides in inventory
4186 open outermost_lpn_for_dock;
4187 LOOP
4188 fetch outermost_lpn_for_dock into l_outermost_lpn_id;
4189 exit when outermost_lpn_for_dock%NOTFOUND;
4190 UPDATE WMS_LICENSE_PLATE_NUMBERS
4191 SET lpn_context = 11, --WMS_Container_PUB.LPN_CONTEXT_INV,
4192 last_update_date = SYSDATE,
4193 last_updated_by = FND_GLOBAL.USER_ID
4194 where lpn_id = l_outermost_lpn_id;
4195
4196 -- update the lpn context for all children lpns
4197 FOR l_lpn_id IN nested_children_lpn_cursor(l_outermost_lpn_id) LOOP
4198 UPDATE WMS_LICENSE_PLATE_NUMBERS
4199 SET lpn_context = 11, --WMS_Container_PUB.LPN_CONTEXT_INV,
4200 last_update_date = SYSDATE,
4201 last_updated_by = FND_GLOBAL.USER_ID
4202 where lpn_id = l_lpn_id.lpn_id;
4203 END LOOP;
4204 END LOOP;
4205 close outermost_lpn_for_dock;
4206 -- delete the record from the temp table
4207
4208 -- bug 2760062
4209
4210 DELETE FROM mtl_material_transactions_temp
4211 WHERE wms_task_type = 7
4212 AND organization_id = p_organization_id
4213 AND content_lpn_id IN
4214 (SELECT outermost_lpn_id
4215 FROM wms_shipping_transaction_temp
4216 WHERE organization_id = p_organization_id
4217 AND dock_door_id = p_dock_door_id
4218 AND dock_appoint_flag = 'N'
4219 AND Nvl(direct_ship_flag,'N') = 'N');
4220
4221 delete from wms_shipping_transaction_temp
4222 where organization_id = p_organization_id
4223 and dock_door_id = p_dock_door_id
4224 and dock_appoint_flag = 'N'
4225 and nvl(direct_ship_flag,'N') = 'N';
4226 end if;
4227
4228 -- print the shipping labels
4229 print_label(l_del_rows, l_return_status);
4230 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4231 debug('print_label failed','ship_confirm_lpn_deliveries');
4232 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
4233 FND_MSG_PUB.ADD;
4234 l_num_warnings := l_num_warnings + 1;
4235 END IF;
4236 ELSE --corresponding if - p_verify_only = 'Y'
4237 if p_trip_stop_id =0 then
4238 -- First ship out the deliveries without trip
4239 l_del_rows.DELETE;
4240 l_ship_method_tbl.DELETE;
4241
4242 open Deliveries_without_trip;
4243 l_del_index := 1;
4244 LOOP
4245 fetch Deliveries_without_trip into l_delivery_id,l_ship_method;
4246 EXIT WHEN Deliveries_without_trip%NOTFOUND;
4247 l_del_rows(l_del_index) := l_delivery_id;
4248 l_ship_method_tbl(l_del_index) := l_ship_method;
4249 l_del_index := l_del_index +1;
4250 END LOOP;
4251 close Deliveries_without_trip;
4252
4253 --patchset J. Shipping API cleanup
4254 FOR i IN 1..l_del_rows.COUNT LOOP
4255 IF l_debug = 1 THEN
4256 debug('About to call wsh_deliveries_pub.delivery_action'
4257 || ' with delivery_id : ' || l_del_rows(i) || ' ship_method_code: '
4258 || l_ship_method_tbl(i),'SHIP_CONFIRM_LPN_DELIVERIES');
4259 END IF;
4260
4261
4262
4263 /*
4264 * GLOG-OTM Integration ..that we must pass ship method from Trip, if one
4265 * exists, to Delivery_action API */
4266
4267 OPEN c_get_trip_ship_method(l_del_rows(i) );
4268 FETCH c_get_trip_ship_method INTO l_trip_trip_id, l_trip_ship_method_code;
4269
4270 IF (c_get_trip_ship_method%NOTFOUND) THEN
4271 l_trip_ship_method_code := l_ship_method_tbl(i);
4272 IF l_debug = 1 THEN
4273 debug('Delivery does not belong to any trip','SHIP_CONFIRM_LPN_DELIVERIES');
4274 END IF;
4275 END IF;
4276
4277 CLOSE c_get_trip_ship_method;
4278
4279
4280 IF l_debug = 1 THEN
4281 debug('2:l_del_rows(i) : ' || l_del_rows(i)
4282 || ':l_trip_trip_id : ' || l_trip_trip_id
4283 || ':l_trip_ship_method_code : ' || l_trip_ship_method_code,
4284 'SHIP_CONFIRM_LPN_DELIVERIES');
4285 END if;
4286
4287 -- If the Ship Confirm Rule id is present, use the values from the ship confirm rule
4288 IF l_sc_rule_id IS NOT NULL THEN
4289 l_sc_intransit_flag := l_intransit_flag;
4290 l_sc_close_trip_flag := l_close_trip_flag;
4291 l_sc_defer_interface_flag := l_defer_interface_flag;
4292 ELSE
4293 l_sc_intransit_flag := 'Y';
4294 l_sc_close_trip_flag := 'Y';
4295 l_sc_defer_interface_flag := 'N';
4296 END IF;
4297
4298 wsh_deliveries_pub.delivery_action
4299 (p_api_version_number => 1.0,
4300 p_init_msg_list => fnd_api.g_true,
4301 x_return_status => l_return_status,
4302 x_msg_count => l_msg_count,
4303 x_msg_data => l_msg_data,
4304 p_action_code => 'CONFIRM',
4305 p_delivery_id => l_del_rows(i),
4306 p_sc_action_flag => 'A',
4307 p_sc_intransit_flag => l_sc_intransit_flag,
4308 p_sc_close_trip_flag => l_sc_close_trip_flag,
4309 p_sc_create_bol_flag => l_bol_flag, --Bug 5158964
4310 p_sc_stage_del_flag => 'Y',
4311 p_sc_trip_ship_method => l_trip_ship_method_code, --l_ship_method_tbl(i) for GlogInt
4312 p_sc_actual_dep_date => l_actual_dep_date,
4313 p_sc_report_set_id => l_report_set_id,
4314 p_sc_defer_interface_flag => l_sc_defer_interface_flag,
4315 x_trip_id => l_trip_id,
4316 x_trip_name => l_trip_name);
4317
4318 IF (l_return_status NOT IN ('S','W')) THEN
4319 IF l_debug = 1 THEN
4320 debug('wsh_deliveries_pub.delivery_action failed '
4321 || 'with status ' || l_return_status,'SHIP_CONFIRM_LPN_DELIVERIES');
4322 END IF;
4323
4324 ROLLBACK;
4325 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4326
4327 ELSIF l_return_status = 'W' THEN
4328 l_num_warnings := l_num_warnings + 1;
4329
4330 END IF;
4331 END LOOP;
4332 --\Shipping API cleanup
4333
4334 -- bug 3805194
4335 print_label(l_del_rows, l_return_status);
4336 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4337 debug('print_label failed','SHIP_CONFIRM_LPN_DELIVERIES');
4338 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
4339 FND_MSG_PUB.ADD;
4340
4341 l_num_warnings := l_num_warnings + 1;
4342 END IF;
4343
4344 -- Then ship out the deliveries with trip
4345 l_del_rows.DELETE;
4346 l_ship_method_tbl.DELETE;
4347
4348 open Deliveries_with_trip;
4349 l_del_index := 1;
4350 LOOP
4351 fetch Deliveries_with_trip into l_delivery_id,l_ship_method;
4352 EXIT WHEN Deliveries_with_trip%NOTFOUND;
4353 IF l_intransit_flag = 'Y' AND l_open_delivery_id IS NULL THEN
4354 OPEN check_last_trip(l_delivery_id);
4355 FETCH check_last_trip INTO l_open_delivery_id;
4356 IF l_debug=1 then
4357 debug('Found atleast one open delivery in trip : '||l_open_delivery_id,'ship_confirm_lpn_deliveries');
4358 END IF;
4359 CLOSE check_last_trip;
4360 END IF;
4361 l_del_rows(l_del_index) := l_delivery_id;
4362 l_ship_method_tbl(l_del_index) := l_ship_method;
4363 l_del_index := l_del_index +1;
4364 END LOOP;
4365 close Deliveries_with_trip;
4366
4367 if (l_del_index >1) then
4368 -- fix bug 2175253, get the pick_up_stop before confirm_delivery
4369 IF p_close_trip_flag = 'Y' OR (l_intransit_flag = 'Y' AND l_open_delivery_id IS NULL) THEN
4370 OPEN pick_up_stops;
4371 l_del_index := 1;
4372 LOOP
4373 fetch pick_up_stops into l_pick_up_stop_id,l_stop_sequence_number;
4374 EXIT WHEN pick_up_stops%NOTFOUND;
4375 IF l_debug = 1 THEN
4376 debug('pick_up_stop_id: ' || l_pick_up_stop_id || ' stop_sequence_number: ' || l_stop_sequence_number,'LPN_SHIP');
4377 END IF;
4378 l_stop_rows(l_del_index) := l_pick_up_stop_id;
4379 l_del_index := l_del_index +1;
4380 END LOOP;
4381 CLOSE pick_up_stops;
4382 END IF;
4383
4384 IF l_debug = 1 THEN
4385 debug('Number of pickup stops: ' || l_stop_rows.COUNT,'LPN_SHIP');
4386 END IF;
4387 --User specified to have entire trip close
4388 --Get the drop off stops on the trip as well
4389 IF (p_close_trip_flag = 'Y' OR (l_close_trip_flag = 'Y' AND l_open_delivery_id IS NULL))
4390 AND l_stop_rows.COUNT >= 1 THEN
4391 IF l_debug = 1 then
4392 debug('Getting drop-off stops to close','LPN_SHIP');
4393 END IF;
4394 OPEN drop_off_stops(p_dock_appoint_flag => 'N');
4395 l_del_index := 1;
4396 l_drop_off_stops.DELETE;
4397 LOOP
4398 FETCH drop_off_stops INTO l_drop_off_stop_id;
4399 EXIT WHEN drop_off_stops%notfound;
4400 l_drop_off_stops(l_del_index) := l_drop_off_stop_id;
4401 l_del_index := l_del_index + 1;
4402 END LOOP;
4403 IF l_debug = 1 THEN
4404 debug('Finished getting drop-off stops','LPN_SHIP');
4405 debug('Total drop-off stops for current dock door: ' || l_drop_off_stops.COUNT,'LPN_SHIP');
4406 END IF;
4407 END IF;
4408
4409 --patchset J. Shipping API cleanup
4410 FOR i IN 1..l_del_rows.COUNT LOOP
4411 IF l_debug = 1 THEN
4412 debug('Shipping out delivereis that have trip.','SHIP_CONFIRM_LPN_DELIVERIES');
4413 debug('About to call wsh_deliveries_pub.delivery_action'
4414 || ' with delivery_id : ' || l_del_rows(i) || ' and ship_method_code: '
4415 || l_ship_method_tbl(i),'SHIP_CONFIRM_LPN_DELIVERIES');
4416 END IF;
4417
4418
4419
4420 /*
4421 * GLOG-OTM Integration ..that we must pass ship method from Trip, if one
4422 * exists, to Delivery_action API */
4423
4424 OPEN c_get_trip_ship_method(l_del_rows(i) );
4425 FETCH c_get_trip_ship_method INTO l_trip_trip_id, l_trip_ship_method_code;
4426
4427 IF (c_get_trip_ship_method%NOTFOUND) THEN
4428 l_trip_ship_method_code := NULL;
4429 IF l_debug = 1 THEN
4430 debug('Delivery does not belong to any trip','SHIP_CONFIRM_LPN_DELIVERIES');
4431 END IF;
4432 END IF;
4433 CLOSE c_get_trip_ship_method;
4434
4435 IF l_debug = 1 THEN
4436 debug('3:l_del_rows(i) : ' || l_del_rows(i)
4437 || ':l_trip_trip_id : ' || l_trip_trip_id
4438 || ':l_trip_ship_method_code: ' || l_trip_ship_method_code,
4439 'SHIP_CONFIRM_LPN_DELIVERIES');
4440 END IF;
4441
4442
4443 wsh_deliveries_pub.delivery_action
4444 (p_api_version_number => 1.0,
4445 p_init_msg_list => fnd_api.g_false,
4446 x_return_status => l_return_status,
4447 x_msg_count => l_msg_count,
4448 x_msg_data => l_msg_data,
4449 p_action_code => 'CONFIRM',
4450 p_delivery_id => l_del_rows(i),
4451 p_sc_action_flag => 'A',
4452 p_sc_intransit_flag => 'N',
4453 p_sc_close_trip_flag => 'N',
4454 p_sc_create_bol_flag => l_bol_flag, --Bug 5158964
4455 p_sc_stage_del_flag => 'N',
4456 p_sc_trip_ship_method => l_trip_ship_method_code, --l_ship_method_tbl(i) for GlogInt
4457 p_sc_actual_dep_date => l_actual_dep_date,
4458 p_sc_report_set_id => l_report_set_id,
4459 p_sc_defer_interface_flag => 'Y',
4460 x_trip_id => l_trip_id,
4461 x_trip_name => l_trip_name);
4462
4463 IF (l_return_status NOT IN ('S','W')) THEN
4464 IF l_debug = 1 THEN
4465 debug('wsh_deliveries_pub.delivery_action failed '
4466 || 'with status ' || l_return_status,'SHIP_CONFIRM_LPN_DELIVERIES');
4467 END IF;
4468
4469 ROLLBACK;
4470 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4471
4472 ELSIF l_return_status = 'W' THEN
4473 l_num_warnings := l_num_warnings + 1;
4474
4475 END IF;
4476 END LOOP;
4477 --\Shipping API cleanup
4478
4479 --Bug 5947804 Loop through all the trip stops
4480 IF (p_close_trip_flag = 'Y' OR (l_intransit_flag = 'Y' AND l_open_delivery_id IS NULL))
4481 AND (l_stop_rows.COUNT >= 1) THEN
4482 FOR i IN 1..l_stop_rows.COUNT LOOP
4483 IF l_debug = 1 THEN
4484 debug('Calling wsh_trip_stops_pub.stop_action','LPN_SHIP');
4485 debug('l_stop_rows(i) ' || l_stop_rows(i),'LPN_SHIP');
4486 END IF;
4487
4488 --patchset J. Shipping API cleanup
4489 wsh_trip_stops_pub.stop_action
4490 (p_api_version_number => 1.0,
4491 p_init_msg_list => G_TRUE,
4492 x_return_status => l_return_status,
4493 x_msg_count => l_msg_count,
4494 x_msg_data => l_msg_data,
4495 p_action_code => 'CLOSE',
4496 --p_stop_id => l_stop_rows(1),
4497 p_stop_id => l_stop_rows(i), --Bug 5947804
4498 p_actual_date => sysdate,
4499 p_defer_interface_flag => NVL(l_defer_interface_flag,'N'));
4500
4501 IF (l_debug = 1) THEN
4502 debug('return status:'||l_return_status, 'LPN_SHIP');
4503 END IF;
4504 if( l_return_status not in ('S', 'W') ) then
4505 IF (l_debug = 1) THEN
4506 debug('l_return_status is ' || l_return_status, 'Ship_Confirm');
4507 END IF;
4508 rollback;
4509 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4510
4511 ELSIF l_return_status = 'W' THEN
4512 l_num_warnings := l_num_warnings + 1;
4513
4514 end if;
4515
4516 END LOOP;
4517 END IF;
4518 --\Shipping API cleanup
4519
4520 --Close the drop-off stops as well
4521 IF (p_close_trip_flag = 'Y' OR (l_close_trip_flag = 'Y' AND l_open_delivery_id IS NULL))
4522 AND (l_drop_off_stops.COUNT >= 1) THEN
4523 IF l_debug = 1 THEN
4524 debug('Calling change status for the drop-off stops','LPN_SHIP');
4525 END IF;
4526
4527 FOR i IN 1..l_drop_off_stops.COUNT LOOP
4528 wsh_trip_stops_pub.stop_action
4529 (p_api_version_number => 1.0,
4530 p_init_msg_list => G_TRUE,
4531 x_return_status => l_return_status,
4532 x_msg_count => l_msg_count,
4533 x_msg_data => l_msg_data,
4534 p_action_code => 'CLOSE',
4535 p_stop_id => l_drop_off_stops(i),
4536 p_actual_date => sysdate,
4537 p_defer_interface_flag => 'Y');
4538 IF l_debug = 1 THEN
4539 debug('wsh_trip_stops_actions.change_status return status: ' || l_return_status,'LPN_SHIP');
4540 END IF;
4541
4542 IF l_return_status NOT IN ('S','W') THEN
4543 IF l_debug = 1 THEN
4544 debug('Could not close the drop-off stops. Let the transaction go through','LPN_SHIP');
4545 END IF;
4546
4547 ELSIF l_return_status = 'W' THEN
4548 l_num_warnings := l_num_warnings + 1;
4549
4550 END IF;
4551 END LOOP;
4552 END IF;
4553
4554 end if; --corresponding if: l_del_index > 1 (there are deliveries with trip)
4555
4556 -- delete the records from the temp table after ship confirm
4557
4558 -- bug 2760062
4559
4560 DELETE FROM mtl_material_transactions_temp
4561 WHERE wms_task_type = 7
4562 AND organization_id = p_organization_id
4563 AND content_lpn_id IN
4564 (SELECT outermost_lpn_id
4565 FROM wms_shipping_transaction_temp
4566 WHERE organization_id = p_organization_id
4567 AND dock_door_id = p_dock_door_id
4568 AND dock_appoint_flag = 'N'
4569 AND Nvl(direct_ship_flag,'N') = 'N');
4570
4571 delete from wms_shipping_transaction_temp
4572 where organization_id = p_organization_id
4573 and dock_door_id = p_dock_door_id
4574 and dock_appoint_flag = 'N'
4575 and nvl(direct_ship_flag,'N') = 'N';
4576
4577 print_label(l_del_rows, l_return_status);
4578 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4579 debug('print_label failed','SHIP_CONFIRM_LPN_DELIVERIES');
4580 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
4581 FND_MSG_PUB.ADD;
4582
4583 l_num_warnings := l_num_warnings + 1;
4584 END IF;
4585
4586 else -- close the trip stop corresponding if: p_trip_stop_id = 0
4587 IF l_debug = 1 THEN
4588 debug('p_trip_id: ' || p_trip_id, 'LPN_SHIP');
4589 END IF;
4590
4591 IF p_close_trip_flag = 'Y' OR l_close_trip_flag = 'Y' THEN
4592 IF l_debug = 1 THEN
4593 debug('User wants entire trip close. Getting drop-off stops','LPN_SHIP');
4594 END IF;
4595
4596 SELECT COUNT(DISTINCT wdl.pick_up_stop_id)
4597 INTO l_pick_up_count
4598 FROM wsh_trip_stops wts, wsh_delivery_legs wdl
4599 where wts.stop_id = wdl.pick_up_stop_id
4600 and wts.trip_id = p_trip_id;
4601
4602 debug('l_pick_up_count: ' || l_pick_up_count,'LPN_SHIP');
4603 IF l_pick_up_count = 1 then
4604 OPEN drop_off_stops(p_dock_appoint_flag => 'Y');
4605 l_del_index := 1;
4606 l_drop_off_stops.DELETE;
4607 LOOP
4608 FETCH drop_off_stops INTO l_drop_off_stop_id;
4609 EXIT WHEN drop_off_stops%notfound;
4610 l_drop_off_stops(l_del_index) := l_drop_off_stop_id;
4611 l_del_index := l_del_index + 1;
4612 END LOOP;
4613
4614 IF l_debug = 1 THEN
4615 debug('Finished getting drop-off stops','LPN_SHIP');
4616 debug('Total drop-off stops for current dock door: ' || l_drop_off_stops.COUNT,'LPN_SHIP');
4617 END IF;
4618 ELSE
4619 debug('Trip contains multiple pick-up stops','LPN_SHIP');
4620 END IF;
4621 END IF;
4622
4623 FOR i IN 1..l_del_rows.COUNT LOOP
4624 IF l_debug = 1 THEN
4625 debug('p_trip_stop_id is : ' || p_trip_stop_id, 'SHIP_CONFIRM_LPN_DELIVEREIS');
4626 debug('About to call wsh_deliveries_pub.delivery_action'
4627 || ' with delivery_id : ' || l_del_rows(i) || ' and ship_method_code: '
4628 || l_ship_method_tbl(i),'SHIP_CONFIRM_LPN_DELIVERIES');
4629 END IF;
4630
4631
4632 /*
4633 * GLOG-OTM Integration ..that we must pass ship method from Trip, if one
4634 * exists, to Delivery_action API */
4635
4636
4637 OPEN c_get_trip_ship_method(l_del_rows(i) );
4638 FETCH c_get_trip_ship_method INTO l_trip_trip_id, l_trip_ship_method_code;
4639
4640 IF (c_get_trip_ship_method%NOTFOUND) THEN
4641 l_trip_ship_method_code := l_ship_method_tbl(i);
4642 IF l_debug = 1 THEN
4643 debug('Delivery does not belong to any trip','SHIP_CONFIRM_LPN_DELIVERIES');
4644 END IF;
4645 END IF;
4646 CLOSE c_get_trip_ship_method;
4647
4648
4649 IF l_debug = 1 THEN
4650 debug('4:l_del_rows(i) : ' || l_del_rows(i)
4651 || ':l_trip_trip_id : ' || l_trip_trip_id
4652 || ':l_trip_ship_method_code: ' || l_trip_ship_method_code,
4653 'SHIP_CONFIRM_LPN_DELIVERIES');
4654 END IF;
4655
4656
4657 wsh_deliveries_pub.delivery_action
4658 (p_api_version_number => 1.0,
4659 p_init_msg_list => fnd_api.g_false,
4660 x_return_status => l_return_status,
4661 x_msg_count => l_msg_count,
4662 x_msg_data => l_msg_data,
4663 p_action_code => 'CONFIRM',
4664 p_delivery_id => l_del_rows(i),
4665 p_sc_action_flag => 'A',
4666 p_sc_intransit_flag => 'N',
4667 p_sc_close_trip_flag => 'N',
4668 p_sc_create_bol_flag => l_bol_flag, --Bug 5158964
4669 p_sc_stage_del_flag => 'N',
4670 p_sc_trip_ship_method => l_trip_ship_method_code, --l_ship_method_tbl(i) for GlogInt
4671 p_sc_actual_dep_date => l_actual_dep_date,
4672 p_sc_report_set_id => l_report_set_id,
4673 p_sc_defer_interface_flag => 'Y',
4674 x_trip_id => l_trip_id,
4675 x_trip_name => l_trip_name);
4676
4677 IF (l_return_status NOT IN ('S','W')) THEN
4678 IF l_debug = 1 THEN
4679 debug('wsh_deliveries_pub.delivery_action failed '
4680 || 'with status ' || l_return_status,'SHIP_CONFIRM_LPN_DELIVERIES');
4681 END IF;
4682
4683 ROLLBACK;
4684 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4685
4686 ELSIF l_return_status = 'W' THEN
4687 l_num_warnings := l_num_warnings + 1;
4688
4689 END IF;
4690 END LOOP;
4691
4692 IF (l_debug = 1) THEN
4693 debug('Calling change_status','LPN_SHIP');
4694 END IF;
4695
4696 l_stop_rows(1) := p_trip_stop_id;
4697 --patchset J. Shipping API cleanup
4698 IF p_close_trip_flag = 'Y' OR l_intransit_flag = 'Y' THEN
4699 wsh_trip_stops_pub.stop_action
4700 (p_api_version_number => 1.0,
4701 p_init_msg_list => G_TRUE,
4702 x_return_status => l_return_status,
4703 x_msg_count => l_msg_count,
4704 x_msg_data => l_msg_data,
4705 p_action_code => 'CLOSE',
4706 p_stop_id => p_trip_stop_id,
4707 p_actual_date => sysdate,
4708 p_defer_interface_flag =>NVL(l_defer_interface_flag,'N'));
4709 --patchset J. Shipping API cleanup
4710
4711 IF (l_debug = 1) THEN
4712 debug('return status:'||l_return_status, 'LPN_SHIP');
4713 END IF;
4714 if( l_return_status not in ('S', 'W') ) then
4715 IF (l_debug = 1) THEN
4716 debug('l_return_status is ' || l_return_status, 'Ship_Confirm');
4717 END IF;
4718 rollback;
4719 raise FND_API.G_EXC_UNEXPECTED_ERROR;
4720 ELSE -- l_return_status
4721
4722 IF l_return_status = 'W' THEN
4723 l_num_warnings := l_num_warnings + 1;
4724 END IF;
4725
4726 IF (p_close_trip_flag = 'Y' OR l_close_trip_flag = 'Y') AND l_pick_up_count = 1 THEN
4727 IF l_debug = 1 THEN
4728 debug('Call Shipping to close drop-off stops','LPN_SHIP');
4729 END IF;
4730
4731 FOR i IN 1..l_drop_off_stops.COUNT LOOP
4732 wsh_trip_stops_pub.stop_action
4733 (p_api_version_number => 1.0,
4734 p_init_msg_list => G_TRUE,
4735 x_return_status => l_return_status,
4736 x_msg_count => l_msg_count,
4737 x_msg_data => l_msg_data,
4738 p_action_code => 'CLOSE',
4739 p_stop_id => l_drop_off_stops(i),
4740 p_actual_date => sysdate,
4741 p_defer_interface_flag =>'Y');
4742
4743 IF l_debug = 1 THEN
4744 debug('wsh_trip_stops_actions.change_status return status: ' || l_return_status,'LPN_SHIP');
4745 END IF;
4746 IF l_return_status NOT IN ('S','W') THEN
4747 IF l_debug = 1 THEN
4748 debug('Could not close the drop-off stops. Let the transaction go through','LPN_SHIP');
4749 END IF;
4750
4751 ELSIF l_return_status = 'W' THEN
4752 l_num_warnings := l_num_warnings + 1;
4753
4754 END IF;
4755
4756 END LOOP;
4757 END IF;
4758 END IF;
4759
4760 -- delete the records from the temp table after ship confirm
4761 if (p_trip_id <> 0 ) THEN
4762
4763 -- bug 2760062
4764
4765 DELETE FROM mtl_material_transactions_temp
4766 WHERE wms_task_type = 7
4767 AND organization_id = p_organization_id
4768 AND content_lpn_id IN
4769 (SELECT outermost_lpn_id
4770 FROM wms_shipping_transaction_temp
4771 WHERE trip_id = p_trip_id
4772 AND organization_id = p_organization_id
4773 AND Nvl(direct_ship_flag,'N') = 'N');
4774
4775 delete from wms_shipping_transaction_temp where trip_id = p_trip_id
4776 and organization_id = p_organization_id
4777 and nvl(direct_ship_flag,'N') = 'N';
4778 ELSE --correspndong if: p_trip_id <> 0
4779
4780 -- bug 2760062
4781
4782 DELETE FROM mtl_material_transactions_temp
4783 WHERE wms_task_type = 7
4784 AND organization_id = p_organization_id
4785 AND content_lpn_id IN
4786 (SELECT outermost_lpn_id
4787 FROM wms_shipping_transaction_temp
4788 WHERE organization_id = p_organization_id
4789 AND dock_door_id = p_dock_door_id
4790 AND dock_appoint_flag = 'N'
4791 AND Nvl(direct_ship_flag,'N') = 'N');
4792
4793 delete from wms_shipping_transaction_temp
4794 where organization_id = p_organization_id
4795 and dock_door_id = p_dock_door_id
4796 and dock_appoint_flag = 'N'
4797 and nvl(direct_ship_flag,'N') = 'N';
4798 end if;
4799
4800 -- print the shipping labels
4801 print_label(l_del_rows, l_return_status);
4802 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4803 debug('print_label failed','SHIP_CONFIRM_LPN_DELIVERIES');
4804 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL');
4805 FND_MSG_PUB.ADD;
4806
4807 l_num_warnings := l_num_warnings + 1;
4808 END IF;
4809 end if; -- p_trip_id <> 0
4810 end if; --l_return_status in ('S','W')
4811 end if;
4812
4813 --If last return status is 'S' but there was a warning encountered before, setting x_return_status to 'W'
4814 IF ((x_return_status = 'S') AND (l_num_warnings > 0)) THEN
4815 x_return_status := 'W';
4816 END IF;
4817
4818 process_mobile_msg;
4819 x_msg_count := fnd_msg_pub.count_msg;
4820 x_msg_data := '';
4821 FOR i IN 1..x_msg_count LOOP
4822 fnd_msg_pub.get(p_encoded=>'F'
4823 ,p_msg_index => i
4824 ,p_data => l_msg_data
4825 ,p_msg_index_out => l_dummy_number);
4826 IF (l_debug = 1) THEN
4827 debug('Message ('|| i ||') : '|| l_msg_data,'SHIP_CONFIRM_LPN_DELIVERIES');
4828 END IF;
4829 IF length(x_msg_data || ' ' || l_msg_data) < 2000 THEN
4830 x_msg_data := x_msg_data || ' ' || l_msg_data;
4831 END IF;
4832 END LOOP;
4833 debug('Actual message pass back to java: ' || x_msg_data,'SHIP_CONFIRM_LPN_DELIVERIES');
4834 debug('Msg count passed back: ' || x_msg_count,'SHIP_CONFIRM_LPN_DELIVERIES');
4835
4836 EXCEPTION
4837 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4838 debug('Unexpected error raised: ' || SQLERRM, 'SHIP_CONFIRM_LPN_DELIVERIES');
4839 x_return_status := l_return_status;
4840
4841 --DHERRING Bug#5651219. Fix starts
4842 x_msg_count := FND_MSG_PUB.Count_msg;
4843 FOR i in 1..x_msg_count LOOP
4844 FND_MSG_PUB.get(p_encoded => FND_API.G_FALSE, p_msg_index => i, p_data=> l_tmp_buffer,
4845 p_msg_index_out => l_tmp_out);
4846 x_msg_data:=x_msg_data ||'|'|| l_tmp_buffer;
4847 END LOOP;
4848
4849 IF (l_debug = 1) THEN
4850 debug('inside EXCEPTION, l_msg_count is ' || x_msg_count, 'SHIP_CONFIRM_LPN_DELIVERIES');
4851 debug('inside EXCEPTION, x_msg_data is ' || x_msg_data, 'SHIP_CONFIRM_LPN_DELIVERIES');
4852 END IF;
4853 /* commented for DHERRING Bug#5651219
4854 wsh_util_core.get_messages
4855 (p_init_msg_list => 'Y',
4856 x_summary => l_msg_data,
4857 x_details => l_summary,
4858 x_count => l_msg_count);*/
4859 --DHERRING Bug#5651219. Fix Ends
4860
4861 debug('SHIP_CONFIRM_LPN_DELIVERIES raised exception with summary: '
4862 || l_summary, 'SHIP_CONFIRM_LPN_DELIVERIES');
4863 debug('SHIP_CONFIRM_LPN_DELIVERIES raised exception with messages: '
4864 || l_msg_data, 'SHIP_CONFIRM_LPN_DELIVERIES');
4865 debug('SHIP_CONFIRM_LPN_DELIVERIES raised exception with msg_count: '
4866 || l_msg_count, 'SHIP_CONFIRM_LPN_DELIVERIES');
4867 WHEN OTHERS THEN
4868 x_return_status := G_RET_STS_UNEXP_ERROR;
4869 IF l_debug = 1 THEN
4870 debug('Other exception raised: ' || SQLERRM, 'SHIP_CONFIRM_LPN_DELIVERIES');
4871 END IF;
4872 END SHIP_CONFIRM_LPN_DELIVERIES;
4873
4874 procedure get_serial_number_for_so(
4875 x_serial_lov out NOCOPY t_genref,
4876 p_inventory_item_id IN NUMBER,
4877 p_organization_id IN NUMBER,
4878 p_subinventory_code IN VARCHAR2,
4879 p_locator_id IN NUMBER,
4880 p_revision IN VARCHAR2,
4881 p_lot_number IN VARCHAR2,
4882 p_serial_number IN VARCHAR2) IS
4883 BEGIN
4884 open x_serial_lov for
4885 select serial_number, current_subinventory_code, current_locator_id, lot_number
4886 from mtl_serial_numbers
4887 where inventory_item_id = p_inventory_item_id
4888 and current_organization_id = p_organization_id
4889 and (group_mark_id is null or group_mark_id = -1)
4890 and ((nvl(current_subinventory_code,'@@@') = nvl(p_subinventory_code,'@@@')
4891 and nvl(current_locator_id,-1) = nvl(p_locator_id,-1)
4892 and nvl(lot_number,'@@@') = nvl(p_lot_number,'@@@')
4893 and nvl(revision,'@@@') = nvl(p_revision,'@@@')
4894 and current_status = 3)
4895 or current_status = 1)
4896 and serial_number like (p_serial_number)
4897 order by lpad(serial_number,20);
4898 END get_serial_number_for_so;
4899
4900 PROCEDURE insert_serial_numbers
4901 (x_status OUT NOCOPY VARCHAR2,
4902 p_fm_serial_number IN VARCHAR2,
4903 p_to_serial_number IN VARCHAR2,
4904 p_transaction_Temp_id IN NUMBER) IS
4905 l_status VARCHAR2(1) := 'S';
4906 l_fm_serial_number VARCHAR2(30) := p_fm_serial_number;
4907 l_to_serial_number VARCHAR2(30) := p_to_serial_number;
4908 l_serial_prefix VARCHAR2(30);
4909 l_user NUMBER;
4910 l_login_id NUMBER;
4911 BEGIN
4912
4913 l_user := fnd_global.user_id;
4914 l_login_id := fnd_global.login_id;
4915
4916 l_serial_prefix := rtrim(l_fm_serial_number, '0123456789');
4917
4918 insert into mtl_serial_numbers_temp
4919 (
4920 transaction_Temp_id,
4921 last_update_date,
4922 last_updated_by,
4923 creation_date,
4924 created_By,
4925 last_update_login,
4926 fm_serial_number,
4927 to_serial_number,
4928 serial_prefix
4929 ) values
4930 (
4931 p_transaction_temp_id,
4932 sysdate,
4933 l_user,
4934 sysdate,
4935 l_user,
4936 l_login_id,
4937 l_fm_serial_number,
4938 l_to_serial_number,
4939 l_serial_prefix
4940 );
4941
4942 x_status := l_status;
4943 EXCEPTION
4944 when others then
4945 x_status := 'E';
4946 END insert_Serial_Numbers;
4947
4948
4949
4950 procedure wms_installed_status(x_status OUT NOCOPY VARCHAR2) is
4951 l_wms_application_id constant number := 385;
4952 l_status Varchar2(10);
4953 l_industry varchar2(10);
4954 l_return_val boolean;
4955 begin
4956
4957 l_return_val := fnd_installation.get(
4958 appl_id => l_wms_application_id,
4959 dep_appl_id => l_wms_application_id,
4960 status => l_status,
4961 industry => l_industry);
4962 if( l_return_val = TRUE ) then
4963 x_status := l_status;
4964 else
4965 x_status := 'ERROR';
4966 end if;
4967 end wms_installed_status;
4968
4969 procedure GET_SERIAL_STATUS_CODE(x_serial_status_id OUT NOCOPY NUMBER,
4970 x_serial_status_code OUT NOCOPY VARCHAR2,
4971 p_organization_id IN NUMBER,
4972 p_inventory_item_id IN NUMBER) IS
4973 l_serial_status_id NUMBER;
4974 l_serial_status_code VARCHAR2(10);
4975 l_serial_status_enabled VARCHAR2(1);
4976 begin
4977 select nvl(msik.serial_status_enabled,'N'), nvl(msik.default_Serial_status_id, -1), mst.status_code
4978 into l_serial_status_enabled, l_serial_status_id, l_serial_status_code
4979 from mtl_system_items_kfv msik, mtl_material_statuses_vl mst
4980 where msik.organization_id = p_organization_id
4981 and msik.inventory_item_id = p_inventory_item_id
4982 and msik.default_serial_status_id = mst.status_id(+);
4983
4984 if( l_serial_status_enabled = 'N' ) then
4985 x_serial_status_id := -1;
4986 x_serial_status_code := 'NULL';
4987 else
4988 x_serial_status_id := l_serial_status_id;
4989 if( l_serial_status_id = -1 ) then
4990 x_serial_status_code := 'NULL';
4991 else
4992 x_serial_status_code := l_serial_status_code;
4993 end if;
4994 end if;
4995 end get_serial_status_code;
4996
4997 --patchset J. Shipping API cleanup
4998 --Calling procedure/function should get the message stack
4999 --This will only return a status
5000 PROCEDURE UNASSIGN_DELIVERY_LINE(
5001 p_delivery_detail_id IN NUMBER,
5002 x_return_status OUT NOCOPY VARCHAR2,
5003 p_delivery_id IN NUMBER DEFAULT NULL,
5004 p_commit_flag IN VARCHAR2 DEFAULT fnd_api.g_true) IS
5005 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5006 l_debug number;
5007
5008 /* Bug: 5585359: 10/09/06 Start*/
5009 l_action_prms wsh_interface_ext_grp.del_action_parameters_rectype;
5010 l_delivery_id_tab wsh_util_core.id_tab_type;
5011 l_delivery_out_rec wsh_interface_ext_grp.del_action_out_rec_type;
5012 l_planned_flag VARCHAR2(1);
5013 /* Bug: 5585359: 10/09/06 - End*/
5014
5015 l_delivery_details wsh_delivery_details_pub.id_tab_type;
5016 l_msg_count NUMBER;
5017 l_msg_data VARCHAR2(2000);
5018 BEGIN
5019 IF g_debug IS NULL THEN
5020 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5021 END IF;
5022 l_debug := g_debug;
5023
5024 l_delivery_details(1) := p_delivery_detail_id;
5025
5026 /* Bug: 5585359: 10/09/06 */
5027 l_delivery_id_tab(1) := p_delivery_id;
5028
5029 IF l_debug = 1 THEN
5030 debug('Calling WSH_DELIVERY_DETAILS_PUB.detail_to_delivery ', 'UNASSIGN_DELIVERY_LINE');
5031 debug('delivery_detail_id : ' || p_delivery_detail_id, 'UNASSIGN_DELIVERY_LINE');
5032 debug('delivery_id : ' || p_delivery_id, 'UNASSIGN_DELIVERY_LINE');
5033 END IF;
5034 -- {{ Test a case where delivery exist before ship confirm }}
5035
5036
5037 /* Bug: 5585359: 10/09/06 - Start*/
5038
5039 IF l_delivery_id_tab(1) is NOT NULL
5040 THEN
5041 SELECT PLANNED_FLAG
5042 INTO L_PLANNED_FLAG
5043 FROM wsh_new_deliveries
5044 WHERE delivery_id = l_delivery_id_tab(1);
5045 ELSE
5046
5047 -- {{ Test a case where delivery does not exist before ship confirm, to see,}}
5048 -- {{ if this will return no_data_found? }}
5049
5050 -- The following sql is required as it is not possible
5051 -- to use the unfirm shipping api without the delivery id
5052 -- being known.
5053
5054 SELECT delivery_id
5055 INTO l_delivery_id_tab(1)
5056 FROM wsh_delivery_assignments
5057 WHERE delivery_detail_id = l_delivery_details(1);
5058
5059 BEGIN
5060 SELECT wnd.planned_flag
5061 INTO l_planned_flag
5062 FROM wsh_new_deliveries wnd,
5063 wsh_delivery_details wdd,
5064 wsh_delivery_assignments wda
5065 WHERE wdd.delivery_detail_id = l_delivery_details(1)
5066 AND wda.delivery_detail_id = wdd.delivery_detail_id
5067 AND wda.delivery_id = wnd.delivery_id;
5068 EXCEPTION
5069 WHEN NO_DATA_FOUND THEN
5070 IF l_debug = 1 THEN
5071 debug('Calling WSH_DELIVERY_DETAILS_PUB.detail_to_delivery ', 'UNASSIGN_DELIVERY_LINE');
5072 END IF;
5073 null; -- It is OK
5074 END;
5075 END IF;
5076 IF l_debug = 1 THEN
5077 debug('l_planned_flag: ' || l_planned_flag, 'UNASSIGN_DELIVERY_LINE');
5078 END IF;
5079 IF l_planned_flag = 'Y' THEN
5080 l_action_prms.caller := 'WMS';
5081 l_action_prms.action_code := 'UNPLAN';
5082
5083 IF l_debug = 1 THEN
5084 DEBUG('Unfirm delivery for unassignment','UNASSIGN_DELIVERY_LINE');
5085 END IF;
5086 wsh_interface_ext_grp.delivery_action
5087 (p_api_version_number => 1.0,
5088 p_init_msg_list => fnd_api.g_false,
5089 p_commit => fnd_api.g_false,
5090 p_action_prms => l_action_prms,
5091 p_delivery_id_tab => l_delivery_id_tab,
5092 x_delivery_out_rec => l_delivery_out_rec,
5093 x_return_status => x_return_status,
5094 x_msg_count => l_msg_count,
5095 x_msg_data => l_msg_data);
5096
5097 IF x_return_status IN (G_RET_STS_ERROR,G_RET_STS_UNEXP_ERROR) THEN
5098 IF l_debug = 1 THEN
5099 debug('Unfirming delivery failed!','UNASSIGN_DELIVERY_LINE');
5100 debug('msg_data: ' || l_msg_data,'UNASSIGN_DELIVERY_LINE');
5101 END IF;
5102 RAISE fnd_api.g_exc_unexpected_error;
5103 END IF;
5104 END IF;
5105
5106 IF l_debug = 1 THEN
5107 debug('Unfirmed the Delivery !','UNASSIGN_DELIVERY_LINE');
5108 END IF;
5109 /* Bug: 5585359: 10/09/06 - End*/
5110
5111 WSH_DELIVERY_DETAILS_PUB.detail_to_delivery
5112 (p_api_version => 1.0,
5113 p_init_msg_list => G_FALSE,
5114 p_commit => p_commit_flag,
5115 x_return_status => x_return_status,
5116 x_msg_count => l_msg_count,
5117 x_msg_data => l_msg_data,
5118 p_tabofdeldets => l_delivery_details,
5119 p_action => 'UNASSIGN');
5120
5121 IF l_debug = 1 THEN
5122 debug('WSH_DELIVERY_DETAILS_PUB.detail_to_delivery '
5123 || 'return status: ' || x_return_status
5124 , 'UNASSIGN_DELIVERY_LINE');
5125
5126 IF x_return_status <> 'S' THEN
5127 debug('msg_count : ' || l_msg_count
5128 || ' msg_data : ' || l_msg_data
5129 , 'UNASSIGN_DELIVERY_LINE');
5130 END IF;
5131 END IF;
5132
5133 /* Bug: 5585359: 10/09/06 - Start*/
5134
5135 l_action_prms.caller := 'WMS';
5136 l_action_prms.action_code := 'PLAN';
5137 IF l_debug = 1 THEN
5138 DEBUG('firm delivery after unassignment','UNASSIGN_DELIVERY_LINE');
5139 END IF;
5140 wsh_interface_ext_grp.delivery_action
5141 (p_api_version_number => 1.0,
5142 p_init_msg_list => fnd_api.g_false,
5143 p_commit => p_commit_flag,
5144 p_action_prms => l_action_prms,
5145 p_delivery_id_tab => l_delivery_id_tab,
5146 x_delivery_out_rec => l_delivery_out_rec,
5147 x_return_status => x_return_status,
5148 x_msg_count => l_msg_count,
5149 x_msg_data => l_msg_data);
5150
5151 IF l_debug = 1 THEN
5152 debug('firm delivery after unassignment status := '
5153 || 'return status: ' || x_return_status
5154 , 'UNASSIGN_DELIVERY_LINE');
5155
5156 IF x_return_status <> 'S' THEN
5157 debug('msg_count : ' || l_msg_count
5158 || ' msg_data : ' || l_msg_data
5159 , 'UNASSIGN_DELIVERY_LINE');
5160 END IF;
5161 END IF;
5162
5163 /* Bug: 5585359: 10/09/06 - End*/
5164
5165 END UNASSIGN_DELIVERY_LINE;
5166 --\Shipping API cleanup
5167
5168 -- Update the subinventory and locator for the delivery detail lines
5169 -- within an LPN.
5170 -- Added for LPN consolidation from different staging lanes
5171
5172 PROCEDURE update_wdd_loc_by_lpn
5173 (x_return_status OUT NOCOPY VARCHAR2,
5174 p_lpn_id NUMBER,
5175 p_subinventory_code VARCHAR2,
5176 p_locator_id NUMBER)
5177 IS
5178 l_delivery_detail_id NUMBER;
5179 l_oe_order_header_id NUMBER;
5180 l_oe_order_line_id NUMBER;
5181 l_released_status VARCHAR2(1);
5182 l_organization_id NUMBER;
5183
5184 l_shipping_attr_tab WSH_INTERFACE.ChangedAttributeTabType;
5185 l_wdd_counter NUMBER := 1;
5186
5187 l_progress VARCHAR2(10);
5188 l_return_status VARCHAR2(1);
5189
5190 CURSOR cur_delivery_details
5191 IS
5192 SELECT wdd.delivery_detail_id,
5193 ol.header_id,
5194 ol.line_id,
5195 wdd.released_status,
5196 mol.organization_id
5197 FROM wsh_delivery_details_ob_grp_v wdd,
5198 wsh_delivery_assignments_v wda,
5199 wsh_delivery_details_ob_grp_v wdd2,
5200 wms_license_plate_numbers lpn,
5201 mtl_txn_request_lines mol,
5202 oe_order_lines_all ol
5203 WHERE lpn.outermost_lpn_id = p_lpn_id
5204 AND wdd2.lpn_id = lpn.lpn_id
5205 AND wdd2.released_status = 'X' -- For LPN reuse ER : 6845650
5206 AND wdd2.delivery_detail_id = wda.parent_delivery_detail_id
5207 AND wdd.delivery_detail_id = wda.delivery_detail_id
5208 AND mol.line_id = wdd.move_order_line_id
5209 AND ol.line_id = wdd.source_line_id;
5210
5211
5212 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5213 l_debug number;
5214 BEGIN
5215 l_progress := '10';
5216 IF g_debug IS NULL THEN
5217 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5218 END IF;
5219 l_debug := g_debug;
5220
5221 IF (l_debug = 1) THEN
5222 debug('update_wdd_loc_by_lpn 10 - p_lpn_id = '||p_lpn_id,'WMS_SHIPPING_TRANSACTION_PUB');
5223 debug('p_subinventory_code = ' || p_subinventory_code, 'WMS_SHIPPING_TRANSACTION_PUB');
5224 debug('p_locator_id = ' || p_locator_id, 'WMS_SHIPPING_TRANSACTION_PUB');
5225 END IF;
5226
5227 SAVEPOINT update_wdd_loc_sp;
5228 x_return_status := FND_API.G_RET_STS_SUCCESS;
5229
5230 OPEN cur_delivery_details;
5231
5232 l_progress := '20';
5233
5234 LOOP
5235 FETCH cur_delivery_details
5236 INTO
5237 l_delivery_detail_id,
5238 l_oe_order_header_id,
5239 l_oe_order_line_id,
5240 l_released_status,
5241 l_organization_id;
5242 EXIT WHEN cur_delivery_details%notfound;
5243
5244 l_progress := '30';
5245
5246 IF (l_debug = 1) THEN
5247 debug('update_wdd_loc_by_lpn 15 - l_delivery_detail_id = '
5248 ||l_delivery_detail_id,'WMS_SHIPPING_TRANSACTION_PUB');
5249 debug('l_oe_order_header_id = '||l_oe_order_header_id,'WMS_SHIPPING_TRANSACTION_PUB');
5250 debug('l_oe_order_line_id = '||l_oe_order_line_id,'WMS_SHIPPING_TRANSACTION_PUB');
5251 debug('l_organization_id = '||l_organization_id,'WMS_SHIPPING_TRANSACTION_PUB');
5252 debug('l_released_status = '||l_released_status,'WMS_SHIPPING_TRANSACTION_PUB');
5253 END IF;
5254
5255 l_shipping_attr_tab(l_wdd_counter).source_header_id := l_oe_order_header_id;
5256 l_shipping_attr_tab(l_wdd_counter).source_line_id := l_oe_order_line_id;
5257 l_shipping_attr_tab(l_wdd_counter).ship_from_org_id := l_organization_id;
5258 l_shipping_attr_tab(l_wdd_counter).released_status := l_released_status;
5259 l_shipping_attr_tab(l_wdd_counter).delivery_detail_id := l_delivery_detail_id;
5260 l_shipping_attr_tab(l_wdd_counter).action_flag := 'U';
5261 l_shipping_attr_tab(l_wdd_counter).subinventory := p_subinventory_code;
5262 l_shipping_attr_tab(l_wdd_counter).locator_id := p_locator_id;
5263 l_shipping_attr_tab(l_wdd_counter).transfer_lpn_id := p_lpn_id;
5264
5265 IF (l_debug = 1) THEN
5266 debug('Disassociate delivery detail with the old lpn, delivery detail id = '
5267 ||l_shipping_attr_tab(l_wdd_counter).delivery_detail_id, 'WMS_SHIPPING_TRANSACTION_PUB');
5268 END IF;
5269
5270 WSH_DELIVERY_DETAILS_ACTIONS.Unassign_Detail_from_Cont
5271 ( P_DETAIL_ID => l_shipping_attr_tab(l_wdd_counter).delivery_detail_id,
5272 X_RETURN_STATUS => l_return_status );
5273 if (l_return_status <> fnd_api.g_ret_sts_success) then
5274 IF (l_debug = 1) THEN
5275 debug('Error Unassign_Detail_from_Cont'|| l_return_status, 'WMS_SHIPPING_TRANSACTION_PUB');
5276 END IF;
5277 FND_MESSAGE.SET_NAME('INV', 'INV_UNASSIGN_DEL_FAILURE');
5278 FND_MSG_PUB.ADD;
5279 RAISE FND_API.G_EXC_ERROR;
5280 end if;
5281
5282 l_wdd_counter := l_wdd_counter + 1;
5283 END LOOP;
5284
5285 l_progress := '40';
5286
5287 CLOSE cur_delivery_details;
5288
5289
5290 IF (l_debug = 1) THEN
5291 debug('update_wdd_loc_by_lpn 20 - l_wdd_counter = ' || l_wdd_counter, 'WMS_SHIPPING_TRANSACTION_PUB');
5292 END IF;
5293
5294 l_progress := '50';
5295
5296 WSH_INTERFACE.Update_Shipping_Attributes
5297 (p_source_code => 'INV',
5298 p_changed_attributes => l_shipping_attr_tab,
5299 x_return_status => l_return_status
5300 );
5301
5302 IF (l_debug = 1) THEN
5303 debug('update_wdd_loc_by_lpn 25 - WSH_INTERFACE.Update_Shipping_Attributes returns : '
5304 ||l_return_status, 'WMS_SHIPPING_TRANSACTION_PUB');
5305 END IF;
5306
5307 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5308 IF (l_debug = 1) THEN
5309 debug('update_wdd_loc_by_lpn 30 - return expected error from update_shipping_attributes',
5310 'WMS_SHIPPING_TRANSACTION_PUB');
5311 END IF;
5312
5313 RAISE FND_API.G_EXC_ERROR;
5314
5315 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5316 IF (l_debug = 1) THEN
5317 debug('update_wdd_loc_by_lpn 40 - return unexpected error from update_shipping_attributes',
5318 'WMS_SHIPPING_TRANSACTION_PUB');
5319 END IF;
5320
5321 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5322 END IF;
5323
5324 l_progress := '60';
5325
5326 IF (l_debug = 1) THEN
5327 debug('update_wdd_loc_by_lpn 50 - complete','WMS_SHIPPING_TRANSACTION_PUB');
5328 END IF;
5329
5330 EXCEPTION
5331 WHEN fnd_api.g_exc_error THEN
5332 x_return_status := fnd_api.g_ret_sts_error;
5333 ROLLBACK TO update_wdd_loc_sp;
5334
5335 IF cur_delivery_details%isopen THEN
5336 CLOSE cur_delivery_details;
5337 END IF;
5338
5339 FND_MESSAGE.SET_NAME('WMS', 'WMS_UPDATE_WDD_LOC_FAIL');
5340 FND_MSG_PUB.ADD;
5341
5342 IF (l_debug = 1) THEN
5343 debug('update_wdd_loc_by_lpn 60 - expected error', 'WMS_SHIPPING_TRANSACTION_PUB');
5344 END IF;
5345
5346 WHEN fnd_api.g_exc_unexpected_error THEN
5347 x_return_status := fnd_api.g_ret_sts_unexp_error;
5348 ROLLBACK TO update_wdd_loc_sp;
5349
5350 IF cur_delivery_details%isopen THEN
5351 CLOSE cur_delivery_details;
5352 END IF;
5353
5354 FND_MESSAGE.SET_NAME('WMS', 'WMS_UPDATE_WDD_LOC_FAIL');
5355 FND_MSG_PUB.ADD;
5356
5357 IF (l_debug = 1) THEN
5358 debug('update_wdd_loc_by_lpn 65 - unexpected error', 'WMS_SHIPPING_TRANSACTION_PUB');
5359 END IF;
5360
5361 WHEN OTHERS THEN
5362 ROLLBACK TO update_wdd_loc_sp;
5363 x_return_status := fnd_api.g_ret_sts_unexp_error ;
5364 IF cur_delivery_details%isopen THEN
5365 CLOSE cur_delivery_details;
5366 END IF;
5367
5368 IF (l_debug = 1) THEN
5369 debug('update_wdd_loc_by_lpn 70 - other error', 'WMS_SHIPPING_TRANSACTION_PUB');
5370 END IF;
5371
5372 FND_MESSAGE.SET_NAME('WMS', 'WMS_UPDATE_WDD_LOC_FAIL');
5373 FND_MSG_PUB.ADD;
5374
5375 IF SQLCODE IS NOT NULL THEN
5376 inv_mobile_helper_functions.sql_error('WMS_SHIPPING_TRANSACTION_PUB.update_wdd_loc_by_lpn',
5377 l_progress, SQLCODE);
5378 END IF;
5379
5380 END update_wdd_loc_by_lpn;
5381
5382 PROCEDURE GET_LOADED_LPN_LOV(x_lpn_lov out NOCOPY t_genref,
5383 p_organization_id IN NUMBER,
5384 p_dock_door_id IN NUMBER,
5385 p_lpn IN VARCHAR2)
5386 IS
5387 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5388 l_debug number;
5389 BEGIN
5390 IF g_debug IS NULL THEN
5391 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5392 END IF;
5393 l_debug := g_debug;
5394
5395 IF (l_debug = 1) THEN
5396 debug( 'Org ID : '||p_organization_id||' Dock Door : '||p_dock_door_id, 'get_loaded_lpn_lov');
5397 END IF;
5398 open x_lpn_lov for
5399 select distinct wlpn.license_plate_number, wlpn.lpn_id,
5400 wlpn.subinventory_code, milk.concatenated_segments
5401 from wms_license_plate_numbers wlpn,
5402 wms_shipping_transaction_temp wstt,
5403 mtl_item_locations_kfv milk
5404 WHERE wlpn.organization_id = wstt.organization_id
5405 AND wlpn.organization_id = p_organization_id
5406 AND wlpn.lpn_id = wstt.outermost_lpn_id
5407 and wlpn.lpn_context = wms_globals.lpn_loaded_for_shipment
5408 AND wstt.dock_door_id = p_dock_door_id
5409 AND nvl(wstt.direct_ship_flag,'N') = 'N'
5410 AND milk.organization_id = wlpn.organization_id
5411 AND milk.inventory_location_id = wlpn.locator_id
5412 and wlpn.license_plate_number like (p_lpn)
5413 order by wlpn.license_plate_number;
5414 END get_loaded_lpn_lov;
5415
5416 PROCEDURE GET_LOADED_DOCK_DOORS(x_dock_door_LOV OUT NOCOPY t_genref,
5417 p_organization_id in NUMBER,
5418 p_dock_door IN VARCHAR2) IS
5419 BEGIN
5420 --Bug# 2780663: Dock Door LOV should show only physical locators. (.)s at the positions of Project and Task
5421 -- segments should be suppressed from the KFV in the LOV. Alias "milk_concatenated_segments"
5422 -- is used to avoid "unambiguous column name" error
5423 open x_dock_door_lov for
5424 select DISTINCT milk.inventory_location_id,
5425 inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id)
5426 milk_concatenated_segments,
5427 0, milk.organization_id,
5428 0,0,'','',is_loaded(p_organization_id,milk.inventory_location_id,'N')
5429 ,''
5430 from mtl_item_locations_kfv milk
5431 , wms_shipping_transaction_temp wstt
5432 where inventory_location_type = 1
5433 and milk.organization_id = p_organization_id
5434 AND milk.organization_id = wstt.organization_id
5435 AND milk.inventory_location_id = wstt.dock_door_id
5436 and inv_project.get_locsegs(milk.inventory_location_id, milk.organization_id) like (p_dock_door)
5437 order by milk_concatenated_segments;
5438
5439 END GET_LOADED_DOCK_DOORS;
5440
5441 PROCEDURE lpn_unload(p_organization_id IN NUMBER,
5442 p_outermost_lpn_id IN NUMBER,
5443 x_error_code OUT NOCOPY NUMBER)
5444 IS
5445 l_delivery_detail_id NUMBER;
5446 CURSOR delivery_details IS
5447 SELECT delivery_detail_id
5448 FROM wms_shipping_transaction_temp
5449 WHERE organization_id = p_organization_id
5450 AND nvl(direct_ship_flag,'N') = 'N'
5451 AND outermost_lpn_id = p_outermost_lpn_id;
5452
5453 l_index NUMBER;
5454 l_detail_attributes WSH_DELIVERY_DETAILS_PUB.ChangedAttributeTabType;
5455 l_return_status VARCHAR2(1);
5456 l_msg_data VARCHAR2(2000);
5457 l_msg_count NUMBER;
5458
5459 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5460 l_debug number;
5461
5462 BEGIN
5463 IF g_debug IS NULL THEN
5464 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5465 END IF;
5466 l_debug := g_debug;
5467
5468 x_error_code := 0;
5469 IF (l_debug = 1) THEN
5470 debug('In lpn_unload', 'LPN_UNLOAD');
5471 END IF;
5472
5473 --update lpn_context
5474 UPDATE wms_license_plate_numbers
5475 SET lpn_context = wms_globals.lpn_context_picked,
5476 last_update_date = Sysdate,
5477 last_updated_by = fnd_global.user_id
5478 WHERE organization_id = p_organization_id
5479 AND outermost_lpn_id = p_outermost_lpn_id;
5480
5481 --patchset J. Shipping API cleanup
5482 --update shipped_quantity
5483 l_index := 1;
5484 l_detail_attributes.DELETE;
5485 FOR l_delivery_detail_id IN delivery_details LOOP
5486
5487 l_detail_attributes(l_index).shipped_quantity := NULL;
5488 l_detail_attributes(l_index).delivery_detail_id :=
5489 l_delivery_detail_id.delivery_detail_id;
5490
5491 l_index := l_index + 1;
5492 END LOOP;
5493
5494 IF l_debug = 1 THEN
5495 debug('About to call wsh_delivery_details_pub.update_shipping_attributes','LPN_UNLOAD');
5496 debug('l_detail_attributes count: ' || l_detail_attributes.COUNT,'LPN_UNLOAD');
5497 END IF;
5498
5499 wsh_delivery_details_pub.update_shipping_attributes
5500 (p_api_version_number => 1.0,
5501 p_init_msg_list => G_TRUE,
5502 p_commit => G_FALSE,
5503 x_return_status => l_return_status,
5504 x_msg_count => l_msg_count,
5505 x_msg_data => l_msg_data,
5506 p_changed_attributes => l_detail_attributes,
5507 p_source_code => 'OE');
5508
5509 IF l_return_status <> G_RET_STS_SUCCESS THEN
5510 IF l_debug = 1 THEN
5511 debug('wsh_delivery_details_pub.update_shipping_attributes failed'
5512 || ' with status: ' || l_return_status, 'LPN_UNLOAD');
5513 END IF;
5514 RAISE fnd_api.g_exc_unexpected_error;
5515 END IF;
5516 --\Shipping API cleanup
5517
5518 --Patchset J LPN hierarchy
5519
5520 --Release 12: LPN Synchronize
5521 -- The following code of populating shipping with LPN hierarchy
5522 -- is not necessary because LPN hierarchy is in sync between WMS and WSH
5523 -- before the load/unload stage
5524 -- Removed the call to container_nesting
5525
5526 --Clean up data for unloading
5527 DELETE FROM mtl_material_transactions_temp
5528 WHERE wms_task_type = 7
5529 AND organization_id = p_organization_id
5530 AND content_lpn_id = p_outermost_lpn_id;
5531
5532 DELETE FROM wms_shipping_transaction_temp
5533 WHERE organization_id = p_organization_id
5534 AND outermost_lpn_id = p_outermost_lpn_id
5535 and nvl(direct_ship_flag,'N') = 'N';
5536
5537 -- Commit if no errors
5538 COMMIT;
5539
5540 EXCEPTION
5541 WHEN fnd_api.g_exc_unexpected_error THEN
5542 x_error_code := 9999;
5543 ROLLBACK;
5544 WHEN OTHERS THEN
5545 x_error_code := 9999;
5546 ROLLBACK;
5547 IF (l_debug = 1) THEN
5548 debug('Error in lpn_unload : '||SQLERRM, 'LPN_UNLOAD');
5549 END IF;
5550
5551 END lpn_unload;
5552
5553 PROCEDURE nontransactable_item_check(x_nt_item OUT NOCOPY t_genref,
5554 p_trip_id IN NUMBER,
5555 p_dock_door_id IN NUMBER,
5556 p_organization_id IN NUMBER,
5557 x_nt_count OUT NOCOPY NUMBER)
5558 IS
5559 l_count NUMBER;
5560 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5561 l_debug number;
5562 BEGIN
5563 IF g_debug IS NULL THEN
5564 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5565 END IF;
5566 l_debug := g_debug;
5567
5568 IF (l_debug = 1) THEN
5569 Debug( 'In Non Transactable Item Check', 'NONTRANSACTABLE_ITEM_CHECK');
5570 END IF;
5571 x_nt_count := 0;
5572 l_count := 0;
5573
5574 IF (l_debug = 1) THEN
5575 Debug( 'p_dock_door_id is ' || p_dock_door_id, 'NONTRANSACTABLE_ITEM_CHECK');
5576 Debug( 'p_organization_id is ' || p_organization_id, 'NONTRANSACTABLE_ITEM_CHECK');
5577 END IF;
5578
5579 IF ( p_trip_id <> 0 ) THEN
5580 IF (l_debug = 1) THEN
5581 Debug( 'p_trip_id is ' || p_trip_id, 'NONTRANSACTABLE_ITEM_CHECK');
5582 END IF;
5583 BEGIN
5584 SELECT COUNT(*)
5585 INTO l_count
5586 FROM wsh_delivery_details_ob_grp_v wdd,
5587 wsh_delivery_assignments_v wda,
5588 wsh_new_deliveries_ob_grp_v wnd,
5589 wsh_delivery_legs_ob_grp_v wdl,
5590 wsh_trip_Stops_ob_grp_v pickup_stop,
5591 mtl_system_items_kfv msik
5592 WHERE wnd.delivery_id = wda.delivery_id
5593 AND wda.delivery_id = wdl.delivery_id
5594 AND wda.delivery_detail_id = wdd.delivery_detail_id
5595 AND wdl.pick_up_stop_id = pickup_stop.stop_id
5596 AND pickup_stop.trip_id = p_trip_id
5597 AND wdd.lpn_id IS NULL
5598 AND wdd.inventory_item_id = msik.inventory_item_id
5599 AND wdd.organization_id = p_organization_id
5600 AND wdd.organization_id = msik.organization_id
5601 AND msik.mtl_transactions_enabled_flag = 'N';
5602
5603 IF l_count > 0 THEN
5604 x_nt_count := l_count;
5605 END IF;
5606 EXCEPTION
5607 WHEN NO_DATA_FOUND THEN
5608 OPEN x_nt_item FOR SELECT 1 FROM dual;
5609 RETURN;
5610 END;
5611 OPEN x_nt_item FOR
5612 SELECT wnd.name,
5613 wdd.delivery_detail_id,
5614 wdd.inventory_item_id,
5615 wdd.requested_quantity,
5616 wdd.requested_quantity_uom,
5617 msik.concatenated_segments,
5618 msik.description
5619 FROM wsh_delivery_details_ob_grp_v wdd,
5620 wsh_delivery_assignments_v wda,
5621 wsh_new_deliveries_ob_grp_v wnd,
5622 wsh_delivery_legs_ob_grp_v wdl,
5623 wsh_trip_stops_ob_grp_v pickup_stop,
5624 mtl_system_items_kfv msik
5625 WHERE wnd.delivery_id = wda.delivery_id
5626 AND wda.delivery_id = wdl.delivery_id
5627 AND wda.delivery_detail_id = wdd.delivery_detail_id
5628 AND wdl.pick_up_stop_id = pickup_stop.stop_id
5629 AND pickup_stop.trip_id = p_trip_id
5630 AND wdd.lpn_id IS NULL
5631 AND wdd.inventory_item_id = msik.inventory_item_id
5632 AND wdd.organization_id = p_organization_id
5633 AND wdd.organization_id = msik.organization_id
5634 AND msik.mtl_transactions_enabled_flag = 'N';
5635 ELSE
5636 BEGIN
5637 SELECT COUNT(*)
5638 INTO l_count
5639 FROM wsh_delivery_details_ob_grp_v wdd,
5640 wsh_delivery_assignments_v wda,
5641 mtl_system_items_kfv
5642 msik, wsh_new_deliveries_ob_grp_v wnd
5643 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
5644 AND wdd.lpn_id IS NULL
5645 AND wda.delivery_id IN (SELECT DISTINCT delivery_id
5646 FROM wms_shipping_transaction_temp
5647 WHERE dock_door_id = p_dock_door_id
5648 AND organization_id = p_organization_id
5649 AND dock_appoint_flag = 'N'
5650 AND delivery_id IS NOT NULL
5651 UNION
5652 SELECT DISTINCT wdl.delivery_id
5653 from wsh_delivery_legs_ob_grp_v wdl,
5654 wms_shipping_transaction_temp wstt,
5655 wsh_trip_stops_ob_grp_v wts
5656 WHERE wdl.pick_up_stop_id = wts.stop_id
5657 AND wts.trip_id = wstt.trip_id
5658 AND wstt.dock_door_id = p_dock_door_id
5659 AND wstt.organization_id = p_organization_id
5660 AND wstt.dock_appoint_flag = 'N'
5661 AND nvl(wstt.direct_ship_flag,'N') = 'N')
5662 AND wda.delivery_id = wnd.delivery_id
5663 AND wdd.organization_id = p_organization_id
5664 AND wdd.inventory_item_id = msik.inventory_item_id
5665 AND wdd.organization_id = msik.organization_id
5666 AND msik.mtl_transactions_enabled_flag = 'N';
5667
5668 IF l_count > 0 THEN
5669 x_nt_count := l_count;
5670 END IF;
5671 EXCEPTION
5672 WHEN NO_DATA_FOUND THEN
5673 OPEN x_nt_item FOR SELECT 1 FROM dual;
5674 RETURN;
5675 END;
5676 OPEN x_nt_item FOR
5677 SELECT wnd.name,
5678 wdd.delivery_detail_id,
5679 wdd.inventory_item_id,
5680 wdd.requested_quantity,
5681 wdd.requested_quantity_uom,
5682 msik.concatenated_segments,
5683 msik.description
5684 FROM wsh_delivery_details_ob_grp_v wdd,
5685 wsh_delivery_assignments_v wda,
5686 mtl_system_items_kfv
5687 msik, wsh_new_deliveries_ob_grp_v wnd
5688 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
5689 AND wdd.lpn_id IS NULL
5690 AND wda.delivery_id IN (SELECT DISTINCT delivery_id
5691 FROM wms_shipping_transaction_temp
5692 WHERE dock_door_id = p_dock_door_id
5693 AND organization_id = p_organization_id
5694 AND dock_appoint_flag = 'N'
5695 AND nvl(direct_ship_flag,'N') = 'N'
5696 AND delivery_id IS NOT NULL
5697 UNION
5698 SELECT DISTINCT wdl.delivery_id
5699 FROM wsh_delivery_legs_ob_grp_v wdl,
5700 wms_shipping_transaction_temp wstt,
5701 wsh_trip_stops_ob_grp_v wts
5702 WHERE wdl.pick_up_stop_id = wts.stop_id
5703 AND wts.trip_id = wstt.trip_id
5704 AND wstt.dock_door_id = p_dock_door_id
5705 AND wstt.organization_id = p_organization_id
5706 AND wstt.dock_appoint_flag = 'N'
5707 AND nvl(direct_ship_flag,'N') = 'N')
5708 AND wda.delivery_id = wnd.delivery_id
5709 AND wdd.organization_id = p_organization_id
5710 AND wdd.inventory_item_id = msik.inventory_item_id
5711 AND wdd.organization_id = msik.organization_id
5712 AND msik.mtl_transactions_enabled_flag = 'N';
5713 END IF;
5714 END nontransactable_item_check;
5715
5716
5717 /* Direct Shipping */
5718
5719 PROCEDURE get_directshiplpn_lov (
5720 x_lpn OUT NOCOPY t_genref
5721 , p_organization_id IN NUMBER
5722 , p_lpn IN VARCHAR2) IS
5723 BEGIN
5724
5725 OPEN x_lpn FOR
5726 SELECT wlpn.license_plate_number
5727 , wlpn.lpn_id
5728 , wlpn.inventory_item_id
5729 , msi.concatenated_segments
5730 , wlpn.gross_weight
5731 , wlpn.gross_weight_uom_code
5732 , wlpn.tare_weight
5733 , wlpn.tare_weight_uom_code
5734 FROM wms_license_plate_numbers wlpn
5735 , mtl_system_items_kfv msi
5736 WHERE wlpn.organization_id = p_organization_id
5737 AND wlpn.license_plate_number LIKE (p_lpn)
5738 AND wlpn.lpn_context = 1 /* Resides in Inventory */
5739 AND wlpn.parent_lpn_id is null
5740 AND wlpn.inventory_item_id = msi.inventory_item_id(+)
5741 AND msi.organization_id(+) = wlpn.organization_id
5742 ORDER BY upper (wlpn.license_plate_number);
5743
5744 END get_directshiplpn_lov;
5745
5746 /* Bug#
5747 * In OrderLOV.java setReturnValues(), position 5 is fetched into Customer Id
5748 * and position 6 is fetched into Customer Number. While here in the
5749 * Select statement, they are swapped (6, 5 positions).
5750 * In setReturnValues(), Long.parseLong() is used for 5th position field
5751 * which is Customer Number-Varchar. This fails if Customer Number has
5752 * alphanumeric characters. Customer Id is made position 5 and Customer Number
5753 * for position 6 as the resolution.
5754 */
5755 PROCEDURE get_order_lov(
5756 x_order_lov OUT NOCOPY t_genref
5757 , p_org_id IN NUMBER
5758 , p_order IN VARCHAR2) IS
5759
5760 BEGIN
5761 open x_order_lov FOR
5762 select distinct wdd.source_header_number
5763 , wdd.source_header_id
5764 , otl.name
5765 , wdd.source_header_type_id
5766 , c.party_name
5767 , hca.cust_account_id
5768 , c.party_number
5769 from wsh_delivery_details_ob_grp_v wdd
5770 --, R12 TCA changes ra_customers c -- added the following tables instead
5771 , hz_parties c , hz_cust_accounts hca
5772 , oe_transaction_types_tl otl
5773 , wms_direct_ship_temp wdst
5774 where wdd.customer_id = hca.cust_account_id
5775 and c.party_id = hca.party_id
5776 and otl.language=userenv('LANG')
5777 and wdd.source_header_number like (p_order)
5778 and otl.transaction_type_id=wdd.source_header_type_id
5779 and wdd.organization_id = p_org_id
5780 and wdd.source_code = 'OE'
5781 and wdd.date_scheduled is not null
5782 and (wdd.released_status in ('B','R','X') --Added bug 4128854
5783 or
5784 (wdst.order_header_id = wdd.source_header_id
5785 and wdd.released_status = ('Y')))
5786 and wdst.organization_id (+) = wdd.organization_id --Added bug 4128854
5787 order by 2,1;
5788
5789 END get_order_lov;
5790
5791
5792 PROCEDURE get_orderline_lov(
5793 x_orderline_lov OUT NOCOPY T_GENREF
5794 , p_org_id IN NUMBER
5795 , p_header_id IN NUMBER
5796 , p_order_line IN VARCHAR2
5797 , p_outermost_lpn_id IN NUMBER
5798 , p_cross_proj_flag IN VARCHAR2
5799 , p_project_id IN NUMBER
5800 , p_task_id IN NUMBER )
5801 IS
5802 l_select_stmt VARCHAR2(2000);
5803 l_prj_where VARCHAR2(2000);
5804 l_group_by VARCHAR2(2000);
5805 --l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5806 l_debug number;
5807
5808 BEGIN
5809 IF g_debug IS NULL THEN
5810 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5811 END IF;
5812 l_debug := g_debug;
5813
5814 IF (l_debug = 1) THEN
5815 DEBUG('Get orderline lov 1','GET_ORDERLINE_LOV');
5816 DEBUG('p_org_id= '||p_org_id,'GET_ORDERLINE_LOV');
5817 DEBUG('p_header_id '||p_header_id,'GET_ORDERLINE_LOV');
5818 DEBUG('p_order_line '||p_order_line,'GET_ORDERLINE_LOV');
5819 DEBUG('p_outermost_lpn_id '||p_outermost_lpn_id,'GET_ORDERLINE_LOV');
5820 DEBUG('p_cross_proj_flag '||p_cross_proj_flag,'GET_ORDERLINE_LOV');
5821 DEBUG('p_project_id '||p_project_id,'GET_ORDERLINE_LOV');
5822 DEBUG('p_task_id '||p_task_id,'GET_ORDERLINE_LOV');
5823 END IF;
5824
5825 IF (p_cross_proj_flag = 'Y') THEN
5826 OPEN x_orderline_lov FOR
5827 SELECT oel.line_id
5828 ,to_char(oel.line_number)||
5829 '.'||to_char(oel.shipment_number) ||
5830 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
5831 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
5832 '.'||to_char(oel.component_number)) LINE_NUMBER
5833 , oel.inventory_item_id
5834 , oel.item_revision
5835 , oel.PROJECT_ID
5836 , oel.TASK_ID
5837 , oel.END_ITEM_UNIT_NUMBER
5838 , oel.SHIP_TOLERANCE_ABOVE
5839 , oel.ship_tolerance_below
5840 , oel.FLOW_STATUS_CODE
5841 , oel.SHIPPING_INTERFACED_FLAG
5842 , oel.REQUEST_DATE
5843 , msik.serial_number_control_code
5844 , msik.concatenated_segments
5845 , wdd.src_requested_quantity --Bug 4169926, sum(wdd.requested_quantity)
5846 , wdd.REQUESTED_QUANTITY_UOM
5847 , wdd.SHIP_FROM_LOCATION_ID
5848 , wdd.SHIP_TO_LOCATION_ID
5849 , wdd.CUSTOMER_ID
5850 , wdd.INTMED_SHIP_TO_LOCATION_ID
5851 , wdd.SHIP_METHOD_CODE
5852 , wdd.FOB_CODE
5853 , wdd.FREIGHT_TERMS_CODE
5854 , NVL(wds.processed_flag,'N') processed_flag
5855 , NVL(wds.processed_quantity,0) processed_quantity
5856 , wdd.src_requested_quantity_uom
5857 FROM oe_order_lines_all oel
5858 , wsh_delivery_details_ob_grp_v wdd
5859 , mtl_system_items_kfv msik
5860 , wms_direct_ship_temp wds
5861 WHERE oel.header_id =p_header_id
5862 and oel.ship_from_org_id = p_org_id
5863 and oel.item_type_code in ('STANDARD','CONFIG','INCLUDED','OPTION')
5864 and msik.inventory_item_id = oel.inventory_item_id
5865 and msik.organization_id = oel.ship_from_org_id
5866 and msik.mtl_transactions_enabled_flag <> 'N'
5867 and wdd.source_header_id = oel.header_id
5868 and wdd.source_line_id = oel.line_id
5869 and wdd.released_status in ('B','R','X')
5870 and wds.lpn_id(+)=p_outermost_lpn_id
5871 and oel.LINE_ID=wds.ORDER_LINE_ID (+)
5872 and oel.HEADER_ID = wds.order_header_id (+)
5873 and oel.ship_from_org_id = wds.organization_id (+)
5874 and to_char(oel.line_number)||
5875 '.'||to_char(oel.shipment_number) ||
5876 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
5877 decode(oel.component_number, null, null,decode(oel.option_number, null, '.',null)||
5878 '.'||to_char(oel.component_number)) like (p_order_line)
5879 and exists (select 1
5880 from wms_license_plate_numbers lpn
5881 , wms_lpn_contents lpc
5882 where lpn.outermost_lpn_id = p_outermost_lpn_id
5883 and lpn.lpn_id = lpc.parent_lpn_id
5884 and lpc.inventory_item_id = oel.inventory_item_id
5885 )
5886 -- Bug# 4258360: Do not include order lines with crossdocked WDD records
5887 AND NOT EXISTS (SELECT 'xdock'
5888 FROM wsh_delivery_details wdd_xdock
5889 WHERE wdd_xdock.source_header_id = oel.header_id
5890 AND wdd_xdock.source_line_id = oel.line_id
5891 AND wdd_xdock.released_status = 'S'
5892 AND wdd_xdock.move_order_line_id IS NULL)
5893 GROUP BY oel.line_id
5894 , to_char(oel.line_number) ||'.'||to_char(oel.shipment_number) ||
5895 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
5896 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
5897 '.'||to_char(oel.component_number))
5898 , oel.inventory_item_id
5899 , oel.item_revision
5900 , oel.PROJECT_ID
5901 , oel.TASK_ID
5902 , oel.END_ITEM_UNIT_NUMBER
5903 , oel.SHIP_TOLERANCE_ABOVE
5904 , oel.ship_tolerance_below
5905 , oel.FLOW_STATUS_CODE
5906 , oel.SHIPPING_INTERFACED_FLAG
5907 , oel.REQUEST_DATE
5908 , msik.serial_number_control_code
5909 , msik.concatenated_segments
5910 , wdd.REQUESTED_QUANTITY_UOM
5911 , wdd.SHIP_FROM_LOCATION_ID
5912 , wdd.SHIP_TO_LOCATION_ID
5913 , wdd.CUSTOMER_ID
5914 , wdd.INTMED_SHIP_TO_LOCATION_ID
5915 , wdd.SHIP_METHOD_CODE
5916 , wdd.FOB_CODE
5917 , wdd.FREIGHT_TERMS_CODE
5918 , wds.processed_flag
5919 , wds.processed_quantity
5920 , wdd.src_requested_quantity --Bug 4169926
5921 , wdd.src_requested_quantity_uom
5922 UNION --Added bug 4128854
5923
5924 SELECT oel.line_id
5925 ,to_char(oel.line_number)||
5926 '.'||to_char(oel.shipment_number) ||
5927 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
5928 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
5929 '.'||to_char(oel.component_number)) LINE_NUMBER
5930 , oel.inventory_item_id
5931 , oel.item_revision
5932 , oel.PROJECT_ID
5933 , oel.TASK_ID
5934 , oel.END_ITEM_UNIT_NUMBER
5935 , oel.SHIP_TOLERANCE_ABOVE
5936 , oel.ship_tolerance_below
5937 , oel.FLOW_STATUS_CODE
5938 , oel.SHIPPING_INTERFACED_FLAG
5939 , oel.REQUEST_DATE
5940 , msik.serial_number_control_code
5941 , msik.concatenated_segments
5942 , 0
5943 , wdd.REQUESTED_QUANTITY_UOM
5944 , wdd.SHIP_FROM_LOCATION_ID
5945 , wdd.SHIP_TO_LOCATION_ID
5946 , wdd.CUSTOMER_ID
5947 , wdd.INTMED_SHIP_TO_LOCATION_ID
5948 , wdd.SHIP_METHOD_CODE
5949 , wdd.FOB_CODE
5950 , wdd.FREIGHT_TERMS_CODE
5951 , 'N' processed_flag
5952 , 0 processed_quantity
5953 , wdd.src_requested_quantity_uom
5954 FROM oe_order_lines_all oel
5955 , wsh_delivery_details_ob_grp_v wdd
5956 , mtl_system_items_kfv msik
5957 , wms_direct_ship_temp wds
5958 WHERE oel.header_id =p_header_id
5959 and oel.ship_from_org_id = p_org_id
5960 and oel.item_type_code in ('STANDARD','CONFIG','INCLUDED','OPTION')
5961 and msik.inventory_item_id = oel.inventory_item_id
5962 and msik.organization_id = oel.ship_from_org_id
5963 and msik.mtl_transactions_enabled_flag <> 'N'
5964 and wdd.source_header_id = oel.header_id
5965 and wdd.source_line_id = oel.line_id
5966 and wdd.released_status in ('Y')
5967 and not exists (select 1
5968 from wsh_delivery_details wdd2
5969 where wdd.source_header_id =wdd2.source_header_id
5970 and wdd.source_line_id = wdd2.source_line_id
5971 and wdd2.released_status in ('B','X','R')
5972 )
5973 and wds.lpn_id(+)=p_outermost_lpn_id
5974 and oel.LINE_ID=wds.ORDER_LINE_ID(+)
5975 and oel.HEADER_ID = wds.order_header_id(+)
5976 and oel.ship_from_org_id = wds.organization_id(+)
5977 and to_char(oel.line_number)||
5978 '.'||to_char(oel.shipment_number) ||
5979 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
5980 decode(oel.component_number, null, null,decode(oel.option_number, null, '.',null)||
5981 '.'||to_char(oel.component_number)) like (p_order_line)
5982 and exists (select 1
5983 from wms_license_plate_numbers lpn
5984 , wms_lpn_contents lpc
5985 where lpn.outermost_lpn_id = p_outermost_lpn_id
5986 and lpn.lpn_id = lpc.parent_lpn_id
5987 and lpc.inventory_item_id = oel.inventory_item_id
5988 )
5989 -- Bug# 4258360: Do not include order lines with crossdocked WDD records
5990 AND NOT EXISTS (SELECT 'xdock'
5991 FROM wsh_delivery_details wdd_xdock
5992 WHERE wdd_xdock.source_header_id = oel.header_id
5993 AND wdd_xdock.source_line_id = oel.line_id
5994 AND wdd_xdock.released_status = 'S'
5995 AND wdd_xdock.move_order_line_id IS NULL)
5996 GROUP BY oel.line_id
5997 , to_char(oel.line_number) ||'.'||to_char(oel.shipment_number) ||
5998 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
5999 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
6000 '.'||to_char(oel.component_number))
6001 , oel.inventory_item_id
6002 , oel.item_revision
6003 , oel.PROJECT_ID
6004 , oel.TASK_ID
6005 , oel.END_ITEM_UNIT_NUMBER
6006 , oel.SHIP_TOLERANCE_ABOVE
6007 , oel.ship_tolerance_below
6008 , oel.FLOW_STATUS_CODE
6009 , oel.SHIPPING_INTERFACED_FLAG
6010 , oel.REQUEST_DATE
6011 , msik.serial_number_control_code
6012 , msik.concatenated_segments
6013 , wdd.REQUESTED_QUANTITY_UOM
6014 , wdd.SHIP_FROM_LOCATION_ID
6015 , wdd.SHIP_TO_LOCATION_ID
6016 , wdd.CUSTOMER_ID
6017 , wdd.INTMED_SHIP_TO_LOCATION_ID
6018 , wdd.SHIP_METHOD_CODE
6019 , wdd.FOB_CODE
6020 , wdd.FREIGHT_TERMS_CODE
6021 , wds.processed_flag
6022 , wds.processed_quantity
6023 , wdd.src_requested_quantity_uom
6024 ORDER BY 1,2;
6025
6026 ELSE
6027
6028 OPEN x_orderline_lov FOR
6029 SELECT oel.line_id
6030 ,to_char(oel.line_number)||
6031 '.'||to_char(oel.shipment_number) ||
6032 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
6033 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
6034 '.'||to_char(oel.component_number)) LINE_NUMBER
6035 , oel.inventory_item_id
6036 , oel.item_revision
6037 , oel.PROJECT_ID
6038 , oel.TASK_ID
6039 , oel.END_ITEM_UNIT_NUMBER
6040 , oel.SHIP_TOLERANCE_ABOVE
6041 , oel.ship_tolerance_below
6042 , oel.FLOW_STATUS_CODE
6043 , oel.SHIPPING_INTERFACED_FLAG
6044 , oel.REQUEST_DATE
6045 , msik.serial_number_control_code
6046 , msik.concatenated_segments
6047 , wdd.src_requested_quantity --Bug 4169926, sum(wdd.requested_quantity)
6048 , wdd.REQUESTED_QUANTITY_UOM
6049 , wdd.SHIP_FROM_LOCATION_ID
6050 , wdd.SHIP_TO_LOCATION_ID
6051 , wdd.CUSTOMER_ID
6052 , wdd.INTMED_SHIP_TO_LOCATION_ID
6053 , wdd.SHIP_METHOD_CODE
6054 , wdd.FOB_CODE
6055 , wdd.FREIGHT_TERMS_CODE
6056 , NVL(wds.processed_flag,'N') processed_flag
6057 , NVL(wds.processed_quantity,0) processed_quantity
6058 , wdd.src_requested_quantity_uom
6059 FROM oe_order_lines_all oel
6060 , wsh_delivery_details_ob_grp_v wdd
6061 , mtl_system_items_kfv msik
6062 , wms_direct_ship_temp wds
6063 WHERE oel.header_id =p_header_id
6064 and oel.ship_from_org_id = p_org_id
6065 and oel.item_type_code in ('STANDARD','CONFIG','INCLUDED','OPTION')
6066 and msik.inventory_item_id = oel.inventory_item_id
6067 and msik.organization_id = oel.ship_from_org_id
6068 and msik.mtl_transactions_enabled_flag <> 'N'
6069 and wdd.source_header_id = oel.header_id
6070 and wdd.source_line_id = oel.line_id
6071 and wdd.released_status in ('B','R','X')
6072 and wds.lpn_id(+)=p_outermost_lpn_id
6073 and oel.LINE_ID=wds.ORDER_LINE_ID (+)
6074 and oel.HEADER_ID = wds.order_header_id (+)
6075 and oel.ship_from_org_id = wds.organization_id (+)
6076 and to_char(oel.line_number)||
6077 '.'||to_char(oel.shipment_number) ||
6078 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
6079 decode(oel.component_number, null, null,decode(oel.option_number, null, '.',null)||
6080 '.'||to_char(oel.component_number)) like (p_order_line)
6081 and exists (select 1
6082 from wms_license_plate_numbers lpn
6083 , wms_lpn_contents lpc
6084 where lpn.outermost_lpn_id = p_outermost_lpn_id
6085 and lpn.lpn_id = lpc.parent_lpn_id
6086 and lpc.inventory_item_id = oel.inventory_item_id
6087 )
6088 and NVL(oel.project_id,-1)=NVL(p_project_id,-1) and NVL(oel.task_id,-1)=NVL(p_task_id,-1)
6089 -- Bug# 4258360: Do not include order lines with crossdocked WDD records
6090 AND NOT EXISTS (SELECT 'xdock'
6091 FROM wsh_delivery_details wdd_xdock
6092 WHERE wdd_xdock.source_header_id = oel.header_id
6093 AND wdd_xdock.source_line_id = oel.line_id
6094 AND wdd_xdock.released_status = 'S'
6095 AND wdd_xdock.move_order_line_id IS NULL)
6096 GROUP BY oel.line_id
6097 , to_char(oel.line_number) ||'.'||to_char(oel.shipment_number) ||
6098 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
6099 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
6100 '.'||to_char(oel.component_number))
6101 , oel.inventory_item_id
6102 , oel.item_revision
6103 , oel.PROJECT_ID
6104 , oel.TASK_ID
6105 , oel.END_ITEM_UNIT_NUMBER
6106 , oel.SHIP_TOLERANCE_ABOVE
6107 , oel.ship_tolerance_below
6108 , oel.FLOW_STATUS_CODE
6109 , oel.SHIPPING_INTERFACED_FLAG
6110 , oel.REQUEST_DATE
6111 , msik.serial_number_control_code
6112 , msik.concatenated_segments
6113 , wdd.REQUESTED_QUANTITY_UOM
6114 , wdd.SHIP_FROM_LOCATION_ID
6115 , wdd.SHIP_TO_LOCATION_ID
6116 , wdd.CUSTOMER_ID
6117 , wdd.INTMED_SHIP_TO_LOCATION_ID
6118 , wdd.SHIP_METHOD_CODE
6119 , wdd.FOB_CODE
6120 , wdd.FREIGHT_TERMS_CODE
6121 , wds.processed_flag
6122 , wds.processed_quantity
6123 , wdd.src_requested_quantity --Bug 4169926
6124 , wdd.src_requested_quantity_uom
6125 UNION --Added bug 4128854
6126
6127 SELECT oel.line_id
6128 ,to_char(oel.line_number)||
6129 '.'||to_char(oel.shipment_number) ||
6130 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
6131 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
6132 '.'||to_char(oel.component_number)) LINE_NUMBER
6133 , oel.inventory_item_id
6134 , oel.item_revision
6135 , oel.PROJECT_ID
6136 , oel.TASK_ID
6137 , oel.END_ITEM_UNIT_NUMBER
6138 , oel.SHIP_TOLERANCE_ABOVE
6139 , oel.ship_tolerance_below
6140 , oel.FLOW_STATUS_CODE
6141 , oel.SHIPPING_INTERFACED_FLAG
6142 , oel.REQUEST_DATE
6143 , msik.serial_number_control_code
6144 , msik.concatenated_segments
6145 , 0
6146 , wdd.REQUESTED_QUANTITY_UOM
6147 , wdd.SHIP_FROM_LOCATION_ID
6148 , wdd.SHIP_TO_LOCATION_ID
6149 , wdd.CUSTOMER_ID
6150 , wdd.INTMED_SHIP_TO_LOCATION_ID
6151 , wdd.SHIP_METHOD_CODE
6152 , wdd.FOB_CODE
6153 , wdd.FREIGHT_TERMS_CODE
6154 , 'N' processed_flag
6155 , 0 processed_quantity
6156 , wdd.src_requested_quantity_uom
6157 FROM oe_order_lines_all oel
6158 , wsh_delivery_details_ob_grp_v wdd
6159 , mtl_system_items_kfv msik
6160 , wms_direct_ship_temp wds
6161 WHERE oel.header_id =p_header_id
6162 and oel.ship_from_org_id = p_org_id
6163 and oel.item_type_code in ('STANDARD','CONFIG','INCLUDED','OPTION')
6164 and msik.inventory_item_id = oel.inventory_item_id
6165 and msik.organization_id = oel.ship_from_org_id
6166 and msik.mtl_transactions_enabled_flag <> 'N'
6167 and wdd.source_header_id = oel.header_id
6168 and wdd.source_line_id = oel.line_id
6169 and wdd.released_status in ('Y')
6170 and not exists (select 1
6171 from wsh_delivery_details wdd2
6172 where wdd.source_header_id =wdd2.source_header_id
6173 and wdd.source_line_id = wdd2.source_line_id
6174 and wdd2.released_status in ('B','X','R')
6175 )
6176 and wds.lpn_id(+)=p_outermost_lpn_id
6177 and oel.LINE_ID=wds.ORDER_LINE_ID (+)
6178 and oel.HEADER_ID = wds.order_header_id (+)
6179 and oel.ship_from_org_id = wds.organization_id (+)
6180 and to_char(oel.line_number)||
6181 '.'||to_char(oel.shipment_number) ||
6182 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
6183 decode(oel.component_number, null, null,decode(oel.option_number, null, '.',null)||
6184 '.'||to_char(oel.component_number)) like (p_order_line)
6185 and exists (select 1
6186 from wms_license_plate_numbers lpn
6187 , wms_lpn_contents lpc
6188 where lpn.outermost_lpn_id = p_outermost_lpn_id
6189 and lpn.lpn_id = lpc.parent_lpn_id
6190 and lpc.inventory_item_id = oel.inventory_item_id
6191 )
6192 and NVL(oel.project_id,-1)=NVL(p_project_id,-1) and NVL(oel.task_id,-1)=NVL(p_task_id,-1)
6193 -- Bug# 4258360: Do not include order lines with crossdocked WDD records
6194 AND NOT EXISTS (SELECT 'xdock'
6195 FROM wsh_delivery_details wdd_xdock
6196 WHERE wdd_xdock.source_header_id = oel.header_id
6197 AND wdd_xdock.source_line_id = oel.line_id
6198 AND wdd_xdock.released_status = 'S'
6199 AND wdd_xdock.move_order_line_id IS NULL)
6200 GROUP BY oel.line_id
6201 , to_char(oel.line_number) ||'.'||to_char(oel.shipment_number) ||
6202 decode(oel.option_number,NULL,NULL,'.'||to_char(oel.option_number))||
6203 decode(oel.component_number, null, null,decode(oel.option_number, null,'.',null)||
6204 '.'||to_char(oel.component_number))
6205 , oel.inventory_item_id
6206 , oel.item_revision
6207 , oel.PROJECT_ID
6208 , oel.TASK_ID
6209 , oel.END_ITEM_UNIT_NUMBER
6210 , oel.SHIP_TOLERANCE_ABOVE
6211 , oel.ship_tolerance_below
6212 , oel.FLOW_STATUS_CODE
6213 , oel.SHIPPING_INTERFACED_FLAG
6214 , oel.REQUEST_DATE
6215 , msik.serial_number_control_code
6216 , msik.concatenated_segments
6217 , wdd.REQUESTED_QUANTITY_UOM
6218 , wdd.SHIP_FROM_LOCATION_ID
6219 , wdd.SHIP_TO_LOCATION_ID
6220 , wdd.CUSTOMER_ID
6221 , wdd.INTMED_SHIP_TO_LOCATION_ID
6222 , wdd.SHIP_METHOD_CODE
6223 , wdd.FOB_CODE
6224 , wdd.FREIGHT_TERMS_CODE
6225 , wds.processed_flag
6226 , wds.processed_quantity
6227 , wdd.src_requested_quantity_uom
6228 ORDER BY 1,2;
6229 END IF;
6230
6231 IF (l_debug = 1) THEN
6232 DEBUG('Get orderline lov 2','GET_ORDERLINE_LOV');
6233 END IF;
6234
6235 END get_orderline_lov;
6236
6237
6238
6239 PROCEDURE Get_FreightCost_Type
6240 ( x_freight_type_code out NOCOPY t_genref
6241 , p_text in VARCHAR2) IS
6242 BEGIN
6243 open x_freight_type_code for
6244 Select name
6245 , amount
6246 , currency_code
6247 , freight_cost_type_id
6248 From wsh_freight_cost_types
6249 Where sysdate between nvl(start_date_active, sysdate) and
6250 nvl(end_date_active, sysdate)
6251 And name like (p_text)
6252 Order by name;
6253
6254 END Get_FreightCost_Type;
6255
6256 PROCEDURE Get_Freight_Term
6257 (x_freight_terms out NOCOPY t_genref
6258 , p_text in varchar2) IS
6259 BEGIN
6260 open x_freight_terms for
6261 select freight_terms
6262 , freight_terms_code
6263 from oe_frght_terms_active_v
6264 where freight_terms like (p_text)
6265 order by freight_terms_code;
6266
6267 END Get_Freight_Term;
6268
6269
6270 PROCEDURE get_document_set_lov
6271 (x_report_set out NOCOPY t_genref
6272 , p_text in varchar2) IS
6273 BEGIN
6274 Open x_report_set for
6275 Select report_set_id
6276 , name
6277 , description
6278 from wsh_report_sets
6279 where usage_code = 'SHIP_CONFIRM'
6280 and trunc(nvl(start_date_active, sysdate)) <= trunc(sysdate)
6281 and trunc(nvl(end_date_active, sysdate+1)) > trunc(sysdate)
6282 and name like (p_text);
6283
6284 END Get_document_set_lov;
6285
6286 PROCEDURE get_conversion_type
6287 (x_conversion_type out NOCOPY t_genref
6288 , p_text in varchar2) IS
6289 BEGIN
6290 open x_conversion_type for
6291 Select conversion_type
6292 , user_conversion_type
6293 , description
6294 From gl_daily_conversion_types
6295 Where conversion_type <> 'EMU FIXED'
6296 and user_conversion_type like (p_text)
6297 Order by user_conversion_type, description;
6298
6299 END GET_CONVERSION_TYPE;
6300
6301 PROCEDURE get_currency_code
6302 (x_currency out NOCOPY t_genref
6303 , p_text in varchar2) IS
6304 BEGIN
6305 open x_currency for
6306 select c.currency_code
6307 , c.name currency_name
6308 , c.precision
6309 from fnd_currencies_vl c
6310 where c.currency_flag='Y'
6311 and c.enabled_flag='Y'
6312 and trunc(nvl(c.start_date_active,sysdate))<=trunc(sysdate)
6313 and trunc(nvl(c.end_date_active,sysdate+1))>trunc(sysdate)
6314 and currency_code like (p_text)
6315 order by c.currency_code;
6316
6317 END GET_CURRENCY_CODE;
6318
6319 Procedure Get_unloadTruck_lpn_lov
6320 (x_lpn_lov out NOCOPY t_genref
6321 , p_organization_id IN NUMBER
6322 , p_dock_door_id IN NUMBER
6323 , p_lpn IN VARCHAR2) IS
6324
6325 BEGIN
6326 open x_lpn_lov for
6327 select distinct wlpn.license_plate_number
6328 , wlpn.lpn_id
6329 , wlpn.subinventory_code
6330 , milk.concatenated_segments
6331 from wms_license_plate_numbers wlpn
6332 , wms_shipping_transaction_temp wstt
6333 , mtl_item_locations_kfv milk
6334 WHERE wlpn.organization_id = wstt.organization_id
6335 AND wlpn.organization_id = p_organization_id
6336 AND wlpn.lpn_id = wstt.outermost_lpn_id
6337 AND nvl(wstt.direct_ship_flag,'N') = 'Y'
6338 /* Uncomment this after this flag is introduced in the table */
6339 AND wlpn.lpn_context = 9
6340 AND wstt.dock_door_id = p_dock_door_id
6341 AND milk.organization_id = wlpn.organization_id
6342 AND milk.inventory_location_id = wlpn.locator_id
6343 AND wlpn.license_plate_number like (p_lpn)
6344 order by wlpn.license_plate_number;
6345
6346 END Get_unloadTruck_lpn_lov;
6347
6348 PROCEDURE GET_LPN_CONTENTS
6349 (
6350 x_lpn_contents OUT NOCOPY t_genref,
6351 p_lpn_id IN NUMBER,
6352 p_org_id IN NUMBER
6353 )
6354 IS
6355 CURSOR lpn_id_cursor IS
6356 SELECT lpn_id
6357 FROM wms_license_plate_numbers lpn
6358 WHERE outermost_lpn_id = p_lpn_id
6359 AND organization_id = p_org_id
6360 AND lpn_context = 1;
6361
6362 lpn_id_str VARCHAR(2000);
6363 lpn_contents_select_str VARCHAR2(4000);
6364 v_lpn_id NUMBER;
6365 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6366 l_debug number;
6367 BEGIN
6368 IF g_debug IS NULL THEN
6369 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6370 END IF;
6371 l_debug := g_debug;
6372
6373 IF (l_debug = 1) THEN
6374 DEBUG('Starting to get the Contents' , 'GET_LPN_CONTENTS');
6375 END IF;
6376 lpn_id_str := '( ';
6377 lpn_contents_select_str := 'SELECT parent_lpn_id, inventory_item_id, quantity, uom_code, revision ';
6378 lpn_contents_select_str := lpn_contents_select_str || ' FROM wms_lpn_contents ';
6379 lpn_contents_select_str := lpn_contents_select_str || ' WHERE parent_lpn_id IN ';
6380
6381 OPEN lpn_id_cursor;
6382 FETCH lpn_id_cursor INTO v_lpn_id;
6383 lpn_id_str := '( ' || to_char(v_lpn_id);
6384 LOOP
6385 FETCH lpn_id_cursor INTO v_lpn_id;
6386 EXIT WHEN lpn_id_cursor%NOTFOUND;
6387 lpn_id_str := lpn_id_str || ' , ' || v_lpn_id;
6388 END LOOP;
6389 CLOSE lpn_id_cursor;
6390 lpn_id_str := lpn_id_str || ' )';
6391 lpn_contents_select_str := lpn_contents_select_str || lpn_id_str;
6392
6393 OPEN x_lpn_contents FOR lpn_contents_select_str;
6394 IF (l_debug = 1) THEN
6395 DEBUG('Finihed getting the Contents' , 'GET_LPN_CONTENTS');
6396 END IF;
6397 EXCEPTION
6398 WHEN OTHERS THEN
6399 IF (l_debug = 1) THEN
6400 DEBUG('Exception Occured' || SQLERRM, 'GET_LPN_CONTENTS');
6401 END IF;
6402 END GET_LPN_CONTENTS;
6403
6404 /* Direct Shipping */
6405
6406 /* This function is added as part of bug fix 2529382.
6407 This function gets the next heigher name of a resuable container
6408 by which the existing container in shipping is updated.
6409 */
6410 FUNCTION get_container_name(p_container_name IN VARCHAR2) RETURN VARCHAR2 IS
6411
6412 CURSOR l_container IS
6413 select container_name from wsh_delivery_details_ob_grp_v
6414 where container_name like p_container_name||'-@-%';
6415
6416 l_num_part_str VARCHAR2(30);
6417
6418 x VARCHAR2(30);
6419 to_return NUMBER:=0;
6420
6421 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6422 l_debug number;
6423 BEGIN
6424 IF g_debug IS NULL THEN
6425 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6426 END IF;
6427 l_debug := g_debug;
6428
6429 FOR l_cont_cur IN l_container LOOP
6430 IF (l_debug = 1) THEN
6431 debug('l_cont_cur.container_name = '||l_cont_cur.container_name
6432 ||' p_container_name '||p_container_name,'get_container_name');
6433 END IF;
6434
6435 l_num_part_str:=substr(l_cont_cur.container_name,length(p_container_name||'-@-')+1);
6436 begin
6437 IF (l_debug = 1) THEN
6438 debug('Num part value = '||l_num_part_str,'get_container_name');
6439 END IF;
6440 x:=to_number(l_num_part_str);
6441 if x> to_return then
6442 to_return:=x;
6443 end if;
6444 exception
6445 when invalid_number then
6446 IF (l_debug = 1) THEN
6447 debug('Exception : Num part value = '||l_num_part_str,'get_container_name');
6448 END IF;
6449 when value_error then
6450 IF (l_debug = 1) THEN
6451 debug('Exception : Num part value = '||l_num_part_str,'get_container_name');
6452 END IF;
6453 end;
6454 END LOOP;
6455 IF (l_debug = 1) THEN
6456 debug('Return value'||l_num_part_str,'get_container_name');
6457 END IF;
6458 return p_container_name||'-@-'||to_char(to_return+1);
6459
6460 EXCEPTION
6461 when others then
6462 IF (l_debug = 1) THEN
6463 debug('Exception occured while getting new container name: '||
6464 l_num_part_str,'get_container_name');
6465 END IF;
6466 END;
6467
6468
6469
6470 -- This procedure is introduced for RFID project
6471 /*
6472 API Name:close_truck
6473
6474 Input parameters:
6475 P_dock_door_id : Shipping dock door id
6476 P_organization_id : organization_id
6477 p_shipping_mode : 'NORMAL'--Equivalent to normal LPN ship;
6478 'DIRECT'--Equivalent to Direct LPN ship;
6479 NULL --will process both above;
6480 Output parameters:
6481 x_return_status : 'S' --Sucess,
6482 'W' --Warning
6483 'E' --ERROR
6484 x_return_msg : Returned message
6485
6486 */
6487
6488 procedure close_truck
6489 ( P_dock_door_id IN NUMBER,
6490 P_organization_id IN NUMBER,
6491 p_shipping_mode IN VARCHAR2 DEFAULT null,
6492 p_commit_flag IN VARCHAR2 DEFAULT fnd_api.g_true,
6493 x_return_status OUT NOCOPY VARCHAR2,
6494 x_return_msg OUT NOCOPY VARCHAR2
6495 )
6496 IS
6497
6498 --for LPNs loaded through Normal method only
6499 --for LPNs loaded through direct method, it is handled inside wms_direct_ship_pvt.close_truck
6500 -- check for missing LPN is done for the delivery
6501
6502 cursor normal_lpns_for_dock is
6503 select DISTINCT outermost_lpn_id,Nvl(trip_id,0)
6504 from WMS_SHIPPING_TRANSACTION_TEMP
6505 where organization_id = p_organization_id
6506 and dock_door_id = p_dock_door_id
6507 and nvl(direct_ship_flag,'N') = 'N';
6508
6509
6510 l_return_status VARCHAR2(1);
6511 l_msg_data VARCHAR2(2000);
6512 l_msg_count NUMBER;
6513 l_missing_items t_genref;
6514 l_error_code NUMBER;
6515 l_trip_id NUMBER;
6516
6517
6518 l_vehicle_item_id NUMBER;
6519 l_vehicle_num_prefix VARCHAR2(30);
6520 l_vehicle_num VARCHAR2(30);
6521 l_seal_code VARCHAR2(30);
6522 l_document_set_id NUMBER;
6523 l_outermost_lpn_id NUMBER;
6524 l_serial_at_issue NUMBER;
6525 l_missing_item t_genref;
6526 l_missing_lpns t_genref;
6527 l_ship_set VARCHAR2(30);
6528 l_delivery_info t_genref;
6529 l_deli_count NUMBER;
6530 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6531 l_debug number;
6532
6533 BEGIN
6534
6535 x_return_status := FND_API.g_ret_sts_success;
6536 IF g_debug IS NULL THEN
6537 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6538 END IF;
6539 l_debug := g_debug;
6540
6541 IF (l_debug = 1) THEN
6542 DEBUG('p_dock_door_id :: P_organization_id :: p_shipping_mode', 'CLOSE_TRUCK');
6543 DEBUG(''||p_dock_door_id ||'::'|| P_organization_id ||'::'|| p_shipping_mode, 'CLOSE_TRUCK');
6544 END IF;
6545
6546
6547 IF p_shipping_mode = 'NORMAL' OR p_shipping_mode IS NULL THEN
6548
6549 IF (l_debug = 1) THEN
6550 debug(' Before calling check_lpn_deliveries : NORMAL', 'CLOSE_TRUCK');
6551 END IF;
6552
6553
6554 --since shipping ship-confirms all the staged lines and does not
6555 --distinguishes between lines that have loaded to the dock-door or just
6556 --staged, We need to give an option to user whether he would like to
6557 --unassign ALL unloaded lines automatically or fail the
6558 --transaction. since there is no UI in rfid txn, it can be done with
6559 --parameter at Org level. For the Patch set J, We will fail the
6560 --transaction IF there are lines which are staged but not loaded to
6561 --the dock-door. It is done inside following check_lpn_deliveries API
6562
6563 BEGIN
6564 OPEN normal_lpns_for_dock;
6565 LOOP
6566 fetch normal_lpns_for_dock into l_outermost_lpn_id,l_trip_id;
6567 exit when normal_lpns_for_dock%NOTFOUND;
6568 IF (l_debug = 1) THEN
6569 debug(' processing LPNs l_outermost_lpn_id ::'||l_outermost_lpn_id||
6570 '::l_trip_id ::'||l_trip_id, 'CLOSE_TRUCK');
6571 END IF;
6572
6573
6574 check_lpn_deliveries
6575 (p_trip_id => l_trip_id,--relevant for dock
6576 --appointment, it will have value if loaded with dock appointment
6577 p_organization_id => p_organization_id,
6578 p_dock_door_id => p_dock_door_id,
6579 p_outermost_lpn_id => l_outermost_lpn_id,
6580 p_delivery_id => null,
6581 x_error_code => l_error_code, -- 0 means success
6582 x_missing_item => l_missing_item,
6583 x_missing_lpns => l_missing_lpns,
6584 x_ship_set => l_ship_set,
6585 x_delivery_info => l_delivery_info,
6586 x_deli_count => l_deli_count,
6587 p_rfid_call => 'Y');
6588
6589 debug( 'p_error_code:'|| l_error_code, 'CLOSE_TRUCK');
6590
6591 IF l_error_code <> 0 THEN
6592 IF (l_debug = 1) THEN
6593 debug('check_lpn_deliveries delivery failed','CLOSE_TRUCK');
6594 END IF;
6595 RAISE FND_API.G_EXC_ERROR;
6596 END IF;
6597 END LOOP;
6598 CLOSE normal_lpns_for_dock;
6599 EXCEPTION
6600 when no_data_found then
6601 IF (l_debug = 1) THEN
6602 debug('check_lpn_deliveries: NO DATA FOUND','CLOSE_TRUCK');
6603 END IF;
6604 RAISE FND_API.G_EXC_ERROR;
6605 END;
6606
6607 --Following api process ship LPNs with dock-appointment and without dock
6608 -- appointment, ALL that are loaded TO the dock door
6609
6610 IF (l_debug = 1) THEN
6611 debug(' calling ship_confirm_lpn_deliveries()', 'CLOSE_TRUCK');
6612 END IF;
6613
6614 ship_confirm_lpn_deliveries
6615 (x_return_status => l_return_status,
6616 x_msg_data => l_msg_data,
6617 x_msg_count => l_msg_count,
6618 p_trip_stop_id => 0,
6619 p_trip_id => l_trip_id,--relevant for dock appointment
6620 p_dock_door_id => p_dock_door_id,
6621 p_organization_id => p_organization_id,
6622 p_verify_only => 'N');
6623
6624 IF (l_debug = 1) THEN
6625 debug(' AFTER calling wms_shipping_transaction_pub.ship_confirm_lpn_deliveries()', 'CLOSE_TRUCK');
6626 debug(' l_return_status::' ||l_return_status, 'CLOSE_TRUCK');
6627 debug(' l_msg_data::' ||l_msg_data, 'CLOSE_TRUCK');
6628 END IF;
6629
6630 IF l_return_status IN ('S','W') THEN
6631
6632 IF p_commit_flag = fnd_api.g_true THEN
6633 IF (l_debug = 1) THEN
6634 debug(' Commit', 'CLOSE_TRUCK');
6635 END IF;
6636
6637 COMMIT;
6638 else
6639
6640 IF (l_debug = 1) THEN
6641 debug(' No Commit', 'CLOSE_TRUCK');
6642 END IF;
6643
6644 END IF;
6645
6646 ELSE
6647
6648 IF (l_debug = 1) THEN
6649 debug(' returning Error', 'CLOSE_TRUCK');
6650 END IF;
6651 RAISE fnd_api.g_exc_error;
6652
6653 END IF;
6654 END IF;
6655
6656 IF p_shipping_mode = 'DIRECT' OR p_shipping_mode IS NULL THEN
6657
6658
6659 IF (l_debug = 1) THEN
6660 debug(' Before calling wms_direct_ship_pvt.close_truck : DIRECT', 'CLOSE_TRUCK');
6661 END IF;
6662
6663 --handles dircet ship with dock appointment and without dock
6664 --appointment, inside it does all required validations for LPNs
6665 --loaded TO the dock door via direct method
6666
6667 wms_direct_ship_pvt.close_truck(
6668 x_return_status => l_return_status
6669 , x_msg_data => l_msg_data
6670 , x_msg_count => l_msg_count
6671 , x_error_code => l_error_code
6672 , x_missing_item_cur => l_missing_items
6673 , p_dock_door_id => p_dock_door_id
6674 , p_group_id => NULL --no longer needed after I
6675 , p_org_id => p_organization_id
6676 );
6677
6678 IF (l_debug = 1) THEN
6679 debug(' l_return_status, l_msg_data, l_msg_count', 'CLOSE_TRUCK');
6680 debug(' '||l_return_status||'::'||l_msg_data||'::'||l_msg_count, 'CLOSE_TRUCK');
6681 END IF;
6682
6683
6684 IF l_return_status IN ('S','W') THEN
6685
6686 IF p_commit_flag = fnd_api.g_true THEN
6687 IF (l_debug = 1) THEN
6688 debug(' Commit', 'CLOSE_TRUCK');
6689 END IF;
6690
6691 COMMIT;
6692 ELSE
6693
6694 IF (l_debug = 1) THEN
6695 debug(' No Commit', 'CLOSE_TRUCK');
6696 END IF;
6697
6698 END IF;
6699
6700 ELSE
6701 debug(' returning Error', 'CLOSE_TRUCK');
6702 RAISE fnd_api.g_exc_error;
6703
6704 END IF;
6705
6706 END IF;
6707 debug('Returning from API','CLOSE_TRUCK');
6708 x_return_msg := l_msg_data;
6709
6710 EXCEPTION
6711 WHEN OTHERS THEN
6712
6713 IF normal_lpns_for_dock%ISOPEN THEN
6714 CLOSE normal_lpns_for_dock;
6715 END IF;
6716
6717 x_return_status := 'E';
6718 IF (l_debug = 1) THEN
6719 debug('Other error in close_truck()', 'CLOSE_TRUCK');
6720 debug('SQL error :'||substr(sqlerrm, 1, 240), 'CLOSE_TRUCK');
6721 END IF;
6722
6723 END close_truck;
6724
6725 --bug3643846: This method will set the serial_number_entry column in WLC
6726 --This is only needed for serial @ SO issue item because
6727 --by the time of ship confirmation, it's only serial @ SO issue items
6728 --that will not have this column set corrected. This column should be
6729 --set correctly during pack operations of other serial controlled items.
6730 PROCEDURE update_lpn_contents
6731 (p_outermost_lpn_id IN NUMBER,
6732 p_org_id IN NUMBER,
6733 x_return_status OUT nocopy VARCHAR2,
6734 x_msg_count OUT nocopy NUMBER,
6735 x_msg_data OUT nocopy VARCHAR2) IS
6736
6737 TYPE lpn_id_tbl_type IS TABLE OF wms_lpn_contents.parent_lpn_id%TYPE;
6738 TYPE inventory_item_id_tbl_type IS TABLE OF wms_lpn_contents.inventory_item_id%TYPE;
6739
6740 l_parent_lpn_id lpn_id_tbl_type;
6741 l_inventory_item_id inventory_item_id_tbl_type;
6742
6743 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6744 l_debug number;
6745 BEGIN
6746 IF g_debug IS NULL THEN
6747 g_debug := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6748 END IF;
6749 l_debug := g_debug;
6750
6751 debug('Entered with p_outermost_lpn_id : ' || p_outermost_lpn_id
6752 || ' p_org_id : ' || p_org_id,'UPDATE_LPN_CONTENTS');
6753
6754 x_return_status := 'S';
6755
6756 SELECT wlc.parent_lpn_id, wlc.inventory_item_id
6757 bulk collect INTO l_parent_lpn_id, l_inventory_item_id
6758 from wms_lpn_contents wlc, wms_license_plate_numbers wlpn, mtl_system_items_kfv msik
6759 where wlc.organization_id = p_org_id
6760 and msik.organization_id = p_org_id
6761 and wlpn.organization_id = wlc.organization_id
6762 AND wlpn.outermost_lpn_id = p_outermost_lpn_id
6763 and wlpn.lpn_id = wlc.parent_lpn_id
6764 and wlc.inventory_item_id = msik.inventory_item_id
6765 and msik.serial_number_control_code = 6
6766 and wlc.serial_summary_entry <> 1;
6767
6768 IF l_parent_lpn_id.COUNT > 0 THEN
6769 IF l_debug = 1 THEN
6770 debug('Found ' || l_parent_lpn_id.COUNT || ' entries to update','UPDATE_LPN_CONTENTS');
6771 debug('The list of lpn_id to update:','UPDATE_LPN_CONTENTS');
6772 FOR j IN l_parent_lpn_id.first .. l_parent_lpn_id.last LOOP
6773 debug(j || ': ' || l_parent_lpn_id(j),'UPDATE_LPN_CONTENTS');
6774 END LOOP;
6775 END IF;
6776
6777 forall i IN l_parent_lpn_id.first .. l_parent_lpn_id.last
6778 UPDATE wms_lpn_contents
6779 SET serial_summary_entry = 1
6780 WHERE parent_lpn_id = l_parent_lpn_id(i)
6781 AND inventory_item_id = l_inventory_item_id(i);
6782 ELSE
6783 debug('Did not find any content lpn to update','UPDATE_LPN_CONTENTS');
6784 END IF;
6785
6786 END update_lpn_contents;
6787
6788
6789
6790 END WMS_SHIPPING_TRANSACTION_PUB;