[Home] [Help]
PACKAGE BODY: APPS.WMS_TASK_DISPATCH_GEN
Source
1 PACKAGE BODY wms_task_dispatch_gen AS
2 /* $Header: WMSTASKB.pls 120.30.12020000.3 2012/09/05 05:38:59 pramadur 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.30.12020000.3 2012/09/05 05:38:59 pramadur 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 -- Bug 14261335
10160 SELECT COUNT(msnt.transaction_temp_id)
10161 INTO l_serial_count
10162 FROM mtl_serial_numbers_temp msnt,
10163 mtl_material_transactions_temp mmtt,
10164 mtl_transaction_lots_temp mtlt
10165 WHERE mmtt.transaction_temp_id = mtlt.transaction_temp_id
10166 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
10167 AND mmtt.inventory_item_id = l_item_id
10168 AND mmtt.organization_id = p_org_id
10169 AND mtlt.lot_number = p_lot
10170 AND msnt.fm_serial_number = l_fm_serial;
10171
10172 /*Bug#3957819.IF the serial number is already used , throw an error*/
10173 IF l_serial_count > 1 THEN
10174 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10175 fnd_msg_pub.ADD;
10176 RAISE fnd_api.g_exc_error;
10177 END IF;
10178 /*End of fix for Bug#3957819 */
10179
10180 l_progress := '480';
10181 END IF;
10182
10183 l_progress := '490';
10184
10185 BEGIN
10186 UPDATE mtl_transaction_lots_temp
10187 SET transaction_quantity = l_qty
10188 , primary_quantity = l_pr_qty
10189 , serial_transaction_temp_id = l_new_serial_temp_id
10190 , last_update_date = SYSDATE
10191 , last_updated_by = l_user_id
10192 WHERE transaction_temp_id = l_local_temp_id
10193 AND lot_number = p_lot;
10194 EXCEPTION
10195 WHEN NO_DATA_FOUND THEN
10196 IF (l_debug = 1) THEN
10197 mydebug('multiple_pick: MTLT did not get updated. Lot number NOT passed');
10198 END IF;
10199 END;
10200
10201 l_progress := '500';
10202 ELSIF(l_serial_code > 1
10203 AND l_serial_code <> 6) THEN
10204 -- serial controlled only
10205 l_progress := '510';
10206
10207 IF p_sn_allocated_flag = 'N' THEN
10208 l_real_serial_prefix := RTRIM(l_fm_serial, '0123456789');
10209 l_serial_numeric_frm := TO_NUMBER(SUBSTR(l_fm_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10210 l_serial_numeric_to := TO_NUMBER(SUBSTR(l_to_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10211 l_serial_prefix := (l_serial_numeric_to - l_serial_numeric_frm) + 1;
10212 mydebug('SERIAL_PREFIX IS :' || l_serial_prefix);
10213
10214 INSERT INTO mtl_serial_numbers_temp
10215 (
10216 transaction_temp_id
10217 , last_update_date
10218 , last_updated_by
10219 , creation_date
10220 , created_by
10221 , fm_serial_number
10222 , to_serial_number
10223 , serial_prefix
10224 )
10225 VALUES (
10226 l_local_temp_id
10227 , SYSDATE
10228 , l_user_id
10229 , SYSDATE
10230 , l_user_id
10231 , l_fm_serial
10232 , l_to_serial
10233 , l_serial_prefix
10234 );
10235 END IF;
10236
10237 l_progress := '520';
10238
10239 UPDATE mtl_serial_numbers
10240 SET group_mark_id = l_txn_header_id
10241 WHERE inventory_item_id = l_item_id
10242 AND current_organization_id = p_org_id
10243 AND serial_number IN(SELECT fm_serial_number
10244 FROM mtl_serial_numbers_temp msnt
10245 WHERE msnt.transaction_temp_id = l_local_temp_id);
10246
10247 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10248 -- Bug 14261335
10249 SELECT COUNT(msnt.transaction_temp_id)
10250 INTO l_serial_count
10251 FROM mtl_serial_numbers_temp msnt,
10252 mtl_material_transactions_temp mmtt
10253 WHERE mmtt.transaction_temp_id = msnt.transaction_temp_id
10254 AND mmtt.inventory_item_id = l_item_id
10255 AND mmtt.organization_id = p_org_id
10256 AND msnt.fm_serial_number = l_fm_serial;
10257
10258
10259 /*Bug#3957819.IF the serial number is already used , throw an error*/
10260 IF l_serial_count > 1 THEN
10261 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10262 fnd_msg_pub.ADD;
10263 RAISE fnd_api.g_exc_error;
10264 END IF;
10265 /*End of fix for Bug#3957819 */
10266
10267 l_progress := '530';
10268 END IF;
10269 ELSE
10270 l_progress := '540';
10271
10272 IF (l_debug = 1) THEN
10273 mydebug('multiple_pick: Picked loose');
10274 END IF;
10275
10276 IF (l_pick_qty_remaining = 0) THEN
10277 IF (l_debug = 1) THEN
10278 mydebug('multiple_pick: User has picked entire requested quantity. This is loose');
10279 END IF;
10280
10281 IF (l_debug = 1) THEN
10282 mydebug('multiple_pick: l_temp_id:' || l_temp_id);
10283 mydebug('multiple_pick: l_to_lpn_id:' || l_to_lpn_id);
10284 END IF;
10285
10286 l_local_temp_id := l_temp_id;
10287 END IF;
10288
10289 UPDATE mtl_material_transactions_temp
10290 SET transfer_lpn_id = l_to_lpn_id
10291 , lpn_id = NULL
10292 , content_lpn_id = NULL
10293 , subinventory_code = l_act_sub
10294 , locator_id = l_act_loc
10295 , last_update_date = SYSDATE
10296 , last_updated_by = l_user_id
10297 WHERE transaction_temp_id = l_local_temp_id;
10298
10299 l_progress := '550';
10300
10301 IF l_lot_code > 1 THEN
10302 IF (l_serial_code > 1
10303 AND l_serial_code <> 6) THEN
10304 SELECT NVL(serial_transaction_temp_id, 0)
10305 INTO l_lot_ser_seq
10306 FROM mtl_transaction_lots_temp
10307 WHERE transaction_temp_id = l_local_temp_id
10308 AND lot_number = l_lot;
10309
10310 l_progress := '560';
10311
10312 IF l_lot_ser_seq = 0 THEN
10313 SELECT mtl_material_transactions_s.NEXTVAL
10314 INTO l_new_serial_temp_id
10315 FROM DUAL;
10316 ELSE
10317 l_new_serial_temp_id := l_lot_ser_seq;
10318 END IF;
10319
10320 IF p_sn_allocated_flag = 'N' THEN
10321 INSERT INTO mtl_serial_numbers_temp
10322 (
10323 transaction_temp_id
10324 , last_update_date
10325 , last_updated_by
10326 , creation_date
10327 , created_by
10328 , fm_serial_number
10329 , to_serial_number
10330 )
10331 VALUES (
10332 l_new_serial_temp_id
10333 , SYSDATE
10334 , l_user_id
10335 , SYSDATE
10336 , l_user_id
10337 , l_fm_serial
10338 , l_to_serial
10339 );
10340 END IF;
10341
10342 l_progress := '570';
10343
10344 UPDATE mtl_serial_numbers
10345 SET group_mark_id = l_txn_header_id
10346 WHERE inventory_item_id = l_item_id
10347 AND current_organization_id = p_org_id
10348 AND serial_number IN(SELECT fm_serial_number
10349 FROM mtl_serial_numbers_temp
10350 WHERE transaction_temp_id = l_new_serial_temp_id);
10351
10352 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10353 -- Bug 14261335
10354 SELECT COUNT(msnt.transaction_temp_id)
10355 INTO l_serial_count
10356 FROM mtl_serial_numbers_temp msnt,
10357 mtl_material_transactions_temp mmtt,
10358 mtl_transaction_lots_temp mtlt
10359 WHERE mmtt.transaction_temp_id = mtlt.transaction_temp_id
10360 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
10361 AND mmtt.inventory_item_id = l_item_id
10362 AND mmtt.organization_id = p_org_id
10363 AND mtlt.lot_number = l_lot
10364 AND msnt.fm_serial_number = l_fm_serial;
10365
10366 /*Bug#3957819.IF the serial number is already used , throw an error*/
10367 IF l_serial_count > 1 THEN
10368 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10369 fnd_msg_pub.ADD;
10370 RAISE fnd_api.g_exc_error;
10371 END IF;
10372 /*End of fix for Bug#3957819 */
10373
10374 l_progress := '580';
10375 END IF;
10376
10377 UPDATE mtl_transaction_lots_temp
10378 SET transaction_quantity = l_qty
10379 , primary_quantity = l_pr_qty
10380 , serial_transaction_temp_id = l_new_serial_temp_id
10381 , last_update_date = SYSDATE
10382 , last_updated_by = l_user_id
10383 WHERE transaction_temp_id = l_local_temp_id
10384 AND lot_number = p_lot;
10385
10386 l_progress := '590';
10387 ELSIF(l_serial_code > 1
10388 AND l_serial_code <> 6) THEN
10389 -- serial controlled only
10390
10391 l_progress := '600';
10392
10393 IF p_sn_allocated_flag = 'N' THEN
10394 l_real_serial_prefix := RTRIM(l_fm_serial, '0123456789');
10395 l_serial_numeric_frm := TO_NUMBER(SUBSTR(l_fm_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10396 l_serial_numeric_to := TO_NUMBER(SUBSTR(l_to_serial, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
10397 l_serial_prefix := (l_serial_numeric_to - l_serial_numeric_frm) + 1;
10398 mydebug('SERIAL_PREFIX IS :' || l_serial_prefix);
10399
10400 INSERT INTO mtl_serial_numbers_temp
10401 (
10402 transaction_temp_id
10403 , last_update_date
10404 , last_updated_by
10405 , creation_date
10406 , created_by
10407 , fm_serial_number
10408 , to_serial_number
10409 , serial_prefix
10410 )
10411 VALUES (
10412 l_local_temp_id
10413 , SYSDATE
10414 , l_user_id
10415 , SYSDATE
10416 , l_user_id
10417 , l_fm_serial
10418 , l_to_serial
10419 , NVL(l_serial_prefix, 1)
10420 );
10421 END IF;
10422
10423 l_progress := '610';
10424
10425 UPDATE mtl_serial_numbers
10426 SET group_mark_id = l_txn_header_id
10427 WHERE inventory_item_id = l_item_id
10428 AND current_organization_id = p_org_id
10429 AND serial_number IN(SELECT fm_serial_number
10430 FROM mtl_serial_numbers_temp
10431 WHERE transaction_temp_id = l_local_temp_id);
10432
10433 --Added bug#4245565.Check if any other MSNT records are there for this serial number.
10434 -- Bug 14261335
10435 SELECT COUNT(msnt.transaction_temp_id)
10436 INTO l_serial_count
10437 FROM mtl_serial_numbers_temp msnt,
10438 mtl_material_transactions_temp mmtt
10439 WHERE mmtt.transaction_temp_id = msnt.transaction_temp_id
10440 AND mmtt.inventory_item_id = l_item_id
10441 AND mmtt.organization_id = p_org_id
10442 AND msnt.fm_serial_number = l_fm_serial;
10443
10444 /*Bug#3957819.IF the serial number is already used , throw an error*/
10445 IF l_serial_count > 1 THEN
10446 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
10447 fnd_msg_pub.ADD;
10448 RAISE fnd_api.g_exc_error;
10449 END IF;
10450 /*End of fix for Bug#3957819 */
10451
10452 l_progress := '620';
10453 END IF;
10454 END IF;
10455
10456 l_progress := '630';
10457
10458 IF p_is_serial_control = 'true'
10459 OR p_is_lot_control = 'true' THEN
10460 IF (l_debug = 1) THEN
10461 mydebug('multiple_pick: Lot or serial controlled. Do not updated wmsdt AS loaded');
10462 END IF;
10463 ELSE
10464 IF (l_debug = 1) THEN
10465 mydebug('multiple_pick: Plain item. Update WMSDT as loaded');
10466 END IF;
10467
10468 UPDATE wms_dispatched_tasks
10469 SET status = 4
10470 , loaded_time = SYSDATE
10471 , --to_date(to_char(sysdate,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH:MI:SS'),
10472 last_update_date = SYSDATE
10473 , last_updated_by = l_user_id
10474 WHERE transaction_temp_id = l_local_temp_id;
10475 END IF;
10476
10477 l_progress := '640';
10478
10479 IF (l_debug = 1) THEN
10480 mydebug('multiple_pick: Before checking for pregenerated LPNs');
10481 END IF;
10482
10483 -- If the pick-to LPN was pregenerated (context = 5),
10484 -- Changed the context to be updated to 8 instead of 1 as done earlier
10485
10486 IF l_to_lpn_context = wms_container_pub.lpn_context_pregenerated THEN
10487 -- Bug5659809: update last_update_date and last_update_by as well
10488 UPDATE wms_license_plate_numbers
10489 SET lpn_context = wms_container_pub.lpn_context_packing
10490 , last_update_date = SYSDATE
10491 , last_updated_by = fnd_global.user_id
10492 WHERE lpn_id = l_to_lpn_id;
10493 END IF;
10494
10495 l_progress := '650';
10496 x_temp_id := l_local_temp_id;
10497 x_return_status := fnd_api.g_ret_sts_success;
10498
10499 IF (l_debug = 1) THEN
10500 mydebug('multiple_pick: End of multiple_pick');
10501 END IF;
10502 EXCEPTION
10503 WHEN fnd_api.g_exc_error THEN
10504 x_return_status := fnd_api.g_ret_sts_error;
10505 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10506 ROLLBACK TO sp_multiple_pick;
10507
10508 IF (l_debug = 1) THEN
10509 mydebug('multiple_pick : raise FND_API.G_EXC_ERROR: ' || SQLERRM);
10510 mydebug('l_progress = ' || l_progress);
10511 END IF;
10512 WHEN OTHERS THEN
10513 x_return_status := fnd_api.g_ret_sts_unexp_error;
10514 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10515 ROLLBACK TO sp_multiple_pick;
10516
10517 IF (l_debug = 1) THEN
10518 mydebug('multiple_pick : raise OTHER exception: ' || SQLERRM);
10519 mydebug('l_progress = ' || l_progress);
10520 END IF;
10521 END multiple_pick;
10522
10523 PROCEDURE create_lpn(
10524 p_organization_id NUMBER
10525 , p_lpn IN VARCHAR2
10526 , p_lpn_id OUT NOCOPY NUMBER
10527 , x_return_status OUT NOCOPY VARCHAR2
10528 , x_msg_count OUT NOCOPY NUMBER
10529 , x_msg_data OUT NOCOPY VARCHAR2
10530 ) IS
10531 l_lpn_rec wms_container_pub.lpn;
10532 l_return_status VARCHAR2(1);
10533 l_msg_count NUMBER;
10534 l_msg_data VARCHAR2(4000);
10535 l_exist NUMBER;
10536 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10537 BEGIN
10538 l_exist := 0;
10539 l_return_status := fnd_api.g_ret_sts_success;
10540
10541 IF (l_debug = 1) THEN
10542 mydebug('In create LPN..');
10543 END IF;
10544
10545 l_lpn_rec.license_plate_number := p_lpn;
10546 l_exist := 0;
10547
10548 /* SELECT COUNT(*) INTO l_exist FROM wms_license_plate_numbers
10549 WHERE license_plate_number=p_lpn;*/
10550 BEGIN
10551 SELECT 1
10552 INTO l_exist
10553 FROM DUAL
10554 WHERE EXISTS(SELECT 1
10555 FROM wms_license_plate_numbers
10556 WHERE license_plate_number = p_lpn);
10557 EXCEPTION
10558 WHEN NO_DATA_FOUND THEN
10559 l_exist := 0;
10560 END;
10561
10562 IF l_exist = 0 THEN
10563 IF (l_debug = 1) THEN
10564 mydebug('LPN Does not exist..');
10565 END IF;
10566
10567 wms_container_pub.create_lpn(
10568 p_api_version => 1.0
10569 , x_return_status => l_return_status
10570 , x_msg_count => l_msg_count
10571 , x_msg_data => x_msg_data
10572 , p_lpn => p_lpn
10573 , p_organization_id => p_organization_id
10574 , x_lpn_id => p_lpn_id
10575 , p_source => 3
10576 );
10577 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => x_msg_data);
10578
10579 IF (l_msg_count = 0) THEN
10580 IF (l_debug = 1) THEN
10581 mydebug('Successful');
10582 END IF;
10583 ELSIF(l_msg_count = 1) THEN
10584 IF (l_debug = 1) THEN
10585 mydebug('Not Successful');
10586 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
10587 END IF;
10588 ELSE
10589 IF (l_debug = 1) THEN
10590 mydebug('Not Successful2');
10591 END IF;
10592
10593 FOR i IN 1 .. l_msg_count LOOP
10594 x_msg_data := fnd_msg_pub.get(i, 'F');
10595
10596 IF (l_debug = 1) THEN
10597 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
10598 END IF;
10599 END LOOP;
10600 END IF;
10601
10602 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
10603 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
10604 fnd_msg_pub.ADD;
10605 RAISE fnd_api.g_exc_unexpected_error;
10606 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
10607 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
10608 fnd_msg_pub.ADD;
10609 RAISE fnd_api.g_exc_error;
10610 END IF;
10611 ELSE -- lpn exists
10612 SELECT lpn_id
10613 INTO p_lpn_id
10614 FROM wms_license_plate_numbers
10615 WHERE license_plate_number = p_lpn;
10616 END IF;
10617
10618 x_return_status := fnd_api.g_ret_sts_success;
10619 EXCEPTION
10620 WHEN fnd_api.g_exc_error THEN
10621 x_return_status := fnd_api.g_ret_sts_error;
10622 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10623 WHEN OTHERS THEN
10624 x_return_status := fnd_api.g_ret_sts_unexp_error;
10625 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10626 END create_lpn;
10627
10628 -- p sub, p_loc are user entered values
10629 -- p_orig_sub, p_orig_loc are system suggested values
10630 PROCEDURE pick_drop(
10631 p_temp_id IN NUMBER
10632 , p_txn_header_id IN NUMBER
10633 , p_org_id IN NUMBER
10634 , x_return_status OUT NOCOPY VARCHAR2
10635 , x_msg_count OUT NOCOPY NUMBER
10636 , x_msg_data OUT NOCOPY VARCHAR2
10637 , p_from_lpn_id IN NUMBER
10638 , p_drop_lpn IN VARCHAR2
10639 , p_loc_reason_id IN NUMBER
10640 , p_sub IN VARCHAR
10641 , p_loc IN NUMBER
10642 , p_orig_sub IN VARCHAR
10643 , p_orig_loc IN VARCHAR
10644 , p_user_id IN NUMBER
10645 , p_task_type IN NUMBER
10646 , p_commit IN VARCHAR2
10647 ) IS
10648 l_temp_id NUMBER;
10649 l_org_id NUMBER;
10650 l_cnt NUMBER;
10651 l_return_status VARCHAR2(1);
10652 l_msg_count NUMBER;
10653 l_msg_data VARCHAR2(5000);
10654 l_mmtt_line_id NUMBER;
10655 l_mmtt_qty NUMBER;
10656 l_txn_header_id NUMBER;
10657 l_txn_ret NUMBER;
10658 l_transfer_sub VARCHAR2(10);
10659 l_transfer_loc NUMBER;
10660 l_content_lpn_id NUMBER;
10661 l_lpn_id NUMBER;
10662 l_transfer_lpn_id NUMBER;
10663 l_tran_type_id NUMBER;
10664 l_flow NUMBER;
10665 l_label_status NUMBER;
10666 l_del_det_id NUMBER;
10667 l_mo_line_id NUMBER;
10668 l_label_transaction_id NUMBER;
10669 l_period_id NUMBER;
10670 l_open_past_period BOOLEAN;
10671 l_isdroplpnentered BOOLEAN;
10672 l_xfrlpnid NUMBER;
10673 l_lpn_context NUMBER;
10674 l_from_lpn_context NUMBER; -- Added for bug 12853197
10675 l_update_frm_lpn BOOLEAN:= FALSE; -- Added for bug 12853197
10676 l_tran_source_type_id NUMBER;
10677 l_tran_action_id NUMBER;
10678 -- local variables for workflow
10679 l_wf NUMBER;
10680 l_sub VARCHAR(30);
10681 l_loc NUMBER;
10682 l_orig_sub VARCHAR2(30);
10683 l_orig_loc NUMBER;
10684 l_loc_reason_id NUMBER;
10685 l_user_id NUMBER;
10686 l_task_type NUMBER;
10687 l_inventory_item_id NUMBER;
10688 l_from_sub VARCHAR2(30);
10689 l_from_loc NUMBER;
10690 l_shipped_wdd_count_in_lpn NUMBER;
10691 l_open_wdd_count_in_lpn NUMBER;
10692 l_is_transfer_sub_lpn NUMBER; /* 3150462*/
10693 l_check_tasks NUMBER :=0; --Bug 5318552
10694
10695
10696
10697 CURSOR mmtt_csr IS
10698 SELECT mmtt.transaction_temp_id
10699 FROM mtl_material_transactions_temp mmtt
10700 WHERE mmtt.transaction_header_id = l_txn_header_id
10701 AND mmtt.organization_id = l_org_id;
10702
10703 -- VARAJAGO for bug 5222498, added to fetch the group_mark_id details of MSN
10704 CURSOR msn_stg_mov_csr (lpnid_in_msn NUMBER) IS
10705 SELECT serial_number
10706 , organization_id
10707 , inventory_item_id
10708 , transaction_temp_id, lpn_id
10709 FROM wms_wsh_wdd_gtemp WHERE lpn_id = lpnid_in_msn;
10710
10711 -- DHERRING additional cursor to find all nested LPNs
10712 CURSOR child_lpns_csr IS
10713 SELECT lpn_id
10714 FROM wms_license_plate_numbers
10715 START WITH lpn_id = l_xfrlpnid
10716 CONNECT BY PRIOR lpn_id = parent_lpn_id;
10717
10718 -- End of changes for 5222498
10719 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10720
10721 --==================================================
10722 --R12.1 Replenishment Project (6681109) Starts
10723
10724 l_index NUMBER;
10725 l_b_index NUMBER;
10726
10727 L_ORDER_ID_SORT VARCHAR2(4) := NULL;
10728 L_INVOICE_VALUE_SORT VARCHAR2(4) := NULL;
10729 L_SCHEDULE_DATE_SORT VARCHAR2(4) := NULL;
10730 L_TRIP_STOP_DATE_SORT VARCHAR2(4) := NULL;
10731 L_SHIPMENT_PRI_SORT VARCHAR2(4) := NULL;
10732
10733
10734 l_detail_info_tab WSH_INTERFACE_EXT_GRP.delivery_details_Attr_tbl_Type;
10735 l_in_rec WSH_INTERFACE_EXT_GRP.detailInRecType;
10736 l_out_rec WSH_INTERFACE_EXT_GRP.detailOutRecType;
10737
10738 l_detail_id_tab WSH_UTIL_CORE.id_tab_type;
10739 l_action_prms WSH_GLBL_VAR_STRCT_GRP.dd_action_parameters_rec_type;
10740 l_action_out_rec WSH_GLBL_VAR_STRCT_GRP.dd_action_out_rec_type;
10741 l_rsv_tbl_tmp inv_reservation_global.mtl_reservation_tbl_type;
10742
10743 L_delivery_detail_id NUMBER;
10744 l_req_quantity_uom VARCHAR2(3);
10745 L_SHIP_SET_ID NUMBER;
10746 L_SHIP_MODEL_ID NUMBER;
10747 l_exists_in_wrd NUMBER;
10748 l_not_mmtt_row NUMBER;
10749
10750 l_prev_mol NUMBER;
10751 l_wrd_pri_quantity NUMBER;
10752 l_requested_quantity NUMBER;
10753 l_demand_pri_qty NUMBER;
10754 l_primary_uom VARCHAR(3);
10755 l_repl_type NUMBER;
10756 l_repl_level NUMBER := 1; -- TO DECIDE WHETHER TO PICK_RELEASE DEMAND OR allocate repl MO FOR LEVEL > 1
10757 l_batch_id NUMBER;
10758 l_prev_batch_id NUMBER;
10759 l_batch_id_tab num_tab;
10760 l_pick_rel_tab pick_release_tab;
10761 j NUMBER;
10762
10763 L_REMAINING_MMTT_QTY NUMBER;
10764 l_release_sequence_rule_id NUMBER;
10765 l_demand_type_id NUMBER;
10766 l_demand_header_id NUMBER;
10767 l_demand_line_id NUMBER;
10768
10769 l_attr1 NUMBER;
10770 l_attr2 NUMBER;
10771 l_attr3 NUMBER;
10772 l_attr4 NUMBER;
10773 l_attr5 NUMBER;
10774
10775 l_prev_move_order_line_id NUMBER := -9999; --BUG14014540
10776 l_curr_move_order_line_id NUMBER := -9999; --BUG14014540
10777
10778 CURSOR c_mark_demand_rc_csr(p_mo_line_id NUMBER) IS
10779 SELECT WDD.DELIVERY_DETAIL_ID,
10780 MTRL.SHIP_SET_ID,
10781 MTRL.SHIP_MODEL_ID,
10782 WRD.primary_quantity WRD_PRI_QUANTITY,
10783 Nvl(WDD.requested_quantity,0) REQUESTED_QUANTITY,
10784 WRD.primary_uom,
10785 wrd.repl_type,
10786 wrd.repl_level, -- TO DECIDE WHETHER TO PICK_RELEASE DEMAND OR allocate repl MO FOR LEVEL > 1
10787 wdd.batch_id,
10788 wrd.demand_type_id
10789 FROM
10790 wms_replenishment_details WRD,
10791 MTL_TXN_REQUEST_LINES MTRL,
10792 WSH_DELIVERY_DETAILS WDD
10793 WHERE WRD.ORGANIZATION_ID = P_ORG_ID
10794 AND WRD.SOURCE_LINE_ID = p_mo_line_id
10795 AND wrd.demand_type_id <> 4 -- true only for first level of REPL
10796 AND WRD.SOURCE_LINE_ID = MTRL.LINE_ID
10797 AND WRD.SOURCE_HEADER_ID = MTRL.HEADER_ID
10798 AND WRD.ORGANIZATION_ID = MTRL.ORGANIZATION_ID
10799 AND WRD.INVENTORY_ITEM_ID = MTRL.INVENTORY_ITEM_ID
10800 AND WRD.DEMAND_LINE_DETAIL_ID = WDD.delivery_detail_id
10801 AND WRD.ORGANIZATION_ID = WDD.organization_id
10802 ORDER BY wdd.batch_id, DEMAND_SORT_ORDER;
10803
10804 CURSOR c_multi_level_repl_alloc(p_mo_line_id NUMBER) IS
10805 SELECT wrd.demand_header_id,
10806 wrd.demand_line_id,
10807 WRD.primary_quantity WRD_PRI_QUANTITY,
10808 wrd.repl_level, -- TO DECIDE WHETHER TO PICK_RELEASE DEMAND OR allocate repl MO FOR LEVEL > 1
10809 wrd.demand_type_id
10810 FROM
10811 wms_replenishment_details WRD,
10812 MTL_TXN_REQUEST_LINES MTRL
10813 WHERE WRD.ORGANIZATION_ID = P_ORG_ID
10814 AND WRD.SOURCE_LINE_ID = p_mo_line_id
10815 AND wrd.demand_type_id = 4 -- true for multi level repl (>1)
10816 AND WRD.SOURCE_LINE_ID = MTRL.LINE_ID
10817 AND WRD.SOURCE_HEADER_ID = MTRL.HEADER_ID
10818 AND WRD.ORGANIZATION_ID = MTRL.ORGANIZATION_ID
10819 AND WRD.INVENTORY_ITEM_ID = MTRL.inventory_item_id
10820 ORDER BY DEMAND_SORT_ORDER;
10821
10822 --bug 9356579 : Since we are tracking all the MO created here through the WRD table,
10823 --there will not be any situation in which we will end up move order lines that are not part of the WRD table.
10824 --Even for those MO lines that we did not create ourself rather they were existing and
10825 --we are netting demand lines against them, we are tracking them in WRD table as well. So Following changes is NOT needed anymore.
10826 --Blocking this cursor and the usage of the cursor in this code.
10827
10828 /* cursor c_untracked_dmd_repl_cur will consider only those demands that are not tracked in WRD table but we have created replenishment move orders for them */
10829
10830 /* CURSOR c_untracked_dmd_repl_cur(P_ITEM_ID NUMBER) IS
10831 SELECT
10832 WDD.DELIVERY_DETAIL_ID,
10833 wdd.requested_quantity AS PRIMARY_QUANTITY, -- this is always stored in primary UOM
10834 wdd.requested_quantity_uom,
10835
10836 -- get for sort_attribute1
10837 To_number(DECODE(l_release_sequence_rule_id,
10838 null,
10839 null,
10840 DECODE(g_ordered_psr(1).attribute_name,
10841 'ORDER_NUMBER',
10842 DECODE(L_ORDER_ID_SORT,
10843 'ASC',
10844 To_number(wdd.source_header_number),
10845 'DESC',
10846 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10847 null),
10848 'SHIPMENT_PRIORITY',
10849 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10850 'High',
10851 20,
10852 'Standard',
10853 10,
10854 NULL),
10855 'INVOICE_VALUE',
10856 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10857 L_INVOICE_VALUE_SORT),
10858 'SCHEDULE_DATE',
10859 DECODE(L_SCHEDULE_DATE_SORT,
10860 'ASC',
10861 (WDD.DATE_SCHEDULED -
10862 TO_DATE('01-01-1700 23:59:59',
10863 'DD-MM-YYYY HH24:MI:SS')),
10864 'DESC',
10865 (TO_DATE('01-01-1700 23:59:59',
10866 'DD-MM-YYYY HH24:MI:SS') -
10867 WDD.DATE_SCHEDULED),
10868 null),
10869 'TRIP_STOP_DATE',
10870 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10871 L_TRIP_STOP_DATE_SORT),
10872 NULL))) as sort_attribute1,
10873
10874 -- get for sort_attribute2
10875 To_number(DECODE(l_release_sequence_rule_id,
10876 null,
10877 null,
10878 DECODE(g_ordered_psr(2).attribute_name,
10879 'ORDER_NUMBER',
10880 DECODE(L_ORDER_ID_SORT,
10881 'ASC',
10882 To_number(wdd.source_header_number),
10883 'DESC',
10884 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10885 null),
10886 'SHIPMENT_PRIORITY',
10887 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10888 'High',
10889 20,
10890 'Standard',
10891 10,
10892 NULL),
10893 'INVOICE_VALUE',
10894 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10895 L_INVOICE_VALUE_SORT),
10896 'SCHEDULE_DATE',
10897 DECODE(L_SCHEDULE_DATE_SORT,
10898 'ASC',
10899 (WDD.DATE_SCHEDULED -
10900 TO_DATE('01-01-1700 23:59:59',
10901 'DD-MM-YYYY HH24:MI:SS')),
10902 'DESC',
10903 (TO_DATE('01-01-1700 23:59:59',
10904 'DD-MM-YYYY HH24:MI:SS') -
10905 WDD.DATE_SCHEDULED),
10906 null),
10907 'TRIP_STOP_DATE',
10908 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10909 L_TRIP_STOP_DATE_SORT),
10910 NULL))) as sort_attribute2,
10911
10912 -- get for sort_attribute3
10913 To_number(DECODE(l_release_sequence_rule_id,
10914 null,
10915 null,
10916 DECODE(g_ordered_psr(3).attribute_name,
10917 'ORDER_NUMBER',
10918 DECODE(L_ORDER_ID_SORT,
10919 'ASC',
10920 To_number(wdd.source_header_number),
10921 'DESC',
10922 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10923 null),
10924 'SHIPMENT_PRIORITY',
10925 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10926 'High',
10927 20,
10928 'Standard',
10929 10,
10930 NULL),
10931 'INVOICE_VALUE',
10932 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10933 L_INVOICE_VALUE_SORT),
10934 'SCHEDULE_DATE',
10935 DECODE(L_SCHEDULE_DATE_SORT,
10936 'ASC',
10937 (WDD.DATE_SCHEDULED -
10938 TO_DATE('01-01-1700 23:59:59',
10939 'DD-MM-YYYY HH24:MI:SS')),
10940 'DESC',
10941 (TO_DATE('01-01-1700 23:59:59',
10942 'DD-MM-YYYY HH24:MI:SS') -
10943 WDD.DATE_SCHEDULED),
10944 null),
10945 'TRIP_STOP_DATE',
10946 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10947 L_TRIP_STOP_DATE_SORT),
10948 NULL))) as sort_attribute3,
10949
10950 -- get for sort_attribute4
10951 To_number(DECODE(l_release_sequence_rule_id,
10952 null,
10953 null,
10954 DECODE(g_ordered_psr(4).attribute_name,
10955 'ORDER_NUMBER',
10956 DECODE(L_ORDER_ID_SORT,
10957 'ASC',
10958 To_number(wdd.source_header_number),
10959 'DESC',
10960 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10961 null),
10962 'SHIPMENT_PRIORITY',
10963 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
10964 'High',
10965 20,
10966 'Standard',
10967 10,
10968 NULL),
10969 'INVOICE_VALUE',
10970 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
10971 L_INVOICE_VALUE_SORT),
10972 'SCHEDULE_DATE',
10973 DECODE(L_SCHEDULE_DATE_SORT,
10974 'ASC',
10975 (WDD.DATE_SCHEDULED -
10976 TO_DATE('01-01-1700 23:59:59',
10977 'DD-MM-YYYY HH24:MI:SS')),
10978 'DESC',
10979 (TO_DATE('01-01-1700 23:59:59',
10980 'DD-MM-YYYY HH24:MI:SS') -
10981 WDD.DATE_SCHEDULED),
10982 null),
10983 'TRIP_STOP_DATE',
10984 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
10985 L_TRIP_STOP_DATE_SORT),
10986 NULL))) as sort_attribute4,
10987
10988 -- get for sort_attribute5
10989 To_number(DECODE(l_release_sequence_rule_id,
10990 null,
10991 null,
10992 DECODE(g_ordered_psr(5).attribute_name,
10993 'ORDER_NUMBER',
10994 DECODE(L_ORDER_ID_SORT,
10995 'ASC',
10996 To_number(wdd.source_header_number),
10997 'DESC',
10998 (-1 * To_number(wdd.SOURCE_HEADER_NUMBER)),
10999 null),
11000 'SHIPMENT_PRIORITY',
11001 DECODE(WDD.SHIPMENT_PRIORITY_CODE,
11002 'High',
11003 20,
11004 'Standard',
11005 10,
11006 null),
11007 'INVOICE_VALUE',
11008 wms_replenishment_pvt.GET_SORT_INVOICE_VALUE(WDD.SOURCE_HEADER_ID,
11009 L_INVOICE_VALUE_SORT),
11010 'SCHEDULE_DATE',
11011 DECODE(L_SCHEDULE_DATE_SORT,
11012 'ASC',
11013 (WDD.DATE_SCHEDULED -
11014 TO_DATE('01-01-1700 23:59:59',
11015 'DD-MM-YYYY HH24:MI:SS')),
11016 'DESC',
11017 (TO_DATE('01-01-1700 23:59:59',
11018 'DD-MM-YYYY HH24:MI:SS') -
11019 WDD.DATE_SCHEDULED),
11020 null),
11021 'TRIP_STOP_DATE',
11022 wms_replenishment_pvt.GET_SORT_TRIP_STOP_DATE(wdd.delivery_detail_id,
11023 L_TRIP_STOP_DATE_SORT),
11024 NULL))) as sort_attribute5
11025
11026 FROM
11027 WSH_DELIVERY_DETAILS wdd
11028 WHERE
11029 wdd.source_code = 'OE'
11030 AND wdd.requested_quantity > 0
11031 And WDD.ORGANIZATION_ID = L_ORG_ID
11032 AND WDD.INVENTORY_ITEM_ID = P_ITEM_ID
11033 -- original status demand lines only
11034 AND wdd.released_status in ('R','B') and replenishment_status is NULL --9356579
11035 AND wdd.subinventory IS NULL -- since push_repl conc program does not consider forward pick sub either
11036 -- these demands should not be part of WRD
11037 AND NOT EXISTS (select wrd.demand_line_detail_id
11038 from WMS_REPLENISHMENT_DETAILS wrd
11039 where wrd.demand_line_detail_id = wdd.delivery_detail_id
11040 and wrd.demand_line_id = wdd.source_line_id
11041 and wrd.organization_id = wdd.organization_id)
11042 ORDER BY organization_id, sort_attribute1, sort_attribute2, sort_attribute3, sort_attribute4, sort_attribute5;
11043
11044 Bug 9356579 cursor c_untracked_dmd_repl_cur ends here so unblock */
11045
11046 -- CURSOR TO GET ALL MMTT LINES ASSOCIATED WITH DROP LPN
11047 CURSOR C_DROP_LPN_MMTT_LINE_CSR IS
11048 SELECT organization_id, TRANSACTION_TEMP_ID, MOVE_ORDER_LINE_ID, INVENTORY_ITEM_ID, PRIMARY_QUANTITY
11049 FROM mtl_material_transactions_temp mmtt
11050 WHERE TRANSACTION_HEADER_ID = l_txn_header_id
11051 AND mmtt.organization_id = l_org_id
11052 ORDER BY move_order_line_id asc,primary_quantity desc ;
11053
11054
11055 --pl/sql table to store information about mmtt lines that are going to be dropped
11056 TYPE drop_lpn_item_tbl IS TABLE OF C_DROP_LPN_MMTT_LINE_CSR%ROWTYPE INDEX BY BINARY_INTEGER;
11057 l_drop_lpn_item_tbl drop_lpn_item_tbl;
11058
11059
11060 --R12 Replenishment Project (6681109) ends
11061
11062
11063
11064 BEGIN
11065 IF (l_debug = 1) THEN
11066 mydebug('In Pick_Drop'||g_pkg_version);
11067 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);
11068 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);
11069 END IF;
11070
11071 l_temp_id := p_temp_id;
11072 l_org_id := p_org_id;
11073 l_return_status := fnd_api.g_ret_sts_success;
11074 l_txn_ret := 0;
11075 l_txn_header_id := p_txn_header_id;
11076 l_cnt := 0;
11077 l_isdroplpnentered := TRUE;
11078 -- setting local variables for workflow and logging exceptions
11079 l_wf := 0;
11080 l_sub := p_sub;
11081 l_loc := p_loc;
11082 l_orig_sub := p_orig_sub;
11083 l_loc_reason_id := p_loc_reason_id;
11084
11085 IF (l_debug = 1) THEN
11086 mydebug('pick_drop: ' || p_orig_loc || ' : ' || l_orig_sub || ' : ' || l_org_id);
11087 END IF;
11088
11089 l_user_id := p_user_id;
11090 l_task_type := p_task_type;
11091
11092 -- Added for bug 12853197
11093 SELECT lpn_id
11094 , content_lpn_id
11095 , transfer_lpn_id
11096 , subinventory_code
11097 , locator_id
11098 , transfer_subinventory
11099 , transfer_to_location
11100 , transaction_type_id
11101 , move_order_line_id
11102 , transaction_source_type_id
11103 , inventory_item_id
11104 , transaction_action_id
11105 INTO l_lpn_id
11106 , l_content_lpn_id
11107 , l_transfer_lpn_id
11108 , l_from_sub
11109 , l_from_loc
11110 , l_transfer_sub
11111 , l_transfer_loc
11112 , l_tran_type_id
11113 , l_mo_line_id
11114 , l_tran_source_type_id
11115 , l_inventory_item_id
11116 , l_tran_action_id
11117 FROM mtl_material_transactions_temp
11118 WHERE transaction_temp_id = l_temp_id
11119 AND organization_id = l_org_id;
11120
11121 IF (p_drop_lpn = ''
11122 OR p_drop_lpn IS NULL) THEN
11123 l_isdroplpnentered := FALSE;
11124
11125 IF (l_debug = 1) THEN
11126 mydebug('pick_drop: no drop LPN entered');
11127 END IF;
11128 ELSE
11129 l_isdroplpnentered := TRUE;
11130
11131 IF (l_tran_action_id <> 2 OR l_tran_source_type_id NOT IN(4, 13) OR l_task_type = 7) THEN -- Added for bug 12853197
11132
11133 IF (l_debug = 1) THEN
11134 mydebug('pick_drop: Creating final row for packing. Calling insert_mmtt_pack');
11135 END IF;
11136
11137 wms_task_dispatch_gen.insert_mmtt_pack(
11138 p_temp_id => p_temp_id
11139 , p_lpn_id => p_from_lpn_id
11140 , p_transfer_lpn => p_drop_lpn
11141 , p_container_item_id => 0
11142 , x_return_status => l_return_status
11143 , x_msg_count => l_msg_count
11144 , x_msg_data => l_msg_data
11145 );
11146
11147 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
11148 IF (l_debug = 1) THEN
11149 mydebug('pick_drop: Insert MMTT pack Unexpected error');
11150 END IF;
11151
11152 fnd_msg_pub.ADD;
11153 RAISE fnd_api.g_exc_unexpected_error;
11154 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
11155 IF (l_debug = 1) THEN
11156 mydebug('pick_drop: Insert MMTT pack error');
11157 END IF;
11158
11159 fnd_msg_pub.ADD;
11160 RAISE fnd_api.g_exc_error;
11161 END IF;
11162 END IF; -- Added for bug 12853197
11163 END IF;
11164
11165 IF (l_debug = 1) THEN
11166 mydebug('pick_drop: After call to insert_mmtt_pack');
11167 END IF;
11168
11169 /* Commented for bug 12853197
11170 SELECT lpn_id
11171 , content_lpn_id
11172 , transfer_lpn_id
11173 , subinventory_code
11174 , locator_id
11175 , transfer_subinventory
11176 , transfer_to_location
11177 , transaction_type_id
11178 , move_order_line_id
11179 , transaction_source_type_id
11180 , inventory_item_id
11181 , transaction_action_id
11182 INTO l_lpn_id
11183 , l_content_lpn_id
11184 , l_transfer_lpn_id
11185 , l_from_sub
11186 , l_from_loc
11187 , l_transfer_sub
11188 , l_transfer_loc
11189 , l_tran_type_id
11190 , l_mo_line_id
11191 , l_tran_source_type_id
11192 , l_inventory_item_id
11193 , l_tran_action_id
11194 FROM mtl_material_transactions_temp
11195 WHERE transaction_temp_id = l_temp_id
11196 AND organization_id = l_org_id; */
11197
11198 BEGIN
11199 SELECT LPN_CONTROLLED_FLAG
11200 INTO l_is_transfer_sub_lpn
11201 FROM mtl_secondary_inventories
11202 WHERE ORGANIZATION_ID = p_org_id
11203 AND SECONDARY_INVENTORY_NAME = l_transfer_sub;
11204 EXCEPTION
11205 WHEN OTHERS THEN
11206 l_is_transfer_sub_lpn := 1;
11207 END;
11208
11209 IF (l_debug = 1) THEN
11210 mydebug('l_transfer_sub_lpn :' || l_is_transfer_sub_lpn);
11211 END IF;
11212
11213 IF (WMS_CONTROL.get_current_release_level <
11214 INV_RELEASE.get_j_release_level)
11215 THEN
11216 BEGIN
11217 SELECT 1
11218 INTO l_cnt
11219 FROM DUAL
11220 WHERE EXISTS(SELECT 1
11221 FROM mtl_material_transactions_temp
11222 WHERE parent_line_id = l_temp_id);
11223 EXCEPTION
11224 WHEN NO_DATA_FOUND THEN
11225 l_cnt := 0;
11226 END;
11227
11228 IF l_cnt > 0 THEN
11229 IF (l_debug = 1) THEN
11230 mydebug('pick_drop: Bulk pick line..');
11231 END IF;
11232
11233 -- This is a bulk pick consolidated line. We have to update the
11234 -- child lines with the txn header id
11235
11236 -- Get the lpn info
11237
11238 IF l_content_lpn_id IS NULL THEN
11239 -- User did not pick a complete LPN
11240 IF (l_debug = 1) THEN
11241 mydebug('pick_drop: User did not pick entire lpn');
11242 END IF;
11243
11244 UPDATE mtl_material_transactions_temp
11245 SET transaction_header_id = l_txn_header_id
11246 , lpn_id = l_lpn_id
11247 , transfer_lpn_id = l_transfer_lpn_id
11248 , transaction_status = 3
11249 WHERE parent_line_id = l_temp_id
11250 AND organization_id = l_org_id;
11251 ELSE
11252 -- User picked a complete LPN
11253 IF (l_debug = 1) THEN
11254 mydebug('pick_drop: User picked entire lpn');
11255 END IF;
11256
11257 -- Set lpn_id and transfer_lpn_id to be the same
11258 -- so that the txn manager does not pack or unpack it
11259 -- We have to do this as kind of a hack because we basically
11260 -- are picking one complete lpn but fulfilling multiple
11261 -- mmtt lines
11262
11263 UPDATE mtl_material_transactions_temp
11264 SET transaction_header_id = l_txn_header_id
11265 , lpn_id = l_content_lpn_id
11266 , transfer_lpn_id = l_content_lpn_id
11267 , content_lpn_id = NULL
11268 , transaction_status = 3
11269 WHERE parent_line_id = l_temp_id
11270 AND organization_id = l_org_id;
11271
11272 -- Now update the loc of the LPN
11273
11274 -- Bug5659809: update last_update_date and last_update_by as well
11275 UPDATE wms_license_plate_numbers
11276 SET subinventory_code = l_transfer_sub
11277 , locator_id = l_transfer_loc
11278 , last_update_date = SYSDATE
11279 , last_updated_by = fnd_global.user_id
11280 WHERE lpn_id = l_content_lpn_id
11281 AND organization_id = l_org_id;
11282 END IF;
11283
11284 IF (l_debug = 1) THEN
11285 mydebug('pick_drop: Deleting orig mmtt bulk pick line..');
11286 END IF;
11287
11288 -- Get rid of the original MMTT line (which was a bogus line created
11289 -- for bulk picking
11290 DELETE mtl_material_transactions_temp
11291 WHERE transaction_temp_id = l_temp_id;
11292 END IF;
11293 END IF;
11294
11295 IF (l_debug = 1) THEN
11296 mydebug('pick_drop: Determining business flow code...');
11297 END IF;
11298
11299 l_flow := inv_label.wms_bf_pick_drop;
11300
11301 IF l_tran_type_id = 52 THEN -- Picking for sales order
11302 l_flow := inv_label.wms_bf_pick_drop;
11303 ELSIF l_tran_type_id = 35 THEN -- WIP issue
11304 l_flow := inv_label.wms_bf_wip_pick_drop;
11305 ELSIF l_tran_type_id = 51
11306 AND l_tran_source_type_id = 13 THEN --Backflush
11307 l_flow := inv_label.wms_bf_wip_pick_drop;
11308 ELSIF l_tran_action_id = 2
11309 AND l_tran_source_type_id IN(4, 13) THEN --Replenishment
11310 l_flow := inv_label.wms_bf_replenishment_drop;
11311 END IF;
11312
11313 IF (l_debug = 1) THEN
11314 mydebug('pick_drop: l_txn_header_id= ' || l_txn_header_id);
11315 mydebug('pick_drop: l_flow= ' || l_flow);
11316 END IF;
11317
11318 IF (l_debug = 1) THEN
11319 mydebug('pick_drop: Need to check if account period is open before calling TM');
11320 END IF;
11321
11322 invttmtx.tdatechk
11323 ( org_id => l_org_id
11324 , transaction_date => SYSDATE
11325 , period_id => l_period_id
11326 , open_past_period => l_open_past_period
11327 );
11328
11329 IF l_period_id <> -1 THEN
11330 IF (l_debug = 1) THEN
11331 mydebug('pick_drop: Need to update the account period in MMTT');
11332 END IF;
11333
11334 UPDATE mtl_material_transactions_temp
11335 SET acct_period_id = l_period_id
11336 WHERE transaction_header_id = l_txn_header_id
11337 AND organization_id = l_org_id;
11338 ELSE
11339 IF (l_debug = 1) THEN
11340 mydebug('pick_drop: Period is invalid');
11341 END IF;
11342
11343 fnd_message.set_name('INV', 'INV_NO_OPEN_PERIOD');
11344 fnd_msg_pub.ADD;
11345 RAISE fnd_api.g_exc_unexpected_error;
11346 END IF;
11347
11348 -- call workflow for location discrepancy
11349 IF (l_debug = 1) THEN
11350 mydebug('pick_drop: l_loc_reason_id ' || l_loc_reason_id);
11351 END IF;
11352
11353 l_wf := 0;
11354
11355 IF (l_loc_reason_id > 0) THEN
11356 --Log exception
11357 IF (l_debug = 1) THEN
11358 mydebug('pick_drop: Logging exceptions for loc discrepancy');
11359 mydebug('pick_drop: txn_header_id: ' || l_txn_header_id);
11360 mydebug('l_from_sub: ' || l_from_sub);
11361 mydebug('l_from_loc: ' || l_from_loc);
11362 mydebug('l_task type: ' || l_task_type);
11363 mydebug('l_item id' || l_inventory_item_id);
11364 END IF;
11365
11366 FOR rec_mmtt IN mmtt_csr loop
11367 -- right now we give the from_sub and from_loc until
11368 -- wms control board is enhanced.
11369 wms_txnrsn_actions_pub.log_exception
11370 (p_api_version_number => 1.0,
11371 p_init_msg_lst => fnd_api.g_false,
11372 p_commit => fnd_api.g_false,
11373 x_return_status => l_return_status,
11374 x_msg_count => l_msg_count,
11375 x_msg_data => l_msg_data,
11376 p_organization_id => l_org_id,
11377 p_mmtt_id => rec_mmtt.transaction_temp_id,
11378 p_task_id => rec_mmtt.transaction_temp_id,
11379 p_reason_id => l_loc_reason_id,
11380 p_subinventory_code => l_from_sub,
11381 p_locator_id => l_from_loc,
11382 p_discrepancy_type => l_task_type,
11383 p_user_id => l_user_id,
11384 p_item_id => l_inventory_item_id,
11385 p_revision => NULL,
11386 p_lot_number => NULL,
11387 p_is_loc_desc => TRUE); --Added bug 3989684
11388
11389 IF (l_debug = 1) THEN
11390 mydebug('pick_drop: after logging exception for temp_id: ' || rec_mmtt.transaction_temp_id);
11391 END IF;
11392
11393 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
11394 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
11395 fnd_msg_pub.ADD;
11396 RAISE fnd_api.g_exc_unexpected_error;
11397 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
11398 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
11399 fnd_msg_pub.ADD;
11400 RAISE fnd_api.g_exc_error;
11401 END IF;
11402
11403 END LOOP;
11404
11405 -- bug 2782039
11406 -- we now pass in the suggested locator ID directly
11407 BEGIN
11408 l_orig_loc := TO_NUMBER(p_orig_loc);
11409 EXCEPTION
11410 WHEN OTHERS THEN
11411 IF (l_debug = 1) THEN
11412 mydebug('pick_drop: converting p_orig_loc : ' || p_orig_loc || ' to l_orig_loc throws exception.');
11413 END IF;
11414 END;
11415
11416 IF (l_debug = 1) THEN
11417 mydebug('pick_drop: l_orig_loc: ' || l_orig_loc);
11418 END IF;
11419
11420 BEGIN
11421 SELECT 1
11422 INTO l_wf
11423 FROM mtl_transaction_reasons
11424 WHERE reason_id = l_loc_reason_id
11425 AND workflow_name IS NOT NULL
11426 AND workflow_name <> ' '
11427 AND workflow_process IS NOT NULL
11428 AND workflow_process <> ' ';
11429 EXCEPTION
11430 WHEN NO_DATA_FOUND THEN
11431 l_wf := 0;
11432 END;
11433
11434 IF l_wf > 0 THEN
11435 IF (l_debug = 1) THEN
11436 mydebug('pick_drop : WF exists for this reason code: ' || l_loc_reason_id);
11437 mydebug('pick_drop : Calling workflow wrapper FOR location');
11438 END IF;
11439
11440 -- Calling Workflow
11441 wms_workflow_wrappers.wf_wrapper(
11442 p_api_version => 1.0
11443 , p_init_msg_list => fnd_api.g_false
11444 , p_commit => fnd_api.g_false
11445 , x_return_status => l_return_status
11446 , x_msg_count => l_msg_count
11447 , x_msg_data => l_msg_data
11448 , p_org_id => l_org_id
11449 , p_rsn_id => l_loc_reason_id
11450 , p_calling_program => 'pick_drop - for loc discrepancy'
11451 , p_tmp_id => l_temp_id
11452 , p_quantity_picked => NULL
11453 , p_dest_sub => l_orig_sub
11454 , p_dest_loc => l_orig_loc
11455 );
11456
11457 IF (l_debug = 1) THEN
11458 mydebug('pick_drop : After Calling WF Wrapper');
11459 END IF;
11460
11461 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
11462 IF (l_debug = 1) THEN
11463 mydebug('pick_drop : Error callinf WF wrapper');
11464 END IF;
11465
11466 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
11467 fnd_msg_pub.ADD;
11468 RAISE fnd_api.g_exc_unexpected_error;
11469 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
11470 IF (l_debug = 1) THEN
11471 mydebug('pick_drop : Error calling WF wrapper');
11472 END IF;
11473
11474 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
11475 fnd_msg_pub.ADD;
11476 RAISE fnd_api.g_exc_error;
11477 END IF;
11478 END IF;
11479 END IF;
11480
11481 IF (l_debug = 1) THEN
11482 mydebug('pick_drop: Insert WDT History');
11483 END IF;
11484
11485 OPEN mmtt_csr;
11486
11487 LOOP
11488 FETCH mmtt_csr INTO l_temp_id;
11489 EXIT WHEN mmtt_csr%NOTFOUND;
11490 wms_task_dispatch_put_away.archive_task
11491 ( p_temp_id => l_temp_id
11492 , p_org_id => l_org_id
11493 , x_return_status => l_return_status
11494 , x_msg_count => l_msg_count
11495 , x_msg_data => l_msg_data
11496 , p_delete_mmtt_flag => 'N'
11497 , p_txn_header_id => l_txn_header_id
11498 , p_transfer_lpn_id => NVL(l_transfer_lpn_id, l_content_lpn_id)
11499 );
11500 END LOOP;
11501
11502 CLOSE mmtt_csr;
11503
11504 -- Now need to update LPN context appropriately
11505 IF l_isdroplpnentered = TRUE THEN
11506 SELECT lpn_id
11507 INTO l_xfrlpnid
11508 FROM wms_license_plate_numbers
11509 WHERE license_plate_number = p_drop_lpn;
11510 ELSE
11511 l_xfrlpnid := p_from_lpn_id;
11512 END IF;
11513
11514 l_lpn_context := wms_container_pub.lpn_context_picked;
11515
11516
11517 IF l_tran_type_id = 35 THEN -- WIP issue
11518 l_lpn_context := wms_container_pub.lpn_context_pregenerated;
11519
11520 ELSIF l_tran_type_id = 51 AND l_tran_source_type_id = 13 THEN --Backflush
11521 -- Bug 3954141
11522 -- If destination subinventory is not lpn controlled
11523 -- lpn context should be set to defined but not used
11524 --
11525 IF (l_is_transfer_sub_lpn = 2)
11526 THEN
11527 l_lpn_context := wms_container_pub.lpn_context_pregenerated;
11528 ELSE
11529 l_lpn_context := wms_container_pub.lpn_context_inv;
11530 END IF;
11531
11532 ELSIF l_tran_action_id = 2
11533 AND l_tran_source_type_id IN (13)
11534 AND l_task_type IN (7) THEN --Staging move
11535 l_lpn_context := wms_container_pub.lpn_context_picked;
11536
11537 ELSIF l_tran_action_id = 2
11538 AND l_tran_source_type_id IN(4, 13) THEN --Replenishment
11539
11540 -- Modified for bug 12853197
11541
11542 SELECT count(transaction_temp_id)
11543 INTO l_check_tasks
11544 FROM mtl_material_transactions_temp mmtt
11545 WHERE transfer_lpn_id = l_transfer_lpn_id
11546 AND transaction_header_id <> l_txn_header_id;
11547
11548
11549 IF (l_is_transfer_sub_lpn = 2)
11550 THEN
11551 IF (l_debug = 1) THEN
11552 mydebug('pick_drop: In the condition for l_trs_sub');
11553 mydebug('pick_drop: Values of l_temp_id:' || l_temp_id);
11554 mydebug('pick_drop: Values of l_transfer_lpn_id:' || l_transfer_lpn_id);
11555 mydebug('pick_drop: Values of l_transfer_sub:' || l_transfer_sub);
11556 mydebug('pick_drop: Values of l_transfer_loc:' || l_transfer_loc);
11557 END IF;
11558
11559 IF l_check_tasks = 0 THEN
11560 l_lpn_context := wms_container_pub.LPN_CONTEXT_PREGENERATED;
11561 ELSE
11562 l_lpn_context := wms_container_pub.LPN_CONTEXT_PACKING;
11563 END IF;
11564
11565 UPDATE mtl_material_transactions_temp
11566 SET transfer_lpn_id = NULL
11567 WHERE transaction_header_id = l_txn_header_id;
11568
11569 ELSE
11570
11571 IF l_xfrlpnid<>l_transfer_lpn_id THEN
11572
11573 l_lpn_context := wms_container_pub.lpn_context_inv;
11574
11575 UPDATE mtl_material_transactions_temp
11576 SET transfer_lpn_id = l_xfrlpnid
11577 WHERE transaction_header_id = l_txn_header_id;
11578
11579 IF (l_check_tasks=0) THEN
11580 l_from_lpn_context := wms_container_pub.LPN_CONTEXT_PREGENERATED;
11581 ELSE
11582 l_from_lpn_context := wms_container_pub.LPN_CONTEXT_PACKING;
11583 END IF;
11584
11585 l_update_frm_lpn :=TRUE;
11586
11587 ELSE
11588
11589 IF l_check_tasks>0 THEN
11590
11591 l_lpn_context := wms_container_pub.LPN_CONTEXT_PACKING;
11592
11593 UPDATE mtl_material_transactions_temp
11594 SET transfer_lpn_id = null
11595 WHERE transaction_header_id = l_txn_header_id;
11596
11597 ELSE
11598 l_lpn_context := wms_container_pub.lpn_context_inv;
11599 END IF;
11600 END IF;
11601
11602 END IF;
11603 /*
11604 l_lpn_context := wms_container_pub.lpn_context_inv;
11605
11606 --
11607 -- Bug 3160462:
11608 -- If its a no lpn controlled transfer
11609 -- sub xfer lpn should go to define but not used
11610 --
11611 IF (l_is_transfer_sub_lpn = 2) THEN
11612
11613 IF (l_debug = 1) THEN
11614 mydebug('pick_drop: In the condition for l_trs_sub');
11615 mydebug('pick_drop: Values of l_temp_id:' || l_temp_id);
11616 mydebug('pick_drop: Values of l_transfer_lpn_id:' || l_transfer_lpn_id);
11617 mydebug('pick_drop: Values of l_transfer_sub:' || l_transfer_sub);
11618 mydebug('pick_drop: Values of l_transfer_loc:' || l_transfer_loc);
11619 END IF;
11620
11621 --Bug 5318552
11622 -- Only if the LPN being dropped does not have any more pending DROPS
11623 -- that its context should be set to pregenerated, otherwise to Packing
11624 -- (as it was before drop)
11625
11626 SELECT count(transaction_temp_id)
11627 INTO l_check_tasks
11628 FROM mtl_material_transactions_temp mmtt
11629 WHERE transfer_lpn_id = l_transfer_lpn_id
11630 AND transaction_temp_id <> l_temp_id ;
11631 IF l_check_tasks = 0 THEN
11632 l_lpn_context := wms_container_pub.LPN_CONTEXT_PREGENERATED;
11633 ELSE
11634 l_lpn_context := wms_container_pub.LPN_CONTEXT_PACKING;
11635 END IF;
11636
11637 --End of fix for Bug 5318552
11638
11639 END IF; */
11640 ELSIF wms_task_utils_pvt.can_drop(p_lpn_id => p_from_lpn_id) = 'W' THEN
11641 -- Sales order cancelled
11642 l_lpn_context := wms_container_pub.lpn_context_inv;
11643 END IF;
11644
11645 --Bug # 2275770
11646 --Update mmtt.transaction_date to sysdate
11647 UPDATE mtl_material_transactions_temp
11648 SET transaction_date = SYSDATE
11649 WHERE transaction_header_id = l_txn_header_id;
11650
11651 -- Now call the txn processor...
11652
11653 IF (l_debug = 1) THEN
11654 mydebug('pick_drop: Before Calling txn proc');
11655 END IF;
11656
11657 IF l_tran_type_id = 35 THEN
11658 --
11659 -- WIP issue
11660 --
11661 IF (WMS_CONTROL.get_current_release_level >= INV_RELEASE.get_j_release_level)
11662 THEN
11663 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx
11664 ( p_trx_hdr_id => l_txn_header_id
11665 , p_commit => fnd_api.g_false
11666 , p_proc_mode => 1
11667 , x_proc_msg => l_msg_data
11668 , p_business_flow_code => l_flow
11669 );
11670
11671 IF (l_debug = 1) THEN
11672 mydebug('pick_drop: After Calling txn proc');
11673 mydebug('pick_drop: Txn proc ret' || l_txn_ret);
11674 END IF;
11675
11676 IF l_txn_ret <> 0 THEN
11677 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11678 fnd_msg_pub.ADD;
11679 RAISE fnd_api.g_exc_unexpected_error;
11680 END IF;
11681 ELSE
11682 --
11683 -- Bug 2747945 : Added business flow code to the call to the wip processor.
11684 --
11685 IF (l_debug = 1) THEN
11686 mydebug('pick_drop:seperate call for WIP issue');
11687 END IF;
11688
11689 wms_wip_integration.wip_processor
11690 ( p_txn_hdr_id => l_txn_header_id
11691 , p_business_flow_code => l_flow
11692 , x_return_status => l_return_status
11693 );
11694
11695 IF (l_debug = 1) THEN
11696 mydebug('pick_drop: After Calling WIP txn proc STATUS' || l_return_status);
11697 END IF;
11698
11699 IF l_return_status <> fnd_api.g_ret_sts_success THEN
11700 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11701 fnd_msg_pub.ADD;
11702 RAISE fnd_api.g_exc_unexpected_error;
11703 END IF;
11704 END IF; -- end if release J
11705 ELSE
11706 --
11707 -- Not a WIP issue task
11708 --
11709 -- bug 2760062
11710 -- for Staing move task type
11711 -- if the LPN contains any WDD line that has been ship-confirmed
11712 -- do NOT call TM.
11713
11714 IF l_task_type = 7 THEN
11715 -- 8714995 added released_status 'X' condition
11716 SELECT COUNT(wdd2.lpn_id)
11717 INTO l_open_wdd_count_in_lpn
11718 FROM wsh_delivery_details wdd1
11719 , wsh_delivery_details wdd2
11720 , wsh_delivery_assignments_v wda
11721 , wms_license_plate_numbers wlpn
11722 WHERE wdd2.released_status = 'X'
11723 AND wda.parent_delivery_detail_id = wdd2.delivery_detail_id
11724 AND wda.delivery_detail_id = wdd1.delivery_detail_id
11725 AND wdd2.lpn_id = wlpn.lpn_id
11726 AND wlpn.outermost_lpn_id = l_content_lpn_id;
11727
11728 SELECT COUNT(wdd2.lpn_id)
11729 INTO l_shipped_wdd_count_in_lpn
11730 FROM wsh_delivery_details wdd1
11731 , wsh_delivery_details wdd2
11732 , wsh_delivery_assignments_v wda
11733 , wms_license_plate_numbers wlpn
11734 WHERE wdd1.released_status = 'C'
11735 AND wda.delivery_detail_id = wdd1.delivery_detail_id
11736 AND wda.parent_delivery_detail_id = wdd2.delivery_detail_id
11737 AND wdd2.lpn_id = wlpn.lpn_id
11738 AND wlpn.outermost_lpn_id = l_content_lpn_id;
11739
11740 IF (l_open_wdd_count_in_lpn = 0 and l_shipped_wdd_count_in_lpn > 0) THEN
11741 IF (l_debug = 1) THEN
11742 mydebug('pick_drop: this LPN ' || l_content_lpn_id ||
11743 ' contains delivery details lines that have been ship confirmed.');
11744 END IF;
11745
11746 fnd_message.set_name('WMS', 'WMS_STG_MV_LPN_SHIPPED');
11747 fnd_msg_pub.ADD;
11748 RAISE fnd_api.g_exc_unexpected_error;
11749 END IF;
11750 END IF;
11751
11752 -- VARAJAGO for bug 5222498, inserting the serial_number's group_mark_id into the temp table
11753 -- DHERRING added to change to include nested LPN solution.
11754
11755 DELETE wms_wsh_wdd_gtemp;
11756 IF l_tran_type_id = 2 AND l_tran_action_id = 2 AND l_tran_source_type_id = 13
11757 AND l_lpn_context = 11 THEN -- only for the staging xfer transaction
11758
11759 FOR rec_child_lpns_csr IN child_lpns_csr LOOP
11760 IF (l_debug = 1) THEN
11761 mydebug('pick_drop: Xfer LPN id : ' || l_xfrlpnid );
11762 mydebug('pick_drop: l_lpn_id : ' || rec_child_lpns_csr.lpn_id );
11763 mydebug('pick_drop: p_from_lpn_id : ' || p_from_lpn_id );
11764 END IF;
11765
11766 INSERT INTO wms_wsh_wdd_gtemp
11767 (SERIAL_NUMBER
11768 , organization_id
11769 , INVENTORY_ITEM_ID
11770 , transaction_temp_id
11771 , LPN_ID)
11772 SELECT serial_number
11773 , current_organization_id
11774 , inventory_item_id
11775 , group_mark_id
11776 , lpn_id
11777 FROM mtl_serial_numbers
11778 WHERE lpn_id = rec_child_lpns_csr.lpn_id;
11779
11780 END LOOP;
11781 END IF;
11782 -- VARAJAGO End of code for bug 5222498.
11783
11784
11785 --===================================================
11786 --R12.1 Replenishment Project 6681109 STARTS
11787 --Store all the Items and qty that are going to be dropped along with this drop LPN
11788 --Query the MMTT based on the transaction_header_id and get all Item_id and quantity and save them in a PL/SQL table.
11789 -- Assuming that at the end of the TM processing all these lines will be trnsacted.
11790 -- 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.
11791
11792 IF l_task_type = 4 THEN -- replenishemnt drop tasks
11793 -- BULK UPLOAD ALL cursor records into l_DROP_LPN_ITEM_TBL HERE
11794 IF (l_debug = 1) THEN
11795 mydebug('Store All mmtt records being dropped for replenishment');
11796 END IF;
11797
11798 OPEN C_DROP_LPN_MMTT_LINE_CSR;
11799 FETCH C_DROP_LPN_MMTT_LINE_CSR BULK COLLECT INTO l_drop_lpn_item_tbl ;
11800 CLOSE C_DROP_LPN_MMTT_LINE_CSR;
11801
11802 IF (l_debug = 1) THEN
11803 mydebug('Repl MMTT records selected - Count :'||l_drop_lpn_item_tbl.COUNT() );
11804 END IF;
11805
11806 END IF;
11807
11808 --R12.1 Replenishment Project 6681109 ENDS
11809 --===================================================
11810
11811
11812
11813 -- Release 12 Shipping Content Enhancement 4645826
11814 -- For Pick Drop, call label printing after TM, do not pass business flow to TM
11815 -- For other business flow, call labels through TM
11816
11817 IF l_flow = inv_label.wms_bf_pick_drop THEN
11818 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx
11819 ( p_trx_hdr_id => l_txn_header_id
11820 , p_commit => fnd_api.g_false
11821 , p_proc_mode => 1
11822 , x_proc_msg => l_msg_data
11823 , p_business_flow_code => null
11824 );
11825 ELSE
11826 -- TM call for Replenishment Drop will come here
11827 IF (l_debug = 1) THEN
11828 mydebug('TEST: Going to call TM for Replenishment Drop................ ');
11829 END IF;
11830 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx
11831 ( p_trx_hdr_id => l_txn_header_id
11832 , p_commit => fnd_api.g_false
11833 , p_proc_mode => 1
11834 , x_proc_msg => l_msg_data
11835 , p_business_flow_code => l_flow
11836 );
11837 END IF;
11838 -- End 4645826
11839
11840
11841 IF (l_debug = 1) THEN
11842 mydebug('pick_drop: After Calling txn proc');
11843 mydebug('pick_drop: Txn proc ret' || l_txn_ret);
11844 END IF;
11845
11846 IF l_txn_ret <> 0 THEN
11847 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11848 fnd_msg_pub.ADD;
11849 RAISE fnd_api.g_exc_unexpected_error;
11850 END IF;
11851 END IF; -- for l_tran_type_id <> 35
11852
11853
11854 --===================================================
11855 -- R12.1 replenishment Project 6681109 STARTS -----
11856
11857 IF l_txn_ret = 0 AND l_task_type = 4 THEN -- replenishment drop task
11858 IF (l_debug = 1) THEN
11859 mydebug('Consume replenishment related demands..STARTS....HERE ');
11860 END IF;
11861
11862 /* Brought the variables Out of Loop as the counter was always 1 when inside 14014540*/
11863 l_index := 0;
11864 l_b_index := 0;
11865 FOR CNT IN 1..l_DROP_LPN_ITEM_TBL.COUNT() LOOP
11866 IF (l_debug = 1) THEN
11867 mydebug('Processing Item_Id :'|| L_DROP_LPN_ITEM_TBL(CNT).inventory_item_id||', Qty :'
11868 || L_DROP_LPN_ITEM_TBL(CNT).primary_quantity||', MO_Line_ID :'
11869 || L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id);
11870 END IF;
11871
11872 --BUG14014540 Begin
11873 l_curr_move_order_line_id := L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id;
11874 IF(l_prev_move_order_line_id <> l_curr_move_order_line_id) THEN
11875 --call the proc here
11876 --The procedure is call for the previous move order line. The current loop already is orderd by move order line id..
11877 IF(l_prev_move_order_line_id <> -9999) THEN
11878 process_remaining_wdds_repl(l_prev_move_order_line_id, p_org_id);
11879 END IF;
11880 l_prev_move_order_line_id := l_curr_move_order_line_id;
11881
11882 IF (l_debug = 1) THEN
11883 mydebug('MO_Line_ID :' || L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id ||' ,l_prev_move_order_line_id '||l_prev_move_order_line_id ||' ,l_curr_move_order_line_id '||l_curr_move_order_line_id);
11884 END IF;
11885 END IF;
11886 --BUG14014540 End
11887
11888
11889 L_REMAINING_MMTT_QTY:= L_DROP_LPN_ITEM_TBL(CNT).PRIMARY_QUANTITY;
11890
11891 IF L_REMAINING_MMTT_QTY > 0 THEN
11892
11893 -- See it the move order line is part of WRD table
11894 -- Existance check only if the MOL changes from the previous MMTT record
11895 IF l_prev_mol IS NULL OR l_prev_mol <>
11896 L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id THEN
11897
11898 BEGIN
11899 SELECT 1, demand_type_id INTO l_exists_in_wrd, l_demand_type_id
11900 FROM wms_replenishment_details wrd
11901 WHERE WRD.ORGANIZATION_ID = P_ORG_ID
11902 AND WRD.SOURCE_LINE_ID = L_DROP_LPN_ITEM_TBL(CNT).MOVE_ORDER_LINE_ID
11903 AND WRD.INVENTORY_ITEM_ID = L_DROP_LPN_ITEM_TBL(CNT).INVENTORY_ITEM_ID
11904 AND ROWNUM = 1;
11905
11906 EXCEPTION
11907 WHEN no_data_found THEN
11908 IF (l_debug = 1) THEN
11909 mydebug('Move Order Line NOT found in WRD');
11910 END IF;
11911 l_exists_in_wrd := 0;
11912 WHEN OTHERS THEN
11913 l_exists_in_wrd := 0;
11914 END;
11915
11916 END IF; -- IF l_prev_mol IS NULL OR l_prev_mol <>
11917
11918 IF (l_debug = 1) THEN
11919 mydebug('IF the MOL exists in WRD :' ||l_exists_in_wrd);
11920 mydebug('MOL demand_type_id :' ||l_demand_type_id);
11921 END IF;
11922
11923
11924 IF l_exists_in_wrd = 1 THEN -- consume demand from WRD table
11925
11926 IF l_demand_type_id = 4 THEN -- means multi level repl
11927 -- code will come here only for repl_level > 1 based on l_demand_type_id
11928 -- find all associated demand move order lines and allocate them
11929
11930 OPEN c_multi_level_repl_alloc(L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id) ;
11931 LOOP
11932 FETCH c_multi_level_repl_alloc INTO l_demand_header_id,l_demand_line_id,
11933 l_wrd_pri_quantity,l_repl_level, l_demand_type_id;
11934
11935 EXIT WHEN c_multi_level_repl_alloc%NOTFOUND;
11936
11937 IF (l_debug = 1) THEN
11938 mydebug('Move Order Header :' || l_demand_header_id);
11939 mydebug('Replenishment Level :' || l_repl_level);
11940 mydebug('Demand Type Id :' || l_demand_type_id);
11941 mydebug('Primary MO Quantity :' || l_wrd_pri_quantity);
11942 mydebug('Calling Allocation Engine for MO :' || l_demand_line_id);
11943 END IF;
11944
11945 -- Call Allocation engine for allocate MO
11946 WMS_Engine_PVT.create_suggestions(
11947 p_api_version => 1.0,
11948 p_init_msg_list => fnd_api.g_false,
11949 p_commit => fnd_api.g_false,
11950 p_validation_level => fnd_api.g_valid_level_none,
11951 x_return_status => l_return_status,
11952 x_msg_count => l_msg_count,
11953 x_msg_data => l_msg_data,
11954 p_transaction_temp_id => l_demand_line_id,
11955 p_reservations => l_rsv_tbl_tmp, --No rsv FOR repl MO
11956 p_suggest_serial => fnd_api.g_false,
11957 p_plan_tasks => FALSE
11958 );
11959
11960 IF l_return_status <> fnd_api.g_ret_sts_success THEN
11961 IF (l_debug = 1) THEN
11962 mydebug('Move Order Allocation Failed, Move to next one');
11963 END IF;
11964 -- do nothing, skip this
11965
11966 ELSE -- Move order got allocated successfully
11967 -- remove the record from the WRD table
11968
11969 DELETE FROM WMS_REPLENISHMENT_DETAILS
11970 WHERE organization_id = p_org_id
11971 AND demand_type_id = 4
11972 AND demand_header_id = l_demand_header_id
11973 AND demand_line_id = l_demand_line_id;
11974
11975
11976 END IF;
11977
11978 END LOOP;
11979 CLOSE c_multi_level_repl_alloc;
11980
11981 ELSE --means l_demand_type_id <> 4; demand is WDD
11982
11983 -- code will come here only for repl_level = 1
11984 -- Mark RC to demand lines that are part of C_MARK_DEMAND_RC_CSR
11985 -- And pick release these lines if part of dynamic repl
11986 -- Moving the variable out of the main loop 14014540
11987 -- l_index := 0;
11988 -- l_b_index := 0;
11989
11990 OPEN c_mark_demand_rc_csr(L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id) ;
11991 LOOP
11992 FETCH c_mark_demand_rc_csr INTO l_delivery_detail_id, L_SHIP_SET_ID,
11993 l_SHIP_MODEL_ID,
11994 l_wrd_pri_quantity,l_REQUESTED_QUANTITY,
11995 l_primary_uom, l_repl_type,l_repl_level, l_batch_id,l_demand_type_id;
11996
11997 EXIT WHEN c_mark_demand_rc_csr%notfound;
11998
11999 IF (l_debug = 1) THEN
12000 mydebug('Currently Consuming REPL MO for Repl Level :'||l_repl_level);
12001 mydebug('l_demand_type_id :'||l_demand_type_id);
12002 END IF;
12003
12004 -- Verify level of replenishment
12005 IF l_repl_level = 1 THEN -- replenishment for original demand
12006 IF l_wrd_pri_quantity <= l_requested_quantity THEN
12007 l_demand_pri_qty := l_wrd_pri_quantity;
12008 ELSE
12009 l_demand_pri_qty := l_requested_quantity;
12010 END IF;
12011
12012 ELSE -- invalid value of repl level
12013 IF (l_debug = 1) THEN
12014 mydebug('Invalid Value of Replenishment Level, skip this demand');
12015 END IF;
12016
12017 END IF;
12018
12019 IF L_REMAINING_MMTT_QTY >= L_DEMAND_PRI_QTY THEN
12020 IF (l_debug = 1) THEN
12021 mydebug('repl completion qty is greater than tied up demand qty');
12022 mydebug('Mark the delivery detail to RC - detail_id :' ||l_delivery_detail_id);
12023 END IF;
12024
12025 -- CALL SHIPPING API TO MARK THESE DELIVERY DETAILS AS 'RC' based on
12026 --l_delivery_detail_id
12027
12028 wms_replenishment_pvt.update_wdd_repl_status
12029 (p_deliv_detail_id => l_delivery_detail_id
12030 , p_repl_status => 'C' -- for completed status
12031 , x_return_status => l_return_status
12032 );
12033
12034 IF l_return_status <> fnd_api.g_ret_sts_success THEN
12035 -- do nothing, skip this
12036 GOTO next_repl_demand;
12037 END IF;
12038
12039
12040 --Remove the entry from the WRD table
12041 DELETE FROM WMS_REPLENISHMENT_DETAILS
12042 WHERE organization_id = p_org_id
12043 AND DEMAND_LINE_DETAIL_ID= l_delivery_detail_id;
12044
12045 -- Decrease the current MMTT qty
12046 L_REMAINING_MMTT_QTY := L_REMAINING_MMTT_QTY - L_DEMAND_PRI_QTY;
12047
12048
12049 ELSE -- means (l_demand_pri_qty > l_remaining_mmtt_qty )
12050
12051 IF (l_debug = 1) THEN
12052 mydebug('repl completion qty is LESS than tied up demand qty');
12053 mydebug('SPLIT the delivery line');
12054 END IF;
12055
12056 -- Split the original deamand line
12057 -- the newly created demand line will have qty =(L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY)
12058 -- WITH original 'RR" status . The shipping API with 'SPLIT-LINE' action in turn calls
12059 -- the wms_replenishment_pvt.update_delivery_detail() API that insert the newly created
12060 -- record with RR status in the WRD table AND updates the qty to l_remaining_mmtt_qty
12061 -- for the old delivery_detail record in the WRD table
12062
12063 -- So after calling for the split-line action, I need to call shipping
12064 -- AND mark the original delivery detail line to 'RC' and delete this WRD record
12065
12066
12067 l_detail_id_tab.DELETE;
12068 l_action_prms := NULL;
12069 l_detail_id_tab(1) := l_delivery_detail_id;
12070 -- Caller needs to be WSH_PUB in order for shipping to allow this action
12071 l_action_prms.caller := 'WSH_PUB';
12072 l_action_prms.action_code := 'SPLIT-LINE';
12073 l_action_prms.split_quantity := (L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY) ;
12074
12075 WSH_INTERFACE_GRP.Delivery_Detail_Action
12076 (p_api_version_number => 1.0,
12077 p_init_msg_list => fnd_api.g_false,
12078 p_commit => fnd_api.g_false,
12079 x_return_status => l_return_status,
12080 x_msg_count => x_msg_count,
12081 x_msg_data => x_msg_data,
12082 p_detail_id_tab => l_detail_id_tab,
12083 p_action_prms => l_action_prms,
12084 x_action_out_rec => l_action_out_rec
12085 );
12086
12087 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
12088 IF (l_debug = 1) THEN
12089 mydebug('Error returned from Split Delivery_Detail_Action API..skip this demand');
12090 END IF;
12091 -- do nothing, skip this demand line
12092 GOTO next_repl_demand;
12093
12094 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
12095 IF (l_debug = 1) THEN
12096 mydebug('Unexpected errror from Split Delivery_Detail_Action API..skip this demand');
12097 END IF;
12098 -- do nothing, skip this demand line
12099 GOTO next_repl_demand;
12100 END IF;
12101
12102 -- At this point the new delivery is already inserted in the WRD table.
12103 -- AND the qty for original delivery has been updated
12104 -- TO l_remaining_mmtt_qty IN WRD as above api calls
12105 -- wms_replenishment_pvt.update_delivery_detail() internally.
12106 -- SO JUST MARK original delivery replenishment_status RC
12107 -- and then delete the original record from the WRD table
12108
12109 wms_replenishment_pvt.update_wdd_repl_status
12110 (p_deliv_detail_id => l_delivery_detail_id
12111 , p_repl_status => 'C' -- for completed status
12112 , x_return_status => l_return_status
12113 );
12114
12115 IF l_return_status <> fnd_api.g_ret_sts_success THEN
12116 IF (l_debug = 1) THEN
12117 mydebug('Errror from Delivery_Detail_Action api to mark RC...skip this demand');
12118 END IF;
12119 -- do nothing, skip this demand line
12120 GOTO next_repl_demand;
12121 END IF;
12122
12123
12124 -- delete the original demand as it was marked RC
12125 -- nwely created delviery will be in WRD as 'RR'
12126 DELETE FROM WMS_REPLENISHMENT_DETAILS
12127 WHERE DEMAND_LINE_DETAIL_ID= l_delivery_detail_id;
12128
12129 L_REMAINING_MMTT_QTY := 0;
12130
12131 END IF; -- for L_REMAINING_MMTT_QTY >= L_DEMAND_PRI_QTY
12132
12133
12134 -- Pick Release associated demand lines as well only FOR repl_level = 1
12135 -- Store all these delivery_detail_ids and release in bulk per batch_id
12136 IF l_repl_type = 2 THEN -- pick release only if part of dynamic replenishment
12137 IF L_SHIP_SET_ID IS NULL and L_SHIP_MODEL_ID IS NULL THEN
12138
12139 IF (l_debug = 1) THEN
12140 mydebug('NOT part OF ship Set/Model Pick Releasing delivery Detail :'||l_delivery_detail_id);
12141 mydebug('Current Batch_id :'||l_batch_id);
12142 END IF;
12143 -- Store all deliv_detail_ids
12144
12145 l_index:= l_index +1;
12146 l_pick_rel_tab(l_index).delivery_detail_id := l_delivery_detail_id;
12147 l_pick_rel_tab(l_index).batch_id := l_batch_id;
12148
12149 IF (l_prev_batch_id IS NULL) OR l_prev_batch_id <> l_batch_id THEN
12150 IF (l_debug = 1) THEN
12151 mydebug('Got distinct batch, adding to the TABLE :'||l_batch_id);
12152 END IF;
12153 l_b_index := l_b_index +1;
12154 l_batch_id_tab(l_b_index) := l_batch_id;
12155 END IF;
12156
12157 ELSE -- means ship set or ship model exists
12158 -- check if this is the last RC status move_order line in the batch of ship set / ship model;
12159 -- If Yes, then pick release all move_orders lines in the batch
12160 -- We are postponing the support for ship set / ship model for later release ???
12161 IF (l_debug = 1) THEN
12162 mydebug('DO NOT Pick Release Demand Lines. Part OF ship Set/Model ');
12163 END IF;
12164 END IF;-- means ship set or ship model
12165 END IF; -- for IF l_repl_type = 2
12166
12167 EXIT WHEN L_REMAINING_MMTT_QTY= 0;
12168
12169 <<next_repl_demand>>
12170 l_prev_batch_id := l_batch_id;
12171 END LOOP;
12172 CLOSE c_mark_demand_rc_csr;
12173 END IF; -- for l_demand_type_id = 4
12174 END IF; -- for l_exists_in_wrd = 1
12175
12176
12177 -- Bug 9356579 call of cursor c_untracked_dmd_repl_cur so blocking the below code as it is no more reqd. Read comment given during cursor definition.
12178 /* IF (l_debug = 1) THEN
12179 mydebug('Check if REPL MOL is not tracked in WRD to replenish wdd demand Lines');
12180 END IF;
12181
12182 -- in general all records for MO line should have same value OF l_repl_level FOR a move order
12183 -- taking default l_repl_level value unless it gets overwritten by value of
12184 -- last rcord IN above loop
12185 IF (l_repl_level =1 AND (l_exists_in_wrd <> 1) OR
12186 (l_repl_level =1 AND l_exists_in_wrd = 1 AND L_REMAINING_MMTT_QTY > 0 )) THEN
12187 -- Either some remaining qty after consuming demand from WRD OR move order line is not part of WRD table
12188
12189 IF (l_debug = 1) THEN
12190 mydebug('Either MO is not part od WRD OR Qty left out exhausting qty IN wrd tracked MO Lines ');
12191 mydebug('Related Demand lines will NOT be released...');
12192 END IF;
12193
12194 BEGIN
12195 select pick_sequence_rule_id
12196 INTO l_release_sequence_rule_id
12197 from wsh_shipping_parameters
12198 where organization_id = l_org_id;
12199 EXCEPTION
12200 WHEN no_data_found THEN
12201 l_release_sequence_rule_id := NULL;
12202 END;
12203
12204 IF (l_debug = 1) THEN
12205 mydebug('PICK SEQUENCE RULE ID FOR THE ORG :'||l_release_sequence_rule_id);
12206 END IF;
12207
12208 -- Get the Order By Clause based on Pick Release Rule
12209 --initialize gloabl variables
12210 -- delete old value
12211 g_ordered_psr.DELETE;
12212 wms_replenishment_pvt.init_rules
12213 (p_pick_seq_rule_id => l_release_sequence_rule_id,
12214 x_order_id_sort => l_ORDER_ID_SORT,
12215 x_INVOICE_VALUE_SORT => l_INVOICE_VALUE_SORT,
12216 x_SCHEDULE_DATE_SORT => l_SCHEDULE_DATE_SORT,
12217 x_trip_stop_date_sort => l_TRIP_STOP_DATE_SORT,
12218 x_SHIPMENT_PRI_SORT => l_shipment_pri_sort,
12219 x_ordered_psr => g_ordered_psr,
12220 x_api_status => l_return_status );
12221
12222 IF (l_debug = 1) THEN
12223 mydebug('Status after calling init_rules'||l_return_status);
12224 END IF;
12225
12226 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
12227 IF (l_debug = 1) THEN
12228 mydebug('init_rules returned Success, Processing untracked demand lines');
12229 END IF;
12230
12231 -- Mark RC to demand lines that are part of c_untracked_dmd_repl_cur
12232 -- DO NOT PICK RELEASE THESE LINES
12233 OPEN c_untracked_dmd_repl_cur(L_DROP_LPN_ITEM_TBL(CNT).inventory_item_id);
12234 LOOP
12235 FETCH c_untracked_dmd_repl_cur INTO
12236 l_delivery_detail_id, l_demand_pri_qty, l_req_quantity_uom,
12237 l_attr1,l_attr2,l_attr3,l_attr4,l_attr5 ;
12238 EXIT WHEN c_untracked_dmd_repl_cur%NOTFOUND;
12239
12240 IF (l_debug = 1) THEN
12241 mydebug('Currently processing detail_id :'||l_delivery_detail_id);
12242 END IF;
12243
12244
12245 IF L_REMAINING_MMTT_QTY >= L_DEMAND_PRI_QTY THEN
12246 IF (l_debug = 1) THEN
12247 mydebug('MO Qty >= Demand Qty; Mark demand as RC ');
12248 END IF;
12249
12250 wms_replenishment_pvt.update_wdd_repl_status
12251 (p_deliv_detail_id => l_delivery_detail_id
12252 , p_repl_status => 'C' -- for completed status
12253 , x_return_status => l_return_status
12254 );
12255
12256 IF l_return_status <> fnd_api.g_ret_sts_success THEN
12257 IF (l_debug = 1) THEN
12258 mydebug('Errror from Delivery_Detail_Action api to mark RC...skip this demand');
12259 END IF;
12260 -- DO NOTHING, SKIP THIS DEMAND LINE
12261 GOTO next_untrkd_dmd;
12262 END IF;
12263
12264 -- Nothing in the WRD table ot start with
12265 -- Just decrease the current MMTT qty
12266 L_REMAINING_MMTT_QTY := L_REMAINING_MMTT_QTY - L_DEMAND_PRI_QTY;
12267
12268
12269 ELSE -- means mmtt qty is less than demand qty
12270 IF (l_debug = 1) THEN
12271 mydebug('MO Qty < Demand Qty; Split the demand.... ');
12272 END IF;
12273
12274 -- Split the original deamand line
12275 -- the newly created demand line will have qty =(L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY) WITH
12276 -- original status . The shipping API with 'SPLIT-LINE' action in turn calls
12277 -- the wms_replenishment_pvt.update_delivery_detail()
12278 -- API but in this case since original
12279 -- delivery_detial was NOT tracked in the WRD table
12280 -- to start with, nothing happens there. In shipping,
12281 -- we have a new split WDD though
12282
12283 -- So after calling for the split-line action, I need to call shipping
12284 -- AND mark the original delivery detail line to 'RC' and delete this WRD record
12285
12286 l_detail_id_tab.DELETE;
12287 l_action_prms := NULL;
12288 l_detail_id_tab(1) := l_delivery_detail_id;
12289 -- Caller needs to be WSH_PUB in order for shipping to allow this action
12290 l_action_prms.caller := 'WSH_PUB';
12291 l_action_prms.action_code := 'SPLIT-LINE';
12292 l_action_prms.split_quantity := (L_DEMAND_PRI_QTY - L_REMAINING_MMTT_QTY) ;
12293
12294 WSH_INTERFACE_GRP.Delivery_Detail_Action
12295 (p_api_version_number => 1.0,
12296 p_init_msg_list => fnd_api.g_false,
12297 p_commit => fnd_api.g_false,
12298 x_return_status => l_return_status,
12299 x_msg_count => x_msg_count,
12300 x_msg_data => x_msg_data,
12301 p_detail_id_tab => l_detail_id_tab,
12302 p_action_prms => l_action_prms,
12303 x_action_out_rec => l_action_out_rec
12304 );
12305
12306 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
12307 IF (l_debug = 1) THEN
12308 mydebug('Error returned from Split Delivery_Detail_Action API..skip this demand Line');
12309 END IF;
12310 -- DO NOTHING, SKIP THIS DEMAND LINE
12311 GOTO next_untrkd_dmd;
12312 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
12313 IF (l_debug = 1) THEN
12314 mydebug('Unexpected errror from Split Delivery_Detail_Action API..skip this demand Line');
12315 END IF;
12316 -- DO NOTHING, SKIP THIS DEMAND LINE
12317 GOTO next_untrkd_dmd;
12318 END IF;
12319
12320 -- At this point the new delivery is already inserted in the WRD table.
12321 -- AND the qty for original delivery has been updated
12322 -- TO l_remaining_mmtt_qty IN WRD as above api calls
12323 -- wms_replenishment_pvt.update_delivery_detail() internally.
12324 -- SO JUST MARK original delviery replenishment_status RC
12325 -- and then delete the original record from the WRD table
12326
12327 wms_replenishment_pvt.update_wdd_repl_status
12328 (p_deliv_detail_id => l_delivery_detail_id
12329 , p_repl_status => 'C' -- for completed status
12330 , x_return_status => l_return_status
12331 );
12332
12333 IF l_return_status <> fnd_api.g_ret_sts_success THEN
12334 -- DO NOTHING, SKIP THIS DEMAND LINE
12335 GOTO next_untrkd_dmd;
12336 END IF;
12337
12338 -- In this case the original delivery was NOT tracked
12339 -- in the WRD table. So no need to delete WRD
12340
12341 L_REMAINING_MMTT_QTY := 0;
12342
12343
12344 END IF; -- for L_REMAINING_MMTT_QTY => L_DEMAND_PRI_QTY
12345
12346 EXIT WHEN L_REMAINING_MMTT_QTY =0;
12347
12348 <<next_untrkd_dmd>>
12349 NULL;
12350
12351 END LOOP;
12352 CLOSE c_untracked_dmd_repl_cur;
12353
12354 ELSE --init_rules returned error
12355
12356 IF (l_debug = 1) THEN
12357 mydebug('init_rules returned Error, Can NOT mark demand lines RC');
12358 END IF ;
12359
12360 END IF; -- for init_rules returned success
12361
12362 END IF; --for IF (l_repl_level =1 AND (l_exists_in_wrd <> 1)
12363
12364 end of code-block done as a part of fix for bug 9356579*/
12365
12366
12367 END IF; -- FOR L_REMAINING_MMTT_QTY > 0
12368
12369 l_prev_mol := L_DROP_LPN_ITEM_TBL(CNT).move_order_line_id;
12370 END LOOP; -- for L_DROP_LPN_ITEM_TBL.COUNT
12371
12372 IF (l_debug = 1) THEN
12373 mydebug('Calling process_remaining_wdds_repl for last MO '||l_curr_move_order_line_id); --BUG14014540
12374 END IF;
12375 process_remaining_wdds_repl(l_curr_move_order_line_id, p_org_id); --BUG14014540
12376 END IF; -- l_task_type = 4
12377 -- R12.1 replenishment Project 6681109 ENDS -----
12378 --===================================================
12379
12380
12381 -- VARAJAGO for bug 5222498, getting the grup_mark_id for the serial_number from temp table
12382 -- and update MSN.
12383 IF l_tran_type_id = 2 AND l_tran_action_id = 2 AND l_tran_source_type_id = 13
12384 AND l_lpn_context = 11 THEN -- only for staging move tranasction
12385 mydebug('pick_drop: INSIDE IF');
12386 FOR rec_child_lpns_csr IN child_lpns_csr LOOP -- for the Nested LPNs.
12387 mydebug('pick_drop: INSIDE FOR rec_child_lpns_csr : ' || rec_child_lpns_csr.lpn_id);
12388 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
12389 mydebug('pick_drop: INSIDE FOR rec_msn_stg_mov_csr');
12390 IF (l_debug = 1) THEN
12391 mydebug('pick_drop: serial_number :' || rec_msn_stg_mov_csr.serial_number);
12392 mydebug('pick_drop: group_mark_id :' || rec_msn_stg_mov_csr.transaction_temp_id);
12393 mydebug('pick_drop: lpn_id :' || rec_msn_stg_mov_csr.lpn_id);
12394 END IF;
12395
12396 UPDATE mtl_serial_numbers
12397 SET mtl_serial_numbers.group_mark_id = rec_msn_stg_mov_csr.transaction_temp_id
12398 WHERE mtl_serial_numbers.serial_number = rec_msn_stg_mov_csr.serial_number
12399 AND mtl_serial_numbers.current_organization_id = rec_msn_stg_mov_csr.organization_id
12400 AND mtl_serial_numbers.inventory_item_id = rec_msn_stg_mov_csr.inventory_item_id
12401 AND mtl_serial_numbers.lpn_id = rec_msn_stg_mov_csr.lpn_id;
12402
12403 END LOOP;
12404
12405 END LOOP;
12406
12407 END IF;
12408 -- End of changes for 5222498
12409 --12595055 adding for LPN context remains packing context when dropped to non lpn controlled sub after lot substitution..
12410 IF (l_is_transfer_sub_lpn = 2 AND l_tran_action_id = 2 AND l_tran_source_type_id IN(4, 13)) THEN
12411 SELECT count(transaction_temp_id)
12412 INTO l_check_tasks
12413 FROM mtl_material_transactions_temp mmtt
12414 WHERE transfer_lpn_id = l_transfer_lpn_id
12415 AND transaction_temp_id <> l_temp_id ;
12416 IF l_check_tasks = 0 THEN
12417 l_lpn_context := wms_container_pub.LPN_CONTEXT_PREGENERATED;
12418 ELSE
12419 l_lpn_context := wms_container_pub.LPN_CONTEXT_PACKING;
12420 END IF;
12421 END IF;
12422 --12595055 End
12423
12424 IF (l_debug = 1) THEN
12425 mydebug('pick_drop: call to modify_lpn_wrapper with lpn_context of ' || l_lpn_context);
12426 mydebug('coming to my debug to print the value of l_check_tasks ' || l_check_tasks);
12427 mydebug('coming to my debug to print the value of l_temp_id ' || l_temp_id);
12428 mydebug('coming to my debug to print the value of l_transfer_lpn_id ' || l_transfer_lpn_id);
12429 END IF;
12430
12431 -- Bug 4238917 no longer update lpn_context to 11 outside of TM
12432 IF ( l_lpn_context <> wms_container_pub.lpn_context_picked ) THEN
12433 wms_container_pub.modify_lpn_wrapper
12434 ( p_api_version => 1.0
12435 , x_return_status => l_return_status
12436 , x_msg_count => l_msg_count
12437 , x_msg_data => l_msg_data
12438 , p_lpn_id => l_xfrlpnid
12439 , p_lpn_context => l_lpn_context
12440 );
12441
12442 IF l_return_status = fnd_api.g_ret_sts_success AND l_lpn_context = 5 THEN -- 14372784
12443 mydebug('Modified LPN Context :' || l_lpn_context);
12444 mydebug('DELETING WLC FOR LPN_ID : '||l_xfrlpnid);
12445 DELETE FROM wms_lpn_contents WHERE parent_lpn_id = l_xfrlpnid;
12446 END IF;
12447
12448 -- Added for bug 12853197
12449 IF l_update_frm_lpn=TRUE THEN
12450
12451 IF ( l_from_lpn_context <> wms_container_pub.lpn_context_picked ) THEN
12452 wms_container_pub.modify_lpn_wrapper
12453 ( p_api_version => 1.0
12454 , x_return_status => l_return_status
12455 , x_msg_count => l_msg_count
12456 , x_msg_data => l_msg_data
12457 , p_lpn_id => l_transfer_lpn_id
12458 , p_lpn_context => l_from_lpn_context
12459
12460 );
12461
12462 IF l_return_status = fnd_api.g_ret_sts_success AND l_from_lpn_context = 5 THEN -- 14372784
12463 mydebug('Modified From_LPN Context :' || l_from_lpn_context);
12464 mydebug('DELETING WLC FOR FROM_LPN_ID : '||l_transfer_lpn_id);
12465 DELETE FROM wms_lpn_contents WHERE parent_lpn_id = l_transfer_lpn_id;
12466 END IF;
12467
12468
12469 ELSE
12470 /*Bug#6677616. For picked LPN, we will call the below API inorder to update shipping
12471 about the weight, volume etc of LPN so that it gets reflected in shipping tables.*/
12472 wms_container_pub.modify_lpn_wrapper
12473 ( p_api_version => 1.0
12474 , x_return_status => l_return_status
12475 , x_msg_count => l_msg_count
12476 , x_msg_data => l_msg_data
12477 , p_lpn_id => l_transfer_lpn_id
12478 );
12479 END IF;
12480
12481 END IF;
12482 ELSE
12483 /*Bug#6712364. For picked LPN, we will call the below API(wihout hcnaging anything) inorder to
12484 update shipping about the weight, volume etc of LPN so that it gets reflected in shipping tables.*/
12485 wms_container_pub.modify_lpn_wrapper
12486 ( p_api_version => 1.0
12487 , x_return_status => l_return_status
12488 , x_msg_count => l_msg_count
12489 , x_msg_data => l_msg_data
12490 , p_lpn_id => l_xfrlpnid
12491 );
12492 END IF;
12493
12494 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
12495 IF (l_debug = 1) THEN
12496 mydebug('pick_drop: modify_lpn_wrapper Unexpected error');
12497 END IF;
12498
12499 fnd_msg_pub.ADD;
12500 RAISE fnd_api.g_exc_unexpected_error;
12501 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
12502 IF (l_debug = 1) THEN
12503 mydebug('pick_drop: modify_lpn_wrapper error');
12504 END IF;
12505
12506 fnd_msg_pub.ADD;
12507 RAISE fnd_api.g_exc_error;
12508 END IF;
12509
12510 -- Bug 4238917 no longer update lpn_context to 11 outside of TM
12511 /*
12512 -- IF droplpngenerated and lpn_context = PICKED then update the
12513 -- lpn_context of the from_lpn also.
12514 IF l_isdroplpnentered = TRUE THEN
12515 IF l_lpn_context = wms_container_pub.lpn_context_picked THEN
12516 wms_container_pub.modify_lpn_wrapper(
12517 p_api_version => 1.0
12518 , x_return_status => l_return_status
12519 , x_msg_count => l_msg_count
12520 , x_msg_data => l_msg_data
12521 , p_lpn_id => p_from_lpn_id
12522 , p_lpn_context => l_lpn_context
12523 );
12524 END IF;
12525 END IF; */
12526 --END IF;
12527
12528 -- Release 12 Shipping Content Enhancement 4645826
12529 -- For Pick Drop, call label printing after TM,
12530 IF (l_debug = 1) THEN
12531 mydebug('Pick Drop, calling label printing API with l_lpn_id '||nvl(l_xfrlpnid,nvl(l_transfer_lpn_id, l_content_lpn_id)));
12532 END IF;
12533 IF l_flow = inv_label.wms_bf_pick_drop THEN
12534 INV_LABEL.PRINT_LABEL_MANUAL_WRAP(
12535 x_return_status => l_return_status
12536 , x_msg_count => l_msg_count
12537 , x_msg_data => l_msg_data
12538 , x_label_status => l_label_status
12539 , p_business_flow_code => l_flow
12540 , p_lpn_id => nvl(l_xfrlpnid,nvl(l_transfer_lpn_id, l_content_lpn_id))
12541 );
12542 END IF;
12543 -- End 4645826
12544
12545 IF p_commit = 'Y'
12546 THEN
12547 COMMIT;
12548 END IF;
12549
12550 --===================================================
12551 -- R12.1 replenishment Project 6681109 STARTS -----
12552
12553 -- WE NEED TO COMMIT ONCE SO THAT PICK RELEASE CONCURRENT PROGRAM BELOW
12554 -- CAN SEE MOVED MATERIAL FOR DROPPED TASKS.
12555 IF l_txn_ret = 0 AND l_task_type = 4 THEN -- replenishment drop task
12556
12557 IF (l_debug = 1) THEN
12558 mydebug('Processing Pick Release of Dmd Lines in batch...');
12559 mydebug('Number of batch_ids processed togather :'||l_batch_id_tab.count());
12560 END IF;
12561
12562 -- Call the Pick release per batch_id
12563 -- l_batch_id_tab stores only UNIQUE batch_id
12564 -- l_pick_rel_tab stores unique delivery_detail_id with respective batch_id
12565
12566 FOR i IN 1 .. l_batch_id_tab.count() LOOP
12567 l_detail_id_tab.DELETE;
12568 l_action_prms := NULL;
12569 l_cnt := 0;
12570 IF (l_debug = 1) THEN
12571 mydebug('****** Calling Pick Release with Batch_id :' ||l_batch_id_tab(i));
12572 mydebug('****** The number of unique WDDs is :' ||l_pick_rel_tab.count());
12573 END IF;
12574
12575 <<inner>>
12576 FOR j IN 1 .. l_pick_rel_tab.count() LOOP
12577 IF l_batch_id_tab(i) = l_pick_rel_tab(j).batch_id THEN
12578 l_cnt := l_cnt +1;
12579 l_detail_id_tab(l_cnt) := l_pick_rel_tab(j).delivery_detail_id;
12580 IF (l_debug = 1) THEN
12581 mydebug('The l_detail_id_tab.l_cnt id stored is ' ||l_detail_id_tab(l_cnt));
12582 mydebug('Value of l_cnt is ' ||l_cnt);
12583 mydebug('The WDD id stored is ' ||l_pick_rel_tab(j).delivery_detail_id);
12584 END IF;
12585 END IF;
12586 EXIT inner WHEN l_pick_rel_tab(j).batch_id > l_batch_id_tab(i);
12587 -- Since inserted records has alredy been ordered by batch_id
12588 END LOOP;
12589
12590 -- Call the pick release with l_batch_id_tab(i) AND l_detail_id_tab
12591 IF (l_debug = 1) THEN
12592 mydebug('Number of delivery details in this batch :'||l_detail_id_tab.COUNT());
12593 END IF;
12594
12595 l_action_prms.caller := 'WSH_PUB';
12596 l_action_prms.batch_id := l_batch_id_tab(i);
12597 l_action_prms.action_code := 'PICK-RELEASE';
12598
12599 WSH_INTERFACE_GRP.Delivery_Detail_Action
12600 (p_api_version_number => 1.0,
12601 p_init_msg_list => fnd_api.g_false,
12602 p_commit => fnd_api.g_false,
12603 x_return_status => l_return_status,
12604 x_msg_count => x_msg_count,
12605 x_msg_data => x_msg_data,
12606 p_detail_id_tab => l_detail_id_tab,
12607 p_action_prms => l_action_prms,
12608 x_action_out_rec => l_action_out_rec
12609 );
12610
12611 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
12612 IF (l_debug = 1) THEN
12613 mydebug('Error from Split Delivery_Detail_Action API..nothing TO be done');
12614 END IF;
12615 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
12616 IF (l_debug = 1) THEN
12617 mydebug('Unexpected error Split Delivery_Detail_Action API....nothing TO be done');
12618 END IF;
12619 END IF;
12620
12621 END LOOP;
12622
12623 --clear tables
12624 l_batch_id_tab.DELETE;
12625 l_pick_rel_tab.DELETE;
12626
12627 IF (l_debug = 1) THEN
12628 mydebug('AFTER Calling Repl Pick Release (in Batch) Status :'||l_return_status );
12629 END IF;
12630
12631 END IF; -- IF l_txn_ret = 0 AND l_task_type = 4
12632
12633
12634 IF p_commit = 'Y'
12635 THEN
12636 COMMIT;
12637 END IF;
12638 -- R12.1 replenishment Project 6681109 ENDS -----
12639 --===================================================
12640
12641
12642 x_return_status := fnd_api.g_ret_sts_success;
12643
12644 IF (l_debug = 1) THEN
12645 mydebug('pick_drop: done WITH Pick Drop API');
12646 END IF;
12647 EXCEPTION
12648 WHEN fnd_api.g_exc_error THEN
12649 x_return_status := fnd_api.g_ret_sts_error;
12650
12651 IF (l_debug = 1) THEN
12652 mydebug('pick_drop: Error in pick_drop API: ' || SQLERRM);
12653 END IF;
12654
12655 fnd_message.set_name('WMS', 'WMS_TD_PICK_DROP_FAIL');
12656 fnd_msg_pub.ADD;
12657 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12658 WHEN OTHERS THEN
12659 x_return_status := fnd_api.g_ret_sts_error;
12660
12661 IF (l_debug = 1) THEN
12662 mydebug('pick_drop: Unexpected Error in pick_drop API: ' || SQLERRM);
12663 END IF;
12664
12665 fnd_message.set_name('WMS', 'WMS_TD_PICK_DROP_FAIL');
12666 fnd_msg_pub.ADD;
12667 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12668 END pick_drop;
12669
12670 PROCEDURE pick_by_label(
12671 p_sign_on_emp_id IN NUMBER
12672 , p_sign_on_org_id IN NUMBER
12673 , p_sign_on_zone IN VARCHAR2
12674 , p_sign_on_equipment_id IN NUMBER
12675 , p_sign_on_equipment_srl IN VARCHAR2
12676 , p_task_type IN VARCHAR2
12677 , x_nbr_tasks OUT NOCOPY NUMBER
12678 , p_lpn_id IN NUMBER
12679 , x_return_status OUT NOCOPY VARCHAR2
12680 , x_msg_count OUT NOCOPY NUMBER
12681 , x_msg_data OUT NOCOPY VARCHAR2
12682 ) IS
12683 l_cartonization_id NUMBER := NULL;
12684 task_rec wms_task_dispatch_gen.task_rec_tp;
12685 l_task_cur wms_task_dispatch_gen.task_rec_cur_tp;
12686 l_user_id NUMBER;
12687 l_emp_id NUMBER;
12688 l_org_id NUMBER;
12689 l_zone VARCHAR2(10);
12690 l_eqp_id NUMBER;
12691 l_eqp_ins VARCHAR2(30);
12692 l_task_type VARCHAR2(30);
12693 l_c_rows NUMBER;
12694 l_next_task_id NUMBER;
12695 l_per_res_id NUMBER;
12696 l_mac_res_id NUMBER;
12697 l_std_op_id NUMBER;
12698 l_operation_plan_id NUMBER;
12699 l_move_order_line_id NUMBER;
12700 l_priority NUMBER;
12701 l_wms_task_type NUMBER;
12702 l_msg_count NUMBER;
12703 l_msg_data VARCHAR2(4000);
12704 l_return_status VARCHAR2(1);
12705 l_lpn_id NUMBER;
12706 l_mmtt_rowcnt NUMBER;
12707 l_wdt_rowcnt NUMBER;
12708 l_undispatched_picks NUMBER;
12709 l_txn_hdr_id NUMBER;
12710 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12711 BEGIN
12712 IF (l_debug = 1) THEN
12713 mydebug('pick_by_label: In Pick By Label API');
12714 END IF;
12715
12716 l_return_status := fnd_api.g_ret_sts_success;
12717 l_user_id := p_sign_on_emp_id;
12718 l_org_id := p_sign_on_org_id;
12719 l_zone := p_sign_on_zone;
12720 l_eqp_id := p_sign_on_equipment_id;
12721 l_eqp_ins := p_sign_on_equipment_srl;
12722 l_task_type := p_task_type;
12723 l_c_rows := 0;
12724 l_next_task_id := 0;
12725 l_std_op_id := 1;
12726 l_priority := 1;
12727 l_wms_task_type := 1;
12728 l_lpn_id := p_lpn_id;
12729
12730 IF (l_debug = 1) THEN
12731 mydebug('pick_by_label: get employee id');
12732 END IF;
12733
12734 l_emp_id := l_user_id;
12735
12736 IF (l_debug = 1) THEN
12737 mydebug('pick_by_label: emp id:' || l_emp_id);
12738 END IF;
12739
12740 l_mmtt_rowcnt := 0;
12741 l_wdt_rowcnt := 0;
12742
12743 IF l_eqp_id = -999 THEN
12744 l_eqp_id := NULL;
12745 END IF;
12746
12747 IF l_lpn_id = 0 THEN
12748 l_lpn_id := NULL;
12749 END IF;
12750
12751 IF (l_debug = 1) THEN
12752 mydebug('pick_by_label: Getting undispatched MMTT rows for this lpn..');
12753 END IF;
12754
12755 SELECT COUNT(*)
12756 INTO l_mmtt_rowcnt
12757 FROM mtl_material_transactions_temp m
12758 WHERE m.cartonization_id IS NOT NULL
12759 AND m.cartonization_id = l_lpn_id
12760 AND parent_line_id IS NULL;
12761
12762 IF (l_debug = 1) THEN
12763 mydebug('pick_by_label: MMTT rows' || l_mmtt_rowcnt);
12764 END IF;
12765
12766 IF l_mmtt_rowcnt > 0 THEN
12767 -- There are MMTT tasks for this LPN
12768 SELECT COUNT(*)
12769 INTO l_wdt_rowcnt
12770 FROM mtl_material_transactions_temp m, wms_dispatched_tasks t
12771 WHERE m.cartonization_id = l_lpn_id
12772 AND t.transaction_temp_id = m.transaction_temp_id
12773 AND t.status = 4;
12774
12775 IF (l_debug = 1) THEN
12776 mydebug('pick_by_label: WDT rows' || l_wdt_rowcnt);
12777 END IF;
12778
12779 l_undispatched_picks := l_mmtt_rowcnt - l_wdt_rowcnt;
12780
12781 IF (l_debug = 1) THEN
12782 mydebug('pick_by_label: Undispatched Picks' || l_undispatched_picks);
12783 END IF;
12784
12785 IF l_undispatched_picks > 0 THEN
12786 -- There are undispatched picks!
12787
12788 -- Need to call the TD engine here primarily to ensure user
12789 -- is eligible for task
12790
12791
12792
12793 IF (l_debug = 1) THEN
12794 mydebug('pick_by_label: Before Calling TD Engine');
12795 END IF;
12796
12797 IF l_lpn_id = fnd_api.g_miss_num THEN
12798 l_lpn_id := NULL;
12799 END IF;
12800
12801 --TEST have TO change eqpid to not null later
12802 --Call Lei's TD Engine
12803 wms_task_dispatch_engine.dispatch_task(
12804 p_api_version => 1.0
12805 , p_init_msg_list => 'F'
12806 , p_commit => NULL
12807 , p_sign_on_emp_id => l_emp_id
12808 , p_sign_on_org_id => l_org_id
12809 , p_sign_on_zone => l_zone
12810 , p_sign_on_equipment_id => l_eqp_id
12811 , p_sign_on_equipment_srl => l_eqp_ins
12812 , p_task_type => 'ALL'
12813 , x_task_cur => l_task_cur
12814 , x_return_status => l_return_status
12815 , x_msg_count => l_msg_count
12816 , x_msg_data => l_msg_data
12817 , p_cartonization_id => l_lpn_id
12818 );
12819
12820 IF (l_debug = 1) THEN
12821 mydebug('pick_by_label: Ret Stst11' || l_return_status);
12822 END IF;
12823
12824 IF l_return_status = fnd_api.g_ret_sts_success THEN
12825 LOOP
12826 FETCH l_task_cur INTO task_rec;
12827 EXIT WHEN l_task_cur%NOTFOUND;
12828 l_c_rows := l_c_rows + 1;
12829
12830 IF (l_debug = 1) THEN
12831 mydebug('pick_by_label: TaskID:' || task_rec.task_id);
12832 END IF;
12833
12834 IF (l_debug = 1) THEN
12835 mydebug('pick_by_label: getting Resource ID....');
12836 END IF;
12837
12838 SELECT bremp.resource_id role_id
12839 , t.wms_task_type
12840 , t.standard_operation_id
12841 , t.operation_plan_id
12842 , t.move_order_line_id
12843 INTO l_per_res_id
12844 , l_wms_task_type
12845 , l_std_op_id
12846 , l_operation_plan_id
12847 , l_move_order_line_id
12848 FROM mtl_material_transactions_temp t, bom_std_op_resources bsor, bom_resources bremp
12849 WHERE t.transaction_temp_id = task_rec.task_id
12850 AND t.standard_operation_id = bsor.standard_operation_id
12851 AND bsor.resource_id = bremp.resource_id
12852 AND bremp.resource_type = 2
12853 AND ROWNUM < 2;
12854
12855 IF (l_debug = 1) THEN
12856 mydebug('pick_by_label: After getting Resource ID....');
12857 END IF;
12858
12859 IF l_eqp_id IS NOT NULL THEN
12860 -- bug fix 1772907, lezhang
12861
12862 SELECT resource_id
12863 INTO l_mac_res_id
12864 FROM bom_resource_equipments
12865 WHERE inventory_item_id = l_eqp_id
12866 AND ROWNUM < 2;
12867 /*
12868 select breqp.resource_id equip_type_id
12869 INTO l_mac_res_id
12870 from mtl_material_transactions_temp t,
12871 bom_std_op_resources bsor,
12872 bom_resources breqp
12873 where t.transaction_temp_id = task_rec.task_id
12874 and t.standard_operation_id = bsor.standard_operation_id
12875 and bsor.resource_id = breqp.resource_id
12876 and breqp.resource_type = 1
12877 and rownum<2;
12878 */
12879 END IF;
12880
12881 SELECT mtl_material_transactions_s.NEXTVAL txnhdrid
12882 INTO l_txn_hdr_id
12883 FROM DUAL;
12884
12885 UPDATE mtl_material_transactions_temp
12886 SET transaction_header_id = l_txn_hdr_id
12887 WHERE transaction_temp_id = task_rec.task_id;
12888
12889 -- Insert into WMS_DISPATCHED_TASKS for this user
12890
12891 --Get value from sequence for next task id
12892 SELECT wms_dispatched_tasks_s.NEXTVAL
12893 INTO l_next_task_id
12894 FROM DUAL;
12895
12896 --mydebug('pick_by_label: Before Insert into WMSDT');
12897
12898
12899 INSERT INTO wms_dispatched_tasks
12900 (
12901 task_id
12902 , transaction_temp_id
12903 , organization_id
12904 , user_task_type
12905 , person_id
12906 , effective_start_date
12907 , effective_end_date
12908 , equipment_id
12909 , equipment_instance
12910 , person_resource_id
12911 , machine_resource_id
12912 , status
12913 , dispatched_time
12914 , last_update_date
12915 , last_updated_by
12916 , creation_date
12917 , created_by
12918 , task_type
12919 , priority
12920 , operation_plan_id
12921 , move_order_line_id
12922 )
12923 VALUES (
12924 l_next_task_id
12925 , task_rec.task_id
12926 , l_org_id
12927 , NVL(l_std_op_id, 2)
12928 , l_user_id
12929 , SYSDATE
12930 , SYSDATE
12931 , l_eqp_id
12932 , l_eqp_ins
12933 , l_per_res_id
12934 , l_mac_res_id
12935 , 3
12936 , SYSDATE
12937 , SYSDATE
12938 , l_emp_id
12939 , SYSDATE
12940 , l_emp_id
12941 , l_wms_task_type
12942 , task_rec.task_priority
12943 , l_operation_plan_id
12944 , l_move_order_line_id
12945 );
12946
12947 IF (l_debug = 1) THEN
12948 mydebug('pick_by_label: After Insert into WMSDT');
12949 END IF;
12950 /* BUG3209582 Pick By Label should dispatch all the tasks belonging to the
12951 Cartonized LPN to the same user else all the tasks are not dispatched to
12952 user continuously
12953 -- If LPN has been provided, exit, since we only want the first
12954 --task
12955 IF l_lpn_id IS NULL
12956 OR l_lpn_id = fnd_api.g_miss_num THEN
12957 IF (l_debug = 1) THEN
12958 mydebug('pick_by_label: LPN was not provided');
12959 END IF;
12960 ELSE
12961 IF (l_debug = 1) THEN
12962 mydebug('pick_by_label: LPN was provided - pick by label');
12963 END IF;
12964
12965 -- Setting nbr of tasks
12966 x_nbr_tasks := l_undispatched_picks;
12967 EXIT;
12968 END IF; */
12969 END LOOP;
12970 x_nbr_tasks := l_undispatched_picks;--bug3209582
12971
12972 -- Committing these tasks to this user
12973 IF (l_debug = 1) THEN
12974 mydebug('pick_by_label: before commiting');
12975 END IF;
12976
12977 COMMIT;
12978 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
12979 fnd_message.set_name('WMS', 'WMS_TD_TDENG_ERROR');
12980 fnd_msg_pub.ADD;
12981 RAISE fnd_api.g_exc_unexpected_error;
12982 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
12983 IF (l_debug = 1) THEN
12984 mydebug('pick_by_label: Setting status to S');
12985 END IF;
12986
12987 l_return_status := fnd_api.g_ret_sts_success;
12988
12989 -- TD Engine brought back 0 tasks.
12990 -- Since there are undispatched tasks for this LPN,
12991 -- it means that this user is not eligible for this task
12992 IF (l_debug = 1) THEN
12993 mydebug('pick_by_label: Ineligible USer');
12994 END IF;
12995
12996 x_nbr_tasks := -1;
12997 END IF;
12998 ELSE
12999 -- There are no undipatched tasks, hence user can drop off the task
13000 x_nbr_tasks := 0;
13001 END IF; -- l_undispatched_picks>0 end if
13002 ELSE -- l_mmtt_rowcnt>0 if
13003 IF (l_debug = 1) THEN
13004 mydebug('pick_by_label: There are no mmtt rows for this LPN');
13005 END IF;
13006
13007 x_nbr_tasks := -1;
13008 END IF;
13009
13010 x_return_status := fnd_api.g_ret_sts_success;
13011 EXCEPTION
13012 WHEN fnd_api.g_exc_error THEN
13013 x_return_status := fnd_api.g_ret_sts_error;
13014 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13015 WHEN OTHERS THEN
13016 x_return_status := fnd_api.g_ret_sts_unexp_error;
13017 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13018 END pick_by_label;
13019
13020 PROCEDURE manual_pick(
13021 p_sign_on_emp_id IN NUMBER
13022 , p_sign_on_org_id IN NUMBER
13023 , p_sign_on_zone IN VARCHAR2 := NULL
13024 , p_sign_on_equipment_id IN NUMBER := NULL
13025 , p_sign_on_equipment_srl IN VARCHAR2 := NULL
13026 , p_task_type IN VARCHAR2 := 'PICKING'
13027 , p_pick_slip_id IN NUMBER
13028 , x_return_status OUT NOCOPY VARCHAR2
13029 , x_msg_count OUT NOCOPY NUMBER
13030 , x_msg_data OUT NOCOPY VARCHAR2
13031 ) IS
13032 task_rec wms_task_dispatch_gen.task_rec_tp;
13033 l_task_cur wms_task_dispatch_gen.task_rec_cur_tp;
13034 l_user_id NUMBER;
13035 l_emp_id NUMBER;
13036 l_org_id NUMBER;
13037 l_zone VARCHAR2(10);
13038 l_eqp_id NUMBER;
13039 l_eqp_ins VARCHAR2(30);
13040 l_task_type VARCHAR2(30);
13041 l_c_rows NUMBER;
13042 l_next_task_id NUMBER;
13043 l_per_res_id NUMBER;
13044 l_mac_res_id NUMBER;
13045 l_std_op_id NUMBER;
13046 l_operation_plan_id NUMBER;
13047 l_move_order_line_id NUMBER;
13048 l_priority NUMBER;
13049 l_wms_task_type NUMBER;
13050 l_msg_count NUMBER;
13051 l_msg_data VARCHAR2(4000);
13052 l_return_status VARCHAR2(1);
13053 l_pick_slip_id NUMBER;
13054 l_mmtt_rowcnt NUMBER;
13055 l_wdt_rowcnt NUMBER;
13056 l_undispatched_picks NUMBER;
13057 l_txn_hdr_id NUMBER;
13058 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13059
13060 /*6009436 Begin */
13061 CURSOR c_fm_to_serial_number IS
13062 SELECT
13063 msnt.fm_serial_number,
13064 msnt.to_serial_number
13065 FROM mtl_serial_numbers_temp msnt
13066 WHERE msnt.transaction_temp_id = p_pick_slip_id;
13067
13068 CURSOR c_fm_to_lot_serial_number IS
13069 SELECT
13070 msnt.fm_serial_number,
13071 msnt.to_serial_number
13072 FROM
13073 mtl_serial_numbers_temp msnt,
13074 mtl_transaction_lots_temp mtlt
13075 WHERE mtlt.transaction_temp_id = p_pick_slip_id
13076 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
13077
13078 l_item_id NUMBER := NULL;
13079 l_serial_ctrl_code NUMBER;
13080 l_lot_ctrl_code NUMBER ;
13081 l_fm_serial_number MTL_SERIAL_NUMBERS_TEMP.FM_SERIAL_NUMBER%TYPE;
13082 l_to_serial_number MTL_SERIAL_NUMBERS_TEMP.TO_SERIAL_NUMBER%TYPE;
13083 /*6009436 End */
13084
13085 BEGIN
13086 IF (l_debug = 1) THEN
13087 mydebug('manual_pick: In Manual Pick API');
13088 END IF;
13089
13090 l_return_status := fnd_api.g_ret_sts_success;
13091 l_user_id := p_sign_on_emp_id;
13092 l_org_id := p_sign_on_org_id;
13093 l_zone := p_sign_on_zone;
13094 l_eqp_id := p_sign_on_equipment_id;
13095 l_eqp_ins := p_sign_on_equipment_srl;
13096 l_task_type := p_task_type;
13097 l_c_rows := 0;
13098 l_next_task_id := 0;
13099 l_std_op_id := 1;
13100 l_priority := 1;
13101 l_wms_task_type := 1;
13102 l_pick_slip_id := p_pick_slip_id;
13103
13104 IF (l_debug = 1) THEN
13105 mydebug('manual_pick: get employee id');
13106 END IF;
13107
13108 l_emp_id := l_user_id;
13109
13110 IF (l_debug = 1) THEN
13111 mydebug('manual_pick: emp id:' || l_emp_id);
13112 END IF;
13113
13114 l_mmtt_rowcnt := 0;
13115 l_wdt_rowcnt := 0;
13116
13117 IF l_eqp_id = -999 THEN
13118 l_eqp_id := NULL;
13119 END IF;
13120
13121 IF (l_debug = 1) THEN
13122 mydebug('manual_pick: Getting MMTT rows for this pick_Slip_id..');
13123 END IF;
13124
13125 -- bug 2729509 :Restricting the user not to load the child task
13126 -- which are merged using bulk pick. Added the condition parent_line_id
13127 -- not null for the same.
13128
13129 BEGIN
13130 SELECT 1
13131 INTO l_mmtt_rowcnt
13132 FROM DUAL
13133 WHERE EXISTS(SELECT 1
13134 FROM mtl_material_transactions_temp
13135 WHERE transaction_temp_id = l_pick_slip_id
13136 AND parent_line_id is NULL);
13137 EXCEPTION
13138 WHEN NO_DATA_FOUND THEN
13139 IF (l_debug = 1) THEN
13140 mydebug('manual_pick: No mmtt rows found for pick slip' || l_pick_slip_id);
13141 END IF;
13142
13143 l_mmtt_rowcnt := 0;
13144 fnd_message.set_name('WMS', 'WMS_INVALID_PICKID');
13145 fnd_msg_pub.ADD;
13146 RAISE fnd_api.g_exc_error;
13147 END;
13148
13149 IF (l_debug = 1) THEN
13150 mydebug('manual_pick: MMTT rows' || l_mmtt_rowcnt);
13151 END IF;
13152
13153 IF l_mmtt_rowcnt > 0 THEN
13154 -- Check if this line has been sent to somebody else
13155
13156 BEGIN
13157 SELECT 1
13158 INTO l_wdt_rowcnt
13159 FROM DUAL
13160 WHERE EXISTS(SELECT 1
13161 FROM wms_dispatched_tasks t
13162 WHERE t.transaction_temp_id = l_pick_slip_id);
13163 EXCEPTION
13164 WHEN NO_DATA_FOUND THEN
13165 l_wdt_rowcnt := 0;
13166 END;
13167
13168 IF l_wdt_rowcnt > 0 THEN
13169 IF (l_debug = 1) THEN
13170 mydebug('manual_pick: WDT rows' || l_wdt_rowcnt);
13171 mydebug('manual_pick: Task has been assigned to somebody else');
13172 END IF;
13173
13174 fnd_message.set_name('WMS', 'WMS_TASK_UNAVAIL');
13175 fnd_msg_pub.ADD;
13176 RAISE fnd_api.g_exc_error;
13177 ELSE
13178 IF (l_debug = 1) THEN
13179 mydebug('manual_pick: getting Resource ID....');
13180 END IF;
13181
13182 BEGIN
13183 SELECT bremp.resource_id role_id
13184 , t.wms_task_type
13185 , t.standard_operation_id
13186 , t.operation_plan_id
13187 , t.move_order_line_id
13188 , t.inventory_item_id --Bug#6009436
13189 INTO l_per_res_id
13190 , l_wms_task_type
13191 , l_std_op_id
13192 , l_operation_plan_id
13193 , l_move_order_line_id
13194 , l_item_id --Bug6009436
13195 FROM mtl_material_transactions_temp t, bom_std_op_resources bsor, bom_resources bremp
13196 WHERE t.transaction_temp_id = l_pick_slip_id
13197 AND t.standard_operation_id = bsor.standard_operation_id
13198 AND bsor.resource_id = bremp.resource_id
13199 AND bremp.resource_type = 2
13200 AND t.organization_id = l_org_id --Bug # 3704626
13201 AND ROWNUM < 2;
13202
13203 IF (l_debug = 1) THEN
13204 mydebug('manual_pick: After getting Resource ID....');
13205 END IF;
13206 EXCEPTION
13207 WHEN NO_DATA_FOUND THEN
13208 IF (l_debug = 1) THEN
13209 mydebug('manual_pick: No Person Resource ID found');
13210 END IF;
13211
13212 RAISE fnd_api.g_exc_error;
13213 END;
13214
13215 IF l_eqp_id IS NOT NULL THEN
13216 BEGIN
13217 -- bug fix 1772907, lezhang
13218
13219 SELECT resource_id
13220 INTO l_mac_res_id
13221 FROM bom_resource_equipments
13222 WHERE inventory_item_id = l_eqp_id
13223 AND ROWNUM < 2;
13224 /*
13225 select breqp.resource_id equip_type_id
13226 INTO l_mac_res_id
13227 from mtl_material_transactions_temp t,
13228 bom_std_op_resources bsor,
13229 bom_resources breqp
13230 where t.transaction_temp_id = task_rec.task_id
13231 and t.standard_operation_id = bsor.standard_operation_id
13232 and bsor.resource_id = breqp.resource_id
13233 and breqp.resource_type = 1
13234 and rownum<2;
13235 */
13236 EXCEPTION
13237 WHEN NO_DATA_FOUND THEN
13238 IF (l_debug = 1) THEN
13239 mydebug('manual_pick: No Machine Resource ID found');
13240 END IF;
13241
13242 RAISE fnd_api.g_exc_error;
13243 END;
13244 END IF;
13245
13246 -- Insert into WMS_DISPATCHED_TASKS for this user
13247
13248 --Get value from sequence for next task id
13249 SELECT wms_dispatched_tasks_s.NEXTVAL
13250 INTO l_next_task_id
13251 FROM DUAL;
13252
13253 --mydebug('manual_pick: Before Insert into WMSDT');
13254
13255 SELECT mtl_material_transactions_s.NEXTVAL txnhdrid
13256 INTO l_txn_hdr_id
13257 FROM DUAL;
13258
13259 UPDATE mtl_material_transactions_temp
13260 SET transaction_header_id = l_txn_hdr_id
13261 WHERE transaction_temp_id = l_pick_slip_id;
13262
13263 --Bug6009436.Begin
13264 SELECT msi.serial_number_control_code
13265 , msi.lot_control_code
13266 INTO l_serial_ctrl_code
13267 , l_lot_ctrl_code
13268 FROM mtl_system_items msi
13269 WHERE msi.inventory_item_id = l_item_id
13270 AND msi.organization_id =p_sign_on_org_id ;
13271
13272 IF (l_debug = 1) THEN
13273 mydebug('manual_pick:serial control code:'||l_serial_ctrl_code || ',lot control code :'||l_lot_ctrl_code);
13274 END IF;
13275
13276 IF (l_serial_ctrl_code NOT IN (1,6) ) THEN --Serial controlled item
13277 BEGIN
13278 IF (l_lot_ctrl_code > 1 ) THEN --Serial and lot controlled item
13279 OPEN c_fm_to_lot_serial_number;
13280 LOOP
13281 FETCH c_fm_to_lot_serial_number
13282 INTO l_fm_serial_number,l_to_serial_number;
13283 EXIT WHEN c_fm_to_lot_serial_number%NOTFOUND;
13284
13285 UPDATE MTL_SERIAL_NUMBERS msn
13286 SET GROUP_MARK_ID=l_txn_hdr_id
13287 WHERE msn.current_organization_id=p_sign_on_org_id
13288 AND msn.inventory_item_id= l_item_id
13289 AND msn.SERIAL_NUMBER BETWEEN l_fm_serial_number AND
13290 l_to_serial_number;
13291 END LOOP;
13292 CLOSE c_fm_to_lot_serial_number;
13293
13294 UPDATE mtl_serial_numbers_temp
13295 SET group_header_id= l_txn_hdr_id
13296 WHERE transaction_temp_id in ( SELECT serial_transaction_temp_id
13297 FROM mtl_transaction_lots_temp
13298 WHERE transaction_temp_id= l_pick_slip_id );
13299 ELSE --Non-Lot item
13300
13301 OPEN c_fm_to_serial_number;
13302 LOOP
13303 FETCH c_fm_to_serial_number
13304 INTO l_fm_serial_number,l_to_serial_number;
13305 EXIT WHEN c_fm_to_serial_number%NOTFOUND;
13306
13307 UPDATE MTL_SERIAL_NUMBERS msn
13308 SET GROUP_MARK_ID=l_txn_hdr_id
13309 WHERE msn.current_organization_id=p_sign_on_org_id
13310 AND msn.inventory_item_id= l_item_id
13311 AND msn.SERIAL_NUMBER BETWEEN l_fm_serial_number AND
13312 l_to_serial_number;
13313 END LOOP;
13314 CLOSE c_fm_to_serial_number;
13315
13316 UPDATE mtl_serial_numbers_temp
13317 SET group_header_id= l_txn_hdr_id
13318 WHERE transaction_temp_id=l_pick_slip_id ;
13319
13320 END IF;
13321
13322 IF (l_debug = 1) THEN
13323 mydebug('manual_pick: Updated MSNT');
13324 END IF;
13325
13326 EXCEPTION
13327 WHEN OTHERS THEN
13328 IF (l_debug = 1) THEN
13329 mydebug('manual_pick:EXCEPTION!!! while updating MSNT');
13330 END IF;
13331 raise fnd_api.g_exc_error;
13332 END ;
13333 END IF;
13334 --Bug6009436.End
13335
13336 INSERT INTO wms_dispatched_tasks
13337 (
13338 task_id
13339 , transaction_temp_id
13340 , organization_id
13341 , user_task_type
13342 , person_id
13343 , effective_start_date
13344 , effective_end_date
13345 , equipment_id
13346 , equipment_instance
13347 , person_resource_id
13348 , machine_resource_id
13349 , status
13350 , dispatched_time
13351 , last_update_date
13352 , last_updated_by
13353 , creation_date
13354 , created_by
13355 , task_type
13356 , operation_plan_id
13357 , move_order_line_id
13358 )
13359 VALUES (
13360 l_next_task_id
13361 , l_pick_slip_id
13362 , l_org_id
13363 , NVL(l_std_op_id, 2)
13364 , l_user_id
13365 , SYSDATE
13366 , SYSDATE
13367 , l_eqp_id
13368 , l_eqp_ins
13369 , l_per_res_id
13370 , l_mac_res_id
13371 , 3
13372 , SYSDATE
13373 , SYSDATE
13374 , l_emp_id
13375 , SYSDATE
13376 , l_emp_id
13377 , l_wms_task_type
13378 , l_operation_plan_id
13379 , l_move_order_line_id
13380 );
13381
13382 IF (l_debug = 1) THEN
13383 mydebug('manual_pick: After Insert into WMSDT');
13384 END IF;
13385 END IF;
13386 END IF; --mmtt rowcount if
13387
13388 COMMIT;
13389 x_return_status := fnd_api.g_ret_sts_success;
13390 EXCEPTION
13391 WHEN fnd_api.g_exc_error THEN
13392 x_return_status := fnd_api.g_ret_sts_error;
13393 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13394 WHEN OTHERS THEN
13395 x_return_status := fnd_api.g_ret_sts_unexp_error;
13396 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13397 END manual_pick;
13398
13399 PROCEDURE check_carton(
13400 p_carton_id IN NUMBER
13401 , p_org_id IN NUMBER
13402 , x_nbr_tasks OUT NOCOPY NUMBER
13403 , x_return_status OUT NOCOPY VARCHAR2
13404 , x_msg_count OUT NOCOPY NUMBER
13405 , x_msg_data OUT NOCOPY VARCHAR2
13406 ) IS
13407 l_cartonization_id NUMBER := NULL;
13408 l_c_rows NUMBER;
13409 l_msg_count NUMBER;
13410 l_msg_data VARCHAR2(4000);
13411 l_return_status VARCHAR2(1);
13412 l_lpn_id NUMBER;
13413 l_org_id NUMBER;
13414 l_mmtt_rowcnt NUMBER;
13415 l_wdt_rowcnt NUMBER;
13416 l_undispatched_picks NUMBER;
13417 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13418 BEGIN
13419 IF (l_debug = 1) THEN
13420 mydebug('check_carton: In check carton API');
13421 END IF;
13422
13423 l_return_status := fnd_api.g_ret_sts_success;
13424 l_org_id := p_org_id;
13425 l_c_rows := 0;
13426 l_lpn_id := p_carton_id;
13427 l_mmtt_rowcnt := 0;
13428 l_wdt_rowcnt := 0;
13429
13430 IF (l_debug = 1) THEN
13431 mydebug('check_carton: Getting undispatched MMTT rows for this lpn..');
13432 END IF;
13433
13434 SELECT COUNT(*)
13435 INTO l_mmtt_rowcnt
13436 FROM mtl_material_transactions_temp m
13437 WHERE m.cartonization_id IS NOT NULL
13438 AND m.cartonization_id = l_lpn_id
13439 AND parent_line_id IS NULL;
13440
13441 IF (l_debug = 1) THEN
13442 mydebug('check_carton: MMTT rows' || l_mmtt_rowcnt);
13443 END IF;
13444
13445 IF l_mmtt_rowcnt > 0 THEN
13446 -- There are MMTT tasks for this LPN
13447 SELECT COUNT(*)
13448 INTO l_wdt_rowcnt
13449 FROM mtl_material_transactions_temp m, wms_dispatched_tasks t
13450 WHERE m.cartonization_id = l_lpn_id
13451 AND t.transaction_temp_id = m.transaction_temp_id
13452 AND t.status = 4;
13453
13454 IF (l_debug = 1) THEN
13455 mydebug('check_carton: WDT rows' || l_wdt_rowcnt);
13456 END IF;
13457
13458 l_undispatched_picks := l_mmtt_rowcnt - l_wdt_rowcnt;
13459
13460 IF (l_debug = 1) THEN
13461 mydebug('check_carton: Undispatched Picks' || l_undispatched_picks);
13462 END IF;
13463
13464 x_nbr_tasks := l_undispatched_picks;
13465 ELSE -- l_mmtt_rowcnt>0 if
13466 IF (l_debug = 1) THEN
13467 mydebug('check_carton: There are no mmtt rows for this LPN');
13468 END IF;
13469
13470 x_nbr_tasks := -1;
13471 END IF;
13472
13473 x_return_status := fnd_api.g_ret_sts_success;
13474 EXCEPTION
13475 WHEN fnd_api.g_exc_error THEN
13476 x_return_status := fnd_api.g_ret_sts_error;
13477 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13478 WHEN OTHERS THEN
13479 x_return_status := fnd_api.g_ret_sts_unexp_error;
13480 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13481 END check_carton;
13482
13483
13484
13485 PROCEDURE check_pack_lpn
13486 ( p_lpn IN VARCHAR2
13487 , p_org_id IN NUMBER
13488 , x_return_status OUT NOCOPY VARCHAR2
13489 , x_msg_count OUT NOCOPY NUMBER
13490 , x_msg_data OUT NOCOPY VARCHAR2
13491 ) IS
13492 lpn_cont NUMBER := 0;
13493 create_lpn VARCHAR2(1) := 'N';
13494 l_return_status VARCHAR2(1);
13495 l_msg_count NUMBER;
13496 l_msg_data VARCHAR2(4000);
13497 l_exist NUMBER;
13498 p_lpn_id NUMBER;
13499 l_org_id NUMBER;
13500 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13501 BEGIN
13502 IF (l_debug = 1) THEN
13503 mydebug('check_pack_lpn: check_pack_lpn begins');
13504 END IF;
13505
13506 l_return_status := fnd_api.g_ret_sts_success;
13507
13508 IF ((p_lpn IS NULL)
13509 OR(p_lpn = '')) THEN
13510 x_return_status := fnd_api.g_ret_sts_success;
13511 RETURN;
13512 END IF;
13513
13514 BEGIN
13515 SELECT lpn_context
13516 , organization_id
13517 INTO lpn_cont
13518 , l_org_id
13519 FROM wms_license_plate_numbers
13520 WHERE license_plate_number = p_lpn;
13521 EXCEPTION
13522 WHEN NO_DATA_FOUND THEN
13523 create_lpn := 'Y';
13524 END;
13525
13526 IF (
13527 create_lpn = 'N'
13528 AND(
13529 (
13530 lpn_cont = wms_container_pub.lpn_context_wip
13531 OR lpn_cont = wms_container_pub.lpn_context_rcv
13532 OR lpn_cont = wms_container_pub.lpn_context_stores
13533 OR lpn_cont = wms_container_pub.lpn_context_intransit
13534 OR lpn_cont = wms_container_pub.lpn_context_vendor
13535 OR lpn_cont = wms_container_pub.lpn_loaded_for_shipment
13536 OR lpn_cont = wms_container_pub.lpn_prepack_for_wip
13537 OR lpn_cont = wms_container_pub.lpn_context_picked
13538 OR lpn_cont = wms_container_pub.lpn_context_inv --Bug 5038228
13539 )
13540 OR l_org_id <> p_org_id
13541 )
13542 ) THEN
13543 IF (l_debug = 1) THEN
13544 mydebug('check_pack_lpn: LPN already exists but with different context or Org');
13545 END IF;--bug9165521
13546 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_CNTXT_ORG');
13547 fnd_msg_pub.ADD;
13548
13549
13550 x_return_status := fnd_api.g_ret_sts_error;
13551 RETURN;
13552 END IF;
13553
13554 IF create_lpn = 'Y' THEN
13555 IF (l_debug = 1) THEN
13556 mydebug('check_pack_lpn: calling wms_container_pub.create_lpn');
13557 END IF;
13558
13559 wms_container_pub.create_lpn
13560 ( p_api_version => 1.0
13561 , x_return_status => l_return_status
13562 , x_msg_count => l_msg_count
13563 , x_msg_data => x_msg_data
13564 , p_lpn => p_lpn
13565 , p_organization_id => p_org_id
13566 , x_lpn_id => p_lpn_id
13567 , p_source => 8
13568 );
13569
13570 IF (l_msg_count = 0) THEN
13571 IF (l_debug = 1) THEN
13572 mydebug('check_pack_lpn: Successful');
13573 END IF;
13574 ELSIF(l_msg_count = 1) THEN
13575 IF (l_debug = 1) THEN
13576 mydebug('check_pack_lpn: Not Successful');
13577 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
13578 END IF;
13579 ELSE
13580 IF (l_debug = 1) THEN
13581 mydebug('check_pack_lpn: Not Successful2');
13582 END IF;
13583
13584 FOR i IN 1 .. l_msg_count LOOP
13585 x_msg_data := fnd_msg_pub.get(i, 'F');
13586
13587 IF (l_debug = 1) THEN
13588 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
13589 END IF;
13590 END LOOP;
13591 END IF;
13592
13593 IF l_return_status = fnd_api.g_ret_sts_unexp_error
13594 OR l_return_status = fnd_api.g_ret_sts_error THEN
13595 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
13596 fnd_msg_pub.ADD;
13597 RAISE fnd_api.g_exc_unexpected_error;
13598 END IF;
13599
13600 END IF;
13601
13602 x_return_status := fnd_api.g_ret_sts_success;
13603
13604 IF (l_debug = 1) THEN
13605 mydebug('check_pack_lpn: check_pack_lpn ends');
13606 END IF;
13607 EXCEPTION
13608 WHEN fnd_api.g_exc_error THEN
13609 x_return_status := fnd_api.g_ret_sts_error;
13610 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13611 WHEN OTHERS THEN
13612 x_return_status := fnd_api.g_ret_sts_unexp_error;
13613 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
13614 END check_pack_lpn;
13615
13616 PROCEDURE mydebug(msg IN VARCHAR2) IS
13617 l_msg VARCHAR2(5100);
13618 l_ts VARCHAR2(30);
13619 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13620 BEGIN
13621 -- select to_char(sysdate,'MM/DD/YYYY HH:MM:SS') INTO l_ts from dual;
13622 -- l_msg:=l_ts||' '||msg;
13623
13624 l_msg := msg;
13625 inv_mobile_helper_functions.tracelog(p_err_msg => l_msg, p_module => 'WMS_Task_Dispatch_Gen', p_level => 4);
13626 --dbms_output.put_line(l_msg);
13627
13628 NULL;
13629 END;
13630
13631 -- Procedure
13632 -- check_is_reservable_sub
13633 -- Description
13634 -- check from db tables whether the sub specified in
13635 -- the input is a reservable sub or not.
13636 PROCEDURE check_is_reservable_sub(
13637 x_return_status OUT NOCOPY VARCHAR2
13638 , p_organization_id IN VARCHAR2
13639 , p_subinventory_code IN VARCHAR2
13640 , x_is_reservable_sub OUT NOCOPY BOOLEAN
13641 ) IS
13642 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
13643 l_reservable_type NUMBER;
13644 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13645 BEGIN
13646 SELECT reservable_type
13647 INTO l_reservable_type
13648 FROM mtl_secondary_inventories
13649 WHERE organization_id = p_organization_id
13650 AND secondary_inventory_name = p_subinventory_code;
13651
13652 IF (l_reservable_type = 1) THEN
13653 x_is_reservable_sub := TRUE;
13654 ELSE
13655 x_is_reservable_sub := FALSE;
13656 END IF;
13657
13658 x_return_status := l_return_status;
13659 EXCEPTION
13660 WHEN OTHERS THEN
13661 x_return_status := fnd_api.g_ret_sts_unexp_error;
13662
13663 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
13664 fnd_msg_pub.add_exc_msg(g_pkg_name, 'Check_Is_Reservable_SUB');
13665 END IF;
13666 END check_is_reservable_sub;
13667 -- Bug 2924823 H to I added delete allocation
13668
13669 PROCEDURE delete_allocation
13670 (
13671 p_temp_id IN NUMBER,
13672 p_lot_control_code IN NUMBER,
13673 p_serial_control_code IN NUMBER,
13674 p_serial_allocate_flag IN VARCHAR2,
13675 p_item_id IN NUMBER,
13676 p_org_id IN NUMBER
13677 )
13678
13679 IS
13680 l_fm_serial_number VARCHAR2(30);
13681 l_to_serial_number VARCHAR2(30);
13682
13683 CURSOR c_fm_to_serial_number IS
13684 SELECT
13685 msnt.fm_serial_number,
13686 msnt.to_serial_number
13687 FROM mtl_serial_numbers_temp msnt
13688 WHERE msnt.transaction_temp_id = p_temp_id;
13689
13690 CURSOR c_fm_to_lot_serial_number IS
13691 SELECT
13692 msnt.fm_serial_number,
13693 msnt.to_serial_number
13694 FROM
13695 mtl_serial_numbers_temp msnt,
13696 mtl_transaction_lots_temp mtlt
13697 WHERE mtlt.transaction_temp_id = p_temp_id
13698 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
13699
13700 BEGIN
13701 DELETE FROM mtl_material_transactions_temp
13702 WHERE transaction_temp_id = p_temp_id;
13703
13704 DELETE FROM wms_dispatched_tasks
13705 WHERE transaction_temp_id = p_temp_id;
13706
13707 IF p_lot_control_code > 1 THEN
13708
13709 -- Lot controlled item
13710
13711 IF p_serial_control_code NOT IN (1,6) AND
13712 p_serial_allocate_flag = 'Y' THEN
13713
13714 -- Lot and Serial controlled item
13715 OPEN c_fm_to_lot_serial_number;
13716 LOOP
13717 FETCH c_fm_to_lot_serial_number
13718 INTO l_fm_serial_number,l_to_serial_number;
13719 EXIT WHEN c_fm_to_serial_number%NOTFOUND;
13720
13721 UPDATE mtl_serial_numbers
13722 SET group_mark_id = NULL
13723 WHERE inventory_item_id = p_item_id
13724 AND current_organization_id = p_org_id
13725 AND serial_number BETWEEN l_fm_serial_number AND
13726 l_to_serial_number;
13727
13728 END LOOP;
13729 CLOSE c_fm_to_lot_serial_number;
13730
13731 DELETE FROM mtl_serial_numbers_temp msnt
13732 WHERE msnt.transaction_temp_id IN
13733 (SELECT mtlt.serial_transaction_temp_id
13734 FROM mtl_transaction_lots_temp mtlt
13735 WHERE mtlt.transaction_temp_id = p_temp_id);
13736
13737 END IF;
13738
13739 DELETE FROM mtl_transaction_lots_temp mtlt
13740 WHERE mtlt.transaction_temp_id = p_temp_id;
13741
13742 END IF;
13743
13744 END delete_allocation;
13745
13746
13747 PROCEDURE cleanup_task(
13748 p_temp_id IN NUMBER
13749 , p_qty_rsn_id IN NUMBER
13750 , p_user_id IN NUMBER
13751 , x_return_status OUT NOCOPY VARCHAR2
13752 , x_msg_count OUT NOCOPY NUMBER
13753 , x_msg_data OUT NOCOPY VARCHAR2
13754 ) IS
13755 l_txn_hdr_id NUMBER;
13756 l_txn_temp_id NUMBER;
13757 l_org_id NUMBER;
13758 l_item_id NUMBER;
13759 l_sub VARCHAR2(10);
13760 l_loc NUMBER;
13761 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
13762 l_lot VARCHAR2(80);
13763 l_rev VARCHAR2(3);
13764 l_txn_qty NUMBER;
13765 l_other_mmtt_count NUMBER;
13766 l_mo_line_id NUMBER;
13767 l_mo_type NUMBER;
13768 l_mol_qty NUMBER;
13769 l_mol_qty_delivered NUMBER;
13770 l_mol_src_id NUMBER;
13771 l_mol_src_line_id NUMBER;
13772 l_mol_reference_id NUMBER;
13773 l_mol_status NUMBER;--bug3139307
13774 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
13775 l_wf NUMBER;
13776 l_mmtt_transaction_uom VARCHAR2(3);
13777 l_mtrl_uom VARCHAR2(3);
13778 l_primary_quantity NUMBER;
13779 l_kill_mo_profile NUMBER := NVL(FND_PROFILE.VALUE_WNPS('INV_KILL_MOVE_ORDER'),2);
13780 l_return_status VARCHAR2(1);
13781
13782 CURSOR c_mmtt_info IS
13783 SELECT mmtt.transaction_header_id
13784 , mmtt.transaction_temp_id
13785 , mmtt.inventory_item_id
13786 , mmtt.organization_id
13787 , mmtt.revision
13788 , mmtt.lot_number
13789 , mmtt.subinventory_code
13790 , mmtt.locator_id
13791 , mmtt.move_order_line_id
13792 , mmtt.transaction_quantity
13793 , mmtt.transaction_uom
13794 , mmtt.primary_quantity
13795 FROM mtl_material_transactions_temp mmtt
13796 WHERE mmtt.transaction_temp_id = p_temp_id
13797 AND NOT EXISTS(SELECT 1
13798 FROM mtl_material_transactions_temp t1
13799 WHERE t1.parent_line_id = mmtt.transaction_temp_id)
13800 UNION ALL
13801 SELECT mmtt.transaction_header_id
13802 , mmtt.transaction_temp_id
13803 , mmtt.inventory_item_id
13804 , mmtt.organization_id
13805 , mmtt.revision
13806 , mmtt.lot_number
13807 , mmtt.subinventory_code
13808 , mmtt.locator_id
13809 , mmtt.move_order_line_id
13810 , mmtt.transaction_quantity
13811 , mmtt.transaction_uom
13812 , mmtt.primary_quantity
13813 FROM mtl_material_transactions_temp mmtt
13814 WHERE mmtt.parent_line_id = p_temp_id;
13815
13816 CURSOR c_mo_line_info IS
13817 SELECT mtrh.move_order_type
13818 , mtrl.txn_source_id
13819 , mtrl.txn_source_line_id
13820 , mtrl.reference_id
13821 , mtrl.quantity
13822 , mtrl.uom_code
13823 , nvl(mtrl.quantity_delivered,0)
13824 , mtrl.line_status --bug3139307
13825 FROM mtl_txn_request_headers mtrh, mtl_txn_request_lines mtrl
13826 WHERE mtrl.line_id = l_mo_line_id
13827 AND mtrh.header_id = mtrl.header_id;
13828
13829 CURSOR c_get_other_mmtt IS
13830 SELECT COUNT(*)
13831 FROM mtl_material_transactions_temp mmtt
13832 WHERE mmtt.move_order_line_id = l_mo_line_id
13833 AND mmtt.transaction_temp_id <> l_txn_temp_id
13834 AND NOT EXISTS(SELECT 1
13835 FROM mtl_material_transactions_temp t1
13836 WHERE t1.parent_line_id = mmtt.transaction_temp_id);
13837 BEGIN
13838 IF (l_debug = 1) THEN
13839 mydebug('CLEANUP_TASK: Cleaning up the Task with Temp ID = ' || p_temp_id);
13840 END IF;
13841
13842 x_return_status := fnd_api.g_ret_sts_success;
13843
13844 OPEN c_mmtt_info;
13845 LOOP
13846 FETCH c_mmtt_info INTO l_txn_hdr_id
13847 , l_txn_temp_id
13848 , l_item_id
13849 , l_org_id
13850 , l_rev
13851 , l_lot
13852 , l_sub
13853 , l_loc
13854 , l_mo_line_id
13855 , l_txn_qty
13856 , l_mmtt_transaction_uom
13857 , l_primary_quantity;
13858 EXIT WHEN c_mmtt_info%NOTFOUND;
13859
13860 IF (l_debug = 1) THEN
13861 mydebug('CLEANUP_TASK: Logging Exceptions with Reason ID = ' || p_qty_rsn_id || ' and TxnTempID = ' || l_txn_temp_id);
13862 END IF;
13863
13864 wms_txnrsn_actions_pub.log_exception(
13865 p_api_version_number => 1.0
13866 , p_init_msg_lst => fnd_api.g_false
13867 , p_commit => fnd_api.g_false
13868 , x_return_status => x_return_status
13869 , x_msg_count => x_msg_count
13870 , x_msg_data => x_msg_data
13871 , p_organization_id => l_org_id
13872 , p_item_id => l_item_id
13873 , p_revision => l_rev
13874 , p_lot_number => l_lot
13875 , p_subinventory_code => l_sub
13876 , p_locator_id => l_loc
13877 , p_mmtt_id => l_txn_hdr_id
13878 , p_task_id => l_txn_temp_id
13879 , p_reason_id => p_qty_rsn_id
13880 , p_discrepancy_type => 1
13881 , p_user_id => p_user_id
13882 );
13883
13884 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
13885 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
13886 fnd_msg_pub.ADD;
13887 RAISE fnd_api.g_exc_unexpected_error;
13888 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
13889 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
13890 fnd_msg_pub.ADD;
13891 RAISE fnd_api.g_exc_error;
13892 END IF;
13893
13894 mydebug('CLEANUP_TASK : Calling WorkFlow with Calling Program as **cleanup_task: Pick zero**');
13895 BEGIN
13896 call_workflow(
13897 p_rsn_id => p_qty_rsn_id
13898 , p_calling_program => 'cleanup_task: Pick zero'
13899 , p_org_id => l_org_id
13900 , p_tmp_id => l_txn_temp_id
13901 , p_quantity_picked => l_txn_qty
13902 , p_dest_sub => l_sub
13903 , p_dest_loc => l_loc
13904 , x_return_status => x_return_status
13905 , x_msg_count => x_msg_count
13906 , x_msg_data => x_msg_data
13907 , x_wf => l_wf
13908 );
13909
13910 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13911 mydebug('CLEANUP_TASK : Workflow Call is not successful');
13912 RAISE fnd_api.g_exc_unexpected_error;
13913 END IF;
13914 EXCEPTION
13915 WHEN OTHERS THEN
13916 mydebug('CLEANUP_TASK : Call to WorkFlow ended up in Exceptions');
13917 NULL;
13918 END;
13919 -- Called c_get_other_mmtt later after c_mo_line_info
13920 OPEN c_mo_line_info;
13921 FETCH c_mo_line_info INTO l_mo_type, l_mol_src_id, l_mol_src_line_id,
13922 l_mol_reference_id, l_mol_qty, l_mtrl_uom, l_mol_qty_delivered,l_mol_status;
13923 --bug3139307
13924 CLOSE c_mo_line_info;
13925 mydebug('cleanup_task: transaction_uom:'||l_mmtt_transaction_uom);
13926 mydebug('cleanup_task: move order line uom :'|| l_mtrl_uom);
13927 -- Bug 2924823 H to I
13928 if (l_mtrl_uom <> l_mmtt_transaction_uom) then
13929 mydebug('cleanup_task: move order line uom is different from mmtt
13930 transaction uom');
13931 l_txn_qty := INV_Convert.inv_um_convert
13932 (item_id => l_item_id,
13933 precision => null,
13934 from_quantity => l_txn_qty,
13935 from_unit => l_mmtt_transaction_uom,
13936 to_unit => l_mtrl_uom,
13937 from_name => null,
13938 to_name => null);
13939 end if;
13940
13941
13942 OPEN c_get_other_mmtt;
13943 FETCH c_get_other_mmtt INTO l_other_mmtt_count;
13944 CLOSE c_get_other_mmtt;
13945
13946 IF (l_debug = 1) THEN
13947 mydebug('CLEANUP_TASK: Number of MMTTs other than this MMTT : ' || l_other_mmtt_count);
13948 END IF;
13949
13950 IF l_other_mmtt_count > 0 THEN
13951 IF (l_debug = 1) THEN
13952 mydebug('CLEANUP_TASK: Other MMTT lines exist too. So cant close MO Line');
13953 END IF;
13954
13955 inv_trx_util_pub.delete_transaction(
13956 x_return_status => x_return_status
13957 , x_msg_data => x_msg_data
13958 , x_msg_count => x_msg_count
13959 , p_transaction_temp_id => l_txn_temp_id
13960 , p_update_parent => FALSE --Added bug 3765153
13961 );
13962
13963 IF x_return_status <> fnd_api.g_ret_sts_success THEN
13964 IF l_debug = 1 THEN
13965 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
13966 END IF;
13967 RAISE fnd_api.g_exc_error;
13968 END IF;
13969 -- Bug 2924823 H to I
13970 if (l_wf <= 0) or (p_qty_rsn_id <= 0) then
13971 UPDATE mtl_txn_request_lines
13972 SET quantity_detailed = quantity_detailed - l_txn_qty
13973 WHERE line_id = l_mo_line_id;
13974 end if;
13975 ELSE
13976 IF (l_debug = 1) THEN
13977 mydebug('CLEANUP_TASK: Just one MMTT line exists. Close MO');
13978 END IF;
13979
13980 /* OPEN c_mo_line_info;
13981 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;
13982 CLOSE c_mo_line_info;
13983 */
13984 IF (l_mo_type = INV_GLOBALS.G_MOVE_ORDER_PICK_WAVE) THEN
13985 DELETE FROM wms_dispatched_tasks WHERE transaction_temp_id = p_temp_id;
13986
13987 /*bug3139307 suggest_alternate_location API in wms_txnrsn_actions_pub
13988 would call INV_Replenish_Detail_PUB.Line_Details_PUB . When there is
13989 no quantity to allocate the sales order would be automatically
13990 backordered and move order is closed. So we need not call
13991 backorder API here again. */
13992 IF l_mol_status <> 5 THEN --bug3139307 bug 2924823 H to I
13993 inv_mo_backorder_pvt.backorder(
13994 p_line_id => l_mo_line_id
13995 , x_return_status => x_return_status
13996 , x_msg_count => x_msg_count
13997 , x_msg_data => x_msg_data
13998 );
13999
14000 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
14001 IF (l_debug = 1) THEN
14002 mydebug('CLEANUP_TASK: Unexpected error occurrend while calling BackOrder API');
14003 END IF;
14004 RAISE fnd_api.g_exc_unexpected_error;
14005 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
14006 IF (l_debug = 1) THEN
14007 mydebug('CLEANUP_TASK: Expected error occurrend while calling BackOrder API');
14008 END IF;
14009 RAISE fnd_api.g_exc_error;
14010 END IF;
14011
14012 IF (l_debug = 1) THEN
14013 mydebug('CLEANUP_TASK: Calling API to clean up reservations');
14014 END IF;
14015
14016 inv_transfer_order_pvt.clean_reservations(
14017 p_source_line_id => l_mol_src_line_id
14018 , x_return_status => x_return_status
14019 , x_msg_count => x_msg_count
14020 , x_msg_data => x_msg_data
14021 );
14022
14023 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
14024 IF (l_debug = 1) THEN
14025 mydebug('CLEANUP_TASK: Unexpected error occurred while Cleaning up Reservations');
14026 END IF;
14027 RAISE fnd_api.g_exc_unexpected_error;
14028 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
14029 IF (l_debug = 1) THEN
14030 mydebug('CLEANUP_TASK: Expected error occurred while Cleaning up Reservations');
14031 END IF;
14032 RAISE fnd_api.g_exc_error;
14033 END IF;
14034
14035 ELSE -- if mol.status = 5 --bug3139307
14036 /*Need to delete the MMTT as the suggest_alternate-location
14037 procedure in WMSTRSAB.pls would set the MMTT transaction qty. primary
14038 transaction qty to zero before calling pick release. When Pick rellease
14039 backorders the mo line it does not clean up the taks. This
14040 has to be done here.*/
14041
14042 INV_TRX_UTIL_PUB.delete_transaction(
14043 x_return_status => x_return_status
14044 , x_msg_data => x_msg_data
14045 , x_msg_count => x_msg_count
14046 , p_transaction_temp_id => l_txn_temp_id
14047 , p_update_parent => FALSE --Added bug 3765153
14048 );
14049
14050 IF x_return_status <> fnd_api.g_ret_sts_success THEN
14051 IF l_debug = 1 THEN
14052 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
14053 END IF;
14054 RAISE fnd_api.g_exc_error;
14055 END IF;
14056 END IF; --bug3139307 bug 2924823 H to I
14057 /* IF l_mo_type = INV_GLOBALS.G_MOVE_ORDER_MFG_PICK THEN */
14058 ELSIF l_mo_type IN (5,7)THEN -- wip picking bug 2924823 H to I
14059 UPDATE mtl_txn_request_lines
14060 SET quantity_detailed = quantity_delivered
14061 , line_status = 5
14062 WHERE line_id = l_mo_line_id;
14063
14064 wip_picking_pub.unallocate_material(
14065 p_wip_entity_id => l_mol_src_id
14066 , p_operation_seq_num => l_mol_src_line_id
14067 , p_inventory_item_id => l_item_id
14068 , p_repetitive_schedule_id => l_mol_reference_id
14069 , p_primary_quantity => l_mol_qty - l_mol_qty_delivered
14070 , x_return_status => x_return_status
14071 , x_msg_data => x_msg_data
14072 );
14073
14074 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
14075 IF (l_debug = 1) THEN
14076 mydebug('CLEANUP_TASK: Unexpected error occurred while Unallocating WIP Material');
14077 END IF;
14078 RAISE fnd_api.g_exc_unexpected_error;
14079 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
14080 IF (l_debug = 1) THEN
14081 mydebug('CLEANUP_TASK: Expected error occurred while Unallocating WIP Material');
14082 END IF;
14083 RAISE fnd_api.g_exc_error;
14084 END IF;
14085
14086 inv_trx_util_pub.delete_transaction(
14087 x_return_status => x_return_status
14088 , x_msg_data => x_msg_data
14089 , x_msg_count => x_msg_count
14090 , p_transaction_temp_id => l_txn_temp_id
14091 , p_update_parent => FALSE --Added bug3765153
14092 );
14093
14094 IF x_return_status <> fnd_api.g_ret_sts_success THEN
14095 IF l_debug = 1 THEN
14096 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
14097 END IF;
14098 RAISE fnd_api.g_exc_error;
14099 END IF;
14100 -- Bug 2924823 H to I
14101 if (l_wf <= 0) or (p_qty_rsn_id <= 0) then
14102 UPDATE mtl_txn_request_lines
14103 SET quantity_detailed = quantity_detailed - l_txn_qty,
14104 line_status = 5
14105 WHERE line_id = l_mo_line_id;
14106 end if;
14107 ELSIF l_mo_type IN (INV_GLOBALS.G_MOVE_ORDER_REQUISITION, INV_GLOBALS.G_MOVE_ORDER_REPLENISHMENT) THEN
14108 UPDATE mtl_txn_request_lines
14109 SET quantity_detailed = quantity_delivered
14110 WHERE line_id = l_mo_line_id;
14111
14112 inv_trx_util_pub.delete_transaction(
14113 x_return_status => x_return_status
14114 , x_msg_data => x_msg_data
14115 , x_msg_count => x_msg_count
14116 , p_transaction_temp_id => l_txn_temp_id
14117 );
14118
14119 IF x_return_status <> fnd_api.g_ret_sts_success THEN
14120 IF l_debug = 1 THEN
14121 mydebug('CLEANUP_TASK: Error occurred while deleting MMTT');
14122 END IF;
14123 RAISE fnd_api.g_exc_error;
14124 END IF;
14125
14126 /* 3926046 */
14127 IF (l_kill_mo_profile = 1) and (l_mo_type = INV_GLOBALS.G_MOVE_ORDER_REPLENISHMENT) THEN
14128
14129 IF (l_debug = 1) THEN
14130 mydebug('Replenishment Move Order... pending task count :'|| l_other_mmtt_count);
14131 mydebug('Replenishment Move Order... quantity delivered :'|| l_mol_qty_delivered);
14132 END IF;
14133
14134 IF ((l_other_mmtt_count = 0) and (l_mol_qty_delivered > 0)) THEN
14135 IF (l_debug = 1) THEN
14136 mydebug('Replenishment Move Order... Closing the Move Order');
14137 END IF;
14138 INV_MO_ADMIN_PUB.close_line(1.0,'F','F','F',l_mo_line_id,x_msg_count,x_msg_data,l_return_status);
14139
14140 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
14141 RAISE FND_API.G_EXC_ERROR;
14142 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
14143 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
14144 END IF;
14145 END IF;
14146 END IF;
14147
14148 -- Bug 2924823 H to I
14149 if (l_wf <= 0) or (p_qty_rsn_id <= 0) then
14150 UPDATE mtl_txn_request_lines
14151 SET quantity_detailed = quantity_delivered
14152 WHERE line_id = l_mo_line_id;
14153 end if;
14154 END IF;
14155 END IF;
14156 END LOOP;
14157
14158 CLOSE c_mmtt_info;
14159 COMMIT;
14160 EXCEPTION
14161 WHEN OTHERS THEN
14162 x_return_status := fnd_api.g_ret_sts_error;
14163 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14164 IF c_mmtt_info%ISOPEN THEN
14165 CLOSE c_mmtt_info;
14166 END IF;
14167 IF (l_debug = 1) THEN
14168 mydebug('CLEANUP_TASK: Exception Occurred = ' || SQLERRM);
14169 END IF;
14170 END cleanup_task;
14171
14172 PROCEDURE get_td_lot_lov_count(
14173 x_lot_num_lov_count OUT NOCOPY NUMBER
14174 , p_organization_id IN NUMBER
14175 , p_item_id IN NUMBER
14176 , p_lot_number IN VARCHAR2
14177 , p_transaction_type_id IN NUMBER
14178 , p_wms_installed IN VARCHAR2
14179 , p_lpn_id IN NUMBER
14180 , p_subinventory_code IN VARCHAR2
14181 , p_locator_id IN NUMBER
14182 , p_txn_temp_id IN NUMBER
14183 ) IS
14184 l_negative_rcpt_code NUMBER;
14185 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14186 BEGIN
14187 SELECT negative_inv_receipt_code
14188 INTO l_negative_rcpt_code
14189 FROM mtl_parameters
14190 WHERE organization_id = p_organization_id;
14191
14192 IF (l_negative_rcpt_code = 1) THEN
14193 -- Negative inventory balances allowed
14194
14195 IF (p_lpn_id IS NULL
14196 OR p_lpn_id = 0) THEN
14197 SELECT COUNT(*)
14198 INTO x_lot_num_lov_count
14199 FROM mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt
14200 WHERE mln.organization_id = p_organization_id
14201 AND mln.inventory_item_id = p_item_id
14202 AND mln.lot_number LIKE(p_lot_number || '%')
14203 AND mtlt.lot_number = mln.lot_number
14204 AND mtlt.transaction_temp_id = p_txn_temp_id
14205 AND inv_material_status_grp.is_status_applicable(
14206 p_wms_installed
14207 , NULL
14208 , p_transaction_type_id
14209 , NULL
14210 , NULL
14211 , p_organization_id
14212 , p_item_id
14213 , NULL
14214 , NULL
14215 , mln.lot_number
14216 , NULL
14217 , 'O'
14218 ) = 'Y';
14219 ELSE
14220 -- It however remains same for LPNs
14221 SELECT COUNT(*)
14222 INTO x_lot_num_lov_count
14223 FROM mtl_onhand_quantities_detail moq, mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt, wms_lpn_contents wlc
14224 WHERE mln.organization_id = p_organization_id
14225 AND mln.inventory_item_id = p_item_id
14226 AND mln.lot_number LIKE(p_lot_number || '%')
14227 AND moq.lot_number = mln.lot_number
14228 AND moq.inventory_item_id = mln.inventory_item_id
14229 AND moq.organization_id = mln.organization_id
14230 AND mtlt.lot_number = mln.lot_number
14231 AND mtlt.transaction_temp_id = p_txn_temp_id
14232 AND moq.containerized_flag = 1
14233 AND wlc.parent_lpn_id = p_lpn_id
14234 AND wlc.lot_number = mln.lot_number
14235 AND wlc.inventory_item_id = p_item_id
14236 AND wlc.organization_id = p_organization_id
14237 AND moq.subinventory_code = NVL(p_subinventory_code, moq.subinventory_code)
14238 AND NVL(moq.locator_id, -1) = NVL(NVL(p_locator_id, moq.locator_id), -1)
14239 AND inv_material_status_grp.is_status_applicable(
14240 p_wms_installed
14241 , NULL
14242 , p_transaction_type_id
14243 , NULL
14244 , NULL
14245 , p_organization_id
14246 , p_item_id
14247 , NULL
14248 , NULL
14249 , mln.lot_number
14250 , NULL
14251 , 'O'
14252 ) = 'Y';
14253 END IF;
14254 ELSE
14255 -- Negative inventory balances not allowed
14256
14257 IF (p_lpn_id IS NULL
14258 OR p_lpn_id = 0) THEN
14259 SELECT COUNT(*)
14260 INTO x_lot_num_lov_count
14261 FROM mtl_onhand_quantities_detail moq, mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt
14262 WHERE mln.organization_id = p_organization_id
14263 AND mln.inventory_item_id = p_item_id
14264 AND mln.lot_number LIKE(p_lot_number || '%')
14265 AND moq.lot_number = mln.lot_number
14266 AND moq.inventory_item_id = mln.inventory_item_id
14267 AND moq.organization_id = mln.organization_id
14268 AND mtlt.lot_number = mln.lot_number
14269 AND mtlt.transaction_temp_id = p_txn_temp_id
14270 AND moq.containerized_flag = 2
14271 AND moq.subinventory_code = NVL(p_subinventory_code, moq.subinventory_code)
14272 AND NVL(moq.locator_id, -1) = NVL(NVL(p_locator_id, moq.locator_id), -1)
14273 AND inv_material_status_grp.is_status_applicable(
14274 p_wms_installed
14275 , NULL
14276 , p_transaction_type_id
14277 , NULL
14278 , NULL
14279 , p_organization_id
14280 , p_item_id
14281 , NULL
14282 , NULL
14283 , mln.lot_number
14284 , NULL
14285 , 'O'
14286 ) = 'Y';
14287 ELSE
14288 SELECT COUNT(*)
14289 INTO x_lot_num_lov_count
14290 FROM mtl_onhand_quantities_detail moq, mtl_lot_numbers_all_v mln, mtl_transaction_lots_temp mtlt, wms_lpn_contents wlc
14291 WHERE mln.organization_id = p_organization_id
14292 AND mln.inventory_item_id = p_item_id
14293 AND mln.lot_number LIKE(p_lot_number || '%')
14294 AND moq.lot_number = mln.lot_number
14295 AND moq.inventory_item_id = mln.inventory_item_id
14296 AND moq.organization_id = mln.organization_id
14297 AND mtlt.lot_number = mln.lot_number
14298 AND mtlt.transaction_temp_id = p_txn_temp_id
14299 AND moq.containerized_flag = 1
14300 AND wlc.parent_lpn_id = p_lpn_id
14301 AND wlc.lot_number = mln.lot_number
14302 AND wlc.inventory_item_id = p_item_id
14303 AND wlc.organization_id = p_organization_id
14304 AND moq.subinventory_code = NVL(p_subinventory_code, moq.subinventory_code)
14305 AND NVL(moq.locator_id, -1) = NVL(NVL(p_locator_id, moq.locator_id), -1)
14306 AND inv_material_status_grp.is_status_applicable(
14307 p_wms_installed
14308 , NULL
14309 , p_transaction_type_id
14310 , NULL
14311 , NULL
14312 , p_organization_id
14313 , p_item_id
14314 , NULL
14315 , NULL
14316 , mln.lot_number
14317 , NULL
14318 , 'O'
14319 ) = 'Y';
14320 END IF;
14321 END IF;
14322 END get_td_lot_lov_count;
14323
14324 PROCEDURE validate_sub_loc_status(
14325 p_wms_installed IN VARCHAR2
14326 , p_temp_id IN NUMBER
14327 , p_confirmed_sub IN VARCHAR2
14328 , p_confirmed_loc_id IN NUMBER
14329 , x_return_status OUT NOCOPY VARCHAR2
14330 , x_msg_count OUT NOCOPY NUMBER
14331 , x_msg_data OUT NOCOPY VARCHAR2
14332 , x_result OUT NOCOPY NUMBER
14333 ) IS
14334 l_transaction_type_id NUMBER;
14335 l_org_id NUMBER;
14336 l_item_id NUMBER;
14337 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14338 BEGIN
14339 IF (l_debug = 1) THEN
14340 mydebug('validate_sub_loc_status: validate_sub_loc_status begins');
14341 END IF;
14342
14343 x_return_status := fnd_api.g_ret_sts_success;
14344
14345 SELECT mmtt.transaction_type_id
14346 , mmtt.organization_id
14347 , mmtt.inventory_item_id
14348 INTO l_transaction_type_id
14349 , l_org_id
14350 , l_item_id
14351 FROM mtl_material_transactions_temp mmtt
14352 WHERE mmtt.transaction_temp_id = p_temp_id;
14353
14354 IF inv_material_status_grp.is_status_applicable(
14355 p_wms_installed => p_wms_installed
14356 , p_trx_status_enabled => NULL
14357 , p_trx_type_id => l_transaction_type_id
14358 , p_lot_status_enabled => NULL
14359 , p_serial_status_enabled => NULL
14360 , p_organization_id => l_org_id
14361 , p_inventory_item_id => l_item_id
14362 , p_sub_code => p_confirmed_sub
14363 , p_locator_id => p_confirmed_loc_id
14364 , p_lot_number => NULL
14365 , p_serial_number => NULL
14366 , p_object_type => 'Z'
14367 ) = 'Y'
14368 AND inv_material_status_grp.is_status_applicable(
14369 p_wms_installed => p_wms_installed
14370 , p_trx_status_enabled => NULL
14371 , p_trx_type_id => l_transaction_type_id
14372 , p_lot_status_enabled => NULL
14373 , p_serial_status_enabled => NULL
14374 , p_organization_id => l_org_id
14375 , p_inventory_item_id => l_item_id
14376 , p_sub_code => p_confirmed_sub
14377 , p_locator_id => p_confirmed_loc_id
14378 , p_lot_number => NULL
14379 , p_serial_number => NULL
14380 , p_object_type => 'L'
14381 ) = 'Y' THEN
14382 x_result := 1;
14383
14384 IF (l_debug = 1) THEN
14385 mydebug('validate_sub_loc_status: Material status is correct. x_result = 1');
14386 END IF;
14387 ELSE
14388 x_result := 0;
14389
14390 IF (l_debug = 1) THEN
14391 mydebug('validate_sub_loc_status: Material status is incorrect. x_result = 0');
14392 END IF;
14393 END IF;
14394
14395 IF (l_debug = 1) THEN
14396 mydebug('validate_sub_loc_status: End of validate_sub_loc_status');
14397 END IF;
14398 EXCEPTION
14399 WHEN fnd_api.g_exc_error THEN
14400 x_return_status := fnd_api.g_ret_sts_error;
14401
14402 IF (l_debug = 1) THEN
14403 mydebug('validate_sub_loc_status: Error - ' || SQLERRM);
14404 END IF;
14405
14406 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14407 WHEN OTHERS THEN
14408 x_return_status := fnd_api.g_ret_sts_unexp_error;
14409
14410 IF (l_debug = 1) THEN
14411 mydebug('validate_sub_loc_status: Unexpected Error - ' || SQLERRM);
14412 END IF;
14413
14414 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14415 END validate_sub_loc_status;
14416
14417 PROCEDURE validate_pick_drop_sub(
14418 p_temp_id IN NUMBER
14419 , p_confirmed_drop_sub IN VARCHAR2
14420 , x_return_status OUT NOCOPY VARCHAR2
14421 , x_msg_count OUT NOCOPY NUMBER
14422 , x_msg_data OUT NOCOPY VARCHAR2
14423 ) IS
14424 l_xfr_lpn_id NUMBER;
14425 l_lpn_controlled_flag NUMBER;
14426 l_count NUMBER := 0;
14427 l_orig_xfr_sub VARCHAR2(30);
14428 l_mmtt_mo_type NUMBER := NULL;
14429 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14430 l_wms_task_type NUMBER;
14431 --Bug#9659710
14432 l_txn_source_id NUMBER;
14433 l_wip_entity_type NUMBER;
14434 Cursor get_wip_entity_type is
14435 select entity_type
14436 from wip_entities
14437 where wip_entity_id = l_txn_source_id;
14438
14439 BEGIN
14440 IF (l_debug = 1) THEN
14441 mydebug('validate_pick_drop_sub: validate_pick_drop_sub begins ');
14442 mydebug(' p_temp_id = ' || p_temp_id);
14443 mydebug(' p_confirmed_drop_sub = ' || p_confirmed_drop_sub);
14444 END IF;
14445
14446 x_return_status := fnd_api.g_ret_sts_success;
14447
14448 -- bug fix 2805229
14449 SELECT wms_task_type
14450 INTO l_wms_task_type
14451 FROM mtl_material_transactions_temp
14452 WHERE transaction_temp_id = p_temp_id;
14453
14454 IF l_wms_task_type = 7 THEN -- staging move
14455 IF (l_debug = 1) THEN
14456 mydebug('Skip further validation because l_wms_task_type = ' || l_wms_task_type);
14457 END IF;
14458
14459 RETURN;
14460 END IF;
14461
14462 -- end bug fix 2805229
14463
14464
14465
14466 SELECT mtrh.move_order_type,
14467 mtrl.txn_source_id
14468 INTO l_mmtt_mo_type,
14469 l_txn_source_id --Bug#9659710
14470 FROM mtl_txn_request_headers mtrh, -- mo header for the new task
14471 mtl_txn_request_lines mtrl, mtl_material_transactions_temp mmtt
14472 WHERE mtrh.header_id = mtrl.header_id
14473 AND mtrl.line_id = mmtt.move_order_line_id
14474 AND mmtt.transaction_temp_id = p_temp_id;
14475
14476 IF (l_debug = 1) THEN
14477 mydebug('validate_pick_drop_sub : l_mmtt_mo_type = ' || l_mmtt_mo_type);
14478 END IF;
14479
14480 SELECT msi.lpn_controlled_flag
14481 , mmtt.transfer_lpn_id
14482 , mmtt.transfer_subinventory
14483 INTO l_lpn_controlled_flag
14484 , l_xfr_lpn_id
14485 , l_orig_xfr_sub
14486 FROM mtl_material_transactions_temp mmtt, mtl_secondary_inventories msi
14487 WHERE mmtt.transaction_temp_id = p_temp_id
14488 AND mmtt.organization_id = msi.organization_id
14489 AND msi.secondary_inventory_name = p_confirmed_drop_sub;
14490
14491 IF l_lpn_controlled_flag = wms_globals.g_lpn_controlled_sub THEN
14492 IF (l_mmtt_mo_type = 5) THEN
14493 /*Bug#9659710 for GME batches, the validation should not be there as it allows the move order transfer
14494 to a LPN controlled subinventory and allowd the material consumption from the same later */
14495 OPEN get_wip_entity_type;
14496 FETCH get_wip_entity_type INTO l_wip_entity_type;
14497 CLOSE get_wip_entity_type;
14498 IF (l_wip_entity_type not in (9,10)) THEN
14499 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
14500 fnd_msg_pub.ADD;
14501 RAISE fnd_api.g_exc_error;
14502 END IF;
14503 END IF;
14504
14505 IF (l_debug = 1) THEN
14506 mydebug('validate_pick_drop_sub: Transfer Sub is LPN Controlled');
14507 END IF;
14508
14509 l_count := 0;
14510
14511 BEGIN
14512 SELECT 1
14513 INTO l_count
14514 FROM DUAL
14515 WHERE EXISTS(
14516 SELECT 1
14517 FROM mtl_material_transactions_temp mmtt
14518 WHERE mmtt.transaction_temp_id <> p_temp_id
14519 AND mmtt.transfer_lpn_id = l_xfr_lpn_id
14520 AND mmtt.transfer_subinventory <> p_confirmed_drop_sub
14521 AND mmtt.transfer_subinventory <> l_orig_xfr_sub);
14522 EXCEPTION
14523 WHEN NO_DATA_FOUND THEN
14524 l_count := 0;
14525 END;
14526
14527 IF l_count > 0 THEN
14528 IF (l_debug = 1) THEN
14529 mydebug('validate_pick_drop_sub: Drop LPN is going to a different sub');
14530 END IF;
14531
14532 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
14533 fnd_msg_pub.ADD;
14534 RAISE fnd_api.g_exc_error;
14535 END IF;
14536 END IF;
14537
14538 IF (l_debug = 1) THEN
14539 mydebug('validate_pick_drop_sub: End of validate_pick_drop_sub');
14540 END IF;
14541 EXCEPTION
14542 WHEN fnd_api.g_exc_error THEN
14543 x_return_status := fnd_api.g_ret_sts_error;
14544
14545 IF (l_debug = 1) THEN
14546 mydebug('validate_pick_drop_sub: Error - ' || SQLERRM);
14547 END IF;
14548
14549 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14550 WHEN OTHERS THEN
14551 x_return_status := fnd_api.g_ret_sts_unexp_error;
14552
14553 IF (l_debug = 1) THEN
14554 mydebug('validate_pick_drop_sub: Unexpected Error - ' || SQLERRM);
14555 END IF;
14556
14557 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14558 END validate_pick_drop_sub;
14559
14560 -- Added for bug 12853197
14561 PROCEDURE validate_pick_drop_sub(
14562 p_temp_id IN NUMBER
14563 , p_confirmed_drop_sub IN VARCHAR2
14564 , x_return_status OUT NOCOPY VARCHAR2
14565 , x_msg_count OUT NOCOPY NUMBER
14566 , x_msg_data OUT NOCOPY VARCHAR2
14567 , x_lpn_controlled_flag OUT NOCOPY VARCHAR2
14568 ) IS
14569 l_xfr_lpn_id NUMBER;
14570 l_lpn_controlled_flag NUMBER;
14571 l_count NUMBER := 0;
14572 l_orig_xfr_sub VARCHAR2(30);
14573 l_mmtt_mo_type NUMBER := NULL;
14574 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14575 l_wms_task_type NUMBER;
14576 BEGIN
14577 IF (l_debug = 1) THEN
14578 mydebug('validate_pick_drop_sub: validate_pick_drop_sub begins ');
14579 mydebug(' p_temp_id = ' || p_temp_id);
14580 mydebug(' p_confirmed_drop_sub = ' || p_confirmed_drop_sub);
14581 END IF;
14582
14583 x_return_status := fnd_api.g_ret_sts_success;
14584
14585 -- bug fix 2805229
14586 SELECT wms_task_type
14587 INTO l_wms_task_type
14588 FROM mtl_material_transactions_temp
14589 WHERE transaction_temp_id = p_temp_id;
14590
14591 IF l_wms_task_type = 7 THEN -- staging move
14592 IF (l_debug = 1) THEN
14593 mydebug('Skip further validation because l_wms_task_type = ' || l_wms_task_type);
14594 END IF;
14595
14596 RETURN;
14597 END IF;
14598
14599 -- end bug fix 2805229
14600
14601
14602
14603 SELECT mtrh.move_order_type
14604 INTO l_mmtt_mo_type
14605 FROM mtl_txn_request_headers mtrh, -- mo header for the new task
14606 mtl_txn_request_lines mtrl, mtl_material_transactions_temp mmtt
14607 WHERE mtrh.header_id = mtrl.header_id
14608 AND mtrl.line_id = mmtt.move_order_line_id
14609 AND mmtt.transaction_temp_id = p_temp_id;
14610
14611 IF (l_debug = 1) THEN
14612 mydebug('validate_pick_drop_sub : l_mmtt_mo_type = ' || l_mmtt_mo_type);
14613 END IF;
14614
14615 SELECT msi.lpn_controlled_flag
14616 , mmtt.transfer_lpn_id
14617 , mmtt.transfer_subinventory
14618 INTO l_lpn_controlled_flag
14619 , l_xfr_lpn_id
14620 , l_orig_xfr_sub
14621 FROM mtl_material_transactions_temp mmtt, mtl_secondary_inventories msi
14622 WHERE mmtt.transaction_temp_id = p_temp_id
14623 AND mmtt.organization_id = msi.organization_id
14624 AND msi.secondary_inventory_name = p_confirmed_drop_sub;
14625
14626 x_lpn_controlled_flag:=l_lpn_controlled_flag;
14627
14628 IF l_lpn_controlled_flag = wms_globals.g_lpn_controlled_sub THEN
14629 IF (l_mmtt_mo_type = 5) THEN
14630 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
14631 fnd_msg_pub.ADD;
14632 RAISE fnd_api.g_exc_error;
14633 END IF;
14634
14635 IF (l_debug = 1) THEN
14636 mydebug('validate_pick_drop_sub: Transfer Sub is LPN Controlled');
14637 END IF;
14638
14639 l_count := 0;
14640
14641 BEGIN
14642 SELECT 1
14643 INTO l_count
14644 FROM DUAL
14645 WHERE EXISTS(
14646 SELECT 1
14647 FROM mtl_material_transactions_temp mmtt
14648 WHERE mmtt.transaction_temp_id <> p_temp_id
14649 AND mmtt.transfer_lpn_id = l_xfr_lpn_id
14650 AND mmtt.transfer_subinventory <> p_confirmed_drop_sub
14651 AND mmtt.transfer_subinventory <> l_orig_xfr_sub);
14652 EXCEPTION
14653 WHEN NO_DATA_FOUND THEN
14654 l_count := 0;
14655 END;
14656
14657 IF l_count > 0 THEN
14658 IF (l_debug = 1) THEN
14659 mydebug('validate_pick_drop_sub: Drop LPN is going to a different sub');
14660 END IF;
14661
14662 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
14663 fnd_msg_pub.ADD;
14664 RAISE fnd_api.g_exc_error;
14665 END IF;
14666 END IF;
14667
14668 IF (l_debug = 1) THEN
14669 mydebug('validate_pick_drop_sub: End of validate_pick_drop_sub');
14670 END IF;
14671 EXCEPTION
14672 WHEN fnd_api.g_exc_error THEN
14673 x_return_status := fnd_api.g_ret_sts_error;
14674
14675 IF (l_debug = 1) THEN
14676 mydebug('validate_pick_drop_sub: Error - ' || SQLERRM);
14677 END IF;
14678
14679 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14680 WHEN OTHERS THEN
14681 x_return_status := fnd_api.g_ret_sts_unexp_error;
14682
14683 IF (l_debug = 1) THEN
14684 mydebug('validate_pick_drop_sub: Unexpected Error - ' || SQLERRM);
14685 END IF;
14686
14687 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
14688 END validate_pick_drop_sub;
14689
14690 PROCEDURE create_lock_mmtt_temp_id(lock_name IN VARCHAR2, x_return_status OUT NOCOPY VARCHAR2) IS
14691 l_lock_id VARCHAR2(50);
14692 lock_result NUMBER;
14693 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14694 BEGIN
14695 IF (l_debug = 1) THEN
14696 mydebug('Inside create_lock_mmtt_temp_id');
14697 END IF;
14698
14699 DBMS_LOCK.allocate_unique(lockname => lock_name, lockhandle => l_lock_id);
14700 lock_result :=
14701 DBMS_LOCK.request --EXCLUSIVE LOCK
14702 (lockhandle => l_lock_id, lockmode => 6, TIMEOUT => 5, -- 5 seconds ???
14703 release_on_commit => TRUE);
14704
14705 IF (l_debug = 1) THEN
14706 mydebug('dbms_lock,lock_result:' || lock_result);
14707 END IF;
14708
14709 IF (lock_result = 0) THEN
14710 IF (l_debug = 1) THEN
14711 mydebug('creating lock mmtt.temp_id, to be used in CTRLBD is successful');
14712 END IF;
14713
14714 x_return_status := fnd_api.g_ret_sts_success;
14715 ELSIF lock_result IN(1, 2) THEN
14716 IF (l_debug = 1) THEN
14717 mydebug('timeout for the creation of user lock or deadlock');
14718 END IF;
14719
14720 fnd_message.set_name('WMS', 'WMS_RECORD_BEING_CHANGED');
14721 fnd_msg_pub.ADD;
14722 RAISE fnd_api.g_exc_error;
14723 END IF;
14724 EXCEPTION
14725 WHEN fnd_api.g_exc_error THEN
14726 x_return_status := fnd_api.g_ret_sts_error;
14727 WHEN OTHERS THEN
14728 x_return_status := fnd_api.g_ret_sts_unexp_error;
14729
14730 IF (l_debug = 1) THEN
14731 mydebug('lock_mmtt_temp_id - ' || SQLERRM);
14732 END IF;
14733 END create_lock_mmtt_temp_id;
14734
14735 /*
14736 -- This procedure will be used for distributing the quantity
14737 -- picked (in one or more parent MMTT lines) to the original
14738 -- child MMTT lines (again one or more)
14739 */
14740 PROCEDURE bulk_pick(
14741 p_temp_id IN NUMBER
14742 , p_txn_hdr_id IN NUMBER
14743 , p_org_id IN NUMBER
14744 , p_pick_qty_remaining IN NUMBER
14745 , p_user_id IN NUMBER
14746 , x_new_txn_hdr_id OUT NOCOPY NUMBER
14747 , x_return_status OUT NOCOPY VARCHAR2
14748 , x_msg_count OUT NOCOPY NUMBER
14749 , x_msg_data OUT NOCOPY VARCHAR2
14750 , p_reason_id IN NUMBER --Added bug 3765153
14751 ) IS
14752 CURSOR c_parent_mmtt_lines IS
14753 SELECT mmtt.transaction_temp_id
14754 , mmtt.inventory_item_id
14755 , mmtt.subinventory_code
14756 , mmtt.locator_id
14757 , NVL(mmtt.content_lpn_id, mmtt.lpn_id)
14758 , mmtt.transfer_lpn_id
14759 , mmtt.transaction_uom
14760 , mmtt.transaction_quantity
14761 , mmtt.primary_quantity
14762 FROM mtl_material_transactions_temp mmtt
14763 WHERE mmtt.transaction_header_id = p_txn_hdr_id
14764 AND mmtt.organization_id = p_org_id
14765 AND mmtt.transaction_quantity > 0
14766 AND mmtt.parent_line_id is NULL --Added bug3765153 to ensure only parent line are picked
14767 ORDER BY mmtt.transaction_quantity DESC;
14768
14769 CURSOR c_child_mmtt_lines IS
14770 SELECT mmtt.transaction_temp_id
14771 , mmtt.transaction_uom
14772 , mmtt.transaction_quantity
14773 , mmtt.primary_quantity
14774 FROM mtl_material_transactions_temp mmtt
14775 WHERE mmtt.parent_line_id = p_temp_id
14776 AND mmtt.organization_id = p_org_id
14777 ORDER BY mmtt.transaction_quantity DESC;
14778
14779 CURSOR unpicked_child_mmtt_lines(p_parent_line_id NUMBER,p_org_id NUMBER) IS
14780 SELECT mmtt.transaction_temp_id
14781 FROM mtl_material_transactions_temp mmtt
14782 WHERE mmtt.organization_id = p_org_id
14783 AND mmtt.parent_line_id = p_parent_line_id; --Added bug3765153 to determine and back order unpicked lines
14784
14785 l_parent_txn_qty NUMBER;
14786 l_child_txn_qty NUMBER := 0; --bug3765153 defaulted to 0
14787 l_parent_pri_qty NUMBER;
14788 l_child_pri_qty NUMBER;
14789 l_parent_uom VARCHAR2(10);
14790 l_child_uom VARCHAR2(10);
14791 l_parent_txn_temp_id NUMBER;
14792 l_child_txn_temp_id NUMBER;
14793 l_item_id NUMBER;
14794 l_parent_sub_code VARCHAR2(30);
14795 l_parent_loc_id NUMBER;
14796 l_lpn_id NUMBER;
14797 l_transfer_lpn_id NUMBER;
14798 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
14799 l_new_temp_id NUMBER; --Added bug3765153
14800 BEGIN
14801 x_return_status := fnd_api.g_ret_sts_success;
14802
14803 IF l_debug = 1 THEN
14804 mydebug('Dispatching Bulk Pick Tasks for TxnHdrID = ' || p_txn_hdr_id || ' : TxnTempID = ' || p_temp_id);
14805 END IF;
14806
14807 SELECT mtl_material_transactions_s.NEXTVAL
14808 INTO x_new_txn_hdr_id
14809 FROM DUAL;
14810
14811 OPEN c_parent_mmtt_lines;
14812
14813 LOOP
14814 FETCH c_parent_mmtt_lines INTO l_parent_txn_temp_id
14815 , l_item_id
14816 , l_parent_sub_code
14817 , l_parent_loc_id
14818 , l_lpn_id
14819 , l_transfer_lpn_id
14820 , l_parent_uom
14821 , l_parent_txn_qty
14822 , l_parent_pri_qty;
14823 EXIT WHEN c_parent_mmtt_lines%NOTFOUND;
14824 OPEN c_child_mmtt_lines;
14825
14826 LOOP
14827 IF l_child_txn_qty = 0 THEN --Added bug3765153
14828 IF l_debug = 1 THEN
14829 mydebug('Bulk Pick:Fethcing new child record');
14830 END IF;
14831 FETCH c_child_mmtt_lines INTO l_child_txn_temp_id, l_child_uom, l_child_txn_qty, l_child_pri_qty;
14832 EXIT WHEN c_child_mmtt_lines%NOTFOUND;
14833 END IF;
14834
14835 IF l_debug = 1 THEN
14836 mydebug('Child Temp ID = ' || l_child_txn_temp_id);
14837 mydebug('Current Parent Qty = ' || l_parent_txn_qty || ' : Child Qty = ' || l_child_txn_qty);
14838 END IF;
14839
14840 IF l_parent_uom <> l_child_uom THEN
14841 l_child_txn_qty :=
14842 inv_convert.inv_um_convert(
14843 item_id => l_item_id
14844 , PRECISION => NULL
14845 , from_quantity => l_child_txn_qty
14846 , from_unit => l_child_uom
14847 , to_unit => l_parent_uom
14848 , from_name => NULL
14849 , to_name => NULL
14850 );
14851 END IF;
14852
14853 IF l_parent_txn_qty >= l_child_txn_qty THEN
14854 UPDATE mtl_material_transactions_temp mmtt
14855 SET mmtt.transaction_header_id = x_new_txn_hdr_id
14856 , mmtt.transfer_lpn_id = l_transfer_lpn_id
14857 , mmtt.lpn_id = l_lpn_id
14858 , mmtt.parent_line_id = l_parent_txn_temp_id --Modified from NULL bug3765153
14859 , mmtt.subinventory_code = l_parent_sub_code
14860 , mmtt.locator_id = l_parent_loc_id
14861 , mmtt.transaction_uom = l_parent_uom
14862 , mmtt.last_update_date = SYSDATE
14863 , mmtt.last_updated_by = p_user_id
14864 WHERE mmtt.transaction_temp_id = l_child_txn_temp_id;
14865
14866 l_parent_txn_qty := l_parent_txn_qty - l_child_txn_qty;
14867 l_parent_pri_qty := l_parent_pri_qty - l_child_pri_qty;
14868 l_child_txn_qty := 0;
14869 l_child_pri_qty := 0;
14870 EXIT WHEN l_parent_txn_qty = 0;
14871 ELSE -- Current Child Qty is greater than Parent Picked Qty
14872
14873 select mtl_material_transactions_s.NEXTVAL
14874 into l_new_temp_id
14875 from dual; --Added bug3765153
14876
14877 INSERT INTO mtl_material_transactions_temp
14878 (
14879 transaction_header_id
14880 , transaction_temp_id
14881 , source_code
14882 , source_line_id
14883 , transaction_mode
14884 , lock_flag
14885 , last_update_date
14886 , last_updated_by
14887 , creation_date
14888 , created_by
14889 , last_update_login
14890 , request_id
14891 , program_application_id
14892 , program_id
14893 , program_update_date
14894 , inventory_item_id
14895 , revision
14896 , organization_id
14897 , subinventory_code
14898 , locator_id
14899 , transaction_quantity
14900 , primary_quantity
14901 , transaction_uom
14902 , transaction_cost
14903 , transaction_type_id
14904 , transaction_action_id
14905 , transaction_source_type_id
14906 , transaction_source_id
14907 , transaction_source_name
14908 , transaction_date
14909 , acct_period_id
14910 , distribution_account_id
14911 , transaction_reference
14912 , requisition_line_id
14913 , requisition_distribution_id
14914 , reason_id
14915 , lot_number
14916 , lot_expiration_date
14917 , serial_number
14918 , receiving_document
14919 , demand_id
14920 , rcv_transaction_id
14921 , move_transaction_id
14922 , completion_transaction_id
14923 , wip_entity_type
14924 , schedule_id
14925 , repetitive_line_id
14926 , employee_code
14927 , primary_switch
14928 , schedule_update_code
14929 , setup_teardown_code
14930 , item_ordering
14931 , negative_req_flag
14932 , operation_seq_num
14933 , picking_line_id
14934 , trx_source_line_id
14935 , trx_source_delivery_id
14936 , physical_adjustment_id
14937 , cycle_count_id
14938 , rma_line_id
14939 , customer_ship_id
14940 , currency_code
14941 , currency_conversion_rate
14942 , currency_conversion_type
14943 , currency_conversion_date
14944 , ussgl_transaction_code
14945 , vendor_lot_number
14946 , encumbrance_account
14947 , encumbrance_amount
14948 , ship_to_location
14949 , shipment_number
14950 , transfer_cost
14951 , transportation_cost
14952 , transportation_account
14953 , freight_code
14954 , containers
14955 , waybill_airbill
14956 , expected_arrival_date
14957 , transfer_subinventory
14958 , transfer_organization
14959 , transfer_to_location
14960 , new_average_cost
14961 , value_change
14962 , percentage_change
14963 , material_allocation_temp_id
14964 , demand_source_header_id
14965 , demand_source_line
14966 , demand_source_delivery
14967 , item_segments
14968 , item_description
14969 , item_trx_enabled_flag
14970 , item_location_control_code
14971 , item_restrict_subinv_code
14972 , item_restrict_locators_code
14973 , item_revision_qty_control_code
14974 , item_primary_uom_code
14975 , item_uom_class
14976 , item_shelf_life_code
14977 , item_shelf_life_days
14978 , item_lot_control_code
14979 , item_serial_control_code
14980 , item_inventory_asset_flag
14981 , allowed_units_lookup_code
14982 , department_id
14983 , department_code
14984 , wip_supply_type
14985 , supply_subinventory
14986 , supply_locator_id
14987 , valid_subinventory_flag
14988 , valid_locator_flag
14989 , locator_segments
14990 , current_locator_control_code
14991 , number_of_lots_entered
14992 , wip_commit_flag
14993 , next_lot_number
14994 , lot_alpha_prefix
14995 , next_serial_number
14996 , serial_alpha_prefix
14997 , shippable_flag
14998 , posting_flag
14999 , required_flag
15000 , process_flag
15001 , ERROR_CODE
15002 , error_explanation
15003 , attribute_category
15004 , attribute1
15005 , attribute2
15006 , attribute3
15007 , attribute4
15008 , attribute5
15009 , attribute6
15010 , attribute7
15011 , attribute8
15012 , attribute9
15013 , attribute10
15014 , attribute11
15015 , attribute12
15016 , attribute13
15017 , attribute14
15018 , attribute15
15019 , movement_id
15020 , reservation_quantity
15021 , shipped_quantity
15022 , transaction_line_number
15023 , task_id
15024 , to_task_id
15025 , source_task_id
15026 , project_id
15027 , source_project_id
15028 , pa_expenditure_org_id
15029 , to_project_id
15030 , expenditure_type
15031 , final_completion_flag
15032 , transfer_percentage
15033 , transaction_sequence_id
15034 , material_account
15035 , material_overhead_account
15036 , resource_account
15037 , outside_processing_account
15038 , overhead_account
15039 , flow_schedule
15040 , cost_group_id
15041 , demand_class
15042 , qa_collection_id
15043 , kanban_card_id
15044 , overcompletion_transaction_id
15045 , overcompletion_primary_qty
15046 , overcompletion_transaction_qty
15047 , end_item_unit_number
15048 , scheduled_payback_date
15049 , line_type_code
15050 , parent_transaction_temp_id
15051 , put_away_strategy_id
15052 , put_away_rule_id
15053 , pick_strategy_id
15054 , pick_rule_id
15055 , common_bom_seq_id
15056 , common_routing_seq_id
15057 , cost_type_id
15058 , org_cost_group_id
15059 , move_order_line_id
15060 , task_group_id
15061 , pick_slip_number
15062 , reservation_id
15063 , transaction_status
15064 , transfer_cost_group_id
15065 , lpn_id
15066 , transfer_lpn_id
15067 , content_lpn_id
15068 , cartonization_id
15069 , standard_operation_id
15070 , wms_task_type
15071 , task_priority
15072 , container_item_id
15073 , operation_plan_id
15074 , parent_line_id
15075 )
15076 (SELECT transaction_header_id
15077 , l_new_temp_id --Changed from mtl_material_transactions_s.NEXTVAL bug3765153
15078 , source_code
15079 , source_line_id
15080 , transaction_mode
15081 , lock_flag
15082 , SYSDATE
15083 , last_updated_by
15084 , SYSDATE
15085 , created_by
15086 , last_update_login
15087 , request_id
15088 , program_application_id
15089 , program_id
15090 , program_update_date
15091 , inventory_item_id
15092 , revision
15093 , organization_id
15094 , subinventory_code
15095 , locator_id
15096 , l_child_pri_qty - l_parent_pri_qty
15097 , l_child_txn_qty - l_parent_txn_qty
15098 , l_parent_uom
15099 , transaction_cost
15100 , transaction_type_id
15101 , transaction_action_id
15102 , transaction_source_type_id
15103 , transaction_source_id
15104 , transaction_source_name
15105 , transaction_date
15106 , acct_period_id
15107 , distribution_account_id
15108 , transaction_reference
15109 , requisition_line_id
15110 , requisition_distribution_id
15111 , reason_id
15112 , lot_number
15113 , lot_expiration_date
15114 , serial_number
15115 , receiving_document
15116 , demand_id
15117 , rcv_transaction_id
15118 , move_transaction_id
15119 , completion_transaction_id
15120 , wip_entity_type
15121 , schedule_id
15122 , repetitive_line_id
15123 , employee_code
15124 , primary_switch
15125 , schedule_update_code
15126 , setup_teardown_code
15127 , item_ordering
15128 , negative_req_flag
15129 , operation_seq_num
15130 , picking_line_id
15131 , trx_source_line_id
15132 , trx_source_delivery_id
15133 , physical_adjustment_id
15134 , cycle_count_id
15135 , rma_line_id
15136 , customer_ship_id
15137 , currency_code
15138 , currency_conversion_rate
15139 , currency_conversion_type
15140 , currency_conversion_date
15141 , ussgl_transaction_code
15142 , vendor_lot_number
15143 , encumbrance_account
15144 , encumbrance_amount
15145 , ship_to_location
15146 , shipment_number
15147 , transfer_cost
15148 , transportation_cost
15149 , transportation_account
15150 , freight_code
15151 , containers
15152 , waybill_airbill
15153 , expected_arrival_date
15154 , transfer_subinventory
15155 , transfer_organization
15156 , transfer_to_location
15157 , new_average_cost
15158 , value_change
15159 , percentage_change
15160 , material_allocation_temp_id
15161 , demand_source_header_id
15162 , demand_source_line
15163 , demand_source_delivery
15164 , item_segments
15165 , item_description
15166 , item_trx_enabled_flag
15167 , item_location_control_code
15168 , item_restrict_subinv_code
15169 , item_restrict_locators_code
15170 , item_revision_qty_control_code
15171 , item_primary_uom_code
15172 , item_uom_class
15173 , item_shelf_life_code
15174 , item_shelf_life_days
15175 , item_lot_control_code
15176 , item_serial_control_code
15177 , item_inventory_asset_flag
15178 , allowed_units_lookup_code
15179 , department_id
15180 , department_code
15181 , wip_supply_type
15182 , supply_subinventory
15183 , supply_locator_id
15184 , valid_subinventory_flag
15185 , valid_locator_flag
15186 , locator_segments
15187 , current_locator_control_code
15188 , number_of_lots_entered
15189 , wip_commit_flag
15190 , next_lot_number
15191 , lot_alpha_prefix
15192 , next_serial_number
15193 , serial_alpha_prefix
15194 , shippable_flag
15195 , posting_flag
15196 , required_flag
15197 , process_flag
15198 , ERROR_CODE
15199 , error_explanation
15200 , attribute_category
15201 , attribute1
15202 , attribute2
15203 , attribute3
15204 , attribute4
15205 , attribute5
15206 , attribute6
15207 , attribute7
15208 , attribute8
15209 , attribute9
15210 , attribute10
15211 , attribute11
15212 , attribute12
15213 , attribute13
15214 , attribute14
15215 , attribute15
15216 , movement_id
15217 , reservation_quantity
15218 , shipped_quantity
15219 , transaction_line_number
15220 , task_id
15221 , to_task_id
15222 , source_task_id
15223 , project_id
15224 , source_project_id
15225 , pa_expenditure_org_id
15226 , to_project_id
15227 , expenditure_type
15228 , final_completion_flag
15229 , transfer_percentage
15230 , transaction_sequence_id
15231 , material_account
15232 , material_overhead_account
15233 , resource_account
15234 , outside_processing_account
15235 , overhead_account
15236 , flow_schedule
15237 , cost_group_id
15238 , demand_class
15239 , qa_collection_id
15240 , kanban_card_id
15241 , overcompletion_transaction_id
15242 , overcompletion_primary_qty
15243 , overcompletion_transaction_qty
15244 , end_item_unit_number
15245 , scheduled_payback_date
15246 , line_type_code
15247 , parent_transaction_temp_id
15248 , put_away_strategy_id
15249 , put_away_rule_id
15250 , pick_strategy_id
15251 , pick_rule_id
15252 , common_bom_seq_id
15253 , common_routing_seq_id
15254 , cost_type_id
15255 , org_cost_group_id
15256 , move_order_line_id
15257 , task_group_id
15258 , pick_slip_number
15259 , reservation_id
15260 , transaction_status
15261 , transfer_cost_group_id
15262 , lpn_id
15263 , transfer_lpn_id
15264 , content_lpn_id
15265 , cartonization_id
15266 , standard_operation_id
15267 , wms_task_type
15268 , task_priority
15269 , container_item_id
15270 , operation_plan_id
15271 , parent_line_id
15272 FROM mtl_material_transactions_temp
15273 WHERE transaction_temp_id = l_child_txn_temp_id);
15274
15275 UPDATE mtl_material_transactions_temp mmtt
15276 SET mmtt.transaction_header_id = x_new_txn_hdr_id
15277 , mmtt.transaction_quantity = l_parent_txn_qty
15278 , mmtt.primary_quantity = l_parent_pri_qty
15279 , mmtt.parent_line_id = NULL --l_parent_txn_temp_id --Modified from NULL bug3765153
15280 , mmtt.transfer_lpn_id = l_transfer_lpn_id
15281 , mmtt.lpn_id = l_lpn_id
15282 , mmtt.subinventory_code = l_parent_sub_code
15283 , mmtt.locator_id = l_parent_loc_id
15284 , mmtt.transaction_uom = l_parent_uom
15285 , mmtt.last_update_date = SYSDATE
15286 , mmtt.last_updated_by = p_user_id
15287 WHERE mmtt.transaction_temp_id = l_child_txn_temp_id;
15288
15289 --Added bug 3765153
15290 l_child_txn_temp_id := l_new_temp_id;
15291 l_child_pri_qty := l_child_pri_qty - l_parent_pri_qty;
15292 l_child_txn_qty := l_child_txn_qty - l_parent_txn_qty;
15293 l_parent_txn_qty := 0;
15294 l_parent_pri_qty := 0;
15295
15296 IF l_debug = 1 THEN
15297 mydebug('BULK_PICK:new MMTT tmp id:'||l_new_temp_id);
15298 mydebug('BULK_PICK:new child pri qty:'||l_child_pri_qty);
15299 mydebug('BULK_PICK:new child txn qty:'||l_child_txn_qty);
15300 END IF;
15301 --end bug 3765153
15302 EXIT;
15303 END IF;
15304 END LOOP;
15305
15306 CLOSE c_child_mmtt_lines;
15307 END LOOP;
15308
15309 CLOSE c_parent_mmtt_lines;
15310
15311 IF l_debug = 1 THEN
15312 mydebug('Dispatching Child Tasks');
15313 END IF;
15314
15315 -- Dispatching Picked Child Tasks
15316 INSERT INTO wms_dispatched_tasks
15317 (
15318 task_id
15319 , transaction_temp_id
15320 , organization_id
15321 , user_task_type
15322 , person_id
15323 , effective_start_date
15324 , effective_end_date
15325 , equipment_id
15326 , equipment_instance
15327 , person_resource_id
15328 , machine_resource_id
15329 , status
15330 , dispatched_time
15331 , last_update_date
15332 , last_updated_by
15333 , creation_date
15334 , created_by
15335 , task_type
15336 , loaded_time
15337 , operation_plan_id
15338 , move_order_line_id
15339 )
15340 (SELECT wms_dispatched_tasks_s.NEXTVAL
15341 , mmtt.transaction_temp_id
15342 , mmtt.organization_id
15343 , wdt.user_task_type
15344 , wdt.person_id
15345 , wdt.effective_start_date
15346 , wdt.effective_end_date
15347 , wdt.equipment_id
15348 , wdt.equipment_instance
15349 , wdt.person_resource_id
15350 , wdt.machine_resource_id
15351 , 4
15352 , wdt.dispatched_time
15353 , SYSDATE
15354 , p_user_id
15355 , SYSDATE
15356 , p_user_id
15357 , wdt.task_type
15358 , SYSDATE
15359 , mmtt.operation_plan_id
15360 , mmtt.move_order_line_id
15361 FROM wms_dispatched_tasks wdt, mtl_material_transactions_temp mmtt
15362 WHERE wdt.transaction_temp_id = p_temp_id
15363 AND mmtt.transaction_header_id = x_new_txn_hdr_id);
15364
15365 DELETE FROM wms_dispatched_tasks wdt
15366 WHERE wdt.transaction_temp_id IN(SELECT mmtt.transaction_temp_id
15367 FROM mtl_material_transactions_temp mmtt
15368 WHERE mmtt.transaction_header_id = p_txn_hdr_id
15369 AND mmtt.organization_id = p_org_id);
15370
15371 --Added bug 3765153 to clean up lines with remaining qty
15372 IF p_pick_qty_remaining > 0 THEN
15373 for mmtt_rec in unpicked_child_mmtt_lines(p_temp_id,p_org_id) LOOP
15374 mydebug('BULK_PICK:calling cleanup_task for mmtt line:'||mmtt_rec.transaction_temp_id);
15375 cleanup_task(
15376 p_temp_id => mmtt_rec.transaction_temp_id
15377 , p_qty_rsn_id => p_reason_id
15378 , p_user_id => p_user_id
15379 , x_return_status => x_return_status
15380 , x_msg_count => x_msg_count
15381 , x_msg_data => x_msg_data
15382 );
15383
15384 IF x_return_status <> fnd_api.g_ret_sts_success THEN
15385 IF l_debug = 1 THEN
15386 mydebug('BULK_PICK: Error occurred while calling cleanup tasK ');
15387 END IF;
15388 RAISE fnd_api.g_exc_error;
15389 END IF;
15390
15391 END LOOP;
15392 END IF;
15393 --End bug3765153
15394
15395 IF l_debug = 1 THEN
15396 mydebug('Deleting the Parent Task and Parent Line');
15397 END IF;
15398
15399 -- Deleting Parent Tasks. Once loaded, only Child Tasks are considered.
15400
15401 DELETE FROM mtl_material_transactions_temp mmtt
15402 WHERE mmtt.transaction_header_id = p_txn_hdr_id
15403 AND mmtt.organization_id = p_org_id;
15404
15405 -- nullify the parent_line_id for the children lines
15406 -- since the parent lines are gone Bug3765153
15407 update mtl_material_transactions_temp
15408 set parent_line_id = null
15409 where transaction_header_id = x_new_txn_hdr_id;
15410
15411 EXCEPTION
15412 WHEN OTHERS THEN
15413 x_return_status := fnd_api.g_ret_sts_unexp_error;
15414 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
15415
15416 IF (l_debug = 1) THEN
15417 mydebug('Unexpected Error occurred - ' || SQLERRM);
15418 END IF;
15419 END bulk_pick;
15420
15421 PROCEDURE call_workflow(
15422 p_rsn_id IN NUMBER
15423 , p_calling_program IN VARCHAR2
15424 , p_org_id IN NUMBER
15425 , p_tmp_id IN NUMBER DEFAULT NULL
15426 , p_quantity_picked IN NUMBER DEFAULT NULL
15427 , p_dest_sub IN VARCHAR2 DEFAULT NULL
15428 , p_dest_loc IN NUMBER DEFAULT NULL
15429 , x_return_status OUT NOCOPY VARCHAR2
15430 , x_msg_count OUT NOCOPY NUMBER
15431 , x_msg_data OUT NOCOPY VARCHAR2
15432 , x_wf OUT NOCOPY NUMBER
15433 ) IS
15434 l_wf NUMBER := 0;
15435 BEGIN
15436 mydebug('call_workflow :in ');
15437 x_return_status := fnd_api.g_ret_sts_success;
15438
15439 BEGIN
15440 SELECT 1
15441 INTO l_wf
15442 FROM mtl_transaction_reasons
15443 WHERE reason_id = p_rsn_id
15444 AND workflow_name IS NOT NULL
15445 AND workflow_name <> ' '
15446 AND workflow_process IS NOT NULL
15447 AND workflow_process <> ' ';
15448 EXCEPTION
15449 WHEN NO_DATA_FOUND THEN
15450 l_wf := 0;
15451 END;
15452
15453 mydebug('call_workflow- p_rsn_id: ' || p_rsn_id || ':l_wf: ' || l_wf);
15454 x_wf := l_wf; -- Bug 2924823 H to I
15455 IF l_wf > 0 THEN
15456 mydebug(' call workflow : WF exists for this reason id : ' || p_rsn_id || ':');
15457 mydebug(' call workflow : Before Calling WF Wrapper for Qty Discrepancy ');
15458
15459 -- Calling Workflow
15460
15461 IF p_rsn_id > 0 THEN
15462 mydebug('call workflow: Calling ... workflow wrapper');
15463 wms_workflow_wrappers.wf_wrapper(
15464 p_api_version => 1.0
15465 , p_init_msg_list => fnd_api.g_false
15466 , p_commit => fnd_api.g_false
15467 , x_return_status => x_return_status
15468 , x_msg_count => x_msg_count
15469 , x_msg_data => x_msg_data
15470 , p_org_id => p_org_id
15471 , p_rsn_id => p_rsn_id
15472 , p_calling_program => p_calling_program
15473 , p_tmp_id => p_tmp_id
15474 , p_quantity_picked => p_quantity_picked
15475 , p_dest_sub => p_dest_sub
15476 , p_dest_loc => p_dest_loc
15477 );
15478
15479 mydebug('call_workflow : After Calling WF Wrapper');
15480 -- Bug 2924823 H to I
15481 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
15482 mydebug('call_workflow : Error callinf WF wrapper');
15483 FND_MESSAGE.SET_NAME('WMS','WMS_WORK_FLOW_FAIL');
15484 FND_MSG_PUB.ADD;
15485 RAISE FND_API.g_exc_unexpected_error;
15486
15487 ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
15488 mydebug('call_workflow : Error calling WF wrapper');
15489 FND_MESSAGE.SET_NAME('WMS','WMS_WORK_FLOW_FAIL');
15490 FND_MSG_PUB.ADD;
15491 RAISE FND_API.G_EXC_ERROR;
15492 END IF;
15493 END IF;
15494 END IF;
15495 END call_workflow;
15496
15497 /*Added to validate cost group comingle bug3813165*/
15498 procedure validate_loaded_lpn_cg( p_organization_id IN NUMBER,
15499 p_inventory_item_id IN NUMBER,
15500 p_subinventory_code IN VARCHAR2,
15501 p_locator_id IN NUMBER,
15502 p_revision IN VARCHAR2,
15503 p_lot_number IN VARCHAR2,
15504 p_lpn_id IN NUMBER,
15505 p_transfer_lpn_id IN NUMBER,
15506 p_lot_control IN NUMBER,
15507 p_revision_control IN NUMBER,
15508 x_commingle_exist OUT nocopy VARCHAR2,
15509 x_return_status OUT nocopy VARCHAR2)
15510 IS
15511 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15512 l_cur_cost_group_id NUMBER := NULL;
15513 l_exist_cost_group_id NUMBER := NULL;
15514 l_sub VARCHAR2(20);
15515 l_loc NUMBER;
15516 l_rev VARCHAR2(4);
15517 l_lpn NUMBER;
15518 l_ser VARCHAR2(20);
15519 l_lot VARCHAR2(20);
15520 BEGIN
15521 IF (l_debug = 1) THEN
15522 mydebug( 'In check_cg_commingle... ');
15523 mydebug('p_organization_id'||p_organization_id);
15524 mydebug('p_inventory_item_id'||p_inventory_item_id);
15525 mydebug('p_subinventory_code'||p_subinventory_code);
15526 mydebug('p_locator_id'||p_locator_id);
15527 mydebug('p_revision'||p_revision);
15528 mydebug('p_lot_number'||p_lot_number);
15529 mydebug('p_transfer_lpn_id'||p_transfer_lpn_id);
15530 mydebug('p_lpn_id'||p_lpn_id);
15531 mydebug('p_lot_control'||p_lot_control);
15532 mydebug('p_revision_control'||p_revision_control);
15533 END IF;
15534
15535 x_return_status := fnd_api.g_ret_sts_success;
15536 x_commingle_exist := 'N';
15537
15538 IF p_lot_control = 1 THEN
15539 select mmtt.subinventory_code,
15540 mmtt.locator_id,
15541 mmtt.revision,
15542 mmtt.lpn_id,
15543 null,
15544 null
15545 INTO l_sub,l_loc,l_rev,l_lpn,l_ser,l_lot
15546 from mtl_material_Transactions_temp mmtt
15547 where mmtt.inventory_item_id = p_inventory_item_id
15548 and mmtt.organization_id = p_organization_id
15549 and mmtt.transfer_lpn_id = p_transfer_lpn_id
15550 and mmtt.content_lpn_id is null
15551 and decode(p_revision_control,2,mmtt.revision,1,'~~') = nvl(p_revision,'~~')
15552 and rownum<2;
15553 ELSE
15554 select mmtt.subinventory_code,
15555 mmtt.locator_id,
15556 mmtt.revision,
15557 mmtt.lpn_id,
15558 null,
15559 mtlt.lot_number
15560 INTO l_sub,l_loc,l_rev,l_lpn,l_ser,l_lot
15561 from mtl_material_Transactions_temp mmtt,
15562 mtl_transaction_lots_temp mtlt
15563 where mmtt.inventory_item_id = p_inventory_item_id
15564 and mmtt.organization_id = p_organization_id
15565 and mmtt.transfer_lpn_id = p_transfer_lpn_id
15566 and mmtt.content_lpn_id is null
15567 and decode(p_revision_control,2,mmtt.revision,1,'~~') = nvl(p_revision,'~~')
15568 and mmtt.transaction_temp_id = mtlt.transaction_temp_id
15569 and mtlt.lot_number = p_lot_number
15570 and rownum<2;
15571 END IF;
15572
15573 IF (l_debug = 1) THEN
15574 mydebug( 'Loaded LPN data From MMTT');
15575 mydebug('l_subinventory_code'||l_sub);
15576 mydebug('l_locator_id'||l_loc);
15577 mydebug('l_revision'||l_rev);
15578 mydebug('l_lot_number'||l_lot);
15579 mydebug('l_serial_number'||l_ser);
15580 mydebug('l_lpn_id'||l_lpn);
15581 END IF;
15582
15583 inv_cost_group_update.proc_get_costgroup(
15584 p_organization_id => p_organization_id,
15585 p_inventory_item_id => p_inventory_item_id,
15586 p_subinventory_code => p_subinventory_code,
15587 p_locator_id => p_locator_id,
15588 p_revision => p_revision,
15589 p_lot_number => p_lot_number,
15590 p_serial_number => null,
15591 p_containerized_flag => null,
15592 p_lpn_id => p_lpn_id,
15593 p_transaction_action_id => null,
15594 x_cost_group_id => l_cur_cost_group_id,
15595 x_return_status => x_return_status);
15596 IF x_return_status <> fnd_api.g_ret_sts_success THEN
15597 RAISE fnd_api.g_exc_unexpected_error;
15598 END IF;
15599
15600 inv_cost_group_update.proc_get_costgroup(
15601 p_organization_id => p_organization_id,
15602 p_inventory_item_id => p_inventory_item_id,
15603 p_subinventory_code => l_sub,
15604 p_locator_id => l_loc,
15605 p_revision => l_rev,
15606 p_lot_number => l_lot,
15607 p_serial_number => l_ser,
15608 p_containerized_flag => null,
15609 p_lpn_id => l_lpn,
15610 p_transaction_action_id => null,
15611 x_cost_group_id => l_exist_cost_group_id,
15612 x_return_status => x_return_status);
15613
15614 IF x_return_status <> fnd_api.g_ret_sts_success THEN
15615 RAISE fnd_api.g_exc_unexpected_error;
15616 END IF;
15617
15618 IF l_exist_cost_group_id <> l_cur_cost_group_id THEN
15619 x_return_status := fnd_api.g_ret_sts_success;
15620 x_commingle_exist := 'Y';
15621 END IF;
15622
15623 EXCEPTION
15624 WHEN NO_DATA_FOUND THEN
15625 IF (l_debug = 1) THEN
15626 mydebug('First record being loaded into LPN');
15627 END IF;
15628 x_return_status := fnd_api.g_ret_sts_success;
15629 x_commingle_exist := 'N';
15630 WHEN OTHERS THEN
15631 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
15632 x_commingle_exist := 'Y';
15633 END validate_loaded_lpn_cg;
15634
15635
15636 -- ----------------------------------------------------------------------------------
15637 -- ----------------------------------------------------------------------------------
15638 FUNCTION validate_pick_drop_lpn
15639 ( p_api_version_number IN NUMBER ,
15640 p_init_msg_lst IN VARCHAR2 := fnd_api.g_false ,
15641 p_pick_lpn_id IN NUMBER ,
15642 p_organization_id IN NUMBER ,
15643 p_drop_lpn IN VARCHAR2,
15644 p_drop_sub IN VARCHAR2,
15645 p_drop_loc IN NUMBER)
15646 -- Added sub and loc for validation
15647 RETURN NUMBER
15648
15649 IS
15650 l_dummy VARCHAR2(1) := NULL;
15651
15652 l_api_version_number CONSTANT NUMBER := 1.0;
15653 l_api_name CONSTANT VARCHAR2(30) := 'Validate_Pick_Drop_Lpn';
15654 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
15655
15656 l_drop_lpn_exists BOOLEAN := FALSE;
15657 l_drop_lpn_has_picked_inv BOOLEAN := FALSE;
15658 l_pick_lpn_delivery_id NUMBER := NULL;
15659 l_drop_lpn_delivery_id NUMBER := NULL;
15660 l_line_rows WSH_UTIL_CORE.id_tab_type; -- Added for bug#4106176
15661 l_grouping_rows WSH_UTIL_CORE.id_tab_type; -- Added for bug#4106176
15662
15663 TYPE lpn_rectype is RECORD
15664 (
15665 lpn_id wms_license_plate_numbers.lpn_id%TYPE,
15666 lpn_context wms_license_plate_numbers.lpn_context%TYPE,
15667 subinventory_code wms_license_plate_numbers.subinventory_code%TYPE,
15668 locator_id wms_license_plate_numbers.locator_id%TYPE
15669 );
15670 drop_lpn_rec lpn_rectype;
15671
15672 CURSOR drop_lpn_cursor IS
15673 SELECT lpn_id,
15674 lpn_context,
15675 subinventory_code,
15676 locator_id
15677 FROM wms_license_plate_numbers
15678 WHERE license_plate_number = p_drop_lpn
15679 AND organization_id = p_organization_id;
15680
15681 CURSOR pick_delivery_cursor IS
15682 SELECT wda.delivery_id
15683 FROM wsh_delivery_assignments wda,
15684 wsh_delivery_details wdd,
15685 mtl_material_transactions_temp temp
15686 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
15687 AND wdd.move_order_line_id = temp.move_order_line_id
15688 AND wdd.organization_id = temp.organization_id
15689 AND temp.transfer_lpn_id = p_pick_lpn_id
15690 AND temp.organization_id = p_organization_id ;
15691
15692 CURSOR drop_delivery_cursor(l_lpn_id IN NUMBER) IS
15693 SELECT wda.delivery_id
15694 FROM wsh_delivery_assignments wda,
15695 wsh_delivery_details wdd,
15696 wms_license_plate_numbers lpn
15697 WHERE wda.parent_delivery_detail_id = wdd.delivery_detail_id
15698 AND wdd.lpn_id = lpn.lpn_id
15699 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
15700 AND lpn.outermost_lpn_id = l_lpn_id
15701 AND wdd.organization_id = p_organization_id ;
15702
15703 l_delivery_match_flag NUMBER;
15704
15705 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15706 BEGIN
15707
15708 IF (l_debug = 1) THEN
15709 mydebug ('Start Validate_Pick_Drop_Lpn.');
15710 END IF;
15711
15712 --
15713 -- Initialize API return status to success
15714 --
15715 l_return_status := FND_API.G_RET_STS_SUCCESS;
15716 l_delivery_match_flag := -1;
15717
15718 --
15719 -- Begin validation process:
15720 -- Check if drop lpn exists by trying to retrieve
15721 -- its lpn ID. If it does not exist,
15722 -- no further validations required - return success.
15723 --
15724 OPEN drop_lpn_cursor;
15725 FETCH drop_lpn_cursor INTO drop_lpn_rec;
15726 IF drop_lpn_cursor%NOTFOUND THEN
15727 l_drop_lpn_exists := FALSE;
15728 ELSE
15729 l_drop_lpn_exists := TRUE;
15730 END IF;
15731
15732 IF NOT l_drop_lpn_exists THEN
15733 IF (l_debug = 1) THEN
15734 mydebug ('Drop LPN is a new LPN, no checking required.');
15735 END IF;
15736 RETURN 1;
15737 END IF;
15738
15739 --
15740 -- If the drop lpn was pre-generated, no validations required
15741 --
15742
15743 IF drop_lpn_rec.lpn_context =
15744 WMS_Container_PUB.LPN_CONTEXT_PREGENERATED THEN
15745 --
15746 -- Update the context to "Resides in Inventory" (1)
15747 --
15748 /* UPDATE wms_license_plate_numbers
15749 SET lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
15750 WHERE lpn_id = drop_lpn_rec.lpn_id;*/
15751
15752 IF (l_debug = 1) THEN
15753 mydebug ('Drop LPN is pre-generated, no checking required.');
15754 END IF;
15755 RETURN 1;
15756
15757 ELSIF drop_lpn_rec.lpn_context = WMS_Container_PUB.lpn_context_picked THEN
15758 IF drop_lpn_rec.subinventory_code <> p_drop_sub or
15759 drop_lpn_rec.locator_id <> p_drop_loc THEN
15760 IF (l_debug = 1) THEN
15761 mydebug ('Drop LPN does not belong to the same sub and loc.');
15762 END IF;
15763 RETURN 2; -- Drop LPN resides in another Staging Lane
15764 END IF;
15765 END IF;
15766
15767 IF drop_lpn_rec.lpn_context =
15768 WMS_Container_PUB.LPN_LOADED_FOR_SHIPMENT THEN
15769 IF (l_debug = 1) THEN
15770 mydebug ('Drop LPN is loaded to dock door already');
15771 END IF;
15772 RETURN 4; -- Drop LPN is loaded to dock door already
15773 END IF;
15774
15775 --
15776 -- Drop LPN cannot be the same as the picked LPN
15777 --
15778 IF drop_lpn_rec.lpn_id = p_pick_lpn_id THEN
15779 IF (l_debug = 1) THEN
15780 mydebug ('Drop LPN cannot be the picked LPN.');
15781 END IF;
15782 RETURN 3; -- Drop LPN Cannot be the same as Pick LPN
15783 END IF;
15784
15785
15786 --
15787 -- Now check if the picked LPN and drop LPN
15788 -- belong to different deliveries
15789 --
15790 OPEN pick_delivery_cursor;
15791 LOOP
15792 FETCH pick_delivery_cursor INTO l_pick_lpn_delivery_id;
15793 EXIT WHEN l_pick_lpn_delivery_id IS NOT NULL OR pick_delivery_cursor%NOTFOUND;
15794 END LOOP;
15795 CLOSE pick_delivery_cursor;
15796
15797 --
15798 -- If the picked LPN is not associated with a delivery yet
15799 -- then no further checking required, return success
15800 --
15801 IF l_pick_lpn_delivery_id is NULL THEN
15802
15803 /*Bug#4106176.The following block is added.*/
15804 BEGIN
15805 SELECT delivery_detail_id
15806 INTO l_line_rows(1)
15807 FROM wsh_delivery_details
15808 WHERE lpn_id = drop_lpn_rec.lpn_id
15809 AND rownum = 1 ;
15810
15811 SELECT wdd.delivery_detail_id
15812 INTO l_line_rows(2)
15813 FROM wsh_delivery_details wdd, Mtl_material_transactions_temp mmtt
15814 WHERE mmtt.move_order_line_id = wdd.move_order_line_id
15815 AND wdd.organization_id = mmtt.organization_id
15816 AND mmtt.organization_id= p_organization_id
15817 AND mmtt.transfer_lpn_id= p_pick_lpn_id
15818 AND rownum = 1 ;
15819
15820 --call to the shipping API.
15821 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping( p_line_rows => l_line_rows,
15822 x_grouping_rows => l_grouping_rows,
15823 x_return_status => l_return_status);
15824 IF (l_debug = 1) THEN
15825 mydebug ('parameters : l_line_rows(1) :'||l_line_rows(1) ||',l_line_rows(2) :' || l_line_rows(2) );
15826 mydebug('count l_grp_rows'|| l_grouping_rows.count);
15827 mydebug('l_grp_rows(1) : '||l_grouping_rows(1) ||',l_grp_rows(2) : '||l_grouping_rows(2) );
15828 END IF;
15829
15830 IF (l_return_status = FND_API.G_RET_STS_SUCCESS AND l_grouping_rows(1) = l_grouping_rows(2) ) THEN
15831 IF (l_debug = 1) THEN
15832 mydebug('The LPN with LPN_ID ' || p_pick_lpn_id || ' can be dropped into LPN_ID '||drop_lpn_rec.lpn_id);
15833 END IF;
15834 RETURN 1; --Validated both LPNs , so return success.
15835 ELSE
15836 IF (l_debug = 1) THEN
15837 mydebug('Picked LPN does not belong to same delivery as Drop LPN. So cannot be dropped');
15838 END IF;
15839 RETURN 0;
15840 END IF;
15841
15842 EXCEPTION
15843 WHEN NO_DATA_FOUND THEN
15844 IF (l_debug = 1) THEN
15845 mydebug('No Data found Exception raised when checking for delivery grouping');
15846 mydebug('Picked LPN is not associated with a delivery, so dont show ANY lpn.');
15847 END IF;
15848 RETURN 0;
15849 WHEN OTHERS THEN
15850 IF (l_debug = 1) THEN
15851 mydebug('Other Exception raised when checking for delivery grouping');
15852 mydebug('Picked LPN is not associated with a delivery, so dont show ANY lpn.');
15853 END IF;
15854 RETURN 0;
15855 END; --End of Fix for bug#4106176
15856 END IF;
15857
15858 --
15859 -- Find the drop LPN's delivery ID
15860 --
15861
15862 OPEN drop_delivery_cursor(drop_lpn_rec.lpn_id);
15863 LOOP
15864 FETCH drop_delivery_cursor INTO l_drop_lpn_delivery_id;
15865 EXIT WHEN drop_delivery_cursor%notfound OR l_delivery_match_flag = 0;
15866
15867 IF l_drop_lpn_delivery_id is NOT NULL THEN
15868
15869 IF l_drop_lpn_delivery_id <> l_pick_lpn_delivery_id THEN
15870 IF (l_debug = 1) THEN
15871 mydebug('Picked and drop LPNs are on different deliveries.');
15872 END IF;
15873
15874 l_delivery_match_flag := 0;
15875 ELSE
15876 --
15877 -- Drop LPN and picked LPN are on the same delivery
15878 -- return success
15879 --
15880 IF (l_debug = 1) THEN
15881 mydebug('Drop and pick LPNs are on the same delivery: '||l_drop_lpn_delivery_id);
15882 END IF;
15883
15884 l_delivery_match_flag := 1;
15885 END IF;
15886 END IF;
15887
15888 END LOOP;
15889 CLOSE drop_delivery_cursor;
15890
15891 IF l_delivery_match_flag = 0 OR l_delivery_match_flag = -1 THEN
15892
15893 RETURN 0;
15894
15895 ELSIF l_delivery_match_flag = 1 THEN
15896
15897 RETURN 1;
15898
15899 END IF;
15900
15901 IF l_return_status =FND_API.g_ret_sts_success THEN
15902 RETURN 1;
15903 ELSE
15904 RETURN 0;
15905 END IF;
15906
15907 EXCEPTION
15908 WHEN fnd_api.g_exc_error THEN
15909
15910 RETURN 0;
15911
15912 WHEN OTHERS THEN
15913
15914 RETURN 0;
15915
15916 END validate_pick_drop_lpn;
15917
15918
15919 PROCEDURE default_pick_drop_lpn
15920 ( p_api_version_number IN NUMBER ,
15921 p_init_msg_lst IN VARCHAR2 := fnd_api.g_false ,
15922 p_pick_lpn_id IN NUMBER ,
15923 p_organization_id IN NUMBER ,
15924 x_lpn_number OUT nocopy VARCHAR2)
15925
15926 IS
15927
15928 l_api_version_number CONSTANT NUMBER := 1.0;
15929 l_api_name CONSTANT VARCHAR2(30) :=
15930 'default_pick_drop_lpn';
15931 l_return_status VARCHAR2(1) :=
15932 fnd_api.g_ret_sts_success;
15933 l_delivery_id NUMBER;
15934 l_drop_sub VARCHAR2(10);
15935 l_drop_loc NUMBER;
15936 l_lpn_id NUMBER;
15937
15938
15939 CURSOR pick_delivery_cursor IS
15940 SELECT wda.delivery_id
15941 FROM wsh_delivery_assignments wda,
15942 wsh_delivery_details wdd,
15943 mtl_material_transactions_temp temp
15944 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
15945 AND wdd.move_order_line_id = temp.move_order_line_id
15946 AND wdd.organization_id = temp.organization_id
15947 AND temp.transfer_lpn_id = p_pick_lpn_id
15948 AND temp.organization_id = p_organization_id;
15949
15950 CURSOR drop_delivery_cursor (l_delivery_id_c IN NUMBER,
15951 l_drop_sub_c IN VARCHAR2,
15952 l_drop_loc_c IN NUMBER ) IS
15953 --Bug Fix 4622935 Added hint as suggested by Ben Chihaoui
15954 SELECT /*+ index(wda WSH_DELIVERY_ASSIGNMENTS_N1) ORDERED USE_NL (WDA WDD WLPN) */ wlpn.outermost_lpn_id
15955 FROM wsh_delivery_assignments wda,
15956 wsh_delivery_details wdd,
15957 wms_license_plate_numbers wlpn
15958 WHERE wda.delivery_id = l_delivery_id_c
15959 AND wda.parent_delivery_detail_id = wdd.delivery_detail_id
15960 AND wdd.organization_id = p_organization_id
15961 AND wdd.lpn_id = wlpn.lpn_id
15962 AND wlpn.subinventory_code = l_drop_sub_c
15963 AND wlpn.locator_id = l_drop_loc_c
15964 AND wlpn.lpn_context = 11
15965 ORDER BY wda.CREATION_DATE DESC ;
15966
15967
15968 delivery_id_rec pick_delivery_cursor%ROWTYPE;
15969 license_plate_rec drop_delivery_cursor%ROWTYPE;
15970
15971 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15972 BEGIN
15973
15974
15975 IF NOT fnd_api.compatible_api_call (l_api_version_number
15976 , p_api_version_number
15977 , l_api_name
15978 , G_PKG_NAME
15979 ) THEN
15980 FND_MESSAGE.SET_NAME('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
15981 FND_MSG_PUB.ADD;
15982 RAISE FND_API.G_EXC_ERROR;
15983 END IF;
15984
15985
15986 l_return_status := FND_API.G_RET_STS_SUCCESS;
15987 --
15988 -- Initialize message list.
15989 --
15990
15991 IF fnd_api.to_boolean(p_init_msg_lst) THEN
15992 fnd_msg_pub.initialize;
15993 END IF;
15994
15995
15996 BEGIN
15997 Select transfer_subinventory, transfer_to_location into l_drop_sub,
15998 l_drop_loc
15999 from mtl_material_transactions_temp
16000 where transfer_lpn_id = p_pick_lpn_id
16001 AND organization_id = p_organization_id;
16002
16003 EXCEPTION
16004 WHEN NO_DATA_FOUND THEN
16005 l_delivery_id := NULL;
16006
16007 WHEN OTHERS THEN
16008 l_delivery_id := NULL;
16009 END;
16010
16011 -- Select the Delivery for the LPN that is being picked
16012
16013 FOR delivery_id_rec IN pick_delivery_cursor
16014 LOOP
16015 l_delivery_id := delivery_id_rec.delivery_id;
16016 EXIT WHEN delivery_id_rec.delivery_id IS NOT NULL OR pick_delivery_cursor%NOTFOUND;
16017 END LOOP;
16018
16019
16020 -- Find the drop LPN's delivery ID
16021 FOR license_plate_rec IN drop_delivery_cursor
16022 (l_delivery_id,l_drop_sub,l_drop_loc )
16023 LOOP
16024 l_lpn_id := license_plate_rec.outermost_lpn_id;
16025 EXIT WHEN license_plate_rec.outermost_lpn_id IS NOT NULL OR drop_delivery_cursor%NOTFOUND;
16026 END LOOP;
16027
16028
16029 BEGIN
16030 SELECT license_plate_number INTO x_lpn_number FROM
16031 wms_license_plate_numbers WHERE lpn_id = l_lpn_id;
16032
16033 EXCEPTION
16034 WHEN NO_DATA_FOUND THEN
16035 x_lpn_number := NULL;
16036
16037 WHEN OTHERS THEN
16038 x_lpn_number := NULL;
16039 END;
16040
16041 END default_pick_drop_lpn;
16042
16043
16044 --BUG14014540 Begin
16045 PROCEDURE process_remaining_wdds_repl(
16046 p_mo_line_id IN NUMBER,
16047 p_organization_id IN NUMBER ) IS
16048
16049 CURSOR wrd_records_for_mo
16050 IS
16051 SELECT DEMAND_LINE_DETAIL_ID, PRIMARY_QUANTITY
16052 FROM wms_replenishment_details
16053 WHERE SOURCE_LINE_ID = p_mo_line_id
16054 AND organization_id = p_organization_id;
16055
16056 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
16057 l_mo_line_status NUMBER;
16058 l_demand_line_detail_id NUMBER;
16059 l_return_status VARCHAR2(1);
16060 l_mmtt_exists NUMBER := -1;
16061 l_bo_qty NUMBER := 0;
16062
16063 -- get the profile value of INV: Fill Kill Move Order
16064 -- 1 = > YES, 2 => NO : Metalink Note : 254705.1
16065 l_kill_mo_profile NUMBER := NVL(FND_PROFILE.VALUE_WNPS('INV_KILL_MOVE_ORDER'),2); -- 14014540 105
16066
16067 BEGIN
16068
16069 SELECT line_status
16070 INTO l_mo_line_status
16071 FROM mtl_txn_request_lines
16072 WHERE line_id = p_mo_line_id
16073 AND organization_id = p_organization_id;
16074
16075 IF (l_debug = 1) THEN
16076 mydebug('Coming to new procedure process_remaining_wdds_repl');
16077 mydebug('l_kill_mo_profile == > '||l_kill_mo_profile);
16078 mydebug('l_mo_line_status -- '||l_mo_line_status);
16079 END IF;
16080
16081 -- Adding Starts 14014540
16082 IF l_mo_line_status <> 5 THEN
16083 /* Scenario : Pick Partial + Curtail Pick */
16084 IF (l_debug = 1) THEN
16085 mydebug('Inside l_mo_line_status not equal to 5 -- ');
16086 END IF;
16087 BEGIN
16088 SELECT COUNT(1) INTO l_mmtt_exists
16089 FROM mtl_material_transactions_temp
16090 WHERE move_order_line_id = p_mo_line_id;
16091 EXCEPTION
16092 WHEN no_data_found THEN
16093 l_mmtt_exists := 0;
16094 END;
16095 END IF;
16096
16097 IF (l_debug = 1) THEN
16098 mydebug('Value of l_mmtt_exists -- '||l_mmtt_exists);
16099 END IF;
16100
16101 -- Adding End 14014540
16102 -- Kill the Repl Move order and Backorder WDD only if INV: Fill-Kill Move Order is set to yes
16103 IF (l_mo_line_status = 5 OR (l_mmtt_exists = 0 AND l_kill_mo_profile = 1)) THEN
16104 IF (l_debug = 1) THEN
16105 mydebug('Passed the conditions for back ordering..Either MO is closed or MMTT does not exist and Fill Kill is Yes ');
16106 END IF;
16107
16108 OPEN wrd_records_for_mo;
16109 LOOP
16110 FETCH wrd_records_for_mo INTO l_demand_line_detail_id, l_bo_qty;
16111 EXIT WHEN wrd_records_for_mo%NOTFOUND;
16112
16113 IF (l_debug = 1) THEN
16114 mydebug('Current Fetched record for backordering.. '||l_demand_line_detail_id);
16115 END IF;
16116
16117 wms_replenishment_pvt.update_wdd_repl_status
16118 (p_deliv_detail_id => l_demand_line_detail_id
16119 , p_repl_status => NULL
16120 , p_deliv_qty => l_bo_qty
16121 , x_return_status => l_return_status );
16122
16123 IF l_return_status <> fnd_api.g_ret_sts_success THEN
16124 IF (l_debug = 1) THEN
16125 mydebug('Error from Delivery_Detail_Action api to mark the WDD as backordered..');
16126 END IF;
16127 END IF;
16128
16129 END LOOP;
16130
16131 IF (l_debug = 1) THEN
16132 mydebug('Deleting the WRDs assosciated with delivery_detail_id ' || l_demand_line_detail_id);
16133 END IF;
16134
16135 DELETE
16136 FROM WMS_REPLENISHMENT_DETAILS --Do only one delete based on MO line rather than multiple deletes based on WDD..
16137 WHERE SOURCE_LINE_ID = p_mo_line_id;
16138
16139 END IF;
16140
16141 IF (l_mo_line_status <> 5 AND l_mmtt_exists = 0 AND l_kill_mo_profile = 1) THEN -- Only if MOL is not closed, no MMTT (There can be loaded MMTT), and Fill Kill Yes
16142 UPDATE mtl_txn_request_lines
16143 SET line_status = 5
16144 WHERE line_id = p_mo_line_id;
16145
16146 IF (l_debug = 1) THEN
16147 mydebug('Closed the move order line - '||p_mo_line_id );
16148 END IF;
16149 END IF;
16150
16151 IF (l_debug = 1) THEN
16152 mydebug('Completed process_remaining_wdds_repl successfully..');
16153 END IF;
16154
16155 EXCEPTION
16156 WHEN OTHERS THEN
16157 IF (l_debug = 1) THEN
16158 mydebug('SQL CODE == '||SQLCODE);
16159 mydebug('SQL ERRM == '||SQLERRM);
16160 END IF;
16161 END process_remaining_wdds_repl;
16162 --BUG14014540 End
16163
16164 END wms_task_dispatch_gen;