[Home] [Help]
PACKAGE BODY: APPS.WMS_TASK_DISPATCH_GEN
Source
1 PACKAGE BODY wms_task_dispatch_gen AS
2 /* $Header: WMSTASKB.pls 120.18.12010000.2 2008/08/22 10:57:04 satishku ship $ */
3
4
5 -- Global constant holding the package name
6
7 g_pkg_name CONSTANT VARCHAR2(30) := 'WMS_Task_Dispatch_Gen';
8 g_pkg_version CONSTANT VARCHAR2(100) := '$Header: WMSTASKB.pls 120.18.12010000.2 2008/08/22 10:57:04 satishku ship $';
9
10 --Replenishment Project --6681109
11 g_ordered_psr wms_replenishment_pvt.psrTabTyp;
12
13 PROCEDURE call_workflow(
14 p_rsn_id IN NUMBER
15 , p_calling_program IN VARCHAR2
16 , p_org_id IN NUMBER
17 , p_tmp_id IN NUMBER DEFAULT NULL
18 , p_quantity_picked IN NUMBER DEFAULT NULL
19 , p_dest_sub IN VARCHAR2 DEFAULT NULL
20 , p_dest_loc IN NUMBER DEFAULT NULL
21 , x_return_status OUT NOCOPY VARCHAR2
22 , x_msg_count OUT NOCOPY NUMBER
23 , x_msg_data OUT NOCOPY VARCHAR2
24 , x_wf OUT NOCOPY NUMBER ); -- Bug2924823 H to I
25
26 -- If you need to make any changes in the spec of create_mo, then make
27 -- changes both in wms_task_dispatch_put_away.create_mo and in
28 -- wms_task_dispatch_gen.create_mo
29
30 PROCEDURE create_mo(
31 p_org_id IN NUMBER
32 , p_inventory_item_id IN NUMBER
33 , p_qty IN NUMBER
34 , p_uom IN VARCHAR2
35 , p_lpn IN NUMBER
36 , p_project_id IN NUMBER
37 , p_task_id IN NUMBER
38 , p_reference IN VARCHAR2
39 , p_reference_type_code IN NUMBER
40 , p_reference_id IN NUMBER
41 , p_lot_number IN VARCHAR2
42 , p_revision IN VARCHAR2
43 , p_header_id IN OUT NOCOPY NUMBER
44 , p_sub IN VARCHAR
45 , p_loc IN NUMBER
46 , x_line_id OUT NOCOPY NUMBER
47 , p_inspection_status IN NUMBER
48 , p_txn_source_id IN NUMBER
49 , p_transaction_type_id IN NUMBER
50 , p_transaction_source_type_id IN NUMBER
51 , p_wms_process_flag IN NUMBER
52 , x_return_status OUT NOCOPY VARCHAR2
53 , x_msg_count OUT NOCOPY NUMBER
54 , x_msg_data OUT NOCOPY VARCHAR2
55 , p_from_cost_group_id IN NUMBER
56 , p_transfer_org_id IN NUMBER
57 ) IS
58 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
59 BEGIN
60 wms_task_dispatch_put_away.create_mo(
61 p_org_id => p_org_id
62 , p_inventory_item_id => p_inventory_item_id
63 , p_qty => p_qty
64 , p_uom => p_uom
65 , p_lpn => p_lpn
66 , p_project_id => p_project_id
67 , p_task_id => p_task_id
68 , p_reference => p_reference
69 , p_reference_type_code => p_reference_type_code
70 , p_reference_id => p_reference_id
71 , p_lot_number => p_lot_number
72 , p_revision => p_revision
73 , p_header_id => p_header_id
74 , p_sub => p_sub
75 , p_loc => p_loc
76 , x_line_id => x_line_id
77 , p_inspection_status => p_inspection_status
78 , p_txn_source_id => p_txn_source_id
79 , p_transaction_type_id => p_transaction_type_id
80 , p_transaction_source_type_id => p_transaction_source_type_id
81 , p_wms_process_flag => p_wms_process_flag
82 , x_return_status => x_return_status
83 , x_msg_count => x_msg_count
84 , x_msg_data => x_msg_data
85 , p_from_cost_group_id => p_from_cost_group_id
86 , p_transfer_org_id => p_transfer_org_id
87 );
88 EXCEPTION
89 WHEN fnd_api.g_exc_error THEN
90 x_return_status := fnd_api.g_ret_sts_error;
91
92 IF (l_debug = 1) THEN
93 mydebug('create_mo: call to WMS_Task_Dispatch_put_away.create_mo failed');
94 END IF;
95
96 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
97 WHEN OTHERS THEN
98 x_return_status := fnd_api.g_ret_sts_unexp_error;
99
100 IF (l_debug = 1) THEN
101 mydebug('create_mo: call to WMS_Task_Dispatch_put_away.create_mo failed');
102 END IF;
103
104 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
105 END create_mo;
106
107 PROCEDURE insert_task(
108 p_org_id IN NUMBER
109 , p_user_id IN NUMBER
110 , p_eqp_ins IN VARCHAR2
111 , p_temp_id IN NUMBER
112 , x_return_status OUT NOCOPY VARCHAR2
113 ) IS
114 l_org_id NUMBER;
115 l_temp_id NUMBER;
116 l_person_id NUMBER;
117 l_eqp_id NUMBER;
118 l_eqp_ins VARCHAR2(30);
119 l_per_res_id NUMBER;
120 l_mac_res_id NUMBER;
121 l_return_status VARCHAR2(1);
122 l_task_id NUMBER;
123 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
124 BEGIN
125 l_return_status := fnd_api.g_ret_sts_success;
126 l_org_id := p_org_id;
127 l_temp_id := p_temp_id;
128 l_person_id := p_user_id;
129 l_eqp_id := 1111;
130 l_eqp_ins := p_eqp_ins;
131 l_per_res_id := 1113;
132 l_mac_res_id := 1001;
133
134 /* SELECT resource_id INTO l_mac_res_id
135 FROM bom_resource_equipments
136 WHERE organization_id=l_org_id
137 AND inventory_item_id=l_eqp_id;
138
139
140 SELECT resource_id INTO l_per_res_id
141 FROM bom_resource_employees
142 WHERE organization_id=l_org_id
143 AND person_id=l_emp_id;
144 */
145 SELECT wms_dispatched_tasks_s.NEXTVAL
146 INTO l_task_id
147 FROM DUAL;
148
149 INSERT INTO wms_dispatched_tasks
150 (
151 task_id
152 , transaction_temp_id
153 , organization_id
154 , user_task_type
155 , person_id
156 , effective_start_date
157 , effective_end_date
158 , equipment_id
159 , equipment_instance
160 , person_resource_id
161 , machine_resource_id
162 , status
163 , dispatched_time
164 , last_update_date
165 , last_updated_by
166 , creation_date
167 , created_by
168 , task_type
169 , priority
170 , operation_plan_id
171 , move_order_line_id
172 )
173 (SELECT l_task_id
174 , transaction_temp_id
175 , organization_id
176 , NVL(standard_operation_id, 2)
177 , l_person_id
178 , SYSDATE
179 , SYSDATE
180 , l_eqp_id
181 , l_eqp_ins
182 , l_per_res_id
183 , l_mac_res_id
184 , 4
185 , SYSDATE
186 , SYSDATE
187 , l_person_id
188 , SYSDATE
189 , l_person_id
190 , NVL(wms_task_type, 1)
191 , task_priority
192 , operation_plan_id
193 , move_order_line_id
194 FROM mtl_material_transactions_temp
195 WHERE transaction_temp_id = l_temp_id);
196
197 x_return_status := fnd_api.g_ret_sts_success;
198 EXCEPTION
199 WHEN OTHERS THEN
200 x_return_status := fnd_api.g_ret_sts_unexp_error;
201 fnd_message.set_name('WMS', 'WMS_TD_INSERT_TASK');
202 fnd_msg_pub.ADD;
203 END insert_task;
204
205 PROCEDURE next_task(
206 p_sign_on_emp_id IN NUMBER
207 , p_sign_on_org_id IN NUMBER
208 , p_sign_on_zone IN VARCHAR2
209 , p_sign_on_equipment_id IN NUMBER
210 , p_sign_on_equipment_srl IN VARCHAR2
211 , p_task_type IN VARCHAR2
212 , x_nbr_tasks OUT NOCOPY NUMBER
213 , p_lpn_id IN NUMBER
214 , x_return_status OUT NOCOPY VARCHAR2
215 , x_msg_count OUT NOCOPY NUMBER
216 , x_msg_data OUT NOCOPY VARCHAR2
217 , x_task_type OUT NOCOPY NUMBER
218 , p_sign_on_device_id IN NUMBER := NULL
219 , x_avail_device_id OUT NOCOPY NUMBER
220 ) IS
221 l_cartonization_id NUMBER := NULL;
222 task_rec wms_task_dispatch_gen.task_rec_tp;
223 l_task_cur wms_task_dispatch_gen.task_rec_cur_tp;
224 l_user_id NUMBER;
225 l_emp_id NUMBER;
226 l_org_id NUMBER;
227 l_zone VARCHAR2(10);
228 l_eqp_id NUMBER;
229 l_eqp_ins VARCHAR2(30);
230 l_task_type VARCHAR2(30);
231 l_c_rows NUMBER;
232 l_next_task_id NUMBER;
233 l_per_res_id NUMBER;
234 l_mac_res_id NUMBER;
235 l_std_op_id NUMBER;
236 l_move_order_line_id NUMBER;
237 l_operation_plan_id NUMBER;
238 l_priority NUMBER;
239 l_wms_task_type NUMBER;
240 l_msg_count NUMBER;
241 l_msg_data VARCHAR2(2000);
242 l_return_status VARCHAR2(1);
243 l_request_msg VARCHAR2(200);
244 l_lpn_id NUMBER;
245 l_tsks NUMBER;
246 l_device_id NUMBER := NULL;
247 l_temp_device_id NUMBER := NULL;
248 l_assignment_temp_id NUMBER;
249 l_avail_device_id NUMBER := NULL;
250 l_need_dispatch BOOLEAN := TRUE;
251 l_task_type_n NUMBER;
252 l_task_id NUMBER;
253 l_device_invoked VARCHAR2(1);
254 l_invoked_device_id NUMBER;
255 l_first_task BOOLEAN;
256 l_period_id NUMBER;
257 l_open_past_period BOOLEAN;
258 l_request_id NUMBER := NULL;
259
260 CURSOR following_device_list(p_emp_id NUMBER, p_current_device_temp_id NUMBER) IS
261 SELECT wdat.device_id
262 , wdat.assignment_temp_id
263 , wdb.subinventory_code
264 FROM wms_device_assignment_temp wdat, wms_devices_b wdb
265 WHERE wdat.assignment_temp_id >= p_current_device_temp_id
266 AND wdat.employee_id = p_emp_id
267 AND wdat.device_id = wdb.device_id
268 ORDER BY wdat.assignment_temp_id;
269
270 CURSOR front_device_list(p_emp_id NUMBER, p_current_device_temp_id NUMBER) IS
271 SELECT wdat.device_id
272 , wdat.assignment_temp_id
273 , wdb.subinventory_code
274 FROM wms_device_assignment_temp wdat, wms_devices_b wdb
275 WHERE wdat.assignment_temp_id < p_current_device_temp_id
276 AND wdat.employee_id = p_emp_id
277 AND wdat.device_id = wdb.device_id
278 ORDER BY wdat.assignment_temp_id;
279
280 l_txn_hdr_id NUMBER;
281 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
282 BEGIN
283 IF (l_debug = 1) THEN
284 mydebug('In next task:');
285 END IF;
286
287 SAVEPOINT sp_td_gen_next_task;
288 l_return_status := fnd_api.g_ret_sts_success;
289 l_user_id := p_sign_on_emp_id;
290 l_org_id := p_sign_on_org_id;
291 l_zone := p_sign_on_zone;
292 l_eqp_id := p_sign_on_equipment_id;
293 l_eqp_ins := p_sign_on_equipment_srl;
294 l_task_type := p_task_type;
295 l_c_rows := 0;
296 l_next_task_id := 0;
297 -- l_per_res_id:=111;
298 -- l_mac_res_id:=111;
299 l_std_op_id := 1;
300 l_priority := 1;
301 l_wms_task_type := 1;
302 l_lpn_id := p_lpn_id;
303 l_device_id := p_sign_on_device_id;
304
305 IF l_device_id = 0 THEN
306 l_device_id := NULL;
307 END IF;
308
309 l_emp_id := l_user_id;
310 l_tsks := 0;
311 x_task_type := 0;
312
313 IF (l_debug = 1) THEN
314 mydebug('next_task : Need to check if the period is open');
315 END IF;
316
317 invttmtx.tdatechk(org_id => l_org_id, transaction_date => SYSDATE, period_id => l_period_id, open_past_period => l_open_past_period);
318
319 IF l_period_id = -1 THEN
320 IF (l_debug = 1) THEN
321 mydebug('next_task: Period is invalid');
322 END IF;
323
324 fnd_message.set_name('INV', 'INV_NO_OPEN_PERIOD');
325 fnd_msg_pub.ADD;
326 RAISE fnd_api.g_exc_unexpected_error;
327 END IF;
328
329 IF (l_debug = 1) THEN
330 mydebug('next_task: Check to see if there are tasks in wms_disp_tasks already..');
331 END IF;
332
333 /* 3189172 */
334
335 IF l_task_type = 'EXPPICK' THEN
336 SELECT COUNT(*) tsk
337 INTO l_tsks
338 FROM wms_dispatched_tasks wdt
339 WHERE wdt.person_id = l_user_id
340 AND wdt.organization_id = l_org_id
341 AND wdt.task_type IN(1, 3, 4, 5, 6)
342 AND wms_express_pick_task.is_express_pick_task(task_id) = 'S'
343 AND wdt.status <= 3
344 AND ((wdt.task_type = 3
345 AND exists
346 (SELECT NVL(cycle_count_entry_id,-1)
347 --Bug 3808770- Added the table mtl_cycle_count_headers in the from clause
348 FROM mtl_cycle_count_entries mcce,mtl_cycle_count_headers mcch
349 WHERE mcce.cycle_count_entry_id = wdt.transaction_temp_id
350 AND mcce.organization_id = wdt.organization_id
351 AND mcce.subinventory = nvl(p_sign_on_zone,mcce.subinventory) --Added bug3771517
352 AND mcce.entry_status_code in (1,3)
353 --Bug 3808770 Added the following conditions to select only those tasks whose cycle count is not disabled.
354 AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
355 AND NVL(mcch.disable_date,sysdate+1)> sysdate
356 --End of fix for Bug 3808770
357 )
358 )
359 OR (wdt.task_type IN (1, 4, 5, 6)
360 AND EXISTS
361 (SELECT Nvl(mmtt.transaction_temp_id, -1)
362 FROM mtl_material_transactions_temp mmtt
363 WHERE mmtt.transaction_temp_id = wdt.transaction_temp_id
364 AND mmtt.subinventory_code = nvl(p_sign_on_zone,mmtt.subinventory_code) --Added bug3771517
365 AND mmtt.organization_id = wdt.organization_id))
366 );
367
368 ELSE
369
370 SELECT count(*) TSK
371 INTO l_tsks
372 FROM wms_dispatched_tasks wdt
373 WHERE wdt.person_id = l_user_id
374 AND wdt.organization_id = l_org_id
375 AND wdt.task_type IN (1, 3, 4, 5, 6)
376 AND wdt.status <= 3
377 AND ((wdt.task_type = 3
378 AND exists
379 (SELECT NVL(cycle_count_entry_id,-1)
380 FROM mtl_cycle_count_entries mcce ,mtl_cycle_count_headers mcch
381 WHERE mcce.cycle_count_entry_id = wdt.transaction_temp_id
382 AND mcce.subinventory = nvl(p_sign_on_zone,mcce.subinventory) --Added bug3771517
383 AND mcce.organization_id = wdt.organization_id
384 and mcce.entry_status_code in (1,3)
385 --Bug 3808770 Added the following conditions to select only those tasks whose cycle count is not disabled.
386 AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
387 AND NVL(mcch.disable_date,sysdate+1)> sysdate
388 --End of fix for Bug 3808770
389 )
390 )
391 OR (wdt.task_type IN (1, 4, 5, 6)
392 AND EXISTS
393 (SELECT Nvl(mmtt.transaction_temp_id, -1)
394 FROM mtl_material_transactions_temp mmtt
395 WHERE mmtt.transaction_temp_id = wdt.transaction_temp_id
396 AND mmtt.subinventory_code = nvl(p_sign_on_zone,mmtt.subinventory_code) --Added bug3771517
397 AND mmtt.organization_id = wdt.organization_id))
398 );
399
400 END IF;
401
402 IF (l_debug = 1) THEN
403 mydebug('next_task: l_device_id: ' || l_device_id);
404 END IF;
405
406 IF l_tsks <> 0
407 AND l_device_id IS NULL THEN
408 IF (l_debug = 1) THEN
409 mydebug('next_task: There are tasks in wms_disp_tasks already');
410 END IF;
411
412 l_c_rows := -999;
413 x_return_status := fnd_api.g_ret_sts_success;
414
415 -- Also set the task type value even if tasks have
416 -- already been dispatched
417 IF l_task_type = 'EXPPICK' THEN
418 SELECT wt.task_type
419 INTO x_task_type
420 FROM (SELECT wdt.task_type
421 , wdt.priority
422 , wdt.task_id task_id
423 , sub.picking_order sub_picking_order
424 , loc.picking_order loc_picking_order
425 FROM mtl_material_transactions_temp mmtt, wms_dispatched_tasks wdt, mtl_item_locations loc, mtl_secondary_inventories sub
426 WHERE wdt.person_id = l_user_id
427 AND wdt.organization_id = l_org_id
428 AND wdt.status <= 3
429 AND wdt.task_type IN (1, 4, 5, 6)
430 AND WMS_EXPRESS_PICK_TASK.IS_EXPRESS_PICK_TASK(wdt.TASK_ID) = 'S'
431 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
432 AND mmtt.subinventory_code = nvl(p_sign_on_zone,mmtt.subinventory_code) --Added bug3771517
433 AND sub.organization_id = mmtt.organization_id
434 AND sub.secondary_inventory_name = mmtt.subinventory_code
435 AND loc.organization_id = mmtt.organization_id
436 AND loc.inventory_location_id = mmtt.locator_id
437 UNION
438 SELECT wdt.task_type
439 , wdt.priority
440 , wdt.task_id task_id
441 , sub.picking_order sub_picking_order
442 , loc.picking_order loc_picking_order
443 --Bug 3808770 -Added the table mtl_cycle_count_headers in the FROM clause
444 FROM mtl_cycle_count_entries mcce, wms_dispatched_tasks wdt, mtl_item_locations loc, mtl_secondary_inventories sub
445 ,mtl_cycle_count_headers mcch
446 WHERE wdt.person_id = l_user_id
447 AND wdt.organization_id = l_org_id
448 AND wdt.status <= 3
449 AND wdt.task_type = 3
450 AND WMS_EXPRESS_PICK_TASK.IS_EXPRESS_PICK_TASK(wdt.TASK_ID) = 'S'
451 AND wdt.transaction_temp_id = mcce.cycle_count_entry_id
452 AND sub.organization_id = mcce.organization_id
453 AND mcce.subinventory = nvl(p_sign_on_zone,mcce.subinventory) --Added bug3771517
454 AND sub.secondary_inventory_name = mcce.subinventory
455 AND loc.organization_id = mcce.organization_id
456 AND loc.inventory_location_id = mcce.locator_id
457 --Bug 3808770 Added the following conditions to select only those tasks whose cycle count is not disabled.
458 AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
459 AND NVL(mcch.disable_date,sysdate+1)> sysdate ) wt
460 --End of fix for Bug 3808770
461 WHERE ROWNUM = 1
462 order by wt.priority,wt.sub_picking_order, wt.loc_picking_order, wt.task_id ;
463
464 ELSE
465 SELECT wt.task_type
466 INTO x_task_type
467 FROM (SELECT wdt.task_type
468 , wdt.priority
469 , wdt.task_id task_id
470 , sub.picking_order sub_picking_order
471 , loc.picking_order loc_picking_order
472 FROM mtl_material_transactions_temp mmtt, wms_dispatched_tasks wdt, mtl_item_locations loc, mtl_secondary_inventories sub
473 WHERE wdt.person_id = l_user_id
474 AND wdt.organization_id = l_org_id
475 AND wdt.status <= 3
476 AND wdt.task_type IN (1, 4, 5, 6)
477 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
478 AND sub.organization_id = mmtt.organization_id
479 AND sub.secondary_inventory_name = mmtt.subinventory_code
480 AND mmtt.subinventory_code = nvl(p_sign_on_zone,mmtt.subinventory_code) --Added bug3771517
481 AND loc.organization_id = mmtt.organization_id
482 AND loc.inventory_location_id = mmtt.locator_id
483 UNION
484 SELECT wdt.task_type
485 , wdt.priority
486 , wdt.task_id task_id
487 , sub.picking_order sub_picking_order
488 , loc.picking_order loc_picking_order
489 --Bug 3808770 -Added the table mtl_cycle_count_headers in the FROM clause
490 FROM mtl_cycle_count_entries mcce, wms_dispatched_tasks wdt, mtl_item_locations loc, mtl_secondary_inventories sub
491 , mtl_cycle_count_headers mcch
492 WHERE wdt.person_id = l_user_id
493 AND wdt.organization_id = l_org_id
494 AND wdt.status <= 3
495 AND wdt.task_type = 3
496 AND wdt.transaction_temp_id = mcce.cycle_count_entry_id
497 AND sub.organization_id = mcce.organization_id
498 AND mcce.subinventory = nvl(p_sign_on_zone,mcce.subinventory) --Added bug3771517
499 AND sub.secondary_inventory_name = mcce.subinventory
500 AND loc.organization_id = mcce.organization_id
501 AND loc.inventory_location_id = mcce.locator_id
502 --Bug 3808770 Added the following conditions to select only those tasks whose cycle count is not disabled.
503 AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
504 AND NVL(mcch.disable_date,sysdate+1)> sysdate )wt
505 --End of fix for Bug 3808770
506 WHERE ROWNUM = 1
507 order by wt.priority,wt.sub_picking_order, wt.loc_picking_order, wt.task_id;
508
509 END IF;
510 ELSE
511 IF (l_debug = 1) THEN
512 mydebug('next_task: There are no tasks in wms_disp_tasks or device signed on');
513 END IF;
514
515 -- SELECT employee_id INTO l_emp_id FROM fnd_user WHERE user_id=l_user_id;
516
517 IF l_eqp_id = -999 THEN
518 l_eqp_id := NULL;
519 END IF;
520
521 IF l_lpn_id = 0 THEN
522 l_lpn_id := NULL;
523 END IF;
524
525 IF l_device_id IS NOT NULL THEN
526 SELECT wdat.assignment_temp_id
527 , wd.subinventory_code
528 INTO l_assignment_temp_id
529 , l_zone
530 FROM wms_device_assignment_temp wdat, wms_devices_vl wd
531 WHERE wdat.device_id = l_device_id
532 AND wdat.device_id = wd.device_id
533 AND employee_id = l_emp_id;
534 END IF;
535
536 --IF l_eqp_id IS NOT NULL THEN
537 --SELECT resource_id INTO l_mac_res_id
538 --FROM bom_resource_equipments
539 --WHERE organization_id=l_org_id
540 --AND inventory_item_id=l_eqp_id;
541 --END IF;
542
543 --SELECT resource_id INTO l_per_res_id
544 --FROM bom_resource_employees
545 --WHERE organization_id=l_org_id
546 --AND person_id=l_emp_id;
547
548 IF (l_debug = 1) THEN
549 mydebug('next_task: TaskType' || l_task_type);
550 END IF;
551
552 IF l_lpn_id = fnd_api.g_miss_num THEN
553 l_lpn_id := NULL;
554 END IF;
555
556 IF (l_device_id IS NOT NULL) THEN
557 OPEN following_device_list(l_emp_id, l_assignment_temp_id);
558 OPEN front_device_list(l_emp_id, l_assignment_temp_id);
559 END IF;
560
561 LOOP
562 IF l_device_id IS NOT NULL THEN
563
564 <<search_device_loop>>
565 LOOP -- loop to find the available task and check if we need to dispatch task to some devices
566 FETCH following_device_list INTO l_temp_device_id, l_assignment_temp_id, l_zone;
567
568 IF (following_device_list%NOTFOUND) THEN
569 FETCH front_device_list INTO l_temp_device_id, l_assignment_temp_id, l_zone;
570
571 IF (front_device_list%NOTFOUND) THEN
572 CLOSE following_device_list;
573 CLOSE front_device_list;
574 l_need_dispatch := FALSE;
575 EXIT search_device_loop;
576 END IF;
577 END IF;
578
579 BEGIN
580 SELECT transaction_temp_id
581 , task_type
582 , device_invoked
583 INTO l_task_id
584 , l_task_type_n
585 , l_device_invoked
586 FROM wms_dispatched_tasks
587 WHERE person_id = l_user_id
588 AND organization_id = l_org_id
589 AND device_id = l_temp_device_id
590 AND task_type IN(1, 3, 4, 5, 6)
591 AND status <= 3
592 AND ROWNUM = 1
593 ORDER BY 1;
594
595 IF (l_device_invoked = 'Y'
596 AND l_avail_device_id IS NULL) THEN
597 l_avail_device_id := l_temp_device_id;
598 x_task_type := l_task_type_n;
599 ELSIF l_device_invoked = 'N' THEN
600 wms_device_integration_pvt.device_request(
601 p_bus_event => wms_device_integration_pvt.wms_be_pick_load
602 , p_call_ctx => wms_device_integration_pvt.dev_req_auto
603 , p_task_trx_id => l_task_id
604 , p_org_id => l_org_id
605 , x_request_msg => l_request_msg
606 , x_return_status => l_return_status
607 , x_msg_count => l_msg_count
608 , x_msg_data => l_msg_data
609 , p_request_id => l_request_id
610 );
611
612 -- always dispatch the task whether invoking device successfully or not
613 -- So update the table always
614
615 UPDATE wms_dispatched_tasks
616 SET device_invoked = 'Y'
617 , device_request_id = l_request_id
618 WHERE transaction_temp_id = l_task_id;
619
620 IF l_invoked_device_id IS NULL THEN
621 l_invoked_device_id := l_temp_device_id;
622 END IF;
623
624 IF l_return_status <> fnd_api.g_ret_sts_success THEN
625 IF (l_debug = 1) THEN
626 mydebug('next_task:failed to invoke device ' || TO_CHAR(l_temp_device_id));
627 END IF;
628 END IF;
629 END IF;
630 EXCEPTION
631 WHEN NO_DATA_FOUND THEN
632 l_need_dispatch := TRUE;
633 EXIT search_device_loop;
634 END;
635 END LOOP;
636 END IF;
637
638 EXIT WHEN l_need_dispatch = FALSE;
639
640 IF (l_debug = 1) THEN
641 mydebug('next_task: Before Calling TD Engine');
642 END IF;
643
644 if (l_eqp_id is null and l_eqp_ins is null) then
645 IF (l_debug = 1) THEN
646 mydebug('l_eqp_id is null and l_eqp_ins is null');
647 end if;
648 l_eqp_ins := 'NONE';
649 end if;
650
651 IF (l_debug = 1) THEN
652 mydebug('l_eqp_id='||l_eqp_id);
653 mydebug('l_eqp_ins='||l_eqp_ins);
654 end if;
655
656 wms_task_dispatch_engine.dispatch_task(
657 p_api_version => 1.0
658 , p_init_msg_list => 'F'
659 , p_commit => NULL
660 , p_sign_on_emp_id => l_emp_id
661 , p_sign_on_org_id => l_org_id
662 , p_sign_on_zone => l_zone
663 , p_sign_on_equipment_id => l_eqp_id
664 , p_sign_on_equipment_srl => l_eqp_ins
665 , p_task_type => l_task_type
666 , x_task_cur => l_task_cur
667 , x_return_status => l_return_status
668 , x_msg_count => l_msg_count
669 , x_msg_data => l_msg_data
670 , p_cartonization_id => l_lpn_id
671 );
672
673 IF (l_debug = 1) THEN
674 mydebug('next_task: Ret Status' || l_return_status);
675 END IF;
676
677 IF l_return_status = fnd_api.g_ret_sts_success THEN
678 IF (l_debug = 1) THEN
679 mydebug('in here');
680 END IF;
681
682 l_first_task := TRUE;
683
684 LOOP
685 FETCH l_task_cur INTO task_rec;
686
687 IF (l_debug = 1) THEN
688 mydebug('before l_task_cur');
689 END IF;
690
691 EXIT WHEN l_task_cur%NOTFOUND;
692 l_c_rows := l_c_rows + 1;
693
694 IF (l_debug = 1) THEN
695 mydebug('next_task: TaskID:' || task_rec.task_id);
696 END IF;
697
698 IF (l_debug = 1) THEN
699 mydebug('next_task: getting Resource ID....');
700 END IF;
701
702 IF (task_rec.task_type <> 3) THEN
703 -- Picking, Putaway, or Replenishment task
704 SELECT bremp.resource_id role_id
705 , t.wms_task_type
706 , t.standard_operation_id
707 , t.operation_plan_id
708 , t.move_order_line_id
709 INTO l_per_res_id
710 , l_wms_task_type
711 , l_std_op_id
712 , l_operation_plan_id
713 , l_move_order_line_id
714 FROM mtl_material_transactions_temp t, bom_std_op_resources bsor, bom_resources bremp
715 WHERE t.transaction_temp_id = task_rec.task_id
716 AND t.standard_operation_id = bsor.standard_operation_id
717 AND bsor.resource_id = bremp.resource_id
718 AND bremp.resource_type = 2
719 AND ROWNUM < 2;
720 ELSE
721 -- Cycle counting task
722 SELECT bremp.resource_id role_id
723 , 3
724 , mcce.standard_operation_id
725 INTO l_per_res_id
726 , l_wms_task_type
727 , l_std_op_id
728 --Bug 3808770- Added the table mtl_cycle_count_headers in the FROM clause
729 FROM mtl_cycle_count_entries mcce, bom_std_op_resources bsor, bom_resources bremp,mtl_cycle_count_headers mcch
730 WHERE mcce.cycle_count_entry_id = task_rec.task_id
731 AND mcce.standard_operation_id = bsor.standard_operation_id
732 AND bsor.resource_id = bremp.resource_id
733 AND bremp.resource_type = 2
734 AND ROWNUM < 2
735 AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
736 AND NVL(mcch.disable_date,sysdate+1)> sysdate;
737 END IF;
738
739 IF (l_debug = 1) THEN
740 mydebug('next_task: After getting Resource ID....');
741 END IF;
742
743 IF l_eqp_id IS NOT NULL THEN
744 -- bug fix 1772907, lezhang
745
746 SELECT resource_id
747 INTO l_mac_res_id
748 FROM bom_resource_equipments
749 WHERE inventory_item_id = l_eqp_id
750 AND ROWNUM < 2;
751 --select breqp.resource_id equip_type_id
752 --INTO l_mac_res_id
753 --from mtl_material_transactions_temp t,
754 --bom_std_op_resources bsor,
755 --bom_resources breqp
756 --where t.transaction_temp_id = task_rec.task_id
757 --and t.standard_operation_id = bsor.standard_operation_id
758 --and bsor.resource_id = breqp.resource_id
759 --and breqp.resource_type = 1
760 --and rownum<2;
761
762 END IF;
763
764 SELECT mtl_material_transactions_s.NEXTVAL txnhdrid
765 INTO l_txn_hdr_id
766 FROM DUAL;
767
768 UPDATE mtl_material_transactions_temp
769 SET transaction_header_id = l_txn_hdr_id
770 WHERE transaction_temp_id = task_rec.task_id;
771
772 -- Insert into WMS_DISPATCHED_TASKS for this user
773
774 SELECT wms_dispatched_tasks_s.NEXTVAL
775 INTO l_next_task_id
776 FROM DUAL;
777
778 INSERT INTO wms_dispatched_tasks
779 (
780 task_id
781 , transaction_temp_id
782 , organization_id
783 , user_task_type
784 , person_id
785 , effective_start_date
786 , effective_end_date
787 , equipment_id
788 , equipment_instance
789 , person_resource_id
790 , machine_resource_id
791 , status
792 , dispatched_time
793 , last_update_date
794 , last_updated_by
795 , creation_date
796 , created_by
797 , task_type
798 , priority
799 , operation_plan_id
800 , move_order_line_id
801 )
802 VALUES (
803 l_next_task_id
804 , task_rec.task_id
805 , l_org_id
806 , NVL(l_std_op_id, 2)
807 , l_user_id
808 , SYSDATE
809 , SYSDATE
810 , l_eqp_id
811 , l_eqp_ins
812 , l_per_res_id
813 , l_mac_res_id
814 , 3
815 , SYSDATE
816 , SYSDATE
817 , l_emp_id
818 , SYSDATE
819 , l_emp_id
820 , l_wms_task_type
821 , task_rec.task_priority
822 , l_operation_plan_id
823 , l_move_order_line_id
824 );
825
826 IF (l_debug = 1) THEN
827 mydebug('next_task: After Insert into WMSDT');
828 END IF;
829
830 -- If LPN has been provided, exit, since we only want the first
831 --task
832 IF l_lpn_id IS NULL
833 OR l_lpn_id = fnd_api.g_miss_num THEN
834 IF (l_debug = 1) THEN
835 mydebug('next_task: LPN was not provided');
836 END IF;
837 ELSE
838 IF (l_debug = 1) THEN
839 mydebug('next_task: LPN was provided - pick by label');
840 END IF;
841
842 EXIT;
843 END IF;
844
845 IF l_temp_device_id IS NOT NULL THEN
846 IF (l_debug = 1) THEN
847 mydebug('next_task: temp_device_id');
848 END IF;
849
850 UPDATE wms_dispatched_tasks
851 SET device_id = l_temp_device_id
852 , device_invoked = 'N'
853 WHERE task_id = l_next_task_id;
854
855 IF l_first_task THEN -- invoke the device
856 wms_device_integration_pvt.device_request(
857 p_bus_event => wms_device_integration_pvt.wms_be_pick_load
858 , p_call_ctx => wms_device_integration_pvt.dev_req_auto
859 , p_task_trx_id => task_rec.task_id
860 , p_org_id => l_org_id
861 , x_request_msg => l_request_msg
862 , x_return_status => l_return_status
863 , x_msg_count => l_msg_count
864 , x_msg_data => l_msg_data
865 , p_request_id => l_request_id
866 );
867
868 -- always dispatch the task whether invoking device successfully or not
869 -- So update the table always
870
871
872 UPDATE wms_dispatched_tasks
873 SET device_invoked = 'Y'
874 , device_request_id = l_request_id
875 WHERE task_id = l_next_task_id;
876
877 IF l_invoked_device_id IS NULL THEN
878 l_invoked_device_id := l_temp_device_id;
879 END IF;
880
881 IF l_return_status <> fnd_api.g_ret_sts_success THEN
882 IF (l_debug = 1) THEN
883 mydebug('next_task:failed to invoke device ' || TO_CHAR(l_temp_device_id));
884 END IF;
885 END IF;
886
887 l_first_task := FALSE;
888 END IF;
889 END IF;
890 END LOOP;
891
892 --********************
893 DELETE FROM wms_skip_task_exceptions
894 WHERE task_id = task_rec.task_id
895 AND task_id IN(
896 SELECT wste.task_id
897 FROM wms_skip_task_exceptions wste, mtl_parameters mp
898 WHERE ABS((SYSDATE - wste.creation_date) * 24 * 60) > mp.skip_task_waiting_minutes
899 AND wste.task_id = task_rec.task_id
900 AND wste.organization_id = mp.organization_id);
901
902 --************************
903
904 -- Set the output task type parameter equals to the last
905 -- task type returned since they should all be of the same type
906 x_task_type := l_wms_task_type;
907
908 -- Committing these tasks to this user
909 IF (l_debug = 1) THEN
910 mydebug('before commiting');
911 END IF;
912
913 COMMIT;
914 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
915 fnd_message.set_name('WMS', 'WMS_TD_TDENG_ERROR');
916 fnd_msg_pub.ADD;
917 RAISE fnd_api.g_exc_unexpected_error;
918 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
919 IF (l_debug = 1) THEN
920 mydebug('next_task: Setting status to S');
921 END IF;
922
923 l_return_status := fnd_api.g_ret_sts_success;
924 -- l_c_rows:=0;
925 END IF;
926
927 IF l_device_id IS NULL THEN
928 l_need_dispatch := FALSE;
929 END IF;
930 END LOOP; -- end loop of the devices
931
932 IF l_avail_device_id IS NOT NULL THEN
933 x_avail_device_id := l_avail_device_id;
934 l_c_rows := 1; -- to indicate there are tasks already
935 ELSIF l_invoked_device_id IS NOT NULL THEN
936 x_avail_device_id := l_invoked_device_id;
937 l_c_rows := 1; -- to indicate there are tasks already
938
939 SELECT task_type
940 INTO x_task_type
941 FROM wms_dispatched_tasks
942 WHERE device_id = x_avail_device_id
943 AND device_invoked = 'Y'
944 AND person_id = l_user_id
945 AND status <= 3
946 AND task_type IN(1, 3, 4, 5, 6);
947 ELSIF l_device_id IS NOT NULL THEN
948 l_c_rows := 0;
949 END IF;
950 END IF;
951
952 IF (l_debug = 1) THEN
953 mydebug('next_tasks: number of tasks: ' || l_c_rows);
954 mydebug('next_task: done with API');
955 END IF;
956
957 x_nbr_tasks := l_c_rows;
958 x_return_status := fnd_api.g_ret_sts_success;
959 COMMIT;
960 EXCEPTION
961 WHEN fnd_api.g_exc_error THEN
962 x_return_status := fnd_api.g_ret_sts_error;
963 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
964 ROLLBACK TO sp_td_gen_next_task;
965 WHEN OTHERS THEN
966 x_return_status := fnd_api.g_ret_sts_unexp_error;
967 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
968 ROLLBACK TO sp_td_gen_next_task;
969 END next_task;
970
971 -- Cluster Picking Enhancments.
972 -- This procedure will call task dispatching for Cluster Pick
973 PROCEDURE next_cluster_pick_task(
974 p_sign_on_emp_id IN NUMBER
975 , p_sign_on_org_id IN NUMBER
976 , p_sign_on_zone IN VARCHAR2
977 , p_sign_on_equipment_id IN NUMBER
978 , p_sign_on_equipment_srl IN VARCHAR2
979 , p_task_type IN VARCHAR2
980 , x_nbr_tasks OUT NOCOPY NUMBER
981 , p_lpn_id IN NUMBER
982 , x_return_status OUT NOCOPY VARCHAR2
983 , x_msg_count OUT NOCOPY NUMBER
984 , x_msg_data OUT NOCOPY VARCHAR2
985 , x_task_type OUT NOCOPY NUMBER
986 , p_sign_on_device_id IN NUMBER
987 , x_avail_device_id OUT NOCOPY NUMBER
988 , p_max_clusters IN NUMBER
989 , x_deliveries_list OUT NOCOPY VARCHAR2
990 , x_cartons_list OUT NOCOPY VARCHAR2
991 ) IS
992 l_cartonization_id NUMBER := NULL;
993 task_rec wms_task_dispatch_gen.task_rec_tp;
994 l_task_cur wms_task_dispatch_gen.task_rec_cur_tp;
995 l_user_id NUMBER;
996 l_emp_id NUMBER;
997 l_org_id NUMBER;
998 l_zone VARCHAR2(10);
999 l_eqp_id NUMBER;
1000 l_eqp_ins VARCHAR2(30);
1001 l_task_type VARCHAR2(30);
1002 l_c_rows NUMBER;
1003 l_next_task_id NUMBER;
1004 l_per_res_id NUMBER;
1005 l_mac_res_id NUMBER;
1006 l_std_op_id NUMBER;
1007 l_move_order_line_id NUMBER;
1008 l_operation_plan_id NUMBER;
1009 l_priority NUMBER;
1010 l_wms_task_type NUMBER;
1011 l_msg_count NUMBER;
1012 l_msg_data VARCHAR2(2000);
1013 l_return_status VARCHAR2(1);
1014 l_request_msg VARCHAR2(200);
1015 l_lpn_id NUMBER;
1016 l_tsks NUMBER;
1017 l_device_id NUMBER := NULL;
1018 l_temp_device_id NUMBER := NULL;
1019 l_assignment_temp_id NUMBER;
1020 l_avail_device_id NUMBER := NULL;
1021 l_need_dispatch BOOLEAN := TRUE;
1022 l_task_type_n NUMBER;
1023 l_task_id NUMBER;
1024 l_device_invoked VARCHAR2(1);
1025 l_invoked_device_id NUMBER;
1026 l_first_task BOOLEAN;
1027 l_period_id NUMBER;
1028 l_open_past_period BOOLEAN;
1029 l_request_id NUMBER := NULL;
1030
1031 CURSOR following_device_list(p_emp_id NUMBER, p_current_device_temp_id NUMBER) IS
1032 SELECT wdat.device_id
1033 , wdat.assignment_temp_id
1034 , wdb.subinventory_code
1035 FROM wms_device_assignment_temp wdat, wms_devices_b wdb
1036 WHERE wdat.assignment_temp_id >= p_current_device_temp_id
1037 AND wdat.employee_id = p_emp_id
1038 AND wdat.device_id = wdb.device_id
1039 ORDER BY wdat.assignment_temp_id;
1040
1041 CURSOR front_device_list(p_emp_id NUMBER, p_current_device_temp_id NUMBER) IS
1042 SELECT wdat.device_id
1043 , wdat.assignment_temp_id
1044 , wdb.subinventory_code
1045 FROM wms_device_assignment_temp wdat, wms_devices_b wdb
1046 WHERE wdat.assignment_temp_id < p_current_device_temp_id
1047 AND wdat.employee_id = p_emp_id
1048 AND wdat.device_id = wdb.device_id
1049 ORDER BY wdat.assignment_temp_id;
1050
1051 l_txn_hdr_id NUMBER;
1052 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1053 BEGIN
1054 IF (l_debug = 1) THEN
1055 mydebug('In next task:');
1056 END IF;
1057
1058 SAVEPOINT sp_td_gen_next_cp_task;
1059 l_return_status := fnd_api.g_ret_sts_success;
1060 l_user_id := p_sign_on_emp_id;
1061 l_org_id := p_sign_on_org_id;
1062 l_zone := p_sign_on_zone;
1063 l_eqp_id := p_sign_on_equipment_id;
1064 l_eqp_ins := p_sign_on_equipment_srl;
1065 l_task_type := p_task_type;
1066 l_c_rows := 0;
1067 l_next_task_id := 0;
1068 -- l_per_res_id:=111;
1069 -- l_mac_res_id:=111;
1070 l_std_op_id := 1;
1071 l_priority := 1;
1072 l_wms_task_type := 1;
1073 l_lpn_id := p_lpn_id;
1074 l_device_id := p_sign_on_device_id;
1075
1076 IF l_device_id = 0 THEN
1077 l_device_id := NULL;
1078 END IF;
1079
1080 l_emp_id := l_user_id;
1081 l_tsks := 0;
1082 x_task_type := 0;
1083
1084 IF (l_debug = 1) THEN
1085 mydebug('next_CP_task : Need to check if the period is open');
1086 END IF;
1087
1088 invttmtx.tdatechk(org_id => l_org_id, transaction_date => SYSDATE, period_id => l_period_id, open_past_period => l_open_past_period);
1089
1090 IF l_period_id = -1 THEN
1091 IF (l_debug = 1) THEN
1092 mydebug('next_CP_task: Period is invalid');
1093 END IF;
1094
1095 fnd_message.set_name('INV', 'INV_NO_OPEN_PERIOD');
1096 fnd_msg_pub.ADD;
1097 RAISE fnd_api.g_exc_unexpected_error;
1098 END IF;
1099
1100 IF (l_debug = 1) THEN
1101 mydebug('next_CP_task: done with open period check');
1102 END IF;
1103
1104 IF l_eqp_id = -999 THEN
1105 l_eqp_id := NULL;
1106 END IF;
1107
1108 IF l_lpn_id = 0 THEN
1109 l_lpn_id := NULL;
1110 END IF;
1111
1112 IF l_device_id IS NOT NULL THEN
1113 SELECT wdat.assignment_temp_id
1114 , wd.subinventory_code
1115 INTO l_assignment_temp_id
1116 , l_zone
1117 FROM wms_device_assignment_temp wdat, wms_devices_vl wd
1118 WHERE wdat.device_id = l_device_id
1119 AND wdat.device_id = wd.device_id
1120 AND employee_id = l_emp_id;
1121 END IF;
1122
1123 IF (l_debug = 1) THEN
1124 mydebug('next_CP_task: TaskType' || l_task_type);
1125 END IF;
1126
1127 IF l_lpn_id = fnd_api.g_miss_num THEN
1128 l_lpn_id := NULL;
1129 END IF;
1130
1131 IF (l_device_id IS NOT NULL) THEN
1132 OPEN following_device_list(l_emp_id, l_assignment_temp_id);
1133 OPEN front_device_list(l_emp_id, l_assignment_temp_id);
1134 END IF;
1135
1136 LOOP
1137 IF l_device_id IS NOT NULL THEN
1138
1139 <<search_device_loop>>
1140 LOOP -- loop to find the available task and check if we need to dispatch task to some devices
1141 FETCH following_device_list INTO l_temp_device_id, l_assignment_temp_id, l_zone;
1142
1143 IF (following_device_list%NOTFOUND) THEN
1144 FETCH front_device_list INTO l_temp_device_id, l_assignment_temp_id, l_zone;
1145
1146 IF (front_device_list%NOTFOUND) THEN
1147 CLOSE following_device_list;
1148 CLOSE front_device_list;
1149 l_need_dispatch := FALSE;
1150 EXIT search_device_loop;
1151 END IF;
1152 END IF;
1153
1154 BEGIN
1155 SELECT transaction_temp_id
1156 , task_type
1157 , device_invoked
1158 INTO l_task_id
1159 , l_task_type_n
1160 , l_device_invoked
1161 FROM wms_dispatched_tasks
1162 WHERE person_id = l_user_id
1163 AND organization_id = l_org_id
1164 AND device_id = l_temp_device_id
1165 AND task_type IN(1, 3, 4, 5, 6)
1166 AND status <= 3
1167 AND ROWNUM = 1
1168 ORDER BY 1;
1169
1170 IF (l_device_invoked = 'Y'
1171 AND l_avail_device_id IS NULL) THEN
1172 l_avail_device_id := l_temp_device_id;
1173 x_task_type := l_task_type_n;
1174 ELSIF l_device_invoked = 'N' THEN
1175 wms_device_integration_pvt.device_request(
1176 p_bus_event => wms_device_integration_pvt.wms_be_pick_load
1177 , p_call_ctx => wms_device_integration_pvt.dev_req_auto
1178 , p_task_trx_id => l_task_id
1179 , p_org_id => l_org_id
1180 , x_request_msg => l_request_msg
1181 , x_return_status => l_return_status
1182 , x_msg_count => l_msg_count
1183 , x_msg_data => l_msg_data
1184 , p_request_id => l_request_id
1185 );
1186
1187 -- always dispatch the task whether invoking device successfully or not
1188 -- So update the table always
1189
1190 UPDATE wms_dispatched_tasks
1191 SET device_invoked = 'Y'
1192 , device_request_id = l_request_id
1193 WHERE transaction_temp_id = l_task_id;
1194
1195 IF l_invoked_device_id IS NULL THEN
1196 l_invoked_device_id := l_temp_device_id;
1197 END IF;
1198
1199 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1200 IF (l_debug = 1) THEN
1201 mydebug('next_CP_task:failed to invoke device ' || TO_CHAR(l_temp_device_id));
1202 END IF;
1203 END IF;
1204 END IF;
1205 EXCEPTION
1206 WHEN NO_DATA_FOUND THEN
1207 l_need_dispatch := TRUE;
1208 EXIT search_device_loop;
1209 END;
1210 END LOOP;
1211 END IF;
1212
1213 EXIT WHEN l_need_dispatch = FALSE;
1214
1215 IF (l_debug = 1) THEN
1216 mydebug('next_CP_task: Before Calling TD Engine');
1217 END IF;
1218
1219 wms_task_dispatch_engine.dispatch_task(
1220 p_api_version => 1.0
1221 , p_init_msg_list => 'F'
1222 , p_commit => NULL
1223 , p_sign_on_emp_id => l_emp_id
1224 , p_sign_on_org_id => l_org_id
1225 , p_sign_on_zone => l_zone
1226 , p_sign_on_equipment_id => l_eqp_id
1227 , p_sign_on_equipment_srl => l_eqp_ins
1228 , p_task_type => l_task_type
1229 , x_task_cur => l_task_cur
1230 , x_return_status => l_return_status
1231 , x_msg_count => l_msg_count
1232 , x_msg_data => l_msg_data
1233 , p_cartonization_id => l_lpn_id
1234 , p_max_clusters => p_max_clusters
1235 , x_deliveries_list => x_deliveries_list
1236 , x_cartons_list => x_cartons_list
1237 );
1238
1239 IF (l_debug = 1) THEN
1240 mydebug('next_CP_task: Ret Status' || l_return_status);
1241 END IF;
1242
1243 IF l_return_status = fnd_api.g_ret_sts_success THEN
1244 IF (l_debug = 1) THEN
1245 mydebug('Task dispatch is sucess for cluster pick');
1246 END IF;
1247
1248 l_first_task := TRUE;
1249
1250 LOOP
1251 FETCH l_task_cur INTO task_rec;
1252
1253 IF (l_debug = 1) THEN
1254 mydebug('before l_task_cur');
1255 END IF;
1256
1257 EXIT WHEN l_task_cur%NOTFOUND;
1258 l_c_rows := l_c_rows + 1;
1259
1260 IF (l_debug = 1) THEN
1261 mydebug('next_CP_task: TaskID:' || task_rec.task_id);
1262 END IF;
1263
1264 IF (l_debug = 1) THEN
1265 mydebug('next_CP_task: getting Resource ID....');
1266 END IF;
1267
1268 IF (task_rec.task_type <> 3) THEN
1269 -- Picking, Putaway, or Replenishment task
1270 SELECT bremp.resource_id role_id
1271 , t.wms_task_type
1272 , t.standard_operation_id
1273 , t.operation_plan_id
1274 , t.move_order_line_id
1275 INTO l_per_res_id
1276 , l_wms_task_type
1277 , l_std_op_id
1278 , l_operation_plan_id
1279 , l_move_order_line_id
1280 FROM mtl_material_transactions_temp t, bom_std_op_resources bsor, bom_resources bremp
1281 WHERE t.transaction_temp_id = task_rec.task_id
1282 AND t.standard_operation_id = bsor.standard_operation_id
1283 AND bsor.resource_id = bremp.resource_id
1284 AND bremp.resource_type = 2
1285 AND ROWNUM < 2;
1286 /*ELSE
1287 -- Cycle counting task
1288 SELECT
1289 bremp.resource_id role_id,
1290 3,
1291 mcce.standard_operation_id
1292 INTO
1293 l_per_res_id,
1294 l_wms_task_type,
1295 l_std_op_id
1296 FROM
1297 mtl_cycle_count_entries mcce,
1298 bom_std_op_resources bsor,
1299 bom_resources bremp
1300 where mcce.cycle_count_entry_id = task_rec.task_id
1301 and mcce.standard_operation_id = bsor.standard_operation_id
1302 and bsor.resource_id = bremp.resource_id
1303 and bremp.resource_type = 2
1304 and rownum<2;
1305 */
1306 END IF;
1307
1308 IF (l_debug = 1) THEN
1309 mydebug('next_CP_task: After getting Resource ID....');
1310 END IF;
1311
1312 IF l_eqp_id IS NOT NULL THEN
1313 SELECT resource_id
1314 INTO l_mac_res_id
1315 FROM bom_resource_equipments
1316 WHERE inventory_item_id = l_eqp_id
1317 AND ROWNUM < 2;
1318 END IF;
1319
1320 SELECT mtl_material_transactions_s.NEXTVAL txnhdrid
1321 INTO l_txn_hdr_id
1322 FROM DUAL;
1323
1324 UPDATE mtl_material_transactions_temp
1325 SET transaction_header_id = l_txn_hdr_id
1326 WHERE transaction_temp_id = task_rec.task_id;
1327
1328 -- Insert into WMS_DISPATCHED_TASKS for this user
1329 SELECT wms_dispatched_tasks_s.NEXTVAL
1330 INTO l_next_task_id
1331 FROM DUAL;
1332
1333 INSERT INTO wms_dispatched_tasks
1334 (
1335 task_id
1336 , transaction_temp_id
1337 , organization_id
1338 , user_task_type
1339 , person_id
1340 , effective_start_date
1341 , effective_end_date
1342 , equipment_id
1343 , equipment_instance
1344 , person_resource_id
1345 , machine_resource_id
1346 , status
1347 , dispatched_time
1348 , last_update_date
1349 , last_updated_by
1350 , creation_date
1351 , created_by
1352 , task_type
1353 , priority
1354 , operation_plan_id
1355 , move_order_line_id
1356 )
1357 VALUES (
1358 l_next_task_id
1359 , task_rec.task_id
1360 , l_org_id
1361 , NVL(l_std_op_id, 2)
1362 , l_user_id
1363 , SYSDATE
1364 , SYSDATE
1365 , l_eqp_id
1366 , l_eqp_ins
1367 , l_per_res_id
1368 , l_mac_res_id
1369 , 3
1370 , SYSDATE
1371 , SYSDATE
1372 , l_emp_id
1373 , SYSDATE
1374 , l_emp_id
1375 , l_wms_task_type
1376 , task_rec.task_priority
1377 , l_operation_plan_id
1378 , l_move_order_line_id
1379 );
1380
1381 IF (l_debug = 1) THEN
1382 mydebug('next_CP_task: After Insert into WMSDT');
1383 END IF;
1384
1385 -- If LPN has been provided, exit, since we only want the first
1386 --task
1387 IF l_lpn_id IS NULL
1388 OR l_lpn_id = fnd_api.g_miss_num THEN
1389 IF (l_debug = 1) THEN
1390 mydebug('next_CP_task: LPN was not provided');
1391 END IF;
1392 ELSE
1393 IF (l_debug = 1) THEN
1394 mydebug('next_CP_task: LPN was provided - pick by label');
1395 END IF;
1396
1397 EXIT;
1398 END IF;
1399
1400 IF l_temp_device_id IS NOT NULL THEN
1401 IF (l_debug = 1) THEN
1402 mydebug('next_CP_task: temp_device_id');
1403 END IF;
1404
1405 UPDATE wms_dispatched_tasks
1406 SET device_id = l_temp_device_id
1407 , device_invoked = 'N'
1408 WHERE task_id = l_next_task_id;
1409
1410 IF l_first_task THEN -- invoke the device
1411 wms_device_integration_pvt.device_request(
1412 p_bus_event => wms_device_integration_pvt.wms_be_pick_load
1413 , p_call_ctx => wms_device_integration_pvt.dev_req_auto
1414 , p_task_trx_id => task_rec.task_id
1415 , p_org_id => l_org_id
1416 , x_request_msg => l_request_msg
1417 , x_return_status => l_return_status
1418 , x_msg_count => l_msg_count
1419 , x_msg_data => l_msg_data
1420 , p_request_id => l_request_id
1421 );
1422
1423 -- always dispatch the task whether invoking device successfully or not
1424 -- So update the table always
1425
1426
1427 UPDATE wms_dispatched_tasks
1428 SET device_invoked = 'Y'
1429 , device_request_id = l_request_id
1430 WHERE task_id = l_next_task_id;
1431
1432 IF l_invoked_device_id IS NULL THEN
1433 l_invoked_device_id := l_temp_device_id;
1434 END IF;
1435
1436 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1437 IF (l_debug = 1) THEN
1438 mydebug('next_CP_task:failed to invoke device ' || TO_CHAR(l_temp_device_id));
1439 END IF;
1440 END IF;
1441
1442 l_first_task := FALSE;
1443 END IF;
1444 END IF;
1445 END LOOP;
1446
1447 --********************
1448 DELETE FROM wms_skip_task_exceptions
1449 WHERE task_id = task_rec.task_id
1450 AND task_id IN(
1451 SELECT wste.task_id
1452 FROM wms_skip_task_exceptions wste, mtl_parameters mp
1453 WHERE ABS((SYSDATE - wste.creation_date) * 24 * 60) > mp.skip_task_waiting_minutes
1454 AND wste.task_id = task_rec.task_id
1455 AND wste.organization_id = mp.organization_id);
1456
1457 --************************
1458
1459 -- Set the output task type parameter equals to the last
1460 -- task type returned since they should all be of the same type
1461 x_task_type := l_wms_task_type;
1462
1463 -- Committing these tasks to this user
1464 IF (l_debug = 1) THEN
1465 mydebug('before commiting');
1466 END IF;
1467
1468 COMMIT;
1469 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1470 fnd_message.set_name('WMS', 'WMS_TD_TDENG_ERROR');
1471 fnd_msg_pub.ADD;
1472 RAISE fnd_api.g_exc_unexpected_error;
1473 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1474 IF (l_debug = 1) THEN
1475 mydebug('next_CP_task: Setting status to S');
1476 END IF;
1477
1478 l_return_status := fnd_api.g_ret_sts_success;
1479 -- l_c_rows:=0;
1480 END IF;
1481
1482 IF l_device_id IS NULL THEN
1483 l_need_dispatch := FALSE;
1484 END IF;
1485 END LOOP; -- end loop of the devices
1486
1487 IF l_avail_device_id IS NOT NULL THEN
1488 x_avail_device_id := l_avail_device_id;
1489 l_c_rows := 1; -- to indicate there are tasks already
1490 ELSIF l_invoked_device_id IS NOT NULL THEN
1491 x_avail_device_id := l_invoked_device_id;
1492 l_c_rows := 1; -- to indicate there are tasks already
1493
1494 SELECT task_type
1495 INTO x_task_type
1496 FROM wms_dispatched_tasks
1497 WHERE device_id = x_avail_device_id
1498 AND device_invoked = 'Y'
1499 AND person_id = l_user_id
1500 AND status <= 3
1501 AND task_type IN(1, 3, 4, 5, 6);
1502 ELSIF l_device_id IS NOT NULL THEN
1503 l_c_rows := 0;
1504 END IF;
1505
1506 IF (l_debug = 1) THEN
1507 mydebug('next_CP_task: number of tasks: ' || l_c_rows);
1508 mydebug('next_CP_task: done with API');
1509 END IF;
1510
1511 x_nbr_tasks := l_c_rows;
1512 x_return_status := fnd_api.g_ret_sts_success;
1513 COMMIT;
1514 EXCEPTION
1515 WHEN fnd_api.g_exc_error THEN
1516 x_return_status := fnd_api.g_ret_sts_error;
1517 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1518 ROLLBACK TO sp_td_gen_next_cp_task;
1519 WHEN OTHERS THEN
1520 x_return_status := fnd_api.g_ret_sts_unexp_error;
1521 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1522 ROLLBACK TO sp_td_gen_next_cp_task;
1523 END next_cluster_pick_task;
1524
1525 --p_loc, p_sub are user inputs
1526 PROCEDURE complete_pick(
1527 p_lpn IN VARCHAR2
1528 , p_container_item_id IN NUMBER
1529 , p_org_id IN NUMBER
1530 , p_temp_id IN NUMBER
1531 , p_loc IN NUMBER
1532 , p_sub IN VARCHAR2
1533 , p_from_lpn_id IN NUMBER
1534 , p_txn_hdr_id IN NUMBER
1535 , p_user_id IN NUMBER
1536 , x_return_status OUT NOCOPY VARCHAR2
1537 , x_msg_count OUT NOCOPY NUMBER
1538 , x_msg_data OUT NOCOPY VARCHAR2
1539 , p_ok_to_process OUT NOCOPY VARCHAR2
1540 ) IS
1541 l_msg_cnt NUMBER;
1542 l_msg_data VARCHAR2(2000);
1543 l_return_status VARCHAR2(240);
1544 l_lpn_id NUMBER;
1545 l_lpn VARCHAR2(30);
1546 l_exist_lpn NUMBER;
1547 l_txn_ret NUMBER;
1548 l_loc NUMBER;
1549 l_from_lpn_id NUMBER;
1550 l_content_lpn_id NUMBER;
1551 l_mmtt_from_lpn_id NUMBER;
1552 l_transfer_lpn_id NUMBER;
1553 l_outermost_lpn_id NUMBER;
1554 -- Stuff for pick confirm
1555
1556 l_orig_sub VARCHAR2(10);
1557 l_orig_loc NUMBER;
1558 l_tran_type_id NUMBER;
1559 l_orig_txn_header_id NUMBER;
1560 l_item_id NUMBER;
1561 l_qty NUMBER;
1562 l_uom VARCHAR2(10);
1563 l_from_sub VARCHAR2(30);
1564 l_from_loc NUMBER;
1565 l_serial_code NUMBER;
1566 l_lot_code NUMBER;
1567 l_is_lot_control VARCHAR2(5) := 'false';
1568 l_is_serial_control VARCHAR2(5) := 'false';
1569 l_is_revision_control VARCHAR2(5) := 'false';
1570 l_sub_reservable_type NUMBER;
1571 l_rev VARCHAR2(3);
1572 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
1573 l_lot_number VARCHAR2(80);
1574
1575 CURSOR mtlt_csr IS
1576 SELECT mtlt.lot_number
1577 , mtlt.transaction_quantity
1578 FROM mtl_transaction_lots_temp mtlt
1579 WHERE mtlt.transaction_temp_id = p_temp_id;
1580
1581 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1582 BEGIN
1583 l_return_status := fnd_api.g_ret_sts_success;
1584 l_lpn := p_lpn;
1585 l_loc := p_loc;
1586 l_exist_lpn := NULL;
1587 l_lpn_id := NULL;
1588 l_from_lpn_id := p_from_lpn_id;
1589 p_ok_to_process := 'true';
1590
1591 IF (l_loc = 0) THEN
1592 l_loc := NULL;
1593 END IF;
1594
1595 SELECT NVL(content_lpn_id, 0)
1596 , NVL(lpn_id, 0)
1597 , transfer_lpn_id
1598 , transfer_subinventory
1599 , transfer_to_location
1600 , transaction_type_id
1601 , transaction_header_id
1602 INTO l_content_lpn_id
1603 , l_mmtt_from_lpn_id
1604 , l_transfer_lpn_id
1605 , l_orig_sub
1606 , l_orig_loc
1607 , l_tran_type_id
1608 , l_orig_txn_header_id
1609 FROM mtl_material_transactions_temp
1610 WHERE transaction_temp_id = p_temp_id;
1611
1612 IF (l_loc <> l_orig_loc)
1613 OR(p_sub <> l_orig_sub) THEN
1614 IF (l_debug = 1) THEN
1615 mydebug('complete_pick: User entered a different sub');
1616 END IF;
1617
1618 UPDATE mtl_material_transactions_temp
1619 SET transfer_subinventory = p_sub
1620 , transfer_to_location = l_loc
1621 WHERE transaction_temp_id = p_temp_id;
1622 END IF;
1623
1624 IF (p_sub <> l_orig_sub) THEN
1625 SELECT msi.reservable_type
1626 INTO l_sub_reservable_type
1627 FROM mtl_secondary_inventories msi
1628 WHERE msi.secondary_inventory_name = p_sub
1629 AND msi.organization_id = p_org_id;
1630
1631 IF l_sub_reservable_type = 2 THEN
1632 IF (l_debug = 1) THEN
1633 mydebug('complete_pick: Transfer Sub is non-reservable');
1634 END IF;
1635
1636 SELECT mmtt.inventory_item_id
1637 , mmtt.transaction_quantity
1638 , mmtt.transaction_uom
1639 , mmtt.subinventory_code
1640 , mmtt.locator_id
1641 , mmtt.revision
1642 INTO l_item_id
1643 , l_qty
1644 , l_uom
1645 , l_from_sub
1646 , l_from_loc
1647 , l_rev
1648 FROM mtl_material_transactions_temp mmtt
1649 WHERE mmtt.transaction_temp_id = p_temp_id;
1650
1651 SELECT msi.serial_number_control_code
1652 , msi.lot_control_code
1653 INTO l_serial_code
1654 , l_lot_code
1655 FROM mtl_system_items msi
1656 WHERE msi.inventory_item_id = l_item_id
1657 AND msi.organization_id = p_org_id;
1658
1659 IF (l_serial_code > 1
1660 AND l_serial_code <> 6) THEN
1661 l_is_serial_control := 'true';
1662 END IF;
1663
1664 IF l_rev IS NOT NULL THEN
1665 l_is_revision_control := 'true';
1666 END IF;
1667
1668 IF l_lot_code > 1 THEN
1669 l_is_lot_control := 'true';
1670
1671 IF (l_debug = 1) THEN
1672 mydebug('complete_pick: Lot controlled');
1673 END IF;
1674
1675 OPEN mtlt_csr;
1676
1677 LOOP
1678 FETCH mtlt_csr INTO l_lot_number, l_qty;
1679 EXIT WHEN mtlt_csr%NOTFOUND;
1680 inv_txn_validations.check_loose_and_packed_qty(
1681 p_api_version_number => 1.0
1682 , p_init_msg_lst => fnd_api.g_false
1683 , x_return_status => l_return_status
1684 , x_msg_count => x_msg_count
1685 , x_msg_data => x_msg_data
1686 , p_organization_id => p_org_id
1687 , p_inventory_item_id => l_item_id
1688 , p_is_revision_control => l_is_revision_control
1689 , p_is_lot_control => l_is_lot_control
1690 , p_is_serial_control => l_is_serial_control
1691 , p_revision => l_rev
1692 , p_lot_number => l_lot_number
1693 , p_transaction_quantity => l_qty
1694 , p_transaction_uom => l_uom
1695 , p_subinventory_code => l_from_sub
1696 , p_locator_id => l_from_loc
1697 , p_transaction_temp_id => p_temp_id
1698 , p_ok_to_process => p_ok_to_process
1699 , p_transfer_subinventory => p_sub
1700 );
1701 END LOOP;
1702
1703 CLOSE mtlt_csr;
1704 ELSE
1705 IF (l_debug = 1) THEN
1706 mydebug('complete_pick: Not lot controlled');
1707 END IF;
1708
1709 inv_txn_validations.check_loose_and_packed_qty(
1710 p_api_version_number => 1.0
1711 , p_init_msg_lst => fnd_api.g_false
1712 , x_return_status => l_return_status
1713 , x_msg_count => x_msg_count
1714 , x_msg_data => x_msg_data
1715 , p_organization_id => p_org_id
1716 , p_inventory_item_id => l_item_id
1717 , p_is_revision_control => l_is_revision_control
1718 , p_is_lot_control => l_is_lot_control
1719 , p_is_serial_control => l_is_serial_control
1720 , p_revision => l_rev
1721 , p_lot_number => NULL
1722 , p_transaction_quantity => l_qty
1723 , p_transaction_uom => l_uom
1724 , p_subinventory_code => l_from_sub
1725 , p_locator_id => l_from_loc
1726 , p_transaction_temp_id => p_temp_id
1727 , p_ok_to_process => p_ok_to_process
1728 , p_transfer_subinventory => p_sub
1729 );
1730
1731 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1732 IF (l_debug = 1) THEN
1733 mydebug('complete_pick: unexpected error in check_loose_and_packed_qty');
1734 END IF;
1735
1736 p_ok_to_process := 'false';
1737 RAISE fnd_api.g_exc_unexpected_error;
1738 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1739 IF (l_debug = 1) THEN
1740 mydebug('complete_pick: error in check_and_packed_loose_qty');
1741 END IF;
1742
1743 p_ok_to_process := 'false';
1744 RAISE fnd_api.g_exc_error;
1745 END IF;
1746
1747 IF p_ok_to_process = 'false' THEN
1748 IF (l_debug = 1) THEN
1749 mydebug('complete_pick: After quantity validation. Quantity not enough. Cannot process');
1750 END IF;
1751
1752 x_return_status := fnd_api.g_ret_sts_success;
1753 RETURN;
1754 END IF;
1755 END IF;
1756 END IF;
1757 END IF;
1758
1759 -- Check to see if LPN exists
1760
1761 IF (l_lpn IS NULL
1762 OR l_lpn = '') THEN
1763 l_lpn_id := NULL;
1764
1765 IF (l_debug = 1) THEN
1766 mydebug('complete_pick: No LPN was passed');
1767 END IF;
1768 ELSE
1769 IF (l_debug = 1) THEN
1770 mydebug('complete_pick: LPN was passed');
1771 END IF;
1772
1773 l_exist_lpn := 0;
1774
1775 BEGIN
1776 SELECT 1
1777 INTO l_exist_lpn
1778 FROM DUAL
1779 WHERE EXISTS(SELECT 1
1780 FROM wms_license_plate_numbers
1781 WHERE license_plate_number = l_lpn
1782 AND organization_id = p_org_id);
1783 EXCEPTION
1784 WHEN NO_DATA_FOUND THEN
1785 l_exist_lpn := 0;
1786 END;
1787
1788 IF (l_exist_lpn = 0) THEN
1789 -- LPN does not exist, create it
1790 -- Call Suresh's Create LPN API
1791 IF (l_debug = 1) THEN
1792 mydebug('complete_pick: Creating LPN');
1793 END IF;
1794
1795 wms_container_pub.create_lpn(
1796 p_api_version => 1.0
1797 , p_init_msg_list => fnd_api.g_false
1798 , p_commit => fnd_api.g_false
1799 , x_return_status => l_return_status
1800 , x_msg_count => l_msg_cnt
1801 , x_msg_data => l_msg_data
1802 , p_lpn => l_lpn
1803 , p_organization_id => p_org_id
1804 , p_container_item_id => p_container_item_id
1805 , p_lot_number => NULL
1806 , p_revision => NULL
1807 , p_serial_number => NULL
1808 , p_subinventory => p_sub
1809 , p_locator_id => l_loc
1810 , p_source => WMS_CONTAINER_PUB.LPN_CONTEXT_PREGENERATED --Bug#4864812.
1811 , p_cost_group_id => NULL
1812 , x_lpn_id => l_lpn_id
1813 );
1814 fnd_msg_pub.count_and_get(p_count => l_msg_cnt, p_data => l_msg_data);
1815
1816 IF (l_msg_cnt = 0) THEN
1817 IF (l_debug = 1) THEN
1818 mydebug('complete_pick: Successful');
1819 END IF;
1820 ELSIF(l_msg_cnt = 1) THEN
1821 IF (l_debug = 1) THEN
1822 mydebug('complete_pick: Not Successful');
1823 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
1824 END IF;
1825 ELSE
1826 IF (l_debug = 1) THEN
1827 mydebug('complete_pick: Not Successful2');
1828 END IF;
1829
1830 FOR i IN 1 .. l_msg_cnt LOOP
1831 l_msg_data := fnd_msg_pub.get(i, 'F');
1832
1833 IF (l_debug = 1) THEN
1834 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
1835 END IF;
1836 END LOOP;
1837 END IF;
1838
1839 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1840 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
1841 fnd_msg_pub.ADD;
1842 RAISE fnd_api.g_exc_unexpected_error;
1843 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1844 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
1845 fnd_msg_pub.ADD;
1846 RAISE fnd_api.g_exc_error;
1847 END IF;
1848 ELSE
1849 -- LPN exists. Get LPN ID
1850 SELECT lpn_id
1851 INTO l_lpn_id
1852 FROM wms_license_plate_numbers
1853 WHERE license_plate_number = l_lpn
1854 AND organization_id = p_org_id;
1855 END IF;
1856 END IF;
1857
1858 IF (l_debug = 1) THEN
1859 mydebug('complete_pick: Updating MMTT');
1860 END IF;
1861
1862 IF (WMS_CONTROL.get_current_release_level >=
1863 INV_RELEASE.get_j_release_level)
1864 THEN
1865 --
1866 -- Bug 3362939:
1867 -- Do not update transaction_batch_seq
1868 -- In patchset J this is done in
1869 -- wms_pick_drop_pvt.pick_drop
1870 --
1871 IF (l_content_lpn_id IS NULL
1872 OR l_content_lpn_id <> l_transfer_lpn_id) THEN
1873 UPDATE mtl_material_transactions_temp mmtt
1874 SET transaction_status = 3
1875 , transaction_header_id = p_txn_hdr_id
1876 , last_update_date = SYSDATE
1877 , last_updated_by = p_user_id
1878 , transaction_batch_id = p_txn_hdr_id
1879 WHERE mmtt.transaction_temp_id = p_temp_id;
1880 ELSIF(l_content_lpn_id = l_transfer_lpn_id) THEN
1881 -- We are transferring the entire lpn
1882 UPDATE mtl_material_transactions_temp mmtt
1883 SET transaction_status = 3
1884 , transaction_header_id = p_txn_hdr_id
1885 , transfer_lpn_id = NULL
1886 , last_update_date = SYSDATE
1887 , last_updated_by = p_user_id
1888 , transaction_batch_id = p_txn_hdr_id
1889 WHERE mmtt.transaction_temp_id = p_temp_id;
1890 END IF;
1891 ELSE
1892 IF (l_content_lpn_id IS NULL
1893 OR l_content_lpn_id <> l_transfer_lpn_id) THEN
1894 UPDATE mtl_material_transactions_temp mmtt
1895 SET transaction_status = 3
1896 , transaction_header_id = p_txn_hdr_id
1897 , last_update_date = SYSDATE
1898 , last_updated_by = p_user_id
1899 , transaction_batch_id = p_txn_hdr_id
1900 , transaction_batch_seq = p_temp_id
1901 WHERE mmtt.transaction_temp_id = p_temp_id;
1902 ELSIF(l_content_lpn_id = l_transfer_lpn_id) THEN
1903 -- We are transferring the entire lpn
1904 UPDATE mtl_material_transactions_temp mmtt
1905 SET transaction_status = 3
1906 , transaction_header_id = p_txn_hdr_id
1907 , transfer_lpn_id = NULL
1908 , last_update_date = SYSDATE
1909 , last_updated_by = p_user_id
1910 , transaction_batch_id = p_txn_hdr_id
1911 , transaction_batch_seq = p_temp_id
1912 WHERE mmtt.transaction_temp_id = p_temp_id;
1913 END IF;
1914 END IF;
1915
1916 IF l_tran_type_id = 35 THEN
1917 IF (l_debug = 1) THEN
1918 mydebug('complete_pick: WIP issue: update txn qty and primary qty to -ve');
1919 END IF;
1920
1921 --
1922 -- For 11.5.10 or higher do not set process_flag to 'W'
1923 --
1924 IF (WMS_CONTROL.get_current_release_level >=
1925 INV_RELEASE.get_j_release_level)
1926 THEN
1927 UPDATE mtl_material_transactions_temp
1928 SET transaction_quantity = -1 * ABS(transaction_quantity)
1929 , primary_quantity = -1 * ABS(primary_quantity)
1930 WHERE transaction_temp_id = p_temp_id
1931 AND organization_id = p_org_id;
1932 ELSE
1933 UPDATE mtl_material_transactions_temp
1934 SET transaction_quantity = -1 * ABS(transaction_quantity)
1935 , primary_quantity = -1 * ABS(primary_quantity)
1936 , process_flag = 'W'
1937 WHERE transaction_temp_id = p_temp_id
1938 AND organization_id = p_org_id;
1939 END IF;
1940 END IF;
1941
1942 -- Have to update WMS_Exceptions so that any exceptions already
1943 -- recorded for this MMTT line will now be updated with the new txn
1944 -- header_id
1945 UPDATE wms_exceptions
1946 SET transaction_header_id = p_txn_hdr_id
1947 WHERE transaction_header_id = l_orig_txn_header_id;
1948
1949 x_return_status := fnd_api.g_ret_sts_success;
1950 EXCEPTION
1951 WHEN fnd_api.g_exc_error THEN
1952 x_return_status := fnd_api.g_ret_sts_error;
1953 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1954 WHEN OTHERS THEN
1955 x_return_status := fnd_api.g_ret_sts_unexp_error;
1956 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1957 END complete_pick;
1958
1959 FUNCTION get_primary_quantity(p_item_id IN NUMBER, p_organization_id IN NUMBER, p_from_quantity IN NUMBER, p_from_unit IN VARCHAR2)
1960 RETURN NUMBER IS
1961 l_primary_uom VARCHAR2(3);
1962 l_primary_quantity NUMBER;
1963 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1964 BEGIN
1965 SELECT primary_uom_code
1966 INTO l_primary_uom
1967 FROM mtl_system_items
1968 WHERE organization_id = p_organization_id
1969 AND inventory_item_id = p_item_id;
1970
1971 l_primary_quantity :=
1972 inv_convert.inv_um_convert(
1973 item_id => p_item_id
1974 , PRECISION => NULL
1975 , from_quantity => p_from_quantity
1976 , from_unit => p_from_unit
1977 , to_unit => l_primary_uom
1978 , from_name => NULL
1979 , to_name => NULL
1980 );
1981 RETURN l_primary_quantity;
1982 END get_primary_quantity;
1983
1984 PROCEDURE process_lot_serial(
1985 p_org_id IN NUMBER
1986 , p_user_id IN NUMBER
1987 , p_temp_id IN NUMBER
1988 , p_item_id IN NUMBER
1989 , p_qty IN NUMBER
1990 , p_uom IN VARCHAR2
1991 , p_lot IN VARCHAR2
1992 , p_fm_serial IN VARCHAR2
1993 , p_to_serial IN VARCHAR2
1994 , p_action IN NUMBER
1995 , x_return_status OUT NOCOPY VARCHAR2
1996 , x_msg_count OUT NOCOPY NUMBER
1997 , x_msg_data OUT NOCOPY VARCHAR2
1998 ) IS
1999 l_org_id NUMBER;
2000 l_temp_id NUMBER;
2001 l_item_id NUMBER;
2002 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
2003 l_lot VARCHAR2(80);
2004 l_fm_serial VARCHAR2(30);
2005 l_to_serial VARCHAR2(30);
2006 l_qty NUMBER;
2007 l_uom VARCHAR2(3);
2008 l_action NUMBER;
2009 l_exp_date DATE;
2010 l_pr_qty NUMBER;
2011 l_user_id NUMBER;
2012 l_ser_seq NUMBER;
2013 l_cnt NUMBER;
2014 l_lot_ser_seq NUMBER := 0;
2015 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2016
2017 l_from_ser_number NUMBER;
2018 l_to_ser_number NUMBER;
2019 l_temp_prefix VARCHAR2(30);
2020 l_range_numbers NUMBER;
2021 l_ser_num_length NUMBER;
2022 l_prefix_length NUMBER;
2023 l_cur_ser_num NUMBER;
2024 l_cur_serial_number mtl_serial_numbers.serial_number%type;
2025
2026 --Bug #2966531 - Cursor to store serial attributes from MSN
2027 CURSOR c_msn_attributes( v_serial_number VARCHAR2
2028 , v_inventory_item_id NUMBER) IS
2029 SELECT vendor_serial_number, vendor_lot_number, parent_serial_number
2030 , origination_date, end_item_unit_number, territory_code, time_since_new, cycles_since_new
2031 , time_since_overhaul, cycles_since_overhaul, time_since_repair, cycles_since_repair
2032 , time_since_visit, cycles_since_visit, time_since_mark, cycles_since_mark
2033 , number_of_repairs, serial_attribute_category, c_attribute1, c_attribute2
2034 , c_attribute3, c_attribute4, c_attribute5, c_attribute6, c_attribute7
2035 , c_attribute8, c_attribute9, c_attribute10, c_attribute11, c_attribute12
2036 , c_attribute13, c_attribute14, c_attribute15, c_attribute16, c_attribute17, c_attribute18
2037 , c_attribute19, c_attribute20, d_attribute1, d_attribute2, d_attribute3
2038 , d_attribute4, d_attribute5, d_attribute6, d_attribute7, d_attribute8
2039 , d_attribute9, d_attribute10, n_attribute1, n_attribute2, n_attribute3
2040 , n_attribute4, n_attribute5, n_attribute6, n_attribute7, n_attribute8
2041 , n_attribute9, n_attribute10
2042 FROM mtl_serial_numbers
2043 WHERE serial_number = v_serial_number
2044 AND inventory_item_id = v_inventory_item_id;
2045
2046 TYPE msn_attribute_rec_tp IS RECORD (
2047 vendor_serial_number mtl_serial_numbers.vendor_serial_number%type,
2048 vendor_lot_number mtl_serial_numbers.vendor_lot_number%type,
2049 parent_serial_number mtl_serial_numbers.parent_serial_number%type,
2050 origination_date mtl_serial_numbers.origination_date%type,
2051 end_item_unit_number mtl_serial_numbers.end_item_unit_number%type,
2052 territory_code mtl_serial_numbers.territory_code%type,
2053 time_since_new mtl_serial_numbers.time_since_new%type,
2054 cycles_since_new mtl_serial_numbers.cycles_since_new%type,
2055 time_since_overhaul mtl_serial_numbers.time_since_overhaul%type,
2056 cycles_since_overhaul mtl_serial_numbers.cycles_since_overhaul%type,
2057 time_since_repair mtl_serial_numbers.time_since_repair%type,
2058 cycles_since_repair mtl_serial_numbers.cycles_since_repair%type,
2059 time_since_visit mtl_serial_numbers.time_since_visit%type,
2060 cycles_since_visit mtl_serial_numbers.cycles_since_visit%type,
2061 time_since_mark mtl_serial_numbers.time_since_mark%type,
2062 cycles_since_mark mtl_serial_numbers.cycles_since_mark%type,
2063 number_of_repairs mtl_serial_numbers.number_of_repairs%type,
2064 serial_attribute_category mtl_serial_numbers.serial_attribute_category%type,
2065 c_attribute1 mtl_serial_numbers.c_attribute1%type,
2066 c_attribute2 mtl_serial_numbers.c_attribute2%type,
2067 c_attribute3 mtl_serial_numbers.c_attribute3%type,
2068 c_attribute4 mtl_serial_numbers.c_attribute4%type,
2069 c_attribute5 mtl_serial_numbers.c_attribute5%type,
2070 c_attribute6 mtl_serial_numbers.c_attribute6%type,
2071 c_attribute7 mtl_serial_numbers.c_attribute7%type,
2072 c_attribute8 mtl_serial_numbers.c_attribute8%type,
2073 c_attribute9 mtl_serial_numbers.c_attribute9%type,
2074 c_attribute10 mtl_serial_numbers.c_attribute10%type,
2075 c_attribute11 mtl_serial_numbers.c_attribute11%type,
2076 c_attribute12 mtl_serial_numbers.c_attribute12%type,
2077 c_attribute13 mtl_serial_numbers.c_attribute13%type,
2078 c_attribute14 mtl_serial_numbers.c_attribute14%type,
2079 c_attribute15 mtl_serial_numbers.c_attribute15%type,
2080 c_attribute16 mtl_serial_numbers.c_attribute16%type,
2081 c_attribute17 mtl_serial_numbers.c_attribute17%type,
2082 c_attribute18 mtl_serial_numbers.c_attribute18%type,
2083 c_attribute19 mtl_serial_numbers.c_attribute19%type,
2084 c_attribute20 mtl_serial_numbers.c_attribute20%type,
2085 d_attribute1 mtl_serial_numbers.d_attribute1%type,
2086 d_attribute2 mtl_serial_numbers.d_attribute2%type,
2087 d_attribute3 mtl_serial_numbers.d_attribute3%type,
2088 d_attribute4 mtl_serial_numbers.d_attribute4%type,
2089 d_attribute5 mtl_serial_numbers.d_attribute5%type,
2090 d_attribute6 mtl_serial_numbers.d_attribute6%type,
2091 d_attribute7 mtl_serial_numbers.d_attribute7%type,
2092 d_attribute8 mtl_serial_numbers.d_attribute8%type,
2093 d_attribute9 mtl_serial_numbers.d_attribute9%type,
2094 d_attribute10 mtl_serial_numbers.d_attribute10%type,
2095 n_attribute1 mtl_serial_numbers.n_attribute1%type,
2096 n_attribute2 mtl_serial_numbers.n_attribute2%type,
2097 n_attribute3 mtl_serial_numbers.n_attribute3%type,
2098 n_attribute4 mtl_serial_numbers.n_attribute4%type,
2099 n_attribute5 mtl_serial_numbers.n_attribute5%type,
2100 n_attribute6 mtl_serial_numbers.n_attribute6%type,
2101 n_attribute7 mtl_serial_numbers.n_attribute7%type,
2102 n_attribute8 mtl_serial_numbers.n_attribute8%type,
2103 n_attribute9 mtl_serial_numbers.n_attribute9%type,
2104 n_attribute10 mtl_serial_numbers.n_attribute10%type );
2105
2106 l_msn_attribute_rec msn_attribute_rec_tp;
2107 BEGIN
2108 l_org_id := p_org_id;
2109 l_temp_id := p_temp_id;
2110 l_item_id := p_item_id;
2111 l_lot := p_lot;
2112 l_fm_serial := p_fm_serial;
2113 l_to_serial := p_to_serial;
2114 l_qty := p_qty;
2115 l_uom := p_uom;
2116 l_action := p_action;
2117 l_user_id := p_user_id;
2118 l_cnt := 0;
2119
2120 IF (l_debug = 1) THEN
2121 mydebug('process_lot_serial: In Process Lot Serial');
2122 END IF;
2123
2124 -- Calculate Primary Quantity
2125
2126 l_pr_qty :=
2127 wms_task_dispatch_gen.get_primary_quantity(p_item_id => l_item_id, p_organization_id => l_org_id, p_from_quantity => l_qty
2128 , p_from_unit => l_uom);
2129
2130 IF (l_debug = 1) THEN
2131 mydebug('process_lot_serial: after prim qty');
2132 mydebug('process_lot_serial: prim qty' || l_pr_qty);
2133 mydebug('process_lot_serial: qty' || l_qty);
2134 mydebug('process_lot_serial: Lot' || l_lot);
2135 mydebug('process_lot_serial: TempId:' || l_temp_id);
2136 END IF;
2137
2138 IF (l_action <> 3) THEN
2139 -- Lot controlled. Get expiration date
2140 SELECT expiration_date
2141 INTO l_exp_date
2142 FROM mtl_lot_numbers
2143 WHERE organization_id = l_org_id
2144 AND inventory_item_id = l_item_id
2145 AND lot_number = l_lot;
2146 END IF;
2147
2148 IF (l_action = 1) THEN
2149 -- Lot Controlled only
2150 -- Insert into mtl_transaction_lot
2151 IF (l_debug = 1) THEN
2152 mydebug('process_lot_serial: Inserting Lots');
2153 END IF;
2154
2155 UPDATE mtl_transaction_lots_temp
2156 SET transaction_quantity = l_qty
2157 , primary_quantity = l_pr_qty
2158 , last_update_date = SYSDATE
2159 , last_updated_by = l_user_id
2160 WHERE transaction_temp_id = l_temp_id
2161 AND lot_number = l_lot;
2162
2163 IF (l_debug = 1) THEN
2164 mydebug('process_lot_serial: After lot update');
2165 END IF;
2166 ELSIF(l_action = 2) THEN
2167 -- Lot and serial controlled
2168 -- Get sequence for serial tran id
2169
2170 SELECT NVL(serial_transaction_temp_id, 0)
2171 INTO l_lot_ser_seq
2172 FROM mtl_transaction_lots_temp
2173 WHERE transaction_temp_id = l_temp_id
2174 AND lot_number = l_lot;
2175
2176 IF l_lot_ser_seq = 0 THEN
2177 SELECT mtl_material_transactions_s.NEXTVAL
2178 INTO l_ser_seq
2179 FROM DUAL;
2180 ELSE
2181 l_ser_seq := l_lot_ser_seq;
2182 END IF;
2183
2184 --mydebug('process_lot_serial: Inserting Lots and.....');
2185 UPDATE mtl_transaction_lots_temp
2186 SET transaction_quantity = l_qty
2187 , primary_quantity = l_pr_qty
2188 , serial_transaction_temp_id = l_ser_seq
2189 , last_update_date = SYSDATE
2190 , last_updated_by = l_user_id
2191 WHERE transaction_temp_id = l_temp_id
2192 AND lot_number = l_lot;
2193
2194 /* Bug #2966531
2195 * For each serial number in the range between from serial and to serial
2196 * Open the cursor and fetch the attributes for the current serial number
2197 * Create one MSNT record for each serial number and set the attributes from the cursor
2198 */
2199
2200 --get the numeric part of the from serial #
2201 inv_validate.number_from_sequence(l_fm_serial, l_temp_prefix, l_from_ser_number);
2202
2203 --get the numeric part of the to serial #
2204 inv_validate.number_from_sequence(l_to_serial, l_temp_prefix, l_to_ser_number);
2205
2206 l_range_numbers := l_to_ser_number - l_from_ser_number + 1;
2207 l_ser_num_length := length(l_fm_serial);
2208 l_prefix_length := length(l_temp_prefix);
2209
2210 --For each serial number in the range, fetch the attributes from MSN
2211 --and insert a record into MSNT
2212 FOR i IN 1 .. l_range_numbers LOOP
2213 l_cur_ser_num := l_from_ser_number + i - 1;
2214
2215 --Get the serial number by concatenating the character and the string part
2216 l_cur_serial_number := l_temp_prefix ||
2217 LPAD(l_cur_ser_num, l_ser_num_length - NVL(l_prefix_length,0), '0');
2218
2219 mydebug('cir ser num: ' || l_cur_serial_number);
2220
2221 OPEN c_msn_attributes(l_cur_serial_number, l_item_id);
2222 FETCH c_msn_attributes INTO l_msn_attribute_rec;
2223 CLOSE c_msn_attributes;
2224
2225 INSERT INTO mtl_serial_numbers_temp
2226 ( TRANSACTION_TEMP_ID
2227 , LAST_UPDATE_DATE
2228 , LAST_UPDATED_BY
2229 , CREATION_DATE
2230 , CREATED_BY
2231 , fm_serial_number
2232 , to_serial_number
2233 , vendor_serial_number
2234 , vendor_lot_number
2235 , parent_serial_number
2236 , origination_date
2237 , end_item_unit_number
2238 , territory_code
2239 , time_since_new
2240 , cycles_since_new
2241 , time_since_overhaul
2242 , cycles_since_overhaul
2243 , time_since_repair
2244 , cycles_since_repair
2245 , time_since_visit
2246 , cycles_since_visit
2247 , time_since_mark
2248 , cycles_since_mark
2249 , number_of_repairs
2250 , serial_attribute_category
2251 , c_attribute1
2252 , c_attribute2
2253 , c_attribute3
2254 , c_attribute4
2255 , c_attribute5
2256 , c_attribute6
2257 , c_attribute7
2258 , c_attribute8
2259 , c_attribute9
2260 , c_attribute10
2261 , c_attribute11
2262 , c_attribute12
2263 , c_attribute13
2264 , c_attribute14
2265 , c_attribute15
2266 , c_attribute16
2267 , c_attribute17
2268 , c_attribute18
2269 , c_attribute19
2270 , c_attribute20
2271 , d_attribute1
2272 , d_attribute2
2273 , d_attribute3
2274 , d_attribute4
2275 , d_attribute5
2276 , d_attribute6
2277 , d_attribute7
2278 , d_attribute8
2279 , d_attribute9
2280 , d_attribute10
2281 , n_attribute1
2282 , n_attribute2
2283 , n_attribute3
2284 , n_attribute4
2285 , n_attribute5
2286 , n_attribute6
2287 , n_attribute7
2288 , n_attribute8
2289 , n_attribute9
2290 , n_attribute10
2291 )
2292 VALUES (
2293 l_ser_seq
2294 , Sysdate
2295 , l_user_id
2296 , Sysdate
2297 , l_user_id
2298 , l_fm_serial
2299 , l_to_serial
2300 , l_msn_attribute_rec.vendor_serial_number
2301 , l_msn_attribute_rec.vendor_lot_number
2302 , l_msn_attribute_rec.parent_serial_number
2303 , l_msn_attribute_rec.origination_date
2304 , l_msn_attribute_rec.end_item_unit_number
2305 , l_msn_attribute_rec.territory_code
2306 , l_msn_attribute_rec.time_since_new
2307 , l_msn_attribute_rec.cycles_since_new
2308 , l_msn_attribute_rec.time_since_overhaul
2309 , l_msn_attribute_rec.cycles_since_overhaul
2310 , l_msn_attribute_rec.time_since_repair
2311 , l_msn_attribute_rec.cycles_since_repair
2312 , l_msn_attribute_rec.time_since_visit
2313 , l_msn_attribute_rec.cycles_since_visit
2314 , l_msn_attribute_rec.time_since_mark
2315 , l_msn_attribute_rec.cycles_since_mark
2316 , l_msn_attribute_rec.number_of_repairs
2317 , l_msn_attribute_rec.serial_attribute_category
2318 , l_msn_attribute_rec.c_attribute1
2319 , l_msn_attribute_rec.c_attribute2
2320 , l_msn_attribute_rec.c_attribute3
2321 , l_msn_attribute_rec.c_attribute4
2322 , l_msn_attribute_rec.c_attribute5
2323 , l_msn_attribute_rec.c_attribute6
2324 , l_msn_attribute_rec.c_attribute7
2325 , l_msn_attribute_rec.c_attribute8
2326 , l_msn_attribute_rec.c_attribute9
2327 , l_msn_attribute_rec.c_attribute10
2328 , l_msn_attribute_rec.c_attribute11
2329 , l_msn_attribute_rec.c_attribute12
2330 , l_msn_attribute_rec.c_attribute13
2331 , l_msn_attribute_rec.c_attribute14
2332 , l_msn_attribute_rec.c_attribute15
2333 , l_msn_attribute_rec.c_attribute16
2334 , l_msn_attribute_rec.c_attribute17
2335 , l_msn_attribute_rec.c_attribute18
2336 , l_msn_attribute_rec.c_attribute19
2337 , l_msn_attribute_rec.c_attribute20
2338 , l_msn_attribute_rec.d_attribute1
2339 , l_msn_attribute_rec.d_attribute2
2340 , l_msn_attribute_rec.d_attribute3
2341 , l_msn_attribute_rec.d_attribute4
2342 , l_msn_attribute_rec.d_attribute5
2343 , l_msn_attribute_rec.d_attribute6
2344 , l_msn_attribute_rec.d_attribute7
2345 , l_msn_attribute_rec.d_attribute8
2346 , l_msn_attribute_rec.d_attribute9
2347 , l_msn_attribute_rec.d_attribute10
2348 , l_msn_attribute_rec.n_attribute1
2349 , l_msn_attribute_rec.n_attribute2
2350 , l_msn_attribute_rec.n_attribute3
2351 , l_msn_attribute_rec.n_attribute4
2352 , l_msn_attribute_rec.n_attribute5
2353 , l_msn_attribute_rec.n_attribute6
2354 , l_msn_attribute_rec.n_attribute7
2355 , l_msn_attribute_rec.n_attribute8
2356 , l_msn_attribute_rec.n_attribute9
2357 , l_msn_attribute_rec.n_attribute10
2358 );
2359 END LOOP; --END for each serial number
2360 -- Insert into serial
2361 --mydebug('process_lot_serial: Inserting Serials');
2362 /*INSERT INTO mtl_serial_numbers_temp
2363 (
2364 transaction_temp_id
2365 , last_update_date
2366 , last_updated_by
2367 , creation_date
2368 , created_by
2369 , fm_serial_number
2370 , to_serial_number
2371 )
2372 VALUES (
2373 l_ser_seq
2374 , SYSDATE
2375 , l_user_id
2376 , SYSDATE
2377 , l_user_id
2378 , l_fm_serial
2379 , l_to_serial
2380 );*/
2381 ELSIF(l_action = 3) THEN
2382 -- Serial controlled only
2383
2384 IF (l_debug = 1) THEN
2385 mydebug('process_lot_serial: Inserting Serials Only');
2386 END IF;
2387
2388 /* Bug #2966531
2389 * For each serial number in the range between from serial and to serial
2390 * Open the cursor and fetch the attributes for the current serial number
2391 * Create one MSNT record for each serial number and set the attributes from the cursor
2392 */
2393
2394 --get the numeric part of the from serial #
2395 inv_validate.number_from_sequence(l_fm_serial, l_temp_prefix, l_from_ser_number);
2396
2397 --get the numeric part of the to serial #
2398 inv_validate.number_from_sequence(l_to_serial, l_temp_prefix, l_to_ser_number);
2399
2400 l_range_numbers := l_to_ser_number - l_from_ser_number + 1;
2401 l_ser_num_length := length(l_fm_serial);
2402 l_prefix_length := length(l_temp_prefix);
2403
2404 --For each serial number in the range, fetch the attributes from MSN
2405 --and insert a record into MSNT
2406 FOR i IN 1 .. l_range_numbers LOOP
2407 l_cur_ser_num := l_from_ser_number + i - 1;
2408 --Get the serial number by concatenating the character and the string part
2409 l_cur_serial_number := l_temp_prefix ||
2410 LPAD(l_cur_ser_num, l_ser_num_length - NVL(l_prefix_length,0), '0');
2411
2412 OPEN c_msn_attributes(l_cur_serial_number, l_item_id);
2413 FETCH c_msn_attributes INTO l_msn_attribute_rec;
2414 CLOSE c_msn_attributes;
2415
2416 INSERT INTO mtl_serial_numbers_temp
2417 ( TRANSACTION_TEMP_ID
2418 , LAST_UPDATE_DATE
2419 , LAST_UPDATED_BY
2420 , CREATION_DATE
2421 , CREATED_BY
2422 , fm_serial_number
2423 , to_serial_number
2424 , vendor_serial_number
2425 , vendor_lot_number
2426 , parent_serial_number
2427 , origination_date
2428 , end_item_unit_number
2429 , territory_code
2430 , time_since_new
2431 , cycles_since_new
2432 , time_since_overhaul
2433 , cycles_since_overhaul
2434 , time_since_repair
2435 , cycles_since_repair
2436 , time_since_visit
2437 , cycles_since_visit
2438 , time_since_mark
2439 , cycles_since_mark
2440 , number_of_repairs
2441 , serial_attribute_category
2442 , c_attribute1
2443 , c_attribute2
2444 , c_attribute3
2445 , c_attribute4
2446 , c_attribute5
2447 , c_attribute6
2448 , c_attribute7
2449 , c_attribute8
2450 , c_attribute9
2451 , c_attribute10
2452 , c_attribute11
2453 , c_attribute12
2454 , c_attribute13
2455 , c_attribute14
2456 , c_attribute15
2457 , c_attribute16
2458 , c_attribute17
2459 , c_attribute18
2460 , c_attribute19
2461 , c_attribute20
2462 , d_attribute1
2463 , d_attribute2
2464 , d_attribute3
2465 , d_attribute4
2466 , d_attribute5
2467 , d_attribute6
2468 , d_attribute7
2469 , d_attribute8
2470 , d_attribute9
2471 , d_attribute10
2472 , n_attribute1
2473 , n_attribute2
2474 , n_attribute3
2475 , n_attribute4
2476 , n_attribute5
2477 , n_attribute6
2478 , n_attribute7
2479 , n_attribute8
2480 , n_attribute9
2481 , n_attribute10
2482 )
2483 VALUES (
2484 l_temp_id
2485 , Sysdate
2486 , l_user_id
2487 , Sysdate
2488 , l_user_id
2489 , l_fm_serial
2490 , l_to_serial
2491 , l_msn_attribute_rec.vendor_serial_number
2492 , l_msn_attribute_rec.vendor_lot_number
2493 , l_msn_attribute_rec.parent_serial_number
2494 , l_msn_attribute_rec.origination_date
2495 , l_msn_attribute_rec.end_item_unit_number
2496 , l_msn_attribute_rec.territory_code
2497 , l_msn_attribute_rec.time_since_new
2498 , l_msn_attribute_rec.cycles_since_new
2499 , l_msn_attribute_rec.time_since_overhaul
2500 , l_msn_attribute_rec.cycles_since_overhaul
2501 , l_msn_attribute_rec.time_since_repair
2502 , l_msn_attribute_rec.cycles_since_repair
2503 , l_msn_attribute_rec.time_since_visit
2504 , l_msn_attribute_rec.cycles_since_visit
2505 , l_msn_attribute_rec.time_since_mark
2506 , l_msn_attribute_rec.cycles_since_mark
2507 , l_msn_attribute_rec.number_of_repairs
2508 , l_msn_attribute_rec.serial_attribute_category
2509 , l_msn_attribute_rec.c_attribute1
2510 , l_msn_attribute_rec.c_attribute2
2511 , l_msn_attribute_rec.c_attribute3
2512 , l_msn_attribute_rec.c_attribute4
2513 , l_msn_attribute_rec.c_attribute5
2514 , l_msn_attribute_rec.c_attribute6
2515 , l_msn_attribute_rec.c_attribute7
2516 , l_msn_attribute_rec.c_attribute8
2517 , l_msn_attribute_rec.c_attribute9
2518 , l_msn_attribute_rec.c_attribute10
2519 , l_msn_attribute_rec.c_attribute11
2520 , l_msn_attribute_rec.c_attribute12
2521 , l_msn_attribute_rec.c_attribute13
2522 , l_msn_attribute_rec.c_attribute14
2523 , l_msn_attribute_rec.c_attribute15
2524 , l_msn_attribute_rec.c_attribute16
2525 , l_msn_attribute_rec.c_attribute17
2526 , l_msn_attribute_rec.c_attribute18
2527 , l_msn_attribute_rec.c_attribute19
2528 , l_msn_attribute_rec.c_attribute20
2529 , l_msn_attribute_rec.d_attribute1
2530 , l_msn_attribute_rec.d_attribute2
2531 , l_msn_attribute_rec.d_attribute3
2532 , l_msn_attribute_rec.d_attribute4
2533 , l_msn_attribute_rec.d_attribute5
2534 , l_msn_attribute_rec.d_attribute6
2535 , l_msn_attribute_rec.d_attribute7
2536 , l_msn_attribute_rec.d_attribute8
2537 , l_msn_attribute_rec.d_attribute9
2538 , l_msn_attribute_rec.d_attribute10
2539 , l_msn_attribute_rec.n_attribute1
2540 , l_msn_attribute_rec.n_attribute2
2541 , l_msn_attribute_rec.n_attribute3
2542 , l_msn_attribute_rec.n_attribute4
2543 , l_msn_attribute_rec.n_attribute5
2544 , l_msn_attribute_rec.n_attribute6
2545 , l_msn_attribute_rec.n_attribute7
2546 , l_msn_attribute_rec.n_attribute8
2547 , l_msn_attribute_rec.n_attribute9
2548 , l_msn_attribute_rec.n_attribute10
2549 );
2550 END LOOP; --END for each each serial
2551
2552 /* INSERT INTO mtl_serial_numbers_temp
2553 (
2554 transaction_temp_id
2555 , last_update_date
2556 , last_updated_by
2557 , creation_date
2558 , created_by
2559 , fm_serial_number
2560 , to_serial_number
2561 )
2562 VALUES (
2563 l_temp_id
2564 , SYSDATE
2565 , l_user_id
2566 , SYSDATE
2567 , l_user_id
2568 , l_fm_serial
2569 , l_to_serial
2570 );*/
2571 END IF;
2572
2573 x_return_status := fnd_api.g_ret_sts_success;
2574 EXCEPTION
2575 WHEN OTHERS THEN
2576 x_return_status := fnd_api.g_ret_sts_unexp_error;
2577 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2578 END process_lot_serial;
2579
2580 -- Given a lot_number, this returns the qty for the specific lpn and the lot_number
2581
2582 FUNCTION get_lpn_lot_qty(p_lot_number IN VARCHAR2)
2583 RETURN NUMBER IS
2584 l_lpn_qty NUMBER := -1;
2585 i NUMBER;
2586 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2587 BEGIN
2588 FOR i IN 1 .. t_lpn_lot_qty_table.COUNT LOOP
2589 IF (t_lpn_lot_qty_table(i).lot_number = p_lot_number) THEN
2590 l_lpn_qty := t_lpn_lot_qty_table(i).qty;
2591 RETURN l_lpn_qty;
2592 END IF;
2593 END LOOP;
2594
2595 RETURN -1;
2596 EXCEPTION
2597 WHEN OTHERS THEN
2598 RETURN -1;
2599 END get_lpn_lot_qty;
2600
2601 /*
2602 The following table gives the conditions checked by LPN Match
2603 and its return values
2604
2605 Condition x_match x_return_status
2606 =================================================================
2607 LPN already picked 7 E
2608 LPN location is invalid 6 E
2609 LPN SUB is null 10 E
2610 LPN already staged for another SO 12 E
2611 Item/Lot/Revision is not in LPN 5 E
2612 LPN has multiple items 2 S
2613 The user has to manually confirm the LPN
2614 LPN has requested item but quantity is 4 S
2615 more that the allocated quantity
2616 The user has to manually confirm the LPN
2617 Serial number is not valid for this 11 E
2618 transaction.
2619 LPN has requested item with sufficient 8 E
2620 quantity but LPN content status is
2621 invalid
2622 Serial Allocation was requested for the 9 E
2623 item but it is not allowed/there
2624 Everything allright and exact quantity 1 S
2625 match
2626 Everything allright and quantity in LPN 3 S
2627 is less than requested quantity
2628
2629 Although x_match is being set even for error conditions
2630 it is used by the calling code ONLY in case of success
2631
2632 */
2633 PROCEDURE lpn_match(
2634 p_lpn IN NUMBER
2635 , p_org_id IN NUMBER
2636 , p_item_id IN NUMBER
2637 , p_rev IN VARCHAR2
2638 , p_lot IN VARCHAR2
2639 , p_qty IN NUMBER
2640 , p_uom IN VARCHAR2
2641 , x_match OUT NOCOPY NUMBER
2642 , x_sub OUT NOCOPY VARCHAR2
2643 , x_loc OUT NOCOPY VARCHAR2
2644 , x_qty OUT NOCOPY NUMBER
2645 , x_return_status OUT NOCOPY VARCHAR2
2646 , x_msg_count OUT NOCOPY NUMBER
2647 , x_msg_data OUT NOCOPY VARCHAR2
2648 , p_temp_id IN NUMBER
2649 , p_wms_installed IN VARCHAR2
2650 , p_transaction_type_id IN NUMBER
2651 , p_cost_group_id IN NUMBER
2652 , p_is_sn_alloc IN VARCHAR2
2653 , p_action IN NUMBER
2654 , x_temp_id OUT NOCOPY NUMBER
2655 , x_loc_id OUT NOCOPY NUMBER
2656 , x_lpn_lot_vector OUT NOCOPY VARCHAR2
2657 , x_lpn_qty OUT NOCOPY NUMBER --Added bug 3946813
2658 ) IS
2659 l_msg_cnt NUMBER;
2660 l_msg_data VARCHAR2(2000);
2661 l_return_status VARCHAR2(240);
2662 l_exist_qty NUMBER;
2663 l_item_cnt NUMBER;
2664 l_rev_cnt NUMBER;
2665 l_lot_cnt NUMBER;
2666 l_item_cnt2 NUMBER;
2667 l_cg_cnt NUMBER;
2668 l_sub VARCHAR2(60);
2669 l_loc VARCHAR2(60);
2670 l_loaded NUMBER := 0;
2671 l_allocate_serial_flag NUMBER := 0;
2672 l_temp_serial_trans_temp NUMBER := 0;
2673 l_serial_number VARCHAR2(50);
2674 l_lpn_qty NUMBER;
2675 l_lpn_uom VARCHAR2(3);
2676 l_txn_uom VARCHAR2(3);
2677 l_primary_uom VARCHAR2(3);
2678 l_lot_code NUMBER;
2679 l_serial_code NUMBER;
2680 l_mmtt_qty NUMBER;
2681 l_out_temp_id NUMBER := 0;
2682 l_serial_exist_cnt NUMBER := 0;
2683 l_total_serial_cnt NUMBER := 0;
2684 l_so_cnt NUMBER := 0;
2685 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
2686 l_mtlt_lot_number VARCHAR2(80);
2687 l_mtlt_primary_qty NUMBER;
2688 l_wlc_quantity NUMBER;
2689 l_wlc_uom_code VARCHAR2(3);
2690 l_lot_match NUMBER;
2691 l_ok_to_process VARCHAR2(5);
2692 l_is_revision_control VARCHAR2(5);
2693 l_is_lot_control VARCHAR2(5);
2694 l_is_serial_control VARCHAR2(5);
2695 b_is_revision_control BOOLEAN;
2696 b_is_lot_control BOOLEAN;
2697 b_is_serial_control BOOLEAN;
2698 l_from_lpn VARCHAR2(30);
2699 l_loc_id NUMBER;
2700 l_lpn_context NUMBER;
2701 l_lpn_exists NUMBER;
2702 l_qoh NUMBER;
2703 l_rqoh NUMBER;
2704 l_qr NUMBER;
2705 l_qs NUMBER;
2706 l_att NUMBER;
2707 l_atr NUMBER;
2708 l_allocated_lpn_id NUMBER;
2709 l_table_index NUMBER := 0;
2710 l_table_total NUMBER := 0;
2711 l_table_count NUMBER;
2712 l_lpn_include_lpn NUMBER;
2713 l_xfr_sub_code VARCHAR2(30);
2714 l_sub_active NUMBER := 0;
2715 l_loc_active NUMBER := 0;
2716 l_mmtt_proj_id NUMBER ; -- 2774506/2905646
2717 l_mmtt_task_id NUMBER ;
2718 l_locator_id NUMBER;
2719 l_organization_id NUMBER;
2720 l_mil_proj_id NUMBER ;
2721 l_mil_task_id NUMBER ; -- 2774506/2905646
2722
2723 CURSOR ser_csr IS
2724 SELECT serial_number
2725 FROM mtl_serial_numbers
2726 WHERE lpn_id = p_lpn
2727 AND inventory_item_id = p_item_id
2728 AND NVL(lot_number, -999) = NVL(p_lot, -999);
2729
2730 CURSOR lot_csr IS
2731 SELECT mtlt.primary_quantity
2732 , mtlt.lot_number
2733 FROM mtl_transaction_lots_temp mtlt
2734 WHERE mtlt.transaction_temp_id = p_temp_id;
2735
2736 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2737 BEGIN
2738 IF (l_debug = 1) THEN
2739 mydebug('lpn_match: In lpn Match');
2740 END IF;
2741
2742 l_lpn_qty := p_qty;
2743 x_return_status := fnd_api.g_ret_sts_success;
2744 l_lpn_exists := 0;
2745 --clear the PL/SQL table each time come in
2746 t_lpn_lot_qty_table.DELETE;
2747
2748 BEGIN
2749 SELECT 1
2750 , lpn_context
2751 INTO l_lpn_exists
2752 , l_lpn_context
2753 FROM wms_license_plate_numbers wlpn
2754 WHERE wlpn.organization_id = p_org_id
2755 AND wlpn.lpn_id = p_lpn;
2756 EXCEPTION
2757 WHEN NO_DATA_FOUND THEN
2758 IF (l_debug = 1) THEN
2759 mydebug('lpn_match: lpn does not exist in org');
2760 END IF;
2761
2762 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
2763 fnd_msg_pub.ADD;
2764 RAISE fnd_api.g_exc_error;
2765 END;
2766
2767 IF l_lpn_exists = 0
2768 OR p_lpn = 0
2769 OR l_lpn_context <> wms_container_pub.lpn_context_inv THEN
2770 IF (l_debug = 1) THEN
2771 mydebug('lpn_match: lpn does not exist in org');
2772 END IF;
2773
2774 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
2775 fnd_msg_pub.ADD;
2776 RAISE fnd_api.g_exc_error;
2777 END IF;
2778
2779 IF (l_debug = 1) THEN
2780 mydebug('lpn_match: Checking if lpn has been picked already');
2781 END IF;
2782
2783 x_match := 0;
2784
2785 BEGIN
2786 -- Bug#2742860 The from LPN should not be loaded,
2787 -- this check should not be restricted to that particular transaction header id
2788
2789
2790 SELECT 1
2791 INTO l_loaded
2792 FROM DUAL
2793 WHERE EXISTS(SELECT 1
2794 FROM mtl_material_transactions_temp
2795 WHERE (transfer_lpn_id = p_lpn
2796 OR content_lpn_id = p_lpn));
2797 EXCEPTION
2798 WHEN NO_DATA_FOUND THEN
2799 l_loaded := 0;
2800 END;
2801
2802 IF l_loaded > 0 THEN
2803 x_match := 7;
2804 fnd_message.set_name('WMS', 'WMS_LOADED_ERROR');
2805 fnd_msg_pub.ADD;
2806 RAISE fnd_api.g_exc_error;
2807 END IF;
2808
2809 -- Check if locator is valid
2810 IF (l_debug = 1) THEN
2811 mydebug('lpn_match: Fetch sub/loc for LPN ');
2812 END IF;
2813
2814 BEGIN
2815 -- WMS PJM Integration, Selecting the resolved concatenated segments instead of concatenated segments
2816 SELECT w.subinventory_code
2817 , inv_project.get_locsegs(w.locator_id, w.organization_id)
2818 , w.license_plate_number
2819 , w.locator_id
2820 , w.lpn_context
2821 INTO l_sub
2822 , l_loc
2823 , l_from_lpn
2824 , l_loc_id
2825 , l_lpn_context
2826 FROM wms_license_plate_numbers w
2827 WHERE w.lpn_id = p_lpn
2828 AND w.locator_id IS NOT NULL;
2829
2830 IF l_sub IS NULL THEN
2831 -- The calling java code treats this condition as an error
2832
2833 x_match := 10;
2834 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
2835 fnd_msg_pub.ADD;
2836 RAISE fnd_api.g_exc_error;
2837 END IF;
2838
2839 -- bug 2398247
2840 -- verify if sub is active
2841 SELECT COUNT(*)
2842 INTO l_sub_active
2843 FROM mtl_secondary_inventories
2844 WHERE NVL(disable_date, SYSDATE + 1) > SYSDATE
2845 AND organization_id = p_org_id
2846 AND secondary_inventory_name = l_sub;
2847
2848 IF l_sub_active = 0 THEN
2849 x_match := 10;
2850 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
2851 fnd_msg_pub.ADD;
2852 RAISE fnd_api.g_exc_error;
2853 END IF;
2854
2855 -- verify if locator is active
2856 SELECT COUNT(*)
2857 INTO l_loc_active
2858 FROM mtl_item_locations_kfv
2859 WHERE NVL(disable_date, SYSDATE + 1) > SYSDATE
2860 AND organization_id = p_org_id
2861 AND subinventory_code = l_sub
2862 AND inventory_location_id = l_loc_id;
2863
2864 IF l_loc_active = 0 THEN
2865 x_match := 10;
2866 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LOC');
2867 fnd_msg_pub.ADD;
2868 RAISE fnd_api.g_exc_error;
2869 END IF;
2870 -- Begin fix for 2774506
2871
2872
2873 SELECT locator_id,organization_id INTO l_locator_id, l_organization_id
2874 from mtl_material_transactions_temp
2875 where transaction_temp_id = p_temp_id;
2876
2877 select nvl(project_id ,-999) , nvl(task_id ,-999)
2878 into l_mmtt_proj_id , l_mmtt_task_id
2879 from mtl_item_locations
2880 where inventory_location_id = l_locator_id
2881 and organization_id = l_organization_id ;
2882
2883 select nvl(project_id, -999) , nvl(task_id ,-999)
2884 into l_mil_proj_id , l_mil_task_id
2885 from mtl_item_locations
2886 where inventory_location_id = l_loc_id
2887 and organization_id = p_org_id ;
2888
2889 mydebug('mmtt project id = '||l_mmtt_proj_id);
2890 mydebug('mmtt task id = '||l_mmtt_task_id);
2891 mydebug('mil project id = '||l_mil_proj_id);
2892 mydebug('mil task id = '||l_mil_task_id);
2893
2894 if ((l_mil_proj_id <> l_mmtt_proj_id ) or ( l_mil_task_id <> l_mmtt_task_id )) then
2895 mydebug('lpn : the project/tak information does not match');
2896 FND_MESSAGE.SET_NAME('WMS','WMS_CONT_INVALID_LPN');
2897 FND_MSG_PUB.ADD;
2898 RAISE FND_API.G_EXC_ERROR;
2899 end if ;
2900
2901 -- End fix for 2774506
2902
2903
2904 x_sub := l_sub;
2905 x_loc := l_loc;
2906 x_loc_id := l_loc_id;
2907 EXCEPTION
2908 WHEN NO_DATA_FOUND THEN
2909 x_match := 6;
2910 fnd_message.set_name('WMS', 'WMS_TD_LPN_LOC_NOT_FOUND');
2911 fnd_msg_pub.ADD;
2912 RAISE fnd_api.g_exc_error;
2913 END;
2914
2915 IF (l_debug = 1) THEN
2916 mydebug('lpn_match: sub is ' || l_sub);
2917 mydebug('lpn_match: loc is ' || l_loc);
2918 END IF;
2919
2920 -- Check if LPN has already been allocated for any Sales order
2921 -- If LPN has been picked for a sales order then it cannot be picked
2922
2923 IF (l_debug = 1) THEN
2924 mydebug('lpn_match: Checking SO for lpn');
2925 END IF;
2926
2927 BEGIN
2928 SELECT 1
2929 INTO l_so_cnt
2930 FROM wms_license_plate_numbers
2931 WHERE lpn_context = 11
2932 AND lpn_id = p_lpn
2933 AND organization_id = p_org_id;
2934 EXCEPTION
2935 WHEN NO_DATA_FOUND THEN
2936 l_so_cnt := 0;
2937 END;
2938
2939 IF l_so_cnt > 0 THEN
2940 x_match := 12;
2941 fnd_message.set_name('WMS', 'WMS_LPN_STAGED');
2942 fnd_msg_pub.ADD;
2943 RAISE fnd_api.g_exc_error;
2944 END IF;
2945
2946 SELECT primary_uom_code
2947 , lot_control_code
2948 , serial_number_control_code
2949 INTO l_primary_uom
2950 , l_lot_code
2951 , l_serial_code
2952 FROM mtl_system_items
2953 WHERE organization_id = p_org_id
2954 AND inventory_item_id = p_item_id;
2955
2956 SELECT mmtt.transfer_subinventory
2957 INTO l_xfr_sub_code
2958 FROM mtl_material_transactions_temp mmtt
2959 WHERE mmtt.transaction_temp_id = p_temp_id;
2960
2961 -- Check to see if the item is in the LPN
2962 IF (l_debug = 1) THEN
2963 mydebug('lpn_match: Checking to see if required item,cg,rev,lot exist in lpn..');
2964 END IF;
2965
2966 l_item_cnt := 0;
2967
2968 IF (l_debug = 1) THEN
2969 mydebug('lpn_match: item' || p_item_id || 'LPN' || p_lpn || 'Org' || p_org_id || ' lot' || p_lot || ' Rev' || p_rev);
2970 END IF;
2971
2972 BEGIN
2973 SELECT 1
2974 INTO l_item_cnt
2975 FROM DUAL
2976 WHERE EXISTS(
2977 SELECT 1
2978 FROM wms_lpn_contents wlc
2979 WHERE wlc.parent_lpn_id = p_lpn
2980 AND wlc.organization_id = p_org_id
2981 AND wlc.inventory_item_id = p_item_id
2982 AND NVL(wlc.revision, '-999') = NVL(p_rev, '-999'));
2983 EXCEPTION
2984 -- Item/lot/rev combo does not exist in LPN
2985
2986 WHEN NO_DATA_FOUND THEN
2987 IF (l_debug = 1) THEN
2988 mydebug('lpn_match: item lot rev combo does not exist');
2989 END IF;
2990
2991 x_match := 5;
2992 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
2993 fnd_msg_pub.ADD;
2994 RAISE fnd_api.g_exc_error;
2995 END;
2996
2997 IF l_item_cnt > 0
2998 AND l_lot_code > 1 THEN
2999 --Do this only for lot controlled items
3000
3001 BEGIN
3002 SELECT 1
3003 INTO l_item_cnt
3004 FROM DUAL
3005 WHERE EXISTS(
3006 SELECT 1
3007 FROM wms_lpn_contents wlc, mtl_transaction_lots_temp mtlt
3008 WHERE wlc.parent_lpn_id = p_lpn
3009 AND wlc.organization_id = p_org_id
3010 AND wlc.inventory_item_id = p_item_id
3011 AND NVL(wlc.revision, '-999') = NVL(p_rev, '-999')
3012 AND(mtlt.transaction_temp_id = p_temp_id
3013 AND mtlt.lot_number = wlc.lot_number));
3014 EXCEPTION
3015 -- Item/lot/rev combo does not exist in LPN
3016
3017 WHEN NO_DATA_FOUND THEN
3018 IF (l_debug = 1) THEN
3019 mydebug('lpn_match:lot rev combo for the item does not exist');
3020 END IF;
3021
3022 x_match := 5;
3023 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LOT_LPN');
3024 fnd_msg_pub.ADD;
3025 RAISE fnd_api.g_exc_error;
3026 END;
3027 END IF;
3028
3029 -- Item with the correct lot/revision exists in LPN
3030 IF p_is_sn_alloc = 'Y'
3031 AND p_action = 4 THEN
3032 b_is_serial_control := TRUE;
3033 l_is_serial_control := 'true';
3034 ELSE
3035 b_is_serial_control := FALSE;
3036 l_is_serial_control := 'false';
3037 END IF;
3038
3039 IF l_lot_code > 1 THEN
3040 b_is_lot_control := TRUE;
3041 l_is_lot_control := 'true';
3042 ELSE
3043 b_is_lot_control := FALSE;
3044 l_is_lot_control := 'false';
3045 END IF;
3046
3047 IF p_rev IS NULL THEN
3048 b_is_revision_control := FALSE;
3049 l_is_revision_control := 'false';
3050 ELSE
3051 b_is_revision_control := TRUE;
3052 l_is_revision_control := 'true';
3053 END IF;
3054
3055 IF (l_debug = 1) THEN
3056 mydebug('lpn_match: is_serial_control:' || l_is_serial_control);
3057 mydebug('lpn_match: is_lot_control:' || l_is_lot_control);
3058 mydebug('lpn_match: is_revision_control:' || l_is_revision_control);
3059 END IF;
3060
3061 BEGIN
3062 SELECT allocated_lpn_id
3063 INTO l_allocated_lpn_id
3064 FROM mtl_material_transactions_temp
3065 WHERE transaction_temp_id = p_temp_id;
3066 EXCEPTION
3067 WHEN NO_DATA_FOUND THEN
3068 IF (l_debug = 1) THEN
3069 mydebug('lpn_match: transaction does not exist in mmtt');
3070 END IF;
3071
3072 fnd_message.set_name('INV', 'INV_INVALID_TRANSACTION');
3073 fnd_msg_pub.ADD;
3074 RAISE fnd_api.g_exc_error;
3075 END;
3076
3077 -- clear quantity cache before we create qty tree.
3078 inv_quantity_tree_pub.clear_quantity_cache;
3079
3080 -- Check if LPN has items other than the one requested
3081
3082 IF (l_debug = 1) THEN
3083 mydebug('lpn_match: lpn has the requested item ');
3084 END IF;
3085
3086 l_item_cnt2 := 0;
3087 l_lot_cnt := 0;
3088 l_rev_cnt := 0;
3089 l_cg_cnt := 0;
3090 l_item_cnt2 := 0;
3091 l_lot_cnt := 0;
3092 l_rev_cnt := 0;
3093 l_cg_cnt := 0;
3094 l_lpn_include_lpn := 0;
3095
3096 SELECT COUNT(DISTINCT inventory_item_id)
3097 , COUNT(DISTINCT lot_number)
3098 , COUNT(DISTINCT revision)
3099 , COUNT(DISTINCT cost_group_id)
3100 INTO l_item_cnt2
3101 , l_lot_cnt
3102 , l_rev_cnt
3103 , l_cg_cnt
3104 FROM wms_lpn_contents
3105 WHERE parent_lpn_id = p_lpn
3106 AND organization_id = p_org_id;
3107
3108 SELECT COUNT(*)
3109 INTO l_lpn_include_lpn
3110 FROM wms_license_plate_numbers
3111 WHERE outermost_lpn_id = p_lpn
3112 AND organization_id = p_org_id;
3113
3114 IF l_item_cnt2 > 1
3115 OR l_rev_cnt > 1
3116 OR l_lpn_include_lpn > 1 THEN
3117 -- LPN has multiple items
3118 -- Such LPN's can be picked but in such cases the user has to
3119 -- manually confirm the LPN.
3120 -- No validation for LPN contents in such a case.
3121
3122 IF (l_debug = 1) THEN
3123 mydebug('lpn_match: lpn has items other than requested item ');
3124 END IF;
3125
3126 x_match := 2;
3127
3128 IF l_lot_code > 1 THEN
3129 l_lpn_qty := 0;
3130 OPEN lot_csr;
3131
3132 LOOP
3133 FETCH lot_csr INTO l_mtlt_primary_qty, l_mtlt_lot_number;
3134 EXIT WHEN lot_csr%NOTFOUND;
3135
3136 IF (l_debug = 1) THEN
3137 mydebug('l_mtlt_lot_number : ' || l_mtlt_lot_number);
3138 mydebug('l_mtlt_primary_qty: ' || l_mtlt_primary_qty);
3139 END IF;
3140
3141 /*BEGIN
3142 SELECT
3143 1,
3144 wlc.quantity,
3145 wlc.uom_code
3146 INTO
3147 l_lot_match,
3148 l_wlc_quantity,
3149 l_wlc_uom_code
3150 FROM
3151 wms_lpn_contents wlc
3152 WHERE wlc.parent_lpn_id = p_lpn
3153 AND wlc.inventory_item_id = p_item_id
3154 AND wlc.organization_id = p_org_id
3155 AND nvl(wlc.revision,'-999') = nvl(p_rev,'-999')
3156 AND wlc.lot_number = l_mtlt_lot_number;
3157
3158 EXCEPTION WHEN no_data_found THEN
3159 IF (l_debug = 1) THEN
3160 mydebug('lpn_match: LPN does not have lot ' || l_mtlt_lot_number);
3161 END IF;
3162
3163 l_wlc_quantity := 0;
3164 END;
3165
3166
3167
3168 IF l_wlc_quantity <> 0 THEN
3169
3170 IF l_mtlt_primary_qty >= wms_task_dispatch_gen.get_primary_quantity(p_item_id,p_org_id,l_wlc_quantity,l_wlc_uom_code) THEN
3171
3172 l_lpn_qty := l_lpn_qty +
3173 wms_task_dispatch_gen.get_primary_quantity(p_item_id,p_org_id,l_wlc_quantity,l_wlc_uom_code);
3174
3175 ELSE
3176
3177 l_lpn_qty := l_lpn_qty + l_mtlt_primary_qty;
3178
3179 END IF;
3180
3181 END IF;*/
3182 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
3183 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
3184 -- in order to get correct att.
3185 inv_quantity_tree_pub.update_quantities(
3186 p_api_version_number => 1.0
3187 , p_init_msg_lst => fnd_api.g_false
3188 , x_return_status => l_return_status
3189 , x_msg_count => l_msg_cnt
3190 , x_msg_data => l_msg_data
3191 , p_organization_id => p_org_id
3192 , p_inventory_item_id => p_item_id
3193 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3194 , p_is_revision_control => b_is_revision_control
3195 , p_is_lot_control => TRUE
3196 , p_is_serial_control => b_is_serial_control
3197 , p_revision => NVL(p_rev, NULL)
3198 , p_lot_number => l_mtlt_lot_number
3199 , p_subinventory_code => l_sub
3200 , p_locator_id => l_loc_id
3201 , p_primary_quantity => -l_mtlt_primary_qty
3202 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3203 , x_qoh => l_qoh
3204 , x_rqoh => l_rqoh
3205 , x_qr => l_qr
3206 , x_qs => l_qs
3207 , x_att => l_att
3208 , x_atr => l_atr
3209 , p_lpn_id => p_lpn
3210 , p_transfer_subinventory_code => l_xfr_sub_code
3211 );
3212
3213 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3214 IF (l_debug = 1) THEN
3215 mydebug('lpn_match: after update qty tree for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
3216 END IF;
3217 ELSE
3218 IF (l_debug = 1) THEN
3219 mydebug('lpn_match: calling update qty tree with lpn 1st time failed ');
3220 END IF;
3221
3222 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3223 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3224 fnd_msg_pub.ADD;
3225 RAISE fnd_api.g_exc_error;
3226 END IF;
3227 ELSE
3228 inv_quantity_tree_pub.update_quantities(
3229 p_api_version_number => 1.0
3230 , p_init_msg_lst => fnd_api.g_false
3231 , x_return_status => l_return_status
3232 , x_msg_count => l_msg_cnt
3233 , x_msg_data => l_msg_data
3234 , p_organization_id => p_org_id
3235 , p_inventory_item_id => p_item_id
3236 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3237 , p_is_revision_control => b_is_revision_control
3238 , p_is_lot_control => TRUE
3239 , p_is_serial_control => b_is_serial_control
3240 , p_revision => NVL(p_rev, NULL)
3241 , p_lot_number => l_mtlt_lot_number
3242 , p_subinventory_code => l_sub
3243 , p_locator_id => l_loc_id
3244 , p_primary_quantity => -l_mtlt_primary_qty
3245 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3246 , x_qoh => l_qoh
3247 , x_rqoh => l_rqoh
3248 , x_qr => l_qr
3249 , x_qs => l_qs
3250 , x_att => l_att
3251 , x_atr => l_atr
3252 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
3253 , p_transfer_subinventory_code => l_xfr_sub_code
3254 );
3255
3256 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3257 IF (l_debug = 1) THEN
3258 mydebug('lpn_match: after update qty tree without lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
3259 END IF;
3260 ELSE
3261 IF (l_debug = 1) THEN
3262 mydebug('lpn_match: calling update qty tree back without lpn 1st time failed ');
3263 END IF;
3264
3265 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3266 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3267 fnd_msg_pub.ADD;
3268 RAISE fnd_api.g_exc_error;
3269 END IF;
3270 END IF;
3271
3272 inv_quantity_tree_pub.query_quantities(
3273 p_api_version_number => 1.0
3274 , p_init_msg_lst => fnd_api.g_false
3275 , x_return_status => l_return_status
3276 , x_msg_count => l_msg_cnt
3277 , x_msg_data => l_msg_data
3278 , p_organization_id => p_org_id
3279 , p_inventory_item_id => p_item_id
3280 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3281 , p_is_revision_control => b_is_revision_control
3282 , p_is_lot_control => TRUE
3283 , p_is_serial_control => b_is_serial_control
3284 , p_demand_source_type_id => -9999
3285 , p_revision => NVL(p_rev, NULL)
3286 , p_lot_number => l_mtlt_lot_number
3287 , p_subinventory_code => l_sub
3288 , p_locator_id => l_loc_id
3289 , x_qoh => l_qoh
3290 , x_rqoh => l_rqoh
3291 , x_qr => l_qr
3292 , x_qs => l_qs
3293 , x_att => l_att
3294 , x_atr => l_atr
3295 , p_lpn_id => p_lpn
3296 , p_transfer_subinventory_code => l_xfr_sub_code
3297 );
3298
3299 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3300 IF (l_att > 0) THEN
3301 l_table_index := l_table_index + 1;
3302
3303 IF (l_mtlt_primary_qty >= l_att) THEN
3304 IF (l_debug = 1) THEN
3305 mydebug('lpn_match: l_table_index:' || l_table_index || ' lot_number:' || l_mtlt_lot_number || ' qty: ' || l_att);
3306 END IF;
3307
3308 l_lpn_qty := l_lpn_qty + l_att;
3309 t_lpn_lot_qty_table(l_table_index).lpn_id := p_lpn;
3310 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
3311 t_lpn_lot_qty_table(l_table_index).qty := l_att;
3312 ELSE
3313 IF (l_debug = 1) THEN
3314 mydebug('lpn_match: l_table_index:' || l_table_index || ' lot_number:' || l_mtlt_lot_number || ' qty: '
3315 || l_mtlt_primary_qty);
3316 END IF;
3317
3318 l_lpn_qty := l_lpn_qty + l_mtlt_primary_qty;
3319 t_lpn_lot_qty_table(l_table_index).lpn_id := p_lpn;
3320 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
3321 t_lpn_lot_qty_table(l_table_index).qty := l_mtlt_primary_qty;
3322 END IF;
3323 ELSE
3324 IF (l_debug = 1) THEN
3325 mydebug('lpn_match: LPN does not have lot ' || l_mtlt_lot_number);
3326 END IF;
3327 /*mydebug('lpn_match: l_table_index:'||l_table_index||' lot_number:'||l_mtlt_lot_number||' qty: 0 ');
3328 t_lpn_lot_qty_table(l_table_index).lpn_id := p_lpn;
3329 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
3330 t_lpn_lot_qty_table(l_table_index).qty := l_mtlt_primary_qty;*/
3331 END IF;
3332 ELSE
3333 IF (l_debug = 1) THEN
3334 mydebug('lpn_match: calling qty tree 1st time failed ');
3335 END IF;
3336
3337 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3338 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3339 fnd_msg_pub.ADD;
3340 RAISE fnd_api.g_exc_error;
3341 END IF;
3342
3343 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
3344 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
3345 -- in order to get correct att.
3346 inv_quantity_tree_pub.update_quantities(
3347 p_api_version_number => 1.0
3348 , p_init_msg_lst => fnd_api.g_false
3349 , x_return_status => l_return_status
3350 , x_msg_count => l_msg_cnt
3351 , x_msg_data => l_msg_data
3352 , p_organization_id => p_org_id
3353 , p_inventory_item_id => p_item_id
3354 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3355 , p_is_revision_control => b_is_revision_control
3356 , p_is_lot_control => TRUE
3357 , p_is_serial_control => b_is_serial_control
3358 , p_revision => NVL(p_rev, NULL)
3359 , p_lot_number => l_mtlt_lot_number
3360 , p_subinventory_code => l_sub
3361 , p_locator_id => l_loc_id
3362 , p_primary_quantity => l_mtlt_primary_qty
3363 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3364 , x_qoh => l_qoh
3365 , x_rqoh => l_rqoh
3366 , x_qr => l_qr
3367 , x_qs => l_qs
3368 , x_att => l_att
3369 , x_atr => l_atr
3370 , p_lpn_id => p_lpn
3371 , p_transfer_subinventory_code => l_xfr_sub_code
3372 );
3373
3374 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3375 IF (l_debug = 1) THEN
3376 mydebug('lpn_match: after update qty tree back for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
3377 END IF;
3378 ELSE
3379 IF (l_debug = 1) THEN
3380 mydebug('lpn_match: calling update qty tree back with lpn 1st time failed ');
3381 END IF;
3382
3383 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3384 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3385 fnd_msg_pub.ADD;
3386 RAISE fnd_api.g_exc_error;
3387 END IF;
3388 ELSE
3389 inv_quantity_tree_pub.update_quantities(
3390 p_api_version_number => 1.0
3391 , p_init_msg_lst => fnd_api.g_false
3392 , x_return_status => l_return_status
3393 , x_msg_count => l_msg_cnt
3394 , x_msg_data => l_msg_data
3395 , p_organization_id => p_org_id
3396 , p_inventory_item_id => p_item_id
3397 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3398 , p_is_revision_control => b_is_revision_control
3399 , p_is_lot_control => TRUE
3400 , p_is_serial_control => b_is_serial_control
3401 , p_revision => NVL(p_rev, NULL)
3402 , p_lot_number => l_mtlt_lot_number
3403 , p_subinventory_code => l_sub
3404 , p_locator_id => l_loc_id
3405 , p_primary_quantity => l_mtlt_primary_qty
3406 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3407 , x_qoh => l_qoh
3408 , x_rqoh => l_rqoh
3409 , x_qr => l_qr
3410 , x_qs => l_qs
3411 , x_att => l_att
3412 , x_atr => l_atr
3413 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
3414 , p_transfer_subinventory_code => l_xfr_sub_code
3415 );
3416
3417 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3418 IF (l_debug = 1) THEN
3419 mydebug('lpn_match: after update qty tree back without lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
3420 END IF;
3421 ELSE
3422 IF (l_debug = 1) THEN
3423 mydebug('lpn_match: calling update qty tree back without lpn 1st time failed ');
3424 END IF;
3425
3426 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3427 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3428 fnd_msg_pub.ADD;
3429 RAISE fnd_api.g_exc_error;
3430 END IF;
3431 END IF;
3432 END LOOP;
3433
3434 CLOSE lot_csr;
3435 ELSIF p_is_sn_alloc = 'Y'
3436 AND p_action = 4 THEN
3437 IF (l_debug = 1) THEN
3438 mydebug('lpn_match: SN control and SN allocation on');
3439 END IF;
3440
3441 SELECT COUNT(fm_serial_number)
3442 INTO l_serial_exist_cnt
3443 FROM mtl_serial_numbers_temp msnt
3444 WHERE msnt.transaction_temp_id = p_temp_id
3445 AND msnt.fm_serial_number IN(
3446 SELECT serial_number
3447 FROM mtl_serial_numbers
3448 WHERE lpn_id = p_lpn
3449 AND inventory_item_id = p_item_id
3450 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
3451
3452 IF (l_debug = 1) THEN
3453 mydebug('lpn_match: SN exist count' || l_serial_exist_cnt);
3454 END IF;
3455
3456 IF (l_serial_exist_cnt = 0) THEN
3457 IF (l_debug = 1) THEN
3458 mydebug('lpn_match: LPN does not have the allocated serials ');
3459 END IF;
3460
3461 -- Serial numbers missing for the transaction
3462 x_match := 9;
3463 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
3464 fnd_msg_pub.ADD;
3465 RAISE fnd_api.g_exc_error;
3466 END IF;
3467
3468 SELECT COUNT(fm_serial_number)
3469 INTO l_total_serial_cnt
3470 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
3471 WHERE mtlt.transaction_temp_id = p_temp_id
3472 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
3473
3474 IF (l_debug = 1) THEN
3475 mydebug('lpn_match: SN tot count' || l_total_serial_cnt);
3476 END IF;
3477
3478 IF (l_total_serial_cnt = l_serial_exist_cnt) THEN
3479 IF (l_debug = 1) THEN
3480 mydebug('lpn_match: LPN matches exactly');
3481 END IF;
3482
3483 x_match := 1;
3484 ELSIF(l_total_serial_cnt > l_serial_exist_cnt) THEN
3485 IF (l_debug = 1) THEN
3486 mydebug('lpn_match: LPN has less');
3487 END IF;
3488
3489 x_match := 3;
3490 l_lpn_qty := l_serial_exist_cnt;
3491 ELSE
3492 IF (l_debug = 1) THEN
3493 mydebug('lpn_match: LPN has extra serials');
3494 END IF;
3495
3496 x_match := 4;
3497 END IF;
3498 ELSE -- Plain item OR REVISION controlled item
3499 IF (l_debug = 1) THEN
3500 mydebug('lpn_match: Getting total qty in user entered uom..');
3501 END IF;
3502
3503 /*SELECT SUM ( INV_Convert.INV_UM_Convert(wlc.inventory_item_id,
3504 null,
3505 wlc.quantity,
3506 wlc.uom_code,
3507 p_uom,
3508 null,
3509 null) )
3510 INTO l_lpn_qty
3511 FROM wms_lpn_contents wlc
3512 WHERE wlc.parent_lpn_id = p_lpn
3513 AND wlc.inventory_item_id = p_item_id
3514 AND Nvl(wlc.revision, '-999') = Nvl(p_rev, '-999'); -- bug fix 2123096 */
3515 IF (l_debug = 1) THEN
3516 mydebug('lpn_match: Getting total qty in user entered uom..');
3517 END IF;
3518
3519 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
3520 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
3521 -- in order to get correct att.
3522 inv_quantity_tree_pub.update_quantities(
3523 p_api_version_number => 1.0
3524 , p_init_msg_lst => fnd_api.g_false
3525 , x_return_status => l_return_status
3526 , x_msg_count => l_msg_cnt
3527 , x_msg_data => l_msg_data
3528 , p_organization_id => p_org_id
3529 , p_inventory_item_id => p_item_id
3530 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3531 , p_is_revision_control => b_is_revision_control
3532 , p_is_lot_control => FALSE
3533 , p_is_serial_control => b_is_serial_control
3534 , p_revision => NVL(p_rev, NULL)
3535 , p_lot_number => NULL
3536 , p_subinventory_code => l_sub
3537 , p_locator_id => l_loc_id
3538 , p_primary_quantity => -p_qty
3539 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3540 , x_qoh => l_qoh
3541 , x_rqoh => l_rqoh
3542 , x_qr => l_qr
3543 , x_qs => l_qs
3544 , x_att => l_att
3545 , x_atr => l_atr
3546 , p_lpn_id => p_lpn
3547 , p_transfer_subinventory_code => l_xfr_sub_code
3548 );
3549
3550 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3551 IF (l_debug = 1) THEN
3552 mydebug('lpn_match: update qty tree with lpn 2nd time: l_att:' || l_att);
3553 END IF;
3554 ELSE
3555 IF (l_debug = 1) THEN
3556 mydebug('lpn_match: calling update qty tree with lpn 2nd time failed ');
3557 END IF;
3558
3559 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3560 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3561 fnd_msg_pub.ADD;
3562 RAISE fnd_api.g_exc_error;
3563 END IF;
3564 ELSE
3565 inv_quantity_tree_pub.update_quantities(
3566 p_api_version_number => 1.0
3567 , p_init_msg_lst => fnd_api.g_false
3568 , x_return_status => l_return_status
3569 , x_msg_count => l_msg_cnt
3570 , x_msg_data => l_msg_data
3571 , p_organization_id => p_org_id
3572 , p_inventory_item_id => p_item_id
3573 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3574 , p_is_revision_control => b_is_revision_control
3575 , p_is_lot_control => FALSE
3576 , p_is_serial_control => b_is_serial_control
3577 , p_revision => NVL(p_rev, NULL)
3578 , p_lot_number => NULL
3579 , p_subinventory_code => l_sub
3580 , p_locator_id => l_loc_id
3581 , p_primary_quantity => -p_qty
3582 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3583 , x_qoh => l_qoh
3584 , x_rqoh => l_rqoh
3585 , x_qr => l_qr
3586 , x_qs => l_qs
3587 , x_att => l_att
3588 , x_atr => l_atr
3589 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
3590 , p_transfer_subinventory_code => l_xfr_sub_code
3591 );
3592
3593 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3594 IF (l_debug = 1) THEN
3595 mydebug('lpn_match: update qty tree without lpn 2nd time:l_att:' || l_att);
3596 END IF;
3597 ELSE
3598 IF (l_debug = 1) THEN
3599 mydebug('lpn_match: calling update qty tree back without lpn 2nd time failed ');
3600 END IF;
3601
3602 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3603 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3604 fnd_msg_pub.ADD;
3605 RAISE fnd_api.g_exc_error;
3606 END IF;
3607 END IF;
3608
3609 inv_quantity_tree_pub.query_quantities(
3610 p_api_version_number => 1.0
3611 , p_init_msg_lst => fnd_api.g_false
3612 , x_return_status => l_return_status
3613 , x_msg_count => l_msg_cnt
3614 , x_msg_data => l_msg_data
3615 , p_organization_id => p_org_id
3616 , p_inventory_item_id => p_item_id
3617 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3618 , p_is_revision_control => b_is_revision_control
3619 , p_is_lot_control => FALSE
3620 , p_is_serial_control => b_is_serial_control
3621 , p_demand_source_type_id => -9999
3622 , p_revision => NVL(p_rev, NULL)
3623 , p_lot_number => NULL
3624 , p_subinventory_code => l_sub
3625 , p_locator_id => l_loc_id
3626 , x_qoh => l_qoh
3627 , x_rqoh => l_rqoh
3628 , x_qr => l_qr
3629 , x_qs => l_qs
3630 , x_att => l_att
3631 , x_atr => l_atr
3632 , p_lpn_id => p_lpn
3633 , p_transfer_subinventory_code => l_xfr_sub_code
3634 );
3635
3636 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3637 l_lpn_qty := l_att;
3638 ELSE
3639 IF (l_debug = 1) THEN
3640 mydebug('lpn_match: calling qty tree 2nd time failed ');
3641 END IF;
3642
3643 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3644 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3645 fnd_msg_pub.ADD;
3646 RAISE fnd_api.g_exc_error;
3647 END IF;
3648
3649 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
3650 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
3651 -- in order to get correct att.
3652 inv_quantity_tree_pub.update_quantities(
3653 p_api_version_number => 1.0
3654 , p_init_msg_lst => fnd_api.g_false
3655 , x_return_status => l_return_status
3656 , x_msg_count => l_msg_cnt
3657 , x_msg_data => l_msg_data
3658 , p_organization_id => p_org_id
3659 , p_inventory_item_id => p_item_id
3660 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3661 , p_is_revision_control => b_is_revision_control
3662 , p_is_lot_control => FALSE
3663 , p_is_serial_control => b_is_serial_control
3664 , p_revision => NVL(p_rev, NULL)
3665 , p_lot_number => NULL
3666 , p_subinventory_code => l_sub
3667 , p_locator_id => l_loc_id
3668 , p_primary_quantity => p_qty
3669 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3670 , x_qoh => l_qoh
3671 , x_rqoh => l_rqoh
3672 , x_qr => l_qr
3673 , x_qs => l_qs
3674 , x_att => l_att
3675 , x_atr => l_atr
3676 , p_lpn_id => p_lpn
3677 , p_transfer_subinventory_code => l_xfr_sub_code
3678 );
3679
3680 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3681 IF (l_debug = 1) THEN
3682 mydebug('lpn_match: update qty tree back with lpn 2nd time: l_att:' || l_att);
3683 END IF;
3684 ELSE
3685 IF (l_debug = 1) THEN
3686 mydebug('lpn_match: calling update qty tree with lpn 2nd time failed ');
3687 END IF;
3688
3689 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3690 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3691 fnd_msg_pub.ADD;
3692 RAISE fnd_api.g_exc_error;
3693 END IF;
3694 ELSE
3695 inv_quantity_tree_pub.update_quantities(
3696 p_api_version_number => 1.0
3697 , p_init_msg_lst => fnd_api.g_false
3698 , x_return_status => l_return_status
3699 , x_msg_count => l_msg_cnt
3700 , x_msg_data => l_msg_data
3701 , p_organization_id => p_org_id
3702 , p_inventory_item_id => p_item_id
3703 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3704 , p_is_revision_control => b_is_revision_control
3705 , p_is_lot_control => FALSE
3706 , p_is_serial_control => b_is_serial_control
3707 , p_revision => NVL(p_rev, NULL)
3708 , p_lot_number => NULL
3709 , p_subinventory_code => l_sub
3710 , p_locator_id => l_loc_id
3711 , p_primary_quantity => p_qty
3712 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3713 , x_qoh => l_qoh
3714 , x_rqoh => l_rqoh
3715 , x_qr => l_qr
3716 , x_qs => l_qs
3717 , x_att => l_att
3718 , x_atr => l_atr
3719 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
3720 , p_transfer_subinventory_code => l_xfr_sub_code
3721 );
3722
3723 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3724 IF (l_debug = 1) THEN
3725 mydebug('lpn_match: update qty tree back without lpn 2nd time:l_att:' || l_att);
3726 END IF;
3727 ELSE
3728 IF (l_debug = 1) THEN
3729 mydebug('lpn_match: calling update qty tree back without lpn 2nd time failed ');
3730 END IF;
3731
3732 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3733 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3734 fnd_msg_pub.ADD;
3735 RAISE fnd_api.g_exc_error;
3736 END IF;
3737 END IF;
3738 END IF;
3739 ELSE
3740 -- LPN has just the item requested
3741 -- See if quantity/details it has will match the quantity allocated
3742 -- Find out if the item is lot/serial controlled and UOM of item
3743 -- and compare with transaction details
3744
3745 IF (l_debug = 1) THEN
3746 mydebug('lpn_match: lpn has only the requested item ');
3747 END IF;
3748
3749 SELECT primary_quantity
3750 , transaction_uom
3751 INTO l_mmtt_qty
3752 , l_txn_uom
3753 FROM mtl_material_transactions_temp
3754 WHERE transaction_temp_id = p_temp_id;
3755
3756 -- If item is lot controlled then validate the lots
3757
3758 IF l_lot_code > 1 THEN
3759 IF (l_debug = 1) THEN
3760 mydebug('lpn_match: item is lot controlled');
3761 END IF;
3762
3763 -- If item is also serial controlled and serial allocation is
3764 -- on then count the number of serials allocated which exist
3765 -- in the LPN.
3766 -- If the count is 0 then raise an error
3767
3768 IF p_is_sn_alloc = 'Y'
3769 AND p_action = 4 THEN
3770 IF (l_debug = 1) THEN
3771 mydebug('lpn_match: SN control and SN allocation on');
3772 END IF;
3773
3774 SELECT COUNT(fm_serial_number)
3775 INTO l_serial_exist_cnt
3776 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
3777 WHERE mtlt.transaction_temp_id = p_temp_id
3778 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
3779 AND msnt.fm_serial_number IN(
3780 SELECT serial_number
3781 FROM mtl_serial_numbers
3782 WHERE lpn_id = p_lpn
3783 AND inventory_item_id = p_item_id
3784 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
3785
3786 IF (l_debug = 1) THEN
3787 mydebug('lpn_match: SN exist count' || l_serial_exist_cnt);
3788 END IF;
3789
3790 IF (l_serial_exist_cnt = 0) THEN
3791 IF (l_debug = 1) THEN
3792 mydebug('lpn_match: No serial allocations have occured or LPN does not have the allocated serials ');
3793 END IF;
3794
3795 -- Serial numbers missing for the transaction
3796 x_match := 9;
3797 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
3798 fnd_msg_pub.ADD;
3799 RAISE fnd_api.g_exc_error;
3800 END IF;
3801 END IF;
3802
3803 -- Check whether the Lots allocated are all in the LPN
3804 -- An LPN can have many lots and items/revisions, check if the
3805 -- lots allocated for the item exist in the LPN and if any of
3806 -- them has quantity less/more than what was suggested.
3807
3808 IF (l_debug = 1) THEN
3809 mydebug('lpn_match: Check whether the LPN has any lot whose quantity exceeds allocated quantity');
3810 END IF;
3811
3812 l_lpn_qty := 0;
3813 OPEN lot_csr;
3814
3815 LOOP
3816 FETCH lot_csr INTO l_mtlt_primary_qty, l_mtlt_lot_number;
3817 EXIT WHEN lot_csr%NOTFOUND;
3818 l_lot_match := 0;
3819
3820 IF (l_debug = 1) THEN
3821 mydebug('lpn_match: l_mtlt_lot_number : ' || l_mtlt_lot_number);
3822 mydebug('lpn_match: l_mtlt_primary_qty: ' || l_mtlt_primary_qty);
3823 END IF;
3824
3825 l_lot_cnt := l_lot_cnt - 1;
3826
3827 /*BEGIN
3828 SELECT
3829 1,
3830 wlc.quantity,
3831 wlc.uom_code
3832 INTO
3833 l_lot_match,
3834 l_wlc_quantity,
3835 l_wlc_uom_code
3836 FROM
3837 wms_lpn_contents wlc
3838 WHERE wlc.parent_lpn_id = p_lpn
3839 AND wlc.inventory_item_id = p_item_id
3840 AND wlc.organization_id = p_org_id
3841 AND nvl(wlc.revision,'-999') = nvl(p_rev,'-999')
3842 AND wlc.lot_number = l_mtlt_lot_number;
3843
3844 EXCEPTION WHEN no_data_found THEN
3845 IF (l_debug = 1) THEN
3846 mydebug('lpn_match: LPN does not have lot ' || l_mtlt_lot_number);
3847 END IF;
3848
3849 IF x_match <> 4 THEN
3850
3851 x_match := 3;
3852 END IF;
3853
3854 l_lot_match := 0;
3855 l_wlc_quantity := 0;
3856 l_lot_cnt := l_lot_cnt + 1;
3857 END;
3858
3859 IF l_wlc_quantity <> 0 THEN
3860
3861 IF l_mtlt_primary_qty >= wms_task_dispatch_gen.get_primary_quantity(p_item_id,p_org_id,l_wlc_quantity,l_wlc_uom_code) THEN
3862
3863 l_lpn_qty := l_lpn_qty + wms_task_dispatch_gen.get_primary_quantity(p_item_id,p_org_id,l_wlc_quantity,l_wlc_uom_code);
3864
3865 ELSE
3866
3867 l_lpn_qty := l_lpn_qty + l_mtlt_primary_qty;
3868
3869 END IF;
3870
3871 END IF;
3872
3873 IF l_lot_match <> 0 AND x_match <> 4 THEN
3874
3875 IF l_mtlt_primary_qty < wms_task_dispatch_gen.get_primary_quantity(p_item_id,p_org_id,l_wlc_quantity,l_wlc_uom_code) THEN
3876
3877 IF (l_debug = 1) THEN
3878 mydebug('lpn_match: Qty in LPN for lot ' || l_mtlt_lot_number || ' more than transaction qty for that lot');
3879 END IF;
3880 x_match := 4;
3881
3882 ELSIF l_mtlt_primary_qty > wms_task_dispatch_gen.get_primary_quantity(p_item_id,p_org_id,l_wlc_quantity,l_wlc_uom_code) THEN
3883
3884 IF (l_debug = 1) THEN
3885 mydebug('lpn_match: Qty in LPN for lot ' || l_mtlt_lot_number || ' less than transaction qty for that lot');
3886 END IF;
3887 x_match := 3;
3888
3889 ELSE
3890
3891 IF x_match <> 3 THEN
3892
3893 IF (l_debug = 1) THEN
3894 mydebug('lpn_match: qty in LPN for lot ' || l_mtlt_lot_number || ' equal to transaction qty for that lot');
3895 END IF;
3896 x_match := 1;
3897 END IF;
3898
3899 END IF;
3900
3901 END IF;*/
3902 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
3903 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
3904 -- in order to get correct att.
3905 inv_quantity_tree_pub.update_quantities(
3906 p_api_version_number => 1.0
3907 , p_init_msg_lst => fnd_api.g_false
3908 , x_return_status => l_return_status
3909 , x_msg_count => l_msg_cnt
3910 , x_msg_data => l_msg_data
3911 , p_organization_id => p_org_id
3912 , p_inventory_item_id => p_item_id
3913 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3914 , p_is_revision_control => b_is_revision_control
3915 , p_is_lot_control => TRUE
3916 , p_is_serial_control => b_is_serial_control
3917 , p_revision => NVL(p_rev, NULL)
3918 , p_lot_number => l_mtlt_lot_number
3919 , p_subinventory_code => l_sub
3920 , p_locator_id => l_loc_id
3921 , p_primary_quantity => -l_mtlt_primary_qty
3922 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3923 , x_qoh => l_qoh
3924 , x_rqoh => l_rqoh
3925 , x_qr => l_qr
3926 , x_qs => l_qs
3927 , x_att => l_att
3928 , x_atr => l_atr
3929 , p_lpn_id => p_lpn
3930 , p_transfer_subinventory_code => l_xfr_sub_code
3931 );
3932
3933 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3934 IF (l_debug = 1) THEN
3935 mydebug('lpn_match: update qty tree 3rd time for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
3936 END IF;
3937 ELSE
3938 IF (l_debug = 1) THEN
3939 mydebug('lpn_match: calling update qty tree with lpn 3rd time failed ');
3940 END IF;
3941
3942 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3943 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3944 fnd_msg_pub.ADD;
3945 RAISE fnd_api.g_exc_error;
3946 END IF;
3947 ELSE
3948 inv_quantity_tree_pub.update_quantities(
3949 p_api_version_number => 1.0
3950 , p_init_msg_lst => fnd_api.g_false
3951 , x_return_status => l_return_status
3952 , x_msg_count => l_msg_cnt
3953 , x_msg_data => l_msg_data
3954 , p_organization_id => p_org_id
3955 , p_inventory_item_id => p_item_id
3956 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
3957 , p_is_revision_control => b_is_revision_control
3958 , p_is_lot_control => TRUE
3959 , p_is_serial_control => b_is_serial_control
3960 , p_revision => NVL(p_rev, NULL)
3961 , p_lot_number => l_mtlt_lot_number
3962 , p_subinventory_code => l_sub
3963 , p_locator_id => l_loc_id
3964 , p_primary_quantity => -l_mtlt_primary_qty
3965 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
3966 , x_qoh => l_qoh
3967 , x_rqoh => l_rqoh
3968 , x_qr => l_qr
3969 , x_qs => l_qs
3970 , x_att => l_att
3971 , x_atr => l_atr
3972 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
3973 , p_transfer_subinventory_code => l_xfr_sub_code
3974 );
3975
3976 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
3977 IF (l_debug = 1) THEN
3978 mydebug('lpn_match: after update without lpn 3rd time l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
3979 END IF;
3980 ELSE
3981 IF (l_debug = 1) THEN
3982 mydebug('lpn_match: calling update qty tree back 3rd time without lpn 3rd time failed ');
3983 END IF;
3984
3985 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
3986 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
3987 fnd_msg_pub.ADD;
3988 RAISE fnd_api.g_exc_error;
3989 END IF;
3990 END IF;
3991
3992 inv_quantity_tree_pub.query_quantities(
3993 p_api_version_number => 1.0
3994 , p_init_msg_lst => fnd_api.g_false
3995 , x_return_status => l_return_status
3996 , x_msg_count => l_msg_cnt
3997 , x_msg_data => l_msg_data
3998 , p_organization_id => p_org_id
3999 , p_inventory_item_id => p_item_id
4000 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4001 , p_is_revision_control => b_is_revision_control
4002 , p_is_lot_control => TRUE
4003 , p_is_serial_control => b_is_serial_control
4004 , p_demand_source_type_id => -9999
4005 , p_revision => NVL(p_rev, NULL)
4006 , p_lot_number => l_mtlt_lot_number
4007 , p_subinventory_code => l_sub
4008 , p_locator_id => l_loc_id
4009 , x_qoh => l_qoh
4010 , x_rqoh => l_rqoh
4011 , x_qr => l_qr
4012 , x_qs => l_qs
4013 , x_att => l_att
4014 , x_atr => l_atr
4015 , p_lpn_id => p_lpn
4016 , p_transfer_subinventory_code => l_xfr_sub_code
4017 );
4018
4019 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4020 l_lot_match := 1;
4021
4022 IF (l_att > 0) THEN
4023 l_table_index := l_table_index + 1;
4024
4025 IF (l_mtlt_primary_qty >= l_att) THEN
4026 l_lpn_qty := l_lpn_qty + l_att;
4027
4028 IF (l_debug = 1) THEN
4029 mydebug('lpn_match: l_table_index:' || l_table_index || ' lot_number:' || l_mtlt_lot_number || ' qty:' || l_att);
4030 END IF;
4031
4032 t_lpn_lot_qty_table(l_table_index).lpn_id := p_lpn;
4033 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
4034 t_lpn_lot_qty_table(l_table_index).qty := l_att;
4035 ELSE
4036 l_lpn_qty := l_lpn_qty + l_mtlt_primary_qty;
4037
4038 IF (l_debug = 1) THEN
4039 mydebug('lpn_match: l_table_index:' || l_table_index || ' lot_number:' || l_mtlt_lot_number || ' qty:'
4040 || l_mtlt_primary_qty);
4041 END IF;
4042
4043 t_lpn_lot_qty_table(l_table_index).lpn_id := p_lpn;
4044 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
4045 t_lpn_lot_qty_table(l_table_index).qty := l_mtlt_primary_qty;
4046 END IF;
4047 ELSE
4048 IF (l_debug = 1) THEN
4049 mydebug('lpn_match: LPN does not have lot ' || l_mtlt_lot_number);
4050 END IF;
4051
4052 /*mydebug('lpn_match: l_table_index:'||l_table_index||' lot_number:'||l_mtlt_lot_number||' qty:0');
4053 t_lpn_lot_qty_table(l_table_index).lpn_id := p_lpn;
4054 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
4055 t_lpn_lot_qty_table(l_table_index).qty := 0; */
4056 IF x_match <> 4 THEN
4057 x_match := 3;
4058 END IF;
4059
4060 l_lot_match := 0;
4061 l_lot_cnt := l_lot_cnt + 1;
4062 END IF;
4063 ELSE
4064 IF (l_debug = 1) THEN
4065 mydebug('lpn_match: calling qty tree 3rd time failed ');
4066 END IF;
4067
4068 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4069 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4070 fnd_msg_pub.ADD;
4071 RAISE fnd_api.g_exc_error;
4072 END IF;
4073
4074 IF l_lot_match <> 0
4075 AND x_match <> 4 THEN
4076 IF l_mtlt_primary_qty < l_att THEN
4077 IF (l_debug = 1) THEN
4078 mydebug('lpn_match: Qty in LPN for lot ' || l_mtlt_lot_number || ' more than transaction qty for that lot');
4079 END IF;
4080
4081 x_match := 4;
4082 ELSIF l_mtlt_primary_qty > l_att THEN
4083 IF l_qoh = l_att THEN
4084 IF (l_debug = 1) THEN
4085 mydebug('lpn_match: Qty in LPN for lot ' || l_mtlt_lot_number || ' less than transaction qty for that lot');
4086 END IF;
4087
4088 x_match := 3;
4089 ELSE
4090 IF (l_debug = 1) THEN
4091 mydebug(
4092 'lpn_match: Qty in LPN for lot '
4093 || l_mtlt_lot_number
4094 || ' less than transaction qty for that lot and lpn is for multiple task'
4095 );
4096 END IF;
4097
4098 x_match := 4;
4099 END IF;
4100 ELSE
4101 IF x_match <> 3 THEN
4102 IF (l_debug = 1) THEN
4103 mydebug('lpn_match: qty in LPN for lot ' || l_mtlt_lot_number || ' equal to transaction qty for that lot');
4104 END IF;
4105
4106 IF l_qoh = l_att THEN
4107 IF (l_debug = 1) THEN
4108 mydebug('lpn_match: lpn qoh is equal to att. Exact match');
4109 END IF;
4110
4111 x_match := 1;
4112 ELSE
4113 IF (l_debug = 1) THEN
4114 mydebug('lpn_match: lpn qoh is great than att. part of lpn is match');
4115 END IF;
4116
4117 x_match := 4;
4118 END IF;
4119 END IF;
4120 END IF;
4121 END IF;
4122
4123 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
4124 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
4125 -- in order to get correct att.
4126 inv_quantity_tree_pub.update_quantities(
4127 p_api_version_number => 1.0
4128 , p_init_msg_lst => fnd_api.g_false
4129 , x_return_status => l_return_status
4130 , x_msg_count => l_msg_cnt
4131 , x_msg_data => l_msg_data
4132 , p_organization_id => p_org_id
4133 , p_inventory_item_id => p_item_id
4134 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4135 , p_is_revision_control => b_is_revision_control
4136 , p_is_lot_control => TRUE
4137 , p_is_serial_control => b_is_serial_control
4138 , p_revision => NVL(p_rev, NULL)
4139 , p_lot_number => l_mtlt_lot_number
4140 , p_subinventory_code => l_sub
4141 , p_locator_id => l_loc_id
4142 , p_primary_quantity => l_mtlt_primary_qty
4143 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4144 , x_qoh => l_qoh
4145 , x_rqoh => l_rqoh
4146 , x_qr => l_qr
4147 , x_qs => l_qs
4148 , x_att => l_att
4149 , x_atr => l_atr
4150 , p_lpn_id => p_lpn
4151 , p_transfer_subinventory_code => l_xfr_sub_code
4152 );
4153
4154 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4155 IF (l_debug = 1) THEN
4156 mydebug('lpn_match: update qty tree back 3rd time for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
4157 END IF;
4158 ELSE
4159 IF (l_debug = 1) THEN
4160 mydebug('lpn_match: calling update qty tree with lpn 3rd time failed ');
4161 END IF;
4162
4163 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4164 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4165 fnd_msg_pub.ADD;
4166 RAISE fnd_api.g_exc_error;
4167 END IF;
4168 ELSE
4169 inv_quantity_tree_pub.update_quantities(
4170 p_api_version_number => 1.0
4171 , p_init_msg_lst => fnd_api.g_false
4172 , x_return_status => l_return_status
4173 , x_msg_count => l_msg_cnt
4174 , x_msg_data => l_msg_data
4175 , p_organization_id => p_org_id
4176 , p_inventory_item_id => p_item_id
4177 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4178 , p_is_revision_control => b_is_revision_control
4179 , p_is_lot_control => TRUE
4180 , p_is_serial_control => b_is_serial_control
4181 , p_revision => NVL(p_rev, NULL)
4182 , p_lot_number => l_mtlt_lot_number
4183 , p_subinventory_code => l_sub
4184 , p_locator_id => l_loc_id
4185 , p_primary_quantity => l_mtlt_primary_qty
4186 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4187 , x_qoh => l_qoh
4188 , x_rqoh => l_rqoh
4189 , x_qr => l_qr
4190 , x_qs => l_qs
4191 , x_att => l_att
4192 , x_atr => l_atr
4193 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
4194 , p_transfer_subinventory_code => l_xfr_sub_code
4195 );
4196
4197 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4198 IF (l_debug = 1) THEN
4199 mydebug('lpn_match: after update qty tree back without lpn 3rd time l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
4200 END IF;
4201 ELSE
4202 IF (l_debug = 1) THEN
4203 mydebug('lpn_match: calling update qty tree back without lpn 3rd time failed ');
4204 END IF;
4205
4206 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4207 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4208 fnd_msg_pub.ADD;
4209 RAISE fnd_api.g_exc_error;
4210 END IF;
4211 END IF;
4212 END LOOP;
4213
4214 CLOSE lot_csr;
4215
4216 IF l_lot_cnt > 0 THEN
4217 x_match := 4;
4218 END IF;
4219
4220 -- Now that all the lots have been validated, check whether the serial
4221 -- numbers allocated match the ones in the lpn.
4222
4223 IF p_is_sn_alloc = 'Y'
4224 AND p_action = 4
4225 AND(x_match = 1
4226 OR x_match = 3) THEN
4227 SELECT COUNT(fm_serial_number)
4228 INTO l_total_serial_cnt
4229 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
4230 WHERE mtlt.transaction_temp_id = p_temp_id
4231 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
4232
4233 IF (l_debug = 1) THEN
4234 mydebug('lpn_match: SN tot count' || l_total_serial_cnt);
4235 END IF;
4236
4237 IF (l_total_serial_cnt = l_serial_exist_cnt) THEN
4238 IF (l_debug = 1) THEN
4239 mydebug('lpn_match: LPN matches exactly');
4240 END IF;
4241
4242 x_match := 1;
4243 ELSIF(l_total_serial_cnt > l_serial_exist_cnt) THEN
4244 IF (l_debug = 1) THEN
4245 mydebug('lpn_match: LPN has less');
4246 END IF;
4247
4248 x_match := 3;
4249 ELSE
4250 IF (l_debug = 1) THEN
4251 mydebug('lpn_match: LPN has extra serials');
4252 END IF;
4253
4254 x_match := 4;
4255 END IF;
4256 END IF;
4257 ELSE -- Item is not lot controlled
4258 IF (l_debug = 1) THEN
4259 mydebug('lpn_match: Not Lot controlled ..');
4260 END IF;
4261
4262 -- Check serial numbers if serial controlled and serial
4263 -- allocation is turned on
4264
4265 IF p_is_sn_alloc = 'Y'
4266 AND p_action = 4 THEN
4267 IF (l_debug = 1) THEN
4268 mydebug('lpn_match: SN control and SN allocation on');
4269 END IF;
4270
4271 SELECT COUNT(fm_serial_number)
4272 INTO l_serial_exist_cnt
4273 FROM mtl_serial_numbers_temp msnt
4274 WHERE msnt.transaction_temp_id = p_temp_id
4275 AND msnt.fm_serial_number IN(
4276 SELECT serial_number
4277 FROM mtl_serial_numbers
4278 WHERE lpn_id = p_lpn
4279 AND inventory_item_id = p_item_id
4280 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
4281
4282 IF (l_debug = 1) THEN
4283 mydebug('lpn_match: SN exist count' || l_serial_exist_cnt);
4284 END IF;
4285
4286 IF (l_serial_exist_cnt = 0) THEN
4287 IF (l_debug = 1) THEN
4288 mydebug('lpn_match: LPN does not have the allocated serials ');
4289 END IF;
4290
4291 -- Serial numbers missing for the transaction
4292 x_match := 9;
4293 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
4294 fnd_msg_pub.ADD;
4295 RAISE fnd_api.g_exc_error;
4296 END IF;
4297 END IF;
4298
4299 -- Get qty
4300 IF (l_debug = 1) THEN
4301 mydebug('lpn_match: get lpn quantity ');
4302 END IF;
4303
4304 /*SELECT
4305 quantity,
4306 uom_code
4307 INTO
4308 l_exist_qty,
4309 l_lpn_uom
4310 FROM wms_lpn_contents
4311 WHERE parent_lpn_id = p_lpn
4312 AND organization_id = p_org_id
4313 AND inventory_item_id = p_item_id
4314 AND Nvl(cost_group_id,'-999') = Nvl(p_cost_group_id,'-999')
4315 AND Nvl(revision,'-999') = Nvl(p_rev,'-999');
4316
4317 IF (l_debug = 1) THEN
4318 mydebug('lpn_match: lpn quantity = ' || l_exist_qty );
4319 END IF;
4320
4321 IF l_lpn_uom <> l_primary_uom THEN
4322
4323 l_exist_qty := wms_task_dispatch_gen.get_primary_quantity
4324 (p_item_id => p_item_id,
4325 p_organization_id => p_org_id,
4326 p_from_quantity => l_exist_qty,
4327 p_from_unit => l_lpn_uom);
4328 END IF;
4329
4330 IF (l_debug = 1) THEN
4331 mydebug('lpn_match: lpn quantity in correct UOM = ' || l_exist_qty );
4332 mydebug('lpn_match: allocated quantity = ' || l_exist_qty );
4333 END IF;
4334
4335 IF l_mmtt_qty = l_exist_qty THEN
4336 -- LPN is a match!
4337 IF (l_debug = 1) THEN
4338 mydebug('lpn_match: LPN matched');
4339 END IF;
4340 x_match := 1;
4341
4342 ELSIF l_mmtt_qty > l_exist_qty THEN
4343
4344 x_match := 3;
4345 l_lpn_qty := l_exist_qty;
4346
4347 ELSE
4348
4349 x_match := 4;
4350
4351 END IF;*/
4352 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
4353 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
4354 -- in order to get correct att.
4355 inv_quantity_tree_pub.update_quantities(
4356 p_api_version_number => 1.0
4357 , p_init_msg_lst => fnd_api.g_false
4358 , x_return_status => l_return_status
4359 , x_msg_count => l_msg_cnt
4360 , x_msg_data => l_msg_data
4361 , p_organization_id => p_org_id
4362 , p_inventory_item_id => p_item_id
4363 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4364 , p_is_revision_control => b_is_revision_control
4365 , p_is_lot_control => FALSE
4366 , p_is_serial_control => b_is_serial_control
4367 , p_revision => NVL(p_rev, NULL)
4368 , p_lot_number => NULL
4369 , p_subinventory_code => l_sub
4370 , p_locator_id => l_loc_id
4371 , p_primary_quantity => -l_mmtt_qty
4372 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4373 , x_qoh => l_qoh
4374 , x_rqoh => l_rqoh
4375 , x_qr => l_qr
4376 , x_qs => l_qs
4377 , x_att => l_att
4378 , x_atr => l_atr
4379 , p_lpn_id => p_lpn
4380 , p_transfer_subinventory_code => l_xfr_sub_code
4381 );
4382
4383 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4384 IF (l_debug = 1) THEN
4385 mydebug('lpn_match: update qty tree with lpn 4th time: l_att:' || l_att);
4386 END IF;
4387 ELSE
4388 IF (l_debug = 1) THEN
4389 mydebug('lpn_match: calling update qty tree with lpn 4th time failed ');
4390 END IF;
4391
4392 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4393 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4394 fnd_msg_pub.ADD;
4395 RAISE fnd_api.g_exc_error;
4396 END IF;
4397 ELSE
4398 inv_quantity_tree_pub.update_quantities(
4399 p_api_version_number => 1.0
4400 , p_init_msg_lst => fnd_api.g_false
4401 , x_return_status => l_return_status
4402 , x_msg_count => l_msg_cnt
4403 , x_msg_data => l_msg_data
4404 , p_organization_id => p_org_id
4405 , p_inventory_item_id => p_item_id
4406 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4407 , p_is_revision_control => b_is_revision_control
4408 , p_is_lot_control => FALSE
4409 , p_is_serial_control => b_is_serial_control
4410 , p_revision => NVL(p_rev, NULL)
4411 , p_lot_number => NULL
4412 , p_subinventory_code => l_sub
4413 , p_locator_id => l_loc_id
4414 , p_primary_quantity => -l_mmtt_qty
4415 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4416 , x_qoh => l_qoh
4417 , x_rqoh => l_rqoh
4418 , x_qr => l_qr
4419 , x_qs => l_qs
4420 , x_att => l_att
4421 , x_atr => l_atr
4422 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
4423 , p_transfer_subinventory_code => l_xfr_sub_code
4424 );
4425
4426 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4427 IF (l_debug = 1) THEN
4428 mydebug('lpn_match: update qty tree without lpn 4th time:l_att:' || l_att);
4429 END IF;
4430 ELSE
4431 IF (l_debug = 1) THEN
4432 mydebug('lpn_match: calling update qty tree without lpn 4th time failed ');
4433 END IF;
4434
4435 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4436 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4437 fnd_msg_pub.ADD;
4438 RAISE fnd_api.g_exc_error;
4439 END IF;
4440 END IF;
4441
4442 inv_quantity_tree_pub.query_quantities(
4443 p_api_version_number => 1.0
4444 , p_init_msg_lst => fnd_api.g_false
4445 , x_return_status => l_return_status
4446 , x_msg_count => l_msg_cnt
4447 , x_msg_data => l_msg_data
4448 , p_organization_id => p_org_id
4449 , p_inventory_item_id => p_item_id
4450 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode --??
4451 , p_is_revision_control => b_is_revision_control
4452 , p_is_lot_control => FALSE
4453 , p_is_serial_control => b_is_serial_control
4454 , p_demand_source_type_id => -9999
4455 , p_revision => NVL(p_rev, NULL)
4456 , p_lot_number => NULL
4457 , p_subinventory_code => l_sub
4458 , p_locator_id => l_loc_id
4459 , x_qoh => l_qoh
4460 , x_rqoh => l_rqoh
4461 , x_qr => l_qr
4462 , x_qs => l_qs
4463 , x_att => l_att
4464 , x_atr => l_atr
4465 , p_lpn_id => p_lpn
4466 , p_transfer_subinventory_code => l_xfr_sub_code
4467 );
4468
4469 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4470 IF (l_debug = 1) THEN
4471 mydebug('lpn_match: lpn quantity ATT= ' || l_att);
4472 mydebug('lpn_match: lpn quantity QOH= ' || l_qoh);
4473 END IF;
4474 x_lpn_qty := l_qoh; --Added bug 3946813
4475
4476 IF l_mmtt_qty = l_att THEN
4477 IF l_qoh = l_att THEN
4478 -- LPN is a match!
4479 IF (l_debug = 1) THEN
4480 mydebug('lpn_match: LPN matched');
4481 END IF;
4482
4483 x_match := 1;
4484 ELSE
4485 -- LPN is for multiple task
4486 IF (l_debug = 1) THEN
4487 mydebug('lpn_match: LPN has multiple task.');
4488 END IF;
4489
4490 x_match := 4;
4491 END IF;
4492 ELSIF l_mmtt_qty > l_att THEN
4493 IF l_qoh = l_att THEN
4494 IF (l_debug = 1) THEN
4495 mydebug('lpn_match: lpn has less requested qty and lpn is whole allocation');
4496 END IF;
4497
4498 x_match := 3;
4499 ELSE
4500 IF (l_debug = 1) THEN
4501 mydebug('lpn_match: lpn has less than requested qty and lpn is partial allocation');
4502 END IF;
4503
4504 x_match := 4;
4505 END IF;
4506
4507 l_lpn_qty := l_att;
4508 ELSE
4509 x_match := 4;
4510 END IF;
4511 ELSE
4512 IF (l_debug = 1) THEN
4513 mydebug('lpn_match: calling qty tree 4th time failed');
4514 END IF;
4515
4516 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4517 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4518 fnd_msg_pub.ADD;
4519 RAISE fnd_api.g_exc_error;
4520 END IF;
4521
4522 IF NVL(l_allocated_lpn_id, 0) = p_lpn THEN
4523 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
4524 -- in order to get correct att.
4525 inv_quantity_tree_pub.update_quantities(
4526 p_api_version_number => 1.0
4527 , p_init_msg_lst => fnd_api.g_false
4528 , x_return_status => l_return_status
4529 , x_msg_count => l_msg_cnt
4530 , x_msg_data => l_msg_data
4531 , p_organization_id => p_org_id
4532 , p_inventory_item_id => p_item_id
4533 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4534 , p_is_revision_control => b_is_revision_control
4535 , p_is_lot_control => FALSE
4536 , p_is_serial_control => b_is_serial_control
4537 , p_revision => NVL(p_rev, NULL)
4538 , p_lot_number => NULL
4539 , p_subinventory_code => l_sub
4540 , p_locator_id => l_loc_id
4541 , p_primary_quantity => l_mmtt_qty
4542 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4543 , x_qoh => l_qoh
4544 , x_rqoh => l_rqoh
4545 , x_qr => l_qr
4546 , x_qs => l_qs
4547 , x_att => l_att
4548 , x_atr => l_atr
4549 , p_lpn_id => p_lpn
4550 , p_transfer_subinventory_code => l_xfr_sub_code
4551 );
4552
4553 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4554 IF (l_debug = 1) THEN
4555 mydebug('lpn_match: update qty tree back with lpn 4th time: l_att:' || l_att);
4556 END IF;
4557 ELSE
4558 IF (l_debug = 1) THEN
4559 mydebug('lpn_match: calling update qty tree back with lpn 4th time failed ');
4560 END IF;
4561
4562 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4563 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4564 fnd_msg_pub.ADD;
4565 RAISE fnd_api.g_exc_error;
4566 END IF;
4567 ELSE
4568 inv_quantity_tree_pub.update_quantities(
4569 p_api_version_number => 1.0
4570 , p_init_msg_lst => fnd_api.g_false
4571 , x_return_status => l_return_status
4572 , x_msg_count => l_msg_cnt
4573 , x_msg_data => l_msg_data
4574 , p_organization_id => p_org_id
4575 , p_inventory_item_id => p_item_id
4576 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
4577 , p_is_revision_control => b_is_revision_control
4578 , p_is_lot_control => FALSE
4579 , p_is_serial_control => b_is_serial_control
4580 , p_revision => NVL(p_rev, NULL)
4581 , p_lot_number => NULL
4582 , p_subinventory_code => l_sub
4583 , p_locator_id => l_loc_id
4584 , p_primary_quantity => l_mmtt_qty
4585 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4586 , x_qoh => l_qoh
4587 , x_rqoh => l_rqoh
4588 , x_qr => l_qr
4589 , x_qs => l_qs
4590 , x_att => l_att
4591 , x_atr => l_atr
4592 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
4593 , p_transfer_subinventory_code => l_xfr_sub_code
4594 );
4595
4596 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
4597 IF (l_debug = 1) THEN
4598 mydebug('lpn_match: update qty tree back without lpn 4th time:l_att:' || l_att);
4599 END IF;
4600 ELSE
4601 IF (l_debug = 1) THEN
4602 mydebug('lpn_match: calling update qty tree back without lpn 4th time failed ');
4603 END IF;
4604
4605 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
4606 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
4607 fnd_msg_pub.ADD;
4608 RAISE fnd_api.g_exc_error;
4609 END IF;
4610 END IF;
4611
4612 -- If the LPN quantity exactly matches/ has less than, the requested
4613 -- quantity then match the serial numbers also
4614
4615 IF p_is_sn_alloc = 'Y'
4616 AND p_action = 4
4617 AND(x_match = 1
4618 OR x_match = 3) THEN
4619 SELECT COUNT(fm_serial_number)
4620 INTO l_total_serial_cnt
4621 FROM mtl_serial_numbers_temp msnt
4622 WHERE msnt.transaction_temp_id = p_temp_id;
4623
4624 IF (l_debug = 1) THEN
4625 mydebug('lpn_match: SN tot count' || l_total_serial_cnt);
4626 END IF;
4627
4628 IF (l_total_serial_cnt = l_serial_exist_cnt) THEN
4629 IF (l_debug = 1) THEN
4630 mydebug('lpn_match: LPN matches exactly');
4631 END IF;
4632
4633 x_match := 1;
4634 ELSIF(l_total_serial_cnt > l_serial_exist_cnt) THEN
4635 IF (l_debug = 1) THEN
4636 mydebug('lpn_match: LPN has less');
4637 END IF;
4638
4639 x_match := 3;
4640 l_lpn_qty := l_serial_exist_cnt;
4641 ELSE
4642 IF (l_debug = 1) THEN
4643 mydebug('lpn_match: LPN has extra serials');
4644 END IF;
4645
4646 x_match := 4;
4647 END IF;
4648 END IF;
4649
4650 IF (l_debug = 1) THEN
4651 mydebug('lpn_match: After 4');
4652 END IF;
4653 END IF; -- lot control check
4654 END IF; -- lpn has only one item
4655
4656 IF x_match = 1
4657 OR x_match = 3 THEN
4658 IF p_action = 4 THEN
4659 -- serial controlled - CHECK serial status
4660 IF (l_debug = 1) THEN
4661 mydebug('lpn_match: x_match is ' || x_match || ' and item is serial controlled ');
4662 END IF;
4663
4664 OPEN ser_csr;
4665
4666 LOOP
4667 FETCH ser_csr INTO l_serial_number;
4668 EXIT WHEN ser_csr%NOTFOUND;
4669
4670 IF inv_material_status_grp.is_status_applicable(
4671 p_wms_installed => p_wms_installed
4672 , p_trx_status_enabled => NULL
4673 , p_trx_type_id => p_transaction_type_id
4674 , p_lot_status_enabled => NULL
4675 , p_serial_status_enabled => NULL
4676 , p_organization_id => p_org_id
4677 , p_inventory_item_id => p_item_id
4678 , p_sub_code => x_sub
4679 , p_locator_id => NULL
4680 , p_lot_number => p_lot
4681 , p_serial_number => l_serial_number
4682 , p_object_type => 'A'
4683 ) = 'N' THEN
4684 IF (l_debug = 1) THEN
4685 mydebug('lpn_match: After 6');
4686 END IF;
4687
4688 x_match := 11;
4689 CLOSE ser_csr;
4690 fnd_message.set_name('INV', 'INV_SER_STATUS_NA');
4691 fnd_message.set_token('TOKEN', l_serial_number);
4692 fnd_msg_pub.ADD;
4693 RAISE fnd_api.g_exc_error;
4694 END IF;
4695 END LOOP;
4696
4697 CLOSE ser_csr;
4698 ELSE
4699 l_serial_number := NULL;
4700
4701 -- Check whether the LPN status is applicable for this transaction
4702 IF inv_material_status_grp.is_status_applicable(
4703 p_wms_installed => p_wms_installed
4704 , p_trx_status_enabled => NULL
4705 , p_trx_type_id => p_transaction_type_id
4706 , p_lot_status_enabled => NULL
4707 , p_serial_status_enabled => NULL
4708 , p_organization_id => p_org_id
4709 , p_inventory_item_id => p_item_id
4710 , p_sub_code => x_sub
4711 , p_locator_id => NULL
4712 , p_lot_number => p_lot
4713 , p_serial_number => l_serial_number
4714 , p_object_type => 'A'
4715 ) = 'N' THEN
4716 x_match := 8;
4717 -- LPN status is invalid for this operation
4718
4719 fnd_message.set_name('INV', 'INV_INVALID_LPN_STATUS');
4720 fnd_message.set_token('TOKEN1', TO_CHAR(p_lpn));
4721 fnd_msg_pub.ADD;
4722 RAISE fnd_api.g_exc_error;
4723 END IF;
4724 END IF;
4725 END IF;
4726
4727 IF (l_debug = 1) THEN
4728 mydebug('lpn_match: x_match : ' || x_match);
4729 mydebug('lpn_match: p_is_sn_alloc : ' || p_is_sn_alloc);
4730 mydebug('lpn_match: p_action : ' || p_action);
4731 END IF;
4732
4733 /*
4734 -- Check if Serial Numbers are allocated
4735 -- Why do you need p_action ?? Wouldn't p_is_sn_alloc suffice ??
4736
4737 IF (x_match = 1 OR x_match=3) AND p_is_sn_alloc = 'Y' AND p_action = 4 THEN
4738
4739 l_allocate_serial_flag := 0;
4740
4741 IF (l_debug = 1) THEN
4742 mydebug('lpn_match: Before calling SN allocation checking API');
4743 END IF;
4744 -- Check if serial numbers are allocated
4745
4746 OPEN ser_alloc;
4747 LOOP
4748
4749 EXIT WHEN ser_alloc%NOTFOUND;
4750
4751 l_temp_serial_trans_temp := 0;
4752
4753 FETCH ser_alloc INTO l_temp_serial_trans_temp;
4754
4755 IF l_temp_serial_trans_temp IS NOT NULL THEN
4756
4757 IF (l_debug = 1) THEN
4758 mydebug('lpn_match: l_temp_serial_trans_temp is not null');
4759 END IF;
4760 SELECT 1
4761 INTO l_allocate_serial_flag
4762 FROM mtl_serial_numbers_temp msnt,
4763 mtl_serial_numbers msn
4764 WHERE msnt.transaction_temp_id = l_temp_serial_trans_temp
4765 AND msn.serial_number = msnt.fm_serial_number
4766 AND msn.lpn_id = p_lpn
4767 AND ROWNUM = 1;
4768
4769 ELSE
4770
4771 IF (l_debug = 1) THEN
4772 mydebug('lpn_match: l_temp_serial_trans_temp is null');
4773 END IF;
4774 SELECT 1
4775 INTO l_allocate_serial_flag
4776 FROM mtl_material_transactions_temp mmtt,
4777 mtl_serial_numbers_temp msnt,
4778 mtl_serial_numbers msn
4779 WHERE mmtt.transaction_temp_id = p_temp_id
4780 AND mmtt.organization_id = p_org_id
4781 AND mmtt.inventory_item_id = p_item_id
4782 AND msnt.transaction_temp_id = mmtt.transaction_temp_id
4783 AND msn.serial_number = msnt.fm_serial_number
4784 AND msn.inventory_item_id = mmtt.inventory_item_id
4785 AND msn.lpn_id = p_lpn
4786 AND ROWNUM = 1;
4787
4788 END IF;
4789
4790 END LOOP;
4791 CLOSE ser_alloc;
4792
4793 -- Here we are not checking for the actual number
4794 -- of serials allocated against the requested quantity.
4795 -- Just existance of serials is checked.
4796
4797 IF l_allocate_serial_flag = 0 THEN
4798
4799 -- Serial records missing for this transaction
4800
4801 IF (l_debug = 1) THEN
4802 mydebug('lpn_match: Serial numbers should not be allocated');
4803 END IF;
4804 x_match := 9;
4805 FND_MESSAGE.SET_NAME('INV','INV_INT_SERMISEXP');
4806 FND_MSG_PUB.ADD;
4807 RAISE FND_API.G_EXC_ERROR;
4808
4809 END IF;
4810
4811 END IF;
4812 */
4813
4814 -- Call multiple_pick only for lot and serial items. For plain items, it
4815 -- will anyways be called during load_pick
4816 IF x_match = 1
4817 AND(l_lot_code > 1
4818 OR(p_is_sn_alloc = 'Y'
4819 AND p_action = 4)) THEN
4820 IF (l_debug = 1) THEN
4821 mydebug('lpn_match: MMTT lines need to be split..');
4822 mydebug('lpn_match: Calling multiple_pick API..');
4823 END IF;
4824
4825 /* moved to the begining
4826 IF p_is_sn_alloc = 'Y' AND p_action = 4 THEN
4827 l_is_serial_control := 'true';
4828 ELSE
4829 l_is_serial_control := 'false';
4830 END IF;
4831
4832 IF l_lot_code > 1 THEN
4833 l_is_lot_control := 'true';
4834 ELSE
4835 l_is_lot_control := 'false';
4836 END IF;
4837
4838 IF p_rev IS NULL THEN
4839 l_is_revision_control := 'false';
4840 ELSE
4841 l_is_revision_control := 'true';
4842 END IF;*/
4843 IF (l_debug = 1) THEN
4844 mydebug('lpn_match: just before multiple_pick');
4845 END IF;
4846
4847 wms_task_dispatch_gen.multiple_pick(
4848 p_pick_qty => p_qty
4849 , p_org_id => p_org_id
4850 , p_temp_id => p_temp_id
4851 , x_return_status => l_return_status
4852 , x_msg_count => x_msg_count
4853 , x_msg_data => x_msg_data
4854 , p_sn_allocated_flag => p_is_sn_alloc
4855 , p_act_uom => p_uom
4856 , p_from_lpn => l_from_lpn
4857 , p_from_lpn_id => p_lpn
4858 , p_to_lpn => '-999'
4859 , p_ok_to_process => l_ok_to_process
4860 , p_is_revision_control => l_is_revision_control
4861 , p_is_lot_control => l_is_lot_control
4862 , p_is_serial_control => l_is_serial_control
4863 , p_act_rev => p_rev
4864 , p_lot => NULL
4865 , p_act_sub => l_sub
4866 , p_act_loc => l_loc_id
4867 , p_container_item_id => 0
4868 , p_entire_lpn => 'Y'
4869 , p_pick_qty_remaining => 0
4870 , x_temp_id => l_out_temp_id
4871 , p_serial_number => NULL
4872 );
4873
4874 IF (l_debug = 1) THEN
4875 mydebug('lpn_match: just after multiple_pick: ' || l_return_status);
4876 END IF;
4877
4878 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4879 IF (l_debug = 1) THEN
4880 mydebug('lpn_match: Unexpected error in call to multiple_pick');
4881 END IF;
4882
4883 RAISE fnd_api.g_exc_unexpected_error;
4884 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
4885 IF (l_debug = 1) THEN
4886 mydebug('lpn_match: Error in call to multiple_pick');
4887 END IF;
4888
4889 RAISE fnd_api.g_exc_error;
4890 END IF;
4891 END IF;
4892
4893 IF x_match = 3 THEN
4894 IF (l_debug = 1) THEN
4895 mydebug('lpn_match: MMTT lines need to be split..');
4896 mydebug('lpn_match: Calling multiple lpn picking..');
4897 END IF;
4898
4899 wms_task_dispatch_gen.multiple_lpn_pick(
4900 p_lpn_id => p_lpn
4901 , p_lpn_qty => l_lpn_qty
4902 , p_org_id => p_org_id
4903 , p_temp_id => p_temp_id
4904 , x_temp_id => l_out_temp_id
4905 , x_return_status => l_return_status
4906 , x_msg_count => l_msg_cnt
4907 , x_msg_data => l_msg_data
4908 , p_sn_allocated_flag => p_is_sn_alloc
4909 , p_uom_code => p_uom
4910 , p_to_lpn_id => p_lpn
4911 , p_entire_lpn => 'Y'
4912 );
4913
4914 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4915 fnd_message.set_name('WMS', 'WMS_MULT_LPN_ERROR');
4916 fnd_msg_pub.ADD;
4917 RAISE fnd_api.g_exc_unexpected_error;
4918 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
4919 fnd_message.set_name('WMS', 'WMS_MULT_LPN_ERROR');
4920 fnd_msg_pub.ADD;
4921 RAISE fnd_api.g_exc_error;
4922 END IF;
4923
4924 IF (l_debug = 1) THEN
4925 mydebug('lpn_match: AFTER Calling multiple lpn picking..');
4926 END IF;
4927 END IF;
4928
4929 /*IF nvl(l_allocated_lpn_id, 0) = p_lpn THEN
4930 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
4931 -- in order to get correct att.
4932 inv_quantity_tree_pub.update_quantities
4933 ( p_api_version_number => 1.0
4934 , p_init_msg_lst => fnd_api.g_false
4935 , x_return_status => l_return_status
4936 , x_msg_count => l_msg_cnt
4937 , x_msg_data => l_msg_data
4938 , p_organization_id => p_org_id
4939 , p_inventory_item_id => p_item_id
4940 , p_tree_mode => INV_Quantity_Tree_PUB.g_transaction_mode
4941 , p_is_revision_control => b_is_revision_control
4942 , p_is_lot_control => b_is_lot_control
4943 , p_is_serial_control => b_is_serial_control
4944 --, p_demand_source_type_id => NULL
4945 , p_revision => p_rev
4946 , p_lot_number => p_lot
4947 , p_subinventory_code => l_sub
4948 , p_locator_id => l_loc_id
4949 , p_primary_quantity => p_qty
4950 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4951 , x_qoh => l_qoh
4952 , x_rqoh => l_rqoh
4953 , x_qr => l_qr
4954 , x_qs => l_qs
4955 , x_att => l_att
4956 , x_atr => l_atr
4957 , p_lpn_id => p_lpn
4958 , p_transfer_subinventory_code => l_xfr_sub_code
4959 );
4960 ELSE
4961 inv_quantity_tree_pub.update_quantities
4962 ( p_api_version_number => 1.0
4963 , p_init_msg_lst => fnd_api.g_false
4964 , x_return_status => l_return_status
4965 , x_msg_count => l_msg_cnt
4966 , x_msg_data => l_msg_data
4967 , p_organization_id => p_org_id
4968 , p_inventory_item_id => p_item_id
4969 , p_tree_mode => INV_Quantity_Tree_PUB.g_transaction_mode
4970 , p_is_revision_control => b_is_revision_control
4971 , p_is_lot_control => b_is_lot_control
4972 , p_is_serial_control => b_is_serial_control
4973 --, p_demand_source_type_id => NULL
4974 , p_revision => p_rev
4975 , p_lot_number => p_lot
4976 , p_subinventory_code => l_sub
4977 , p_locator_id => l_loc_id
4978 , p_primary_quantity => p_qty
4979 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
4980 , x_qoh => l_qoh
4981 , x_rqoh => l_rqoh
4982 , x_qr => l_qr
4983 , x_qs => l_qs
4984 , x_att => l_att
4985 , x_atr => l_atr
4986 -- , p_lpn_id => p_lpn withour lpn_id, only to locator level
4987 , p_transfer_subinventory_code => l_xfr_sub_code
4988 );
4989 END IF;*/
4990 l_table_total := t_lpn_lot_qty_table.COUNT;
4991
4992 IF l_table_total > 0 THEN
4993 IF (l_debug = 1) THEN
4994 mydebug('lpn_match: building lpn lot vector for ' || l_table_total || ' records');
4995 END IF;
4996
4997 FOR l_table_count IN 1 .. l_table_total LOOP
4998 IF (l_debug = 1) THEN
4999 mydebug('lpn_match: index is : ' || l_table_count);
5000 END IF;
5001
5002 x_lpn_lot_vector :=
5003 x_lpn_lot_vector || t_lpn_lot_qty_table(l_table_count).lot_number || '@@@@@' || t_lpn_lot_qty_table(l_table_count).qty
5004 || '&&&&&';
5005 END LOOP;
5006 ELSE
5007 x_lpn_lot_vector := NULL;
5008 END IF;
5009
5010 IF (l_debug = 1) THEN
5011 mydebug('lpn_match: LPN QTY ' || l_lpn_qty);
5012 mydebug('lpn_match: x_temp_id: ' || l_out_temp_id);
5013 END IF;
5014
5015 x_temp_id := l_out_temp_id;
5016 x_qty := LEAST(l_lpn_qty, p_qty);
5017 x_return_status := fnd_api.g_ret_sts_success;
5018
5019 IF (l_debug = 1) THEN
5020 mydebug('lpn_match: Match ' || x_match);
5021 END IF;
5022
5023 -- added following for bug fix 2769358
5024
5025 IF x_match = 3 THEN
5026 IF (l_debug = 1) THEN
5027 mydebug('Set lpn context to packing for lpn_ID : ' || p_lpn);
5028 END IF;
5029
5030 -- Bug5659809: update last_update_date and last_update_by as well
5031 UPDATE wms_license_plate_numbers
5032 SET lpn_context = wms_container_pub.lpn_context_packing
5033 , last_update_date = SYSDATE
5034 , last_updated_by = fnd_global.user_id
5035 WHERE lpn_id = p_lpn;
5036 END IF;
5037 -- end 2769358
5038
5039 EXCEPTION
5040 WHEN fnd_api.g_exc_error THEN
5041 IF (l_debug = 1) THEN
5042 mydebug('lpn_match: Exception raised');
5043 END IF;
5044
5045 x_return_status := fnd_api.g_ret_sts_error;
5046 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5047 WHEN OTHERS THEN
5048 IF (l_debug = 1) THEN
5049 mydebug('lpn_match: Other exception raised : ' || SQLERRM);
5050 END IF;
5051
5052 x_return_status := fnd_api.g_ret_sts_unexp_error;
5053 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5054 END lpn_match;
5055
5056 FUNCTION can_pickdrop(txn_temp_id IN NUMBER) RETURN VARCHAR2 IS
5057 l_ret VARCHAR2(1) := 'X';
5058 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5059 CURSOR c_cancelled_tasks IS
5060 SELECT decode(mmtt.transaction_type_id, 35,'N',51,'N','Y')
5061 FROM mtl_material_transactions_temp mmtt, mtl_txn_request_lines mol
5062 WHERE (mmtt.transaction_temp_id = txn_temp_id OR mmtt.parent_line_id = txn_temp_id)
5063 AND mmtt.move_order_line_id = mol.line_id
5064 AND mol.line_status = inv_globals.g_to_status_cancel_by_source
5065 AND ROWNUM = 1;
5066 BEGIN
5067 IF (l_debug = 1) THEN
5068 mydebug('In CAN_PICKDROP for Transaction Temp ID = ' || txn_temp_id);
5069 END IF;
5070
5071 OPEN c_cancelled_tasks;
5072 FETCH c_cancelled_tasks INTO l_ret;
5073 IF c_cancelled_tasks%NOTFOUND THEN
5074 IF l_debug = 1 THEN
5075 mydebug('Found no Cancelled Task');
5076 END IF;
5077 RETURN 'X';
5078 ELSE
5079 IF l_debug = 1 THEN
5080 mydebug('Found Cancelled Tasks');
5081 END IF;
5082 RETURN l_ret;
5083 END IF;
5084 CLOSE c_cancelled_tasks;
5085 END;
5086
5087 PROCEDURE load_pick(
5088 p_to_lpn IN VARCHAR2
5089 , p_container_item_id IN NUMBER
5090 , p_org_id IN NUMBER
5091 , p_temp_id IN NUMBER
5092 , p_from_lpn IN VARCHAR2
5093 , p_from_lpn_id IN NUMBER
5094 , p_act_sub IN VARCHAR2
5095 , p_act_loc IN NUMBER
5096 , p_entire_lpn IN VARCHAR2
5097 , x_return_status OUT NOCOPY VARCHAR2
5098 , x_msg_count OUT NOCOPY NUMBER
5099 , x_msg_data OUT NOCOPY VARCHAR2
5100 , p_loc_rsn_id IN NUMBER
5101 , p_qty_rsn_id IN NUMBER
5102 , p_sn_allocated_flag IN VARCHAR2
5103 , p_task_id IN NUMBER
5104 , p_user_id IN NUMBER
5105 , p_qty IN NUMBER
5106 , p_qty_uom IN VARCHAR2
5107 , p_is_revision_control IN VARCHAR2
5108 , p_is_lot_control IN VARCHAR2
5109 , p_is_serial_control IN VARCHAR2
5110 , p_item_id IN NUMBER
5111 , p_act_rev IN VARCHAR2
5112 , p_lot IN VARCHAR2
5113 , p_ok_to_process OUT NOCOPY VARCHAR2
5114 , p_pick_qty_remaining IN NUMBER
5115 , x_temp_id OUT NOCOPY NUMBER
5116 , p_lots_to_delete IN VARCHAR2
5117 , p_mmtt_to_update IN VARCHAR2
5118 , p_serial_number IN VARCHAR2
5119 , x_out_lpn OUT NOCOPY NUMBER
5120 ) IS
5121 l_temp_id NUMBER;
5122 l_msg_cnt NUMBER;
5123 l_msg_data VARCHAR2(2000);
5124 l_return_status VARCHAR2(240);
5125 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
5126 l_lot VARCHAR2(80);
5127 l_item_id NUMBER;
5128 l_user_id NUMBER;
5129 l_to_sub VARCHAR2(10);
5130 l_to_loc NUMBER;
5131 l_txn_hdr_id NUMBER;
5132 l_new_txn_hdr_id NUMBER;
5133 l_qty_picked NUMBER;
5134 l_qty_uom VARCHAR2(3);
5135 l_wf NUMBER := 0;
5136 l_tabtype inv_utilities.vector_tabtype;
5137 l_counter NUMBER;
5138 l_transfer_lpn_id NUMBER;
5139 l_content_lpn_id NUMBER;
5140 l_lpn_id NUMBER;
5141 l_to_lpn_id NUMBER;
5142 l_to_lpn_exists NUMBER;
5143 l_label_status VARCHAR2(300);
5144 l_content_parent_lpn_id NUMBER;
5145
5146 CURSOR mmtt_csr IS
5147 SELECT mmtt2.transaction_temp_id
5148 , mmtt1.transaction_uom
5149 , mmtt2.transaction_uom
5150 , mmtt2.transaction_quantity
5151 , mmtt2.primary_quantity
5152 FROM mtl_material_transactions_temp mmtt1, mtl_material_transactions_temp mmtt2
5153 WHERE mmtt1.transaction_temp_id = p_temp_id
5154 AND mmtt1.transaction_header_id = l_txn_hdr_id
5155 AND mmtt1.organization_id = p_org_id
5156 AND mmtt2.transaction_header_id = mmtt1.transaction_header_id
5157 AND mmtt2.organization_id = mmtt1.organization_id
5158 AND mmtt2.transaction_temp_id <> mmtt1.transaction_temp_id
5159 AND mmtt2.move_order_line_id = mmtt1.move_order_line_id
5160 AND NVL(mmtt2.reservation_id, 0) = NVL(mmtt1.reservation_id, 0)
5161 AND mmtt2.inventory_item_id = mmtt1.inventory_item_id
5162 AND mmtt2.subinventory_code = mmtt1.subinventory_code
5163 AND mmtt2.locator_id = mmtt1.locator_id
5164 AND NVL(mmtt2.transfer_lpn_id, 0) = NVL(mmtt1.transfer_lpn_id, 0)
5165 AND NVL(mmtt2.content_lpn_id, 0) = NVL(mmtt1.content_lpn_id, 0)
5166 AND NVL(mmtt2.lpn_id, 0) = NVL(mmtt1.lpn_id, 0);
5167
5168 l_mmtt2_txn_temp_id NUMBER;
5169 l_mmtt1_txn_uom VARCHAR2(10);
5170 l_mmtt2_txn_uom VARCHAR2(10);
5171 l_mmtt2_txn_qty NUMBER;
5172 l_mmtt2_primary_qty NUMBER;
5173 l_business_flow_code NUMBER;
5174 l_tran_type_id NUMBER;
5175 l_tran_source_type_id NUMBER;
5176 l_to_lpn_context NUMBER := wms_container_pub.lpn_context_packing;
5177 l_loaded NUMBER := 0;
5178
5179 CURSOR mmtt_csr2(p_transaction_header_id NUMBER) IS
5180 SELECT mmtt.transaction_temp_id
5181 FROM mtl_material_transactions_temp mmtt
5182 WHERE mmtt.transaction_header_id = p_transaction_header_id;
5183
5184
5185 l_move_order_line_id NUMBER; --Bug2924823 H to I
5186 l_mmtt_transaction_uom VARCHAR(3);
5187 l_transaction_qty NUMBER;
5188 --l_reservation_id NUMBER;
5189 l_mol_uom VARCHAR2(3);
5190 l_mol_delta_qty NUMBER;
5191 l_primary_qty NUMBER;
5192 --l_detailed_quantity NUMBER;
5193 l_debug NUMBER :=NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'),0);
5194 l_bulk_pick_flag NUMBER := 0;
5195 BEGIN
5196 l_return_status := fnd_api.g_ret_sts_success;
5197 x_return_status := l_return_status;
5198
5199 mydebug('load_pick : Entered Load Pick');
5200 l_qty_picked := p_qty;
5201 l_qty_uom := p_qty_uom;
5202 l_lot := p_lot;
5203 l_item_id := p_item_id;
5204 l_user_id := p_user_id;
5205 -- Initialize p_ok_to_process to TRUE
5206 p_ok_to_process := 'true';
5207 l_to_lpn_exists := 0;
5208
5209 SELECT transfer_subinventory
5210 , transfer_to_location
5211 INTO l_to_sub
5212 , l_to_loc
5213 FROM mtl_material_transactions_temp
5214 WHERE transaction_temp_id = p_temp_id;
5215
5216 BEGIN
5217 SELECT 1
5218 INTO l_to_lpn_exists
5219 FROM wms_license_plate_numbers
5220 WHERE license_plate_number = p_to_lpn
5221 AND organization_id = p_org_id;
5222 EXCEPTION
5223 WHEN NO_DATA_FOUND THEN
5224 l_to_lpn_exists := 0;
5225 END;
5226
5227 IF (l_debug = 1) THEN
5228 mydebug('load_pick: l_to_lpn_exists : ' || l_to_lpn_exists);
5229 END IF;
5230
5231 IF (l_to_lpn_exists = 0) THEN
5232 -- LPN does not exist, create it
5233 -- Call Suresh's Create LPN API
5234 IF (l_debug = 1) THEN
5235 mydebug('load_pick: Creating LPN. LPN does not exist');
5236 END IF;
5237
5238 wms_container_pub.create_lpn(
5239 p_api_version => 1.0
5240 , p_init_msg_list => fnd_api.g_false
5241 , p_commit => fnd_api.g_false
5242 , x_return_status => l_return_status
5243 , x_msg_count => l_msg_cnt
5244 , x_msg_data => l_msg_data
5245 , p_lpn => p_to_lpn
5246 , p_organization_id => p_org_id
5247 , p_container_item_id => 0
5248 , p_lot_number => l_lot
5249 , p_revision => p_act_rev
5250 , p_serial_number => p_serial_number
5251 , p_subinventory => l_to_sub
5252 , p_locator_id => l_to_loc
5253 , p_source => 8
5254 , p_cost_group_id => NULL
5255 , x_lpn_id => l_to_lpn_id
5256 );
5257 fnd_msg_pub.count_and_get(p_count => l_msg_cnt, p_data => l_msg_data);
5258
5259 IF (l_msg_cnt = 0) THEN
5260 IF (l_debug = 1) THEN
5261 mydebug('load_pick: Successful');
5262 END IF;
5263 ELSIF(l_msg_cnt = 1) THEN
5264 IF (l_debug = 1) THEN
5265 mydebug('load_pick: Not Successful');
5266 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
5267 END IF;
5268 ELSE
5269 IF (l_debug = 1) THEN
5270 mydebug('load_pick: Not Successful2');
5271 END IF;
5272
5273 FOR i IN 1 .. l_msg_cnt LOOP
5274 l_msg_data := fnd_msg_pub.get(i, 'F');
5275
5276 IF (l_debug = 1) THEN
5277 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
5278 END IF;
5279 END LOOP;
5280 END IF;
5281
5282 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5283 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
5284 fnd_msg_pub.ADD;
5285 RAISE fnd_api.g_exc_unexpected_error;
5286 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5287 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
5288 fnd_msg_pub.ADD;
5289 RAISE fnd_api.g_exc_error;
5290 END IF;
5291 ELSE
5292 IF (l_debug = 1) THEN
5293 mydebug('load_pick: LPN exists');
5294 END IF;
5295
5296 --Check whether the from LPN is loaded already
5297 --bug 2803936 We should only do the
5298 --loaded check if entire LPN was picked. Also, we should discount
5299 -- current temp id
5300
5301 IF p_entire_lpn = 'Y' THEN -- bug 2803936
5302
5303 --Check whether the from LPN is loaded already
5304 BEGIN
5305 SELECT 0
5306 INTO l_loaded
5307 FROM DUAL
5308 WHERE NOT EXISTS(SELECT 1
5309 FROM mtl_material_transactions_temp
5310 WHERE content_lpn_id = p_from_lpn_id
5311 AND transaction_temp_id<>p_temp_id);
5312
5313 IF (l_debug = 1) THEN
5314 mydebug('load_pick: LPN ' || p_from_lpn_id || ' hasnot been loaded already');
5315 END IF;
5316 EXCEPTION
5317 WHEN OTHERS THEN
5318 l_loaded := 1;
5319
5320 IF (l_debug = 1) THEN
5321 mydebug('load_pick: LPN ' || p_from_lpn_id || ' has been already loaded so error out');
5322 END IF;
5323
5324 fnd_message.set_name('WMS', 'WMS_LPN_LOADED_ERROR');
5325 fnd_msg_pub.ADD;
5326 RAISE fnd_api.g_exc_error;
5327 END;
5328 END IF;
5329
5330 -- LPN exists. Get LPN ID
5331 SELECT lpn_id
5332 , lpn_context
5333 INTO l_to_lpn_id
5334 , l_to_lpn_context
5335 FROM wms_license_plate_numbers
5336 WHERE license_plate_number = p_to_lpn
5337 AND organization_id = p_org_id;
5338 END IF;
5339
5340 x_out_lpn := l_to_lpn_id;
5341
5342 -- Removed following check for bug 2769358
5343 -- IF l_to_lpn_context = wms_container_pub.lpn_context_pregenerated THEN
5344 --
5345 -- Update the context to "Packing context" (8)
5346 --
5347 -- Bug5659809: update last_update_date and last_update_by as well
5348 UPDATE wms_license_plate_numbers
5349 SET lpn_context = wms_container_pub.lpn_context_packing
5350 , last_update_date = SYSDATE
5351 , last_updated_by = fnd_global.user_id
5352 WHERE lpn_id = l_to_lpn_id;
5353 -- END IF;
5354
5355 IF p_is_lot_control = 'true'
5356 OR p_is_serial_control = 'true' THEN
5357 IF (l_debug = 1) THEN
5358 mydebug('load_pick : Either lot or serial control. Will not call multiple_pick');
5359 END IF;
5360
5361 x_temp_id := p_temp_id;
5362 inv_utilities.parse_vector(vector_in => p_mmtt_to_update, delimiter => ':', table_of_strings => l_tabtype);
5363
5364 FOR l_counter IN 0 ..(l_tabtype.COUNT - 1) LOOP
5365 IF (l_debug = 1) THEN
5366 mydebug('load_pick : MMTT about to update' || l_tabtype(l_counter) || ':');
5367 END IF;
5368
5369 IF p_from_lpn_id <> 0 THEN
5370 IF p_entire_lpn = 'Y' THEN
5371 IF (l_debug = 1) THEN
5372 mydebug('load_pick : Entire LPN');
5373 END IF;
5374
5375 l_transfer_lpn_id := l_to_lpn_id;
5376 l_lpn_id := NULL;
5377 l_content_lpn_id := p_from_lpn_id;
5378
5379 -- for nested LPNs selected for picking items from:start
5380 IF (l_debug = 1) THEN
5381 mydebug('load_pick: getting outermost LPN for selected lpn ON PKLP');
5382 END IF;
5383
5384 SELECT parent_lpn_id
5385 INTO l_content_parent_lpn_id
5386 FROM wms_license_plate_numbers
5387 WHERE lpn_id = p_from_lpn_id
5388 AND organization_id = p_org_id;
5389
5390 IF (l_debug = 1) THEN
5391 mydebug('load_pick: outermost LPN for the selected LPN::' || l_content_parent_lpn_id);
5392 END IF;
5393
5394 IF (l_content_parent_lpn_id <> p_from_lpn_id) THEN
5395 IF (l_debug = 1) THEN
5396 mydebug('load_pick: setting lpn_id in MMTT to outermost LPN for nested LPN from PKLP');
5397 END IF;
5398
5399 l_lpn_id := l_content_parent_lpn_id; --TM will take care of this
5400 END IF;
5401 -- for nested LPNs selected for picking items from:ends
5402
5403 ELSE
5404 IF (l_debug = 1) THEN
5405 mydebug('load_pick : Partial LPN');
5406 END IF;
5407
5408 l_transfer_lpn_id := l_to_lpn_id;
5409 l_content_lpn_id := NULL;
5410 l_lpn_id := p_from_lpn_id;
5411 END IF;
5412 ELSE
5413 IF (l_debug = 1) THEN
5414 mydebug('load_pick : Picked loose');
5415 END IF;
5416
5417 l_transfer_lpn_id := l_to_lpn_id;
5418 l_content_lpn_id := NULL;
5419 l_lpn_id := NULL;
5420 END IF;
5421
5422 IF (l_debug = 1) THEN
5423 mydebug('load_pick : transfer_lpn_id :' || l_transfer_lpn_id);
5424 mydebug('load_pick : lpn_id :' || l_lpn_id);
5425 mydebug('load_pick : content_lpn_id :' || l_content_lpn_id);
5426 END IF;
5427
5428 -- added following for bug fix 2769358
5429
5430 IF l_content_lpn_id IS NOT NULL THEN
5431 IF (l_debug = 1) THEN
5432 mydebug('Set lpn context to packing for lpn_ID : ' || l_content_lpn_id);
5433 END IF;
5434
5435 -- Bug5659809: update last_update_date and last_update_by as well
5436 UPDATE wms_license_plate_numbers
5437 SET lpn_context = wms_container_pub.lpn_context_packing
5438 , last_update_date = SYSDATE
5439 , last_updated_by = fnd_global.user_id
5440 WHERE lpn_id = l_content_lpn_id;
5441 END IF;
5442
5443 -- end bug fix 2769358
5444
5445 UPDATE mtl_material_transactions_temp
5446 SET transfer_lpn_id = l_transfer_lpn_id
5447 , content_lpn_id = l_content_lpn_id
5448 , lpn_id = l_lpn_id
5449 WHERE transaction_temp_id = l_tabtype(l_counter);
5450
5451 -- Also update WDT to loaded status
5452
5453 UPDATE wms_dispatched_tasks
5454 SET status = 4
5455 , loaded_time = SYSDATE
5456 , --loaded_time=to_date(to_char(sysdate,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH:MI:SS'),
5457 last_update_date = SYSDATE
5458 , last_updated_by = l_user_id
5459 WHERE transaction_temp_id = l_tabtype(l_counter);
5460 END LOOP;
5461 ELSE
5462 IF (l_qty_picked = 0) THEN
5463 IF (l_debug = 1) THEN
5464 mydebug('load_pick :Picked qty is 0, doesnot need to call multiple_pick');
5465 END IF;
5466
5467 x_temp_id := p_temp_id;
5468 p_ok_to_process := 'true';
5469 ELSE
5470 IF (l_debug = 1) THEN
5471 mydebug('load_pick : Neither lot nor serial control. Calling multiple_pick');
5472 END IF;
5473
5474 wms_task_dispatch_gen.multiple_pick(
5475 p_pick_qty => l_qty_picked
5476 , p_org_id => p_org_id
5477 , p_temp_id => p_temp_id
5478 , x_return_status => l_return_status
5479 , x_msg_count => x_msg_count
5480 , x_msg_data => x_msg_data
5481 , p_sn_allocated_flag => p_sn_allocated_flag
5482 , p_act_uom => p_qty_uom
5483 , p_from_lpn => p_from_lpn
5484 , p_from_lpn_id => p_from_lpn_id
5485 , p_to_lpn => p_to_lpn
5486 , p_ok_to_process => p_ok_to_process
5487 , p_is_revision_control => p_is_revision_control
5488 , p_is_lot_control => p_is_lot_control
5489 , p_is_serial_control => p_is_serial_control
5490 , p_act_rev => p_act_rev
5491 , p_lot => p_lot
5492 , p_act_sub => p_act_sub
5493 , p_act_loc => p_act_loc
5494 , p_container_item_id => p_container_item_id
5495 , p_entire_lpn => p_entire_lpn
5496 , p_pick_qty_remaining => p_pick_qty_remaining
5497 , x_temp_id => x_temp_id
5498 , p_serial_number => p_serial_number
5499 );
5500
5501 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5502 RAISE fnd_api.g_exc_unexpected_error;
5503 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5504 RAISE fnd_api.g_exc_error;
5505 END IF;
5506 END IF;
5507 END IF;
5508
5509 IF p_ok_to_process = 'false' THEN
5510 x_temp_id := 0;
5511 RETURN;
5512 END IF;
5513
5514 IF (l_debug = 1) THEN
5515 mydebug('Load_Pick:user id before' || l_user_id);
5516 END IF;
5517
5518 SELECT transaction_header_id
5519 , --last_updated_by,Bug 2672785:Wrong value being fetched for user_id
5520 inventory_item_id
5521 , lot_number
5522 , transaction_type_id
5523 , transaction_source_type_id
5524 INTO l_txn_hdr_id
5525 , --l_user_id,
5526 l_item_id
5527 , l_lot
5528 , l_tran_type_id
5529 , l_tran_source_type_id
5530 FROM mtl_material_transactions_temp
5531 WHERE transaction_temp_id = x_temp_id;
5532
5533 IF (l_debug = 1) THEN
5534 mydebug('load_pick : Transaction_temp_id : ' || x_temp_id);
5535 mydebug('load_pick : Transaction_header_id: ' || l_txn_hdr_id);
5536 mydebug('Load_Pick: User id: ' || l_user_id);
5537 END IF;
5538
5539 -- Log Exception
5540
5541 IF p_qty_rsn_id > 0 THEN
5542 IF (l_debug = 1) THEN
5543 mydebug('load_pick : Qty Discrepancy exists');
5544 END IF;
5545
5546 wms_txnrsn_actions_pub.log_exception(
5547 p_api_version_number => 1.0
5548 , p_init_msg_lst => fnd_api.g_false
5549 , p_commit => fnd_api.g_false
5550 , x_return_status => l_return_status
5551 , x_msg_count => l_msg_cnt
5552 , x_msg_data => l_msg_data
5553 , p_organization_id => p_org_id
5554 , p_mmtt_id => l_txn_hdr_id
5555 , p_task_id => l_txn_hdr_id
5556 , p_reason_id => p_qty_rsn_id
5557 , p_subinventory_code => p_act_sub
5558 , p_locator_id => p_act_loc
5559 , p_discrepancy_type => 1
5560 , p_user_id => l_user_id
5561 , p_item_id => l_item_id
5562 , p_revision => p_act_rev
5563 , p_lot_number => l_lot
5564 );
5565
5566 IF (l_debug = 1) THEN
5567 mydebug('after logging exception for qty discrepancy');
5568 END IF;
5569
5570 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5571 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5572 fnd_msg_pub.ADD;
5573 RAISE fnd_api.g_exc_unexpected_error;
5574 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5575 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5576 fnd_msg_pub.ADD;
5577 RAISE fnd_api.g_exc_error;
5578 END IF;
5579 END IF;
5580
5581 IF p_loc_rsn_id > 0 THEN
5582 IF (l_debug = 1) THEN
5583 mydebug('load_pick : Loc Discrepancy exists');
5584 mydebug('Load_pick : user id' || l_user_id);
5585 END IF;
5586
5587 wms_txnrsn_actions_pub.log_exception(
5588 p_api_version_number => 1.0
5589 , p_init_msg_lst => fnd_api.g_false
5590 , p_commit => fnd_api.g_false
5591 , x_return_status => l_return_status
5592 , x_msg_count => l_msg_cnt
5593 , x_msg_data => l_msg_data
5594 , p_organization_id => p_org_id
5595 , p_mmtt_id => l_txn_hdr_id
5596 , p_task_id => l_txn_hdr_id
5597 , p_reason_id => p_loc_rsn_id
5598 , p_subinventory_code => p_act_sub
5599 , p_locator_id => p_act_loc
5600 , p_discrepancy_type => 1
5601 , p_user_id => l_user_id
5602 , p_item_id => l_item_id
5603 , p_revision => p_act_rev
5604 , p_lot_number => l_lot
5605 , p_is_loc_desc => TRUE --Added bug 3989684
5606 );
5607
5608 IF (l_debug = 1) THEN
5609 mydebug('after logging exception for loc discrepancy');
5610 END IF;
5611
5612 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5613 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5614 fnd_msg_pub.ADD;
5615 RAISE fnd_api.g_exc_unexpected_error;
5616 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5617 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5618 fnd_msg_pub.ADD;
5619 RAISE fnd_api.g_exc_error;
5620 END IF;
5621 END IF;
5622
5623 l_wf := 0;
5624
5625 BEGIN
5626 SELECT 1
5627 INTO l_wf
5628 FROM mtl_transaction_reasons
5629 WHERE reason_id = p_qty_rsn_id
5630 AND workflow_name IS NOT NULL
5631 AND workflow_name <> ' '
5632 AND workflow_process IS NOT NULL
5633 AND workflow_process <> ' ';
5634 EXCEPTION
5635 WHEN NO_DATA_FOUND THEN
5636 l_wf := 0;
5637 END;
5638
5639 IF l_wf > 0 THEN
5640 IF (l_debug = 1) THEN
5641 mydebug(' load_pick : WF exists for this reason code');
5642 mydebug(' load_pick : Before Calling WF Wrapper for Qty Discrepancy ');
5643 END IF;
5644
5645 -- Calling Workflow
5646
5647 IF p_qty_rsn_id > 0 THEN
5648 IF (l_debug = 1) THEN
5649 mydebug('load_pick: Calling Jefri... workflow wrapper');
5650 END IF;
5651
5652 wms_workflow_wrappers.wf_wrapper(
5653 p_api_version => 1.0
5654 , p_init_msg_list => fnd_api.g_false
5655 , p_commit => fnd_api.g_false
5656 , x_return_status => l_return_status
5657 , x_msg_count => l_msg_cnt
5658 , x_msg_data => l_msg_data
5659 , p_org_id => p_org_id
5660 , p_rsn_id => p_qty_rsn_id
5661 , p_calling_program => 'wms_task_dispatch_gen.load_pick'
5662 , p_tmp_id => p_temp_id
5663 , p_quantity_picked => l_qty_picked
5664 , p_dest_sub => p_act_sub
5665 , p_dest_loc => p_act_loc
5666 );
5667 END IF;
5668
5669 IF (l_debug = 1) THEN
5670 mydebug('load_pick : After Calling WF Wrapper');
5671 END IF;
5672
5673 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5674 IF (l_debug = 1) THEN
5675 mydebug('load_pick : Error callinf WF wrapper');
5676 END IF;
5677
5678 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5679 fnd_msg_pub.ADD;
5680 RAISE fnd_api.g_exc_unexpected_error;
5681 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
5682 IF (l_debug = 1) THEN
5683 mydebug('load_pick : Error calling WF wrapper');
5684 END IF;
5685
5686 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5687 fnd_msg_pub.ADD;
5688 RAISE fnd_api.g_exc_error;
5689 END IF;
5690 END IF;
5691
5692 -- Clean up code. Have to delete MMTT, MTLT, MSNT, WDT, if picked less
5693 -- and update move order line
5694
5695 IF p_is_lot_control = 'true' THEN
5696 IF (l_debug = 1) THEN
5697 mydebug('load_pick : lot controlled');
5698 END IF;
5699
5700 inv_utilities.parse_vector(vector_in => p_lots_to_delete, delimiter => ':', table_of_strings => l_tabtype);
5701
5702 FOR l_counter IN 0 ..(l_tabtype.COUNT - 1) LOOP
5703 IF (l_debug = 1) THEN
5704 mydebug('load_pick : ' || l_tabtype(l_counter));
5705 END IF;
5706
5707 IF p_is_serial_control = 'true' THEN
5708 UPDATE mtl_serial_numbers
5709 SET group_mark_id = NULL
5710 WHERE inventory_item_id = l_item_id
5711 AND current_organization_id = p_org_id
5712 AND serial_number IN(SELECT fm_serial_number
5713 FROM mtl_serial_numbers_temp
5714 WHERE transaction_temp_id IN(SELECT transaction_temp_id
5715 FROM mtl_transaction_lots_temp
5716 WHERE lot_number = l_tabtype(l_counter)
5717 AND transaction_temp_id = p_temp_id));
5718
5719 DELETE FROM mtl_serial_numbers_temp
5720 WHERE transaction_temp_id IN(SELECT transaction_temp_id
5721 FROM mtl_transaction_lots_temp
5722 WHERE lot_number = l_tabtype(l_counter)
5723 AND transaction_temp_id = p_temp_id);
5724 END IF;
5725
5726 DELETE FROM mtl_transaction_lots_temp
5727 WHERE lot_number = l_tabtype(l_counter)
5728 AND transaction_temp_id = p_temp_id;
5729 END LOOP;
5730 END IF;
5731
5732 IF p_is_serial_control = 'true' THEN
5733 IF p_qty_rsn_id > 0 THEN
5734 -- Deleting serials which have not been picked
5735
5736 UPDATE mtl_serial_numbers msn
5737 SET msn.group_mark_id = NULL
5738 WHERE msn.inventory_item_id = l_item_id
5739 AND msn.current_organization_id = p_org_id
5740 AND msn.group_mark_id = p_temp_id
5741 AND msn.serial_number IN(SELECT msnt.fm_serial_number
5742 FROM mtl_serial_numbers_temp msnt
5743 WHERE msnt.transaction_temp_id = p_temp_id);
5744
5745 DELETE FROM mtl_serial_numbers_temp msnt
5746 WHERE msnt.transaction_temp_id = p_temp_id
5747 AND msnt.fm_serial_number IN(
5748 SELECT msn.serial_number
5749 FROM mtl_serial_numbers msn
5750 WHERE msn.inventory_item_id = l_item_id
5751 AND msn.current_organization_id = p_org_id
5752 AND msn.group_mark_id IS NULL);
5753 END IF;
5754 END IF;
5755
5756 -- Find if bulk pick task or not. If bulk pick task we will have to
5757 -- loop thru the move orer lines AND decrement quantity one BY one
5758 l_bulk_pick_flag := 0;
5759
5760 BEGIN
5761 SELECT 1
5762 INTO l_bulk_pick_flag
5763 FROM DUAL
5764 WHERE EXISTS(SELECT 1
5765 FROM mtl_material_transactions_temp mmtt
5766 WHERE mmtt.parent_line_id = p_temp_id);
5767 EXCEPTION
5768 WHEN NO_DATA_FOUND THEN
5769 l_bulk_pick_flag := 0;
5770 END;
5771
5772 -- Code to merge MMTT line if all qty has been picked
5773 -- Note: Merging MMTT only for same reservation IDs. Will not work for
5774 -- detailed reseravtion
5775
5776 IF p_pick_qty_remaining = 0 THEN
5777 IF (l_debug = 1) THEN
5778 mydebug('load_pick: About to merge MMTT lines');
5779 END IF;
5780
5781 OPEN mmtt_csr;
5782
5783 LOOP
5784 FETCH mmtt_csr INTO l_mmtt2_txn_temp_id, l_mmtt1_txn_uom, l_mmtt2_txn_uom, l_mmtt2_txn_qty, l_mmtt2_primary_qty;
5785 EXIT WHEN mmtt_csr%NOTFOUND;
5786
5787 IF (l_debug = 1) THEN
5788 mydebug('load_pick: About to merge MMTT ' || l_mmtt2_txn_temp_id || ' with MMTT ' || p_temp_id);
5789 END IF;
5790
5791 IF l_mmtt1_txn_uom <> l_mmtt2_txn_uom THEN
5792 l_mmtt2_txn_qty :=
5793 inv_convert.inv_um_convert(
5794 item_id => l_item_id
5795 , PRECISION => NULL
5796 , from_quantity => l_mmtt2_txn_qty
5797 , from_unit => l_mmtt2_txn_uom
5798 , to_unit => l_mmtt1_txn_uom
5799 , from_name => NULL
5800 , to_name => NULL
5801 );
5802 END IF;
5803
5804 -- Merge MMTT, MTLT, MSNT
5805
5806 UPDATE mtl_material_transactions_temp
5807 SET transaction_quantity = transaction_quantity + l_mmtt2_txn_qty
5808 , primary_quantity = primary_quantity + l_mmtt2_primary_qty
5809 WHERE transaction_temp_id = p_temp_id;
5810
5811 IF p_is_lot_control = 'true' THEN
5812 UPDATE mtl_transaction_lots_temp
5813 SET transaction_temp_id = p_temp_id
5814 WHERE transaction_temp_id = l_mmtt2_txn_temp_id;
5815 ELSIF p_is_serial_control = 'true' THEN
5816 UPDATE mtl_serial_numbers_temp
5817 SET transaction_temp_id = p_temp_id
5818 WHERE transaction_temp_id = l_mmtt2_txn_temp_id;
5819 END IF;
5820
5821 DELETE FROM mtl_material_transactions_temp
5822 WHERE transaction_temp_id = l_mmtt2_txn_temp_id;
5823
5824 DELETE FROM wms_dispatched_tasks
5825 WHERE transaction_temp_id = l_mmtt2_txn_temp_id;
5826 END LOOP;
5827
5828 CLOSE mmtt_csr;
5829
5830 IF l_bulk_pick_flag <> 0 THEN
5831 bulk_pick(
5832 p_temp_id => p_temp_id
5833 , p_txn_hdr_id => l_txn_hdr_id
5834 , p_org_id => p_org_id
5835 , p_pick_qty_remaining => p_pick_qty_remaining
5836 , p_user_id => p_user_id
5837 , x_new_txn_hdr_id => l_new_txn_hdr_id
5838 , x_return_status => x_return_status
5839 , x_msg_count => x_msg_count
5840 , x_msg_data => x_msg_data
5841 , p_reason_id => p_qty_rsn_id --Added bug 3765153
5842 );
5843
5844 IF x_return_status = 'U' THEN
5845 RAISE fnd_api.g_exc_unexpected_error;
5846 ELSIF x_return_status = 'E' THEN
5847 RAISE fnd_api.g_exc_error;
5848 END IF;
5849
5850 l_txn_hdr_id := l_new_txn_hdr_id;
5851 END IF;
5852 END IF;
5853
5854 IF p_pick_qty_remaining <> 0 THEN
5855 IF (l_debug = 1) THEN
5856 mydebug('load_pick: Updating move order line with reduced quantity');
5857 END IF;
5858
5859 IF l_bulk_pick_flag = 0 THEN
5860 -- Not a bulk pick task Bug 2924823 H to I
5861
5862 BEGIN
5863 SELECT transaction_uom
5864 ,transaction_quantity
5865 ,move_order_line_id
5866 INTO l_mmtt_transaction_uom
5867 ,l_transaction_qty
5868 , l_move_order_line_id
5869 FROM mtl_material_transactions_temp
5870 WHERE transaction_temp_id = p_temp_id;
5871
5872 mydebug('load_pick:
5873 transaction_uom:'||l_mmtt_transaction_uom);
5874 EXCEPTION
5875 WHEN OTHERS THEN
5876 l_mmtt_transaction_uom := null;
5877 l_move_order_line_id := null;
5878 mydebug('load_pick: others exception encounted in selecting
5879 mmtt transaction uom code ');
5880 END;
5881
5882 if l_move_order_line_id is not null then
5883
5884
5885
5886
5887 BEGIN
5888 SELECT uom_code INTO l_mol_uom
5889 FROM mtl_txn_request_lines
5890 WHERE line_id = l_move_order_line_id;
5891
5892 mydebug('load_pick: l_mol_uom_code: '||l_mol_uom);
5893 EXCEPTION
5894 WHEN OTHERS THEN
5895 l_mol_uom := null;
5896 mydebug('load_pick: others exception enchounted in selecting move order uom code');
5897 END;
5898
5899 if (l_mmtt_transaction_uom is not null) and (l_mol_uom is not null ) then
5900 mydebug('l_mmtt_transaction_uom and l_mol_uom both are not null');
5901 if (l_mmtt_transaction_uom <> l_mol_uom ) then
5902 mydebug('load_pick: mmtt transaction uom is different from mol uom');
5903 l_mol_delta_qty := INV_Convert.inv_um_convert
5904 (item_id => l_item_id,
5905 precision => null,
5906 from_quantity => l_transaction_qty,
5907 from_unit => l_mmtt_transaction_uom,
5908 to_unit => l_mol_uom,
5909 from_name => null,
5910 to_name => null);
5911 else
5912 mydebug('load_pick: mmtt transaction uom is the same as mol');
5913 l_mol_delta_qty := l_transaction_qty;
5914 end if;
5915 mydebug('load_pick: l_mol_detal_qty:'||l_mol_delta_qty);
5916 else
5917 mydebug('load_pick: either l_mmtt_transaction_uom or l_mol_uom
5918 null');
5919 end if;
5920 else
5921 mydebug('load_pick: l_move_order_line_id is null');
5922 end if;
5923
5924 mydebug('load_pick: Deleting MMTT');
5925 -- merging from H
5926
5927 DELETE FROM mtl_material_transactions_temp
5928 WHERE transaction_temp_id = p_temp_id;
5929
5930 mydebug('load_pick: Updating move order line with reduced quantity');
5931
5932 mydebug('load_pick: Updating move order line with reduced
5933 quantity');
5934
5935 update mtl_txn_request_lines
5936 set quantity_detailed = quantity_detailed - l_mol_delta_qty
5937 where line_id = l_move_order_line_id;
5938
5939 mydebug('load_pick: after updating move order line detailed
5940 quantity');
5941 DELETE FROM wms_dispatched_tasks
5942 WHERE transaction_temp_id = p_temp_id;
5943
5944
5945 ELSE
5946 DELETE FROM mtl_material_transactions_temp
5947 WHERE transaction_temp_id = p_temp_id;
5948
5949 update mtl_material_transactions_temp
5950 set transaction_temp_id=p_temp_id
5951 where transaction_temp_id=x_temp_id; --Added bug 3765153
5952
5953 bulk_pick(
5954 p_temp_id => p_temp_id
5955 , p_txn_hdr_id => l_txn_hdr_id
5956 , p_org_id => p_org_id
5957 , p_pick_qty_remaining => p_pick_qty_remaining
5958 , p_user_id => p_user_id
5959 , x_new_txn_hdr_id => l_new_txn_hdr_id
5960 , x_return_status => x_return_status
5961 , x_msg_count => x_msg_count
5962 , x_msg_data => x_msg_data
5963 , p_reason_id => p_qty_rsn_id --Added bug 3765153
5964 );
5965
5966 IF x_return_status = 'U' THEN
5967 RAISE fnd_api.g_exc_unexpected_error;
5968 ELSIF x_return_status = 'E' THEN
5969 RAISE fnd_api.g_exc_error;
5970 END IF;
5971
5972 l_txn_hdr_id := l_new_txn_hdr_id;
5973
5974 IF (l_debug = 1) THEN
5975 mydebug('load_pick: archiving task');
5976 END IF;
5977
5978 DELETE FROM wms_dispatched_tasks
5979 WHERE transaction_temp_id = p_temp_id;
5980 END IF;
5981 END IF;
5982 IF (l_debug = 1) THEN
5983 mydebug('load_pick : Calling the label printing API');
5984 END IF;
5985
5986 BEGIN
5987 l_business_flow_code := inv_label.wms_bf_pick_load;
5988
5989 IF l_tran_type_id = 52 THEN -- Picking for sales order
5990 l_business_flow_code := inv_label.wms_bf_pick_load;
5991 ELSIF l_tran_type_id = 35 THEN -- WIP issue
5992 l_business_flow_code := inv_label.wms_bf_wip_pick_load;
5993 ELSIF l_tran_type_id = 51
5994 AND l_tran_source_type_id = 13 THEN --Backflush
5995 l_business_flow_code := inv_label.wms_bf_wip_pick_load;
5996 ELSIF l_tran_type_id = 64
5997 AND l_tran_source_type_id = 4 THEN --Replenishment
5998 l_business_flow_code := inv_label.wms_bf_replenishment_load;
5999 END IF;
6000 /*Added if else for 3451284. We will print labels for only this transaction temp id , except in the case of bulk pick
6001 where will continue with the old code of using transaction header id*/
6002 IF (l_bulk_pick_flag = 0) THEN --if its not a bulk pick task only print lable for the transaction temp id.
6003
6004 /*Bug#4113235. we need to call the label printing api with the transaction_temp_id of the new
6005 MMTT created after splitting the original MMTT in case of short pick */
6006 IF (l_debug = 1) THEN
6007 mydebug('load_pick: Calling label printing for transaction:' || x_temp_id);
6008 END IF;
6009
6010 inv_label.print_label_wrap(
6011 x_return_status => l_return_status
6012 , x_msg_count => x_msg_count
6013 , x_msg_data => x_msg_data
6014 , x_label_status => l_label_status
6015 , p_business_flow_code => l_business_flow_code
6016 , p_transaction_id => x_temp_id --Changed bug#4113235.
6017 );
6018
6019 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
6020 IF (l_debug = 1) THEN
6021 mydebug('load_pick: Label printing failed. Continue');
6022 END IF;
6023 END IF;
6024 ELSE -- old code print labels based on heade id.
6025 OPEN mmtt_csr2(l_txn_hdr_id);
6026
6027 LOOP
6028 FETCH mmtt_csr2 INTO l_temp_id;
6029 EXIT WHEN mmtt_csr2%NOTFOUND;
6030
6031 IF (l_debug = 1) THEN
6032 mydebug('load_pick: Calling label printing for transaction:' || l_temp_id);
6033 END IF;
6034
6035 inv_label.print_label_wrap(
6036 x_return_status => l_return_status
6037 , x_msg_count => x_msg_count
6038 , x_msg_data => x_msg_data
6039 , x_label_status => l_label_status
6040 , p_business_flow_code => l_business_flow_code
6041 , p_transaction_id => l_temp_id
6042 );
6043
6044 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
6045 IF (l_debug = 1) THEN
6046 mydebug('load_pick: Label printing failed. Continue');
6047 END IF;
6048 END IF;
6049 END LOOP;
6050
6051 CLOSE mmtt_csr2;
6052 END IF;--end onf bulk pick or not bulk pick.
6053 END;
6054
6055 IF (l_debug = 1) THEN
6056 mydebug('load_pick: End of load_pick');
6057 END IF;
6058
6059 x_return_status := fnd_api.g_ret_sts_success;
6060
6061 IF (l_debug = 1) THEN
6062 mydebug(' p_ok_to_process: ' || p_ok_to_process);
6063 END IF;
6064 EXCEPTION
6065 WHEN fnd_api.g_exc_error THEN
6066 x_return_status := fnd_api.g_ret_sts_error;
6067 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6068
6069 IF (l_debug = 1) THEN
6070 mydebug('load_pick: Error in load_pick API: ' || SQLERRM);
6071 END IF;
6072 WHEN OTHERS THEN
6073 x_return_status := fnd_api.g_ret_sts_unexp_error;
6074 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6075
6076 IF (l_debug = 1) THEN
6077 mydebug('load_pick: Unexpected Error in load_pick API: ' || SQLERRM);
6078 END IF;
6079 END load_pick;
6080
6081 PROCEDURE insert_mmtt_pack(
6082 p_temp_id IN NUMBER
6083 , p_lpn_id IN NUMBER
6084 , p_transfer_lpn IN VARCHAR2
6085 , p_container_item_id IN NUMBER
6086 , x_return_status OUT NOCOPY VARCHAR2
6087 , x_msg_count OUT NOCOPY NUMBER
6088 , x_msg_data OUT NOCOPY VARCHAR2
6089 ) IS
6090 l_mmtt_rec inv_mo_line_detail_util.g_mmtt_rec;
6091 l_temp_id NUMBER;
6092 l_lpn_id NUMBER;
6093 l_transfer_lpn_id NUMBER;
6094 l_new_temp_id NUMBER;
6095 l_lpn VARCHAR2(30);
6096 l_exist_lpn NUMBER;
6097 l_cost_group_id NUMBER;
6098 l_container_item_id NUMBER;
6099 l_org_id NUMBER;
6100 l_msg_cnt NUMBER;
6101 l_msg_data VARCHAR2(2000);
6102 l_return_status VARCHAR2(1);
6103 l_rows NUMBER;
6104 l_loc NUMBER;
6105 l_sub VARCHAR2(10);
6106 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6107 BEGIN
6108 l_return_status := fnd_api.g_ret_sts_success;
6109 l_temp_id := p_temp_id;
6110 l_lpn_id := p_lpn_id;
6111 l_lpn := p_transfer_lpn;
6112 l_container_item_id := p_container_item_id;
6113
6114 IF l_container_item_id = 0 THEN
6115 l_container_item_id := NULL;
6116 END IF;
6117
6118 -- Check to see if LPN exists
6119
6120 IF (l_lpn IS NULL
6121 OR l_lpn = '') THEN
6122 l_lpn_id := NULL;
6123
6124 IF (l_debug = 1) THEN
6125 mydebug('insert_mmtt_pack: No LPN was passed');
6126 END IF;
6127 ELSE
6128 SELECT transfer_cost_group_id
6129 , organization_id
6130 , transfer_subinventory
6131 , transfer_to_location
6132 INTO l_cost_group_id
6133 , l_org_id
6134 , l_sub
6135 , l_loc
6136 FROM mtl_material_transactions_temp
6137 WHERE transaction_temp_id = l_temp_id;
6138
6139 l_exist_lpn := 0;
6140
6141 /* SELECT COUNT(*) INTO l_exist_lpn
6142 FROM WMS_LICENSE_PLATE_NUMBERS
6143 WHERE license_plate_number=l_lpn
6144 AND organization_id=l_org_id;*/
6145 BEGIN
6146 SELECT 1
6147 INTO l_exist_lpn
6148 FROM DUAL
6149 WHERE EXISTS(SELECT 1
6150 FROM wms_license_plate_numbers
6151 WHERE license_plate_number = l_lpn
6152 AND organization_id = l_org_id);
6153 EXCEPTION
6154 WHEN NO_DATA_FOUND THEN
6155 l_exist_lpn := 0;
6156 END;
6157
6158 IF (l_exist_lpn = 0) THEN
6159 -- LPN does not exist, create it
6160 -- Call Suresh's Create LPN API
6161 IF (l_debug = 1) THEN
6162 mydebug('insert_mmtt_pack: Creating LPN');
6163 END IF;
6164
6165 wms_container_pub.create_lpn(
6166 p_api_version => 1.0
6167 , p_init_msg_list => fnd_api.g_false
6168 , p_commit => fnd_api.g_false
6169 , x_return_status => l_return_status
6170 , x_msg_count => l_msg_cnt
6171 , x_msg_data => l_msg_data
6172 , p_lpn => l_lpn
6173 , p_organization_id => l_org_id
6174 , p_container_item_id => l_container_item_id
6175 , p_lot_number => NULL
6176 , p_revision => NULL
6177 , p_serial_number => NULL
6178 , p_subinventory => l_sub
6179 , p_locator_id => l_loc
6180 , p_source => 1
6181 , p_cost_group_id => NULL
6182 , x_lpn_id => l_transfer_lpn_id
6183 );
6184 fnd_msg_pub.count_and_get(p_count => l_msg_cnt, p_data => l_msg_data);
6185
6186 IF (l_msg_cnt = 0) THEN
6187 IF (l_debug = 1) THEN
6188 mydebug('insert_mmtt_pack: Successful');
6189 END IF;
6190 ELSIF(l_msg_cnt = 1) THEN
6191 IF (l_debug = 1) THEN
6192 mydebug('insert_mmtt_pack: Not Successful');
6193 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
6194 END IF;
6195 ELSE
6196 IF (l_debug = 1) THEN
6197 mydebug('insert_mmtt_pack: Not Successful2');
6198 END IF;
6199
6200 FOR i IN 1 .. l_msg_cnt LOOP
6201 l_msg_data := fnd_msg_pub.get(i, 'F');
6202
6203 IF (l_debug = 1) THEN
6204 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
6205 END IF;
6206 END LOOP;
6207 END IF;
6208
6209 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6210 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
6211 fnd_msg_pub.ADD;
6212 RAISE fnd_api.g_exc_unexpected_error;
6213 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6214 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
6215 fnd_msg_pub.ADD;
6216 RAISE fnd_api.g_exc_error;
6217 END IF;
6218 ELSE
6219 -- LPN exists. Get LPN ID
6220 SELECT lpn_id
6221 INTO l_transfer_lpn_id
6222 FROM wms_license_plate_numbers
6223 WHERE license_plate_number = l_lpn
6224 AND organization_id = l_org_id;
6225 END IF;
6226 END IF;
6227
6228 SELECT mtl_material_transactions_s.NEXTVAL
6229 INTO l_new_temp_id
6230 FROM DUAL;
6231
6232 INSERT INTO mtl_material_transactions_temp
6233 (
6234 transaction_header_id
6235 , transaction_temp_id
6236 , source_code
6237 , source_line_id
6238 , transaction_mode
6239 , lock_flag
6240 , last_update_date
6241 , last_updated_by
6242 , creation_date
6243 , created_by
6244 , last_update_login
6245 , request_id
6246 , program_application_id
6247 , program_id
6248 , program_update_date
6249 , inventory_item_id
6250 , revision
6251 , organization_id
6252 , subinventory_code
6253 , locator_id
6254 , transaction_quantity
6255 , primary_quantity
6256 , transaction_uom
6257 , transaction_cost
6258 , transaction_type_id
6259 , transaction_action_id
6260 , transaction_source_type_id
6261 , transaction_source_id
6262 , transaction_source_name
6263 , transaction_date
6264 , acct_period_id
6265 , distribution_account_id
6266 , transaction_reference
6267 , requisition_line_id
6268 , requisition_distribution_id
6269 , reason_id
6270 , lot_number
6271 , lot_expiration_date
6272 , serial_number
6273 , receiving_document
6274 , demand_id
6275 , rcv_transaction_id
6276 , move_transaction_id
6277 , completion_transaction_id
6278 , wip_entity_type
6279 , schedule_id
6280 , repetitive_line_id
6281 , employee_code
6282 , primary_switch
6283 , schedule_update_code
6284 , setup_teardown_code
6285 , item_ordering
6286 , negative_req_flag
6287 , operation_seq_num
6288 , picking_line_id
6289 , trx_source_line_id
6290 , trx_source_delivery_id
6291 , physical_adjustment_id
6292 , cycle_count_id
6293 , rma_line_id
6294 , customer_ship_id
6295 , currency_code
6296 , currency_conversion_rate
6297 , currency_conversion_type
6298 , currency_conversion_date
6299 , ussgl_transaction_code
6300 , vendor_lot_number
6301 , encumbrance_account
6302 , encumbrance_amount
6303 , ship_to_location
6304 , shipment_number
6305 , transfer_cost
6306 , transportation_cost
6307 , transportation_account
6308 , freight_code
6309 , containers
6310 , waybill_airbill
6311 , expected_arrival_date
6312 , transfer_subinventory
6313 , transfer_organization
6314 , transfer_to_location
6315 , new_average_cost
6316 , value_change
6317 , percentage_change
6318 , material_allocation_temp_id
6319 , demand_source_header_id
6320 , demand_source_line
6321 , demand_source_delivery
6322 , item_segments
6323 , item_description
6324 , item_trx_enabled_flag
6325 , item_location_control_code
6326 , item_restrict_subinv_code
6327 , item_restrict_locators_code
6328 , item_revision_qty_control_code
6329 , item_primary_uom_code
6330 , item_uom_class
6331 , item_shelf_life_code
6332 , item_shelf_life_days
6333 , item_lot_control_code
6334 , item_serial_control_code
6335 , item_inventory_asset_flag
6336 , allowed_units_lookup_code
6337 , department_id
6338 , department_code
6339 , wip_supply_type
6340 , supply_subinventory
6341 , supply_locator_id
6342 , valid_subinventory_flag
6343 , valid_locator_flag
6344 , locator_segments
6345 , current_locator_control_code
6346 , number_of_lots_entered
6347 , wip_commit_flag
6348 , next_lot_number
6349 , lot_alpha_prefix
6350 , next_serial_number
6351 , serial_alpha_prefix
6352 , shippable_flag
6353 , posting_flag
6354 , required_flag
6355 , process_flag
6356 , ERROR_CODE
6357 , error_explanation
6358 , attribute_category
6359 , attribute1
6360 , attribute2
6361 , attribute3
6362 , attribute4
6363 , attribute5
6364 , attribute6
6365 , attribute7
6366 , attribute8
6367 , attribute9
6368 , attribute10
6369 , attribute11
6370 , attribute12
6371 , attribute13
6372 , attribute14
6373 , attribute15
6374 , movement_id
6375 , reservation_quantity
6376 , shipped_quantity
6377 , transaction_line_number
6378 , task_id
6379 , to_task_id
6380 , source_task_id
6381 , project_id
6382 , source_project_id
6383 , pa_expenditure_org_id
6384 , to_project_id
6385 , expenditure_type
6386 , final_completion_flag
6387 , transfer_percentage
6388 , transaction_sequence_id
6389 , material_account
6390 , material_overhead_account
6391 , resource_account
6392 , outside_processing_account
6393 , overhead_account
6394 , flow_schedule
6395 , cost_group_id
6396 , demand_class
6397 , qa_collection_id
6398 , kanban_card_id
6399 , overcompletion_transaction_id
6400 , overcompletion_primary_qty
6401 , overcompletion_transaction_qty
6402 , end_item_unit_number
6403 , scheduled_payback_date
6404 , line_type_code
6405 , parent_transaction_temp_id
6406 , put_away_strategy_id
6407 , put_away_rule_id
6408 , pick_strategy_id
6409 , pick_rule_id
6410 , common_bom_seq_id
6411 , common_routing_seq_id
6412 , cost_type_id
6413 , org_cost_group_id
6414 , move_order_line_id
6415 , task_group_id
6416 , pick_slip_number
6417 , reservation_id
6418 , transaction_status
6419 , transfer_cost_group_id
6420 , lpn_id
6421 , transfer_lpn_id
6422 , content_lpn_id
6423 , operation_plan_id
6424 , transaction_batch_id
6425 , transaction_batch_seq
6426 )
6427 (SELECT transaction_header_id
6428 , l_new_temp_id
6429 , source_code
6430 , source_line_id
6431 , transaction_mode
6432 , lock_flag
6433 , last_update_date
6434 , last_updated_by
6435 , creation_date
6436 , created_by
6437 , last_update_login
6438 , request_id
6439 , program_application_id
6440 , program_id
6441 , program_update_date
6442 , inventory_item_id
6443 , revision
6444 , organization_id
6445 , transfer_subinventory
6446 , transfer_to_location
6447 , 1
6448 , 1
6449 , transaction_uom
6450 , transaction_cost
6451 , inv_globals.g_type_container_pack
6452 , 50
6453 , 13
6454 , NULL
6455 , NULL
6456 , SYSDATE
6457 , acct_period_id
6458 , distribution_account_id
6459 , transaction_reference
6460 , requisition_line_id
6461 , requisition_distribution_id
6462 , reason_id
6463 , lot_number
6464 , lot_expiration_date
6465 , serial_number
6466 , receiving_document
6467 , demand_id
6468 , rcv_transaction_id
6469 , move_transaction_id
6470 , completion_transaction_id
6471 , wip_entity_type
6472 , schedule_id
6473 , repetitive_line_id
6474 , employee_code
6475 , primary_switch
6476 , schedule_update_code
6477 , setup_teardown_code
6478 , item_ordering
6479 , negative_req_flag
6480 , operation_seq_num
6481 , picking_line_id
6482 , trx_source_line_id
6483 , trx_source_delivery_id
6484 , physical_adjustment_id
6485 , cycle_count_id
6486 , rma_line_id
6487 , customer_ship_id
6488 , currency_code
6489 , currency_conversion_rate
6490 , currency_conversion_type
6491 , currency_conversion_date
6492 , ussgl_transaction_code
6493 , vendor_lot_number
6494 , encumbrance_account
6495 , encumbrance_amount
6496 , ship_to_location
6497 , shipment_number
6498 , transfer_cost
6499 , transportation_cost
6500 , transportation_account
6501 , freight_code
6502 , containers
6503 , waybill_airbill
6504 , expected_arrival_date
6505 , transfer_subinventory
6506 , transfer_organization
6507 , transfer_to_location
6508 , new_average_cost
6509 , value_change
6510 , percentage_change
6511 , material_allocation_temp_id
6512 , demand_source_header_id
6513 , demand_source_line
6514 , demand_source_delivery
6515 , item_segments
6516 , item_description
6517 , item_trx_enabled_flag
6518 , item_location_control_code
6519 , item_restrict_subinv_code
6520 , item_restrict_locators_code
6521 , item_revision_qty_control_code
6522 , item_primary_uom_code
6523 , item_uom_class
6524 , item_shelf_life_code
6525 , item_shelf_life_days
6526 , item_lot_control_code
6527 , item_serial_control_code
6528 , item_inventory_asset_flag
6529 , allowed_units_lookup_code
6530 , department_id
6531 , department_code
6532 , wip_supply_type
6533 , supply_subinventory
6534 , supply_locator_id
6535 , valid_subinventory_flag
6536 , valid_locator_flag
6537 , locator_segments
6538 , current_locator_control_code
6539 , number_of_lots_entered
6540 , wip_commit_flag
6541 , next_lot_number
6542 , lot_alpha_prefix
6543 , next_serial_number
6544 , serial_alpha_prefix
6545 , shippable_flag
6546 , posting_flag
6547 , required_flag
6548 , process_flag
6549 , ERROR_CODE
6550 , error_explanation
6551 , attribute_category
6552 , attribute1
6553 , attribute2
6554 , attribute3
6555 , attribute4
6556 , attribute5
6557 , attribute6
6558 , attribute7
6559 , attribute8
6560 , attribute9
6561 , attribute10
6562 , attribute11
6563 , attribute12
6564 , attribute13
6565 , attribute14
6566 , attribute15
6567 , movement_id
6568 , reservation_quantity
6569 , shipped_quantity
6570 , transaction_line_number
6571 , task_id
6572 , to_task_id
6573 , source_task_id
6574 , project_id
6575 , source_project_id
6576 , pa_expenditure_org_id
6577 , to_project_id
6578 , expenditure_type
6579 , final_completion_flag
6580 , transfer_percentage
6581 , transaction_sequence_id
6582 , material_account
6583 , material_overhead_account
6584 , resource_account
6585 , outside_processing_account
6586 , overhead_account
6587 , flow_schedule
6588 , cost_group_id
6589 , demand_class
6590 , qa_collection_id
6591 , kanban_card_id
6592 , overcompletion_transaction_id
6593 , overcompletion_primary_qty
6594 , overcompletion_transaction_qty
6595 , end_item_unit_number
6596 , scheduled_payback_date
6597 , line_type_code
6598 , parent_transaction_temp_id
6599 , put_away_strategy_id
6600 , put_away_rule_id
6601 , pick_strategy_id
6602 , pick_rule_id
6603 , common_bom_seq_id
6604 , common_routing_seq_id
6605 , cost_type_id
6606 , org_cost_group_id
6607 , NULL
6608 , task_group_id
6609 , pick_slip_number
6610 , NULL
6611 , transaction_status
6612 , transfer_cost_group_id
6613 , lpn_id
6614 , l_transfer_lpn_id
6615 , l_lpn_id
6616 , operation_plan_id
6617 , transaction_header_id
6618 , l_new_temp_id
6619 FROM mtl_material_transactions_temp
6620 WHERE transaction_temp_id = l_temp_id);
6621
6622 x_return_status := fnd_api.g_ret_sts_success;
6623 EXCEPTION
6624 WHEN fnd_api.g_exc_error THEN
6625 x_return_status := fnd_api.g_ret_sts_error;
6626 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6627 WHEN OTHERS THEN
6628 x_return_status := fnd_api.g_ret_sts_unexp_error;
6629 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6630 END insert_mmtt_pack;
6631
6632 PROCEDURE change_lpn(
6633 p_org_id IN NUMBER
6634 , p_container IN NUMBER
6635 , p_lpn_name IN VARCHAR2 --New LPN
6636 , p_sug_lpn_name IN VARCHAR2
6637 , x_ret OUT NOCOPY NUMBER
6638 , x_return_status OUT NOCOPY VARCHAR2
6639 , x_msg_count OUT NOCOPY NUMBER
6640 , x_msg_data OUT NOCOPY VARCHAR2
6641 ) IS
6642 l_org_id NUMBER;
6643 l_container NUMBER;
6644 l_lpn_name VARCHAR2(60);
6645 l_sug_lpn_name VARCHAR2(60);
6646 l_ret NUMBER;
6647 l_exist_lpn NUMBER;
6648 l_exist_lpn2 NUMBER;
6649 l_lpn_id NUMBER;
6650 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
6651 l_msg_cnt NUMBER;
6652 l_msg_data VARCHAR2(2000);
6653 l_exist_contents NUMBER;
6654 b_can_modify BOOLEAN;
6655 l_sug_lpn_id NUMBER;
6656 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6657 BEGIN
6658 IF (l_debug = 1) THEN
6659 mydebug('In change lpn');
6660 END IF;
6661
6662 l_org_id := p_org_id;
6663 l_container := p_container;
6664 l_lpn_name := p_lpn_name;
6665 l_sug_lpn_name := p_sug_lpn_name;
6666 l_ret := 0;
6667 l_exist_lpn := 0;
6668 l_exist_lpn2 := 0;
6669 l_exist_contents := 0;
6670 b_can_modify := TRUE;
6671
6672 /*
6673 -- get sug lpn id
6674 SELECT lpn_id INTO l_sug_lpn_id
6675 FROM WMS_LICENSE_PLATE_NUMBERS
6676 WHERE license_plate_number=l_sug_lpn_name
6677 AND organization_id=l_org_id;
6678 */
6679 --Bug#2095232
6680 -- get new lpn id instead of suggested one
6681 SELECT lpn_id
6682 INTO l_lpn_id
6683 FROM wms_license_plate_numbers
6684 WHERE license_plate_number = l_lpn_name
6685 AND organization_id = l_org_id;
6686
6687 IF (l_lpn_name IS NULL) THEN
6688 IF (l_debug = 1) THEN
6689 mydebug('license plate number not changed');
6690 END IF;
6691 ELSE
6692 IF (l_debug = 1) THEN
6693 mydebug('license plate number changed');
6694 END IF;
6695
6696 l_exist_lpn := 0;
6697
6698 /* SELECT COUNT(*) INTO l_exist_lpn
6699 FROM WMS_LICENSE_PLATE_NUMBERS
6700 WHERE license_plate_number=l_lpn_name
6701 AND organization_id=l_org_id
6702 AND lpn_context<>wms_container_pub.lpn_context_packing;*/
6703 BEGIN
6704 SELECT 1
6705 INTO l_exist_lpn
6706 FROM DUAL
6707 WHERE EXISTS(
6708 SELECT 1
6709 FROM wms_license_plate_numbers
6710 WHERE license_plate_number = l_lpn_name
6711 AND organization_id = l_org_id
6712 AND lpn_context <> wms_container_pub.lpn_context_packing);
6713 EXCEPTION
6714 WHEN NO_DATA_FOUND THEN
6715 l_exist_lpn := 0;
6716 END;
6717
6718 IF (l_exist_lpn > 0) THEN
6719 -- LPN exists.Cannot use
6720 b_can_modify := FALSE;
6721 l_ret := 2;
6722 ELSE
6723 -- Check to see if the suggested lpn has contents already
6724 -- if yes, we cannot modify
6725 l_exist_lpn2 := 0;
6726
6727 /* SELECT COUNT(*) INTO l_exist_lpn2
6728 FROM wms_license_plate_numbers w, wms_lpn_contents c
6729 WHERE w.license_plate_number=l_sug_lpn_name
6730 AND w.organization_id=l_org_id
6731 AND w.lpn_id=c.parent_lpn_id;*/
6732 BEGIN
6733 SELECT 1
6734 INTO l_exist_lpn2
6735 FROM DUAL
6736 WHERE EXISTS(SELECT 1
6737 FROM wms_license_plate_numbers w, wms_lpn_contents c
6738 WHERE w.license_plate_number = l_sug_lpn_name
6739 AND w.organization_id = l_org_id
6740 AND w.lpn_id = c.parent_lpn_id);
6741 EXCEPTION
6742 WHEN NO_DATA_FOUND THEN
6743 l_exist_lpn2 := 0;
6744 END;
6745
6746 IF (l_exist_lpn2 > 0) THEN
6747 -- Sug LPN has contents.Cannot modify, treat as new
6748 b_can_modify := FALSE;
6749 l_ret := 1;
6750 END IF;
6751 END IF;
6752 END IF;
6753
6754 -- Only need to call
6755
6756
6757 IF (b_can_modify) THEN
6758 -- LPN does not exist,we can update it
6759 IF (l_debug = 1) THEN
6760 mydebug('Modifying LPN: b_can_modify = TRUE');
6761 END IF;
6762
6763 wms_container_pub.modify_lpn_wrapper(
6764 p_api_version => 1.0
6765 , p_init_msg_list => fnd_api.g_false
6766 , p_commit => fnd_api.g_false
6767 , x_return_status => l_return_status
6768 , x_msg_count => l_msg_cnt
6769 , x_msg_data => l_msg_data
6770 , p_lpn_id => l_lpn_id
6771 , --Bug#2095232
6772 p_license_plate_number => l_lpn_name
6773 , p_inventory_item_id => l_container
6774 , p_weight_uom_code => NULL
6775 , p_gross_weight => NULL
6776 , p_volume_uom_code => NULL
6777 , p_content_volume => NULL
6778 , p_status_id => NULL
6779 , p_lpn_context => wms_container_pub.lpn_context_packing
6780 , p_sealed_status => NULL
6781 , p_organization_id => l_org_id
6782 , p_subinventory => NULL
6783 , p_locator_id => NULL
6784 , p_source_type_id => NULL
6785 , p_source_header_id => NULL
6786 , p_source_name => NULL
6787 , p_source_line_id => NULL
6788 , p_source_line_detail_id => NULL
6789 );
6790
6791 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6792 fnd_message.set_name('WMS', 'WMS_TD_MODIFY_LPN_ERROR');
6793 fnd_msg_pub.ADD;
6794 RAISE fnd_api.g_exc_unexpected_error;
6795 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
6796 fnd_message.set_name('WMS', 'WMS_TD_MODIFY_LPN_ERROR');
6797 fnd_msg_pub.ADD;
6798 RAISE fnd_api.g_exc_error;
6799 END IF;
6800 END IF;
6801
6802 x_ret := l_ret;
6803 x_return_status := fnd_api.g_ret_sts_success;
6804 EXCEPTION
6805 WHEN fnd_api.g_exc_error THEN
6806 x_return_status := fnd_api.g_ret_sts_error;
6807 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6808 WHEN OTHERS THEN
6809 x_return_status := fnd_api.g_ret_sts_unexp_error;
6810 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6811 END change_lpn;
6812
6813 PROCEDURE multiple_lpn_pick(
6814 p_lpn_id IN NUMBER
6815 , p_lpn_qty IN NUMBER
6816 , p_org_id IN NUMBER
6817 , p_temp_id IN NUMBER
6818 , x_temp_id OUT NOCOPY NUMBER
6819 , x_return_status OUT NOCOPY VARCHAR2
6820 , x_msg_count OUT NOCOPY NUMBER
6821 , x_msg_data OUT NOCOPY VARCHAR2
6822 , p_sn_allocated_flag IN VARCHAR2
6823 , p_uom_code IN VARCHAR2
6824 , p_to_lpn_id IN NUMBER
6825 , p_entire_lpn IN VARCHAR2
6826 ) IS
6827 l_lpn_id NUMBER;
6828 l_org_id NUMBER;
6829 l_temp_id NUMBER;
6830 l_msg_cnt NUMBER;
6831 l_msg_data VARCHAR2(2000);
6832 l_return_status VARCHAR2(1);
6833 l_rows NUMBER;
6834 l_cost_group_id NUMBER;
6835 l_loc NUMBER;
6836 l_sub VARCHAR2(10);
6837 l_user_loc NUMBER;
6838 l_user_sub VARCHAR2(10);
6839 l_from_lpn_id NUMBER;
6840 l_ser_temp_id VARCHAR2(30);
6841 l_serial_number VARCHAR2(30);
6842 l_qty NUMBER;
6843 l_uom VARCHAR2(3);
6844 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
6845 l_lot VARCHAR2(80);
6846 l_pr_qty NUMBER;
6847 l_item_id NUMBER;
6848 l_lot_code NUMBER;
6849 l_serial_code NUMBER;
6850 l_ser_seq NUMBER;
6851 l_user_id NUMBER;
6852 l_mo_line_id NUMBER;
6853 l_orig_qty NUMBER;
6854 l_new_temp_id NUMBER;
6855 l_next_task_id NUMBER;
6856 l_lpn_cnt NUMBER;
6857 l_txn_header_id NUMBER;
6858
6859 CURSOR lpn_ser_cur(v_lot_number VARCHAR2) IS
6860 SELECT serial_number
6861 FROM mtl_serial_numbers
6862 WHERE lpn_id = p_lpn_id
6863 AND NVL(lot_number, 'NONE') = NVL(v_lot_number, 'NONE');
6864
6865 CURSOR lpn_lot_cur IS
6866 SELECT lot_number
6867 , quantity
6868 , uom_code
6869 FROM wms_lpn_contents
6870 WHERE parent_lpn_id = p_lpn_id;
6871
6872 CURSOR mtlt_lot_cur(v_lot_number VARCHAR2) IS
6873 SELECT *
6874 FROM mtl_transaction_lots_temp
6875 WHERE transaction_temp_id = p_temp_id
6876 AND lot_number = v_lot_number;
6877
6878 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
6879 l_lpn_lot_number VARCHAR2(80);
6880 l_lpn_lot_qty NUMBER;
6881 l_lpn_lot_primary_qty NUMBER;
6882 l_lpn_uom_code VARCHAR2(3);
6883 l_lot_primary_qty NUMBER;
6884 l_mtlt_rec mtl_transaction_lots_temp%ROWTYPE;
6885 l_allocate_serial_flag NUMBER := 0;
6886 l_new_serial_temp_id NUMBER;
6887 l_lot_serial_temp_id NUMBER;
6888 l_temp_lpn_id NUMBER;
6889 l_transfer_lpn_id NUMBER;
6890 l_content_lpn_id NUMBER;
6891 l_to_lpn_id NUMBER;
6892 l_test_qty NUMBER;
6893 l_content_parent_lpn_id NUMBER;
6894 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6895 l_lpn_sub VARCHAR2(30); --Added bug3765153
6896 l_lpn_loc NUMBER; --Added bug3765153
6897 BEGIN
6898 SAVEPOINT sp_multiple_lpn_pick;
6899 l_return_status := fnd_api.g_ret_sts_success;
6900
6901 IF (l_debug = 1) THEN
6902 mydebug('multiple_lpn_pick: p_lpn_id = ' || p_lpn_id);
6903 mydebug('multiple_lpn_pick: p_temp_id = ' || p_temp_id);
6904 mydebug('multiple_lpn_pick: p_org_id = ' || p_org_id);
6905 mydebug('multiple_lpn_pick: p_lpn_qty = ' || p_lpn_qty);
6906 mydebug('multiple_lpn_pick: p_uom_code = ' || p_uom_code);
6907 mydebug('multiple_lpn_pick: p_sn_allocated_flag = ' || p_sn_allocated_flag);
6908 END IF;
6909
6910 l_lpn_id := p_lpn_id;
6911 l_org_id := p_org_id;
6912 l_temp_id := p_temp_id;
6913 l_to_lpn_id := p_to_lpn_id;
6914
6915 IF p_entire_lpn = 'Y' THEN
6916 -- for nested LPNs selected for picking items from:start
6917 IF (l_debug = 1) THEN
6918 mydebug('multiple_lpn_pick: getting outermost LPN for selected lpn ON PKLP');
6919 END IF;
6920
6921 --Modifying the below sql to also get the data of sub and loc from the LPN in case of multiple pick bug3765153
6922 SELECT parent_lpn_id,subinventory_code,locator_id
6923 INTO l_content_parent_lpn_id,l_lpn_sub,l_lpn_loc
6924 FROM wms_license_plate_numbers
6925 WHERE lpn_id = l_lpn_id
6926 AND organization_id = p_org_id;
6927
6928 IF (l_debug = 1) THEN
6929 mydebug('multiple_lpn_pick: outermost LPN for the selected LPN::' || l_content_parent_lpn_id);
6930 END IF;
6931
6932 IF (l_content_parent_lpn_id <> l_lpn_id) THEN
6933 IF (l_debug = 1) THEN
6934 mydebug('multiple_lpn_pick: setting lpn_id in MMTT to outermost LPN for nested LPN from PKLP');
6935 END IF;
6936
6937 l_lpn_id := l_content_parent_lpn_id; --TM will take care of this
6938 END IF;
6939
6940 -- for nested LPNs selected for picking items from:end
6941
6942 l_temp_lpn_id := NULL;
6943 l_transfer_lpn_id := l_lpn_id;
6944 l_content_lpn_id := l_lpn_id;
6945 ELSE
6946 l_temp_lpn_id := l_lpn_id;
6947 l_transfer_lpn_id := l_to_lpn_id;
6948 l_content_lpn_id := NULL;
6949 END IF;
6950
6951 SELECT transfer_cost_group_id
6952 , transfer_subinventory
6953 , transfer_to_location
6954 , lot_number
6955 , transaction_quantity
6956 , transaction_uom
6957 , inventory_item_id
6958 , last_updated_by
6959 , move_order_line_id
6960 INTO l_cost_group_id
6961 , l_sub
6962 , l_loc
6963 , l_lot
6964 , l_orig_qty
6965 , l_uom
6966 , l_item_id
6967 , l_user_id
6968 , l_mo_line_id
6969 FROM mtl_material_transactions_temp
6970 WHERE transaction_temp_id = l_temp_id;
6971
6972 IF l_uom = p_uom_code THEN
6973 l_qty := p_lpn_qty;
6974 ELSE
6975 l_qty :=
6976 inv_convert.inv_um_convert(
6977 item_id => l_item_id
6978 , PRECISION => NULL
6979 , from_quantity => p_lpn_qty
6980 , from_unit => p_uom_code
6981 , to_unit => l_uom
6982 , from_name => NULL
6983 , to_name => NULL
6984 );
6985
6986 IF (l_debug = 1) THEN
6987 mydebug('multiple_lpn_pick: l_qty = ' || l_qty);
6988 END IF;
6989 END IF;
6990
6991 -- Calculate Primary Quantity
6992
6993 l_pr_qty :=
6994 wms_task_dispatch_gen.get_primary_quantity(p_item_id => l_item_id, p_organization_id => l_org_id, p_from_quantity => l_qty
6995 , p_from_unit => l_uom);
6996
6997 IF (l_debug = 1) THEN
6998 mydebug('multiple_lpn_pick: l_pr_qty = ' || l_pr_qty);
6999 END IF;
7000
7001 -- Create new MMTT line with qty and primary qty in the LPN, content_lpn_id, transfer_lpn_id
7002
7003 SELECT mtl_material_transactions_s.NEXTVAL
7004 INTO l_new_temp_id
7005 FROM DUAL;
7006
7007 IF (l_debug = 1) THEN
7008 mydebug('multiple_lpn_pick: l_new_temp_id = ' || l_new_temp_id);
7009 END IF;
7010
7011 INSERT INTO mtl_material_transactions_temp
7012 (
7013 transaction_header_id
7014 , transaction_temp_id
7015 , source_code
7016 , source_line_id
7017 , transaction_mode
7018 , lock_flag
7019 , last_update_date
7020 , last_updated_by
7021 , creation_date
7022 , created_by
7023 , last_update_login
7024 , request_id
7025 , program_application_id
7026 , program_id
7027 , program_update_date
7028 , inventory_item_id
7029 , revision
7030 , organization_id
7031 , subinventory_code
7032 , locator_id
7033 , transaction_quantity
7034 , primary_quantity
7035 , transaction_uom
7036 , transaction_cost
7037 , transaction_type_id
7038 , transaction_action_id
7039 , transaction_source_type_id
7040 , transaction_source_id
7041 , transaction_source_name
7042 , transaction_date
7043 , acct_period_id
7044 , distribution_account_id
7045 , transaction_reference
7046 , requisition_line_id
7047 , requisition_distribution_id
7048 , reason_id
7049 , lot_number
7050 , lot_expiration_date
7051 , serial_number
7052 , receiving_document
7053 , demand_id
7054 , rcv_transaction_id
7055 , move_transaction_id
7056 , completion_transaction_id
7057 , wip_entity_type
7058 , schedule_id
7059 , repetitive_line_id
7060 , employee_code
7061 , primary_switch
7062 , schedule_update_code
7063 , setup_teardown_code
7064 , item_ordering
7065 , negative_req_flag
7066 , operation_seq_num
7067 , picking_line_id
7068 , trx_source_line_id
7069 , trx_source_delivery_id
7070 , physical_adjustment_id
7071 , cycle_count_id
7072 , rma_line_id
7073 , customer_ship_id
7074 , currency_code
7075 , currency_conversion_rate
7076 , currency_conversion_type
7077 , currency_conversion_date
7078 , ussgl_transaction_code
7079 , vendor_lot_number
7080 , encumbrance_account
7081 , encumbrance_amount
7082 , ship_to_location
7083 , shipment_number
7084 , transfer_cost
7085 , transportation_cost
7086 , transportation_account
7087 , freight_code
7088 , containers
7089 , waybill_airbill
7090 , expected_arrival_date
7091 , transfer_subinventory
7092 , transfer_organization
7093 , transfer_to_location
7094 , new_average_cost
7095 , value_change
7096 , percentage_change
7097 , material_allocation_temp_id
7098 , demand_source_header_id
7099 , demand_source_line
7100 , demand_source_delivery
7101 , item_segments
7102 , item_description
7103 , item_trx_enabled_flag
7104 , item_location_control_code
7105 , item_restrict_subinv_code
7106 , item_restrict_locators_code
7107 , item_revision_qty_control_code
7108 , item_primary_uom_code
7109 , item_uom_class
7110 , item_shelf_life_code
7111 , item_shelf_life_days
7112 , item_lot_control_code
7113 , item_serial_control_code
7114 , item_inventory_asset_flag
7115 , allowed_units_lookup_code
7116 , department_id
7117 , department_code
7118 , wip_supply_type
7119 , supply_subinventory
7120 , supply_locator_id
7121 , valid_subinventory_flag
7122 , valid_locator_flag
7123 , locator_segments
7124 , current_locator_control_code
7125 , number_of_lots_entered
7126 , wip_commit_flag
7127 , next_lot_number
7128 , lot_alpha_prefix
7129 , next_serial_number
7130 , serial_alpha_prefix
7131 , shippable_flag
7132 , posting_flag
7133 , required_flag
7134 , process_flag
7135 , ERROR_CODE
7136 , error_explanation
7137 , attribute_category
7138 , attribute1
7139 , attribute2
7140 , attribute3
7141 , attribute4
7142 , attribute5
7143 , attribute6
7144 , attribute7
7145 , attribute8
7146 , attribute9
7147 , attribute10
7148 , attribute11
7149 , attribute12
7150 , attribute13
7151 , attribute14
7152 , attribute15
7153 , movement_id
7154 , reservation_quantity
7155 , shipped_quantity
7156 , transaction_line_number
7157 , task_id
7158 , to_task_id
7159 , source_task_id
7160 , project_id
7161 , source_project_id
7162 , pa_expenditure_org_id
7163 , to_project_id
7164 , expenditure_type
7165 , final_completion_flag
7166 , transfer_percentage
7167 , transaction_sequence_id
7168 , material_account
7169 , material_overhead_account
7170 , resource_account
7171 , outside_processing_account
7172 , overhead_account
7173 , flow_schedule
7174 , cost_group_id
7175 , demand_class
7176 , qa_collection_id
7177 , kanban_card_id
7178 , overcompletion_transaction_id
7179 , overcompletion_primary_qty
7180 , overcompletion_transaction_qty
7181 , end_item_unit_number
7182 , scheduled_payback_date
7183 , line_type_code
7184 , parent_transaction_temp_id
7185 , put_away_strategy_id
7186 , put_away_rule_id
7187 , pick_strategy_id
7188 , pick_rule_id
7189 , common_bom_seq_id
7190 , common_routing_seq_id
7191 , cost_type_id
7192 , org_cost_group_id
7193 , move_order_line_id
7194 , task_group_id
7195 , pick_slip_number
7196 , reservation_id
7197 , transaction_status
7198 , transfer_cost_group_id
7199 , lpn_id
7200 , transfer_lpn_id
7201 , content_lpn_id
7202 , cartonization_id
7203 , standard_operation_id
7204 , wms_task_type
7205 , task_priority
7206 , container_item_id
7207 , operation_plan_id
7208 )
7209 (SELECT transaction_header_id
7210 , l_new_temp_id
7211 , source_code
7212 , source_line_id
7213 , transaction_mode
7214 , lock_flag
7215 , SYSDATE
7216 , l_user_id
7217 , SYSDATE
7218 , l_user_id
7219 , last_update_login
7220 , request_id
7221 , program_application_id
7222 , program_id
7223 , program_update_date
7224 , inventory_item_id
7225 , revision
7226 , organization_id
7227 , l_lpn_sub --, subinventory_code changed to LPN's sub bug3765153
7228 , l_lpn_loc --, locator_id changed to LPN's sub bug3765153
7229 , l_qty
7230 , l_pr_qty
7231 , transaction_uom
7232 , transaction_cost
7233 , transaction_type_id
7234 , transaction_action_id
7235 , transaction_source_type_id
7236 , transaction_source_id
7237 , transaction_source_name
7238 , transaction_date
7239 , acct_period_id
7240 , distribution_account_id
7241 , transaction_reference
7242 , requisition_line_id
7243 , requisition_distribution_id
7244 , reason_id
7245 , lot_number
7246 , lot_expiration_date
7247 , serial_number
7248 , receiving_document
7249 , demand_id
7250 , rcv_transaction_id
7251 , move_transaction_id
7252 , completion_transaction_id
7253 , wip_entity_type
7254 , schedule_id
7255 , repetitive_line_id
7256 , employee_code
7257 , primary_switch
7258 , schedule_update_code
7259 , setup_teardown_code
7260 , item_ordering
7261 , negative_req_flag
7262 , operation_seq_num
7263 , picking_line_id
7264 , trx_source_line_id
7265 , trx_source_delivery_id
7266 , physical_adjustment_id
7267 , cycle_count_id
7268 , rma_line_id
7269 , customer_ship_id
7270 , currency_code
7271 , currency_conversion_rate
7272 , currency_conversion_type
7273 , currency_conversion_date
7274 , ussgl_transaction_code
7275 , vendor_lot_number
7276 , encumbrance_account
7277 , encumbrance_amount
7278 , ship_to_location
7279 , shipment_number
7280 , transfer_cost
7281 , transportation_cost
7282 , transportation_account
7283 , freight_code
7284 , containers
7285 , waybill_airbill
7286 , expected_arrival_date
7287 , transfer_subinventory
7288 , transfer_organization
7289 , transfer_to_location
7290 , new_average_cost
7291 , value_change
7292 , percentage_change
7293 , material_allocation_temp_id
7294 , demand_source_header_id
7295 , demand_source_line
7296 , demand_source_delivery
7297 , item_segments
7298 , item_description
7299 , item_trx_enabled_flag
7300 , item_location_control_code
7301 , item_restrict_subinv_code
7302 , item_restrict_locators_code
7303 , item_revision_qty_control_code
7304 , item_primary_uom_code
7305 , item_uom_class
7306 , item_shelf_life_code
7307 , item_shelf_life_days
7308 , item_lot_control_code
7309 , item_serial_control_code
7310 , item_inventory_asset_flag
7311 , allowed_units_lookup_code
7312 , department_id
7313 , department_code
7314 , wip_supply_type
7315 , supply_subinventory
7316 , supply_locator_id
7317 , valid_subinventory_flag
7318 , valid_locator_flag
7319 , locator_segments
7320 , current_locator_control_code
7321 , number_of_lots_entered
7322 , wip_commit_flag
7323 , next_lot_number
7324 , lot_alpha_prefix
7325 , next_serial_number
7326 , serial_alpha_prefix
7327 , shippable_flag
7328 , posting_flag
7329 , required_flag
7330 , process_flag
7331 , ERROR_CODE
7332 , error_explanation
7333 , attribute_category
7334 , attribute1
7335 , attribute2
7336 , attribute3
7337 , attribute4
7338 , attribute5
7339 , attribute6
7340 , attribute7
7341 , attribute8
7342 , attribute9
7343 , attribute10
7344 , attribute11
7345 , attribute12
7346 , attribute13
7347 , attribute14
7348 , attribute15
7349 , movement_id
7350 , reservation_quantity
7351 , shipped_quantity
7352 , transaction_line_number
7353 , task_id
7354 , to_task_id
7355 , source_task_id
7356 , project_id
7357 , source_project_id
7358 , pa_expenditure_org_id
7359 , to_project_id
7360 , expenditure_type
7361 , final_completion_flag
7362 , transfer_percentage
7363 , transaction_sequence_id
7364 , material_account
7365 , material_overhead_account
7366 , resource_account
7367 , outside_processing_account
7368 , overhead_account
7369 , flow_schedule
7370 , cost_group_id
7371 , demand_class
7372 , qa_collection_id
7373 , kanban_card_id
7374 , overcompletion_transaction_id
7375 , overcompletion_primary_qty
7376 , overcompletion_transaction_qty
7377 , end_item_unit_number
7378 , scheduled_payback_date
7379 , line_type_code
7380 , parent_transaction_temp_id
7381 , put_away_strategy_id
7382 , put_away_rule_id
7383 , pick_strategy_id
7384 , pick_rule_id
7385 , common_bom_seq_id
7386 , common_routing_seq_id
7387 , cost_type_id
7388 , org_cost_group_id
7389 , move_order_line_id
7390 , task_group_id
7391 , pick_slip_number
7392 , reservation_id
7393 , transaction_status
7394 , transfer_cost_group_id
7395 , l_temp_lpn_id
7396 , l_transfer_lpn_id
7397 , l_content_lpn_id
7398 , cartonization_id
7399 , standard_operation_id
7400 , wms_task_type
7401 , task_priority
7402 , container_item_id
7403 , operation_plan_id
7404 FROM mtl_material_transactions_temp
7405 WHERE transaction_temp_id = l_temp_id);
7406
7407 -- Update original MMTT with the remaining transaction and primary qty
7408
7409 UPDATE mtl_material_transactions_temp
7410 SET transaction_quantity = transaction_quantity - l_qty
7411 , primary_quantity = primary_quantity - l_pr_qty
7412 WHERE transaction_temp_id = l_temp_id;
7413
7414 IF (l_debug = 1) THEN
7415 mydebug('multiple_lpn_pick: after updating mmtt ');
7416 END IF;
7417
7418 SELECT lot_control_code
7419 , serial_number_control_code
7420 INTO l_lot_code
7421 , l_serial_code
7422 FROM mtl_system_items
7423 WHERE organization_id = l_org_id
7424 AND inventory_item_id = l_item_id;
7425
7426 IF (l_debug = 1) THEN
7427 mydebug('multiple_lpn_pick: l_lot_code = ' || l_lot_code);
7428 mydebug('multiple_lpn_pick: l_serial_code = ' || l_serial_code);
7429 END IF;
7430
7431 IF l_lot_code > 1 THEN -- lot controlled
7432 IF (l_debug = 1) THEN
7433 mydebug('multiple_lpn_pick: Inserting Lots');
7434 END IF;
7435
7436 IF (l_serial_code > 1
7437 AND l_serial_code <> 6) -- lot serial controlled
7438 AND p_sn_allocated_flag = 'Y' -- and allocate to serial ON
7439 THEN
7440 IF (l_debug = 1) THEN
7441 mydebug('multiple_lpn_pick: lot/serial controlled and allocate to serial ON');
7442 END IF;
7443
7444 OPEN lpn_lot_cur;
7445
7446 LOOP -- loop through all lot numbers within this LPN
7447 FETCH lpn_lot_cur INTO l_lpn_lot_number, l_lpn_lot_qty, l_lpn_uom_code;
7448 EXIT WHEN lpn_lot_cur%NOTFOUND;
7449
7450 IF (l_debug = 1) THEN
7451 mydebug('multiple_lpn_pick: Lpn Record: ');
7452 END IF;
7453
7454 IF (l_debug = 1) THEN
7455 mydebug('multiple_lpn_pick: l_lpn_lot_number = ' || l_lpn_lot_number);
7456 mydebug('multiple_lpn_pick: l_lpn_lot_qty = ' || l_lpn_lot_qty);
7457 mydebug('multiple_lpn_pick: l_lpn_uom_code = ' || l_lpn_uom_code);
7458 END IF;
7459
7460 OPEN mtlt_lot_cur(l_lpn_lot_number);
7461
7462 LOOP -- loop through mtlt for the lot number in this lpn contents
7463 FETCH mtlt_lot_cur INTO l_mtlt_rec;
7464 l_lot_primary_qty := l_mtlt_rec.primary_quantity;
7465 l_lot_serial_temp_id := l_mtlt_rec.serial_transaction_temp_id;
7466 EXIT WHEN mtlt_lot_cur%NOTFOUND;
7467
7468 IF (l_debug = 1) THEN
7469 mydebug('multiple_lpn_pick: MTLT Record: ');
7470 mydebug('multiple_lpn_pick: l_lot_primary_qty = ' || l_lot_primary_qty);
7471 END IF;
7472
7473 l_lpn_lot_primary_qty :=
7474 wms_task_dispatch_gen.get_primary_quantity(p_item_id => l_item_id, p_organization_id => l_org_id
7475 , p_from_quantity => l_lpn_lot_qty, p_from_unit => l_lpn_uom_code);
7476
7477 IF (l_debug = 1) THEN
7478 mydebug('multiple_lpn_pick: l_lpn_lot_primary_qty = ' || l_lpn_lot_primary_qty);
7479 END IF;
7480
7481 IF l_lot_primary_qty > l_lpn_lot_primary_qty THEN
7482 -- need to create a new mtlt record and link it to the new mmtt
7483 IF (l_debug = 1) THEN
7484 mydebug('multiple_lpn_pick: create new mtlt');
7485 END IF;
7486
7487 l_mtlt_rec.transaction_temp_id := l_new_temp_id;
7488 l_mtlt_rec.primary_quantity := l_lpn_lot_primary_qty;
7489 l_mtlt_rec.transaction_quantity := l_lpn_lot_primary_qty *(l_qty / l_pr_qty);
7490
7491 -- get new serial_transaction_id
7492
7493 SELECT mtl_material_transactions_s.NEXTVAL
7494 INTO l_new_serial_temp_id
7495 FROM DUAL;
7496
7497 l_mtlt_rec.serial_transaction_temp_id := l_new_serial_temp_id;
7498
7499 IF (l_debug = 1) THEN
7500 mydebug('multiple_lpn_pick: l_new_temp_id = ' || l_new_temp_id);
7501 mydebug('multiple_lpn_pick: primary_quantity = ' || l_mtlt_rec.primary_quantity);
7502 mydebug('multiple_lpn_pick: transaction_quantity = ' || l_mtlt_rec.transaction_quantity);
7503 mydebug('multiple_lpn_pick: l_new_serial_temp_id = ' || l_new_serial_temp_id);
7504 END IF;
7505
7506 inv_rcv_common_apis.insert_mtlt(l_mtlt_rec);
7507 OPEN lpn_ser_cur(l_mtlt_rec.lot_number);
7508
7509 LOOP
7510 FETCH lpn_ser_cur INTO l_serial_number;
7511 EXIT WHEN lpn_ser_cur%NOTFOUND;
7512
7513 UPDATE mtl_serial_numbers_temp
7514 SET transaction_temp_id = l_new_serial_temp_id
7515 WHERE transaction_temp_id = l_lot_serial_temp_id
7516 AND fm_serial_number = l_serial_number
7517 AND to_serial_number = l_serial_number;
7518 END LOOP;
7519
7520 CLOSE lpn_ser_cur;
7521
7522 -- also update the original mtlt record with remaining qty
7523
7524 UPDATE mtl_transaction_lots_temp
7525 SET primary_quantity = primary_quantity - l_mtlt_rec.primary_quantity
7526 , transaction_quantity = transaction_quantity - l_mtlt_rec.transaction_quantity
7527 WHERE transaction_temp_id = p_temp_id
7528 AND lot_number = l_lpn_lot_number;
7529 ELSE
7530 IF (l_debug = 1) THEN
7531 mydebug('multiple_lpn_pick: link original mtlt to new mmtt');
7532 END IF;
7533
7534 -- link the original mtlt to new mmtt
7535 UPDATE mtl_transaction_lots_temp
7536 SET transaction_temp_id = l_new_temp_id
7537 WHERE transaction_temp_id = p_temp_id
7538 AND lot_number = l_lpn_lot_number;
7539 END IF;
7540 END LOOP;
7541
7542 CLOSE mtlt_lot_cur;
7543 END LOOP;
7544
7545 CLOSE lpn_lot_cur;
7546 ELSE -- lot controlled only OR lot seial controlled but Allocate to
7547 -- serial OFF
7548 IF (l_debug = 1) THEN
7549 mydebug('multiple_lpn_pick: lot controlled only OR lot seial controlled but Allocate to serial OFF');
7550 END IF;
7551
7552 OPEN lpn_lot_cur;
7553
7554 LOOP -- loop through all lot numbers within this LPN
7555 FETCH lpn_lot_cur INTO l_lpn_lot_number, l_lpn_lot_qty, l_lpn_uom_code;
7556 EXIT WHEN lpn_lot_cur%NOTFOUND;
7557
7558 IF (l_debug = 1) THEN
7559 mydebug('multiple_lpn_pick: Lpn Record');
7560 END IF;
7561
7562 IF (l_debug = 1) THEN
7563 mydebug('multiple_lpn_pick: l_lpn_lot_number = ' || l_lpn_lot_number);
7564 mydebug('multiple_lpn_pick: l_lpn_lot_qty = ' || l_lpn_lot_qty);
7565 mydebug('multiple_lpn_pick: l_lpn_uom_code = ' || l_lpn_uom_code);
7566 END IF;
7567
7568 OPEN mtlt_lot_cur(l_lpn_lot_number);
7569
7570 LOOP -- loop through mtlt for the lot number in this lpn contents
7571 FETCH mtlt_lot_cur INTO l_mtlt_rec;
7572 l_lot_primary_qty := l_mtlt_rec.primary_quantity;
7573 l_lot_serial_temp_id := l_mtlt_rec.serial_transaction_temp_id;
7574 EXIT WHEN mtlt_lot_cur%NOTFOUND;
7575
7576 IF (l_debug = 1) THEN
7577 mydebug('multiple_lpn_pick: MTLT Record');
7578 mydebug('multiple_lpn_pick: l_lot_primary_qty = ' || l_lot_primary_qty);
7579 END IF;
7580
7581 l_lpn_lot_primary_qty :=
7582 wms_task_dispatch_gen.get_primary_quantity(p_item_id => l_item_id, p_organization_id => l_org_id
7583 , p_from_quantity => l_lpn_lot_qty, p_from_unit => l_lpn_uom_code);
7584
7585 IF (l_debug = 1) THEN
7586 mydebug('multiple_lpn_pick: l_lpn_lot_primary_qty = ' || l_lpn_lot_primary_qty);
7587 END IF;
7588
7589 IF l_lot_primary_qty > l_lpn_lot_primary_qty THEN
7590 IF (l_debug = 1) THEN
7591 mydebug('multiple_lpn_pick: need to create a new mtlt record and link it to the new mmtt');
7592 END IF;
7593
7594 /* Moved the selection of serial temp id here */
7595 IF (l_serial_code > 1
7596 AND l_serial_code <> 6) THEN
7597 SELECT mtl_material_transactions_s.NEXTVAL
7598 INTO l_new_serial_temp_id
7599 FROM DUAL;
7600
7601 l_mtlt_rec.serial_transaction_temp_id := l_new_serial_temp_id;
7602 ELSE
7603 l_new_serial_temp_id := NULL;
7604 END IF;
7605
7606 IF (l_debug = 1) THEN
7607 mydebug('multiple_lpn_pick: create new mtlt');
7608 END IF;
7609
7610 l_mtlt_rec.transaction_temp_id := l_new_temp_id;
7611 l_mtlt_rec.primary_quantity := l_lpn_lot_primary_qty;
7612 l_mtlt_rec.transaction_quantity := l_lpn_lot_primary_qty *(l_qty / l_pr_qty);
7613
7614 IF (l_debug = 1) THEN
7615 mydebug('multiple_lpn_pick: l_new_temp_id = ' || l_new_temp_id);
7616 mydebug('multiple_lpn_pick: primary_quantity = ' || l_mtlt_rec.primary_quantity);
7617 mydebug('multiple_lpn_pick: transaction_quantity = ' || l_mtlt_rec.transaction_quantity);
7618 END IF;
7619
7620 inv_rcv_common_apis.insert_mtlt(l_mtlt_rec);
7621
7622 IF (l_debug = 1) THEN
7623 mydebug('multiple_lpn_pick: l_new_serial_temp_id = ' || l_new_serial_temp_id);
7624 END IF;
7625
7626 -- also update the original mtlt record with remaining
7627
7628 IF (l_debug = 1) THEN
7629 mydebug('multiple_lpn_pick: PriMQty' || l_mtlt_rec.primary_quantity);
7630 END IF;
7631
7632 UPDATE mtl_transaction_lots_temp
7633 SET primary_quantity = primary_quantity - l_mtlt_rec.primary_quantity
7634 , transaction_quantity = transaction_quantity - l_mtlt_rec.transaction_quantity
7635 WHERE transaction_temp_id = p_temp_id
7636 AND lot_number = l_lpn_lot_number;
7637
7638 /* AND Nvl(serial_transaction_temp_id,0) = Nvl(l_new_serial_temp_id,Nvl(serial_transaction_temp_id,0));
7639 */
7640 IF (l_serial_code > 1
7641 AND l_serial_code <> 6) THEN
7642 IF (l_debug = 1) THEN
7643 mydebug('multiple_lpn_pick: Lot/Ser controlled, allocate to serial OFF');
7644 END IF;
7645
7646 OPEN lpn_ser_cur(l_lpn_lot_number);
7647
7648 LOOP
7649 FETCH lpn_ser_cur INTO l_serial_number;
7650 EXIT WHEN lpn_ser_cur%NOTFOUND;
7651
7652 INSERT INTO mtl_serial_numbers_temp
7653 (
7654 transaction_temp_id
7655 , last_update_date
7656 , last_updated_by
7657 , creation_date
7658 , created_by
7659 , fm_serial_number
7660 , to_serial_number
7661 )
7662 VALUES (
7663 l_new_serial_temp_id
7664 , SYSDATE
7665 , l_user_id
7666 , SYSDATE
7667 , l_user_id
7668 , l_serial_number
7669 , l_serial_number
7670 );
7671 END LOOP;
7672
7673 CLOSE lpn_ser_cur;
7674 END IF;
7675 ELSE
7676 IF (l_debug = 1) THEN
7677 mydebug('multiple_lpn_pick: link original mtlt to new mmtt');
7678 END IF;
7679
7680 IF (l_serial_code > 1
7681 AND l_serial_code <> 6) THEN
7682 SELECT mtl_material_transactions_s.NEXTVAL
7683 INTO l_new_serial_temp_id
7684 FROM DUAL;
7685 ELSE
7686 l_new_serial_temp_id := NULL;
7687 END IF;
7688
7689 -- link the original mtlt to new mmtt
7690 UPDATE mtl_transaction_lots_temp
7691 SET transaction_temp_id = l_new_temp_id
7692 , serial_transaction_temp_id = NVL(l_new_serial_temp_id, serial_transaction_temp_id)
7693 WHERE transaction_temp_id = p_temp_id
7694 AND lot_number = l_lpn_lot_number;
7695
7696 /* AS: Need to insert Serial Numbers here also*/
7697 IF (l_serial_code > 1
7698 AND l_serial_code <> 6) THEN
7699 IF (l_debug = 1) THEN
7700 mydebug('multiple_lpn_pick: Lot/Ser controlled, allocate to serial OFF');
7701 END IF;
7702
7703 OPEN lpn_ser_cur(l_lpn_lot_number);
7704
7705 LOOP
7706 FETCH lpn_ser_cur INTO l_serial_number;
7707 EXIT WHEN lpn_ser_cur%NOTFOUND;
7708
7709 INSERT INTO mtl_serial_numbers_temp
7710 (
7711 transaction_temp_id
7712 , last_update_date
7713 , last_updated_by
7714 , creation_date
7715 , created_by
7716 , fm_serial_number
7717 , to_serial_number
7718 )
7719 VALUES (
7720 l_new_serial_temp_id
7721 , SYSDATE
7722 , l_user_id
7723 , SYSDATE
7724 , l_user_id
7725 , l_serial_number
7726 , l_serial_number
7727 );
7728 END LOOP;
7729
7730 CLOSE lpn_ser_cur;
7731 END IF;
7732 END IF;
7733 END LOOP;
7734
7735 CLOSE mtlt_lot_cur;
7736 END LOOP;
7737
7738 CLOSE lpn_lot_cur;
7739 END IF; -- End Serial Loop
7740 ELSIF (l_serial_code > 1
7741 AND l_serial_code <> 6) -- serial controlled only
7742 AND p_sn_allocated_flag = 'Y' THEN -- and allocate to serial ON
7743 IF (l_debug = 1) THEN
7744 mydebug('multiple_lpn_pick: Serial Controlled Only and SN allocate ON');
7745 END IF;
7746
7747 OPEN lpn_ser_cur(NULL);
7748
7749 LOOP
7750 FETCH lpn_ser_cur INTO l_serial_number;
7751 EXIT WHEN lpn_ser_cur%NOTFOUND;
7752
7753 UPDATE mtl_serial_numbers_temp
7754 SET transaction_temp_id = l_new_temp_id
7755 WHERE transaction_temp_id = p_temp_id
7756 AND fm_serial_number = l_serial_number
7757 AND to_serial_number = l_serial_number;
7758 END LOOP;
7759
7760 CLOSE lpn_ser_cur;
7761 ELSIF(l_serial_code > 1
7762 AND l_serial_code <> 6) THEN -- serial controlled only and allocate to serial OFF
7763 IF (l_debug = 1) THEN
7764 mydebug('multiple_lpn_pick: Serial controlled, allocate to serial OFF');
7765 END IF;
7766
7767 OPEN lpn_ser_cur(NULL);
7768
7769 LOOP
7770 FETCH lpn_ser_cur INTO l_serial_number;
7771 EXIT WHEN lpn_ser_cur%NOTFOUND;
7772
7773 INSERT INTO mtl_serial_numbers_temp
7774 (
7775 transaction_temp_id
7776 , last_update_date
7777 , last_updated_by
7778 , creation_date
7779 , created_by
7780 , fm_serial_number
7781 , to_serial_number
7782 )
7783 VALUES (
7784 l_new_temp_id
7785 , SYSDATE
7786 , l_user_id
7787 , SYSDATE
7788 , l_user_id
7789 , l_serial_number
7790 , l_serial_number
7791 );
7792 END LOOP;
7793
7794 CLOSE lpn_ser_cur;
7795 END IF;
7796
7797 -- Insert into tasks table
7798
7799 --Get value from sequence for next task id
7800 SELECT wms_dispatched_tasks_s.NEXTVAL
7801 INTO l_next_task_id
7802 FROM DUAL;
7803
7804 IF (l_debug = 1) THEN
7805 mydebug('multiple_lpn_pick: Before Insert into WMSDT');
7806 END IF;
7807
7808 INSERT INTO wms_dispatched_tasks
7809 (
7810 task_id
7811 , transaction_temp_id
7812 , organization_id
7813 , user_task_type
7814 , person_id
7815 , effective_start_date
7816 , effective_end_date
7817 , equipment_id
7818 , equipment_instance
7819 , person_resource_id
7820 , machine_resource_id
7821 , status
7822 , dispatched_time
7823 , last_update_date
7824 , last_updated_by
7825 , creation_date
7826 , created_by
7827 , task_type
7828 , loaded_time
7829 , operation_plan_id
7830 , move_order_line_id
7831 )
7832 (SELECT l_next_task_id
7833 , l_new_temp_id
7834 , organization_id
7835 , user_task_type
7836 , person_id
7837 , effective_start_date
7838 , effective_end_date
7839 , equipment_id
7840 , equipment_instance
7841 , person_resource_id
7842 , machine_resource_id
7843 , 4
7844 , dispatched_time
7845 , last_update_date
7846 , last_updated_by
7847 , creation_date
7848 , created_by
7849 , task_type
7850 , SYSDATE
7851 , operation_plan_id
7852 , move_order_line_id
7853 --to_date(to_char(sysdate,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH:MI:SS')
7854 FROM wms_dispatched_tasks
7855 WHERE transaction_temp_id = l_temp_id);
7856
7857 IF (l_debug = 1) THEN
7858 mydebug('multiple_lpn_pick: Update WMSDT as loaded');
7859 END IF;
7860
7861 x_temp_id := l_new_temp_id;
7862 x_return_status := fnd_api.g_ret_sts_success;
7863
7864 IF (l_debug = 1) THEN
7865 mydebug('multiple_lpn_pick: Complete x_temp_id = ' || x_temp_id);
7866 END IF;
7867 EXCEPTION
7868 WHEN fnd_api.g_exc_error THEN
7869 x_return_status := fnd_api.g_ret_sts_error;
7870 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7871
7872 IF lpn_ser_cur%ISOPEN THEN
7873 CLOSE lpn_ser_cur;
7874 END IF;
7875
7876 IF lpn_lot_cur%ISOPEN THEN
7877 CLOSE lpn_lot_cur;
7878 END IF;
7879
7880 IF mtlt_lot_cur%ISOPEN THEN
7881 CLOSE mtlt_lot_cur;
7882 END IF;
7883
7884 ROLLBACK TO sp_multiple_lpn_pick;
7885
7886 IF (l_debug = 1) THEN
7887 mydebug('multiple_lpn_pick: raise FND_API.G_EXC_ERROR');
7888 END IF;
7889 WHEN OTHERS THEN
7890 x_return_status := fnd_api.g_ret_sts_unexp_error;
7891 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7892
7893 IF lpn_ser_cur%ISOPEN THEN
7894 CLOSE lpn_ser_cur;
7895 END IF;
7896
7897 IF lpn_lot_cur%ISOPEN THEN
7898 CLOSE lpn_lot_cur;
7899 END IF;
7900
7901 IF mtlt_lot_cur%ISOPEN THEN
7902 CLOSE mtlt_lot_cur;
7903 END IF;
7904
7905 ROLLBACK TO sp_multiple_lpn_pick;
7906
7907 IF (l_debug = 1) THEN
7908 mydebug('multiple_lpn_pick: raise OTHER exception');
7909 END IF;
7910 END multiple_lpn_pick;
7911
7912
7913
7914 PROCEDURE validate_pick_to_lpn
7915 ( p_api_version_number IN NUMBER
7916 , p_init_msg_lst IN VARCHAR2
7917 , x_return_status OUT NOCOPY VARCHAR2
7918 , x_msg_count OUT NOCOPY NUMBER
7919 , x_msg_data OUT NOCOPY VARCHAR2
7920 , p_organization_id IN NUMBER
7921 , p_pick_to_lpn IN VARCHAR2
7922 , p_temp_id IN NUMBER
7923 , p_project_id IN NUMBER
7924 , p_task_id IN NUMBER
7925 ) IS
7926
7927 l_api_version_number CONSTANT NUMBER := 1.0;
7928 l_api_name CONSTANT VARCHAR2(30) := 'validate_pick_to_lpn';
7929 l_pick_to_lpn_exists BOOLEAN := FALSE;
7930 l_current_mmtt_delivery_id NUMBER := NULL;
7931 l_pick_to_lpn_delivery_id NUMBER := NULL;
7932 l_pick_to_lpn_delivery_id2 NUMBER := -999;
7933 l_outermost_lpn_id NUMBER := NULL;
7934
7935 --Added for PJM Integration
7936 l_project_id NUMBER := NULL;
7937 l_task_id NUMBER := NULL;
7938
7939 -- ********************* Start of bug fix 2078002 ********************
7940 l_mmtt_mo_type NUMBER := NULL;
7941 l_mo_type_in_lpn NUMBER := NULL;
7942 l_mmtt_wip_entity_type NUMBER;
7943 l_mmtt_txn_type_id NUMBER;
7944 l_wip_entity_type_in_lpn NUMBER;
7945 -- ********************* End of bug fix 2078002 ********************
7946
7947 l_xfr_sub VARCHAR2(30);
7948 l_xfr_to_location NUMBER;
7949 l_lpn_controlled_flag NUMBER;
7950 l_count NUMBER := 0;
7951 l_item_id NUMBER;
7952 l_operation_plan_id NUMBER;
7953 l_current_carton_grouping_id NUMBER := -999;
7954 l_carton_grouping_id NUMBER := -999;
7955 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7956 l_line_rows WSH_UTIL_CORE.id_tab_type; --Bug#4440585
7957 l_grouping_rows WSH_UTIL_CORE.id_tab_type; --Bug#4440585
7958 l_same_carton_grouping BOOLEAN := FALSE; --Bug#4440585
7959 l_return_status VARCHAR2(2) ;
7960
7961 TYPE lpn_rectype IS RECORD
7962 ( lpn_id wms_license_plate_numbers.lpn_id%TYPE
7963 , lpn_context wms_license_plate_numbers.lpn_context%TYPE
7964 , outermost_lpn_id wms_license_plate_numbers.outermost_lpn_id%TYPE
7965 );
7966
7967 pick_to_lpn_rec lpn_rectype;
7968
7969 TYPE pjm_rectype IS RECORD
7970 ( prj_id mtl_item_locations.project_id%TYPE
7971 , tsk_id mtl_item_locations.task_id%TYPE
7972 );
7973
7974 mtl_pjm_prj_tsk_rec pjm_rectype;
7975 lpn_pjm_prj_tsk_rec pjm_rectype;
7976
7977 CURSOR others_in_mmtt_delivery_cursor(l_lpn_id IN NUMBER) IS
7978 SELECT wda.delivery_id
7979 FROM wsh_delivery_assignments_v wda
7980 , wsh_delivery_details wdd
7981 , mtl_material_transactions_temp mmtt
7982 WHERE mmtt.transfer_lpn_id = l_lpn_id
7983 AND wda.delivery_detail_id = wdd.delivery_detail_id
7984 AND wdd.move_order_line_id = mmtt.move_order_line_id
7985 AND wdd.organization_id = mmtt.organization_id;
7986
7987 CURSOR pick_to_lpn_cursor IS
7988 SELECT lpn_id
7989 , lpn_context
7990 , outermost_lpn_id
7991 FROM wms_license_plate_numbers
7992 WHERE license_plate_number = p_pick_to_lpn;
7993
7994 CURSOR child_lpns_cursor(l_lpn_id IN NUMBER) IS
7995 SELECT lpn_id
7996 FROM wms_license_plate_numbers
7997 START WITH lpn_id = l_lpn_id
7998 CONNECT BY parent_lpn_id = PRIOR lpn_id;
7999
8000 child_lpns_rec child_lpns_cursor%ROWTYPE;
8001
8002 CURSOR current_delivery_cursor IS
8003 SELECT wda.delivery_id
8004 FROM wsh_delivery_assignments_v wda
8005 , wsh_delivery_details wdd
8006 , mtl_material_transactions_temp mmtt
8007 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
8008 AND wdd.move_order_line_id = mmtt.move_order_line_id
8009 AND wdd.organization_id = mmtt.organization_id
8010 AND mmtt.transaction_temp_id = p_temp_id
8011 AND mmtt.organization_id = p_organization_id;
8012
8013 CURSOR drop_delivery_cursor(l_lpn_id IN NUMBER) IS
8014 SELECT wda.delivery_id
8015 FROM wsh_delivery_assignments_v wda, wsh_delivery_details wdd
8016 WHERE wda.parent_delivery_detail_id = wdd.delivery_detail_id
8017 AND wdd.lpn_id = l_lpn_id
8018 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
8019 AND wdd.organization_id = p_organization_id;
8020
8021 --
8022 -- This cursor gets the project and task id fo the lpn to be
8023 -- loaded into
8024 --
8025 CURSOR lpn_project_task_cursor IS
8026 SELECT NVL(mil.project_id, -1)
8027 , NVL(mil.task_id, -1)
8028 FROM mtl_item_locations mil, mtl_material_transactions_temp mmtt
8029 WHERE mil.inventory_location_id = mmtt.transfer_to_location
8030 AND mil.organization_id = mmtt.organization_id
8031 AND mmtt.transfer_lpn_id = p_pick_to_lpn
8032 AND mmtt.organization_id = p_organization_id;
8033
8034 --
8035 -- This cursor gets the project and task id of the task that is about
8036 -- to be packed
8037 --
8038 CURSOR mtl_project_task_cursor IS
8039 SELECT NVL(mil.project_id, -1)
8040 , NVL(mil.task_id, -1)
8041 FROM mtl_item_locations mil, mtl_material_transactions_temp mmtt
8042 WHERE mil.inventory_location_id = mmtt.transfer_to_location
8043 AND mil.organization_id = mmtt.organization_id
8044 AND mmtt.organization_id = p_organization_id
8045 AND mmtt.transaction_temp_id = p_temp_id;
8046
8047 CURSOR current_carton_grouping_cursor IS
8048 SELECT mol.carton_grouping_id
8049 FROM mtl_txn_request_lines mol, mtl_material_transactions_temp mmtt
8050 WHERE mmtt.transaction_temp_id = p_temp_id
8051 AND mmtt.organization_id = mol.organization_id
8052 AND mmtt.move_order_line_id = mol.line_id;
8053
8054 CURSOR others_carton_grouping_cursor(p_lpn_id IN NUMBER) IS
8055 SELECT DISTINCT mol.carton_grouping_id
8056 FROM mtl_txn_request_lines mol, mtl_material_transactions_temp mmtt
8057 WHERE mmtt.transfer_lpn_id = p_lpn_id
8058 AND mmtt.organization_id = mol.organization_id
8059 AND mmtt.move_order_line_id = mol.line_id;
8060 BEGIN
8061 IF (l_debug = 1) THEN
8062 mydebug('validate_pick_to_lpn: Start Validate_pick_to_lpn.');
8063 END IF;
8064
8065 --
8066 -- Standard call to check for call compatibility
8067 --
8068 IF NOT fnd_api.compatible_api_call(l_api_version_number, p_api_version_number, l_api_name, g_pkg_name) THEN
8069 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
8070 fnd_msg_pub.ADD;
8071 RAISE fnd_api.g_exc_error;
8072 END IF;
8073
8074 --
8075 -- Initialize message list.
8076 --
8077 IF fnd_api.to_boolean(p_init_msg_lst) THEN
8078 fnd_msg_pub.initialize;
8079 END IF;
8080
8081 --
8082 -- Initialize API return status to success
8083 --
8084 x_return_status := fnd_api.g_ret_sts_success;
8085
8086 --
8087 -- Begin validation process:
8088 -- Check if drop lpn exists by trying to retrieve its lpn ID.
8089 -- If it does not exist, no further validations required
8090 -- so return success.
8091 --
8092 OPEN pick_to_lpn_cursor;
8093 FETCH pick_to_lpn_cursor INTO pick_to_lpn_rec;
8094
8095 IF pick_to_lpn_cursor%NOTFOUND THEN
8096 l_pick_to_lpn_exists := FALSE;
8097 ELSE
8098 l_pick_to_lpn_exists := TRUE;
8099 END IF;
8100
8101 CLOSE pick_to_lpn_cursor;
8102
8103 IF NOT l_pick_to_lpn_exists THEN
8104 IF (l_debug = 1) THEN
8105 mydebug('validate_pick_to_lpn: Drop LPN is a new LPN, no checking required.');
8106 END IF;
8107 RETURN;
8108 END IF;
8109
8110 wms_task_dispatch_gen.check_pack_lpn
8111 ( p_lpn => p_pick_to_lpn
8112 , p_org_id => p_organization_id
8113 , x_return_status => x_return_status
8114 , x_msg_count => x_msg_count
8115 , x_msg_data => x_msg_data
8116 );
8117
8118
8119
8120 IF x_return_status = fnd_api.g_ret_sts_unexp_error
8121 OR x_return_status = fnd_api.g_ret_sts_error THEN
8122 RAISE fnd_api.g_exc_error;
8123 END IF;
8124
8125
8126
8127 --
8128 -- If the drop lpn was pre-generated, no validations required
8129 -- Changed the context to be updated to 8 instead of 1 as done earlier
8130 --
8131 IF pick_to_lpn_rec.lpn_context = wms_container_pub.lpn_context_pregenerated THEN
8132 --
8133 -- Update the context to "Packing Context" (8)
8134 --
8135 -- Bug5659809: update last_update_date and last_update_by as well
8136 UPDATE wms_license_plate_numbers
8137 SET lpn_context = wms_container_pub.lpn_context_packing
8138 , last_update_date = SYSDATE
8139 , last_updated_by = fnd_global.user_id
8140 WHERE lpn_id = pick_to_lpn_rec.lpn_id;
8141
8142 IF (l_debug = 1) THEN
8143 mydebug('validate_pick_to_lpn: Drop LPN is pre-generated, no checking required.');
8144 END IF;
8145
8146 RETURN;
8147 END IF;
8148
8149
8150 --
8151 -- *********************Start of bug fix 2078002,2095080 ********************
8152 -- Check if the task that is about to pack into the LPN has the same
8153 -- move order type as the tasks already packed into the same LPN
8154 --
8155 SELECT mtrh.move_order_type
8156 , mmtt.transaction_type_id
8157 , mmtt.wip_entity_type
8158 INTO l_mmtt_mo_type
8159 , l_mmtt_txn_type_id
8160 , l_mmtt_wip_entity_type
8161 FROM mtl_txn_request_headers mtrh
8162 , mtl_txn_request_lines mtrl
8163 , mtl_material_transactions_temp mmtt
8164 WHERE mtrh.header_id = mtrl.header_id
8165 AND mtrl.line_id = mmtt.move_order_line_id
8166 AND mmtt.transaction_temp_id = p_temp_id;
8167
8168
8169
8170 BEGIN
8171 SELECT mtrh.move_order_type
8172 , mmtt.wip_entity_type
8173 INTO l_mo_type_in_lpn
8174 , l_wip_entity_type_in_lpn
8175 FROM mtl_txn_request_headers mtrh
8176 , mtl_txn_request_lines mtrl
8177 , mtl_material_transactions_temp mmtt
8178 WHERE mtrh.header_id = mtrl.header_id
8179 AND mtrl.line_id = mmtt.move_order_line_id
8180 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
8181 AND ROWNUM < 2;
8182 EXCEPTION
8183 WHEN no_data_found THEN
8184 NULL;
8185 END;
8186
8187
8188
8189 IF l_mo_type_in_lpn <> l_mmtt_mo_type THEN
8190 IF (l_debug = 1) THEN
8191 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT have different MO type.');
8192 mydebug(' p_temp_id => ' || p_temp_id);
8193 mydebug(' lpn_id => ' || pick_to_lpn_rec.lpn_id);
8194 mydebug(' l_mmtt_mo_type => ' || l_mmtt_mo_type);
8195 mydebug(' l_mo_type_in_lpn => ' || l_mo_type_in_lpn);
8196 END IF;
8197 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_MO_TYPE');
8198 fnd_msg_pub.ADD;
8199 RAISE fnd_api.g_exc_error;
8200 ELSIF l_mmtt_txn_type_id = 35
8201 OR l_mmtt_txn_type_id = 51 THEN -- Mfg pick
8202 IF l_mmtt_wip_entity_type <> l_wip_entity_type_in_lpn THEN
8203 IF (l_debug = 1) THEN
8204 mydebug('validate_pick_to_lpn: This is a manufacturing component pick.');
8205 mydebug('WIP entity type IS NOT the same AS that OF the old mmtt RECORD');
8206 END IF;
8207 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_MFG_MODE');
8208 fnd_msg_pub.ADD;
8209 RAISE fnd_api.g_exc_error;
8210 END IF;
8211 END IF;
8212 -- *********************End of bug fix 2078002,2095080 ********************
8213
8214
8215
8216 --
8217 -- Bug 2355453: Check to see if the LPN is already going to some other lpn
8218 -- controlled sub. In that case, do not allow material to be picked into
8219 -- this LPN
8220 --
8221 IF (l_debug = 1) THEN
8222 mydebug('validate_pick_to_lpn: Check to see if LPN is already going to some other sub/loc');
8223 END IF;
8224
8225 SELECT mmtt.transfer_subinventory
8226 , mmtt.transfer_to_location
8227 , mmtt.inventory_item_id
8228 , mmtt.operation_plan_id
8229 INTO l_xfr_sub
8230 , l_xfr_to_location
8231 , l_item_id
8232 , l_operation_plan_id
8233 FROM mtl_material_transactions_temp mmtt
8234 WHERE mmtt.transaction_temp_id = p_temp_id;
8235
8236 l_lpn_controlled_flag := wms_globals.g_non_lpn_controlled_sub;
8237
8238 IF l_xfr_sub IS NOT NULL THEN
8239 SELECT lpn_controlled_flag
8240 INTO l_lpn_controlled_flag
8241 FROM mtl_secondary_inventories
8242 WHERE organization_id = p_organization_id
8243 AND secondary_inventory_name = l_xfr_sub;
8244 END IF;
8245
8246 IF l_xfr_sub IS NOT NULL
8247 AND l_lpn_controlled_flag = wms_globals.g_lpn_controlled_sub THEN
8248 IF (l_debug = 1) THEN
8249 mydebug('validate_pick_to_lpn: Transfer Sub is LPN Controlled');
8250 END IF;
8251
8252 --
8253 -- Ensure that all remaining picks on the LPN are also for the same sub
8254 --
8255 l_count := 0;
8256
8257 BEGIN
8258 SELECT COUNT(*)
8259 INTO l_count
8260 FROM mtl_material_transactions_temp mmtt
8261 WHERE mmtt.transaction_temp_id <> p_temp_id
8262 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
8263 AND ( NVL(mmtt.transfer_subinventory, 0) <> l_xfr_sub
8264 OR
8265 NVL(mmtt.transfer_to_location, 0) <> l_xfr_to_location
8266 );
8267 EXCEPTION
8268 WHEN NO_DATA_FOUND THEN
8269 l_count := 0;
8270 END;
8271
8272 IF l_count > 0 THEN
8273 IF (l_debug = 1) THEN
8274 mydebug('validate_pick_to_lpn: Drop LPN is going to an LPN controlled sub');
8275 mydebug('validate_pick_to_lpn: Cannot add picks not going to the same sub');
8276 END IF;
8277
8278 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_SUBINV');
8279 fnd_msg_pub.ADD;
8280 RAISE fnd_api.g_exc_error;
8281 END IF;
8282 ELSE
8283 --
8284 -- Current temp ID has a NULL xfer sub (issue txn)
8285 -- or the xfer sub is non LPN-controlled.
8286 -- Ensure that no other picks on the same LPN are to
8287 -- LPN controlled subs
8288 --
8289
8290 IF (l_debug = 1) THEN
8291 mydebug('validate_pick_to_lpn: Transfer Sub is non LPN Controlled or null.');
8292 END IF;
8293
8294 l_count := 0;
8295 BEGIN
8296 SELECT 1
8297 INTO l_count
8298 FROM DUAL
8299 WHERE EXISTS
8300 ( SELECT 'x'
8301 FROM mtl_material_transactions_temp mmtt
8302 , mtl_secondary_inventories msi
8303 WHERE mmtt.transaction_temp_id <> p_temp_id
8304 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
8305 AND msi.organization_id = p_organization_id
8306 AND msi.secondary_inventory_name = mmtt.transfer_subinventory
8307 AND msi.lpn_controlled_flag = wms_globals.g_lpn_controlled_sub
8308 );
8309 EXCEPTION
8310 WHEN NO_DATA_FOUND THEN
8311 l_count := 0;
8312 END;
8313
8314 IF l_count > 0 THEN
8315 IF (l_debug = 1) THEN
8316 mydebug('validate_pick_to_lpn: Drop LPN has pick(s) for an LPN-controlled sub');
8317 END IF;
8318
8319 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_SUBINV');
8320 fnd_msg_pub.ADD;
8321 RAISE fnd_api.g_exc_error;
8322 END IF;
8323 END IF;
8324
8325 --
8326 IF (l_debug = 1) THEN
8327 mydebug('validate_pick_to_lpn: Check to see if LPN is associated with material' ||
8328 ' FOR a different operation plan');
8329 END IF;
8330
8331 l_count := 0;
8332 BEGIN
8333 SELECT COUNT(1)
8334 INTO l_count
8335 FROM mtl_material_transactions_temp mmtt
8336 WHERE mmtt.transaction_temp_id <> p_temp_id
8337 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
8338 AND mmtt.operation_plan_id <> l_operation_plan_id;
8339 EXCEPTION
8340 WHEN NO_DATA_FOUND THEN
8341 l_count := 0;
8342 END;
8343
8344 IF l_count > 0 THEN
8345 IF (l_debug = 1) THEN
8346 mydebug('validate_pick_to_lpn: Drop LPN is associated with material FOR a different operation plan');
8347 END IF;
8348
8349 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_OPER_PLAN');
8350 fnd_msg_pub.ADD;
8351 RAISE fnd_api.g_exc_error;
8352 END IF;
8353
8354
8355 --
8356 -- No further checks required if LPN contains manufacturing picks
8357 -- The checks after this are related to delivery ID and PJM orgs
8358 --
8359 IF l_mmtt_mo_type = 5 THEN
8360 RETURN;
8361 END IF;
8362
8363 -- Now check if the picked LPN
8364 -- belongs to delivery which is different from current delivery
8365 --
8366 OPEN current_delivery_cursor;
8367
8368 LOOP
8369 FETCH current_delivery_cursor INTO l_current_mmtt_delivery_id;
8370 EXIT WHEN l_current_mmtt_delivery_id IS NOT NULL
8371 OR current_delivery_cursor%NOTFOUND;
8372 END LOOP;
8373
8374 CLOSE current_delivery_cursor;
8375
8376 IF (l_debug = 1) THEN
8377 mydebug('validate_pick_to_lpn: l_current_mmtt_delivery_id:' || l_current_mmtt_delivery_id);
8378 END IF;
8379
8380 --
8381 -- If the current MMTT is not associated with a delivery yet
8382 -- then no further checking required, return success
8383 --
8384 IF l_current_mmtt_delivery_id IS NULL THEN
8385 IF (l_debug = 1) THEN
8386 mydebug('validate_pick_to_lpn: Current MMTT is not associated with a delivery');
8387 END IF;
8388
8389 OPEN current_carton_grouping_cursor;
8390 FETCH current_carton_grouping_cursor INTO l_current_carton_grouping_id;
8391 CLOSE current_carton_grouping_cursor;
8392
8393 IF (l_current_carton_grouping_id = -999) THEN
8394 IF (l_debug = 1) THEN
8395 mydebug('validate_pick_to_lpn: can NOT find move order line for current task');
8396 END IF;
8397
8398 fnd_message.set_name('WMS', 'WMS_NO_MOL');
8399 fnd_msg_pub.ADD;
8400 RAISE fnd_api.g_exc_error;
8401 END IF;
8402
8403 IF l_current_carton_grouping_id IS NOT NULL THEN -- found carton_grouping_id
8404 OPEN others_carton_grouping_cursor(pick_to_lpn_rec.lpn_id);
8405
8406 LOOP
8407 FETCH others_carton_grouping_cursor INTO l_carton_grouping_id;
8408 EXIT WHEN l_current_carton_grouping_id = NVL(l_carton_grouping_id, 0)
8409 OR others_carton_grouping_cursor%NOTFOUND;
8410 END LOOP;
8411
8412 CLOSE others_carton_grouping_cursor;
8413
8414 IF l_carton_grouping_id = -999 THEN -- it is the first task in the lpn
8415 mydebug('validate_pick_to_lpn: This is the first task for the lpn ' ||
8416 'and the task without delivery, so ok..');
8417 RETURN;
8418 END IF;
8419
8420 IF l_carton_grouping_id IS NOT NULL THEN
8421 IF l_carton_grouping_id = l_current_carton_grouping_id THEN --the same carton_grouping_id
8422 IF (l_debug = 1) THEN
8423 mydebug('validate_pick_to_lpn: found the task in lpn which has ' ||
8424 'the same carton_grouping_id as current task');
8425 END IF;
8426
8427 OPEN others_in_mmtt_delivery_cursor(pick_to_lpn_rec.lpn_id);
8428 l_pick_to_lpn_delivery_id := -999;
8429
8430 LOOP
8431 FETCH others_in_mmtt_delivery_cursor INTO l_pick_to_lpn_delivery_id;
8432 EXIT WHEN l_pick_to_lpn_delivery_id IS NULL
8433 OR others_in_mmtt_delivery_cursor%NOTFOUND;
8434 END LOOP;
8435
8436 CLOSE others_in_mmtt_delivery_cursor;
8437
8438 IF l_pick_to_lpn_delivery_id = -999 THEN --there is mol, but no wdd or wda, raise error
8439 IF (l_debug = 1) THEN
8440 mydebug('validate_pick_to_lpn: can NOT find either wdd or wda for tasks in the lpn');
8441 END IF;
8442
8443 fnd_message.set_name('WMS', 'WMS_NO_WDD_WDA');
8444 fnd_msg_pub.ADD;
8445 RAISE fnd_api.g_exc_error;
8446 END IF;
8447
8448 IF l_pick_to_lpn_delivery_id IS NULL THEN
8449 IF (l_debug = 1) THEN
8450 mydebug('validate_pick_to_lpn: found a task which has ' ||
8451 'the same carton_grouping_id as current task, and also no delivery.');
8452 END IF;
8453
8454 RETURN;
8455 ELSE
8456 IF (l_debug = 1) THEN
8457 mydebug('validate_pick_to_lpn: other tasks in lpn have different deliveries');
8458 END IF;
8459
8460 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
8461 fnd_msg_pub.ADD;
8462 RAISE fnd_api.g_exc_error;
8463 END IF;
8464 ELSE -- they have different carton_grouping_id
8465 IF (l_debug = 1) THEN
8466 mydebug('validate_pick_to_lpn: other tasks in lpn have different carton grouping id');
8467 END IF;
8468
8469 --Bug#4440585. Added this block
8470 BEGIN
8471 SELECT wdd.delivery_detail_id INTO l_line_rows(1)
8472 FROM wsh_delivery_details wdd
8473 , mtl_material_transactions_temp mmtt
8474 WHERE mmtt.transaction_temp_id = p_temp_id
8475 AND wdd.move_order_line_id = mmtt.move_order_line_id
8476 AND wdd.organization_id = mmtt.organization_id;
8477
8478 SELECT wdd.delivery_detail_id INTO l_line_rows(2)
8479 FROM wsh_delivery_details wdd
8480 , mtl_material_transactions_temp mmtt
8481 WHERE mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
8482 AND wdd.move_order_line_id = mmtt.move_order_line_id
8483 AND wdd.organization_id = mmtt.organization_id
8484 AND rownum<2;
8485 IF (l_debug = 1) THEN
8486 mydebug('validate_pick_to_lpn: Before calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping() to decide if we can load into this LPN');
8487 mydebug('Parameters : delivery_detail_id(1):'|| l_line_rows(1) ||' , delivery_detail_id(2) :'||l_line_rows(2));
8488 END IF;
8489 --call to the shipping API.
8490 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping(
8491 p_line_rows => l_line_rows,
8492 x_grouping_rows => l_grouping_rows,
8493 x_return_status => l_return_status);
8494
8495 IF (l_return_status = FND_API.G_RET_STS_SUCCESS
8496 AND l_grouping_rows (1) = l_grouping_rows(2) ) THEN
8497 l_same_carton_grouping := TRUE;
8498 ELSE
8499 l_same_carton_grouping := FALSE;
8500 END IF;
8501 EXCEPTION
8502 WHEN NO_DATA_FOUND THEN
8503 IF (l_debug = 1) THEN
8504 mydebug('No Data found Exception raised when matching delivery grouping attributes');
8505 l_same_carton_grouping := FALSE;
8506 END IF;
8507 WHEN OTHERS THEN
8508 IF (l_debug = 1) THEN
8509 mydebug('Other Exception raised when matching for delivery grouping attributes');
8510 l_same_carton_grouping := FALSE;
8511 END IF;
8512 END;
8513 IF (l_same_carton_grouping = FALSE) then
8514 fnd_message.set_name('WMS', 'WMS_DIFF_CARTON_GROUP');
8515 fnd_msg_pub.ADD;
8516 RAISE fnd_api.g_exc_error;
8517 END IF; --End of fix for bug#4440585.
8518
8519 END IF;
8520 ELSE -- some of carton_grouping_id is null
8521 IF (l_debug = 1) THEN
8522 mydebug('validate_pick_to_lpn: some of tasks in lpn have NULL carton_grouping_id');
8523 END IF;
8524
8525 fnd_message.set_name('WMS', 'WMS_CARTON_GROUP_NULL');
8526 fnd_msg_pub.ADD;
8527 RAISE fnd_api.g_exc_error;
8528 END IF;
8529 ELSE --carton_grouping_id is null
8530 IF (l_debug = 1) THEN
8531 mydebug('validate_pick_to_lpn: carton_grouping_id of current task is null');
8532 END IF;
8533 --bug3481923 only fail if it is not requisition on repl mo
8534 if (l_mmtt_mo_type not in(1,2)) then
8535 fnd_message.set_name('WMS', 'WMS_CARTON_GROUP_NULL');
8536 fnd_msg_pub.ADD;
8537 RAISE fnd_api.g_exc_error;
8538 end if;
8539 END IF;
8540 END IF;
8541
8542 -- Check if picked LPN has been picked_to in previous tasks, tasks that
8543 -- are still IN MMTT and shipping tables do not have the drop lpn yet
8544
8545 OPEN others_in_mmtt_delivery_cursor(pick_to_lpn_rec.lpn_id);
8546
8547 LOOP
8548 FETCH others_in_mmtt_delivery_cursor INTO l_pick_to_lpn_delivery_id2;
8549 EXIT WHEN l_pick_to_lpn_delivery_id2 IS NOT NULL
8550 OR others_in_mmtt_delivery_cursor%NOTFOUND;
8551 END LOOP;
8552
8553 CLOSE others_in_mmtt_delivery_cursor;
8554
8555 IF (l_debug = 1) THEN
8556 mydebug('validate_pick_to_lpn: l_pick_to_lpn_delivery_id2' || l_pick_to_lpn_delivery_id2);
8557 END IF;
8558
8559 IF l_pick_to_lpn_delivery_id2 IS NOT NULL THEN
8560 IF (l_pick_to_lpn_delivery_id2 <> l_current_mmtt_delivery_id AND
8561 l_pick_to_lpn_delivery_id2 <> -999 ) THEN
8562 IF (l_debug = 1) THEN
8563 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT go to different deliveries.');
8564 END IF;
8565
8566 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
8567 fnd_msg_pub.ADD;
8568 RAISE fnd_api.g_exc_error;
8569 END IF;
8570 ELSIF l_pick_to_lpn_delivery_id2 IS NULL THEN
8571 IF (l_debug = 1) THEN
8572 mydebug('validate_pick_to_lpn: Picked LPN does not have deliveries.');
8573 END IF;
8574
8575 IF l_current_mmtt_delivery_id IS NOT NULL THEN
8576 IF (l_debug = 1) THEN
8577 mydebug('validate_pick_to_lpn: Current task has delivery.');
8578 mydebug('validate_pick_to_lpn: Picked LPN does not have delivery and current task has delivery.');
8579 END IF;
8580
8581 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
8582 fnd_msg_pub.ADD;
8583 RAISE fnd_api.g_exc_error;
8584 END IF;
8585 ELSIF l_pick_to_lpn_delivery_id2 = -999 THEN
8586 IF (l_debug = 1) THEN
8587 mydebug('validate_pick_to_lpn: LPN does not contain other tasks. This is the first task, so ok.');
8588 END IF;
8589 END IF;
8590
8591 IF pick_to_lpn_rec.outermost_lpn_id IS NOT NULL THEN
8592 -- We need to check delivery for outermost lpn or drill down if needed
8593 l_outermost_lpn_id := pick_to_lpn_rec.outermost_lpn_id;
8594 ELSE
8595 -- We need to check delivery for pick_to_lpn or drill down if needed
8596 l_outermost_lpn_id := pick_to_lpn_rec.lpn_id;
8597 END IF;
8598
8599 --
8600 -- Find the outermost LPN's delivery ID
8601 --
8602 OPEN drop_delivery_cursor(l_outermost_lpn_id);
8603 FETCH drop_delivery_cursor INTO l_pick_to_lpn_delivery_id;
8604 CLOSE drop_delivery_cursor;
8605
8606 IF l_pick_to_lpn_delivery_id IS NOT NULL THEN
8607 IF l_pick_to_lpn_delivery_id <> l_current_mmtt_delivery_id THEN
8608 IF (l_debug = 1) THEN
8609 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT go to different deliveries.');
8610 END IF;
8611
8612 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
8613 fnd_msg_pub.ADD;
8614 RAISE fnd_api.g_exc_error;
8615 ELSE
8616 --
8617 -- Picked LPN and current MMTT are on the same delivery
8618 -- return success
8619 --
8620 IF (l_debug = 1) THEN
8621 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT go to same delivery: ' ||
8622 l_pick_to_lpn_delivery_id);
8623 END IF;
8624
8625 RETURN;
8626 END IF;
8627 ELSE
8628 IF (l_debug = 1) THEN
8629 mydebug('validate_pick_to_lpn: Drop LPN does not have a delivery ID, checking child LPNs');
8630 END IF;
8631
8632 OPEN child_lpns_cursor(l_outermost_lpn_id);
8633
8634 LOOP
8635 FETCH child_lpns_cursor INTO child_lpns_rec;
8636 EXIT WHEN child_lpns_cursor%NOTFOUND;
8637
8638 IF child_lpns_cursor%FOUND THEN
8639 OPEN drop_delivery_cursor(child_lpns_rec.lpn_id);
8640 FETCH drop_delivery_cursor INTO l_pick_to_lpn_delivery_id;
8641 CLOSE drop_delivery_cursor;
8642 END IF;
8643
8644 EXIT WHEN l_pick_to_lpn_delivery_id IS NOT NULL;
8645 END LOOP;
8646
8647 CLOSE child_lpns_cursor;
8648
8649 --
8650 -- If the child LPNs also don't have a delivery ID
8651 -- then ok to deposit
8652 --
8653 IF l_pick_to_lpn_delivery_id IS NOT NULL THEN
8654 IF l_pick_to_lpn_delivery_id <> l_current_mmtt_delivery_id THEN
8655 IF (l_debug = 1) THEN
8656 mydebug('validate_pick_to_lpn: LPNs are on diff deliveries.');
8657 END IF;
8658
8659 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
8660 fnd_msg_pub.ADD;
8661 RAISE fnd_api.g_exc_error;
8662 ELSE
8663 --
8664 -- Child LPN has the delivery as the current MMTT, return success
8665 --
8666 IF (l_debug = 1) THEN
8667 mydebug('validate_pick_to_lpn: A child LPN is on the same delivery ' ||
8668 'as that OF the CURRENT MMTT, return success.');
8669 END IF;
8670
8671 RETURN;
8672 END IF;
8673 ELSE
8674 --
8675 -- No child LPNs have a delivery ID yet
8676 -- return success
8677 --
8678 IF (l_debug = 1) THEN
8679 mydebug('validate_pick_to_lpn: Child LPNs do not have a delivery ID either, return success.');
8680 END IF;
8681
8682 RETURN;
8683 END IF;
8684 END IF;
8685
8686 --
8687 -- Fetch the Project/Task id associated with the LPN passed
8688 --
8689 -- PJM Integration:
8690 -- Check if the task that is about to pack into the LPN has the same
8691 -- transfer project_id and task_id as the lpn to which it is going to
8692 -- be loaded into.
8693 -- If yes, proceed, else return
8694 --
8695 IF (p_project_id IS NOT NULL) THEN
8696 OPEN lpn_project_task_cursor;
8697
8698 LOOP
8699 FETCH lpn_project_task_cursor INTO lpn_pjm_prj_tsk_rec;
8700 EXIT WHEN lpn_project_task_cursor%NOTFOUND;
8701 OPEN mtl_project_task_cursor;
8702
8703 LOOP
8704 FETCH mtl_project_task_cursor INTO mtl_pjm_prj_tsk_rec;
8705 EXIT WHEN mtl_project_task_cursor%NOTFOUND;
8706
8707 IF ((mtl_pjm_prj_tsk_rec.prj_id <> lpn_pjm_prj_tsk_rec.prj_id)
8708 AND(mtl_pjm_prj_tsk_rec.tsk_id <> lpn_pjm_prj_tsk_rec.tsk_id)) THEN
8709 RAISE fnd_api.g_exc_error;
8710 END IF;
8711 END LOOP;
8712
8713 CLOSE mtl_project_task_cursor;
8714 END LOOP;
8715
8716 CLOSE lpn_project_task_cursor;
8717 END IF;
8718 EXCEPTION
8719 WHEN fnd_api.g_exc_error THEN
8720 x_return_status := fnd_api.g_ret_sts_error;
8721 -- Get message count and data
8722 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8723
8724 IF (l_debug = 1) THEN
8725 mydebug('validate_pick_to_lpn: @' || x_msg_data || '@');
8726 END IF;
8727
8728 IF others_in_mmtt_delivery_cursor%ISOPEN THEN
8729 CLOSE others_in_mmtt_delivery_cursor;
8730 END IF;
8731
8732 IF pick_to_lpn_cursor%ISOPEN THEN
8733 CLOSE pick_to_lpn_cursor;
8734 END IF;
8735
8736 IF child_lpns_cursor%ISOPEN THEN
8737 CLOSE child_lpns_cursor;
8738 END IF;
8739
8740 IF current_delivery_cursor%ISOPEN THEN
8741 CLOSE current_delivery_cursor;
8742 END IF;
8743
8744 IF drop_delivery_cursor%ISOPEN THEN
8745 CLOSE drop_delivery_cursor;
8746 END IF;
8747
8748 IF lpn_project_task_cursor%ISOPEN THEN
8749 CLOSE lpn_project_task_cursor;
8750 END IF;
8751
8752 IF mtl_project_task_cursor%ISOPEN THEN
8753 CLOSE mtl_project_task_cursor;
8754 END IF;
8755
8756 IF current_carton_grouping_cursor%ISOPEN THEN
8757 CLOSE current_carton_grouping_cursor;
8758 END IF;
8759
8760 IF others_carton_grouping_cursor%ISOPEN THEN
8761 CLOSE others_carton_grouping_cursor;
8762 END IF;
8763 WHEN OTHERS THEN
8764 x_return_status := fnd_api.g_ret_sts_unexp_error;
8765
8766 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8767 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
8768 END IF;
8769
8770 -- Get message count and data
8771 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8772
8773 IF others_in_mmtt_delivery_cursor%ISOPEN THEN
8774 CLOSE others_in_mmtt_delivery_cursor;
8775 END IF;
8776
8777 IF pick_to_lpn_cursor%ISOPEN THEN
8778 CLOSE pick_to_lpn_cursor;
8779 END IF;
8780
8781 IF child_lpns_cursor%ISOPEN THEN
8782 CLOSE child_lpns_cursor;
8783 END IF;
8784
8785 IF current_delivery_cursor%ISOPEN THEN
8786 CLOSE current_delivery_cursor;
8787 END IF;
8788
8789 IF drop_delivery_cursor%ISOPEN THEN
8790 CLOSE drop_delivery_cursor;
8791 END IF;
8792
8793 IF lpn_project_task_cursor%ISOPEN THEN
8794 CLOSE lpn_project_task_cursor;
8795 END IF;
8796
8797 IF mtl_project_task_cursor%ISOPEN THEN
8798 CLOSE mtl_project_task_cursor;
8799 END IF;
8800
8801 IF current_carton_grouping_cursor%ISOPEN THEN
8802 CLOSE current_carton_grouping_cursor;
8803 END IF;
8804
8805 IF others_carton_grouping_cursor%ISOPEN THEN
8806 CLOSE others_carton_grouping_cursor;
8807 END IF;
8808
8809 IF (l_debug = 1) THEN
8810 mydebug('validate_pick_to_lpn: @' || x_msg_data || '@');
8811 END IF;
8812 END validate_pick_to_lpn;
8813
8814 PROCEDURE multiple_pick(
8815 p_pick_qty IN NUMBER
8816 , p_org_id IN NUMBER
8817 , p_temp_id IN NUMBER
8818 , x_return_status OUT NOCOPY VARCHAR2
8819 , x_msg_count OUT NOCOPY NUMBER
8820 , x_msg_data OUT NOCOPY VARCHAR2
8821 , p_sn_allocated_flag IN VARCHAR2
8822 , p_act_uom IN VARCHAR2
8823 , p_from_lpn IN VARCHAR2
8824 , p_from_lpn_id IN NUMBER
8825 , p_to_lpn IN VARCHAR2
8826 , p_ok_to_process OUT NOCOPY VARCHAR2
8827 , p_is_revision_control IN VARCHAR2
8828 , p_is_lot_control IN VARCHAR2
8829 , p_is_serial_control IN VARCHAR2
8830 , p_act_rev IN VARCHAR2
8831 , p_lot IN VARCHAR2
8832 , p_act_sub IN VARCHAR2
8833 , p_act_loc IN NUMBER
8834 , p_container_item_id IN NUMBER
8835 , p_entire_lpn IN VARCHAR2
8836 , p_pick_qty_remaining IN NUMBER
8837 , x_temp_id OUT NOCOPY NUMBER
8838 , p_serial_number IN VARCHAR2
8839 ) IS
8840 l_temp_id NUMBER;
8841 l_msg_cnt NUMBER;
8842 l_msg_data VARCHAR2(2000);
8843 l_return_status VARCHAR2(1);
8844 l_sug_loc NUMBER;
8845 l_sug_sub VARCHAR2(10);
8846 l_act_loc NUMBER;
8847 l_act_sub VARCHAR2(10);
8848 l_to_sub VARCHAR2(10);
8849 l_to_loc NUMBER;
8850 l_sug_uom VARCHAR2(3);
8851 l_sug_rev VARCHAR2(10);
8852 l_fm_serial VARCHAR2(30);
8853 l_to_serial VARCHAR2(30);
8854 l_qty NUMBER;
8855 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
8856 l_lot VARCHAR2(80);
8857 l_pr_qty NUMBER;
8858 l_item_id NUMBER;
8859 l_lot_code NUMBER;
8860 l_serial_code NUMBER;
8861 l_user_id NUMBER;
8862 l_mo_line_id NUMBER;
8863 l_new_temp_id NUMBER;
8864 l_next_task_id NUMBER;
8865 l_txn_header_id NUMBER;
8866 l_new_serial_temp_id NUMBER;
8867 l_lot_ser_seq NUMBER;
8868 l_from_lpn_id NUMBER;
8869 l_to_lpn_id NUMBER;
8870 l_to_lpn_exists NUMBER;
8871 l_to_lpn_context NUMBER;
8872 l_reservation_id NUMBER;
8873 l_is_conf_sub_reservable BOOLEAN;
8874 if_detailed_reservation BOOLEAN;
8875 l_res_sub VARCHAR2(10);
8876 l_to_reservation_id NUMBER;
8877 l_mtl_reservation_tbl inv_reservation_global.mtl_reservation_tbl_type;
8878 l_mtl_reservation_rec inv_reservation_global.mtl_reservation_rec_type;
8879 l_to_serial_number inv_reservation_global.serial_number_tbl_type;
8880 l_mtl_reservation_tbl_count NUMBER;
8881 l_error_code NUMBER;
8882 l_pick_qty_remaining NUMBER;
8883 l_mtlt_rec mtl_transaction_lots_temp%ROWTYPE;
8884 l_local_temp_id NUMBER;
8885 l_orig_txn_qty NUMBER;
8886 l_orig_primary_qty NUMBER;
8887 l_content_parent_lpn_id NUMBER;
8888 l_progress VARCHAR2(4);
8889 l_lpn_exact_match VARCHAR2(1) := 'N';
8890 l_lpn_id NUMBER;
8891 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8892 l_serial_prefix NUMBER;
8893 l_real_serial_prefix VARCHAR2(30);
8894 l_serial_numeric_frm NUMBER;
8895 l_serial_numeric_to NUMBER;
8896 l_serial_count NUMBER := 0 ; --Added for bug 4245565
8897 l_res_loc NUMBER; --Bug#4339517
8898 BEGIN
8899 IF (l_debug = 1) THEN
8900 mydebug('multiple_pick: begins');
8901 END IF;
8902
8903 SAVEPOINT sp_multiple_pick;
8904 l_progress := '10';
8905 l_return_status := fnd_api.g_ret_sts_success;
8906
8907 IF (l_debug = 1) THEN
8908 mydebug('multiple_pick: p_temp_id = ' || p_temp_id);
8909 mydebug('multiple_pick: p_org_id = ' || p_org_id);
8910 mydebug('multiple_pick: p_pick_qty = ' || p_pick_qty);
8911 mydebug('multiple_pick: p_uom_code = ' || p_act_uom);
8912 mydebug('multiple_pick: p_sn_allocated_flag = ' || p_sn_allocated_flag);
8913 mydebug('multiple_pick: p_from_lpn = ' || p_from_lpn);
8914 mydebug('multiple_pick: p_to_lpn = ' || p_to_lpn);
8915 END IF;
8916
8917 l_temp_id := p_temp_id;
8918 l_from_lpn_id := p_from_lpn_id;
8919 l_pick_qty_remaining := p_pick_qty_remaining;
8920 l_act_sub := p_act_sub;
8921 l_act_loc := p_act_loc;
8922 -- initialize the p_ok_to_process
8923 p_ok_to_process := 'true';
8924
8925 IF l_act_loc = 0 THEN
8926 l_act_loc := NULL;
8927 END IF;
8928
8929 l_fm_serial := p_serial_number;
8930 l_to_serial := p_serial_number;
8931 l_lot := p_lot;
8932 l_local_temp_id := l_temp_id;
8933 l_progress := '20';
8934
8935 SELECT transaction_header_id
8936 , subinventory_code
8937 , locator_id
8938 , transfer_subinventory
8939 , transfer_to_location
8940 , revision
8941 , transaction_quantity
8942 , primary_quantity
8943 , transaction_uom
8944 , inventory_item_id
8945 , last_updated_by
8946 , move_order_line_id
8947 , reservation_id
8948 INTO l_txn_header_id
8949 , l_sug_sub
8950 , l_sug_loc
8951 , l_to_sub
8952 , l_to_loc
8953 , l_sug_rev
8954 , l_orig_txn_qty
8955 , l_orig_primary_qty
8956 , l_sug_uom
8957 , l_item_id
8958 , l_user_id
8959 , l_mo_line_id
8960 , l_reservation_id
8961 FROM mtl_material_transactions_temp
8962 WHERE transaction_temp_id = l_temp_id;
8963
8964 l_to_reservation_id := l_reservation_id;
8965 l_progress := '30';
8966
8967 SELECT lot_control_code
8968 , serial_number_control_code
8969 INTO l_lot_code
8970 , l_serial_code
8971 FROM mtl_system_items
8972 WHERE organization_id = p_org_id
8973 AND inventory_item_id = l_item_id;
8974
8975 IF (l_debug = 1) THEN
8976 mydebug('multiple_pick: l_lot_code = ' || l_lot_code);
8977 mydebug('multiple_pick: l_serial_code = ' || l_serial_code);
8978 END IF;
8979
8980 l_progress := '40';
8981
8982 IF l_sug_uom = p_act_uom THEN
8983 l_qty := p_pick_qty;
8984 ELSE
8985 l_qty :=
8986 inv_convert.inv_um_convert(
8987 item_id => l_item_id
8988 , PRECISION => NULL
8989 , from_quantity => p_pick_qty
8990 , from_unit => p_act_uom
8991 , to_unit => l_sug_uom
8992 , from_name => NULL
8993 , to_name => NULL
8994 );
8995
8996 IF (l_debug = 1) THEN
8997 mydebug('multiple_pick: l_qty = ' || l_qty);
8998 END IF;
8999 END IF;
9000
9001 l_progress := '50';
9002 -- Calculate Primary Quantity
9003
9004 l_pr_qty :=
9005 wms_task_dispatch_gen.get_primary_quantity(p_item_id => l_item_id, p_organization_id => p_org_id, p_from_quantity => l_qty
9006 , p_from_unit => l_sug_uom);
9007 l_progress := '60';
9008
9009 IF (l_debug = 1) THEN
9010 mydebug('multiple_pick: l_pr_qty = ' || l_pr_qty);
9011 END IF;
9012
9013 IF (l_from_lpn_id <= 0
9014 OR l_from_lpn_id IS NULL) THEN
9015 IF (l_debug = 1) THEN
9016 mydebug('multiple_pick: Loose items were picked and not LPN');
9017 mydebug('multiple_pick: Validating loose Quantity');
9018 END IF;
9019
9020 inv_txn_validations.check_loose_quantity(
9021 p_api_version_number => 1.0
9022 , p_init_msg_lst => fnd_api.g_false
9023 , x_return_status => l_return_status
9024 , x_msg_count => x_msg_count
9025 , x_msg_data => x_msg_data
9026 , p_organization_id => p_org_id
9027 , p_inventory_item_id => l_item_id
9028 , p_is_revision_control => p_is_revision_control
9029 , p_is_lot_control => p_is_lot_control
9030 , p_is_serial_control => p_is_serial_control
9031 , p_revision => p_act_rev
9032 , p_lot_number => p_lot
9033 , p_transaction_quantity => p_pick_qty
9034 , p_transaction_uom => p_act_uom
9035 , p_subinventory_code => p_act_sub
9036 , p_locator_id => l_act_loc
9037 , p_transaction_temp_id => l_temp_id
9038 , p_ok_to_process => p_ok_to_process
9039 , p_transfer_subinventory => l_to_sub
9040 );
9041 l_progress := '70';
9042
9043 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
9044 IF (l_debug = 1) THEN
9045 mydebug('multiple_pick: unexpected error in check_loose_qty');
9046 END IF;
9047
9048 p_ok_to_process := 'false';
9049 RAISE fnd_api.g_exc_unexpected_error;
9050 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
9051 IF (l_debug = 1) THEN
9052 mydebug('multiple_pick: error in check_loose_qty');
9053 END IF;
9054
9055 p_ok_to_process := 'false';
9056 RAISE fnd_api.g_exc_error;
9057 END IF;
9058
9059 IF p_ok_to_process = 'false' THEN
9060 x_temp_id := 0;
9061 l_temp_id := 0;
9062
9063 IF (l_debug = 1) THEN
9064 mydebug('multiple_pick: After quantity validation. Quantity not enough. Cannot process');
9065 END IF;
9066
9067 x_return_status := fnd_api.g_ret_sts_success;
9068 RETURN;
9069 END IF;
9070 ELSE
9071 IF (l_sug_loc <> l_act_loc
9072 OR l_sug_sub <> l_act_sub) THEN
9073 IF (l_debug = 1) THEN
9074 mydebug('multiple_pick: LPN was picked. Validating qty');
9075 END IF;
9076
9077 inv_txn_validations.check_loose_and_packed_qty(
9078 p_api_version_number => 1.0
9079 , p_init_msg_lst => fnd_api.g_false
9080 , x_return_status => l_return_status
9081 , x_msg_count => x_msg_count
9082 , x_msg_data => x_msg_data
9083 , p_organization_id => p_org_id
9084 , p_inventory_item_id => l_item_id
9085 , p_is_revision_control => p_is_revision_control
9086 , p_is_lot_control => p_is_lot_control
9087 , p_is_serial_control => p_is_serial_control
9088 , p_revision => p_act_rev
9089 , p_lot_number => p_lot
9090 , p_transaction_quantity => p_pick_qty
9091 , p_transaction_uom => p_act_uom
9092 , p_subinventory_code => p_act_sub
9093 , p_locator_id => l_act_loc
9094 , p_transaction_temp_id => l_temp_id
9095 , p_ok_to_process => p_ok_to_process
9096 , p_transfer_subinventory => l_to_sub
9097 );
9098 l_progress := '71';
9099
9100 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
9101 IF (l_debug = 1) THEN
9102 mydebug('multiple_pick: unexpected error in check_loose_and_packed_qty');
9103 END IF;
9104
9105 p_ok_to_process := 'false';
9106 RAISE fnd_api.g_exc_unexpected_error;
9107 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
9108 IF (l_debug = 1) THEN
9109 mydebug('multiple_pick: error in check_and_packed_loose_qty');
9110 END IF;
9111
9112 p_ok_to_process := 'false';
9113 RAISE fnd_api.g_exc_error;
9114 END IF;
9115
9116 IF p_ok_to_process = 'false' THEN
9117 x_temp_id := 0;
9118 l_temp_id := 0;
9119
9120 IF (l_debug = 1) THEN
9121 mydebug('multiple_pick: After quantity validation. Quantity not enough. Cannot process');
9122 END IF;
9123
9124 x_return_status := fnd_api.g_ret_sts_success;
9125 RETURN;
9126 END IF;
9127 END IF;
9128 END IF;
9129
9130 /*
9131 Bug #2075166.
9132 If check_loose_quantity returns p_ok_to_process as 'warning'
9133 then retain it. Else set it to true
9134 */
9135 IF p_ok_to_process <> 'warning' THEN
9136 p_ok_to_process := 'true';
9137 END IF;
9138
9139 l_to_lpn_exists := 0;
9140 l_progress := '80';
9141
9142 BEGIN
9143 SELECT 1
9144 INTO l_to_lpn_exists
9145 FROM wms_license_plate_numbers
9146 WHERE license_plate_number = p_to_lpn
9147 AND organization_id = p_org_id;
9148 EXCEPTION
9149 WHEN NO_DATA_FOUND THEN
9150 l_to_lpn_exists := 0;
9151 END;
9152
9153 IF (l_debug = 1) THEN
9154 mydebug('multiple_pick: l_to_lpn_exists : ' || l_to_lpn_exists);
9155 END IF;
9156
9157 l_progress := '90';
9158
9159 IF (l_to_lpn_exists = 0
9160 AND p_to_lpn <> '-999') THEN
9161 -- LPN does not exist, create it
9162 -- Call Suresh's Create LPN API
9163 IF (l_debug = 1) THEN
9164 mydebug('multiple_pick: Creating LPN');
9165 mydebug('multiple_pick: LPN does not exist');
9166 END IF;
9167
9168 wms_container_pub.create_lpn(
9169 p_api_version => 1.0
9170 , p_init_msg_list => fnd_api.g_false
9171 , p_commit => fnd_api.g_false
9172 , x_return_status => l_return_status
9173 , x_msg_count => l_msg_cnt
9174 , x_msg_data => l_msg_data
9175 , p_lpn => p_to_lpn
9176 , p_organization_id => p_org_id
9177 , p_container_item_id => p_container_item_id
9178 , p_lot_number => l_lot
9179 , p_revision => p_act_rev
9180 , p_serial_number => l_fm_serial
9181 , p_subinventory => l_to_sub
9182 , p_locator_id => l_to_loc
9183 , p_source => 8
9184 , p_cost_group_id => NULL
9185 , x_lpn_id => l_to_lpn_id
9186 );
9187 fnd_msg_pub.count_and_get(p_count => l_msg_cnt, p_data => l_msg_data);
9188
9189 IF (l_msg_cnt = 0) THEN
9190 IF (l_debug = 1) THEN
9191 mydebug('multiple_pick: Successful');
9192 END IF;
9193 ELSIF(l_msg_cnt = 1) THEN
9194 IF (l_debug = 1) THEN
9195 mydebug('multiple_pick: Not Successful');
9196 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
9197 END IF;
9198 ELSE
9199 IF (l_debug = 1) THEN
9200 mydebug('multiple_pick: Not Successful2');
9201 END IF;
9202
9203 FOR i IN 1 .. l_msg_cnt LOOP
9204 l_msg_data := fnd_msg_pub.get(i, 'F');
9205
9206 IF (l_debug = 1) THEN
9207 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
9208 END IF;
9209 END LOOP;
9210 END IF;
9211
9212 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
9213 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
9214 fnd_msg_pub.ADD;
9215 RAISE fnd_api.g_exc_unexpected_error;
9216 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
9217 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
9218 fnd_msg_pub.ADD;
9219 RAISE fnd_api.g_exc_error;
9220 END IF;
9221 ELSIF p_to_lpn <> '-999' THEN
9222 IF (l_debug = 1) THEN
9223 mydebug('multiple_pick: LPN exists');
9224 END IF;
9225
9226 l_progress := '100';
9227
9228 -- LPN exists. Get LPN ID
9229 SELECT lpn_id
9230 , lpn_context
9231 INTO l_to_lpn_id
9232 , l_to_lpn_context
9233 FROM wms_license_plate_numbers
9234 WHERE license_plate_number = p_to_lpn
9235 AND organization_id = p_org_id;
9236 ELSE
9237 l_to_lpn_id := NULL;
9238 END IF;
9239
9240 l_progress := '110';
9241
9242 -- Handle reservations in case of location discrepancy
9243
9244 IF ((l_sug_loc <> l_act_loc
9245 OR l_sug_sub <> l_act_sub)
9246 AND l_reservation_id IS NOT NULL) THEN
9247 IF (l_debug = 1) THEN
9248 mydebug('multiple_pick: Sub/Loc discrepancy: Handling reservations');
9249 END IF;
9250
9251 l_progress := '120';
9252
9253 SELECT subinventory_code,locator_id --Bug#4339517 . Added locator_id
9254 INTO l_res_sub,l_res_loc --Bug#4339517 . Added l_res_loc
9255 FROM mtl_reservations
9256 WHERE reservation_id = l_reservation_id
9257 AND organization_id = p_org_id
9258 AND inventory_item_id = l_item_id;
9259
9260 l_progress := '130';
9261
9262 IF (l_res_sub = ''
9263 OR l_res_sub IS NULL) THEN
9264 IF (l_debug = 1) THEN
9265 mydebug('multiple_pick: No detailed reservation ' || l_res_sub);
9266 END IF;
9267
9268 if_detailed_reservation := FALSE;
9269
9270 --Bug#4339517.Begin
9271 ELSIF ( (l_res_loc ='' OR l_res_loc is null) and l_res_sub=l_act_sub ) THEN
9272 IF (l_debug = 1) THEN
9273 mydebug('multiple_pick:reservation locator is null and subinv matches. So allow transaction');
9274 END IF;
9275 if_detailed_reservation := FALSE;
9276 --End of fix for bug#4339517.
9277 ELSE
9278 IF (l_debug = 1) THEN
9279 mydebug('multiple_pick: There is detailed reservation ' || l_res_sub);
9280 END IF;
9281
9282 if_detailed_reservation := TRUE;
9283 END IF;
9284
9285 l_progress := '140';
9286
9287 IF (if_detailed_reservation = TRUE) THEN
9288 IF (l_debug = 1) THEN
9289 mydebug('multiple_pick: Detailed reservation exists. Cannot pick FROM ANY other location');
9290 END IF;
9291
9292 /*
9293 IF (l_debug = 1) THEN
9294 mydebug('multiple_pick: transfer detailed reservations');
9295 END IF;
9296
9297 wms_task_dispatch_gen.check_is_reservable_sub
9298 (x_return_status => l_return_status,
9299 p_organization_id => p_org_id,
9300 p_subinventory_code => l_act_sub,
9301 x_is_reservable_sub => l_is_conf_sub_reservable);
9302
9303 l_progress := '150';
9304
9305 IF (l_is_conf_sub_reservable = TRUE) THEN
9306
9307 IF (l_debug = 1) THEN
9308 mydebug('multiple_pick: Confirmed sub is reservable');
9309 END IF;
9310
9311 l_mtl_reservation_rec.reservation_id := l_reservation_id;
9312
9313 inv_reservation_pub.query_reservation
9314 (p_api_version_number => 1.0,
9315 x_return_status => l_return_status,
9316 x_msg_count => x_msg_count,
9317 x_msg_data => x_msg_data,
9318 p_query_input => l_mtl_reservation_rec,
9319 x_mtl_reservation_tbl => l_mtl_reservation_tbl,
9320 x_mtl_reservation_tbl_count => l_mtl_reservation_tbl_count,
9321 x_error_code => l_error_code);
9322
9323 l_mtl_reservation_rec := l_mtl_reservation_tbl(1);
9324
9325 l_progress := '160';
9326
9327 IF l_pick_qty_remaining > l_mtl_reservation_tbl(1).primary_reservation_quantity THEN
9328 FND_MESSAGE.SET_NAME('INV','INV_INSUFF_QTY_RSV');
9329 FND_MSG_PUB.Add;
9330 RAISE fnd_api.g_exc_unexpected_error;
9331 END IF;
9332
9333 --Update loc, sub and locator in new reservation
9334 l_mtl_reservation_rec.locator_id := l_act_loc;
9335 l_mtl_reservation_rec.subinventory_code := l_act_sub;
9336 l_mtl_reservation_rec.revision := p_act_rev;
9337 l_mtl_reservation_rec.reservation_quantity := l_qty;
9338 l_mtl_reservation_rec.primary_reservation_quantity := l_pr_qty;
9339
9340 inv_reservation_pub.transfer_reservation
9341 (p_api_version_number => 1.0,
9342 p_init_msg_lst => fnd_api.g_false,
9343 x_return_status => l_return_status,
9344 x_msg_count => x_msg_count,
9345 x_msg_data => x_msg_data,
9346 p_original_rsv_rec => l_mtl_reservation_tbl(1),
9347 p_to_rsv_rec => l_mtl_reservation_rec,
9348 p_original_serial_number => l_to_serial_number,
9349 p_to_serial_number => l_to_serial_number,
9350 x_to_reservation_id => l_to_reservation_id);
9351
9352 l_progress := '170';
9353
9354 -- Return an error if the transfer reservations call failed
9355 IF l_return_status <> fnd_api.g_ret_sts_success THEN
9356 FND_MESSAGE.SET_NAME('INV','INV_TRANSFER_RSV_FAILED');
9357 FND_MSG_PUB.Add;
9358 RAISE fnd_api.g_exc_unexpected_error;
9359 END IF;
9360
9361 ELSE
9362
9363 IF (l_debug = 1) THEN
9364 mydebug('multiple_pick: Confirmed sub is not reservable');
9365 END IF;
9366
9367 IF l_pick_qty_remaining <> 0 THEN
9368
9369 IF (l_debug = 1) THEN
9370 mydebug('multiple_pick: Cannot transfer detailed reservation as confirmed sub is NOT reservable. cannot pick FROM NEW location. throw error');
9371 END IF;
9372
9373 FND_MESSAGE.SET_NAME('INV','INV_TRANSFER_RSV_FAILED');
9374 FND_MSG_PUB.ADD;
9375 RAISE FND_API.g_exc_unexpected_error;
9376
9377 END IF;
9378
9379 END IF;
9380 */
9381 fnd_message.set_name('INV', 'INV_TRANSFER_RSV_FAILED');
9382 fnd_msg_pub.ADD;
9383 RAISE fnd_api.g_exc_unexpected_error;
9384 END IF;
9385 END IF;
9386
9387 --Call any location discrepancy workflow or any other workflow
9388
9389 --Create MMTT if more quantity needs to be picked
9390 l_progress := '200';
9391
9392 IF (l_pick_qty_remaining <> 0) THEN
9393 IF (l_debug = 1) THEN
9394 mydebug('multiple_pick: User has confirmed less quantity');
9395 mydebug('multiple_pick: MMTT lines need to be split..');
9396 END IF;
9397
9398 -- Create new MMTT line with qty and primary qty picked
9399
9400 SELECT mtl_material_transactions_s.NEXTVAL
9401 INTO l_new_temp_id
9402 FROM DUAL;
9403
9404 l_progress := '210';
9405 l_local_temp_id := l_new_temp_id;
9406
9407 IF (l_debug = 1) THEN
9408 mydebug('multiple_pick: l_new_temp_id = ' || l_new_temp_id);
9409 END IF;
9410
9411 -- Create new MMTT line
9412
9413 l_progress := '270';
9414
9415 INSERT INTO mtl_material_transactions_temp
9416 (
9417 transaction_header_id
9418 , transaction_temp_id
9419 , source_code
9420 , source_line_id
9421 , transaction_mode
9422 , lock_flag
9423 , last_update_date
9424 , last_updated_by
9425 , creation_date
9426 , created_by
9427 , last_update_login
9428 , request_id
9429 , program_application_id
9430 , program_id
9431 , program_update_date
9432 , inventory_item_id
9433 , revision
9434 , organization_id
9435 , subinventory_code
9436 , locator_id
9437 , transaction_quantity
9438 , primary_quantity
9439 , transaction_uom
9440 , transaction_cost
9441 , transaction_type_id
9442 , transaction_action_id
9443 , transaction_source_type_id
9444 , transaction_source_id
9445 , transaction_source_name
9446 , transaction_date
9447 , acct_period_id
9448 , distribution_account_id
9449 , transaction_reference
9450 , requisition_line_id
9451 , requisition_distribution_id
9452 , reason_id
9453 , lot_number
9454 , lot_expiration_date
9455 , serial_number
9456 , receiving_document
9457 , demand_id
9458 , rcv_transaction_id
9459 , move_transaction_id
9460 , completion_transaction_id
9461 , wip_entity_type
9462 , schedule_id
9463 , repetitive_line_id
9464 , employee_code
9465 , primary_switch
9466 , schedule_update_code
9467 , setup_teardown_code
9468 , item_ordering
9469 , negative_req_flag
9470 , operation_seq_num
9471 , picking_line_id
9472 , trx_source_line_id
9473 , trx_source_delivery_id
9474 , physical_adjustment_id
9475 , cycle_count_id
9476 , rma_line_id
9477 , customer_ship_id
9478 , currency_code
9479 , currency_conversion_rate
9480 , currency_conversion_type
9481 , currency_conversion_date
9482 , ussgl_transaction_code
9483 , vendor_lot_number
9484 , encumbrance_account
9485 , encumbrance_amount
9486 , ship_to_location
9487 , shipment_number
9488 , transfer_cost
9489 , transportation_cost
9490 , transportation_account
9491 , freight_code
9492 , containers
9493 , waybill_airbill
9494 , expected_arrival_date
9495 , transfer_subinventory
9496 , transfer_organization
9497 , transfer_to_location
9498 , new_average_cost
9499 , value_change
9500 , percentage_change
9501 , material_allocation_temp_id
9502 , demand_source_header_id
9503 , demand_source_line
9504 , demand_source_delivery
9505 , item_segments
9506 , item_description
9507 , item_trx_enabled_flag
9508 , item_location_control_code
9509 , item_restrict_subinv_code
9510 , item_restrict_locators_code
9511 , item_revision_qty_control_code
9512 , item_primary_uom_code
9513 , item_uom_class
9514 , item_shelf_life_code
9515 , item_shelf_life_days
9516 , item_lot_control_code
9517 , item_serial_control_code
9518 , item_inventory_asset_flag
9519 , allowed_units_lookup_code
9520 , department_id
9521 , department_code
9522 , wip_supply_type
9523 , supply_subinventory
9524 , supply_locator_id
9525 , valid_subinventory_flag
9526 , valid_locator_flag
9527 , locator_segments
9528 , current_locator_control_code
9529 , number_of_lots_entered
9530 , wip_commit_flag
9531 , next_lot_number
9532 , lot_alpha_prefix
9533 , next_serial_number
9534 , serial_alpha_prefix
9535 , shippable_flag
9536 , posting_flag
9537 , required_flag
9538 , process_flag
9539 , ERROR_CODE
9540 , error_explanation
9541 , attribute_category
9542 , attribute1
9543 , attribute2
9544 , attribute3
9545 , attribute4
9546 , attribute5
9547 , attribute6
9548 , attribute7
9549 , attribute8
9550 , attribute9
9551 , attribute10
9552 , attribute11
9553 , attribute12
9554 , attribute13
9555 , attribute14
9556 , attribute15
9557 , movement_id
9558 , reservation_quantity
9559 , shipped_quantity
9560 , transaction_line_number
9561 , task_id
9562 , to_task_id
9563 , source_task_id
9564 , project_id
9565 , source_project_id
9566 , pa_expenditure_org_id
9567 , to_project_id
9568 , expenditure_type
9569 , final_completion_flag
9570 , transfer_percentage
9571 , transaction_sequence_id
9572 , material_account
9573 , material_overhead_account
9574 , resource_account
9575 , outside_processing_account
9576 , overhead_account
9577 , flow_schedule
9578 , cost_group_id
9579 , demand_class
9580 , qa_collection_id
9581 , kanban_card_id
9582 , overcompletion_transaction_id
9583 , overcompletion_primary_qty
9584 , overcompletion_transaction_qty
9585 , end_item_unit_number
9586 , scheduled_payback_date
9587 , line_type_code
9588 , parent_transaction_temp_id
9589 , put_away_strategy_id
9590 , put_away_rule_id
9591 , pick_strategy_id
9592 , pick_rule_id
9593 , common_bom_seq_id
9594 , common_routing_seq_id
9595 , cost_type_id
9596 , org_cost_group_id
9597 , move_order_line_id
9598 , task_group_id
9599 , pick_slip_number
9600 , reservation_id
9601 , transaction_status
9602 , transfer_cost_group_id
9603 , lpn_id
9604 , transfer_lpn_id
9605 , content_lpn_id
9606 , cartonization_id
9607 , standard_operation_id
9608 , wms_task_type
9609 , task_priority
9610 , container_item_id
9611 , operation_plan_id
9612 )
9613 (SELECT transaction_header_id
9614 , l_new_temp_id
9615 , source_code
9616 , source_line_id
9617 , transaction_mode
9618 , lock_flag
9619 , SYSDATE
9620 , l_user_id
9621 , SYSDATE
9622 , l_user_id
9623 , last_update_login
9624 , request_id
9625 , program_application_id
9626 , program_id
9627 , program_update_date
9628 , inventory_item_id
9629 , revision
9630 , organization_id
9631 , subinventory_code
9632 , locator_id
9633 , l_qty
9634 , l_pr_qty
9635 , transaction_uom
9636 , transaction_cost
9637 , transaction_type_id
9638 , transaction_action_id
9639 , transaction_source_type_id
9640 , transaction_source_id
9641 , transaction_source_name
9642 , transaction_date
9643 , acct_period_id
9644 , distribution_account_id
9645 , transaction_reference
9646 , requisition_line_id
9647 , requisition_distribution_id
9648 , reason_id
9649 , lot_number
9650 , lot_expiration_date
9651 , serial_number
9652 , receiving_document
9653 , demand_id
9654 , rcv_transaction_id
9655 , move_transaction_id
9656 , completion_transaction_id
9657 , wip_entity_type
9658 , schedule_id
9659 , repetitive_line_id
9660 , employee_code
9661 , primary_switch
9662 , schedule_update_code
9663 , setup_teardown_code
9664 , item_ordering
9665 , negative_req_flag
9666 , operation_seq_num
9667 , picking_line_id
9668 , trx_source_line_id
9669 , trx_source_delivery_id
9670 , physical_adjustment_id
9671 , cycle_count_id
9672 , rma_line_id
9673 , customer_ship_id
9674 , currency_code
9675 , currency_conversion_rate
9676 , currency_conversion_type
9677 , currency_conversion_date
9678 , ussgl_transaction_code
9679 , vendor_lot_number
9680 , encumbrance_account
9681 , encumbrance_amount
9682 , ship_to_location
9683 , shipment_number
9684 , transfer_cost
9685 , transportation_cost
9686 , transportation_account
9687 , freight_code
9688 , containers
9689 , waybill_airbill
9690 , expected_arrival_date
9691 , transfer_subinventory
9692 , transfer_organization
9693 , transfer_to_location
9694 , new_average_cost
9695 , value_change
9696 , percentage_change
9697 , material_allocation_temp_id
9698 , demand_source_header_id
9699 , demand_source_line
9700 , demand_source_delivery
9701 , item_segments
9702 , item_description
9703 , item_trx_enabled_flag
9704 , item_location_control_code
9705 , item_restrict_subinv_code
9706 , item_restrict_locators_code
9707 , item_revision_qty_control_code
9708 , item_primary_uom_code
9709 , item_uom_class
9710 , item_shelf_life_code
9711 , item_shelf_life_days
9712 , item_lot_control_code
9713 , item_serial_control_code
9714 , item_inventory_asset_flag
9715 , allowed_units_lookup_code
9716 , department_id
9717 , department_code
9718 , wip_supply_type
9719 , supply_subinventory
9720 , supply_locator_id
9721 , valid_subinventory_flag
9722 , valid_locator_flag
9723 , locator_segments
9724 , current_locator_control_code
9725 , number_of_lots_entered
9726 , wip_commit_flag
9727 , next_lot_number
9728 , lot_alpha_prefix
9729 , next_serial_number
9730 , serial_alpha_prefix
9731 , shippable_flag
9732 , posting_flag
9733 , required_flag
9734 , process_flag
9735 , ERROR_CODE
9736 , error_explanation
9737 , attribute_category
9738 , attribute1
9739 , attribute2
9740 , attribute3
9741 , attribute4
9742 , attribute5
9743 , attribute6
9744 , attribute7
9745 , attribute8
9746 , attribute9
9747 , attribute10
9748 , attribute11
9749 , attribute12
9750 , attribute13
9751 , attribute14
9752 , attribute15
9753 , movement_id
9754 , reservation_quantity
9755 , shipped_quantity
9756 , transaction_line_number
9757 , task_id
9758 , to_task_id
9759 , source_task_id
9760 , project_id
9761 , source_project_id
9762 , pa_expenditure_org_id
9763 , to_project_id
9764 , expenditure_type
9765 , final_completion_flag
9766 , transfer_percentage
9767 , transaction_sequence_id
9768 , material_account
9769 , material_overhead_account
9770 , resource_account
9771 , outside_processing_account
9772 , overhead_account
9773 , flow_schedule
9774 , cost_group_id
9775 , demand_class
9776 , qa_collection_id
9777 , kanban_card_id
9778 , overcompletion_transaction_id
9779 , overcompletion_primary_qty
9780 , overcompletion_transaction_qty
9781 , end_item_unit_number
9782 , scheduled_payback_date
9783 , line_type_code
9784 , parent_transaction_temp_id
9785 , put_away_strategy_id
9786 , put_away_rule_id
9787 , pick_strategy_id
9788 , pick_rule_id
9789 , common_bom_seq_id
9790 , common_routing_seq_id
9791 , cost_type_id
9792 , org_cost_group_id
9793 , move_order_line_id
9794 , task_group_id
9795 , pick_slip_number
9796 , l_to_reservation_id -- This is the new reservation ID
9797 , transaction_status
9798 , transfer_cost_group_id
9799 , NULL -- lpn_id is null for loose
9800 , l_to_lpn_id -- transfer_lpn_id is toLPN for loose
9801 , NULL -- content_lpn_id is NULL for loose
9802 , cartonization_id
9803 , standard_operation_id
9804 , wms_task_type
9805 , task_priority
9806 , container_item_id
9807 , operation_plan_id
9808 FROM mtl_material_transactions_temp
9809 WHERE transaction_temp_id = l_temp_id);
9810
9811 l_progress := '280';
9812
9813 -- Update original MMTT with the remaining transaction and primary qty
9814
9815 UPDATE mtl_material_transactions_temp
9816 SET transaction_quantity = transaction_quantity - l_qty
9817 , primary_quantity = primary_quantity - l_pr_qty
9818 , lpn_id = null --bug 4046834
9819 , content_lpn_id = null
9820 , transfer_lpn_id = null
9821 , last_update_date = SYSDATE
9822 , last_updated_by = l_user_id
9823 WHERE transaction_temp_id = l_temp_id;
9824
9825 IF (l_debug = 1) THEN
9826 mydebug('multiple_pick: After updating original mmtt ');
9827 END IF;
9828
9829 l_progress := '290';
9830
9831 ----Put the code for lot/serial items here
9832
9833 IF l_lot_code > 1 THEN -- lot controlled
9834 IF (l_debug = 1) THEN
9835 mydebug('multiple_pick: Inserting Lots');
9836 END IF;
9837
9838 SELECT *
9839 INTO l_mtlt_rec
9840 FROM mtl_transaction_lots_temp
9841 WHERE transaction_temp_id = l_temp_id
9842 AND lot_number = p_lot;
9843
9844 l_progress := '300';
9845
9846 IF (l_serial_code > 1
9847 AND l_serial_code <> 6) -- lot serial controlled
9848 AND p_sn_allocated_flag = 'Y' -- and allocate to serial ON
9849 THEN
9850 IF (l_debug = 1) THEN
9851 mydebug('multiple_pick: lot/serial controlled and allocate to serial ON');
9852 END IF;
9853
9854 SELECT mtl_material_transactions_s.NEXTVAL
9855 INTO l_new_serial_temp_id
9856 FROM DUAL;
9857
9858 l_progress := '310';
9859
9860 UPDATE mtl_serial_numbers_temp
9861 SET transaction_temp_id = l_new_serial_temp_id
9862 WHERE transaction_temp_id = l_mtlt_rec.serial_transaction_temp_id
9863 AND fm_serial_number = l_fm_serial
9864 AND to_serial_number = l_to_serial;
9865
9866 l_progress := '320';
9867 l_mtlt_rec.serial_transaction_temp_id := l_new_serial_temp_id;
9868 ELSIF (l_serial_code > 1
9869 AND l_serial_code <> 6) -- lot serial controlled
9870 AND p_sn_allocated_flag = 'N' -- and allocate to serial ON
9871 THEN
9872 IF (l_debug = 1) THEN
9873 mydebug('multiple_pick: lot controlled only OR lot/serial controlled but Allocate to serial OFF');
9874 END IF;
9875
9876 SELECT mtl_material_transactions_s.NEXTVAL
9877 INTO l_new_serial_temp_id
9878 FROM DUAL;
9879
9880 l_progress := '330';
9881 l_mtlt_rec.serial_transaction_temp_id := l_new_serial_temp_id;
9882 END IF;
9883
9884 l_mtlt_rec.transaction_temp_id := l_new_temp_id;
9885 l_mtlt_rec.primary_quantity := l_pr_qty;
9886 l_mtlt_rec.transaction_quantity := l_qty;
9887
9888 IF (l_debug = 1) THEN
9889 mydebug('multiple_pick: Inserting into MTLT');
9890 mydebug('multiple_pick: primary_quantity = ' || l_mtlt_rec.primary_quantity);
9891 mydebug('multiple_pick: transaction_quantity = ' || l_mtlt_rec.transaction_quantity);
9892 mydebug('multiple_pick: serial_transaction_temp_id = ' || l_mtlt_rec.serial_transaction_temp_id);
9893 END IF;
9894
9895 l_progress := '340';
9896 -- Insert new line into MTLT
9897 inv_rcv_common_apis.insert_mtlt(l_mtlt_rec);
9898 l_progress := '350';
9899
9900 UPDATE mtl_transaction_lots_temp
9901 SET primary_quantity = primary_quantity - l_mtlt_rec.primary_quantity
9902 , transaction_quantity = transaction_quantity - l_mtlt_rec.transaction_quantity
9903 , last_update_date = SYSDATE
9904 , last_updated_by = l_user_id
9905 WHERE transaction_temp_id = l_temp_id
9906 AND lot_number = p_lot;
9907
9908 l_progress := '360';
9909
9910 IF (l_debug = 1) THEN
9911 mydebug('multiple_pick: After lot update');
9912 END IF;
9913
9914 --Cleaning original MTLT if txn qty is zero
9915
9916 DELETE FROM mtl_transaction_lots_temp
9917 WHERE transaction_quantity = 0
9918 AND lot_number = p_lot
9919 AND transaction_temp_id = p_temp_id;
9920
9921 l_progress := '370';
9922 ELSIF(l_serial_code > 1
9923 AND l_serial_code <> 6) THEN
9924 -- serial controlled only
9925
9926 IF p_sn_allocated_flag = 'Y' THEN
9927 IF (l_debug = 1) THEN
9928 mydebug('multiple_pick: Serial Controlled Only and SN allocate ON');
9929 END IF;
9930
9931 l_progress := '380';
9932
9933 UPDATE mtl_serial_numbers_temp
9934 SET transaction_temp_id = l_new_temp_id
9935 WHERE transaction_temp_id = l_temp_id
9936 AND fm_serial_number = l_fm_serial
9937 AND to_serial_number = l_to_serial;
9938
9939 l_progress := '390';
9940 END IF;
9941 END IF;
9942
9943 -- Insert into tasks table
9944
9945 l_progress := '400';
9946
9947 --Get value from sequence for next task id
9948 SELECT wms_dispatched_tasks_s.NEXTVAL
9949 INTO l_next_task_id
9950 FROM DUAL;
9951
9952 l_progress := '410';
9953
9954 IF (l_debug = 1) THEN
9955 mydebug('multiple_pick: Before Insert into WMSDT');
9956 END IF;
9957
9958 INSERT INTO wms_dispatched_tasks
9959 (
9960 task_id
9961 , transaction_temp_id
9962 , organization_id
9963 , user_task_type
9964 , person_id
9965 , effective_start_date
9966 , effective_end_date
9967 , equipment_id
9968 , equipment_instance
9969 , person_resource_id
9970 , machine_resource_id
9971 , status
9972 , dispatched_time
9973 , last_update_date
9974 , last_updated_by
9975 , creation_date
9976 , created_by
9977 , task_type
9978 , loaded_time
9979 , operation_plan_id
9980 , move_order_line_id
9981 )
9982 (SELECT l_next_task_id
9983 , l_new_temp_id
9984 , organization_id
9985 , user_task_type
9986 , person_id
9987 , effective_start_date
9988 , effective_end_date
9989 , equipment_id
9990 , equipment_instance
9991 , person_resource_id
9992 , machine_resource_id
9993 , 3
9994 , dispatched_time
9995 , last_update_date
9996 , last_updated_by
9997 , creation_date
9998 , created_by
9999 , task_type
10000 , SYSDATE
10001 , operation_plan_id
10002 , move_order_line_id
10003 --to_date(to_char(sysdate,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH:MI:SS')
10004 FROM wms_dispatched_tasks
10005 WHERE transaction_temp_id = l_temp_id);
10006 END IF;
10007
10008 l_progress := '420';
10009
10010 IF (l_from_lpn_id <> 0
10011 AND l_from_lpn_id IS NOT NULL) THEN
10012 IF (l_debug = 1) THEN
10013 mydebug('multiple_pick: LPN has been picked');
10014 END IF;
10015
10016 IF (l_pick_qty_remaining = 0) THEN
10017 IF (l_debug = 1) THEN
10018 mydebug('multiple_pick: User has picked entire requested quantity. This is packed');
10019 END IF;
10020
10021 l_local_temp_id := l_temp_id;
10022
10023 IF (l_lot = ''
10024 OR l_lot IS NULL) THEN
10025 /* If LPN is an exact match, the multiple pick API is being
10026 called WITH NULL FOR lot AND serial. hence am checking here. If
10027 this IS the CASE, we DO NOT need TO INSERT INTO mtlt OR msnt */
10028 l_lpn_exact_match := 'Y';
10029 END IF;
10030 END IF;
10031
10032 IF (l_debug = 1) THEN
10033 mydebug('multiple_pick: l_local_temp_id : ' || l_local_temp_id);
10034 END IF;
10035
10036 SELECT subinventory_code
10037 , locator_id
10038 INTO l_act_sub
10039 , l_act_loc
10040 FROM wms_license_plate_numbers
10041 WHERE lpn_id = l_from_lpn_id;
10042
10043 l_progress := '430';
10044
10045 IF (p_entire_lpn = 'Y') THEN
10046 -- for nested LPNs selected for picking items from:start
10047 IF (l_debug = 1) THEN
10048 mydebug('multiple_pick: getting outermost LPN for selected lpn ON PKLP');
10049 END IF;
10050
10051 SELECT parent_lpn_id
10052 INTO l_content_parent_lpn_id
10053 FROM wms_license_plate_numbers
10054 WHERE lpn_id = l_from_lpn_id
10055 AND organization_id = p_org_id;
10056
10057 IF (l_debug = 1) THEN
10058 mydebug('multiple_pick: outermost LPN for the selected LPN::' || l_content_parent_lpn_id);
10059 END IF;
10060
10061 IF (l_content_parent_lpn_id <> l_from_lpn_id) THEN
10062 IF (l_debug = 1) THEN
10063 mydebug('multiple_pick: setting lpn_id in MMTT to outermost LPN for nested LPN from PKLP');
10064 END IF;
10065
10066 l_lpn_id := l_content_parent_lpn_id; --TM will take care of this
10067 ELSE
10068 l_lpn_id := NULL;
10069 END IF;
10070
10071 -- for nested LPNs selected for picking items from:end
10072
10073 UPDATE mtl_material_transactions_temp
10074 SET content_lpn_id = l_from_lpn_id
10075 , transfer_lpn_id = l_to_lpn_id
10076 , lpn_id = l_lpn_id
10077 , subinventory_code = l_act_sub
10078 , locator_id = l_act_loc
10079 , transaction_uom = p_act_uom
10080 , last_update_date = SYSDATE
10081 , last_updated_by = l_user_id
10082 WHERE transaction_temp_id = l_local_temp_id;
10083 ELSE
10084 UPDATE mtl_material_transactions_temp
10085 SET transfer_lpn_id = l_to_lpn_id
10086 , lpn_id = l_from_lpn_id
10087 , content_lpn_id = NULL
10088 , subinventory_code = l_act_sub
10089 , locator_id = l_act_loc
10090 , transaction_uom = p_act_uom
10091 , last_update_date = SYSDATE
10092 , last_updated_by = l_user_id
10093 WHERE transaction_temp_id = l_local_temp_id;
10094 END IF;
10095
10096 l_progress := '440';
10097
10098 IF (l_lot_code > 1
10099 AND l_lpn_exact_match = 'N') THEN
10100 l_new_serial_temp_id := NULL;
10101
10102 IF (l_serial_code > 1
10103 AND l_serial_code <> 6) THEN
10104 SELECT NVL(serial_transaction_temp_id, 0)
10105 INTO l_lot_ser_seq
10106 FROM mtl_transaction_lots_temp
10107 WHERE transaction_temp_id = l_local_temp_id
10108 AND lot_number = l_lot;
10109
10110 l_progress := '450';
10111
10112 IF l_lot_ser_seq = 0 THEN
10113 SELECT mtl_material_transactions_s.NEXTVAL
10114 INTO l_new_serial_temp_id
10115 FROM DUAL;
10116 ELSE
10117 l_new_serial_temp_id := l_lot_ser_seq;
10118 END IF;
10119
10120 l_progress := '460';
10121
10122 IF p_sn_allocated_flag = 'N' THEN
10123 INSERT INTO mtl_serial_numbers_temp
10124 (
10125 transaction_temp_id
10126 , last_update_date
10127 , last_updated_by
10128 , creation_date
10129 , created_by
10130 , fm_serial_number
10131 , to_serial_number
10132 )
10133 VALUES (
10134 l_new_serial_temp_id
10135 , SYSDATE
10136 , l_user_id
10137 , SYSDATE
10138 , l_user_id
10139 , l_fm_serial
10140 , l_to_serial
10141 );
10142 END IF;
10143
10144 l_progress := '470';
10145
10146 IF (l_debug = 1) THEN
10147 mydebug('multiple_pick: updating msn for l_new_serial_temp_id = ' || l_new_serial_temp_id);
10148 END IF;
10149
10150 UPDATE mtl_serial_numbers
10151 SET group_mark_id = l_txn_header_id
10152 WHERE inventory_item_id = l_item_id
10153 AND current_organization_id = p_org_id
10154 AND serial_number IN(SELECT fm_serial_number
10155 FROM mtl_serial_numbers_temp msnt
10156 WHERE msnt.transaction_temp_id = l_new_serial_temp_id);
10157
10158 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10159 SELECT count(MSNT.transaction_temp_id)
10160 INTO l_serial_count
10161 FROM Mtl_Serial_Numbers_Temp MSNT
10162 WHERE MSNT.fm_serial_number = l_fm_serial;
10163
10164 /*Bug#3957819.IF the serial number is already used , throw an error*/
10165 IF l_serial_count > 1 THEN
10166 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10167 fnd_msg_pub.ADD;
10168 RAISE fnd_api.g_exc_error;
10169 END IF;
10170 /*End of fix for Bug#3957819 */
10171
10172 l_progress := '480';
10173 END IF;
10174
10175 l_progress := '490';
10176
10177 BEGIN
10178 UPDATE mtl_transaction_lots_temp
10179 SET transaction_quantity = l_qty
10180 , primary_quantity = l_pr_qty
10181 , serial_transaction_temp_id = l_new_serial_temp_id
10182 , last_update_date = SYSDATE
10183 , last_updated_by = l_user_id
10184 WHERE transaction_temp_id = l_local_temp_id
10185 AND lot_number = p_lot;
10186 EXCEPTION
10187 WHEN NO_DATA_FOUND THEN
10188 IF (l_debug = 1) THEN
10189 mydebug('multiple_pick: MTLT did not get updated. Lot number NOT passed');
10190 END IF;
10191 END;
10192
10193 l_progress := '500';
10194 ELSIF(l_serial_code > 1
10195 AND l_serial_code <> 6) THEN
10196 -- serial controlled only
10197 l_progress := '510';
10198
10199 IF p_sn_allocated_flag = 'N' THEN
10200 l_real_serial_prefix := RTRIM(l_fm_serial, '0123456789');
10201 l_serial_numeric_frm := TO_NUMBER(SUBSTR(l_fm_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10202 l_serial_numeric_to := TO_NUMBER(SUBSTR(l_to_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10203 l_serial_prefix := (l_serial_numeric_to - l_serial_numeric_frm) + 1;
10204 mydebug('SERIAL_PREFIX IS :' || l_serial_prefix);
10205
10206 INSERT INTO mtl_serial_numbers_temp
10207 (
10208 transaction_temp_id
10209 , last_update_date
10210 , last_updated_by
10211 , creation_date
10212 , created_by
10213 , fm_serial_number
10214 , to_serial_number
10215 , serial_prefix
10216 )
10217 VALUES (
10218 l_local_temp_id
10219 , SYSDATE
10220 , l_user_id
10221 , SYSDATE
10222 , l_user_id
10223 , l_fm_serial
10224 , l_to_serial
10225 , l_serial_prefix
10226 );
10227 END IF;
10228
10229 l_progress := '520';
10230
10231 UPDATE mtl_serial_numbers
10232 SET group_mark_id = l_txn_header_id
10233 WHERE inventory_item_id = l_item_id
10234 AND current_organization_id = p_org_id
10235 AND serial_number IN(SELECT fm_serial_number
10236 FROM mtl_serial_numbers_temp msnt
10237 WHERE msnt.transaction_temp_id = l_local_temp_id);
10238
10239 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10240 SELECT count(MSNT.transaction_temp_id)
10241 INTO l_serial_count
10242 FROM Mtl_Serial_Numbers_Temp MSNT
10243 WHERE MSNT.fm_serial_number = l_fm_serial;
10244
10245
10246 /*Bug#3957819.IF the serial number is already used , throw an error*/
10247 IF l_serial_count > 1 THEN
10248 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10249 fnd_msg_pub.ADD;
10250 RAISE fnd_api.g_exc_error;
10251 END IF;
10252 /*End of fix for Bug#3957819 */
10253
10254 l_progress := '530';
10255 END IF;
10256 ELSE
10257 l_progress := '540';
10258
10259 IF (l_debug = 1) THEN
10260 mydebug('multiple_pick: Picked loose');
10261 END IF;
10262
10263 IF (l_pick_qty_remaining = 0) THEN
10264 IF (l_debug = 1) THEN
10265 mydebug('multiple_pick: User has picked entire requested quantity. This is loose');
10266 END IF;
10267
10268 IF (l_debug = 1) THEN
10269 mydebug('multiple_pick: l_temp_id:' || l_temp_id);
10270 mydebug('multiple_pick: l_to_lpn_id:' || l_to_lpn_id);
10271 END IF;
10272
10273 l_local_temp_id := l_temp_id;
10274 END IF;
10275
10276 UPDATE mtl_material_transactions_temp
10277 SET transfer_lpn_id = l_to_lpn_id
10278 , lpn_id = NULL
10279 , content_lpn_id = NULL
10280 , subinventory_code = l_act_sub
10281 , locator_id = l_act_loc
10282 , last_update_date = SYSDATE
10283 , last_updated_by = l_user_id
10284 WHERE transaction_temp_id = l_local_temp_id;
10285
10286 l_progress := '550';
10287
10288 IF l_lot_code > 1 THEN
10289 IF (l_serial_code > 1
10290 AND l_serial_code <> 6) THEN
10291 SELECT NVL(serial_transaction_temp_id, 0)
10292 INTO l_lot_ser_seq
10293 FROM mtl_transaction_lots_temp
10294 WHERE transaction_temp_id = l_local_temp_id
10295 AND lot_number = l_lot;
10296
10297 l_progress := '560';
10298
10299 IF l_lot_ser_seq = 0 THEN
10300 SELECT mtl_material_transactions_s.NEXTVAL
10301 INTO l_new_serial_temp_id
10302 FROM DUAL;
10303 ELSE
10304 l_new_serial_temp_id := l_lot_ser_seq;
10305 END IF;
10306
10307 IF p_sn_allocated_flag = 'N' THEN
10308 INSERT INTO mtl_serial_numbers_temp
10309 (
10310 transaction_temp_id
10311 , last_update_date
10312 , last_updated_by
10313 , creation_date
10314 , created_by
10315 , fm_serial_number
10316 , to_serial_number
10317 )
10318 VALUES (
10319 l_new_serial_temp_id
10320 , SYSDATE
10321 , l_user_id
10322 , SYSDATE
10323 , l_user_id
10324 , l_fm_serial
10325 , l_to_serial
10326 );
10327 END IF;
10328
10329 l_progress := '570';
10330
10331 UPDATE mtl_serial_numbers
10332 SET group_mark_id = l_txn_header_id
10333 WHERE inventory_item_id = l_item_id
10334 AND current_organization_id = p_org_id
10335 AND serial_number IN(SELECT fm_serial_number
10336 FROM mtl_serial_numbers_temp
10337 WHERE transaction_temp_id = l_new_serial_temp_id);
10338
10339 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10340 SELECT count(MSNT.transaction_temp_id)
10341 INTO l_serial_count
10342 FROM Mtl_Serial_Numbers_Temp MSNT
10343 WHERE MSNT.fm_serial_number = l_fm_serial;
10344
10345 /*Bug#3957819.IF the serial number is already used , throw an error*/
10346 IF l_serial_count > 1 THEN
10347 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10348 fnd_msg_pub.ADD;
10349 RAISE fnd_api.g_exc_error;
10350 END IF;
10351 /*End of fix for Bug#3957819 */
10352
10353 l_progress := '580';
10354 END IF;
10355
10356 UPDATE mtl_transaction_lots_temp
10357 SET transaction_quantity = l_qty
10358 , primary_quantity = l_pr_qty
10359 , serial_transaction_temp_id = l_new_serial_temp_id
10360 , last_update_date = SYSDATE
10361 , last_updated_by = l_user_id
10362 WHERE transaction_temp_id = l_local_temp_id
10363 AND lot_number = p_lot;
10364
10365 l_progress := '590';
10366 ELSIF(l_serial_code > 1
10367 AND l_serial_code <> 6) THEN
10368 -- serial controlled only
10369
10370 l_progress := '600';
10371
10372 IF p_sn_allocated_flag = 'N' THEN
10373 l_real_serial_prefix := RTRIM(l_fm_serial, '0123456789');
10374 l_serial_numeric_frm := TO_NUMBER(SUBSTR(l_fm_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10375 l_serial_numeric_to := TO_NUMBER(SUBSTR(l_to_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10376 l_serial_prefix := (l_serial_numeric_to - l_serial_numeric_frm) + 1;
10377 mydebug('SERIAL_PREFIX IS :' || l_serial_prefix);
10378
10379 INSERT INTO mtl_serial_numbers_temp
10380 (
10381 transaction_temp_id
10382 , last_update_date
10383 , last_updated_by
10384 , creation_date
10385 , created_by
10386 , fm_serial_number
10387 , to_serial_number
10388 , serial_prefix
10389 )
10390 VALUES (
10391 l_local_temp_id
10392 , SYSDATE
10393 , l_user_id
10394 , SYSDATE
10395 , l_user_id
10396 , l_fm_serial
10397 , l_to_serial
10398 , NVL(l_serial_prefix, 1)
10399 );
10400 END IF;
10401
10402 l_progress := '610';
10403
10404 UPDATE mtl_serial_numbers
10405 SET group_mark_id = l_txn_header_id
10406 WHERE inventory_item_id = l_item_id
10407 AND current_organization_id = p_org_id
10408 AND serial_number IN(SELECT fm_serial_number
10409 FROM mtl_serial_numbers_temp
10410 WHERE transaction_temp_id = l_local_temp_id);
10411
10412 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10413 SELECT count(MSNT.transaction_temp_id)
10414 INTO l_serial_count
10415 FROM Mtl_Serial_Numbers_Temp MSNT
10416 WHERE MSNT.fm_serial_number = l_fm_serial;
10417
10418 /*Bug#3957819.IF the serial number is already used , throw an error*/
10419 IF l_serial_count > 1 THEN
10420 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10421 fnd_msg_pub.ADD;
10422 RAISE fnd_api.g_exc_error;
10423 END IF;
10424 /*End of fix for Bug#3957819 */
10425
10426 l_progress := '620';
10427 END IF;
10428 END IF;
10429
10430 l_progress := '630';
10431
10432 IF p_is_serial_control = 'true'
10433 OR p_is_lot_control = 'true' THEN
10434 IF (l_debug = 1) THEN
10435 mydebug('multiple_pick: Lot or serial controlled. Do not updated wmsdt AS loaded');
10436 END IF;
10437 ELSE
10438 IF (l_debug = 1) THEN
10439 mydebug('multiple_pick: Plain item. Update WMSDT as loaded');
10440 END IF;
10441
10442 UPDATE wms_dispatched_tasks
10443 SET status = 4
10444 , loaded_time = SYSDATE
10445 , --to_date(to_char(sysdate,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH:MI:SS'),
10446 last_update_date = SYSDATE
10447 , last_updated_by = l_user_id
10448 WHERE transaction_temp_id = l_local_temp_id;
10449 END IF;
10450
10451 l_progress := '640';
10452
10453 IF (l_debug = 1) THEN
10454 mydebug('multiple_pick: Before checking for pregenerated LPNs');
10455 END IF;
10456
10457 -- If the pick-to LPN was pregenerated (context = 5),
10458 -- Changed the context to be updated to 8 instead of 1 as done earlier
10459
10460 IF l_to_lpn_context = wms_container_pub.lpn_context_pregenerated THEN
10461 -- Bug5659809: update last_update_date and last_update_by as well
10462 UPDATE wms_license_plate_numbers
10463 SET lpn_context = wms_container_pub.lpn_context_packing
10464 , last_update_date = SYSDATE
10465 , last_updated_by = fnd_global.user_id
10466 WHERE lpn_id = l_to_lpn_id;
10467 END IF;
10468
10469 l_progress := '650';
10470 x_temp_id := l_local_temp_id;
10471 x_return_status := fnd_api.g_ret_sts_success;
10472
10473 IF (l_debug = 1) THEN
10474 mydebug('multiple_pick: End of multiple_pick');
10475 END IF;
10476 EXCEPTION
10477 WHEN fnd_api.g_exc_error THEN
10478 x_return_status := fnd_api.g_ret_sts_error;
10479 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10480 ROLLBACK TO sp_multiple_pick;
10481
10482 IF (l_debug = 1) THEN
10483 mydebug('multiple_pick : raise FND_API.G_EXC_ERROR: ' || SQLERRM);
10484 mydebug('l_progress = ' || l_progress);
10485 END IF;
10486 WHEN OTHERS THEN
10487 x_return_status := fnd_api.g_ret_sts_unexp_error;
10488 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10489 ROLLBACK TO sp_multiple_pick;
10490
10491 IF (l_debug = 1) THEN
10492 mydebug('multiple_pick : raise OTHER exception: ' || SQLERRM);
10493 mydebug('l_progress = ' || l_progress);
10494 END IF;
10495 END multiple_pick;
10496
10497 PROCEDURE create_lpn(
10498 p_organization_id NUMBER
10499 , p_lpn IN VARCHAR2
10500 , p_lpn_id OUT NOCOPY NUMBER
10501 , x_return_status OUT NOCOPY VARCHAR2
10502 , x_msg_count OUT NOCOPY NUMBER
10503 , x_msg_data OUT NOCOPY VARCHAR2
10504 ) IS
10505 l_lpn_rec wms_container_pub.lpn;
10506 l_return_status VARCHAR2(1);
10507 l_msg_count NUMBER;
10508 l_msg_data VARCHAR2(4000);
10509 l_exist NUMBER;
10510 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10511 BEGIN
10512 l_exist := 0;
10513 l_return_status := fnd_api.g_ret_sts_success;
10514
10515 IF (l_debug = 1) THEN
10516 mydebug('In create LPN..');
10517 END IF;
10518
10519 l_lpn_rec.license_plate_number := p_lpn;
10520 l_exist := 0;
10521
10522 /* SELECT COUNT(*) INTO l_exist FROM wms_license_plate_numbers
10523 WHERE license_plate_number=p_lpn;*/
10524 BEGIN
10525 SELECT 1
10526 INTO l_exist
10527 FROM DUAL
10528 WHERE EXISTS(SELECT 1
10529 FROM wms_license_plate_numbers
10530 WHERE license_plate_number = p_lpn);
10531 EXCEPTION
10532 WHEN NO_DATA_FOUND THEN
10533 l_exist := 0;
10534 END;
10535
10536 IF l_exist = 0 THEN
10537 IF (l_debug = 1) THEN
10538 mydebug('LPN Does not exist..');
10539 END IF;
10540
10541 wms_container_pub.create_lpn(
10542 p_api_version => 1.0
10543 , x_return_status => l_return_status
10544 , x_msg_count => l_msg_count
10545 , x_msg_data => x_msg_data
10546 , p_lpn => p_lpn
10547 , p_organization_id => p_organization_id
10548 , x_lpn_id => p_lpn_id
10549 , p_source => 3
10550 );
10551 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => x_msg_data);
10552
10553 IF (l_msg_count = 0) THEN
10554 IF (l_debug = 1) THEN
10555 mydebug('Successful');
10556 END IF;
10557 ELSIF(l_msg_count = 1) THEN
10558 IF (l_debug = 1) THEN
10559 mydebug('Not Successful');
10560 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
10561 END IF;
10562 ELSE
10563 IF (l_debug = 1) THEN
10564 mydebug('Not Successful2');
10565 END IF;
10566
10567 FOR i IN 1 .. l_msg_count LOOP
10568 x_msg_data := fnd_msg_pub.get(i, 'F');
10569
10570 IF (l_debug = 1) THEN
10571 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
10572 END IF;
10573 END LOOP;
10574 END IF;
10575
10576 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
10577 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
10578 fnd_msg_pub.ADD;
10579 RAISE fnd_api.g_exc_unexpected_error;
10580 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
10581 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
10582 fnd_msg_pub.ADD;
10583 RAISE fnd_api.g_exc_error;
10584 END IF;
10585 ELSE -- lpn exists
10586 SELECT lpn_id
10587 INTO p_lpn_id
10588 FROM wms_license_plate_numbers
10589 WHERE license_plate_number = p_lpn;
10590 END IF;
10591
10592 x_return_status := fnd_api.g_ret_sts_success;
10593 EXCEPTION
10594 WHEN fnd_api.g_exc_error THEN
10595 x_return_status := fnd_api.g_ret_sts_error;
10596 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10597 WHEN OTHERS THEN
10598 x_return_status := fnd_api.g_ret_sts_unexp_error;
10599 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10600 END create_lpn;
10601
10602 -- p sub, p_loc are user entered values
10603 -- p_orig_sub, p_orig_loc are system suggested values
10604 PROCEDURE pick_drop(
10605 p_temp_id IN NUMBER
10606 , p_txn_header_id IN NUMBER
10607 , p_org_id IN NUMBER
10608 , x_return_status OUT NOCOPY VARCHAR2
10609 , x_msg_count OUT NOCOPY NUMBER
10610 , x_msg_data OUT NOCOPY VARCHAR2
10611 , p_from_lpn_id IN NUMBER
10612 , p_drop_lpn IN VARCHAR2
10613 , p_loc_reason_id IN NUMBER
10614 , p_sub IN VARCHAR
10615 , p_loc IN NUMBER
10616 , p_orig_sub IN VARCHAR
10617 , p_orig_loc IN VARCHAR
10618 , p_user_id IN NUMBER
10619 , p_task_type IN NUMBER
10620 , p_commit IN VARCHAR2
10621 ) IS
10622 l_temp_id NUMBER;
10623 l_org_id NUMBER;
10624 l_cnt NUMBER;
10625 l_return_status VARCHAR2(1);
10626 l_msg_count NUMBER;
10627 l_msg_data VARCHAR2(5000);
10628 l_mmtt_line_id NUMBER;
10629 l_mmtt_qty NUMBER;
10630 l_txn_header_id NUMBER;
10631 l_txn_ret NUMBER;
10632 l_transfer_sub VARCHAR2(10);
10633 l_transfer_loc NUMBER;
10634 l_content_lpn_id NUMBER;
10635 l_lpn_id NUMBER;
10636 l_transfer_lpn_id NUMBER;
10637 l_tran_type_id NUMBER;
10638 l_flow NUMBER;
10639 l_label_status NUMBER;
10640 l_del_det_id NUMBER;
10641 l_mo_line_id NUMBER;
10642 l_label_transaction_id NUMBER;
10643 l_period_id NUMBER;
10644 l_open_past_period BOOLEAN;
10645 l_isdroplpnentered BOOLEAN;
10646 l_xfrlpnid NUMBER;
10647 l_lpn_context NUMBER;
10648 l_tran_source_type_id NUMBER;
10649 l_tran_action_id NUMBER;
10650 -- local variables for workflow
10651 l_wf NUMBER;
10652 l_sub VARCHAR(30);
10653 l_loc NUMBER;
10654 l_orig_sub VARCHAR2(30);
10655 l_orig_loc NUMBER;
10656 l_loc_reason_id NUMBER;
10657 l_user_id NUMBER;
10658 l_task_type NUMBER;
10659 l_inventory_item_id NUMBER;
10660 l_from_sub VARCHAR2(30);
10661 l_from_loc NUMBER;
10662 l_shipped_wdd_count_in_lpn NUMBER;
10663 l_is_transfer_sub_lpn NUMBER; /* 3150462*/
10664 l_check_tasks NUMBER :=0; --Bug 5318552
10665
10666
10667
10668 CURSOR mmtt_csr IS
10669 SELECT mmtt.transaction_temp_id
10670 FROM mtl_material_transactions_temp mmtt
10671 WHERE mmtt.transaction_header_id = l_txn_header_id
10672 AND mmtt.organization_id = l_org_id;
10673
10674 -- VARAJAGO for bug 5222498, added to fetch the group_mark_id details of MSN
10675 CURSOR msn_stg_mov_csr (lpnid_in_msn NUMBER) IS
10676 SELECT serial_number
10677 , organization_id
10678 , inventory_item_id
10679 , transaction_temp_id, lpn_id
10680 FROM wms_wsh_wdd_gtemp WHERE lpn_id = lpnid_in_msn;
10681
10682 -- DHERRING additional cursor to find all nested LPNs
10683 CURSOR child_lpns_csr IS
10684 SELECT lpn_id
10685 FROM wms_license_plate_numbers
10686 START WITH lpn_id = l_xfrlpnid
10687 CONNECT BY PRIOR lpn_id = parent_lpn_id;
10688
10689 -- End of changes for 5222498
10690 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10691
10692 --==================================================
10693 --R12.1 Replenishment Project (6681109) Starts
10694
10695 l_index NUMBER;
10696 l_b_index NUMBER;
10697
10698 L_ORDER_ID_SORT VARCHAR2(4) := NULL;
10699 L_INVOICE_VALUE_SORT VARCHAR2(4) := NULL;
10700 L_SCHEDULE_DATE_SORT VARCHAR2(4) := NULL;
10701 L_TRIP_STOP_DATE_SORT VARCHAR2(4) := NULL;
10702 L_SHIPMENT_PRI_SORT VARCHAR2(4) := NULL;
10703
10704
10705 l_detail_info_tab WSH_INTERFACE_EXT_GRP.delivery_details_Attr_tbl_Type;
10706 l_in_rec WSH_INTERFACE_EXT_GRP.detailInRecType;
10707 l_out_rec WSH_INTERFACE_EXT_GRP.detailOutRecType;
10708
10709 l_detail_id_tab WSH_UTIL_CORE.id_tab_type;
10710 l_action_prms WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
10711 l_action_out_rec WSH_GLBL_VAR_STRCT_GRP.dd_action_out_rec_type;
10712 l_rsv_tbl_tmp inv_reservation_global.mtl_reservation_tbl_type;
10713
10714 L_delivery_detail_id NUMBER;
10715 l_req_quantity_uom VARCHAR2(3);
10716 L_SHIP_SET_ID NUMBER;
10717 L_SHIP_MODEL_ID NUMBER;
10718 l_exists_in_wrd NUMBER;
10719 l_not_mmtt_row NUMBER;
10720
10721 l_prev_mol NUMBER;
10722 l_wrd_pri_quantity NUMBER;
10723 l_requested_quantity NUMBER;
10724 l_demand_pri_qty NUMBER;
10725 l_primary_uom VARCHAR(3);
10726 l_repl_type NUMBER;
10727 l_repl_level NUMBER := 1; -- TO DECIDE WHETHER TO PICK_RELEASE DEMAND OR allocate repl MO FOR LEVEL > 1
10728 l_batch_id NUMBER;
10729 l_prev_batch_id NUMBER;
10730 l_batch_id_tab num_tab;
10731 l_pick_rel_tab pick_release_tab;
10732 j NUMBER;
10733
10734 L_REMAINING_MMTT_QTY NUMBER;
10735 l_release_sequence_rule_id NUMBER;
10736 l_demand_type_id NUMBER;
10737 l_demand_header_id NUMBER;
10738 l_demand_line_id NUMBER;
10739
10740 l_attr1 NUMBER;
10741 l_attr2 NUMBER;
10742 l_attr3 NUMBER;
10743 l_attr4 NUMBER;
10744 l_attr5 NUMBER;
10745
10746
10747 CURSOR c_mark_demand_rc_csr(p_mo_line_id NUMBER) IS
10748 SELECT WDD.DELIVERY_DETAIL_ID,
10749 MTRL.SHIP_SET_ID,
10750 MTRL.SHIP_MODEL_ID,
10751 WRD.primary_quantity WRD_PRI_QUANTITY,
10752 Nvl(WDD.requested_quantity,0) REQUESTED_QUANTITY,
10753 WRD.primary_uom,
10754 wrd.repl_type,
10755 wrd.repl_level, -- TO DECIDE WHETHER TO PICK_RELEASE DEMAND OR allocate repl MO FOR LEVEL > 1
10756 wdd.batch_id,
10757 wrd.demand_type_id
10758 FROM
10759 wms_replenishment_details WRD,
10760 MTL_TXN_REQUEST_LINES MTRL,
10761 WSH_DELIVERY_DETAILS WDD
10762 WHERE WRD.ORGANIZATION_ID = P_ORG_ID
10763 AND WRD.SOURCE_LINE_ID = p_mo_line_id
10764 AND wrd.demand_type_id <> 4 -- true only for first level of REPL
10765 AND WRD.SOURCE_LINE_ID = MTRL.LINE_ID
10766 AND WRD.SOURCE_HEADER_ID = MTRL.HEADER_ID
10767 AND WRD.ORGANIZATION_ID = MTRL.ORGANIZATION_ID
10768 AND WRD.INVENTORY_ITEM_ID = MTRL.INVENTORY_ITEM_ID
10769 AND WRD.DEMAND_LINE_DETAIL_ID = WDD.delivery_detail_id
10770 AND WRD.ORGANIZATION_ID = WDD.organization_id
10771 ORDER BY wdd.batch_id, DEMAND_SORT_ORDER;
10772
10773 CURSOR c_multi_level_repl_alloc(p_mo_line_id NUMBER) IS
10774 SELECT wrd.demand_header_id,
10775 wrd.demand_line_id,
10776 WRD.primary_quantity WRD_PRI_QUANTITY,
10777 wrd.repl_level, -- TO DECIDE WHETHER TO PICK_RELEASE DEMAND OR allocate repl MO FOR LEVEL > 1
10778 wrd.demand_type_id
10779 FROM
10780 wms_replenishment_details WRD,
10781 MTL_TXN_REQUEST_LINES MTRL
10782 WHERE WRD.ORGANIZATION_ID = P_ORG_ID
10783 AND WRD.SOURCE_LINE_ID = p_mo_line_id
10784 AND wrd.demand_type_id = 4 -- true for multi level repl (>1)
10785 AND WRD.SOURCE_LINE_ID = MTRL.LINE_ID
10786 AND WRD.SOURCE_HEADER_ID = MTRL.HEADER_ID
10787 AND WRD.ORGANIZATION_ID = MTRL.ORGANIZATION_ID
10788 AND WRD.INVENTORY_ITEM_ID = MTRL.inventory_item_id
10789 ORDER BY DEMAND_SORT_ORDER;
10790
10791
10792 /* this cursor will consider only those demands that are not tracked in WRD table but we have created replenishment move orders for them */
10793 CURSOR c_untracked_dmd_repl_cur(P_ITEM_ID NUMBER) IS
10794 SELECT
10795 WDD.DELIVERY_DETAIL_ID,
10796 wdd.requested_quantity AS PRIMARY_QUANTITY, -- this is always stored in primary UOM
10797 wdd.requested_quantity_uom,
10798
10799 -- get for sort_attribute1
10800 To_number(DECODE(l_release_sequence_rule_id,
10801 null,
10802 null,
10803 DECODE(g_ordered_psr(1).attribute_name,
10804 'ORDER_NUMBER',
10805 DECODE(L_ORDER_ID_SORT,
10806 'ASC',
10807 To_number(wdd.source_header_number),
10808 'DESC',
10809 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10810 null),
10811 'SHIPMENT_PRIORITY',
10812 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10813 'High',
10814 20,
10815 'Standard',
10816 10,
10817 NULL),
10818 'INVOICE_VALUE',
10819 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10820 L_INVOICE_VALUE_SORT),
10821 'SCHEDULE_DATE',
10822 DECODE(L_SCHEDULE_DATE_SORT,
10823 'ASC',
10824 (WDD.DATE_SCHEDULED -
10825 TO_DATE('01-01-1700 23:59:59',
10826 'DD-MM-YYYY HH24:MI:SS')),
10827 'DESC',
10828 (TO_DATE('01-01-1700 23:59:59',
10829 'DD-MM-YYYY HH24:MI:SS') -
10830 WDD.DATE_SCHEDULED),
10831 null),
10832 'TRIP_STOP_DATE',
10833 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10834 L_TRIP_STOP_DATE_SORT),
10835 NULL))) as sort_attribute1,
10836
10837 -- get for sort_attribute2
10838 To_number(DECODE(l_release_sequence_rule_id,
10839 null,
10840 null,
10841 DECODE(g_ordered_psr(2).attribute_name,
10842 'ORDER_NUMBER',
10843 DECODE(L_ORDER_ID_SORT,
10844 'ASC',
10845 To_number(wdd.source_header_number),
10846 'DESC',
10847 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10848 null),
10849 'SHIPMENT_PRIORITY',
10850 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10851 'High',
10852 20,
10853 'Standard',
10854 10,
10855 NULL),
10856 'INVOICE_VALUE',
10857 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10858 L_INVOICE_VALUE_SORT),
10859 'SCHEDULE_DATE',
10860 DECODE(L_SCHEDULE_DATE_SORT,
10861 'ASC',
10862 (WDD.DATE_SCHEDULED -
10863 TO_DATE('01-01-1700 23:59:59',
10864 'DD-MM-YYYY HH24:MI:SS')),
10865 'DESC',
10866 (TO_DATE('01-01-1700 23:59:59',
10867 'DD-MM-YYYY HH24:MI:SS') -
10868 WDD.DATE_SCHEDULED),
10869 null),
10870 'TRIP_STOP_DATE',
10871 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10872 L_TRIP_STOP_DATE_SORT),
10873 NULL))) as sort_attribute2,
10874
10875 -- get for sort_attribute3
10876 To_number(DECODE(l_release_sequence_rule_id,
10877 null,
10878 null,
10879 DECODE(g_ordered_psr(3).attribute_name,
10880 'ORDER_NUMBER',
10881 DECODE(L_ORDER_ID_SORT,
10882 'ASC',
10883 To_number(wdd.source_header_number),
10884 'DESC',
10885 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10886 null),
10887 'SHIPMENT_PRIORITY',
10888 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10889 'High',
10890 20,
10891 'Standard',
10892 10,
10893 NULL),
10894 'INVOICE_VALUE',
10895 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10896 L_INVOICE_VALUE_SORT),
10897 'SCHEDULE_DATE',
10898 DECODE(L_SCHEDULE_DATE_SORT,
10899 'ASC',
10900 (WDD.DATE_SCHEDULED -
10901 TO_DATE('01-01-1700 23:59:59',
10902 'DD-MM-YYYY HH24:MI:SS')),
10903 'DESC',
10904 (TO_DATE('01-01-1700 23:59:59',
10905 'DD-MM-YYYY HH24:MI:SS') -
10906 WDD.DATE_SCHEDULED),
10907 null),
10908 'TRIP_STOP_DATE',
10909 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10910 L_TRIP_STOP_DATE_SORT),
10911 NULL))) as sort_attribute3,
10912
10913 -- get for sort_attribute4
10914 To_number(DECODE(l_release_sequence_rule_id,
10915 null,
10916 null,
10917 DECODE(g_ordered_psr(4).attribute_name,
10918 'ORDER_NUMBER',
10919 DECODE(L_ORDER_ID_SORT,
10920 'ASC',
10921 To_number(wdd.source_header_number),
10922 'DESC',
10923 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10924 null),
10925 'SHIPMENT_PRIORITY',
10926 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10927 'High',
10928 20,
10929 'Standard',
10930 10,
10931 NULL),
10932 'INVOICE_VALUE',
10933 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10934 L_INVOICE_VALUE_SORT),
10935 'SCHEDULE_DATE',
10936 DECODE(L_SCHEDULE_DATE_SORT,
10937 'ASC',
10938 (WDD.DATE_SCHEDULED -
10939 TO_DATE('01-01-1700 23:59:59',
10940 'DD-MM-YYYY HH24:MI:SS')),
10941 'DESC',
10942 (TO_DATE('01-01-1700 23:59:59',
10943 'DD-MM-YYYY HH24:MI:SS') -
10944 WDD.DATE_SCHEDULED),
10945 null),
10946 'TRIP_STOP_DATE',
10947 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10948 L_TRIP_STOP_DATE_SORT),
10949 NULL))) as sort_attribute4,
10950
10951 -- get for sort_attribute5
10952 To_number(DECODE(l_release_sequence_rule_id,
10953 null,
10954 null,
10955 DECODE(g_ordered_psr(5).attribute_name,
10956 'ORDER_NUMBER',
10957 DECODE(L_ORDER_ID_SORT,
10958 'ASC',
10959 To_number(wdd.source_header_number),
10960 'DESC',
10961 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10962 null),
10963 'SHIPMENT_PRIORITY',
10964 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10965 'High',
10966 20,
10967 'Standard',
10968 10,
10969 null),
10970 'INVOICE_VALUE',
10971 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10972 L_INVOICE_VALUE_SORT),
10973 'SCHEDULE_DATE',
10974 DECODE(L_SCHEDULE_DATE_SORT,
10975 'ASC',
10976 (WDD.DATE_SCHEDULED -
10977 TO_DATE('01-01-1700 23:59:59',
10978 'DD-MM-YYYY HH24:MI:SS')),
10979 'DESC',
10980 (TO_DATE('01-01-1700 23:59:59',
10981 'DD-MM-YYYY HH24:MI:SS') -
10982 WDD.DATE_SCHEDULED),
10983 null),
10984 'TRIP_STOP_DATE',
10985 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10986 L_TRIP_STOP_DATE_SORT),
10987 NULL))) as sort_attribute5
10988
10989 FROM
10990 WSH_DELIVERY_DETAILS wdd
10991 WHERE
10992 wdd.source_code = 'OE'
10993 AND wdd.requested_quantity > 0
10994 And WDD.ORGANIZATION_ID = L_ORG_ID
10995 AND WDD.INVENTORY_ITEM_ID = P_ITEM_ID
10996 -- original status demand lines only
10997 AND wdd.released_status in ('R','B') and replenishment_status is NULL
10998 AND wdd.subinventory IS NULL -- since push_repl conc program does not consider forward pick sub either
10999 -- these demands should not be part of WRD
11000 AND NOT EXISTS (select wrd.demand_line_detail_id
11001 from WMS_REPLENISHMENT_DETAILS wrd
11002 where wrd.demand_line_detail_id = wdd.delivery_detail_id
11003 and wrd.demand_line_id = wdd.source_line_id
11004 and wrd.organization_id = wdd.organization_id)
11005 ORDER BY organization_id, sort_attribute1, sort_attribute2, sort_attribute3, sort_attribute4, sort_attribute5;
11006
11007
11008 -- CURSOR TO GET ALL MMTT LINES ASSOCIATED WITH DROP LPN
11009 CURSOR C_DROP_LPN_MMTT_LINE_CSR IS
11010 SELECT organization_id, TRANSACTION_TEMP_ID, MOVE_ORDER_LINE_ID, INVENTORY_ITEM_ID, PRIMARY_QUANTITY
11011 FROM mtl_material_transactions_temp mmtt
11012 WHERE TRANSACTION_HEADER_ID = l_txn_header_id
11013 AND mmtt.organization_id = l_org_id
11014 ORDER BY move_order_line_id asc,primary_quantity desc ;
11015
11016
11017 --pl/sql table to store information about mmtt lines that are going to be dropped
11018 TYPE drop_lpn_item_tbl IS TABLE OF C_DROP_LPN_MMTT_LINE_CSR%ROWTYPE INDEX BY BINARY_INTEGER;
11019 l_drop_lpn_item_tbl drop_lpn_item_tbl;
11020
11021
11022 --R12 Replenishment Project (6681109) ends
11023
11024
11025
11026 BEGIN
11027 IF (l_debug = 1) THEN
11028 mydebug('In Pick_Drop'||g_pkg_version);
11029 mydebug('tmpid='||p_temp_id||' hdrid='||p_txn_header_id||' org='||p_org_id||' fmlpn='||p_from_lpn_id||' dplpn='||p_drop_lpn||' locrsn='||p_loc_reason_id);
11030 mydebug('sub='||p_sub||' loc='||p_loc||' origsub='||p_orig_sub||' origloc='||p_orig_loc||' user='||p_user_id||' tsktyp='||p_task_type||' cmt='||p_commit);
11031 END IF;
11032
11033 l_temp_id := p_temp_id;
11034 l_org_id := p_org_id;
11035 l_return_status := fnd_api.g_ret_sts_success;
11036 l_txn_ret := 0;
11037 l_txn_header_id := p_txn_header_id;
11038 l_cnt := 0;
11039 l_isdroplpnentered := TRUE;
11040 -- setting local variables for workflow and logging exceptions
11041 l_wf := 0;
11042 l_sub := p_sub;
11043 l_loc := p_loc;
11044 l_orig_sub := p_orig_sub;
11045 l_loc_reason_id := p_loc_reason_id;
11046
11047 IF (l_debug = 1) THEN
11048 mydebug('pick_drop: ' || p_orig_loc || ' : ' || l_orig_sub || ' : ' || l_org_id);
11049 END IF;
11050
11051 l_user_id := p_user_id;
11052 l_task_type := p_task_type;
11053
11054 IF (p_drop_lpn = ''
11055 OR p_drop_lpn IS NULL) THEN
11056 l_isdroplpnentered := FALSE;
11057
11058 IF (l_debug = 1) THEN
11059 mydebug('pick_drop: no drop LPN entered');
11060 END IF;
11061 ELSE
11062 l_isdroplpnentered := TRUE;
11063
11064 IF (l_debug = 1) THEN
11065 mydebug('pick_drop: Creating final row for packing. Calling insert_mmtt_pack');
11066 END IF;
11067
11068 wms_task_dispatch_gen.insert_mmtt_pack(
11069 p_temp_id => p_temp_id
11070 , p_lpn_id => p_from_lpn_id
11071 , p_transfer_lpn => p_drop_lpn
11072 , p_container_item_id => 0
11073 , x_return_status => l_return_status
11074 , x_msg_count => l_msg_count
11075 , x_msg_data => l_msg_data
11076 );
11077
11078 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
11079 IF (l_debug = 1) THEN
11080 mydebug('pick_drop: Insert MMTT pack Unexpected error');
11081 END IF;
11082
11083 fnd_msg_pub.ADD;
11084 RAISE fnd_api.g_exc_unexpected_error;
11085 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
11086 IF (l_debug = 1) THEN
11087 mydebug('pick_drop: Insert MMTT pack error');
11088 END IF;
11089
11090 fnd_msg_pub.ADD;
11091 RAISE fnd_api.g_exc_error;
11092 END IF;
11093 END IF;
11094
11095 IF (l_debug = 1) THEN
11096 mydebug('pick_drop: After call to insert_mmtt_pack');
11097 END IF;
11098
11099 SELECT lpn_id
11100 , content_lpn_id
11101 , transfer_lpn_id
11102 , subinventory_code
11103 , locator_id
11104 , transfer_subinventory
11105 , transfer_to_location
11106 , transaction_type_id
11107 , move_order_line_id
11108 , transaction_source_type_id
11109 , inventory_item_id
11110 , transaction_action_id
11111 INTO l_lpn_id
11112 , l_content_lpn_id
11113 , l_transfer_lpn_id
11114 , l_from_sub
11115 , l_from_loc
11116 , l_transfer_sub
11117 , l_transfer_loc
11118 , l_tran_type_id
11119 , l_mo_line_id
11120 , l_tran_source_type_id
11121 , l_inventory_item_id
11122 , l_tran_action_id
11123 FROM mtl_material_transactions_temp
11124 WHERE transaction_temp_id = l_temp_id
11125 AND organization_id = l_org_id;
11126
11127 BEGIN
11128 SELECT LPN_CONTROLLED_FLAG
11129 INTO l_is_transfer_sub_lpn
11130 FROM mtl_secondary_inventories
11131 WHERE ORGANIZATION_ID = p_org_id
11132 AND SECONDARY_INVENTORY_NAME = l_transfer_sub;
11133 EXCEPTION
11134 WHEN OTHERS THEN
11135 l_is_transfer_sub_lpn := 1;
11136 END;
11137
11138 IF (l_debug = 1) THEN
11139 mydebug('l_transfer_sub_lpn :' || l_is_transfer_sub_lpn);
11140 END IF;
11141
11142 IF (WMS_CONTROL.get_current_release_level <
11143 INV_RELEASE.get_j_release_level)
11144 THEN
11145 BEGIN
11146 SELECT 1
11147 INTO l_cnt
11148 FROM DUAL
11149 WHERE EXISTS(SELECT 1
11150 FROM mtl_material_transactions_temp
11151 WHERE parent_line_id = l_temp_id);
11152 EXCEPTION
11153 WHEN NO_DATA_FOUND THEN
11154 l_cnt := 0;
11155 END;
11156
11157 IF l_cnt > 0 THEN
11158 IF (l_debug = 1) THEN
11159 mydebug('pick_drop: Bulk pick line..');
11160 END IF;
11161
11162 -- This is a bulk pick consolidated line. We have to update the
11163 -- child lines with the txn header id
11164
11165 -- Get the lpn info
11166
11167 IF l_content_lpn_id IS NULL THEN
11168 -- User did not pick a complete LPN
11169 IF (l_debug = 1) THEN
11170 mydebug('pick_drop: User did not pick entire lpn');
11171 END IF;
11172
11173 UPDATE mtl_material_transactions_temp
11174 SET transaction_header_id = l_txn_header_id
11175 , lpn_id = l_lpn_id
11176 , transfer_lpn_id = l_transfer_lpn_id
11177 , transaction_status = 3
11178 WHERE parent_line_id = l_temp_id
11179 AND organization_id = l_org_id;
11180 ELSE
11181 -- User picked a complete LPN
11182 IF (l_debug = 1) THEN
11183 mydebug('pick_drop: User picked entire lpn');
11184 END IF;
11185
11186 -- Set lpn_id and transfer_lpn_id to be the same
11187 -- so that the txn manager does not pack or unpack it
11188 -- We have to do this as kind of a hack because we basically
11189 -- are picking one complete lpn but fulfilling multiple
11190 -- mmtt lines
11191
11192 UPDATE mtl_material_transactions_temp
11193 SET transaction_header_id = l_txn_header_id
11194 , lpn_id = l_content_lpn_id
11195 , transfer_lpn_id = l_content_lpn_id
11196 , content_lpn_id = NULL
11197 , transaction_status = 3
11198 WHERE parent_line_id = l_temp_id
11199 AND organization_id = l_org_id;
11200
11201 -- Now update the loc of the LPN
11202
11203 -- Bug5659809: update last_update_date and last_update_by as well
11204 UPDATE wms_license_plate_numbers
11205 SET subinventory_code = l_transfer_sub
11206 , locator_id = l_transfer_loc
11207 , last_update_date = SYSDATE
11208 , last_updated_by = fnd_global.user_id
11209 WHERE lpn_id = l_content_lpn_id
11210 AND organization_id = l_org_id;
11211 END IF;
11212
11213 IF (l_debug = 1) THEN
11214 mydebug('pick_drop: Deleting orig mmtt bulk pick line..');
11215 END IF;
11216
11217 -- Get rid of the original MMTT line (which was a bogus line created
11218 -- for bulk picking
11219 DELETE mtl_material_transactions_temp
11220 WHERE transaction_temp_id = l_temp_id;
11221 END IF;
11222 END IF;
11223
11224 IF (l_debug = 1) THEN
11225 mydebug('pick_drop: Determining business flow code...');
11226 END IF;
11227
11228 l_flow := inv_label.wms_bf_pick_drop;
11229
11230 IF l_tran_type_id = 52 THEN -- Picking for sales order
11231 l_flow := inv_label.wms_bf_pick_drop;
11232 ELSIF l_tran_type_id = 35 THEN -- WIP issue
11233 l_flow := inv_label.wms_bf_wip_pick_drop;
11234 ELSIF l_tran_type_id = 51
11235 AND l_tran_source_type_id = 13 THEN --Backflush
11236 l_flow := inv_label.wms_bf_wip_pick_drop;
11237 ELSIF l_tran_action_id = 2
11238 AND l_tran_source_type_id IN(4, 13) THEN --Replenishment
11239 l_flow := inv_label.wms_bf_replenishment_drop;
11240 END IF;
11241
11242 IF (l_debug = 1) THEN
11243 mydebug('pick_drop: l_txn_header_id= ' || l_txn_header_id);
11244 mydebug('pick_drop: l_flow= ' || l_flow);
11245 END IF;
11246
11247 IF (l_debug = 1) THEN
11248 mydebug('pick_drop: Need to check if account period is open before calling TM');
11249 END IF;
11250
11251 invttmtx.tdatechk
11252 ( org_id => l_org_id
11253 , transaction_date => SYSDATE
11254 , period_id => l_period_id
11255 , open_past_period => l_open_past_period
11256 );
11257
11258 IF l_period_id <> -1 THEN
11259 IF (l_debug = 1) THEN
11260 mydebug('pick_drop: Need to update the account period in MMTT');
11261 END IF;
11262
11263 UPDATE mtl_material_transactions_temp
11264 SET acct_period_id = l_period_id
11265 WHERE transaction_header_id = l_txn_header_id
11266 AND organization_id = l_org_id;
11267 ELSE
11268 IF (l_debug = 1) THEN
11269 mydebug('pick_drop: Period is invalid');
11270 END IF;
11271
11272 fnd_message.set_name('INV', 'INV_NO_OPEN_PERIOD');
11273 fnd_msg_pub.ADD;
11274 RAISE fnd_api.g_exc_unexpected_error;
11275 END IF;
11276
11277 -- call workflow for location discrepancy
11278 IF (l_debug = 1) THEN
11279 mydebug('pick_drop: l_loc_reason_id ' || l_loc_reason_id);
11280 END IF;
11281
11282 l_wf := 0;
11283
11284 IF (l_loc_reason_id > 0) THEN
11285 --Log exception
11286 IF (l_debug = 1) THEN
11287 mydebug('pick_drop: Logging exceptions for loc discrepancy');
11288 mydebug('pick_drop: txn_header_id: ' || l_txn_header_id);
11289 mydebug('l_from_sub: ' || l_from_sub);
11290 mydebug('l_from_loc: ' || l_from_loc);
11291 mydebug('l_task type: ' || l_task_type);
11292 mydebug('l_item id' || l_inventory_item_id);
11293 END IF;
11294
11295 FOR rec_mmtt IN mmtt_csr loop
11296 -- right now we give the from_sub and from_loc until
11297 -- wms control board is enhanced.
11298 wms_txnrsn_actions_pub.log_exception
11299 (p_api_version_number => 1.0,
11300 p_init_msg_lst => fnd_api.g_false,
11301 p_commit => fnd_api.g_false,
11302 x_return_status => l_return_status,
11303 x_msg_count => l_msg_count,
11304 x_msg_data => l_msg_data,
11305 p_organization_id => l_org_id,
11306 p_mmtt_id => rec_mmtt.transaction_temp_id,
11307 p_task_id => rec_mmtt.transaction_temp_id,
11308 p_reason_id => l_loc_reason_id,
11309 p_subinventory_code => l_from_sub,
11310 p_locator_id => l_from_loc,
11311 p_discrepancy_type => l_task_type,
11312 p_user_id => l_user_id,
11313 p_item_id => l_inventory_item_id,
11314 p_revision => NULL,
11315 p_lot_number => NULL,
11316 p_is_loc_desc => TRUE); --Added bug 3989684
11317
11318 IF (l_debug = 1) THEN
11319 mydebug('pick_drop: after logging exception for temp_id: ' || rec_mmtt.transaction_temp_id);
11320 END IF;
11321
11322 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
11323 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
11324 fnd_msg_pub.ADD;
11325 RAISE fnd_api.g_exc_unexpected_error;
11326 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
11327 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
11328 fnd_msg_pub.ADD;
11329 RAISE fnd_api.g_exc_error;
11330 END IF;
11331
11332 END LOOP;
11333
11334 -- bug 2782039
11335 -- we now pass in the suggested locator ID directly
11336 BEGIN
11337 l_orig_loc := TO_NUMBER(p_orig_loc);
11338 EXCEPTION
11339 WHEN OTHERS THEN
11340 IF (l_debug = 1) THEN
11341 mydebug('pick_drop: converting p_orig_loc : ' || p_orig_loc || ' to l_orig_loc throws exception.');
11342 END IF;
11343 END;
11344
11345 IF (l_debug = 1) THEN
11346 mydebug('pick_drop: l_orig_loc: ' || l_orig_loc);
11347 END IF;
11348
11349 BEGIN
11350 SELECT 1
11351 INTO l_wf
11352 FROM mtl_transaction_reasons
11353 WHERE reason_id = l_loc_reason_id
11354 AND workflow_name IS NOT NULL
11355 AND workflow_name <> ' '
11356 AND workflow_process IS NOT NULL
11357 AND workflow_process <> ' ';
11358 EXCEPTION
11359 WHEN NO_DATA_FOUND THEN
11360 l_wf := 0;
11361 END;
11362
11363 IF l_wf > 0 THEN
11364 IF (l_debug = 1) THEN
11365 mydebug('pick_drop : WF exists for this reason code: ' || l_loc_reason_id);
11366 mydebug('pick_drop : Calling workflow wrapper FOR location');
11367 END IF;
11368
11369 -- Calling Workflow
11370 wms_workflow_wrappers.wf_wrapper(
11371 p_api_version => 1.0
11372 , p_init_msg_list => fnd_api.g_false
11373 , p_commit => fnd_api.g_false
11374 , x_return_status => l_return_status
11375 , x_msg_count => l_msg_count
11376 , x_msg_data => l_msg_data
11377 , p_org_id => l_org_id
11378 , p_rsn_id => l_loc_reason_id
11379 , p_calling_program => 'pick_drop - for loc discrepancy'
11380 , p_tmp_id => l_temp_id
11381 , p_quantity_picked => NULL
11382 , p_dest_sub => l_orig_sub
11383 , p_dest_loc => l_orig_loc
11384 );
11385
11386 IF (l_debug = 1) THEN
11387 mydebug('pick_drop : After Calling WF Wrapper');
11388 END IF;
11389
11390 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
11391 IF (l_debug = 1) THEN
11392 mydebug('pick_drop : Error callinf WF wrapper');
11393 END IF;
11394
11395 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
11396 fnd_msg_pub.ADD;
11397 RAISE fnd_api.g_exc_unexpected_error;
11398 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
11399 IF (l_debug = 1) THEN
11400 mydebug('pick_drop : Error calling WF wrapper');
11401 END IF;
11402
11403 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
11404 fnd_msg_pub.ADD;
11405 RAISE fnd_api.g_exc_error;
11406 END IF;
11407 END IF;
11408 END IF;
11409
11410 IF (l_debug = 1) THEN
11411 mydebug('pick_drop: Insert WDT History');
11412 END IF;
11413
11414 OPEN mmtt_csr;
11415
11416 LOOP
11417 FETCH mmtt_csr INTO l_temp_id;
11418 EXIT WHEN mmtt_csr%NOTFOUND;
11419 wms_task_dispatch_put_away.archive_task
11420 ( p_temp_id => l_temp_id
11421 , p_org_id => l_org_id
11422 , x_return_status => l_return_status
11423 , x_msg_count => l_msg_count
11424 , x_msg_data => l_msg_data
11425 , p_delete_mmtt_flag => 'N'
11426 , p_txn_header_id => l_txn_header_id
11427 , p_transfer_lpn_id => NVL(l_transfer_lpn_id, l_content_lpn_id)
11428 );
11429 END LOOP;
11430
11431 CLOSE mmtt_csr;
11432
11433 -- Now need to update LPN context appropriately
11434 IF l_isdroplpnentered = TRUE THEN
11435 SELECT lpn_id
11436 INTO l_xfrlpnid
11437 FROM wms_license_plate_numbers
11438 WHERE license_plate_number = p_drop_lpn;
11439 ELSE
11440 l_xfrlpnid := p_from_lpn_id;
11441 END IF;
11442
11443 l_lpn_context := wms_container_pub.lpn_context_picked;
11444
11445
11446 IF l_tran_type_id = 35 THEN -- WIP issue
11447 l_lpn_context := wms_container_pub.lpn_context_pregenerated;
11448
11449 ELSIF l_tran_type_id = 51 AND l_tran_source_type_id = 13 THEN --Backflush
11450 -- Bug 3954141
11451 -- If destination subinventory is not lpn controlled
11452 -- lpn context should be set to defined but not used
11453 --
11454 IF (l_is_transfer_sub_lpn = 2)
11455 THEN
11456 l_lpn_context := wms_container_pub.lpn_context_pregenerated;
11457 ELSE
11458 l_lpn_context := wms_container_pub.lpn_context_inv;
11459 END IF;
11460
11461 ELSIF l_tran_action_id = 2
11462 AND l_tran_source_type_id IN (13)
11463 AND l_task_type IN (7) THEN --Staging move
11464 l_lpn_context := wms_container_pub.lpn_context_picked;
11465
11466 ELSIF l_tran_action_id = 2
11467 AND l_tran_source_type_id IN(4, 13) THEN --Replenishment
11468 l_lpn_context := wms_container_pub.lpn_context_inv;
11469
11470 --
11471 -- Bug 3160462:
11472 -- If its a no lpn controlled transfer
11473 -- sub xfer lpn should go to define but not used
11474 --
11475 IF (l_is_transfer_sub_lpn = 2) THEN
11476
11477 IF (l_debug = 1) THEN
11478 mydebug('pick_drop: In the condition for l_trs_sub');
11479 mydebug('pick_drop: Values of l_temp_id:' || l_temp_id);
11480 mydebug('pick_drop: Values of l_transfer_lpn_id:' || l_transfer_lpn_id);
11481 mydebug('pick_drop: Values of l_transfer_sub:' || l_transfer_sub);
11482 mydebug('pick_drop: Values of l_transfer_loc:' || l_transfer_loc);
11483 END IF;
11484
11485 --Bug 5318552
11486 -- Only if the LPN being dropped does not have any more pending DROPS
11487 -- that its context should be set to pregenerated, otherwise to Packing
11488 -- (as it was before drop)
11489
11490 SELECT count(transaction_temp_id)
11491 INTO l_check_tasks
11492 FROM mtl_material_transactions_temp mmtt
11493 WHERE transfer_lpn_id = l_transfer_lpn_id
11494 AND transaction_temp_id <> l_temp_id ;
11495 IF l_check_tasks = 0 THEN
11496 l_lpn_context := wms_container_pub.LPN_CONTEXT_PREGENERATED;
11497 ELSE
11498 l_lpn_context := wms_container_pub.LPN_CONTEXT_PACKING;
11499 END IF;
11500
11501 --End of fix for Bug 5318552
11502
11503 END IF;
11504 ELSIF wms_task_utils_pvt.can_drop(p_lpn_id => p_from_lpn_id) = 'W' THEN
11505 -- Sales order cancelled
11506 l_lpn_context := wms_container_pub.lpn_context_inv;
11507 END IF;
11508
11509 --Bug # 2275770
11510 --Update mmtt.transaction_date to sysdate
11511 UPDATE mtl_material_transactions_temp
11512 SET transaction_date = SYSDATE
11513 WHERE transaction_header_id = l_txn_header_id;
11514
11515 -- Now call the txn processor...
11516
11517 IF (l_debug = 1) THEN
11518 mydebug('pick_drop: Before Calling txn proc');
11519 END IF;
11520
11521 IF l_tran_type_id = 35 THEN
11522 --
11523 -- WIP issue
11524 --
11525 IF (WMS_CONTROL.get_current_release_level >= INV_RELEASE.get_j_release_level)
11526 THEN
11527 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx
11528 ( p_trx_hdr_id => l_txn_header_id
11529 , p_commit => fnd_api.g_false
11530 , p_proc_mode => 1
11531 , x_proc_msg => l_msg_data
11532 , p_business_flow_code => l_flow
11533 );
11534
11535 IF (l_debug = 1) THEN
11536 mydebug('pick_drop: After Calling txn proc');
11537 mydebug('pick_drop: Txn proc ret' || l_txn_ret);
11538 END IF;
11539
11540 IF l_txn_ret <> 0 THEN
11541 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11542 fnd_msg_pub.ADD;
11543 RAISE fnd_api.g_exc_unexpected_error;
11544 END IF;
11545 ELSE
11546 --
11547 -- Bug 2747945 : Added business flow code to the call to the wip processor.
11548 --
11549 IF (l_debug = 1) THEN
11550 mydebug('pick_drop:seperate call for WIP issue');
11551 END IF;
11552
11553 wms_wip_integration.wip_processor
11554 ( p_txn_hdr_id => l_txn_header_id
11555 , p_business_flow_code => l_flow
11556 , x_return_status => l_return_status
11557 );
11558
11559 IF (l_debug = 1) THEN
11560 mydebug('pick_drop: After Calling WIP txn proc STATUS' || l_return_status);
11561 END IF;
11562
11563 IF l_return_status <> fnd_api.g_ret_sts_success THEN
11564 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11565 fnd_msg_pub.ADD;
11566 RAISE fnd_api.g_exc_unexpected_error;
11567 END IF;
11568 END IF; -- end if release J
11569 ELSE
11570 --
11571 -- Not a WIP issue task
11572 --
11573 -- bug 2760062
11574 -- for Staing move task type
11575 -- if the LPN contains any WDD line that has been ship-confirmed
11576 -- do NOT call TM.
11577
11578 IF l_task_type = 7 THEN
11579 SELECT COUNT(wdd2.lpn_id)
11580 INTO l_shipped_wdd_count_in_lpn
11581 FROM wsh_delivery_details wdd1
11582 , wsh_delivery_details wdd2
11583 , wsh_delivery_assignments_v wda
11584 , wms_license_plate_numbers wlpn
11585 WHERE wdd1.released_status = 'C'
11586 AND wda.delivery_detail_id = wdd1.delivery_detail_id
11587 AND wda.parent_delivery_detail_id = wdd2.delivery_detail_id
11588 AND wdd2.lpn_id = wlpn.lpn_id
11589 AND wlpn.outermost_lpn_id = l_content_lpn_id;
11590
11591 IF l_shipped_wdd_count_in_lpn > 0 THEN
11592 IF (l_debug = 1) THEN
11593 mydebug('pick_drop: this LPN ' || l_content_lpn_id ||
11594 ' contains delivery details lines that have been ship confirmed.');
11595 END IF;
11596
11597 fnd_message.set_name('WMS', 'WMS_STG_MV_LPN_SHIPPED');
11598 fnd_msg_pub.ADD;
11599 RAISE fnd_api.g_exc_unexpected_error;
11600 END IF;
11601 END IF;
11602
11603 -- VARAJAGO for bug 5222498, inserting the serial_number's group_mark_id into the temp table
11604 -- DHERRING added to change to include nested LPN solution.
11605
11606 DELETE wms_wsh_wdd_gtemp;
11607 IF l_tran_type_id = 2 AND l_tran_action_id = 2 AND l_tran_source_type_id = 13
11608 AND l_lpn_context = 11 THEN -- only for the staging xfer transaction
11609
11610 FOR rec_child_lpns_csr IN child_lpns_csr LOOP
11611 IF (l_debug = 1) THEN
11612 mydebug('pick_drop: Xfer LPN id : ' || l_xfrlpnid );
11613 mydebug('pick_drop: l_lpn_id : ' || rec_child_lpns_csr.lpn_id );
11614 mydebug('pick_drop: p_from_lpn_id : ' || p_from_lpn_id );
11615 END IF;
11616
11617 INSERT INTO wms_wsh_wdd_gtemp
11618 (SERIAL_NUMBER
11619 , organization_id
11620 , INVENTORY_ITEM_ID
11621 , transaction_temp_id
11622 , LPN_ID)
11623 SELECT serial_number
11624 , current_organization_id
11625 , inventory_item_id
11626 , group_mark_id
11627 , lpn_id
11628 FROM mtl_serial_numbers
11629 WHERE lpn_id = rec_child_lpns_csr.lpn_id;
11630
11631 END LOOP;
11632 END IF;
11633 -- VARAJAGO End of code for bug 5222498.
11634
11635
11636 --===================================================
11637 --R12.1 Replenishment Project 6681109 STARTS
11638 --Store all the Items and qty that are going to be dropped along with this drop LPN
11639 --Query the MMTT based on the transaction_header_id and get all Item_id and quantity and save them in a PL/SQL table.
11640 -- Assuming that at the end of the TM processing all these lines will be trnsacted.
11641 -- Once the TM is called all MMTT will be deleted. So we have to store all this information in a PL/SQL table before the TM call.
11642
11643 IF l_task_type = 4 THEN -- replenishemnt drop tasks
11644 -- BULK UPLOAD ALL cursor records into l_DROP_LPN_ITEM_TBL HERE
11645 IF (l_debug = 1) THEN
11646 mydebug('Store All mmtt records being dropped for replenishment');
11647 END IF;
11648
11649 OPEN C_DROP_LPN_MMTT_LINE_CSR;
11650 FETCH C_DROP_LPN_MMTT_LINE_CSR BULK COLLECT INTO l_drop_lpn_item_tbl ;
11651 CLOSE C_DROP_LPN_MMTT_LINE_CSR;
11652
11653 IF (l_debug = 1) THEN
11654 mydebug('Repl MMTT records selected - Count :'||l_drop_lpn_item_tbl.COUNT() );
11655 END IF;
11656
11657 END IF;
11658
11659 --R12.1 Replenishment Project 6681109 ENDS
11660 --===================================================
11661
11662
11663
11664 -- Release 12 Shipping Content Enhancement 4645826
11665 -- For Pick Drop, call label printing after TM, do not pass business flow to TM
11666 -- For other business flow, call labels through TM
11667
11668 IF l_flow = inv_label.wms_bf_pick_drop THEN
11669 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx
11670 ( p_trx_hdr_id => l_txn_header_id
11671 , p_commit => fnd_api.g_false
11672 , p_proc_mode => 1
11673 , x_proc_msg => l_msg_data
11674 , p_business_flow_code => null
11675 );
11676 ELSE
11677 -- TM call for Replenishment Drop will come here
11678 IF (l_debug = 1) THEN
11679 mydebug('TEST: Going to call TM for Replenishment Drop................ ');
11680 END IF;
11681 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx
11682 ( p_trx_hdr_id => l_txn_header_id
11683 , p_commit => fnd_api.g_false
11684 , p_proc_mode => 1
11685 , x_proc_msg => l_msg_data
11686 , p_business_flow_code => l_flow
11687 );
11688 END IF;
11689 -- End 4645826
11690
11691
11692 IF (l_debug = 1) THEN
11693 mydebug('pick_drop: After Calling txn proc');
11694 mydebug('pick_drop: Txn proc ret' || l_txn_ret);
11695 END IF;
11696
11697 IF l_txn_ret <> 0 THEN
11698 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11699 fnd_msg_pub.ADD;
11700 RAISE fnd_api.g_exc_unexpected_error;
11701 END IF;
11702 END IF; -- for l_tran_type_id <> 35
11703
11704
11705 --===================================================
11706 -- R12.1 replenishment Project 6681109 STARTS -----
11707
11708 IF l_txn_ret = 0 AND l_task_type = 4 THEN -- replenishment drop task
11709 IF (l_debug = 1) THEN
11710 mydebug('Consume replenishment related demands..STARTS....HERE ');
11711 END IF;
11712
11713
11714 FOR CNT IN 1..l_DROP_LPN_ITEM_TBL.COUNT() LOOP
11715 IF (l_debug = 1) THEN
11716 mydebug('Processing Item_Id :'|| L_DROP_LPN_ITEM_TBL(CNT).inventory_item_id||', Qty :'
11717 || L_DROP_LPN_ITEM_TBL(CNT).primary_quantity||', MO_Line_ID :'
11718 || L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id);
11719 END IF;
11720
11721 L_REMAINING_MMTT_QTY:= L_DROP_LPN_ITEM_TBL(CNT).PRIMARY_QUANTITY;
11722
11723 IF L_REMAINING_MMTT_QTY > 0 THEN
11724
11725 -- See it the move order line is part of WRD table
11726 -- Existance check only if the MOL changes from the previous MMTT record
11727 IF l_prev_mol IS NULL OR l_prev_mol <>
11728 L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id THEN
11729
11730 BEGIN
11731 SELECT 1, demand_type_id INTO l_exists_in_wrd, l_demand_type_id
11732 FROM wms_replenishment_details wrd
11733 WHERE WRD.ORGANIZATION_ID = P_ORG_ID
11734 AND WRD.SOURCE_LINE_ID = L_DROP_LPN_ITEM_TBL(CNT).MOVE_ORDER_LINE_ID
11735 AND WRD.INVENTORY_ITEM_ID = L_DROP_LPN_ITEM_TBL(CNT).INVENTORY_ITEM_ID
11736 AND ROWNUM = 1;
11737
11738 EXCEPTION
11739 WHEN no_data_found THEN
11740 IF (l_debug = 1) THEN
11741 mydebug('Move Order Line NOT found in WRD');
11742 END IF;
11743 l_exists_in_wrd := 0;
11744 WHEN OTHERS THEN
11745 l_exists_in_wrd := 0;
11746 END;
11747
11748 END IF; -- IF l_prev_mol IS NULL OR l_prev_mol <>
11749
11750 IF (l_debug = 1) THEN
11751 mydebug('IF the MOL exists in WRD :' ||l_exists_in_wrd);
11752 mydebug('MOL demand_type_id :' ||l_demand_type_id);
11753 END IF;
11754
11755
11756 IF l_exists_in_wrd = 1 THEN -- consume demand from WRD table
11757
11758 IF l_demand_type_id = 4 THEN -- means multi level repl
11759 -- code will come here only for repl_level > 1 based on l_demand_type_id
11760 -- find all associated demand move order lines and allocate them
11761
11762 OPEN c_multi_level_repl_alloc(L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id) ;
11763 LOOP
11764 FETCH c_multi_level_repl_alloc INTO l_demand_header_id,l_demand_line_id,
11765 l_wrd_pri_quantity,l_repl_level, l_demand_type_id;
11766
11767 EXIT WHEN c_multi_level_repl_alloc%NOTFOUND;
11768
11769 IF (l_debug = 1) THEN
11770 mydebug('Move Order Header :' || l_demand_header_id);
11771 mydebug('Replenishment Level :' || l_repl_level);
11772 mydebug('Demand Type Id :' || l_demand_type_id);
11773 mydebug('Primary MO Quantity :' || l_wrd_pri_quantity);
11774 mydebug('Calling Allocation Engine for MO :' || l_demand_line_id);
11775 END IF;
11776
11777 -- Call Allocation engine for allocate MO
11778 WMS_Engine_PVT.create_suggestions(
11779 p_api_version => 1.0,
11780 p_init_msg_list => fnd_api.g_false,
11781 p_commit => fnd_api.g_false,
11782 p_validation_level => fnd_api.g_valid_level_none,
11783 x_return_status => l_return_status,
11784 x_msg_count => l_msg_count,
11785 x_msg_data => l_msg_data,
11786 p_transaction_temp_id => l_demand_line_id,
11787 p_reservations => l_rsv_tbl_tmp, --No rsv FOR repl MO
11788 p_suggest_serial => fnd_api.g_false,
11789 p_plan_tasks => FALSE
11790 );
11791
11792 IF l_return_status <> fnd_api.g_ret_sts_success THEN
11793 IF (l_debug = 1) THEN
11794 mydebug('Move Order Allocation Failed, Move to next one');
11795 END IF;
11796 -- do nothing, skip this
11797
11798 ELSE -- Move order got allocated successfully
11799 -- remove the record from the WRD table
11800
11801 DELETE FROM WMS_REPLENISHMENT_DETAILS
11802 WHERE organization_id = p_org_id
11803 AND demand_type_id = 4
11804 AND demand_header_id = l_demand_header_id
11805 AND demand_line_id = l_demand_line_id;
11806
11807
11808 END IF;
11809
11810 END LOOP;
11811 CLOSE c_multi_level_repl_alloc;
11812
11813 ELSE --means l_demand_type_id <> 4; demand is WDD
11814
11815 -- code will come here only for repl_level = 1
11816 -- Mark RC to demand lines that are part of C_MARK_DEMAND_RC_CSR
11817 -- And pick release these lines if part of dynamic repl
11818 l_index := 0;
11819 l_b_index := 0;
11820 OPEN c_mark_demand_rc_csr(L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id) ;
11821 LOOP
11822 FETCH c_mark_demand_rc_csr INTO l_delivery_detail_id, L_SHIP_SET_ID,
11823 l_SHIP_MODEL_ID,
11824 l_wrd_pri_quantity,l_REQUESTED_QUANTITY,
11825 l_primary_uom, l_repl_type,l_repl_level, l_batch_id,l_demand_type_id;
11826
11827 EXIT WHEN c_mark_demand_rc_csr%notfound;
11828
11829 IF (l_debug = 1) THEN
11830 mydebug('Currently Consuming REPL MO for Repl Level :'||l_repl_level);
11831 mydebug('l_demand_type_id :'||l_demand_type_id);
11832 END IF;
11833
11834 -- Verify level of replenishment
11835 IF l_repl_level = 1 THEN -- replenishment for original demand
11836 IF l_wrd_pri_quantity <= l_requested_quantity THEN
11837 l_demand_pri_qty := l_wrd_pri_quantity;
11838 ELSE
11839 l_demand_pri_qty := l_requested_quantity;
11840 END IF;
11841
11842 ELSE -- invalid value of repl level
11843 IF (l_debug = 1) THEN
11844 mydebug('Invalid Value of Replenishment Level, skip this demand');
11845 END IF;
11846
11847 END IF;
11848
11849 IF L_REMAINING_MMTT_QTY >= L_DEMAND_PRI_QTY THEN
11850 IF (l_debug = 1) THEN
11851 mydebug('repl completion qty is greater than tied up demand qty');
11852 mydebug('Mark the delivery detail to RC - detail_id :' ||l_delivery_detail_id);
11853 END IF;
11854
11855 -- CALL SHIPPING API TO MARK THESE DELIVERY DETAILS AS 'RC' based on
11856 --l_delivery_detail_id
11857
11858 wms_replenishment_pvt.update_wdd_repl_status
11859 (p_deliv_detail_id => l_delivery_detail_id
11860 , p_repl_status => 'C' -- for completed status
11861 , x_return_status => l_return_status
11862 );
11863
11864 IF l_return_status <> fnd_api.g_ret_sts_success THEN
11865 -- do nothing, skip this
11866 GOTO next_repl_demand;
11867 END IF;
11868
11869
11870 --Remove the entry from the WRD table
11871 DELETE FROM WMS_REPLENISHMENT_DETAILS
11872 WHERE organization_id = p_org_id
11873 AND DEMAND_LINE_DETAIL_ID= l_delivery_detail_id;
11874
11875 -- Decrease the current MMTT qty
11876 L_REMAINING_MMTT_QTY := L_REMAINING_MMTT_QTY - L_DEMAND_PRI_QTY;
11877
11878
11879 ELSE -- means (l_demand_pri_qty > l_remaining_mmtt_qty )
11880
11881 IF (l_debug = 1) THEN
11882 mydebug('repl completion qty is LESS than tied up demand qty');
11883 mydebug('SPLIT the delivery line');
11884 END IF;
11885
11886 -- Split the original deamand line
11887 -- the newly created demand line will have qty =(L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY)
11888 -- WITH original 'RR" status . The shipping API with 'SPLIT-LINE' action in turn calls
11889 -- the wms_replenishment_pvt.update_delivery_detail() API that insert the newly created
11890 -- record with RR status in the WRD table AND updates the qty to l_remaining_mmtt_qty
11891 -- for the old delivery_detail record in the WRD table
11892
11893 -- So after calling for the split-line action, I need to call shipping
11894 -- AND mark the original delivery detail line to 'RC' and delete this WRD record
11895
11896
11897 l_detail_id_tab.DELETE;
11898 l_action_prms := NULL;
11899 l_detail_id_tab(1) := l_delivery_detail_id;
11900 -- Caller needs to be WSH_PUB in order for shipping to allow this action
11901 l_action_prms.caller := 'WSH_PUB';
11902 l_action_prms.action_code := 'SPLIT-LINE';
11903 l_action_prms.split_quantity := (L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY) ;
11904
11905 WSH_INTERFACE_GRP.Delivery_Detail_Action
11906 (p_api_version_number => 1.0,
11907 p_init_msg_list => fnd_api.g_false,
11908 p_commit => fnd_api.g_false,
11909 x_return_status => l_return_status,
11910 x_msg_count => x_msg_count,
11911 x_msg_data => x_msg_data,
11912 p_detail_id_tab => l_detail_id_tab,
11913 p_action_prms => l_action_prms,
11914 x_action_out_rec => l_action_out_rec
11915 );
11916
11917 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
11918 IF (l_debug = 1) THEN
11919 mydebug('Error returned from Split Delivery_Detail_Action API..skip this demand');
11920 END IF;
11921 -- do nothing, skip this demand line
11922 GOTO next_repl_demand;
11923
11924 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
11925 IF (l_debug = 1) THEN
11926 mydebug('Unexpected errror from Split Delivery_Detail_Action API..skip this demand');
11927 END IF;
11928 -- do nothing, skip this demand line
11929 GOTO next_repl_demand;
11930 END IF;
11931
11932 -- At this point the new delivery is already inserted in the WRD table.
11933 -- AND the qty for original delivery has been updated
11934 -- TO l_remaining_mmtt_qty IN WRD as above api calls
11935 -- wms_replenishment_pvt.update_delivery_detail() internally.
11936 -- SO JUST MARK original delivery replenishment_status RC
11937 -- and then delete the original record from the WRD table
11938
11939 wms_replenishment_pvt.update_wdd_repl_status
11940 (p_deliv_detail_id => l_delivery_detail_id
11941 , p_repl_status => 'C' -- for completed status
11942 , x_return_status => l_return_status
11943 );
11944
11945 IF l_return_status <> fnd_api.g_ret_sts_success THEN
11946 IF (l_debug = 1) THEN
11947 mydebug('Errror from Delivery_Detail_Action api to mark RC...skip this demand');
11948 END IF;
11949 -- do nothing, skip this demand line
11950 GOTO next_repl_demand;
11951 END IF;
11952
11953
11954 -- delete the original demand as it was marked RC
11955 -- nwely created delviery will be in WRD as 'RR'
11956 DELETE FROM WMS_REPLENISHMENT_DETAILS
11957 WHERE DEMAND_LINE_DETAIL_ID= l_delivery_detail_id;
11958
11959 L_REMAINING_MMTT_QTY := 0;
11960
11961 END IF; -- for L_REMAINING_MMTT_QTY >= L_DEMAND_PRI_QTY
11962
11963
11964 -- Pick Release associated demand lines as well only FOR repl_level = 1
11965 -- Store all these delivery_detail_ids and release in bulk per batch_id
11966 IF l_repl_type = 2 THEN -- pick release only if part of dynamic replenishment
11967 IF L_SHIP_SET_ID IS NULL and L_SHIP_MODEL_ID IS NULL THEN
11968
11969 IF (l_debug = 1) THEN
11970 mydebug('NOT part OF ship Set/Model Pick Releasing delivery Detail :'||l_delivery_detail_id);
11971 mydebug('Current Batch_id :'||l_batch_id);
11972 END IF;
11973 -- Store all deliv_detail_ids
11974
11975 l_index:= l_index +1;
11976 l_pick_rel_tab(l_index).delivery_detail_id := l_delivery_detail_id;
11977 l_pick_rel_tab(l_index).batch_id := l_batch_id;
11978
11979 IF (l_prev_batch_id IS NULL) OR l_prev_batch_id <> l_batch_id THEN
11980 IF (l_debug = 1) THEN
11981 mydebug('Got distinct batch, adding to the TABLE :'||l_batch_id);
11982 END IF;
11983 l_b_index := l_b_index +1;
11984 l_batch_id_tab(l_b_index) := l_batch_id;
11985 END IF;
11986
11987 ELSE -- means ship set or ship model exists
11988 -- check if this is the last RC status move_order line in the batch of ship set / ship model;
11989 -- If Yes, then pick release all move_orders lines in the batch
11990 -- We are postponing the support for ship set / ship model for later release ???
11991 IF (l_debug = 1) THEN
11992 mydebug('DO NOT Pick Release Demand Lines. Part OF ship Set/Model ');
11993 END IF;
11994 END IF;-- means ship set or ship model
11995 END IF; -- for IF l_repl_type = 2
11996
11997 EXIT WHEN L_REMAINING_MMTT_QTY= 0;
11998
11999 <<next_repl_demand>>
12000 l_prev_batch_id := l_batch_id;
12001 END LOOP;
12002 CLOSE c_mark_demand_rc_csr;
12003 END IF; -- for l_demand_type_id = 4
12004 END IF; -- for l_exists_in_wrd = 1
12005
12006
12007
12008 IF (l_debug = 1) THEN
12009 mydebug('Check if REPL MOL is not tracked in WRD to replenish wdd demand Lines');
12010 END IF;
12011
12012 -- in general all records for MO line should have same value OF l_repl_level FOR a move order
12013 -- taking default l_repl_level value unless it gets overwritten by value of
12014 -- last rcord IN above loop
12015 IF (l_repl_level =1 AND (l_exists_in_wrd <> 1) OR
12016 (l_repl_level =1 AND l_exists_in_wrd = 1 AND L_REMAINING_MMTT_QTY > 0 )) THEN
12017 -- Either some remaining qty after consuming demand from WRD OR move order line is not part of WRD table
12018
12019 IF (l_debug = 1) THEN
12020 mydebug('Either MO is not part od WRD OR Qty left out exhausting qty IN wrd tracked MO Lines ');
12021 mydebug('Related Demand lines will NOT be released...');
12022 END IF;
12023
12024 BEGIN
12025 select pick_sequence_rule_id
12026 INTO l_release_sequence_rule_id
12027 from wsh_shipping_parameters
12028 where organization_id = l_org_id;
12029 EXCEPTION
12030 WHEN no_data_found THEN
12031 l_release_sequence_rule_id := NULL;
12032 END;
12033
12034 IF (l_debug = 1) THEN
12035 mydebug('PICK SEQUENCE RULE ID FOR THE ORG :'||l_release_sequence_rule_id);
12036 END IF;
12037
12038 -- Get the Order By Clause based on Pick Release Rule
12039 --initialize gloabl variables
12040 -- delete old value
12041 g_ordered_psr.DELETE;
12042 wms_replenishment_pvt.init_rules
12043 (p_pick_seq_rule_id => l_release_sequence_rule_id,
12044 x_order_id_sort => l_ORDER_ID_SORT,
12045 x_INVOICE_VALUE_SORT => l_INVOICE_VALUE_SORT,
12046 x_SCHEDULE_DATE_SORT => l_SCHEDULE_DATE_SORT,
12047 x_trip_stop_date_sort => l_TRIP_STOP_DATE_SORT,
12048 x_SHIPMENT_PRI_SORT => l_shipment_pri_sort,
12049 x_ordered_psr => g_ordered_psr,
12050 x_api_status => l_return_status );
12051
12052 IF (l_debug = 1) THEN
12053 mydebug('Status after calling init_rules'||l_return_status);
12054 END IF;
12055
12056 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
12057 IF (l_debug = 1) THEN
12058 mydebug('init_rules returned Success, Processing untracked demand lines');
12059 END IF;
12060
12061 -- Mark RC to demand lines that are part of c_untracked_dmd_repl_cur
12062 -- DO NOT PICK RELEASE THESE LINES
12063 OPEN c_untracked_dmd_repl_cur(L_DROP_LPN_ITEM_TBL(CNT).inventory_item_id);
12064 LOOP
12065 FETCH c_untracked_dmd_repl_cur INTO
12066 l_delivery_detail_id, l_demand_pri_qty, l_req_quantity_uom,
12067 l_attr1,l_attr2,l_attr3,l_attr4,l_attr5 ;
12068 EXIT WHEN c_untracked_dmd_repl_cur%NOTFOUND;
12069
12070 IF (l_debug = 1) THEN
12071 mydebug('Currently processing detail_id :'||l_delivery_detail_id);
12072 END IF;
12073
12074
12075 IF L_REMAINING_MMTT_QTY >= L_DEMAND_PRI_QTY THEN
12076 IF (l_debug = 1) THEN
12077 mydebug('MO Qty >= Demand Qty; Mark demand as RC ');
12078 END IF;
12079
12080 wms_replenishment_pvt.update_wdd_repl_status
12081 (p_deliv_detail_id => l_delivery_detail_id
12082 , p_repl_status => 'C' -- for completed status
12083 , x_return_status => l_return_status
12084 );
12085
12086 IF l_return_status <> fnd_api.g_ret_sts_success THEN
12087 IF (l_debug = 1) THEN
12088 mydebug('Errror from Delivery_Detail_Action api to mark RC...skip this demand');
12089 END IF;
12090 -- DO NOTHING, SKIP THIS DEMAND LINE
12091 GOTO next_untrkd_dmd;
12092 END IF;
12093
12094 -- Nothing in the WRD table ot start with
12095 -- Just decrease the current MMTT qty
12096 L_REMAINING_MMTT_QTY := L_REMAINING_MMTT_QTY - L_DEMAND_PRI_QTY;
12097
12098
12099 ELSE -- means mmtt qty is less than demand qty
12100 IF (l_debug = 1) THEN
12101 mydebug('MO Qty < Demand Qty; Split the demand.... ');
12102 END IF;
12103
12104 -- Split the original deamand line
12105 -- the newly created demand line will have qty =(L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY) WITH
12106 -- original status . The shipping API with 'SPLIT-LINE' action in turn calls
12107 -- the wms_replenishment_pvt.update_delivery_detail()
12108 -- API but in this case since original
12109 -- delivery_detial was NOT tracked in the WRD table
12110 -- to start with, nothing happens there. In shipping,
12111 -- we have a new split WDD though
12112
12113 -- So after calling for the split-line action, I need to call shipping
12114 -- AND mark the original delivery detail line to 'RC' and delete this WRD record
12115
12116 l_detail_id_tab.DELETE;
12117 l_action_prms := NULL;
12118 l_detail_id_tab(1) := l_delivery_detail_id;
12119 -- Caller needs to be WSH_PUB in order for shipping to allow this action
12120 l_action_prms.caller := 'WSH_PUB';
12121 l_action_prms.action_code := 'SPLIT-LINE';
12122 l_action_prms.split_quantity := (L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY) ;
12123
12124 WSH_INTERFACE_GRP.Delivery_Detail_Action
12125 (p_api_version_number => 1.0,
12126 p_init_msg_list => fnd_api.g_false,
12127 p_commit => fnd_api.g_false,
12128 x_return_status => l_return_status,
12129 x_msg_count => x_msg_count,
12130 x_msg_data => x_msg_data,
12131 p_detail_id_tab => l_detail_id_tab,
12132 p_action_prms => l_action_prms,
12133 x_action_out_rec => l_action_out_rec
12134 );
12135
12136 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
12137 IF (l_debug = 1) THEN
12138 mydebug('Error returned from Split Delivery_Detail_Action API..skip this demand Line');
12139 END IF;
12140 -- DO NOTHING, SKIP THIS DEMAND LINE
12141 GOTO next_untrkd_dmd;
12142 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
12143 IF (l_debug = 1) THEN
12144 mydebug('Unexpected errror from Split Delivery_Detail_Action API..skip this demand Line');
12145 END IF;
12146 -- DO NOTHING, SKIP THIS DEMAND LINE
12147 GOTO next_untrkd_dmd;
12148 END IF;
12149
12150 -- At this point the new delivery is already inserted in the WRD table.
12151 -- AND the qty for original delivery has been updated
12152 -- TO l_remaining_mmtt_qty IN WRD as above api calls
12153 -- wms_replenishment_pvt.update_delivery_detail() internally.
12154 -- SO JUST MARK original delviery replenishment_status RC
12155 -- and then delete the original record from the WRD table
12156
12157 wms_replenishment_pvt.update_wdd_repl_status
12158 (p_deliv_detail_id => l_delivery_detail_id
12159 , p_repl_status => 'C' -- for completed status
12160 , x_return_status => l_return_status
12161 );
12162
12163 IF l_return_status <> fnd_api.g_ret_sts_success THEN
12164 -- DO NOTHING, SKIP THIS DEMAND LINE
12165 GOTO next_untrkd_dmd;
12166 END IF;
12167
12168 -- In this case the original delivery was NOT tracked
12169 -- in the WRD table. So no need to delete WRD
12170
12171 L_REMAINING_MMTT_QTY := 0;
12172
12173
12174 END IF; -- for L_REMAINING_MMTT_QTY => L_DEMAND_PRI_QTY
12175
12176 EXIT WHEN L_REMAINING_MMTT_QTY =0;
12177
12178 <<next_untrkd_dmd>>
12179 NULL;
12180
12181 END LOOP;
12182 CLOSE c_untracked_dmd_repl_cur;
12183
12184 ELSE --init_rules returned error
12185
12186 IF (l_debug = 1) THEN
12187 mydebug('init_rules returned Error, Can NOT mark demand lines RC');
12188 END IF ;
12189
12190 END IF; -- for init_rules returned success
12191
12192 END IF; --for IF (l_repl_level =1 AND (l_exists_in_wrd <> 1)
12193
12194 END IF; -- FOR L_REMAINING_MMTT_QTY > 0
12195
12196 l_prev_mol := L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id;
12197 END LOOP; -- for L_DROP_LPN_ITEM_TBL.COUNT
12198
12199 END IF; -- l_task_type = 4
12200 -- R12.1 replenishment Project 6681109 ENDS -----
12201 --===================================================
12202
12203
12204 -- VARAJAGO for bug 5222498, getting the grup_mark_id for the serial_number from temp table
12205 -- and update MSN.
12206 IF l_tran_type_id = 2 AND l_tran_action_id = 2 AND l_tran_source_type_id = 13
12207 AND l_lpn_context = 11 THEN -- only for staging move tranasction
12208 mydebug('pick_drop: INSIDE IF');
12209 FOR rec_child_lpns_csr IN child_lpns_csr LOOP -- for the Nested LPNs.
12210 mydebug('pick_drop: INSIDE FOR rec_child_lpns_csr : ' || rec_child_lpns_csr.lpn_id);
12211 FOR rec_msn_stg_mov_csr IN msn_stg_mov_csr(rec_child_lpns_csr.lpn_id) LOOP -- for the SNs matching the lpn_id
12212 mydebug('pick_drop: INSIDE FOR rec_msn_stg_mov_csr');
12213 IF (l_debug = 1) THEN
12214 mydebug('pick_drop: serial_number :' || rec_msn_stg_mov_csr.serial_number);
12215 mydebug('pick_drop: group_mark_id :' || rec_msn_stg_mov_csr.transaction_temp_id);
12216 mydebug('pick_drop: lpn_id :' || rec_msn_stg_mov_csr.lpn_id);
12217 END IF;
12218
12219 UPDATE mtl_serial_numbers
12220 SET mtl_serial_numbers.group_mark_id = rec_msn_stg_mov_csr.transaction_temp_id
12221 WHERE mtl_serial_numbers.serial_number = rec_msn_stg_mov_csr.serial_number
12222 AND mtl_serial_numbers.current_organization_id = rec_msn_stg_mov_csr.organization_id
12223 AND mtl_serial_numbers.inventory_item_id = rec_msn_stg_mov_csr.inventory_item_id
12224 AND mtl_serial_numbers.lpn_id = rec_msn_stg_mov_csr.lpn_id;
12225
12226 END LOOP;
12227
12228 END LOOP;
12229
12230 END IF;
12231 -- End of changes for 5222498
12232
12233 IF (l_debug = 1) THEN
12234 mydebug('pick_drop: call to modify_lpn_wrapper with lpn_context of ' || l_lpn_context);
12235 END IF;
12236
12237 -- Bug 4238917 no longer update lpn_context to 11 outside of TM
12238 IF ( l_lpn_context <> wms_container_pub.lpn_context_picked ) THEN
12239 wms_container_pub.modify_lpn_wrapper
12240 ( p_api_version => 1.0
12241 , x_return_status => l_return_status
12242 , x_msg_count => l_msg_count
12243 , x_msg_data => l_msg_data
12244 , p_lpn_id => l_xfrlpnid
12245 , p_lpn_context => l_lpn_context
12246 );
12247
12248 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
12249 IF (l_debug = 1) THEN
12250 mydebug('pick_drop: modify_lpn_wrapper Unexpected error');
12251 END IF;
12252
12253 fnd_msg_pub.ADD;
12254 RAISE fnd_api.g_exc_unexpected_error;
12255 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
12256 IF (l_debug = 1) THEN
12257 mydebug('pick_drop: modify_lpn_wrapper error');
12258 END IF;
12259
12260 fnd_msg_pub.ADD;
12261 RAISE fnd_api.g_exc_error;
12262 END IF;
12263
12264 -- Bug 4238917 no longer update lpn_context to 11 outside of TM
12265 /*
12266 -- IF droplpngenerated and lpn_context = PICKED then update the
12267 -- lpn_context of the from_lpn also.
12268 IF l_isdroplpnentered = TRUE THEN
12269 IF l_lpn_context = wms_container_pub.lpn_context_picked THEN
12270 wms_container_pub.modify_lpn_wrapper(
12271 p_api_version => 1.0
12272 , x_return_status => l_return_status
12273 , x_msg_count => l_msg_count
12274 , x_msg_data => l_msg_data
12275 , p_lpn_id => p_from_lpn_id
12276 , p_lpn_context => l_lpn_context
12277 );
12278 END IF;
12279 END IF; */
12280 END IF;
12281
12282 -- Release 12 Shipping Content Enhancement 4645826
12283 -- For Pick Drop, call label printing after TM,
12284 IF (l_debug = 1) THEN
12285 mydebug('Pick Drop, calling label printing API with l_lpn_id '||nvl(l_xfrlpnid,nvl(l_transfer_lpn_id, l_content_lpn_id)));
12286 END IF;
12287 IF l_flow = inv_label.wms_bf_pick_drop THEN
12288 INV_LABEL.PRINT_LABEL_MANUAL_WRAP(
12289 x_return_status => l_return_status
12290 , x_msg_count => l_msg_count
12291 , x_msg_data => l_msg_data
12292 , x_label_status => l_label_status
12293 , p_business_flow_code => l_flow
12294 , p_lpn_id => nvl(l_xfrlpnid,nvl(l_transfer_lpn_id, l_content_lpn_id))
12295 );
12296 END IF;
12297 -- End 4645826
12298
12299 IF p_commit = 'Y'
12300 THEN
12301 COMMIT;
12302 END IF;
12303
12304 --===================================================
12305 -- R12.1 replenishment Project 6681109 STARTS -----
12306
12307 -- WE NEED TO COMMIT ONCE SO THAT PICK RELEASE CONCURRENT PROGRAM BELOW
12308 -- CAN SEE MOVED MATERIAL FOR DROPPED TASKS.
12309 IF l_txn_ret = 0 AND l_task_type = 4 THEN -- replenishment drop task
12310
12311 IF (l_debug = 1) THEN
12312 mydebug('Processing Pick Release of Dmd Lines in batch...');
12313 mydebug('Number of batch_ids processed togather :'||l_batch_id_tab.count());
12314 END IF;
12315
12316 -- Call the Pick release per batch_id
12317 -- l_batch_id_tab stores only UNIQUE batch_id
12318 -- l_pick_rel_tab stores unique delivery_detail_id with respective batch_id
12319
12320 FOR i IN 1 .. l_batch_id_tab.count() LOOP
12321 l_detail_id_tab.DELETE;
12322 l_action_prms := NULL;
12323 l_cnt := 0;
12324 IF (l_debug = 1) THEN
12325 mydebug('****** Calling Pick Release with Batch_id :' ||l_batch_id_tab(i));
12326 END IF;
12327
12328 <<inner>>
12329 FOR j IN 1 .. l_pick_rel_tab.count() LOOP
12330 IF l_batch_id_tab(i) = l_pick_rel_tab(j).batch_id THEN
12331 l_cnt := l_cnt +1;
12332 l_detail_id_tab(l_cnt) := l_pick_rel_tab(j).delivery_detail_id;
12333 END IF;
12334 EXIT inner WHEN l_pick_rel_tab(j).batch_id > l_batch_id_tab(i);
12335 -- Since inserted records has alredy been ordered by batch_id
12336 END LOOP;
12337
12338 -- Call the pick release with l_batch_id_tab(i) AND l_detail_id_tab
12339 IF (l_debug = 1) THEN
12340 mydebug('Number of delivery details in this batch :'||l_detail_id_tab.COUNT());
12341 END IF;
12342
12343 l_action_prms.caller := 'WSH_PUB';
12344 l_action_prms.batch_id := l_batch_id_tab(i);
12345 l_action_prms.action_code := 'PICK-RELEASE';
12346
12347 WSH_INTERFACE_GRP.Delivery_Detail_Action
12348 (p_api_version_number => 1.0,
12349 p_init_msg_list => fnd_api.g_false,
12350 p_commit => fnd_api.g_false,
12351 x_return_status => l_return_status,
12352 x_msg_count => x_msg_count,
12353 x_msg_data => x_msg_data,
12354 p_detail_id_tab => l_detail_id_tab,
12355 p_action_prms => l_action_prms,
12356 x_action_out_rec => l_action_out_rec
12357 );
12358
12359 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
12360 IF (l_debug = 1) THEN
12361 mydebug('Error from Split Delivery_Detail_Action API..nothing TO be done');
12362 END IF;
12363 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
12364 IF (l_debug = 1) THEN
12365 mydebug('Unexpected error Split Delivery_Detail_Action API....nothing TO be done');
12366 END IF;
12367 END IF;
12368
12369 END LOOP;
12370
12371 --clear tables
12372 l_batch_id_tab.DELETE;
12373 l_pick_rel_tab.DELETE;
12374
12375 IF (l_debug = 1) THEN
12376 mydebug('AFTER Calling Repl Pick Release (in Batch) Status :'||l_return_status );
12377 END IF;
12378
12379 END IF; -- IF l_txn_ret = 0 AND l_task_type = 4
12380
12381
12382 IF p_commit = 'Y'
12383 THEN
12384 COMMIT;
12385 END IF;
12386 -- R12.1 replenishment Project 6681109 ENDS -----
12387 --===================================================
12388
12389
12390 x_return_status := fnd_api.g_ret_sts_success;
12391
12392 IF (l_debug = 1) THEN
12393 mydebug('pick_drop: done WITH Pick Drop API');
12394 END IF;
12395 EXCEPTION
12396 WHEN fnd_api.g_exc_error THEN
12397 x_return_status := fnd_api.g_ret_sts_error;
12398
12399 IF (l_debug = 1) THEN
12400 mydebug('pick_drop: Error in pick_drop API: ' || SQLERRM);
12401 END IF;
12402
12403 fnd_message.set_name('WMS', 'WMS_TD_PICK_DROP_FAIL');
12404 fnd_msg_pub.ADD;
12405 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12406 WHEN OTHERS THEN
12407 x_return_status := fnd_api.g_ret_sts_error;
12408
12409 IF (l_debug = 1) THEN
12410 mydebug('pick_drop: Unexpected Error in pick_drop API: ' || SQLERRM);
12411 END IF;
12412
12413 fnd_message.set_name('WMS', 'WMS_TD_PICK_DROP_FAIL');
12414 fnd_msg_pub.ADD;
12415 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12416 END pick_drop;
12417
12418 PROCEDURE pick_by_label(
12419 p_sign_on_emp_id IN NUMBER
12420 , p_sign_on_org_id IN NUMBER
12421 , p_sign_on_zone IN VARCHAR2
12422 , p_sign_on_equipment_id IN NUMBER
12423 , p_sign_on_equipment_srl IN VARCHAR2
12424 , p_task_type IN VARCHAR2
12425 , x_nbr_tasks OUT NOCOPY NUMBER
12426 , p_lpn_id IN NUMBER
12427 , x_return_status OUT NOCOPY VARCHAR2
12428 , x_msg_count OUT NOCOPY NUMBER
12429 , x_msg_data OUT NOCOPY VARCHAR2
12430 ) IS
12431 l_cartonization_id NUMBER := NULL;
12432 task_rec wms_task_dispatch_gen.task_rec_tp;
12433 l_task_cur wms_task_dispatch_gen.task_rec_cur_tp;
12434 l_user_id NUMBER;
12435 l_emp_id NUMBER;
12436 l_org_id NUMBER;
12437 l_zone VARCHAR2(10);
12438 l_eqp_id NUMBER;
12439 l_eqp_ins VARCHAR2(30);
12440 l_task_type VARCHAR2(30);
12441 l_c_rows NUMBER;
12442 l_next_task_id NUMBER;
12443 l_per_res_id NUMBER;
12444 l_mac_res_id NUMBER;
12445 l_std_op_id NUMBER;
12446 l_operation_plan_id NUMBER;
12447 l_move_order_line_id NUMBER;
12448 l_priority NUMBER;
12449 l_wms_task_type NUMBER;
12450 l_msg_count NUMBER;
12451 l_msg_data VARCHAR2(4000);
12452 l_return_status VARCHAR2(1);
12453 l_lpn_id NUMBER;
12454 l_mmtt_rowcnt NUMBER;
12455 l_wdt_rowcnt NUMBER;
12456 l_undispatched_picks NUMBER;
12457 l_txn_hdr_id NUMBER;
12458 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12459 BEGIN
12460 IF (l_debug = 1) THEN
12461 mydebug('pick_by_label: In Pick By Label API');
12462 END IF;
12463
12464 l_return_status := fnd_api.g_ret_sts_success;
12465 l_user_id := p_sign_on_emp_id;
12466 l_org_id := p_sign_on_org_id;
12467 l_zone := p_sign_on_zone;
12468 l_eqp_id := p_sign_on_equipment_id;
12469 l_eqp_ins := p_sign_on_equipment_srl;
12470 l_task_type := p_task_type;
12471 l_c_rows := 0;
12472 l_next_task_id := 0;
12473 l_std_op_id := 1;
12474 l_priority := 1;
12475 l_wms_task_type := 1;
12476 l_lpn_id := p_lpn_id;
12477
12478 IF (l_debug = 1) THEN
12479 mydebug('pick_by_label: get employee id');
12480 END IF;
12481
12482 l_emp_id := l_user_id;
12483
12484 IF (l_debug = 1) THEN
12485 mydebug('pick_by_label: emp id:' || l_emp_id);
12486 END IF;
12487
12488 l_mmtt_rowcnt := 0;
12489 l_wdt_rowcnt := 0;
12490
12491 IF l_eqp_id = -999 THEN
12492 l_eqp_id := NULL;
12493 END IF;
12494
12495 IF l_lpn_id = 0 THEN
12496 l_lpn_id := NULL;
12497 END IF;
12498
12499 IF (l_debug = 1) THEN
12500 mydebug('pick_by_label: Getting undispatched MMTT rows for this lpn..');
12501 END IF;
12502
12503 SELECT COUNT(*)
12504 INTO l_mmtt_rowcnt
12505 FROM mtl_material_transactions_temp m
12506 WHERE m.cartonization_id IS NOT NULL
12507 AND m.cartonization_id = l_lpn_id
12508 AND parent_line_id IS NULL;
12509
12510 IF (l_debug = 1) THEN
12511 mydebug('pick_by_label: MMTT rows' || l_mmtt_rowcnt);
12512 END IF;
12513
12514 IF l_mmtt_rowcnt > 0 THEN
12515 -- There are MMTT tasks for this LPN
12516 SELECT COUNT(*)
12517 INTO l_wdt_rowcnt
12518 FROM mtl_material_transactions_temp m, wms_dispatched_tasks t
12519 WHERE m.cartonization_id = l_lpn_id
12520 AND t.transaction_temp_id = m.transaction_temp_id
12521 AND t.status = 4;
12522
12523 IF (l_debug = 1) THEN
12524 mydebug('pick_by_label: WDT rows' || l_wdt_rowcnt);
12525 END IF;
12526
12527 l_undispatched_picks := l_mmtt_rowcnt - l_wdt_rowcnt;
12528
12529 IF (l_debug = 1) THEN
12530 mydebug('pick_by_label: Undispatched Picks' || l_undispatched_picks);
12531 END IF;
12532
12533 IF l_undispatched_picks > 0 THEN
12534 -- There are undispatched picks!
12535
12536 -- Need to call the TD engine here primarily to ensure user
12537 -- is eligible for task
12538
12539
12540
12541 IF (l_debug = 1) THEN
12542 mydebug('pick_by_label: Before Calling TD Engine');
12543 END IF;
12544
12545 IF l_lpn_id = fnd_api.g_miss_num THEN
12546 l_lpn_id := NULL;
12547 END IF;
12548
12549 --TEST have TO change eqpid to not null later
12550 --Call Lei's TD Engine
12551 wms_task_dispatch_engine.dispatch_task(
12552 p_api_version => 1.0
12553 , p_init_msg_list => 'F'
12554 , p_commit => NULL
12555 , p_sign_on_emp_id => l_emp_id
12556 , p_sign_on_org_id => l_org_id
12557 , p_sign_on_zone => l_zone
12558 , p_sign_on_equipment_id => l_eqp_id
12559 , p_sign_on_equipment_srl => l_eqp_ins
12560 , p_task_type => 'ALL'
12561 , x_task_cur => l_task_cur
12562 , x_return_status => l_return_status
12563 , x_msg_count => l_msg_count
12564 , x_msg_data => l_msg_data
12565 , p_cartonization_id => l_lpn_id
12566 );
12567
12568 IF (l_debug = 1) THEN
12569 mydebug('pick_by_label: Ret Stst11' || l_return_status);
12570 END IF;
12571
12572 IF l_return_status = fnd_api.g_ret_sts_success THEN
12573 LOOP
12574 FETCH l_task_cur INTO task_rec;
12575 EXIT WHEN l_task_cur%NOTFOUND;
12576 l_c_rows := l_c_rows + 1;
12577
12578 IF (l_debug = 1) THEN
12579 mydebug('pick_by_label: TaskID:' || task_rec.task_id);
12580 END IF;
12581
12582 IF (l_debug = 1) THEN
12583 mydebug('pick_by_label: getting Resource ID....');
12584 END IF;
12585
12586 SELECT bremp.resource_id role_id
12587 , t.wms_task_type
12588 , t.standard_operation_id
12589 , t.operation_plan_id
12590 , t.move_order_line_id
12591 INTO l_per_res_id
12592 , l_wms_task_type
12593 , l_std_op_id
12594 , l_operation_plan_id
12595 , l_move_order_line_id
12596 FROM mtl_material_transactions_temp t, bom_std_op_resources bsor, bom_resources bremp
12597 WHERE t.transaction_temp_id = task_rec.task_id
12598 AND t.standard_operation_id = bsor.standard_operation_id
12599 AND bsor.resource_id = bremp.resource_id
12600 AND bremp.resource_type = 2
12601 AND ROWNUM < 2;
12602
12603 IF (l_debug = 1) THEN
12604 mydebug('pick_by_label: After getting Resource ID....');
12605 END IF;
12606
12607 IF l_eqp_id IS NOT NULL THEN
12608 -- bug fix 1772907, lezhang
12609
12610 SELECT resource_id
12611 INTO l_mac_res_id
12612 FROM bom_resource_equipments
12613 WHERE inventory_item_id = l_eqp_id
12614 AND ROWNUM < 2;
12615 /*
12616 select breqp.resource_id equip_type_id
12617 INTO l_mac_res_id
12618 from mtl_material_transactions_temp t,
12619 bom_std_op_resources bsor,
12620 bom_resources breqp
12621 where t.transaction_temp_id = task_rec.task_id
12622 and t.standard_operation_id = bsor.standard_operation_id
12623 and bsor.resource_id = breqp.resource_id
12624 and breqp.resource_type = 1
12625 and rownum<2;
12626 */
12627 END IF;
12628
12629 SELECT mtl_material_transactions_s.NEXTVAL txnhdrid
12630 INTO l_txn_hdr_id
12631 FROM DUAL;
12632
12633 UPDATE mtl_material_transactions_temp
12634 SET transaction_header_id = l_txn_hdr_id
12635 WHERE transaction_temp_id = task_rec.task_id;
12636
12637 -- Insert into WMS_DISPATCHED_TASKS for this user
12638
12639 --Get value from sequence for next task id
12640 SELECT wms_dispatched_tasks_s.NEXTVAL
12641 INTO l_next_task_id
12642 FROM DUAL;
12643
12644 --mydebug('pick_by_label: Before Insert into WMSDT');
12645
12646
12647 INSERT INTO wms_dispatched_tasks
12648 (
12649 task_id
12650 , transaction_temp_id
12651 , organization_id
12652 , user_task_type
12653 , person_id
12654 , effective_start_date
12655 , effective_end_date
12656 , equipment_id
12657 , equipment_instance
12658 , person_resource_id
12659 , machine_resource_id
12660 , status
12661 , dispatched_time
12662 , last_update_date
12663 , last_updated_by
12664 , creation_date
12665 , created_by
12666 , task_type
12667 , priority
12668 , operation_plan_id
12669 , move_order_line_id
12670 )
12671 VALUES (
12672 l_next_task_id
12673 , task_rec.task_id
12674 , l_org_id
12675 , NVL(l_std_op_id, 2)
12676 , l_user_id
12677 , SYSDATE
12678 , SYSDATE
12679 , l_eqp_id
12680 , l_eqp_ins
12681 , l_per_res_id
12682 , l_mac_res_id
12683 , 3
12684 , SYSDATE
12685 , SYSDATE
12686 , l_emp_id
12687 , SYSDATE
12688 , l_emp_id
12689 , l_wms_task_type
12690 , task_rec.task_priority
12691 , l_operation_plan_id
12692 , l_move_order_line_id
12693 );
12694
12695 IF (l_debug = 1) THEN
12696 mydebug('pick_by_label: After Insert into WMSDT');
12697 END IF;
12698 /* BUG3209582 Pick By Label should dispatch all the tasks belonging to the
12699 Cartonized LPN to the same user else all the tasks are not dispatched to
12700 user continuously
12701 -- If LPN has been provided, exit, since we only want the first
12702 --task
12703 IF l_lpn_id IS NULL
12704 OR l_lpn_id = fnd_api.g_miss_num THEN
12705 IF (l_debug = 1) THEN
12706 mydebug('pick_by_label: LPN was not provided');
12707 END IF;
12708 ELSE
12709 IF (l_debug = 1) THEN
12710 mydebug('pick_by_label: LPN was provided - pick by label');
12711 END IF;
12712
12713 -- Setting nbr of tasks
12714 x_nbr_tasks := l_undispatched_picks;
12715 EXIT;
12716 END IF; */
12717 END LOOP;
12718 x_nbr_tasks := l_undispatched_picks;--bug3209582
12719
12720 -- Committing these tasks to this user
12721 IF (l_debug = 1) THEN
12722 mydebug('pick_by_label: before commiting');
12723 END IF;
12724
12725 COMMIT;
12726 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
12727 fnd_message.set_name('WMS', 'WMS_TD_TDENG_ERROR');
12728 fnd_msg_pub.ADD;
12729 RAISE fnd_api.g_exc_unexpected_error;
12730 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
12731 IF (l_debug = 1) THEN
12732 mydebug('pick_by_label: Setting status to S');
12733 END IF;
12734
12735 l_return_status := fnd_api.g_ret_sts_success;
12736
12737 -- TD Engine brought back 0 tasks.
12738 -- Since there are undispatched tasks for this LPN,
12739 -- it means that this user is not eligible for this task
12740 IF (l_debug = 1) THEN
12741 mydebug('pick_by_label: Ineligible USer');
12742 END IF;
12743
12744 x_nbr_tasks := -1;
12745 END IF;
12746 ELSE
12747 -- There are no undipatched tasks, hence user can drop off the task
12748 x_nbr_tasks := 0;
12749 END IF; -- l_undispatched_picks>0 end if
12750 ELSE -- l_mmtt_rowcnt>0 if
12751 IF (l_debug = 1) THEN
12752 mydebug('pick_by_label: There are no mmtt rows for this LPN');
12753 END IF;
12754
12755 x_nbr_tasks := -1;
12756 END IF;
12757
12758 x_return_status := fnd_api.g_ret_sts_success;
12759 EXCEPTION
12760 WHEN fnd_api.g_exc_error THEN
12761 x_return_status := fnd_api.g_ret_sts_error;
12762 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12763 WHEN OTHERS THEN
12764 x_return_status := fnd_api.g_ret_sts_unexp_error;
12765 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12766 END pick_by_label;
12767
12768 PROCEDURE manual_pick(
12769 p_sign_on_emp_id IN NUMBER
12770 , p_sign_on_org_id IN NUMBER
12771 , p_sign_on_zone IN VARCHAR2 := NULL
12772 , p_sign_on_equipment_id IN NUMBER := NULL
12773 , p_sign_on_equipment_srl IN VARCHAR2 := NULL
12774 , p_task_type IN VARCHAR2 := 'PICKING'
12775 , p_pick_slip_id IN NUMBER
12776 , x_return_status OUT NOCOPY VARCHAR2
12777 , x_msg_count OUT NOCOPY NUMBER
12778 , x_msg_data OUT NOCOPY VARCHAR2
12779 ) IS
12780 task_rec wms_task_dispatch_gen.task_rec_tp;
12781 l_task_cur wms_task_dispatch_gen.task_rec_cur_tp;
12782 l_user_id NUMBER;
12783 l_emp_id NUMBER;
12784 l_org_id NUMBER;
12785 l_zone VARCHAR2(10);
12786 l_eqp_id NUMBER;
12787 l_eqp_ins VARCHAR2(30);
12788 l_task_type VARCHAR2(30);
12789 l_c_rows NUMBER;
12790 l_next_task_id NUMBER;
12791 l_per_res_id NUMBER;
12792 l_mac_res_id NUMBER;
12793 l_std_op_id NUMBER;
12794 l_operation_plan_id NUMBER;
12795 l_move_order_line_id NUMBER;
12796 l_priority NUMBER;
12797 l_wms_task_type NUMBER;
12798 l_msg_count NUMBER;
12799 l_msg_data VARCHAR2(4000);
12800 l_return_status VARCHAR2(1);
12801 l_pick_slip_id NUMBER;
12802 l_mmtt_rowcnt NUMBER;
12803 l_wdt_rowcnt NUMBER;
12804 l_undispatched_picks NUMBER;
12805 l_txn_hdr_id NUMBER;
12806 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12807
12808 /*6009436 Begin */
12809 CURSOR c_fm_to_serial_number IS
12810 SELECT
12811 msnt.fm_serial_number,
12812 msnt.to_serial_number
12813 FROM mtl_serial_numbers_temp msnt
12814 WHERE msnt.transaction_temp_id = p_pick_slip_id;
12815
12816 CURSOR c_fm_to_lot_serial_number IS
12817 SELECT
12818 msnt.fm_serial_number,
12819 msnt.to_serial_number
12820 FROM
12821 mtl_serial_numbers_temp msnt,
12822 mtl_transaction_lots_temp mtlt
12823 WHERE mtlt.transaction_temp_id = p_pick_slip_id
12824 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
12825
12826 l_item_id NUMBER := NULL;
12827 l_serial_ctrl_code NUMBER;
12828 l_lot_ctrl_code NUMBER ;
12829 l_fm_serial_number MTL_SERIAL_NUMBERS_TEMP.FM_SERIAL_NUMBER%TYPE;
12830 l_to_serial_number MTL_SERIAL_NUMBERS_TEMP.TO_SERIAL_NUMBER%TYPE;
12831 /*6009436 End */
12832
12833 BEGIN
12834 IF (l_debug = 1) THEN
12835 mydebug('manual_pick: In Manual Pick API');
12836 END IF;
12837
12838 l_return_status := fnd_api.g_ret_sts_success;
12839 l_user_id := p_sign_on_emp_id;
12840 l_org_id := p_sign_on_org_id;
12841 l_zone := p_sign_on_zone;
12842 l_eqp_id := p_sign_on_equipment_id;
12843 l_eqp_ins := p_sign_on_equipment_srl;
12844 l_task_type := p_task_type;
12845 l_c_rows := 0;
12846 l_next_task_id := 0;
12847 l_std_op_id := 1;
12848 l_priority := 1;
12849 l_wms_task_type := 1;
12850 l_pick_slip_id := p_pick_slip_id;
12851
12852 IF (l_debug = 1) THEN
12853 mydebug('manual_pick: get employee id');
12854 END IF;
12855
12856 l_emp_id := l_user_id;
12857
12858 IF (l_debug = 1) THEN
12859 mydebug('manual_pick: emp id:' || l_emp_id);
12860 END IF;
12861
12862 l_mmtt_rowcnt := 0;
12863 l_wdt_rowcnt := 0;
12864
12865 IF l_eqp_id = -999 THEN
12866 l_eqp_id := NULL;
12867 END IF;
12868
12869 IF (l_debug = 1) THEN
12870 mydebug('manual_pick: Getting MMTT rows for this pick_Slip_id..');
12871 END IF;
12872
12873 -- bug 2729509 :Restricting the user not to load the child task
12874 -- which are merged using bulk pick. Added the condition parent_line_id
12875 -- not null for the same.
12876
12877 BEGIN
12878 SELECT 1
12879 INTO l_mmtt_rowcnt
12880 FROM DUAL
12881 WHERE EXISTS(SELECT 1
12882 FROM mtl_material_transactions_temp
12883 WHERE transaction_temp_id = l_pick_slip_id
12884 AND parent_line_id is NULL);
12885 EXCEPTION
12886 WHEN NO_DATA_FOUND THEN
12887 IF (l_debug = 1) THEN
12888 mydebug('manual_pick: No mmtt rows found for pick slip' || l_pick_slip_id);
12889 END IF;
12890
12891 l_mmtt_rowcnt := 0;
12892 fnd_message.set_name('WMS', 'WMS_INVALID_PICKID');
12893 fnd_msg_pub.ADD;
12894 RAISE fnd_api.g_exc_error;
12895 END;
12896
12897 IF (l_debug = 1) THEN
12898 mydebug('manual_pick: MMTT rows' || l_mmtt_rowcnt);
12899 END IF;
12900
12901 IF l_mmtt_rowcnt > 0 THEN
12902 -- Check if this line has been sent to somebody else
12903
12904 BEGIN
12905 SELECT 1
12906 INTO l_wdt_rowcnt
12907 FROM DUAL
12908 WHERE EXISTS(SELECT 1
12909 FROM wms_dispatched_tasks t
12910 WHERE t.transaction_temp_id = l_pick_slip_id);
12911 EXCEPTION
12912 WHEN NO_DATA_FOUND THEN
12913 l_wdt_rowcnt := 0;
12914 END;
12915
12916 IF l_wdt_rowcnt > 0 THEN
12917 IF (l_debug = 1) THEN
12918 mydebug('manual_pick: WDT rows' || l_wdt_rowcnt);
12919 mydebug('manual_pick: Task has been assigned to somebody else');
12920 END IF;
12921
12922 fnd_message.set_name('WMS', 'WMS_TASK_UNAVAIL');
12923 fnd_msg_pub.ADD;
12924 RAISE fnd_api.g_exc_error;
12925 ELSE
12926 IF (l_debug = 1) THEN
12927 mydebug('manual_pick: getting Resource ID....');
12928 END IF;
12929
12930 BEGIN
12931 SELECT bremp.resource_id role_id
12932 , t.wms_task_type
12933 , t.standard_operation_id
12934 , t.operation_plan_id
12935 , t.move_order_line_id
12936 , t.inventory_item_id --Bug#6009436
12937 INTO l_per_res_id
12938 , l_wms_task_type
12939 , l_std_op_id
12940 , l_operation_plan_id
12941 , l_move_order_line_id
12942 , l_item_id --Bug6009436
12943 FROM mtl_material_transactions_temp t, bom_std_op_resources bsor, bom_resources bremp
12944 WHERE t.transaction_temp_id = l_pick_slip_id
12945 AND t.standard_operation_id = bsor.standard_operation_id
12946 AND bsor.resource_id = bremp.resource_id
12947 AND bremp.resource_type = 2
12948 AND t.organization_id = l_org_id --Bug # 3704626
12949 AND ROWNUM < 2;
12950
12951 IF (l_debug = 1) THEN
12952 mydebug('manual_pick: After getting Resource ID....');
12953 END IF;
12954 EXCEPTION
12955 WHEN NO_DATA_FOUND THEN
12956 IF (l_debug = 1) THEN
12957 mydebug('manual_pick: No Person Resource ID found');
12958 END IF;
12959
12960 RAISE fnd_api.g_exc_error;
12961 END;
12962
12963 IF l_eqp_id IS NOT NULL THEN
12964 BEGIN
12965 -- bug fix 1772907, lezhang
12966
12967 SELECT resource_id
12968 INTO l_mac_res_id
12969 FROM bom_resource_equipments
12970 WHERE inventory_item_id = l_eqp_id
12971 AND ROWNUM < 2;
12972 /*
12973 select breqp.resource_id equip_type_id
12974 INTO l_mac_res_id
12975 from mtl_material_transactions_temp t,
12976 bom_std_op_resources bsor,
12977 bom_resources breqp
12978 where t.transaction_temp_id = task_rec.task_id
12979 and t.standard_operation_id = bsor.standard_operation_id
12980 and bsor.resource_id = breqp.resource_id
12981 and breqp.resource_type = 1
12982 and rownum<2;
12983 */
12984 EXCEPTION
12985 WHEN NO_DATA_FOUND THEN
12986 IF (l_debug = 1) THEN
12987 mydebug('manual_pick: No Machine Resource ID found');
12988 END IF;
12989
12990 RAISE fnd_api.g_exc_error;
12991 END;
12992 END IF;
12993
12994 -- Insert into WMS_DISPATCHED_TASKS for this user
12995
12996 --Get value from sequence for next task id
12997 SELECT wms_dispatched_tasks_s.NEXTVAL
12998 INTO l_next_task_id
12999 FROM DUAL;
13000
13001 --mydebug('manual_pick: Before Insert into WMSDT');
13002
13003 SELECT mtl_material_transactions_s.NEXTVAL txnhdrid
13004 INTO l_txn_hdr_id
13005 FROM DUAL;
13006
13007 UPDATE mtl_material_transactions_temp
13008 SET transaction_header_id = l_txn_hdr_id
13009 WHERE transaction_temp_id = l_pick_slip_id;
13010
13011 --Bug6009436.Begin
13012 SELECT msi.serial_number_control_code
13013 , msi.lot_control_code
13014 INTO l_serial_ctrl_code
13015 , l_lot_ctrl_code
13016 FROM mtl_system_items msi
13017 WHERE msi.inventory_item_id = l_item_id
13018 AND msi.organization_id =p_sign_on_org_id ;
13019
13020 IF (l_debug = 1) THEN
13021 mydebug('manual_pick:serial control code:'||l_serial_ctrl_code || ',lot control code :'||l_lot_ctrl_code);
13022 END IF;
13023
13024 IF (l_serial_ctrl_code NOT IN (1,6) ) THEN --Serial controlled item
13025 BEGIN
13026 IF (l_lot_ctrl_code > 1 ) THEN --Serial and lot controlled item
13027 OPEN c_fm_to_lot_serial_number;
13028 LOOP
13029 FETCH c_fm_to_lot_serial_number
13030 INTO l_fm_serial_number,l_to_serial_number;
13031 EXIT WHEN c_fm_to_lot_serial_number%NOTFOUND;
13032
13033 UPDATE MTL_SERIAL_NUMBERS msn
13034 SET GROUP_MARK_ID=l_txn_hdr_id
13035 WHERE msn.current_organization_id=p_sign_on_org_id
13036 AND msn.inventory_item_id= l_item_id
13037 AND msn.SERIAL_NUMBER BETWEEN l_fm_serial_number AND
13038 l_to_serial_number;
13039 END LOOP;
13040 CLOSE c_fm_to_lot_serial_number;
13041
13042 UPDATE mtl_serial_numbers_temp
13043 SET group_header_id= l_txn_hdr_id
13044 WHERE transaction_temp_id in ( SELECT serial_transaction_temp_id
13045 FROM mtl_transaction_lots_temp
13046 WHERE transaction_temp_id= l_pick_slip_id );
13047 ELSE --Non-Lot item
13048
13049 OPEN c_fm_to_serial_number;
13050 LOOP
13051 FETCH c_fm_to_serial_number
13052 INTO l_fm_serial_number,l_to_serial_number;
13053 EXIT WHEN c_fm_to_serial_number%NOTFOUND;
13054
13055 UPDATE MTL_SERIAL_NUMBERS msn
13056 SET GROUP_MARK_ID=l_txn_hdr_id
13057 WHERE msn.current_organization_id=p_sign_on_org_id
13058 AND msn.inventory_item_id= l_item_id
13059 AND msn.SERIAL_NUMBER BETWEEN l_fm_serial_number AND
13060 l_to_serial_number;
13061 END LOOP;
13062 CLOSE c_fm_to_serial_number;
13063
13064 UPDATE mtl_serial_numbers_temp
13065 SET group_header_id= l_txn_hdr_id
13066 WHERE transaction_temp_id=l_pick_slip_id ;
13067
13068 END IF;
13069
13070 IF (l_debug = 1) THEN
13071 mydebug('manual_pick: Updated MSNT');
13072 END IF;
13073
13074 EXCEPTION
13075 WHEN OTHERS THEN
13076 IF (l_debug = 1) THEN
13077 mydebug('manual_pick:EXCEPTION!!! while updating MSNT');
13078 END IF;
13079 raise fnd_api.g_exc_error;
13080 END ;
13081 END IF;
13082 --Bug6009436.End
13083
13084 INSERT INTO wms_dispatched_tasks
13085 (
13086 task_id
13087 , transaction_temp_id
13088 , organization_id
13089 , user_task_type
13090 , person_id
13091 , effective_start_date
13092 , effective_end_date
13093 , equipment_id
13094 , equipment_instance
13095 , person_resource_id
13096 , machine_resource_id
13097 , status
13098 , dispatched_time
13099 , last_update_date
13100 , last_updated_by
13101 , creation_date
13102 , created_by
13103 , task_type
13104 , operation_plan_id
13105 , move_order_line_id
13106 )
13107 VALUES (
13108 l_next_task_id
13109 , l_pick_slip_id
13110 , l_org_id
13111 , NVL(l_std_op_id, 2)
13112 , l_user_id
13113 , SYSDATE
13114 , SYSDATE
13115 , l_eqp_id
13116 , l_eqp_ins
13117 , l_per_res_id
13118 , l_mac_res_id
13119 , 3
13120 , SYSDATE
13121 , SYSDATE
13122 , l_emp_id
13123 , SYSDATE
13124 , l_emp_id
13125 , l_wms_task_type
13126 , l_operation_plan_id
13127 , l_move_order_line_id
13128 );
13129
13130 IF (l_debug = 1) THEN
13131 mydebug('manual_pick: After Insert into WMSDT');
13132 END IF;
13133 END IF;
13134 END IF; --mmtt rowcount if
13135
13136 COMMIT;
13137 x_return_status := fnd_api.g_ret_sts_success;
13138 EXCEPTION
13139 WHEN fnd_api.g_exc_error THEN
13140 x_return_status := fnd_api.g_ret_sts_error;
13141 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13142 WHEN OTHERS THEN
13143 x_return_status := fnd_api.g_ret_sts_unexp_error;
13144 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13145 END manual_pick;
13146
13147 PROCEDURE check_carton(
13148 p_carton_id IN NUMBER
13149 , p_org_id IN NUMBER
13150 , x_nbr_tasks OUT NOCOPY NUMBER
13151 , x_return_status OUT NOCOPY VARCHAR2
13152 , x_msg_count OUT NOCOPY NUMBER
13153 , x_msg_data OUT NOCOPY VARCHAR2
13154 ) IS
13155 l_cartonization_id NUMBER := NULL;
13156 l_c_rows NUMBER;
13157 l_msg_count NUMBER;
13158 l_msg_data VARCHAR2(4000);
13159 l_return_status VARCHAR2(1);
13160 l_lpn_id NUMBER;
13161 l_org_id NUMBER;
13162 l_mmtt_rowcnt NUMBER;
13163 l_wdt_rowcnt NUMBER;
13164 l_undispatched_picks NUMBER;
13165 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13166 BEGIN
13167 IF (l_debug = 1) THEN
13168 mydebug('check_carton: In check carton API');
13169 END IF;
13170
13171 l_return_status := fnd_api.g_ret_sts_success;
13172 l_org_id := p_org_id;
13173 l_c_rows := 0;
13174 l_lpn_id := p_carton_id;
13175 l_mmtt_rowcnt := 0;
13176 l_wdt_rowcnt := 0;
13177
13178 IF (l_debug = 1) THEN
13179 mydebug('check_carton: Getting undispatched MMTT rows for this lpn..');
13180 END IF;
13181
13182 SELECT COUNT(*)
13183 INTO l_mmtt_rowcnt
13184 FROM mtl_material_transactions_temp m
13185 WHERE m.cartonization_id IS NOT NULL
13186 AND m.cartonization_id = l_lpn_id
13187 AND parent_line_id IS NULL;
13188
13189 IF (l_debug = 1) THEN
13190 mydebug('check_carton: MMTT rows' || l_mmtt_rowcnt);
13191 END IF;
13192
13193 IF l_mmtt_rowcnt > 0 THEN
13194 -- There are MMTT tasks for this LPN
13195 SELECT COUNT(*)
13196 INTO l_wdt_rowcnt
13197 FROM mtl_material_transactions_temp m, wms_dispatched_tasks t
13198 WHERE m.cartonization_id = l_lpn_id
13199 AND t.transaction_temp_id = m.transaction_temp_id
13200 AND t.status = 4;
13201
13202 IF (l_debug = 1) THEN
13203 mydebug('check_carton: WDT rows' || l_wdt_rowcnt);
13204 END IF;
13205
13206 l_undispatched_picks := l_mmtt_rowcnt - l_wdt_rowcnt;
13207
13208 IF (l_debug = 1) THEN
13209 mydebug('check_carton: Undispatched Picks' || l_undispatched_picks);
13210 END IF;
13211
13212 x_nbr_tasks := l_undispatched_picks;
13213 ELSE -- l_mmtt_rowcnt>0 if
13214 IF (l_debug = 1) THEN
13215 mydebug('check_carton: There are no mmtt rows for this LPN');
13216 END IF;
13217
13218 x_nbr_tasks := -1;
13219 END IF;
13220
13221 x_return_status := fnd_api.g_ret_sts_success;
13222 EXCEPTION
13223 WHEN fnd_api.g_exc_error THEN
13224 x_return_status := fnd_api.g_ret_sts_error;
13225 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13226 WHEN OTHERS THEN
13227 x_return_status := fnd_api.g_ret_sts_unexp_error;
13228 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13229 END check_carton;
13230
13231
13232
13233 PROCEDURE check_pack_lpn
13234 ( p_lpn IN VARCHAR2
13235 , p_org_id IN NUMBER
13236 , x_return_status OUT NOCOPY VARCHAR2
13237 , x_msg_count OUT NOCOPY NUMBER
13238 , x_msg_data OUT NOCOPY VARCHAR2
13239 ) IS
13240 lpn_cont NUMBER := 0;
13241 create_lpn VARCHAR2(1) := 'N';
13242 l_return_status VARCHAR2(1);
13243 l_msg_count NUMBER;
13244 l_msg_data VARCHAR2(4000);
13245 l_exist NUMBER;
13246 p_lpn_id NUMBER;
13247 l_org_id NUMBER;
13248 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13249 BEGIN
13250 IF (l_debug = 1) THEN
13251 mydebug('check_pack_lpn: check_pack_lpn begins');
13252 END IF;
13253
13254 l_return_status := fnd_api.g_ret_sts_success;
13255
13256 IF ((p_lpn IS NULL)
13257 OR(p_lpn = '')) THEN
13258 x_return_status := fnd_api.g_ret_sts_success;
13259 RETURN;
13260 END IF;
13261
13262 BEGIN
13263 SELECT lpn_context
13264 , organization_id
13265 INTO lpn_cont
13266 , l_org_id
13267 FROM wms_license_plate_numbers
13268 WHERE license_plate_number = p_lpn;
13269 EXCEPTION
13270 WHEN NO_DATA_FOUND THEN
13271 create_lpn := 'Y';
13272 END;
13273
13274 IF (
13275 create_lpn = 'N'
13276 AND(
13277 (
13278 lpn_cont = wms_container_pub.lpn_context_wip
13279 OR lpn_cont = wms_container_pub.lpn_context_rcv
13280 OR lpn_cont = wms_container_pub.lpn_context_stores
13281 OR lpn_cont = wms_container_pub.lpn_context_intransit
13282 OR lpn_cont = wms_container_pub.lpn_context_vendor
13283 OR lpn_cont = wms_container_pub.lpn_loaded_for_shipment
13284 OR lpn_cont = wms_container_pub.lpn_prepack_for_wip
13285 OR lpn_cont = wms_container_pub.lpn_context_picked
13286 OR lpn_cont = wms_container_pub.lpn_context_inv --Bug 5038228
13287 )
13288 OR l_org_id <> p_org_id
13289 )
13290 ) THEN
13291 IF (l_debug = 1) THEN
13292 mydebug('check_pack_lpn: LPN already exists but with different context or Org');
13293 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_CNTXT_ORG');
13294 fnd_msg_pub.ADD;
13295 END IF;
13296
13297 x_return_status := fnd_api.g_ret_sts_error;
13298 RETURN;
13299 END IF;
13300
13301 IF create_lpn = 'Y' THEN
13302 IF (l_debug = 1) THEN
13303 mydebug('check_pack_lpn: calling wms_container_pub.create_lpn');
13304 END IF;
13305
13306 wms_container_pub.create_lpn
13307 ( p_api_version => 1.0
13308 , x_return_status => l_return_status
13309 , x_msg_count => l_msg_count
13310 , x_msg_data => x_msg_data
13311 , p_lpn => p_lpn
13312 , p_organization_id => p_org_id
13313 , x_lpn_id => p_lpn_id
13314 , p_source => 8
13315 );
13316
13317 IF (l_msg_count = 0) THEN
13318 IF (l_debug = 1) THEN
13319 mydebug('check_pack_lpn: Successful');
13320 END IF;
13321 ELSIF(l_msg_count = 1) THEN
13322 IF (l_debug = 1) THEN
13323 mydebug('check_pack_lpn: Not Successful');
13324 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
13325 END IF;
13326 ELSE
13327 IF (l_debug = 1) THEN
13328 mydebug('check_pack_lpn: Not Successful2');
13329 END IF;
13330
13331 FOR i IN 1 .. l_msg_count LOOP
13332 x_msg_data := fnd_msg_pub.get(i, 'F');
13333
13334 IF (l_debug = 1) THEN
13335 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
13336 END IF;
13337 END LOOP;
13338 END IF;
13339
13340 IF l_return_status = fnd_api.g_ret_sts_unexp_error
13341 OR l_return_status = fnd_api.g_ret_sts_error THEN
13342 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
13343 fnd_msg_pub.ADD;
13344 RAISE fnd_api.g_exc_unexpected_error;
13345 END IF;
13346
13347 END IF;
13348
13349 x_return_status := fnd_api.g_ret_sts_success;
13350
13351 IF (l_debug = 1) THEN
13352 mydebug('check_pack_lpn: check_pack_lpn ends');
13353 END IF;
13354 EXCEPTION
13355 WHEN fnd_api.g_exc_error THEN
13356 x_return_status := fnd_api.g_ret_sts_error;
13357 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13358 WHEN OTHERS THEN
13359 x_return_status := fnd_api.g_ret_sts_unexp_error;
13360 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13361 END check_pack_lpn;
13362
13363 PROCEDURE mydebug(msg IN VARCHAR2) IS
13364 l_msg VARCHAR2(5100);
13365 l_ts VARCHAR2(30);
13366 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13367 BEGIN
13368 -- select to_char(sysdate,'MM/DD/YYYY HH:MM:SS') INTO l_ts from dual;
13369 -- l_msg:=l_ts||' '||msg;
13370
13371 l_msg := msg;
13372 inv_mobile_helper_functions.tracelog(p_err_msg => l_msg, p_module => 'WMS_Task_Dispatch_Gen', p_level => 4);
13373 --dbms_output.put_line(l_msg);
13374
13375 NULL;
13376 END;
13377
13378 -- Procedure
13379 -- check_is_reservable_sub
13380 -- Description
13381 -- check from db tables whether the sub specified in
13382 -- the input is a reservable sub or not.
13383 PROCEDURE check_is_reservable_sub(
13384 x_return_status OUT NOCOPY VARCHAR2
13385 , p_organization_id IN VARCHAR2
13386 , p_subinventory_code IN VARCHAR2
13387 , x_is_reservable_sub OUT NOCOPY BOOLEAN
13388 ) IS
13389 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
13390 l_reservable_type NUMBER;
13391 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13392 BEGIN
13393 SELECT reservable_type
13394 INTO l_reservable_type
13395 FROM mtl_secondary_inventories
13396 WHERE organization_id = p_organization_id
13397 AND secondary_inventory_name = p_subinventory_code;
13398
13399 IF (l_reservable_type = 1) THEN
13400 x_is_reservable_sub := TRUE;
13401 ELSE
13402 x_is_reservable_sub := FALSE;
13403 END IF;
13404
13405 x_return_status := l_return_status;
13406 EXCEPTION
13407 WHEN OTHERS THEN
13408 x_return_status := fnd_api.g_ret_sts_unexp_error;
13409
13410 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
13411 fnd_msg_pub.add_exc_msg(g_pkg_name, 'Check_Is_Reservable_SUB');
13412 END IF;
13413 END check_is_reservable_sub;
13414 -- Bug 2924823 H to I added delete allocation
13415
13416 PROCEDURE delete_allocation
13417 (
13418 p_temp_id IN NUMBER,
13419 p_lot_control_code IN NUMBER,
13420 p_serial_control_code IN NUMBER,
13421 p_serial_allocate_flag IN VARCHAR2,
13422 p_item_id IN NUMBER,
13423 p_org_id IN NUMBER
13424 )
13425
13426 IS
13427 l_fm_serial_number VARCHAR2(30);
13428 l_to_serial_number VARCHAR2(30);
13429
13430 CURSOR c_fm_to_serial_number IS
13431 SELECT
13432 msnt.fm_serial_number,
13433 msnt.to_serial_number
13434 FROM mtl_serial_numbers_temp msnt
13435 WHERE msnt.transaction_temp_id = p_temp_id;
13436
13437 CURSOR c_fm_to_lot_serial_number IS
13438 SELECT
13439 msnt.fm_serial_number,
13440 msnt.to_serial_number
13441 FROM
13442 mtl_serial_numbers_temp msnt,
13443 mtl_transaction_lots_temp mtlt
13444 WHERE mtlt.transaction_temp_id = p_temp_id
13445 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
13446
13447 BEGIN
13448 DELETE FROM mtl_material_transactions_temp
13449 WHERE transaction_temp_id = p_temp_id;
13450
13451 DELETE FROM wms_dispatched_tasks
13452 WHERE transaction_temp_id = p_temp_id;
13453
13454 IF p_lot_control_code > 1 THEN
13455
13456 -- Lot controlled item
13457
13458 IF p_serial_control_code NOT IN (1,6) AND
13459 p_serial_allocate_flag = 'Y' THEN
13460
13461 -- Lot and Serial controlled item
13462 OPEN c_fm_to_lot_serial_number;
13463 LOOP
13464 FETCH c_fm_to_lot_serial_number
13465 INTO l_fm_serial_number,l_to_serial_number;
13466 EXIT WHEN c_fm_to_serial_number%NOTFOUND;
13467
13468 UPDATE mtl_serial_numbers
13469 SET group_mark_id = NULL
13470 WHERE inventory_item_id = p_item_id
13471 AND current_organization_id = p_org_id
13472 AND serial_number BETWEEN l_fm_serial_number AND
13473 l_to_serial_number;
13474
13475 END LOOP;
13476 CLOSE c_fm_to_lot_serial_number;
13477
13478 DELETE FROM mtl_serial_numbers_temp msnt
13479 WHERE msnt.transaction_temp_id IN
13480 (SELECT mtlt.serial_transaction_temp_id
13481 FROM mtl_transaction_lots_temp mtlt
13482 WHERE mtlt.transaction_temp_id = p_temp_id);
13483
13484 END IF;
13485
13486 DELETE FROM mtl_transaction_lots_temp mtlt
13487 WHERE mtlt.transaction_temp_id = p_temp_id;
13488
13489 END IF;
13490
13491 END delete_allocation;
13492
13493
13494 PROCEDURE cleanup_task(
13495 p_temp_id IN NUMBER
13496 , p_qty_rsn_id IN NUMBER
13497 , p_user_id IN NUMBER
13498 , x_return_status OUT NOCOPY VARCHAR2
13499 , x_msg_count OUT NOCOPY NUMBER
13500 , x_msg_data OUT NOCOPY VARCHAR2
13501 ) IS
13502 l_txn_hdr_id NUMBER;
13503 l_txn_temp_id NUMBER;
13504 l_org_id NUMBER;
13505 l_item_id NUMBER;
13506 l_sub VARCHAR2(10);
13507 l_loc NUMBER;
13508 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
13509 l_lot VARCHAR2(80);
13510 l_rev VARCHAR2(3);
13511 l_txn_qty NUMBER;
13512 l_other_mmtt_count NUMBER;
13513 l_mo_line_id NUMBER;
13514 l_mo_type NUMBER;
13515 l_mol_qty NUMBER;
13516 l_mol_qty_delivered NUMBER;
13517 l_mol_src_id NUMBER;
13518 l_mol_src_line_id NUMBER;
13519 l_mol_reference_id NUMBER;
13520 l_mol_status NUMBER;--bug3139307
13521 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13522 l_wf NUMBER;
13523 l_mmtt_transaction_uom VARCHAR2(3);
13524 l_mtrl_uom VARCHAR2(3);
13525 l_primary_quantity NUMBER;
13526 l_kill_mo_profile NUMBER := NVL(FND_PROFILE.VALUE_WNPS('INV_KILL_MOVE_ORDER'),2);
13527 l_return_status VARCHAR2(1);
13528
13529 CURSOR c_mmtt_info IS
13530 SELECT mmtt.transaction_header_id
13531 , mmtt.transaction_temp_id
13532 , mmtt.inventory_item_id
13533 , mmtt.organization_id
13534 , mmtt.revision
13535 , mmtt.lot_number
13536 , mmtt.subinventory_code
13537 , mmtt.locator_id
13538 , mmtt.move_order_line_id
13539 , mmtt.transaction_quantity
13540 , mmtt.transaction_uom
13541 , mmtt.primary_quantity
13542 FROM mtl_material_transactions_temp mmtt
13543 WHERE mmtt.transaction_temp_id = p_temp_id
13544 AND NOT EXISTS(SELECT 1
13545 FROM mtl_material_transactions_temp t1
13546 WHERE t1.parent_line_id = mmtt.transaction_temp_id)
13547 UNION ALL
13548 SELECT mmtt.transaction_header_id
13549 , mmtt.transaction_temp_id
13550 , mmtt.inventory_item_id
13551 , mmtt.organization_id
13552 , mmtt.revision
13553 , mmtt.lot_number
13554 , mmtt.subinventory_code
13555 , mmtt.locator_id
13556 , mmtt.move_order_line_id
13557 , mmtt.transaction_quantity
13558 , mmtt.transaction_uom
13559 , mmtt.primary_quantity
13560 FROM mtl_material_transactions_temp mmtt
13561 WHERE mmtt.parent_line_id = p_temp_id;
13562
13563 CURSOR c_mo_line_info IS
13564 SELECT mtrh.move_order_type
13565 , mtrl.txn_source_id
13566 , mtrl.txn_source_line_id
13567 , mtrl.reference_id
13568 , mtrl.quantity
13569 , mtrl.uom_code
13570 , nvl(mtrl.quantity_delivered,0)
13571 , mtrl.line_status --bug3139307
13572 FROM mtl_txn_request_headers mtrh, mtl_txn_request_lines mtrl
13573 WHERE mtrl.line_id = l_mo_line_id
13574 AND mtrh.header_id = mtrl.header_id;
13575
13576 CURSOR c_get_other_mmtt IS
13577 SELECT COUNT(*)
13578 FROM mtl_material_transactions_temp mmtt
13579 WHERE mmtt.move_order_line_id = l_mo_line_id
13580 AND mmtt.transaction_temp_id <> l_txn_temp_id
13581 AND NOT EXISTS(SELECT 1
13582 FROM mtl_material_transactions_temp t1
13583 WHERE t1.parent_line_id = mmtt.transaction_temp_id);
13584 BEGIN
13585 IF (l_debug = 1) THEN
13586 mydebug('CLEANUP_TASK: Cleaning up the Task with Temp ID = ' || p_temp_id);
13587 END IF;
13588
13589 x_return_status := fnd_api.g_ret_sts_success;
13590
13591 OPEN c_mmtt_info;
13592 LOOP
13593 FETCH c_mmtt_info INTO l_txn_hdr_id
13594 , l_txn_temp_id
13595 , l_item_id
13596 , l_org_id
13597 , l_rev
13598 , l_lot
13599 , l_sub
13600 , l_loc
13601 , l_mo_line_id
13602 , l_txn_qty
13603 , l_mmtt_transaction_uom
13604 , l_primary_quantity;
13605 EXIT WHEN c_mmtt_info%NOTFOUND;
13606
13607 IF (l_debug = 1) THEN
13608 mydebug('CLEANUP_TASK: Logging Exceptions with Reason ID = ' || p_qty_rsn_id || ' and TxnTempID = ' || l_txn_temp_id);
13609 END IF;
13610
13611 wms_txnrsn_actions_pub.log_exception(
13612 p_api_version_number => 1.0
13613 , p_init_msg_lst => fnd_api.g_false
13614 , p_commit => fnd_api.g_false
13615 , x_return_status => x_return_status
13616 , x_msg_count => x_msg_count
13617 , x_msg_data => x_msg_data
13618 , p_organization_id => l_org_id
13619 , p_item_id => l_item_id
13620 , p_revision => l_rev
13621 , p_lot_number => l_lot
13622 , p_subinventory_code => l_sub
13623 , p_locator_id => l_loc
13624 , p_mmtt_id => l_txn_hdr_id
13625 , p_task_id => l_txn_temp_id
13626 , p_reason_id => p_qty_rsn_id
13627 , p_discrepancy_type => 1
13628 , p_user_id => p_user_id
13629 );
13630
13631 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
13632 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
13633 fnd_msg_pub.ADD;
13634 RAISE fnd_api.g_exc_unexpected_error;
13635 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
13636 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
13637 fnd_msg_pub.ADD;
13638 RAISE fnd_api.g_exc_error;
13639 END IF;
13640
13641 mydebug('CLEANUP_TASK : Calling WorkFlow with Calling Program as **cleanup_task: Pick zero**');
13642 BEGIN
13643 call_workflow(
13644 p_rsn_id => p_qty_rsn_id
13645 , p_calling_program => 'cleanup_task: Pick zero'
13646 , p_org_id => l_org_id
13647 , p_tmp_id => l_txn_temp_id
13648 , p_quantity_picked => l_txn_qty
13649 , p_dest_sub => l_sub
13650 , p_dest_loc => l_loc
13651 , x_return_status => x_return_status
13652 , x_msg_count => x_msg_count
13653 , x_msg_data => x_msg_data
13654 , x_wf => l_wf
13655 );
13656
13657 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13658 mydebug('CLEANUP_TASK : Workflow Call is not successful');
13659 RAISE fnd_api.g_exc_unexpected_error;
13660 END IF;
13661 EXCEPTION
13662 WHEN OTHERS THEN
13663 mydebug('CLEANUP_TASK : Call to WorkFlow ended up in Exceptions');
13664 NULL;
13665 END;
13666 -- Called c_get_other_mmtt later after c_mo_line_info
13667 OPEN c_mo_line_info;
13668 FETCH c_mo_line_info INTO l_mo_type, l_mol_src_id, l_mol_src_line_id,
13669 l_mol_reference_id, l_mol_qty, l_mtrl_uom, l_mol_qty_delivered,l_mol_status;
13670 --bug3139307
13671 CLOSE c_mo_line_info;
13672 mydebug('cleanup_task: transaction_uom:'||l_mmtt_transaction_uom);
13673 mydebug('cleanup_task: move order line uom :'|| l_mtrl_uom);
13674 -- Bug 2924823 H to I
13675 if (l_mtrl_uom <> l_mmtt_transaction_uom) then
13676 mydebug('cleanup_task: move order line uom is different from mmtt
13677 transaction uom');
13678 l_txn_qty := INV_Convert.inv_um_convert
13679 (item_id => l_item_id,
13680 precision => null,
13681 from_quantity => l_txn_qty,
13682 from_unit => l_mmtt_transaction_uom,
13683 to_unit => l_mtrl_uom,
13684 from_name => null,
13685 to_name => null);
13686 end if;
13687
13688
13689 OPEN c_get_other_mmtt;
13690 FETCH c_get_other_mmtt INTO l_other_mmtt_count;
13691 CLOSE c_get_other_mmtt;
13692
13693 IF (l_debug = 1) THEN
13694 mydebug('CLEANUP_TASK: Number of MMTTs other than this MMTT : ' || l_other_mmtt_count);
13695 END IF;
13696
13697 IF l_other_mmtt_count > 0 THEN
13698 IF (l_debug = 1) THEN
13699 mydebug('CLEANUP_TASK: Other MMTT lines exist too. So cant close MO Line');
13700 END IF;
13701
13702 inv_trx_util_pub.delete_transaction(
13703 x_return_status => x_return_status
13704 , x_msg_data => x_msg_data
13705 , x_msg_count => x_msg_count
13706 , p_transaction_temp_id => l_txn_temp_id
13707 , p_update_parent => FALSE --Added bug 3765153
13708 );
13709
13710 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13711 IF l_debug = 1 THEN
13712 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
13713 END IF;
13714 RAISE fnd_api.g_exc_error;
13715 END IF;
13716 -- Bug 2924823 H to I
13717 if (l_wf <= 0) or (p_qty_rsn_id <= 0) then
13718 UPDATE mtl_txn_request_lines
13719 SET quantity_detailed = quantity_detailed - l_txn_qty
13720 WHERE line_id = l_mo_line_id;
13721 end if;
13722 ELSE
13723 IF (l_debug = 1) THEN
13724 mydebug('CLEANUP_TASK: Just one MMTT line exists. Close MO');
13725 END IF;
13726
13727 /* OPEN c_mo_line_info;
13728 FETCH c_mo_line_info INTO l_mo_type, l_mol_src_id, l_mol_src_line_id, l_mol_reference_id, l_mol_qty, l_mol_qty_delivered;
13729 CLOSE c_mo_line_info;
13730 */
13731 IF (l_mo_type = INV_GLOBALS.G_MOVE_ORDER_PICK_WAVE) THEN
13732 DELETE FROM wms_dispatched_tasks WHERE transaction_temp_id = p_temp_id;
13733
13734 /*bug3139307 suggest_alternate_location API in wms_txnrsn_actions_pub
13735 would call INV_Replenish_Detail_PUB.Line_Details_PUB . When there is
13736 no quantity to allocate the sales order would be automatically
13737 backordered and move order is closed. So we need not call
13738 backorder API here again. */
13739 IF l_mol_status <> 5 THEN --bug3139307 bug 2924823 H to I
13740 inv_mo_backorder_pvt.backorder(
13741 p_line_id => l_mo_line_id
13742 , x_return_status => x_return_status
13743 , x_msg_count => x_msg_count
13744 , x_msg_data => x_msg_data
13745 );
13746
13747 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
13748 IF (l_debug = 1) THEN
13749 mydebug('CLEANUP_TASK: Unexpected error occurrend while calling BackOrder API');
13750 END IF;
13751 RAISE fnd_api.g_exc_unexpected_error;
13752 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
13753 IF (l_debug = 1) THEN
13754 mydebug('CLEANUP_TASK: Expected error occurrend while calling BackOrder API');
13755 END IF;
13756 RAISE fnd_api.g_exc_error;
13757 END IF;
13758
13759 IF (l_debug = 1) THEN
13760 mydebug('CLEANUP_TASK: Calling API to clean up reservations');
13761 END IF;
13762
13763 inv_transfer_order_pvt.clean_reservations(
13764 p_source_line_id => l_mol_src_line_id
13765 , x_return_status => x_return_status
13766 , x_msg_count => x_msg_count
13767 , x_msg_data => x_msg_data
13768 );
13769
13770 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
13771 IF (l_debug = 1) THEN
13772 mydebug('CLEANUP_TASK: Unexpected error occurred while Cleaning up Reservations');
13773 END IF;
13774 RAISE fnd_api.g_exc_unexpected_error;
13775 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
13776 IF (l_debug = 1) THEN
13777 mydebug('CLEANUP_TASK: Expected error occurred while Cleaning up Reservations');
13778 END IF;
13779 RAISE fnd_api.g_exc_error;
13780 END IF;
13781
13782 ELSE -- if mol.status = 5 --bug3139307
13783 /*Need to delete the MMTT as the suggest_alternate-location
13784 procedure in WMSTRSAB.pls would set the MMTT transaction qty. primary
13785 transaction qty to zero before calling pick release. When Pick rellease
13786 backorders the mo line it does not clean up the taks. This
13787 has to be done here.*/
13788
13789 INV_TRX_UTIL_PUB.delete_transaction(
13790 x_return_status => x_return_status
13791 , x_msg_data => x_msg_data
13792 , x_msg_count => x_msg_count
13793 , p_transaction_temp_id => l_txn_temp_id
13794 , p_update_parent => FALSE --Added bug 3765153
13795 );
13796
13797 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13798 IF l_debug = 1 THEN
13799 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
13800 END IF;
13801 RAISE fnd_api.g_exc_error;
13802 END IF;
13803 END IF; --bug3139307 bug 2924823 H to I
13804 /* IF l_mo_type = INV_GLOBALS.G_MOVE_ORDER_MFG_PICK THEN */
13805 ELSIF l_mo_type IN (5,7)THEN -- wip picking bug 2924823 H to I
13806 UPDATE mtl_txn_request_lines
13807 SET quantity_detailed = quantity_delivered
13808 , line_status = 5
13809 WHERE line_id = l_mo_line_id;
13810
13811 wip_picking_pub.unallocate_material(
13812 p_wip_entity_id => l_mol_src_id
13813 , p_operation_seq_num => l_mol_src_line_id
13814 , p_inventory_item_id => l_item_id
13815 , p_repetitive_schedule_id => l_mol_reference_id
13816 , p_primary_quantity => l_mol_qty - l_mol_qty_delivered
13817 , x_return_status => x_return_status
13818 , x_msg_data => x_msg_data
13819 );
13820
13821 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
13822 IF (l_debug = 1) THEN
13823 mydebug('CLEANUP_TASK: Unexpected error occurred while Unallocating WIP Material');
13824 END IF;
13825 RAISE fnd_api.g_exc_unexpected_error;
13826 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
13827 IF (l_debug = 1) THEN
13828 mydebug('CLEANUP_TASK: Expected error occurred while Unallocating WIP Material');
13829 END IF;
13830 RAISE fnd_api.g_exc_error;
13831 END IF;
13832
13833 inv_trx_util_pub.delete_transaction(
13834 x_return_status => x_return_status
13835 , x_msg_data => x_msg_data
13836 , x_msg_count => x_msg_count
13837 , p_transaction_temp_id => l_txn_temp_id
13838 , p_update_parent => FALSE --Added bug3765153
13839 );
13840
13841 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13842 IF l_debug = 1 THEN
13843 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
13844 END IF;
13845 RAISE fnd_api.g_exc_error;
13846 END IF;
13847 -- Bug 2924823 H to I
13848 if (l_wf <= 0) or (p_qty_rsn_id <= 0) then
13849 UPDATE mtl_txn_request_lines
13850 SET quantity_detailed = quantity_detailed - l_txn_qty,
13851 line_status = 5
13852 WHERE line_id = l_mo_line_id;
13853 end if;
13854 ELSIF l_mo_type IN (INV_GLOBALS.G_MOVE_ORDER_REQUISITION, INV_GLOBALS.G_MOVE_ORDER_REPLENISHMENT) THEN
13855 UPDATE mtl_txn_request_lines
13856 SET quantity_detailed = quantity_delivered
13857 WHERE line_id = l_mo_line_id;
13858
13859 inv_trx_util_pub.delete_transaction(
13860 x_return_status => x_return_status
13861 , x_msg_data => x_msg_data
13862 , x_msg_count => x_msg_count
13863 , p_transaction_temp_id => l_txn_temp_id
13864 );
13865
13866 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13867 IF l_debug = 1 THEN
13868 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
13869 END IF;
13870 RAISE fnd_api.g_exc_error;
13871 END IF;
13872
13873 /* 3926046 */
13874 IF (l_kill_mo_profile = 1) and (l_mo_type = INV_GLOBALS.G_MOVE_ORDER_REPLENISHMENT) THEN
13875
13876 IF (l_debug = 1) THEN
13877 mydebug('Replenishment Move Order... pending task count :'|| l_other_mmtt_count);
13878 mydebug('Replenishment Move Order... quantity delivered :'|| l_mol_qty_delivered);
13879 END IF;
13880
13881 IF ((l_other_mmtt_count = 0) and (l_mol_qty_delivered > 0)) THEN
13882 IF (l_debug = 1) THEN
13883 mydebug('Replenishment Move Order... Closing the Move Order');
13884 END IF;
13885 INV_MO_ADMIN_PUB.close_line(1.0,'F','F','F',l_mo_line_id,x_msg_count,x_msg_data,l_return_status);
13886
13887 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
13888 RAISE FND_API.G_EXC_ERROR;
13889 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
13890 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
13891 END IF;
13892 END IF;
13893 END IF;
13894
13895 -- Bug 2924823 H to I
13896 if (l_wf <= 0) or (p_qty_rsn_id <= 0) then
13897 UPDATE mtl_txn_request_lines
13898 SET quantity_detailed = quantity_delivered
13899 WHERE line_id = l_mo_line_id;
13900 end if;
13901 END IF;
13902 END IF;
13903 END LOOP;
13904
13905 CLOSE c_mmtt_info;
13906 COMMIT;
13907 EXCEPTION
13908 WHEN OTHERS THEN
13909 x_return_status := fnd_api.g_ret_sts_error;
13910 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13911 IF c_mmtt_info%ISOPEN THEN
13912 CLOSE c_mmtt_info;
13913 END IF;
13914 IF (l_debug = 1) THEN
13915 mydebug('CLEANUP_TASK: Exception Occurred = ' || SQLERRM);
13916 END IF;
13917 END cleanup_task;
13918
13919 PROCEDURE get_td_lot_lov_count(
13920 x_lot_num_lov_count OUT NOCOPY NUMBER
13921 , p_organization_id IN NUMBER
13922 , p_item_id IN NUMBER
13923 , p_lot_number IN VARCHAR2
13924 , p_transaction_type_id IN NUMBER
13925 , p_wms_installed IN VARCHAR2
13926 , p_lpn_id IN NUMBER
13927 , p_subinventory_code IN VARCHAR2
13928 , p_locator_id IN NUMBER
13929 , p_txn_temp_id IN NUMBER
13930 ) IS
13931 l_negative_rcpt_code NUMBER;
13932 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13933 BEGIN
13934 SELECT negative_inv_receipt_code
13935 INTO l_negative_rcpt_code
13936 FROM mtl_parameters
13937 WHERE organization_id = p_organization_id;
13938
13939 IF (l_negative_rcpt_code = 1) THEN
13940 -- Negative inventory balances allowed
13941
13942 IF (p_lpn_id IS NULL
13943 OR p_lpn_id = 0) THEN
13944 SELECT COUNT(*)
13945 INTO x_lot_num_lov_count
13946 FROM mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt
13947 WHERE mln.organization_id = p_organization_id
13948 AND mln.inventory_item_id = p_item_id
13949 AND mln.lot_number LIKE(p_lot_number || '%')
13950 AND mtlt.lot_number = mln.lot_number
13951 AND mtlt.transaction_temp_id = p_txn_temp_id
13952 AND inv_material_status_grp.is_status_applicable(
13953 p_wms_installed
13954 , NULL
13955 , p_transaction_type_id
13956 , NULL
13957 , NULL
13958 , p_organization_id
13959 , p_item_id
13960 , NULL
13961 , NULL
13962 , mln.lot_number
13963 , NULL
13964 , 'O'
13965 ) = 'Y';
13966 ELSE
13967 -- It however remains same for LPNs
13968 SELECT COUNT(*)
13969 INTO x_lot_num_lov_count
13970 FROM mtl_onhand_quantities_detail moq, mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt, wms_lpn_contents wlc
13971 WHERE mln.organization_id = p_organization_id
13972 AND mln.inventory_item_id = p_item_id
13973 AND mln.lot_number LIKE(p_lot_number || '%')
13974 AND moq.lot_number = mln.lot_number
13975 AND moq.inventory_item_id = mln.inventory_item_id
13976 AND moq.organization_id = mln.organization_id
13977 AND mtlt.lot_number = mln.lot_number
13978 AND mtlt.transaction_temp_id = p_txn_temp_id
13979 AND moq.containerized_flag = 1
13980 AND wlc.parent_lpn_id = p_lpn_id
13981 AND wlc.lot_number = mln.lot_number
13982 AND wlc.inventory_item_id = p_item_id
13983 AND wlc.organization_id = p_organization_id
13984 AND moq.subinventory_code = NVL(p_subinventory_code, moq.subinventory_code)
13985 AND NVL(moq.locator_id, -1) = NVL(NVL(p_locator_id, moq.locator_id), -1)
13986 AND inv_material_status_grp.is_status_applicable(
13987 p_wms_installed
13988 , NULL
13989 , p_transaction_type_id
13990 , NULL
13991 , NULL
13992 , p_organization_id
13993 , p_item_id
13994 , NULL
13995 , NULL
13996 , mln.lot_number
13997 , NULL
13998 , 'O'
13999 ) = 'Y';
14000 END IF;
14001 ELSE
14002 -- Negative inventory balances not allowed
14003
14004 IF (p_lpn_id IS NULL
14005 OR p_lpn_id = 0) THEN
14006 SELECT COUNT(*)
14007 INTO x_lot_num_lov_count
14008 FROM mtl_onhand_quantities_detail moq, mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt
14009 WHERE mln.organization_id = p_organization_id
14010 AND mln.inventory_item_id = p_item_id
14011 AND mln.lot_number LIKE(p_lot_number || '%')
14012 AND moq.lot_number = mln.lot_number
14013 AND moq.inventory_item_id = mln.inventory_item_id
14014 AND moq.organization_id = mln.organization_id
14015 AND mtlt.lot_number = mln.lot_number
14016 AND mtlt.transaction_temp_id = p_txn_temp_id
14017 AND moq.containerized_flag = 2
14018 AND moq.subinventory_code = NVL(p_subinventory_code, moq.subinventory_code)
14019 AND NVL(moq.locator_id, -1) = NVL(NVL(p_locator_id, moq.locator_id), -1)
14020 AND inv_material_status_grp.is_status_applicable(
14021 p_wms_installed
14022 , NULL
14023 , p_transaction_type_id
14024 , NULL
14025 , NULL
14026 , p_organization_id
14027 , p_item_id
14028 , NULL
14029 , NULL
14030 , mln.lot_number
14031 , NULL
14032 , 'O'
14033 ) = 'Y';
14034 ELSE
14035 SELECT COUNT(*)
14036 INTO x_lot_num_lov_count
14037 FROM mtl_onhand_quantities_detail moq, mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt, wms_lpn_contents wlc
14038 WHERE mln.organization_id = p_organization_id
14039 AND mln.inventory_item_id = p_item_id
14040 AND mln.lot_number LIKE(p_lot_number || '%')
14041 AND moq.lot_number = mln.lot_number
14042 AND moq.inventory_item_id = mln.inventory_item_id
14043 AND moq.organization_id = mln.organization_id
14044 AND mtlt.lot_number = mln.lot_number
14045 AND mtlt.transaction_temp_id = p_txn_temp_id
14046 AND moq.containerized_flag = 1
14047 AND wlc.parent_lpn_id = p_lpn_id
14048 AND wlc.lot_number = mln.lot_number
14049 AND wlc.inventory_item_id = p_item_id
14050 AND wlc.organization_id = p_organization_id
14051 AND moq.subinventory_code = NVL(p_subinventory_code, moq.subinventory_code)
14052 AND NVL(moq.locator_id, -1) = NVL(NVL(p_locator_id, moq.locator_id), -1)
14053 AND inv_material_status_grp.is_status_applicable(
14054 p_wms_installed
14055 , NULL
14056 , p_transaction_type_id
14057 , NULL
14058 , NULL
14059 , p_organization_id
14060 , p_item_id
14061 , NULL
14062 , NULL
14063 , mln.lot_number
14064 , NULL
14065 , 'O'
14066 ) = 'Y';
14067 END IF;
14068 END IF;
14069 END get_td_lot_lov_count;
14070
14071 PROCEDURE validate_sub_loc_status(
14072 p_wms_installed IN VARCHAR2
14073 , p_temp_id IN NUMBER
14074 , p_confirmed_sub IN VARCHAR2
14075 , p_confirmed_loc_id IN NUMBER
14076 , x_return_status OUT NOCOPY VARCHAR2
14077 , x_msg_count OUT NOCOPY NUMBER
14078 , x_msg_data OUT NOCOPY VARCHAR2
14079 , x_result OUT NOCOPY NUMBER
14080 ) IS
14081 l_transaction_type_id NUMBER;
14082 l_org_id NUMBER;
14083 l_item_id NUMBER;
14084 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14085 BEGIN
14086 IF (l_debug = 1) THEN
14087 mydebug('validate_sub_loc_status: validate_sub_loc_status begins');
14088 END IF;
14089
14090 x_return_status := fnd_api.g_ret_sts_success;
14091
14092 SELECT mmtt.transaction_type_id
14093 , mmtt.organization_id
14094 , mmtt.inventory_item_id
14095 INTO l_transaction_type_id
14096 , l_org_id
14097 , l_item_id
14098 FROM mtl_material_transactions_temp mmtt
14099 WHERE mmtt.transaction_temp_id = p_temp_id;
14100
14101 IF inv_material_status_grp.is_status_applicable(
14102 p_wms_installed => p_wms_installed
14103 , p_trx_status_enabled => NULL
14104 , p_trx_type_id => l_transaction_type_id
14105 , p_lot_status_enabled => NULL
14106 , p_serial_status_enabled => NULL
14107 , p_organization_id => l_org_id
14108 , p_inventory_item_id => l_item_id
14109 , p_sub_code => p_confirmed_sub
14110 , p_locator_id => p_confirmed_loc_id
14111 , p_lot_number => NULL
14112 , p_serial_number => NULL
14113 , p_object_type => 'Z'
14114 ) = 'Y'
14115 AND inv_material_status_grp.is_status_applicable(
14116 p_wms_installed => p_wms_installed
14117 , p_trx_status_enabled => NULL
14118 , p_trx_type_id => l_transaction_type_id
14119 , p_lot_status_enabled => NULL
14120 , p_serial_status_enabled => NULL
14121 , p_organization_id => l_org_id
14122 , p_inventory_item_id => l_item_id
14123 , p_sub_code => p_confirmed_sub
14124 , p_locator_id => p_confirmed_loc_id
14125 , p_lot_number => NULL
14126 , p_serial_number => NULL
14127 , p_object_type => 'L'
14128 ) = 'Y' THEN
14129 x_result := 1;
14130
14131 IF (l_debug = 1) THEN
14132 mydebug('validate_sub_loc_status: Material status is correct. x_result = 1');
14133 END IF;
14134 ELSE
14135 x_result := 0;
14136
14137 IF (l_debug = 1) THEN
14138 mydebug('validate_sub_loc_status: Material status is incorrect. x_result = 0');
14139 END IF;
14140 END IF;
14141
14142 IF (l_debug = 1) THEN
14143 mydebug('validate_sub_loc_status: End of validate_sub_loc_status');
14144 END IF;
14145 EXCEPTION
14146 WHEN fnd_api.g_exc_error THEN
14147 x_return_status := fnd_api.g_ret_sts_error;
14148
14149 IF (l_debug = 1) THEN
14150 mydebug('validate_sub_loc_status: Error - ' || SQLERRM);
14151 END IF;
14152
14153 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14154 WHEN OTHERS THEN
14155 x_return_status := fnd_api.g_ret_sts_unexp_error;
14156
14157 IF (l_debug = 1) THEN
14158 mydebug('validate_sub_loc_status: Unexpected Error - ' || SQLERRM);
14159 END IF;
14160
14161 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14162 END validate_sub_loc_status;
14163
14164 PROCEDURE validate_pick_drop_sub(
14165 p_temp_id IN NUMBER
14166 , p_confirmed_drop_sub IN VARCHAR2
14167 , x_return_status OUT NOCOPY VARCHAR2
14168 , x_msg_count OUT NOCOPY NUMBER
14169 , x_msg_data OUT NOCOPY VARCHAR2
14170 ) IS
14171 l_xfr_lpn_id NUMBER;
14172 l_lpn_controlled_flag NUMBER;
14173 l_count NUMBER := 0;
14174 l_orig_xfr_sub VARCHAR2(30);
14175 l_mmtt_mo_type NUMBER := NULL;
14176 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14177 l_wms_task_type NUMBER;
14178 BEGIN
14179 IF (l_debug = 1) THEN
14180 mydebug('validate_pick_drop_sub: validate_pick_drop_sub begins ');
14181 mydebug(' p_temp_id = ' || p_temp_id);
14182 mydebug(' p_confirmed_drop_sub = ' || p_confirmed_drop_sub);
14183 END IF;
14184
14185 x_return_status := fnd_api.g_ret_sts_success;
14186
14187 -- bug fix 2805229
14188 SELECT wms_task_type
14189 INTO l_wms_task_type
14190 FROM mtl_material_transactions_temp
14191 WHERE transaction_temp_id = p_temp_id;
14192
14193 IF l_wms_task_type = 7 THEN -- staging move
14194 IF (l_debug = 1) THEN
14195 mydebug('Skip further validation because l_wms_task_type = ' || l_wms_task_type);
14196 END IF;
14197
14198 RETURN;
14199 END IF;
14200
14201 -- end bug fix 2805229
14202
14203
14204
14205 SELECT mtrh.move_order_type
14206 INTO l_mmtt_mo_type
14207 FROM mtl_txn_request_headers mtrh, -- mo header for the new task
14208 mtl_txn_request_lines mtrl, mtl_material_transactions_temp mmtt
14209 WHERE mtrh.header_id = mtrl.header_id
14210 AND mtrl.line_id = mmtt.move_order_line_id
14211 AND mmtt.transaction_temp_id = p_temp_id;
14212
14213 IF (l_debug = 1) THEN
14214 mydebug('validate_pick_drop_sub : l_mmtt_mo_type = ' || l_mmtt_mo_type);
14215 END IF;
14216
14217 SELECT msi.lpn_controlled_flag
14218 , mmtt.transfer_lpn_id
14219 , mmtt.transfer_subinventory
14220 INTO l_lpn_controlled_flag
14221 , l_xfr_lpn_id
14222 , l_orig_xfr_sub
14223 FROM mtl_material_transactions_temp mmtt, mtl_secondary_inventories msi
14224 WHERE mmtt.transaction_temp_id = p_temp_id
14225 AND mmtt.organization_id = msi.organization_id
14226 AND msi.secondary_inventory_name = p_confirmed_drop_sub;
14227
14228 IF l_lpn_controlled_flag = wms_globals.g_lpn_controlled_sub THEN
14229 IF (l_mmtt_mo_type = 5) THEN
14230 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
14231 fnd_msg_pub.ADD;
14232 RAISE fnd_api.g_exc_error;
14233 END IF;
14234
14235 IF (l_debug = 1) THEN
14236 mydebug('validate_pick_drop_sub: Transfer Sub is LPN Controlled');
14237 END IF;
14238
14239 l_count := 0;
14240
14241 BEGIN
14242 SELECT 1
14243 INTO l_count
14244 FROM DUAL
14245 WHERE EXISTS(
14246 SELECT 1
14247 FROM mtl_material_transactions_temp mmtt
14248 WHERE mmtt.transaction_temp_id <> p_temp_id
14249 AND mmtt.transfer_lpn_id = l_xfr_lpn_id
14250 AND mmtt.transfer_subinventory <> p_confirmed_drop_sub
14251 AND mmtt.transfer_subinventory <> l_orig_xfr_sub);
14252 EXCEPTION
14253 WHEN NO_DATA_FOUND THEN
14254 l_count := 0;
14255 END;
14256
14257 IF l_count > 0 THEN
14258 IF (l_debug = 1) THEN
14259 mydebug('validate_pick_drop_sub: Drop LPN is going to a different sub');
14260 END IF;
14261
14262 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
14263 fnd_msg_pub.ADD;
14264 RAISE fnd_api.g_exc_error;
14265 END IF;
14266 END IF;
14267
14268 IF (l_debug = 1) THEN
14269 mydebug('validate_pick_drop_sub: End of validate_pick_drop_sub');
14270 END IF;
14271 EXCEPTION
14272 WHEN fnd_api.g_exc_error THEN
14273 x_return_status := fnd_api.g_ret_sts_error;
14274
14275 IF (l_debug = 1) THEN
14276 mydebug('validate_pick_drop_sub: Error - ' || SQLERRM);
14277 END IF;
14278
14279 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14280 WHEN OTHERS THEN
14281 x_return_status := fnd_api.g_ret_sts_unexp_error;
14282
14283 IF (l_debug = 1) THEN
14284 mydebug('validate_pick_drop_sub: Unexpected Error - ' || SQLERRM);
14285 END IF;
14286
14287 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14288 END validate_pick_drop_sub;
14289
14290 PROCEDURE create_lock_mmtt_temp_id(lock_name IN VARCHAR2, x_return_status OUT NOCOPY VARCHAR2) IS
14291 l_lock_id VARCHAR2(50);
14292 lock_result NUMBER;
14293 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14294 BEGIN
14295 IF (l_debug = 1) THEN
14296 mydebug('Inside create_lock_mmtt_temp_id');
14297 END IF;
14298
14299 DBMS_LOCK.allocate_unique(lockname => lock_name, lockhandle => l_lock_id);
14300 lock_result :=
14301 DBMS_LOCK.request --EXCLUSIVE LOCK
14302 (lockhandle => l_lock_id, lockmode => 6, TIMEOUT => 5, -- 5 seconds ???
14303 release_on_commit => TRUE);
14304
14305 IF (l_debug = 1) THEN
14306 mydebug('dbms_lock,lock_result:' || lock_result);
14307 END IF;
14308
14309 IF (lock_result = 0) THEN
14310 IF (l_debug = 1) THEN
14311 mydebug('creating lock mmtt.temp_id, to be used in CTRLBD is successful');
14312 END IF;
14313
14314 x_return_status := fnd_api.g_ret_sts_success;
14315 ELSIF lock_result IN(1, 2) THEN
14316 IF (l_debug = 1) THEN
14317 mydebug('timeout for the creation of user lock or deadlock');
14318 END IF;
14319
14320 fnd_message.set_name('WMS', 'WMS_RECORD_BEING_CHANGED');
14321 fnd_msg_pub.ADD;
14322 RAISE fnd_api.g_exc_error;
14323 END IF;
14324 EXCEPTION
14325 WHEN fnd_api.g_exc_error THEN
14326 x_return_status := fnd_api.g_ret_sts_error;
14327 WHEN OTHERS THEN
14328 x_return_status := fnd_api.g_ret_sts_unexp_error;
14329
14330 IF (l_debug = 1) THEN
14331 mydebug('lock_mmtt_temp_id - ' || SQLERRM);
14332 END IF;
14333 END create_lock_mmtt_temp_id;
14334
14335 /*
14336 -- This procedure will be used for distributing the quantity
14337 -- picked (in one or more parent MMTT lines) to the original
14338 -- child MMTT lines (again one or more)
14339 */
14340 PROCEDURE bulk_pick(
14341 p_temp_id IN NUMBER
14342 , p_txn_hdr_id IN NUMBER
14343 , p_org_id IN NUMBER
14344 , p_pick_qty_remaining IN NUMBER
14345 , p_user_id IN NUMBER
14346 , x_new_txn_hdr_id OUT NOCOPY NUMBER
14347 , x_return_status OUT NOCOPY VARCHAR2
14348 , x_msg_count OUT NOCOPY NUMBER
14349 , x_msg_data OUT NOCOPY VARCHAR2
14350 , p_reason_id IN NUMBER --Added bug 3765153
14351 ) IS
14352 CURSOR c_parent_mmtt_lines IS
14353 SELECT mmtt.transaction_temp_id
14354 , mmtt.inventory_item_id
14355 , mmtt.subinventory_code
14356 , mmtt.locator_id
14357 , NVL(mmtt.content_lpn_id, mmtt.lpn_id)
14358 , mmtt.transfer_lpn_id
14359 , mmtt.transaction_uom
14360 , mmtt.transaction_quantity
14361 , mmtt.primary_quantity
14362 FROM mtl_material_transactions_temp mmtt
14363 WHERE mmtt.transaction_header_id = p_txn_hdr_id
14364 AND mmtt.organization_id = p_org_id
14365 AND mmtt.transaction_quantity > 0
14366 AND mmtt.parent_line_id is NULL --Added bug3765153 to ensure only parent line are picked
14367 ORDER BY mmtt.transaction_quantity DESC;
14368
14369 CURSOR c_child_mmtt_lines IS
14370 SELECT mmtt.transaction_temp_id
14371 , mmtt.transaction_uom
14372 , mmtt.transaction_quantity
14373 , mmtt.primary_quantity
14374 FROM mtl_material_transactions_temp mmtt
14375 WHERE mmtt.parent_line_id = p_temp_id
14376 AND mmtt.organization_id = p_org_id
14377 ORDER BY mmtt.transaction_quantity DESC;
14378
14379 CURSOR unpicked_child_mmtt_lines(p_parent_line_id NUMBER,p_org_id NUMBER) IS
14380 SELECT mmtt.transaction_temp_id
14381 FROM mtl_material_transactions_temp mmtt
14382 WHERE mmtt.organization_id = p_org_id
14383 AND mmtt.parent_line_id = p_parent_line_id; --Added bug3765153 to determine and back order unpicked lines
14384
14385 l_parent_txn_qty NUMBER;
14386 l_child_txn_qty NUMBER := 0; --bug3765153 defaulted to 0
14387 l_parent_pri_qty NUMBER;
14388 l_child_pri_qty NUMBER;
14389 l_parent_uom VARCHAR2(10);
14390 l_child_uom VARCHAR2(10);
14391 l_parent_txn_temp_id NUMBER;
14392 l_child_txn_temp_id NUMBER;
14393 l_item_id NUMBER;
14394 l_parent_sub_code VARCHAR2(30);
14395 l_parent_loc_id NUMBER;
14396 l_lpn_id NUMBER;
14397 l_transfer_lpn_id NUMBER;
14398 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14399 l_new_temp_id NUMBER; --Added bug3765153
14400 BEGIN
14401 x_return_status := fnd_api.g_ret_sts_success;
14402
14403 IF l_debug = 1 THEN
14404 mydebug('Dispatching Bulk Pick Tasks for TxnHdrID = ' || p_txn_hdr_id || ' : TxnTempID = ' || p_temp_id);
14405 END IF;
14406
14407 SELECT mtl_material_transactions_s.NEXTVAL
14408 INTO x_new_txn_hdr_id
14409 FROM DUAL;
14410
14411 OPEN c_parent_mmtt_lines;
14412
14413 LOOP
14414 FETCH c_parent_mmtt_lines INTO l_parent_txn_temp_id
14415 , l_item_id
14416 , l_parent_sub_code
14417 , l_parent_loc_id
14418 , l_lpn_id
14419 , l_transfer_lpn_id
14420 , l_parent_uom
14421 , l_parent_txn_qty
14422 , l_parent_pri_qty;
14423 EXIT WHEN c_parent_mmtt_lines%NOTFOUND;
14424 OPEN c_child_mmtt_lines;
14425
14426 LOOP
14427 IF l_child_txn_qty = 0 THEN --Added bug3765153
14428 IF l_debug = 1 THEN
14429 mydebug('Bulk Pick:Fethcing new child record');
14430 END IF;
14431 FETCH c_child_mmtt_lines INTO l_child_txn_temp_id, l_child_uom, l_child_txn_qty, l_child_pri_qty;
14432 EXIT WHEN c_child_mmtt_lines%NOTFOUND;
14433 END IF;
14434
14435 IF l_debug = 1 THEN
14436 mydebug('Child Temp ID = ' || l_child_txn_temp_id);
14437 mydebug('Current Parent Qty = ' || l_parent_txn_qty || ' : Child Qty = ' || l_child_txn_qty);
14438 END IF;
14439
14440 IF l_parent_uom <> l_child_uom THEN
14441 l_child_txn_qty :=
14442 inv_convert.inv_um_convert(
14443 item_id => l_item_id
14444 , PRECISION => NULL
14445 , from_quantity => l_child_txn_qty
14446 , from_unit => l_child_uom
14447 , to_unit => l_parent_uom
14448 , from_name => NULL
14449 , to_name => NULL
14450 );
14451 END IF;
14452
14453 IF l_parent_txn_qty >= l_child_txn_qty THEN
14454 UPDATE mtl_material_transactions_temp mmtt
14455 SET mmtt.transaction_header_id = x_new_txn_hdr_id
14456 , mmtt.transfer_lpn_id = l_transfer_lpn_id
14457 , mmtt.lpn_id = l_lpn_id
14458 , mmtt.parent_line_id = l_parent_txn_temp_id --Modified from NULL bug3765153
14459 , mmtt.subinventory_code = l_parent_sub_code
14460 , mmtt.locator_id = l_parent_loc_id
14461 , mmtt.transaction_uom = l_parent_uom
14462 , mmtt.last_update_date = SYSDATE
14463 , mmtt.last_updated_by = p_user_id
14464 WHERE mmtt.transaction_temp_id = l_child_txn_temp_id;
14465
14466 l_parent_txn_qty := l_parent_txn_qty - l_child_txn_qty;
14467 l_parent_pri_qty := l_parent_pri_qty - l_child_pri_qty;
14468 l_child_txn_qty := 0;
14469 l_child_pri_qty := 0;
14470 EXIT WHEN l_parent_txn_qty = 0;
14471 ELSE -- Current Child Qty is greater than Parent Picked Qty
14472
14473 select mtl_material_transactions_s.NEXTVAL
14474 into l_new_temp_id
14475 from dual; --Added bug3765153
14476
14477 INSERT INTO mtl_material_transactions_temp
14478 (
14479 transaction_header_id
14480 , transaction_temp_id
14481 , source_code
14482 , source_line_id
14483 , transaction_mode
14484 , lock_flag
14485 , last_update_date
14486 , last_updated_by
14487 , creation_date
14488 , created_by
14489 , last_update_login
14490 , request_id
14491 , program_application_id
14492 , program_id
14493 , program_update_date
14494 , inventory_item_id
14495 , revision
14496 , organization_id
14497 , subinventory_code
14498 , locator_id
14499 , transaction_quantity
14500 , primary_quantity
14501 , transaction_uom
14502 , transaction_cost
14503 , transaction_type_id
14504 , transaction_action_id
14505 , transaction_source_type_id
14506 , transaction_source_id
14507 , transaction_source_name
14508 , transaction_date
14509 , acct_period_id
14510 , distribution_account_id
14511 , transaction_reference
14512 , requisition_line_id
14513 , requisition_distribution_id
14514 , reason_id
14515 , lot_number
14516 , lot_expiration_date
14517 , serial_number
14518 , receiving_document
14519 , demand_id
14520 , rcv_transaction_id
14521 , move_transaction_id
14522 , completion_transaction_id
14523 , wip_entity_type
14524 , schedule_id
14525 , repetitive_line_id
14526 , employee_code
14527 , primary_switch
14528 , schedule_update_code
14529 , setup_teardown_code
14530 , item_ordering
14531 , negative_req_flag
14532 , operation_seq_num
14533 , picking_line_id
14534 , trx_source_line_id
14535 , trx_source_delivery_id
14536 , physical_adjustment_id
14537 , cycle_count_id
14538 , rma_line_id
14539 , customer_ship_id
14540 , currency_code
14541 , currency_conversion_rate
14542 , currency_conversion_type
14543 , currency_conversion_date
14544 , ussgl_transaction_code
14545 , vendor_lot_number
14546 , encumbrance_account
14547 , encumbrance_amount
14548 , ship_to_location
14549 , shipment_number
14550 , transfer_cost
14551 , transportation_cost
14552 , transportation_account
14553 , freight_code
14554 , containers
14555 , waybill_airbill
14556 , expected_arrival_date
14557 , transfer_subinventory
14558 , transfer_organization
14559 , transfer_to_location
14560 , new_average_cost
14561 , value_change
14562 , percentage_change
14563 , material_allocation_temp_id
14564 , demand_source_header_id
14565 , demand_source_line
14566 , demand_source_delivery
14567 , item_segments
14568 , item_description
14569 , item_trx_enabled_flag
14570 , item_location_control_code
14571 , item_restrict_subinv_code
14572 , item_restrict_locators_code
14573 , item_revision_qty_control_code
14574 , item_primary_uom_code
14575 , item_uom_class
14576 , item_shelf_life_code
14577 , item_shelf_life_days
14578 , item_lot_control_code
14579 , item_serial_control_code
14580 , item_inventory_asset_flag
14581 , allowed_units_lookup_code
14582 , department_id
14583 , department_code
14584 , wip_supply_type
14585 , supply_subinventory
14586 , supply_locator_id
14587 , valid_subinventory_flag
14588 , valid_locator_flag
14589 , locator_segments
14590 , current_locator_control_code
14591 , number_of_lots_entered
14592 , wip_commit_flag
14593 , next_lot_number
14594 , lot_alpha_prefix
14595 , next_serial_number
14596 , serial_alpha_prefix
14597 , shippable_flag
14598 , posting_flag
14599 , required_flag
14600 , process_flag
14601 , ERROR_CODE
14602 , error_explanation
14603 , attribute_category
14604 , attribute1
14605 , attribute2
14606 , attribute3
14607 , attribute4
14608 , attribute5
14609 , attribute6
14610 , attribute7
14611 , attribute8
14612 , attribute9
14613 , attribute10
14614 , attribute11
14615 , attribute12
14616 , attribute13
14617 , attribute14
14618 , attribute15
14619 , movement_id
14620 , reservation_quantity
14621 , shipped_quantity
14622 , transaction_line_number
14623 , task_id
14624 , to_task_id
14625 , source_task_id
14626 , project_id
14627 , source_project_id
14628 , pa_expenditure_org_id
14629 , to_project_id
14630 , expenditure_type
14631 , final_completion_flag
14632 , transfer_percentage
14633 , transaction_sequence_id
14634 , material_account
14635 , material_overhead_account
14636 , resource_account
14637 , outside_processing_account
14638 , overhead_account
14639 , flow_schedule
14640 , cost_group_id
14641 , demand_class
14642 , qa_collection_id
14643 , kanban_card_id
14644 , overcompletion_transaction_id
14645 , overcompletion_primary_qty
14646 , overcompletion_transaction_qty
14647 , end_item_unit_number
14648 , scheduled_payback_date
14649 , line_type_code
14650 , parent_transaction_temp_id
14651 , put_away_strategy_id
14652 , put_away_rule_id
14653 , pick_strategy_id
14654 , pick_rule_id
14655 , common_bom_seq_id
14656 , common_routing_seq_id
14657 , cost_type_id
14658 , org_cost_group_id
14659 , move_order_line_id
14660 , task_group_id
14661 , pick_slip_number
14662 , reservation_id
14663 , transaction_status
14664 , transfer_cost_group_id
14665 , lpn_id
14666 , transfer_lpn_id
14667 , content_lpn_id
14668 , cartonization_id
14669 , standard_operation_id
14670 , wms_task_type
14671 , task_priority
14672 , container_item_id
14673 , operation_plan_id
14674 , parent_line_id
14675 )
14676 (SELECT transaction_header_id
14677 , l_new_temp_id --Changed from mtl_material_transactions_s.NEXTVAL bug3765153
14678 , source_code
14679 , source_line_id
14680 , transaction_mode
14681 , lock_flag
14682 , SYSDATE
14683 , last_updated_by
14684 , SYSDATE
14685 , created_by
14686 , last_update_login
14687 , request_id
14688 , program_application_id
14689 , program_id
14690 , program_update_date
14691 , inventory_item_id
14692 , revision
14693 , organization_id
14694 , subinventory_code
14695 , locator_id
14696 , l_child_pri_qty - l_parent_pri_qty
14697 , l_child_txn_qty - l_parent_txn_qty
14698 , l_parent_uom
14699 , transaction_cost
14700 , transaction_type_id
14701 , transaction_action_id
14702 , transaction_source_type_id
14703 , transaction_source_id
14704 , transaction_source_name
14705 , transaction_date
14706 , acct_period_id
14707 , distribution_account_id
14708 , transaction_reference
14709 , requisition_line_id
14710 , requisition_distribution_id
14711 , reason_id
14712 , lot_number
14713 , lot_expiration_date
14714 , serial_number
14715 , receiving_document
14716 , demand_id
14717 , rcv_transaction_id
14718 , move_transaction_id
14719 , completion_transaction_id
14720 , wip_entity_type
14721 , schedule_id
14722 , repetitive_line_id
14723 , employee_code
14724 , primary_switch
14725 , schedule_update_code
14726 , setup_teardown_code
14727 , item_ordering
14728 , negative_req_flag
14729 , operation_seq_num
14730 , picking_line_id
14731 , trx_source_line_id
14732 , trx_source_delivery_id
14733 , physical_adjustment_id
14734 , cycle_count_id
14735 , rma_line_id
14736 , customer_ship_id
14737 , currency_code
14738 , currency_conversion_rate
14739 , currency_conversion_type
14740 , currency_conversion_date
14741 , ussgl_transaction_code
14742 , vendor_lot_number
14743 , encumbrance_account
14744 , encumbrance_amount
14745 , ship_to_location
14746 , shipment_number
14747 , transfer_cost
14748 , transportation_cost
14749 , transportation_account
14750 , freight_code
14751 , containers
14752 , waybill_airbill
14753 , expected_arrival_date
14754 , transfer_subinventory
14755 , transfer_organization
14756 , transfer_to_location
14757 , new_average_cost
14758 , value_change
14759 , percentage_change
14760 , material_allocation_temp_id
14761 , demand_source_header_id
14762 , demand_source_line
14763 , demand_source_delivery
14764 , item_segments
14765 , item_description
14766 , item_trx_enabled_flag
14767 , item_location_control_code
14768 , item_restrict_subinv_code
14769 , item_restrict_locators_code
14770 , item_revision_qty_control_code
14771 , item_primary_uom_code
14772 , item_uom_class
14773 , item_shelf_life_code
14774 , item_shelf_life_days
14775 , item_lot_control_code
14776 , item_serial_control_code
14777 , item_inventory_asset_flag
14778 , allowed_units_lookup_code
14779 , department_id
14780 , department_code
14781 , wip_supply_type
14782 , supply_subinventory
14783 , supply_locator_id
14784 , valid_subinventory_flag
14785 , valid_locator_flag
14786 , locator_segments
14787 , current_locator_control_code
14788 , number_of_lots_entered
14789 , wip_commit_flag
14790 , next_lot_number
14791 , lot_alpha_prefix
14792 , next_serial_number
14793 , serial_alpha_prefix
14794 , shippable_flag
14795 , posting_flag
14796 , required_flag
14797 , process_flag
14798 , ERROR_CODE
14799 , error_explanation
14800 , attribute_category
14801 , attribute1
14802 , attribute2
14803 , attribute3
14804 , attribute4
14805 , attribute5
14806 , attribute6
14807 , attribute7
14808 , attribute8
14809 , attribute9
14810 , attribute10
14811 , attribute11
14812 , attribute12
14813 , attribute13
14814 , attribute14
14815 , attribute15
14816 , movement_id
14817 , reservation_quantity
14818 , shipped_quantity
14819 , transaction_line_number
14820 , task_id
14821 , to_task_id
14822 , source_task_id
14823 , project_id
14824 , source_project_id
14825 , pa_expenditure_org_id
14826 , to_project_id
14827 , expenditure_type
14828 , final_completion_flag
14829 , transfer_percentage
14830 , transaction_sequence_id
14831 , material_account
14832 , material_overhead_account
14833 , resource_account
14834 , outside_processing_account
14835 , overhead_account
14836 , flow_schedule
14837 , cost_group_id
14838 , demand_class
14839 , qa_collection_id
14840 , kanban_card_id
14841 , overcompletion_transaction_id
14842 , overcompletion_primary_qty
14843 , overcompletion_transaction_qty
14844 , end_item_unit_number
14845 , scheduled_payback_date
14846 , line_type_code
14847 , parent_transaction_temp_id
14848 , put_away_strategy_id
14849 , put_away_rule_id
14850 , pick_strategy_id
14851 , pick_rule_id
14852 , common_bom_seq_id
14853 , common_routing_seq_id
14854 , cost_type_id
14855 , org_cost_group_id
14856 , move_order_line_id
14857 , task_group_id
14858 , pick_slip_number
14859 , reservation_id
14860 , transaction_status
14861 , transfer_cost_group_id
14862 , lpn_id
14863 , transfer_lpn_id
14864 , content_lpn_id
14865 , cartonization_id
14866 , standard_operation_id
14867 , wms_task_type
14868 , task_priority
14869 , container_item_id
14870 , operation_plan_id
14871 , parent_line_id
14872 FROM mtl_material_transactions_temp
14873 WHERE transaction_temp_id = l_child_txn_temp_id);
14874
14875 UPDATE mtl_material_transactions_temp mmtt
14876 SET mmtt.transaction_header_id = x_new_txn_hdr_id
14877 , mmtt.transaction_quantity = l_parent_txn_qty
14878 , mmtt.primary_quantity = l_parent_pri_qty
14879 , mmtt.parent_line_id = NULL --l_parent_txn_temp_id --Modified from NULL bug3765153
14880 , mmtt.transfer_lpn_id = l_transfer_lpn_id
14881 , mmtt.lpn_id = l_lpn_id
14882 , mmtt.subinventory_code = l_parent_sub_code
14883 , mmtt.locator_id = l_parent_loc_id
14884 , mmtt.transaction_uom = l_parent_uom
14885 , mmtt.last_update_date = SYSDATE
14886 , mmtt.last_updated_by = p_user_id
14887 WHERE mmtt.transaction_temp_id = l_child_txn_temp_id;
14888
14889 --Added bug 3765153
14890 l_child_txn_temp_id := l_new_temp_id;
14891 l_child_pri_qty := l_child_pri_qty - l_parent_pri_qty;
14892 l_child_txn_qty := l_child_txn_qty - l_parent_txn_qty;
14893 l_parent_txn_qty := 0;
14894 l_parent_pri_qty := 0;
14895
14896 IF l_debug = 1 THEN
14897 mydebug('BULK_PICK:new MMTT tmp id:'||l_new_temp_id);
14898 mydebug('BULK_PICK:new child pri qty:'||l_child_pri_qty);
14899 mydebug('BULK_PICK:new child txn qty:'||l_child_txn_qty);
14900 END IF;
14901 --end bug 3765153
14902 EXIT;
14903 END IF;
14904 END LOOP;
14905
14906 CLOSE c_child_mmtt_lines;
14907 END LOOP;
14908
14909 CLOSE c_parent_mmtt_lines;
14910
14911 IF l_debug = 1 THEN
14912 mydebug('Dispatching Child Tasks');
14913 END IF;
14914
14915 -- Dispatching Picked Child Tasks
14916 INSERT INTO wms_dispatched_tasks
14917 (
14918 task_id
14919 , transaction_temp_id
14920 , organization_id
14921 , user_task_type
14922 , person_id
14923 , effective_start_date
14924 , effective_end_date
14925 , equipment_id
14926 , equipment_instance
14927 , person_resource_id
14928 , machine_resource_id
14929 , status
14930 , dispatched_time
14931 , last_update_date
14932 , last_updated_by
14933 , creation_date
14934 , created_by
14935 , task_type
14936 , loaded_time
14937 , operation_plan_id
14938 , move_order_line_id
14939 )
14940 (SELECT wms_dispatched_tasks_s.NEXTVAL
14941 , mmtt.transaction_temp_id
14942 , mmtt.organization_id
14943 , wdt.user_task_type
14944 , wdt.person_id
14945 , wdt.effective_start_date
14946 , wdt.effective_end_date
14947 , wdt.equipment_id
14948 , wdt.equipment_instance
14949 , wdt.person_resource_id
14950 , wdt.machine_resource_id
14951 , 4
14952 , wdt.dispatched_time
14953 , SYSDATE
14954 , p_user_id
14955 , SYSDATE
14956 , p_user_id
14957 , wdt.task_type
14958 , SYSDATE
14959 , mmtt.operation_plan_id
14960 , mmtt.move_order_line_id
14961 FROM wms_dispatched_tasks wdt, mtl_material_transactions_temp mmtt
14962 WHERE wdt.transaction_temp_id = p_temp_id
14963 AND mmtt.transaction_header_id = x_new_txn_hdr_id);
14964
14965 DELETE FROM wms_dispatched_tasks wdt
14966 WHERE wdt.transaction_temp_id IN(SELECT mmtt.transaction_temp_id
14967 FROM mtl_material_transactions_temp mmtt
14968 WHERE mmtt.transaction_header_id = p_txn_hdr_id
14969 AND mmtt.organization_id = p_org_id);
14970
14971 --Added bug 3765153 to clean up lines with remaining qty
14972 IF p_pick_qty_remaining > 0 THEN
14973 for mmtt_rec in unpicked_child_mmtt_lines(p_temp_id,p_org_id) LOOP
14974 mydebug('BULK_PICK:calling cleanup_task for mmtt line:'||mmtt_rec.transaction_temp_id);
14975 cleanup_task(
14976 p_temp_id => mmtt_rec.transaction_temp_id
14977 , p_qty_rsn_id => p_reason_id
14978 , p_user_id => p_user_id
14979 , x_return_status => x_return_status
14980 , x_msg_count => x_msg_count
14981 , x_msg_data => x_msg_data
14982 );
14983
14984 IF x_return_status <> fnd_api.g_ret_sts_success THEN
14985 IF l_debug = 1 THEN
14986 mydebug('BULK_PICK: Error occurred while calling cleanup tasK ');
14987 END IF;
14988 RAISE fnd_api.g_exc_error;
14989 END IF;
14990
14991 END LOOP;
14992 END IF;
14993 --End bug3765153
14994
14995 IF l_debug = 1 THEN
14996 mydebug('Deleting the Parent Task and Parent Line');
14997 END IF;
14998
14999 -- Deleting Parent Tasks. Once loaded, only Child Tasks are considered.
15000
15001 DELETE FROM mtl_material_transactions_temp mmtt
15002 WHERE mmtt.transaction_header_id = p_txn_hdr_id
15003 AND mmtt.organization_id = p_org_id;
15004
15005 -- nullify the parent_line_id for the children lines
15006 -- since the parent lines are gone Bug3765153
15007 update mtl_material_transactions_temp
15008 set parent_line_id = null
15009 where transaction_header_id = x_new_txn_hdr_id;
15010
15011 EXCEPTION
15012 WHEN OTHERS THEN
15013 x_return_status := fnd_api.g_ret_sts_unexp_error;
15014 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
15015
15016 IF (l_debug = 1) THEN
15017 mydebug('Unexpected Error occurred - ' || SQLERRM);
15018 END IF;
15019 END bulk_pick;
15020
15021 PROCEDURE call_workflow(
15022 p_rsn_id IN NUMBER
15023 , p_calling_program IN VARCHAR2
15024 , p_org_id IN NUMBER
15025 , p_tmp_id IN NUMBER DEFAULT NULL
15026 , p_quantity_picked IN NUMBER DEFAULT NULL
15027 , p_dest_sub IN VARCHAR2 DEFAULT NULL
15028 , p_dest_loc IN NUMBER DEFAULT NULL
15029 , x_return_status OUT NOCOPY VARCHAR2
15030 , x_msg_count OUT NOCOPY NUMBER
15031 , x_msg_data OUT NOCOPY VARCHAR2
15032 , x_wf OUT NOCOPY NUMBER
15033 ) IS
15034 l_wf NUMBER := 0;
15035 BEGIN
15036 mydebug('call_workflow :in ');
15037 x_return_status := fnd_api.g_ret_sts_success;
15038
15039 BEGIN
15040 SELECT 1
15041 INTO l_wf
15042 FROM mtl_transaction_reasons
15043 WHERE reason_id = p_rsn_id
15044 AND workflow_name IS NOT NULL
15045 AND workflow_name <> ' '
15046 AND workflow_process IS NOT NULL
15047 AND workflow_process <> ' ';
15048 EXCEPTION
15049 WHEN NO_DATA_FOUND THEN
15050 l_wf := 0;
15051 END;
15052
15053 mydebug('call_workflow- p_rsn_id: ' || p_rsn_id || ':l_wf: ' || l_wf);
15054 x_wf := l_wf; -- Bug 2924823 H to I
15055 IF l_wf > 0 THEN
15056 mydebug(' call workflow : WF exists for this reason id : ' || p_rsn_id || ':');
15057 mydebug(' call workflow : Before Calling WF Wrapper for Qty Discrepancy ');
15058
15059 -- Calling Workflow
15060
15061 IF p_rsn_id > 0 THEN
15062 mydebug('call workflow: Calling ... workflow wrapper');
15063 wms_workflow_wrappers.wf_wrapper(
15064 p_api_version => 1.0
15065 , p_init_msg_list => fnd_api.g_false
15066 , p_commit => fnd_api.g_false
15067 , x_return_status => x_return_status
15068 , x_msg_count => x_msg_count
15069 , x_msg_data => x_msg_data
15070 , p_org_id => p_org_id
15071 , p_rsn_id => p_rsn_id
15072 , p_calling_program => p_calling_program
15073 , p_tmp_id => p_tmp_id
15074 , p_quantity_picked => p_quantity_picked
15075 , p_dest_sub => p_dest_sub
15076 , p_dest_loc => p_dest_loc
15077 );
15078
15079 mydebug('call_workflow : After Calling WF Wrapper');
15080 -- Bug 2924823 H to I
15081 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
15082 mydebug('call_workflow : Error callinf WF wrapper');
15083 FND_MESSAGE.SET_NAME('WMS','WMS_WORK_FLOW_FAIL');
15084 FND_MSG_PUB.ADD;
15085 RAISE FND_API.g_exc_unexpected_error;
15086
15087 ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
15088 mydebug('call_workflow : Error calling WF wrapper');
15089 FND_MESSAGE.SET_NAME('WMS','WMS_WORK_FLOW_FAIL');
15090 FND_MSG_PUB.ADD;
15091 RAISE FND_API.G_EXC_ERROR;
15092 END IF;
15093 END IF;
15094 END IF;
15095 END call_workflow;
15096
15097 /*Added to validate cost group comingle bug3813165*/
15098 procedure validate_loaded_lpn_cg( p_organization_id IN NUMBER,
15099 p_inventory_item_id IN NUMBER,
15100 p_subinventory_code IN VARCHAR2,
15101 p_locator_id IN NUMBER,
15102 p_revision IN VARCHAR2,
15103 p_lot_number IN VARCHAR2,
15104 p_lpn_id IN NUMBER,
15105 p_transfer_lpn_id IN NUMBER,
15106 p_lot_control IN NUMBER,
15107 p_revision_control IN NUMBER,
15108 x_commingle_exist OUT nocopy VARCHAR2,
15109 x_return_status OUT nocopy VARCHAR2)
15110 IS
15111 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15112 l_cur_cost_group_id NUMBER := NULL;
15113 l_exist_cost_group_id NUMBER := NULL;
15114 l_sub VARCHAR2(20);
15115 l_loc NUMBER;
15116 l_rev VARCHAR2(4);
15117 l_lpn NUMBER;
15118 l_ser VARCHAR2(20);
15119 l_lot VARCHAR2(20);
15120 BEGIN
15121 IF (l_debug = 1) THEN
15122 mydebug( 'In check_cg_commingle... ');
15123 mydebug('p_organization_id'||p_organization_id);
15124 mydebug('p_inventory_item_id'||p_inventory_item_id);
15125 mydebug('p_subinventory_code'||p_subinventory_code);
15126 mydebug('p_locator_id'||p_locator_id);
15127 mydebug('p_revision'||p_revision);
15128 mydebug('p_lot_number'||p_lot_number);
15129 mydebug('p_transfer_lpn_id'||p_transfer_lpn_id);
15130 mydebug('p_lpn_id'||p_lpn_id);
15131 mydebug('p_lot_control'||p_lot_control);
15132 mydebug('p_revision_control'||p_revision_control);
15133 END IF;
15134
15135 x_return_status := fnd_api.g_ret_sts_success;
15136 x_commingle_exist := 'N';
15137
15138 IF p_lot_control = 1 THEN
15139 select mmtt.subinventory_code,
15140 mmtt.locator_id,
15141 mmtt.revision,
15142 mmtt.lpn_id,
15143 null,
15144 null
15145 INTO l_sub,l_loc,l_rev,l_lpn,l_ser,l_lot
15146 from mtl_material_Transactions_temp mmtt
15147 where mmtt.inventory_item_id = p_inventory_item_id
15148 and mmtt.organization_id = p_organization_id
15149 and mmtt.transfer_lpn_id = p_transfer_lpn_id
15150 and mmtt.content_lpn_id is null
15151 and decode(p_revision_control,2,mmtt.revision,1,'~~') = nvl(p_revision,'~~')
15152 and rownum<2;
15153 ELSE
15154 select mmtt.subinventory_code,
15155 mmtt.locator_id,
15156 mmtt.revision,
15157 mmtt.lpn_id,
15158 null,
15159 mtlt.lot_number
15160 INTO l_sub,l_loc,l_rev,l_lpn,l_ser,l_lot
15161 from mtl_material_Transactions_temp mmtt,
15162 mtl_transaction_lots_temp mtlt
15163 where mmtt.inventory_item_id = p_inventory_item_id
15164 and mmtt.organization_id = p_organization_id
15165 and mmtt.transfer_lpn_id = p_transfer_lpn_id
15166 and mmtt.content_lpn_id is null
15167 and decode(p_revision_control,2,mmtt.revision,1,'~~') = nvl(p_revision,'~~')
15168 and mmtt.transaction_temp_id = mtlt.transaction_temp_id
15169 and mtlt.lot_number = p_lot_number
15170 and rownum<2;
15171 END IF;
15172
15173 IF (l_debug = 1) THEN
15174 mydebug( 'Loaded LPN data From MMTT');
15175 mydebug('l_subinventory_code'||l_sub);
15176 mydebug('l_locator_id'||l_loc);
15177 mydebug('l_revision'||l_rev);
15178 mydebug('l_lot_number'||l_lot);
15179 mydebug('l_serial_number'||l_ser);
15180 mydebug('l_lpn_id'||l_lpn);
15181 END IF;
15182
15183 inv_cost_group_update.proc_get_costgroup(
15184 p_organization_id => p_organization_id,
15185 p_inventory_item_id => p_inventory_item_id,
15186 p_subinventory_code => p_subinventory_code,
15187 p_locator_id => p_locator_id,
15188 p_revision => p_revision,
15189 p_lot_number => p_lot_number,
15190 p_serial_number => null,
15191 p_containerized_flag => null,
15192 p_lpn_id => p_lpn_id,
15193 p_transaction_action_id => null,
15194 x_cost_group_id => l_cur_cost_group_id,
15195 x_return_status => x_return_status);
15196 IF x_return_status <> fnd_api.g_ret_sts_success THEN
15197 RAISE fnd_api.g_exc_unexpected_error;
15198 END IF;
15199
15200 inv_cost_group_update.proc_get_costgroup(
15201 p_organization_id => p_organization_id,
15202 p_inventory_item_id => p_inventory_item_id,
15203 p_subinventory_code => l_sub,
15204 p_locator_id => l_loc,
15205 p_revision => l_rev,
15206 p_lot_number => l_lot,
15207 p_serial_number => l_ser,
15208 p_containerized_flag => null,
15209 p_lpn_id => l_lpn,
15210 p_transaction_action_id => null,
15211 x_cost_group_id => l_exist_cost_group_id,
15212 x_return_status => x_return_status);
15213
15214 IF x_return_status <> fnd_api.g_ret_sts_success THEN
15215 RAISE fnd_api.g_exc_unexpected_error;
15216 END IF;
15217
15218 IF l_exist_cost_group_id <> l_cur_cost_group_id THEN
15219 x_return_status := fnd_api.g_ret_sts_success;
15220 x_commingle_exist := 'Y';
15221 END IF;
15222
15223 EXCEPTION
15224 WHEN NO_DATA_FOUND THEN
15225 IF (l_debug = 1) THEN
15226 mydebug('First record being loaded into LPN');
15227 END IF;
15228 x_return_status := fnd_api.g_ret_sts_success;
15229 x_commingle_exist := 'N';
15230 WHEN OTHERS THEN
15231 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
15232 x_commingle_exist := 'Y';
15233 END validate_loaded_lpn_cg;
15234
15235
15236 -- ----------------------------------------------------------------------------------
15237 -- ----------------------------------------------------------------------------------
15238 FUNCTION validate_pick_drop_lpn
15239 ( p_api_version_number IN NUMBER ,
15240 p_init_msg_lst IN VARCHAR2 := fnd_api.g_false ,
15241 p_pick_lpn_id IN NUMBER ,
15242 p_organization_id IN NUMBER ,
15243 p_drop_lpn IN VARCHAR2,
15244 p_drop_sub IN VARCHAR2,
15245 p_drop_loc IN NUMBER)
15246 -- Added sub and loc for validation
15247 RETURN NUMBER
15248
15249 IS
15250 l_dummy VARCHAR2(1) := NULL;
15251
15252 l_api_version_number CONSTANT NUMBER := 1.0;
15253 l_api_name CONSTANT VARCHAR2(30) := 'Validate_Pick_Drop_Lpn';
15254 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
15255
15256 l_drop_lpn_exists BOOLEAN := FALSE;
15257 l_drop_lpn_has_picked_inv BOOLEAN := FALSE;
15258 l_pick_lpn_delivery_id NUMBER := NULL;
15259 l_drop_lpn_delivery_id NUMBER := NULL;
15260 l_line_rows WSH_UTIL_CORE.id_tab_type; -- Added for bug#4106176
15261 l_grouping_rows WSH_UTIL_CORE.id_tab_type; -- Added for bug#4106176
15262
15263 TYPE lpn_rectype is RECORD
15264 (
15265 lpn_id wms_license_plate_numbers.lpn_id%TYPE,
15266 lpn_context wms_license_plate_numbers.lpn_context%TYPE,
15267 subinventory_code wms_license_plate_numbers.subinventory_code%TYPE,
15268 locator_id wms_license_plate_numbers.locator_id%TYPE
15269 );
15270 drop_lpn_rec lpn_rectype;
15271
15272 CURSOR drop_lpn_cursor IS
15273 SELECT lpn_id,
15274 lpn_context,
15275 subinventory_code,
15276 locator_id
15277 FROM wms_license_plate_numbers
15278 WHERE license_plate_number = p_drop_lpn
15279 AND organization_id = p_organization_id;
15280
15281 CURSOR pick_delivery_cursor IS
15282 SELECT wda.delivery_id
15283 FROM wsh_delivery_assignments wda,
15284 wsh_delivery_details wdd,
15285 mtl_material_transactions_temp temp
15286 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
15287 AND wdd.move_order_line_id = temp.move_order_line_id
15288 AND wdd.organization_id = temp.organization_id
15289 AND temp.transfer_lpn_id = p_pick_lpn_id
15290 AND temp.organization_id = p_organization_id ;
15291
15292 CURSOR drop_delivery_cursor(l_lpn_id IN NUMBER) IS
15293 SELECT wda.delivery_id
15294 FROM wsh_delivery_assignments wda,
15295 wsh_delivery_details wdd,
15296 wms_license_plate_numbers lpn
15297 WHERE wda.parent_delivery_detail_id = wdd.delivery_detail_id
15298 AND wdd.lpn_id = lpn.lpn_id
15299 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
15300 AND lpn.outermost_lpn_id = l_lpn_id
15301 AND wdd.organization_id = p_organization_id ;
15302
15303 l_delivery_match_flag NUMBER;
15304
15305 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15306 BEGIN
15307
15308 IF (l_debug = 1) THEN
15309 mydebug ('Start Validate_Pick_Drop_Lpn.');
15310 END IF;
15311
15312 --
15313 -- Initialize API return status to success
15314 --
15315 l_return_status := FND_API.G_RET_STS_SUCCESS;
15316 l_delivery_match_flag := -1;
15317
15318 --
15319 -- Begin validation process:
15320 -- Check if drop lpn exists by trying to retrieve
15321 -- its lpn ID. If it does not exist,
15322 -- no further validations required - return success.
15323 --
15324 OPEN drop_lpn_cursor;
15325 FETCH drop_lpn_cursor INTO drop_lpn_rec;
15326 IF drop_lpn_cursor%NOTFOUND THEN
15327 l_drop_lpn_exists := FALSE;
15328 ELSE
15329 l_drop_lpn_exists := TRUE;
15330 END IF;
15331
15332 IF NOT l_drop_lpn_exists THEN
15333 IF (l_debug = 1) THEN
15334 mydebug ('Drop LPN is a new LPN, no checking required.');
15335 END IF;
15336 RETURN 1;
15337 END IF;
15338
15339 --
15340 -- If the drop lpn was pre-generated, no validations required
15341 --
15342
15343 IF drop_lpn_rec.lpn_context =
15344 WMS_Container_PUB.LPN_CONTEXT_PREGENERATED THEN
15345 --
15346 -- Update the context to "Resides in Inventory" (1)
15347 --
15348 /* UPDATE wms_license_plate_numbers
15349 SET lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
15350 WHERE lpn_id = drop_lpn_rec.lpn_id;*/
15351
15352 IF (l_debug = 1) THEN
15353 mydebug ('Drop LPN is pre-generated, no checking required.');
15354 END IF;
15355 RETURN 1;
15356
15357 ELSIF drop_lpn_rec.lpn_context = WMS_Container_PUB.lpn_context_picked THEN
15358 IF drop_lpn_rec.subinventory_code <> p_drop_sub or
15359 drop_lpn_rec.locator_id <> p_drop_loc THEN
15360 IF (l_debug = 1) THEN
15361 mydebug ('Drop LPN does not belong to the same sub and loc.');
15362 END IF;
15363 RETURN 2; -- Drop LPN resides in another Staging Lane
15364 END IF;
15365 END IF;
15366
15367 IF drop_lpn_rec.lpn_context =
15368 WMS_Container_PUB.LPN_LOADED_FOR_SHIPMENT THEN
15369 IF (l_debug = 1) THEN
15370 mydebug ('Drop LPN is loaded to dock door already');
15371 END IF;
15372 RETURN 4; -- Drop LPN is loaded to dock door already
15373 END IF;
15374
15375 --
15376 -- Drop LPN cannot be the same as the picked LPN
15377 --
15378 IF drop_lpn_rec.lpn_id = p_pick_lpn_id THEN
15379 IF (l_debug = 1) THEN
15380 mydebug ('Drop LPN cannot be the picked LPN.');
15381 END IF;
15382 RETURN 3; -- Drop LPN Cannot be the same as Pick LPN
15383 END IF;
15384
15385
15386 --
15387 -- Now check if the picked LPN and drop LPN
15388 -- belong to different deliveries
15389 --
15390 OPEN pick_delivery_cursor;
15391 LOOP
15392 FETCH pick_delivery_cursor INTO l_pick_lpn_delivery_id;
15393 EXIT WHEN l_pick_lpn_delivery_id IS NOT NULL OR pick_delivery_cursor%NOTFOUND;
15394 END LOOP;
15395 CLOSE pick_delivery_cursor;
15396
15397 --
15398 -- If the picked LPN is not associated with a delivery yet
15399 -- then no further checking required, return success
15400 --
15401 IF l_pick_lpn_delivery_id is NULL THEN
15402
15403 /*Bug#4106176.The following block is added.*/
15404 BEGIN
15405 SELECT delivery_detail_id
15406 INTO l_line_rows(1)
15407 FROM wsh_delivery_details
15408 WHERE lpn_id = drop_lpn_rec.lpn_id
15409 AND rownum = 1 ;
15410
15411 SELECT wdd.delivery_detail_id
15412 INTO l_line_rows(2)
15413 FROM wsh_delivery_details wdd, Mtl_material_transactions_temp mmtt
15414 WHERE mmtt.move_order_line_id = wdd.move_order_line_id
15415 AND wdd.organization_id = mmtt.organization_id
15416 AND mmtt.organization_id= p_organization_id
15417 AND mmtt.transfer_lpn_id= p_pick_lpn_id
15418 AND rownum = 1 ;
15419
15420 --call to the shipping API.
15421 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping( p_line_rows => l_line_rows,
15422 x_grouping_rows => l_grouping_rows,
15423 x_return_status => l_return_status);
15424 IF (l_debug = 1) THEN
15425 mydebug ('parameters : l_line_rows(1) :'||l_line_rows(1) ||',l_line_rows(2) :' || l_line_rows(2) );
15426 mydebug('count l_grp_rows'|| l_grouping_rows.count);
15427 mydebug('l_grp_rows(1) : '||l_grouping_rows(1) ||',l_grp_rows(2) : '||l_grouping_rows(2) );
15428 END IF;
15429
15430 IF (l_return_status = FND_API.G_RET_STS_SUCCESS AND l_grouping_rows(1) = l_grouping_rows(2) ) THEN
15431 IF (l_debug = 1) THEN
15432 mydebug('The LPN with LPN_ID ' || p_pick_lpn_id || ' can be dropped into LPN_ID '||drop_lpn_rec.lpn_id);
15433 END IF;
15434 RETURN 1; --Validated both LPNs , so return success.
15435 ELSE
15436 IF (l_debug = 1) THEN
15437 mydebug('Picked LPN does not belong to same delivery as Drop LPN. So cannot be dropped');
15438 END IF;
15439 RETURN 0;
15440 END IF;
15441
15442 EXCEPTION
15443 WHEN NO_DATA_FOUND THEN
15444 IF (l_debug = 1) THEN
15445 mydebug('No Data found Exception raised when checking for delivery grouping');
15446 mydebug('Picked LPN is not associated with a delivery, so dont show ANY lpn.');
15447 END IF;
15448 RETURN 0;
15449 WHEN OTHERS THEN
15450 IF (l_debug = 1) THEN
15451 mydebug('Other Exception raised when checking for delivery grouping');
15452 mydebug('Picked LPN is not associated with a delivery, so dont show ANY lpn.');
15453 END IF;
15454 RETURN 0;
15455 END; --End of Fix for bug#4106176
15456 END IF;
15457
15458 --
15459 -- Find the drop LPN's delivery ID
15460 --
15461
15462 OPEN drop_delivery_cursor(drop_lpn_rec.lpn_id);
15463 LOOP
15464 FETCH drop_delivery_cursor INTO l_drop_lpn_delivery_id;
15465 EXIT WHEN drop_delivery_cursor%notfound OR l_delivery_match_flag = 0;
15466
15467 IF l_drop_lpn_delivery_id is NOT NULL THEN
15468
15469 IF l_drop_lpn_delivery_id <> l_pick_lpn_delivery_id THEN
15470 IF (l_debug = 1) THEN
15471 mydebug('Picked and drop LPNs are on different deliveries.');
15472 END IF;
15473
15474 l_delivery_match_flag := 0;
15475 ELSE
15476 --
15477 -- Drop LPN and picked LPN are on the same delivery
15478 -- return success
15479 --
15480 IF (l_debug = 1) THEN
15481 mydebug('Drop and pick LPNs are on the same delivery: '||l_drop_lpn_delivery_id);
15482 END IF;
15483
15484 l_delivery_match_flag := 1;
15485 END IF;
15486 END IF;
15487
15488 END LOOP;
15489 CLOSE drop_delivery_cursor;
15490
15491 IF l_delivery_match_flag = 0 OR l_delivery_match_flag = -1 THEN
15492
15493 RETURN 0;
15494
15495 ELSIF l_delivery_match_flag = 1 THEN
15496
15497 RETURN 1;
15498
15499 END IF;
15500
15501 IF l_return_status =FND_API.g_ret_sts_success THEN
15502 RETURN 1;
15503 ELSE
15504 RETURN 0;
15505 END IF;
15506
15507 EXCEPTION
15508 WHEN fnd_api.g_exc_error THEN
15509
15510 RETURN 0;
15511
15512 WHEN OTHERS THEN
15513
15514 RETURN 0;
15515
15516 END validate_pick_drop_lpn;
15517
15518
15519 PROCEDURE default_pick_drop_lpn
15520 ( p_api_version_number IN NUMBER ,
15521 p_init_msg_lst IN VARCHAR2 := fnd_api.g_false ,
15522 p_pick_lpn_id IN NUMBER ,
15523 p_organization_id IN NUMBER ,
15524 x_lpn_number OUT nocopy VARCHAR2)
15525
15526 IS
15527
15528 l_api_version_number CONSTANT NUMBER := 1.0;
15529 l_api_name CONSTANT VARCHAR2(30) :=
15530 'default_pick_drop_lpn';
15531 l_return_status VARCHAR2(1) :=
15532 fnd_api.g_ret_sts_success;
15533 l_delivery_id NUMBER;
15534 l_drop_sub VARCHAR2(10);
15535 l_drop_loc NUMBER;
15536 l_lpn_id NUMBER;
15537
15538
15539 CURSOR pick_delivery_cursor IS
15540 SELECT wda.delivery_id
15541 FROM wsh_delivery_assignments wda,
15542 wsh_delivery_details wdd,
15543 mtl_material_transactions_temp temp
15544 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
15545 AND wdd.move_order_line_id = temp.move_order_line_id
15546 AND wdd.organization_id = temp.organization_id
15547 AND temp.transfer_lpn_id = p_pick_lpn_id
15548 AND temp.organization_id = p_organization_id;
15549
15550 CURSOR drop_delivery_cursor (l_delivery_id_c IN NUMBER,
15551 l_drop_sub_c IN VARCHAR2,
15552 l_drop_loc_c IN NUMBER ) IS
15553 --Bug Fix 4622935 Added hint as suggested by Ben Chihaoui
15554 SELECT /*+ index(wda WSH_DELIVERY_ASSIGNMENTS_N1) ORDERED USE_NL (WDA WDD WLPN) */ wlpn.outermost_lpn_id
15555 FROM wsh_delivery_assignments wda,
15556 wsh_delivery_details wdd,
15557 wms_license_plate_numbers wlpn
15558 WHERE wda.delivery_id = l_delivery_id_c
15559 AND wda.parent_delivery_detail_id = wdd.delivery_detail_id
15560 AND wdd.organization_id = p_organization_id
15561 AND wdd.lpn_id = wlpn.lpn_id
15562 AND wlpn.subinventory_code = l_drop_sub_c
15563 AND wlpn.locator_id = l_drop_loc_c
15564 AND wlpn.lpn_context = 11
15565 ORDER BY wda.CREATION_DATE DESC ;
15566
15567
15568 delivery_id_rec pick_delivery_cursor%ROWTYPE;
15569 license_plate_rec drop_delivery_cursor%ROWTYPE;
15570
15571 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15572 BEGIN
15573
15574
15575 IF NOT fnd_api.compatible_api_call (l_api_version_number
15576 , p_api_version_number
15577 , l_api_name
15578 , G_PKG_NAME
15579 ) THEN
15580 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
15581 FND_MSG_PUB.ADD;
15582 RAISE FND_API.G_EXC_ERROR;
15583 END IF;
15584
15585
15586 l_return_status := FND_API.G_RET_STS_SUCCESS;
15587 --
15588 -- Initialize message list.
15589 --
15590
15591 IF fnd_api.to_boolean(p_init_msg_lst) THEN
15592 fnd_msg_pub.initialize;
15593 END IF;
15594
15595
15596 BEGIN
15597 Select transfer_subinventory, transfer_to_location into l_drop_sub,
15598 l_drop_loc
15599 from mtl_material_transactions_temp
15600 where transfer_lpn_id = p_pick_lpn_id
15601 AND organization_id = p_organization_id;
15602
15603 EXCEPTION
15604 WHEN NO_DATA_FOUND THEN
15605 l_delivery_id := NULL;
15606
15607 WHEN OTHERS THEN
15608 l_delivery_id := NULL;
15609 END;
15610
15611 -- Select the Delivery for the LPN that is being picked
15612
15613 FOR delivery_id_rec IN pick_delivery_cursor
15614 LOOP
15615 l_delivery_id := delivery_id_rec.delivery_id;
15616 EXIT WHEN delivery_id_rec.delivery_id IS NOT NULL OR pick_delivery_cursor%NOTFOUND;
15617 END LOOP;
15618
15619
15620 -- Find the drop LPN's delivery ID
15621 FOR license_plate_rec IN drop_delivery_cursor
15622 (l_delivery_id,l_drop_sub,l_drop_loc )
15623 LOOP
15624 l_lpn_id := license_plate_rec.outermost_lpn_id;
15625 EXIT WHEN license_plate_rec.outermost_lpn_id IS NOT NULL OR drop_delivery_cursor%NOTFOUND;
15626 END LOOP;
15627
15628
15629 BEGIN
15630 SELECT license_plate_number INTO x_lpn_number FROM
15631 wms_license_plate_numbers WHERE lpn_id = l_lpn_id;
15632
15633 EXCEPTION
15634 WHEN NO_DATA_FOUND THEN
15635 x_lpn_number := NULL;
15636
15637 WHEN OTHERS THEN
15638 x_lpn_number := NULL;
15639 END;
15640
15641 END default_pick_drop_lpn;
15642
15643
15644 END wms_task_dispatch_gen;