[Home] [Help]
PACKAGE BODY: APPS.WMS_TASK_LOAD
Source
1 PACKAGE BODY wms_task_load AS
2 /* $Header: WMSLOADB.pls 120.20.12010000.13 2009/01/21 15:23:46 kjujjuru ship $ */
3
4 -- Global constants
5 g_pkg_name CONSTANT VARCHAR2(30) := 'WMS_TASK_LOAD';
6 l_g_ret_sts_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_error;
7 l_g_ret_sts_unexp_error CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_unexp_error;
8 l_g_ret_sts_success CONSTANT VARCHAR2(30) := fnd_api.g_ret_sts_success;
9
10 l_g_task_pending CONSTANT NUMBER := 1;
11 l_g_task_queued CONSTANT NUMBER := 2;
12 l_g_task_dispatched CONSTANT NUMBER := 3;
13 l_g_task_loaded CONSTANT NUMBER := 4;
14 l_g_task_active CONSTANT NUMBER := 9;
15
16 l_g_decimal_precision CONSTANT NUMBER := 5;
17 l_g_exception_short CONSTANT VARCHAR2(30):= 'SHORT';
18 l_g_exception_over CONSTANT VARCHAR2(30):= 'OVER';
19 l_g_action_split CONSTANT VARCHAR2(30):= 'SPLIT';
20 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
21 l_g_action_load_single CONSTANT VARCHAR2(80):= 'LOAD_SINGLE';
22 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
23 l_g_action_load_multiple CONSTANT VARCHAR2(80):= 'LOAD_MULTIPLE';
24
25 g_debug NUMBER := 1;
26
27 -- Forward declarations
28 PROCEDURE proc_insert_update_task
29 (p_action IN VARCHAR2
30 ,p_insert IN VARCHAR2
31 ,p_update IN VARCHAR2
32 ,p_temp_id IN NUMBER
33 ,p_new_temp_id IN NUMBER
34 ,p_merge_temp_id IN NUMBER
35 ,p_task_status IN NUMBER
36 ,p_user_id IN NUMBER
37 ,x_return_status OUT NOCOPY VARCHAR2
38 ,x_msg_count OUT NOCOPY NUMBER
39 ,x_msg_data OUT NOCOPY VARCHAR2);
40
41 PROCEDURE proc_insert_update_mmtt
42 (p_action IN VARCHAR2
43 ,p_insert IN VARCHAR2
44 ,p_update IN VARCHAR2
45 ,p_organization_id IN NUMBER
46 ,p_user_id IN NUMBER
47 ,p_transaction_header_id IN NUMBER
48 ,p_transaction_temp_id IN NUMBER
49 ,p_transaction_temp_id_to_merge IN NUMBER
50 ,p_lpn_id IN NUMBER
51 ,p_content_lpn_id IN NUMBER
52 ,p_transfer_lpn_id IN NUMBER
53 ,p_confirmed_sub IN VARCHAR2
54 ,p_confirmed_locator_id IN NUMBER
55 ,p_confirmed_uom IN VARCHAR2
56 ,p_suggested_uom IN VARCHAR2
57 ,p_primary_uom IN VARCHAR2
58 ,p_inventory_item_id IN NUMBER
59 ,p_revision IN VARCHAR2
60 ,p_confirmed_trx_qty IN NUMBER
61 ,p_confirmed_lots IN VARCHAR2
62 ,p_confirmed_lot_trx_qty IN VARCHAR2
63 ,p_confirmed_sec_uom IN VARCHAR2
64 ,p_confirmed_sec_qty IN VARCHAR2
65 ,p_confirmed_serials IN VARCHAR2
66 ,p_container_item_id IN NUMBER
67 ,p_wms_task_status IN NUMBER
68 ,p_lpn_match IN NUMBER
69 ,p_lpn_match_lpn_id IN NUMBER
70 ,p_serial_allocated_flag IN VARCHAR2
71 ,p_lot_controlled IN VARCHAR2 -- Y/N
72 ,p_serial_controlled IN VARCHAR2 -- Y/N
73 ,p_exception IN VARCHAR2 -- OVER/SHORT
74 ,p_parent_lpn_id IN NUMBER
75 ,x_new_transaction_temp_id OUT NOCOPY NUMBER
76 ,x_return_status OUT NOCOPY VARCHAR2
77 ,x_msg_count OUT NOCOPY NUMBER
78 ,x_msg_data OUT NOCOPY VARCHAR2);
79
80 PROCEDURE proc_process_confirmed_lots
81 ( p_action IN VARCHAR2
82 ,p_insert IN VARCHAR2
83 ,p_update IN VARCHAR2
84 ,p_organization_id IN NUMBER
85 ,p_user_id IN NUMBER
86 ,p_transaction_header_id IN NUMBER
87 ,p_transaction_temp_id IN NUMBER
88 ,p_new_transaction_temp_id IN NUMBER
89 ,p_transaction_temp_id_to_merge IN NUMBER
90 ,p_inventory_item_id IN NUMBER
91 ,p_revision IN VARCHAR2
92 ,p_suggested_uom IN VARCHAR2
93 ,p_confirmed_uom IN VARCHAR2
94 ,p_primary_uom IN VARCHAR2
95 ,p_confirmed_lots IN VARCHAR2
96 ,p_confirmed_lot_trx_qty IN VARCHAR2
97 ,p_confirmed_serials IN VARCHAR2
98 ,p_serial_allocated_flag IN VARCHAR2
99 ,p_lpn_match IN NUMBER
100 ,p_lpn_match_lpn_id IN NUMBER
101 ,p_confirmed_sec_uom IN VARCHAR2
102 ,p_confirmed_sec_qty IN VARCHAR2
103 ,p_lot_controlled IN VARCHAR2 -- Y/N
104 ,p_serial_controlled IN VARCHAR2 -- Y/N
105 ,p_exception IN VARCHAR2 -- OVER/SHORT
106 ,x_return_status OUT NOCOPY VARCHAR2
107 ,x_msg_count OUT NOCOPY NUMBER
108 ,x_msg_data OUT NOCOPY VARCHAR2);
109
110 PROCEDURE proc_process_confirmed_serials
111 ( p_action IN VARCHAR2
112 ,p_insert IN VARCHAR2
113 ,p_update IN VARCHAR2
114 ,p_organization_id IN NUMBER
115 ,p_user_id IN NUMBER
116 ,p_transaction_header_id IN NUMBER
117 ,p_transaction_temp_id IN NUMBER
118 ,p_new_transaction_temp_id IN NUMBER
119 ,p_transaction_temp_id_to_merge IN NUMBER
120 ,p_serial_transaction_temp_id IN NUMBER
121 ,p_mtlt_serial_temp_id IN NUMBER
122 ,p_inventory_item_id IN NUMBER
123 ,p_revision IN VARCHAR2
124 ,p_suggested_uom IN VARCHAR2
125 ,p_confirmed_uom IN VARCHAR2
126 ,p_primary_uom IN VARCHAR2
127 ,p_serial_lot_number IN VARCHAR2
128 ,p_confirmed_serials IN VARCHAR2
129 ,p_serial_allocated_flag IN VARCHAR2
130 ,p_lpn_match IN NUMBER
131 ,p_lpn_match_lpn_id IN NUMBER
132 ,p_lot_controlled IN VARCHAR2 -- Y/N
133 ,p_serial_controlled IN VARCHAR2 -- Y/N
134 ,x_return_status OUT NOCOPY VARCHAR2
135 ,x_msg_count OUT NOCOPY NUMBER
136 ,x_msg_data OUT NOCOPY VARCHAR2);
137
138 PROCEDURE proc_insert_mtlt
139 (p_lot_record IN mtl_transaction_lots_temp%ROWTYPE
140 ,x_return_status OUT NOCOPY VARCHAR2
141 ,x_msg_count OUT NOCOPY NUMBER
142 ,x_msg_data OUT NOCOPY VARCHAR2);
143
144 PROCEDURE proc_insert_msnt
145 (p_transaction_temp_id IN NUMBER
146 ,p_organization_id IN NUMBER
147 ,p_inventory_item_id IN NUMBER
148 ,p_revision IN VARCHAR2
149 ,p_confirmed_serials IN VARCHAR2
150 ,p_serial_number IN VARCHAR2
151 ,p_lpn_id IN NUMBER
152 ,p_serial_lot_number IN VARCHAR2
153 ,p_user_id IN NUMBER
154 ,x_return_status OUT NOCOPY VARCHAR2
155 ,x_msg_count OUT NOCOPY NUMBER
156 ,x_msg_data OUT NOCOPY VARCHAR2);
157
158 PROCEDURE proc_mark_msn
159 (p_group_mark_id IN NUMBER
160 ,p_organization_id IN NUMBER
161 ,p_inventory_item_id IN NUMBER
162 ,p_Revision IN VARCHAR2
163 ,p_confirmed_serials IN VARCHAR2
164 ,p_serial_lot_number IN VARCHAR2
165 ,p_serial_number IN VARCHAR2
166 ,p_lpn_id IN NUMBER
167 ,p_user_id IN NUMBER
168 ,x_return_status OUT NOCOPY VARCHAR2
169 ,x_msg_count OUT NOCOPY NUMBER
170 ,x_msg_data OUT NOCOPY VARCHAR2);
171
172 PROCEDURE proc_device_call
173 (p_action IN VARCHAR2
174 ,p_employee_id IN NUMBER
175 ,p_transaction_temp_id IN NUMBER
176 ,x_return_status OUT NOCOPY VARCHAR2
177 ,x_msg_count OUT NOCOPY NUMBER
178 ,x_msg_data OUT NOCOPY VARCHAR2 );
179
180 PROCEDURE proc_process_cancelled_MOLs
181 (p_organization_id IN NUMBER
182 ,p_user_id IN NUMBER
183 ,p_transaction_header_id IN NUMBER
184 ,p_transaction_temp_id IN NUMBER
185 ,x_return_status OUT NOCOPY VARCHAR2
186 ,x_msg_count OUT NOCOPY NUMBER
187 ,x_msg_data OUT NOCOPY VARCHAR2);
188
189 PROCEDURE proc_parse_lot_serial_catchwt
190 (p_inventory_item_id IN NUMBER
191 ,p_confirmed_lots IN VARCHAR2
192 ,p_confirmed_lot_trx_qty IN VARCHAR2
193 ,p_confirmed_serials IN VARCHAR2
194 ,p_suggested_uom IN VARCHAR2
195 ,p_confirmed_uom IN VARCHAR2
196 ,p_primary_uom IN VARCHAR2
197 ,p_confirmed_sec_uom IN VARCHAR2
198 ,p_confirmed_sec_qty IN VARCHAR2
199 ,x_return_status OUT NOCOPY VARCHAR2
200 ,x_msg_count OUT NOCOPY NUMBER
201 ,x_msg_data OUT NOCOPY VARCHAR2);
202
203 PROCEDURE proc_reset_lpn_context(
204 p_organization_id IN NUMBER
205 ,p_user_id IN NUMBER
206 ,p_transaction_header_id IN NUMBER
207 ,p_transaction_temp_id IN NUMBER
208 ,x_return_status OUT NOCOPY VARCHAR2
209 ,x_msg_count OUT NOCOPY NUMBER
210 ,x_msg_data OUT NOCOPY VARCHAR2);
211
212 PROCEDURE proc_reset_task_status(
213 p_action IN VARCHAR2
214 ,p_organization_id IN NUMBER
215 ,p_user_id IN NUMBER
216 ,p_employee_id IN NUMBER
217 ,p_transaction_header_id IN NUMBER
218 ,p_transaction_temp_id IN NUMBER
219 ,x_return_status OUT NOCOPY VARCHAR2
220 ,x_msg_count OUT NOCOPY NUMBER
221 ,x_msg_data OUT NOCOPY VARCHAR2);
222 --viks start_over
223 PROCEDURE proc_start_over
224 (p_transaction_header_id IN NUMBER
225 ,p_transaction_temp_id IN NUMBER
226 ,p_user_id IN NUMBER
227 ,x_start_over_taskno OUT NOCOPY NUMBER
228 ,x_return_status OUT NOCOPY VARCHAR2
229 ,x_msg_count OUT NOCOPY NUMBER
230 ,x_msg_data OUT NOCOPY VARCHAR2 );
231
232
233
234 procedure validate_loaded_lpn_cg
235 ( p_organization_id IN NUMBER,
236 p_inventory_item_id IN NUMBER,
237 p_subinventory_code IN VARCHAR2,
238 p_locator_id IN NUMBER,
239 p_revision IN VARCHAR2,
240 p_lot_number IN VARCHAR2,
241 p_lpn_id IN NUMBER,
242 p_transfer_lpn_id IN NUMBER,
243 p_lot_control IN NUMBER,
244 p_revision_control IN NUMBER,
245 x_commingle_exist OUT NOCOPY VARCHAR2,
246 x_return_status OUT NOCOPY VARCHAR2,
247 p_trx_type_id IN VARCHAR2, -- Bug 4632519
248 p_trx_action_id IN VARCHAR2); -- Bug 4632519
249
250
251 PROCEDURE mydebug( p_msg IN VARCHAR2)
252 IS
253 BEGIN
254 IF (g_debug = 1) THEN
255 inv_mobile_helper_functions.tracelog(
256 p_err_msg => p_msg,
257 p_module => g_pkg_name ,
258 p_level => 9);
259
260 END IF;
261 -- dbms_output.put_line( p_msg );
262 END mydebug;
263
264 PROCEDURE mydebug(p_message IN VARCHAR2, p_module IN VARCHAR2)
265 IS
266 BEGIN
267 IF (g_debug = 1) THEN
268 inv_log_util.trace(p_message, p_module, 9);
269 END IF;
270 END mydebug;
271
272 PROCEDURE update_loaded_part
273 (p_user_id IN NUMBER,
274 p_transaction_temp_id1 IN NUMBER,
275 p_transaction_temp_id2 IN NUMBER,
276 p_transfer_lpn_id IN NUMBER,
277 p_transaction_uom IN VARCHAR2,
278 p_transaction_quantity IN NUMBER,
279 p_lot_numbers IN VARCHAR2,
280 p_lot_transaction_quantity IN VARCHAR2,
281 p_secondary_uom IN VARCHAR2,
282 p_secondary_quantity IN VARCHAR2,
283 p_serial_numbers IN VARCHAR2,
284 p_serial_allocated_flag IN VARCHAR2, -- Y/N
285 p_lot_controlled IN VARCHAR2, -- Y/N
286 p_serial_controlled IN VARCHAR2, -- Y/N
287 x_return_status OUT NOCOPY VARCHAR2,
288 x_msg_count OUT NOCOPY NUMBER,
289 x_msg_data OUT NOCOPY VARCHAR2)
290 IS
291 l_serial_transaction_temp_id NUMBER;
292 l_inventory_item_id NUMBER;
293 l_primary_uom VARCHAR2(3);
294 l_primary_quantity NUMBER;
295 l_primary_quantity1 NUMBER;
296
297 l_secondary_uom VARCHAR2(3);
298 l_secondary_quantity NUMBER;
299 l_secondary_quantity1 NUMBER;
300
301 l_delta_primary_quantity NUMBER;
302
303 l_delta_secondary_quantity NUMBER;
304
305 l_transaction_uom1 VARCHAR2(3);
306 l_transaction_uom2 VARCHAR2(3);
307 l_conversion_factor NUMBER;
308 l_conversion_factor1 NUMBER;
309 l_conversion_factor2 NUMBER;
310 l_mtlt_rec mtl_transaction_lots_temp%ROWTYPE;
311 l_row_exists NUMBER;
312 i NUMBER;
313 j NUMBER;
314 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
315 l_lpn_id NUMBER;
316
317 TYPE lot_record_type IS RECORD
318 (lot_number mtl_serial_numbers.lot_number%TYPE,
319 primary_quantity NUMBER,
320 delta_primary_quantity NUMBER,
321 secondary_quantity NUMBER,
322 delta_secondary_quantity NUMBER,
323 secondary_uom mtl_material_transactions_temp.secondary_uom_code%TYPE,
324 serial_transaction_temp_id NUMBER,
325 update_mtlt BOOLEAN,
326 delete_mtlt BOOLEAN);
327
328 TYPE serial_record_type IS RECORD
329 (serial_number mtl_serial_numbers.serial_number%TYPE,
330 lot_number mtl_serial_numbers.lot_number%TYPE,
331 transaction_temp_id NUMBER,
332 delete_msnt BOOLEAN);
333
334 TYPE lot_table_type IS TABLE OF lot_record_type INDEX BY BINARY_INTEGER;
335 TYPE serial_table_type IS TABLE OF serial_record_type INDEX BY BINARY_INTEGER;
336
337 l_lot_table1 lot_table_type;
338 l_serial_table1 serial_table_type;
339
340 CURSOR mmtt_cursor(v_transaction_temp_id1 NUMBER, v_transaction_temp_id2 NUMBER) IS
341 SELECT inventory_item_id, transaction_temp_id, primary_quantity
342 , item_primary_uom_code, transaction_quantity, transaction_uom
343 , secondary_transaction_quantity, secondary_uom_code
344 FROM mtl_material_transactions_temp
345 WHERE transaction_temp_id IN (v_transaction_temp_id1, v_transaction_temp_id2)
346 FOR UPDATE;
347
348 CURSOR mtlt_cursor(v_transaction_temp_id NUMBER) IS
349 SELECT lot_number, primary_quantity, transaction_quantity, secondary_quantity
350 , serial_transaction_temp_id
351 FROM mtl_transaction_lots_temp
352 WHERE transaction_temp_id = v_transaction_temp_id
353 ORDER BY lot_number
354 FOR UPDATE;
355
356 CURSOR msnt_cursor(v_transaction_temp_id NUMBER) IS
357 SELECT fm_serial_number
358 FROM mtl_serial_numbers_temp
359 WHERE transaction_temp_id = v_transaction_temp_id
360 ORDER BY fm_serial_number
361 FOR UPDATE;
362
363 CURSOR confirmed_lot_serial_cursor IS
364 SELECT
365 transaction_temp_id,
366 lot_number,
367 serial_number,
368 SUM(transaction_quantity) transaction_quantity,
369 SUM(primary_quantity) primary_quantity,
370 SUM(secondary_quantity) secondary_quantity
371 FROM mtl_allocations_gtmp
372 WHERE (lot_number IS NOT NULL OR serial_number IS NOT NULL)
373 GROUP BY transaction_temp_id, lot_number, serial_number, secondary_quantity
374 ORDER BY transaction_temp_id, lot_number, serial_number;
375
376 BEGIN
377
378 x_return_status := l_g_ret_sts_success;
379 IF (l_debug = 1) THEN
380 mydebug('Inside UPDATE_LOADED_PART', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
381 END IF;
382
383 FOR mmtt_rec IN mmtt_cursor(p_transaction_temp_id1, p_transaction_temp_id2) LOOP
384 IF mmtt_rec.transaction_temp_id = p_transaction_temp_id1 THEN
385 l_transaction_uom1 := mmtt_rec.transaction_uom;
386 l_conversion_factor1 := mmtt_rec.transaction_quantity/mmtt_rec.primary_quantity;
387 l_primary_quantity1 := mmtt_rec.primary_quantity;
388 l_secondary_quantity1 := mmtt_rec.secondary_transaction_quantity;
389 ELSE
390 l_transaction_uom2 := mmtt_rec.transaction_uom;
391 l_conversion_factor2 := mmtt_rec.transaction_quantity/mmtt_rec.primary_quantity;
392 END IF;
393
394 l_inventory_item_id := mmtt_rec.inventory_item_id;
395 l_primary_uom := mmtt_rec.item_primary_uom_code;
396 l_secondary_uom := mmtt_rec.secondary_uom_code;
397 END LOOP;
398
399 IF p_transaction_uom = l_transaction_uom1 THEN
400 l_conversion_factor := l_conversion_factor1;
401 ELSE
402 l_conversion_factor := inv_convert.inv_um_convert(item_id => l_inventory_item_id,
403 precision => l_g_decimal_precision,
404 from_quantity => 1,
405 from_unit => l_primary_uom,
406 to_unit => p_transaction_uom,
407 from_name => NULL,
408 to_name => NULL);
409 END IF;
410
411 IF (l_debug = 1) THEN
412 mydebug('Conversion Factor: ' || l_conversion_factor, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
413 mydebug('Conversion Factor1: ' || l_conversion_factor1, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
414 mydebug('Conversion Factor2: ' || l_conversion_factor2, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
415 END IF;
416
417 IF p_lot_controlled <> 'Y' AND p_serial_controlled <> 'Y' THEN -- No Lot or serial control
418 fnd_message.set_token('ROUTINE', '- proc_insert_update_task' );
419 fnd_msg_pub.ADD;
420 l_primary_quantity := Round(p_transaction_quantity/l_conversion_factor, l_g_decimal_precision);
421 l_secondary_quantity := p_secondary_quantity;
422 ELSE
423 proc_parse_lot_serial_catchwt
424 (p_inventory_item_id => l_inventory_item_id,
425 p_confirmed_lots => p_lot_numbers,
426 p_confirmed_lot_trx_qty => p_lot_transaction_quantity,
427 p_confirmed_serials => p_serial_numbers,
428 p_suggested_uom => l_transaction_uom1,
429 p_confirmed_uom => p_transaction_uom,
430 p_primary_uom => l_primary_uom ,
431 p_confirmed_sec_uom => p_secondary_uom,
432 p_confirmed_sec_qty => p_secondary_quantity,
433 x_return_status => x_return_status,
434 x_msg_count => x_msg_count,
435 x_msg_data => x_msg_data);
436
437 IF (l_debug = 1) THEN
438 mydebug('Return Status from Lot Serial Parse: ' || x_return_status, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
439 END IF;
440
441 IF x_return_status <> l_g_ret_sts_success
442 THEN
443 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
444 -- Internal Error $ROUTINE
445 fnd_message.set_token('ROUTINE', ' - proc_parse_lot_serial_catchwt API ' );
446 mydebug('Error parsing lot/serial/catch weight string' );
447 -- "Error reserving Serial Number/s"
448 fnd_msg_pub.ADD;
449 RAISE fnd_api.g_exc_error;
450 END IF;
451
452 IF p_lot_controlled = 'Y' AND p_serial_controlled <> 'Y' THEN -- Lot Controlled only
453 IF (l_debug = 1) THEN
454 mydebug('Loaded...', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
455 END IF;
456
457 i := 1; -- lot table counter
458 FOR mtlt_record IN mtlt_cursor(p_transaction_temp_id1) LOOP
459
460 IF (l_debug = 1) THEN
461 mydebug(i || ' Lot Number: ' || mtlt_record.lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
462 END IF;
463
464 l_lot_table1(i).lot_number := mtlt_record.lot_number;
465 l_lot_table1(i).primary_quantity := mtlt_record.primary_quantity;
466 l_lot_table1(i).secondary_quantity := mtlt_record.secondary_quantity;
467
468 i := i + 1;
469 END LOOP;
470
471 IF (l_debug = 1) THEN
472 mydebug('Confirmed...', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
473 END IF;
474
475 i := 1; -- lot table counter
476 l_primary_quantity := 0;
477 l_secondary_quantity := 0;
478 FOR lot_serial_rec IN confirmed_lot_serial_cursor LOOP
479
480 l_primary_quantity := l_primary_quantity + lot_serial_rec.primary_quantity;
481 l_secondary_quantity := l_secondary_quantity + lot_serial_rec.secondary_quantity;
482
483 WHILE l_lot_table1(i).lot_number <> lot_serial_rec.lot_number LOOP
484 IF (l_debug = 1) THEN
485 mydebug(i || 'Marking Lot Number: ' || l_lot_table1(i).lot_number || ' to be deleted', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
486 END IF;
487 l_lot_table1(i).delete_mtlt := TRUE;
488 l_lot_table1(i).delta_primary_quantity := l_lot_table1(i).primary_quantity;
489 l_lot_table1(i).delta_secondary_quantity := l_lot_table1(i).secondary_quantity;
490 i := i + 1;
491 END LOOP;
492
493 IF (l_debug = 1) THEN
494 mydebug(i || ' Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
495 END IF;
496
497 IF l_lot_table1(i).lot_number = lot_serial_rec.lot_number THEN
498 l_lot_table1(i).secondary_quantity := lot_serial_rec.secondary_quantity;
499
500 IF l_lot_table1(i).primary_quantity <> lot_serial_rec.primary_quantity THEN
501
502 IF (l_debug = 1) THEN
503 mydebug(i || 'Marking Lot Number: ' || l_lot_table1(i).lot_number || ' to be updated', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
504 END IF;
505
506 l_lot_table1(i).update_mtlt := TRUE;
507
508 l_lot_table1(i).delta_primary_quantity := l_lot_table1(i).primary_quantity - lot_serial_rec.primary_quantity;
509 l_lot_table1(i).primary_quantity := lot_serial_rec.primary_quantity;
510 l_lot_table1(i).delta_secondary_quantity := l_lot_table1(i).secondary_quantity - lot_serial_rec.secondary_quantity;
511 l_lot_table1(i).secondary_quantity := lot_serial_rec.secondary_quantity;
512
513 END IF;
514 END IF;
515
516 i := i + 1;
517 END LOOP;
518
519 WHILE i <= l_lot_table1.COUNT LOOP
520 l_lot_table1(i).delete_mtlt := TRUE;
521 l_lot_table1(i).delta_primary_quantity := l_lot_table1(i).primary_quantity;
522 l_lot_table1(i).delta_secondary_quantity := l_lot_table1(i).secondary_quantity;
523 i := i + 1;
524 END LOOP;
525
526 FOR i IN 1..l_lot_table1.COUNT LOOP
527
528 BEGIN
529 SELECT serial_transaction_temp_id
530 INTO l_serial_transaction_temp_id
531 FROM mtl_transaction_lots_temp
532 WHERE transaction_temp_id = p_transaction_temp_id2
533 AND lot_number = l_lot_table1(i).lot_number;
534
535 l_row_exists := 1;
536 EXCEPTION
537 WHEN no_data_found THEN
538 l_row_exists := 0;
539 END;
540
541 IF (l_debug = 1) THEN
542 IF l_row_exists = 1 THEN
543 mydebug(i || 'Lot Number: ' || l_lot_table1(i).lot_number || ' exists in remaining', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
544 ELSE
545 mydebug(i || 'Lot Number: ' || l_lot_table1(i).lot_number || ' does not exist in remaining', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
546 END IF;
547 END IF;
548
549
550 IF (l_debug = 1) THEN
551 mydebug(i || 'Delta: ' || l_lot_table1(i).delta_primary_quantity, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
552 mydebug(i || 'Sec Delta: ' || l_lot_table1(i).delta_secondary_quantity, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
553 END IF;
554
555 IF l_lot_table1(i).delete_mtlt THEN
556
557 IF l_row_exists = 1 THEN
558
559 IF (l_debug = 1) THEN
560 mydebug(i || 'Deleting Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
561 END IF;
562
563 UPDATE mtl_transaction_lots_temp
564 SET primary_quantity = primary_quantity + l_lot_table1(i).delta_primary_quantity,
565 transaction_quantity = transaction_quantity +
566 Round(l_lot_table1(i).delta_primary_quantity * l_conversion_factor2,
567 l_g_decimal_precision),
568 secondary_quantity = secondary_quantity + l_lot_table1(i).delta_secondary_quantity,
569 last_update_date = Sysdate,
570 last_updated_by = p_user_id
571 WHERE transaction_temp_id = p_transaction_temp_id2
572 AND lot_number = l_lot_table1(i).lot_number;
573
574 DELETE FROM mtl_transaction_lots_temp
575 WHERE transaction_temp_id = p_transaction_temp_id1
576 AND lot_number = l_lot_table1(i).lot_number;
577
578 ELSE -- row does not exist in 2
579
580 IF (l_debug = 1) THEN
581 mydebug(i || 'Transferring Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
582 END IF;
583
584 UPDATE mtl_transaction_lots_temp
585 SET transaction_temp_id = p_transaction_temp_id2,
586 transaction_quantity = Round(primary_quantity * l_conversion_factor2, l_g_decimal_precision),
587 last_update_date = Sysdate,
588 last_updated_by = p_user_id
589 WHERE transaction_temp_id = p_transaction_temp_id1
590 AND lot_number = l_lot_table1(i).lot_number;
591
592 END IF;
593
594 ELSIF l_lot_table1(i).update_mtlt THEN
595
596 UPDATE mtl_transaction_lots_temp
597 SET primary_quantity = l_lot_table1(i).primary_quantity,
598 transaction_quantity = Round(l_lot_table1(i).primary_quantity * l_conversion_factor, l_g_decimal_precision),
599 secondary_quantity = l_lot_table1(i).secondary_quantity,
600 last_update_date = Sysdate,
601 last_updated_by = p_user_id
602 WHERE transaction_temp_id = p_transaction_temp_id1
603 AND lot_number = l_lot_table1(i).lot_number;
604
605 IF l_row_exists = 1 THEN
606
607 IF (l_debug = 1) THEN
608 mydebug(i || 'Updating Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
609 END IF;
610
611 UPDATE mtl_transaction_lots_temp
612 SET primary_quantity = primary_quantity + l_lot_table1(i).delta_primary_quantity,
613 transaction_quantity = transaction_quantity + Round(l_lot_table1(i).delta_primary_quantity * l_conversion_factor2,
614 l_g_decimal_precision),
615 secondary_quantity = secondary_quantity + l_lot_table1(i).delta_secondary_quantity,
616 last_update_date = Sysdate,
617 last_updated_by = p_user_id
618 WHERE transaction_temp_id = p_transaction_temp_id2
619 AND lot_number = l_lot_table1(i).lot_number;
620 ELSE -- row does not exist in 2
621
622 IF (l_debug = 1) THEN
623 mydebug(i || 'Inserting Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
624 END IF;
625
626 SELECT *
627 INTO l_mtlt_rec
628 FROM mtl_transaction_lots_temp
629 WHERE transaction_temp_id = p_transaction_temp_id1
630 AND lot_number = l_lot_table1(i).lot_number;
631
632 l_mtlt_rec.transaction_temp_id := p_transaction_temp_id2;
633 l_mtlt_rec.transaction_quantity := Round(l_mtlt_rec.primary_quantity * l_conversion_factor2, l_g_decimal_precision);
634
635 proc_insert_mtlt
636 (p_lot_record => l_mtlt_rec,
637 x_return_status => x_return_status,
638 x_msg_count => x_msg_count,
639 x_msg_data => x_msg_data);
640
641 mydebug('x_return_status : ' || x_return_status);
642 IF x_return_status <> l_g_ret_sts_success THEN
643 RAISE fnd_api.g_exc_error;
644 END IF;
645
646 END IF; -- row exists
647
648 END IF; -- delete/update mtlt
649
650 END LOOP; -- lot loop
651 ELSIF p_lot_controlled <> 'Y' AND p_serial_controlled = 'Y' THEN -- Serial controlled only
652
653 IF (l_debug = 1) THEN
654 mydebug('Loaded...', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
655 END IF;
656
657 l_secondary_quantity := p_secondary_quantity;
658
659 j := 1; -- serial table counter
660 FOR msnt_record IN msnt_cursor(p_transaction_temp_id1) LOOP
661 IF (l_debug = 1) THEN
662 mydebug(j || ' Serial Number: ' || msnt_record.fm_serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
663 END IF;
664
665 l_serial_table1(j).serial_number := msnt_record.fm_serial_number;
666 j := j + 1;
667 END LOOP;
668
669 IF (l_debug = 1) THEN
670 mydebug('Confirmed...', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
671 END IF;
672
673 j := 1; -- serial table counter
674 l_primary_quantity := 0;
675 FOR lot_serial_rec IN confirmed_lot_serial_cursor LOOP
676
677 l_primary_quantity := l_primary_quantity + 1;
678
679 WHILE l_serial_table1(j).serial_number <> lot_serial_rec.serial_number LOOP
680 l_serial_table1(j).delete_msnt := TRUE;
681 j := j + 1;
682 END LOOP;
683
684 IF (l_debug = 1) THEN
685 mydebug(j || ' Serial Number: ' || l_serial_table1(j).serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
686 END IF;
687
688 j := j + 1;
689 END LOOP;
690
691
692 WHILE j <= l_serial_table1.COUNT LOOP
693 l_serial_table1(j).delete_msnt := TRUE;
694 j := j + 1;
695 END LOOP;
696
697 j := 1;
698
699 WHILE j <= l_serial_table1.COUNT LOOP
700
701 IF l_serial_table1(j).delete_msnt THEN
702
703 IF p_serial_allocated_flag = 'Y' THEN
704
705 IF (l_debug = 1) THEN
706 mydebug(j || 'Transferring Serial Number: ' || l_serial_table1(j).serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
707 END IF;
708
709 UPDATE mtl_serial_numbers_temp
710 SET transaction_temp_id = p_transaction_temp_id2,
711 last_update_date = Sysdate,
712 last_updated_by = p_user_id
713 WHERE transaction_temp_id = p_transaction_temp_id1
714 AND fm_serial_number = l_serial_table1(j).serial_number;
715 ELSE
716
717 IF (l_debug = 1) THEN
718 mydebug(j || 'Deleting Serial Number: ' || l_serial_table1(j).serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
719 END IF;
720
721 DELETE FROM mtl_serial_numbers_temp
722 WHERE transaction_temp_id = p_transaction_temp_id1
723 AND fm_serial_number = l_serial_table1(j).serial_number;
724
725 -- unmark serial
726 UPDATE mtl_serial_numbers
727 SET group_mark_id = NULL,
728 last_update_date = Sysdate,
729 last_updated_by = p_user_id
730 WHERE serial_number = l_serial_table1(j).serial_number
731 AND inventory_item_id = l_inventory_item_id;
732
733 END IF; -- serial allocated flag
734 END IF;
735
736 j := j + 1;
737 END LOOP;
738
739 ELSIF p_lot_controlled = 'Y' AND p_serial_controlled = 'Y' THEN -- Lot and serial controlled
740
741 IF (l_debug = 1) THEN
742 mydebug('Loaded...', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
743 END IF;
744
745 i := 1; -- lot table counter
746 j := 1; -- serial table counter
747 FOR mtlt_record IN mtlt_cursor(p_transaction_temp_id1) LOOP
748
749 IF (l_debug = 1) THEN
750 mydebug(i || ' Lot Number: ' || mtlt_record.lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
751 END IF;
752
753 l_lot_table1(i).lot_number := mtlt_record.lot_number;
754 l_lot_table1(i).primary_quantity := mtlt_record.primary_quantity;
755
756 FOR msnt_record IN msnt_cursor(mtlt_record.serial_transaction_temp_id) LOOP
757 IF (l_debug = 1) THEN
758 mydebug(j || ' Serial Number: ' || msnt_record.fm_serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
759 END IF;
760
761 l_serial_table1(j).transaction_temp_id := mtlt_record.serial_transaction_temp_id;
762 l_serial_table1(j).serial_number := msnt_record.fm_serial_number;
763 l_serial_table1(j).lot_number := mtlt_record.lot_number;
764
765 j := j + 1;
766 END LOOP;
767
768 i := i + 1;
769 END LOOP;
770
771 IF (l_debug = 1) THEN
772 mydebug('Confirmed...', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
773 END IF;
774
775 i := 1; -- lot table counter
776 j := 1; -- serial table counter
777 l_primary_quantity := 0;
778 FOR lot_serial_rec IN confirmed_lot_serial_cursor LOOP
779
780 l_primary_quantity := l_primary_quantity + 1;
781
782 IF (l_debug = 1) THEN
783 mydebug(i || ' Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
784 END IF;
785
786 IF l_lot_table1(i).lot_number = lot_serial_rec.lot_number THEN
787 l_lot_table1(i).secondary_quantity := lot_serial_rec.secondary_quantity;
788 END IF;
789
790 WHILE l_serial_table1(j).serial_number <> lot_serial_rec.serial_number LOOP
791
792 IF (l_debug = 1) THEN
793 mydebug(j || 'Marking Serial Number: ' || l_serial_table1(j).serial_number || ' to be deleted', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
794 END IF;
795
796 l_serial_table1(j).delete_msnt := TRUE;
797
798 l_lot_table1(i).primary_quantity := l_lot_table1(i).primary_quantity - 1;
799 l_lot_table1(i).delta_primary_quantity := Nvl(l_lot_table1(i).delta_primary_quantity, 0) + 1;
800 l_lot_table1(i).update_mtlt := TRUE;
801
802 IF l_lot_table1(i).primary_quantity = 0 THEN
803 l_lot_table1(i).delete_mtlt := TRUE;
804
805 IF (l_debug = 1) THEN
806 mydebug(i || 'Marking Lot Number: ' || l_lot_table1(i).lot_number || ' to be deleted', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
807 END IF;
808
809 ELSE
810
811 IF (l_debug = 1) THEN
812 mydebug(i || 'Marking Lot Number: ' || l_lot_table1(i).lot_number || ' to be updated', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
813 END IF;
814
815 END IF;
816
817 j := j + 1;
818
819 IF l_serial_table1.COUNT >= j THEN
820 IF l_serial_table1(j-1).lot_number = l_lot_table1(i).lot_number AND
821 l_serial_table1(j).lot_number <> l_lot_table1(i).lot_number THEN
822 i := i + 1;
823 mydebug('Incrementing i', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
824 END IF;
825 END IF;
826
827 END LOOP;
828
829 IF (l_debug = 1) THEN
830 mydebug(j || ' Serial Number: ' || l_serial_table1(j).serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
831 END IF;
832
833 j := j + 1;
834
835 END LOOP;
836
837 WHILE j <= l_serial_table1.COUNT LOOP
838
839 IF (l_debug = 1) THEN
840 mydebug(j || 'Marking Serial Number: ' || l_serial_table1(j).serial_number || ' to be deleted', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
841 END IF;
842
843 l_serial_table1(j).delete_msnt := TRUE;
844
845 l_lot_table1(i).primary_quantity := l_lot_table1(i).primary_quantity - 1;
846 l_lot_table1(i).delta_primary_quantity := Nvl(l_lot_table1(i).delta_primary_quantity, 0) + 1;
847 l_lot_table1(i).update_mtlt := TRUE;
848
849 IF l_lot_table1(i).primary_quantity = 0 THEN
850 l_lot_table1(i).delete_mtlt := TRUE;
851
852 IF (l_debug = 1) THEN
853 mydebug(i || 'Marking Lot Number: ' || l_lot_table1(i).lot_number || ' to be deleted', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
854 END IF;
855
856 ELSE
857
858 IF (l_debug = 1) THEN
859 mydebug(i || 'Marking Lot Number: ' || l_lot_table1(i).lot_number || ' to be updated', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
860 END IF;
861
862 END IF;
863
864 j := j + 1;
865
866 IF l_serial_table1.COUNT >= j THEN
867 IF l_serial_table1(j-1).lot_number = l_lot_table1(i).lot_number AND
868 l_serial_table1(j).lot_number <> l_lot_table1(i).lot_number THEN
869 i := i + 1;
870 mydebug('Incrementing i', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
871 END IF;
872 END IF;
873
874 END LOOP;
875
876 j := 1;
877 FOR i IN 1..l_lot_table1.COUNT LOOP
878
879 l_serial_transaction_temp_id := NULL;
880
881 BEGIN
882 SELECT serial_transaction_temp_id
883 INTO l_serial_transaction_temp_id
884 FROM mtl_transaction_lots_temp
885 WHERE transaction_temp_id = p_transaction_temp_id2
886 AND lot_number = l_lot_table1(i).lot_number;
887
888 l_row_exists := 1;
889 EXCEPTION
890 WHEN no_data_found THEN
891 l_row_exists := 0;
892
893 IF p_serial_allocated_flag = 'Y' THEN
894 SELECT mtl_material_transactions_s.NEXTVAL
895 INTO l_serial_transaction_temp_id
896 FROM dual;
897 END IF;
898 END;
899
900 IF (l_debug = 1) THEN
901 IF l_row_exists = 1 THEN
902 mydebug(i || 'Lot Number: ' || l_lot_table1(i).lot_number || ' exists in remaining', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
903 ELSE
904 mydebug(i || 'Lot Number: ' || l_lot_table1(i).lot_number || ' does not exist in remaining', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
905 END IF;
906 END IF;
907
908 WHILE j <= l_serial_table1.COUNT AND l_serial_table1(j).lot_number = l_lot_table1(i).lot_number LOOP
909
910 IF l_serial_table1(j).delete_msnt THEN
911
912 IF p_serial_allocated_flag = 'Y' THEN
913
914 IF (l_debug = 1) THEN
915 mydebug(j || 'Transferring Serial Number: ' || l_serial_table1(j).serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
916 END IF;
917
918 UPDATE mtl_serial_numbers_temp
919 SET transaction_temp_id = l_serial_transaction_temp_id,
920 last_update_date = Sysdate,
921 last_updated_by = p_user_id
922 WHERE transaction_temp_id = l_serial_table1(j).transaction_temp_id
923 AND fm_serial_number = l_serial_table1(j).serial_number;
924 ELSE
925
926 IF (l_debug = 1) THEN
927 mydebug(j || 'Deleting Serial Number: ' || l_serial_table1(j).serial_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
928 END IF;
929
930 DELETE FROM mtl_serial_numbers_temp
931 WHERE transaction_temp_id = l_serial_table1(j).transaction_temp_id
932 AND fm_serial_number = l_serial_table1(j).serial_number;
933
934 -- unmark serial
935 UPDATE mtl_serial_numbers
936 SET group_mark_id = NULL,
937 last_update_date = Sysdate,
938 last_updated_by = p_user_id
939 WHERE serial_number = l_serial_table1(j).serial_number
940 AND inventory_item_id = l_inventory_item_id;
941
942 END IF; -- serial allocated flag
943 ELSE
944 IF (l_debug = 1) THEN
945 mydebug(j || ' Serial Number: ' || l_serial_table1(j).serial_number || ' left untouched', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
946 END IF;
947 END IF;
948
949 j := j + 1;
950
951 END LOOP;
952
953 IF l_lot_table1(i).delete_mtlt THEN
954
955 IF l_row_exists = 1 THEN
956
957 IF (l_debug = 1) THEN
958 mydebug(i || 'Deleting Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
959 END IF;
960
961 UPDATE mtl_transaction_lots_temp
962 SET primary_quantity = primary_quantity + l_lot_table1(i).delta_primary_quantity,
963 transaction_quantity = transaction_quantity +
964 Round(l_lot_table1(i).delta_primary_quantity * l_conversion_factor2,
965 l_g_decimal_precision),
966 last_update_date = Sysdate,
967 last_updated_by = p_user_id
968 WHERE transaction_temp_id = p_transaction_temp_id2
969 AND lot_number = l_lot_table1(i).lot_number;
970
971 DELETE FROM mtl_transaction_lots_temp
972 WHERE transaction_temp_id = p_transaction_temp_id1
973 AND lot_number = l_lot_table1(i).lot_number;
974
975 ELSE -- row does not exist in 2
976
977 IF (l_debug = 1) THEN
978 mydebug(i || 'Transferring Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
979 END IF;
980
981 UPDATE mtl_transaction_lots_temp
982 SET transaction_temp_id = p_transaction_temp_id2,
983 serial_transaction_temp_id = l_serial_transaction_temp_id,
984 transaction_quantity = Round(primary_quantity * l_conversion_factor2, l_g_decimal_precision),
985 last_update_date = Sysdate,
986 last_updated_by = p_user_id
987 WHERE transaction_temp_id = p_transaction_temp_id1
988 AND lot_number = l_lot_table1(i).lot_number;
989
990 END IF;
991
992 ELSIF l_lot_table1(i).update_mtlt THEN
993
994 UPDATE mtl_transaction_lots_temp
995 SET primary_quantity = l_lot_table1(i).primary_quantity,
996 transaction_quantity = Round(l_lot_table1(i).primary_quantity * l_conversion_factor, l_g_decimal_precision),
997 secondary_quantity = l_lot_table1(i).secondary_quantity,
998 last_update_date = Sysdate,
999 last_updated_by = p_user_id
1000 WHERE transaction_temp_id = p_transaction_temp_id1
1001 AND lot_number = l_lot_table1(i).lot_number;
1002
1003 IF l_row_exists = 1 THEN
1004
1005 IF (l_debug = 1) THEN
1006 mydebug(i || 'Updating Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1007 END IF;
1008
1009 UPDATE mtl_transaction_lots_temp
1010 SET primary_quantity = primary_quantity + l_lot_table1(i).delta_primary_quantity,
1011 transaction_quantity = transaction_quantity + Round(l_lot_table1(i).delta_primary_quantity * l_conversion_factor2,
1012 l_g_decimal_precision),
1013 last_update_date = Sysdate,
1014 last_updated_by = p_user_id
1015 WHERE transaction_temp_id = p_transaction_temp_id2
1016 AND lot_number = l_lot_table1(i).lot_number;
1017 ELSE -- row does not exist in 2
1018
1019 IF (l_debug = 1) THEN
1020 mydebug(i || 'Inserting Lot Number: ' || l_lot_table1(i).lot_number, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1021 END IF;
1022
1023 SELECT *
1024 INTO l_mtlt_rec
1025 FROM mtl_transaction_lots_temp
1026 WHERE transaction_temp_id = p_transaction_temp_id1
1027 AND lot_number = l_lot_table1(i).lot_number;
1028
1029 l_mtlt_rec.transaction_temp_id := p_transaction_temp_id2;
1030 l_mtlt_rec.serial_transaction_temp_id := l_serial_transaction_temp_id;
1031 l_mtlt_rec.transaction_quantity := Round(l_mtlt_rec.primary_quantity * l_conversion_factor2, l_g_decimal_precision);
1032
1033 proc_insert_mtlt
1034 (p_lot_record => l_mtlt_rec,
1035 x_return_status => x_return_status,
1036 x_msg_count => x_msg_count,
1037 x_msg_data => x_msg_data);
1038
1039 mydebug('Return status from insert MTLT : ' || x_return_status, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1040 IF x_return_status <> l_g_ret_sts_success THEN
1041 RAISE fnd_api.g_exc_error;
1042 END IF;
1043
1044 END IF; -- row exists
1045
1046 END IF; -- delete/update mtlt
1047
1048 END LOOP; -- lot loop
1049
1050 END IF; -- lot/serial/lot serial
1051 END IF; -- no control/lot/serial/lot serial
1052
1053 -- Update MMTT records
1054 l_delta_primary_quantity := l_primary_quantity1 - l_primary_quantity;
1055 l_delta_secondary_quantity := l_secondary_quantity1 - l_secondary_quantity;
1056
1057 IF (l_debug = 1) THEN
1058 mydebug('Updating MMTT with delta qty: ' || l_delta_primary_quantity, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1059 mydebug('Updating MMTT with delta sec qty: ' || l_delta_secondary_quantity, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1060 END IF;
1061
1062 UPDATE mtl_material_transactions_temp
1063 SET transaction_quantity = Round(l_primary_quantity*l_conversion_factor, l_g_decimal_precision),
1064 transaction_uom = p_transaction_uom,
1065 primary_quantity = l_primary_quantity,
1066 secondary_transaction_quantity = l_secondary_quantity,
1067 secondary_uom_code = p_secondary_uom,
1068 lpn_id = content_lpn_id,
1069 content_lpn_id = NULL,
1070 transfer_lpn_id = p_transfer_lpn_id,
1071 last_update_date = Sysdate,
1072 last_updated_by = p_user_id
1073 WHERE transaction_temp_id = p_transaction_temp_id1
1074 returning lpn_id INTO l_lpn_id;
1075
1076 -- Bug5659809: update last_update_date and last_update_by as well
1077 UPDATE wms_license_plate_numbers
1078 SET lpn_context = 1
1079 , last_update_date = SYSDATE
1080 , last_updated_by = fnd_global.user_id
1081 WHERE lpn_id = l_lpn_id;
1082
1083 -- Update remaining MMTT record
1084 UPDATE mtl_material_transactions_temp
1085 SET transaction_quantity = transaction_quantity + Round(l_delta_primary_quantity*l_conversion_factor2, l_g_decimal_precision),
1086 primary_quantity = primary_quantity + l_delta_primary_quantity,
1087 secondary_transaction_quantity = secondary_transaction_quantity+l_delta_secondary_quantity,
1088 last_update_date = Sysdate,
1089 last_updated_by = p_user_id
1090 WHERE transaction_temp_id = p_transaction_temp_id2;
1091
1092 EXCEPTION
1093 WHEN fnd_api.g_exc_error THEN
1094 x_return_status := l_g_ret_sts_error;
1095 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1096
1097 IF (l_debug = 1) THEN
1098 mydebug('Error', 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1099 END IF;
1100 ROLLBACK;
1101
1102 WHEN OTHERS THEN
1103 x_return_status := l_g_ret_sts_unexp_error;
1104 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1105 IF (l_debug = 1) THEN
1106 mydebug('Error: ' || Sqlerrm, 'WMS_TASK_LOAD.UPDATE_LOADED_PART');
1107 END IF;
1108 ROLLBACK ;
1109 END update_loaded_part;
1110
1111 PROCEDURE task_merge_split(
1112 p_action IN VARCHAR2 -- LOAD_MULTIPLE/LOAD_SINGLE/SPLIT/UPDATE_LOADED
1113 ,p_exception IN VARCHAR2 -- SHORT/OVER
1114 ,p_organization_id IN NUMBER
1115 ,p_user_id IN NUMBER
1116 ,p_transaction_header_id IN NUMBER
1117 ,p_transaction_temp_id IN NUMBER
1118 ,p_parent_line_id IN NUMBER
1119 ,p_remaining_temp_id IN NUMBER
1120 ,p_lpn_id IN NUMBER
1121 ,p_content_lpn_id IN NUMBER
1122 ,p_transfer_lpn_id IN NUMBER
1123 ,p_confirmed_sub IN VARCHAR2
1124 ,p_confirmed_locator_id IN NUMBER
1125 ,p_confirmed_uom IN VARCHAR2
1126 ,p_suggested_uom IN VARCHAR2
1127 ,p_primary_uom IN VARCHAR2
1128 ,p_inventory_item_id IN NUMBER
1129 ,p_revision IN VARCHAR2
1130 ,p_confirmed_trx_qty IN NUMBER
1131 ,p_confirmed_lots IN VARCHAR2
1132 ,p_confirmed_lot_trx_qty IN VARCHAR2
1133 ,p_confirmed_sec_uom IN VARCHAR2
1134 ,p_confirmed_sec_qty IN VARCHAR2
1135 ,p_confirmed_serials IN VARCHAR2
1136 ,p_container_item_id IN NUMBER
1137 ,p_lpn_match IN NUMBER
1138 ,p_lpn_match_lpn_id IN NUMBER
1139 ,p_serial_allocated_flag IN VARCHAR2
1140 ,p_lot_controlled IN VARCHAR2 -- Y/N
1141 ,p_serial_controlled IN VARCHAR2 -- Y/N
1142 ,p_parent_lpn_id IN NUMBER
1143 ,x_new_transaction_temp_id OUT NOCOPY NUMBER
1144 ,x_cms_check OUT NOCOPY VARCHAR2 -- FAIL/PASS
1145 ,x_return_status OUT NOCOPY VARCHAR2
1146 ,x_msg_count OUT NOCOPY NUMBER
1147 ,x_msg_data OUT NOCOPY VARCHAR2)
1148 IS
1149 --PRAGMA AUTONOMOUS_TRANSACTION;
1150 l_proc_name VARCHAR2(30) := 'TASK_MERGE_SPLIT';
1151 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1152 l_progress VARCHAR2(30) := '100';
1153 l_transaction_temp_id_to_merge NUMBER := NULL;
1154 l_new_transaction_temp_id NUMBER := NULL;
1155 l_insert VARCHAR2(2) := NULL;
1156 l_update VARCHAR2(2) := NULL;
1157 l_action VARCHAR2(30) := p_action;
1158 l_pick_ok VARCHAR2(1) := 'Y';
1159
1160 l_lpn_id NUMBER := p_lpn_id;
1161 l_content_lpn_id NUMBER := p_content_lpn_id;
1162 l_parent_lpn_id NUMBER := p_parent_lpn_id;
1163 l_transfer_lpn_id NUMBER := p_transfer_lpn_id;
1164 l_container_item_id NUMBER := p_container_item_id;
1165 l_lpn_match_lpn_id NUMBER := p_lpn_match_lpn_id;
1166
1167 l_lpn_context_pregenerated CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_PREGENERATED;
1168 l_lpn_context_inv CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_INV;
1169 l_lpn_context_picked CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_PICKED;
1170 l_lpn_context_packing CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_PACKING ;
1171
1172 CURSOR cur_split_mmtts
1173 IS
1174 SELECT transaction_temp_id
1175 FROM mtl_material_transactions_temp
1176 WHERE transaction_header_id = p_transaction_header_id
1177 AND transaction_temp_id <> p_transaction_temp_id
1178 AND inventory_item_id = p_inventory_item_id
1179 AND nvl(revision,'@@') = nvl(p_revision,'@@')
1180 AND subinventory_code = p_confirmed_sub
1181 AND locator_id = p_confirmed_locator_id
1182 AND transaction_uom = p_confirmed_uom
1183 AND transfer_lpn_id = p_transfer_lpn_id
1184 AND nvl(content_lpn_id,0) = nvl(p_content_lpn_id,0)
1185 AND nvl(lpn_id,0) = nvl(p_lpn_id,0);
1186
1187 BEGIN
1188
1189 --/*
1190 -- P_action can have foll. values 'LOAD_MULTIPLE' , 'LOAD_SINGLE' or 'SPLIT'
1191 -- newly genertated LPN is already in wms_lpn table when PichMore Is pressed
1192 -- if fromLpn = toLPN -- FULLY COMSUMABLE
1193 -- from = content_lpn_id, to=transfer_lpn_id
1194 -- content_lpn_id is always nested into transafer_lpn_id
1195 -- else from = lpn_id, to=transfer_lpn_id.
1196 -- l_insert = 'Y' means Yes, --insert new MMTT
1197 -- l_update = 'Y1' means Yes But, 1 update , update original MMTT to reduce qty
1198 -- l_update = 'Y2' means Yes but, 2 updates
1199 -- update original MMTT to reduce qty and
1200 -- update mergeable MMTT to add qty
1201 /* MMTT management
1202 -- Action l_insert L_update update orginalMMTT UpdMergeMMTT InsertNewMMTT WMS_TASK_STATUS CHANGE
1203 -----------------------------------------------------------------------------------------------
1204 -- SPLIT Y Y1 N N Y new MMTT inserted with loaded status
1205 -- SPLIT N Y2 Y Y N no change
1206 -- LOAD_M N Y1 Y N N original MMTT updated to loaded status
1207 -- LOAD_M N Y2 Y-Delete Y N no change
1208 -- LOAD_S N Y1 Y N N original MMTT updated to loaded status
1209 --*/
1210
1211 x_return_status := l_g_ret_sts_success;
1212 g_debug := l_debug;
1213
1214 IF p_lpn_id = 0 THEN l_lpn_id := NULL; END IF;
1215 IF p_content_lpn_id = 0 THEN l_content_lpn_id := NULL; END IF;
1216 IF p_parent_lpn_id = 0 THEN l_parent_lpn_id := NULL; END IF;
1217 IF p_transfer_lpn_id = 0 THEN l_transfer_lpn_id := NULL; END IF;
1218 IF p_container_item_id = 0 THEN l_container_item_id := NULL; END IF;
1219 IF p_lpn_match_lpn_id = 0 THEN l_lpn_match_lpn_id := NULL; END IF;
1220
1221 mydebug ('p_action = ' || p_action );
1222 mydebug ('p_exception = ' || p_exception );
1223 mydebug ('p_transaction_header_id = ' || p_transaction_header_id );
1224 mydebug ('p_transaction_temp_id = ' || p_transaction_temp_id );
1225 mydebug ('p_remaining_temp_id = ' || p_remaining_temp_id );
1226 mydebug ('p_parent_line_id = ' || p_parent_line_id );
1227 mydebug ('p_lpn_id = ' || p_lpn_id || ':' || l_lpn_id);
1228 mydebug ('p_content_lpn_id = ' || p_content_lpn_id || ':' || l_content_lpn_id);
1229 mydebug ('p_parent_lpn_id = ' || p_parent_lpn_id || ':' ||
1230 l_parent_lpn_id);
1231 mydebug ('p_transfer_lpn_id = ' || p_transfer_lpn_id || ':' || l_transfer_lpn_id);
1232 mydebug ('p_confirmed_sub = ' || p_confirmed_sub );
1233 mydebug ('p_confirmed_locator_id = ' || p_confirmed_locator_id );
1234 mydebug ('p_confirmed_uom = ' || p_confirmed_uom );
1235 mydebug ('p_suggested_uom = ' || p_suggested_uom );
1236 mydebug ('p_primary_uom = ' || p_primary_uom );
1237 mydebug ('p_inventory_item_id = ' || p_inventory_item_id );
1238 mydebug ('p_revision = ' || p_revision );
1239 mydebug ('p_confirmed_trx_qty = ' || p_confirmed_trx_qty );
1240 mydebug ('p_confirmed_lots = ' || p_confirmed_lots );
1241 mydebug ('p_confirmed_lot_trx_qty = ' || p_confirmed_lot_trx_qty );
1242 mydebug ('p_confirmed_sec_uom = ' || p_confirmed_sec_uom );
1243 mydebug ('p_confirmed_sec_qty = ' || p_confirmed_sec_qty );
1244 mydebug ('p_confirmed_serials = ' || p_confirmed_serials );
1245 mydebug ('p_serial_allocated_flag = ' || p_serial_allocated_flag );
1246 mydebug ('p_lpn_match = ' || p_lpn_match );
1247 mydebug ('p_lpn_match_lpn_id = ' || p_lpn_match_lpn_id || ':' || l_lpn_match_lpn_id);
1248 mydebug ('p_container_item_id = ' || p_container_item_id || ':' || l_container_item_id);
1249 mydebug ('p_lot_controlled = ' || p_lot_controlled );
1250 mydebug ('p_serial_controlled = ' || p_serial_controlled );
1251
1252 IF p_action = 'UPDATE_LOADED' THEN
1253 update_loaded_part
1254 (p_user_id => p_user_id,
1255 p_transaction_temp_id1 => p_transaction_temp_id,
1256 p_transaction_temp_id2 => p_remaining_temp_id,
1257 p_transfer_lpn_id => l_transfer_lpn_id,
1258 p_transaction_uom => p_confirmed_uom,
1259 p_transaction_quantity => p_confirmed_trx_qty,
1260 p_lot_numbers => p_confirmed_lots,
1261 p_lot_transaction_quantity => p_confirmed_lot_trx_qty,
1262 p_secondary_uom => p_confirmed_sec_uom,
1263 p_secondary_quantity => p_confirmed_sec_qty,
1264 p_serial_numbers => p_confirmed_serials,
1265 p_serial_allocated_flag => p_serial_allocated_flag,
1266 p_lot_controlled => p_lot_controlled,
1267 p_serial_controlled => p_serial_controlled,
1268 x_return_status => x_return_status,
1269 x_msg_count => x_msg_count,
1270 x_msg_data => x_msg_data);
1271
1272 mydebug('x_return_status : ' || x_return_status);
1273 IF x_return_status <> l_g_ret_sts_success THEN
1274 RAISE fnd_api.g_exc_error;
1275 END IF;
1276
1277 ELSE
1278 l_progress := '200';
1279 mydebug ('l_progress: ' || l_progress || ' : Call Can_picdrop to check Move order line status' );
1280 x_cms_check := 'PASS';
1281 -- no need to do CMS check for BULK task
1282 IF p_transaction_temp_id <> p_parent_line_id THEN
1283 x_cms_check := can_pickdrop(p_transaction_temp_id );
1284 mydebug ('x_cms_check: ' || x_cms_check );
1285 IF x_cms_check = 'FAIL'
1286 THEN
1287 --fnd_message.set_name('WMS', 'WMS_CANCELLED_SOURCE');
1288 -- Source of the task is cancelled by source.. F2 to rollback
1289 --fnd_msg_pub.ADD;
1290 RAISE fnd_api.g_exc_error;
1291 END IF;
1292 END IF;
1293
1294
1295 /* Update the LPN context to "Packing context" (8).
1296 -- if p_lpn_match = 1,3 (exact match or fully consumable LPN) then
1297 -- p_lpn_match_lpn_id will be set to Packing context(8) otherwise , we will not
1298 -- change the context of from lpn .
1299 -- Always set the status of p_transfer_lpn_id = Packing context(8) , whether
1300 -- pre-generated or already in Packing context" */
1301 --
1302 l_progress := '200';
1303 mydebug ('l_progress: ' || l_progress );
1304 mydebug ('Updating LPN context for: ' || l_lpn_match_lpn_id || ' And ' || l_transfer_lpn_id);
1305 IF p_lpn_match in (1,3) THEN -- fully consumable lpn or exact match
1306 IF l_lpn_id IS NULL THEN -- lpn_id column of MMTT
1307 /*If we are transferring the contents of from lpn (ie. UI had Xfr LPN enabled
1308 instead of INTO LPN) then do not change the context of the LPN to packing.
1309 TM needs it to be 'resides in inv' to be able to unpack the material */
1310 BEGIN
1311 -- Bug5659809: update last_update_date and last_update_by as well
1312 UPDATE wms_license_plate_numbers
1313 SET lpn_context = l_lpn_context_packing
1314 , last_update_date = SYSDATE
1315 , last_updated_by = fnd_global.user_id
1316 WHERE lpn_id = l_lpn_match_lpn_id
1317 AND lpn_context = l_lpn_context_inv --, l_transfer_lpn_id)
1318 AND organization_id = p_organization_id;
1319
1320 IF SQL%NOTFOUND THEN
1321 mydebug ('Cannot find LPNs to update the context' );
1322 fnd_message.set_name('WMS', 'WMS_WRONG_FROM_LPN_CONTEXT');
1323 -- FROM LPN Context is not valid '
1324 fnd_msg_pub.ADD;
1325 RAISE fnd_api.g_exc_error;
1326
1327 END IF;
1328 EXCEPTION
1329 WHEN OTHERS THEN
1330 mydebug ('Others exception while updating From LPN context: ' || SQLCODE);
1331 RAISE fnd_api.g_exc_error;
1332 END ;
1333 END IF;
1334 END IF;
1335 l_progress := '300';
1336 mydebug ('l_progress: ' || l_progress );
1337 /*If we are transferring the contents of from lpn (fully consumable) (ie. UI had Xfr LPN enabled
1338 instead of INTO LPN) then do not change the context of the LPN to packing.
1339 TM needs it to be 'resides in inv' to be able to unpack the material */
1340 IF (l_lpn_id IS NOT NULL AND
1341 l_lpn_id <> l_transfer_lpn_id)
1342 OR
1343 (l_lpn_id IS NULL)
1344 THEN
1345 BEGIN
1346
1347 -- Bug5659809: update last_update_date and last_update_by as well
1348 UPDATE wms_license_plate_numbers
1349 SET lpn_context = l_lpn_context_packing
1350 , last_update_date = SYSDATE
1351 , last_updated_by = fnd_global.user_id
1352 WHERE lpn_id = l_transfer_lpn_id
1353 AND lpn_context in (l_lpn_context_packing , l_lpn_context_pregenerated)
1354 AND organization_id = p_organization_id;
1355
1356 IF SQL%NOTFOUND THEN
1357 mydebug ('Cannot find LPNs to update the context' );
1358 fnd_message.set_name('WMS', 'WMS_WRONG_TO_LPN_CONTEXT');
1359 -- To LPN Context is not valid
1360 fnd_msg_pub.ADD;
1361
1362 RAISE fnd_api.g_exc_error;
1363 END IF;
1364 EXCEPTION
1365 WHEN OTHERS THEN
1366 mydebug ('Others exception while updating To LPN context: ' || SQLCODE);
1367 RAISE fnd_api.g_exc_error;
1368 END ;
1369 END IF;
1370 -- Find a matching MMTT within the given header_id only if
1371 -- p_action = LOAD_MULTIPLE. for LOAD_SINGLE, we need not try to find
1372 -- a mergeable MMTT
1373 l_progress := '400';
1374 mydebug ('l_progress: ' || l_progress );
1375 IF p_action = l_g_action_split OR
1376 p_action = l_g_action_load_multiple -- ('SPLIT', 'LOAD_MULTIPLE')
1377 THEN
1378 l_progress := '410';
1379 mydebug ('l_progress: ' || l_progress );
1380 FOR rec_split_mmtts IN cur_split_mmtts
1381 LOOP
1382 l_progress := '420';
1383 mydebug ('l_progress: ' || l_progress );
1384 l_transaction_temp_id_to_merge := rec_split_mmtts.transaction_temp_id;
1385 mydebug('in loop..l_transaction_temp_id_to_merge = ' || l_transaction_temp_id_to_merge );
1386 EXIT;
1387 END LOOP;
1388 END IF;
1389
1390
1391 l_progress := '500';
1392 mydebug ('l_progress: ' || l_progress );
1393 mydebug('l_transaction_temp_id_to_merge = ' || l_transaction_temp_id_to_merge );
1394
1395 -- For pick short , it should work as a split so that we can process the workflow
1396 IF p_exception = l_g_exception_short
1397 THEN
1398 l_action := l_g_action_split; -- SPLIT
1399 ELSE
1400 l_action := p_action;
1401 END IF;
1402
1403 mydebug('l_action: ' || l_action);
1404 IF l_transaction_temp_id_to_merge IS NULL
1405 THEN
1406 IF l_action = l_g_action_split THEN
1407 l_insert := 'Y'; --insert new MMTT
1408 l_update := 'Y1'; -- update original MMTT to reduce qty
1409 ELSE -- LOAD_SINGLE or LOAD_MULTIPLE
1410 l_insert := 'N'; -- do not insert new MMTT
1411 l_update := 'Y1'; -- update original MMTT = conmfirmed qty
1412 END IF;
1413 ELSE
1414 l_insert := 'N'; -- Do not insert new MMTT
1415 l_update := 'Y2'; -- 2 updates. 1- original MMTT to reduce qty
1416 -- 2- mergeable MMTT to add qty
1417 END IF;
1418 mydebug('l_insert:' || l_insert || ':l_update:'|| l_update);
1419 proc_insert_update_mmtt
1420 (p_action => l_action
1421 ,p_insert => l_insert
1422 ,p_update => l_update
1423 ,p_organization_id => p_organization_id
1424 ,p_user_id => p_user_id
1425 ,p_transaction_header_id => p_transaction_header_id
1426 ,p_transaction_temp_id => p_transaction_temp_id
1427 ,p_transaction_temp_id_to_merge => l_transaction_temp_id_to_merge
1428 ,p_lpn_id => l_lpn_id
1429 ,p_content_lpn_id => l_content_lpn_id
1430 ,p_transfer_lpn_id => l_transfer_lpn_id
1431 ,p_confirmed_sub => p_confirmed_sub
1432 ,p_confirmed_locator_id => p_confirmed_locator_id
1433 ,p_confirmed_uom => p_confirmed_uom
1434 ,p_suggested_uom => p_suggested_uom
1435 ,p_primary_uom => p_primary_uom
1436 ,p_inventory_item_id => p_inventory_item_id
1437 ,p_revision => p_revision
1438 ,p_confirmed_trx_qty => p_confirmed_trx_qty
1439 ,p_confirmed_lots => p_confirmed_lots
1440 ,p_confirmed_lot_trx_qty => p_confirmed_lot_trx_qty
1441 ,p_confirmed_sec_uom => p_confirmed_sec_uom
1442 ,p_confirmed_sec_qty => p_confirmed_sec_qty
1443 ,p_confirmed_serials => p_confirmed_serials
1444 ,p_container_item_id => l_container_item_id
1445 ,p_lpn_match => p_lpn_match
1446 ,p_lpn_match_lpn_id => l_lpn_match_lpn_id
1447 ,p_serial_allocated_flag => p_serial_allocated_flag
1448 ,p_lot_controlled => p_lot_controlled
1449 ,p_serial_controlled => p_serial_controlled
1450 ,p_wms_task_status => l_g_task_loaded
1451 ,p_exception => p_exception
1452 ,p_parent_lpn_id => l_parent_lpn_id
1453 ,x_new_transaction_temp_id => l_new_transaction_temp_id
1454 ,x_return_status => x_return_status
1455 ,x_msg_count => x_msg_count
1456 ,x_msg_data => x_msg_data);
1457 IF x_return_status <> l_g_ret_sts_success THEN
1458 mydebug('x_return_status : ' || x_return_status);
1459 RAISE fnd_api.G_EXC_ERROR;
1460 END IF;
1461 x_new_transaction_temp_id := l_new_transaction_temp_id;
1462 mydebug('x_new_transaction_temp_id : ' || x_new_transaction_temp_id);
1463
1464 /* Task management
1465 Action l_insert L_update update orginalTSK UpdMergeTSK InsertNewTSK
1466 SPLIT Y Y1 N N Y
1467 SPLIT N Y2 Y Y N
1468 LOAD_M N Y1 Y N N
1469 LOAD_M N Y2 Y-Delete Y N
1470 LOAD_S N Y1 Y N N
1471 */
1472
1473 l_progress := '500';
1474 mydebug ('l_progress: ' || l_progress );
1475 proc_insert_update_task -- new task using p_transaction_temp_id);
1476 (p_action => l_action
1477 ,p_insert => l_insert
1478 ,p_update => l_update
1479 ,p_temp_id => p_transaction_temp_id
1480 ,p_new_temp_id => l_new_transaction_temp_id -- will be notNULL only if p_insert=Y
1481 ,p_merge_temp_id => l_transaction_temp_id_to_merge
1482 ,p_task_status => l_g_task_loaded
1483 ,p_user_id => p_user_id
1484 ,x_return_status => x_return_status
1485 ,x_msg_count => x_msg_count
1486 ,x_msg_data => x_msg_data);
1487
1488 IF x_return_status <> l_g_ret_sts_success THEN
1489 --x_return_status := l_g_ret_sts_success;
1490 RAISE fnd_api.G_EXC_ERROR;
1491 END IF;
1492 END IF;
1493
1494 l_progress := 'END';
1495 mydebug('COmmit ' );
1496 COMMIT;
1497 mydebug('End .. ' || l_proc_name);
1498 EXCEPTION
1499 WHEN fnd_api.g_exc_error THEN
1500 x_return_status := l_g_ret_sts_error;
1501 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1502 mydebug('ROLLBACK ' );
1503 ROLLBACK ;
1504 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
1505 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
1506 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
1507 WHEN fnd_api.g_exc_unexpected_error THEN
1508 x_return_status := fnd_api.g_ret_sts_unexp_error;
1509 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1510 mydebug('ROLLBACK ' );
1511 ROLLBACK ;
1512 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
1513 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
1514 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
1515 WHEN OTHERS THEN
1516 x_return_status := l_g_ret_sts_unexp_error;
1517 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1518 mydebug('ROLLBACK ' );
1519 ROLLBACK ;
1520 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
1521 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
1522 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
1523
1524 END task_merge_split;
1525
1526
1527 PROCEDURE proc_insert_update_task
1528 (p_action IN VARCHAR2
1529 ,p_insert IN VARCHAR2
1530 ,p_update IN VARCHAR2
1531 ,p_temp_id IN NUMBER
1532 ,p_new_temp_id IN NUMBER
1533 ,p_merge_temp_id IN NUMBER
1534 ,p_task_status 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 IS
1540 l_proc_name VARCHAR2(30) := 'proc_insert_update_task';
1541 l_progress VARCHAR2(30) := '100';
1542 l_transaction_temp_id NUMBER := NULL;
1543 BEGIN
1544 mydebug(l_proc_name || ': Before Insert into WMSDT');
1545
1546 x_return_status := l_g_ret_sts_success;
1547
1548 mydebug ('p_action = ' || p_action);
1549 mydebug ('p_insert = ' || p_insert);
1550 mydebug ('p_update = ' || p_update);
1551 mydebug ('p_temp_id = ' || p_temp_id);
1552 mydebug ('p_new_temp_id = ' || p_new_temp_id);
1553 mydebug ('p_merge_temp_id = ' || p_merge_temp_id);
1554 mydebug ('p_task_status = ' || p_task_status);
1555
1556 IF p_insert = 'Y' THEN
1557 INSERT INTO wms_dispatched_tasks
1558 (task_id
1559 ,transaction_temp_id
1560 ,organization_id
1561 ,user_task_type
1562 ,person_id
1563 ,effective_start_date
1564 ,effective_end_date
1565 ,equipment_id
1566 ,equipment_instance
1567 ,person_resource_id
1568 ,machine_resource_id
1569 ,status
1570 ,dispatched_time
1571 ,loaded_time
1572 ,drop_off_time
1573 ,last_update_date
1574 ,last_updated_by
1575 ,creation_date
1576 ,created_by
1577 ,last_update_login
1578 ,attribute_category
1579 ,attribute1
1580 ,attribute2
1581 ,attribute3
1582 ,attribute4
1583 ,attribute5
1584 ,attribute6
1585 ,attribute7
1586 ,attribute8
1587 ,attribute9
1588 ,attribute10
1589 ,attribute11
1590 ,attribute12
1591 ,attribute13
1592 ,attribute14
1593 ,attribute15
1594 ,task_type
1595 ,priority
1596 ,task_group_id
1597 ,device_id
1598 ,device_inVoked
1599 ,device_request_id
1600 ,suggested_dest_subinventory
1601 ,suggested_dest_locator_id
1602 ,operation_plan_id
1603 ,move_order_line_id
1604 ,transfer_lpn_id )
1605 (SELECT wms_dispatched_tasks_s.NEXTVAL
1606 ,p_new_temp_id -- parameter
1607 ,organization_id
1608 ,user_task_type
1609 ,person_id
1610 ,effective_start_date
1611 ,effective_end_date
1612 ,equipment_id
1613 ,equipment_instance
1614 ,person_resource_id
1615 ,machine_resource_id
1616 ,p_task_status -- parameter
1617 ,dispatched_time
1618 ,SYSDATE
1619 ,drop_off_time
1620 ,SYSDATE
1621 ,last_updated_by
1622 ,SYSDATE
1623 ,p_user_id -- parameter
1624 ,last_update_login
1625 ,attribute_category
1626 ,attribute1
1627 ,attribute2
1628 ,attribute3
1629 ,attribute4
1630 ,attribute5
1631 ,attribute6
1632 ,attribute7
1633 ,attribute8
1634 ,attribute9
1635 ,attribute10
1636 ,attribute11
1637 ,attribute12
1638 ,attribute13
1639 ,attribute14
1640 ,attribute15
1641 ,task_type
1642 ,priority
1643 ,task_group_id
1644 ,device_id
1645 ,device_invoked
1646 ,device_request_id
1647 ,suggested_dest_subinventory
1648 ,suggested_dest_locator_id
1649 ,operation_plan_id
1650 ,move_order_line_id
1651 ,transfer_lpn_id
1652 FROM wms_dispatched_tasks
1653 WHERE transaction_temp_id = p_temp_id);
1654 IF SQL%NOTFOUND THEN
1655 myDebug('Error inserting a new task using WDT record for : '|| p_temp_id);
1656 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
1657 -- Internal Error $ROUTINE
1658 fnd_message.set_token('ROUTINE', '- proc_insert_update_task' );
1659 fnd_msg_pub.ADD;
1660 RAISE fnd_api.G_EXC_ERROR;
1661 END IF;
1662 ELSE
1663 l_progress := '200';
1664 mydebug ('l_progress: ' || l_progress );
1665 IF p_update = 'Y1' THEN
1666 l_transaction_temp_id := p_temp_id; -- update only the original task
1667 ELSE
1668 l_transaction_temp_id := p_merge_temp_id; -- update the merged task
1669 END IF;
1670 l_progress := '250';
1671 mydebug('l_progress: ' || l_progress );
1672 mydebug('l_transaction_temp_id : ' || l_transaction_temp_id);
1673 UPDATE wms_dispatched_tasks
1674 SET status = p_task_status
1675 ,loaded_time = SYSDATE
1676 ,last_update_date = SYSDATE
1677 ,last_updated_by = p_user_id
1678 WHERE transaction_temp_id = l_transaction_temp_id;
1679 IF SQL%NOTFOUND THEN
1680 mydebug('l_progress : ' || l_progress);
1681 myDebug('Error updating task for : '|| l_transaction_temp_id);
1682 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
1683 -- Internal Error $ROUTINE
1684 fnd_message.set_token('ROUTINE', '- proc_insert_update_task' );
1685 fnd_msg_pub.ADD;
1686 RAISE fnd_api.G_EXC_ERROR;
1687 END IF;
1688 IF p_update = 'Y2' AND p_action = l_g_action_load_multiple THEN
1689 fnd_message.set_token('ROUTINE', '- proc_insert_update_task' );
1690 fnd_msg_pub.ADD;
1691 l_progress := '300';
1692 mydebug('l_progress: ' || l_progress );
1693 -- delete the original one with p_transaction_temp_id
1694 DELETE wms_dispatched_tasks
1695 WHERE transaction_temp_id = p_temp_id;
1696 IF SQL%NOTFOUND THEN
1697 myDebug('Error deleting task for : '|| l_transaction_temp_id);
1698 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
1699 -- Internal Error $ROUTINE
1700 fnd_message.set_token('ROUTINE', '- proc_insert_update_task' );
1701 fnd_msg_pub.ADD;
1702 RAISE fnd_api.G_EXC_ERROR;
1703 END IF;
1704 END IF;
1705
1706 END IF;
1707
1708 mydebug('End .. ' || l_proc_name);
1709 EXCEPTION
1710 WHEN fnd_api.g_exc_error THEN
1711 x_return_status := l_g_ret_sts_error;
1712 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1713 mydebug('ROLLBACK ' );
1714 ROLLBACK ;
1715 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
1716 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
1717 WHEN fnd_api.g_exc_unexpected_error THEN
1718 x_return_status := fnd_api.g_ret_sts_unexp_error;
1719 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1720 mydebug('ROLLBACK ' );
1721 ROLLBACK ;
1722 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
1723 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
1724 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
1725 WHEN OTHERS THEN
1726 x_return_status := l_g_ret_sts_unexp_error;
1727 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
1728 mydebug('ROLLBACK ' );
1729 ROLLBACK ;
1730 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
1731 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
1732
1733 END proc_insert_update_task;
1734
1735 PROCEDURE proc_insert_update_mmtt
1736 (p_action IN VARCHAR2
1737 ,p_insert IN VARCHAR2
1738 ,p_update IN VARCHAR2
1739 ,p_organization_id IN NUMBER
1740 ,p_user_id IN NUMBER
1741 ,p_transaction_header_id IN NUMBER
1742 ,p_transaction_temp_id IN NUMBER
1743 ,p_transaction_temp_id_to_merge IN NUMBER
1744 ,p_lpn_id IN NUMBER
1745 ,p_content_lpn_id IN NUMBER
1746 ,p_transfer_lpn_id IN NUMBER
1747 ,p_confirmed_sub IN VARCHAR2
1748 ,p_confirmed_locator_id IN NUMBER
1749 ,p_confirmed_uom IN VARCHAR2
1750 ,p_suggested_uom IN VARCHAR2
1751 ,p_primary_uom IN VARCHAR2
1752 ,p_inventory_item_id IN NUMBER
1753 ,p_revision IN VARCHAR2
1754 ,p_confirmed_trx_qty IN NUMBER
1755 ,p_confirmed_lots IN VARCHAR2
1756 ,p_confirmed_lot_trx_qty IN VARCHAR2
1757 ,p_confirmed_sec_uom IN VARCHAR2
1758 ,p_confirmed_sec_qty IN VARCHAR2
1759 ,p_confirmed_serials IN VARCHAR2
1760 ,p_container_item_id IN NUMBER
1761 ,p_wms_task_status IN NUMBER
1762 ,p_lpn_match IN NUMBER
1763 ,p_lpn_match_lpn_id IN NUMBER
1764 ,p_serial_allocated_flag IN VARCHAR2
1765 ,p_lot_controlled IN VARCHAR2 -- Y/N
1766 ,p_serial_controlled IN VARCHAR2 -- Y/N
1767 ,p_exception IN VARCHAR2 -- SHORT/OVER
1768 ,p_parent_lpn_id IN NUMBER
1769 ,x_new_transaction_temp_id OUT NOCOPY NUMBER
1770 ,x_return_status OUT NOCOPY VARCHAR2
1771 ,x_msg_count OUT NOCOPY NUMBER
1772 ,x_msg_data OUT NOCOPY VARCHAR2)
1773 IS
1774 l_proc_name VARCHAR2(30) := 'PROC_INSERT_UPDATE_MMTT';
1775 l_progress VARCHAR2(30) := '100';
1776 l_new_transaction_temp_id NUMBER := NULL;
1777 l_confirmed_prim_qty NUMBER := 0;
1778 l_confirmed_sugg_qty NUMBER := 0;
1779 l_confirmed_sec_qty NUMBER := 0;
1780 l_confirmed_lot_trx_sec_qty NUMBER := 0;
1781 n NUMBER := 1;
1782 m NUMBER := 1;
1783 l_delimiter VARCHAR(30) := ':';
1784 l_rem_lot_pri_qty NUMBER;
1785 l_rem_lot_trx_qty NUMBER;
1786 l_rem_lot_sec_qty NUMBER;
1787
1788
1789 BEGIN
1790 mydebug('In ..' || l_proc_name );
1791
1792 x_return_status := l_g_ret_sts_success;
1793
1794 mydebug ('p_action = ' || p_action );
1795 mydebug ('p_insert = ' || p_insert );
1796 mydebug ('p_update = ' || p_update );
1797 mydebug ('p_transaction_header_id = ' || p_transaction_header_id );
1798 mydebug ('p_transaction_temp_id = ' || p_transaction_temp_id );
1799 mydebug ('p_lpn_id = ' || p_lpn_id );
1800 mydebug ('p_content_lpn_id = ' || p_content_lpn_id );
1801 mydebug ('p_parent_lpn_id = ' || p_parent_lpn_id );
1802 mydebug ('p_transfer_lpn_id = ' || p_transfer_lpn_id );
1803 mydebug ('p_confirmed_sub = ' || p_confirmed_sub );
1804 mydebug ('p_confirmed_locator_id = ' || p_confirmed_locator_id );
1805 mydebug ('p_confirmed_uom = ' || p_confirmed_uom );
1806 mydebug ('p_suggested_uom = ' || p_suggested_uom );
1807 mydebug ('p_primary_uom = ' || p_primary_uom );
1808 mydebug ('p_inventory_item_id = ' || p_inventory_item_id );
1809 mydebug ('p_revision = ' || p_revision );
1810 mydebug ('p_confirmed_trx_qty = ' || p_confirmed_trx_qty );
1811 mydebug ('p_confirmed_lots = ' || p_confirmed_lots );
1812 mydebug ('p_confirmed_lot_trx_qty = ' || p_confirmed_lot_trx_qty );
1813 mydebug ('p_confirmed_sec_uom = ' || p_confirmed_sec_uom );
1814 mydebug ('p_confirmed_sec_qty = ' || p_confirmed_sec_qty );
1815 mydebug ('p_confirmed_serials = ' || p_confirmed_serials );
1816 mydebug ('p_container_item_id = ' || p_container_item_id );
1817 mydebug ('p_lpn_match = ' || p_lpn_match );
1818 mydebug ('p_lpn_match_lpn_id = ' || p_lpn_match_lpn_id );
1819 mydebug ('p_exception = ' || p_exception );
1820
1821
1822 /* p_suggested_uom is the uom in which allocations are created. IN allocation MMTT it
1823 * is the transaction_uom .
1824 * p_confirmed_uom is the uom confirmed on the UI. This may or may not be equal
1825 * to suggested UOM
1826 * p_primary_uom is always static.*/
1827 IF p_primary_uom <> p_confirmed_uom
1828 THEN
1829 l_confirmed_prim_qty := inv_convert.inv_um_convert
1830 (item_id => p_inventory_item_id
1831 ,precision => l_g_decimal_precision
1832 ,from_quantity => p_confirmed_trx_qty
1833 ,from_unit => p_confirmed_uom
1834 ,to_unit => p_primary_uom
1835 ,from_name => NULL
1836 ,to_name => NULL);
1837 ELSE
1838 l_confirmed_prim_qty := p_confirmed_trx_qty;
1839 END IF;
1840
1841
1842 IF p_suggested_uom <> p_confirmed_uom
1843 THEN
1844 l_confirmed_sugg_qty := inv_convert.inv_um_convert
1845 (item_id => p_inventory_item_id
1846 ,precision => l_g_decimal_precision
1847 ,from_quantity => p_confirmed_trx_qty
1848 ,from_unit => p_confirmed_uom
1849 ,to_unit => p_suggested_uom
1850 ,from_name => NULL
1851 ,to_name => NULL);
1852 ELSE
1853 l_confirmed_sugg_qty := p_confirmed_trx_qty;
1854 END IF;
1855
1856
1857 -- Create new MMTT line
1858
1859 IF p_lot_controlled = 'Y'
1860 -- For lot and Lot+serial controlled items, secondary quantity will be stored at lot level (MTLT)
1861 -- for vanilla items and serial controlled items it will be stored at MMTT level
1862 THEN
1863 WHILE (n <> 0)
1864 LOOP
1865 n := INSTR(p_confirmed_sec_qty,l_delimiter,m,1);
1866 IF n = 0 THEN -- Last part OF the string
1867 l_confirmed_lot_trx_sec_qty := NVL(substr(p_confirmed_sec_qty,m,length(p_confirmed_sec_qty)), 0);
1868 ELSE
1869 l_confirmed_lot_trx_sec_qty := substr(p_confirmed_sec_qty,m,n-m) ;-- start at M get m-n chrs.
1870 m := n+1;
1871 END IF;
1872 l_confirmed_sec_qty := l_confirmed_sec_qty + l_confirmed_lot_trx_sec_qty;
1873 END LOOP;
1874 ELSE
1875 l_confirmed_sec_qty := p_confirmed_sec_qty;
1876 END IF;
1877
1878 mydebug ('l_confirmed_sec_qty = ' || l_confirmed_sec_qty);
1879
1880 IF p_insert = 'Y' THEN
1881 l_progress := '110';
1882 SELECT mtl_material_transactions_s.NEXTVAL
1883 INTO l_new_transaction_temp_id
1884 FROM DUAL;
1885 x_new_transaction_temp_id := l_new_transaction_temp_id;
1886
1887 mydebug(l_proc_name || ': l_new_transaction_temp_id = ' || l_new_transaction_temp_id);
1888
1889 INSERT INTO mtl_material_transactions_temp
1890 ( TRANSACTION_HEADER_ID
1891 ,TRANSACTION_TEMP_ID
1892 ,SOURCE_CODE
1893 ,SOURCE_LINE_ID
1894 ,TRANSACTION_MODE
1895 ,LOCK_FLAG
1896 ,LAST_UPDATE_DATE
1897 ,LAST_UPDATED_BY
1898 ,CREATION_DATE
1899 ,CREATED_BY
1900 ,LAST_UPDATE_LOGIN
1901 ,REQUEST_ID
1902 ,PROGRAM_APPLICATION_ID
1903 ,PROGRAM_ID
1904 ,PROGRAM_UPDATE_DATE
1905 ,INVENTORY_ITEM_ID
1906 ,REVISION
1907 ,ORGANIZATION_ID
1908 ,SUBINVENTORY_CODE
1909 ,LOCATOR_ID
1910 ,TRANSACTION_QUANTITY
1911 ,PRIMARY_QUANTITY
1912 ,TRANSACTION_UOM
1913 ,TRANSACTION_COST
1914 ,TRANSACTION_TYPE_ID
1915 ,TRANSACTION_ACTION_ID
1916 ,TRANSACTION_SOURCE_TYPE_ID
1917 ,TRANSACTION_SOURCE_ID
1918 ,TRANSACTION_SOURCE_NAME
1919 ,TRANSACTION_DATE
1920 ,ACCT_PERIOD_ID
1921 ,DISTRIBUTION_ACCOUNT_ID
1922 ,TRANSACTION_REFERENCE
1923 ,REQUISITION_LINE_ID
1924 ,REQUISITION_DISTRIBUTION_ID
1925 ,REASON_ID
1926 ,LOT_NUMBER
1927 ,LOT_EXPIRATION_DATE
1928 ,SERIAL_NUMBER
1929 ,RECEIVING_DOCUMENT
1930 ,DEMAND_ID
1931 ,RCV_TRANSACTION_ID
1932 ,MOVE_TRANSACTION_ID
1933 ,COMPLETION_TRANSACTION_ID
1934 ,WIP_ENTITY_TYPE
1935 ,SCHEDULE_ID
1936 ,REPETITIVE_LINE_ID
1937 ,EMPLOYEE_CODE
1938 ,PRIMARY_SWITCH
1939 ,SCHEDULE_UPDATE_CODE
1940 ,SETUP_TEARDOWN_CODE
1941 ,ITEM_ORDERING
1942 ,NEGATIVE_REQ_FLAG
1943 ,OPERATION_SEQ_NUM
1944 ,PICKING_LINE_ID
1945 ,TRX_SOURCE_LINE_ID
1946 ,TRX_SOURCE_DELIVERY_ID
1947 ,PHYSICAL_ADJUSTMENT_ID
1948 ,CYCLE_COUNT_ID
1949 ,RMA_LINE_ID
1950 ,CUSTOMER_SHIP_ID
1951 ,CURRENCY_CODE
1952 ,CURRENCY_CONVERSION_RATE
1953 ,CURRENCY_CONVERSION_TYPE
1954 ,CURRENCY_CONVERSION_DATE
1955 ,USSGL_TRANSACTION_CODE
1956 ,VENDOR_LOT_NUMBER
1957 ,ENCUMBRANCE_ACCOUNT
1958 ,ENCUMBRANCE_AMOUNT
1959 ,SHIP_TO_LOCATION
1960 ,SHIPMENT_NUMBER
1961 ,TRANSFER_COST
1962 ,TRANSPORTATION_COST
1963 ,TRANSPORTATION_ACCOUNT
1964 ,FREIGHT_CODE
1965 ,CONTAINERS
1966 ,WAYBILL_AIRBILL
1967 ,EXPECTED_ARRIVAL_DATE
1968 ,TRANSFER_SUBINVENTORY
1969 ,TRANSFER_ORGANIZATION
1970 ,TRANSFER_TO_LOCATION
1971 ,NEW_AVERAGE_COST
1972 ,VALUE_CHANGE
1973 ,PERCENTAGE_CHANGE
1974 ,MATERIAL_ALLOCATION_TEMP_ID
1975 ,DEMAND_SOURCE_HEADER_ID
1976 ,DEMAND_SOURCE_LINE
1977 ,DEMAND_SOURCE_DELIVERY
1978 ,ITEM_SEGMENTS
1979 ,ITEM_DESCRIPTION
1980 ,ITEM_TRX_ENABLED_FLAG
1981 ,ITEM_LOCATION_CONTROL_CODE
1982 ,ITEM_RESTRICT_SUBINV_CODE
1983 ,ITEM_RESTRICT_LOCATORS_CODE
1984 ,ITEM_REVISION_QTY_CONTROL_CODE
1985 ,ITEM_PRIMARY_UOM_CODE
1986 ,ITEM_UOM_CLASS
1987 ,ITEM_SHELF_LIFE_CODE
1988 ,ITEM_SHELF_LIFE_DAYS
1989 ,ITEM_LOT_CONTROL_CODE
1990 ,ITEM_SERIAL_CONTROL_CODE
1991 ,ITEM_INVENTORY_ASSET_FLAG
1992 ,ALLOWED_UNITS_LOOKUP_CODE
1993 ,DEPARTMENT_ID
1994 ,DEPARTMENT_CODE
1995 ,WIP_SUPPLY_TYPE
1996 ,SUPPLY_SUBINVENTORY
1997 ,SUPPLY_LOCATOR_ID
1998 ,VALID_SUBINVENTORY_FLAG
1999 ,VALID_LOCATOR_FLAG
2000 ,LOCATOR_SEGMENTS
2001 ,CURRENT_LOCATOR_CONTROL_CODE
2002 ,NUMBER_OF_LOTS_ENTERED
2003 ,WIP_COMMIT_FLAG
2004 ,NEXT_LOT_NUMBER
2005 ,LOT_ALPHA_PREFIX
2006 ,NEXT_SERIAL_NUMBER
2007 ,SERIAL_ALPHA_PREFIX
2008 ,SHIPPABLE_FLAG
2009 ,POSTING_FLAG
2010 ,REQUIRED_FLAG
2011 ,PROCESS_FLAG
2012 ,ERROR_CODE
2013 ,ERROR_EXPLANATION
2014 ,ATTRIBUTE_CATEGORY
2015 ,ATTRIBUTE1
2016 ,ATTRIBUTE2
2017 ,ATTRIBUTE3
2018 ,ATTRIBUTE4
2019 ,ATTRIBUTE5
2020 ,ATTRIBUTE6
2021 ,ATTRIBUTE7
2022 ,ATTRIBUTE8
2023 ,ATTRIBUTE9
2024 ,ATTRIBUTE10
2025 ,ATTRIBUTE11
2026 ,ATTRIBUTE12
2027 ,ATTRIBUTE13
2028 ,ATTRIBUTE14
2029 ,ATTRIBUTE15
2030 ,MOVEMENT_ID
2031 ,RESERVATION_QUANTITY
2032 ,SHIPPED_QUANTITY
2033 ,TRANSACTION_LINE_NUMBER
2034 ,TASK_ID
2035 ,TO_TASK_ID
2036 ,SOURCE_TASK_ID
2037 ,PROJECT_ID
2038 ,SOURCE_PROJECT_ID
2039 ,PA_EXPENDITURE_ORG_ID
2040 ,TO_PROJECT_ID
2041 ,EXPENDITURE_TYPE
2042 ,FINAL_COMPLETION_FLAG
2043 ,TRANSFER_PERCENTAGE
2044 ,TRANSACTION_SEQUENCE_ID
2045 ,MATERIAL_ACCOUNT
2046 ,MATERIAL_OVERHEAD_ACCOUNT
2047 ,RESOURCE_ACCOUNT
2048 ,OUTSIDE_PROCESSING_ACCOUNT
2049 ,OVERHEAD_ACCOUNT
2050 ,FLOW_SCHEDULE
2051 ,COST_GROUP_ID
2052 ,TRANSFER_COST_GROUP_ID
2053 ,DEMAND_CLASS
2054 ,QA_COLLECTION_ID
2055 ,KANBAN_CARD_ID
2056 ,OVERCOMPLETION_TRANSACTION_QTY
2057 ,OVERCOMPLETION_PRIMARY_QTY
2058 ,OVERCOMPLETION_TRANSACTION_ID
2059 ,END_ITEM_UNIT_NUMBER
2060 ,SCHEDULED_PAYBACK_DATE
2061 ,LINE_TYPE_CODE
2062 ,PARENT_TRANSACTION_TEMP_ID
2063 ,PUT_AWAY_STRATEGY_ID
2064 ,PUT_AWAY_RULE_ID
2065 ,PICK_STRATEGY_ID
2066 ,PICK_RULE_ID
2067 ,MOVE_ORDER_LINE_ID
2068 ,TASK_GROUP_ID
2069 ,PICK_SLIP_NUMBER
2070 ,RESERVATION_ID
2071 ,COMMON_BOM_SEQ_ID
2072 ,COMMON_ROUTING_SEQ_ID
2073 ,ORG_COST_GROUP_ID
2074 ,COST_TYPE_ID
2075 ,TRANSACTION_STATUS
2076 ,STANDARD_OPERATION_ID
2077 ,TASK_PRIORITY
2078 ,WMS_TASK_TYPE
2079 ,PARENT_LINE_ID
2080 ,LPN_ID
2081 ,TRANSFER_LPN_ID
2082 ,WMS_TASK_STATUS
2083 ,CONTENT_LPN_ID
2084 ,CONTAINER_ITEM_ID
2085 ,CARTONIZATION_ID
2086 ,PICK_SLIP_DATE
2087 ,REBUILD_ITEM_ID
2088 ,REBUILD_SERIAL_NUMBER
2089 ,REBUILD_ACTIVITY_ID
2090 ,REBUILD_JOB_NAME
2091 ,ORGANIZATION_TYPE
2092 ,TRANSFER_ORGANIZATION_TYPE
2093 ,OWNING_ORGANIZATION_ID
2094 ,OWNING_TP_TYPE
2095 ,XFR_OWNING_ORGANIZATION_ID
2096 ,TRANSFER_OWNING_TP_TYPE
2097 ,PLANNING_ORGANIZATION_ID
2098 ,PLANNING_TP_TYPE
2099 ,XFR_PLANNING_ORGANIZATION_ID
2100 ,TRANSFER_PLANNING_TP_TYPE
2101 ,SECONDARY_UOM_CODE
2102 ,SECONDARY_TRANSACTION_QUANTITY
2103 ,TRANSACTION_BATCH_ID
2104 ,TRANSACTION_BATCH_SEQ
2105 ,ALLOCATED_LPN_ID
2106 ,SCHEDULE_NUMBER
2107 ,SCHEDULED_FLAG
2108 ,CLASS_CODE
2109 ,SCHEDULE_GROUP
2110 ,BUILD_SEQUENCE
2111 ,BOM_REVISION
2112 ,ROUTING_REVISION
2113 ,BOM_REVISION_DATE
2114 ,ROUTING_REVISION_DATE
2115 ,ALTERNATE_BOM_DESIGNATOR
2116 ,ALTERNATE_ROUTING_DESIGNATOR
2117 ,OPERATION_PLAN_ID
2118 ,INTRANSIT_ACCOUNT
2119 ,FOB_POINT
2120 ,MOVE_ORDER_HEADER_ID
2121 ,SERIAL_ALLOCATED_FLAG
2122 )
2123 (SELECT
2124 TRANSACTION_HEADER_ID
2125 ,l_new_transaction_temp_id
2126 ,SOURCE_CODE
2127 ,SOURCE_LINE_ID
2128 ,TRANSACTION_MODE
2129 ,LOCK_FLAG
2130 ,SYSDATE -- it should not copy from original MMTT
2131 ,p_user_id -- it should not copy from original MMTT
2132 ,SYSDATE
2133 ,p_user_id
2134 ,LAST_UPDATE_LOGIN
2135 ,REQUEST_ID
2136 ,PROGRAM_APPLICATION_ID
2137 ,PROGRAM_ID
2138 ,PROGRAM_UPDATE_DATE
2139 ,INVENTORY_ITEM_ID
2140 ,REVISION
2141 ,ORGANIZATION_ID
2142 ,p_confirmed_sub
2143 ,p_confirmed_locator_id
2144 ,p_confirmed_trx_qty
2145 ,l_confirmed_prim_qty
2146 ,nvl(p_confirmed_uom, item_primary_uom_code)
2147 ,TRANSACTION_COST
2148 ,TRANSACTION_TYPE_ID
2149 ,TRANSACTION_ACTION_ID
2150 ,TRANSACTION_SOURCE_TYPE_ID
2151 ,TRANSACTION_SOURCE_ID
2152 ,TRANSACTION_SOURCE_NAME
2153 ,TRANSACTION_DATE
2154 ,ACCT_PERIOD_ID
2155 ,DISTRIBUTION_ACCOUNT_ID
2156 ,TRANSACTION_REFERENCE
2157 ,REQUISITION_LINE_ID
2158 ,REQUISITION_DISTRIBUTION_ID
2159 ,REASON_ID
2160 ,LOT_NUMBER
2161 ,LOT_EXPIRATION_DATE
2162 ,SERIAL_NUMBER
2163 ,RECEIVING_DOCUMENT
2164 ,DEMAND_ID
2165 ,RCV_TRANSACTION_ID
2166 ,MOVE_TRANSACTION_ID
2167 ,COMPLETION_TRANSACTION_ID
2168 ,WIP_ENTITY_TYPE
2169 ,SCHEDULE_ID
2170 ,REPETITIVE_LINE_ID
2171 ,EMPLOYEE_CODE
2172 ,PRIMARY_SWITCH
2173 ,SCHEDULE_UPDATE_CODE
2174 ,SETUP_TEARDOWN_CODE
2175 ,ITEM_ORDERING
2176 ,NEGATIVE_REQ_FLAG
2177 ,OPERATION_SEQ_NUM
2178 ,PICKING_LINE_ID
2179 ,TRX_SOURCE_LINE_ID
2180 ,TRX_SOURCE_DELIVERY_ID
2181 ,PHYSICAL_ADJUSTMENT_ID
2182 ,CYCLE_COUNT_ID
2183 ,RMA_LINE_ID
2184 ,CUSTOMER_SHIP_ID
2185 ,CURRENCY_CODE
2186 ,CURRENCY_CONVERSION_RATE
2187 ,CURRENCY_CONVERSION_TYPE
2188 ,CURRENCY_CONVERSION_DATE
2189 ,USSGL_TRANSACTION_CODE
2190 ,VENDOR_LOT_NUMBER
2191 ,ENCUMBRANCE_ACCOUNT
2192 ,ENCUMBRANCE_AMOUNT
2193 ,SHIP_TO_LOCATION
2194 ,SHIPMENT_NUMBER
2195 ,TRANSFER_COST
2196 ,TRANSPORTATION_COST
2197 ,TRANSPORTATION_ACCOUNT
2198 ,FREIGHT_CODE
2199 ,CONTAINERS
2200 ,WAYBILL_AIRBILL
2201 ,EXPECTED_ARRIVAL_DATE
2202 ,TRANSFER_SUBINVENTORY
2203 ,TRANSFER_ORGANIZATION
2204 ,TRANSFER_TO_LOCATION
2205 ,NEW_AVERAGE_COST
2206 ,VALUE_CHANGE
2207 ,PERCENTAGE_CHANGE
2208 ,MATERIAL_ALLOCATION_TEMP_ID
2209 ,DEMAND_SOURCE_HEADER_ID
2210 ,DEMAND_SOURCE_LINE
2211 ,DEMAND_SOURCE_DELIVERY
2212 ,ITEM_SEGMENTS
2213 ,ITEM_DESCRIPTION
2214 ,ITEM_TRX_ENABLED_FLAG
2215 ,ITEM_LOCATION_CONTROL_CODE
2216 ,ITEM_RESTRICT_SUBINV_CODE
2217 ,ITEM_RESTRICT_LOCATORS_CODE
2218 ,ITEM_REVISION_QTY_CONTROL_CODE
2219 ,ITEM_PRIMARY_UOM_CODE
2220 ,ITEM_UOM_CLASS
2221 ,ITEM_SHELF_LIFE_CODE
2222 ,ITEM_SHELF_LIFE_DAYS
2223 ,ITEM_LOT_CONTROL_CODE
2224 ,ITEM_SERIAL_CONTROL_CODE
2225 ,ITEM_INVENTORY_ASSET_FLAG
2226 ,ALLOWED_UNITS_LOOKUP_CODE
2227 ,DEPARTMENT_ID
2228 ,DEPARTMENT_CODE
2229 ,WIP_SUPPLY_TYPE
2230 ,SUPPLY_SUBINVENTORY
2231 ,SUPPLY_LOCATOR_ID
2232 ,VALID_SUBINVENTORY_FLAG
2233 ,VALID_LOCATOR_FLAG
2234 ,LOCATOR_SEGMENTS
2235 ,CURRENT_LOCATOR_CONTROL_CODE
2236 ,NUMBER_OF_LOTS_ENTERED
2237 ,WIP_COMMIT_FLAG
2238 ,NEXT_LOT_NUMBER
2239 ,LOT_ALPHA_PREFIX
2240 ,NEXT_SERIAL_NUMBER
2241 ,SERIAL_ALPHA_PREFIX
2242 ,SHIPPABLE_FLAG
2243 ,POSTING_FLAG
2244 ,REQUIRED_FLAG
2245 ,PROCESS_FLAG
2246 ,ERROR_CODE
2247 ,ERROR_EXPLANATION
2248 ,ATTRIBUTE_CATEGORY
2249 ,ATTRIBUTE1
2250 ,ATTRIBUTE2
2251 ,ATTRIBUTE3
2252 ,ATTRIBUTE4
2253 ,ATTRIBUTE5
2254 ,ATTRIBUTE6
2255 ,ATTRIBUTE7
2256 ,ATTRIBUTE8
2257 ,ATTRIBUTE9
2258 ,ATTRIBUTE10
2259 ,ATTRIBUTE11
2260 ,ATTRIBUTE12
2261 ,ATTRIBUTE13
2262 ,ATTRIBUTE14
2263 ,ATTRIBUTE15
2264 ,MOVEMENT_ID
2265 ,RESERVATION_QUANTITY
2266 ,SHIPPED_QUANTITY
2267 ,TRANSACTION_LINE_NUMBER
2268 ,TASK_ID
2269 ,TO_TASK_ID
2270 ,SOURCE_TASK_ID
2271 ,PROJECT_ID
2272 ,SOURCE_PROJECT_ID
2273 ,PA_EXPENDITURE_ORG_ID
2274 ,TO_PROJECT_ID
2275 ,EXPENDITURE_TYPE
2276 ,FINAL_COMPLETION_FLAG
2277 ,TRANSFER_PERCENTAGE
2278 ,TRANSACTION_SEQUENCE_ID
2279 ,MATERIAL_ACCOUNT
2280 ,MATERIAL_OVERHEAD_ACCOUNT
2281 ,RESOURCE_ACCOUNT
2282 ,OUTSIDE_PROCESSING_ACCOUNT
2283 ,OVERHEAD_ACCOUNT
2284 ,FLOW_SCHEDULE
2285 ,COST_GROUP_ID
2286 ,TRANSFER_COST_GROUP_ID
2287 ,DEMAND_CLASS
2288 ,QA_COLLECTION_ID
2289 ,KANBAN_CARD_ID
2290 ,OVERCOMPLETION_TRANSACTION_QTY
2291 ,OVERCOMPLETION_PRIMARY_QTY
2292 ,OVERCOMPLETION_TRANSACTION_ID
2293 ,END_ITEM_UNIT_NUMBER
2294 ,SCHEDULED_PAYBACK_DATE
2295 ,LINE_TYPE_CODE
2296 ,PARENT_TRANSACTION_TEMP_ID
2297 ,PUT_AWAY_STRATEGY_ID
2298 ,PUT_AWAY_RULE_ID
2299 ,PICK_STRATEGY_ID
2300 ,PICK_RULE_ID
2301 ,MOVE_ORDER_LINE_ID
2302 ,TASK_GROUP_ID
2303 ,PICK_SLIP_NUMBER
2304 ,reservation_id
2305 ,COMMON_BOM_SEQ_ID
2306 ,COMMON_ROUTING_SEQ_ID
2307 ,ORG_COST_GROUP_ID
2308 ,COST_TYPE_ID
2309 ,TRANSACTION_STATUS
2310 ,STANDARD_OPERATION_ID
2311 ,TASK_PRIORITY
2312 ,WMS_TASK_TYPE
2313 ,decode(PARENT_LINE_ID, NULL,NULL,l_new_transaction_temp_id) -- Take care of BULK parent
2314 ,nvl(p_lpn_id,p_parent_lpn_id) -- process the nesting
2315 -- fully consumble LPN Pick
2316 ,p_transfer_lpn_id
2317 -- Bug4185621: instead of inheriting previous line's status, use loaded as status for new line
2318 , p_wms_task_status -- wms_task_status
2319 ,p_content_lpn_id
2320 ,nvl(p_container_item_id,container_item_id)
2321 ,CARTONIZATION_ID --??
2322 ,PICK_SLIP_DATE
2323 ,REBUILD_ITEM_ID
2324 ,REBUILD_SERIAL_NUMBER
2325 ,REBUILD_ACTIVITY_ID
2326 ,REBUILD_JOB_NAME
2327 ,ORGANIZATION_TYPE
2328 ,TRANSFER_ORGANIZATION_TYPE
2329 ,OWNING_ORGANIZATION_ID
2330 ,OWNING_TP_TYPE
2331 ,XFR_OWNING_ORGANIZATION_ID
2332 ,TRANSFER_OWNING_TP_TYPE
2333 ,PLANNING_ORGANIZATION_ID
2334 ,PLANNING_TP_TYPE
2335 ,XFR_PLANNING_ORGANIZATION_ID
2336 ,TRANSFER_PLANNING_TP_TYPE
2337 ,p_confirmed_sec_uom
2338 ,decode( p_confirmed_sec_uom, null, null, l_confirmed_sec_qty )-- Bug 4576653
2339 ,TRANSACTION_BATCH_ID
2340 ,TRANSACTION_BATCH_SEQ
2341 ,ALLOCATED_LPN_ID
2342 ,SCHEDULE_NUMBER
2343 ,SCHEDULED_FLAG
2344 ,CLASS_CODE
2345 ,SCHEDULE_GROUP
2346 ,BUILD_SEQUENCE
2347 ,BOM_REVISION
2348 ,ROUTING_REVISION
2349 ,BOM_REVISION_DATE
2350 ,ROUTING_REVISION_DATE
2351 ,ALTERNATE_BOM_DESIGNATOR
2352 ,ALTERNATE_ROUTING_DESIGNATOR
2353 ,OPERATION_PLAN_ID
2354 ,INTRANSIT_ACCOUNT
2355 ,FOB_POINT
2356 ,MOVE_ORDER_HEADER_ID
2357 ,SERIAL_ALLOCATED_FLAG
2358 FROM mtl_material_transactions_temp
2359 WHERE transaction_temp_id = p_transaction_temp_id);
2360 IF SQL%NOTFOUND THEN
2361 mydebug (' p_transaction_temp_id: NOT found : ' || p_transaction_temp_id);
2362 fnd_message.set_name('WMS', 'WMS_INSERT_ALLOCATION'); -- NEWMSG
2363 -- "Error Inserting Allocation ."
2364 fnd_msg_pub.ADD;
2365 RAISE fnd_api.G_EXC_ERROR;
2366 END IF;
2367 l_progress := '120';
2368 mydebug ('l_progress: ' || l_progress );
2369 END IF ; -- insert MMTT only if p_insert = 'Y'
2370 l_progress := '130';
2371 mydebug ('l_progress: ' || l_progress );
2372 -- ****Lot Controlled items
2373
2374 IF p_confirmed_lots IS NOT NULL OR
2375 p_confirmed_serials IS NOT NULL
2376 THEN
2377 l_progress := '140';
2378 mydebug ('l_progress: ' || l_progress );
2379 proc_parse_lot_serial_catchwt
2380 (p_inventory_item_id => p_inventory_item_id
2381 ,p_confirmed_lots => p_confirmed_lots
2382 ,p_confirmed_lot_trx_qty => p_confirmed_lot_trx_qty
2383 ,p_confirmed_serials => p_confirmed_serials
2384 ,p_suggested_uom => p_suggested_uom
2385 ,p_confirmed_uom => p_confirmed_uom
2386 ,p_primary_uom => p_primary_uom
2387 ,p_confirmed_sec_uom => p_confirmed_sec_uom
2388 ,p_confirmed_sec_qty => p_confirmed_sec_qty
2389 ,x_return_status => x_return_status
2390 ,x_msg_count => x_msg_count
2391 ,x_msg_data => x_msg_data);
2392 IF x_return_status <> l_g_ret_sts_success
2393 THEN
2394 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
2395 -- Internal Error $ROUTINE
2396 fnd_message.set_token('ROUTINE', ' - proc_parse_lot_serial_catchwt API ' );
2397 mydebug('Error parsing lot/serial/catch weight string' );
2398 -- "Error reserving Serial Number/s"
2399 RAISE fnd_api.G_EXC_ERROR;
2400 END IF;
2401 END IF;
2402
2403 -- ****Lot only Controlled items OR
2404 -- ****Lot and Serial Controlled items
2405 IF (p_lot_controlled = 'Y' )
2406 THEN
2407 l_progress := '140';
2408 proc_process_confirmed_lots
2409 (p_action => p_action
2410 ,p_insert => p_insert
2411 ,p_update => p_update
2412 ,p_organization_id => p_organization_id
2413 ,p_user_id => p_user_id
2414 ,p_transaction_header_id => p_transaction_header_id
2415 ,p_transaction_temp_id => p_transaction_temp_id
2416 ,p_new_transaction_temp_id => l_new_transaction_temp_id
2417 ,p_transaction_temp_id_to_merge => p_transaction_temp_id_to_merge
2418 ,p_inventory_item_id => p_inventory_item_id
2419 ,p_revision => p_revision
2420 ,p_suggested_uom => p_suggested_uom
2421 ,p_confirmed_uom => p_confirmed_uom
2422 ,p_primary_uom => p_primary_uom
2423 ,p_confirmed_lots => p_confirmed_lots
2424 ,p_confirmed_lot_trx_qty => p_confirmed_lot_trx_qty
2425 ,p_confirmed_serials => p_confirmed_serials
2426 ,p_serial_allocated_flag => p_serial_allocated_flag
2427 ,p_lpn_match => p_lpn_match
2428 ,p_lpn_match_lpn_id => p_lpn_match_lpn_id
2429 ,p_confirmed_sec_uom => p_confirmed_sec_uom
2430 ,p_confirmed_sec_qty => p_confirmed_sec_qty
2431 ,p_lot_controlled => p_lot_controlled
2432 ,p_serial_controlled => p_serial_controlled
2433 ,p_exception => p_exception
2434 ,x_return_status => x_return_status
2435 ,x_msg_count => x_msg_count
2436 ,x_msg_data => x_msg_data);
2437 IF x_return_status <> l_g_ret_sts_success THEN
2438 mydebug('proc_process_confirmed_lots.x_return_status : ' || x_return_status);
2439 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
2440 -- Internal Error $ROUTINE
2441 fnd_message.set_token('ROUTINE', '- proc_process_confirmed_lots API' );
2442 fnd_msg_pub.ADD;
2443 RAISE fnd_api.g_exc_error;
2444 END IF;
2445 mydebug ('Return from proc_process_confirmed_lots ' );
2446 END IF;
2447 l_progress := '150';
2448 -- ****Serial Controlled items
2449 IF (p_lot_controlled = 'N' AND p_serial_controlled = 'Y')
2450 THEN
2451 l_progress := '300';
2452 mydebug ('l_progress: ' || l_progress );
2453 -- may not be necessary to call if p_insert = N , LOAD_SINGLE
2454 proc_process_confirmed_serials
2455 (p_action => p_action
2456 ,p_insert => p_insert
2457 ,p_update => p_update
2458 ,p_organization_id => p_organization_id
2459 ,p_user_id => p_user_id
2460 ,p_transaction_header_id => p_transaction_header_id
2461 ,p_transaction_temp_id => p_transaction_temp_id
2462 ,p_new_transaction_temp_id => l_new_transaction_temp_id
2463 ,p_transaction_temp_id_to_merge => p_transaction_temp_id_to_merge
2464 ,p_serial_transaction_temp_id => NULL
2465 ,p_mtlt_serial_temp_id => NULL
2466 ,p_inventory_item_id => p_inventory_item_id
2467 ,p_revision => p_revision
2468 ,p_suggested_uom => p_suggested_uom
2469 ,p_confirmed_uom => p_confirmed_uom
2470 ,p_primary_uom => p_primary_uom
2471 ,p_serial_lot_number => NULL
2472 ,p_confirmed_serials => p_confirmed_serials
2473 ,p_serial_allocated_flag => p_serial_allocated_flag
2474 ,p_lpn_match => p_lpn_match
2475 ,p_lpn_match_lpn_id => p_lpn_match_lpn_id
2476 ,p_lot_controlled => p_lot_controlled
2477 ,p_serial_controlled => p_serial_controlled
2478 ,x_return_status => x_return_status
2479 ,x_msg_count => x_msg_count
2480 ,x_msg_data => x_msg_data);
2481 IF x_return_status <> l_g_ret_sts_success THEN
2482 mydebug('proc_process_confirmed_serials.x_return_status : ' || x_return_status);
2483 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
2484 -- Internal Error $ROUTINE
2485 fnd_message.set_token('ROUTINE', '- proc_process_confirmed_serials API' );
2486 fnd_msg_pub.ADD;
2487 RAISE fnd_api.g_exc_error;
2488 END IF;
2489 l_progress := '330';
2490 mydebug ('l_progress: ' || l_progress );
2491 END IF;
2492
2493 l_progress := '170';
2494 -- update p_transaction_temp_id (reduce qty) for p_update = Y1 or Y2
2495 mydebug ('l_progress: ' || l_progress );
2496 mydebug ('p_confirmed_trx_qty: ' || p_confirmed_trx_qty);
2497 mydebug ('l_confirmed_prim_qty: ' || l_confirmed_prim_qty);
2498 mydebug ('l_confirmed_sugg_qty: ' || l_confirmed_sugg_qty);
2499 IF p_update = 'Y1' -- update p_transaction_temp_id to reduce primary/trxqty
2500 THEN
2501 IF p_action = l_g_action_split THEN
2502 l_progress := '190';
2503 mydebug('l_progress : ' || l_progress);
2504 IF p_exception='OVER' and p_lot_controlled='Y' THEN
2505 select sum(primary_quantity),sum(transaction_quantity),sum(SECONDARY_QUANTITY)
2506 into l_rem_lot_pri_qty,l_rem_lot_trx_qty,l_rem_lot_sec_qty
2507 from mtl_transaction_lots_temp
2508 where transaction_temp_id = p_transaction_temp_id
2509 group by transaction_temp_id;
2510
2511
2512 UPDATE mtl_material_transactions_temp
2513 SET transaction_quantity = l_rem_lot_trx_qty
2514 , primary_quantity = l_rem_lot_pri_qty
2515 , secondary_transaction_quantity = l_rem_lot_sec_qty
2516 , last_update_date = SYSDATE
2517 , last_updated_by = p_user_id
2518 WHERE transaction_temp_id = p_transaction_temp_id;
2519 ELSE
2520 UPDATE mtl_material_transactions_temp
2521 SET transaction_quantity = transaction_quantity - l_confirmed_sugg_qty
2522 , primary_quantity = primary_quantity - l_confirmed_prim_qty
2523 , secondary_transaction_quantity = secondary_transaction_quantity - l_confirmed_sec_qty
2524 , last_update_date = SYSDATE
2525 , last_updated_by = p_user_id
2526 WHERE transaction_temp_id = p_transaction_temp_id;
2527 END IF;
2528
2529 IF SQL%NOTFOUND THEN
2530 RAISE fnd_api.G_EXC_ERROR;
2531 END IF;
2532 ELSE -- LOAD
2533 l_progress := '200';
2534 mydebug('l_progress : ' || l_progress);
2535 UPDATE mtl_material_transactions_temp
2536 SET transaction_quantity = p_confirmed_trx_qty
2537 , primary_quantity = l_confirmed_prim_qty
2538 , secondary_transaction_quantity = decode( p_confirmed_sec_uom,
2539 null,
2540 null,
2541 l_confirmed_sec_qty
2542 ) -- Bug 4576653
2543 , secondary_uom_code = p_confirmed_sec_uom
2544 , lpn_id = nvl(p_lpn_id,p_parent_lpn_id)
2545 -- process the nesting
2546 -- fully consumble LPN Pick
2547 , content_lpn_id = p_content_lpn_id
2548 , transfer_lpn_id = p_transfer_lpn_id
2549 , subinventory_code = p_confirmed_sub
2550 , locator_id = p_confirmed_locator_id
2551 , transaction_uom = p_confirmed_uom
2552 , container_item_id = p_container_item_id
2553 , last_update_date = SYSDATE
2554 , last_updated_by = p_user_id
2555 , wms_task_status = p_wms_task_status -- Bug4185621: update mmtt task status to loaded
2556 WHERE transaction_temp_id = p_transaction_temp_id;
2557
2558 IF SQL%NOTFOUND THEN
2559 RAISE fnd_api.G_EXC_ERROR;
2560 END IF;
2561 END IF;
2562 END IF;
2563
2564 l_progress := '180';
2565
2566 IF p_update = 'Y2' -- -- and update p_transaction_temp_id_to_merge to add qty)
2567 THEN
2568 l_progress := '190';
2569 mydebug ('l_progress ' || l_progress);
2570 UPDATE mtl_material_transactions_temp
2571 SET transaction_quantity = transaction_quantity + p_confirmed_trx_qty
2572 , primary_quantity = primary_quantity + nvl(l_confirmed_prim_qty ,0)
2573 , secondary_transaction_quantity = secondary_transaction_quantity + nvl(l_confirmed_sec_qty, 0)
2574 , secondary_uom_code = p_confirmed_sec_uom
2575 , last_update_date = SYSDATE
2576 , last_updated_by = p_user_id
2577 WHERE transaction_temp_id = p_transaction_temp_id_to_merge;
2578 IF SQL%NOTFOUND THEN
2579 RAISE fnd_api.G_EXC_ERROR;
2580 END IF;
2581 IF p_action = l_g_action_load_multiple THEN
2582 l_progress := '190'; -- Delete the original MMTT, if merging into another MMTT
2583 mydebug ('l_progress ' || l_progress);
2584 DELETE mtl_material_transactions_temp
2585 WHERE transaction_temp_id = p_transaction_temp_id;
2586 IF SQL%NOTFOUND THEN
2587 RAISE fnd_api.G_EXC_ERROR;
2588 END IF;
2589 ELSE -- 'SPLIT'
2590 l_progress := '200';
2591 mydebug('l_progress : ' || l_progress);
2592 UPDATE mtl_material_transactions_temp
2593 SET transaction_quantity = transaction_quantity - l_confirmed_sugg_qty
2594 , primary_quantity = primary_quantity - l_confirmed_prim_qty
2595 , secondary_transaction_quantity = secondary_transaction_quantity - l_confirmed_sec_qty
2596 , last_update_date = SYSDATE
2597 , last_updated_by = p_user_id
2598 WHERE transaction_temp_id = p_transaction_temp_id;
2599
2600 IF SQL%NOTFOUND THEN
2601 RAISE fnd_api.G_EXC_ERROR;
2602 END IF;
2603 END IF;
2604 END IF;
2605 mydebug ('End of :' || l_proc_name);
2606
2607 EXCEPTION
2608 WHEN fnd_api.g_exc_error THEN
2609 x_return_status := l_g_ret_sts_error;
2610 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2611 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
2612 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
2613 mydebug('ROLLBACK ' );
2614 ROLLBACK ;
2615 WHEN fnd_api.g_exc_unexpected_error THEN
2616 x_return_status := fnd_api.g_ret_sts_unexp_error;
2617 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2618 mydebug('ROLLBACK ' );
2619 ROLLBACK ;
2620 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
2621 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
2622 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
2623 WHEN OTHERS THEN
2624 x_return_status := l_g_ret_sts_unexp_error;
2625 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2626 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
2627 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
2628 mydebug('ROLLBACK ' );
2629 ROLLBACK ;
2630 END proc_insert_update_mmtt;
2631
2632 PROCEDURE proc_process_confirmed_lots
2633 ( p_action IN VARCHAR2
2634 ,p_insert IN VARCHAR2
2635 ,p_update IN VARCHAR2
2636 ,p_organization_id IN NUMBER
2637 ,p_user_id IN NUMBER
2638 ,p_transaction_header_id IN NUMBER
2639 ,p_transaction_temp_id IN NUMBER
2640 ,p_new_transaction_temp_id IN NUMBER
2641 ,p_transaction_temp_id_to_merge IN NUMBER
2642 ,p_inventory_item_id IN NUMBER
2643 ,p_revision IN VARCHAR2
2644 ,p_suggested_uom IN VARCHAR2
2645 ,p_confirmed_uom IN VARCHAR2
2646 ,p_primary_uom IN VARCHAR2
2647 ,p_confirmed_lots IN VARCHAR2
2648 ,p_confirmed_lot_trx_qty IN VARCHAR2
2649 ,p_confirmed_serials IN VARCHAR2
2650 ,p_serial_allocated_flag IN VARCHAR2
2651 ,p_lpn_match IN NUMBER
2652 ,p_lpn_match_lpn_id IN NUMBER
2653 ,p_confirmed_sec_uom IN VARCHAR2
2654 ,p_confirmed_sec_qty IN VARCHAR2
2655 ,p_lot_controlled IN VARCHAR2 -- Y/N
2656 ,p_serial_controlled IN VARCHAR2 -- Y/N
2657 ,p_exception IN VARCHAR2 -- SHORT/OVER
2658 ,x_return_status OUT NOCOPY VARCHAR2
2659 ,x_msg_count OUT NOCOPY NUMBER
2660 ,x_msg_data OUT NOCOPY VARCHAR2)
2661 IS
2662 l_proc_name VARCHAR2(30) := 'PROC_PROCESS_CONFIRMED_LOTS';
2663 l_progress VARCHAR2(30) := '100';
2664 l_delimiter VARCHAR2(30) := ':';
2665 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
2666 l_prev_lot_number VARCHAR2(80) := '@@@';
2667 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
2668 l_lot_number VARCHAR2(80) := NULL;
2669 l_lot_trx_qty NUMBER := NULL;
2670 l_lot_prim_qty NUMBER := NULL;
2671 l_lot_sugg_qty NUMBER := NULL;
2672 l_original_lot_prim_qty NUMBER := NULL;
2673 l_serial_transaction_temp_id NUMBER := NULL;
2674 l_mtlt_serial_temp_id NUMBER := NULL;
2675
2676 CURSOR cur_mtlt_to_copy_from (p_lot_number VARCHAR2
2677 ,p_lot_transaction_temp_id NUMBER ) IS
2678 SELECT mtlt.*
2679 FROM mtl_transaction_lots_temp mtlt
2680 WHERE transaction_temp_id = p_lot_transaction_temp_id
2681 AND lot_number = p_lot_number;
2682
2683 l_rec_mtlt_to_copy_from mtl_transaction_lots_temp%ROWTYPE;
2684
2685 CURSOR cur_confirmed_lots_serials IS
2686 SELECT DISTINCT -- so that we get only lot records in case of lot+Serial item control
2687 lot_number
2688 ,transaction_temp_id
2689 ,serial_number
2690 ,transaction_quantity
2691 ,primary_quantity
2692 ,suggested_quantity
2693 ,secondary_quantity
2694 FROM mtl_allocations_gtmp
2695 ORDER BY
2696 transaction_temp_id
2697 ,lot_number;
2698
2699 BEGIN
2700 /* MMTT management
2701 Action l_insert L_update update orginalMMTT UpdMergeMMTT InsertNewMMTT
2702 -----------------------------------------------------------------------------------------------
2703 SPLIT Y Y1 N N Y
2704 SPLIT N Y2 Y Y N
2705 LOAD_M N Y1 Y N N
2706 LOAD_M N Y2 Y-Delete Y N
2707 LOAD_S N Y1 Y N N
2708
2709 ****MTLT ****
2710 Action l_insert L_update update orginalMTLT UpdMergeMTLT
2711 -----------------------------------------------------------------------------------------------
2712 SPLIT Y Y1 Y-upd original OR N
2713 -ins new/upd orig
2714 SPLIT N Y2 Y Y if MTLT exist
2715 OR ins new/upd orig
2716 LOAD_M N Y1 N N
2717 LOAD_M N Y2 Y Y if MTLT exist
2718 OR ins new/upd orig
2719 LOAD_S N Y1 N-not necessary N
2720
2721 */
2722
2723 x_return_status := l_g_ret_sts_success;
2724 mydebug ('In :' || l_proc_name );
2725 mydebug ('p_action = ' || p_action );
2726 mydebug ('p_insert = ' || p_insert );
2727 mydebug ('p_update = ' || p_update );
2728 mydebug ('p_transaction_header_id = ' || p_transaction_header_id );
2729 mydebug ('p_transaction_temp_id = ' || p_transaction_temp_id );
2730 mydebug ('p_new_transaction_temp_id= ' || p_new_transaction_temp_id);
2731 mydebug ('p_transaction_temp_id_to_merge = ' || p_transaction_temp_id_to_merge );
2732 mydebug ('p_inventory_item_id = ' || p_inventory_item_id );
2733 mydebug ('p_revision = ' || p_revision );
2734 mydebug ('p_suggested_uom = ' || p_suggested_uom );
2735 mydebug ('p_primary_uom = ' || p_primary_uom );
2736 mydebug ('p_confirmed_uom = ' || p_confirmed_uom );
2737 mydebug ('p_confirmed_lots = ' || p_confirmed_lots );
2738 mydebug ('p_confirmed_lot_trx_qty = ' || p_confirmed_lot_trx_qty );
2739 mydebug ('p_confirmed_serials = ' || p_confirmed_serials );
2740 mydebug ('p_serial_allocated_flag = ' || p_serial_allocated_flag );
2741 mydebug ('p_lpn_match = ' || p_lpn_match );
2742 mydebug ('p_lpn_match_lpn_id = ' || p_lpn_match_lpn_id );
2743 mydebug ('p_exception = ' || p_exception );
2744
2745 FOR rec_confirmed_lots_serials IN cur_confirmed_lots_serials
2746 LOOP
2747 mydebug('Group_number : ' || rec_confirmed_lots_serials.transaction_temp_id);
2748 mydebug('lot_number : ' || rec_confirmed_lots_serials.lot_number);
2749 mydebug('Serial_number : ' || rec_confirmed_lots_serials.serial_number);
2750 mydebug('Transaction_quantity : ' || rec_confirmed_lots_serials.transaction_Quantity);
2751 mydebug('Primary_quantity : ' || rec_confirmed_lots_serials.primary_quantity);
2752 mydebug('suggested_quantity : ' || rec_confirmed_lots_serials.suggested_quantity);
2753 mydebug('Secondary_quantity : ' || rec_confirmed_lots_serials.Secondary_quantity);
2754 -- Get lot record details that is attached to the original p_transaction_temp_id
2755 -- Only p_insert = y means a new MMTT is created and therefore new MTLT will have to
2756 -- be created.
2757
2758 IF l_prev_lot_number <> rec_confirmed_lots_serials.lot_number
2759 THEN
2760 l_prev_lot_number := rec_confirmed_lots_serials.lot_number ;
2761 IF p_insert = 'Y' or p_update = 'Y2' THEN
2762 -- we need this only if we ever need to create a new MTLT
2763 FOR rec_mtlt_to_copy_from IN cur_mtlt_to_copy_from
2764 (p_lot_number => rec_confirmed_lots_serials.lot_number,
2765 p_lot_transaction_temp_id => p_transaction_temp_id)
2766 LOOP
2767 l_progress := '150';
2768 mydebug ('In : rec_mtlt_to_copy_from cursor' );
2769 l_rec_mtlt_to_copy_from := rec_mtlt_to_copy_from;
2770 --l_original_lot_prim_qty := rec_mtlt_to_copy_from.primary_quantity;
2771 EXIT;
2772 END LOOP;
2773
2774 l_progress := '160';
2775 mydebug ('l_rec_mtlt_to_copy_from.transaction_temp_id: ' ||
2776 l_rec_mtlt_to_copy_from.transaction_temp_id);
2777 mydebug ('l_rec_mtlt_to_copy_from.serial_transaction_temp_id:' ||
2778 l_rec_mtlt_to_copy_from.serial_transaction_temp_id );
2779 IF l_rec_mtlt_to_copy_from.transaction_temp_id IS NULL
2780 THEN
2781 l_progress := '170';
2782 -- lot record attached to the original MMTT should have been found
2783 RAISE fnd_api.G_EXC_ERROR;
2784 END IF;
2785
2786 END IF;
2787 l_progress := '175';
2788 -- For lot + serial controlled items
2789 IF p_serial_controlled = 'Y'
2790 THEN
2791 l_mtlt_serial_temp_id := l_rec_mtlt_to_copy_from.serial_transaction_temp_id;
2792
2793 SELECT mtl_material_transactions_s.NEXTVAL
2794 INTO l_serial_transaction_temp_id
2795 FROM DUAL;
2796 ELSE
2797 l_serial_transaction_temp_id := NULL;
2798 l_mtlt_serial_temp_id := NULL;
2799 END IF;
2800
2801 mydebug ('l_mtlt_serial_temp_id: ' || l_mtlt_serial_temp_id);
2802 mydebug ('l_serial_transaction_temp_id: ' || l_serial_transaction_temp_id);
2803 l_progress := '180';
2804 mydebug ('p_insert: ' || p_insert);
2805 IF p_insert = 'Y' THEN
2806 l_progress := '190';
2807 IF l_rec_mtlt_to_copy_from.primary_quantity <= rec_confirmed_lots_serials.primary_quantity THEN
2808 -- lot qty in the selected, in the above cursor, MTLT equals qty that is needed for the new MTLT
2809 -- update the MTLT with new temp id instead of inserting a new and then deleting the old one
2810 l_progress := '200';
2811 mydebug('l_progress: ' || l_progress );
2812 UPDATE mtl_transaction_lots_temp
2813 SET transaction_temp_id = p_new_transaction_temp_id
2814 , transaction_quantity = rec_confirmed_lots_serials.transaction_Quantity
2815 , primary_quantity = rec_confirmed_lots_serials.primary_quantity
2816 , secondary_quantity = rec_confirmed_lots_serials.secondary_quantity
2817 , secondary_unit_of_measure = p_confirmed_sec_uom
2818 , serial_transaction_temp_id = l_serial_transaction_temp_id
2819 , last_update_date = SYSDATE
2820 , last_updated_by = p_user_id
2821 WHERE transaction_temp_id = l_rec_mtlt_to_copy_from.transaction_temp_id
2822 AND lot_number = rec_confirmed_lots_serials.lot_number;
2823 IF SQL%NOTFOUND THEN
2824 RAISE fnd_api.G_EXC_ERROR;
2825 END IF;
2826 ELSE
2827 -- insert a new MTLT
2828 l_progress := '210';
2829 mydebug('l_progress: ' || l_progress );
2830 l_rec_mtlt_to_copy_from.transaction_quantity := rec_confirmed_lots_serials.transaction_Quantity ;
2831 l_rec_mtlt_to_copy_from.primary_quantity := rec_confirmed_lots_serials.primary_quantity ;
2832 l_rec_mtlt_to_copy_from.secondary_quantity := rec_confirmed_lots_serials.secondary_quantity ;
2833 l_rec_mtlt_to_copy_from.secondary_unit_of_measure := p_confirmed_sec_uom;
2834 l_rec_mtlt_to_copy_from.created_by := p_user_id;
2835 l_rec_mtlt_to_copy_from.transaction_temp_id := p_new_transaction_temp_id;
2836 -- For lot + serial controlled items
2837 l_rec_mtlt_to_copy_from.serial_transaction_temp_id := l_serial_transaction_temp_id;
2838 proc_insert_mtlt
2839 (p_lot_record => l_rec_mtlt_to_copy_from
2840 ,x_return_status => x_return_status
2841 ,x_msg_count => x_msg_count
2842 ,x_msg_data => x_msg_data);
2843 mydebug('x_return_status : ' || x_return_status);
2844 IF x_return_status <> l_g_ret_sts_success THEN
2845 RAISE fnd_api.G_EXC_ERROR;
2846 END IF;
2847 mydebug('l_progress: ' || l_progress );
2848 l_progress := '220';
2849 -- If new MTLT is inserted for p_new_transaction_temp_id this means
2850 -- the original MTLT still has some qty remaining...so update it.
2851 -- the original MTLT need not be adjusted for secondary quantity.
2852 -- It is not expected to be populated
2853 UPDATE mtl_transaction_lots_temp
2854 SET transaction_quantity = transaction_quantity - rec_confirmed_lots_serials.suggested_quantity
2855 ,primary_quantity = primary_quantity - rec_confirmed_lots_serials.primary_quantity
2856 ,secondary_quantity = NVL(secondary_quantity, rec_confirmed_lots_serials.secondary_quantity) - rec_confirmed_lots_serials.secondary_quantity
2857 ,last_update_date = SYSDATE
2858 ,last_updated_by = p_user_id
2859 WHERE transaction_temp_id = p_transaction_temp_id
2860 AND lot_number = rec_confirmed_lots_serials.lot_number;
2861 IF SQL%NOTFOUND THEN
2862 RAISE fnd_api.G_EXC_ERROR;
2863 END IF;
2864 mydebug('l_progress: ' || l_progress );
2865 END IF;
2866 END IF;
2867
2868 l_progress := '230';
2869 mydebug ('p_update: ' || p_update);
2870 -- p_update = 'Y2' means, p_insert = N which means that current MMTT (in this call)
2871 -- was merged with another existing MMTT. In this case, it is possible that existing MMTT already has
2872 -- MTLT record for this lot number. If this is the case then update the MTLT otherwise ,
2873 -- insert a new MTLT using l_rec_mtlt_to_copy_from from the above cursor
2874 IF p_update = 'Y2'
2875 THEN
2876 l_progress := '240';
2877 mydebug('l_progress: ' || l_progress );
2878 UPDATE mtl_transaction_lots_temp
2879 SET transaction_quantity = transaction_quantity +
2880 rec_confirmed_lots_serials.transaction_Quantity
2881 ,primary_quantity = primary_quantity + rec_confirmed_lots_serials.primary_quantity
2882 ,secondary_quantity = secondary_quantity+ rec_confirmed_lots_serials.secondary_quantity
2883 ,last_update_date = SYSDATE
2884 ,last_updated_by = p_user_id
2885 WHERE transaction_temp_id = p_transaction_temp_id_to_merge
2886 AND lot_number = rec_confirmed_lots_serials.lot_number
2887 -- For lot + serial controlled items
2888 RETURNING serial_transaction_temp_id INTO l_serial_transaction_temp_id;
2889
2890 mydebug ('returned value - l_serial_transaction_temp_id: ' || l_serial_transaction_temp_id);
2891 IF SQL%NOTFOUND THEN
2892 IF l_rec_mtlt_to_copy_from.primary_quantity = rec_confirmed_lots_serials.primary_quantity THEN
2893 -- lot qty in the selected MTLT = qty that is needed for the new MTLT
2894 --update the MTLT with new temp id instead of inserting a new and then deleting the old one
2895 l_progress := '250';
2896 mydebug('l_progress: ' || l_progress );
2897 UPDATE mtl_transaction_lots_temp
2898 SET transaction_temp_id = p_transaction_temp_id_to_merge --p_new_transaction_temp_id
2899 , secondary_quantity = rec_confirmed_lots_serials.secondary_quantity
2900 , secondary_unit_of_measure = p_confirmed_sec_uom
2901 -- For lot + serial controlled items
2902 , serial_transaction_temp_id = l_serial_transaction_temp_id
2903 , last_update_date = SYSDATE
2904 , last_updated_by = p_user_id
2905 WHERE transaction_temp_id = l_rec_mtlt_to_copy_from.transaction_temp_id
2906 AND lot_number = rec_confirmed_lots_serials.lot_number;
2907 IF SQL%NOTFOUND THEN
2908 RAISE fnd_api.G_EXC_ERROR;
2909 END IF;
2910 ELSE
2911 l_progress := '260';
2912 mydebug('l_progress: ' || l_progress );
2913 l_rec_mtlt_to_copy_from.transaction_quantity := rec_confirmed_lots_serials.transaction_Quantity ;
2914 l_rec_mtlt_to_copy_from.primary_quantity := rec_confirmed_lots_serials.primary_quantity ;
2915 l_rec_mtlt_to_copy_from.secondary_quantity := rec_confirmed_lots_serials.secondary_quantity;
2916 l_rec_mtlt_to_copy_from.transaction_temp_id := p_transaction_temp_id_to_merge;
2917 -- For lot + serial controlled items
2918 l_rec_mtlt_to_copy_from.serial_transaction_temp_id := l_serial_transaction_temp_id;
2919 l_rec_mtlt_to_copy_from.created_by := p_user_id;
2920 proc_insert_mtlt
2921 (p_lot_record => l_rec_mtlt_to_copy_from
2922 ,x_return_status => x_return_status
2923 ,x_msg_count => x_msg_count
2924 ,x_msg_data => x_msg_data);
2925 IF x_return_status <> l_g_ret_sts_success THEN
2926 mydebug('x_return_status : ' || x_return_status);
2927 RAISE fnd_api.G_EXC_ERROR;
2928 END IF;
2929 L_progress := '270';
2930 mydebug('l_progress: ' || l_progress );
2931 -- If new MTLT is inserted for p_transaction_temp_id_to_merge this means
2932 -- the original MTLT still has some qty remaining...so update it.
2933 UPDATE mtl_transaction_lots_temp
2934 SET transaction_quantity = transaction_quantity -
2935 rec_confirmed_lots_serials.suggested_Quantity
2936 ,primary_quantity = primary_quantity -
2937 rec_confirmed_lots_serials.primary_quantity
2938 ,secondary_quantity = NVL(secondary_quantity, rec_confirmed_lots_serials.secondary_quantity) - rec_confirmed_lots_serials.secondary_quantity
2939 ,last_update_date = SYSDATE
2940 ,last_updated_by = p_user_id
2941 WHERE transaction_temp_id = p_transaction_temp_id -- l_rec_mtlt_to_copy_from.transaction_temp_id
2942 AND lot_number = rec_confirmed_lots_serials.lot_number;
2943 IF SQL%NOTFOUND THEN
2944 RAISE fnd_api.G_EXC_ERROR;
2945 END IF;
2946 END IF;
2947 ELSE -- found mtlt for the current lot number attached to p_transaction_temp_id_to_merge
2948 L_progress := '280';
2949 mydebug('l_progress: ' || l_progress );
2950 -- if the quantity in mtlt of orginal p_tranaction_temp_id is equal to the qty confirmed for this lot
2951 -- and we merged the current lot qty with an existing mtlt record then we do not need this mtlt.
2952 -- delete it.
2953 IF l_rec_mtlt_to_copy_from.primary_quantity = rec_confirmed_lots_serials.primary_quantity THEN
2954 L_progress := '290';
2955 mydebug('l_progress: ' || l_progress );
2956 -- If all the qty from the original MTLT is consumed and merged to the
2957 -- p_transaction_temp_id_to_merge we do not need the original MTLT ..delete it
2958 DELETE mtl_transaction_lots_temp
2959 WHERE transaction_temp_id = p_transaction_temp_id -- l_rec_mtlt_to_copy_from.transaction_temp_id
2960 AND lot_number = rec_confirmed_lots_serials.lot_number;
2961 IF SQL%NOTFOUND THEN
2962 RAISE fnd_api.G_EXC_ERROR;
2963 END IF;
2964 ELSE
2965 -- If all the qty from the original MTLT is not consumed then update the original MTLT
2966 -- attached to p_transaction_temp_id .. as selected in the cursor above
2967 L_progress := '300';
2968 mydebug('l_progress: ' || l_progress );
2969 UPDATE mtl_transaction_lots_temp
2970 SET transaction_quantity = transaction_quantity - rec_confirmed_lots_serials.suggested_Quantity
2971 ,primary_quantity = primary_quantity - rec_confirmed_lots_serials.primary_quantity
2972 ,secondary_quantity = NVL(secondary_quantity, rec_confirmed_lots_serials.secondary_quantity) -
2973 rec_confirmed_lots_serials.secondary_quantity
2974 ,last_update_date = SYSDATE
2975 ,last_updated_by = p_user_id
2976 WHERE transaction_temp_id = p_transaction_temp_id -- l_rec_mtlt_to_copy_from.transaction_temp_id
2977 AND lot_number = rec_confirmed_lots_serials.lot_number;
2978 IF SQL%NOTFOUND THEN
2979 RAISE fnd_api.G_EXC_ERROR;
2980 END IF;
2981 END IF;
2982 END IF;
2983 END IF;
2984 /* Usually for p_update = 'Y1' one does not need to update MTLT since nothing would have changed
2985 But, for catch weight enabled items, it is necessary */
2986 /* If serials are not allocateed and lpn_match = 1/3 , MSNT records need to be populated
2987 so, update serial_transaction_temp_id mtlt*. MSNT gets created in process_confirmed_serials */
2988 IF (p_update = 'Y1' AND
2989 p_insert = 'N' AND
2990 p_serial_controlled = 'Y' AND
2991 p_serial_allocated_flag = 'N' AND
2992 p_confirmed_serials IS NULL AND
2993 p_lpn_match IN (1,3) )
2994 THEN
2995 l_progress := '350';
2996 mydebug('l_progress: ' || l_progress );
2997 UPDATE mtl_transaction_lots_temp
2998 SET
2999 transaction_quantity = rec_confirmed_lots_serials.transaction_quantity --jxlu
3000 ,primary_quantity = rec_confirmed_lots_serials.primary_quantity --jxlu
3001 ,secondary_quantity = rec_confirmed_lots_serials.secondary_quantity
3002 ,secondary_unit_of_measure = p_confirmed_sec_uom
3003 ,serial_transaction_temp_id = l_serial_transaction_temp_id
3004 ,last_update_date = SYSDATE
3005 ,last_updated_by = p_user_id
3006 WHERE transaction_temp_id = p_transaction_temp_id
3007 AND lot_number = rec_confirmed_lots_serials.lot_number;
3008 IF SQL%NOTFOUND THEN
3009 RAISE fnd_api.G_EXC_ERROR;
3010 END IF;
3011 ELSE
3012 /* Usually for p_update = 'Y1' one does not need to update MTLT since nothing would have changed
3013 But, for catch weight enabled items, Overpicking or changed TXN-UOM it is necessary
3014 */
3015 /* following condition is independent of the above condition in that :
3016 * for serial controlled items, UOM cannot be different from primary
3017 * UOM (atleast as of this patchset (11.5.10)) .
3018 * for lpn_match 1,3 , it cannot be a case of overpick. */
3019 IF (p_update = 'Y1' AND
3020 p_insert = 'N' ) AND
3021 (p_confirmed_sec_qty is NOT NULL OR
3022 p_confirmed_uom <> p_primary_uom OR
3023 p_exception = 'OVER')
3024 THEN
3025 l_progress := '360';
3026 mydebug('l_progress: ' || l_progress );
3027 UPDATE mtl_transaction_lots_temp
3028 SET
3029 transaction_quantity = rec_confirmed_lots_serials.transaction_quantity
3030 ,primary_quantity = rec_confirmed_lots_serials.primary_quantity
3031 ,secondary_quantity = rec_confirmed_lots_serials.secondary_quantity
3032 ,secondary_unit_of_measure = p_confirmed_sec_uom
3033 ,last_update_date = SYSDATE
3034 ,last_updated_by = p_user_id
3035 WHERE transaction_temp_id = p_transaction_temp_id
3036 AND lot_number = rec_confirmed_lots_serials.lot_number;
3037 IF SQL%NOTFOUND THEN
3038 RAISE fnd_api.G_EXC_ERROR;
3039 END IF;
3040 END IF;
3041 END IF;
3042
3043 -- For lot + serial controlled items, process serials for the given lot now
3044 L_progress := '400';
3045 mydebug('l_progress: ' || l_progress );
3046 mydebug('rec_confirmed_lots_serials.serial_number: ' || rec_confirmed_lots_serials.serial_number );
3047 --IF rec_confirmed_lots_serials.serial_number IS NOT NULL
3048 IF p_serial_controlled = 'Y'
3049 THEN
3050 L_progress := '410';
3051 mydebug('l_progress: ' || l_progress );
3052 -- update all serial records with the serial_transaction_temp_id to be populated
3053 UPDATE mtl_allocations_gtmp
3054 SET child_transaction_temp_id = l_serial_transaction_temp_id
3055 WHERE lot_number = rec_confirmed_lots_serials.lot_number
3056 AND transaction_temp_id = rec_confirmed_lots_serials.transaction_temp_id ;
3057 IF SQL%NOTFOUND THEN
3058 RAISE fnd_api.G_EXC_ERROR;
3059 END IF;
3060 L_progress := '420';
3061 mydebug('l_progress: ' || l_progress );
3062 proc_process_confirmed_serials
3063 (p_action => p_action
3064 ,p_insert => p_insert
3065 ,p_update => p_update
3066 ,p_organization_id => p_organization_id
3067 ,p_user_id => p_user_id
3068 ,p_transaction_header_id => p_transaction_header_id
3069 ,p_transaction_temp_id => p_transaction_temp_id
3070 ,p_new_transaction_temp_id => p_new_transaction_temp_id --??l_serial_transaction_temp_id
3071 ,p_transaction_temp_id_to_merge => p_transaction_temp_id_to_merge
3072 ,p_serial_transaction_temp_id => l_serial_transaction_temp_id
3073 ,p_mtlt_serial_temp_id => l_mtlt_serial_temp_id
3074 ,p_inventory_item_id => p_inventory_item_id
3075 ,p_revision => p_revision
3076 ,p_suggested_uom => p_suggested_uom
3077 ,p_confirmed_uom => p_confirmed_uom
3078 ,p_primary_uom => p_primary_uom
3079 ,p_serial_lot_number => rec_confirmed_lots_serials.lot_number
3080 ,p_confirmed_serials => p_confirmed_serials
3081 ,p_serial_allocated_flag => p_serial_allocated_flag
3082 ,p_lpn_match => p_lpn_match
3083 ,p_lpn_match_lpn_id => p_lpn_match_lpn_id
3084 ,p_lot_controlled => p_lot_controlled
3085 ,p_serial_controlled => p_serial_controlled
3086 ,x_return_status => x_return_status
3087 ,x_msg_count => x_msg_count
3088 ,x_msg_data => x_msg_data);
3089 IF x_return_status <> l_g_ret_sts_success THEN
3090 RAISE fnd_api.G_EXC_ERROR;
3091 END IF;
3092 END IF;
3093 END IF; -- l_prev_lot_number <> rec_confirmed_lots_serials.lot_number
3094 L_progress := '430';
3095 mydebug('l_progress: ' || l_progress );
3096 END LOOP; --rec_confirmed_lots_serials IN cur_confirmed_lots_serials
3097 mydebug('End .. ' || l_proc_name);
3098 EXCEPTION
3099 WHEN fnd_api.g_exc_error THEN
3100 x_return_status := l_g_ret_sts_error;
3101 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3102 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3103 mydebug('fnd_api.g_exc_error: ' || SQLERRM);
3104 mydebug('ROLLBACK ' );
3105 ROLLBACK ;
3106 WHEN fnd_api.g_exc_unexpected_error THEN
3107 x_return_status := fnd_api.g_ret_sts_unexp_error;
3108 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3109 mydebug('ROLLBACK ' );
3110 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3111 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
3112 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
3113 ROLLBACK ;
3114 WHEN OTHERS THEN
3115 x_return_status := l_g_ret_sts_unexp_error;
3116 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3117 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3118 mydebug('fnd_api.g_exc_error: ' || SQLERRM);
3119 mydebug('ROLLBACK ' );
3120 ROLLBACK ;
3121
3122 END proc_process_confirmed_lots;
3123
3124 PROCEDURE proc_process_confirmed_serials
3125 ( p_action IN VARCHAR2
3126 ,p_insert IN VARCHAR2
3127 ,p_update IN VARCHAR2
3128 ,p_organization_id IN NUMBER
3129 ,p_user_id IN NUMBER
3130 ,p_transaction_header_id IN NUMBER
3131 ,p_transaction_temp_id IN NUMBER
3132 ,p_new_transaction_temp_id IN NUMBER
3133 ,p_transaction_temp_id_to_merge IN NUMBER
3134 ,p_serial_transaction_temp_id IN NUMBER
3135 ,p_mtlt_serial_temp_id IN NUMBER
3136 ,p_inventory_item_id IN NUMBER
3137 ,p_revision IN VARCHAR2
3138 ,p_suggested_uom IN VARCHAR2
3139 ,p_confirmed_uom IN VARCHAR2
3140 ,p_primary_uom IN VARCHAR2
3141 ,p_serial_lot_number IN VARCHAR2
3142 ,p_confirmed_serials IN VARCHAR2
3143 ,p_serial_allocated_flag IN VARCHAR2
3144 ,p_lpn_match IN NUMBER
3145 ,p_lpn_match_lpn_id IN NUMBER
3146 ,p_lot_controlled IN VARCHAR2 -- Y/N
3147 ,p_serial_controlled IN VARCHAR2 -- Y/N
3148 ,x_return_status OUT NOCOPY VARCHAR2
3149 ,x_msg_count OUT NOCOPY NUMBER
3150 ,x_msg_data OUT NOCOPY VARCHAR2)
3151 IS
3152 l_proc_name VARCHAR2(30) := 'PROC_PROCESS_CONFIRMED_SERIALS';
3153 l_progress VARCHAR2(30) := '100';
3154 l_delimiter VARCHAR2(30) := ':';
3155 l_serial_number VARCHAR2(30) := NULL;
3156 l_n_msnt_transaction_temp_id NUMBER;
3157 l_o_msnt_transaction_temp_id NUMBER;
3158 l_msnt_record MTL_SERIAL_NUMBERS_TEMP%ROWTYPE;
3159 m NUMBER := 1; -- position of delimiter
3160 n NUMBER := 1; -- Start position for substr or search for delimiter
3161 CURSOR cur_confirmed_serials IS
3162 SELECT transaction_temp_id
3163 ,lot_number
3164 ,serial_number
3165 ,transaction_quantity
3166 ,primary_quantity
3167 FROM mtl_allocations_gtmp
3168 WHERE NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@')
3169 ORDER BY
3170 transaction_temp_id
3171 --,nvl(lot_number,'@@')
3172 ,serial_number;
3173
3174 BEGIN
3175 /* MMTT management
3176 Action l_insert L_update update orginalMMTT UpdMergeMMTT InsertNewMMTT
3177 -----------------------------------------------------------------------------------------------
3178 SPLIT Y Y1 N N Y
3179 SPLIT N Y2 Y Y N
3180 LOAD_M N Y1 Y N N
3181 LOAD_M N Y2 Y-Delete Y N
3182 LOAD_S N Y1 Y N N
3183
3184 ****MSNT ****
3185 Action l_insert L_update update orginalMSNT
3186 -----------------------------------------------------------------------------------------------
3187 SPLIT Y Y1 Y-set temp_id = new temp_id
3188 SPLIT N Y2 Y-set temp_id= merge temp_id
3189 LOAD_M N Y1 N
3190 LOAD_M N Y2 Y-set temp_id= merge temp_id
3191 LOAD_S N Y1 N-not necessary
3192 */
3193
3194 mydebug ('In : ' || l_proc_name);
3195 mydebug ('p_action = ' || p_action );
3196 mydebug ('p_insert = ' || p_insert );
3197 mydebug ('p_update = ' || p_update );
3198 mydebug ('p_transaction_header_id = ' || p_transaction_header_id );
3199 mydebug ('p_transaction_temp_id = ' || p_transaction_temp_id );
3200 mydebug ('p_new_transaction_temp_id= ' || p_new_transaction_temp_id);
3201 mydebug ('p_transaction_temp_id_to_merge = ' || p_transaction_temp_id_to_merge );
3202 mydebug ('p_serial_transaction_temp_id = ' || p_serial_transaction_temp_id );
3203 mydebug ('p_mtlt_serial_temp_id = ' || p_mtlt_serial_temp_id );
3204 mydebug ('p_inventory_item_id = ' || p_inventory_item_id );
3205 mydebug ('p_revision = ' || p_revision );
3206 mydebug ('p_suggested_uom = ' || p_suggested_uom );
3207 mydebug ('p_confirmed_uom = ' || p_confirmed_uom );
3208 mydebug ('p_primary_uom = ' || p_primary_uom );
3209 mydebug ('p_serial_lot_number = ' || p_serial_lot_number );
3210 mydebug ('p_confirmed_serials = ' || p_confirmed_serials );
3211 mydebug ('p_serial_allocated_flag = ' || p_serial_allocated_flag );
3212 mydebug ('p_lpn_match = ' || p_lpn_match );
3213 mydebug ('p_lpn_match_lpn_id = ' || p_lpn_match_lpn_id );
3214 mydebug ('p_lot_controlled = ' || p_lot_controlled );
3215 mydebug ('p_serial_controlled = ' || p_serial_controlled );
3216
3217 x_return_status := l_g_ret_sts_success;
3218 -- No more serials in the string p_confirmed_serials
3219 mydebug ('process serials: ' );
3220 IF (p_serial_transaction_temp_id IS NOT NULL ) -- it is a case of lot + serial
3221 -- and the call came from process_confirmed_lots
3222 THEN
3223 l_n_msnt_transaction_temp_id := p_serial_transaction_temp_id;
3224 l_o_msnt_transaction_temp_id := p_mtlt_serial_temp_id;
3225 ELSE
3226 l_o_msnt_transaction_temp_id :=p_transaction_temp_id;
3227 IF (p_insert = 'Y' ) THEN
3228 l_n_msnt_transaction_temp_id := p_new_transaction_temp_id;
3229 -- if a new mmtt ininserted then the MSNT
3230 -- should be attached to p_new_transaction_temp_id
3231 ELSE
3232 IF p_update = 'Y2' THEN
3233 l_n_msnt_transaction_temp_id := p_transaction_temp_id_to_merge;
3234 -- if current task is merged to an existing MMTT then the MSNT
3235 -- should be attached to p_transaction_temp_id_to_merge
3236 END IF;
3237 IF (p_update = 'Y1' ) THEN
3238 l_n_msnt_transaction_temp_id := p_transaction_temp_id; -- original MMTT
3239 -- and this will be used only if we are inserting MSNTs for
3240 -- no allocated serIals
3241 END IF;
3242 END IF;
3243 END IF;
3244 mydebug ('l_o_msnt_transaction_temp_id = ' || l_o_msnt_transaction_temp_id );
3245 mydebug ('l_n_msnt_transaction_temp_id = ' || l_n_msnt_transaction_temp_id );
3246
3247 IF p_confirmed_serials IS NOT NULL AND
3248 (p_insert = 'Y' OR p_update = 'Y2')
3249 THEN
3250 -- AND ( p_serial_allocated_flag = 'Y'))
3251 /* If serials are allocted then MSNT records will be associated with p_transaction_temp_id.
3252 If serials are not allocated but confirmed_serials is not null that means Java-UI created MSNT
3253 records and associated them with p_transaction_temp_id. there fore, for a case of SPLIT
3254 (leading to Merge or split) these MSNT records have to be moved to the confirmed_mmtt created.
3255 identified by l_n_msnt_transaction_temp_id */
3256 l_progress := '110';
3257 mydebug('l_progress: ' || l_progress );
3258 -- update the existing msnt record and set its transaction-temp_id = new_transaction-temp_id
3259 UPDATE mtl_serial_numbers_temp
3260 SET transaction_temp_id = l_n_msnt_transaction_temp_id
3261 , last_update_date = SYSDATE
3262 , last_updated_by = p_user_id
3263 WHERE transaction_temp_id = l_o_msnt_transaction_temp_id
3264 AND fm_serial_number IN
3265 (SELECT serial_number
3266 FROM mtl_allocations_gtmp
3267 WHERE NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@'));
3268
3269 IF SQL%NOTFOUND THEN
3270 mydebug('msnt not updateed..');
3271 RAISE fnd_api.G_EXC_ERROR;
3272 ELSE
3273 l_progress := '140';
3274 mydebug('l_progress: ' || l_progress );
3275 UPDATE MTL_SERIAL_NUMBERS
3276 SET group_mark_id = l_n_msnt_transaction_temp_id
3277 ,last_update_date= SYSDATE
3278 ,last_updated_by = p_user_id
3279 WHERE current_organization_id = p_organization_id
3280 AND inventory_item_id = p_inventory_item_id
3281 --AND group_mark_id IS NULL
3282 AND serial_number IN
3283 (SELECT serial_number
3284 FROM mtl_allocations_gtmp
3285 WHERE NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@'));
3286
3287 IF SQL%NOTFOUND THEN
3288 RAISE fnd_api.G_EXC_ERROR;
3289 END IF;
3290 END IF;
3291 ELSE
3292 l_progress := '170';
3293 mydebug('l_progress: ' || l_progress );
3294 ---(p_serial_allocated_flag = 'N' AND for allocated serials but lpn_match 1 or 3
3295 IF ( p_serial_allocated_flag = 'N' AND
3296 p_confirmed_serials IS NULL AND
3297 p_lpn_match IN (1,3) )
3298 -- for non-catch weight enabled
3299 --( p_confirmed_serials IS NOT NULL AND p_serial_allocated_flag = 'N')
3300 -- Pick Load page will insert these MSNTs
3301 THEN
3302 l_progress := '180';
3303 mydebug('l_progress: ' || l_progress );
3304
3305 --proc_insert_msnt inserts into MSNT using the data from MSN and also marks MSN
3306 proc_insert_msnt (p_transaction_temp_id => l_n_msnt_transaction_temp_id
3307 ,p_organization_id => p_organization_id
3308 ,p_inventory_item_id => p_inventory_item_id
3309 ,p_revision => p_revision
3310 ,p_confirmed_serials => p_confirmed_serials
3311 ,p_serial_number => NULL
3312 ,p_lpn_id => p_lpn_match_lpn_id -- NULL if lpn_match!=(1,3)
3313 ,p_serial_lot_number => p_serial_lot_number
3314 ,p_user_id => p_user_id
3315 ,x_return_status => x_return_status
3316 ,x_msg_count => x_msg_count
3317 ,x_msg_data => x_msg_data);
3318 IF x_return_status <> l_g_ret_sts_success THEN
3319 mydebug('x_return_status : ' || x_return_status);
3320 RAISE fnd_api.G_EXC_ERROR;
3321 END IF;
3322 END IF;
3323 /* added on 05/04/04 : fully consumable lpn where serials are allocated,
3324 * java does not pass the confirmed serials string . The following logic takes
3325 * care of the same. */
3326 IF p_confirmed_serials IS NULL AND
3327 p_serial_allocated_flag = 'Y' AND
3328 p_lpn_match IN (1,3) AND
3329 (p_insert = 'Y' OR p_update = 'Y2')
3330 THEN
3331 l_progress := '200';
3332 mydebug('l_progress: ' || l_progress );
3333
3334 -- update the existing msnt record and set its transaction-temp_id = new_transaction-temp_id
3335 UPDATE mtl_serial_numbers_temp
3336 SET transaction_temp_id = l_n_msnt_transaction_temp_id
3337 , last_update_date = SYSDATE
3338 , last_updated_by = p_user_id
3339 WHERE transaction_temp_id = l_o_msnt_transaction_temp_id
3340 AND fm_serial_number IN
3341 (SELECT serial_number
3342 FROM mtl_serial_numbers msn
3343 ,mtl_serial_numbers_temp msnt
3344 WHERE msn.serial_number = msnt.fm_serial_number
3345 AND msnt.transaction_temp_id = l_o_msnt_transaction_temp_id
3346 AND NVL(msn.lot_number,'@@') = nvl(p_serial_lot_number,'@@')
3347 AND msn.lpn_id = p_lpn_match_lpn_id);
3348
3349 IF SQL%NOTFOUND THEN
3350 mydebug('msnt not updateed..');
3351 RAISE fnd_api.G_EXC_ERROR;
3352 ELSE
3353 l_progress := '300';
3354 mydebug('l_progress: ' || l_progress );
3355 UPDATE MTL_SERIAL_NUMBERS
3356 SET group_mark_id = l_n_msnt_transaction_temp_id
3357 ,last_update_date= SYSDATE
3358 ,last_updated_by = p_user_id
3359 WHERE current_organization_id = p_organization_id
3360 AND inventory_item_id = p_inventory_item_id
3361 AND serial_number IN
3362 (SELECT serial_number
3363 FROM mtl_serial_numbers msn
3364 ,mtl_serial_numbers_temp msnt
3365 WHERE msn.serial_number = msnt.fm_serial_number
3366 AND msnt.transaction_temp_id = l_n_msnt_transaction_temp_id
3367 AND NVL(msn.lot_number,'@@') = nvl(p_serial_lot_number,'@@')
3368 AND msn.lpn_id = p_lpn_match_lpn_id);
3369
3370 IF SQL%NOTFOUND THEN
3371 RAISE fnd_api.G_EXC_ERROR;
3372 END IF;
3373 END IF;
3374 END IF;
3375 END IF;
3376 mydebug('End .. ' || l_proc_name);
3377 EXCEPTION
3378 WHEN fnd_api.g_exc_error THEN
3379 x_return_status := l_g_ret_sts_error;
3380 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3381 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3382 mydebug('fnd_api.g_exc_error: ' || SQLERRM);
3383 mydebug('ROLLBACK ' );
3384 ROLLBACK ;
3385 WHEN fnd_api.g_exc_unexpected_error THEN
3386 x_return_status := fnd_api.g_ret_sts_unexp_error;
3387 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3388 mydebug('ROLLBACK ' );
3389 ROLLBACK ;
3390 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3391 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
3392 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
3393 WHEN OTHERS THEN
3394 x_return_status := l_g_ret_sts_unexp_error;
3395 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3396 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3397 mydebug('fnd_api.g_exc_error: ' || SQLERRM);
3398 mydebug('ROLLBACK ' );
3399 ROLLBACK ;
3400
3401 END proc_process_confirmed_serials;
3402
3403 PROCEDURE proc_insert_mtlt
3404 ( p_lot_record IN mtl_transaction_lots_temp%ROWTYPE
3405 ,x_return_status OUT NOCOPY VARCHAR2
3406 ,x_msg_count OUT NOCOPY NUMBER
3407 ,x_msg_data OUT NOCOPY VARCHAR2)
3408 IS
3409 l_proc_name VARCHAR2(30) := 'PROC_INSERT_MTLT';
3410 l_progress VARCHAR2(30) := '100';
3411 BEGIN
3412 mydebug('In.. ' || l_proc_name);
3413 x_return_status := l_g_ret_sts_success;
3414 INSERT INTO mtl_transaction_lots_temp
3415 (transaction_temp_id
3416 ,last_update_date
3417 ,last_updated_by
3418 ,creation_date
3419 ,created_by
3420 ,last_update_login
3421 ,request_id
3422 ,program_application_id
3423 ,program_id
3424 ,program_update_date
3425 ,transaction_quantity
3426 ,primary_quantity
3427 ,lot_number
3428 ,lot_expiration_date
3429 ,error_code
3430 ,serial_transaction_temp_id
3431 ,group_header_id
3432 ,put_away_rule_id
3433 ,pick_rule_id
3434 ,description
3435 ,vendor_id
3436 ,supplier_lot_number
3437 ,territory_code
3438 ,origination_date
3439 ,date_code
3440 ,grade_code
3441 ,change_date
3442 ,maturity_date
3443 ,status_id
3444 ,retest_date
3445 ,age
3446 ,item_size
3447 ,color
3448 ,volume
3449 ,volume_uom
3450 ,place_of_origin
3451 ,best_by_date
3452 ,length
3453 ,length_uom
3454 ,recycled_content
3455 ,thickness
3456 ,thickness_uom
3457 ,width
3458 ,width_uom
3459 ,curl_wrinkle_fold
3460 ,lot_attribute_category
3461 ,c_attribute1
3462 ,c_attribute2
3463 ,c_attribute3
3464 ,c_attribute4
3465 ,c_attribute5
3466 ,c_attribute6
3467 ,c_attribute7
3468 ,c_attribute8
3469 ,c_attribute9
3470 ,c_attribute10
3471 ,c_attribute11
3472 ,c_attribute12
3473 ,c_attribute13
3474 ,c_attribute14
3475 ,c_attribute15
3476 ,c_attribute16
3477 ,c_attribute17
3478 ,c_attribute18
3479 ,c_attribute19
3480 ,c_attribute20
3481 ,d_attribute1
3482 ,d_attribute2
3483 ,d_attribute3
3484 ,d_attribute4
3485 ,d_attribute5
3486 ,d_attribute6
3487 ,d_attribute7
3488 ,d_attribute8
3489 ,d_attribute9
3490 ,d_attribute10
3491 ,n_attribute1
3492 ,n_attribute2
3493 ,n_attribute3
3494 ,n_attribute4
3495 ,n_attribute5
3496 ,n_attribute6
3497 ,n_attribute7
3498 ,n_attribute8
3499 ,n_attribute9
3500 ,n_attribute10
3501 ,vendor_name
3502 ,sublot_num
3503 ,secondary_quantity
3504 ,secondary_unit_of_measure
3505 ,qc_grade
3506 ,reason_code
3507 ,product_code
3508 ,product_transaction_id
3509 ,attribute_category
3510 ,attribute1
3511 ,attribute2
3512 ,attribute3
3513 ,attribute4
3514 ,attribute5
3515 ,attribute6
3516 ,attribute7
3517 ,attribute8
3518 ,attribute9
3519 ,attribute10
3520 ,attribute11
3521 ,attribute12
3522 ,attribute13
3523 ,attribute14
3524 ,attribute15)
3525 VALUES (
3526 p_lot_record.transaction_temp_id
3527 ,p_lot_record.last_update_date
3528 ,p_lot_record.last_updated_by
3529 ,SYSDATE
3530 ,p_lot_record.created_by
3531 ,p_lot_record.last_update_login
3532 ,p_lot_record.request_id
3533 ,p_lot_record.program_application_id
3534 ,p_lot_record.program_id
3535 ,SYSDATE
3536 ,p_lot_record.transaction_quantity
3537 ,p_lot_record.primary_quantity
3538 ,p_lot_record.lot_number
3539 ,p_lot_record.lot_expiration_date
3540 ,p_lot_record.error_code
3541 ,p_lot_record.serial_transaction_temp_id
3542 ,p_lot_record.group_header_id
3543 ,p_lot_record.put_away_rule_id
3544 ,p_lot_record.pick_rule_id
3545 ,p_lot_record.description
3546 ,p_lot_record.vendor_id
3547 ,p_lot_record.supplier_lot_number
3548 ,p_lot_record.territory_code
3549 ,p_lot_record.origination_date
3550 ,p_lot_record.date_code
3551 ,p_lot_record.grade_code
3552 ,p_lot_record.change_date
3553 ,p_lot_record.maturity_date
3554 ,p_lot_record.status_id
3555 ,p_lot_record.retest_date
3556 ,p_lot_record.age
3557 ,p_lot_record.item_size
3558 ,p_lot_record.color
3559 ,p_lot_record.volume
3560 ,p_lot_record.volume_uom
3561 ,p_lot_record.place_of_origin
3562 ,p_lot_record.best_by_date
3563 ,p_lot_record.length
3564 ,p_lot_record.length_uom
3565 ,p_lot_record.recycled_content
3566 ,p_lot_record.thickness
3567 ,p_lot_record.thickness_uom
3568 ,p_lot_record.width
3569 ,p_lot_record.width_uom
3570 ,p_lot_record.curl_wrinkle_fold
3571 ,p_lot_record.lot_attribute_category
3572 ,p_lot_record.c_attribute1
3573 ,p_lot_record.c_attribute2
3574 ,p_lot_record.c_attribute3
3575 ,p_lot_record.c_attribute4
3576 ,p_lot_record.c_attribute5
3577 ,p_lot_record.c_attribute6
3578 ,p_lot_record.c_attribute7
3579 ,p_lot_record.c_attribute8
3580 ,p_lot_record.c_attribute9
3581 ,p_lot_record.c_attribute10
3582 ,p_lot_record.c_attribute11
3583 ,p_lot_record.c_attribute12
3584 ,p_lot_record.c_attribute13
3585 ,p_lot_record.c_attribute14
3586 ,p_lot_record.c_attribute15
3587 ,p_lot_record.c_attribute16
3588 ,p_lot_record.c_attribute17
3589 ,p_lot_record.c_attribute18
3590 ,p_lot_record.c_attribute19
3591 ,p_lot_record.c_attribute20
3592 ,p_lot_record.d_attribute1
3593 ,p_lot_record.d_attribute2
3594 ,p_lot_record.d_attribute3
3595 ,p_lot_record.d_attribute4
3596 ,p_lot_record.d_attribute5
3597 ,p_lot_record.d_attribute6
3598 ,p_lot_record.d_attribute7
3599 ,p_lot_record.d_attribute8
3600 ,p_lot_record.d_attribute9
3601 ,p_lot_record.d_attribute10
3602 ,p_lot_record.n_attribute1
3603 ,p_lot_record.n_attribute2
3604 ,p_lot_record.n_attribute3
3605 ,p_lot_record.n_attribute4
3606 ,p_lot_record.n_attribute5
3607 ,p_lot_record.n_attribute6
3608 ,p_lot_record.n_attribute7
3609 ,p_lot_record.n_attribute8
3610 ,p_lot_record.n_attribute9
3611 ,p_lot_record.n_attribute10
3612 ,p_lot_record.vendor_name
3613 ,p_lot_record.sublot_num
3614 ,p_lot_record.secondary_quantity
3615 ,p_lot_record.secondary_unit_of_measure
3616 ,p_lot_record.qc_grade
3617 ,p_lot_record.reason_code
3618 ,p_lot_record.product_code
3619 ,p_lot_record.product_transaction_id
3620 ,p_lot_record.attribute_category
3621 ,p_lot_record.attribute1
3622 ,p_lot_record.attribute2
3623 ,p_lot_record.attribute3
3624 ,p_lot_record.attribute4
3625 ,p_lot_record.attribute5
3626 ,p_lot_record.attribute6
3627 ,p_lot_record.attribute7
3628 ,p_lot_record.attribute8
3629 ,p_lot_record.attribute9
3630 ,p_lot_record.attribute10
3631 ,p_lot_record.attribute11
3632 ,p_lot_record.attribute12
3633 ,p_lot_record.attribute13
3634 ,p_lot_record.attribute14
3635 ,p_lot_record.attribute15);
3636
3637 mydebug('l_progress: ' || l_progress );
3638 mydebug('End.. ' || l_proc_name);
3639 EXCEPTION
3640 WHEN fnd_api.g_exc_error THEN
3641 x_return_status := l_g_ret_sts_error;
3642 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3643 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3644 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
3645 mydebug('ROLLBACK ' );
3646 ROLLBACK ;
3647 WHEN fnd_api.g_exc_unexpected_error THEN
3648 x_return_status := fnd_api.g_ret_sts_unexp_error;
3649 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3650 mydebug('ROLLBACK ' );
3651 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3652 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
3653 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
3654 ROLLBACK ;
3655 WHEN OTHERS THEN
3656 x_return_status := l_g_ret_sts_unexp_error;
3657 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3658 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
3659 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
3660 mydebug('ROLLBACK ' );
3661 ROLLBACK ;
3662
3663 END proc_insert_mtlt;
3664
3665
3666 PROCEDURE proc_insert_msnt
3667 (p_transaction_temp_id IN NUMBER
3668 ,p_organization_id IN NUMBER
3669 ,p_inventory_item_id IN NUMBER
3670 ,p_revision IN VARCHAR2
3671 ,p_confirmed_serials IN VARCHAR2
3672 ,p_serial_number IN VARCHAR2
3673 ,p_lpn_id IN NUMBER
3674 ,p_serial_lot_number IN VARCHAR2
3675 ,p_user_id IN NUMBER
3676 ,x_return_status OUT NOCOPY VARCHAR2
3677 ,x_msg_count OUT NOCOPY NUMBER
3678 ,x_msg_data OUT NOCOPY VARCHAR2)
3679 IS
3680 --p_transaction_temp_id := transaction_temp_id of the new MSNT
3681 l_proc_name VARCHAR2(30) := 'PROC_INSERT_MSNT';
3682 l_progress VARCHAR2(30) := '100';
3683 l_serial_prefix NUMBER;
3684 l_real_serial_prefix VARCHAR2(30);
3685 l_serial_numeric_frm NUMBER;
3686 l_serial_numeric_to NUMBER;
3687 l_number_of_serial_numbers NUMBER;
3688
3689 BEGIN
3690 mydebug('In .. ' || l_proc_name);
3691 mydebug('p_transaction_temp_id = ' || p_transaction_temp_id);
3692 mydebug('p_organization_id = ' || p_organization_id);
3693 mydebug('p_inventory_item_id = ' || p_inventory_item_id);
3694 mydebug('p_serial_number = ' || p_serial_number);
3695 mydebug('p_lpn_id = ' || p_lpn_id);
3696 mydebug('p_user_id = ' || p_user_id);
3697
3698 x_return_status := l_g_ret_sts_success;
3699 l_progress := '110';
3700
3701 -- copied the logic from INV_TRX_UTIL_PUB.INSERT_SER_TRX
3702 l_real_serial_prefix := RTRIM(p_serial_number, '0123456789');
3703 l_serial_numeric_frm := TO_NUMBER(SUBSTR(p_serial_number, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
3704 l_serial_numeric_to := TO_NUMBER(SUBSTR(p_serial_number, NVL(LENGTH(l_real_serial_prefix), 0) + 1));
3705 l_serial_prefix := (l_serial_numeric_to - l_serial_numeric_frm) + 1;
3706
3707 l_progress := '120';
3708 mydebug ('l_progress: ' || l_progress );
3709 -- P_serial_number is null means we are inserting a group of serials either
3710 -- 1. using LPN_ID passed in or serial_lot_number passed in (p-confirmed_serials is NULL)
3711 -- OR 2. using the data from the gtmp table (when p_confirmed_serials is nOT NULL)
3712 IF p_serial_number IS NULL
3713 THEN
3714 INSERT INTO mtl_serial_numbers_temp
3715 (transaction_temp_id
3716 ,last_update_date
3717 ,last_updated_by
3718 ,creation_date
3719 ,created_by
3720 ,last_update_login
3721 ,request_id
3722 ,program_application_id
3723 ,program_id
3724 ,program_update_date
3725 ,vendor_serial_number
3726 ,vendor_lot_number
3727 ,fm_serial_number
3728 ,to_serial_number
3729 ,serial_prefix
3730 ,error_code
3731 ,parent_serial_number
3732 ,group_header_id
3733 ,end_item_unit_number
3734 ,serial_attribute_category
3735 ,territory_code
3736 ,origination_date
3737 ,c_attribute1
3738 ,c_attribute2
3739 ,c_attribute3
3740 ,c_attribute4
3741 ,c_attribute5
3742 ,c_attribute6
3743 ,c_attribute7
3744 ,c_attribute8
3745 ,c_attribute9
3746 ,c_attribute10
3747 ,c_attribute11
3748 ,c_attribute12
3749 ,c_attribute13
3750 ,c_attribute14
3751 ,c_attribute15
3752 ,c_attribute16
3753 ,c_attribute17
3754 ,c_attribute18
3755 ,c_attribute19
3756 ,c_attribute20
3757 ,d_attribute1
3758 ,d_attribute2
3759 ,d_attribute3
3760 ,d_attribute4
3761 ,d_attribute5
3762 ,d_attribute6
3763 ,d_attribute7
3764 ,d_attribute8
3765 ,d_attribute9
3766 ,d_attribute10
3767 ,n_attribute1
3768 ,n_attribute2
3769 ,n_attribute3
3770 ,n_attribute4
3771 ,n_attribute5
3772 ,n_attribute6
3773 ,n_attribute7
3774 ,n_attribute8
3775 ,n_attribute9
3776 ,n_attribute10
3777 ,status_id
3778 ,time_since_new
3779 ,cycles_since_new
3780 ,time_since_overhaul
3781 ,cycles_since_overhaul
3782 ,time_since_repair
3783 ,cycles_since_repair
3784 ,time_since_visit
3785 ,cycles_since_visit
3786 ,time_since_mark
3787 ,cycles_since_mark
3788 ,number_of_repairs
3789 ,product_code
3790 ,product_transaction_id )
3791 (SELECT
3792 p_transaction_temp_id
3793 ,SYSDATE
3794 ,-1
3795 ,SYSDATE
3796 ,p_user_id
3797 ,msn.last_update_login
3798 ,msn.request_id
3799 ,msn.program_application_id
3800 ,msn.program_id
3801 ,msn.program_update_date
3802 ,msn.vendor_serial_number
3803 ,msn.vendor_lot_number
3804 ,msn.serial_number
3805 ,msn.serial_number
3806 ,NVL(l_serial_prefix, 1)
3807 ,NULL -- error code
3808 ,msn.parent_serial_number
3809 ,NULL --group_header_id
3810 ,msn.end_item_unit_number
3811 ,msn.serial_attribute_category
3812 ,msn.territory_code
3813 ,msn.origination_date
3814 ,msn.c_attribute1
3815 ,msn.c_attribute2
3816 ,msn.c_attribute3
3817 ,msn.c_attribute4
3818 ,msn.c_attribute5
3819 ,msn.c_attribute6
3820 ,msn.c_attribute7
3821 ,msn.c_attribute8
3822 ,msn.c_attribute9
3823 ,msn.c_attribute10
3824 ,msn.c_attribute11
3825 ,msn.c_attribute12
3826 ,msn.c_attribute13
3827 ,msn.c_attribute14
3828 ,msn.c_attribute15
3829 ,msn.c_attribute16
3830 ,msn.c_attribute17
3831 ,msn.c_attribute18
3832 ,msn.c_attribute19
3833 ,msn.c_attribute20
3834 ,msn.d_attribute1
3835 ,msn.d_attribute2
3836 ,msn.d_attribute3
3837 ,msn.d_attribute4
3838 ,msn.d_attribute5
3839 ,msn.d_attribute6
3840 ,msn.d_attribute7
3841 ,msn.d_attribute8
3842 ,msn.d_attribute9
3843 ,msn.d_attribute10
3844 ,msn.n_attribute1
3845 ,msn.n_attribute2
3846 ,msn.n_attribute3
3847 ,msn.n_attribute4
3848 ,msn.n_attribute5
3849 ,msn.n_attribute6
3850 ,msn.n_attribute7
3851 ,msn.n_attribute8
3852 ,msn.n_attribute9
3853 ,msn.n_attribute10
3854 ,msn.status_id
3855 ,msn.time_since_new
3856 ,msn.cycles_since_new
3857 ,msn.time_since_overhaul
3858 ,msn.cycles_since_overhaul
3859 ,msn.time_since_repair
3860 ,msn.cycles_since_repair
3861 ,msn.time_since_visit
3862 ,msn.cycles_since_visit
3863 ,msn.time_since_mark
3864 ,msn.cycles_since_mark
3865 ,msn.number_of_repairs
3866 ,NULL --product_code
3867 ,NULL --product_transaction_id
3868 FROM mtl_serial_numbers msn
3869 WHERE msn.current_organization_id = p_organization_id
3870 AND msn.inventory_item_id = p_inventory_item_id
3871 AND lpn_id = p_lpn_id
3872 AND NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@'));
3873 --AND group_mark_id IS NULL);
3874
3875 IF SQL%NOTFOUND THEN --- MSN record not found)
3876 RAISE fnd_api.G_EXC_ERROR;
3877 END IF;
3878
3879 l_progress := '130';
3880 mydebug('l_progress: ' || l_progress );
3881 proc_mark_msn (p_group_mark_id => p_transaction_temp_id
3882 ,p_organization_id => p_organization_id
3883 ,p_inventory_item_id => p_inventory_item_id
3884 ,p_revision => p_revision
3885 ,p_confirmed_serials => p_confirmed_serials
3886 ,p_serial_lot_number => p_serial_lot_number
3887 ,p_serial_number => p_serial_number
3888 ,p_lpn_id => p_lpn_id
3889 ,p_user_id => p_user_id
3890 ,x_return_status => x_return_status
3891 ,x_msg_count => x_msg_count
3892 ,x_msg_data => x_msg_data);
3893 IF x_return_status <> l_g_ret_sts_success THEN
3894 mydebug('x_return_status : ' || x_return_status);
3895 RAISE fnd_api.G_EXC_ERROR;
3896 END IF;
3897
3898 ELSE -- confirmed_serials are no null so get the serials from mtl-allocations_gtmp table
3899
3900 INSERT INTO mtl_serial_numbers_temp
3901 (transaction_temp_id
3902 ,last_update_date
3903 ,last_updated_by
3904 ,creation_date
3905 ,created_by
3906 ,last_update_login
3907 ,request_id
3908 ,program_application_id
3909 ,program_id
3910 ,program_update_date
3911 ,vendor_serial_number
3912 ,vendor_lot_number
3913 ,fm_serial_number
3914 ,to_serial_number
3915 ,serial_prefix
3916 ,error_code
3917 ,parent_serial_number
3918 ,group_header_id
3919 ,end_item_unit_number
3920 ,serial_attribute_category
3921 ,territory_code
3922 ,origination_date
3923 ,c_attribute1
3924 ,c_attribute2
3925 ,c_attribute3
3926 ,c_attribute4
3927 ,c_attribute5
3928 ,c_attribute6
3929 ,c_attribute7
3930 ,c_attribute8
3931 ,c_attribute9
3932 ,c_attribute10
3933 ,c_attribute11
3934 ,c_attribute12
3935 ,c_attribute13
3936 ,c_attribute14
3937 ,c_attribute15
3938 ,c_attribute16
3939 ,c_attribute17
3940 ,c_attribute18
3941 ,c_attribute19
3942 ,c_attribute20
3943 ,d_attribute1
3944 ,d_attribute2
3945 ,d_attribute3
3946 ,d_attribute4
3947 ,d_attribute5
3948 ,d_attribute6
3949 ,d_attribute7
3950 ,d_attribute8
3951 ,d_attribute9
3952 ,d_attribute10
3953 ,n_attribute1
3954 ,n_attribute2
3955 ,n_attribute3
3956 ,n_attribute4
3957 ,n_attribute5
3958 ,n_attribute6
3959 ,n_attribute7
3960 ,n_attribute8
3961 ,n_attribute9
3962 ,n_attribute10
3963 ,status_id
3964 ,time_since_new
3965 ,cycles_since_new
3966 ,time_since_overhaul
3967 ,cycles_since_overhaul
3968 ,time_since_repair
3969 ,cycles_since_repair
3970 ,time_since_visit
3971 ,cycles_since_visit
3972 ,time_since_mark
3973 ,cycles_since_mark
3974 ,number_of_repairs
3975 ,product_code
3976 ,product_transaction_id )
3977 (SELECT
3978 p_transaction_temp_id
3979 ,SYSDATE
3980 ,-1
3981 ,SYSDATE
3982 ,p_user_id
3983 ,msn.last_update_login
3984 ,msn.request_id
3985 ,msn.program_application_id
3986 ,msn.program_id
3987 ,msn.program_update_date
3988 ,msn.vendor_serial_number
3989 ,msn.vendor_lot_number
3990 ,msn.serial_number
3991 ,msn.serial_number
3992 ,NVL(l_serial_prefix, 1)
3993 ,NULL -- error code
3994 ,msn.parent_serial_number
3995 ,NULL --group_header_id
3996 ,msn.end_item_unit_number
3997 ,msn.serial_attribute_category
3998 ,msn.territory_code
3999 ,msn.origination_date
4000 ,msn.c_attribute1
4001 ,msn.c_attribute2
4002 ,msn.c_attribute3
4003 ,msn.c_attribute4
4004 ,msn.c_attribute5
4005 ,msn.c_attribute6
4006 ,msn.c_attribute7
4007 ,msn.c_attribute8
4008 ,msn.c_attribute9
4009 ,msn.c_attribute10
4010 ,msn.c_attribute11
4011 ,msn.c_attribute12
4012 ,msn.c_attribute13
4013 ,msn.c_attribute14
4014 ,msn.c_attribute15
4015 ,msn.c_attribute16
4016 ,msn.c_attribute17
4017 ,msn.c_attribute18
4018 ,msn.c_attribute19
4019 ,msn.c_attribute20
4020 ,msn.d_attribute1
4021 ,msn.d_attribute2
4022 ,msn.d_attribute3
4023 ,msn.d_attribute4
4024 ,msn.d_attribute5
4025 ,msn.d_attribute6
4026 ,msn.d_attribute7
4027 ,msn.d_attribute8
4028 ,msn.d_attribute9
4029 ,msn.d_attribute10
4030 ,msn.n_attribute1
4031 ,msn.n_attribute2
4032 ,msn.n_attribute3
4033 ,msn.n_attribute4
4034 ,msn.n_attribute5
4035 ,msn.n_attribute6
4036 ,msn.n_attribute7
4037 ,msn.n_attribute8
4038 ,msn.n_attribute9
4039 ,msn.n_attribute10
4040 ,msn.status_id
4041 ,msn.time_since_new
4042 ,msn.cycles_since_new
4043 ,msn.time_since_overhaul
4044 ,msn.cycles_since_overhaul
4045 ,msn.time_since_repair
4046 ,msn.cycles_since_repair
4047 ,msn.time_since_visit
4048 ,msn.cycles_since_visit
4049 ,msn.time_since_mark
4050 ,msn.cycles_since_mark
4051 ,msn.number_of_repairs
4052 ,NULL --product_code
4053 ,NULL --product_transaction_id
4054 FROM mtl_serial_numbers msn
4055 WHERE msn.current_organization_id = p_organization_id
4056 AND msn.inventory_item_id = p_inventory_item_id
4057 AND nvl(lpn_id,0) = nvl(p_lpn_id,0)
4058 AND NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@')
4059 --AND group_mark_id IS NULL
4060 AND msn.serial_number IN
4061 (SELECT serial_number
4062 FROM mtl_allocations_gtmp
4063 WHERE NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@'))
4064 );
4065 IF SQL%NOTFOUND THEN --- MSN record not found)
4066 RAISE fnd_api.G_EXC_ERROR;
4067 END IF;
4068 l_progress := '130';
4069 mydebug('l_progress: ' || l_progress );
4070 proc_mark_msn (p_group_mark_id => p_transaction_temp_id
4071 ,p_organization_id => p_organization_id
4072 ,p_inventory_item_id => p_inventory_item_id
4073 ,p_revision => p_revision
4074 ,p_confirmed_serials => p_confirmed_serials
4075 ,p_serial_lot_number => p_serial_lot_number
4076 ,p_serial_number => p_serial_number
4077 ,p_lpn_id => p_lpn_id
4078 ,p_user_id => p_user_id
4079 ,x_return_status => x_return_status
4080 ,x_msg_count => x_msg_count
4081 ,x_msg_data => x_msg_data);
4082 IF x_return_status <> l_g_ret_sts_success THEN
4083 mydebug('x_return_status : ' || x_return_status);
4084 RAISE fnd_api.G_EXC_ERROR;
4085 END IF;
4086 END IF;
4087
4088 mydebug('End .. ' || l_proc_name);
4089 EXCEPTION
4090 WHEN fnd_api.g_exc_error THEN
4091 x_return_status := l_g_ret_sts_error;
4092 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4093 mydebug('ROLLBACK ' );
4094 ROLLBACK ;
4095 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4096 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
4097 WHEN fnd_api.g_exc_unexpected_error THEN
4098 x_return_status := fnd_api.g_ret_sts_unexp_error;
4099 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4100 mydebug('ROLLBACK ' );
4101 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4102 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
4103 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
4104 ROLLBACK ;
4105 WHEN OTHERS THEN
4106 x_return_status := l_g_ret_sts_unexp_error;
4107 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4108 mydebug('ROLLBACK ' );
4109 ROLLBACK ;
4110 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4111 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
4112
4113 END proc_insert_msnt ;
4114
4115 PROCEDURE proc_mark_msn
4116 (p_group_mark_id IN NUMBER
4117 ,p_organization_id IN NUMBER
4118 ,p_inventory_item_id IN NUMBER
4119 ,p_Revision IN VARCHAR2
4120 ,p_confirmed_serials IN VARCHAR2
4121 ,p_serial_lot_number IN VARCHAR2
4122 ,p_serial_number IN VARCHAR2
4123 ,p_lpn_id IN NUMBER
4124 ,p_user_id IN NUMBER
4125 ,x_return_status OUT NOCOPY VARCHAR2
4126 ,x_msg_count OUT NOCOPY NUMBER
4127 ,x_msg_data OUT NOCOPY VARCHAR2)
4128 IS
4129 --p_transaction_temp_id := transaction_temp_id of the new MSNT
4130 l_proc_name VARCHAR2(30) := 'PROC_MARK_MSN';
4131 l_progress VARCHAR2(30) := '100';
4132 BEGIN
4133 mydebug('In .. ' || l_proc_name);
4134 mydebug('p_group_mark_id : ' || p_group_mark_id);
4135 mydebug('p_organization_id : ' || p_organization_id);
4136 mydebug('p_inventory_item_id : ' || p_inventory_item_id);
4137 mydebug('p_serial_number : ' || p_serial_number);
4138 mydebug('p_lpn_id : ' || p_lpn_id );
4139 mydebug('p_user_id : ' || p_user_id);
4140
4141 x_return_status := l_g_ret_sts_success;
4142 l_progress := '110';
4143 mydebug('l_progress: ' || l_progress );
4144 IF p_serial_number IS NULL
4145 THEN
4146 l_progress := '200';
4147 mydebug('l_progress: ' || l_progress );
4148 UPDATE MTL_SERIAL_NUMBERS
4149 SET group_mark_id = p_group_mark_id
4150 , last_updated_by = p_user_id
4151 WHERE current_organization_id = p_organization_id
4152 AND inventory_item_id = p_inventory_item_id
4153 AND lpn_id = p_lpn_id ;
4154 --AND group_mark_id IS NULL;
4155
4156 IF SQL%NOTFOUND THEN
4157 fnd_message.set_name('WMS', 'WMS_ERROR_MARKING_SERIAL'); --NEWMSG
4158 -- "Error reserving Serial Number/s"
4159 fnd_msg_pub.ADD;
4160 RAISE fnd_api.G_EXC_ERROR;
4161 END IF;
4162 ELSE
4163 l_progress := '300';
4164 mydebug('l_progress: ' || l_progress );
4165 UPDATE MTL_SERIAL_NUMBERS msn
4166 SET group_mark_id = p_group_mark_id
4167 , last_updated_by = p_user_id
4168 WHERE msn.current_organization_id = p_organization_id
4169 AND msn.inventory_item_id = p_inventory_item_id
4170 AND nvl(lpn_id,0) = nvl(p_lpn_id,0)
4171 AND NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@')
4172 --AND group_mark_id IS NULL
4173 AND msn.serial_number IN
4174 (SELECT serial_number
4175 FROM mtl_allocations_gtmp
4176 WHERE NVL(lot_number,'@@') = nvl(p_serial_lot_number,'@@'));
4177
4178 IF SQL%NOTFOUND THEN
4179 fnd_message.set_name('WMS', 'WMS_ERROR_MARKING_SERIAL'); --NEWMSG
4180 -- "Error reserving Serial Number/s"
4181 fnd_msg_pub.ADD;
4182 RAISE fnd_api.G_EXC_ERROR;
4183 END IF;
4184 END IF;
4185
4186 mydebug('End .. ' || l_proc_name);
4187 EXCEPTION
4188 WHEN fnd_api.g_exc_error THEN
4189 x_return_status := l_g_ret_sts_error;
4190 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4191 mydebug('ROLLBACK ' );
4192 ROLLBACK ;
4193 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4194 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
4195 WHEN fnd_api.g_exc_unexpected_error THEN
4196 x_return_status := fnd_api.g_ret_sts_unexp_error;
4197 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4198 mydebug('ROLLBACK ' );
4199 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4200 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
4201 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
4202 ROLLBACK ;
4203 WHEN OTHERS THEN
4204 x_return_status := l_g_ret_sts_unexp_error;
4205 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4206 mydebug('ROLLBACK ' );
4207 ROLLBACK ;
4208 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4209 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
4210
4211 END proc_mark_msn ;
4212
4213 PROCEDURE proc_unmark_msn (p_group_mark_id IN NUMBER
4214 ,p_organization_id IN NUMBER
4215 ,p_inventory_item_id IN NUMBER
4216 ,p_Revision IN VARCHAR2
4217 ,p_serial_number IN VARCHAR2
4218 ,p_lpn_id IN NUMBER
4219 ,p_user_id IN NUMBER
4220 ,x_return_status OUT NOCOPY VARCHAR2
4221 ,x_msg_count OUT NOCOPY NUMBER
4222 ,x_msg_data OUT NOCOPY VARCHAR2)
4223 IS
4224 --p_transaction_temp_id := transaction_temp_id of the new MSNT
4225 l_proc_name VARCHAR2(30) := 'PROC_UNMARK_MSN';
4226 l_progress VARCHAR2(30) := '100';
4227 BEGIN
4228 mydebug('In .. ' || l_proc_name);
4229 mydebug('p_group_mark_id : ' || p_group_mark_id);
4230 mydebug('p_organization_id : ' || p_organization_id);
4231 mydebug('p_inventory_item_id : ' || p_inventory_item_id);
4232 mydebug('p_serial_number : ' || p_serial_number);
4233 mydebug('p_lpn_id : ' || p_lpn_id );
4234 mydebug('p_user_id : ' || p_user_id);
4235
4236 x_return_status := l_g_ret_sts_success;
4237 l_progress := '110';
4238 mydebug('l_progress: ' || l_progress );
4239 UPDATE MTL_SERIAL_NUMBERS
4240 SET group_mark_id = p_group_mark_id
4241 , last_updated_by = p_user_id
4242 WHERE current_organization_id = p_organization_id
4243 AND inventory_item_id = p_inventory_item_id
4244 AND nvl(lpn_id,0) = nvl(p_lpn_id,0)
4245 AND DECODE(p_serial_number,NULL,'@@',serial_number) = nvl(p_serial_number,'@@') ;
4246 --AND group_mark_id IS NULL;
4247
4248 IF SQL%NOTFOUND THEN
4249 RAISE fnd_api.G_EXC_ERROR;
4250 END IF;
4251
4252 mydebug('End .. ' || l_proc_name);
4253 EXCEPTION
4254 WHEN fnd_api.g_exc_error THEN
4255 x_return_status := l_g_ret_sts_error;
4256 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4257 mydebug('ROLLBACK ' );
4258 ROLLBACK ;
4259 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4260 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
4261 WHEN fnd_api.g_exc_unexpected_error THEN
4262 x_return_status := fnd_api.g_ret_sts_unexp_error;
4263 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4264 mydebug('ROLLBACK ' );
4265 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4266 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
4267 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
4268 ROLLBACK ;
4269 WHEN OTHERS THEN
4270 x_return_status := l_g_ret_sts_unexp_error;
4271 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4272 mydebug('ROLLBACK ' );
4273 ROLLBACK ;
4274 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
4275 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
4276
4277 END proc_unmark_msn ;
4278
4279 /* WHen F2 is pressed, the MMTT/MTLT/MSNT that was split needs to be rolled back so that,
4280 * task is in its original state that is before it was split. Sice the split commits the
4281 * newly inserted/updated details, the rollback has to be done manually.
4282 */
4283 PROCEDURE process_F2(
4284 p_action IN VARCHAR2 -- NULL, CMS
4285 ,p_organization_id IN NUMBER
4286 ,p_user_id IN NUMBER
4287 ,p_employee_id IN NUMBER
4288 ,p_transaction_header_id IN NUMBER
4289 ,p_transaction_temp_id IN NUMBER
4290 ,p_original_sub IN VARCHAR2
4291 ,p_original_locator_id IN NUMBER
4292 ,p_lot_controlled IN VARCHAR2 -- Y/N
4293 ,p_serial_controlled IN VARCHAR2 -- Y/N
4294 ,p_serial_allocated_flag IN VARCHAR2 -- Y/N
4295 ,p_suggested_uom IN VARCHAR2 -- original allocation UOM
4296 ,p_start_over IN VARCHAR2 -- Y/N start_over
4297 ,p_retain_task IN VARCHAR2 -- Y/N for bug 4310093
4298 ,x_start_over_taskno OUT NOCOPY NUMBER -- start_over task
4299 ,x_return_status OUT NOCOPY VARCHAR2
4300 ,x_msg_count OUT NOCOPY NUMBER
4301 ,x_msg_data OUT NOCOPY VARCHAR2)
4302 IS
4303 --PRAGMA AUTONOMOUS_TRANSACTION;
4304
4305 l_proc_name VARCHAR2(30) := 'PROCESS_F2';
4306 l_progress VARCHAR2(30) := '100';
4307 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4308 l_new_transaction_temp_id NUMBER := NULL;
4309 l_serial_transaction_temp_id NUMBER := NULL;
4310 l_transaction_temp_id NUMBER := NULL;
4311 l_original_sub_loc VARCHAR2(1) := 'N';
4312 l_rec_mtlt_to_copy_from mtl_transaction_lots_temp%ROWTYPE;
4313 l_suggested_mmtt_qty NUMBER := 0;
4314 l_suggested_mtlt_qty NUMBER := 0;
4315 -- bug #4141928 INV CONV
4316 l_suggested_mmtt_sec_qty NUMBER := 0;
4317 l_suggested_mtlt_sec_qty NUMBER := 0;
4318
4319 l_op_msnt_to_delete NUMBER := 0;
4320 l_start_over_task NUMBER := 0;
4321 l_parent_posting_flag VARCHAR2(1); -- Bug#4185621
4322
4323
4324 /* cur_mmtt1
4325 -- Group MMTTs(including p_transaction_temp_id) with p_transaction_header_id
4326 -- by inventory_item_id,subinventory_code,locator_id.
4327 -- update one of the MMTTs(min temp_id) from each group and delete rest from that group */
4328
4329 CURSOR cur_mmtt1
4330 IS
4331 SELECT sum(primary_quantity) mmtt_primary_quantity
4332 -- bug #4141928 INV CONV
4333 , sum(secondary_transaction_quantity) mmtt_secondary_quantity
4334 , COUNT(*) mmtt_group_count
4335 , MIN(transaction_temp_id) group_temp_id
4336 , MIN(parent_line_id) parent_line_id -- Bug#4185621
4337 , inventory_item_id
4338 , revision
4339 , subinventory_code
4340 , locator_id
4341 , item_primary_uom_code
4342 FROM mtl_material_transactions_temp mmtt
4343 WHERE mmtt.transaction_header_id = p_transaction_header_id
4344 GROUP BY
4345 inventory_item_id
4346 ,revision
4347 ,subinventory_code
4348 ,locator_id
4349 ,item_primary_uom_code;
4350
4351 CURSOR cur_mtlt1 ( p_subinventory_code VARCHAR2
4352 ,p_locator_id NUMBER
4353 ,p_uom_code VARCHAR2
4354 ,p_inventory_item_id VARCHAR2
4355 ,p_revision VARCHAR2
4356 ,p_group_temp_id NUMBER)
4357 IS
4358 SELECT sum(mtlt.primary_quantity) group_lot_primary_quantity
4359 -- bug #4141928 INV CONV
4360 , sum(mtlt.secondary_quantity) group_lot_secondary_quantity
4361 ,COUNT(*) group_lot_count
4362 ,MIN(mtlt.transaction_temp_id) group_lot_temp_id
4363 ,mtlt.lot_number
4364 FROM mtl_transaction_lots_temp mtlt
4365 , mtl_material_transactions_temp mmtt
4366 WHERE mmtt.transaction_header_id = p_transaction_header_id
4367 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
4368 AND mmtt.subinventory_code = p_subinventory_code
4369 AND mmtt.locator_id = p_locator_id
4370 AND mmtt.item_primary_uom_code = p_uom_code
4371 AND mmtt.inventory_item_id = p_inventory_item_id
4372 AND nvl(mmtt.revision,'@@') = nvl(p_revision,'@@')
4373 GROUP BY
4374 mtlt.lot_number;
4375
4376 CURSOR cur_msnt_to_delete ( p_rec_mmtt1_subinventory_code VARCHAR2
4377 ,p_rec_mmtt1_locator_id NUMBER
4378 ,p_rec_mmtt1_item_primary_uom VARCHAR2
4379 ,p_rec_mmtt1_inventory_item_id NUMBER
4380 ,p_rec_mmtt1_revision VARCHAR2)
4381 IS
4382 SELECT msnt.transaction_temp_id
4383 ,msnt.fm_serial_number
4384 ,mmtt.organization_id
4385 ,mmtt.inventory_item_id
4386 ,msnt.creation_date
4387 FROM mtl_serial_numbers_temp msnt
4388 ,mtl_material_transactions_temp mmtt
4389 WHERE mmtt.transaction_header_id = p_transaction_header_id
4390 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
4391 AND mmtt.subinventory_code = p_rec_mmtt1_subinventory_code
4392 AND mmtt.locator_id = p_rec_mmtt1_locator_id
4393 AND mmtt.item_primary_uom_code = p_rec_mmtt1_item_primary_uom
4394 AND mmtt.inventory_item_id = p_rec_mmtt1_inventory_item_id
4395 AND nvl(mmtt.revision,'@@') = nvl(p_rec_mmtt1_revision,'@@')
4396 ORDER BY msnt.creation_date DESC;
4397
4398 CURSOR cur_msnt_to_delete_LS (p_serial_transaction_temp_id NUMBER)
4399 IS
4400 SELECT msnt.transaction_temp_id
4401 ,msnt.fm_serial_number
4402 ,msnt.creation_date
4403 FROM mtl_serial_numbers_temp msnt
4404 WHERE msnt.transaction_temp_id = p_serial_transaction_temp_id
4405 ORDER BY msnt.creation_date DESC;
4406 BEGIN
4407 mydebug('In .. ' || l_proc_name);
4408 x_return_status := l_g_ret_sts_success;
4409 g_debug := l_debug;
4410
4411 mydebug ('p_action = ' || p_action);
4412 mydebug ('p_organization_id = ' || p_organization_id);
4413 mydebug ('p_user_id = ' || p_user_id);
4414 mydebug ('p_employee_id = ' || p_employee_id);
4415 mydebug ('p_transaction_header_id = ' || p_transaction_header_id);
4416 mydebug ('p_transaction_temp_id = ' || p_transaction_temp_id);
4417 mydebug ('p_original_sub = ' || p_original_sub);
4418 mydebug ('p_original_locator_id = ' || p_original_locator_id);
4419 mydebug ('p_lot_controlled = ' || p_lot_controlled);
4420 mydebug ('p_serial_controlled = ' || p_serial_controlled);
4421 mydebug ('p_serial_allocated_flag = ' || p_serial_allocated_flag);
4422 mydebug ('p_suggested_uom = ' || p_suggested_uom );
4423
4424 l_progress := 110;
4425 mydebug('l_progress = ' || l_progress);
4426 proc_device_call (
4427 p_action => p_action
4428 , p_employee_id => p_employee_id
4429 , p_transaction_temp_id => p_transaction_temp_id
4430 , x_return_status => x_return_status
4431 , x_msg_count => x_msg_count
4432 , x_msg_data => x_msg_data );
4433 IF x_return_status <> l_g_ret_sts_success THEN
4434 mydebug('x_return_status : ' || x_return_status);
4435 --RAISE fnd_api.G_EXC_ERROR; punnet's request
4436 END IF;
4437
4438 l_progress := 200;
4439 mydebug('l_progress = ' || l_progress);
4440
4441 /*{{
4442 * If user had not pressed start over button we would reset the status of task
4443 * as done before.All task would return to pending wdd would be deleted.
4444 *}}
4445 */
4446
4447 IF p_start_over ='N' and p_retain_task='N' THEN --bug 4310093
4448 mydebug('viks start_over button not pressed:');
4449
4450 proc_reset_task_status(
4451 p_action => p_action
4452 ,p_organization_id => p_organization_id
4453 ,p_user_id => p_user_id
4454 ,p_employee_id => p_employee_id
4455 ,p_transaction_header_id => p_transaction_header_id
4456 ,p_transaction_temp_id => p_transaction_temp_id
4457 ,x_return_status => x_return_status
4458 ,x_msg_count => x_msg_count
4459 ,x_msg_data => x_msg_data);
4460 IF x_return_status <> l_g_ret_sts_success THEN
4461 RAISE fnd_api.G_EXC_ERROR;
4462 END IF;
4463 END IF;
4464
4465 l_progress := 300;
4466 IF l_debug = 1 THEN mydebug('l_progress = ' || l_progress); END IF;
4467 proc_process_cancelled_MOLs (
4468 p_organization_id => p_organization_id
4469 ,p_user_id => p_user_id
4470 ,p_transaction_header_id => p_transaction_header_id
4471 ,p_transaction_temp_id => p_transaction_temp_id
4472 ,x_return_status => x_return_status
4473 ,x_msg_count => x_msg_count
4474 ,x_msg_data => x_msg_data);
4475 IF x_return_status <> l_g_ret_sts_success THEN
4476 mydebug('x_return_status : ' || x_return_status);
4477 RAISE fnd_api.G_EXC_ERROR;
4478 END IF;
4479
4480 IF P_ACTION is not NULL AND p_action = 'CMS' THEN
4481 COMMIT;
4482 RETURN;
4483 END IF;
4484
4485 -- Reset Lpn context of content_lpn_ids and transfer_lpn_ids
4486 l_progress := 400;
4487 IF l_debug = 1 THEN mydebug('l_progress = ' || l_progress); END IF;
4488 IF P_ACTION is NULL OR p_action <> 'CMS' THEN
4489 proc_reset_lpn_context(
4490 p_organization_id => p_organization_id
4491 ,p_user_id => p_user_id
4492 ,p_transaction_header_id => p_transaction_header_id
4493 ,p_transaction_temp_id => p_transaction_temp_id
4494 ,x_return_status => x_return_status
4495 ,x_msg_count => x_msg_count
4496 ,x_msg_data => x_msg_data);
4497 IF x_return_status <> l_g_ret_sts_success THEN
4498 RAISE fnd_api.G_EXC_ERROR;
4499 END IF;
4500 END IF;
4501
4502 -- Group MMTTs(including p_transaction_temp_id) with p_transaction_header_id
4503 -- by inventory_item_id,subinventory_code,locator_id.
4504 -- update one of the MMTTs(min temp_id) from each group and delete rest from that group
4505 l_progress := 500;
4506 IF l_debug = 1 THEN mydebug('l_progress = ' || l_progress); END IF;
4507
4508 DELETE mtl_allocations_gtmp ;
4509 IF SQL%NOTFOUND THEN
4510 null;
4511 END IF;
4512
4513 IF P_ACTION is NULL OR p_action <> 'CMS' THEN
4514 FOR rec_mmtt1 IN cur_mmtt1
4515 LOOP
4516 l_progress := 510;
4517 mydebug('l_progress = ' || l_progress);
4518 mydebug('l_original_sub_loc = ' || l_original_sub_loc);
4519 mydebug('rec_mmtt1.mmtt_group_count = ' || rec_mmtt1.mmtt_group_count);
4520 mydebug('rec_mmtt1.group_temp_id = ' || rec_mmtt1.group_temp_id);
4521 mydebug('rec_mmtt1.subinventory_code = ' || rec_mmtt1.subinventory_code);
4522 mydebug('rec_mmtt1.locator_id = ' || rec_mmtt1.locator_id);
4523 mydebug('rec_mmtt1.item_primary_uom_code = ' || rec_mmtt1.item_primary_uom_code);
4524 mydebug('rec_mmtt1.mmtt_primary_quantity = ' || rec_mmtt1.mmtt_primary_quantity);
4525 mydebug('rec_mmtt1.mmtt_secondary_transaction_quantity = ' || rec_mmtt1.mmtt_secondary_quantity);
4526
4527 IF rec_mmtt1.item_primary_uom_code IS NULL THEN
4528 fnd_message.set_name('WMS', 'WMS_NULL_PRIM_UOM');
4529 -- Item primary UOM is null for this task
4530 fnd_msg_pub.ADD;
4531 RAISE fnd_api.g_exc_unexpected_error;
4532 END IF;
4533 -- this global temp table will have a list of transaction_temp_ids of MMTTs that
4534 -- are confirmed to stay back in MMTT. Later we will use this list to decide on which
4535 -- MMTTs should be deleted that belong to the p_transaction-header_id but are not
4536 -- in this list
4537 l_progress := 600;
4538 INSERT
4539 INTO mtl_allocations_gtmp
4540 (transaction_temp_id)
4541 VALUES ( rec_mmtt1.group_temp_id);
4542 mydebug('Inserted temp_id into mtl_allocations_gtmp: ' || rec_mmtt1.group_temp_id);
4543
4544 IF p_suggested_uom <> rec_mmtt1.item_primary_uom_code
4545 THEN
4546 l_suggested_mmtt_qty := inv_convert.inv_um_convert
4547 (item_id => rec_mmtt1.inventory_item_id
4548 ,precision => l_g_decimal_precision
4549 ,from_quantity => rec_mmtt1.mmtt_primary_quantity
4550 ,from_unit => rec_mmtt1.item_primary_uom_code
4551 ,to_unit => p_suggested_uom
4552 ,from_name => NULL
4553 ,to_name => NULL);
4554 ELSE
4555 l_suggested_mmtt_qty := rec_mmtt1.mmtt_primary_quantity;
4556 END IF;
4557 l_suggested_mmtt_sec_qty := rec_mmtt1.mmtt_secondary_quantity;
4558 mydebug('l_suggested_mmtt_qty : ' || l_suggested_mmtt_qty );
4559 mydebug('l_suggested_mmtt_sec_qty : ' || l_suggested_mmtt_sec_qty );
4560 l_progress := 650;
4561
4562 -- Bug#4185621: decide whether to update posting flag
4563 IF (rec_mmtt1.parent_line_id = rec_mmtt1.group_temp_id) THEN
4564 l_parent_posting_flag := 'N'; -- bulk parent, need to update posting flag back to 'N'
4565 ELSE
4566 l_parent_posting_flag := 'Y'; -- non bulk mmtt, keep posting flag as 'Y'
4567 END IF;
4568 -- Bug# 4185621: end change
4569
4570 /* Update the MMTT record with transacttion-temp_id = group_temp_id.
4571 Updating transaction_quantity same as primary_quantity since
4572 the transaction_qty should be IN same uom AS primary qty FOR this mmtt */
4573 UPDATE mtl_material_transactions_temp
4574 SET primary_quantity = rec_mmtt1.mmtt_primary_quantity
4575 , transaction_quantity = l_suggested_mmtt_qty
4576 , secondary_transaction_quantity = DECODE(secondary_transaction_quantity, NULL, NULL, l_suggested_mmtt_sec_qty)
4577 , transaction_uom = p_suggested_uom
4578 , transfer_lpn_id = NULL
4579 , lpn_id = NULL
4580 , content_lpn_id = NULL
4581 , last_update_date = SYSDATE
4582 , last_updated_by = p_user_id
4583 , wms_task_status = l_g_task_pending -- Bug4185621: update mmtt task status back to pending
4584 , posting_flag = l_parent_posting_flag -- Bug4185621: updating posting flag
4585 WHERE transaction_temp_id = rec_mmtt1.group_temp_id;
4586 IF SQL%NOTFOUND THEN
4587 RAISE fnd_api.G_EXC_ERROR;
4588 END IF;
4589
4590 -- Bug# 4185621: update child line posting flag back to 'Y' for bulk picking
4591 IF (l_parent_posting_flag = 'N') THEN
4592 UPDATE mtl_material_transactions_temp mmtt
4593 SET posting_flag = 'Y'
4594 WHERE parent_line_id = rec_mmtt1.group_temp_id
4595 AND parent_line_id <> transaction_temp_id;
4596 END IF;
4597 -- Bug# 4185621: end change
4598
4599 l_progress := 700;
4600 mydebug('l_progress .. ' || l_progress);
4601
4602 -- PROCESS LOTS /SERIALS BEFORE DELETING ..... *****
4603 -- Only if the present cursor group has more than one row
4604 -- that it is necessary to take care of lots and serial
4605 -- IF (rec_mmtt1.mmtt_group_count > 1) THEN : for serials not allocated. It has to be processed
4606 IF ((p_lot_controlled = 'Y' AND p_serial_controlled = 'Y')
4607 OR (p_lot_controlled = 'Y' AND p_serial_controlled <> 'Y'))
4608
4609 THEN
4610 l_progress := 800;
4611 mydebug('l_progress .. ' || l_progress);
4612
4613 --IF (rec_mmtt1.mmtt_group_count > 1)
4614 --OR
4615 --(rec_mmtt1.mmtt_group_count = 1 AND
4616 --p_serial_controlled = 'Y' and p_serial_allocated_flag = 'N')
4617 --THEN
4618 FOR rec_mtlt1 IN cur_mtlt1 (rec_mmtt1.subinventory_code
4619 , rec_mmtt1.locator_id
4620 , rec_mmtt1.item_primary_uom_code
4621 , rec_mmtt1.inventory_item_id
4622 , rec_mmtt1.revision
4623 , rec_mmtt1.group_temp_id)
4624 LOOP
4625 l_progress := 1000;
4626 mydebug('l_progress .. ' || l_progress);
4627 mydebug('rec_mtlt1.lot_number : ' || rec_mtlt1.lot_number);
4628 mydebug('rec_mtlt1.group_lot_primary_quantity : ' || rec_mtlt1.group_lot_primary_quantity);
4629 mydebug('rec_mtlt1.group_lot_secondary_quantity : ' || rec_mtlt1.group_lot_secondary_quantity);
4630 mydebug('rec_mtlt1.group_lot_count : ' || rec_mtlt1.group_lot_count);
4631 mydebug('rec_mtlt1.group_lot_temp_id : ' || rec_mtlt1.group_lot_temp_id);
4632 mydebug('rec_mtlt1.group_lot_primary_quantity : ' || rec_mtlt1.group_lot_primary_quantity);
4633
4634 l_serial_transaction_temp_id := NULL;
4635 SELECT mtl_material_transactions_s.NEXTVAL
4636 INTO l_serial_transaction_temp_id
4637 FROM DUAL;
4638 mydebug('l_serial_transaction_temp_id .. ' || l_serial_transaction_temp_id);
4639 IF p_suggested_uom <> rec_mmtt1.item_primary_uom_code
4640 THEN
4641 l_suggested_mtlt_qty := inv_convert.inv_um_convert
4642 (item_id => rec_mmtt1.inventory_item_id
4643 ,precision => l_g_decimal_precision
4644 ,from_quantity => rec_mtlt1.group_lot_primary_quantity
4645 ,from_unit => rec_mmtt1.item_primary_uom_code
4646 ,to_unit => p_suggested_uom
4647 ,from_name => NULL
4648 ,to_name => NULL);
4649 ELSE
4650 l_suggested_mtlt_qty := rec_mtlt1.group_lot_primary_quantity;
4651 END IF;
4652 l_suggested_mtlt_sec_qty := rec_mtlt1.group_lot_secondary_quantity;
4653 mydebug('l_suggested_mtlt_qty : ' || l_suggested_mtlt_qty);
4654 mydebug('l_suggested_mtlt_sec_qty : ' || l_suggested_mtlt_sec_qty);
4655
4656 IF p_serial_controlled = 'Y' THEN
4657 IF p_serial_allocated_flag = 'Y' THEN
4658
4659 l_progress := 1100;
4660 mydebug('l_progress .. ' || l_progress);
4661 UPDATE mtl_serial_numbers_temp
4662 SET transaction_temp_id = l_serial_transaction_temp_id
4663 , last_update_date = SYSDATE
4664 , last_updated_by = p_user_id
4665 WHERE transaction_temp_id IN
4666 (SELECT mtlt.serial_transaction_temp_id
4667 FROM mtl_transaction_lots_temp mtlt
4668 , mtl_material_transactions_temp mmtt
4669 WHERE mmtt.transaction_header_id = p_transaction_header_id
4670 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
4671 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4672 AND mmtt.locator_id = rec_mmtt1.locator_id
4673 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4674 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4675 AND mtlt.lot_number = rec_mtlt1.lot_number
4676 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4677 mydebug ('ROW COUNT : ' || sql%rowcount);
4678 IF SQL%NOTFOUND THEN
4679 RAISE fnd_api.G_EXC_ERROR;
4680 END IF;
4681 l_progress := 1200;
4682 mydebug('l_progress .. ' || l_progress);
4683 UPDATE MTL_SERIAL_NUMBERS
4684 SET group_mark_id = l_serial_transaction_temp_id
4685 , last_updated_by = p_user_id
4686 , last_update_date = SYSDATE
4687 WHERE current_organization_id = p_organization_id
4688 AND inventory_item_id = rec_mmtt1.inventory_item_id
4689 AND serial_number IN
4690 (SELECT fm_serial_number
4691 FROM mtl_serial_numbers_temp msnt
4692 WHERE msnt.transaction_temp_id = l_serial_transaction_temp_id);
4693
4694 IF SQL%NOTFOUND THEN
4695 RAISE fnd_api.G_EXC_ERROR;
4696 END IF;
4697 ELSE --IF p_serial_allocated_flag = 'N' THEN
4698 l_progress := 1300;
4699 mydebug('l_progress .. ' || l_progress);
4700 -- First unmark serials in all MSNTS
4701 UPDATE MTL_SERIAL_NUMBERS
4702 SET group_mark_id = NULL
4703 , last_updated_by = p_user_id
4704 , last_update_date = SYSDATE
4705 WHERE (current_organization_id
4706 ,inventory_item_id
4707 ,serial_number)
4708 IN (SELECT mmtt.organization_id
4709 ,mmtt.inventory_item_id
4710 ,msnt.fm_serial_number
4711 FROM mtl_transaction_lots_temp mtlt
4712 ,mtl_serial_numbers_temp msnt
4713 ,mtl_material_transactions_temp mmtt
4714 WHERE mmtt.transaction_header_id = p_transaction_header_id
4715 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
4716 AND mtlt.serial_transaction_temp_id = msnt.transaction_temp_id
4717 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4718 AND mmtt.locator_id = rec_mmtt1.locator_id
4719 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4720 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4721 AND mtlt.lot_number = rec_mtlt1.lot_number
4722 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4723
4724 IF SQL%NOTFOUND THEN
4725 mydebug('No MSNT found ..may be because no serials were confirmed for ' ||
4726 'serial_allocation= No before pressing F2' );
4727 ELSE
4728 -- Now delete MSNTs
4729 l_progress := 1400;
4730 mydebug('l_progress .. ' || l_progress);
4731 DELETE mtl_serial_numbers_temp
4732 WHERE transaction_temp_id
4733 IN
4734 (SELECT mtlt.serial_transaction_temp_id
4735 FROM mtl_transaction_lots_temp mtlt
4736 , mtl_material_transactions_temp mmtt
4737 WHERE mmtt.transaction_header_id = p_transaction_header_id
4738 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
4739 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4740 AND mmtt.locator_id = rec_mmtt1.locator_id
4741 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4742 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4743 AND mtlt.lot_number = rec_mtlt1.lot_number
4744 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4745 IF SQL%NOTFOUND THEN
4746 RAISE fnd_api.G_EXC_ERROR;
4747 END IF;
4748 END IF;
4749 END IF; --IF p_serial_allocated_flag = 'N' THEN
4750 l_op_msnt_to_delete := 0;
4751 IF p_serial_allocated_flag = 'Y' THEN -- to delete all overpicked serials
4752 l_progress := 4000;
4753 mydebug('l_progress : ' || l_progress);
4754 SELECT count(*)
4755 INTO l_op_msnt_to_delete
4756 FROM mtl_serial_numbers_temp msnt
4757 WHERE msnt.transaction_temp_id = l_serial_transaction_temp_id;
4758 mydebug('l_op_msnt_to_delete : ' || l_op_msnt_to_delete
4759 || ':' || rec_mtlt1.group_lot_primary_quantity);
4760
4761 -- only if the rec-count in msnt exceeds the total quantity in MMTT
4762 -- means the serials have been overpicked.
4763 IF rec_mtlt1.group_lot_primary_quantity < l_op_msnt_to_delete
4764 THEN
4765 FOR rec_msnt_to_delete_LS IN cur_msnt_to_delete_LS
4766 ( l_serial_transaction_temp_id)
4767 LOOP
4768 mydebug('rec_msnt_to_delete_ls.fm_serial_number : ' || rec_msnt_to_delete_ls.fm_serial_number);
4769 mydebug('rec_msnt_to_delete_ls.transaction_temp_id : ' || rec_msnt_to_delete_ls.transaction_temp_id);
4770 /* In this cursor, we are ordering by creation date with the
4771 * assumption that the overpicked serials are newly inserted MSNT records and
4772 * they will have creation date higher than the originally allocated serials. */
4773 IF l_op_msnt_to_delete <= rec_mtlt1.group_lot_primary_quantity
4774 THEN
4775 mydebug('l_op_msnt_to_delete : ' || l_op_msnt_to_delete);
4776 EXIT; -- we want to process only overpicked records
4777 ELSE
4778 l_op_msnt_to_delete := l_op_msnt_to_delete - 1;
4779 mydebug('l_op_msnt_to_delete : ' || l_op_msnt_to_delete);
4780 END IF;
4781
4782 l_progress := 4300;
4783 mydebug('l_progress : ' || l_progress);
4784 UPDATE MTL_SERIAL_NUMBERS
4785 SET group_mark_id = NULL
4786 ,last_updated_by = p_user_id
4787 ,last_update_date = SYSDATE
4788 WHERE current_organization_id = p_organization_id
4789 AND inventory_item_id = rec_mmtt1.inventory_item_id
4790 AND serial_number = rec_msnt_to_delete_ls.fm_serial_number;
4791 IF SQL%NOTFOUND THEN
4792 mydebug('No MSN found to be updated..not good' );
4793 RAISE fnd_api.G_EXC_ERROR;
4794 ELSE
4795 l_progress := 4400;
4796 mydebug('l_progress : ' || l_progress);
4797 DELETE mtl_serial_numbers_temp
4798 WHERE transaction_temp_id = rec_msnt_to_delete_ls.transaction_temp_id
4799 AND fm_serial_number = rec_msnt_to_delete_ls.fm_serial_number;
4800
4801 IF SQL%NOTFOUND THEN
4802 RAISE fnd_api.G_EXC_ERROR;
4803 END IF;
4804 END IF;
4805 END LOOP;
4806 END IF;
4807 END IF; -- serial_allocated_flag = Y and delete overpicked serials
4808 END IF; -- p_serial_controlled = 'Y'
4809
4810 /* even if the # of records in MTLT for this lot is 1, it has to be updated
4811 with serial-transaction-temp_id and user_id, sysdate.
4812 So, there is no harm is updating qty too */
4813 l_progress := 1500;
4814 mydebug('l_progress .. ' || l_progress);
4815 UPDATE MTL_transaction_lots_temp mtlt
4816 SET transaction_temp_id = rec_mmtt1.group_temp_id
4817 , primary_quantity = rec_mtlt1.group_lot_primary_quantity
4818 , transaction_quantity = l_suggested_mtlt_qty
4819 , secondary_quantity = decode (secondary_quantity, null, null, l_suggested_mtlt_sec_qty)
4820 , mtlt.serial_transaction_temp_id = l_serial_transaction_temp_id
4821 , last_update_date = SYSDATE
4822 , last_updated_by = p_user_id
4823 WHERE lot_number = rec_mtlt1.lot_number
4824 AND transaction_temp_id = rec_mtlt1.group_lot_temp_id;
4825 IF SQL%NOTFOUND THEN
4826 RAISE fnd_api.G_EXC_ERROR;
4827 END IF;
4828
4829 l_progress := 1600;
4830 mydebug('l_progress .. ' || l_progress);
4831 IF rec_mtlt1.group_lot_count > 1 THEN
4832 l_progress := 230;
4833 mydebug('l_progress .. ' || l_progress);
4834 DELETE mtl_transaction_lots_temp
4835 WHERE lot_number = rec_mtlt1.lot_number
4836 AND transaction_temp_id
4837 IN
4838 (SELECT mtlt.transaction_temp_id
4839 FROM mtl_material_transactions_temp mmtt
4840 ,mtl_transaction_lots_temp mtlt
4841 WHERE mmtt.transaction_header_id = p_transaction_header_id
4842 AND mmtt.transaction_temp_id <> rec_mtlt1.group_lot_temp_id
4843 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
4844 AND mtlt.lot_number = rec_mtlt1.lot_number
4845 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4846 AND mmtt.locator_id = rec_mmtt1.locator_id
4847 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4848 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4849 AND mtlt.lot_number = rec_mtlt1.lot_number
4850 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4851
4852 IF SQL%NOTFOUND THEN
4853 RAISE fnd_api.G_EXC_ERROR;
4854 END IF;
4855 END IF;
4856 END LOOP;
4857
4858 --END IF; -- rec_mmtt1.rec_count > 1 OR
4859 -- (rec_mmtt1.mmtt_group_count = 1 AND
4860 -- p_serial_controlled = 'Y' and p_serial_allocated_flag = 'N')
4861 END IF; --lot controlled or lot +serial controlled
4862 l_progress := 1700;
4863 mydebug('l_progress : ' || l_progress);
4864
4865 -- Serial Controlled items
4866 IF (p_lot_controlled <> 'Y' AND p_serial_controlled = 'Y') THEN
4867 -- serial
4868 l_progress := 1800;
4869 mydebug('l_progress : ' || l_progress);
4870 IF (p_serial_allocated_flag = 'Y') THEN
4871 IF rec_mmtt1.mmtt_group_count > 1 THEN
4872 -- Now update MSNT
4873 l_progress := 1900;
4874 mydebug('l_progress : ' || l_progress);
4875
4876 UPDATE mtl_serial_numbers_temp
4877 SET transaction_temp_id = rec_mmtt1.group_temp_id
4878 , last_update_date = SYSDATE
4879 , last_updated_by = p_user_id
4880 WHERE transaction_temp_id
4881 IN
4882 (SELECT msnt.transaction_temp_id
4883 FROM mtl_serial_numbers_temp msnt,
4884 mtl_material_transactions_temp mmtt
4885 WHERE mmtt.transaction_header_id = p_transaction_header_id
4886 AND mmtt.transaction_temp_id <> rec_mmtt1.group_temp_id
4887 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
4888 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4889 AND mmtt.locator_id = rec_mmtt1.locator_id
4890 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4891 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4892 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4893
4894 IF SQL%NOTFOUND THEN
4895 RAISE fnd_api.G_EXC_ERROR;
4896 END IF;
4897 -- REMARK MSN with new temp_id
4898
4899 l_progress := 2000;
4900 mydebug('l_progress : ' || l_progress);
4901 UPDATE MTL_SERIAL_NUMBERS
4902 SET group_mark_id = rec_mmtt1.group_temp_id
4903 , last_updated_by = p_user_id
4904 , last_update_date = SYSDATE
4905 WHERE current_organization_id = p_organization_id
4906 AND inventory_item_id = rec_mmtt1.inventory_item_id
4907 AND serial_number
4908 IN
4909 (SELECT fm_serial_number
4910 FROM mtl_serial_numbers_temp
4911 WHERE transaction_temp_id = rec_mmtt1.group_temp_id);
4912 --l_serial_transaction_temp_id);
4913
4914 IF SQL%NOTFOUND THEN
4915 RAISE fnd_api.G_EXC_ERROR;
4916 END IF;
4917 END IF;
4918 ELSE -- (p_serial_allocated_flag = 'N' ,
4919 -- delete all msnts and unmark all these serials in MSN.
4920 l_progress := 2100;
4921 mydebug('l_progress : ' || l_progress);
4922 UPDATE MTL_SERIAL_NUMBERS
4923 SET group_mark_id = NULL
4924 , last_updated_by = p_user_id
4925 , last_update_date = SYSDATE
4926 WHERE (current_organization_id
4927 ,inventory_item_id
4928 ,serial_number)
4929 IN (SELECT mmtt.organization_id
4930 ,mmtt.inventory_item_id
4931 ,msnt.fm_serial_number
4932 FROM mtl_serial_numbers_temp msnt
4933 ,mtl_material_transactions_temp mmtt
4934 WHERE mmtt.transaction_header_id = p_transaction_header_id
4935 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
4936 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4937 AND mmtt.locator_id = rec_mmtt1.locator_id
4938 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4939 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4940 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4941
4942 IF SQL%NOTFOUND THEN
4943 mydebug('No MSNT found ..may be because no serials were confirmed for ' ||
4944 'serial_allocation= No before pressing F2' );
4945 ELSE
4946 l_progress := 2200;
4947 mydebug('l_progress : ' || l_progress);
4948
4949 DELETE mtl_serial_numbers_temp
4950 WHERE transaction_temp_id IN
4951 (SELECT msnt.transaction_temp_id
4952 FROM mtl_serial_numbers_temp msnt,
4953 mtl_material_transactions_temp mmtt
4954 WHERE mmtt.transaction_header_id = p_transaction_header_id
4955 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
4956 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4957 AND mmtt.locator_id = rec_mmtt1.locator_id
4958 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4959 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4960 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@') );
4961
4962 IF SQL%NOTFOUND THEN
4963 RAISE fnd_api.G_EXC_ERROR;
4964 END IF;
4965 END IF;
4966 END IF;
4967 l_op_msnt_to_delete := 0;
4968 IF p_serial_allocated_flag = 'Y' THEN -- to delete all overpicked serials
4969 l_progress := 3000;
4970 mydebug('l_progress : ' || l_progress);
4971 SELECT count(*)
4972 INTO l_op_msnt_to_delete
4973 FROM mtl_serial_numbers_temp
4974 WHERE (transaction_temp_id ,
4975 fm_serial_number)
4976 IN
4977 (SELECT msnt.transaction_temp_id
4978 ,msnt.fm_serial_number
4979 FROM mtl_serial_numbers_temp msnt
4980 ,mtl_material_transactions_temp mmtt
4981 WHERE mmtt.transaction_header_id = p_transaction_header_id
4982 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
4983 AND mmtt.subinventory_code = rec_mmtt1.subinventory_code
4984 AND mmtt.locator_id = rec_mmtt1.locator_id
4985 AND mmtt.item_primary_uom_code = rec_mmtt1.item_primary_uom_code
4986 AND mmtt.inventory_item_id = rec_mmtt1.inventory_item_id
4987 AND nvl(mmtt.revision,'@@') = nvl(rec_mmtt1.revision,'@@'));
4988 mydebug('l_op_msnt_to_delete : ' || l_op_msnt_to_delete);
4989
4990 -- only if the rec-count in msnt exceeds the total quantity in MMTT
4991 -- means the serials have been overpicked.
4992 IF rec_mmtt1.mmtt_primary_quantity < l_op_msnt_to_delete
4993 THEN
4994 FOR rec_msnt_to_delete IN cur_msnt_to_delete
4995 ( rec_mmtt1.subinventory_code
4996 ,rec_mmtt1.locator_id
4997 ,rec_mmtt1.item_primary_uom_code
4998 ,rec_mmtt1.inventory_item_id
4999 ,rec_mmtt1.revision )
5000 LOOP
5001 mydebug('rec_msnt_to_delete.fm_serial_number : ' || rec_msnt_to_delete.fm_serial_number);
5002 mydebug('rec_msnt_to_delete.transaction_temp_id : ' || rec_msnt_to_delete.transaction_temp_id);
5003 mydebug('rec_msnt_to_delete.organization_id : ' || rec_msnt_to_delete.organization_id);
5004 mydebug('rec_msnt_to_delete.inventory_item_id : ' || rec_msnt_to_delete.inventory_item_id);
5005 mydebug('rec_msnt_to_delete.creation_date : ' ||
5006 to_char(rec_msnt_to_delete.creation_date,'dd:mon-yyyy:hh24:mi:ss'));
5007
5008
5009 /* In this cursor, we are ordering by creation date with the
5010 * assumption that the overpicked serials are newly inserted MSNT records and
5011 * they will have creation date higher than the originally allocated serials. */
5012 IF l_op_msnt_to_delete <= rec_mmtt1.mmtt_primary_quantity
5013 THEN
5014 l_progress := 3200;
5015 mydebug('l_progress : ' || l_progress);
5016 EXIT; -- we want to process only overpicked records
5017 ELSE
5018 l_op_msnt_to_delete := l_op_msnt_to_delete - 1;
5019 mydebug('l_op_msnt_to_delete : ' || l_op_msnt_to_delete);
5020 END IF;
5021 l_progress := 3300;
5022 mydebug('l_progress : ' || l_progress);
5023 UPDATE MTL_SERIAL_NUMBERS
5024 SET group_mark_id = NULL
5025 ,last_updated_by = p_user_id
5026 ,last_update_date = SYSDATE
5027 WHERE current_organization_id = p_organization_id
5028 AND inventory_item_id = rec_mmtt1.inventory_item_id
5029 AND serial_number = rec_msnt_to_delete.fm_serial_number;
5030 IF SQL%NOTFOUND THEN
5031 mydebug('No MSN found to be updated..not good' );
5032 RAISE fnd_api.G_EXC_ERROR;
5033 ELSE
5034 l_progress := 2200;
5035 mydebug('l_progress : ' || l_progress);
5036 DELETE mtl_serial_numbers_temp
5037 WHERE transaction_temp_id = rec_msnt_to_delete.transaction_temp_id
5038 AND fm_serial_number = rec_msnt_to_delete.fm_serial_number;
5039
5040 IF SQL%NOTFOUND THEN
5041 RAISE fnd_api.G_EXC_ERROR;
5042 END IF;
5043 END IF;
5044 END LOOP;
5045 END IF;
5046 END IF;
5047 END IF; -- Serial only Controlled
5048 END LOOP; --cur_mmtt1 loop
5049 END IF; --Non CMS
5050 l_progress := 2300;
5051 mydebug('l_progress .. ' || l_progress);
5052
5053 /* {{viks for start_over we need to call proc_start_over to reset the task
5054 * status to dispatched and sequence transaction_temp_ids in pl/sql table from global temp tablei
5055 * as they are picked.
5056 * }}
5057 */
5058
5059
5060 IF p_start_over = 'Y' THEN
5061
5062 mydebug('viks start_over button pressed calling proc_start_over:');
5063 proc_start_over(p_transaction_header_id => p_transaction_header_id
5064 ,p_transaction_temp_id => p_transaction_temp_id
5065 ,p_user_id => p_user_id
5066 ,x_start_over_taskno => x_start_over_taskno
5067 ,x_return_status => x_return_status
5068 ,x_msg_count => x_msg_count
5069 ,x_msg_data => x_msg_data);
5070 IF x_return_status <> l_g_ret_sts_success THEN
5071 RAISE fnd_api.G_EXC_ERROR;
5072 ELSE
5073 l_start_over_task := x_start_over_taskno;
5074 END IF;
5075 mydebug('viks l_start_over_task return froom proc_start_over :' ||l_start_over_task);
5076 ELSE
5077 mydebug('viks start_over button not pressed :');
5078 --only when it is not start over case, the retain task will be used 431009
5079 wms_picking_pkg.g_start_over_tempid.DELETE;
5080 IF p_retain_task = 'Y' THEN --{ bug 4310093
5081 mydebug('change the task status to Dispatched if retain_task is Y');
5082 UPDATE wms_dispatched_tasks
5083 SET status = l_g_task_dispatched
5084 ,last_update_date = SYSDATE
5085 ,last_updated_by = p_user_id
5086 WHERE transaction_temp_id IN
5087 (SELECT transaction_temp_id
5088 FROM mtl_allocations_gtmp);
5089 mydebug('nullify certain columns for all the dispatched tasks for this user');
5090 UPDATE wms_dispatched_tasks
5091 SET device_invoked = null
5092 -- Following two statement are commnet for bug 4560814
5093 --task_method = NULL -- for cluster picking
5094 -- ,task_group_id = NULL
5095 ,last_update_date = SYSDATE
5096 ,last_updated_by = p_user_id
5097 WHERE person_id = p_employee_id
5098 AND status = l_g_task_dispatched;
5099
5100 END IF; --}
5101 mydebug('viks l_start_over_task return value no :' ||l_start_over_task);
5102
5103
5104
5105 END IF;
5106
5107 x_start_over_taskno := l_start_over_task;
5108 mydebug('viks l_start_over_task return final value :' ||l_start_over_task);
5109
5110
5111 -- this global temp table has a list of transaction_temp_ids of MMTTs that
5112 -- are confirmed to stay back in MMTT and WDT. Using this we will delete WDT and MMTT
5113
5114 DELETE wms_dispatched_tasks
5115 WHERE transaction_temp_id IN
5116 (SELECT transaction_temp_id
5117 FROM mtl_material_transactions_temp
5118 WHERE transaction_header_id = p_transaction_header_id
5119 AND transaction_temp_id NOT IN
5120 (SELECT transaction_temp_id
5121 FROM mtl_allocations_gtmp));
5122 IF SQL%NOTFOUND THEN
5123 mydebug('no extra WDTs to delete :' );
5124 NULL;
5125 END IF;
5126
5127 l_progress := 2400;
5128 mydebug('l_progress .. ' || l_progress);
5129 -- this global temp table has a list of transaction_temp_ids of MMTTs that
5130 -- are confirmed to stay back in MMTT and WDT. Using this we will delete WDT and MMTT
5131 /* {{ If start over is pressed wdd would be deleted .Lines need to stay in
5132 * status dispatched.
5133 * }}
5134 */
5135
5136 IF p_start_over ='N' and p_retain_task='N' THEN --bug 4310093
5137
5138 DELETE wms_dispatched_tasks
5139 WHERE transaction_temp_id IN
5140 (SELECT transaction_temp_id
5141 FROM mtl_allocations_gtmp)
5142 AND status <> l_g_task_queued;
5143 IF SQL%NOTFOUND THEN
5144 mydebug('no non queued WDTs to delete :' );
5145 NULL;
5146 END IF;
5147 END IF;
5148
5149 l_progress := 2500;
5150 mydebug('l_progress .. ' || l_progress);
5151 DELETE mtl_material_transactions_temp
5152 WHERE transaction_header_id = p_transaction_header_id
5153 AND transaction_temp_id NOT IN
5154 (SELECT transaction_temp_id
5155 FROM mtl_allocations_gtmp);
5156 IF SQL%NOTFOUND THEN
5157 mydebug('no extra MMTTs to delete :' );
5158 NULL;
5159 END IF;
5160
5161 mydebug('Commit ' );
5162 COMMIT;
5163 mydebug('End .. ' || l_proc_name);
5164 EXCEPTION
5165 WHEN fnd_api.g_exc_error THEN
5166 x_return_status := l_g_ret_sts_error;
5167 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
5168 -- Internal Error $ROUTINE
5169 fnd_message.set_token('ROUTINE', '- Process_f2 API' );
5170 fnd_msg_pub.ADD;
5171 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5172 mydebug('ROLLBACK ' );
5173 ROLLBACK ;
5174 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5175 mydebug('fnd_api.g_exc_error: ' || SQLERRM);
5176 WHEN fnd_api.g_exc_unexpected_error THEN
5177 x_return_status := fnd_api.g_ret_sts_unexp_error;
5178 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
5179 -- Internal Error $ROUTINE
5180 fnd_message.set_token('ROUTINE', '- Process_f2 API' );
5181 fnd_msg_pub.ADD;
5182 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5183 mydebug('ROLLBACK ' );
5184 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5185 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
5186 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
5187 ROLLBACK ;
5188 WHEN OTHERS THEN
5189 x_return_status := l_g_ret_sts_unexp_error;
5190 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
5191 -- Internal Error $ROUTINE
5192 fnd_message.set_token('ROUTINE', '- Process_f2 API' );
5193 fnd_msg_pub.ADD;
5194 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5195 mydebug('ROLLBACK ' );
5196 ROLLBACK ;
5197 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5198 mydebug('fnd_api.g_exc_error: ' || SQLERRM);
5199
5200
5201 END process_F2;
5202
5203
5204 PROCEDURE proc_device_call
5205 (p_action IN VARCHAR2
5206 ,p_employee_id IN NUMBER
5207 ,p_transaction_temp_id IN NUMBER
5208 ,x_return_status OUT NOCOPY VARCHAR2
5209 ,x_msg_count OUT NOCOPY NUMBER
5210 ,x_msg_data OUT NOCOPY VARCHAR2 )
5211 IS
5212 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5213 l_proc_name VARCHAR2(30) := 'PROC_DEVICE_CALL';
5214 l_progress VARCHAR2(30) := '100';
5215 l_dev_request_msg VARCHAR2(1000) := NULL;
5216
5217 -- select all tasks that belong to this employee
5218 CURSOR cur_wdt_for_emp IS
5219 SELECT transaction_temp_id
5220 , device_request_id
5221 FROM wms_dispatched_tasks
5222 WHERE person_id = p_employee_id
5223 AND ( status <= l_g_task_dispatched OR
5224 status = l_g_task_active) -- (<=3, OR 9 ) ;
5225 AND device_request_id IS NOT NULL;
5226
5227 -- select task that belong to this employee and p_transaction_temp_id
5228 CURSOR cur_wdt_for_temp_id IS
5229 SELECT transaction_temp_id
5230 , device_request_id
5231 FROM wms_dispatched_tasks
5232 WHERE person_id = p_employee_id
5233 AND transaction_temp_id = p_transaction_temp_id
5234 AND device_request_id IS NOT NULL;
5235
5236 BEGIN
5237 mydebug ('IN : ' || l_proc_name);
5238 mydebug ('p_action : ' || p_action);
5239 mydebug ('p_employee_id : ' || p_employee_id);
5240 x_return_status := fnd_api.g_ret_sts_success;
5241
5242 IF p_action is NULL OR p_action <> 'CMS' THEN
5243 For rec_wdt_for_emp IN cur_wdt_for_emp
5244 LOOP
5245 l_progress := '110';
5246 mydebug('transaction_temp_id : ' || rec_wdt_for_emp.transaction_temp_id );
5247 mydebug('device_request_id : ' || rec_wdt_for_emp.device_request_id );
5248 IF rec_wdt_for_emp.transaction_temp_id IS NOT NULL
5249 THEN
5250 wms_device_integration_pvt.device_request(
5251 p_bus_event => wms_device_integration_pvt.wms_be_task_cancel
5252 , p_call_ctx => 'U'
5253 , p_task_trx_id => rec_wdt_for_emp.transaction_temp_id
5254 , p_request_id => rec_wdt_for_emp.device_request_id
5255 , x_request_msg => l_dev_request_msg
5256 , x_return_status => x_return_status
5257 , x_msg_count => x_msg_count
5258 , x_msg_data => x_msg_data );
5259 IF x_return_status <> l_g_ret_sts_success THEN
5260 mydebug('x_return_status : ' || x_return_status);
5261 RAISE fnd_api.G_EXC_ERROR;
5262 END IF;
5263
5264 END IF;
5265 END LOOP;
5266 ELSE
5267 For rec_wdt_for_temp_id IN cur_wdt_for_temp_id
5268 LOOP
5269 l_progress := '210';
5270 mydebug('transaction_temp_id : ' || rec_wdt_for_temp_id.transaction_temp_id );
5271 mydebug('device_request_id : ' || rec_wdt_for_temp_id.device_request_id );
5272 IF rec_wdt_for_temp_id.transaction_temp_id IS NOT NULL
5273 THEN
5274 wms_device_integration_pvt.device_request(
5275 p_bus_event => wms_device_integration_pvt.wms_be_task_cancel
5276 , p_call_ctx => 'U'
5277 , p_task_trx_id => rec_wdt_for_temp_id.transaction_temp_id
5278 , p_request_id => rec_wdt_for_temp_id.device_request_id
5279 , x_request_msg => l_dev_request_msg
5280 , x_return_status => x_return_status
5281 , x_msg_count => x_msg_count
5282 , x_msg_data => x_msg_data );
5283 IF x_return_status <> l_g_ret_sts_success THEN
5284 mydebug('x_return_status : ' || x_return_status);
5285 RAISE fnd_api.G_EXC_ERROR;
5286 END IF;
5287
5288 END IF;
5289 END LOOP;
5290 END IF;
5291 mydebug ('END : ' || l_proc_name);
5292 EXCEPTION
5293 WHEN fnd_api.g_exc_error THEN
5294 x_return_status := l_g_ret_sts_error;
5295 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5296 mydebug('ROLLBACK ' );
5297 ROLLBACK ;
5298 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5299 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5300 WHEN fnd_api.g_exc_unexpected_error THEN
5301 x_return_status := fnd_api.g_ret_sts_unexp_error;
5302 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5303 mydebug('ROLLBACK ' );
5304 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5305 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
5306 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
5307 ROLLBACK ;
5308 WHEN OTHERS THEN
5309 x_return_status := l_g_ret_sts_unexp_error;
5310 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5311 mydebug('ROLLBACK ' );
5312 ROLLBACK ;
5313 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5314 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5315
5316 END proc_device_call ;
5317
5318 PROCEDURE proc_process_cancelled_MOLs (
5319 p_organization_id IN NUMBER
5320 ,p_user_id IN NUMBER
5321 ,p_transaction_header_id IN NUMBER
5322 ,p_transaction_temp_id IN NUMBER
5323 ,x_return_status OUT NOCOPY VARCHAR2
5324 ,x_msg_count OUT NOCOPY NUMBER
5325 ,x_msg_data OUT NOCOPY VARCHAR2)
5326 IS
5327 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5328 l_proc_name VARCHAR2(30) := 'PROC_PROCESS_CANCELLED_MOLs';
5329 l_progress VARCHAR2(30) := '100';
5330
5331 l_deleted_mmtt_qty NUMBER := 0;
5332 l_deleted_mmtt_sec_qty NUMBER := 0;
5333 l_mmtt_count NUMBER := 0;
5334 -- Select all MOLs that are cancelled , so that cancelled tasks can be reduced
5335 CURSOR cur_cancelled_MOLs IS
5336 SELECT mtrl.line_id
5337 , mtrl.uom_code
5338 FROM mtl_material_transactions_temp mmtt
5339 , mtl_txn_request_lines mtrl
5340 WHERE (mmtt.transaction_temp_id = p_transaction_temp_id
5341 -- shld add : and mmtt.mmtt.transaction_temp_id <> mmtt.parent_line_id
5342 OR mmtt.parent_line_id = p_transaction_temp_id)
5343 AND mtrl.line_id = mmtt.move_order_line_id
5344 AND mtrl.line_status = INV_GLOBALS.G_TO_STATUS_CANCEL_BY_SOURCE;
5345
5346 -- all mmtts for the given MOL
5347 -- this MMTT should not have any child records
5348 -- this MMTT should not have a task in WDT
5349 CURSOR c_mmtt_to_del (p_mo_line_id NUMBER )
5350 IS
5351 SELECT mmtt.transaction_temp_id
5352 , mmtt.inventory_item_id
5353 , mmtt.primary_quantity
5354 , mmtt.item_primary_uom_code
5355 , NVL(mmtt.secondary_transaction_quantity, 0) secondary_transaction_quantity
5356 FROM mtl_material_transactions_temp mmtt
5357 WHERE mmtt.move_order_line_id = p_mo_line_id
5358 AND NOT EXISTS(SELECT 1
5359 FROM mtl_material_transactions_temp t1
5360 WHERE t1.parent_line_id = mmtt.transaction_temp_id)
5361 AND NOT EXISTS(SELECT 1
5362 FROM wms_dispatched_tasks wdt
5363 WHERE wdt.transaction_temp_id = mmtt.transaction_temp_id);
5364
5365 BEGIN
5366 mydebug ('IN : ' || l_proc_name);
5367 x_return_status := fnd_api.g_ret_sts_success;
5368 FOR rec_cancelled_MOLs in cur_cancelled_MOLs
5369 LOOP
5370 IF (l_debug = 1) THEN mydebug('mo_line_id = ' || rec_cancelled_mols.line_id); END IF;
5371 l_deleted_mmtt_qty := 0;
5372 l_deleted_mmtt_sec_qty := 0;
5373
5374 FOR rec_mmtt_to_del IN c_mmtt_to_del (
5375 p_mo_line_id => rec_cancelled_MOLs.line_id)
5376 LOOP
5377 -- it adjusts the bulk parent too
5378 inv_trx_util_pub.delete_transaction(
5379 x_return_status => x_return_status
5380 , x_msg_data => x_msg_data
5381 , x_msg_count => x_msg_count
5382 , p_transaction_temp_id => rec_mmtt_to_del.transaction_temp_id);
5383 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5384 IF l_debug = 1 THEN
5385 mydebug('Not able to delete the Txn = ' || rec_mmtt_to_del.transaction_temp_id);
5386 END IF;
5387 RAISE fnd_api.g_exc_unexpected_error;
5388 END IF;
5389
5390 IF (rec_mmtt_to_del.item_primary_uom_code <> rec_cancelled_mols.uom_code)
5391 THEN
5392 l_deleted_mmtt_qty := l_deleted_mmtt_qty +
5393 INV_Convert.inv_um_convert
5394 ( item_id => rec_mmtt_to_del.inventory_item_id
5395 ,precision => 5
5396 ,from_quantity => rec_mmtt_to_del.primary_quantity
5397 ,from_unit => rec_mmtt_to_del.item_primary_uom_code
5398 ,to_unit => rec_cancelled_mols.uom_code
5399 ,from_name => NULL
5400 ,to_name => NULL);
5401
5402
5403 ELSE
5404 l_deleted_mmtt_qty := l_deleted_mmtt_qty + rec_mmtt_to_del.primary_quantity;
5405 END IF;
5406 l_deleted_mmtt_sec_qty := l_deleted_mmtt_sec_qty + rec_mmtt_to_del.secondary_transaction_quantity;
5407 END LOOP;
5408 -- all MMTTs for the given MOL, this MMTT should not have any child records
5409
5410 SELECT count(*)
5411 INTO l_mmtt_count
5412 FROM mtl_material_transactions_temp mmtt
5413 WHERE mmtt.move_order_line_id = rec_cancelled_mols.line_id
5414 AND NOT EXISTS ( SELECT 1
5415 FROM mtl_material_transactions_temp t1
5416 WHERE t1.parent_line_id = mmtt.transaction_temp_id);
5417
5418 UPDATE mtl_txn_request_lines
5419 SET quantity_detailed =(quantity_detailed - l_deleted_mmtt_qty)
5420 , SECONDARY_QUANTITY_DETAILED = (SECONDARY_QUANTITY_DETAILED - l_deleted_mmtt_sec_qty)
5421 , line_status = DECODE(l_mmtt_count, 0, INV_GLOBALS.G_TO_STATUS_CLOSED, line_status)
5422 , last_update_date = SYSDATE
5423 , last_updated_by = p_user_id
5424 WHERE line_id = rec_cancelled_mols.line_id;
5425 IF SQL%NOTFOUND THEN
5426 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR'); --NEWMSG
5427 -- Internal Error $ROUTINE
5428 fnd_message.set_token('ROUTINE', '-proc_process_cancelled_MOLs' );
5429 myDebug('Error updating MTRL in proc_process_cancelled_MOLs for line: ' || rec_cancelled_mols.line_id);
5430 fnd_msg_pub.ADD;
5431 END IF;
5432 END LOOP;
5433 mydebug('END = ' || l_proc_name );
5434 EXCEPTION
5435 WHEN fnd_api.g_exc_error THEN
5436 x_return_status := l_g_ret_sts_error;
5437 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5438 mydebug('ROLLBACK ' );
5439 ROLLBACK ;
5440 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5441 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5442 WHEN fnd_api.g_exc_unexpected_error THEN
5443 x_return_status := fnd_api.g_ret_sts_unexp_error;
5444 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5445 mydebug('ROLLBACK ' );
5446 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5447 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
5448 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
5449 ROLLBACK ;
5450 WHEN OTHERS THEN
5451 x_return_status := l_g_ret_sts_unexp_error;
5452 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5453 mydebug('ROLLBACK ' );
5454 ROLLBACK ;
5455 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5456 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5457
5458 END proc_process_cancelled_MOLs ;
5459
5460 PROCEDURE proc_reset_lpn_context(
5461 p_organization_id IN NUMBER
5462 ,p_user_id IN NUMBER
5463 ,p_transaction_header_id IN NUMBER
5464 ,p_transaction_temp_id IN NUMBER
5465 ,x_return_status OUT NOCOPY VARCHAR2
5466 ,x_msg_count OUT NOCOPY NUMBER
5467 ,x_msg_data OUT NOCOPY VARCHAR2)
5468 IS
5469 l_proc_name VARCHAR2(30) := 'PROC_RESET_LPN_CONTEXT';
5470 l_progress VARCHAR2(30) := '100';
5471 l_other_tasks NUMBER := 0;
5472 l_lpn_context_pregenerated CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_PREGENERATED;
5473 l_lpn_context_inv CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_INV;
5474 l_lpn_context_picked CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_PICKED;
5475 l_lpn_context_packing CONSTANT NUMBER := WMS_Container_PUB.LPN_CONTEXT_PACKING ;
5476
5477 CURSOR cur_from_lpns IS
5478 SELECT DISTINCT lpn_id
5479 FROM mtl_material_transactions_temp
5480 WHERE transaction_header_id = p_transaction_header_id
5481 AND lpn_id IS NOT NULL;
5482
5483 CURSOR cur_content_lpns IS
5484 SELECT DISTINCT content_lpn_id
5485 FROM mtl_material_transactions_temp
5486 WHERE transaction_header_id = p_transaction_header_id
5487 AND content_lpn_id IS NOT NULL;
5488
5489 --modified for bug 6642448
5490 CURSOR cur_transfer_lpns IS
5491 SELECT DISTINCT transfer_lpn_id
5492 FROM mtl_material_transactions_temp
5493 WHERE transaction_header_id = p_transaction_header_id
5494 AND nvl(content_lpn_id , nvl(lpn_id,-999)) <> transfer_lpn_id;
5495
5496 BEGIN
5497 x_return_status := fnd_api.g_ret_sts_success;
5498 mydebug ('IN : ' || l_proc_name);
5499 l_progress := 110;
5500 mydebug('l_progress = ' || l_progress);
5501 mydebug ('p_transaction_header_id : ' || p_transaction_header_id);
5502
5503 FOR rec_transfer_lpns IN cur_transfer_lpns
5504 LOOP
5505 l_other_tasks := 0;
5506 l_progress := 120;
5507 mydebug('rec_transfer_lpns.transfer_lpn_id = ' || rec_transfer_lpns.transfer_lpn_id);
5508 mydebug('l_progress = ' || l_progress);
5509 BEGIN
5510 SELECT 1
5511 INTO l_other_tasks
5512 FROM DUAL
5513 WHERE EXISTS(SELECT 1
5514 FROM mtl_material_transactions_temp
5515 WHERE transaction_header_id <> p_transaction_header_id
5516 AND transfer_lpn_id = rec_transfer_lpns.transfer_lpn_id);
5517 EXCEPTION
5518 WHEN NO_DATA_FOUND THEN
5519 l_other_tasks := 0;
5520 END ;
5521 IF l_other_tasks = 0 THEN
5522 l_progress := 130;
5523 mydebug('l_progress = ' || l_progress);
5524 -- Bug5659809: update last_update_date and last_update_by as well
5525 UPDATE wms_license_plate_numbers
5526 SET lpn_context = l_lpn_context_PREGENERATED
5527 , last_update_date = SYSDATE
5528 , last_updated_by = fnd_global.user_id
5529 WHERE lpn_id = rec_transfer_lpns.transfer_lpn_id
5530 AND lpn_context <> l_lpn_context_picked;
5531
5532 IF SQL%NOTFOUND THEN
5533 mydebug (rec_transfer_lpns.transfer_lpn_id || 'with context <> '
5534 || l_lpn_context_picked || ' Not found ');
5535 END IF;
5536 END IF;
5537 END LOOP;
5538 l_progress := 200;
5539 mydebug('l_progress = ' || l_progress);
5540 FOR rec_from_lpns IN cur_from_lpns
5541 LOOP
5542 l_progress := 220;
5543 mydebug('rec_from_lpns.lpn_id = ' || rec_from_lpns.lpn_id);
5544 mydebug('l_progress = ' || l_progress);
5545 -- we need to do this since mmtt.lpn_id can be a fully consumable lpn in
5546 -- case where xferLPN is enabled on pickload UI.
5547 -- Bug5659809: update last_update_date and last_update_by as well
5548 UPDATE wms_license_plate_numbers
5549 SET lpn_context = l_lpn_context_INV
5550 , last_update_date = SYSDATE
5551 , last_updated_by = fnd_global.user_id
5552 WHERE lpn_id = rec_from_lpns.lpn_id
5553 AND lpn_context = l_lpn_context_packing;
5554
5555 IF SQL%NOTFOUND THEN
5556 mydebug (rec_from_lpns.lpn_id || 'not found with context = packing ' );
5557 END IF;
5558 END LOOP;
5559 l_progress := 300;
5560 mydebug('l_progress = ' || l_progress);
5561 FOR rec_content_lpns IN cur_content_lpns
5562 LOOP
5563 l_other_tasks := 0;
5564 l_progress := 310;
5565 mydebug('rec_content_lpns.content_lpn_id = ' || rec_content_lpns.content_lpn_id);
5566 mydebug('l_progress = ' || l_progress);
5567 BEGIN
5568 SELECT 1
5569 INTO l_other_tasks
5570 FROM DUAL
5571 WHERE EXISTS(SELECT 1
5572 FROM mtl_material_transactions_temp
5573 WHERE transaction_header_id <> p_transaction_header_id
5574 AND content_lpn_id = rec_content_lpns.content_lpn_id);
5575 EXCEPTION
5576 WHEN NO_DATA_FOUND THEN
5577 l_other_tasks := 0;
5578 END ;
5579 IF l_other_tasks = 0 THEN
5580 l_progress := 320;
5581 mydebug('l_progress = ' || l_progress);
5582 -- Bug5659809: update last_update_date and last_update_by as well
5583 UPDATE wms_license_plate_numbers
5584 SET lpn_context = l_lpn_context_inv
5585 , last_update_date = SYSDATE
5586 , last_updated_by = fnd_global.user_id
5587 WHERE lpn_id = rec_content_lpns.content_lpn_id
5588 AND lpn_context <> l_lpn_context_picked;
5589
5590 IF SQL%NOTFOUND THEN
5591 mydebug (rec_content_lpns.content_lpn_id || 'with context <> '
5592 || l_lpn_context_picked || ' Not found ');
5593 END IF;
5594 END IF;
5595 END LOOP;
5596
5597 mydebug('END = ' || l_proc_name );
5598 EXCEPTION
5599 WHEN fnd_api.g_exc_error THEN
5600 x_return_status := l_g_ret_sts_error;
5601 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5602 mydebug('ROLLBACK ' );
5603 ROLLBACK ;
5604 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5605 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5606 WHEN fnd_api.g_exc_unexpected_error THEN
5607 x_return_status := fnd_api.g_ret_sts_unexp_error;
5608 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5609 mydebug('ROLLBACK ' );
5610 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5611 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
5612 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
5613 ROLLBACK ;
5614 WHEN OTHERS THEN
5615 x_return_status := l_g_ret_sts_unexp_error;
5616 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5617 mydebug('ROLLBACK ' );
5618 ROLLBACK ;
5619 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5620 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5621 END proc_reset_lpn_context;
5622
5623 PROCEDURE proc_reset_task_status(
5624 p_action IN VARCHAR2
5625 ,p_organization_id IN NUMBER
5626 ,p_user_id IN NUMBER
5627 ,p_employee_id IN NUMBER
5628 ,p_transaction_header_id IN NUMBER
5629 ,p_transaction_temp_id IN NUMBER
5630 ,x_return_status OUT NOCOPY VARCHAR2
5631 ,x_msg_count OUT NOCOPY NUMBER
5632 ,x_msg_data OUT NOCOPY VARCHAR2)
5633 IS
5634 l_proc_name VARCHAR2(30) := 'PROC_RESET_TASK_STATUS';
5635 l_progress VARCHAR2(30) := '100';
5636 l_other_tasks NUMBER := 0;
5637 l_prev_task_status NUMBER := 0;
5638
5639 CURSOR cur_reset_task_status IS
5640 SELECT transaction_temp_id
5641 ,task_id
5642 FROM wms_dispatched_tasks
5643 WHERE person_id = p_employee_id
5644 AND ( status = l_g_task_dispatched OR
5645 status = l_g_task_active); -- IN (3,9 ) ;
5646 BEGIN
5647 x_return_status := fnd_api.g_ret_sts_success;
5648 mydebug ('IN : ' || l_proc_name);
5649 mydebug ('p_action : ' || p_action);
5650 mydebug ('p_transaction_header_id : ' || p_transaction_header_id);
5651 mydebug ('p_transaction_temp_id : ' || p_transaction_temp_id );
5652 mydebug ('p_employee_id : ' || p_employee_id);
5653 l_progress := 110;
5654 mydebug('l_progress = ' || l_progress);
5655
5656 IF p_action = 'CMS' THEN
5657
5658 DELETE wms_dispatched_tasks
5659 WHERE transaction_temp_id IN
5660 (SELECT transaction_temp_id
5661 FROM mtl_material_transactions_temp
5662 WHERE transaction_header_id = p_transaction_header_id);
5663 IF SQL%NOTFOUND THEN
5664 mydebug('no WDTs to delete for this header:' );
5665 ELSE
5666 mydebug('WDTs deleted for this header:' );
5667 END IF;
5668 RETURN;
5669 END IF;
5670
5671 -- The idea is to delete all tasks belonging to the same header_id (as in case of splits)
5672 -- and also to delete all dscpatched and active tasks
5673 -- Decide to delete all tasks with status = dispatched (3 or Active 9).
5674 -- There is no need to check for a specific header_id . For F2, we anyway always
5675 -- delete all dispatched and active tasks
5676
5677 BEGIN
5678 l_prev_task_status := wms_picking_pkg.g_previous_task_status(p_transaction_temp_id);
5679 wms_picking_pkg.g_previous_task_status.delete(p_transaction_temp_id);
5680 EXCEPTION
5681 WHEN OTHERS THEN
5682 mydebug('wms_picking_pkg.g_previous_task_status(p_transaction_temp_id) : ' || p_transaction_temp_id
5683 || ' : not found' );
5684 l_prev_task_status := l_g_task_pending;
5685 END ;
5686
5687 l_progress := 110;
5688 mydebug('l_progress = ' || l_progress || ' Update status for all temp_ids in thie header_id');
5689 mydebug('l_prev_task_status = ' || l_prev_task_status || ' for p_transaction_temp_id: '
5690 || p_transaction_temp_id);
5691 /* this update is seperate because for a pick nmore case, there can be multiple temp_ids (MMTTs)
5692 for the given header id ...current task) */
5693 UPDATE wms_dispatched_tasks
5694 SET status = l_prev_task_status
5695 ,last_update_date = SYSDATE
5696 ,last_updated_by = p_user_id
5697 WHERE person_id = p_employee_id
5698 AND ( status = l_g_task_dispatched OR
5699 status = l_g_task_active) -- IN (3,9 ) ;
5700 AND transaction_temp_id in (SELECT transaction_temp_id
5701 FROM mtl_material_transactions_temp
5702 WHERE transaction_header_id = p_transaction_header_id);
5703
5704 IF SQL%NOTFOUND THEN
5705 mydebug('no WDT to update for this employee id for this header id with stat in ( 3,9) ' );
5706 END IF;
5707
5708 l_progress := 150;
5709 mydebug('l_progress = ' || l_progress || ' Update status of all other tasks in this group' );
5710 FOR rec_reset_task_status IN cur_reset_task_status
5711 LOOP
5712 BEGIN
5713 l_prev_task_status := wms_picking_pkg.g_previous_task_status(rec_reset_task_status.transaction_temp_id);
5714 wms_picking_pkg.g_previous_task_status.delete(rec_reset_task_status.transaction_temp_id);
5715 EXCEPTION
5716 WHEN OTHERS THEN
5717 mydebug('wms_picking_pkg.g_previous_task_status(transaction_temp_id) : '
5718 || rec_reset_task_status.transaction_temp_id || ' : not found' );
5719 l_prev_task_status := l_g_task_pending;
5720 END ;
5721 mydebug('l_prev_task_status = ' || l_prev_task_status || ' for transaction_temp_id: '
5722 || rec_reset_task_status.transaction_temp_id);
5723 UPDATE wms_dispatched_tasks
5724 SET status = l_prev_task_status
5725 ,last_update_date = SYSDATE
5726 ,last_updated_by = p_user_id
5727 WHERE task_id = rec_reset_task_status.task_id;
5728
5729 IF SQL%NOTFOUND THEN
5730 mydebug('task_id : ' || rec_reset_task_status.task_id || ' : not found to be updated');
5731 END IF;
5732
5733 END LOOP ;
5734
5735 l_progress := 200;
5736 mydebug('l_progress = ' || l_progress);
5737
5738 DELETE wms_dispatched_tasks
5739 WHERE person_id = p_employee_id
5740 AND (status = l_g_task_pending OR
5741 status = l_g_task_dispatched OR
5742 status = l_g_task_active) ; -- IN (3,9 ) ;
5743
5744 IF SQL%NOTFOUND THEN
5745 mydebug('no WDT with status 3,9,1 remaining to delete for this employee id ' );
5746 --It is OK not to find even one task to delete
5747 ELSE
5748 mydebug('Deleted all WDT with staus 3,9,1 for p_employee_id = ' || p_employee_id);
5749 END IF;
5750
5751 l_progress := 300;
5752 mydebug('l_progress = ' || l_progress);
5753 UPDATE wms_dispatched_tasks
5754 SET task_method = NULL -- for cluster picking
5755 WHERE person_id = p_employee_id
5756 AND status = l_g_task_queued;
5757
5758 IF SQL%NOTFOUND THEN
5759 mydebug('no WDT to update for this employee id to be updated for cluster picking case' );
5760 --It is OK not to find even one task to update
5761 END IF;
5762
5763 mydebug('END = ' || l_proc_name );
5764 EXCEPTION
5765 WHEN fnd_api.g_exc_error THEN
5766 x_return_status := l_g_ret_sts_error;
5767 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5768 mydebug('ROLLBACK ' );
5769 ROLLBACK ;
5770 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5771 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5772 WHEN fnd_api.g_exc_unexpected_error THEN
5773 x_return_status := fnd_api.g_ret_sts_unexp_error;
5774 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5775 mydebug('ROLLBACK ' );
5776 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5777 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
5778 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
5779 ROLLBACK ;
5780 WHEN OTHERS THEN
5781 x_return_status := l_g_ret_sts_unexp_error;
5782 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5783 mydebug('ROLLBACK ' );
5784 ROLLBACK ;
5785 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5786 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5787 END proc_reset_task_status;
5788
5789 --viks procedure proc_start_over
5790 /*{{
5791 * When startover button is pressed proc_start_over is called which would return
5792 * no of task to be processed
5793 *}}
5794 */
5795
5796
5797 PROCEDURE proc_start_over
5798 (p_transaction_header_id IN NUMBER
5799 ,p_transaction_temp_id IN NUMBER
5800 ,p_user_id IN NUMBER
5801 ,x_start_over_taskno OUT NOCOPY NUMBER
5802 ,x_return_status OUT NOCOPY VARCHAR2
5803 ,x_msg_count OUT NOCOPY NUMBER
5804 ,x_msg_data OUT NOCOPY VARCHAR2 )
5805
5806 IS
5807 l_proc_name VARCHAR2(30) := 'PROC_START_OVER';
5808 l_progress VARCHAR2(30) := '100';
5809 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5810 l_prev_task_status NUMBER :=0;
5811 l_last_index NUMBER := NULL;
5812 l_first_index NUMBER := NULL;
5813 l_existing_count NUMBER :=0;
5814 l_move_index_offset NUMBER :=0;
5815 new_mmtt_count NUMBER := 0;
5816 m_count NUMBER :=0;
5817 i NUMBER :=0;
5818 p NUMBER :=0;
5819 L NUMBER :=0;
5820
5821
5822 CURSOR tempid_cur (v_transaction_temp_id NUMBER) IS
5823 SELECT transaction_temp_id from mtl_allocations_gtmp
5824 WHERE transaction_temp_id <> v_transaction_temp_id
5825 ORDER BY transaction_temp_id;
5826
5827
5828 BEGIN
5829
5830 x_return_status := fnd_api.g_ret_sts_success;
5831 mydebug ('IN : ' || l_proc_name);
5832 mydebug ('p_transaction_header_id : ' || p_transaction_header_id);
5833 mydebug ('p_transaction_temp_id : ' || p_transaction_temp_id );
5834 l_progress := 110;
5835
5836 l_prev_task_status := wms_picking_pkg.g_previous_task_status(p_transaction_temp_id);
5837
5838 SELECT count(*) into new_mmtt_count from mtl_allocations_gtmp;
5839 mydebug('Total count in mtl_allocations_gtemp: ' || new_mmtt_count);
5840
5841 l_first_index := wms_picking_pkg.g_start_over_tempid.first;
5842 l_existing_count := wms_picking_pkg.g_start_over_tempid.count-1;
5843
5844 mydebug('l_first_index is : ' ||l_first_index);
5845 mydebug('l_existing_count is : ' || l_existing_count);
5846
5847 IF l_first_index IS NULL THEN
5848 l_first_index :=0 ;
5849 END IF;
5850
5851 --setting the sequence space
5852
5853 IF l_first_index >0 and new_mmtt_count >0 THEN
5854 l_move_index_offset := (new_mmtt_count+1) - l_first_index;
5855 mydebug('Inl_move_index_offset:'||l_move_index_offset);
5856 if (l_move_index_offset >0) then -- move forward
5857 for i in REVERSE l_first_index .. (l_first_index+l_existing_count) LOOP
5858 wms_picking_pkg.g_start_over_tempid(i+l_move_index_offset) := wms_picking_pkg.g_start_over_tempid(i);
5859 mydebug('In else index :' ||i);
5860 END LOOP;
5861
5862 elsif (l_move_index_offset <0) then -- move backward
5863 for i in l_first_index..l_first_index+l_existing_count LOOP
5864 wms_picking_pkg.g_start_over_tempid(i+l_move_index_offset) := wms_picking_pkg.g_start_over_tempid(i);
5865 wms_picking_pkg.g_start_over_tempid.DELETE(i);
5866 mydebug('In else if index offset is Neg:' ||wms_picking_pkg.g_start_over_tempid(i+l_move_index_offset));
5867 mydebug('In elseif index :' ||i);
5868 END LOOP;
5869 end if;
5870 END IF;
5871 mydebug('Cont of table :'||wms_picking_pkg.g_start_over_tempid.COUNT);
5872 -- insert temp id value into pl/sql table
5873
5874 p := 1;
5875 FOR tempid_rec IN tempid_cur(v_transaction_temp_id => p_transaction_temp_id)
5876 LOOP
5877 wms_picking_pkg.g_start_over_tempid(p) := tempid_rec.transaction_temp_id;
5878 mydebug('Temp ids in plsql :'||wms_picking_pkg.g_start_over_tempid(p)||'Index:'||p);
5879 wms_picking_pkg.g_previous_task_status(wms_picking_pkg.g_start_over_tempid(p)) :=l_prev_task_status;
5880 p := p +1;
5881 IF SQL%NOTFOUND THEN
5882 mydebug('transaction_temp_id not found only one temp_id present: ');
5883 p :=1;
5884 END IF;
5885
5886 END LOOP;
5887
5888 wms_picking_pkg.g_start_over_tempid(p):= p_transaction_temp_id;
5889 mydebug('Temp id sent last is :'||wms_picking_pkg.g_start_over_tempid(p) ||'Index is::'||p);
5890
5891 L:=0;
5892
5893 -- Updating wdd status and printing final values sent in pl/sql table
5894
5895 forall L in wms_picking_pkg.g_start_over_tempid.FIRST .. wms_picking_pkg.g_start_over_tempid.LAST
5896 UPDATE wms_dispatched_tasks
5897 SET status = l_g_task_dispatched
5898 ,last_update_date = SYSDATE
5899 ,last_updated_by = p_user_id
5900 WHERE transaction_temp_id = wms_picking_pkg.g_start_over_tempid(L);
5901 IF SQL%NOTFOUND THEN
5902 mydebug('transaction_temp_id : ' ||wms_picking_pkg.g_start_over_tempid(L) ||' : not found to be updated');
5903 END IF;
5904
5905 IF (l_debug = 1) THEN
5906 L :=0;
5907 FOR L IN wms_picking_pkg.g_start_over_tempid.FIRST .. wms_picking_pkg.g_start_over_tempid.LAST
5908 LOOP
5909 mydebug('values sent are :' || wms_picking_pkg.g_start_over_tempid(L) || 'value of L' ||L);
5910 IF SQL%NOTFOUND THEN
5911 mydebug('transaction_temp_id : ' ||wms_picking_pkg.g_start_over_tempid(L) ||' : not found to be updated');
5912 END IF;
5913 END LOOP;
5914 END IF;
5915
5916 x_start_over_taskno := wms_picking_pkg.g_start_over_tempid.count;
5917 mydebug('x_start_over_taskno in procedure start_over::'||x_start_over_taskno);
5918 mydebug('END = ' || l_proc_name );
5919 EXCEPTION
5920 WHEN fnd_api.g_exc_error THEN
5921 x_return_status := l_g_ret_sts_error;
5922 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5923 mydebug('ROLLBACK ' );
5924 ROLLBACK ;
5925 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5926 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5927 WHEN fnd_api.g_exc_unexpected_error THEN
5928 x_return_status := fnd_api.g_ret_sts_unexp_error;
5929 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5930 mydebug('ROLLBACK ' );
5931 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5932 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
5933 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
5934 ROLLBACK ;
5935 WHEN OTHERS THEN
5936 x_return_status := l_g_ret_sts_unexp_error;
5937 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5938 mydebug('ROLLBACK ' );
5939 ROLLBACK ;
5940 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
5941 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
5942
5943 END proc_start_over;
5944
5945
5946
5947 PROCEDURE proc_parse_lot_serial_catchwt
5948 (p_inventory_item_id IN NUMBER
5949 ,p_confirmed_lots IN VARCHAR2
5950 ,p_confirmed_lot_trx_qty IN VARCHAR2
5951 ,p_confirmed_serials IN VARCHAR2
5952 ,p_suggested_uom IN VARCHAR2
5953 ,p_confirmed_uom IN VARCHAR2
5954 ,p_primary_uom IN VARCHAR2
5955 ,p_confirmed_sec_uom IN VARCHAR2
5956 ,p_confirmed_sec_qty IN VARCHAR2
5957 ,x_return_status OUT NOCOPY VARCHAR2
5958 ,x_msg_count OUT NOCOPY NUMBER
5959 ,x_msg_data OUT NOCOPY VARCHAR2)
5960 IS
5961 l_proc_name VARCHAR2(30) := 'PROC_PARSE_LOT_SERIAL_CATCHWT';
5962 l_progress VARCHAR2(30) := '100';
5963 l_delimiter VARCHAR2(30) := ':';
5964 l_group_delimiter VARCHAR2(30) := ';';
5965 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
5966 l_lot_number VARCHAR2(80) := NULL;
5967 l_serial_number VARCHAR2(30) := NULL;
5968 l_group_serials VARCHAR2(4000) := NULL;
5969 l_lot_trx_qty NUMBER := NULL;
5970 l_lot_prim_qty NUMBER := NULL;
5971 l_lot_sugg_qty NUMBER := NULL;
5972 l_sec_qty NUMBER := NULL;
5973 -- To store a new number for each lot so that all serials for a lot will have the same number
5974 l_group_number NUMBER := 0;
5975 -- To parse lots
5976 m NUMBER := 1; -- position of delimiter
5977 n NUMBER := 1; -- Start position for substr or search for delimiter
5978 i NUMBER := 1; -- position of delimiter
5979 j NUMBER := 1; -- Start position for substr or search for delimiter
5980 -- To parse Serials
5981 x NUMBER := 1; -- position of delimiter
5982 y NUMBER := 1; -- Start position for substr or search for delimiter
5983 s NUMBER := 1; -- position of delimiter
5984 t NUMBER := 1; -- Start position for substr or search for delimiter
5985 -- To parse Secondary qty
5986 k NUMBER := 1; -- position of delimiter
5987 l NUMBER := 1; -- Start position for substr or search for delimiter
5988 l_number_format_mask VARCHAR2(30) := 'FM9999999999.99999999999999'; --Bug#6274290
5989
5990 BEGIN
5991 x_return_status := l_g_ret_sts_success;
5992 mydebug ('In :' || l_proc_name );
5993
5994 DELETE mtl_allocations_gtmp ;
5995 IF SQL%NOTFOUND THEN
5996 null;
5997 END IF;
5998
5999 WHILE (j <> 0 AND n <> 0)
6000 LOOP
6001 -- Parse P_confirmed_lots and p_confirmed_lot_trx_qty
6002 -- N is the delimiter position,
6003 -- M is the position from which to start looking for the first delimiter
6004 -- for string 'L001:L002:L003' M=1, N=5 for the first search .
6005 -- M=5+1=6, N=10 for the next search .
6006 -- M=10+1=11, N=0 for the next search because this is the last part of string.
6007 --serial_controlled ..p_confrimed_serials will have serials for a LOT delimited by :
6008 --AND serials for different lots delimited by ';'
6009 --Have serials for a lot in l_lot_serials string and parse it
6010
6011 l_progress := '110';
6012 n := INSTR(p_confirmed_lots,l_delimiter,m,1);
6013 j := INSTR(p_confirmed_lot_trx_qty,l_delimiter,i,1);
6014 l_group_number := l_group_number + 1;
6015
6016 mydebug ('m:' || m||':n:' || n || ':i:' || i||':j:'||j );
6017 IF n = 0 THEN -- Last part OF the string
6018 l_lot_number := substr(p_confirmed_lots,m,length(p_confirmed_lots));
6019 ELSE
6020 l_lot_number := substr(p_confirmed_lots,m,n-m) ;-- start at M get m-n chrs.
6021 m := n+1;
6022 END IF;
6023 mydebug ('l_lot_number:' || l_lot_number);
6024 -- Parse p_confirmed_lot_trx_qty
6025 IF j = 0 THEN -- Last part OF the string
6026 l_lot_trx_qty := to_number(substr(p_confirmed_lot_trx_qty,i,length(p_confirmed_lot_trx_qty)) ,l_number_format_mask ) ; --Bug#6274290.
6027 ELSE
6028 l_lot_trx_qty := to_number(substr(p_confirmed_lot_trx_qty,i,j-i), l_number_format_mask ) ;-- start at i till i-j position
6029 i := j+1;
6030 END IF;
6031
6032 mydebug ('m:' || m||':n:' || n || ':i:' || i||':j:'||j );
6033 mydebug ('l_lot_trx_qty:' || l_lot_trx_qty);
6034 IF p_primary_uom <> p_confirmed_uom
6035 THEN
6036 l_progress := '120';
6037 l_lot_prim_qty := inv_convert.inv_um_convert
6038 (item_id => p_inventory_item_id
6039 ,precision => l_g_decimal_precision
6040 ,from_quantity => l_lot_trx_qty
6041 ,from_unit => p_confirmed_uom
6042 ,to_unit => p_primary_uom
6043 ,from_name => NULL
6044 ,to_name => NULL);
6045 ELSE
6046 l_progress := '130';
6047 l_lot_prim_qty := l_lot_trx_qty;
6048 END IF;
6049
6050 l_progress := '140';
6051 mydebug ('l_lot_prim_qty:' || l_lot_prim_qty);
6052
6053 IF p_suggested_uom <> p_confirmed_uom
6054 THEN
6055 l_progress := '120';
6056 l_lot_sugg_qty := inv_convert.inv_um_convert
6057 (item_id => p_inventory_item_id
6058 ,precision => l_g_decimal_precision
6059 ,from_quantity => l_lot_trx_qty
6060 ,from_unit => p_confirmed_uom
6061 ,to_unit => p_suggested_uom
6062 ,from_name => NULL
6063 ,to_name => NULL);
6064 ELSE
6065 l_progress := '130';
6066 l_lot_sugg_qty := l_lot_trx_qty;
6067 END IF;
6068
6069 l_progress := '140';
6070 mydebug ('l_lot_sugg_qty:' || l_lot_sugg_qty);
6071
6072 IF (p_confirmed_sec_qty IS NOT NULL)
6073 AND
6074 (p_confirmed_lots IS NOT NULL)
6075 THEN
6076 -- Secondary qty is at lot level (MTLT) for lot and Lot+serial controlled item
6077 -- Secondary qty is at MMTT level for serial controlled item
6078 l := INSTR(p_confirmed_sec_qty,l_delimiter,k,1);
6079 l_group_number := l_group_number + 1;
6080
6081 mydebug ('k:' || k||':l:' || l );
6082 IF n = 0 THEN -- Last part OF the string
6083 l_sec_qty := to_number( substr(p_confirmed_sec_qty,k,length(p_confirmed_sec_qty)), l_number_format_mask ); --Bug#6274290.
6084 ELSE
6085 l_sec_qty := to_number( substr(p_confirmed_sec_qty,k,l-k),l_number_format_mask );-- start at k get k-l chrs.
6086 k := l+1;
6087 END IF;
6088 mydebug ('l_sec_qty:' || l_sec_qty);
6089
6090 END IF;
6091
6092 IF ( p_confirmed_serials IS NOT NULL)
6093 THEN
6094 -- Parse p_confirmed_serials
6095 -- Y is the delimiter position,
6096 -- X is the position from which to start looking for the first delimiter l_group_delimiter
6097 -- for string 'L001:L002:L003;L004:L001' X=1, Y=15 for the first search .
6098 -- X=15+1=16, Y=0 for the next search because this is the last part of string.
6099 l_group_serials := NULL;
6100 WHILE y <> 0 -- to substr the group
6101 LOOP
6102 y := instr(p_confirmed_serials, l_group_delimiter, x, 1);
6103 IF (y=0) then
6104 l_group_serials := substr(p_confirmed_serials,x,length(p_confirmed_serials));
6105 ELSE
6106 l_group_serials := substr(p_confirmed_serials,x,y-x);
6107 x := y+1;
6108 END IF;
6109
6110 s := 1;
6111 t := 1;
6112 WHILE (t <> 0)
6113 LOOP
6114 l_progress := '110';
6115 -- Parse l_group_serials
6116 -- T is the delimiter position,
6117 -- S is the position from which to start looking for the first delimiter
6118 -- for string 'L001:L002:L003' S=1, T=5 for the first search .
6119 -- S=5+1=6, T=10 for the next search .
6120 -- S=10+1=11, T=0 for the next search because this is the last part of string.
6121 t := nvl(INSTR(l_group_serials,l_delimiter,s,1),0);
6122 mydebug ('s:' || s||':t:' || t );
6123 IF t = 0 THEN -- Last part OF the string
6124 l_serial_number := substr(l_group_serials,s,length(l_group_serials));
6125 ELSE
6126 l_serial_number := substr(l_group_serials,s,t-s) ;-- start at M get s-t chrs.
6127 s := t+1;
6128 END IF;
6129 mydebug ('l_serial_number:' || l_serial_number);
6130 mydebug ('s:' || s||':t:' || t );
6131 INSERT
6132 INTO mtl_allocations_gtmp
6133 (transaction_temp_id
6134 , lot_number
6135 , serial_number
6136 , transaction_quantity
6137 , primary_quantity
6138 , suggested_quantity
6139 , secondary_quantity)
6140 VALUES (l_group_number
6141 , l_lot_number
6142 , l_serial_number
6143 , l_lot_trx_qty
6144 , l_lot_prim_qty
6145 , l_lot_sugg_qty
6146 , l_sec_qty );
6147 END LOOP;
6148 EXIT;
6149 END LOOP;
6150 ELSE
6151 INSERT
6152 INTO mtl_allocations_gtmp
6153 (transaction_temp_id
6154 , lot_number
6155 , serial_number
6156 , transaction_quantity
6157 , primary_quantity
6158 , suggested_quantity
6159 , secondary_quantity)
6160 VALUES (l_group_number
6161 , l_lot_number
6162 , NULL
6163 , l_lot_trx_qty
6164 , l_lot_prim_qty
6165 , l_lot_sugg_qty
6166 , l_sec_qty );
6167 END IF;
6168 END LOOP;
6169
6170 mydebug('END = ' || l_proc_name );
6171 EXCEPTION
6172 WHEN OTHERS THEN
6173 x_return_status := l_g_ret_sts_unexp_error;
6174 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6175 mydebug('ROLLBACK ' );
6176 ROLLBACK ;
6177 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
6178 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
6179
6180 END proc_parse_lot_serial_catchwt;
6181
6182
6183 PROCEDURE task_load(
6184 p_action IN VARCHAR2
6185 , p_organization_id IN NUMBER
6186 , p_user_id IN NUMBER
6187 , p_person_id IN NUMBER
6188 , p_transaction_header_id IN NUMBER
6189 , p_temp_id IN NUMBER
6190 , p_parent_line_id IN NUMBER -- For bulk parent
6191 , p_lpn_id IN NUMBER
6192 , p_content_lpn_id IN NUMBER
6193 , p_transfer_lpn_id IN NUMBER
6194 , p_confirmed_sub IN VARCHAR2
6195 , p_confirmed_loc_id IN NUMBER
6196 , p_confirmed_uom IN VARCHAR2
6197 , p_suggested_uom IN VARCHAR2
6198 , p_primary_uom IN VARCHAR2
6199 , p_item_id IN NUMBER
6200 , p_revision IN VARCHAR2
6201 , p_confirmed_qty IN NUMBER
6202 , p_confirmed_lots IN VARCHAR2
6203 , p_confirmed_lot_trx_qty IN VARCHAR2
6204 , p_confirmed_sec_uom IN VARCHAR2
6205 , p_confirmed_sec_qty IN VARCHAR2
6206 , p_confirmed_serials IN VARCHAR2
6207 , p_container_item_id IN NUMBER
6208 , p_transaction_type_id IN NUMBER
6209 , p_transaction_source_type_id IN NUMBER
6210 , p_lpn_match IN NUMBER
6211 , p_lpn_match_lpn_id IN NUMBER
6212 , p_serial_allocated_flag IN VARCHAR2 -- Y/V or NULL
6213 , p_lot_controlled IN VARCHAR2 -- Y/N
6214 , p_serial_controlled IN VARCHAR2 -- Y/N
6215 , p_effective_start_date IN DATE
6216 , p_effective_end_date IN DATE
6217 , p_exception IN VARCHAR2 -- SHORT, OVER
6218 , p_discrepancies IN VARCHAR2
6219 , p_qty_rsn_id IN NUMBER
6220 , p_parent_lpn_id IN NUMBER
6221 , p_lpnpickedasis IN VARCHAR2 --Y/N
6222 , x_new_transaction_temp_id OUT NOCOPY NUMBER
6223 , x_cms_check OUT NOCOPY VARCHAR2
6224 , x_return_status OUT NOCOPY VARCHAR2
6225 , x_msg_count OUT NOCOPY NUMBER
6226 , x_msg_data OUT NOCOPY VARCHAR2
6227 )
6228 IS
6229 l_return_status VARCHAR2(1);
6230 l_msg_count NUMBER;
6231 l_msg_data VARCHAR2(4000);
6232 l_debug NUMBER:= NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6233 l_proc_name VARCHAR2(30) := 'TASK_LOAD';
6234 l_progress VARCHAR2(30) := '100';
6235 l_temp_id NUMBER;
6236 l_business_flow_code NUMBER;
6237 l_label_status VARCHAR2(300);
6238 l_tran_type_id NUMBER := p_transaction_type_id; -- Bug 3693953
6239 l_tran_source_type_id NUMBER := p_transaction_source_type_id; -- Bug 3693953
6240 l_out_temp_id NUMBER;
6241 l_multiple_pick VARCHAR2(1) := NULL;
6242 l_overpick VARCHAR2(1) := NULL;
6243 l_new_txn_hdr_id NUMBER;
6244
6245 l_parent_line_id NUMBER := p_parent_line_id;
6246 l_lpn_id NUMBER := p_lpn_id;
6247 l_content_lpn_id NUMBER := p_content_lpn_id;
6248 l_transfer_lpn_id NUMBER := p_transfer_lpn_id;
6249 l_container_item_id NUMBER := p_container_item_id;
6250 l_lpn_match_lpn_id NUMBER := p_lpn_match_lpn_id;
6251 l_qty_rsn_id NUMBER := p_qty_rsn_id;
6252 l_parent_lpn_id NUMBER := p_parent_lpn_id;
6253 l_lpn_match NUMBER := p_lpn_match;
6254 l_transaction_temp_id NUMBER := p_temp_id;
6255 --Bug #4762505
6256 --Local variables for updating MOL
6257 l_mo_line_id NUMBER; --Move Order Line OD
6258 l_mol_uom VARCHAR2(3); --UOM Code of the MOL
6259 l_sum_mmtt_qty NUMBER; --Total MMTT primary quantity
6260 l_mmtt_qty_in_mol_uom NUMBER; --Total MMTT qty in MOL UOM
6261
6262 CURSOR mmtt_csr2(p_transaction_header_id NUMBER) IS
6263 SELECT mmtt.transaction_temp_id
6264 FROM mtl_material_transactions_temp mmtt
6265 WHERE mmtt.transaction_header_id = p_transaction_header_id;
6266
6267 CURSOR lot_csr IS
6268 SELECT lot_number, serial_transaction_temp_id
6269 FROM mtl_transaction_lots_temp
6270 WHERE transaction_temp_id = p_temp_id;
6271
6272 CURSOR insert_serial_allocated_csr (p_serial_lot_number VARCHAR2) IS
6273 SELECT serial_number
6274 FROM mtl_serial_numbers msn
6275 WHERE msn.current_organization_id = p_organization_id
6276 AND msn.inventory_item_id = p_item_id
6277 AND lpn_id = p_lpn_match_lpn_id
6278 AND NVL(msn.lot_number,'@@') = NVL(p_serial_lot_number, '@@')
6279 AND msn.serial_number NOT IN
6280 ( select msnt.fm_serial_number
6281 from mtl_serial_numbers_temp msnt,
6282 mtl_transaction_lots_temp mtlt,
6283 mtl_material_transactions_temp mmtt
6284 where mmtt.inventory_item_id = p_item_id
6285 AND mmtt.organization_id = p_organization_id
6286 and mtlt.transaction_temp_id(+) = mmtt.transaction_temp_id
6287 AND msnt.transaction_temp_id = NVL(mtlt.serial_transaction_temp_id, mmtt.transaction_temp_id)
6288 and NVL(mtlt.lot_number, '@@') = NVL(p_serial_lot_number, '@@')
6289 and mmtt.transaction_temp_id = p_temp_id);
6290
6291 BEGIN
6292
6293 x_return_status := fnd_api.g_ret_sts_success;
6294 l_return_status := fnd_api.g_ret_sts_success;
6295 IF p_parent_line_id = 0 THEN l_parent_line_id := NULL; END IF;
6296 IF p_lpn_id = 0 THEN l_lpn_id := NULL; END IF;
6297 IF p_content_lpn_id = 0 THEN l_content_lpn_id := NULL; END IF;
6298 IF p_parent_lpn_id = 0 THEN l_parent_lpn_id := NULL; END IF;
6299 IF p_transfer_lpn_id = 0 THEN l_transfer_lpn_id := NULL; END IF;
6300 IF p_container_item_id = 0 THEN l_container_item_id := NULL; END IF;
6301 IF p_lpn_match_lpn_id = 0 THEN l_lpn_match_lpn_id := NULL; END IF;
6302 IF p_qty_rsn_id = 0 THEN l_qty_rsn_id := NULL; END IF;
6303
6304 IF (l_debug = 1) THEN
6305 mydebug ('l_progress: ' || l_progress );
6306 mydebug('Entered..... task_Load');
6307 mydebug('p_action:'||p_action);
6308 mydebug('p_organization_id:'||p_organization_id);
6309 mydebug('p_user_id:'||p_user_id);
6310 mydebug('p_person_id:'||p_person_id);
6311 mydebug('p_transaction_header_id:'||p_transaction_header_id);
6312 mydebug('p_temp_id:'||p_temp_id);
6313 mydebug('p_parent_line_id:'||p_parent_line_id ||':' || l_parent_line_id);
6314 mydebug('p_lpn_id:' ||p_lpn_id ||':' || l_lpn_id);
6315 mydebug('p_content_lpn_id:' ||p_content_lpn_id ||':'||l_content_lpn_id);
6316 mydebug('p_parent_lpn_id:' ||p_parent_lpn_id ||':'||l_parent_lpn_id);
6317 mydebug('p_transfer_lpn_id:' ||p_transfer_lpn_id ||':' || l_transfer_lpn_id);
6318 mydebug('p_confirmed_sub:' ||p_confirmed_sub);
6319 mydebug('p_confirmed_loc_id:' ||p_confirmed_loc_id);
6320 mydebug('p_confirmed_uom:' ||p_confirmed_uom);
6321 mydebug('p_suggested_uom:' ||p_suggested_uom);
6322 mydebug('p_primary_uom :' ||p_primary_uom );
6323 mydebug('p_item_id:' ||p_item_id);
6324 mydebug('p_revision:' ||p_revision);
6325 mydebug('p_confirmed_qty:' ||p_confirmed_qty);
6326 mydebug('p_confirmed_lots:' ||p_confirmed_lots);
6327 mydebug('p_confirmed_lot_trx_qty:' ||p_confirmed_lot_trx_qty);
6328 mydebug('p_confirmed_sec_uom:' ||p_confirmed_sec_uom);
6329 mydebug('p_confirmed_sec_qty:' ||p_confirmed_sec_qty);
6330 mydebug('p_confirmed_serials:' ||p_confirmed_serials);
6331 mydebug('p_container_item_id:' ||p_container_item_id ||':' || l_container_item_id);
6332 mydebug('p_transaction_type_id: ' || p_transaction_type_id);
6333 mydebug('p_transaction_source_type_id: ' || p_transaction_source_type_id);
6334 mydebug('p_lpn_match:' ||p_lpn_match);
6335 mydebug('p_lpn_match_lpn_id:' ||p_lpn_match_lpn_id || ':' || l_lpn_match_lpn_id);
6336 mydebug('p_serial_allocated_flag:' ||p_serial_allocated_flag);
6337 mydebug('p_lot_controlled:' ||p_lot_controlled);
6338 mydebug('p_serial_controlled:' ||p_serial_controlled);
6339 mydebug('p_effective_start_date:' ||p_effective_start_date);
6340 mydebug('p_exception:' ||p_exception);
6341 mydebug('p_discrepancies:' ||p_discrepancies);
6342 mydebug('p_qty_rsn_id:' ||p_qty_rsn_id || ':' || l_qty_rsn_id);
6343 mydebug('p_lpnpickedasis:'||p_lpnpickedasis);
6344
6345 END IF;
6346
6347 l_progress := '130';
6348 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6349 IF p_confirmed_qty = 0 AND p_exception <> l_g_exception_short
6350 THEN
6351 fnd_message.set_name('WMS', 'WMS_PICK_ZERO_QTY');
6352 -- Confirmed qty for this task is zero
6353 fnd_msg_pub.ADD;
6354 RAISE fnd_api.g_exc_unexpected_error;
6355 END IF;
6356 BEGIN
6357 wms_picking_pkg.g_previous_task_status.delete(p_temp_id);
6358 EXCEPTION
6359 WHEN OTHERS THEN
6360 null; -- it is ok not to find it.
6361 END ;
6362
6363 --Bug #4762505
6364 --Get the move_order_line_id for the current task
6365 BEGIN
6366 SELECT move_order_line_id
6367 INTO l_mo_line_id
6368 FROM mtl_material_transactions_temp
6369 WHERE transaction_temp_id = p_temp_id;
6370 EXCEPTION
6371 WHEN OTHERS THEN
6372 l_mo_line_id := NULL;
6373 END;
6374
6375 -- bug 3983704
6376 IF l_lpn_match =4 and p_transfer_lpn_id = p_lpn_id THEN
6377 l_lpn_match := 1;
6378 l_content_lpn_id := l_lpn_id;
6379 l_lpn_id :=null;
6380 IF (l_debug = 1) THEN
6381 mydebug ('lpn_match is 4 and to lpn=from lpn');
6382 END IF;
6383 END IF;
6384
6385 --jxlu for lpn overpicking
6386
6387 IF p_lpnpickedasis = 'Y'
6388 THEN
6389 IF (l_debug = 1) THEN
6390 mydebug ('lpn_match is 4 and lpnpickedasis is true, change lpn_match to 1 ');
6391 END IF;
6392 l_lpn_match := 1;
6393 IF p_serial_controlled = 'Y'
6394 AND p_serial_allocated_flag = 'Y'
6395 THEN
6396 -- if lot controlled
6397 IF p_lot_controlled = 'Y' THEN
6398 FOR lot_rec in lot_csr LOOP
6399 IF (l_debug = 1) THEN
6400 mydebug ('item is lot controlled and current lot is: '||lot_rec.lot_number);
6401 END IF;
6402 FOR serial_rec in insert_serial_allocated_csr(lot_rec.lot_number) LOOP
6403 -- insert serial into msnt and mark msn
6404 insert_serial(
6405 p_serial_transaction_temp_id => lot_rec.serial_transaction_temp_id,
6406 p_organization_id => p_organization_id,
6407 p_item_id => p_item_id,
6408 p_revision => p_revision,
6409 p_lot => lot_rec.lot_number,
6410 p_transaction_temp_id => p_temp_id,
6411 p_created_by => p_user_id,
6412 p_from_serial => serial_rec.serial_number,
6413 p_to_serial => serial_rec.serial_number,
6414 p_status_id => NULL,
6415 x_return_status => l_return_status,
6416 x_msg_data => l_msg_data);
6417 IF l_return_status IN ( fnd_api.g_ret_sts_unexp_error, fnd_api.g_ret_sts_error)
6418 THEN
6419 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR');
6420 -- Internal Error $ROUTINE
6421 fnd_message.set_token('ROUTINE', '-INSERT_SERIAL API - ' || p_action);
6422 fnd_msg_pub.ADD;
6423 RAISE fnd_api.g_exc_unexpected_error;
6424 ELSE
6425 IF (l_debug = 1) THEN
6426 mydebug ('the serial number is: '|| serial_rec.serial_number);
6427 END IF;
6428 END IF;
6429 END LOOP;
6430 END LOOP;
6431 ELSE
6432 IF (l_debug = 1) THEN
6433 mydebug ('only serial controlled item and serial is allocated');
6434 END IF;
6435 FOR serial_rec IN insert_serial_allocated_csr(NULL) LOOP
6436 -- insert serial into msnt and mark msn
6437 insert_serial(
6438 p_serial_transaction_temp_id => l_transaction_temp_id,
6439 p_organization_id => p_organization_id,
6440 p_item_id => p_item_id,
6441 p_revision => p_revision,
6442 p_lot => NULL,
6443 p_transaction_temp_id => p_temp_id,
6444 p_created_by => p_user_id,
6445 p_from_serial => serial_rec.serial_number,
6446 p_to_serial => serial_rec.serial_number,
6447 p_status_id => NULL,
6448 x_return_status => l_return_status,
6449 x_msg_data => l_msg_data);
6450 IF l_return_status IN ( fnd_api.g_ret_sts_unexp_error, fnd_api.g_ret_sts_error)
6451 THEN
6452 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR');
6453 -- Internal Error $ROUTINE
6454 fnd_message.set_token('ROUTINE', '- INSERT_SERIAL API - ');
6455 fnd_msg_pub.ADD;
6456 RAISE fnd_api.g_exc_unexpected_error;
6457 ELSE
6458 IF (l_debug = 1) THEN
6459 mydebug ('the serial number is: '|| serial_rec.serial_number);
6460 END IF;
6461 END IF;
6462 END LOOP;
6463 END IF;
6464 END IF;
6465 END IF;
6466
6467 IF p_confirmed_qty <> 0 THEN
6468 l_progress := '140';
6469 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6470 task_merge_split(
6471 p_action => p_action
6472 ,p_exception => p_exception
6473 ,p_organization_id => p_organization_id
6474 ,p_user_id => p_user_id
6475 ,p_transaction_header_id => p_transaction_header_id
6476 ,p_transaction_temp_id => p_temp_id
6477 ,p_parent_line_id => p_parent_line_id
6478 ,p_remaining_temp_id => NULL
6479 ,p_lpn_id => l_lpn_id
6480 ,p_content_lpn_id => l_content_lpn_id
6481 ,p_transfer_lpn_id => l_transfer_lpn_id
6482 ,p_confirmed_sub => p_confirmed_sub
6483 ,p_confirmed_locator_id => p_confirmed_loc_id
6484 ,p_confirmed_uom => p_confirmed_uom
6485 ,p_suggested_uom => p_suggested_uom
6486 ,p_primary_uom => p_primary_uom
6487 ,p_inventory_item_id => p_item_id
6488 ,p_revision => p_revision
6489 ,p_confirmed_trx_qty => p_confirmed_qty
6490 ,p_confirmed_lots => p_confirmed_lots
6491 ,p_confirmed_lot_trx_qty => p_confirmed_lot_trx_qty
6492 ,p_confirmed_sec_uom => p_confirmed_sec_uom
6493 ,p_confirmed_sec_qty => p_confirmed_sec_qty
6494 ,p_confirmed_serials => p_confirmed_serials
6495 ,p_container_item_id => l_container_item_id
6496 ,p_lpn_match => l_lpn_match
6497 ,p_lpn_match_lpn_id => l_lpn_match_lpn_id
6498 ,p_serial_allocated_flag => p_serial_allocated_flag
6499 ,p_lot_controlled => p_lot_controlled
6500 ,p_serial_controlled => p_serial_controlled
6501 ,p_parent_lpn_id => l_parent_lpn_id
6502 --,p_lpnpickedasis => p_lpnpickedasis
6503 ,x_new_transaction_temp_id=> l_out_temp_id
6504 ,x_cms_check => x_cms_check
6505 ,x_return_status => l_return_status
6506 ,x_msg_count => l_msg_count
6507 ,x_msg_data => l_msg_data);
6508
6509 IF l_return_status IN ( fnd_api.g_ret_sts_unexp_error, fnd_api.g_ret_sts_error)
6510 THEN
6511 fnd_message.set_name('WMS', 'WMS_INTERNAL_ERROR');
6512 -- Internal Error $ROUTINE
6513 fnd_message.set_token('ROUTINE', '-Task_Merge_Split API - ' || p_action);
6514 fnd_msg_pub.ADD;
6515 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6516 RAISE fnd_api.g_exc_unexpected_error;
6517 ELSE
6518 RAISE fnd_api.g_exc_error;
6519 END IF;
6520 END IF;
6521 END IF; -- confirmed_qty <> 0
6522
6523 -- REASONS ...EXCEPTION HANDLING will deal with MOL upd'ns , deletion of MMTT and its children etc.
6524 -- NO REASONS ...EXCEPTION HANDLING o for BULJK.... Janet will call from bulk API
6525 -- BULK API .. to process children etc
6526 -- No LAbel printing of BULK
6527
6528 l_progress := '200';
6529 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6530 IF p_action = l_g_action_load_multiple
6531 THEN
6532 l_multiple_pick := 'Y';
6533 ELSE
6534 l_multiple_pick := 'N';
6535 END IF;
6536 l_progress := '210';
6537 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6538
6539 /* IF p_discrepancies IS NOT NULL
6540 -- there are non quantity discrepencies to be logged
6541 -- in wms_exceptions table.
6542 -- it also includes overpick and shortpick for LPN/Lot.
6543 -- Qty exception is one where total picked < suggested
6544 -- and there can be only one qty exception for a task. */
6545
6546 IF p_discrepancies IS NOT NULL
6547 THEN
6548 l_progress := '300';
6549 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6550 wms_txnrsn_actions_pub.process_exceptions
6551 ( p_organization_id => p_organization_id
6552 ,p_employee_id => p_person_id
6553 ,p_effective_start_date => p_effective_start_date
6554 ,p_effective_end_date => p_effective_end_date
6555 ,p_inventory_item_id => p_item_id
6556 ,p_revision => p_revision
6557 ,p_discrepancies => p_discrepancies
6558 ,x_return_status => x_return_status
6559 ,x_msg_count => x_msg_count
6560 ,x_msg_data => x_msg_data );
6561 IF (l_debug = 1) THEN
6562 mydebug ('x_return_status: ' || x_return_status );
6563 END IF;
6564 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
6565 RAISE fnd_api.g_exc_unexpected_error;
6566 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
6567 RAISE fnd_api.g_exc_error;
6568 END IF;
6569 END IF;
6570
6571 IF l_parent_line_id IS NULL -- non bulk parent or non-bulk-child
6572 AND
6573 --l_qty_rsn_id IS NOT NULL -- There is a Curtail pick exception
6574 p_exception = 'SHORT'
6575 THEN
6576 -- it should be called only for qty exceptions where picked quantity < suggested quantity
6577 -- and not for overpicked qty
6578 l_progress := '400';
6579 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6580 wms_txnrsn_actions_pub.cleanup_task
6581 ( p_temp_id => p_temp_id
6582 , p_qty_rsn_id => l_qty_rsn_id
6583 , p_user_id => p_user_id
6584 , p_employee_id => p_person_id
6585 , x_return_status => x_return_status
6586 , x_msg_count => x_msg_count
6587 , x_msg_data => x_msg_data);
6588 IF (l_debug = 1) THEN
6589 mydebug ('x_return_status: ' || x_return_status );
6590 END IF;
6591 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
6592 RAISE fnd_api.g_exc_unexpected_error;
6593 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
6594 RAISE fnd_api.g_exc_error;
6595 END IF;
6596
6597 END IF;
6598
6599 -- Bug #: 6908598
6600 -- Calling label printing both for bulk and independent tasks
6601 BEGIN
6602 l_business_flow_code := inv_label.wms_bf_pick_load;
6603 IF l_tran_type_id = 52 THEN -- Picking for sales order
6604 l_business_flow_code := inv_label.wms_bf_pick_load;
6605 ELSIF l_tran_type_id = 35 THEN -- WIP issue
6606 l_business_flow_code := inv_label.wms_bf_wip_pick_load;
6607 ELSIF l_tran_type_id = 51
6608 AND l_tran_source_type_id = 13 THEN --Backflush
6609 l_business_flow_code := inv_label.wms_bf_wip_pick_load;
6610 ELSIF l_tran_type_id = 64
6611 AND l_tran_source_type_id = 4 THEN --Replenishment
6612 l_business_flow_code := inv_label.wms_bf_replenishment_load;
6613 END IF;
6614 l_progress := '410';
6615 IF (l_debug = 1) THEN mydebug ('l_business_flow_code: ' || l_business_flow_code ); END IF;
6616
6617 OPEN mmtt_csr2(p_transaction_header_id);
6618 LOOP
6619 FETCH mmtt_csr2 INTO l_temp_id;
6620 EXIT WHEN mmtt_csr2%NOTFOUND;
6621
6622 IF (l_debug = 1) THEN
6623 mydebug('task_load: Calling label printing for transaction:' || l_temp_id);
6624 END IF;
6625
6626 inv_label.print_label_wrap(
6627 x_return_status => x_return_status
6628 , x_msg_count => x_msg_count
6629 , x_msg_data => x_msg_data
6630 , x_label_status => l_label_status
6631 , p_business_flow_code => l_business_flow_code
6632 , p_transaction_id => l_temp_id
6633 );
6634
6635 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6636 IF (l_debug = 1) THEN mydebug('Label printing failed. Continue'); END IF;
6637 END IF;
6638 END LOOP;
6639
6640 CLOSE mmtt_csr2;
6641 END;
6642 -- End of Bug #: 6908598
6643
6644 IF nvl(l_parent_line_id,0) = p_temp_id
6645 THEN
6646 -- Call Bulk_API to process bulk children
6647 -- This API will also take care of qty exceptions workflow call for children
6648 -- affected by picking less than the requested qty
6649 l_progress := '500';
6650 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6651 wms_bulk_pick.bulk_pick(
6652 p_temp_id => p_temp_id
6653 , p_txn_hdr_id => p_transaction_header_id
6654 , p_org_id => p_organization_id
6655 , p_multiple_pick => l_multiple_pick
6656 , p_exception => p_exception
6657 , p_lot_controlled => p_lot_controlled
6658 , p_user_id => p_user_id
6659 , p_employee_id => p_person_id
6660 , p_reason_id => p_qty_rsn_id
6661 , x_new_txn_hdr_id => l_new_txn_hdr_id
6662 , x_return_status => x_return_status
6663 , x_msg_count => x_msg_count
6664 , x_msg_data => x_msg_data);
6665
6666
6667 IF (l_debug = 1) THEN
6668 mydebug ('l_new_txn_hdr_id: ' || l_new_txn_hdr_id );
6669 mydebug ('x_return_status: ' || x_return_status );
6670 END IF;
6671 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
6672 --fnd_message.set_name('WMS', 'WMS_MULT_LPN_ERROR');
6673 --fnd_msg_pub.ADD;
6674 RAISE fnd_api.g_exc_unexpected_error;
6675 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
6676 --fnd_message.set_name('WMS', 'WMS_MULT_LPN_ERROR');
6677 --fnd_msg_pub.ADD;
6678 RAISE fnd_api.g_exc_error;
6679 END IF;
6680
6681 /* -- Bug #: 6908598 Commenting else part as we are calling the label printing irrespective of whether it is a bulk task or not */
6682 /*
6683 ELSE
6684 -- call label printing for all tasks other than bulk tasks.
6685 l_progress := '600';
6686 IF (l_debug = 1) THEN mydebug ('l_progress: ' || l_progress ); END IF;
6687 BEGIN
6688 l_business_flow_code := inv_label.wms_bf_pick_load;
6689 IF l_tran_type_id = 52 THEN -- Picking for sales order
6690 l_business_flow_code := inv_label.wms_bf_pick_load;
6691 ELSIF l_tran_type_id = 35 THEN -- WIP issue
6692 l_business_flow_code := inv_label.wms_bf_wip_pick_load;
6693 ELSIF l_tran_type_id = 51
6694 AND l_tran_source_type_id = 13 THEN --Backflush
6695 l_business_flow_code := inv_label.wms_bf_wip_pick_load;
6696 ELSIF l_tran_type_id = 64
6697 AND l_tran_source_type_id = 4 THEN --Replenishment
6698 l_business_flow_code := inv_label.wms_bf_replenishment_load;
6699 END IF;
6700 l_progress := '610';
6701 IF (l_debug = 1) THEN mydebug ('l_business_flow_code: ' || l_business_flow_code ); END IF;
6702
6703 OPEN mmtt_csr2(p_transaction_header_id);
6704 LOOP
6705 FETCH mmtt_csr2 INTO l_temp_id;
6706 EXIT WHEN mmtt_csr2%NOTFOUND;
6707
6708 IF (l_debug = 1) THEN
6709 mydebug('task_load: Calling label printing for transaction:' || l_temp_id);
6710 END IF;
6711
6712 inv_label.print_label_wrap(
6713 x_return_status => x_return_status
6714 , x_msg_count => x_msg_count
6715 , x_msg_data => x_msg_data
6716 , x_label_status => l_label_status
6717 , p_business_flow_code => l_business_flow_code
6718 , p_transaction_id => l_temp_id
6719 );
6720
6721 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6722 IF (l_debug = 1) THEN mydebug('Label printing failed. Continue'); END IF;
6723 END IF;
6724 END LOOP;
6725
6726 CLOSE mmtt_csr2;
6727 END;
6728
6729 */
6730
6731
6732 END IF; -- Not a bulk task.. finished label printing
6733
6734 --Bug #4762505
6735 --At the end of the load process, we need to update the quantity_detailed
6736 --of the move order line. Do this for non-bulk tasks
6737 IF (l_mo_line_id IS NOT NULL AND l_parent_line_id IS NULL) THEN
6738
6739 IF (l_debug = 1) THEN
6740 mydebug('Should update quantity_detailed for MO Line ID: ' || l_mo_line_id);
6741 END IF;
6742
6743 --Fetch the UOM code of the MO line and lock the MO line
6744 SELECT uom_code
6745 INTO l_mol_uom
6746 FROM mtl_txn_request_lines
6747 WHERE line_id = l_mo_line_id
6748 FOR UPDATE;
6749
6750 --Fetch the primary quantity for all MMTTs for this MO line
6751 SELECT ABS(SUM(primary_quantity))
6752 INTO l_sum_mmtt_qty
6753 FROM mtl_material_transactions_temp
6754 WHERE move_order_line_id = l_mo_line_id;
6755
6756 --Convert the MMTT primary quantity into MOL UOM
6757 IF p_primary_uom = l_mol_uom THEN
6758 l_mmtt_qty_in_mol_uom := l_sum_mmtt_qty;
6759 ELSE
6760 l_mmtt_qty_in_mol_uom := inv_convert.inv_um_convert
6761 (item_id => p_item_id
6762 ,precision => l_g_decimal_precision
6763 ,from_quantity => l_sum_mmtt_qty
6764 ,from_unit => p_primary_uom
6765 ,to_unit => l_mol_uom
6766 ,from_name => NULL
6767 ,to_name => NULL);
6768 END IF;
6769
6770 IF (l_debug = 1) THEN
6771 mydebug('update quantity_detailed in MOL with: ' || l_mmtt_qty_in_mol_uom);
6772 END IF;
6773
6774 --Now update quantity_detailed as quanity_delivered + sum(mmtt qty)
6775 UPDATE mtl_txn_request_lines
6776 SET quantity_detailed = NVL(quantity_delivered, 0) + l_mmtt_qty_in_mol_uom
6777 , last_update_date = SYSDATE
6778 , last_updated_by = p_user_id
6779 WHERE line_id = l_mo_line_id;
6780 END IF; --END IF l_mo_line_id IS NOT NULL AND l_parent_line_id IS NULL
6781 --End changes for Bug #4762505
6782
6783 IF (l_debug = 1) THEN
6784 mydebug('End of load_pick');
6785 mydebug('x_return_status :'||x_return_status);
6786 mydebug('x_msg_count:'||x_msg_count);
6787 mydebug('x_msg_data:' || x_msg_data);
6788 END IF;
6789
6790 EXCEPTION
6791 WHEN fnd_api.g_exc_error THEN
6792 x_return_status := l_g_ret_sts_error;
6793 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6794 mydebug('ROLLBACK ' );
6795 ROLLBACK ;
6796 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
6797 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
6798 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
6799 WHEN fnd_api.g_exc_unexpected_error THEN
6800 x_return_status := fnd_api.g_ret_sts_unexp_error;
6801 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6802 mydebug('ROLLBACK ' );
6803 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
6804 mydebug('RAISE fnd_api.g_exc_unexpected_error: ' || SQLERRM);
6805 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
6806 ROLLBACK ;
6807 WHEN OTHERS THEN
6808 x_return_status := l_g_ret_sts_unexp_error;
6809 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6810 mydebug('ROLLBACK ' );
6811 ROLLBACK ;
6812 mydebug('l_progress = ' || l_proc_name || ':'|| l_progress);
6813 mydebug('RAISE fnd_api.g_exc_error: ' || SQLERRM);
6814 mydebug('x_msg_count/Data = ' || x_msg_count || '/'|| x_msg_data);
6815
6816 END TASK_LOAD;
6817
6818 /*
6819 The following table gives the conditions checked by LPN Match
6820 and its return values
6821
6822 Condition x_match x_return_status
6823 =================================================================
6824 LPN already picked 7 E
6825 LPN location is invalid 6 E
6826 LPN SUB is null 10 E
6827 LPN already staged for another SO 12 E
6828 Item/Lot/Revision is not in LPN 13 E
6829 LPN has multiple items, item_qty<reqQty 2 S
6830 The user has to manually confirm the LPN
6831 LPN has requested item but quantity is 4 S
6832 more than the allocated quantity
6833 The user has to manually confirm the LPN
6834 Serial number is not valid for this 11 E
6835 transaction.
6836 LPN has requested item with sufficient 8 E
6837 quantity but LPN content status is
6838 invalid
6839 Serial Allocation was requested for the 9 E
6840 item but it is not allowed/there
6841 Everything allright and exact quantity 1 S
6842 match
6843 Everything allright and quantity in LPN 3 S
6844 is less than requested quantity
6845
6846 Although x_match is being set even for error conditions
6847 it is used by the calling code ONLY in case of success
6848
6849 */
6850
6851 PROCEDURE lpn_match(
6852 p_fromlpn_id IN NUMBER
6853 , p_org_id IN NUMBER
6854 , p_item_id IN NUMBER
6855 , p_rev IN VARCHAR2
6856 , p_lot IN VARCHAR2
6857 , p_trx_qty IN NUMBER
6858 , p_trx_uom IN VARCHAR2
6859 , p_sec_qty IN NUMBER -- Bug #4141928
6860 , p_sec_uom IN VARCHAR2 -- Bug #4141928
6861 , x_match OUT NOCOPY NUMBER
6862 , x_sub OUT NOCOPY VARCHAR2
6863 , x_loc OUT NOCOPY VARCHAR2
6864 , x_trx_qty OUT NOCOPY NUMBER
6865 , x_trx_sec_qty OUT NOCOPY NUMBER -- Bug #4141928
6866 , x_return_status OUT NOCOPY VARCHAR2
6867 , x_msg_count OUT NOCOPY NUMBER
6868 , x_msg_data OUT NOCOPY VARCHAR2
6869 , p_temp_id IN NUMBER
6870 , p_parent_line_id IN NUMBER
6871 , p_wms_installed IN VARCHAR2
6872 , p_transaction_type_id IN NUMBER
6873 , p_cost_group_id IN NUMBER
6874 , p_is_sn_alloc IN VARCHAR2
6875 , p_action IN NUMBER
6876 , p_split IN VARCHAR2
6877 , p_user_id IN NUMBER
6878 , x_temp_id OUT NOCOPY NUMBER
6879 , x_loc_id OUT NOCOPY NUMBER
6880 , x_lpn_lot_vector OUT NOCOPY VARCHAR2
6881 , x_cms_check OUT NOCOPY VARCHAR2
6882 , x_parent_lpn_id OUT NOCOPY VARCHAR2
6883 , x_trx_qty_alloc OUT NOCOPY NUMBER
6884 , p_transaction_action_id IN NUMBER
6885 , p_pickOverNoException IN VARCHAR2
6886 , p_toLPN_Default IN VARCHAR2 -- Bug 3855835
6887 , p_project_id IN NUMBER
6888 , p_task_id IN NUMBER
6889 , p_confirmed_sub IN VARCHAR2
6890 , p_confirmed_loc_id IN NUMBER
6891 , p_from_lpn_id IN NUMBER
6892 , x_toLPN_status OUT NOCOPY VARCHAR2 --Bug 3855835
6893 , x_lpnpickedasis OUT NOCOPY VARCHAR2
6894 , x_lpn_qoh OUT NOCOPY NUMBER
6895 ) IS
6896 l_proc_name VARCHAR2(30) := 'LPN_MATCH' ;
6897 l_msg_cnt NUMBER;
6898 l_msg_data VARCHAR2(2000);
6899 l_return_status VARCHAR2(240);
6900 l_exist_qty NUMBER;
6901 l_item_cnt NUMBER;
6902 l_rev_cnt NUMBER;
6903 l_lot_cnt NUMBER;
6904 l_item_cnt2 NUMBER;
6905 l_cg_cnt NUMBER;
6906 l_sub VARCHAR2(60);
6907 l_loc VARCHAR2(60);
6908 l_loaded NUMBER := 0;
6909 l_allocate_serial_flag NUMBER := 0;
6910 l_temp_serial_trans_temp NUMBER := 0;
6911 l_serial_number VARCHAR2(50);
6912
6913 l_lpn_pr_qty NUMBER;
6914 l_lpn_trx_qty NUMBER;
6915 l_lpn_sec_qty NUMBER; -- Bug #4141928
6916
6917 l_pr_qty NUMBER;
6918 l_primary_uom VARCHAR2(3);
6919 l_sec_qty NUMBER; -- Bug #4141928
6920 l_secondary_uom VARCHAR2(3); -- Bug #4141928
6921
6922 l_lot_code NUMBER;
6923 l_serial_code NUMBER;
6924
6925 l_mmtt_qty NUMBER;
6926 l_mmtt_sec_qty NUMBER; -- Bug #4141928
6927
6928 l_out_temp_id NUMBER := 0;
6929 l_serial_exist_cnt NUMBER := 0;
6930 l_total_serial_cnt NUMBER := 0;
6931 l_so_cnt NUMBER := 0;
6932 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
6933 l_mtlt_lot_number VARCHAR2(80);
6934
6935 l_mtlt_primary_qty NUMBER;
6936 l_wlc_quantity NUMBER;
6937 l_wlc_uom_code VARCHAR2(3);
6938 l_mtlt_secondary_qty NUMBER; -- Bug #4141928
6939 l_wlc_sec_quantity NUMBER; -- Bug #4141928
6940 l_wlc_sec_uom_code VARCHAR2(3); -- Bug #4141928
6941
6942 l_lot_match NUMBER;
6943 l_ok_to_process VARCHAR2(5);
6944 l_is_revision_control VARCHAR2(1);
6945 l_is_lot_control VARCHAR2(1);
6946 l_is_serial_control VARCHAR2(1);
6947 b_is_revision_control BOOLEAN;
6948 b_is_lot_control BOOLEAN;
6949 b_is_serial_control BOOLEAN;
6950 l_from_lpn VARCHAR2(30);
6951 l_loc_id NUMBER;
6952 l_lpn_context NUMBER;
6953 l_lpn_exists NUMBER;
6954
6955 l_qoh NUMBER;
6956 l_rqoh NUMBER;
6957 l_qr NUMBER;
6958 l_qs NUMBER;
6959 l_att NUMBER;
6960 l_atr NUMBER;
6961 l_sqoh NUMBER; -- Bug #4141928
6962 l_srqoh NUMBER; -- Bug #4141928
6963 l_sqr NUMBER; -- Bug #4141928
6964 l_sqs NUMBER; -- Bug #4141928
6965 l_satt NUMBER; -- Bug #4141928
6966 l_satr NUMBER; -- Bug #4141928
6967
6968 l_allocated_lpn_id NUMBER;
6969 l_table_index NUMBER := 0;
6970 l_table_total NUMBER := 0;
6971 l_table_count NUMBER;
6972 l_lpn_include_lpn NUMBER;
6973 l_xfr_sub_code VARCHAR2(30);
6974 l_sub_active NUMBER := 0;
6975 l_loc_active NUMBER := 0;
6976 l_mmtt_proj_id NUMBER ; -- 2774506/2905646
6977 l_mmtt_task_id NUMBER ;
6978 l_locator_id NUMBER;
6979 l_organization_id NUMBER;
6980 l_mil_proj_id NUMBER ;
6981 l_mil_task_id NUMBER ; -- 2774506/2905646
6982 l_transaction_header_id NUMBER;
6983 l_transaction_uom VARCHAR2(3);
6984 l_sec_transaction_uom VARCHAR2(3); -- Bug #4141928
6985 l_lpn_id NUMBER;
6986 l_content_lpn_id NUMBER;
6987 --l_transfer_lpn_id NUMBER;
6988 l_check_tolerance Boolean;
6989 l_overpicked_qty NUMBER ;
6990 l_lot_string VARCHAR2(12000);--Bug 6148865
6991 l_lot_qty_string VARCHAR2(12000);--Bug 6148865
6992 l_lot_sec_qty_string VARCHAR2(12000); -- Bug #4141928 --Bug 6148865
6993 l_sec_qty_str VARCHAR2(12000); -- Bug #4141928 --Bug 6148865
6994 l_serial_string VARCHAR2(2000);
6995 l_check_overpick_passed VARCHAR2(1);
6996 l_overpick_error_code NUMBER;
6997 l_match_serials Boolean := false;
6998 l_pick_to_lpn_id NUMBER;
6999 l_lot_v VARCHAR2(12000) := null; --Bug 6148865
7000
7001 --Bug5649056
7002 l_mmtt_sub VARCHAR2(60);
7003 l_mmtt_loc NUMBER;
7004 l_lpn_sub VARCHAR2(60);
7005 l_lpn_loc NUMBER;
7006 --Bug5649056
7007 l_value VARCHAR2(3); --bug 6651517
7008 CURSOR ser_csr IS
7009 SELECT serial_number
7010 FROM mtl_serial_numbers
7011 WHERE lpn_id = p_fromlpn_id
7012 AND inventory_item_id = p_item_id
7013 AND NVL(lot_number, -999) = NVL(p_lot, -999);
7014
7015 CURSOR lot_csr IS
7016 SELECT mtlt.primary_quantity
7017 , NVL(mtlt.secondary_quantity, 0) -- Bug #4141928
7018 , mtlt.lot_number
7019 FROM mtl_transaction_lots_temp mtlt
7020 WHERE mtlt.transaction_temp_id = p_temp_id
7021 ORDER BY LOT_NUMBER;
7022
7023 --jxlu 10/12/04
7024 CURSOR lot_att IS
7025 SELECT lot_number, sum(transaction_quantity) transaction_quantity
7026 from wms_ALLOCATIONS_GTMP
7027 GROUP BY LOT_NUMBER
7028 ORDER BY LOT_NUMBER;
7029
7030 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7031
7032 BEGIN
7033 BEGIN
7034 -- this is done to release a lock on LPN that was picked first and later changed
7035 -- so that the lock on first one is released and next one will be locked later.
7036 ROLLBACK TO LPN_MATCH;
7037 EXCEPTION
7038 WHEN OTHERS THEN
7039 IF SQLCODE = -1086 THEN -- savepoint 'XYZ' never established
7040 -- Ignore
7041 mydebug ('Save point not available.. may be the first visit to this API ' );
7042 END IF ;
7043 END ;
7044
7045 SAVEPOINT LPN_MATCH ; --
7046 g_debug := l_debug;
7047 IF (l_debug = 1) THEN
7048 mydebug('In lpn Match');
7049 END IF;
7050
7051 x_return_status := fnd_api.g_ret_sts_success;
7052 l_lpn_exists := 0;
7053 --clear the PL/SQL table each time coming in
7054
7055 t_lpn_lot_qty_table.DELETE;
7056
7057 x_trx_qty_alloc := 0;
7058 x_lpnpickedasis := 'N';
7059
7060 SELECT primary_uom_code
7061 , secondary_uom_code -- Bug #4141928
7062 , lot_control_code
7063 , serial_number_control_code
7064 INTO l_primary_uom
7065 , l_secondary_uom -- Bug #4141928
7066 , l_lot_code
7067 , l_serial_code
7068 FROM mtl_system_items
7069 WHERE organization_id = p_org_id
7070 AND inventory_item_id = p_item_id;
7071
7072 --bug 6651517
7073 select value
7074 into l_value
7075 from v$nls_parameters
7076 where parameter = 'NLS_NUMERIC_CHARACTERS';
7077
7078 -- p_trx_qty was passed in transaction_uom, need to convert it to primary_uom
7079 IF (l_debug = 1) THEN
7080 mydebug('p_trx_uom :'|| p_trx_uom);
7081 mydebug('l_primary_uom :'|| l_primary_uom);
7082 mydebug('p_trx_qty in transaction uom:'|| p_trx_qty);
7083 mydebug('p_sec_uom :'|| p_sec_uom); -- Bug #4141928
7084 mydebug('l_secondary_uom :'|| l_secondary_uom); -- Bug #4141928
7085 END IF;
7086
7087 IF (p_trx_uom <> l_primary_uom) THEN
7088 l_pr_qty := inv_convert.inv_um_convert(
7089 item_id => p_item_id
7090 ,precision => null
7091 ,from_quantity => p_trx_qty
7092 ,from_unit => p_trx_uom
7093 ,to_unit => l_primary_uom
7094 ,from_name => null
7095 ,to_name => null);
7096 l_lpn_pr_qty := l_pr_qty;
7097 IF (l_debug = 1) THEN
7098 mydebug('transaction uom is different from primary uom');
7099 mydebug('p_trx_qty in primary uom is l_pri_qty:'|| l_pr_qty);
7100 mydebug('l_lpn_pri_qty in primary uom :'|| l_lpn_pr_qty);
7101 END IF;
7102 ELSE
7103 l_lpn_pr_qty := p_trx_qty;
7104 l_lpn_trx_qty := p_trx_qty;
7105 l_pr_qty := p_trx_qty;
7106 IF (l_debug = 1) THEN
7107 mydebug('transaction uom is the same as primary uom');
7108 mydebug('l_lpn_pr_qty is the same as p_trx_qty :'|| l_lpn_pr_qty);
7109 mydebug('l_lpn_trx_qty is the same as p_trx_qty :'|| l_lpn_trx_qty);
7110 END IF;
7111 END IF;
7112
7113 l_lpn_sec_qty := p_sec_qty; -- Bug #4141928
7114 l_sec_qty := p_sec_qty; -- Bug #4141928
7115
7116 BEGIN
7117 -- Bug5649056: Added sub and loc in following query.
7118 SELECT 1
7119 , lpn_context
7120 , parent_lpn_id
7121 , subinventory_code
7122 , locator_id
7123 INTO l_lpn_exists
7124 , l_lpn_context
7125 , x_parent_lpn_id
7126 , l_lpn_sub
7127 , l_lpn_loc
7128 FROM wms_license_plate_numbers wlpn
7129 WHERE wlpn.organization_id = p_org_id
7130 AND wlpn.lpn_id = p_fromlpn_id;
7131 EXCEPTION
7132 WHEN NO_DATA_FOUND THEN
7133 IF (l_debug = 1) THEN
7134 mydebug('lpn does not exist in org');
7135 END IF;
7136
7137 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
7138 fnd_msg_pub.ADD;
7139 RAISE fnd_api.g_exc_error;
7140 END;
7141
7142 IF l_lpn_exists = 0
7143 OR p_fromlpn_id = 0
7144 OR l_lpn_context <> wms_container_pub.lpn_context_inv THEN
7145 IF (l_debug = 1) THEN
7146 mydebug('lpn does not exist in org');
7147 END IF;
7148
7149 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
7150 fnd_msg_pub.ADD;
7151 RAISE fnd_api.g_exc_error;
7152 END IF;
7153
7154 IF (l_debug = 1) THEN
7155 mydebug('Checking if lpn has been picked already');
7156 END IF;
7157
7158 x_match := 0;
7159
7160 BEGIN
7161 -- Bug#2742860 The from LPN should not be loaded,
7162 -- this check should not be restricted to that particular transaction header id
7163
7164
7165 SELECT 1
7166 INTO l_loaded
7167 FROM DUAL
7168 WHERE EXISTS(SELECT 1
7169 FROM mtl_material_transactions_temp
7170 WHERE (transfer_lpn_id = p_fromlpn_id
7171 OR content_lpn_id = p_fromlpn_id));
7172 EXCEPTION
7173 WHEN NO_DATA_FOUND THEN
7174 l_loaded := 0;
7175 END;
7176
7177 IF l_loaded > 0 THEN
7178 x_match := 7;
7179 fnd_message.set_name('WMS', 'WMS_LOADED_ERROR');
7180 fnd_msg_pub.ADD;
7181 RAISE fnd_api.g_exc_error;
7182 END IF;
7183
7184 -- Check if locator is valid
7185 IF (l_debug = 1) THEN
7186 mydebug('Fetch sub/loc for LPN ');
7187 END IF;
7188
7189 BEGIN
7190 -- WMS PJM Integration, Selecting the resolved concatenated segments instead of concatenated segments
7191 SELECT w.subinventory_code
7192 , inv_project.get_locsegs(w.locator_id, w.organization_id)
7193 , w.license_plate_number
7194 , w.locator_id
7195 , w.lpn_context
7196 INTO l_sub
7197 , l_loc
7198 , l_from_lpn
7199 , l_loc_id
7200 , l_lpn_context
7201 FROM wms_license_plate_numbers w
7202 WHERE w.lpn_id = p_fromlpn_id
7203 AND w.locator_id IS NOT NULL;
7204
7205 IF l_sub IS NULL THEN
7206 -- The calling java code treats this condition as an error
7207
7208 x_match := 10;
7209 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
7210 fnd_msg_pub.ADD;
7211 RAISE fnd_api.g_exc_error;
7212 END IF;
7213
7214 -- bug 2398247
7215 -- verify if sub is active
7216 SELECT COUNT(*)
7217 INTO l_sub_active
7218 FROM mtl_secondary_inventories
7219 WHERE NVL(disable_date, SYSDATE + 1) > SYSDATE
7220 AND organization_id = p_org_id
7221 AND secondary_inventory_name = l_sub;
7222
7223 IF l_sub_active = 0 THEN
7224 x_match := 10;
7225 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SUB');
7226 fnd_msg_pub.ADD;
7227 RAISE fnd_api.g_exc_error;
7228 END IF;
7229
7230 -- verify if locator is active
7231 SELECT COUNT(*)
7232 INTO l_loc_active
7233 FROM mtl_item_locations_kfv
7234 WHERE NVL(disable_date, SYSDATE + 1) > SYSDATE
7235 AND organization_id = p_org_id
7236 AND subinventory_code = l_sub
7237 AND inventory_location_id = l_loc_id;
7238
7239 IF l_loc_active = 0 THEN
7240 x_match := 10;
7241 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LOC');
7242 fnd_msg_pub.ADD;
7243 RAISE fnd_api.g_exc_error;
7244 END IF;
7245 -- Begin fix for 2774506
7246
7247
7248 SELECT locator_id,organization_id,
7249 transaction_header_id,
7250 transaction_uom,
7251 SECONDARY_UOM_CODE -- Bug #4141928
7252 INTO l_locator_id, l_organization_id,
7253 l_transaction_header_id,
7254 l_transaction_uom,
7255 l_sec_transaction_uom -- Bug #4141928
7256 from mtl_material_transactions_temp
7257 where transaction_temp_id = p_temp_id;
7258
7259 select nvl(project_id ,-999) , nvl(task_id ,-999)
7260 into l_mmtt_proj_id , l_mmtt_task_id
7261 from mtl_item_locations
7262 where inventory_location_id = l_locator_id
7263 and organization_id = l_organization_id ;
7264
7265 select nvl(project_id, -999) , nvl(task_id ,-999)
7266 into l_mil_proj_id , l_mil_task_id
7267 from mtl_item_locations
7268 where inventory_location_id = l_loc_id
7269 and organization_id = p_org_id ;
7270
7271 mydebug('mmtt project id = '||l_mmtt_proj_id);
7272 mydebug('mmtt task id = '||l_mmtt_task_id);
7273 mydebug('mil project id = '||l_mil_proj_id);
7274 mydebug('mil task id = '||l_mil_task_id);
7275
7276 if ((l_mil_proj_id <> l_mmtt_proj_id ) or ( l_mil_task_id <> l_mmtt_task_id )) then
7277 mydebug('lpn : the project/tak information does not match');
7278 FND_MESSAGE.SET_NAME('WMS','WMS_CONT_INVALID_LPN');
7279 FND_MSG_PUB.ADD;
7280 RAISE FND_API.G_EXC_ERROR;
7281 end if ;
7282
7283 -- End fix for 2774506
7284
7285
7286 x_sub := l_sub;
7287 x_loc := l_loc;
7288 x_loc_id := l_loc_id;
7289 EXCEPTION
7290 WHEN NO_DATA_FOUND THEN
7291 x_match := 6;
7292 fnd_message.set_name('WMS', 'WMS_TD_LPN_LOC_NOT_FOUND');
7293 fnd_msg_pub.ADD;
7294 RAISE fnd_api.g_exc_error;
7295 END;
7296
7297 IF (l_debug = 1) THEN
7298 mydebug('sub is ' || l_sub);
7299 mydebug('loc is ' || l_loc);
7300 END IF;
7301
7302 -- Check if LPN has already been allocated for any Sales order
7303 -- If LPN has been picked for a sales order then it cannot be picked
7304
7305 IF (l_debug = 1) THEN
7306 mydebug('Checking SO for lpn');
7307 END IF;
7308
7309 BEGIN
7310 SELECT 1
7311 INTO l_so_cnt
7312 FROM wms_license_plate_numbers
7313 WHERE lpn_context = 11
7314 AND lpn_id = p_fromlpn_id
7315 AND organization_id = p_org_id;
7316 EXCEPTION
7317 WHEN NO_DATA_FOUND THEN
7318 l_so_cnt := 0;
7319 END;
7320
7321 IF l_so_cnt > 0 THEN
7322 x_match := 12;
7323 fnd_message.set_name('WMS', 'WMS_LPN_STAGED');
7324 fnd_msg_pub.ADD;
7325 RAISE fnd_api.g_exc_error;
7326 END IF;
7327
7328 -- SELECT primary_uom_code
7329 -- , lot_control_code
7330 ---- , serial_number_control_code
7331 -- INTO l_primary_uom
7332 -- , l_lot_code
7333 -- , l_serial_code
7334 -- FROM mtl_system_items
7335 -- WHERE organization_id = p_org_id
7336 -- AND inventory_item_id = p_item_id;
7337
7338 --Bug5649056: added sub and locator below
7339 SELECT mmtt.transfer_subinventory
7340 , mmtt.subinventory_code
7341 , mmtt.locator_id
7342 INTO l_xfr_sub_code
7343 , l_mmtt_sub
7344 , l_mmtt_loc
7345 FROM mtl_material_transactions_temp mmtt
7346 WHERE mmtt.transaction_temp_id = p_temp_id;
7347
7348 -- Check to see if the item is in the LPN
7349 IF (l_debug = 1) THEN
7350 mydebug('Checking to see if required item,cg,rev,lot exist in lpn..');
7351 END IF;
7352
7353 l_item_cnt := 0;
7354
7355 IF (l_debug = 1) THEN
7356 mydebug('item' || p_item_id || 'LPN' || p_fromlpn_id || 'Org' || p_org_id || ' lot' || p_lot || ' Rev' || p_rev);
7357 END IF;
7358
7359 BEGIN
7360 SELECT 1
7361 INTO l_item_cnt
7362 FROM DUAL
7363 WHERE EXISTS(
7364 SELECT 1
7365 FROM wms_lpn_contents wlc
7366 WHERE wlc.parent_lpn_id = p_fromlpn_id
7367 AND wlc.organization_id = p_org_id
7368 AND wlc.inventory_item_id = p_item_id
7369 AND NVL(wlc.revision, '-999') = NVL(p_rev, '-999'));
7370 EXCEPTION
7371 -- Item/lot/rev combo does not exist in LPN
7372
7373 WHEN NO_DATA_FOUND THEN
7374 IF (l_debug = 1) THEN
7375 mydebug('item lot rev combo does not exist');
7376 END IF;
7377
7378 x_match := 13;
7379 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
7380 fnd_msg_pub.ADD;
7381 RAISE fnd_api.g_exc_error;
7382 END;
7383
7384 IF l_item_cnt > 0
7385 AND l_lot_code > 1 THEN
7386 --Do this only for lot controlled items
7387
7388 BEGIN
7389 SELECT 1
7390 INTO l_item_cnt
7391 FROM DUAL
7392 WHERE EXISTS(
7393 SELECT 1
7394 FROM wms_lpn_contents wlc, mtl_transaction_lots_temp mtlt
7395 WHERE wlc.parent_lpn_id = p_fromlpn_id
7396 AND wlc.organization_id = p_org_id
7397 AND wlc.inventory_item_id = p_item_id
7398 AND NVL(wlc.revision, '-999') = NVL(p_rev, '-999')
7399 AND(mtlt.transaction_temp_id = p_temp_id
7400 AND mtlt.lot_number = wlc.lot_number));
7401 EXCEPTION
7402 -- Item/lot/rev combo does not exist in LPN
7403
7404 WHEN NO_DATA_FOUND THEN
7405 IF (l_debug = 1) THEN
7406 mydebug('lot rev combo for the item does not exist');
7407 END IF;
7408
7409 x_match := 5;
7410 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LOT_LPN');
7411 fnd_msg_pub.ADD;
7412 RAISE fnd_api.g_exc_error;
7413 END;
7414 END IF;
7415
7416 -- Item with the correct lot/revision exists in LPN
7417 IF p_is_sn_alloc = 'Y'
7418 AND p_action = 4 THEN
7419 b_is_serial_control := TRUE;
7420 ELSE
7421 b_is_serial_control := FALSE;
7422 END IF;
7423
7424 IF p_action = 4 THEN
7425 l_is_serial_control := 'Y';
7426 ELSE
7427 l_is_serial_control := 'N';
7428 END IF;
7429
7430 IF l_lot_code > 1 THEN
7431 b_is_lot_control := TRUE;
7432 l_is_lot_control := 'Y';
7433 ELSE
7434 b_is_lot_control := FALSE;
7435 l_is_lot_control := 'N';
7436 END IF;
7437
7438 IF p_rev IS NULL THEN
7439 b_is_revision_control := FALSE;
7440 l_is_revision_control := 'N';
7441 ELSE
7442 b_is_revision_control := TRUE;
7443 l_is_revision_control := 'Y';
7444 END IF;
7445
7446 IF (l_debug = 1) THEN
7447 mydebug('is_serial_control:' || l_is_serial_control);
7448 mydebug('is_lot_control:' || l_is_lot_control);
7449 mydebug('is_revision_control:' || l_is_revision_control);
7450 END IF;
7451
7452 BEGIN
7453 SELECT allocated_lpn_id
7454 INTO l_allocated_lpn_id
7455 FROM mtl_material_transactions_temp
7456 WHERE transaction_temp_id = p_temp_id;
7457 EXCEPTION
7458 WHEN NO_DATA_FOUND THEN
7459 IF (l_debug = 1) THEN
7460 mydebug('transaction does not exist in mmtt');
7461 END IF;
7462
7463 fnd_message.set_name('INV', 'INV_INVALID_TRANSACTION');
7464 fnd_msg_pub.ADD;
7465 RAISE fnd_api.g_exc_error;
7466 END;
7467
7468 -- clear quantity cache before we create qty tree.
7469 inv_quantity_tree_pub.clear_quantity_cache;
7470
7471 -- Check if LPN has items other than the one requested
7472
7473 IF (l_debug = 1) THEN
7474 mydebug('lpn has the requested item ');
7475 END IF;
7476
7477 l_item_cnt2 := 0;
7478 l_lot_cnt := 0;
7479 l_rev_cnt := 0;
7480 l_cg_cnt := 0;
7481 l_item_cnt2 := 0;
7482 l_lot_cnt := 0;
7483 l_rev_cnt := 0;
7484 l_cg_cnt := 0;
7485 l_lpn_include_lpn := 0;
7486
7487 SELECT COUNT(DISTINCT inventory_item_id)
7488 , COUNT(DISTINCT lot_number)
7489 , COUNT(DISTINCT revision)
7490 , COUNT(DISTINCT cost_group_id)
7491 INTO l_item_cnt2
7492 , l_lot_cnt
7493 , l_rev_cnt
7494 , l_cg_cnt
7495 FROM wms_lpn_contents
7496 WHERE parent_lpn_id = p_fromlpn_id
7497 AND organization_id = p_org_id;
7498
7499 SELECT COUNT(*)
7500 INTO l_lpn_include_lpn
7501 FROM wms_license_plate_numbers
7502 WHERE outermost_lpn_id = p_fromlpn_id
7503 AND organization_id = p_org_id;
7504
7505 IF l_item_cnt2 > 1
7506 OR l_rev_cnt > 1
7507 OR l_lpn_include_lpn > 1 THEN
7508 -- LPN has multiple items
7509 -- Such LPN's can be picked but in such cases the user has to
7510 -- manually confirm the LPN.
7511 -- No validation for LPN contents in such a case.
7512
7513 IF (l_debug = 1) THEN
7514 mydebug('lpn has items other than requested item ');
7515 END IF;
7516
7517 x_match := 2;
7518
7519 IF l_lot_code > 1 THEN
7520
7521 -- adding serial allocation checking for lot+serial item
7522 IF p_is_sn_alloc = 'Y'
7523 AND p_action = 4 THEN
7524 IF (l_debug = 1) THEN
7525 mydebug('SN control and SN allocation on');
7526 END IF;
7527
7528 SELECT COUNT(fm_serial_number)
7529 INTO l_serial_exist_cnt
7530 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
7531 WHERE mtlt.transaction_temp_id = p_temp_id
7532 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
7533 AND msnt.fm_serial_number IN(
7534 SELECT serial_number
7535 FROM mtl_serial_numbers
7536 WHERE lpn_id = p_fromlpn_id
7537 AND inventory_item_id = p_item_id
7538 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
7539
7540 IF (l_debug = 1) THEN
7541 mydebug('SN exist count' || l_serial_exist_cnt);
7542 END IF;
7543
7544 IF (l_serial_exist_cnt = 0) THEN
7545 IF (l_debug = 1) THEN
7546 mydebug('No serial allocations have occured or LPN does not have the allocated serials ');
7547 END IF;
7548
7549 -- Serial numbers missing for the transaction
7550 x_match := 9;
7551 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
7552 fnd_msg_pub.ADD;
7553 RAISE fnd_api.g_exc_error;
7554 END IF;
7555 END IF;
7556
7557 l_lpn_pr_qty := 0;
7558 l_lpn_sec_qty := 0; -- Bug #4141928
7559 OPEN lot_csr;
7560
7561 LOOP
7562 FETCH lot_csr INTO l_mtlt_primary_qty, l_mtlt_secondary_qty, l_mtlt_lot_number; -- Bug #4141928
7563 EXIT WHEN lot_csr%NOTFOUND;
7564
7565 IF (l_debug = 1) THEN
7566 mydebug('l_mtlt_lot_number : ' || l_mtlt_lot_number);
7567 mydebug('l_mtlt_primary_qty: ' || l_mtlt_primary_qty);
7568 mydebug('l_mtlt_secondary_qty: ' || l_mtlt_secondary_qty); -- Bug #4141928
7569 END IF;
7570
7571
7572 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
7573 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
7574 -- in order to get correct att.
7575 inv_quantity_tree_pub.update_quantities(
7576 p_api_version_number => 1.0
7577 , p_init_msg_lst => fnd_api.g_false
7578 , x_return_status => l_return_status
7579 , x_msg_count => l_msg_cnt
7580 , x_msg_data => l_msg_data
7581 , p_organization_id => p_org_id
7582 , p_inventory_item_id => p_item_id
7583 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
7584 , p_is_revision_control => b_is_revision_control
7585 , p_is_lot_control => TRUE
7586 , p_is_serial_control => b_is_serial_control
7587 , p_revision => NVL(p_rev, NULL)
7588 , p_lot_number => l_mtlt_lot_number
7589 , p_subinventory_code => l_sub
7590 , p_locator_id => l_loc_id
7591 , p_primary_quantity => -l_mtlt_primary_qty
7592 , p_secondary_quantity => -l_mtlt_secondary_qty -- Bug #4141928
7593 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
7594 , x_qoh => l_qoh
7595 , x_rqoh => l_rqoh
7596 , x_qr => l_qr
7597 , x_qs => l_qs
7598 , x_att => l_att
7599 , x_atr => l_atr
7600 , x_sqoh => l_sqoh -- Bug #4141928
7601 , x_srqoh => l_srqoh -- Bug #4141928
7602 , x_sqr => l_sqr -- Bug #4141928
7603 , x_sqs => l_sqs -- Bug #4141928
7604 , x_satt => l_satt -- Bug #4141928
7605 , x_satr => l_satr -- Bug #4141928
7606 , p_lpn_id => p_fromlpn_id
7607 , p_transfer_subinventory_code => l_xfr_sub_code
7608 );
7609
7610 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
7611 IF (l_debug = 1) THEN
7612 mydebug('after update qty tree for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
7613 mydebug('after update qty tree for lpn l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number);
7614 END IF;
7615 ELSE
7616 IF (l_debug = 1) THEN
7617 mydebug('calling update qty tree with lpn 1st time failed ');
7618 END IF;
7619
7620 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
7621 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
7622 fnd_msg_pub.ADD;
7623 RAISE fnd_api.g_exc_error;
7624 END IF;
7625 --Bug#5649056: only update if subinventory and locator match
7626 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
7627 inv_quantity_tree_pub.update_quantities(
7628 p_api_version_number => 1.0
7629 , p_init_msg_lst => fnd_api.g_false
7630 , x_return_status => l_return_status
7631 , x_msg_count => l_msg_cnt
7632 , x_msg_data => l_msg_data
7633 , p_organization_id => p_org_id
7634 , p_inventory_item_id => p_item_id
7635 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
7636 , p_is_revision_control => b_is_revision_control
7637 , p_is_lot_control => TRUE
7638 , p_is_serial_control => b_is_serial_control
7639 , p_revision => NVL(p_rev, NULL)
7640 , p_lot_number => l_mtlt_lot_number
7641 , p_subinventory_code => l_sub
7642 , p_locator_id => l_loc_id
7643 , p_primary_quantity => -l_mtlt_primary_qty
7644 , p_secondary_quantity => -l_mtlt_secondary_qty -- Bug #4141928
7645 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
7646 , x_qoh => l_qoh
7647 , x_rqoh => l_rqoh
7648 , x_qr => l_qr
7649 , x_qs => l_qs
7650 , x_att => l_att
7651 , x_atr => l_atr
7652 , x_sqoh => l_sqoh -- Bug #4141928
7653 , x_srqoh => l_srqoh -- Bug #4141928
7654 , x_sqr => l_sqr -- Bug #4141928
7655 , x_sqs => l_sqs -- Bug #4141928
7656 , x_satt => l_satt -- Bug #4141928
7657 , x_satr => l_satr -- Bug #4141928
7658 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
7659 , p_transfer_subinventory_code => l_xfr_sub_code
7660 );
7661
7662 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
7663 IF (l_debug = 1) THEN
7664 mydebug('after update qty tree without lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
7665 mydebug('after update qty tree without lpn l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number);
7666 END IF;
7667 ELSE
7668 IF (l_debug = 1) THEN
7669 mydebug('calling update qty tree back without lpn 1st time failed ');
7670 END IF;
7671
7672 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
7673 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
7674 fnd_msg_pub.ADD;
7675 RAISE fnd_api.g_exc_error;
7676 END IF;
7677 END IF;
7678
7679 inv_quantity_tree_pub.query_quantities(
7680 p_api_version_number => 1.0
7681 , p_init_msg_lst => fnd_api.g_false
7682 , x_return_status => l_return_status
7683 , x_msg_count => l_msg_cnt
7684 , x_msg_data => l_msg_data
7685 , p_organization_id => p_org_id
7686 , p_inventory_item_id => p_item_id
7687 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
7688 , p_is_revision_control => b_is_revision_control
7689 , p_is_lot_control => TRUE
7690 , p_is_serial_control => b_is_serial_control
7691 , p_demand_source_type_id => -9999
7692 , p_revision => NVL(p_rev, NULL)
7693 , p_lot_number => l_mtlt_lot_number
7694 , p_subinventory_code => l_sub
7695 , p_locator_id => l_loc_id
7696 , x_qoh => l_qoh
7697 , x_rqoh => l_rqoh
7698 , x_qr => l_qr
7699 , x_qs => l_qs
7700 , x_att => l_att
7701 , x_atr => l_atr
7702 , x_sqoh => l_sqoh -- Bug #4141928
7703 , x_srqoh => l_srqoh -- Bug #4141928
7704 , x_sqr => l_sqr -- Bug #4141928
7705 , x_sqs => l_sqs -- Bug #4141928
7706 , x_satt => l_satt -- Bug #4141928
7707 , x_satr => l_satr -- Bug #4141928
7708 , p_lpn_id => p_fromlpn_id
7709 , p_transfer_subinventory_code => l_xfr_sub_code
7710 , p_grade_code => NULL -- Bug #4141928
7711 );
7712
7713 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
7714 IF (l_att > 0) THEN
7715 l_table_index := l_table_index + 1;
7716
7717 IF (l_debug = 1) THEN
7718 mydebug('l_table_index:' || l_table_index || ' lot_number:' || l_mtlt_lot_number || ' qty: ' || l_att);
7719 END IF;
7720 -- bug 3547725, now no matter what relation it is between l_mtlt_primary_qty and l_att
7721 -- we always use l_att
7722
7723 l_lpn_pr_qty := l_lpn_pr_qty + l_att;
7724 l_lpn_sec_qty := l_lpn_sec_qty + l_satt;
7725 t_lpn_lot_qty_table(l_table_index).lpn_id := p_fromlpn_id;
7726 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
7727 t_lpn_lot_qty_table(l_table_index).pri_qty := l_att;
7728 t_lpn_lot_qty_table(l_table_index).sec_qty := l_satt; -- Bug #4141928
7729 IF (l_primary_uom = p_trx_uom) THEN
7730 t_lpn_lot_qty_table(l_table_index).trx_qty := l_att;
7731 ELSE
7732 t_lpn_lot_qty_table(l_table_index).trx_qty := inv_convert.inv_um_convert(
7733 item_id => p_item_id
7734 ,precision => null
7735 ,from_quantity => l_att
7736 ,from_unit => l_primary_uom
7737 ,to_unit => p_trx_uom
7738 ,from_name => null
7739 ,to_name => null);
7740 END IF;
7741 ELSE
7742 IF (l_debug = 1) THEN
7743 mydebug('LPN does not have lot ' || l_mtlt_lot_number);
7744 END IF;
7745 --mydebug('l_table_index:'||l_table_index||' lot_number:'||l_mtlt_lot_number||' qty: 0 ');
7746 --t_lpn_lot_qty_table(l_table_index).lpn_id := p_fromlpn_id;
7747 --t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
7748 --t_lpn_lot_qty_table(l_table_index).pri_qty := l_mtlt_primary_qty;
7749 END IF;
7750 ELSE
7751 IF (l_debug = 1) THEN
7752 mydebug('calling qty tree 1st time failed ');
7753 END IF;
7754
7755 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
7756 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
7757 fnd_msg_pub.ADD;
7758 RAISE fnd_api.g_exc_error;
7759 END IF;
7760
7761 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
7762 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
7763 -- in order to get correct att.
7764 inv_quantity_tree_pub.update_quantities(
7765 p_api_version_number => 1.0
7766 , p_init_msg_lst => fnd_api.g_false
7767 , x_return_status => l_return_status
7768 , x_msg_count => l_msg_cnt
7769 , x_msg_data => l_msg_data
7770 , p_organization_id => p_org_id
7771 , p_inventory_item_id => p_item_id
7772 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
7773 , p_is_revision_control => b_is_revision_control
7774 , p_is_lot_control => TRUE
7775 , p_is_serial_control => b_is_serial_control
7776 , p_revision => NVL(p_rev, NULL)
7777 , p_lot_number => l_mtlt_lot_number
7778 , p_subinventory_code => l_sub
7779 , p_locator_id => l_loc_id
7780 , p_primary_quantity => l_mtlt_primary_qty
7781 , p_secondary_quantity => l_mtlt_secondary_qty -- Bug #4141928
7782 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
7783 , x_qoh => l_qoh
7784 , x_rqoh => l_rqoh
7785 , x_qr => l_qr
7786 , x_qs => l_qs
7787 , x_att => l_att
7788 , x_atr => l_atr
7789 , x_sqoh => l_sqoh -- Bug #4141928
7790 , x_srqoh => l_srqoh -- Bug #4141928
7791 , x_sqr => l_sqr -- Bug #4141928
7792 , x_sqs => l_sqs -- Bug #4141928
7793 , x_satt => l_satt -- Bug #4141928
7794 , x_satr => l_satr -- Bug #4141928
7795 , p_lpn_id => p_fromlpn_id
7796 , p_transfer_subinventory_code => l_xfr_sub_code
7797 );
7798
7799 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
7800 IF (l_debug = 1) THEN
7801 mydebug('after update qty tree back for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
7802 mydebug('after update qty tree back for lpn l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number);
7803 END IF;
7804 ELSE
7805 IF (l_debug = 1) THEN
7806 mydebug('calling update qty tree back with lpn 1st time failed ');
7807 END IF;
7808
7809 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
7810 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
7811 fnd_msg_pub.ADD;
7812 RAISE fnd_api.g_exc_error;
7813 END IF;
7814 --Bug#5649056: only update if subinventory and locator match
7815 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
7816 inv_quantity_tree_pub.update_quantities(
7817 p_api_version_number => 1.0
7818 , p_init_msg_lst => fnd_api.g_false
7819 , x_return_status => l_return_status
7820 , x_msg_count => l_msg_cnt
7821 , x_msg_data => l_msg_data
7822 , p_organization_id => p_org_id
7823 , p_inventory_item_id => p_item_id
7824 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
7825 , p_is_revision_control => b_is_revision_control
7826 , p_is_lot_control => TRUE
7827 , p_is_serial_control => b_is_serial_control
7828 , p_revision => NVL(p_rev, NULL)
7829 , p_lot_number => l_mtlt_lot_number
7830 , p_subinventory_code => l_sub
7831 , p_locator_id => l_loc_id
7832 , p_primary_quantity => l_mtlt_primary_qty
7833 , p_secondary_quantity => l_mtlt_secondary_qty -- Bug #4141928
7834 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
7835 , x_qoh => l_qoh
7836 , x_rqoh => l_rqoh
7837 , x_qr => l_qr
7838 , x_qs => l_qs
7839 , x_att => l_att
7840 , x_atr => l_atr
7841 , x_sqoh => l_sqoh -- Bug #4141928
7842 , x_srqoh => l_srqoh -- Bug #4141928
7843 , x_sqr => l_sqr -- Bug #4141928
7844 , x_sqs => l_sqs -- Bug #4141928
7845 , x_satt => l_satt -- Bug #4141928
7846 , x_satr => l_satr -- Bug #4141928
7847 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
7848 , p_transfer_subinventory_code => l_xfr_sub_code
7849 );
7850
7851 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
7852 IF (l_debug = 1) THEN
7853 mydebug('after update qty tree back without lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
7854 mydebug('after update qty tree back without lpn l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number);
7855 END IF;
7856 ELSE
7857 IF (l_debug = 1) THEN
7858 mydebug('calling update qty tree back without lpn 1st time failed ');
7859 END IF;
7860
7861 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
7862 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
7863 fnd_msg_pub.ADD;
7864 RAISE fnd_api.g_exc_error;
7865 END IF;
7866 END IF;
7867 END LOOP;
7868
7869 CLOSE lot_csr;
7870 -- Bug #4141928. No changes required for OPM convergence.
7871 -- Let primary qty drive the lpn_match
7872 IF (l_lpn_pr_qty >= l_pr_qty ) THEN
7873 x_match := 5;
7874 ELSE
7875 x_match := 2;
7876 END IF;
7877 -- Bug #4141928. No changes required for OPM convergence.
7878 -- OPM does not have a serial case
7879 -- bug 4277869
7880 /* ELSIF p_is_sn_alloc = 'Y'
7881 AND p_action = 4 THEN
7882 IF (l_debug = 1) THEN
7883 mydebug('SN control and SN allocation on');
7884 END IF;
7885
7886 SELECT COUNT(fm_serial_number)
7887 INTO l_serial_exist_cnt
7888 FROM mtl_serial_numbers_temp msnt
7889 WHERE msnt.transaction_temp_id = p_temp_id
7890 AND msnt.fm_serial_number IN(
7891 SELECT serial_number
7892 FROM mtl_serial_numbers
7893 WHERE lpn_id = p_fromlpn_id
7894 AND inventory_item_id = p_item_id
7895 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
7896
7897 IF (l_debug = 1) THEN
7898 mydebug('SN exist count' || l_serial_exist_cnt);
7899 END IF;
7900
7901 IF (l_serial_exist_cnt = 0) THEN
7902 IF (l_debug = 1) THEN
7903 mydebug('LPN does not have the allocated serials ');
7904 END IF;
7905
7906 -- Serial numbers missing for the transaction
7907 x_match := 9;
7908 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
7909 fnd_msg_pub.ADD;
7910 RAISE fnd_api.g_exc_error;
7911 END IF;
7912
7913 SELECT COUNT(fm_serial_number)
7914 INTO l_total_serial_cnt
7915 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
7916 WHERE mtlt.transaction_temp_id = p_temp_id
7917 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
7918
7919 IF (l_debug = 1) THEN
7920 mydebug('SN tot count' || l_total_serial_cnt);
7921 END IF;
7922
7923 IF (l_total_serial_cnt = l_serial_exist_cnt) THEN
7924 IF (l_debug = 1) THEN
7925 mydebug('LPN matches exactly');
7926 END IF;
7927
7928 --x_match := 1; It can not be exactly match, since lpn contains other items
7929 x_match := 5;
7930 ELSIF(l_total_serial_cnt > l_serial_exist_cnt) THEN
7931 IF (l_debug = 1) THEN
7932 mydebug('LPN has less');
7933 END IF;
7934
7935 --x_match := 3; It can not be fully consumable lpn, since lpn contains other items.
7936 x_match := 2;
7937 l_lpn_pr_qty := l_serial_exist_cnt;
7938 ELSE
7939 IF (l_debug = 1) THEN
7940 mydebug('LPN has extra serials');
7941 END IF;
7942
7943 x_match := 4;
7944 END IF;
7945 -- end of bug 4277869
7946 */
7947 ELSE -- Plain item OR REVISION controlled item
7948 -- or serial controlled
7949 -- bug 4277869
7950 IF p_is_sn_alloc = 'Y'
7951 AND p_action = 4 THEN
7952 IF (l_debug = 1) THEN
7953 mydebug('SN control and SN allocation on');
7954 END IF;
7955
7956 SELECT COUNT(fm_serial_number)
7957 INTO l_serial_exist_cnt
7958 FROM mtl_serial_numbers_temp msnt
7959 WHERE msnt.transaction_temp_id = p_temp_id
7960 AND msnt.fm_serial_number IN(
7961 SELECT serial_number
7962 FROM mtl_serial_numbers
7963 WHERE lpn_id = p_fromlpn_id
7964 AND inventory_item_id = p_item_id
7965 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
7966
7967 IF (l_debug = 1) THEN
7968 mydebug('SN exist count' || l_serial_exist_cnt);
7969 END IF;
7970
7971 IF (l_serial_exist_cnt = 0) THEN
7972 IF (l_debug = 1) THEN
7973 mydebug('LPN does not have the allocated serials ');
7974 END IF;
7975
7976 -- Serial numbers missing for the transaction
7977 x_match := 9;
7978 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
7979 fnd_msg_pub.ADD;
7980 RAISE fnd_api.g_exc_error;
7981 END IF;
7982 END IF;
7983 -- end of bug 4277869
7984
7985 IF (l_debug = 1) THEN
7986 mydebug('Getting total qty in user entered uom..');
7987 END IF;
7988
7989 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
7990 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
7991 -- in order to get correct att.
7992 inv_quantity_tree_pub.update_quantities(
7993 p_api_version_number => 1.0
7994 , p_init_msg_lst => fnd_api.g_false
7995 , x_return_status => l_return_status
7996 , x_msg_count => l_msg_cnt
7997 , x_msg_data => l_msg_data
7998 , p_organization_id => p_org_id
7999 , p_inventory_item_id => p_item_id
8000 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8001 , p_is_revision_control => b_is_revision_control
8002 , p_is_lot_control => FALSE
8003 , p_is_serial_control => b_is_serial_control
8004 , p_revision => NVL(p_rev, NULL)
8005 , p_lot_number => NULL
8006 , p_subinventory_code => l_sub
8007 , p_locator_id => l_loc_id
8008 , p_primary_quantity => -l_pr_qty
8009 , p_secondary_quantity => -l_sec_qty -- Bug #4141928
8010 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8011 , x_qoh => l_qoh
8012 , x_rqoh => l_rqoh
8013 , x_qr => l_qr
8014 , x_qs => l_qs
8015 , x_att => l_att
8016 , x_atr => l_atr
8017 , x_sqoh => l_sqoh -- Bug #4141928
8018 , x_srqoh => l_srqoh -- Bug #4141928
8019 , x_sqr => l_sqr -- Bug #4141928
8020 , x_sqs => l_sqs -- Bug #4141928
8021 , x_satt => l_satt -- Bug #4141928
8022 , x_satr => l_satr -- Bug #4141928
8023 , p_lpn_id => p_fromlpn_id
8024 , p_transfer_subinventory_code => l_xfr_sub_code
8025 );
8026
8027 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8028 IF (l_debug = 1) THEN
8029 mydebug('update qty tree with lpn 2nd time: l_att:' || l_att);
8030 mydebug('update qty tree with lpn 2nd time: l_satt:' || l_satt); -- Bug #4141928
8031 END IF;
8032 ELSE
8033 IF (l_debug = 1) THEN
8034 mydebug('calling update qty tree with lpn 2nd time failed ');
8035 END IF;
8036
8037 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8038 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8039 fnd_msg_pub.ADD;
8040 RAISE fnd_api.g_exc_error;
8041 END IF;
8042 --Bug#5649056: only update if subinventory and locator match
8043 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
8044 inv_quantity_tree_pub.update_quantities(
8045 p_api_version_number => 1.0
8046 , p_init_msg_lst => fnd_api.g_false
8047 , x_return_status => l_return_status
8048 , x_msg_count => l_msg_cnt
8049 , x_msg_data => l_msg_data
8050 , p_organization_id => p_org_id
8051 , p_inventory_item_id => p_item_id
8052 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8053 , p_is_revision_control => b_is_revision_control
8054 , p_is_lot_control => FALSE
8055 , p_is_serial_control => b_is_serial_control
8056 , p_revision => NVL(p_rev, NULL)
8057 , p_lot_number => NULL
8058 , p_subinventory_code => l_sub
8059 , p_locator_id => l_loc_id
8060 , p_primary_quantity => -l_pr_qty
8061 , p_secondary_quantity => -l_sec_qty -- Bug #4141928
8062 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8063 , x_qoh => l_qoh
8064 , x_rqoh => l_rqoh
8065 , x_qr => l_qr
8066 , x_qs => l_qs
8067 , x_att => l_att
8068 , x_atr => l_atr
8069 , x_sqoh => l_sqoh -- Bug #4141928
8070 , x_srqoh => l_srqoh -- Bug #4141928
8071 , x_sqr => l_sqr -- Bug #4141928
8072 , x_sqs => l_sqs -- Bug #4141928
8073 , x_satt => l_satt -- Bug #4141928
8074 , x_satr => l_satr -- Bug #4141928
8075 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
8076 , p_transfer_subinventory_code => l_xfr_sub_code
8077 );
8078
8079 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8080 IF (l_debug = 1) THEN
8081 mydebug('update qty tree without lpn 2nd time:l_att:' || l_att);
8082 mydebug('update qty tree with lpn 2nd time: l_satt:' || l_satt); -- Bug #4141928
8083 END IF;
8084 ELSE
8085 IF (l_debug = 1) THEN
8086 mydebug('calling update qty tree back without lpn 2nd time failed ');
8087 END IF;
8088
8089 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8090 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8091 fnd_msg_pub.ADD;
8092 RAISE fnd_api.g_exc_error;
8093 END IF;
8094 END IF;
8095
8096 inv_quantity_tree_pub.query_quantities(
8097 p_api_version_number => 1.0
8098 , p_init_msg_lst => fnd_api.g_false
8099 , x_return_status => l_return_status
8100 , x_msg_count => l_msg_cnt
8101 , x_msg_data => l_msg_data
8102 , p_organization_id => p_org_id
8103 , p_inventory_item_id => p_item_id
8104 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8105 , p_is_revision_control => b_is_revision_control
8106 , p_is_lot_control => FALSE
8107 , p_is_serial_control => b_is_serial_control
8108 , p_demand_source_type_id => -9999
8109 , p_revision => NVL(p_rev, NULL)
8110 , p_lot_number => NULL
8111 , p_subinventory_code => l_sub
8112 , p_locator_id => l_loc_id
8113 , x_qoh => l_qoh
8114 , x_rqoh => l_rqoh
8115 , x_qr => l_qr
8116 , x_qs => l_qs
8117 , x_att => l_att
8118 , x_atr => l_atr
8119 , x_sqoh => l_sqoh -- Bug #4141928
8120 , x_srqoh => l_srqoh -- Bug #4141928
8121 , x_sqr => l_sqr -- Bug #4141928
8122 , x_sqs => l_sqs -- Bug #4141928
8123 , x_satt => l_satt -- Bug #4141928
8124 , x_satr => l_satr -- Bug #4141928
8125 , p_lpn_id => p_fromlpn_id
8126 , p_transfer_subinventory_code => l_xfr_sub_code
8127 , p_grade_code => NULL -- Bug #4141928
8128 );
8129
8130 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8131 l_lpn_pr_qty := l_att;
8132 l_lpn_sec_qty := l_satt; -- Bug #4141928
8133 -- Bug #4141928. No changes required for OPM convergence.
8134 -- let primary qty drive the lpn match
8135 IF (l_debug = 1) THEN
8136 mydebug('l_att: ' || l_att);
8137 mydebug('l_lpn_pr_qty: ' || l_lpn_pr_qty);
8138 mydebug('l_pr_qty: ' || l_pr_qty);
8139 END IF;
8140 IF (l_lpn_pr_qty >= l_pr_qty) THEN
8141 x_match := 5;
8142 ELSE
8143 x_match := 2;
8144 END IF;
8145 ELSE
8146 IF (l_debug = 1) THEN
8147 mydebug('calling qty tree 2nd time failed ');
8148 END IF;
8149
8150 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8151 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8152 fnd_msg_pub.ADD;
8153 RAISE fnd_api.g_exc_error;
8154 END IF;
8155
8156 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
8157 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
8158 -- in order to get correct att.
8159 inv_quantity_tree_pub.update_quantities(
8160 p_api_version_number => 1.0
8161 , p_init_msg_lst => fnd_api.g_false
8162 , x_return_status => l_return_status
8163 , x_msg_count => l_msg_cnt
8164 , x_msg_data => l_msg_data
8165 , p_organization_id => p_org_id
8166 , p_inventory_item_id => p_item_id
8167 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8168 , p_is_revision_control => b_is_revision_control
8169 , p_is_lot_control => FALSE
8170 , p_is_serial_control => b_is_serial_control
8171 , p_revision => NVL(p_rev, NULL)
8172 , p_lot_number => NULL
8173 , p_subinventory_code => l_sub
8174 , p_locator_id => l_loc_id
8175 , p_primary_quantity => l_pr_qty
8176 , p_secondary_quantity => l_sec_qty -- Bug #4141928
8177 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8178 , x_qoh => l_qoh
8179 , x_rqoh => l_rqoh
8180 , x_qr => l_qr
8181 , x_qs => l_qs
8182 , x_att => l_att
8183 , x_atr => l_atr
8184 , x_sqoh => l_sqoh -- Bug #4141928
8185 , x_srqoh => l_srqoh -- Bug #4141928
8186 , x_sqr => l_sqr -- Bug #4141928
8187 , x_sqs => l_sqs -- Bug #4141928
8188 , x_satt => l_satt -- Bug #4141928
8189 , x_satr => l_satr -- Bug #4141928
8190 , p_lpn_id => p_fromlpn_id
8191 , p_transfer_subinventory_code => l_xfr_sub_code
8192 );
8193
8194 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8195 IF (l_debug = 1) THEN
8196 mydebug('update qty tree back with lpn 2nd time: l_att:' || l_att);
8197 mydebug('update qty tree back with lpn 2nd time: l_satt:' || l_satt); -- Bug #4141928
8198 END IF;
8199 ELSE
8200 IF (l_debug = 1) THEN
8201 mydebug('calling update qty tree with lpn 2nd time failed ');
8202 END IF;
8203
8204 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8205 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8206 fnd_msg_pub.ADD;
8207 RAISE fnd_api.g_exc_error;
8208 END IF;
8209 --Bug#5649056: only update if subinventory and locator match
8210 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
8211 inv_quantity_tree_pub.update_quantities(
8212 p_api_version_number => 1.0
8213 , p_init_msg_lst => fnd_api.g_false
8214 , x_return_status => l_return_status
8215 , x_msg_count => l_msg_cnt
8216 , x_msg_data => l_msg_data
8217 , p_organization_id => p_org_id
8218 , p_inventory_item_id => p_item_id
8219 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8220 , p_is_revision_control => b_is_revision_control
8221 , p_is_lot_control => FALSE
8222 , p_is_serial_control => b_is_serial_control
8223 , p_revision => NVL(p_rev, NULL)
8224 , p_lot_number => NULL
8225 , p_subinventory_code => l_sub
8226 , p_locator_id => l_loc_id
8227 , p_primary_quantity => l_pr_qty
8228 , p_secondary_quantity => l_sec_qty -- Bug #4141928
8229 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8230 , x_qoh => l_qoh
8231 , x_rqoh => l_rqoh
8232 , x_qr => l_qr
8233 , x_qs => l_qs
8234 , x_att => l_att
8235 , x_atr => l_atr
8236 , x_sqoh => l_sqoh -- Bug #4141928
8237 , x_srqoh => l_srqoh -- Bug #4141928
8238 , x_sqr => l_sqr -- Bug #4141928
8239 , x_sqs => l_sqs -- Bug #4141928
8240 , x_satt => l_satt -- Bug #4141928
8241 , x_satr => l_satr -- Bug #4141928
8242 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
8243 , p_transfer_subinventory_code => l_xfr_sub_code
8244 );
8245
8246 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8247 IF (l_debug = 1) THEN
8248 mydebug('update qty tree back without lpn 2nd time:l_att:' || l_att);
8249 mydebug('update qty tree back without lpn 2nd time:l_satt:' || l_satt); -- Bug #4141928
8250 END IF;
8251 ELSE
8252 IF (l_debug = 1) THEN
8253 mydebug('calling update qty tree back without lpn 2nd time failed ');
8254 END IF;
8255
8256 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8257 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8258 fnd_msg_pub.ADD;
8259 RAISE fnd_api.g_exc_error;
8260 END IF;
8261 END IF;
8262 END IF;
8263 ELSE
8264 -- LPN has just the item requested
8265 -- See if quantity/details it has will match the quantity allocated
8266 -- Find out if the item is lot/serial controlled and UOM of item
8267 -- and compare with transaction details
8268
8269 IF (l_debug = 1) THEN
8270 mydebug('lpn has only the requested item ');
8271 END IF;
8272
8273 SELECT primary_quantity, NVL(secondary_transaction_quantity, 0) -- Bug #4141928
8274 INTO l_mmtt_qty, l_mmtt_sec_qty -- Bug #4141928
8275 FROM mtl_material_transactions_temp
8276 WHERE transaction_temp_id = p_temp_id;
8277
8278 -- If item is lot controlled then validate the lots
8279
8280 IF l_lot_code > 1 THEN
8281 IF (l_debug = 1) THEN
8282 mydebug('item is lot controlled');
8283 END IF;
8284
8285 -- initialize
8286 l_check_tolerance := true;
8287 -- If item is also serial controlled and serial allocation is
8288 -- on then count the number of serials allocated which exist
8289 -- in the LPN.
8290 -- If the count is 0 then raise an error
8291
8292 IF p_is_sn_alloc = 'Y'
8293 AND p_action = 4 THEN
8294 IF (l_debug = 1) THEN
8295 mydebug('SN control and SN allocation on');
8296 END IF;
8297
8298 SELECT COUNT(fm_serial_number)
8299 INTO l_serial_exist_cnt
8300 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
8301 WHERE mtlt.transaction_temp_id = p_temp_id
8302 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
8303 AND msnt.fm_serial_number IN(
8304 SELECT serial_number
8305 FROM mtl_serial_numbers
8306 WHERE lpn_id = p_fromlpn_id
8307 AND inventory_item_id = p_item_id
8308 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
8309
8310 IF (l_debug = 1) THEN
8311 mydebug('SN exist count' || l_serial_exist_cnt);
8312 END IF;
8313
8314 IF (l_serial_exist_cnt = 0) THEN
8315 IF (l_debug = 1) THEN
8316 mydebug('No serial allocations have occured or LPN does not have the allocated serials ');
8317 END IF;
8318
8319 -- Serial numbers missing for the transaction
8320 x_match := 9;
8321 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
8322 fnd_msg_pub.ADD;
8323 RAISE fnd_api.g_exc_error;
8324 END IF;
8325 END IF;
8326
8327 -- Check whether the Lots allocated are all in the LPN
8328 -- An LPN can have many lots and items/revisions, check if the
8329 -- lots allocated for the item exist in the LPN and if any of
8330 -- them has quantity less/more than what was suggested.
8331
8332 IF (l_debug = 1) THEN
8333 mydebug('Check whether the LPN has any lot whose quantity exceeds allocated quantity');
8334 END IF;
8335
8336 l_lpn_pr_qty := 0;
8337 l_lpn_sec_qty := 0; -- Bug #4141928
8338 OPEN lot_csr;
8339
8340 LOOP
8341 FETCH lot_csr INTO l_mtlt_primary_qty, l_mtlt_secondary_qty, l_mtlt_lot_number; -- Bug #4141928
8342 EXIT WHEN lot_csr%NOTFOUND;
8343 l_lot_match := 0;
8344
8345 IF (l_debug = 1) THEN
8346 mydebug('l_mtlt_lot_number : ' || l_mtlt_lot_number);
8347 mydebug('l_mtlt_primary_qty: ' || l_mtlt_primary_qty);
8348 mydebug('l_mtlt_secondary_qty: ' || l_mtlt_secondary_qty); -- Bug #4141928
8349 END IF;
8350
8351 l_lot_cnt := l_lot_cnt - 1;
8352
8353 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
8354 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
8355 -- in order to get correct att.
8356 inv_quantity_tree_pub.update_quantities(
8357 p_api_version_number => 1.0
8358 , p_init_msg_lst => fnd_api.g_false
8359 , x_return_status => l_return_status
8360 , x_msg_count => l_msg_cnt
8361 , x_msg_data => l_msg_data
8362 , p_organization_id => p_org_id
8363 , p_inventory_item_id => p_item_id
8364 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8365 , p_is_revision_control => b_is_revision_control
8366 , p_is_lot_control => TRUE
8367 , p_is_serial_control => b_is_serial_control
8368 , p_revision => NVL(p_rev, NULL)
8369 , p_lot_number => l_mtlt_lot_number
8370 , p_subinventory_code => l_sub
8371 , p_locator_id => l_loc_id
8372 , p_primary_quantity => -l_mtlt_primary_qty
8373 , p_secondary_quantity => -l_mtlt_secondary_qty -- Bug #4141928
8374 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8375 , x_qoh => l_qoh
8376 , x_rqoh => l_rqoh
8377 , x_qr => l_qr
8378 , x_qs => l_qs
8379 , x_att => l_att
8380 , x_atr => l_atr
8381 , x_sqoh => l_sqoh -- Bug #4141928
8382 , x_srqoh => l_srqoh -- Bug #4141928
8383 , x_sqr => l_sqr -- Bug #4141928
8384 , x_sqs => l_sqs -- Bug #4141928
8385 , x_satt => l_satt -- Bug #4141928
8386 , x_satr => l_satr -- Bug #4141928
8387 , p_lpn_id => p_fromlpn_id
8388 , p_transfer_subinventory_code => l_xfr_sub_code
8389 );
8390
8391 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8392 IF (l_debug = 1) THEN
8393 mydebug('update qty tree 3rd time for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
8394 mydebug('update qty tree 3rd time for lpn l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number); -- Bug #4141928
8395 END IF;
8396 ELSE
8397 IF (l_debug = 1) THEN
8398 mydebug('calling update qty tree with lpn 3rd time failed ');
8399 END IF;
8400
8401 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8402 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8403 fnd_msg_pub.ADD;
8404 RAISE fnd_api.g_exc_error;
8405 END IF;
8406 --Bug#5649056: only update if subinventory and locator match
8407 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
8408 inv_quantity_tree_pub.update_quantities(
8409 p_api_version_number => 1.0
8410 , p_init_msg_lst => fnd_api.g_false
8411 , x_return_status => l_return_status
8412 , x_msg_count => l_msg_cnt
8413 , x_msg_data => l_msg_data
8414 , p_organization_id => p_org_id
8415 , p_inventory_item_id => p_item_id
8416 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8417 , p_is_revision_control => b_is_revision_control
8418 , p_is_lot_control => TRUE
8419 , p_is_serial_control => b_is_serial_control
8420 , p_revision => NVL(p_rev, NULL)
8421 , p_lot_number => l_mtlt_lot_number
8422 , p_subinventory_code => l_sub
8423 , p_locator_id => l_loc_id
8424 , p_primary_quantity => -l_mtlt_primary_qty
8425 , p_secondary_quantity => -l_mtlt_secondary_qty -- Bug #4141928
8426 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8427 , x_qoh => l_qoh
8428 , x_rqoh => l_rqoh
8429 , x_qr => l_qr
8430 , x_qs => l_qs
8431 , x_att => l_att
8432 , x_atr => l_atr
8433 , x_sqoh => l_sqoh -- Bug #4141928
8434 , x_srqoh => l_srqoh -- Bug #4141928
8435 , x_sqr => l_sqr -- Bug #4141928
8436 , x_sqs => l_sqs -- Bug #4141928
8437 , x_satt => l_satt -- Bug #4141928
8438 , x_satr => l_satr -- Bug #4141928
8439 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
8440 , p_transfer_subinventory_code => l_xfr_sub_code
8441 );
8442
8443 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8444 IF (l_debug = 1) THEN
8445 mydebug('after update without lpn 3rd time l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
8446 mydebug('after update without lpn 3rd time l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number); -- Bug #4141928
8447 END IF;
8448 ELSE
8449 IF (l_debug = 1) THEN
8450 mydebug('calling update qty tree back 3rd time without lpn 3rd time failed ');
8451 END IF;
8452
8453 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8454 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8455 fnd_msg_pub.ADD;
8456 RAISE fnd_api.g_exc_error;
8457 END IF;
8458 END IF;
8459
8460 inv_quantity_tree_pub.query_quantities(
8461 p_api_version_number => 1.0
8462 , p_init_msg_lst => fnd_api.g_false
8463 , x_return_status => l_return_status
8464 , x_msg_count => l_msg_cnt
8465 , x_msg_data => l_msg_data
8466 , p_organization_id => p_org_id
8467 , p_inventory_item_id => p_item_id
8468 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8469 , p_is_revision_control => b_is_revision_control
8470 , p_is_lot_control => TRUE
8471 , p_is_serial_control => b_is_serial_control
8472 , p_demand_source_type_id => -9999
8473 , p_revision => NVL(p_rev, NULL)
8474 , p_lot_number => l_mtlt_lot_number
8475 , p_subinventory_code => l_sub
8476 , p_locator_id => l_loc_id
8477 , x_qoh => l_qoh
8478 , x_rqoh => l_rqoh
8479 , x_qr => l_qr
8480 , x_qs => l_qs
8481 , x_att => l_att
8482 , x_atr => l_atr
8483 , x_sqoh => l_sqoh -- Bug #4141928
8484 , x_srqoh => l_srqoh -- Bug #4141928
8485 , x_sqr => l_sqr -- Bug #4141928
8486 , x_sqs => l_sqs -- Bug #4141928
8487 , x_satt => l_satt -- Bug #4141928
8488 , x_satr => l_satr -- Bug #4141928
8489 , p_lpn_id => p_fromlpn_id
8490 , p_transfer_subinventory_code => l_xfr_sub_code
8491 , p_grade_code => NULL -- Bug #4141928
8492 );
8493
8494 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8495 l_lot_match := 1;
8496
8497 IF (l_att > 0) THEN
8498 l_table_index := l_table_index + 1;
8499 -- bug 3547725, now no matter what relation it is between l_mtlt_primary_qty and l_att
8500 -- we always use l_att
8501
8502 l_lpn_pr_qty := l_lpn_pr_qty + l_att;
8503 l_lpn_sec_qty := l_lpn_sec_qty + l_satt; -- Bug #4141928
8504 IF l_att < l_qoh THEN
8505 l_check_tolerance := false;
8506 IF (l_debug = 1) THEN
8507 mydebug('l_att < l_qoh: set l_check_tolerance to false');
8508 END IF;
8509 END IF;
8510
8511 IF (l_debug = 1) THEN
8512 mydebug('l_table_index:' || l_table_index || ' lot_number:' || l_mtlt_lot_number || ' qty:' || l_att);
8513 END IF;
8514
8515 t_lpn_lot_qty_table(l_table_index).lpn_id := p_fromlpn_id;
8516 t_lpn_lot_qty_table(l_table_index).lot_number := l_mtlt_lot_number;
8517 t_lpn_lot_qty_table(l_table_index).pri_qty := l_att;
8518 t_lpn_lot_qty_table(l_table_index).sec_qty := l_satt; -- Bug #4141928
8519 IF (l_primary_uom = p_trx_uom) THEN
8520 t_lpn_lot_qty_table(l_table_index).trx_qty := l_att;
8521 ELSE
8522 t_lpn_lot_qty_table(l_table_index).trx_qty := inv_convert.inv_um_convert(
8523 item_id => p_item_id
8524 ,precision => null
8525 ,from_quantity => l_att
8526 ,from_unit => l_primary_uom
8527 ,to_unit => p_trx_uom
8528 ,from_name => null
8529 ,to_name => null);
8530 END IF;
8531 ELSE
8532 IF (l_debug = 1) THEN
8533 mydebug('LPN does not have lot ' || l_mtlt_lot_number);
8534 END IF;
8535
8536 IF x_match <> 4 THEN
8537 x_match := 3;
8538 END IF;
8539
8540 l_lot_match := 0;
8541 l_lot_cnt := l_lot_cnt + 1;
8542 l_check_tolerance := false;
8543 IF (l_debug = 1) THEN
8544 mydebug('LPN does not have lot ' || l_mtlt_lot_number);
8545 mydebug('set l_check_tolerance to false');
8546 END IF;
8547 END IF;
8548 ELSE
8549 IF (l_debug = 1) THEN
8550 mydebug('calling qty tree 3rd time failed ');
8551 END IF;
8552
8553 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8554 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8555 fnd_msg_pub.ADD;
8556 RAISE fnd_api.g_exc_error;
8557 END IF;
8558
8559 IF (l_lot_match <> 0)
8560 AND (x_match <> 4) THEN
8561 IF l_mtlt_primary_qty < l_att THEN
8562 IF (l_debug = 1) THEN
8563 mydebug('Qty in LPN for lot ' || l_mtlt_lot_number || ' is more than transaction qty for that lot');
8564 END IF;
8565
8566 x_match := 4;
8567 ELSIF l_mtlt_primary_qty > l_att THEN
8568 IF l_qoh = l_att THEN
8569 IF (l_debug = 1) THEN
8570 mydebug('Qty in LPN for lot ' || l_mtlt_lot_number || ' is less than transaction qty for that lot');
8571 END IF;
8572
8573 x_match := 3;
8574 if (l_lot_string is null) then
8575 l_lot_string := l_mtlt_lot_number;
8576 else
8577 l_lot_string := l_lot_string ||':'||l_mtlt_lot_number;
8578 end if;
8579
8580 if (l_lot_qty_string is null ) then
8581 l_lot_qty_string := l_att;
8582 else
8583 l_lot_qty_string := l_lot_qty_string || ':'||l_att;
8584 end if;
8585
8586 -- Bug #4141928. Build the sec lot qty string
8587 if (l_lot_sec_qty_string is null ) then
8588 l_lot_sec_qty_string := l_satt;
8589 else
8590 l_lot_sec_qty_string := l_lot_sec_qty_string || ':'||l_satt;
8591 end if;
8592 -- Bug #4141928
8593 l_sec_qty_str := l_lot_sec_qty_string;
8594 IF (l_debug = 1) THEN
8595 mydebug('l_lot_string:'||l_lot_string);
8596 mydebug('l_lot_qty_string:'||l_lot_qty_string);
8597 mydebug('l_lot_sec_qty_string:'||l_lot_qty_string);
8598 END IF;
8599
8600 ELSE --l_qoh > l_att
8601 IF (l_debug = 1) THEN
8602 mydebug(
8603 'Qty in LPN for lot '
8604 || l_mtlt_lot_number
8605 || ' is less than transaction qty for that lot and lpn is for multiple task'
8606 );
8607 END IF;
8608
8609 x_match := 4;
8610 END IF;
8611 ELSE
8612 IF x_match <> 3 THEN
8613 IF (l_debug = 1) THEN
8614 mydebug('qty in LPN for lot ' || l_mtlt_lot_number || ' is equal to transaction qty for that lot');
8615 END IF;
8616
8617 IF l_qoh = l_att THEN
8618 IF (l_debug = 1) THEN
8619 mydebug('lpn qoh is equal to att. Exact match');
8620 END IF;
8621 -- Bug #4141928
8622 l_sec_qty_str := l_lot_sec_qty_string;
8623 x_match := 1;
8624 ELSE
8625 IF (l_debug = 1) THEN
8626 mydebug('lpn qoh is great than att. part of lpn is match');
8627 END IF;
8628
8629 x_match := 4;
8630 END IF;
8631 END IF;
8632 END IF;
8633 END IF;
8634
8635 if x_match <> 4 then
8636 IF (l_debug = 1) THEN
8637 mydebug('x_match is not 4.');
8638 END IF;
8639 IF x_match <> 1 THEN
8640 l_check_tolerance := false;
8641 IF (l_debug = 1) THEN
8642 mydebug('x_match is not 1, set l_check_tolerance to false');
8643 END IF;
8644 ELSE
8645 IF (l_debug = 1) THEN
8646 mydebug('x_match is 1 so far');
8647 END IF;
8648 END IF;
8649 else
8650 IF (l_debug = 1) THEN
8651 mydebug('x_match is 4');
8652 END IF;
8653 if l_check_tolerance then
8654 IF (l_debug = 1) THEN
8655 mydebug('l_check_tolerance is true');
8656 END IF;
8657 IF l_mtlt_primary_qty > l_att then
8658 l_check_tolerance := false;
8659 IF (l_debug = 1) THEN
8660 mydebug('lpn has less qty than transaction qty for that lot. set l_check_tolerance to false');
8661 END IF;
8662 else -- in multiple lots case, since l_check_tolerance is for each lot, we will not
8663 -- set l_check_tolerance to false when lpn_lot_qty = allocated_lot_qty.
8664 IF (l_debug = 1) THEN
8665 mydebug('LPN has more or equal qty than transaction qty for that lot');
8666 END IF;
8667 if l_qoh > l_att then
8668 l_check_tolerance := false;
8669 IF (l_debug = 1) THEN
8670 mydebug('l_qoh > l_att, set l_check_tolerance to false');
8671 END IF;
8672 end if;
8673 end if;
8674 end if;
8675 end if;
8676
8677 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
8678 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
8679 -- in order to get correct att.
8680 inv_quantity_tree_pub.update_quantities(
8681 p_api_version_number => 1.0
8682 , p_init_msg_lst => fnd_api.g_false
8683 , x_return_status => l_return_status
8684 , x_msg_count => l_msg_cnt
8685 , x_msg_data => l_msg_data
8686 , p_organization_id => p_org_id
8687 , p_inventory_item_id => p_item_id
8688 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8689 , p_is_revision_control => b_is_revision_control
8690 , p_is_lot_control => TRUE
8691 , p_is_serial_control => b_is_serial_control
8692 , p_revision => NVL(p_rev, NULL)
8693 , p_lot_number => l_mtlt_lot_number
8694 , p_subinventory_code => l_sub
8695 , p_locator_id => l_loc_id
8696 , p_primary_quantity => l_mtlt_primary_qty
8697 , p_secondary_quantity => l_mtlt_secondary_qty -- Bug #4141928
8698 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8699 , x_qoh => l_qoh
8700 , x_rqoh => l_rqoh
8701 , x_qr => l_qr
8702 , x_qs => l_qs
8703 , x_att => l_att
8704 , x_atr => l_atr
8705 , x_sqoh => l_sqoh -- Bug #4141928
8706 , x_srqoh => l_srqoh -- Bug #4141928
8707 , x_sqr => l_sqr -- Bug #4141928
8708 , x_sqs => l_sqs -- Bug #4141928
8709 , x_satt => l_satt -- Bug #4141928
8710 , x_satr => l_satr -- Bug #4141928
8711 , p_lpn_id => p_fromlpn_id
8712 , p_transfer_subinventory_code => l_xfr_sub_code
8713 );
8714
8715 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8716 IF (l_debug = 1) THEN
8717 mydebug('update qty tree back 3rd time for lpn l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
8718 mydebug('update qty tree back 3rd time for lpn l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number); -- Bug #4141928
8719 END IF;
8720 ELSE
8721 IF (l_debug = 1) THEN
8722 mydebug('calling update qty tree with lpn 3rd time failed ');
8723 END IF;
8724
8725 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8726 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8727 fnd_msg_pub.ADD;
8728 RAISE fnd_api.g_exc_error;
8729 END IF;
8730 --Bug#5649056: only update if subinventory and locator match
8731 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
8732 inv_quantity_tree_pub.update_quantities(
8733 p_api_version_number => 1.0
8734 , p_init_msg_lst => fnd_api.g_false
8735 , x_return_status => l_return_status
8736 , x_msg_count => l_msg_cnt
8737 , x_msg_data => l_msg_data
8738 , p_organization_id => p_org_id
8739 , p_inventory_item_id => p_item_id
8740 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8741 , p_is_revision_control => b_is_revision_control
8742 , p_is_lot_control => TRUE
8743 , p_is_serial_control => b_is_serial_control
8744 , p_revision => NVL(p_rev, NULL)
8745 , p_lot_number => l_mtlt_lot_number
8746 , p_subinventory_code => l_sub
8747 , p_locator_id => l_loc_id
8748 , p_primary_quantity => l_mtlt_primary_qty
8749 , p_secondary_quantity => l_mtlt_secondary_qty -- Bug #4141928
8750 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8751 , x_qoh => l_qoh
8752 , x_rqoh => l_rqoh
8753 , x_qr => l_qr
8754 , x_qs => l_qs
8755 , x_att => l_att
8756 , x_atr => l_atr
8757 , x_sqoh => l_sqoh -- Bug #4141928
8758 , x_srqoh => l_srqoh -- Bug #4141928
8759 , x_sqr => l_sqr -- Bug #4141928
8760 , x_sqs => l_sqs -- Bug #4141928
8761 , x_satt => l_satt -- Bug #4141928
8762 , x_satr => l_satr -- Bug #4141928
8763 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
8764 , p_transfer_subinventory_code => l_xfr_sub_code
8765 );
8766
8767 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8768 IF (l_debug = 1) THEN
8769 mydebug('after update qty tree back without lpn 3rd time l_att:' || l_att || ' for lot:' || l_mtlt_lot_number);
8770 mydebug('after update qty tree back without lpn 3rd time l_satt:' || l_satt || ' for lot:' || l_mtlt_lot_number); -- Bug #4141928
8771 END IF;
8772 ELSE
8773 IF (l_debug = 1) THEN
8774 mydebug('calling update qty tree back without lpn 3rd time failed ');
8775 END IF;
8776
8777 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8778 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8779 fnd_msg_pub.ADD;
8780 RAISE fnd_api.g_exc_error;
8781 END IF;
8782 END IF;
8783 END LOOP;
8784
8785 CLOSE lot_csr;
8786
8787 IF l_lot_cnt > 0 THEN
8788 IF (l_debug = 1) THEN
8789 mydebug('l_lot_cnt: '||l_lot_cnt||' l_lot_cnt > 0');
8790 mydebug('set l_check_tolerance to false');
8791 END IF;
8792 l_check_tolerance := false;
8793 x_match := 4;
8794 END IF;
8795
8796 -- Now that all the lots have been validated, check whether the serial
8797 -- numbers allocated match the ones in the lpn.
8798
8799 -- Bug #4141928. No changes required for OPM convergence.
8800 -- since this is a serial context
8801 IF p_is_sn_alloc = 'Y'
8802 AND p_action = 4 THEN
8803
8804 SELECT COUNT(fm_serial_number)
8805 INTO l_total_serial_cnt
8806 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt
8807 WHERE mtlt.transaction_temp_id = p_temp_id
8808 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
8809
8810 IF (l_debug = 1) THEN
8811 mydebug('SN tot count' || l_total_serial_cnt);
8812 END IF;
8813
8814 IF (x_match = 1
8815 OR x_match = 3 ) THEN
8816 IF (l_total_serial_cnt = l_serial_exist_cnt) THEN
8817 IF (l_debug = 1) THEN
8818 mydebug('LPN matches exactly');
8819 END IF;
8820 x_match := 1;
8821 ELSIF(l_total_serial_cnt > l_serial_exist_cnt) THEN
8822 IF (l_debug = 1) THEN
8823 mydebug('LPN has less');
8824 END IF;
8825 x_match := 3;
8826 ELSE
8827 IF (l_debug = 1) THEN
8828 mydebug('LPN has extra serials');
8829 END IF;
8830 x_match := 4;
8831 END IF;
8832 END IF;
8833 IF (l_check_tolerance) THEN
8834 IF (l_total_serial_cnt > l_serial_exist_cnt) THEN
8835 IF (l_debug = 1) THEN
8836 mydebug('There are serials which is not inside the lpn. set l_check_tolerance to false');
8837 END IF;
8838 l_check_tolerance := false;
8839 END IF;
8840 END IF;
8841 END IF;
8842
8843 IF l_check_tolerance THEN
8844 l_overpicked_qty := l_lpn_pr_qty - l_pr_qty;
8845 IF (l_debug = 1) THEN
8846 mydebug('end of mutiple lots, l_check_tolerance is true and l_overpicked_qty: '||l_overpicked_qty);
8847 END IF;
8848 END IF;
8849
8850 ELSE -- Item is not lot controlled
8851 IF (l_debug = 1) THEN
8852 mydebug('Not Lot controlled ..');
8853 END IF;
8854 -- initialize
8855 l_check_tolerance := false;
8856 -- Check serial numbers if serial controlled and serial
8857 -- allocation is turned on
8858
8859 -- Bug #4141928. No changes required for OPM convergence.
8860 -- since this is a serial context
8861 IF p_is_sn_alloc = 'Y'
8862 AND p_action = 4 THEN
8863 IF (l_debug = 1) THEN
8864 mydebug('SN control and SN allocation on');
8865 END IF;
8866
8867 SELECT COUNT(fm_serial_number)
8868 INTO l_serial_exist_cnt
8869 FROM mtl_serial_numbers_temp msnt
8870 WHERE msnt.transaction_temp_id = p_temp_id
8871 AND msnt.fm_serial_number IN(
8872 SELECT serial_number
8873 FROM mtl_serial_numbers
8874 WHERE lpn_id = p_fromlpn_id
8875 AND inventory_item_id = p_item_id
8876 AND NVL(revision, '-999') = NVL(p_rev, '-999'));
8877
8878
8879 IF (l_debug = 1) THEN
8880 mydebug('SN exist count' || l_serial_exist_cnt);
8881 END IF;
8882
8883 IF (l_serial_exist_cnt = 0) THEN
8884 IF (l_debug = 1) THEN
8885 mydebug('LPN does not have the allocated serials ');
8886 END IF;
8887
8888 -- Serial numbers missing for the transaction
8889 x_match := 9;
8890 fnd_message.set_name('INV', 'INV_INT_SERMISEXP');
8891 fnd_msg_pub.ADD;
8892 RAISE fnd_api.g_exc_error;
8893 END IF;
8894 END IF;
8895
8896 -- Get qty
8897 IF (l_debug = 1) THEN
8898 mydebug('get lpn quantity ');
8899 END IF;
8900
8901 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
8902 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
8903 -- in order to get correct att.
8904 inv_quantity_tree_pub.update_quantities(
8905 p_api_version_number => 1.0
8906 , p_init_msg_lst => fnd_api.g_false
8907 , x_return_status => l_return_status
8908 , x_msg_count => l_msg_cnt
8909 , x_msg_data => l_msg_data
8910 , p_organization_id => p_org_id
8911 , p_inventory_item_id => p_item_id
8912 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8913 , p_is_revision_control => b_is_revision_control
8914 , p_is_lot_control => FALSE
8915 , p_is_serial_control => b_is_serial_control
8916 , p_revision => NVL(p_rev, NULL)
8917 , p_lot_number => NULL
8918 , p_subinventory_code => l_sub
8919 , p_locator_id => l_loc_id
8920 , p_primary_quantity => -l_mmtt_qty
8921 , p_secondary_quantity => -l_mmtt_sec_qty -- Bug #4141928
8922 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8923 , x_qoh => l_qoh
8924 , x_rqoh => l_rqoh
8925 , x_qr => l_qr
8926 , x_qs => l_qs
8927 , x_att => l_att
8928 , x_atr => l_atr
8929 , x_sqoh => l_sqoh -- Bug #4141928
8930 , x_srqoh => l_srqoh -- Bug #4141928
8931 , x_sqr => l_sqr -- Bug #4141928
8932 , x_sqs => l_sqs -- Bug #4141928
8933 , x_satt => l_satt -- Bug #4141928
8934 , x_satr => l_satr -- Bug #4141928
8935 , p_lpn_id => p_fromlpn_id
8936 , p_transfer_subinventory_code => l_xfr_sub_code
8937 );
8938
8939 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8940 IF (l_debug = 1) THEN
8941 mydebug('update qty tree with lpn 4th time: l_att:' || l_att);
8942 mydebug('update qty tree with lpn 4th time: l_satt:' || l_satt); -- Bug #4141928
8943 END IF;
8944 ELSE
8945 IF (l_debug = 1) THEN
8946 mydebug('calling update qty tree with lpn 4th time failed ');
8947 END IF;
8948
8949 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
8950 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
8951 fnd_msg_pub.ADD;
8952 RAISE fnd_api.g_exc_error;
8953 END IF;
8954 --Bug#5649056: only update if subinventory and locator match
8955 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
8956
8957 inv_quantity_tree_pub.update_quantities(
8958 p_api_version_number => 1.0
8959 , p_init_msg_lst => fnd_api.g_false
8960 , x_return_status => l_return_status
8961 , x_msg_count => l_msg_cnt
8962 , x_msg_data => l_msg_data
8963 , p_organization_id => p_org_id
8964 , p_inventory_item_id => p_item_id
8965 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
8966 , p_is_revision_control => b_is_revision_control
8967 , p_is_lot_control => FALSE
8968 , p_is_serial_control => b_is_serial_control
8969 , p_revision => NVL(p_rev, NULL)
8970 , p_lot_number => NULL
8971 , p_subinventory_code => l_sub
8972 , p_locator_id => l_loc_id
8973 , p_primary_quantity => -l_mmtt_qty
8974 , p_secondary_quantity => -l_mmtt_sec_qty -- Bug #4141928
8975 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
8976 , x_qoh => l_qoh
8977 , x_rqoh => l_rqoh
8978 , x_qr => l_qr
8979 , x_qs => l_qs
8980 , x_att => l_att
8981 , x_atr => l_atr
8982 , x_sqoh => l_sqoh -- Bug #4141928
8983 , x_srqoh => l_srqoh -- Bug #4141928
8984 , x_sqr => l_sqr -- Bug #4141928
8985 , x_sqs => l_sqs -- Bug #4141928
8986 , x_satt => l_satt -- Bug #4141928
8987 , x_satr => l_satr -- Bug #4141928
8988 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
8989 , p_transfer_subinventory_code => l_xfr_sub_code
8990 );
8991
8992 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8993 IF (l_debug = 1) THEN
8994 mydebug('update qty tree without lpn 4th time:l_att:' || l_att);
8995 mydebug('update qty tree without lpn 4th time:l_satt:' || l_satt); -- Bug #4141928
8996 END IF;
8997 ELSE
8998 IF (l_debug = 1) THEN
8999 mydebug('calling update qty tree without lpn 4th time failed ');
9000 END IF;
9001
9002 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
9003 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
9004 fnd_msg_pub.ADD;
9005 RAISE fnd_api.g_exc_error;
9006 END IF;
9007 END IF;
9008
9009 inv_quantity_tree_pub.query_quantities(
9010 p_api_version_number => 1.0
9011 , p_init_msg_lst => fnd_api.g_false
9012 , x_return_status => l_return_status
9013 , x_msg_count => l_msg_cnt
9014 , x_msg_data => l_msg_data
9015 , p_organization_id => p_org_id
9016 , p_inventory_item_id => p_item_id
9017 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode --??
9018 , p_is_revision_control => b_is_revision_control
9019 , p_is_lot_control => FALSE
9020 , p_is_serial_control => b_is_serial_control
9021 , p_demand_source_type_id => -9999
9022 , p_revision => NVL(p_rev, NULL)
9023 , p_lot_number => NULL
9024 , p_subinventory_code => l_sub
9025 , p_locator_id => l_loc_id
9026 , x_qoh => l_qoh
9027 , x_rqoh => l_rqoh
9028 , x_qr => l_qr
9029 , x_qs => l_qs
9030 , x_att => l_att
9031 , x_atr => l_atr
9032 , x_sqoh => l_sqoh -- Bug #4141928
9033 , x_srqoh => l_srqoh -- Bug #4141928
9034 , x_sqr => l_sqr -- Bug #4141928
9035 , x_sqs => l_sqs -- Bug #4141928
9036 , x_satt => l_satt -- Bug #4141928
9037 , x_satr => l_satr -- Bug #4141928
9038 , p_lpn_id => p_fromlpn_id
9039 , p_transfer_subinventory_code => l_xfr_sub_code
9040 , p_grade_code => NULL -- Bug #4141928
9041 );
9042
9043 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
9044 IF (l_debug = 1) THEN
9045 mydebug('lpn quantity = ' || l_att);
9046 mydebug('lpn sec quantity = ' || l_satt);
9047 END IF;
9048
9049 -- Bug #4141928. No changes required for OPM convergence.
9050 -- let primary qty drive the lpn match
9051 IF l_mmtt_qty = l_att THEN
9052 IF l_qoh = l_att THEN
9053 -- LPN is a match!
9054 IF (l_debug = 1) THEN
9055 mydebug('LPN matched');
9056 END IF;
9057 -- Bug #4141928
9058 l_sec_qty_str := l_lpn_sec_qty;
9059 x_match := 1;
9060 ELSE
9061 -- LPN is for multiple task
9062 IF (l_debug = 1) THEN
9063 mydebug('LPN has multiple task.');
9064 END IF;
9065
9066 x_match := 4;
9067 END IF;
9068
9069 ELSIF l_mmtt_qty > l_att THEN
9070 IF l_qoh = l_att THEN
9071 IF (l_debug = 1) THEN
9072 mydebug('lpn has less requested qty and lpn is whole allocation');
9073 END IF;
9074 -- Bug #4141928
9075 l_sec_qty_str := l_lpn_sec_qty;
9076
9077 x_match := 3;
9078 ELSE
9079 IF (l_debug = 1) THEN
9080 mydebug('lpn has less than requested qty and lpn is partial allocation');
9081 END IF;
9082
9083 x_match := 4;
9084 END IF;
9085
9086 l_lpn_pr_qty := l_att;
9087 l_lpn_sec_qty := l_satt; -- Bug #4141928
9088 ELSE
9089 x_match := 4;
9090
9091 --bug 3547725
9092 l_lpn_pr_qty := l_att;
9093 l_lpn_sec_qty := l_satt; -- Bug #4141928
9094 IF l_qoh = l_att THEN
9095 --{{ calculate l_overpicked_qty for vanilla and serial item}}
9096 l_check_tolerance := true;
9097 l_overpicked_qty := l_lpn_pr_qty - l_mmtt_qty;
9098 IF (l_debug = 1) THEN
9099 mydebug('lpn has more than requested qty for loose or serial controlled item.');
9100 mydebug('l_over_picked_qty is: '||l_overpicked_qty);
9101 END IF;
9102 END IF;
9103 END IF;
9104 ELSE
9105 IF (l_debug = 1) THEN
9106 mydebug('calling qty tree 4th time failed');
9107 END IF;
9108
9109 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
9110 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
9111 fnd_msg_pub.ADD;
9112 RAISE fnd_api.g_exc_error;
9113 END IF;
9114
9115 IF NVL(l_allocated_lpn_id, 0) = p_fromlpn_id THEN
9116 --from lpn is the same as allocated_lpn, we need to update qty tree as negative qty
9117 -- in order to get correct att.
9118 inv_quantity_tree_pub.update_quantities(
9119 p_api_version_number => 1.0
9120 , p_init_msg_lst => fnd_api.g_false
9121 , x_return_status => l_return_status
9122 , x_msg_count => l_msg_cnt
9123 , x_msg_data => l_msg_data
9124 , p_organization_id => p_org_id
9125 , p_inventory_item_id => p_item_id
9126 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
9127 , p_is_revision_control => b_is_revision_control
9128 , p_is_lot_control => FALSE
9129 , p_is_serial_control => b_is_serial_control
9130 , p_revision => NVL(p_rev, NULL)
9131 , p_lot_number => NULL
9132 , p_subinventory_code => l_sub
9133 , p_locator_id => l_loc_id
9134 , p_primary_quantity => l_mmtt_qty
9135 , p_secondary_quantity => l_mmtt_sec_qty -- Bug #4141928
9136 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
9137 , x_qoh => l_qoh
9138 , x_rqoh => l_rqoh
9139 , x_qr => l_qr
9140 , x_qs => l_qs
9141 , x_att => l_att
9142 , x_atr => l_atr
9143 , x_sqoh => l_sqoh -- Bug #4141928
9144 , x_srqoh => l_srqoh -- Bug #4141928
9145 , x_sqr => l_sqr -- Bug #4141928
9146 , x_sqs => l_sqs -- Bug #4141928
9147 , x_satt => l_satt -- Bug #4141928
9148 , x_satr => l_satr -- Bug #4141928
9149 , p_lpn_id => p_fromlpn_id
9150 , p_transfer_subinventory_code => l_xfr_sub_code
9151 );
9152
9153 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
9154 IF (l_debug = 1) THEN
9155 mydebug('update qty tree back with lpn 4th time: l_att:' || l_att);
9156 mydebug('update qty tree back with lpn 4th time: l_satt:' || l_satt); -- Bug #4141928
9157 END IF;
9158 ELSE
9159 IF (l_debug = 1) THEN
9160 mydebug('calling update qty tree back with lpn 4th time failed ');
9161 END IF;
9162
9163 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
9164 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
9165 fnd_msg_pub.ADD;
9166 RAISE fnd_api.g_exc_error;
9167 END IF;
9168 --Bug#5649056: only update if subinventory and locator match
9169 ELSIF ( l_lpn_sub = l_mmtt_sub AND l_lpn_loc = l_mmtt_loc ) THEN
9170 inv_quantity_tree_pub.update_quantities(
9171 p_api_version_number => 1.0
9172 , p_init_msg_lst => fnd_api.g_false
9173 , x_return_status => l_return_status
9174 , x_msg_count => l_msg_cnt
9175 , x_msg_data => l_msg_data
9176 , p_organization_id => p_org_id
9177 , p_inventory_item_id => p_item_id
9178 , p_tree_mode => inv_quantity_tree_pub.g_transaction_mode
9179 , p_is_revision_control => b_is_revision_control
9180 , p_is_lot_control => FALSE
9181 , p_is_serial_control => b_is_serial_control
9182 , p_revision => NVL(p_rev, NULL)
9183 , p_lot_number => NULL
9184 , p_subinventory_code => l_sub
9185 , p_locator_id => l_loc_id
9186 , p_primary_quantity => l_mmtt_qty
9187 , p_secondary_quantity => l_mmtt_sec_qty -- Bug #4141928
9188 , p_quantity_type => inv_quantity_tree_pvt.g_qs_txn
9189 , x_qoh => l_qoh
9190 , x_rqoh => l_rqoh
9191 , x_qr => l_qr
9192 , x_qs => l_qs
9193 , x_att => l_att
9194 , x_atr => l_atr
9195 , x_sqoh => l_sqoh -- Bug #4141928
9196 , x_srqoh => l_srqoh -- Bug #4141928
9197 , x_sqr => l_sqr -- Bug #4141928
9198 , x_sqs => l_sqs -- Bug #4141928
9199 , x_satt => l_satt -- Bug #4141928
9200 , x_satr => l_satr -- Bug #4141928
9201 -- , p_lpn_id => p_fromlpn_id withour lpn_id, only to locator level
9202 , p_transfer_subinventory_code => l_xfr_sub_code
9203 );
9204
9205 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
9206 IF (l_debug = 1) THEN
9207 mydebug('update qty tree back without lpn 4th time:l_att:' || l_att);
9208 mydebug('update qty tree back without lpn 4th time:l_satt:' || l_satt);
9209 END IF;
9210 ELSE
9211 IF (l_debug = 1) THEN
9212 mydebug('calling update qty tree back without lpn 4th time failed ');
9213 END IF;
9214
9215 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
9216 fnd_message.set_token('ROUTINE', 'INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
9217 fnd_msg_pub.ADD;
9218 RAISE fnd_api.g_exc_error;
9219 END IF;
9220 END IF;
9221
9222 -- If the LPN quantity exactly matches/ has less than, the requested
9223 -- quantity then match the serial numbers also
9224
9225 -- Bug #4141928. No changes required for OPM convergence.
9226 -- Since this is a serial context
9227 IF p_is_sn_alloc = 'Y'
9228 AND p_action = 4 THEN
9229
9230 SELECT COUNT(fm_serial_number)
9231 INTO l_total_serial_cnt
9232 FROM mtl_serial_numbers_temp msnt
9233 WHERE msnt.transaction_temp_id = p_temp_id;
9234
9235 IF (l_debug = 1) THEN
9236 mydebug('SN tot count' || l_total_serial_cnt);
9237 END IF;
9238 IF (x_match = 1
9239 OR x_match = 3 ) THEN
9240
9241 IF (l_total_serial_cnt = l_serial_exist_cnt) THEN
9242 IF (l_debug = 1) THEN
9243 mydebug('LPN matches exactly.');
9244 END IF;
9245
9246 x_match := 1;
9247
9248 ELSIF(l_total_serial_cnt > l_serial_exist_cnt) THEN
9249 IF (l_debug = 1) THEN
9250 mydebug('LPN has less.');
9251 END IF;
9252
9253 x_match := 3;
9254 l_lpn_pr_qty := l_serial_exist_cnt;
9255 ELSE
9256 IF (l_debug = 1) THEN
9257 mydebug('LPN has extra serials.');
9258 END IF;
9259 x_match := 4;
9260 END IF;
9261 END IF;
9262 IF (l_check_tolerance) THEN
9263 IF l_total_serial_cnt > l_serial_exist_cnt THEN
9264 IF (l_debug = 1) THEN
9265 mydebug('There are serials which is not inside the lpn. set l_check_tolerance to false');
9266 END IF;
9267 l_check_tolerance := false;
9268 END IF;
9269 END IF;
9270 END IF;
9271
9272
9273 IF (l_debug = 1) THEN
9274 mydebug('After 4');
9275 END IF;
9276 END IF; -- lot control check
9277 END IF; -- lpn has only one item
9278
9279 --check ship tolerance
9280 IF p_pickOverNoException = 'Y'
9281 AND l_check_tolerance
9282 AND p_transaction_action_id = 28
9283 AND x_match = 4
9284 THEN
9285 IF (l_debug = 1) THEN
9286 mydebug('calling INV_Replenish_Detail_PUB.check_overpick');
9287 mydebug('p_transaction_temp_id: '||p_temp_id);
9288 mydebug('p_overpicked_qty: '||l_overpicked_qty);
9289 mydebug('p_item_id:' ||p_item_id);
9290 mydebug('p_rev:' ||p_rev);
9291 mydebug('p_lot_num: NULL');
9292 mydebug('p_lot_exp_date: NULL');
9293 mydebug('p_sub: '||l_sub);
9294 mydebug('p_locator_id: '||l_locator_id);
9295 mydebug('p_lpn_id: '||p_fromlpn_id);
9296
9297 END IF;
9298 INV_Replenish_Detail_PUB.check_overpick(
9299 p_transaction_temp_id => p_temp_id
9300 , p_overpicked_qty => l_overpicked_qty
9301 , p_item_id => p_item_id
9302 , p_rev => p_rev
9303 , p_lot_num => NULL
9304 , p_lot_exp_date => NULL
9305 , p_sub => l_sub
9306 , p_locator_id => l_locator_id
9307 , p_lpn_id => p_fromlpn_id
9308 , x_check_overpick_passed => l_check_overpick_passed--OUT NOCOPY VARCHAR
9309 , x_ovpk_error_code => l_overpick_error_code --OUT NOCOPY NUMBER
9310 , x_return_status => l_return_status
9311 , x_msg_count => l_msg_cnt
9312 , x_msg_data => l_msg_data
9313 );
9314
9315
9316 IF x_return_status = fnd_api.g_ret_sts_error THEN
9317 RAISE fnd_api.g_exc_error;
9318 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
9319 RAISE fnd_api.g_exc_unexpected_error;
9320 END IF;
9321
9322 IF l_check_overpick_passed = 'Y' THEN
9323 x_lpnpickedasis := 'Y';
9324 ELSE
9325 IF (l_debug = 1) THEN
9326 mydebug('over picking is not passed. the Error code is: ' || l_overpick_error_code);
9327 END IF;
9328 END IF;
9329
9330 END IF;
9331
9332
9333 IF x_match = 1
9334 OR x_match = 3 THEN
9335 IF p_action = 4 THEN
9336 -- serial controlled - CHECK serial status
9337 IF (l_debug = 1) THEN
9338 mydebug('x_match is ' || x_match || ' and item is serial controlled ');
9339 END IF;
9340
9341 OPEN ser_csr;
9342
9343 LOOP
9344 FETCH ser_csr INTO l_serial_number;
9345 EXIT WHEN ser_csr%NOTFOUND;
9346
9347 IF inv_material_status_grp.is_status_applicable(
9348 p_wms_installed => p_wms_installed
9349 , p_trx_status_enabled => NULL
9350 , p_trx_type_id => p_transaction_type_id
9351 , p_lot_status_enabled => NULL
9352 , p_serial_status_enabled => NULL
9353 , p_organization_id => p_org_id
9354 , p_inventory_item_id => p_item_id
9355 , p_sub_code => x_sub
9356 , p_locator_id => NULL
9357 , p_lot_number => p_lot
9358 , p_serial_number => l_serial_number
9359 , p_object_type => 'A'
9360 ) = 'N' THEN
9361 IF (l_debug = 1) THEN
9362 mydebug('After 6');
9363 END IF;
9364
9365 x_match := 11;
9366 CLOSE ser_csr;
9367 fnd_message.set_name('INV', 'INV_SER_STATUS_NA');
9368 fnd_message.set_token('TOKEN', l_serial_number);
9369 fnd_msg_pub.ADD;
9370 RAISE fnd_api.g_exc_error;
9371 END IF;
9372 END LOOP;
9373
9374 CLOSE ser_csr;
9375 ELSE
9376 l_serial_number := NULL;
9377
9378 -- Check whether the LPN status is applicable for this transaction
9379 IF inv_material_status_grp.is_status_applicable(
9380 p_wms_installed => p_wms_installed
9381 , p_trx_status_enabled => NULL
9382 , p_trx_type_id => p_transaction_type_id
9383 , p_lot_status_enabled => NULL
9384 , p_serial_status_enabled => NULL
9385 , p_organization_id => p_org_id
9386 , p_inventory_item_id => p_item_id
9387 , p_sub_code => x_sub
9388 , p_locator_id => NULL
9389 , p_lot_number => p_lot
9390 , p_serial_number => l_serial_number
9391 , p_object_type => 'A'
9392 ) = 'N' THEN
9393 x_match := 8;
9394 -- LPN status is invalid for this operation
9395
9396 fnd_message.set_name('INV', 'INV_INVALID_LPN_STATUS');
9397 fnd_message.set_token('TOKEN1', TO_CHAR(p_fromlpn_id));
9398 fnd_msg_pub.ADD;
9399 RAISE fnd_api.g_exc_error;
9400 END IF;
9401 END IF;
9402 END IF;
9403
9404 IF (l_debug = 1) THEN
9405 mydebug('x_match : ' || x_match);
9406 mydebug('p_is_sn_alloc : ' || p_is_sn_alloc);
9407 mydebug('p_action : ' || p_action);
9408 mydebug('l_lpn_pr_qty (in primary uom): ' || l_lpn_pr_qty);
9409 END IF;
9410
9411 -- Now l_lpn_pr_qty is in primary uom, need to convert l_lpn_trx_qty in transaction uom (p_trx_uom)
9412 -- if they are different
9413 IF (p_trx_uom <> l_primary_uom) THEN
9414 l_lpn_trx_qty := inv_convert.inv_um_convert(
9415 item_id => p_item_id
9416 ,precision => null
9417 ,from_quantity => l_lpn_pr_qty
9418 ,from_unit => l_primary_uom
9419 ,to_unit => p_trx_uom
9420 ,from_name => null
9421 ,to_name => null);
9422 IF (l_debug = 1) THEN
9423 mydebug('l_lpn_trx_qty :' || l_lpn_trx_qty);
9424 END IF;
9425 ELSE
9426 l_lpn_trx_qty := l_lpn_pr_qty;
9427 END IF;
9428
9429
9430
9431 -- populate the temp table to be used in lot and serial processing
9432 -- ideally this should be done during above process for each case, need
9433 -- revisit them later on
9434
9435
9436 delete from wms_allocations_gtmp;
9437
9438 -- Bug #4141928. No changes required for OPM convergence.
9439 -- Since this is a serial context
9440 IF p_is_sn_alloc = 'Y'
9441 AND p_action = 4 THEN
9442 IF (l_debug = 1) THEN
9443 mydebug('SN control and SN allocation on');
9444 END IF;
9445
9446 IF l_lot_code > 1 THEN
9447
9448 INSERT INTO WMS_ALLOCATIONS_GTMP
9449 (lot_number,
9450 serial_number,
9451 transaction_quantity,
9452 primary_quantity)
9453 SELECT mtlt.lot_number,fm_serial_number,1,1
9454 FROM mtl_serial_numbers_temp msnt,
9455 mtl_transaction_lots_temp mtlt,
9456 mtl_serial_numbers msn
9457 WHERE mtlt.transaction_temp_id = p_temp_id
9458 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
9459 AND msnt.fm_serial_number = msn.serial_number
9460 AND msn.lpn_id = p_fromlpn_id
9461 AND msn.inventory_item_id = p_item_id;
9462
9463 -- jxlu 10/12/04 start
9464 IF (x_lpnpickedasis= 'Y') THEN
9465 x_trx_qty_alloc := l_lpn_trx_qty;
9466 IF (l_debug = 1) THEN
9467 mydebug('lot controlled.SN allocated and x_lpnpickedasis is Y. ');
9468 mydebug(' x_trx_qty_alloc:'||x_trx_qty_alloc);
9469 END IF;
9470 ELSE
9471 x_trx_qty_alloc := SQL%ROWCOUNT;
9472 IF (l_debug = 1) THEN
9473 mydebug('lot controlled.SN allocated and x_lpnpickedasis is N. ');
9474 mydebug(' x_trx_qty_alloc:'||x_trx_qty_alloc);
9475 END IF;
9476 END IF;
9477
9478 -- populate the lot vector
9479 l_table_index := 0;
9480 FOR lot_ATT_rec in lot_att LOOP
9481 l_table_index := l_table_index + 1;
9482 IF (l_debug = 1) THEN
9483 mydebug('lot_ATT_rec.lot_number: '||lot_ATT_rec.lot_number);
9484 mydebug('lot_ATT_rec.transaction_quantity: '||lot_ATT_rec.transaction_quantity);
9485 END IF;
9486 -- since trx_qty already populated before, we can only use
9487 -- non_alloc_qty to temporarily hold the value. later when generating
9488 -- string, then properly place them in the string passed back to java
9489 t_lpn_lot_qty_table(l_table_index).non_alloc_qty := lot_ATT_rec.transaction_quantity;
9490
9491 END LOOP;
9492
9493 IF (l_debug = 1) THEN
9494 mydebug('lot controlled. x_trx_qty_alloc:'||x_trx_qty_alloc);
9495 END IF;
9496 --jxlu 10/12/04 end
9497 ELSE -- not lot controlled
9498 INSERT INTO WMS_ALLOCATIONS_GTMP
9499 (serial_number,
9500 transaction_quantity,
9501 primary_quantity)
9502 SELECT fm_serial_number,1,1
9503 FROM mtl_serial_numbers_temp msnt,
9504 mtl_serial_numbers msn
9505 WHERE msnt.transaction_temp_id = p_temp_id
9506 AND msnt.fm_serial_number = msn.serial_number
9507 AND msn.lpn_id = p_fromlpn_id
9508 AND msn.inventory_item_id = p_item_id;
9509
9510 --jxlu 10/12/04 start
9511 IF (x_lpnpickedasis ='Y') THEN
9512 x_trx_qty_alloc := l_lpn_trx_qty;
9513 IF (l_debug = 1) THEN
9514 mydebug('NOT lot controlled.SN allocated and x_lpnpickedasis is Y. ');
9515 mydebug(' x_trx_qty_alloc:'||x_trx_qty_alloc);
9516 END IF;
9517 ELSE
9518 x_trx_qty_alloc := SQL%ROWCOUNT;
9519 IF (l_debug = 1) THEN
9520 mydebug('NOT lot controlled.SN allocated and x_lpnpickedasis is N. ');
9521 mydebug(' x_trx_qty_alloc:'||x_trx_qty_alloc);
9522 END IF;
9523 END IF;
9524 -- jxlu 10/12/04 end
9525 END IF;
9526 ELSIF p_is_sn_alloc = 'N' AND p_action = 4 AND x_match = 3 THEN
9527
9528 IF (l_debug = 1) THEN
9529 mydebug('SN control and SN allocation off and x_match=3');
9530 END IF;
9531
9532 IF l_lot_code > 1 THEN
9533 INSERT INTO wms_allocations_gtmp
9534 (lot_number,
9535 serial_number,
9536 transaction_quantity,
9537 primary_quantity)
9538 SELECT mtlt.lot_number, serial_number, 1, 1
9539 FROM mtl_transaction_lots_temp mtlt,
9540 mtl_serial_numbers msn
9541 WHERE mtlt.transaction_temp_id = p_temp_id
9542 AND msn.lpn_id = p_fromlpn_id
9543 AND mtlt.lot_number = msn.lot_number
9544 AND msn.inventory_item_id = p_item_id
9545 AND Nvl(msn.group_mark_id, -1) = -1;
9546 ELSE
9547 INSERT INTO wms_allocations_gtmp
9548 (serial_number,
9549 transaction_quantity,
9550 primary_quantity)
9551 SELECT serial_number,1,1
9552 FROM mtl_serial_numbers msn
9553 WHERE msn.lpn_id = p_fromlpn_id
9554 AND msn.inventory_item_id = p_item_id
9555 AND Nvl(msn.group_mark_id, -1) = -1;
9556 END IF;
9557 ELSIF l_lot_code > 1 THEN -- lot controlled
9558
9559 IF (l_debug = 1) THEN
9560 mydebug('lot controlled....');
9561 END IF;
9562
9563 l_table_total := t_lpn_lot_qty_table.COUNT;
9564 IF l_table_total > 0 THEN
9565 IF (l_debug = 1) THEN
9566 mydebug('building lpn lot vector for ' || l_table_total || '
9567 records');
9568 END IF;
9569
9570 FOR l_table_count IN 1 .. l_table_total LOOP
9571 IF (l_debug = 1) THEN
9572 mydebug('index is : ' || l_table_count);
9573 END IF;
9574
9575 INSERT INTO wms_allocations_gtmp(lot_number, primary_quantity,
9576 transaction_quantity, secondary_quantity) -- Bug #4141928
9577 values(t_lpn_lot_qty_table(l_table_count).lot_number,
9578 t_lpn_lot_qty_table(l_table_count).pri_qty,
9579 t_lpn_lot_qty_table(l_table_count).trx_qty,
9580 t_lpn_lot_qty_table(l_table_count).sec_qty
9581 ); -- Bug #4141928
9582
9583 END LOOP;
9584 END IF;
9585
9586
9587 END IF; -- done populating the lot
9588
9589
9590 --populate the lot in lpn vector
9591
9592 l_table_total := t_lpn_lot_qty_table.COUNT;
9593
9594 IF l_table_total > 0 THEN
9595 IF (l_debug = 1) THEN
9596 mydebug('building lpn lot vector for ' || l_table_total || 'records');
9597 END IF;
9598
9599
9600 FOR l_table_count IN 1 .. l_table_total LOOP
9601 IF (l_debug = 1) THEN
9602 mydebug('index is : ' || l_table_count);
9603 END IF;
9604 IF p_is_sn_alloc = 'Y' THEN -- serial allocated
9605 IF (l_debug = 1) THEN
9606 mydebug('serial is allocated');
9607 END IF;
9608 IF (x_lpnpickedasis ='Y') THEN
9609 IF (l_debug = 1) THEN
9610 mydebug('x_lpnpickedasis is Y');
9611 END IF;
9612 IF l_value = '.,' THEN --bug 6651517 added if on the basis of l_value
9613
9614 x_lpn_lot_vector := x_lpn_lot_vector
9615 ||t_lpn_lot_qty_table(l_table_count).lot_number ||'@@@@@'
9616 ||t_lpn_lot_qty_table(l_table_count).trx_qty||'@@@@@'
9617 ||t_lpn_lot_qty_table(l_table_count).trx_qty
9618 || '&&&&&'
9619 || t_lpn_lot_qty_table(l_table_count).sec_qty -- Bug #4141928
9620 || '#####'; -- Bug #4141928
9621 ELSE
9622 x_lpn_lot_vector := x_lpn_lot_vector
9623 ||t_lpn_lot_qty_table(l_table_count).lot_number ||'@@@@@'
9624 ||TO_CHAR(t_lpn_lot_qty_table(l_table_count).trx_qty,'9999999999999999999999.9999999999')||'@@@@@'
9625 ||TO_CHAR(t_lpn_lot_qty_table(l_table_count).trx_qty,'9999999999999999999999.9999999999')
9626 || '&&&&&'
9627 || TO_CHAR(t_lpn_lot_qty_table(l_table_count).sec_qty,'9999999999999999999999.9999999999') -- Bug #4141928
9628 || '#####';
9629 END IF;
9630 -- end of bug 6651517
9631 l_lot_v := l_lot_v
9632 ||t_lpn_lot_qty_table(l_table_count).lot_number||':'; --Bug 3855835
9633 ELSE
9634 IF (l_debug = 1) THEN
9635 mydebug('x_lpnpickedasis is N');
9636 END IF;
9637 IF l_value = '.,' THEN --bug 6651517 added if on the basis of l_value
9638 x_lpn_lot_vector := x_lpn_lot_vector
9639 ||t_lpn_lot_qty_table(l_table_count).lot_number ||'@@@@@'
9640 ||t_lpn_lot_qty_table(l_table_count).non_alloc_qty||'@@@@@'
9641 ||t_lpn_lot_qty_table(l_table_count).trx_qty
9642 || '&&&&&'
9643 || t_lpn_lot_qty_table(l_table_count).sec_qty -- Bug #4141928
9644 || '#####'; -- Bug #4141928
9645 else
9646 x_lpn_lot_vector := x_lpn_lot_vector
9647 ||t_lpn_lot_qty_table(l_table_count).lot_number ||'@@@@@'
9648 ||TO_CHAR(t_lpn_lot_qty_table(l_table_count).non_alloc_qty,'9999999999999999999999.9999999999')||'@@@@@'
9649 ||TO_CHAR(t_lpn_lot_qty_table(l_table_count).trx_qty,'9999999999999999999999.9999999999')
9650 || '&&&&&'
9651 || TO_CHAR(t_lpn_lot_qty_table(l_table_count).sec_qty,'9999999999999999999999.9999999999') -- Bug #4141928
9652 || '#####'; -- Bug #4141928
9653
9654 END IF;
9655 --end of bug 6651517
9656 l_lot_v := l_lot_v
9657 ||t_lpn_lot_qty_table(l_table_count).lot_number||':'; --Bug 3855835
9658 END IF;
9659 IF (l_debug = 1) THEN
9660 mydebug('x_lpn_lot_vector:'||x_lpn_lot_vector);
9661 END IF;
9662 ELSE -- serial is not allocated
9663 IF (l_debug = 1) THEN
9664 mydebug('serial is NOT allocated');
9665 END IF;
9666 --bug 6651517 added if on the basis of l_value
9667 IF l_value = '.,' THEN
9668 x_lpn_lot_vector := x_lpn_lot_vector
9669 ||t_lpn_lot_qty_table(l_table_count).lot_number ||'@@@@@'
9670 ||t_lpn_lot_qty_table(l_table_count).trx_qty||'@@@@@'
9671 ||t_lpn_lot_qty_table(l_table_count).trx_qty
9672 || '&&&&&'
9673 || t_lpn_lot_qty_table(l_table_count).sec_qty -- Bug #4141928
9674 || '#####'; -- Bug #4141928
9675 ELSE
9676 x_lpn_lot_vector := x_lpn_lot_vector
9677 ||t_lpn_lot_qty_table(l_table_count).lot_number ||'@@@@@'
9678 ||TO_CHAR(t_lpn_lot_qty_table(l_table_count).trx_qty,'9999999999999999999999.9999999999')||'@@@@@'
9679 ||TO_CHAR(t_lpn_lot_qty_table(l_table_count).trx_qty,'9999999999999999999999.9999999999')
9680 || '&&&&&'
9681 || TO_CHAR(t_lpn_lot_qty_table(l_table_count).sec_qty,'9999999999999999999999.9999999999') -- Bug #4141928
9682 || '#####'; -- Bug #4141928
9683 END IF; --end of bug 6651517
9684 l_lot_v := l_lot_v
9685 ||t_lpn_lot_qty_table(l_table_count).lot_number||':'; --Bug 3855835
9686 IF (l_debug = 1) THEN
9687 mydebug('l_lot_v:'||l_lot_v);
9688 END IF;
9689 END IF;
9690 END LOOP;
9691 ELSE
9692 IF (l_debug = 1) THEN
9693 mydebug('it is not lot controlled and lot in lpn vector is null... ' );
9694 END IF;
9695 x_lpn_lot_vector := NULL;
9696 END IF;
9697
9698 IF (l_debug = 1) THEN
9699 mydebug('LPN QTY in primary uom' || l_lpn_pr_qty);
9700 mydebug('LPN QTY in transaction uom' || l_lpn_trx_qty);
9701 mydebug('LPN Secondary QTY' || l_lpn_sec_qty); -- Bug #4141928
9702 mydebug('x_temp_id: ' || l_out_temp_id);
9703 END IF;
9704
9705 x_temp_id := l_out_temp_id;
9706 --bug 3547725
9707 --x_trx_qty := LEAST(l_lpn_trx_qty, p_trx_qty);
9708 x_trx_qty := l_lpn_trx_qty;
9709 x_trx_sec_qty := l_lpn_sec_qty; -- Bug #4141928
9710 -- bug 3983704
9711 -- get the packed qoh since the qty tree always return for both loosepack
9712 SELECT NVL(SUM(primary_transaction_quantity),0), NVL(SUM(secondary_transaction_quantity),0)
9713 INTO l_qoh, l_sqoh
9714 FROM mtl_onhand_quantities_detail
9715 WHERE lpn_id = p_fromlpn_id
9716 AND organization_id = p_org_id;
9717
9718 IF (p_trx_uom <> l_primary_uom) THEN
9719 x_lpn_qoh := inv_convert.inv_um_convert(
9720 item_id => p_item_id
9721 ,precision => null
9722 ,from_quantity => l_qoh
9723 ,from_unit => l_primary_uom
9724 ,to_unit => p_trx_uom
9725 ,from_name => null
9726 ,to_name => null);
9727 IF (l_debug = 1) THEN
9728 mydebug(' x_lpn_qoh :' || x_lpn_qoh);
9729 END IF;
9730 ELSE x_lpn_qoh := l_qoh;
9731 END IF;
9732 --x_lpn_qoh := l_sqoh;
9733 x_return_status := fnd_api.g_ret_sts_success;
9734
9735 IF (l_debug = 1) THEN
9736 mydebug('Match ' || x_match);
9737 END IF;
9738
9739 /* Mrana: 12/10/03: we need not change the lpn_context here . We will do it in
9740 * LOAD/split merge API . to avoid hassles of setting and resetting in case
9741 * users picks one lpn and then using cursor key goes up to change it .
9742 * Also, with this approach , we do not need to reset lpn context in case of F2
9743 * We will select this LPN for Update , so that otehr processes cannot get it.
9744 * yes, there is a possibility that
9745 */
9746 IF (x_match = 3) or (x_match = 1) THEN -- added x_match=1
9747 IF (l_debug = 1) THEN
9748 mydebug('Lock lpn_ID : ' || p_fromlpn_id);
9749 END IF;
9750 BEGIN
9751
9752 SELECT lpn_context
9753 INTO l_lpn_context
9754 FROM wms_license_plate_numbers
9755 WHERE lpn_id = p_fromlpn_id
9756 FOR UPDATE NOWAIT;
9757 EXCEPTION
9758 WHEN OTHERS THEN
9759 IF SQLCODE = -54 THEN -- ORA-0054: resource busy and acquire with NOWAIT specified
9760 mydebug('LPN record is locked by another user... cannot pick this LPN' );
9761 fnd_message.set_name('WMS', 'WMS_LPN_LOCKED_ERROR');
9762 -- LPN is in use by another user
9763 fnd_msg_pub.ADD;
9764 RAISE fnd_api.g_exc_error;
9765 ELSE
9766 RAISE fnd_api.g_exc_unexpected_error;
9767 END IF;
9768
9769 END ;
9770 END IF;
9771
9772 --Bug3855835
9773
9774
9775 IF l_lot_v IS NOT NULL THEN
9776 l_lot_v := SUBSTR(l_lot_v,1,LENGTH(l_lot_v)-1);
9777 END IF;
9778
9779 IF p_toLPN_Default IS NOT NULL THEN
9780
9781 validate_pick_to_lpn
9782 ( p_api_version_number => 1.0
9783 , p_init_msg_lst => NULL
9784 , x_return_status => x_return_status
9785 , x_msg_count => l_msg_cnt
9786 , x_msg_data => l_msg_data
9787 , p_organization_id => p_org_id
9788 , p_pick_to_lpn => p_toLPN_Default
9789 , p_temp_id => p_temp_id
9790 , p_project_id => p_project_id
9791 , p_task_id => p_task_id
9792 , p_container_item => NULL
9793 , p_container_item_id => NULL
9794 , p_suggested_container_item => NULL
9795 , p_suggested_container_item_id => NULL
9796 , p_suggested_carton_name => NULL
9797 , p_suggested_tolpn_id => NULL
9798 , x_pick_to_lpn_id => l_pick_to_lpn_id
9799 , p_inventory_item_id => p_item_id
9800 , p_confirmed_sub => p_confirmed_sub
9801 , p_confirmed_loc_id => p_confirmed_loc_id
9802 , p_revision => p_rev
9803 , p_confirmed_lots => l_lot_v
9804 , p_from_lpn_id => p_from_lpn_id
9805 , p_lot_control => l_is_lot_control
9806 , p_revision_control => l_is_revision_control
9807 , p_serial_control => l_is_serial_control
9808 -- Bug 4632519
9809 , p_trx_type_id => to_char(p_transaction_type_id)
9810 , p_trx_action_id => to_char(p_transaction_action_id)
9811 -- Bug 4632519
9812 );
9813
9814
9815 If x_return_status <> fnd_api.g_ret_sts_success THEN
9816 x_toLPN_status := 'F';
9817 IF (l_debug = 1) THEN
9818 mydebug('Validate_pick_to_lpn could not validate toLPNDefault:');
9819 END IF;
9820 x_return_status := fnd_api.g_ret_sts_success;
9821 Else
9822 x_toLPN_status := 'T';
9823 IF (l_debug = 1) THEN
9824 mydebug('Validate_pick_to_lpn validated toLPNDefault:');
9825 END IF;
9826 End If;
9827
9828 END IF;
9829
9830
9831 EXCEPTION
9832 WHEN fnd_api.g_exc_error THEN
9833 IF (l_debug = 1) THEN
9834 mydebug(' Expected Exception raised');
9835 END IF;
9836 x_return_status := fnd_api.g_ret_sts_error;
9837 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9838 WHEN fnd_api.g_exc_unexpected_error THEN
9839 IF (l_debug = 1) THEN
9840 mydebug(' Unexpected Exception raised');
9841 END IF;
9842 x_return_status := fnd_api.g_ret_sts_unexp_error;
9843 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9844 WHEN OTHERS THEN
9845 IF (l_debug = 1) THEN
9846 mydebug('Other exception raised : ' || SQLERRM);
9847 END IF;
9848
9849 x_return_status := fnd_api.g_ret_sts_unexp_error;
9850 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9851 END lpn_match;
9852
9853
9854 -- during the picking process. If the user does not specifies
9855 -- a from lpn, this procedure will figure out if the loose quantity will
9856 -- satisfy the pick in question, the temp table mtl_allocations_gtmp
9857 -- will store the available lot and serial numbers for this pick
9858
9859 PROCEDURE loose_match(
9860 p_org_id IN NUMBER
9861 , p_item_id IN NUMBER
9862 , p_rev IN VARCHAR2
9863 , p_trx_qty IN NUMBER
9864 , p_trx_uom IN VARCHAR2
9865 , p_pri_uom IN VARCHAR2
9866 , p_sec_uom IN VARCHAR2 -- Bug #4141928
9867 , p_sec_qty IN NUMBER -- Bug #4141928
9868 , p_temp_id IN NUMBER
9869 , p_suggested_locator IN NUMBER
9870 , p_confirmed_locator IN NUMBER
9871 , p_confirmed_sub IN VARCHAR2
9872 , p_is_sn_alloc IN VARCHAR2
9873 , p_is_revision_control IN VARCHAR2
9874 , p_is_lot_control IN VARCHAR2
9875 , p_is_serial_control IN VARCHAR2
9876 , p_is_negbal_allowed IN VARCHAR2
9877 , p_toLPN_Default IN VARCHAR2 --Bug 3855835
9878 , p_project_id IN NUMBER
9879 , p_task_id IN NUMBER
9880 , x_trx_qty OUT NOCOPY NUMBER
9881 , x_trx_sec_qty OUT NOCOPY NUMBER -- Bug #4141928
9882 , x_return_status OUT NOCOPY VARCHAR2
9883 , x_msg_count OUT NOCOPY NUMBER
9884 , x_msg_data OUT NOCOPY VARCHAR2
9885 , x_toLPN_status OUT NOCOPY VARCHAR2 --Bug 3855835
9886 , x_lot_att_vector OUT NOCOPY VARCHAR2
9887 , x_trx_qty_alloc OUT NOCOPY NUMBER -- jxlu 10/6/04
9888 , p_transaction_type_id IN NUMBER -- Bug 4632519
9889 , p_transaction_action_id IN NUMBER -- Bug 4632519
9890 ) IS
9891 l_proc_name VARCHAR2(30) := 'LOOSE_MATCH' ;
9892 l_msg_cnt NUMBER;
9893 l_msg_data VARCHAR2(2000);
9894 l_return_status VARCHAR2(1);
9895 l_lot_primary_qty NUMBER;
9896 l_att_trx_qty NUMBER;
9897 l_trx_lot_qty NUMBER;
9898 l_qoh NUMBER;
9899 l_trx_qoh NUMBER;
9900 l_att NUMBER;
9901
9902 l_lot_sec_qty NUMBER; -- Bug #4141928
9903 l_att_trx_sec_qty NUMBER; -- Bug #4141928
9904 l_trx_lot_sec_qty NUMBER; -- Bug #4141928
9905 l_sqoh NUMBER; -- Bug #4141928
9906 l_trx_sec_qoh NUMBER; -- Bug #4141928
9907 l_satt NUMBER; -- Bug #4141928
9908
9909 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
9910 l_lot_number VARCHAR2(80) := null;
9911 l_debug NUMBER :=
9912 NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9913 l_table_index NUMBER := 0;
9914 l_pick_to_lpn_id NUMBER;
9915 l_lot_v VARCHAR2(2000) :=null ;
9916 l_is_lot_control VARCHAR2(1);
9917 l_is_revision_control VARCHAR2(1);
9918 l_is_serial_control VARCHAR2(1);
9919
9920 l_transfer_subinventory VARCHAR2(10) := NULL; -- Bug #7257709
9921 CURSOR lot_csr IS
9922 SELECT mtlt.primary_quantity
9923 , mtlt.transaction_quantity
9924 , NVL(mtlt.secondary_quantity, 0) -- Bug #4141928
9925 , mtlt.lot_number
9926 FROM mtl_transaction_lots_temp mtlt
9927 WHERE mtlt.transaction_temp_id = p_temp_id
9928 ORDER BY LOT_NUMBER;
9929
9930 CURSOR lot_att IS
9931 SELECT lot_number, sum(transaction_quantity) transaction_quantity
9932 from wms_ALLOCATIONS_GTMP
9933 GROUP BY LOT_NUMBER
9934 ORDER BY LOT_NUMBER;
9935
9936 CURSOR mmtt_csr IS
9937 SELECT transfer_subinventory
9938 FROM mtl_material_transactions_temp
9939 WHERE transaction_temp_id = p_temp_id; -- Bug #7257709
9940
9941 BEGIN
9942
9943 SAVEPOINT LOOSE_MATCH ; --
9944 IF (l_debug = 1) THEN
9945 mydebug('In loose Match');
9946 END IF;
9947
9948 x_return_status := fnd_api.g_ret_sts_success;
9949 x_lot_att_vector := null;
9950
9951 DELETE wms_allocations_gtmp;
9952 t_lpn_lot_qty_table.DELETE;
9953
9954 x_trx_qty := 0;
9955 x_trx_sec_qty := 0; -- Bug #4141928
9956 x_trx_qty_alloc := 0;
9957
9958 -- Bug #7257709: pass destination sub code to INV_TXN_VALIDATIONS.get_available_quantity
9959 -- in case of move order tasks
9960 IF (p_transaction_type_id = 64 AND p_transaction_action_id = 2) THEN
9961 OPEN mmtt_csr;
9962 FETCH mmtt_csr INTO l_transfer_subinventory;
9963 CLOSE mmtt_csr;
9964 END IF;
9965
9966 IF p_is_sn_alloc = 'Y' THEN -- serial is allocated
9967 -- create the lot vector and populate the temp table for serial allocated
9968 -- case
9969 IF (l_debug = 1) THEN
9970 mydebug('SN control and SN allocation on');
9971 END IF;
9972
9973 IF p_is_lot_control ='true' THEN -- lot controlled
9974 INSERT INTO wms_allocations_gtmp
9975 (lot_number,
9976 serial_number,
9977 transaction_quantity,
9978 primary_quantity)
9979 SELECT mtlt.lot_number,fm_serial_number,1,1
9980 FROM mtl_serial_numbers_temp msnt,
9981 mtl_transaction_lots_temp mtlt,
9982 mtl_serial_numbers msn
9983 WHERE mtlt.transaction_temp_id = p_temp_id
9984 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
9985 AND msnt.fm_serial_number = msn.serial_number
9986 AND msn.lpn_id is null -- make sure it is loose pick
9987 AND msn.inventory_item_id = p_item_id;
9988
9989 x_trx_qty_alloc := SQL%ROWCOUNT;
9990 -- populate the lot vector
9991 FOR lot_ATT_rec in lot_att LOOP
9992 IF (l_debug = 1) THEN
9993 mydebug('lot_ATT_rec.lot_number: '||lot_ATT_rec.lot_number);
9994 mydebug('lot_ATT_rec.transaction_quantity: '||lot_ATT_rec.transaction_quantity);
9995 END IF;
9996 l_table_index := l_table_index + 1;
9997 /*x_lot_att_alloc_v := x_lot_att_alloc_v
9998 ||lot_ATT_rec.lot_number|| '@@@@@'
9999 ||lot_ATT_rec.transaction_quantity
10000 || '&&&&&'; */
10001 t_lpn_lot_qty_table(l_table_index).lot_number := lot_ATT_rec.lot_number;
10002 t_lpn_lot_qty_table(l_table_index).trx_qty := lot_ATT_rec.transaction_quantity;
10003 END LOOP;
10004 ELSE -- not lot controlled
10005 INSERT INTO wms_ALLOCATIONS_GTMP
10006 (serial_number,
10007 transaction_quantity,
10008 primary_quantity)
10009 SELECT fm_serial_number,1,1
10010 FROM mtl_serial_numbers_temp msnt,
10011 mtl_serial_numbers msn
10012 WHERE msnt.transaction_temp_id = p_temp_id
10013 AND msnt.fm_serial_number = msn.serial_number
10014 AND msn.lpn_id is null
10015 AND msn.inventory_item_id = p_item_id;
10016
10017 x_trx_qty_alloc := SQL%ROWCOUNT;
10018 END IF;
10019 END IF;
10020
10021 IF (l_debug = 1) THEN
10022 mydebug('x_trx_qty_alloc: '||x_trx_qty_alloc);
10023 END IF;
10024
10025 l_table_index := 0;
10026
10027 OPEN lot_csr;
10028 LOOP
10029
10030 if (p_is_lot_control ='true' ) then
10031 fetch lot_csr INTO l_lot_primary_qty, l_trx_lot_qty, l_lot_sec_qty, l_lot_number; -- Bug #4141928
10032 exit when lot_csr%NOTFOUND;
10033 IF (l_debug = 1) THEN
10034 mydebug('l_mtlt_lot_number : ' || l_lot_number);
10035 mydebug('l_mtlt_primary_qty: ' || l_lot_primary_qty);
10036 mydebug('l_mtlt_secondary_qty: ' || l_lot_sec_qty); -- Bug #4141928
10037 END IF;
10038
10039 end if;
10040
10041 IF (p_suggested_locator = p_confirmed_locator) THEN
10042 UPDATE mtl_material_transactions_temp mmtt
10043 SET posting_flag = 'N'
10044 WHERE transaction_temp_id = p_temp_id;
10045 END IF;
10046
10047
10048 -- End change - Bug 4185621
10049 -- always do one query at least for non lot controlled items
10050
10051 INV_TXN_VALIDATIONS.get_available_quantity
10052 (x_return_status => l_return_status,
10053 p_tree_mode => inv_quantity_tree_pub.g_loose_only_mode,
10054 p_organization_id =>p_org_id,
10055 p_inventory_item_id => p_item_id,
10056 p_is_revision_control =>p_is_revision_control,
10057 p_is_lot_control =>p_is_lot_control,
10058 p_is_serial_control =>p_is_serial_control,
10059 p_revision =>p_rev,
10060 p_lot_number =>l_lot_number,
10061 p_grade_code => NULL, -- Bug #4141928
10062 p_lot_expiration_date =>null,
10063 p_subinventory_code =>p_confirmed_sub,
10064 p_locator_id =>p_confirmed_locator,
10065 p_source_type_id =>-9999,
10066 p_cost_group_id => NULL,
10067 p_to_subinventory_code => l_transfer_subinventory,
10068 x_qoh => l_qoh,
10069 x_att => l_att,
10070 x_sqoh => l_sqoh, -- Bug #4141928
10071 x_satt => l_satt -- Bug #4141928
10072 );
10073
10074
10075 -- Start change - Bug 4185621: restore posting flag in mmtt
10076
10077 IF (p_suggested_locator = p_confirmed_locator) THEN
10078 UPDATE mtl_material_transactions_temp mmtt
10079 SET posting_flag = 'Y'
10080 WHERE transaction_temp_id = p_temp_id;
10081 END IF;
10082
10083 -- End change - Bug 4185621
10084 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
10085
10086
10087 -- convert the qty from primary UOM to transaction UOM
10088
10089 if (p_pri_uom = p_trx_uom) then
10090 IF (l_debug = 1) THEN
10091 mydebug('primary uom is the same as transaction uom');
10092 END IF;
10093 l_att_trx_qty := l_att;
10094 l_trx_qoh := l_qoh;
10095 else
10096 l_att_trx_qty := inv_convert.inv_um_convert(
10097 item_id => p_item_id
10098 ,precision => null
10099 ,from_quantity => l_att
10100 ,from_unit => p_pri_uom
10101 ,to_unit => p_trx_uom
10102 ,from_name => null
10103 ,to_name => null);
10104 l_trx_qoh := inv_convert.inv_um_convert(
10105 item_id => p_item_id
10106 ,precision => null
10107 ,from_quantity => l_qoh
10108 ,from_unit => p_pri_uom
10109 ,to_unit => p_trx_uom
10110 ,from_name => null
10111 ,to_name => null);
10112 end if;
10113
10114 l_att_trx_sec_qty := l_satt; -- Bug #4141928
10115 l_trx_sec_qoh := l_sqoh; -- Bug #4141928
10116
10117 IF (l_debug = 1) THEN
10118 mydebug('l_att_trx_qty: '||l_att_trx_qty);
10119 mydebug('l_trx_qoh: '||l_trx_qoh);
10120 mydebug('l_att_trx_sec_qty: '||l_att_trx_sec_qty); -- Bug #4141928
10121 mydebug('l_trx_sec_qoh: '||l_trx_sec_qoh); -- Bug #4141928
10122 END IF;
10123
10124
10125 if (p_is_lot_control ='true' ) then
10126 -- populate the lot vector
10127
10128 l_table_index := l_table_index + 1;
10129 IF p_is_sn_alloc = 'Y' THEN
10130 x_lot_att_vector := x_lot_att_vector
10131 ||l_lot_number || '@@@@@'
10132 ||t_lpn_lot_qty_table(l_table_index).trx_qty|| '@@@@@'
10133 ||l_att_trx_qty
10134 || '&&&&&'
10135 || l_att_trx_sec_qty -- Bug #4141928
10136 || '#####'; -- Bug #4141928
10137 l_lot_v := l_lot_v
10138 ||l_lot_number||':'; --Bug 3855835
10139 IF (l_debug = 1) THEN
10140 mydebug('l_table_index: '||l_table_index);
10141 mydebug('x_lot_att_vector: '||x_lot_att_vector);
10142 END IF;
10143 ELSE -- serial number is not allocated,
10144 x_lot_att_vector := x_lot_att_vector
10145 ||l_lot_number || '@@@@@'
10146 ||l_att_trx_qty|| '@@@@@'
10147 ||l_att_trx_qty
10148 || '&&&&&'
10149 || l_att_trx_sec_qty -- Bug #4141928
10150 || '#####'; -- Bug #4141928
10151 l_lot_v := l_lot_v
10152 ||l_lot_number||':';
10153 IF (l_debug = 1) THEN
10154 mydebug('inserting into global temp table for serial is non allocated....');
10155 END IF;
10156 -- If negative Balance allowed then update vikas 09/07/04 V1
10157 if (p_is_negbal_allowed ='true') then
10158 INSERT INTO wms_ALLOCATIONS_GTMP
10159 (lot_number,
10160 primary_quantity,
10161 transaction_quantity,
10162 secondary_quantity) -- Bug #4141928
10163 VALUES( l_lot_number,
10164 l_lot_primary_qty,
10165 l_trx_lot_qty,
10166 l_trx_lot_sec_qty);
10167
10168 -- vikas 09/07/04 end
10169 else
10170 INSERT INTO wms_ALLOCATIONS_GTMP
10171 (lot_number,
10172 primary_quantity,
10173 transaction_quantity,
10174 secondary_quantity) -- Bug #4141928
10175 VALUES( l_lot_number,
10176 LEAST(l_lot_primary_qty,l_att),
10177 LEAST(l_trx_lot_qty,l_att_trx_qty),
10178 LEAST(l_trx_lot_sec_qty,l_att_trx_sec_qty));
10179 end if;
10180 END IF;
10181
10182 x_trx_qty := x_trx_qty + l_att_trx_qty;
10183 x_trx_sec_qty := x_trx_sec_qty + l_att_trx_sec_qty;
10184
10185
10186 else -- pure serial controlled
10187 x_trx_qty := l_att_trx_qty;
10188 x_trx_sec_qty := l_att_trx_sec_qty; -- Bug #4141928
10189 end if;
10190
10191 ELSE
10192 IF (l_debug = 1) THEN
10193 mydebug('calling qty tree 1st time failed ');
10194 END IF;
10195 fnd_message.set_name('INV', 'INV_INVALID_QUANTITY_TYPE');
10196 fnd_message.set_token('ROUTINE','INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES');
10197 fnd_msg_pub.ADD;
10198 RAISE fnd_api.g_exc_error;
10199 END IF;
10200
10201 EXIT WHEN p_is_lot_control ='false';
10202 END LOOP;
10203
10204 IF (l_debug = 1) THEN
10205 mydebug('x_trx_qty: '||x_trx_qty);
10206 mydebug('x_trx_sec_qty: '||x_trx_sec_qty); -- Bug #4141928
10207 mydebug('x_lot_att_vector: '||x_lot_att_vector);
10208 mydebug('l_lot_v::' ||l_lot_v);
10209 END IF;
10210
10211
10212 IF l_lot_v IS NOT NULL THEN
10213 l_lot_v := SUBSTR(l_lot_v,1,LENGTH(l_lot_v)-1);
10214 END IF;
10215
10216 --v1 calling validate_pick_to_lpn for validating toLPNdefault and if it
10217 --returns success then allow to set to LPN field with toLPNDefault on
10218 --MainPickPage. Bug 3855835
10219
10220
10221 IF p_toLPN_Default IS NOT NULL THEN
10222
10223
10224 If p_is_lot_control ='true' THEN
10225 l_is_lot_control :='Y';
10226 Else
10227 l_is_lot_control :='N';
10228 END If;
10229
10230 If p_is_serial_control ='true' THEN
10231 l_is_serial_control := 'Y';
10232 Else
10233 l_is_serial_control := 'N';
10234 END IF;
10235
10236 If p_is_revision_control ='true' THEN
10237 l_is_revision_control := 'Y';
10238 Else
10239 l_is_revision_control :='N';
10240 END If;
10241
10242
10243 validate_pick_to_lpn
10244 ( p_api_version_number => 1.0
10245 , p_init_msg_lst => NULL
10246 , x_return_status => x_return_status
10247 , x_msg_count => l_msg_cnt
10248 , x_msg_data => l_msg_data
10249 , p_organization_id => p_org_id
10250 , p_pick_to_lpn => p_toLPN_Default
10251 , p_temp_id => p_temp_id
10252 , p_project_id => p_project_id
10253 , p_task_id => p_task_id
10254 , p_container_item => NULL
10255 , p_container_item_id => NULL
10256 , p_suggested_container_item => NULL
10257 , p_suggested_container_item_id => NULL
10258 , p_suggested_carton_name => NULL
10259 , p_suggested_tolpn_id => NULL
10260 , x_pick_to_lpn_id => l_pick_to_lpn_id
10261 , p_inventory_item_id => p_item_id
10262 , p_confirmed_sub => p_confirmed_sub
10263 , p_confirmed_loc_id => p_confirmed_locator
10264 , p_revision => p_rev
10265 , p_confirmed_lots => l_lot_v
10266 , p_from_lpn_id => NULL
10267 , p_lot_control => l_is_lot_control
10268 , p_revision_control => l_is_revision_control
10269 , p_serial_control => l_is_serial_control
10270 -- Bug 4632519
10271 , p_trx_type_id => to_char(p_transaction_type_id)
10272 , p_trx_action_id => to_char(p_transaction_action_id)
10273 -- Bug 4632519
10274 );
10275
10276
10277 If x_return_status <> fnd_api.g_ret_sts_success THEN
10278 x_toLPN_status := 'F';
10279 IF (l_debug = 1) THEN
10280 mydebug('Validate_pick_to_lpn could not validate toLPNDefault:');
10281 END IF;
10282 x_return_status := fnd_api.g_ret_sts_success;
10283 Else
10284 x_toLPN_status := 'T';
10285 IF (l_debug = 1) THEN
10286 mydebug('Validate_pick_to_lpn validated toLPNDefault:');
10287 END IF;
10288 End If;
10289
10290 END IF;
10291
10292 EXCEPTION
10293 WHEN fnd_api.g_exc_error THEN
10294 IF (l_debug = 1) THEN
10295 mydebug('Exception raised');
10296 END IF;
10297
10298 x_return_status := fnd_api.g_ret_sts_error;
10299 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10300 WHEN OTHERS THEN
10301 IF (l_debug = 1) THEN
10302 mydebug('Other exception raised : ' || SQLERRM);
10303 END IF;
10304
10305 x_return_status := fnd_api.g_ret_sts_unexp_error;
10306 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10307 END LOOSE_MATCH;
10308
10309
10310 FUNCTION can_pickdrop(p_transaction_temp_id IN NUMBER) RETURN VARCHAR2 IS
10311 l_ret VARCHAR2(10) := 'PASS';
10312 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10313 CURSOR c_cancelled_tasks IS
10314 --SELECT decode(mmtt.transaction_type_id, 35,'N',51,'N','Y')
10315 SELECT 'FAIL'
10316 FROM mtl_material_transactions_temp mmtt, mtl_txn_request_lines mol
10317 WHERE mmtt.transaction_temp_id = p_transaction_temp_id
10318 AND mmtt.move_order_line_id = mol.line_id
10319 AND mol.line_status = inv_globals.g_to_status_cancel_by_source
10320 AND ROWNUM = 1;
10321 BEGIN
10322 g_debug := l_debug;
10323 mydebug('In CAN_PICKDROP for Transaction Temp ID = ' || p_transaction_temp_id);
10324
10325 OPEN c_cancelled_tasks;
10326 FETCH c_cancelled_tasks INTO l_ret;
10327 IF c_cancelled_tasks%NOTFOUND THEN
10328 mydebug('Found no Cancelled Task' );
10329 ELSE
10330 mydebug('Found Cancelled Tasks');
10331 END IF;
10332 CLOSE c_cancelled_tasks;
10333 mydebug('l_ret : ' || l_ret);
10334 RETURN l_ret;
10335 END can_pickdrop;
10336
10337
10338 PROCEDURE check_pack_lpn
10339 ( p_lpn IN VARCHAR2
10340 , p_org_id IN NUMBER
10341 , p_container_item_id IN NUMBER
10342 , p_temp_id IN NUMBER --Bug7120019
10343 , x_lpn_id OUT NOCOPY NUMBER
10344 , x_lpn_context OUT NOCOPY NUMBER
10345 , x_outermost_lpn_id OUT NOCOPY NUMBER
10346 , x_pick_to_lpn_exists OUT NOCOPY BOOLEAN
10347 , x_return_status OUT NOCOPY VARCHAR2
10348 , x_msg_count OUT NOCOPY NUMBER
10349 , x_msg_data OUT NOCOPY VARCHAR2
10350 ) IS
10351 lpn_cont NUMBER := 0;
10352 create_lpn VARCHAR2(1) := 'N';
10353 l_return_status VARCHAR2(1);
10354 l_msg_count NUMBER;
10355 l_msg_data VARCHAR2(4000);
10356 l_exist NUMBER;
10357 p_lpn_id NUMBER;
10358 l_org_id NUMBER;
10359 l_locator_id NUMBER;
10360 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10361 honor_case_pick_count NUMBER := 0; --Bug7120019
10362 l_CursorStmt VARCHAR2(32000);
10363 l_CursorID INTEGER;
10364 l_Dummy INTEGER;
10365
10366 BEGIN
10367 IF (l_debug = 1) THEN
10368 mydebug('check_pack_lpn: check_pack_lpn begins');
10369 END IF;
10370
10371 l_return_status := fnd_api.g_ret_sts_success;
10372
10373 IF ((p_lpn IS NULL)
10374 OR(p_lpn = '')) THEN
10375 x_return_status := fnd_api.g_ret_sts_success;
10376 RETURN;
10377 END IF;
10378
10379 BEGIN
10380 SELECT lpn_context
10381 , organization_id
10382 , locator_id
10383 , lpn_id
10384 , outermost_lpn_id
10385 INTO lpn_cont
10386 , l_org_id
10387 , l_locator_id
10388 , x_lpn_id
10389 , x_outermost_lpn_id
10390 FROM wms_license_plate_numbers
10391 WHERE license_plate_number = p_lpn;
10392 x_pick_to_lpn_exists := TRUE;
10393 x_lpn_context := lpn_cont;
10394 EXCEPTION
10395 WHEN NO_DATA_FOUND THEN
10396 create_lpn := 'Y';
10397 x_pick_to_lpn_exists := FALSE;
10398 END;
10399
10400 IF (create_lpn = 'N'
10401 AND (l_org_id is not null and l_org_id <> p_org_id)
10402 ) THEN
10403 IF (l_debug = 1) THEN
10404 mydebug('check_pack_lpn: LPN already exists but with different context or Org');
10405 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_ORG');
10406 fnd_msg_pub.ADD;
10407 END IF;
10408
10409 x_return_status := fnd_api.g_ret_sts_error;
10410 RETURN;
10411 END IF;
10412
10413 --Bug7120019
10414 IF wms_control.g_current_release_level >= 120001 THEN
10415 l_CursorStmt := 'SELECT count (*) FROM mtl_material_transactions_temp mmtt, wms_user_task_type_attributes wutta '||
10416 'WHERE mmtt.transaction_temp_id = :x_temp_id ' ||
10417 ' AND mmtt.standard_operation_id = wutta.user_task_type_id '||
10418 ' AND mmtt.organization_id = wutta.organization_id '||
10419 ' AND wutta.honor_case_pick_flag = ''Y'' '; --Added for Bug#7584906
10420 l_CursorID := DBMS_SQL.OPEN_CURSOR;
10421 DBMS_SQL.PARSE(l_CursorID, l_CursorStmt, DBMS_SQL.V7);
10422 DBMS_SQL.DEFINE_COLUMN(l_CursorID, 1, honor_case_pick_count);
10423 DBMS_SQL.BIND_VARIABLE(l_CursorID, ':x_temp_id', p_temp_id);
10424 l_Dummy := DBMS_SQL.EXECUTE(l_CursorID);
10425 l_Dummy := DBMS_SQL.FETCH_ROWS(l_CursorID);
10426 DBMS_SQL.COLUMN_VALUE(l_CursorID, 1, honor_case_pick_count);
10427 DBMS_SQL.CLOSE_CURSOR(l_CursorID);
10428 END IF;
10429
10430 IF (create_lpn = 'N') THEN
10431 IF (wms_control.g_current_release_level >= 120001 AND honor_case_pick_count > 0) THEN
10432 IF (
10433 lpn_cont = wms_container_pub.lpn_context_wip
10434 OR lpn_cont = wms_container_pub.lpn_context_rcv
10435 OR lpn_cont = wms_container_pub.lpn_context_stores
10436 OR lpn_cont = wms_container_pub.lpn_context_intransit
10437 OR lpn_cont = wms_container_pub.lpn_context_vendor
10438 OR lpn_cont = wms_container_pub.lpn_loaded_for_shipment
10439 OR lpn_cont = wms_container_pub.lpn_prepack_for_wip
10440 OR lpn_cont = wms_container_pub.lpn_context_picked
10441 OR lpn_cont = wms_container_pub.LPN_CONTEXT_INV
10442 OR lpn_cont = wms_container_pub.LPN_CONTEXT_PACKING
10443 ) THEN
10444 --OR (l_org_id is not null and l_org_id <> p_org_id)
10445
10446 IF (l_debug = 1) THEN
10447 mydebug('check_pack_lpn: LPN already exists but with different context or Org');
10448 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_CONTEXT');
10449 fnd_msg_pub.ADD;
10450 END IF;
10451
10452 x_return_status := fnd_api.g_ret_sts_error;
10453 RETURN;
10454 END IF;
10455
10456 ELSE -- Not Honor Case Pick
10457 IF (
10458 lpn_cont = wms_container_pub.lpn_context_wip
10459 OR lpn_cont = wms_container_pub.lpn_context_rcv
10460 OR lpn_cont = wms_container_pub.lpn_context_stores
10461 OR lpn_cont = wms_container_pub.lpn_context_intransit
10462 OR lpn_cont = wms_container_pub.lpn_context_vendor
10463 OR lpn_cont = wms_container_pub.lpn_loaded_for_shipment
10464 OR lpn_cont = wms_container_pub.lpn_prepack_for_wip
10465 OR lpn_cont = wms_container_pub.lpn_context_picked
10466 OR lpn_cont = wms_container_pub.LPN_CONTEXT_INV
10467 ) THEN
10468
10469 IF (l_debug = 1) THEN
10470 mydebug('check_pack_lpn: LPN already exists but with different context or Org');
10471 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_CONTEXT');
10472 fnd_msg_pub.ADD;
10473 END IF;
10474
10475 x_return_status := fnd_api.g_ret_sts_error;
10476 RETURN;
10477 END IF;
10478 END IF;
10479 END IF; --Bug7120019
10480
10481 IF create_lpn = 'Y' THEN
10482 IF (l_debug = 1) THEN
10483 mydebug('check_pack_lpn: calling wms_container_pub.create_lpn');
10484 END IF;
10485
10486 wms_container_pub.create_lpn
10487 ( p_api_version => 1.0
10488 , x_return_status => l_return_status
10489 , x_msg_count => l_msg_count
10490 , x_msg_data => x_msg_data
10491 , p_lpn => p_lpn
10492 , p_organization_id => p_org_id
10493 , p_container_item_id => p_container_item_id
10494 , x_lpn_id => x_lpn_id
10495 , p_source => 5
10496 );
10497
10498 IF (l_msg_count = 0) THEN
10499 IF (l_debug = 1) THEN
10500 mydebug('check_pack_lpn: Successful');
10501 END IF;
10502 ELSIF(l_msg_count = 1) THEN
10503 IF (l_debug = 1) THEN
10504 mydebug('check_pack_lpn: Not Successful');
10505 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
10506 END IF;
10507 ELSE
10508 IF (l_debug = 1) THEN
10509 mydebug('check_pack_lpn: Not Successful2');
10510 END IF;
10511
10512 FOR i IN 1 .. l_msg_count LOOP
10513 x_msg_data := fnd_msg_pub.get(i, 'F');
10514
10515 IF (l_debug = 1) THEN
10516 mydebug(REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
10517 END IF;
10518 END LOOP;
10519 END IF;
10520
10521 IF l_return_status = fnd_api.g_ret_sts_unexp_error
10522 OR l_return_status = fnd_api.g_ret_sts_error THEN
10523 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
10524 fnd_msg_pub.ADD;
10525 RAISE fnd_api.g_exc_unexpected_error;
10526 END IF;
10527
10528 END IF;
10529
10530 x_return_status := fnd_api.g_ret_sts_success;
10531
10532 IF (l_debug = 1) THEN
10533 mydebug('check_pack_lpn: check_pack_lpn ends');
10534 END IF;
10535 EXCEPTION
10536 WHEN fnd_api.g_exc_error THEN
10537 x_return_status := fnd_api.g_ret_sts_error;
10538 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10539 IF DBMS_SQL.IS_Open(l_cursorID) THEN
10540 DBMS_SQL.Close_Cursor(l_cursorID);
10541 END IF;
10542 WHEN OTHERS THEN
10543 x_return_status := fnd_api.g_ret_sts_unexp_error;
10544 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
10545 IF DBMS_SQL.IS_Open(l_cursorID) THEN
10546 DBMS_SQL.Close_Cursor(l_cursorID);
10547 END IF;
10548 END check_pack_lpn;
10549
10550
10551 PROCEDURE validate_pick_to_lpn
10552 ( p_api_version_number IN NUMBER
10553 , p_init_msg_lst IN VARCHAR2
10554 , x_return_status OUT NOCOPY VARCHAR2
10555 , x_msg_count OUT NOCOPY NUMBER
10556 , x_msg_data OUT NOCOPY VARCHAR2
10557 , p_organization_id IN NUMBER
10558 , p_pick_to_lpn IN VARCHAR2 --New LPN
10559 , p_temp_id IN NUMBER
10560 , p_project_id IN NUMBER
10561 , p_task_id IN NUMBER
10562 , p_container_item IN VARCHAR2
10563 , p_container_item_id IN NUMBER
10564 , p_suggested_container_item IN VARCHAR2
10565 , p_suggested_container_item_id IN NUMBER
10566 , p_suggested_carton_name IN VARCHAR2
10567 , p_suggested_tolpn_id IN NUMBER
10568 , x_pick_to_lpn_id OUT NOCOPY NUMBER
10569 , p_inventory_item_id IN NUMBER
10570 , p_confirmed_sub IN VARCHAR2
10571 , p_confirmed_loc_id IN NUMBER
10572 , p_revision IN VARCHAR2
10573 , p_confirmed_lots IN VARCHAR2
10574 , p_from_lpn_id IN NUMBER
10575 , p_lot_control IN VARCHAR2
10576 , p_revision_control IN VARCHAR2
10577 , p_serial_control IN VARCHAR2
10578 , p_trx_type_id IN VARCHAR2 -- Bug 4632519
10579 , p_trx_action_id IN VARCHAR2 -- Bug 4632519
10580 ) IS
10581
10582 l_api_version_number CONSTANT NUMBER := 1.0;
10583 l_api_name CONSTANT VARCHAR2(30) := 'validate_pick_to_lpn';
10584 l_pick_to_lpn_exists BOOLEAN := FALSE;
10585 l_current_mmtt_delivery_id NUMBER := NULL;
10586 l_pick_to_lpn_delivery_id NUMBER := NULL;
10587 l_pick_to_lpn_delivery_id2 NUMBER := -999;
10588 l_outermost_lpn_id NUMBER := NULL;
10589
10590 --Added for PJM Integration
10591 l_project_id NUMBER := NULL;
10592 l_task_id NUMBER := NULL;
10593
10594 -- ********************* Start of bug fix 2078002 ********************
10595 l_mmtt_mo_type NUMBER := NULL;
10596 l_mo_type_in_lpn NUMBER := NULL;
10597 l_mmtt_wip_entity_type NUMBER;
10598 l_mmtt_txn_type_id NUMBER;
10599 l_wip_entity_type_in_lpn NUMBER;
10600 -- ********************* End of bug fix 2078002 ********************
10601
10602 l_xfr_sub VARCHAR2(30);
10603 l_xfr_to_location NUMBER;
10604 l_lpn_controlled_flag NUMBER;
10605 l_count NUMBER := 0;
10606 l_item_id NUMBER;
10607 l_operation_plan_id NUMBER;
10608 l_current_carton_grouping_id NUMBER := -999;
10609 l_carton_grouping_id NUMBER := -999;
10610 l_parent_line_id NUMBER;
10611 l_transaction_header_id NUMBER;
10612 l_multiple_pick VARCHAR2(1);
10613 l_bulk_task_exist VARCHAR2(1);
10614 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
10615 l_lot_number VARCHAR2(80) := null;
10616 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
10617 --************added for cartonized check******************
10618 l_container_item_id NUMBER;
10619 l_concatenated_segments VARCHAR2(40);
10620 --***
10621 l_lot_control NUMBER := 1;
10622 l_revision_control NUMBER := 1;
10623 l_commingle_exist VARCHAR2(1);
10624
10625 -- the delimiter for lot string
10626 l_delimiter VARCHAR2(30) := ':';
10627 -- To parse lots
10628 m NUMBER := 1; -- position of delimiter
10629 n NUMBER := 1; -- Start position for substr or
10630 --
10631 -- Bug 4454837,this change will be removed after discussion
10632 /*
10633 l_line_rows WSH_UTIL_CORE.id_tab_type;
10634 l_grouping_rows WSH_UTIL_CORE.id_tab_type;
10635 l_same_carton_grouping BOOLEAN := FALSE;
10636 l_return_status VARCHAR2(2) ;
10637 --
10638 */
10639
10640 --Bug 6168447-Start
10641 l_lpn_name VARCHAR2(30);
10642 l_status_code VARCHAR2(1);
10643 l_delivery_id NUMBER;
10644 l_delivery_detail_id number;
10645 l_wsh_dd_upd_rec WSH_GLBL_VAR_STRCT_GRP.Delivery_Details_Rec_Type;
10646 wsh_update_tbl WSH_GLBL_VAR_STRCT_GRP.delivery_details_Attr_tbl_Type;
10647 l_IN_rec WSH_GLBL_VAR_STRCT_GRP.detailInRecType;
10648 l_OUT_rec WSH_GLBL_VAR_STRCT_GRP.detailOutRecType;
10649 --Bug 6168447-End
10650
10651 TYPE lpn_rectype IS RECORD
10652 ( lpn_id wms_license_plate_numbers.lpn_id%TYPE
10653 , lpn_context wms_license_plate_numbers.lpn_context%TYPE
10654 , outermost_lpn_id wms_license_plate_numbers.outermost_lpn_id%TYPE
10655 );
10656
10657 pick_to_lpn_rec lpn_rectype;
10658
10659 TYPE pjm_rectype IS RECORD
10660 ( prj_id mtl_item_locations.project_id%TYPE
10661 , tsk_id mtl_item_locations.task_id%TYPE
10662 );
10663
10664 mtl_pjm_prj_tsk_rec pjm_rectype;
10665 lpn_pjm_prj_tsk_rec pjm_rectype;
10666
10667 CURSOR others_in_mmtt_delivery_cursor(l_lpn_id IN NUMBER) IS
10668 SELECT wda.delivery_id
10669 FROM wsh_delivery_assignments_v wda
10670 , wsh_delivery_details_ob_grp_v wdd
10671 , mtl_material_transactions_temp mmtt
10672 WHERE mmtt.transfer_lpn_id = l_lpn_id
10673 AND wda.delivery_detail_id = wdd.delivery_detail_id
10674 AND wdd.move_order_line_id = mmtt.move_order_line_id
10675 AND wdd.organization_id = mmtt.organization_id;
10676 --AND wdd.released_status = 'X'; -- For LPN reusability ER : 6845650 Commented for Bug#7430264
10677
10678 CURSOR child_lpns_cursor(l_lpn_id IN NUMBER) IS
10679 SELECT lpn_id
10680 FROM wms_license_plate_numbers
10681 START WITH lpn_id = l_lpn_id
10682 CONNECT BY parent_lpn_id = PRIOR lpn_id;
10683
10684 child_lpns_rec child_lpns_cursor%ROWTYPE;
10685
10686 CURSOR current_delivery_cursor IS
10687 SELECT wda.delivery_id
10688 FROM wsh_delivery_assignments_v wda
10689 , wsh_delivery_details_ob_grp_v wdd
10690 , mtl_material_transactions_temp mmtt
10691 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
10692 AND wdd.move_order_line_id = mmtt.move_order_line_id
10693 AND wdd.organization_id = mmtt.organization_id
10694 AND mmtt.transaction_temp_id = p_temp_id
10695 AND mmtt.organization_id = p_organization_id;
10696
10697 CURSOR drop_delivery_cursor(l_lpn_id IN NUMBER) IS
10698 SELECT wda.delivery_id
10699 FROM wsh_delivery_assignments_v wda
10700 , wsh_delivery_details_ob_grp_v wdd
10701 WHERE wda.parent_delivery_detail_id = wdd.delivery_detail_id
10702 AND wdd.lpn_id = l_lpn_id
10703 AND wdd.organization_id = p_organization_id
10704 AND wdd.released_status = 'X'; -- For LPN reusability ER : 6845650
10705
10706 --
10707 -- This cursor gets the project and task id for the lpn to be
10708 -- loaded into
10709 --
10710 CURSOR lpn_project_task_cursor(p_pick_to_lpn_id NUMBER) IS
10711 SELECT NVL(mil.project_id, -1)
10712 , NVL(mil.task_id, -1)
10713 FROM mtl_item_locations mil, mtl_material_transactions_temp mmtt
10714 WHERE mil.inventory_location_id = mmtt.transfer_to_location
10715 AND mil.organization_id = mmtt.organization_id
10716 AND mmtt.transfer_lpn_id = p_pick_to_lpn_id
10717 AND mmtt.organization_id = p_organization_id;
10718
10719 --
10720 -- This cursor gets the project and task id of the task that is about
10721 -- to be packed
10722 --
10723 CURSOR mtl_project_task_cursor IS
10724 SELECT NVL(mil.project_id, -1)
10725 , NVL(mil.task_id, -1)
10726 FROM mtl_item_locations mil, mtl_material_transactions_temp mmtt
10727 WHERE mil.inventory_location_id = mmtt.transfer_to_location
10728 AND mil.organization_id = mmtt.organization_id
10729 AND mmtt.organization_id = p_organization_id
10730 AND mmtt.transaction_temp_id = p_temp_id;
10731
10732 CURSOR current_carton_grouping_cursor IS
10733 SELECT mol.carton_grouping_id
10734 FROM mtl_txn_request_lines mol, mtl_material_transactions_temp mmtt
10735 WHERE mmtt.transaction_temp_id = p_temp_id
10736 AND mmtt.organization_id = mol.organization_id
10737 AND mmtt.move_order_line_id = mol.line_id;
10738
10739 CURSOR others_carton_grouping_cursor(p_lpn_id IN NUMBER) IS
10740 SELECT DISTINCT mol.carton_grouping_id
10741 FROM mtl_txn_request_lines mol, mtl_material_transactions_temp mmtt
10742 WHERE mmtt.transfer_lpn_id = p_lpn_id
10743 AND mmtt.organization_id = mol.organization_id
10744 AND mmtt.move_order_line_id = mol.line_id;
10745
10746 -- Bug 6168447 : Cursot to check if there are any wdd present for the LPN
10747
10748 CURSOR c_wdd_exists(p_lpn_id NUMBER,p_organization_id NUMBER) is
10749 SELECT distinct wda.delivery_id
10750 FROM wsh_delivery_details wdd, wsh_delivery_assignments wda
10751 WHERE wdd.lpn_id IN (select lpn_id from wms_license_plate_numbers
10752 where organization_id = p_organization_id
10753 and (lpn_id = p_lpn_id
10754 or parent_lpn_id = p_lpn_id
10755 or outermost_lpn_id = p_lpn_id))
10756 AND wda.parent_delivery_detail_id = wdd.delivery_detail_id
10757 AND wdd.released_status = 'X'; -- For LPN reusability ER : 6845650
10758
10759 BEGIN
10760
10761
10762 IF (l_debug = 1) THEN
10763 mydebug('validate_pick_to_lpn: Start Validate_pick_to_lpn.');
10764 END IF;
10765
10766 --
10767 -- Standard call to check for call compatibility
10768 --
10769 IF NOT fnd_api.compatible_api_call(l_api_version_number, p_api_version_number, l_api_name, g_pkg_name) THEN
10770 fnd_message.set_name('WMS', 'WMS_CONT_INCOMPATIBLE_API_CALL');
10771 fnd_msg_pub.ADD;
10772 RAISE fnd_api.g_exc_error;
10773 END IF;
10774
10775 --
10776 -- Initialize message list.
10777 --
10778 IF fnd_api.to_boolean(p_init_msg_lst) THEN
10779 fnd_msg_pub.initialize;
10780 END IF;
10781
10782 --
10783 -- Initialize API return status to success
10784 --
10785 x_return_status := fnd_api.g_ret_sts_success;
10786
10787 --
10788 -- Begin validation process:
10789 -- Check if drop lpn exists by trying to retrieve its lpn ID.
10790 -- If it does not exist, no further validations required
10791 -- so return success.
10792 --
10793 -- jali changed the following: If the LPN doesn't exists then create the LPN.
10794 -- this will resolve the issue why the key in LPN name is not working
10795 -- also the following change will only query the WLPN once.
10796 IF (p_container_item_id = -1) THEN -- no cartonization
10797 l_container_item_id := NULL;
10798 ELSE
10799 l_container_item_id := p_container_item_id;
10800 END IF;
10801
10802 check_pack_lpn
10803 ( p_lpn => p_pick_to_lpn
10804 , p_org_id => p_organization_id
10805 , p_container_item_id => l_container_item_id --new IN parameter
10806 , p_temp_id => p_temp_id --Bug7120019
10807 , x_lpn_id => pick_to_lpn_rec.lpn_id
10808 , x_lpn_context => pick_to_lpn_rec.lpn_context
10809 , x_outermost_lpn_id => pick_to_lpn_rec.outermost_lpn_id
10810 , x_pick_to_lpn_exists => l_pick_to_lpn_exists
10811 , x_return_status => x_return_status
10812 , x_msg_count => x_msg_count
10813 , x_msg_data => x_msg_data
10814 );
10815
10816 IF x_return_status = fnd_api.g_ret_sts_unexp_error
10817 OR x_return_status = fnd_api.g_ret_sts_error THEN
10818 RAISE fnd_api.g_exc_error;
10819 END IF;
10820 x_pick_to_lpn_id := pick_to_lpn_rec.lpn_id;
10821
10822 IF (l_debug = 1) THEN
10823 mydebug('validate_pick_to_lpn:x_pick_to_lpn_id:'||x_pick_to_lpn_id);
10824 END IF;
10825
10826 IF NOT l_pick_to_lpn_exists THEN
10827 IF (l_debug = 1) THEN
10828 mydebug('validate_pick_to_lpn: Drop LPN is a new LPN, no checking required.');
10829 END IF;
10830 RETURN;
10831 --Bug 6168477 -start : Added the following ELSIF condition.
10832 ELSIF pick_to_lpn_rec.lpn_context = wms_container_pub.lpn_context_pregenerated THEN
10833 IF (l_debug = 1) THEN
10834 mydebug('validate_pick_to_lpn: Drop LPN is in context 5,check if associated records are presetn in WDD.');
10835 END IF;
10836 OPEN c_wdd_exists(pick_to_lpn_rec.lpn_id,p_organization_id);
10837 FETCH c_wdd_exists into l_delivery_id;
10838 IF c_wdd_exists%NOTFOUND THEN
10839 CLOSE c_wdd_exists;
10840 ELSE
10841 IF (l_delivery_id IS NOT NULL )THEN
10842 BEGIN
10843 SELECT wlpn.LICENSE_PLATE_NUMBER
10844 INTO l_lpn_name
10845 FROM Wms_License_Plate_Numbers wlpn
10846 WHERE organization_id = p_organization_id
10847 and (lpn_id = pick_to_lpn_rec.lpn_id
10848 or parent_lpn_id = pick_to_lpn_rec.lpn_id
10849 or outermost_lpn_id = pick_to_lpn_rec.lpn_id);
10850
10851 SELECT wdd.released_status,wdd.delivery_detail_id
10852 INTO l_status_code,l_delivery_detail_id
10853 FROM wsh_delivery_details_ob_grp_v wdd
10854 WHERE wdd.container_name = l_lpn_name
10855 AND wdd.released_status = 'X'; -- For LPN reusability ER : 6845650
10856
10857 /* Release 12(K): LPN Synchronization
10858 1. Uniqueness constraint on WDD.container_name is removed
10859 So it is not required to append characters to the LPNs
10860 to get a new containers name
10861 2. Replace API call to wsh_container_grp.update_container
10862 with new API call WSH_WMS_LPN_GRP.Create_Update_Containers
10863 */
10864
10865 IF l_status_code = 'C' THEN
10866
10867 l_wsh_dd_upd_rec.delivery_detail_id := l_delivery_detail_id;
10868 l_wsh_dd_upd_rec.lpn_id := pick_to_lpn_rec.lpn_id;
10869
10870 wsh_update_tbl(1) := l_wsh_dd_upd_rec;
10871
10872 l_IN_rec.caller := 'WMS';
10873 l_IN_rec.action_code := 'UPDATE_NULL';
10874
10875 WSH_WMS_LPN_GRP.Create_Update_Containers (
10876 p_api_version => 1.0
10877 , p_init_msg_list => fnd_api.g_false
10878 , p_commit => fnd_api.g_false
10879 , x_return_status => x_return_status
10880 , x_msg_count => x_msg_count
10881 , x_msg_data => x_msg_data
10882 , p_detail_info_tab => wsh_update_tbl
10883 , p_IN_rec => l_IN_rec
10884 , x_OUT_rec => l_OUT_rec );
10885
10886 IF x_return_status = fnd_api.g_ret_sts_unexp_error
10887 OR x_return_status = fnd_api.g_ret_sts_error THEN
10888 RAISE fnd_api.g_exc_error;
10889 END IF;
10890 ELSE
10891 fnd_message.set_name('WMS','WMS_INVALID_PACK_DELIVERY');
10892 fnd_msg_pub.ADD;
10893 RAISE fnd_api.g_exc_error;
10894 END IF;
10895 END;
10896 CLOSE c_wdd_exists;
10897 END IF;
10898 END IF;
10899 --6168477 End
10900 END IF;
10901
10902
10903 /******** check for cartonized task***************/
10904 IF (p_container_item is not NULL) THEN
10905 IF (l_debug = 1) THEN
10906 mydebug('validate_pick_to_lpn: p_container_item :'||p_container_item);
10907 mydebug('validate_pick_to_lpn: p_container_item_id :'||p_container_item_id);
10908 mydebug('validate_pick_to_lpn: p_suggested_container_item :'||p_suggested_container_item);
10909 mydebug('validate_pick_to_lpn: p_suggested_container_item_id :'||p_suggested_container_item_id);
10910 mydebug('validate_pick_to_lpn: p_pick_to_lpn--new LPN:'||p_pick_to_lpn);
10911 mydebug('validate_pick_to_lpn: p_suggested_carton_name--old LPN:'||p_suggested_carton_name);
10912 mydebug('validate_pick_to_lpn: p_suggested_tolpn_id--old LPN_id:'||p_suggested_tolpn_id);
10913 END IF;
10914
10915 IF (p_pick_to_lpn <> p_suggested_carton_name) THEN
10916 IF (l_debug = 1) THEN
10917 mydebug('tolpn changed from:'||p_suggested_carton_name||' to:'||p_pick_to_lpn);
10918 END IF;
10919 BEGIN
10920 SELECT nvl(inventory_item_id, -999)
10921 INTO l_container_item_id
10922 FROM wms_license_plate_numbers
10923 WHERE license_plate_number = p_pick_to_lpn
10924 AND organization_id = p_organization_id
10925 AND lpn_context IN (wms_container_pub.lpn_context_packing, wms_container_pub.LPN_CONTEXT_PREGENERATED);
10926 EXCEPTION
10927 WHEN no_data_found THEN
10928 -- error out and assuming it should exist
10929 -- tolpn doesn't existing or if existing, but has wrong context
10930 fnd_message.set_name('WMS', 'WMS_LPN_NOT_FOUND');
10931 fnd_msg_pub.ADD;
10932 RAISE fnd_api.g_exc_error;
10933 END;
10934 IF (l_debug = 1) THEN
10935 mydebug('l_container_item_id:'||l_container_item_id);
10936 END IF;
10937 IF (l_container_item_id = -999) THEN --lpn does not use any container
10938 IF (l_debug = 1) THEN
10939 mydebug('LPN does not use any container');
10940 END IF;
10941 fnd_message.set_name('WMS', 'WMS_LPN_NOT_LINKTO_CONT');
10942 fnd_message.set_token('LPN', p_pick_to_lpn );
10943 fnd_msg_pub.ADD;
10944 RAISE fnd_api.g_exc_error;
10945 ELSIF (l_container_item_id <> p_container_item_id) THEN
10946 IF (l_debug = 1) THEN
10947 mydebug('The container, with which LPN associated, is different from confirmed container');
10948 END IF;
10949 BEGIN
10950 SELECT CONCATENATED_SEGMENTS
10951 INTO l_concatenated_segments
10952 FROM MTL_SYSTEM_ITEMS_KFV
10953 WHERE inventory_item_id = l_container_item_id
10954 AND organization_id = p_organization_id;
10955 EXCEPTION
10956 WHEN OTHERS THEN
10957 l_concatenated_segments := '';
10958 END;
10959 fnd_message.set_name('WMS', 'WMS_LPN_ASSOC_WITH_CONT');
10960 fnd_message.set_token('LPN', p_pick_to_lpn );
10961 fnd_message.set_token('CONTAINER', l_concatenated_segments);
10962 fnd_msg_pub.ADD;
10963 RAISE fnd_api.g_exc_error;
10964 END IF;
10965 ELSE
10966 IF (l_debug = 1) THEN
10967 mydebug('tolpn is not changed.');
10968 END IF;
10969 IF (p_container_item = p_suggested_container_item) THEN
10970 IF (l_debug = 1) THEN
10971 mydebug('Container is not changed. tolpn is not change, do nothing');
10972 END IF;
10973 ELSE
10974 IF (l_debug = 1) THEN
10975 mydebug('Container changed. error out');
10976 END IF;
10977 fnd_message.set_name('WMS', 'WMS_LPN_ASSOC_WITH_CONT');
10978 fnd_message.set_token('LPN', p_pick_to_lpn );
10979 fnd_message.set_token('CONTAINER', p_suggested_container_item );
10980 fnd_msg_pub.ADD;
10981 RAISE fnd_api.g_exc_error;
10982 END IF;
10983 END IF;
10984 END IF;
10985
10986 /********* end of checking for cartonized task ********/
10987
10988 /* check for cost group commingle */
10989
10990 IF p_serial_control = 'N' THEN
10991
10992 IF p_lot_control = 'Y' THEN
10993 l_lot_control := 2;
10994 ELSE l_lot_control := 1;
10995 END IF;
10996
10997 IF p_revision_control = 'Y' THEN
10998 l_revision_control := 2;
10999 ELSE l_revision_control := 1;
11000 END IF;
11001
11002
11003 WHILE ( n <> 0)
11004 LOOP
11005 IF p_lot_control = 'Y' THEN
11006 n := INSTR(p_confirmed_lots,l_delimiter,m,1);
11007 IF n = 0 THEN -- Last part OF the string
11008 l_lot_number :=
11009 substr(p_confirmed_lots,m,length(p_confirmed_lots));
11010 ELSE
11011 l_lot_number := substr(p_confirmed_lots,m,n-m) ;
11012 -- start at M get m-n chrs
11013 m := n+1;
11014 END IF;
11015 mydebug ('l_lot_number:' || l_lot_number);
11016 ELSE
11017 n := 0;
11018 mydebug ('not lot controlled');
11019 END IF;
11020
11021 validate_loaded_lpn_cg(
11022 p_organization_id => p_organization_id,
11023 p_inventory_item_id => p_inventory_item_id,
11024 p_subinventory_code => p_confirmed_sub,
11025 p_locator_id => p_confirmed_loc_id,
11026 p_revision => p_revision,
11027 p_lot_number => l_lot_number,
11028 p_lpn_id => p_from_lpn_id,
11029 p_transfer_lpn_id => x_pick_to_lpn_id,
11030 p_lot_control => l_lot_control, --IN NUMBER,
11031 p_revision_control => l_revision_control, --IN NUMBER,
11032 x_commingle_exist => l_commingle_exist,
11033 x_return_status => x_return_status,
11034 p_trx_type_id => p_trx_type_id,
11035 p_trx_action_id => p_trx_action_id);
11036
11037 IF x_return_status = fnd_api.g_ret_sts_unexp_error
11038 OR x_return_status = fnd_api.g_ret_sts_error THEN
11039 RAISE fnd_api.g_exc_error;
11040 END IF;
11041
11042 IF l_commingle_exist = 'Y' THEN
11043 IF (l_debug = 1) THEN
11044 mydebug('Cost group commigle exist.');
11045 END IF;
11046 fnd_message.set_name('WMS', 'WMS_CG_COMMINGLE');
11047 fnd_msg_pub.ADD;
11048 RAISE fnd_api.g_exc_error;
11049 ELSE
11050 IF (l_debug = 1) THEN
11051 mydebug('passed cost group commigle check.');
11052 END IF;
11053 END IF;
11054 END LOOP;
11055
11056 END IF;
11057 /*end of check for cost group commingle */
11058
11059
11060 --
11061 -- If the drop lpn was pre-generated, no validations required
11062 -- Changed the context to be updated to 8 instead of 1 as done earlier
11063 --
11064 /* Mrana: 12/10/03: we need not change the context in this API. We will do it at LOAD
11065 * or Pick More . i.e. Task_load or Task_merge_split API RESP.
11066 * IF pick_to_lpn_rec.lpn_context = wms_container_pub.lpn_context_pregenerated THEN
11067 --
11068 -- Update the context to "Packing Context" (8)
11069 --
11070 UPDATE wms_license_plate_numbers
11071 SET lpn_context = wms_container_pub.lpn_context_packing
11072 WHERE lpn_id = pick_to_lpn_rec.lpn_id;
11073
11074 IF (l_debug = 1) THEN
11075 mydebug('validate_pick_to_lpn: Drop LPN is pre-generated, no checking required.');
11076 END IF;
11077
11078 RETURN;
11079 END IF; */
11080
11081
11082 /**********patchset J bulk picking **********************/
11083 -- move the following query up to here, so that we can query the parent line id to see if
11084 -- it is bulk picking or not -----
11085 /***********************************************************************/
11086 IF (l_debug = 1) THEN
11087 mydebug('validate_pick_to_lpn: patchset J bulk picking started');
11088 END IF;
11089
11090 SELECT mmtt.transfer_subinventory
11091 , mmtt.transfer_to_location
11092 , mmtt.inventory_item_id
11093 , mmtt.operation_plan_id
11094 , nvl(mmtt.parent_line_id,-1)
11095 , mmtt.transaction_header_id
11096 INTO l_xfr_sub
11097 , l_xfr_to_location
11098 , l_item_id
11099 , l_operation_plan_id
11100 , l_parent_line_id
11101 , l_transaction_header_id
11102 FROM mtl_material_transactions_temp mmtt
11103 WHERE mmtt.transaction_temp_id = p_temp_id;
11104
11105 IF (l_debug = 1) THEN
11106 mydebug('validate_pick_to_lpn: parent line id:'||l_parent_line_id);
11107 END IF;
11108
11109
11110 IF l_parent_line_id = p_temp_id THEN -- bulk picking task
11111 -- check to see if this is for multiple pick of the same task or not
11112 -- If yes, no problem, otherwise raise error
11113 -- program can come to here which means the LPN is not pregenerated LPN
11114 BEGIN
11115 select 'N'
11116 into l_multiple_pick
11117 from dual
11118 where exists (select 1
11119 from mtl_material_transactions_temp
11120 where transfer_lpn_id = pick_to_lpn_rec.lpn_id
11121 and transaction_header_id <>l_transaction_header_id);
11122
11123 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_NOT_NEW'); -- new message
11124 fnd_msg_pub.ADD;
11125 RAISE fnd_api.g_exc_error;
11126 EXCEPTION
11127 WHEN NO_DATA_FOUND THEN RETURN; -- this lpn is fine and no need to do all
11128 -- the following checks
11129 END;
11130 ELSE -- regular task but maybe the lpn has contains bulk tasks
11131 BEGIN
11132 select 'Y'
11133 into l_bulk_task_exist
11134 from dual
11135 where exists (select 1
11136 from mtl_material_transactions_temp
11137 where transfer_lpn_id = pick_to_lpn_rec.lpn_id
11138 and transaction_temp_id = parent_line_id -- bulk task
11139 );
11140 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_BULK');
11141 fnd_msg_pub.ADD;
11142 RAISE fnd_api.g_exc_error;
11143 EXCEPTION
11144 WHEN NO_DATA_FOUND THEN null;
11145 END;
11146 END IF;
11147
11148 IF (l_debug = 1) THEN
11149 mydebug('validate_pick_to_lpn: patchset J bulk picking ended');
11150 END IF;
11151
11152 /******** end of patchset J bulk picking ***************************/
11153
11154
11155 --
11156 -- *********************Start of bug fix 2078002,2095080 ********************
11157 -- Check if the task that is about to pack into the LPN has the same
11158 -- move order type as the tasks already packed into the same LPN
11159 --
11160 SELECT mtrh.move_order_type
11161 , mmtt.transaction_type_id
11162 , mmtt.wip_entity_type
11163 INTO l_mmtt_mo_type
11164 , l_mmtt_txn_type_id
11165 , l_mmtt_wip_entity_type
11166 FROM mtl_txn_request_headers mtrh
11167 , mtl_txn_request_lines mtrl
11168 , mtl_material_transactions_temp mmtt
11169 WHERE mtrh.header_id = mtrl.header_id
11170 AND mtrl.line_id = mmtt.move_order_line_id
11171 AND mmtt.transaction_temp_id = p_temp_id;
11172
11173 BEGIN
11174 SELECT mtrh.move_order_type
11175 , mmtt.wip_entity_type
11176 INTO l_mo_type_in_lpn
11177 , l_wip_entity_type_in_lpn
11178 FROM mtl_txn_request_headers mtrh
11179 , mtl_txn_request_lines mtrl
11180 , mtl_material_transactions_temp mmtt
11181 WHERE mtrh.header_id = mtrl.header_id
11182 AND mtrl.line_id = mmtt.move_order_line_id
11183 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
11184 AND ROWNUM < 2;
11185 EXCEPTION
11186 WHEN NO_DATA_FOUND THEN
11187 l_mo_type_in_lpn := null;
11188 END;
11189
11190 IF (l_mo_type_in_lpn is not null ) THEN
11191 IF l_mo_type_in_lpn <> l_mmtt_mo_type THEN
11192 IF (l_debug = 1) THEN
11193 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT have different MO type.');
11194 mydebug(' p_temp_id => ' || p_temp_id);
11195 mydebug(' lpn_id => ' || pick_to_lpn_rec.lpn_id);
11196 mydebug(' l_mmtt_mo_type => ' || l_mmtt_mo_type);
11197 mydebug(' l_mo_type_in_lpn => ' || l_mo_type_in_lpn);
11198 END IF;
11199 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_MO_TYPE');
11200 fnd_msg_pub.ADD;
11201 RAISE fnd_api.g_exc_error;
11202 ELSIF l_mmtt_txn_type_id = 35
11203 OR l_mmtt_txn_type_id = 51 THEN -- Mfg pick
11204 IF l_mmtt_wip_entity_type <> l_wip_entity_type_in_lpn THEN
11205 IF (l_debug = 1) THEN
11206 mydebug('validate_pick_to_lpn: This is a manufacturing component pick.');
11207 mydebug('WIP entity type IS NOT the same AS that OF the old mmtt RECORD');
11208 END IF;
11209 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_MFG_MODE');
11210 fnd_msg_pub.ADD;
11211 RAISE fnd_api.g_exc_error;
11212 END IF;
11213 END IF;
11214 END IF;
11215 -- *********************End of bug fix 2078002,2095080 ********************
11216
11217 --
11218 -- Bug 2355453: Check to see if the LPN is already going to some other lpn
11219 -- controlled sub. In that case, do not allow material to be picked into
11220 -- this LPN
11221 --
11222 IF (l_debug = 1) THEN
11223 mydebug('validate_pick_to_lpn: Check to see if LPN is already going to some other sub/loc');
11224 END IF;
11225
11226 /* moved up already
11227 SELECT mmtt.transfer_subinventory
11228 , mmtt.transfer_to_location
11229 , mmtt.inventory_item_id
11230 , mmtt.operation_plan_id
11231 INTO l_xfr_sub
11232 , l_xfr_to_location
11233 , l_item_id
11234 , l_operation_plan_id
11235 FROM mtl_material_transactions_temp mmtt
11236 WHERE mmtt.transaction_temp_id = p_temp_id; */
11237
11238 l_lpn_controlled_flag := wms_globals.g_non_lpn_controlled_sub;
11239
11240 IF l_xfr_sub IS NOT NULL THEN
11241 SELECT lpn_controlled_flag
11242 INTO l_lpn_controlled_flag
11243 FROM mtl_secondary_inventories
11244 WHERE organization_id = p_organization_id
11245 AND secondary_inventory_name = l_xfr_sub;
11246 END IF;
11247
11248 IF l_xfr_sub IS NOT NULL
11249 AND l_lpn_controlled_flag = wms_globals.g_lpn_controlled_sub THEN
11250 IF (l_debug = 1) THEN
11251 mydebug('validate_pick_to_lpn: Transfer Sub is LPN Controlled');
11252 END IF;
11253
11254 --
11255 -- Ensure that all remaining picks on the LPN are also for the same sub
11256 --
11257 l_count := 0;
11258
11259 BEGIN
11260 SELECT COUNT(*)
11261 INTO l_count
11262 FROM mtl_material_transactions_temp mmtt
11263 WHERE mmtt.transaction_temp_id <> p_temp_id
11264 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
11265 AND ( NVL(mmtt.transfer_subinventory, 0) <> l_xfr_sub
11266 OR
11267 NVL(mmtt.transfer_to_location, 0) <> l_xfr_to_location
11268 );
11269 EXCEPTION
11270 WHEN NO_DATA_FOUND THEN
11271 l_count := 0;
11272 END;
11273
11274 IF l_count > 0 THEN
11275 IF (l_debug = 1) THEN
11276 mydebug('validate_pick_to_lpn: Drop LPN is going to an LPN controlled sub');
11277 mydebug('validate_pick_to_lpn: Cannot add picks not going to the same sub');
11278 END IF;
11279
11280 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_SUBINV');
11281 fnd_msg_pub.ADD;
11282 RAISE fnd_api.g_exc_error;
11283 END IF;
11284 ELSE
11285 --
11286 -- Current temp ID has a NULL xfer sub (issue txn)
11287 -- or the xfer sub is non LPN-controlled.
11288 -- Ensure that no other picks on the same LPN are to
11289 -- LPN controlled subs
11290 --
11291
11292 IF (l_debug = 1) THEN
11293 mydebug('validate_pick_to_lpn: Transfer Sub is non LPN Controlled or null.');
11294 END IF;
11295
11296 l_count := 0;
11297 BEGIN
11298 SELECT 1
11299 INTO l_count
11300 FROM DUAL
11301 WHERE EXISTS
11302 ( SELECT 'x'
11303 FROM mtl_material_transactions_temp mmtt
11304 , mtl_secondary_inventories msi
11305 WHERE mmtt.transaction_temp_id <> p_temp_id
11306 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
11307 AND msi.organization_id = p_organization_id
11308 AND msi.secondary_inventory_name = mmtt.transfer_subinventory
11309 AND msi.lpn_controlled_flag = wms_globals.g_lpn_controlled_sub
11310 );
11311 EXCEPTION
11312 WHEN NO_DATA_FOUND THEN
11313 l_count := 0;
11314 END;
11315
11316 IF l_count > 0 THEN
11317 IF (l_debug = 1) THEN
11318 mydebug('validate_pick_to_lpn: Drop LPN has pick(s) for an LPN-controlled sub');
11319 END IF;
11320
11321 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_SUBINV');
11322 fnd_msg_pub.ADD;
11323 RAISE fnd_api.g_exc_error;
11324 END IF;
11325 END IF;
11326
11327 --
11328 IF (l_debug = 1) THEN
11329 mydebug('validate_pick_to_lpn: Check to see if LPN is associated with material' ||
11330 ' FOR a different operation plan');
11331 END IF;
11332
11333 l_count := 0;
11334 BEGIN
11335 SELECT COUNT(1)
11336 INTO l_count
11337 FROM mtl_material_transactions_temp mmtt
11338 WHERE mmtt.transaction_temp_id <> p_temp_id
11339 AND mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
11340 AND mmtt.operation_plan_id <> l_operation_plan_id;
11341 EXCEPTION
11342 WHEN NO_DATA_FOUND THEN
11343 l_count := 0;
11344 END;
11345
11346 IF l_count > 0 THEN
11347 IF (l_debug = 1) THEN
11348 mydebug('validate_pick_to_lpn: Drop LPN is associated with material FOR a different operation plan');
11349 END IF;
11350
11351 fnd_message.set_name('WMS', 'WMS_INVLD_PICKTO_LPN_OPER_PLAN');
11352 fnd_msg_pub.ADD;
11353 RAISE fnd_api.g_exc_error;
11354 END IF;
11355
11356
11357 --
11358 -- No further checks required if LPN contains manufacturing picks
11359 -- The checks after this are related to delivery ID and PJM orgs
11360 --
11361 -- actually no further checks if it is replenishment or others except pick wave
11362 IF l_mmtt_mo_type <> 3 THEN
11363 RETURN;
11364 END IF;
11365
11366 -- Now check if the picked LPN
11367 -- belongs to delivery which is different from current delivery
11368 --
11369 OPEN current_delivery_cursor;
11370
11371 LOOP
11372 FETCH current_delivery_cursor INTO l_current_mmtt_delivery_id;
11373 EXIT WHEN l_current_mmtt_delivery_id IS NOT NULL
11374 OR current_delivery_cursor%NOTFOUND;
11375 END LOOP;
11376
11377 CLOSE current_delivery_cursor;
11378
11379 IF (l_debug = 1) THEN
11380 mydebug('validate_pick_to_lpn: l_current_mmtt_delivery_id:' || l_current_mmtt_delivery_id);
11381 END IF;
11382
11383 --
11384 -- If the current MMTT is not associated with a delivery yet
11385 -- then no further checking required, return success
11386 --
11387 IF l_current_mmtt_delivery_id IS NULL THEN
11388 IF (l_debug = 1) THEN
11389 mydebug('validate_pick_to_lpn: Current MMTT is not associated with a delivery');
11390 END IF;
11391
11392 OPEN current_carton_grouping_cursor;
11393 FETCH current_carton_grouping_cursor INTO l_current_carton_grouping_id;
11394 CLOSE current_carton_grouping_cursor;
11395
11396 IF (l_current_carton_grouping_id = -999) THEN
11397 IF (l_debug = 1) THEN
11398 mydebug('validate_pick_to_lpn: can NOT find move order line for current task');
11399 END IF;
11400
11401 fnd_message.set_name('WMS', 'WMS_NO_MOL');
11402 fnd_msg_pub.ADD;
11403 RAISE fnd_api.g_exc_error;
11404 END IF;
11405
11406 IF l_current_carton_grouping_id IS NOT NULL THEN -- found carton_grouping_id
11407 OPEN others_carton_grouping_cursor(pick_to_lpn_rec.lpn_id);
11408
11409 LOOP
11410 FETCH others_carton_grouping_cursor INTO l_carton_grouping_id;
11411 EXIT WHEN l_current_carton_grouping_id = NVL(l_carton_grouping_id, 0)
11412 OR others_carton_grouping_cursor%NOTFOUND;
11413 END LOOP;
11414
11415 CLOSE others_carton_grouping_cursor;
11416
11417 IF l_carton_grouping_id = -999 THEN -- it is the first task in the lpn
11418 mydebug('validate_pick_to_lpn: This is the first task for the lpn ' ||
11419 'and the task without delivery, so ok..');
11420 RETURN;
11421 END IF;
11422
11423 IF l_carton_grouping_id IS NOT NULL THEN
11424 IF l_carton_grouping_id = l_current_carton_grouping_id THEN --the same carton_grouping_id
11425 IF (l_debug = 1) THEN
11426 mydebug('validate_pick_to_lpn: found the task in lpn which has ' ||
11427 'the same carton_grouping_id as current task');
11428 END IF;
11429
11430 OPEN others_in_mmtt_delivery_cursor(pick_to_lpn_rec.lpn_id);
11431 l_pick_to_lpn_delivery_id := -999;
11432
11433 LOOP
11434 FETCH others_in_mmtt_delivery_cursor INTO l_pick_to_lpn_delivery_id;
11435 EXIT WHEN l_pick_to_lpn_delivery_id IS NULL
11436 OR others_in_mmtt_delivery_cursor%NOTFOUND;
11437 END LOOP;
11438
11439 CLOSE others_in_mmtt_delivery_cursor;
11440
11441 IF l_pick_to_lpn_delivery_id = -999 THEN --there is mol, but no wdd or wda, raise error
11442 IF (l_debug = 1) THEN
11443 mydebug('validate_pick_to_lpn: can NOT find either wdd or wda for tasks in the lpn');
11444 END IF;
11445
11446 fnd_message.set_name('WMS', 'WMS_NO_WDD_WDA');
11447 fnd_msg_pub.ADD;
11448 RAISE fnd_api.g_exc_error;
11449 END IF;
11450
11451 IF l_pick_to_lpn_delivery_id IS NULL THEN
11452 IF (l_debug = 1) THEN
11453 mydebug('validate_pick_to_lpn: found a task which has ' ||
11454 'the same carton_grouping_id as current task, and also no delivery.');
11455 END IF;
11456
11457 RETURN;
11458 ELSE
11459 IF (l_debug = 1) THEN
11460 mydebug('validate_pick_to_lpn: other tasks in lpn have different deliveries');
11461 END IF;
11462
11463 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
11464 fnd_msg_pub.ADD;
11465 RAISE fnd_api.g_exc_error;
11466 END IF;
11467 ELSE -- they have different carton_grouping_id
11468 --{
11469 IF (l_debug = 1) THEN
11470 mydebug('validate_pick_to_lpn: other tasks in lpn have different carton grouping id');
11471 END IF;
11472 --
11473 -- Start : R12 Bug 4454837, this change will be removed
11474 --
11475 /*
11476 BEGIN
11477 --{
11478 SELECT wdd.delivery_detail_id INTO l_line_rows(1)
11479 FROM wsh_delivery_details wdd
11480 , mtl_material_transactions_temp mmtt
11481 WHERE mmtt.transaction_temp_id = p_temp_id
11482 AND wdd.move_order_line_id = mmtt.move_order_line_id
11483 AND wdd.organization_id = mmtt.organization_id;
11484 --
11485 SELECT wdd.delivery_detail_id INTO l_line_rows(2)
11486 FROM wsh_delivery_details wdd
11487 , mtl_material_transactions_temp mmtt
11488 WHERE mmtt.transfer_lpn_id = pick_to_lpn_rec.lpn_id
11489 AND wdd.move_order_line_id = mmtt.move_order_line_id
11490 AND wdd.organization_id = mmtt.organization_id
11491 AND rownum<2;
11492 --
11493 IF (l_debug = 1) THEN
11494 mydebug('validate_pick_to_lpn: Before calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping() to decide if we can load into this LPN');
11495 mydebug('Parameters : delivery_detail_id(1):'|| l_line_rows(1) ||' , delivery_detail_id(2) :'||l_line_rows(2));
11496 END IF;
11497 --
11498 -- call to the shipping API.
11499 --
11500 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping(
11501 p_line_rows => l_line_rows,
11502 x_grouping_rows => l_grouping_rows,
11503 x_return_status => l_return_status);
11504 --
11505 IF (l_return_status = FND_API.G_RET_STS_SUCCESS
11506 AND l_grouping_rows (1) = l_grouping_rows(2) ) THEN
11507 l_same_carton_grouping := TRUE;
11508 ELSE
11509 l_same_carton_grouping := FALSE;
11510 END IF;
11511 --
11512 EXCEPTION
11513 WHEN NO_DATA_FOUND THEN
11514 IF (l_debug = 1) THEN
11515 mydebug('No Data found Exception raised when matching delivery grouping attributes');
11516 l_same_carton_grouping := FALSE;
11517 END IF;
11518 WHEN OTHERS THEN
11519 IF (l_debug = 1) THEN
11520 mydebug('Other Exception raised when matching for delivery grouping attributes');
11521 l_same_carton_grouping := FALSE;
11522 END IF;
11523 --}
11524 END;
11525 --
11526 IF (l_same_carton_grouping = FALSE) then */
11527 fnd_message.set_name('WMS', 'WMS_DIFF_CARTON_GROUP');
11528 fnd_msg_pub.ADD;
11529 RAISE fnd_api.g_exc_error;
11530 /*END IF;
11531 --
11532 -- End : R12 bug 4454837.
11533 --} */
11534 END IF;
11535 ELSE -- some of carton_grouping_id is null
11536 IF (l_debug = 1) THEN
11537 mydebug('validate_pick_to_lpn: some of tasks in lpn have NULL carton_grouping_id');
11538 END IF;
11539 fnd_message.set_name('WMS', 'WMS_CARTON_GROUP_NULL');
11540 fnd_msg_pub.ADD;
11541 RAISE fnd_api.g_exc_error;
11542 END IF;
11543 ELSE --carton_grouping_id is null
11544 IF (l_debug = 1) THEN
11545 mydebug('validate_pick_to_lpn: carton_grouping_id of current task is null');
11546 END IF;
11547 --bug3481923 only fail if it is not requisition on repl mo
11548 if (l_mmtt_mo_type not in(1,2)) then
11549 fnd_message.set_name('WMS', 'WMS_CARTON_GROUP_NULL');
11550 fnd_msg_pub.ADD;
11551 RAISE fnd_api.g_exc_error;
11552 end if;
11553 END IF;
11554 END IF;
11555
11556 -- Check if picked LPN has been picked_to in previous tasks, tasks that
11557 -- are still IN MMTT and shipping tables do not have the drop lpn yet
11558
11559 OPEN others_in_mmtt_delivery_cursor(pick_to_lpn_rec.lpn_id);
11560
11561 LOOP
11562 FETCH others_in_mmtt_delivery_cursor INTO l_pick_to_lpn_delivery_id2;
11563 EXIT WHEN l_pick_to_lpn_delivery_id2 IS NOT NULL
11564 OR others_in_mmtt_delivery_cursor%NOTFOUND;
11565 END LOOP;
11566
11567 CLOSE others_in_mmtt_delivery_cursor;
11568
11569 IF (l_debug = 1) THEN
11570 mydebug('validate_pick_to_lpn: l_pick_to_lpn_delivery_id2' || l_pick_to_lpn_delivery_id2);
11571 END IF;
11572
11573 mydebug('l_pick_to_lpn_delivery_id2 : '||l_pick_to_lpn_delivery_id2);
11574 mydebug('l_current_mmtt_delivery_id : '||l_current_mmtt_delivery_id);
11575
11576 IF (l_pick_to_lpn_delivery_id2 IS NOT NULL) AND (l_pick_to_lpn_delivery_id2 <> -999) THEN
11577 IF l_pick_to_lpn_delivery_id2 <> l_current_mmtt_delivery_id THEN
11578 IF (l_debug = 1) THEN
11579 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT go to different deliveries.');
11580 END IF;
11581
11582 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
11583 fnd_msg_pub.ADD;
11584 RAISE fnd_api.g_exc_error;
11585 END IF;
11586 ELSIF l_pick_to_lpn_delivery_id2 IS NULL THEN
11587 IF (l_debug = 1) THEN
11588 mydebug('validate_pick_to_lpn: Picked LPN does not have deliveries.');
11589 END IF;
11590
11591 IF l_current_mmtt_delivery_id IS NOT NULL THEN
11592 IF (l_debug = 1) THEN
11593 mydebug('validate_pick_to_lpn: Current task has delivery.');
11594 mydebug('validate_pick_to_lpn: Picked LPN does not have delivery and current task has delivery.');
11595 END IF;
11596
11597 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
11598 fnd_msg_pub.ADD;
11599 RAISE fnd_api.g_exc_error;
11600 END IF;
11601 ELSIF l_pick_to_lpn_delivery_id2 = -999 THEN
11602 IF (l_debug = 1) THEN
11603 mydebug('validate_pick_to_lpn: LPN does not contain other tasks. This is the first task, so ok.');
11604 END IF;
11605 END IF;
11606
11607 IF pick_to_lpn_rec.outermost_lpn_id IS NOT NULL THEN
11608 -- We need to check delivery for outermost lpn or drill down if needed
11609 l_outermost_lpn_id := pick_to_lpn_rec.outermost_lpn_id;
11610 ELSE
11611 -- We need to check delivery for pick_to_lpn or drill down if needed
11612 l_outermost_lpn_id := pick_to_lpn_rec.lpn_id;
11613 END IF;
11614
11615 --
11616 -- Find the outermost LPN's delivery ID
11617 --
11618 OPEN drop_delivery_cursor(l_outermost_lpn_id);
11619 FETCH drop_delivery_cursor INTO l_pick_to_lpn_delivery_id;
11620 CLOSE drop_delivery_cursor;
11621
11622 mydebug('l_pick_to_lpn_delivery_id : '||l_pick_to_lpn_delivery_id);
11623 mydebug('l_current_mmtt_delivery_id : '||l_current_mmtt_delivery_id);
11624
11625 IF l_pick_to_lpn_delivery_id IS NOT NULL THEN
11626 IF l_pick_to_lpn_delivery_id <> l_current_mmtt_delivery_id THEN
11627 IF (l_debug = 1) THEN
11628 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT go to different deliveries.');
11629 END IF;
11630
11631 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
11632 fnd_msg_pub.ADD;
11633 RAISE fnd_api.g_exc_error;
11634 NULL;
11635 ELSE
11636 --
11637 -- Picked LPN and current MMTT are on the same delivery
11638 -- return success
11639 --
11640 IF (l_debug = 1) THEN
11641 mydebug('validate_pick_to_lpn: Picked LPN and current MMTT go to same delivery: ' ||
11642 l_pick_to_lpn_delivery_id);
11643 END IF;
11644
11645 RETURN;
11646 END IF;
11647 ELSE
11648 IF (l_debug = 1) THEN
11649 mydebug('validate_pick_to_lpn: Drop LPN does not have a delivery ID, checking child LPNs');
11650 END IF;
11651
11652 OPEN child_lpns_cursor(l_outermost_lpn_id);
11653
11654 LOOP
11655 FETCH child_lpns_cursor INTO child_lpns_rec;
11656 EXIT WHEN child_lpns_cursor%NOTFOUND;
11657
11658 IF child_lpns_cursor%FOUND THEN
11659 OPEN drop_delivery_cursor(child_lpns_rec.lpn_id);
11660 FETCH drop_delivery_cursor INTO l_pick_to_lpn_delivery_id;
11661 CLOSE drop_delivery_cursor;
11662 END IF;
11663
11664 EXIT WHEN l_pick_to_lpn_delivery_id IS NOT NULL;
11665 END LOOP;
11666
11667 CLOSE child_lpns_cursor;
11668
11669 --
11670 -- If the child LPNs also don't have a delivery ID
11671 -- then ok to deposit
11672 --
11673 IF l_pick_to_lpn_delivery_id IS NOT NULL THEN
11674 IF l_pick_to_lpn_delivery_id <> l_current_mmtt_delivery_id THEN
11675 IF (l_debug = 1) THEN
11676 mydebug('validate_pick_to_lpn: LPNs are on diff deliveries.');
11677 END IF;
11678
11679 fnd_message.set_name('WMS', 'WMS_PICK_TO_LPN_DIFF_DELIV');
11680 fnd_msg_pub.ADD;
11681 RAISE fnd_api.g_exc_error;
11682 ELSE
11683 --
11684 -- Child LPN has the delivery as the current MMTT, return success
11685 --
11686 IF (l_debug = 1) THEN
11687 mydebug('validate_pick_to_lpn: A child LPN is on the same delivery ' ||
11688 'as that OF the CURRENT MMTT, return success.');
11689 END IF;
11690
11691 RETURN;
11692 END IF;
11693 ELSE
11694 --
11695 -- No child LPNs have a delivery ID yet
11696 -- return success
11697 --
11698 IF (l_debug = 1) THEN
11699 mydebug('validate_pick_to_lpn: Child LPNs do not have a delivery ID either, return success.');
11700 END IF;
11701
11702 RETURN;
11703 END IF;
11704 END IF;
11705
11706 --
11707 -- Fetch the Project/Task id associated with the LPN passed
11708 --
11709 -- PJM Integration:
11710 -- Check if the task that is about to pack into the LPN has the same
11711 -- transfer project_id and task_id as the lpn to which it is going to
11712 -- be loaded into.
11713 -- If yes, proceed, else return
11714 --
11715 IF (p_project_id IS NOT NULL) THEN
11716 OPEN lpn_project_task_cursor( pick_to_lpn_rec.lpn_id);
11717
11718 LOOP
11719 FETCH lpn_project_task_cursor INTO lpn_pjm_prj_tsk_rec;
11720 EXIT WHEN lpn_project_task_cursor%NOTFOUND;
11721 OPEN mtl_project_task_cursor;
11722
11723 LOOP
11724 FETCH mtl_project_task_cursor INTO mtl_pjm_prj_tsk_rec;
11725 EXIT WHEN mtl_project_task_cursor%NOTFOUND;
11726 -- project and task both should be the same as
11727 IF ((mtl_pjm_prj_tsk_rec.prj_id <> lpn_pjm_prj_tsk_rec.prj_id)
11728 OR (mtl_pjm_prj_tsk_rec.tsk_id <> lpn_pjm_prj_tsk_rec.tsk_id)) THEN
11729 RAISE fnd_api.g_exc_error;
11730 END IF;
11731 END LOOP;
11732
11733 CLOSE mtl_project_task_cursor;
11734 END LOOP;
11735
11736 CLOSE lpn_project_task_cursor;
11737 END IF;
11738 EXCEPTION
11739 WHEN fnd_api.g_exc_error THEN
11740 x_return_status := fnd_api.g_ret_sts_error;
11741 -- Get message count and data
11742 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11743
11744 IF (l_debug = 1) THEN
11745 mydebug('validate_pick_to_lpn: @' || x_msg_data || '@');
11746 END IF;
11747
11748 IF others_in_mmtt_delivery_cursor%ISOPEN THEN
11749 CLOSE others_in_mmtt_delivery_cursor;
11750 END IF;
11751
11752 IF child_lpns_cursor%ISOPEN THEN
11753 CLOSE child_lpns_cursor;
11754 END IF;
11755
11756 IF current_delivery_cursor%ISOPEN THEN
11757 CLOSE current_delivery_cursor;
11758 END IF;
11759
11760 IF drop_delivery_cursor%ISOPEN THEN
11761 CLOSE drop_delivery_cursor;
11762 END IF;
11763
11764 IF lpn_project_task_cursor%ISOPEN THEN
11765 CLOSE lpn_project_task_cursor;
11766 END IF;
11767
11768 IF mtl_project_task_cursor%ISOPEN THEN
11769 CLOSE mtl_project_task_cursor;
11770 END IF;
11771
11772 IF current_carton_grouping_cursor%ISOPEN THEN
11773 CLOSE current_carton_grouping_cursor;
11774 END IF;
11775
11776 IF others_carton_grouping_cursor%ISOPEN THEN
11777 CLOSE others_carton_grouping_cursor;
11778 END IF;
11779 WHEN OTHERS THEN
11780 x_return_status := fnd_api.g_ret_sts_unexp_error;
11781
11782 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
11783 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
11784 END IF;
11785
11786 -- Get message count and data
11787 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11788
11789 IF others_in_mmtt_delivery_cursor%ISOPEN THEN
11790 CLOSE others_in_mmtt_delivery_cursor;
11791 END IF;
11792
11793 IF child_lpns_cursor%ISOPEN THEN
11794 CLOSE child_lpns_cursor;
11795 END IF;
11796
11797 IF current_delivery_cursor%ISOPEN THEN
11798 CLOSE current_delivery_cursor;
11799 END IF;
11800
11801 IF drop_delivery_cursor%ISOPEN THEN
11802 CLOSE drop_delivery_cursor;
11803 END IF;
11804
11805 IF lpn_project_task_cursor%ISOPEN THEN
11806 CLOSE lpn_project_task_cursor;
11807 END IF;
11808
11809 IF mtl_project_task_cursor%ISOPEN THEN
11810 CLOSE mtl_project_task_cursor;
11811 END IF;
11812
11813 IF current_carton_grouping_cursor%ISOPEN THEN
11814 CLOSE current_carton_grouping_cursor;
11815 END IF;
11816
11817 IF others_carton_grouping_cursor%ISOPEN THEN
11818 CLOSE others_carton_grouping_cursor;
11819 END IF;
11820
11821 IF (l_debug = 1) THEN
11822 mydebug('validate_pick_to_lpn: @' || x_msg_data || '@');
11823 END IF;
11824 END validate_pick_to_lpn;
11825
11826
11827 PROCEDURE validate_sub_loc_status(
11828 p_wms_installed IN VARCHAR2
11829 , p_temp_id IN NUMBER
11830 , p_confirmed_sub IN VARCHAR2
11831 , p_confirmed_loc_id IN NUMBER
11832 , x_return_status OUT NOCOPY VARCHAR2
11833 , x_msg_count OUT NOCOPY NUMBER
11834 , x_msg_data OUT NOCOPY VARCHAR2
11835 , x_result OUT NOCOPY NUMBER
11836 ) IS
11837 l_transaction_type_id NUMBER;
11838 l_org_id NUMBER;
11839 l_item_id NUMBER;
11840 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
11841 BEGIN
11842 IF (l_debug = 1) THEN
11843 mydebug('validate_sub_loc_status: validate_sub_loc_status begins');
11844 END IF;
11845
11846 x_return_status := fnd_api.g_ret_sts_success;
11847
11848 SELECT mmtt.transaction_type_id
11849 , mmtt.organization_id
11850 , mmtt.inventory_item_id
11851 INTO l_transaction_type_id
11852 , l_org_id
11853 , l_item_id
11854 FROM mtl_material_transactions_temp mmtt
11855 WHERE mmtt.transaction_temp_id = p_temp_id;
11856
11857 IF inv_material_status_grp.is_status_applicable(
11858 p_wms_installed => p_wms_installed
11859 , p_trx_status_enabled => NULL
11860 , p_trx_type_id => l_transaction_type_id
11861 , p_lot_status_enabled => NULL
11862 , p_serial_status_enabled => NULL
11863 , p_organization_id => l_org_id
11864 , p_inventory_item_id => l_item_id
11865 , p_sub_code => p_confirmed_sub
11866 , p_locator_id => p_confirmed_loc_id
11867 , p_lot_number => NULL
11868 , p_serial_number => NULL
11869 , p_object_type => 'Z'
11870 ) = 'Y'
11871 AND inv_material_status_grp.is_status_applicable(
11872 p_wms_installed => p_wms_installed
11873 , p_trx_status_enabled => NULL
11874 , p_trx_type_id => l_transaction_type_id
11875 , p_lot_status_enabled => NULL
11876 , p_serial_status_enabled => NULL
11877 , p_organization_id => l_org_id
11878 , p_inventory_item_id => l_item_id
11879 , p_sub_code => p_confirmed_sub
11880 , p_locator_id => p_confirmed_loc_id
11881 , p_lot_number => NULL
11882 , p_serial_number => NULL
11883 , p_object_type => 'L'
11884 ) = 'Y' THEN
11885 x_result := 1;
11886
11887 IF (l_debug = 1) THEN
11888 mydebug('validate_sub_loc_status: Material status is correct. x_result = 1');
11889 END IF;
11890 ELSE
11891 x_result := 0;
11892
11893 IF (l_debug = 1) THEN
11894 mydebug('validate_sub_loc_status: Material status is incorrect. x_result = 0');
11895 END IF;
11896 END IF;
11897
11898 IF (l_debug = 1) THEN
11899 mydebug('validate_sub_loc_status: End of validate_sub_loc_status');
11900 END IF;
11901 EXCEPTION
11902 WHEN fnd_api.g_exc_error THEN
11903 x_return_status := fnd_api.g_ret_sts_error;
11904
11905 IF (l_debug = 1) THEN
11906 mydebug('validate_sub_loc_status: Error - ' || SQLERRM);
11907 END IF;
11908
11909 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11910 WHEN OTHERS THEN
11911 x_return_status := fnd_api.g_ret_sts_unexp_error;
11912
11913 IF (l_debug = 1) THEN
11914 mydebug('validate_sub_loc_status: Unexpected Error - ' || SQLERRM);
11915 END IF;
11916
11917 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11918 END validate_sub_loc_status;
11919
11920 PROCEDURE insert_serial(
11921 p_serial_transaction_temp_id IN OUT NOCOPY NUMBER,
11922 p_organization_id IN NUMBER,
11923 p_item_id IN NUMBER,
11924 p_revision IN VARCHAR2,
11925 p_lot IN VARCHAR2,
11926 p_transaction_temp_id IN NUMBER,
11927 p_created_by IN NUMBER,
11928 p_from_serial IN VARCHAR2,
11929 p_to_serial IN VARCHAR2,
11930 p_status_id IN NUMBER := NULL,
11931 x_return_status OUT NOCOPY VARCHAR2,
11932 x_msg_data OUT NOCOPY VARCHAR2
11933 ) IS
11934
11935 PRAGMA AUTONOMOUS_TRANSACTION;
11936
11937 l_return NUMBER;
11938 l_to_serial VARCHAR2(30);
11939 l_progress VARCHAR2(10);
11940 l_msg_count NUMBER;
11941 l_success NUMBER := 0;
11942 l_count NUMBER := 0;
11943 l_temp_qty NUMBER :=0 ;
11944 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
11945 BEGIN
11946 x_return_status := fnd_api.g_ret_sts_success;
11947 l_progress := '10';
11948 IF (l_debug = 1) THEN
11949 mydebug('Enter insert_serial: 10:'|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
11950 END IF;
11951 --SAVEPOINT rcv_insert_serial_sp;
11952 l_to_serial := p_to_serial;
11953 l_return :=2;
11954
11955
11956 l_progress := '20';
11957 l_count := 0;
11958 BEGIN
11959 SELECT 1
11960 INTO l_count
11961 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt,
11962 mtl_material_transactions_temp mmtt
11963 WHERE (p_from_serial BETWEEN msnt.fm_serial_number AND msnt.to_serial_number
11964 OR p_to_serial BETWEEN msnt.fm_serial_number AND msnt.to_serial_number)
11965 AND mmtt.inventory_item_id = p_item_id
11966 AND mmtt.organization_id = p_organization_id
11967 AND mtlt.transaction_temp_id(+) = mmtt.transaction_temp_id
11968 AND msnt.transaction_temp_id = nvl(mtlt.serial_transaction_temp_id, mmtt.transaction_temp_id);
11969 EXCEPTION
11970 WHEN OTHERS THEN
11971 l_count := 0;
11972 END;
11973
11974 IF l_count <> 0 THEN
11975 fnd_message.set_name('INV', 'INVALID_SERIAL_NUMBER');
11976 fnd_msg_pub.ADD;
11977 RAISE fnd_api.g_exc_error;
11978 END IF;
11979
11980 l_progress := '30';
11981
11982 IF p_serial_transaction_temp_id IS NULL THEN
11983 l_progress := '40';
11984
11985 SELECT serial_transaction_temp_id
11986 INTO p_serial_transaction_temp_id
11987 FROM mtl_transaction_lots_temp
11988 WHERE transaction_temp_id = p_transaction_temp_id
11989 AND lot_number= p_lot;
11990
11991 IF p_serial_transaction_temp_id IS NULL THEN
11992
11993 SELECT mtl_material_transactions_s.NEXTVAL
11994 INTO p_serial_transaction_temp_id
11995 FROM DUAL;
11996
11997 l_progress := '50';
11998
11999 UPDATE mtl_transaction_lots_temp
12000 SET serial_transaction_temp_id = p_serial_transaction_temp_id
12001 WHERE transaction_temp_id = p_transaction_temp_id
12002 AND lot_number= p_lot;
12003
12004 END IF;
12005
12006 END IF;
12007
12008 l_progress := '60';
12009 l_return := inv_trx_util_pub.insert_ser_trx(
12010 p_trx_tmp_id => p_serial_transaction_temp_id,
12011 p_user_id => p_created_by,
12012 p_fm_ser_num => p_from_serial,
12013 p_to_ser_num => p_to_serial,
12014 p_status_id => p_status_id,
12015 x_proc_msg => x_msg_data
12016 );
12017 l_progress := '70';
12018
12019 BEGIN
12020 UPDATE mtl_serial_numbers
12021 SET group_mark_id = p_serial_transaction_temp_id
12022 WHERE inventory_item_id = p_item_id
12023 AND serial_number BETWEEN p_from_serial AND p_to_serial
12024 AND LENGTH(serial_number) = LENGTH(p_from_serial);
12025 EXCEPTION
12026 WHEN OTHERS THEN
12027 IF (l_debug = 1) THEN
12028 mydebug('Exception updating grp. id', 4);
12029 END IF;
12030 END;
12031
12032 IF (l_debug = 1) THEN
12033 mydebug('Insert serial vals'|| p_item_id || ':' || p_from_serial || ':' || p_to_serial, 4);
12034 mydebug('Insert serial, inserted with '|| p_serial_transaction_temp_id || ':' || l_success, 4);
12035 END IF;
12036
12037 -- if the trx manager returned a 1 then it could not insert the row
12038 IF l_return = 1 THEN
12039 RAISE fnd_api.g_exc_error;
12040 END IF;
12041
12042 l_progress := '80';
12043 IF (l_debug = 1) THEN
12044 mydebug('Exitting insert_serial : 90 '|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12045 END IF;
12046
12047 commit;
12048
12049 EXCEPTION
12050 WHEN fnd_api.g_exc_error THEN
12051 --ROLLBACK TO rcv_insert_serial_sp;
12052 ROLLBACK;
12053 x_return_status := fnd_api.g_ret_sts_error;
12054 IF (l_debug = 1) THEN
12055 mydebug('Exitting insert_serial - execution error:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12056 END IF;
12057 -- Get message count and data
12058 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_msg_data);
12059 WHEN OTHERS THEN
12060 x_return_status := fnd_api.g_ret_sts_unexp_error;
12061
12062 IF SQLCODE IS NOT NULL THEN
12063 inv_mobile_helper_functions.sql_error('wms_task_load.insert_serial', l_progress, SQLCODE);
12064 END IF;
12065
12066 IF (l_debug = 1) THEN
12067 mydebug('Exitting insert_serial - other exception:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12068 END IF;
12069
12070 --
12071 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
12072 fnd_msg_pub.add_exc_msg(g_pkg_name, 'insert_serial');
12073 END IF;
12074
12075 END insert_serial;
12076
12077 /*Added to validate cost group comingle bug 3858907 */
12078 procedure validate_loaded_lpn_cg( p_organization_id IN NUMBER,
12079 p_inventory_item_id IN NUMBER,
12080 p_subinventory_code IN VARCHAR2,
12081 p_locator_id IN NUMBER,
12082 p_revision IN VARCHAR2,
12083 p_lot_number IN VARCHAR2,
12084 p_lpn_id IN NUMBER,
12085 p_transfer_lpn_id IN NUMBER,
12086 p_lot_control IN NUMBER,
12087 p_revision_control IN NUMBER,
12088 x_commingle_exist OUT NOCOPY VARCHAR2,
12089 x_return_status OUT NOCOPY VARCHAR2,
12090 p_trx_type_id IN VARCHAR2, -- Bug 4632519
12091 p_trx_action_id IN VARCHAR2) -- Bug 4632519
12092 IS
12093 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12094 l_cur_cost_group_id NUMBER := NULL;
12095 l_exist_cost_group_id NUMBER := NULL;
12096 l_sub VARCHAR2(20);
12097 l_loc NUMBER;
12098 l_rev VARCHAR2(4);
12099 l_lpn NUMBER;
12100 l_ser VARCHAR2(20);
12101 l_lot VARCHAR2(20);
12102 -- Bug 4632519
12103 l_transaction_action_id NUMBER;
12104 l_transaction_type_id NUMBER;
12105 l_is_bf boolean;
12106 -- Bug 4632519
12107 BEGIN
12108 IF (l_debug = 1) THEN
12109 mydebug( 'In check_cg_commingle... ');
12110 mydebug('p_organization_id'||p_organization_id);
12111 mydebug('p_inventory_item_id'||p_inventory_item_id);
12112 mydebug('p_subinventory_code'||p_subinventory_code);
12113 mydebug('p_locator_id'||p_locator_id);
12114 mydebug('p_revision'||p_revision);
12115 mydebug('p_lot_number'||p_lot_number);
12116 mydebug('p_transfer_lpn_id'||p_transfer_lpn_id);
12117 mydebug('p_lpn_id'||p_lpn_id);
12118 mydebug('p_lot_control'||p_lot_control);
12119 mydebug('p_revision_control'||p_revision_control);
12120 mydebug('p_trx_souce_type_id' ||p_trx_type_id);
12121 mydebug('p_trx_action_id ' || p_trx_action_id);
12122 END IF;
12123
12124 x_return_status := fnd_api.g_ret_sts_success;
12125 x_commingle_exist := 'N';
12126
12127 IF p_lot_control = 1 THEN
12128 select mmtt.subinventory_code,
12129 mmtt.locator_id,
12130 mmtt.revision,
12131 mmtt.lpn_id,
12132 null,
12133 null,
12134 mmtt.transaction_action_id, -- Bug 4632519
12135 mmtt.transaction_type_id -- Bug 4632519
12136 INTO l_sub,
12137 l_loc,
12138 l_rev,
12139 l_lpn,
12140 l_ser,l_lot,
12141 l_transaction_action_id, -- Bug 4632519
12142 l_transaction_type_id -- Bug 4632519
12143 from mtl_material_Transactions_temp mmtt
12144 where mmtt.inventory_item_id = p_inventory_item_id
12145 and mmtt.organization_id = p_organization_id
12146 and mmtt.transfer_lpn_id = p_transfer_lpn_id
12147 and mmtt.content_lpn_id is null
12148 and decode(p_revision_control,2,mmtt.revision,1,'~~') = nvl(p_revision,'~~')
12149 and rownum<2;
12150 ELSE
12151 select mmtt.subinventory_code,
12152 mmtt.locator_id,
12153 mmtt.revision,
12154 mmtt.lpn_id,
12155 null,
12156 mtlt.lot_number,
12157 mmtt.transaction_action_id,
12158 mmtt.transaction_type_id
12159 INTO l_sub,
12160 l_loc,
12161 l_rev,
12162 l_lpn,
12163 l_ser,
12164 l_lot,
12165 l_transaction_action_id, -- Bug 4632519
12166 l_transaction_type_id -- Bug 4632519
12167 from mtl_material_Transactions_temp mmtt,
12168 mtl_transaction_lots_temp mtlt
12169 where mmtt.inventory_item_id = p_inventory_item_id
12170 and mmtt.organization_id = p_organization_id
12171 and mmtt.transfer_lpn_id = p_transfer_lpn_id
12172 and mmtt.content_lpn_id is null
12173 and decode(p_revision_control,2,mmtt.revision,1,'~~') = nvl(p_revision,'~~')
12174 and mmtt.transaction_temp_id = mtlt.transaction_temp_id
12175 and mtlt.lot_number = p_lot_number
12176 and rownum<2;
12177 END IF;
12178
12179 IF (l_debug = 1) THEN
12180 mydebug( 'Loaded LPN data From MMTT');
12181 mydebug('l_subinventory_code'||l_sub);
12182 mydebug('l_locator_id'||l_loc);
12183 mydebug('l_revision'||l_rev);
12184 mydebug('l_lot_number'||l_lot);
12185 mydebug('l_serial_number'||l_ser);
12186 mydebug('l_lpn_id'||l_lpn);
12187 END IF;
12188 --
12189 -- Bug 4632519
12190 if (p_trx_type_id='51') then
12191 l_is_bf := true;
12192 end if;
12193 --
12194 inv_cost_group_update.proc_determine_costgroup(
12195 p_organization_id => p_organization_id,
12196 p_inventory_item_id => p_inventory_item_id,
12197 p_subinventory_code => p_subinventory_code,
12198 p_locator_id => p_locator_id,
12199 p_revision => p_revision,
12200 p_lot_number => p_lot_number,
12201 p_serial_number => null,
12202 p_containerized_flag => null,
12203 p_lpn_id => p_lpn_id,
12204 p_transaction_action_id => p_trx_action_id,
12205 p_is_backflush_txn => l_is_bf,
12206 x_cost_group_id => l_cur_cost_group_id,
12207 x_return_status => x_return_status);
12208
12209 IF x_return_status <> fnd_api.g_ret_sts_success THEN
12210 RAISE fnd_api.g_exc_unexpected_error;
12211 END IF;
12212
12213 if (l_transaction_type_id=51) then
12214 l_is_bf := true;
12215 end if;
12216 inv_cost_group_update.proc_determine_costgroup(
12217 p_organization_id => p_organization_id,
12218 p_inventory_item_id => p_inventory_item_id,
12219 p_subinventory_code => l_sub,
12220 p_locator_id => l_loc,
12221 p_revision => l_rev,
12222 p_lot_number => l_lot,
12223 p_serial_number => l_ser,
12224 p_containerized_flag => null,
12225 p_lpn_id => l_lpn,
12226 p_transaction_action_id => l_transaction_action_id,
12227 p_is_backflush_txn => l_is_bf,
12228 x_cost_group_id => l_exist_cost_group_id,
12229 x_return_status => x_return_status);
12230
12231 IF x_return_status <> fnd_api.g_ret_sts_success THEN
12232 RAISE fnd_api.g_exc_unexpected_error;
12233 END IF;
12234
12235 IF l_exist_cost_group_id <> l_cur_cost_group_id THEN
12236 x_return_status := fnd_api.g_ret_sts_success;
12237 x_commingle_exist := 'Y';
12238 END IF;
12239 --
12240 -- Bug 4632519
12241 --
12242 EXCEPTION
12243 WHEN NO_DATA_FOUND THEN
12244 IF (l_debug = 1) THEN
12245 mydebug('First record being loaded into LPN');
12246 END IF;
12247 x_return_status := fnd_api.g_ret_sts_success;
12248 x_commingle_exist := 'N';
12249 WHEN OTHERS THEN
12250 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
12251 x_commingle_exist := 'Y';
12252 END validate_loaded_lpn_cg;
12253
12254
12255 END wms_task_load;