DBA Data[Home] [Help]

PACKAGE BODY: APPS.WMS_SHIPPING_TRANSACTION_PUB

Source


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