1 PACKAGE BODY wms_task_dispatch_put_away AS
2 /* $Header: WMSTKPTB.pls 120.44.12020000.7 2013/04/23 08:02:40 zhnie ship $ */
3
4
5 -- Global constant holding the package name
6 g_pkg_name CONSTANT VARCHAR2(30) := 'WMS_Task_Dispatch_put_away';
7
8 /* FP-J Lot/Serial Support Enhancement
9 * Record type to store information for one serial number. This is used for
10 * inserting MTL_SERIAL_NUMBERS for the serial numbers in the LPN
11 */
12 TYPE msn_attribute_rec_tp IS RECORD(
13 serial_number mtl_serial_numbers.serial_number%TYPE
14 , to_serial_number mtl_serial_numbers.serial_number%TYPE
15 , vendor_serial_number mtl_serial_numbers.vendor_serial_number%TYPE
16 , vendor_lot_number mtl_serial_numbers.vendor_lot_number%TYPE
17 , parent_serial_number mtl_serial_numbers.parent_serial_number%TYPE
18 , origination_date mtl_serial_numbers.origination_date%TYPE
19 , end_item_unit_number mtl_serial_numbers.end_item_unit_number%TYPE
20 , territory_code mtl_serial_numbers.territory_code%TYPE
21 , time_since_new mtl_serial_numbers.time_since_new%TYPE
22 , cycles_since_new mtl_serial_numbers.cycles_since_new%TYPE
23 , time_since_overhaul mtl_serial_numbers.time_since_overhaul%TYPE
24 , cycles_since_overhaul mtl_serial_numbers.cycles_since_overhaul%TYPE
25 , time_since_repair mtl_serial_numbers.time_since_repair%TYPE
26 , cycles_since_repair mtl_serial_numbers.cycles_since_repair%TYPE
27 , time_since_visit mtl_serial_numbers.time_since_visit%TYPE
28 , cycles_since_visit mtl_serial_numbers.cycles_since_visit%TYPE
29 , time_since_mark mtl_serial_numbers.time_since_mark%TYPE
30 , cycles_since_mark mtl_serial_numbers.cycles_since_mark%TYPE
31 , number_of_repairs mtl_serial_numbers.number_of_repairs%TYPE
32 , serial_attribute_category mtl_serial_numbers.serial_attribute_category%TYPE
33 , c_attribute1 mtl_serial_numbers.c_attribute1%TYPE
34 , c_attribute2 mtl_serial_numbers.c_attribute2%TYPE
35 , c_attribute3 mtl_serial_numbers.c_attribute3%TYPE
36 , c_attribute4 mtl_serial_numbers.c_attribute4%TYPE
37 , c_attribute5 mtl_serial_numbers.c_attribute5%TYPE
38 , c_attribute6 mtl_serial_numbers.c_attribute6%TYPE
39 , c_attribute7 mtl_serial_numbers.c_attribute7%TYPE
40 , c_attribute8 mtl_serial_numbers.c_attribute8%TYPE
41 , c_attribute9 mtl_serial_numbers.c_attribute9%TYPE
42 , c_attribute10 mtl_serial_numbers.c_attribute10%TYPE
43 , c_attribute11 mtl_serial_numbers.c_attribute11%TYPE
44 , c_attribute12 mtl_serial_numbers.c_attribute12%TYPE
45 , c_attribute13 mtl_serial_numbers.c_attribute13%TYPE
46 , c_attribute14 mtl_serial_numbers.c_attribute14%TYPE
47 , c_attribute15 mtl_serial_numbers.c_attribute15%TYPE
48 , c_attribute16 mtl_serial_numbers.c_attribute16%TYPE
49 , c_attribute17 mtl_serial_numbers.c_attribute17%TYPE
50 , c_attribute18 mtl_serial_numbers.c_attribute18%TYPE
51 , c_attribute19 mtl_serial_numbers.c_attribute19%TYPE
52 , c_attribute20 mtl_serial_numbers.c_attribute20%TYPE
53 , d_attribute1 mtl_serial_numbers.d_attribute1%TYPE
54 , d_attribute2 mtl_serial_numbers.d_attribute2%TYPE
55 , d_attribute3 mtl_serial_numbers.d_attribute3%TYPE
56 , d_attribute4 mtl_serial_numbers.d_attribute4%TYPE
57 , d_attribute5 mtl_serial_numbers.d_attribute5%TYPE
58 , d_attribute6 mtl_serial_numbers.d_attribute6%TYPE
59 , d_attribute7 mtl_serial_numbers.d_attribute7%TYPE
60 , d_attribute8 mtl_serial_numbers.d_attribute8%TYPE
61 , d_attribute9 mtl_serial_numbers.d_attribute9%TYPE
62 , d_attribute10 mtl_serial_numbers.d_attribute10%TYPE
63 , n_attribute1 mtl_serial_numbers.n_attribute1%TYPE
64 , n_attribute2 mtl_serial_numbers.n_attribute2%TYPE
65 , n_attribute3 mtl_serial_numbers.n_attribute3%TYPE
66 , n_attribute4 mtl_serial_numbers.n_attribute4%TYPE
67 , n_attribute5 mtl_serial_numbers.n_attribute5%TYPE
68 , n_attribute6 mtl_serial_numbers.n_attribute6%TYPE
69 , n_attribute7 mtl_serial_numbers.n_attribute7%TYPE
70 , n_attribute8 mtl_serial_numbers.n_attribute8%TYPE
71 , n_attribute9 mtl_serial_numbers.n_attribute9%TYPE
72 , n_attribute10 mtl_serial_numbers.n_attribute10%TYPE
73 );
74
75
76 -- Constants and types declaration
77
78 TYPE num_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
79
80 -- Task Record
81 SUBTYPE task_rec IS wms_dispatched_tasks%ROWTYPE;
82
83 -- ATF Related constants
84 G_ATF_ACTIVATE_PLAN CONSTANT NUMBER := 1;
85 G_ATF_ABORT_PLAN CONSTANT NUMBER := 2;
86 G_ATF_CANCEL_PLAN CONSTANT NUMBER := 3;
87
88 G_OP_TYPE_DROP CONSTANT NUMBER := wms_globals.G_OP_TYPE_DROP;
89 G_OP_ACTIVITY_INBOUND CONSTANT NUMBER := wms_globals.G_OP_ACTIVITY_INBOUND;
90
91 /**Constants defined for Inspection Flag in validate_operation
92 */
93 G_NO_INSPECTION CONSTANT NUMBER:=1;
94 G_PARTIAL_INSPECTION CONSTANT NUMBER:=2;
95 G_FULL_INSPECTION CONSTANT NUMBER:=3;
96
97 /**Constants defined for Load Flag in validate_operation
98 */
99 G_NO_LOAD CONSTANT NUMBER:=1;
100 G_PARTIAL_LOAD CONSTANT NUMBER:=2;
101 G_FULL_LOAD CONSTANT NUMBER:=3;
102
103
104 /**Constants defined for Drop Flag in validate_operation
105 */
106 G_NO_DROP CONSTANT NUMBER:=1;
107 G_PARTIAL_DROP CONSTANT NUMBER:=2;
108 G_FULL_DROP CONSTANT NUMBER:=3;
109
110
111 PROCEDURE mydebug(msg IN VARCHAR2) IS
112 l_msg VARCHAR2(5100);
113 l_ts VARCHAR2(30);
114 BEGIN
115 -- select to_char(sysdate,'MM/DD/YYYY HH:MM:SS') INTO l_ts from dual;
116 -- l_msg:=l_ts||' '||msg;
117
118 l_msg := msg;
119 inv_mobile_helper_functions.tracelog(p_err_msg => l_msg
120 , p_module => 'WMS_Task_Dispatch_put_away'
121 , p_level => 4);
122 --dbms_output.put_line(l_msg);
123 NULL;
124 END;
125
126 PROCEDURE create_mo_line(
127 p_org_id IN NUMBER
128 , p_inventory_item_id IN NUMBER
129 , p_qty IN NUMBER
130 , p_uom IN VARCHAR2
131 , p_lpn IN NUMBER
132 , p_project_id IN NUMBER
133 , p_task_id IN NUMBER
134 , p_reference IN VARCHAR2
135 , p_reference_type_code IN NUMBER
136 , p_reference_id IN NUMBER
137 , p_header_id IN NUMBER
138 , p_lot_number IN VARCHAR2
139 , p_revision IN VARCHAR2
140 , p_inspection_status IN NUMBER := NULL
141 , p_txn_source_id IN NUMBER := fnd_api.g_miss_num
142 , p_transaction_type_id IN NUMBER := fnd_api.g_miss_num
143 , p_transaction_source_type_id IN NUMBER := fnd_api.g_miss_num
144 , p_wms_process_flag IN NUMBER := NULL
145 , x_return_status OUT NOCOPY VARCHAR2
146 , x_msg_count OUT NOCOPY NUMBER
147 , x_msg_data OUT NOCOPY VARCHAR2
148 , p_from_cost_group_id IN NUMBER := NULL
149 , p_sec_qty IN NUMBER := NULL -- Added for OPM convergance
150 , p_sec_uom IN VARCHAR2 := NULL -- Added for OPM convergance
151 , x_line_id OUT nocopy NUMBER -- Added for R12 MOL Consolidation
152 ) IS
153 l_trolin_tbl inv_move_order_pub.trolin_tbl_type;
154 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
155 l_msg_count NUMBER;
156 l_msg_data VARCHAR2(2400);
157 l_trohdr_val_rec inv_move_order_pub.trolin_val_tbl_type;
158 l_commit VARCHAR2(1) := fnd_api.g_false;
159 l_trolin_val_tbl inv_move_order_pub.trolin_val_tbl_type;
160 l_line_num NUMBER := 0;
161 l_header_id NUMBER := fnd_api.g_miss_num;
162 l_order_count NUMBER := 1;
163 l_trohdr_val_rec inv_move_order_pub.trohdr_val_rec_type;
164 l_commit VARCHAR2(1) := fnd_api.g_false;
165 p_need_by_date DATE := SYSDATE;
166 p_src_subinv VARCHAR2(30);
167 l_org_id NUMBER;
168 l_inventory_item_id NUMBER;
169 l_lpn NUMBER;
170 l_qty NUMBER;
171 l_uom VARCHAR2(60);
172 l_project_id NUMBER;
173 l_task_id NUMBER;
174 l_ref VARCHAR2(240);
175 l_ref_type NUMBER;
176 l_ref_id NUMBER;
177 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
178 l_lot_number VARCHAR2(80);
179 l_revision VARCHAR2(3);
180 l_txn_type_id NUMBER := fnd_api.g_miss_num;
181 l_txn_source_id NUMBER := fnd_api.g_miss_num;
182 l_txn_source_type_id NUMBER := fnd_api.g_miss_num;
183 l_insp_status NUMBER;
184 l_wms_process_flag NUMBER;
185 l_cg_id NUMBER;
186 l_tcg_id NUMBER;
187 l_cg_line NUMBER;
188 l_from_cg_id NUMBER;
189 l1 VARCHAR2(30);
190 l2 NUMBER;
191 l3 NUMBER;
192 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
193 l_sec_qty NUMBER; -- Added for OPM convergance
194 l_sec_uom VARCHAR2(3); -- Added for OPM convergance
195 BEGIN
196 --Get Max line number
197 SELECT MAX(line_number)
198 INTO l_line_num
199 FROM mtl_txn_request_lines
200 WHERE header_id = p_header_id;
201
202 l_header_id := p_header_id;
203 l_org_id := p_org_id;
204 l_inventory_item_id := p_inventory_item_id;
205 l_lpn := p_lpn;
206 l_qty := p_qty;
207 l_uom := p_uom;
208 l_project_id := p_project_id;
209 /*
210 ** Bug 2677818
211 ** l_task_id:=l_task_id;
212 ** Correcting this as below
213 */
214 l_task_id := p_task_id;
215 l_ref := p_reference;
216 l_ref_type := p_reference_type_code;
217 l_ref_id := p_reference_id;
218 l_lot_number := p_lot_number;
219 l_revision := p_revision;
220 l_insp_status := p_inspection_status;
221 l_wms_process_flag := p_wms_process_flag;
222 l_from_cg_id := p_from_cost_group_id;
223
224 l_sec_qty := p_sec_qty; -- Added for OPM convergance
225 l_sec_uom := p_sec_uom; -- Added for OPM convergance
226
227 -- Derive txn_source and type info
228
229 /*Bug 5662957:set the txn_type_id = 12 and txn_source_type_id =13 if reference_type_code = 6.
230 The same was already done in create_mo() API as a part of bug fix 4996680.*/
231
232 IF (l_ref_type = 4) THEN
233 l_txn_type_id := 18;
234 l_txn_source_type_id := 1;
235 ELSIF(l_ref_type = 8) THEN
236 l_txn_type_id := 61;
237 l_txn_source_type_id := 7;
238 ELSIF(l_ref_type = 7) THEN
239 l_txn_type_id := 15;
240 l_txn_source_type_id := 12;
241 ELSIF(l_ref_type = 6) THEN
242 l_txn_type_id := 12;
243 l_txn_source_type_id := 13;
244 ELSE
245 l_txn_type_id := 18;
246 l_txn_source_type_id := 1;
247 END IF;
248
249 -- Note might need to add additional stuff here
250 -- Added for WIP
251 IF (p_txn_source_id <> fnd_api.g_miss_num) THEN
252 l_txn_source_id := p_txn_source_id;
253 ELSE
254 l_txn_source_id := NULL;
255 END IF;
256
257 IF (p_transaction_source_type_id <> fnd_api.g_miss_num) THEN
258 l_txn_source_type_id := p_transaction_source_type_id;
259 END IF;
260
261 IF (p_transaction_type_id <> fnd_api.g_miss_num) THEN
262 l_txn_type_id := p_transaction_type_id;
263 END IF;
264
265 --Increment by 1
266 l_line_num := l_line_num + 1;
267 l_trolin_tbl(l_order_count).header_id := p_header_id;
268 l_trolin_tbl(l_order_count).created_by := fnd_global.user_id;
269 l_trolin_tbl(l_order_count).creation_date := SYSDATE;
270 l_trolin_tbl(l_order_count).date_required := SYSDATE;
271 l_trolin_tbl(l_order_count).from_subinventory_code := NULL;
272 l_trolin_tbl(l_order_count).inventory_item_id := p_inventory_item_id;
273 l_trolin_tbl(l_order_count).last_updated_by := fnd_global.user_id;
274 l_trolin_tbl(l_order_count).last_update_date := SYSDATE;
275 l_trolin_tbl(l_order_count).last_update_login := fnd_global.login_id;
276 l_trolin_tbl(l_order_count).line_id := fnd_api.g_miss_num;
277 l_trolin_tbl(l_order_count).line_number := l_line_num;
278 l_trolin_tbl(l_order_count).line_status := inv_globals.g_to_status_preapproved;
279 l_trolin_tbl(l_order_count).organization_id := p_org_id;
280 l_trolin_tbl(l_order_count).quantity := p_qty;
281 l_trolin_tbl(l_order_count).status_date := SYSDATE;
282 l_trolin_tbl(l_order_count).to_subinventory_code := NULL;
283 l_trolin_tbl(l_order_count).uom_code := p_uom;
284 l_trolin_tbl(l_order_count).db_flag := fnd_api.g_true;
285 l_trolin_tbl(l_order_count).operation := inv_globals.g_opr_create;
286 l_trolin_tbl(l_order_count).lpn_id := p_lpn;
287 l_trolin_tbl(l_order_count).REFERENCE := l_ref;
288 l_trolin_tbl(l_order_count).reference_type_code := l_ref_type;
289 l_trolin_tbl(l_order_count).reference_id := l_ref_id;
290 l_trolin_tbl(l_order_count).project_id := l_project_id;
291 l_trolin_tbl(l_order_count).task_id := l_task_id;
292 l_trolin_tbl(l_order_count).lot_number := l_lot_number;
293 l_trolin_tbl(l_order_count).revision := l_revision;
294 l_trolin_tbl(l_order_count).transaction_type_id := l_txn_type_id;
295 l_trolin_tbl(l_order_count).transaction_source_type_id := l_txn_source_type_id;
296 l_trolin_tbl(l_order_count).inspection_status := l_insp_status;
297 l_trolin_tbl(l_order_count).wms_process_flag := l_wms_process_flag;
298 l_trolin_tbl(l_order_count).secondary_quantity := l_sec_qty; -- Added for OPM convergance
299 l_trolin_tbl(l_order_count).secondary_uom := l_sec_uom; -- Added for OPM convergance
300
301 IF (p_txn_source_id <> fnd_api.g_miss_num) THEN
302 l_trolin_tbl(l_order_count).txn_source_id := l_txn_source_id;
303 END IF;
304
305 l_trolin_tbl(l_order_count).from_cost_group_id := l_from_cg_id;
306 l_trolin_tbl(l_order_count).to_cost_group_id := l_from_cg_id;
307
308 inv_move_order_pub.create_move_order_lines(
309 p_api_version_number => 1.0
310 , p_init_msg_list => 'F'
311 , p_commit => fnd_api.g_false
312 , x_return_status => l_return_status
313 , x_msg_count => l_msg_count
314 , x_msg_data => l_msg_data
315 , p_trolin_tbl => l_trolin_tbl
316 , p_trolin_val_tbl => l_trolin_val_tbl
317 , x_trolin_tbl => l_trolin_tbl
318 , x_trolin_val_tbl => l_trolin_val_tbl
319 );
320
321 IF (l_debug = 1) THEN
322 mydebug('create_mo_line: Org');
323 mydebug('create_mo_line: ' || l_trolin_tbl(1).organization_id);
324 mydebug('create_mo_line: Line');
325 mydebug('create_mo_line: ' || l_trolin_tbl(1).line_id);
326 mydebug('create_mo_line: Status ');
327 mydebug('create_mo_line: ' || l_return_status);
328 END IF;
329
330 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
331 fnd_message.set_name('WMS', 'WMS_TD_MOL_ERROR');
332 fnd_msg_pub.ADD;
333 RAISE fnd_api.g_exc_unexpected_error;
334 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
335 fnd_message.set_name('WMS', 'WMS_TD_MOL_ERROR');
336 fnd_msg_pub.ADD;
337 RAISE fnd_api.g_exc_error;
338 END IF;
339
340 l_cg_line := l_trolin_tbl(1).line_id;
341 x_line_id := l_trolin_tbl(1).line_id;
342
343 IF (l_debug = 1) THEN
344 mydebug('create_mo_line: Line: ' || l_cg_line);
345 END IF;
346
347 SELECT from_subinventory_code
348 , from_cost_group_id
349 , to_cost_group_id
350 INTO l1
351 , l2
352 , l3
353 FROM mtl_txn_request_lines
354 WHERE line_id = l_cg_line;
355
356 IF (l_debug = 1) THEN
357 mydebug('create_mo_line: Act Sub: ' || l1);
358 mydebug('create_mo_line: Act FCG: ' || l2);
359 mydebug('create_mo_line: Act TCG: ' || l3);
360 END IF;
361
362 IF l_from_cg_id IS NULL THEN
363 IF (l_debug = 1) THEN
364 mydebug('create_mo_line: Calling CG Engine');
365 END IF;
366
367 -- Call Cost Group Engine
368 inv_cost_group_pub.assign_cost_group(
369 p_api_version_number => 1.0
370 , p_init_msg_list => fnd_api.g_false
371 , p_commit => fnd_api.g_false
372 , x_return_status => l_return_status
373 , x_msg_count => l_msg_count
374 , x_msg_data => l_msg_data
375 , p_line_id => l_cg_line
376 , p_organization_id => l_org_id
377 , p_input_type => inv_cost_group_pub.g_input_moline
378 , x_cost_group_id => l_cg_id
379 , x_transfer_cost_group_id => l_tcg_id
380 );
381
382 IF (l_debug = 1) THEN
383 mydebug('create_mo_line: After Calling CG Engine');
384 mydebug('create_mo_line: CG: ' || l_cg_id);
385 mydebug('create_mo_line: TCG: ' || l_tcg_id);
386 END IF;
387
388 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
389
390 IF (l_msg_count = 0) THEN
391 IF (l_debug = 1) THEN
392 mydebug('create_mo_line: Successful');
393 END IF;
394 ELSIF(l_msg_count = 1) THEN
395 IF (l_debug = 1) THEN
396 mydebug('create_mo_line: Not Successful');
397 mydebug(REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
398 END IF;
399 ELSE
400 IF (l_debug = 1) THEN
401 mydebug('create_mo_line: Not Successful2');
402 END IF;
403
404 FOR i IN 1 .. l_msg_count LOOP
405 l_msg_data := fnd_msg_pub.get(i, 'F');
406
407 IF (l_debug = 1) THEN
408 mydebug('create_mo_line: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
409 END IF;
410 END LOOP;
411 END IF;
412
413 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
414 fnd_message.set_name('WMS', 'WMS_TD_CG_ERROR');
415 fnd_msg_pub.ADD;
416 RAISE fnd_api.g_exc_unexpected_error;
417 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
418 fnd_message.set_name('WMS', 'WMS_TD_CG_ERROR');
419 fnd_msg_pub.ADD;
420 RAISE fnd_api.g_exc_error;
421 END IF;
422 END IF;
423
424 x_return_status := fnd_api.g_ret_sts_success;
425 EXCEPTION
426 WHEN fnd_api.g_exc_error THEN
427 x_return_status := fnd_api.g_ret_sts_error;
428 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
429 WHEN OTHERS THEN
430 x_return_status := fnd_api.g_ret_sts_unexp_error;
431 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
432 END create_mo_line;
433
434 PROCEDURE create_mo(
435 p_org_id IN NUMBER
436 , p_inventory_item_id IN NUMBER
437 , p_qty IN NUMBER
438 , p_uom IN VARCHAR2
439 , p_lpn IN NUMBER
440 , p_project_id IN NUMBER := NULL
441 , p_task_id IN NUMBER := NULL
442 , p_reference IN VARCHAR2 := NULL
443 , p_reference_type_code IN NUMBER := NULL
444 , p_reference_id IN NUMBER := NULL
445 , p_lot_number IN VARCHAR2
446 , p_revision IN VARCHAR2
447 , p_header_id IN OUT NOCOPY NUMBER
448 , p_sub IN VARCHAR := NULL
449 , p_loc IN NUMBER := NULL
450 , x_line_id OUT NOCOPY NUMBER
451 , p_inspection_status IN NUMBER := NULL
452 , p_txn_source_id IN NUMBER := fnd_api.g_miss_num
453 , p_transaction_type_id IN NUMBER := fnd_api.g_miss_num
454 , p_transaction_source_type_id IN NUMBER := fnd_api.g_miss_num
455 , p_wms_process_flag IN NUMBER := NULL
456 , x_return_status OUT NOCOPY VARCHAR2
457 , x_msg_count OUT NOCOPY NUMBER
458 , x_msg_data OUT NOCOPY VARCHAR2
459 , p_from_cost_group_id IN NUMBER := NULL
460 , p_transfer_org_id IN NUMBER DEFAULT NULL
461 , p_sec_qty IN NUMBER := NULL -- Added for OPM Convergance
462 , p_sec_uom IN VARCHAR2 := NULL -- Added for OPM Convergance
463 ) IS
464 l_trohdr_rec inv_move_order_pub.trohdr_rec_type;
465 l_trolin_tbl inv_move_order_pub.trolin_tbl_type;
466 l_trolin_val_tbl inv_move_order_pub.trolin_val_tbl_type;
467 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
468 l_msg_count NUMBER;
469 l_msg_data VARCHAR2(2000);
470 msg VARCHAR2(2000);
471 l_header_id NUMBER := fnd_api.g_miss_num;
472 l_line_num NUMBER := 0;
473 l_order_count NUMBER := 1;
474 l_trohdr_val_rec inv_move_order_pub.trohdr_val_rec_type;
475 l_commit VARCHAR2(1) := fnd_api.g_false;
476 p_need_by_date DATE := SYSDATE;
477 p_src_subinv VARCHAR2(30);
478 l_org_id NUMBER;
479 l_inventory_item_id NUMBER;
480 l_lpn NUMBER;
481 l_qty NUMBER;
482 l_uom VARCHAR2(60);
483 l_project_id NUMBER;
484 l_task_id NUMBER;
485 l_ref VARCHAR2(240);
486 l_ref_type NUMBER;
487 l_ref_id NUMBER;
488 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
489 l_lot_number VARCHAR2(80);
490 l_revision VARCHAR2(3);
491 l_txn_type_id NUMBER := fnd_api.g_miss_num;
492 l_txn_source_id NUMBER := fnd_api.g_miss_num;
493 l_txn_source_type_id NUMBER := fnd_api.g_miss_num;
494 l_insp_status NUMBER;
495 l_wms_process_flag NUMBER;
496 l_cg_id NUMBER;
497 l_tcg_id NUMBER;
498 l_cg_line NUMBER;
499 l_from_cg_id NUMBER;
500 l1 VARCHAR2(30);
501 l2 NUMBER;
502 l3 NUMBER;
503 l_project_comingle NUMBER;
504 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
505 l_sec_qty NUMBER;
506 l_sec_uom VARCHAR2(3);
507 l_lpn_id_chk number;
508
509
510 l_lot_code NUMBER; --bug#10415632
511 l_serial_control_code NUMBER;--13390994
512 l_serial_count NUMBER; --13390994
513 l_lpn_context NUMBER; --13695803
514 l_inspection_status_code VARCHAR2(50); --13722443
515 BEGIN
516 l_header_id := p_header_id;
517
518 IF p_header_id = 0 THEN
519 l_header_id := fnd_api.g_miss_num;
520 END IF;
521
522 l_org_id := p_org_id;
523 l_inventory_item_id := p_inventory_item_id;
524 l_lpn := p_lpn;
525 l_qty := p_qty;
526 l_uom := p_uom;
527 l_project_id := p_project_id;
528 /*
529 ** l_task_id:=l_task_id;
530 ** Correcting this as below
531 */
532 l_task_id := p_task_id;
533 l_ref := p_reference;
534 l_ref_type := p_reference_type_code;
535 l_ref_id := p_reference_id;
536 l_lot_number := p_lot_number;
537 l_revision := p_revision;
538 l_insp_status := p_inspection_status;
539 l_wms_process_flag := p_wms_process_flag;
540 l_from_cg_id := p_from_cost_group_id;
541 l_return_status := fnd_api.g_ret_sts_success;
542
543 l_sec_qty := p_sec_qty; -- Added for OPM convergance
544 l_sec_uom := p_sec_uom; -- Added for OPM convergance
545
546 /* If we are trying to create an MTRL with out LPN, check if there is RS
547 which does not have lpn_id stamped. If it does not exists throw an exception
548 and stop creation of MTRL
549 */
550
551 -- 13588879
552 if p_reference in ('PO_LINE_LOCATION_ID','SHIPMENT_LINE_ID','ORDER_LINE_ID') then
553
554 mydebug('p_lpn = '||p_lpn);
555 mydebug('p_txn_source_id = '||p_txn_source_id);
556 if p_lpn is null then
557 if (p_txn_source_id <> fnd_api.g_miss_num) then
558 begin
559 select lpn_id into l_lpn_id_chk
560 from rcv_supply rs
561 where rs.rcv_transaction_id = p_txn_source_id
562 and rs.lpn_id is null;
563 exception
564 when others then
565 mydebug('In exception -- select fails' ) ;
566 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
567 fnd_msg_pub.ADD;
568 RAISE fnd_api.g_exc_error;
569 end;
570 end if;
571 end if;
572
573 end if;
574 -- 13588879
575 /*
576 ** Sense project/task comingling in LPN
577 */
578 IF ((p_lpn > 0) AND(p_org_id > 0)) THEN
579 BEGIN
580 SELECT 1
581 INTO l_project_comingle
582 FROM DUAL
583 WHERE EXISTS(
584 SELECT 1
585 FROM mtl_txn_request_lines
586 WHERE lpn_id = p_lpn
587 AND organization_id = p_org_id
588 AND line_status <> inv_globals.g_to_status_closed
589 AND NVL(project_id, -1) <> NVL(p_project_id, -1)
590 AND NVL(task_id, -1) <> NVL(p_task_id, -1));
591
592 fnd_message.set_name('WMS', 'WMS_PROJ_LPN_COMINGLE');
593 fnd_msg_pub.ADD;
594 RAISE fnd_api.g_exc_error;
595 EXCEPTION
596 WHEN NO_DATA_FOUND THEN
597 NULL;
598 END;
599
600 /*
601 ** To identify lot corruption in WMS enabled orgs --bug#10415632
602 */
603 --13390994
604 --Removed the query to fetch Lot Control and got it from Cache
605 IF inv_cache.set_item_rec(p_org_id , l_inventory_item_id) THEN
606 l_lot_code := inv_cache.item_rec.lot_control_code;
607 l_serial_control_code := inv_cache.item_rec.serial_number_control_code;
608 END IF;
609 IF (l_debug = 1) THEN
610 mydebug('create_mo: Item Id : ' || l_inventory_item_id || ', Lot Control code : ' || l_lot_code||', Lot Number : '|| l_lot_number);
611 mydebug('create_mo: Item Id : ' || l_inventory_item_id || ', Serial Control Code : ' || l_serial_control_code);
612 END IF;
613
614 IF (l_lot_code = 2 AND l_lot_number IS NULL) THEN
615 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LOT');
616 fnd_msg_pub.ADD;
617 RAISE fnd_api.g_exc_error;
618 END IF;
619
620 IF l_serial_control_code NOT IN (1,6) THEN
621 --13695803
622 SELECT lpn_context
623 INTO l_lpn_context
624 FROM wms_license_plate_numbers
625 WHERE lpn_id = l_lpn
626 AND organization_id = l_org_id;
627
628 IF l_lpn_context = 3 THEN
629 -- Modified the query below to take care of -ve Correction Transaction
630 -- and issue with Multiple Lots, Revision for the same item in the same LPN
631 -- 13722443
632 IF Nvl(p_inspection_status,1) = 1 THEN
633 l_inspection_status_code := 'NOT INSPECTED';
634 ELSIF
635 p_inspection_status = 2 THEN
636 l_inspection_status_code := 'ACCEPTED';
637 ELSIF
638 p_inspection_status = 3 THEN
639 l_inspection_status_code := 'REJECTED';
640 END IF;
641 --13722443
642 SELECT COUNT(distinct(rss.serial_num))
643 INTO l_serial_count
644 FROM rcv_serials_supply rss, rcv_supply rs , rcv_transactions rt , rcv_lots_supply rls, mtl_system_items msi -- for bug 14192301 added msi table
645 WHERE rs.rcv_transaction_id = rss.transaction_id
646 AND rs.rcv_transaction_id = rt.transaction_id
647 AND rt.inspection_status_code = l_inspection_status_code
648 AND rs.shipment_line_id = rss.shipment_line_id
649 AND p_reference_id = DECODE(l_ref_type,4, Decode(l_ref, 'PO_LINE_LOCATION_ID' , rt.po_line_location_id,
650 'SHIPMENT_LINE_ID' , rt.shipment_line_id),
651 6, rt.shipment_line_id,
652 7, rt.oe_order_line_id,
653 8, rt.shipment_line_id) --14133874
654 AND msi.inventory_item_id = rs.item_id
655 AND msi.organization_id = rt.organization_id
656 AND (msi.revision_qty_control_code = 1
657 OR (msi.revision_qty_control_code = 2 AND Nvl(rs.item_revision,'@@@') = Nvl(p_revision,'@@@'))) -- for bug 14192301
658 AND rs.rcv_transaction_id = rls.transaction_id(+)
659 AND Nvl(rls.lot_num,'@@@') = Nvl(p_lot_number,'@@@')
660 AND rss.supply_type_code = 'RECEIVING'
661 AND Nvl(rss.lot_num , '@#@')= Nvl(rls.lot_num,'@#@')
662 AND rs.lpn_id = l_lpn
663 AND rs.item_id = l_inventory_item_id
664 AND rs.to_organization_id = l_org_id
665 AND EXISTS(SELECT 1
666 FROM mtl_serial_numbers msn
667 WHERE msn.inventory_item_id = l_inventory_item_id
668 -- AND msn.lpn_id = rs.lpn_id --14133874
669 AND msn.serial_number = rss.serial_num );
670
671 IF (l_debug = 1) THEN
672 mydebug('create_mo: Serial Count in RSS : ' || l_serial_count || ', p_qty : ' || p_qty);
673 END IF;
674
675 IF (l_serial_count <> p_qty) THEN
676 mydebug('Discrepancy in Serial qty and qty recd');
677 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
678 fnd_msg_pub.ADD;
679 RAISE fnd_api.g_exc_error;
680 END IF;
681
682 END IF; --13695803
683 END IF;
684 --13390994
685
686 END IF;
687
688 -- Derive txn_source and type info
689 IF (l_ref_type = 4) THEN
690 l_txn_type_id := 18;
691 l_txn_source_type_id := 1;
692 ELSIF(l_ref_type = 8) THEN
693 l_txn_type_id := 61;
694 l_txn_source_type_id := 7;
695 ELSIF(l_ref_type = 7) THEN
696 l_txn_type_id := 15;
697 l_txn_source_type_id := 12;
698 ELSIF(l_ref_type = 6) THEN
699 l_txn_type_id := 12;
700 l_txn_source_type_id := 13;
701 ELSE
702 l_txn_type_id := 18;
703 l_txn_source_type_id := 1;
704 END IF;
705
706 -- Note might need to add additional stuff here
707 -- Added for WIP
708 IF (p_txn_source_id <> fnd_api.g_miss_num) THEN
709 l_txn_source_id := p_txn_source_id;
710 ELSE
711 l_txn_source_id := NULL;
712 END IF;
713
714 IF (p_transaction_source_type_id <> fnd_api.g_miss_num) THEN
715 l_txn_source_type_id := p_transaction_source_type_id;
716 END IF;
717
718 IF (p_transaction_type_id <> fnd_api.g_miss_num) THEN
719 l_txn_type_id := p_transaction_type_id;
720 END IF;
721
722 l_trohdr_rec.created_by := fnd_global.user_id;
723 l_trohdr_rec.creation_date := SYSDATE;
724 l_trohdr_rec.date_required := SYSDATE;
725 l_trohdr_rec.from_subinventory_code := p_sub;
726 l_trohdr_rec.header_status := inv_globals.g_to_status_preapproved;
727 l_trohdr_rec.last_updated_by := fnd_global.user_id;
728 l_trohdr_rec.last_update_date := SYSDATE;
729 l_trohdr_rec.last_update_login := fnd_global.user_id;
730 l_trohdr_rec.organization_id := l_org_id;
731 l_trohdr_rec.status_date := SYSDATE;
732 l_trohdr_rec.to_subinventory_code := NULL;
733 l_trohdr_rec.move_order_type := inv_globals.g_move_order_put_away;
734 l_trohdr_rec.db_flag := fnd_api.g_true;
735 l_trohdr_rec.operation := inv_globals.g_opr_create;
736 l_line_num := l_line_num + 1;
737 l_trolin_tbl(l_order_count).header_id := l_trohdr_rec.header_id;
738 l_trolin_tbl(l_order_count).created_by := fnd_global.user_id;
739 l_trolin_tbl(l_order_count).creation_date := SYSDATE;
740 l_trolin_tbl(l_order_count).date_required := SYSDATE;
741 l_trolin_tbl(l_order_count).from_subinventory_code := p_sub;
742 l_trolin_tbl(l_order_count).from_locator_id := p_loc;
743 l_trolin_tbl(l_order_count).inventory_item_id := l_inventory_item_id;
744 l_trolin_tbl(l_order_count).last_updated_by := fnd_global.user_id;
745 l_trolin_tbl(l_order_count).last_update_date := SYSDATE;
746 l_trolin_tbl(l_order_count).last_updated_by := fnd_global.user_id;
747 l_trolin_tbl(l_order_count).last_update_date := SYSDATE;
748 l_trolin_tbl(l_order_count).last_update_login := fnd_global.login_id;
749 l_trolin_tbl(l_order_count).line_id := fnd_api.g_miss_num;
750 l_trolin_tbl(l_order_count).line_number := l_line_num;
751 l_trolin_tbl(l_order_count).line_status := inv_globals.g_to_status_preapproved;
752 l_trolin_tbl(l_order_count).organization_id := l_org_id;
753 l_trolin_tbl(l_order_count).quantity := l_qty;
754 l_trolin_tbl(l_order_count).status_date := SYSDATE;
755 l_trolin_tbl(l_order_count).to_subinventory_code := NULL;
756 l_trolin_tbl(l_order_count).uom_code := l_uom;
757 l_trolin_tbl(l_order_count).db_flag := fnd_api.g_true;
758 l_trolin_tbl(l_order_count).operation := inv_globals.g_opr_create;
759 l_trolin_tbl(l_order_count).lpn_id := p_lpn;
760 l_trolin_tbl(l_order_count).REFERENCE := l_ref;
761 l_trolin_tbl(l_order_count).reference_type_code := l_ref_type;
762 l_trolin_tbl(l_order_count).reference_id := l_ref_id;
763 l_trolin_tbl(l_order_count).project_id := l_project_id;
764 l_trolin_tbl(l_order_count).task_id := l_task_id;
765 l_trolin_tbl(l_order_count).lot_number := l_lot_number;
766 l_trolin_tbl(l_order_count).revision := l_revision;
767 l_trolin_tbl(l_order_count).transaction_type_id := l_txn_type_id;
768 l_trolin_tbl(l_order_count).transaction_source_type_id := l_txn_source_type_id;
769 l_trolin_tbl(l_order_count).inspection_status := l_insp_status;
770 l_trolin_tbl(l_order_count).wms_process_flag := l_wms_process_flag;
771 -- Added this to be populated for intransit shipments.
772 l_trolin_tbl(l_order_count).to_organization_id := p_transfer_org_id;
773
774 l_trolin_tbl(l_order_count).secondary_quantity := l_sec_qty; -- Added for OPM convergance
775 l_trolin_tbl(l_order_count).secondary_uom := l_sec_uom; -- Added for OPM convergance
776
777 -- l_trolin_tbl(l_order_count).move_order_type:=inv_globals.g_move_order_put_away;
778 IF (p_txn_source_id <> fnd_api.g_miss_num) THEN
779 l_trolin_tbl(l_order_count).txn_source_id := l_txn_source_id;
780 END IF;
781
782 l_trolin_tbl(l_order_count).from_cost_group_id := l_from_cg_id;
783 l_trolin_tbl(l_order_count).to_cost_group_id := l_from_cg_id;
784
785 IF (l_debug = 1) THEN
786 mydebug('create_mo: Before Checking header');
787 END IF;
788
789 IF (l_header_id IS NULL
790 OR l_header_id = fnd_api.g_miss_num) THEN
791 IF (l_debug = 1) THEN
792 mydebug('create_mo: Header Not passed. Calling Process_Move_Order');
793 END IF;
794
795 inv_move_order_pub.process_move_order(
796 p_api_version_number => 1.0
797 , p_init_msg_list => 'F'
798 , p_commit => fnd_api.g_false
799 , x_return_status => l_return_status
800 , x_msg_count => l_msg_count
801 , x_msg_data => l_msg_data
802 , p_trohdr_rec => l_trohdr_rec
803 , p_trohdr_val_rec => l_trohdr_val_rec
804 , p_trolin_tbl => l_trolin_tbl
805 , p_trolin_val_tbl => l_trolin_val_tbl
806 , x_trohdr_rec => l_trohdr_rec
807 , x_trohdr_val_rec => l_trohdr_val_rec
808 , x_trolin_tbl => l_trolin_tbl
809 , x_trolin_val_tbl => l_trolin_val_tbl
810 );
811 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
812
813 IF (l_msg_count = 0) THEN
814 IF (l_debug = 1) THEN
815 mydebug('create_mo: Successful');
816 END IF;
817 ELSIF(l_msg_count = 1) THEN
818 IF (l_debug = 1) THEN
819 mydebug('create_mo: Not Successful');
820 mydebug('create_mo: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
821 END IF;
822 ELSE
823 IF (l_debug = 1) THEN
824 mydebug('create_mo: Not Successful2');
825 END IF;
826
827 FOR i IN 1 .. l_msg_count LOOP
828 l_msg_data := fnd_msg_pub.get(i, 'F');
829
830 IF (l_debug = 1) THEN
831 mydebug('create_mo: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
832 END IF;
833 END LOOP;
834 END IF;
835
836 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
837 fnd_message.set_name('WMS', 'WMS_TD_MO_ERROR');
838 fnd_msg_pub.ADD;
839 RAISE fnd_api.g_exc_unexpected_error;
840 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
841 fnd_message.set_name('WMS', 'WMS_TD_MO_ERROR');
842 fnd_msg_pub.ADD;
843 RAISE fnd_api.g_exc_error;
844 END IF;
845
846 /* Get header and line ids */
847 p_header_id := l_trohdr_rec.header_id;
848 x_line_id := l_trolin_tbl(l_order_count).line_id;
849
850 IF (l_debug = 1) THEN
851 mydebug('create_mo: Header' || p_header_id);
852 mydebug('create_mo: Org');
853 mydebug('create_mo: ' || l_trolin_tbl(1).organization_id);
854 END IF;
855
856 l_cg_line := l_trolin_tbl(1).line_id;
857
858 IF (l_debug = 1) THEN
859 mydebug('create_mo: Line: ' || l_cg_line);
860 mydebug('create_mo: From CG ' || l_trolin_tbl(1).from_cost_group_id);
861 mydebug('create_mo: To CG ' || l_trolin_tbl(1).to_cost_group_id);
862 mydebug('create_mo: From Sub ' || l_trolin_tbl(1).from_subinventory_code);
863 END IF;
864
865 SELECT from_subinventory_code
866 , from_cost_group_id
867 , to_cost_group_id
868 INTO l1
869 , l2
870 , l3
871 FROM mtl_txn_request_lines
872 WHERE line_id = l_cg_line;
873
874 IF (l_debug = 1) THEN
875 mydebug('create_mo: Act Sub: ' || l1);
876 mydebug('create_mo: Act FCG: ' || l2);
877 mydebug('create_mo: Act TCG: ' || l3);
878 END IF;
879
880 IF l_from_cg_id IS NULL THEN
881 IF (l_debug = 1) THEN
882 mydebug('create_mo: Calling CG Engine');
883 END IF;
884
885 inv_cost_group_pub.assign_cost_group(
886 p_api_version_number => 1.0
887 , p_init_msg_list => fnd_api.g_false
888 , p_commit => fnd_api.g_false
889 , x_return_status => l_return_status
890 , x_msg_count => l_msg_count
891 , x_msg_data => l_msg_data
892 , p_line_id => l_cg_line
893 , p_organization_id => l_org_id
894 , p_input_type => inv_cost_group_pub.g_input_moline
895 , x_cost_group_id => l_cg_id
896 , x_transfer_cost_group_id => l_tcg_id
897 );
898
899 IF (l_debug = 1) THEN
900 mydebug('create_mo: After Calling CG Engine');
901 mydebug('create_mo: CG: ' || l_cg_id);
902 mydebug('create_mo: TCG: ' || l_tcg_id);
903 END IF;
904
905 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
906 IF (l_debug = 1) THEN
907 mydebug('create_mo: UnexpError In CG');
908 END IF;
909
910 fnd_message.set_name('WMS', 'WMS_TD_CG_ERROR');
911 fnd_msg_pub.ADD;
912 RAISE fnd_api.g_exc_unexpected_error;
913 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
914 IF (l_debug = 1) THEN
915 mydebug('create_mo: Error In CG');
916 END IF;
917
918 fnd_message.set_name('WMS', 'WMS_TD_CG_ERROR');
919 fnd_msg_pub.ADD;
920 RAISE fnd_api.g_exc_error;
921 END IF;
922 END IF;
923 ELSE
924 IF (l_debug = 1) THEN
925 mydebug('create_mo: Header was passed. Calling create_mo_line');
926 END IF;
927
928 wms_task_dispatch_put_away.create_mo_line(
929 p_org_id => l_org_id
930 , p_inventory_item_id => l_inventory_item_id
931 , p_qty => l_qty
932 , p_uom => l_uom
933 , p_lpn => l_lpn
934 , p_project_id => l_project_id
935 , p_task_id => l_task_id
936 , p_reference => l_ref
937 , p_reference_type_code => l_ref_type
938 , p_reference_id => l_ref_id
939 , p_header_id => l_header_id
940 , p_lot_number => l_lot_number
941 , p_revision => l_revision
942 , p_inspection_status => l_insp_status
943 , p_txn_source_id => l_txn_source_id
944 , p_transaction_type_id => l_txn_type_id
945 , p_transaction_source_type_id => l_txn_source_type_id
946 , p_wms_process_flag => l_wms_process_flag
947 , x_return_status => l_return_status
948 , x_msg_count => l_msg_count
949 , x_msg_data => l_msg_data
950 , p_from_cost_group_id => l_from_cg_id
951 , p_sec_qty => l_sec_qty
952 , p_sec_uom => l_sec_uom
953 , x_line_id => x_line_id
954 );
955
956 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
957 fnd_message.set_name('WMS', 'WMS_TD_MO_ERROR');
958 fnd_msg_pub.ADD;
959 RAISE fnd_api.g_exc_unexpected_error;
960 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
961 fnd_message.set_name('WMS', 'WMS_TD_MO_ERROR');
962 fnd_msg_pub.ADD;
963 RAISE fnd_api.g_exc_error;
964 END IF;
965 END IF;
966
967 x_return_status := fnd_api.g_ret_sts_success;
968 EXCEPTION
969 WHEN fnd_api.g_exc_error THEN
970 x_return_status := fnd_api.g_ret_sts_error;
971 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
972 WHEN OTHERS THEN
973 x_return_status := fnd_api.g_ret_sts_unexp_error;
974
975 IF SQLCODE IS NOT NULL THEN
976 inv_mobile_helper_functions.sql_error('WMS_Task_Dispatch_put_away.create_mo', '10', SQLCODE);
977 END IF;
978
979 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
980 END create_mo;
981
982 -- added for bug 3401817
983 -- An autonomous_transaction wrapper arount wms_putaway_suggestions.cleanup_suggestions
984 -- This is because after cleanup_suggestions, we call create_suggestions,
985 -- which may very well suggest the same locator. In cleanup_suggestions, we call abort_operation_instance, which
986 -- in turn calls revert_loc_sugg_capacity_nauto. However, in create_suggestions, we call update_loc_suggested_capacity,
987 -- with autonomous_transaction, which will cause resource busy.
988
989 /*
990 PROCEDURE cleanup_suggestions
991 ( p_org_id IN NUMBER
992 , p_lpn_id IN NUMBER
993 , x_return_status OUT NOCOPY VARCHAR2
994 , x_msg_count OUT NOCOPY NUMBER
995 , x_msg_data OUT NOCOPY VARCHAR2
996 , p_move_order_line_id IN NUMBER DEFAULT NULL -- added for ATF_J2
997 ) IS
998 PRAGMA autonomous_transaction;
999 BEGIN
1000 wms_putaway_suggestions.cleanup_suggestions
1001 ( p_lpn_id => p_lpn_id
1002 , p_org_id => p_org_id
1003 , x_return_status => x_return_status
1004 , x_msg_count => x_msg_count
1005 , x_msg_data => x_msg_data
1006 , p_move_order_line_id => p_move_order_line_id
1007 );
1008 COMMIT;
1009 END;
1010
1011 */
1012
1013 -- Create Putaway Suggestions
1014 -- Bug# 2752119
1015 -- Added an extra input parameter called p_check_for_crossdock
1016 -- which will default to 'Y' = Yes.
1017 -- This is needed when we are performing an Express Drop and need
1018 -- to validate against the rules. In that case, it is possible that
1019 -- a crossdocking opportunity exists but the user chose to ignore it
1020 -- and proceed with the express drop. We should not call the
1021 -- crossdocking API's at all in that case since it might split the
1022 -- move order lines.
1023 PROCEDURE suggestions_pub(
1024 p_lpn_id IN NUMBER
1025 , p_org_id IN NUMBER
1026 , p_user_id IN NUMBER
1027 , p_eqp_ins IN VARCHAR2
1028 , x_number_of_rows OUT NOCOPY NUMBER
1029 , x_return_status OUT NOCOPY VARCHAR2
1030 , x_msg_count OUT NOCOPY NUMBER
1031 , x_msg_data OUT NOCOPY VARCHAR2
1032 , x_crossdock OUT NOCOPY VARCHAR2
1033 , p_status IN NUMBER := 3
1034 , p_check_for_crossdock IN VARCHAR2 := 'Y'
1035 , p_move_order_line_id IN NUMBER DEFAULT NULL -- added for ATF_J
1036 , p_commit IN VARCHAR2
1037 , p_drop_type IN VARCHAR2
1038 , p_subinventory IN VARCHAR2
1039 , p_locator_id IN NUMBER
1040 ) IS
1041 l_api_version_number CONSTANT NUMBER := 1.0;
1042 l_init_msg_list VARCHAR2(255) := fnd_api.g_false;
1043 l_api_name CONSTANT VARCHAR2(30) := 'Suggestions_PUB';
1044 l_num_of_rows NUMBER := 0;
1045 l_detailed_qty NUMBER := 0;
1046 l_ser_index NUMBER;
1047 x_success NUMBER;
1048 l_revision VARCHAR2(3);
1049 l_transfer_to_location NUMBER;
1050 l_locator_id NUMBER;
1051 l_transaction_temp_id NUMBER;
1052 l_transaction_header_id NUMBER;
1053 l_subinventory_code VARCHAR2(30);
1054 l_transaction_quantity NUMBER;
1055 l_inventory_item_id NUMBER;
1056 l_temp_id NUMBER;
1057 l_mtl_reservation inv_reservation_global.mtl_reservation_tbl_type;
1058 l_return_status VARCHAR2(1);
1059 l_grouping_rule_id NUMBER;
1060 l_message VARCHAR2(2000);
1061 l_msg_data VARCHAR2(2000);
1062 l_count NUMBER;
1063 l_msg_count NUMBER;
1064 l_from_serial_number VARCHAR2(30);
1065 l_to_serial_number VARCHAR2(30);
1066 l_priority NUMBER;
1067 l_std_op_id NUMBER;
1068 l_next_task_id NUMBER;
1069 l_wms_task_type NUMBER;
1070 l_operation_plan_id NUMBER;
1071 l_move_order_line_id NUMBER;
1072 l_line_id NUMBER;
1073 l_serial_flag VARCHAR2(30) := 'N';
1074 l_rcount NUMBER;
1075 l_lpn_id NUMBER;
1076 -- l_lpn_cont NUMBER;
1077 l_lpn_cg_id NUMBER;
1078 l_completion_txn_id NUMBER;
1079 l_ref_id NUMBER;
1080 l_txn_source_type_id NUMBER;
1081 l_flow_schedule VARCHAR2(1);
1082 l_transaction_source_id NUMBER;
1083 l_rows_detailed NUMBER;
1084 l_mtl_status NUMBER;
1085 l_quantity_detailed NUMBER;
1086 l_quantity NUMBER;
1087 l_backorder_delivery_detail_id NUMBER;
1088 l_crossdock_type NUMBER;
1089 wdt_exist VARCHAR2(1) := NULL;
1090 l_tt_id NUMBER := NULL;
1091
1092 CURSOR molines_csr IS --14176228
1093 SELECT *
1094 FROM (
1095 SELECT mtrl.line_id
1096 , mtrl.reference_id
1097 , mtrl.transaction_source_type_id
1098 , mtrl.quantity_detailed
1099 , mtrl.quantity
1100 , mtrl.backorder_delivery_detail_id
1101 , NVL(crossdock_type, 1) crossdock_type
1102 , mtrl.to_subinventory_code
1103 , mtrl.to_locator_id
1104 , mtrl.reference_detail_id
1105 , mtrl.inventory_item_id
1106 , mtrl.txn_source_id
1107 , mtrl.txn_source_line_id
1108 , mtrl.txn_source_line_detail_id
1109 , mtrl.transaction_type_id
1110 FROM mtl_txn_request_lines mtrl, mtl_txn_request_headers mtrh
1111 WHERE mtrl.lpn_id = p_lpn_id
1112 AND mtrl.organization_id = p_org_id
1113 AND mtrl.header_id = mtrh.header_id
1114 AND mtrl.line_status <> inv_globals.g_to_status_closed
1115 AND mtrh.move_order_type = inv_globals.g_move_order_put_away
1116 AND mtrl.line_id = NVL(p_move_order_line_id, mtrl.line_id) -- added for ATF_J
1117 --BUG 5194761
1118 UNION ALL
1119 SELECT mtrl.line_id
1120 , mtrl.reference_id
1121 , mtrl.transaction_source_type_id
1122 , mtrl.quantity_detailed
1123 , mtrl.quantity
1124 , mtrl.backorder_delivery_detail_id
1125 , NVL(crossdock_type, 1) crossdock_type
1126 , mtrl.to_subinventory_code
1127 , mtrl.to_locator_id
1128 , mtrl.reference_detail_id
1129 , mtrl.inventory_item_id
1130 , mtrl.txn_source_id
1131 , mtrl.txn_source_line_id
1132 , mtrl.txn_source_line_detail_id
1133 , mtrl.transaction_type_id
1134
1135 FROM mtl_txn_request_lines mtrl, mtl_txn_request_headers mtrh
1136 WHERE mtrl.lpn_id = p_lpn_id
1137 AND mtrl.organization_id = p_org_id
1138 AND mtrl.header_id = mtrh.header_id
1139 AND mtrl.line_status <> inv_globals.g_to_status_closed
1140 AND mtrh.move_order_type = inv_globals.g_move_order_put_away
1141 AND p_move_order_line_id IS NOT NULL
1142 AND mtrl.reference_detail_id = p_move_order_line_id
1143 --END BUG 5194761
1144 )mtrl
1145 ORDER BY inventory_item_id,transaction_source_type_id,transaction_type_id,txn_source_id,txn_source_line_id,txn_source_line_detail_id;
1146
1147
1148 -- ATF_J2
1149 -- Modified pregen_suggestions_csr cursor to get data from MOL also.
1150 CURSOR pregen_suggestions_csr IS
1151 SELECT mmtt.last_update_date
1152 , mmtt.transaction_temp_id
1153 , mmtt.locator_id mmtt_loc_id
1154 , mol.to_locator_id mol_loc_id
1155 , mol.backorder_delivery_detail_id
1156 , mmtt.operation_plan_id
1157 , mol.inspection_status
1158 FROM mtl_material_transactions_temp mmtt, mtl_txn_request_lines mol
1159 WHERE mmtt.lpn_id = l_lpn_id
1160 -- Added following line for ATF_J
1161 AND mmtt.move_order_line_id = NVL(p_move_order_line_id, mmtt.move_order_line_id)
1162 AND mmtt.organization_id = p_org_id
1163 -- Added for ATF_J to make sure dummy packing MMTT lines are not selected
1164 AND mmtt.transaction_action_id NOT IN (50, 51, 52)
1165 AND mmtt.move_order_line_id = mol.line_id
1166 -- Bug# 3434940 - Performance Fixes
1167 -- Also join against org and LPN for MOL to speed up the parsing
1168 -- time for the query
1169 AND mol.organization_id = p_org_id
1170 AND mol.lpn_id = l_lpn_id;
1171
1172 l_pregen_suggestion pregen_suggestions_csr%ROWTYPE;
1173
1174 -- End ATF_J2
1175
1176
1177 -- ATF_J
1178 -- It is not necessary to add P_move_order_line_ID to cursor suggestion_csr
1179 -- because lpn_csr is called within molines_csr and l_line_id is already restricted.
1180
1181
1182 CURSOR suggestions_csr IS
1183 SELECT transaction_header_id
1184 , transaction_temp_id
1185 , inventory_item_id
1186 , revision
1187 , subinventory_code
1188 , locator_id
1189 , transaction_quantity
1190 , transfer_to_location
1191 , NVL(standard_operation_id, 2)
1192 , task_priority
1193 , NVL(wms_task_type, 2)
1194 , operation_plan_id
1195 , move_order_line_id
1196 FROM mtl_material_transactions_temp
1197 WHERE move_order_line_id = l_line_id
1198 AND transaction_action_id NOT IN (50, 51, 52) --ATF_J3: to make sure dummy packing MMTT lines not selected
1199
1200 ;
1201
1202 -- ATF_J
1203 -- It is not necessary to add P_move_order_line_ID to cursor lpn_csr
1204 -- because lpn_csr is for creating move order lines when they do not exist,
1205 -- in which case P_move_order_line_ID will not be passed.
1206
1207 CURSOR lpn_csr IS
1208 SELECT inventory_item_id
1209 , quantity
1210 , uom_code
1211 , lot_number
1212 , revision
1213 , cost_group_id
1214 , secondary_quantity -- Added for OPM convergance
1215 , secondary_uom_code -- Added for OPM convergance
1216 FROM wms_lpn_contents
1217 WHERE parent_lpn_id = p_lpn_id;
1218
1219 l_m_item NUMBER;
1220 l_m_qty NUMBER;
1221 l_m_uom VARCHAR2(3);
1222 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
1223 l_m_lot VARCHAR2(80);
1224 l_m_rev VARCHAR2(3);
1225 l_m_hdr NUMBER;
1226 l_m_stat VARCHAR2(30);
1227 l_m_line NUMBER;
1228 l_m_sub VARCHAR2(10);
1229 l_m_loc NUMBER;
1230 l_cdock_flag NUMBER;
1231 l_ret_crossdock NUMBER;
1232 l_td_crossdock VARCHAR2(3);
1233 -- ATFJ_2
1234 -- removed l_make_suggestions check.
1235 -- Because it is sufficient to determine if call rules engine or not
1236 -- based on mol.quantity_detailed and mol.quantity
1237
1238 -- l_make_suggestions VARCHAR2(2);
1239 l_regeneration_interval NUMBER;
1240 l_last_update_date DATE;
1241 l_pregen_putaway_tasks_flag NUMBER;
1242 l_temp NUMBER;
1243 l_temp_update_date DATE;
1244 l_wip_supply_type NUMBER;
1245 l_lpn_context NUMBER;
1246 l_project_id NUMBER;
1247 l_task_id NUMBER;
1248 l_emp_id NUMBER;
1249 -- Following variables added in ATF_J
1250
1251 l_atf_error_code NUMBER;
1252 l_crossdock_missmatch_flag VARCHAR2(1) := 'N';
1253 l_task_dispatched_flag VARCHAR2(1) := 'N';
1254 l_op_plan_started_flag VARCHAR2(1) := 'N';
1255 l_mmtt_staled_flag VARCHAR2(1) := 'N';
1256 l_need_to_cleanup_pregen VARCHAR2(1) := 'N';
1257 l_op_plan_instance_status NUMBER;
1258 l_wlc_mol_missmatch_flag VARCHAR2(1) := 'N';
1259
1260 -- End variables added in ATF_J
1261 l_to_sub_code VARCHAR2(30);
1262 l_to_loc_id NUMBER;
1263 l_ref_detail_id NUMBER;--BUG 5194761
1264
1265 -- Following variables added per GRAO's request
1266 -- used for inventory move by rules's engine
1267 l_quick_pick_flag VARCHAR2(1) := 'N';
1268 -- End GRAO
1269
1270 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1271
1272 -- Added for OPM convergance
1273 l_sec_qty NUMBER;
1274 l_sec_uom VARCHAR2(3);
1275 l_process_flag VARCHAR2(5); -- nsinghi. Added for GME-WMS Integration
1276
1277 --14176228
1278 l_transaction_type_id NUMBER;
1279 l_txn_source_id NUMBER;
1280 l_txn_source_line_id NUMBER;
1281 l_txn_source_line_detail_id NUMBER;
1282 l_item_tree_string VARCHAR2(1000);
1283 BEGIN
1284 IF (l_debug = 1) THEN
1285 mydebug('suggestions_pub: In suggestions_pub');
1286 END IF;
1287
1288 -- Bug# 2744186
1289 -- Set the savepoint
1290 SAVEPOINT suggestions_pub_sp;
1291 l_lpn_id := p_lpn_id;
1292 l_return_status := fnd_api.g_ret_sts_success;
1293
1294 IF (l_lpn_id = 0) THEN
1295 l_lpn_id := NULL;
1296 END IF;
1297
1298 l_rcount := 0;
1299 l_td_crossdock := 'N';
1300
1301 -- Bug# 2750060
1302 -- Get the employee ID so we can populate
1303 -- the person_id column in WDT properly.
1304 BEGIN
1305 SELECT employee_id
1306 INTO l_emp_id
1307 FROM fnd_user
1308 WHERE user_id = p_user_id;
1309 EXCEPTION
1310 WHEN NO_DATA_FOUND THEN
1311 IF (l_debug = 1) THEN
1312 mydebug('suggestions_pub: There is no employee tied to the user');
1313 END IF;
1314
1315 l_emp_id := NULL;
1316 END;
1317
1318 SELECT regeneration_interval
1319 , NVL(crossdock_flag, 2) cdock
1320 , pregen_putaway_tasks_flag
1321 INTO l_regeneration_interval
1322 , l_cdock_flag
1323 , l_pregen_putaway_tasks_flag
1324 FROM mtl_parameters
1325 WHERE organization_id = p_org_id;
1326
1327 -- Bug# 2752119
1328 -- Only check for crossdocking if the input parameter is set to 'Y'
1329 -- in case we are calling the Suggestions_PUB while performing an
1330 -- Express Drop with rules validation. We don't want to check for
1331 -- crossdocking in that scenario
1332
1333
1334 --Bug# 2990197
1335 -- The second part of bug 2265157 was never propogated to the main
1336 -- branch. In suggestions_Pub (file WMSTKPTB.pls), before we call
1337 -- crossdock, we should check to make sure that the LPN context is
1338 -- only receiving or WIP.
1339
1340 SELECT lpn_context
1341 INTO l_lpn_context
1342 FROM wms_license_plate_numbers
1343 WHERE lpn_id = l_lpn_id
1344 AND organization_id = p_org_id;
1345
1346 -- ATF_J2 moved crossdock call to after cleanup_suggestions
1347
1348
1349 -- Check to see if mo lines exist already
1350 -- If not, we have to create it
1351 BEGIN
1352 SELECT 1
1353 INTO l_rcount
1354 FROM DUAL
1355 WHERE EXISTS(
1356 SELECT 1
1357 FROM mtl_txn_request_lines l, mtl_txn_request_headers h
1358 WHERE l.lpn_id = l_lpn_id
1359 AND l.line_id = NVL(p_move_order_line_id, l.line_id) -- added for ATF_J
1360 AND NVL(l.quantity_delivered, 0) < l.quantity -- added for ATF_J
1361 AND l.organization_id = p_org_id
1362 AND l.header_id = h.header_id
1363 AND l.line_status <> inv_globals.g_to_status_closed
1364 AND h.move_order_type = inv_globals.g_move_order_put_away);
1365 -- AND Nvl(l.quantity_detailed,0) <l.quantity);
1366
1367 EXCEPTION
1368 WHEN NO_DATA_FOUND THEN
1369 l_rcount := 0;
1370 END;
1371
1372 IF (l_rcount = 0) THEN
1373 IF (l_debug = 1) THEN
1374 mydebug('suggestions_pub: Move order does not exist. Creating new MO..');
1375 END IF;
1376
1377 IF l_lpn_context <> 1 THEN
1378 IF (l_debug = 1) THEN
1379 mydebug('suggestions_pub: Not an INV LPN');
1380 END IF;
1381
1382 fnd_message.set_name('WMS', 'WMS_MO_NOT_FOUND');
1383 fnd_msg_pub.ADD;
1384 RAISE fnd_api.g_exc_error;
1385 END IF;
1386 END IF; -- (l_rcount=0) -- fixed in ATF
1387
1388 -- ATF_J5
1389 -- Added p_move_order_line_id check below.
1390 -- When item load an inventory LPN, putaway UI will create
1391 -- a move order line and pass that to suggestions_pub.
1392 -- In this case we shouldn't close that move order line and create line.
1393 IF l_lpn_context = 1 AND p_move_order_line_id IS NULL THEN
1394 -- ATF_J2
1395 -- Need to chek whether operation plan instance commenced or not
1396 -- If any MMTT lines has operation plan instance commenced, should not
1397 -- delete MMTT and close move order line.
1398 -- only applicable to J or above
1399
1400
1401 mydebug('suggestions_pub: Current release is above J.');
1402 OPEN pregen_suggestions_csr;
1403
1404 LOOP
1405 FETCH pregen_suggestions_csr INTO l_pregen_suggestion;
1406 EXIT WHEN pregen_suggestions_csr%NOTFOUND;
1407
1408 IF l_pregen_suggestion.operation_plan_id IS NOT NULL THEN
1409 IF (l_debug = 1) THEN
1410 mydebug('suggestions_pub: Calling WMS_ATF_RUNTIME_PUB_APIS.Check_Plan_Status with:');
1411 mydebug('p_source_task_id => ' || l_pregen_suggestion.transaction_temp_id);
1412 mydebug('p_activity_type_id => ' || '1');
1413 END IF;
1414
1415 wms_atf_runtime_pub_apis.check_plan_status(
1416 x_return_status => l_return_status
1417 , x_msg_data => l_msg_data
1418 , x_msg_count => l_msg_count
1419 , x_error_code => l_atf_error_code
1420 , x_plan_status => l_op_plan_instance_status
1421 , p_source_task_id => l_pregen_suggestion.transaction_temp_id
1422 , p_activity_type_id => '1' -- inbound
1423 );
1424
1425 IF (l_debug = 1) THEN
1426 mydebug('suggestions_pub: After calling WMS_ATF_RUNTIME_PUB_APIS.Check_Plan_Status.');
1427 mydebug('x_return_status => ' || l_return_status);
1428 mydebug('x_msg_data => ' || l_msg_data);
1429 mydebug('x_msg_count => ' || l_msg_count);
1430 mydebug('x_error_code => ' || l_atf_error_code);
1431 mydebug('x_plan_status => ' || l_op_plan_instance_status);
1432 END IF;
1433
1434 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
1435 IF (l_debug = 1) THEN
1436 mydebug('suggestions_pub: WMS_ATF_RUNTIME_PUB_APIS.Check_Plan_Status failed.');
1437 END IF;
1438
1439 RAISE fnd_api.g_exc_error;
1440 END IF; -- (l_return_status <> fnd_api.g_ret_sts_success)
1441
1442 IF l_op_plan_instance_status IS NOT NULL
1443 AND l_op_plan_instance_status <> 1 -- not pending status
1444 THEN
1445 l_op_plan_started_flag := 'Y';
1446 EXIT;
1447 END IF; -- (l_op_plan_instance_status IS NOT NULL)
1448 END IF; -- IF l_pregen_suggestion.operation_plan_id IS NOT NULL
1449 END LOOP;
1450
1451 CLOSE pregen_suggestions_csr;
1452
1453 -- End ATF_J2
1454
1455 -- ATF_J2
1456 -- only delete MMTT/WDT, close MOL, when there is no operation plan instance commenced
1457
1458 IF l_op_plan_started_flag = 'Y' THEN
1459 NULL;
1460 -- l_make_suggestions := 'N'; --??
1461
1462 ELSE
1463 -- l_make_suggestions := 'Y';
1464
1465 SELECT subinventory_code
1466 , locator_id
1467 INTO l_m_sub
1468 , l_m_loc
1469 FROM wms_license_plate_numbers
1470 WHERE lpn_id = l_lpn_id;
1471
1472 -- Need to close those old MOL lines
1473 -- for inventory LPN
1474 -- Bug 2271470
1475
1476 --Also delete corresponding WDT and MMTTs. bug # 2503594
1477 DELETE FROM wms_dispatched_tasks
1478 WHERE transaction_temp_id IN(
1479 SELECT transaction_temp_id
1480 FROM mtl_material_transactions_temp
1481 WHERE move_order_line_id IN(
1482 SELECT mol.line_id
1483 FROM mtl_txn_request_lines mol
1484 WHERE mol.lpn_id = l_lpn_id
1485 AND mol.line_id = NVL(p_move_order_line_id, mol.line_id) -- added for ATF_J
1486 AND mol.organization_id = p_org_id
1487 AND mol.quantity_detailed > 0
1488 AND EXISTS(
1489 SELECT 1
1490 FROM mtl_txn_request_headers moh
1491 WHERE mol.header_id = moh.header_id
1492 AND moh.move_order_type = inv_globals.g_move_order_put_away)));
1493
1494 -- ATF_J2
1495 -- Need to delete MTLT before deleting MMTT
1496 -- Need tuning ???
1497
1498
1499 DELETE FROM mtl_transaction_lots_temp mtlt
1500 WHERE EXISTS(
1501 SELECT 1
1502 FROM mtl_material_transactions_temp mmtt
1503 WHERE mtlt.transaction_temp_id = mmtt.transaction_temp_id
1504 AND mmtt.move_order_line_id IN(
1505 SELECT mol.line_id
1506 FROM mtl_txn_request_lines mol
1507 WHERE mol.lpn_id = l_lpn_id
1508 AND mol.line_id = NVL(p_move_order_line_id, mol.line_id) -- added for ATF_J
1509 AND mol.organization_id = p_org_id
1510 AND mol.quantity_detailed > 0
1511 AND EXISTS(
1512 SELECT 1
1513 FROM mtl_txn_request_headers moh
1514 WHERE mol.header_id = moh.header_id
1515 AND moh.move_order_type = inv_globals.g_move_order_put_away)));
1516
1517 DELETE FROM mtl_material_transactions_temp
1518 WHERE move_order_line_id IN(
1519 SELECT mol.line_id
1520 FROM mtl_txn_request_lines mol
1521 WHERE mol.lpn_id = l_lpn_id
1522 AND mol.line_id = NVL(p_move_order_line_id, mol.line_id) -- added for ATF_J
1523 AND mol.organization_id = p_org_id
1524 AND mol.quantity_detailed > 0
1525 AND EXISTS(SELECT 1
1526 FROM mtl_txn_request_headers moh
1527 WHERE mol.header_id = moh.header_id
1528 AND moh.move_order_type = inv_globals.g_move_order_put_away));
1529
1530 UPDATE mtl_txn_request_lines mol
1531 SET mol.line_status = inv_globals.g_to_status_closed
1532 WHERE mol.lpn_id = l_lpn_id
1533 AND mol.line_id = NVL(p_move_order_line_id, mol.line_id) -- added for ATF_J
1534 AND mol.organization_id = p_org_id
1535 -- AND mol.quantity_detailed > 0 -- removed in ATF_J3
1536 AND EXISTS(SELECT 1
1537 FROM mtl_txn_request_headers moh
1538 WHERE mol.header_id = moh.header_id
1539 AND moh.move_order_type = inv_globals.g_move_order_put_away);
1540
1541 IF (l_debug = 1) THEN
1542 mydebug('suggestions_pub: after getting sub and loc');
1543 mydebug('suggestions_pub: Loc' || l_m_loc);
1544 mydebug('suggestions_pub: Sub' || l_m_sub);
1545 END IF;
1546
1547 OPEN lpn_csr;
1548
1549 IF (l_debug = 1) THEN
1550 mydebug('suggestions_pub: Opened lpncsr');
1551 END IF;
1552
1553 LOOP
1554 FETCH lpn_csr INTO
1555 l_m_item,
1556 l_m_qty,
1557 l_m_uom,
1558 l_m_lot,
1559 l_m_rev,
1560 l_lpn_cg_id,
1561 l_sec_qty,
1562 l_sec_uom;
1563 EXIT WHEN lpn_csr%NOTFOUND;
1564
1565 IF (l_debug = 1) THEN
1566 mydebug('suggestions_pub: lpn loop');
1567 mydebug('suggestions_pub: lot' || l_m_lot);
1568 END IF;
1569
1570 IF l_m_lot = '-999' THEN
1571 l_m_lot := NULL;
1572 END IF;
1573
1574 IF l_m_rev = '-999' THEN
1575 l_m_rev := NULL;
1576 END IF;
1577
1578 SELECT mil.project_id
1579 , mil.task_id
1580 INTO l_project_id
1581 , l_task_id
1582 FROM mtl_item_locations mil
1583 WHERE mil.inventory_location_id = l_m_loc
1584 AND mil.organization_id = p_org_id
1585 AND mil.subinventory_code = l_m_sub;
1586
1587 -- Call create_mo
1588 IF (l_debug = 1) THEN
1589 mydebug('suggestions_pub: Calling create_mo');
1590 END IF;
1591
1592 wms_task_dispatch_put_away.create_mo(
1593 p_org_id => p_org_id
1594 , p_inventory_item_id => l_m_item
1595 , p_qty => l_m_qty
1596 , p_uom => l_m_uom
1597 , p_lpn => l_lpn_id
1598 , p_project_id => l_project_id
1599 , p_task_id => l_task_id
1600 , p_reference => NULL
1601 , p_reference_type_code => NULL
1602 , p_reference_id => NULL
1603 , p_lot_number => l_m_lot
1604 , p_revision => l_m_rev
1605 , p_header_id => l_m_hdr
1606 , p_sub => l_m_sub
1607 , p_loc => l_m_loc
1608 , x_line_id => l_m_line
1609 , p_inspection_status => NULL
1610 , p_transaction_type_id => 64
1611 , p_transaction_source_type_id => 4
1612 , p_wms_process_flag => NULL
1613 , x_return_status => l_return_status
1614 , x_msg_count => l_msg_count
1615 , x_msg_data => l_msg_data
1616 , p_from_cost_group_id => l_lpn_cg_id
1617 , p_sec_qty => l_sec_qty -- Added for OPM Convergance
1618 , p_sec_uom => l_sec_uom -- Added for OPM Convergance
1619 );
1620 -- bug fix 2271470
1621 l_m_hdr := NULL;
1622 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
1623
1624 IF (l_msg_count = 0) THEN
1625 IF (l_debug = 1) THEN
1626 mydebug('suggestions_pub: Successful');
1627 END IF;
1628 ELSIF(l_msg_count = 1) THEN
1629 IF (l_debug = 1) THEN
1630 mydebug('suggestions_pub: Not Successful');
1631 mydebug('suggestions_pub: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
1632 END IF;
1633 ELSE
1634 IF (l_debug = 1) THEN
1635 mydebug('suggestions_pub: Not Successful2');
1636 END IF;
1637
1638 FOR i IN 1 .. l_msg_count LOOP
1639 l_msg_data := fnd_msg_pub.get(i, 'F');
1640
1641 IF (l_debug = 1) THEN
1642 mydebug('suggestions_pub: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
1643 END IF;
1644 END LOOP;
1645 END IF;
1646
1647 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1648 fnd_message.set_name('WMS', 'WMS_TD_CMO_ERROR');
1649 fnd_msg_pub.ADD;
1650 RAISE fnd_api.g_exc_error;
1651 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
1652 fnd_message.set_name('WMS', 'WMS_TD_CMO_ERROR');
1653 fnd_msg_pub.ADD;
1654 RAISE fnd_api.g_exc_error;
1655 END IF;
1656
1657 IF (l_debug = 1) THEN
1658 mydebug('suggestions_pub: Line ID created');
1659 mydebug('suggestions_pub: ' || l_m_line);
1660 END IF;
1661 END LOOP;
1662
1663 CLOSE lpn_csr;
1664 END IF; -- (l_op_plan_started_flag = 'Y') added for ATF_J2
1665
1666 IF p_drop_type = 'MD' THEN
1667
1668 -- Update the move order lines with the user inputted sub/loc.
1669 -- Also null out the quantity detailed
1670 IF (l_debug = 1) THEN
1671 mydebug('Manual Drop: Updating Move orders to : Sub: ' || p_subinventory || ' loc : '||p_locator_id );
1672 END IF;
1673
1674 UPDATE mtl_txn_request_lines mol
1675 SET to_subinventory_code = p_subinventory
1676 , to_locator_id = p_locator_id
1677 , quantity_detailed = NULL
1678 WHERE organization_id = p_org_id
1679 AND lpn_id = l_lpn_id
1680 AND mol.line_status <> inv_globals.g_to_status_closed;
1681 END IF;
1682
1683 END IF; -- (l_lpn_context = 1)
1684
1685 IF (l_debug = 1) THEN
1686 mydebug('suggestions_pub: after lpn crsr loop');
1687 END IF;
1688
1689 -- Code to check for pregenerated putaway allocations
1690 -- The corresponding pseudo code for that is as follows:
1691 --
1692 -- For a given Equipment, LPN, user, org
1693 -- If there are putaway suggestions already created for this LPN
1694 -- if (current time - update date > regeneration interval)
1695 -- or (l_pregen_putaway_tasks_flag = 0)
1696 -- Delete suggestions and call Putaway Rules Engine again.
1697 -- Delete all MMTT lines for that LPN and set detailed quantity
1698 -- = 0 in MO line
1699 -- l_make_suggestions := Y;
1700 --
1701 -- Else
1702 -- Dont call suggestions API
1703 -- l_make_suggestions := N;
1704 --Else
1705 -- l_make_suggestions := Y
1706 --
1707 --If l_make_suggestions = Y
1708 -- Proceed as before in calling suggestions API
1709 --Else
1710 -- Do not create suggestions
1711 --
1712
1713 IF (l_debug = 1) THEN
1714 mydebug('suggestions_pub: Code to check for pregenerated putaway suggestions');
1715 END IF;
1716
1717 l_rcount := 0;
1718 l_temp_update_date := SYSDATE;
1719
1720 -- ATF_J2
1721 -- Rewrite the logic for deleting pre-generated MMTT
1722 --
1723 -- 1. If LPN context is INV, do not need to delete pregenerate, because MMTT deletion has been
1724 -- taken care of previously for inventory LPNs.
1725 --
1726 -- 2. Open and LOOP through pregen_suggestions_csr, which will decide for this
1727 -- LPN/MOL combination do we need to cleanup suggestions or not,
1728 -- by setting l_Need_to_cleanup_pregen flag.
1729 --
1730 --
1731 --
1732 -- 2.1 If mol.backorder_delivery_detail_id IS NOT NULL (crossdocked)
1733 -- AND MOL.to_locator_id <> MMTT.locator_id (and crossdock doesnot match with MMTT)
1734 -- THEN
1735 -- set l_crossdock_missmatch_flag Yes
1736 --
1737 -- END IF;
1738 -- If MOL crossdock locator doesnot match MMTT's destination locator,
1739 -- for sure there would not be task or operation plan commence, therefore
1740 -- does not need to check those.
1741 --
1742 -- 2.2 If Task has commenced, set l_task_dispatched_flag
1743 --
1744 -- 2.3 If operation plan has commenced, set l_op_plan_started_flag
1745 --
1746 -- 2.4 If task staled and not crossdock, set l_mmtt_staled_flag
1747 --
1748 -- 3. After the loop,
1749 -- set l_Need_to_cleanup_prege based on the flags set.
1750 --
1751 --
1752 -- 4. If l_Need_to_cleanup_prege is YES, call wms_putaway_suggestions.cleanup_suggestions, passing lpn_id and move_order_line_id
1753
1754 IF l_lpn_context <> 1 THEN
1755 IF pregen_suggestions_csr%ISOPEN THEN
1756 CLOSE pregen_suggestions_csr;
1757 END IF;
1758
1759 OPEN pregen_suggestions_csr;
1760
1761 LOOP
1762 FETCH pregen_suggestions_csr INTO l_pregen_suggestion;
1763 EXIT WHEN pregen_suggestions_csr%NOTFOUND;
1764
1765 l_rcount := l_rcount + 1;
1766
1767 /*
1768 -- 2.1 Check if MOL crossdock locator doesnot match MMTT's destination locator.
1769
1770 IF l_pregen_suggestion.backorder_delivery_detail_id IS NOT NULL -- This MOL has been back ordered
1771 AND l_pregen_suggestion.mol_loc_id <> l_pregen_suggestion.mmtt_loc_id -- crossdock locator does not match pregenerated MMTT.locator
1772 AND l_crossdock_missmatch_flag = 'N'
1773 THEN
1774 l_crossdock_missmatch_flag := 'Y';
1775 EXIT;
1776 -- we can only exit in this check, because crossdock mismatch has the highest
1777 -- precedence.
1778
1779 END IF; --(l_pregen_suggestion.backorder_delivery_detail_id IS NOT NULL)
1780
1781 */
1782
1783 -- 2.2 Check if task has been dispatched.
1784
1785 IF l_task_dispatched_flag = 'N' THEN
1786 BEGIN
1787 SELECT '1'
1788 INTO wdt_exist
1789 FROM DUAL
1790 WHERE EXISTS(SELECT transaction_temp_id
1791 FROM wms_dispatched_tasks
1792 WHERE transaction_temp_id = l_pregen_suggestion.transaction_temp_id);
1793 EXCEPTION
1794 WHEN NO_DATA_FOUND THEN
1795 wdt_exist := '2';
1796 END;
1797
1798 IF (wdt_exist = '1') THEN
1799 -- some tasks are already dispatched
1800 -- so nothing needs to be done with pregenerated suggestions
1801 l_task_dispatched_flag := 'Y';
1802 EXIT;
1803 END IF; -- (wdt_exist = '1')
1804 END IF; -- l_task_dispatched_flag = 'N'
1805
1806 -- 2.3 check if operation plan has commenced
1807
1808 IF l_pregen_suggestion.operation_plan_id IS NOT NULL THEN
1809 mydebug('suggestions_pub: Current release is above J.');
1810
1811 IF l_op_plan_started_flag = 'N' THEN
1812 IF (l_debug = 1) THEN
1813 mydebug('suggestions_pub: Calling WMS_ATF_RUNTIME_PUB_APIS.Check_Plan_Status with:');
1814 mydebug('p_source_task_id => ' || l_pregen_suggestion.transaction_temp_id);
1815 END IF;
1816
1817 wms_atf_runtime_pub_apis.check_plan_status
1818 (
1819 x_return_status => l_return_status
1820 , x_msg_data => l_msg_data
1821 , x_msg_count => l_msg_count
1822 , x_error_code => l_atf_error_code
1823 , x_plan_status => l_op_plan_instance_status
1824 , p_source_task_id => l_pregen_suggestion.transaction_temp_id
1825 , p_activity_type_id => '1' -- inbound
1826 );
1827
1828 IF (l_debug = 1) THEN
1829 mydebug('suggestions_pub: After calling WMS_ATF_RUNTIME_PUB_APIS.Check_Plan_Status.');
1830 mydebug('x_return_status => ' || l_return_status);
1831 mydebug('x_msg_data => ' || l_msg_data);
1832 mydebug('x_msg_count => ' || l_msg_count);
1833 mydebug('x_error_code => ' || l_atf_error_code);
1834 mydebug('x_plan_status => ' || l_op_plan_instance_status);
1835 END IF;
1836
1837 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
1838 IF (l_debug = 1) THEN
1839 mydebug('suggestions_pub: WMS_ATF_RUNTIME_PUB_APIS.Check_Plan_Status failed.');
1840 END IF;
1841
1842 RAISE fnd_api.g_exc_error;
1843 END IF; -- (l_return_status <> fnd_api.g_ret_sts_success)
1844
1845 IF l_op_plan_instance_status IS NOT NULL
1846 AND l_op_plan_instance_status <> 1 -- not pending status
1847 THEN
1848 l_op_plan_started_flag := 'Y';
1849 EXIT;
1850 END IF; -- (l_op_plan_instance_status IS NOT NULL)
1851 END IF; -- l_op_plan_started_flag = 'N'
1852 END IF; -- (l_pregen_suggestion.operation_plan_id
1853
1854 IF (
1855 ((SYSDATE - l_pregen_suggestion.last_update_date) * 24 * 60 > l_regeneration_interval)
1856 OR -- MMTT line staled
1857 l_pregen_putaway_tasks_flag <> 1 -- ATF_J5: also treat MMTT lines other than pre-generated as stale. This is to cover what cleanup_partial_putaway used to do
1858 ) -- MMTT was not generated by pregenerate (???)
1859 AND l_mmtt_staled_flag = 'N' THEN
1860 IF (l_pregen_suggestion.backorder_delivery_detail_id IS NULL -- not a backordered line
1861 AND Nvl(l_pregen_suggestion.inspection_status, 2) <> 1) THEN -- not a line that requires inspection i.e. manually pre-gen
1862 l_mmtt_staled_flag := 'Y';
1863 END IF; -- (l_pregen_suggestion.backorder_delivery_detail_id IS NULL)
1864 END IF; -- (Sysdate - l_pregen_suggestion.last_update_date)*24*60
1865 END LOOP;
1866
1867 CLOSE pregen_suggestions_csr;
1868
1869 IF (l_debug = 1) THEN
1870 mydebug(' suggestions_pub: l_crossdock_missmatch_flag = ' || l_crossdock_missmatch_flag);
1871 mydebug(' suggestions_pub: l_task_dispatched_flag = ' || l_task_dispatched_flag);
1872 mydebug(' suggestions_pub: l_op_plan_started_flag = ' || l_op_plan_started_flag);
1873 mydebug(' suggestions_pub: l_mmtt_staled_flag = ' || l_mmtt_staled_flag);
1874 END IF;
1875
1876 IF l_task_dispatched_flag = 'Y' THEN
1877 l_need_to_cleanup_pregen := 'N';
1878 ELSIF l_op_plan_started_flag = 'Y' THEN
1879 l_need_to_cleanup_pregen := 'N';
1880 ELSIF l_mmtt_staled_flag = 'Y' THEN
1881 l_need_to_cleanup_pregen := 'Y';
1882 END IF;
1883
1884 IF (l_debug = 1) THEN
1885 mydebug('suggestions_pub: l_need_to_cleanup_pregen = ' || l_need_to_cleanup_pregen);
1886 END IF;
1887
1888 IF l_need_to_cleanup_pregen = 'Y' OR -- pregenerated MMTT needs cleanup
1889 l_rcount = 0 -- there is no pregenerated MMTT
1890 THEN
1891
1892 IF l_rcount <> 0 THEN -- there are pregenerated MMTT lines, therefore do need to cleanup
1893 IF (l_debug = 1) THEN
1894 mydebug('suggestions_pub: calling cleanup_suggestions (autonomous_transaction) with: ');
1895 mydebug('p_lpn_id = ' || l_lpn_id);
1896 mydebug('p_org_id = ' || p_org_id);
1897 mydebug('p_move_order_line_id = '||p_move_order_line_id);
1898 END IF;
1899
1900
1901 -- Modified the following for bug fix 3866880
1902 -- Decommission the cleanup_suggestions
1903 -- api with autonomous commit, which is conflicting with
1904 -- MMTT and MOL update from inbound UI for item load.
1905 -- The original need for autonomous cleanup_suggestions
1906 -- is satisfied by passing p_for_manual_drop => true
1907 -- into abort_operation_instance .
1908
1909 wms_putaway_suggestions.cleanup_suggestions
1910 (
1911 p_lpn_id => l_lpn_id
1912 , p_org_id => p_org_id
1913 , x_return_status => l_return_status
1914 , x_msg_count => x_msg_count
1915 , x_msg_data => x_msg_data
1916 , p_move_order_line_id => p_move_order_line_id
1917 ); --added for ATF_J2
1918
1919 IF (l_debug = 1) THEN
1920 mydebug(' suggestions_pub: After calling wms_putaway_suggestions.cleanup_suggestions ');
1921 mydebug('x_return_status = ' || l_return_status);
1922 mydebug('x_msg_count = ' || x_msg_count);
1923 mydebug('x_msg_data = ' || x_msg_data);
1924 END IF;
1925
1926 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1927 IF (l_debug = 1) THEN
1928 mydebug(' suggestions_pub: wms_putaway_suggestions.cleanup_suggestions failed');
1929 END IF;
1930
1931 RAISE fnd_api.g_exc_error;
1932 END IF;
1933
1934 END IF; -- IF l_rcount <> 0 THEN
1935
1936 ELSE -- (l_need_to_cleanup_pregen = 'Y')
1937 -- l_make_suggestions := 'N';
1938 NULL;
1939 END IF; -- (l_need_to_cleanup_pregen = 'Y')
1940 END IF; -- (l_lpn_context <> 1)
1941
1942
1943 -- Before creating suggestions
1944 -- verify if MOL and LPN contents match or not
1945 -- Only compare if MOL and LPN content record has the same UOM code, which should always be true
1946
1947
1948 IF l_lpn_context <> 1 OR p_drop_type IS NULL
1949 OR p_drop_type <> 'IIL' THEN
1950 -- Do not check for mismatch for inventory item load
1951 -- because for inventory LPN item load will create move order line
1952 -- on the fly for the loaded quantity, which will not match the quantity in LPN contents.
1953 BEGIN
1954
1955 SELECT 'Y'
1956 INTO l_wlc_mol_missmatch_flag
1957 FROM dual
1958 WHERE exists
1959 (SELECT wlc.inventory_item_id
1960 FROM
1961 (SELECT parent_lpn_id,
1962 SUM(quantity) quantity,
1963 uom_code,
1964 inventory_item_id,
1965 revision,
1966 lot_number,
1967 organization_id--BUG 4607833
1968 FROM
1969 wms_lpn_contents
1970 GROUP BY parent_lpn_id, inventory_item_id, revision, lot_number,uom_code,organization_id--BUG 4607833
1971 ) wlc, -- sub-query is necessary because there could be more than one wlc record for the same inventory_item_id, revision, lot_number
1972 mtl_txn_request_lines mol
1973 WHERE wlc.parent_lpn_id = mol.lpn_id
1974 AND wlc.inventory_item_id = mol.inventory_item_id
1975 -- AND wlc.uom_code = mol.uom_code -- Bug fix 3200526
1976 AND wlc.organization_id = mol.organization_id --Bug 4607833
1977 AND (wlc.revision = mol.revision
1978 OR(wlc.revision IS NULL AND mol.revision IS NULL)
1979 )
1980 AND (wlc.lot_number = mol.lot_number
1981 OR(wlc.lot_number IS NULL AND mol.lot_number IS NULL)
1982 )
1983 AND mol.line_status <> 5 -- not closed
1984 AND mol.lpn_id = l_lpn_id
1985 -- AND mol.line_id = Nvl(p_move_order_line_id, mol.line_id) -- comment out in ATF_J3, we should only check mismatch based on LPN, because in item load pack/unpack happens after receiving TM call
1986 -- Bug fix 3200526 If the MOLs for this LPN have different UOMs,
1987 -- do not consider it mismatch, because we really don't want to call
1988 -- UOM converstion for this pre-cautionary check.
1989 GROUP BY wlc.inventory_item_id, wlc.lot_number, wlc.revision, wlc.uom_code
1990 HAVING MIN(wlc.quantity) <> SUM(mol.quantity-Nvl(mol.quantity_delivered, 0))
1991 AND MIN(mol.UOM_CODE) = MAX(mol.UOM_CODE)
1992 AND wlc.UOM_CODE = MIN(mol.UOM_CODE)
1993 );
1994
1995 EXCEPTION
1996 WHEN OTHERS THEN
1997 l_wlc_mol_missmatch_flag := 'N';
1998 END;
1999
2000 IF l_wlc_mol_missmatch_flag = 'Y' THEN
2001
2002 IF (l_debug = 1) THEN
2003 mydebug('suggestions_pub: There is a mismatch between LPN content and MOL quantity.');
2004 END IF;
2005
2006 -- 13995073 starts
2007
2008 fnd_message.set_name('WMS', 'WMS_MOL_WLC_QTY_MISMATCH');
2009 fnd_msg_pub.add;
2010 RAISE fnd_api.g_exc_error;
2011 END IF; -- IF l_wlc_mol_missmatch_flag = 'Y'
2012 --13995073 ends
2013
2014 END IF; -- IF l_lpn_context <> 1 THEN
2015
2016
2017 -- End ATFJ_2
2018
2019
2020 OPEN molines_csr;
2021
2022 LOOP
2023 FETCH molines_csr INTO l_line_id, l_ref_id, l_txn_source_type_id, l_quantity_detailed, l_quantity
2024 , l_backorder_delivery_detail_id, l_crossdock_type, l_to_sub_code, l_to_loc_id, l_ref_detail_id,
2025 l_inventory_item_id,l_transaction_type_id,l_txn_source_id,l_txn_source_line_id,l_txn_source_line_detail_id; --14176228
2026 EXIT WHEN molines_csr%NOTFOUND;
2027
2028 -- ATF_J2
2029 -- Only need to call crossdock if we cleanup suggestions and
2030 -- create new suggestions.
2031
2032 --{{
2033 -- When move order line is crossdocked but destination sub/loc not stamped
2034 -- need to do check crossdock again.
2035 -- Need to test the case multiple MOL in the same LPN since it is called by MOL here
2036 --}}
2037
2038 IF (l_debug = 1) THEN
2039 mydebug('suggestions_pub: p_move_order_line_id:'||p_move_order_line_id);
2040 END IF;
2041
2042 --BUG 5194761: Do not call crossdock API if this is called from Item Load
2043 --(p_move_order_line_id is NULL), because it would be called from
2044 -- WMSTKILB pre_process_load
2045 IF (p_move_order_line_id IS NULL
2046 AND ((l_cdock_flag = 1 -- WIP, op-xdock enabled, and x-dock not happened
2047 AND p_check_for_crossdock = 'Y'
2048 AND l_lpn_context = 2
2049 AND l_backorder_delivery_detail_id IS NULL)
2050 OR
2051 (l_lpn_context = 3 -- RCV, xdock happened, but staging lane suggestion not successful
2052 AND l_backorder_delivery_detail_id IS NOT NULL
2053 AND (l_to_sub_code IS NULL OR l_to_loc_id IS NULL))
2054 ))
2055 THEN
2056 IF (l_debug = 1) THEN
2057 mydebug('suggestions_pub: Crossdock enabled and check is yes');
2058 END IF;
2059
2060 -- Call the cross dock API
2061 wms_cross_dock_pvt.crossdock(
2062 p_org_id => p_org_id
2063 , p_lpn => l_lpn_id
2064 , x_ret => l_ret_crossdock
2065 , x_return_status => l_return_status
2066 , x_msg_count => l_msg_count
2067 , x_msg_data => l_msg_data
2068 , p_move_order_line_id => l_line_id
2069 ); -- added for ATF_J
2070
2071 IF (l_debug = 1) THEN
2072 mydebug('suggestions_pub: Finished calling crossdock API');
2073 END IF;
2074
2075 -- See if there are any error messages returned from the API
2076 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
2077
2078 IF (l_msg_count = 0) THEN
2079 IF (l_debug = 1) THEN
2080 mydebug('suggestions_pub: Successful');
2081 END IF;
2082 ELSIF(l_msg_count = 1) THEN
2083 IF (l_debug = 1) THEN
2084 mydebug('suggestions_pub: Not Successful');
2085 mydebug('suggestions_pub: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
2086 END IF;
2087 ELSE
2088 IF (l_debug = 1) THEN
2089 mydebug('suggestions_pub: Not Successful2');
2090 END IF;
2091
2092 FOR i IN 1 .. l_msg_count LOOP
2093 l_msg_data := fnd_msg_pub.get(i, 'F');
2094
2095 IF (l_debug = 1) THEN
2096 mydebug('suggestions_pub: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
2097 END IF;
2098 END LOOP;
2099 END IF;
2100
2101 -- Bug# 2744186
2102 -- Check the return status from the API call
2103 -- Throw an exception if the call was not completed successfully
2104 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
2105 IF (l_debug = 1) THEN
2106 mydebug('suggestions_pub: Success returned from WMS_Cross_Dock_Pvt.crossdock API');
2107 END IF;
2108 ELSE
2109 IF (l_debug = 1) THEN
2110 mydebug('suggestions_pub: Failure returned from WMS_Cross_Dock_Pvt.crossdock API');
2111 END IF;
2112
2113 RAISE fnd_api.g_exc_error;
2114 END IF;
2115
2116 -- Check the cross dock return value
2117 IF l_ret_crossdock = 1 THEN
2118 IF (l_debug = 1) THEN
2119 mydebug('suggestions_pub: Nothing to Crossdock');
2120 END IF;
2121 ELSIF l_ret_crossdock = 0 THEN
2122 IF (l_debug = 1) THEN
2123 mydebug('suggestions_pub: CrossDock Succeeded');
2124 END IF;
2125
2126 l_td_crossdock := 'Y';
2127 ELSE
2128 -- DO SOMETHING
2129 l_td_crossdock := 'N';
2130
2131 IF (l_debug = 1) THEN
2132 mydebug('suggestions_pub: CrossDock Error');
2133 END IF;
2134 END IF;
2135
2136 x_crossdock := l_td_crossdock;
2137 ELSE
2138 IF (l_debug = 1) THEN
2139 mydebug('suggestions_pub: Crossdock Not enabled or no check');
2140 END IF;
2141 END IF; -- (l_cdock_flag = 1 AND p_check_for_crossdock = 'Y')
2142 END LOOP;
2143
2144 CLOSE molines_csr;
2145 g_item_qty_tree := Null; -- bug 16082056
2146 OPEN molines_csr;
2147 LOOP
2148 FETCH molines_csr INTO l_line_id, l_ref_id, l_txn_source_type_id, l_quantity_detailed, l_quantity
2149 , l_backorder_delivery_detail_id, l_crossdock_type, l_to_sub_code, l_to_loc_id, l_ref_detail_id,
2150 l_inventory_item_id,l_transaction_type_id,l_txn_source_id,l_txn_source_line_id,l_txn_source_line_detail_id; --14176228
2151 EXIT WHEN molines_csr%NOTFOUND;
2152
2153 IF l_quantity_detailed IS NULL THEN
2154 l_quantity_detailed := 0;
2155 END IF;
2156
2157 IF (l_debug = 1) THEN
2158 mydebug('suggestions_pub: Line ID' || l_line_id);
2159 mydebug('suggestions_pub: l_quantity_detailed' || l_quantity_detailed);
2160 mydebug('suggestions_pub: l_quantity' || l_quantity);
2161 mydebug('suggestions_pub: l_ref_detail_id' || l_ref_detail_id);
2162 END IF;
2163
2164
2165 IF (l_ref_detail_id IS NOT NULL) THEN
2166 BEGIN
2167 UPDATE mtl_txn_request_lines
2168 SET reference_detail_id = NULL
2169 WHERE line_id = l_line_id;
2170 EXCEPTION
2171 WHEN OTHERS THEN
2172 IF (l_debug = 1) THEN
2173 mydebug('suggestions_pub: Error nulling out mtrl.ref_detail_id. SQLERRM:'||SQLERRM);
2174 END IF;
2175 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2176 END;
2177
2178 IF (l_debug = 1) THEN
2179 mydebug('suggestions_pub: Successfully Null out mtrl.ref_detail_id');
2180 END IF;
2181 END IF;
2182
2183 -- ATFJ_2
2184 -- removed l_make_suggestions check.
2185 -- Because it is sufficient to determine if call rules engine or not
2186 -- based on mol.quantity_detailed and mol.quantity
2187
2188 IF NVL(l_quantity_detailed, 0) < NVL(l_quantity, 0) THEN
2189 IF (l_debug = 1) THEN
2190 mydebug('suggestions_pub: Before PPE');
2191 mydebug('suggestions_pub: MOve order line ID ' || l_line_id);
2192 END IF;
2193
2194 IF l_lpn_context = 1 THEN
2195 --bug 14176228
2196 l_item_tree_string := p_org_id||':'||l_inventory_item_id||':'||
2197 Nvl(l_txn_source_type_id,'')||':'||Nvl(l_transaction_type_id,'')||':'||
2198 Nvl(l_txn_source_id,'')||':'||Nvl(l_txn_source_line_id,'')||':'||
2199 Nvl(l_txn_source_line_detail_id,'');
2200 IF (l_debug = 1) THEN
2201 mydebug('suggestions_pub: l_item_tree_string ='||l_item_tree_string);
2202 mydebug('suggestions_pub: g_item_qty_tree ='||g_item_qty_tree);
2203 mydebug('suggestions_pub: p_lpn_id ='||p_lpn_id);
2204 END IF;
2205 IF g_item_qty_tree IS NULL OR l_item_tree_string <> g_item_qty_tree THEN
2206 IF (l_debug = 1) THEN
2207 mydebug('suggestions_pub: Clearing qty. tree Cache');
2208 --call clear qty tree cache for inventory lpns.
2209 END IF;
2210 g_item_qty_tree :=l_item_tree_string;
2211 inv_quantity_tree_pvt.clear_quantity_cache;
2212 -- added per GRAO's request
2213 -- inventory move for rules' engine
2214 END IF;
2215
2216 IF (l_debug = 1) THEN
2217 mydebug('suggestions_pub: Current release is above J. set l_quick_pick_flag to Y');
2218 l_quick_pick_flag := 'Y';
2219 END IF;
2220
2221 END IF;
2222
2223 inv_ppengine_pvt.create_suggestions(
2224 p_api_version => l_api_version_number
2225 , p_init_msg_list => l_init_msg_list
2226 , p_commit => fnd_api.g_false
2227 , p_validation_level => fnd_api.g_valid_level_full
2228 , x_return_status => l_return_status
2229 , x_msg_count => x_msg_count
2230 , x_msg_data => x_msg_data
2231 , p_transaction_temp_id => l_line_id
2232 , p_reservations => l_mtl_reservation
2233 , p_suggest_serial => l_serial_flag
2234 , p_quick_pick_flag => l_quick_pick_flag
2235 );
2236 -- fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
2237
2238 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2239 IF (l_debug = 1) THEN
2240 mydebug('suggestions_pub: unexpected error in inv_ppengine_pvt.create_suggestions');
2241 END IF;
2242
2243 fnd_message.set_name('WMS', 'WMS_ALLOCATE_FAIL');
2244 fnd_msg_pub.ADD;
2245 RAISE fnd_api.g_exc_error;
2246 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
2247 IF (l_debug = 1) THEN
2248 mydebug('suggestions_pub: expected error in inv_ppengine_pvt.create_suggestions');
2249 END IF;
2250
2251 fnd_message.set_name('WMS', 'WMS_ALLOCATE_FAIL');
2252 fnd_msg_pub.ADD;
2253 RAISE fnd_api.g_exc_error;
2254 END IF;
2255
2256 IF (l_debug = 1) THEN
2257 mydebug('suggestions_pub: After calling inv_ppengine_pvt.create_suggestions');
2258 mydebug('suggestions_pub: l_return_status = ' || l_return_status);
2259 END IF;
2260
2261 -- Update Qty detailed in Mtl_txn_request_lines
2262 -- Bug fix 2271470
2263 -- Need to consider quantity_delivered
2264
2265 UPDATE mtl_txn_request_lines mol
2266 SET mol.quantity_detailed = (SELECT NVL(mol.quantity_delivered, 0) + NVL(SUM(mmtt.transaction_quantity), 0)
2267 FROM mtl_material_transactions_temp mmtt
2268 WHERE mmtt.move_order_line_id = l_line_id
2269 AND transaction_action_id NOT IN (50, 51, 52)
2270 AND NOT (transaction_action_id = 2
2271 AND transaction_source_type_id = 13) -- this is to make sure the dummy MMTT erwin created does not contribute this calculation
2272 ),
2273 mol.secondary_quantity_detailed = (SELECT NVL(mol.secondary_quantity_delivered, 0) + NVL(SUM(mmtt.secondary_transaction_quantity), 0)
2274 FROM mtl_material_transactions_temp mmtt
2275 WHERE mmtt.move_order_line_id = l_line_id
2276 AND transaction_action_id NOT IN (50, 51, 52)
2277 AND NOT (transaction_action_id = 2
2278 AND transaction_source_type_id = 13) -- this is to make sure the dummy MMTT erwin created does not contribute this calculation
2279 ) -- Bug# 7716519,Need to update sec_qty_detailed after calling suggestions api
2280
2281 WHERE mol.line_id = l_line_id;
2282
2283 IF (l_debug = 1) THEN
2284 mydebug('suggestions_pub: After UPdate');
2285 END IF;
2286 END IF; -- Nvl(l_quantity_detailed,0) < Nvl(l_quantity,0)
2287
2288 l_num_of_rows := 0;
2289 OPEN suggestions_csr;
2290
2291 LOOP
2292 FETCH suggestions_csr INTO l_transaction_header_id
2293 , l_transaction_temp_id
2294 , l_inventory_item_id
2295 , l_revision
2296 , l_subinventory_code
2297 , l_locator_id
2298 , l_transaction_quantity
2299 , l_transfer_to_location
2300 , l_std_op_id
2301 , l_priority
2302 , l_wms_task_type
2303 , l_operation_plan_id
2304 , l_move_order_line_id;
2305
2306 IF (l_debug = 1) THEN
2307 mydebug('suggestions_pub: Before crs Exit');
2308 END IF;
2309
2310 EXIT WHEN suggestions_csr%NOTFOUND;
2311
2312 IF (l_debug = 1) THEN
2313 mydebug('suggestions_pub: After crs Exit ');
2314 mydebug('suggestions_pub: l_crossdock_type ' || l_crossdock_type);
2315 mydebug('suggestions_pub:l_backorder_delivery_detail_id ' || l_backorder_delivery_detail_id);
2316 END IF;
2317
2318 -- {{
2319 -- removed update WIP related info into MMTT, this should have been take care of by rules engine
2320 -- }}
2321
2322 -- Check mtl statuses
2323 IF (l_debug = 1) THEN
2324 mydebug('suggestions_pub: Checking mtl_status');
2325 END IF;
2326
2327 wms_task_dispatch_put_away.check_mmtt_mtl_status(
2328 p_temp_id => l_transaction_temp_id
2329 , p_org_id => p_org_id
2330 , x_mtl_status => l_mtl_status
2331 , x_return_status => l_return_status
2332 , x_msg_count => l_msg_count
2333 , x_msg_data => l_msg_data
2334 );
2335
2336 IF (l_debug = 1) THEN
2337 mydebug('suggestions_pub: mtl_status = ' || l_mtl_status);
2338 END IF;
2339
2340 IF l_mtl_status = 1 THEN
2341 IF (l_debug = 1) THEN
2342 mydebug('suggestions_pub: Invalid Status');
2343 END IF;
2344
2345 -- Bug# 2743821
2346 -- Commenting out the following rollback statement
2347 -- since the savepoint is never set. Also setting a
2348 -- different error message since the one used initially
2349 -- doesn't seem to be a valid seeded message.
2350 --ROLLBACK TO mtl_stat_chk;
2351 --FND_MESSAGE.SET_NAME('INV', 'INV_INVALID_STATUS');
2352 fnd_message.set_name('WMS', 'WMS_INVALID_LPN_ITEM_STATUS');
2353 fnd_msg_pub.ADD;
2354 RAISE fnd_api.g_exc_error;
2355 END IF;
2356
2357 /* nsinghi - GME-WMS Integration. Added the following select stmt to determine if Process Org.
2358 Also added check in If statement to not refer to Wip_Lpn_Completions table for discrete Orgs.
2359 Also added the If statement to update transaction_source_id in MMTT for Process Orgs. */
2360
2361 SELECT NVL(process_enabled_flag, 'N') INTO l_process_flag
2362 FROM mtl_parameters WHERE organization_id = p_org_id;
2363
2364 -- Update MMTT for WIP
2365 IF (l_txn_source_type_id = 5 AND l_process_flag = 'N') THEN
2366 SELECT completion_transaction_id
2367 , DECODE(wip_entity_type, 4, 'Y', 'N')
2368 , wip_entity_id
2369 INTO l_completion_txn_id
2370 , l_flow_schedule
2371 , l_transaction_source_id
2372 FROM wip_lpn_completions
2373 WHERE header_id = l_ref_id;
2374
2375 UPDATE mtl_material_transactions_temp
2376 SET completion_transaction_id = l_completion_txn_id
2377 , flow_schedule = l_flow_schedule
2378 , transaction_source_id = l_transaction_source_id
2379 WHERE transaction_temp_id = l_transaction_temp_id;
2380 END IF;
2381
2382 /* nsinghi - added the If statement to update transaction_source_id in MMTT for Process Orgs. */
2383 IF (l_txn_source_type_id = 5 AND l_process_flag = 'Y') THEN
2384 SELECT txn_source_id INTO l_transaction_source_id
2385 FROM mtl_txn_request_lines
2386 WHERE line_id = l_line_id;
2387
2388 UPDATE mtl_material_transactions_temp
2389 SET flow_schedule = 'N'
2390 , transaction_source_id = l_transaction_source_id
2391 WHERE transaction_temp_id = l_transaction_temp_id;
2392 END IF;
2393
2394 -- ATF_J:
2395 -- Following two apis,
2396 -- operation_plan_assignment and init_op_plan_instance,
2397 -- are only called if customer is at patchset J or above.
2398 -- Also, only need to call these APIs if current MMTT does not yet have
2399 -- operation_plan_id stamped.
2400
2401 --We should not call the ATF APIs in case of Manual Drop
2402 --Hence adding a check for drop type
2403
2404 IF ( p_drop_type IS NULL OR p_drop_type <> 'MD') THEN
2405 mydebug('suggestions_pub: Current release is above J.');
2406
2407 IF l_operation_plan_id IS NULL
2408 AND l_lpn_context = 3 THEN -- LPN context resides in receiving
2409 mydebug(
2410 ' operation_plan_id is null on MMTT and this is a receiving LPN, assign operation plan and initialize operation plan instance.'
2411 );
2412 --Following API assigns operation plan to an MMTT
2413 mydebug('suggestions_pub: Before calling wms_rule_pvt.assign_operation_plan with following parameters: ');
2414 mydebug('p_task_id = ' || l_transaction_temp_id);
2415 mydebug('p_activity_type_id = ' || 1);
2416 mydebug('p_organization_id = ' || p_org_id);
2417 wms_atf_util_apis.assign_operation_plan(
2418 p_api_version => 1.0
2419 , x_return_status => l_return_status
2420 , x_msg_count => l_msg_count
2421 , x_msg_data => l_msg_data
2422 , p_task_id => l_transaction_temp_id
2423 , p_activity_type_id => 1
2424 , -- Inbound
2425 p_organization_id => p_org_id
2426 );
2427 mydebug('suggestions_pub: After calling wms_rule_pvt.assign_operation_plan');
2428 mydebug('l_return_status = ' || l_return_status);
2429
2430 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
2431 IF (l_debug = 1) THEN
2432 mydebug('suggestions_pub: wms_rule_pvt.assign_operation_plan failed.');
2433 END IF;
2434
2435 RAISE fnd_api.g_exc_error;
2436 END IF; -- (l_return_status <> fnd_api.g_ret_sts_success)
2437
2438 --Following API initializes the operation plan instance
2439
2440 mydebug('suggestions_pub: Before calling wms_op_runtime_pub_apis.init_op_plan_instance with following parameters: ');
2441 mydebug('p_source_task_id = ' || l_transaction_temp_id);
2442 mydebug('p_activity_id = ' || 1);
2443 wms_atf_runtime_pub_apis.init_op_plan_instance(
2444 x_return_status => l_return_status
2445 , x_msg_data => l_msg_data
2446 , x_msg_count => l_msg_count
2447 , x_error_code => l_atf_error_code
2448 , p_source_task_id => l_transaction_temp_id
2449 , p_activity_id => 1 -- Inbound
2450 );
2451 mydebug('suggestions_pub: After calling wms_op_runtime_pub_apis.init_plan_instance');
2452 mydebug('l_return_status = ' || l_return_status);
2453
2454 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
2455 IF (l_debug = 1) THEN
2456 mydebug('suggestions_pub: wms_op_runtime_pub_apis.init_plan_instance failed.');
2457 END IF;
2458
2459 RAISE fnd_api.g_exc_error;
2460 END IF; -- (l_return_status <> fnd_api.g_ret_sts_success)
2461 END IF; -- (l_operation_plan_id IS NULL)
2462 END IF; -- ( p_drop_type IS NULL OR p_drop_type <> 'MD')
2463
2464 -- End ATF_J calling operation_plan_assignment and init_op_plan_instance
2465
2466
2467 -- ATF_J
2468 -- By pass inserting into WMS_DISPATCHED_TASKS
2469 -- if customer is at patchset J or above,
2470 -- because this will be handled by activate_operation_instance.
2471 -- In other words, only insert WMS_DISPATCHED_TASKS if
2472 -- customer release is below patchset J
2473
2474 -- We should not insert record directly into WDT if the drop type is Manual Drop.
2475 -- Since ATF API activate op instance will be called from complete_putaway_wrapper in this case.
2476
2477
2478 l_num_of_rows := l_num_of_rows + 1;
2479
2480 --inv_debug.message('number of rows = ' || l_num_of_rows);
2481
2482 IF l_transaction_quantity < 0 THEN
2483 UPDATE mtl_material_transactions_temp
2484 SET transaction_quantity = ABS(transaction_quantity)
2485 , primary_quantity = ABS(primary_quantity)
2486 WHERE transaction_temp_id = l_transaction_temp_id;
2487 END IF;
2488 END LOOP; -- Detail loop
2489
2490 CLOSE suggestions_csr;
2491
2492 END LOOP; -- MO Lines loop
2493
2494 CLOSE molines_csr;
2495
2496 -- set output variables
2497 -- Get total number of rows detailed
2498 SELECT COUNT(t.transaction_temp_id)
2499 INTO l_rows_detailed
2500 FROM mtl_material_transactions_temp t, mtl_txn_request_lines l
2501 WHERE l.lpn_id = l_lpn_id
2502 AND l.organization_id = p_org_id
2503 AND l.line_id = NVL(p_move_order_line_id, l.line_id) -- Added for ATF_J
2504 AND l.line_id = t.move_order_line_id;
2505
2506 x_number_of_rows := l_rows_detailed;
2507 x_crossdock := l_td_crossdock;
2508 x_return_status := fnd_api.g_ret_sts_success;
2509
2510 -- Fix for Bug 2374961
2511 -- For an Inventory LPN, the rules engine creates a lock
2512 -- at the item org level as part of the detailing
2513 -- Since no commit was being done till the user actually confirmed
2514 -- the drop, the lock was being maintained for an inordinate
2515 -- amount of time, preventing other users from putting away
2516 -- the same item even if it is on a different LPn because of the
2517 -- fact that the rules engine cannot obtain a new lock unless
2518 -- the old one has been released. Hence, for an inventory LPN
2519 -- , have added a commit statement. If the user then changes his
2520 -- mind and presses F2 from the Putaway page, the
2521 -- cleanup_partial_putaway_LPN API is called which deletes
2522 -- the MMTT and MOL lines manually
2523
2524 --Nested LPN Support - Do the commit only if the flag is set.
2525 IF (l_lpn_context = 1 AND l_rows_detailed > 0) THEN
2526 IF (NVL(p_commit, 'Y') = 'Y') THEN
2527 COMMIT;
2528 END IF;
2529 END IF;
2530 EXCEPTION
2531 WHEN fnd_api.g_exc_error THEN
2532 -- Bug# 2744186
2533 -- Perform a rollback in the exception blocks
2534 ROLLBACK TO suggestions_pub_sp;
2535 x_return_status := fnd_api.g_ret_sts_error;
2536 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2537
2538 IF (l_debug = 1) THEN
2539 mydebug('suggestions_pub: Excecution error - ' || SQLERRM);
2540 END IF;
2541
2542 IF pregen_suggestions_csr%ISOPEN THEN
2543 CLOSE pregen_suggestions_csr;
2544 END IF;
2545
2546 IF molines_csr%ISOPEN THEN
2547 CLOSE molines_csr;
2548 END IF;
2549
2550 IF lpn_csr%ISOPEN THEN
2551 CLOSE lpn_csr;
2552 END IF;
2553
2554 IF suggestions_csr%ISOPEN THEN
2555 CLOSE suggestions_csr;
2556 END IF;
2557 WHEN fnd_api.g_exc_unexpected_error THEN
2558 ROLLBACK TO suggestions_pub_sp;
2559 x_return_status := fnd_api.g_ret_sts_unexp_error;
2560 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2561
2562 IF (l_debug = 1) THEN
2563 mydebug('suggestions_pub: Unexpected error - ' || SQLERRM);
2564 END IF;
2565
2566 IF pregen_suggestions_csr%ISOPEN THEN
2567 CLOSE pregen_suggestions_csr;
2568 END IF;
2569
2570 IF molines_csr%ISOPEN THEN
2571 CLOSE molines_csr;
2572 END IF;
2573
2574 IF lpn_csr%ISOPEN THEN
2575 CLOSE lpn_csr;
2576 END IF;
2577
2578 IF suggestions_csr%ISOPEN THEN
2579 CLOSE suggestions_csr;
2580 END IF;
2581 WHEN OTHERS THEN
2582 ROLLBACK TO suggestions_pub_sp;
2583 x_return_status := fnd_api.g_ret_sts_unexp_error;
2584 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2585
2586 IF (l_debug = 1) THEN
2587 mydebug('suggestions_pub: Others exception - ' || SQLERRM);
2588 END IF;
2589
2590 IF pregen_suggestions_csr%ISOPEN THEN
2591 CLOSE pregen_suggestions_csr;
2592 END IF;
2593
2594 IF molines_csr%ISOPEN THEN
2595 CLOSE molines_csr;
2596 END IF;
2597
2598 IF lpn_csr%ISOPEN THEN
2599 CLOSE lpn_csr;
2600 END IF;
2601
2602 IF suggestions_csr%ISOPEN THEN
2603 CLOSE suggestions_csr;
2604 END IF;
2605 END suggestions_pub;
2606
2607 /* Local function to insert record in MTL_SERIAL_NUMBERS_TEMP given
2608 * a record type containing the information of one serial number (including
2609 * attributes). This procedure is called from complete_putaway to create
2610 * as many MSNT records for the serial numbers within the LPN for the quantity
2611 * confirmed
2612 */
2613 FUNCTION insert_msnt_rec(
2614 p_transaction_temp_id IN NUMBER
2615 , p_serial_number IN VARCHAR2
2616 , p_serial_atts IN msn_attribute_rec_tp
2617 , p_user_id IN NUMBER
2618 , p_to_serial_number IN VARCHAR2 DEFAULT NULL) RETURN BOOLEAN IS
2619 BEGIN
2620 INSERT INTO mtl_serial_numbers_temp
2621 (
2622 transaction_temp_id
2623 , last_update_date
2624 , last_updated_by
2625 , creation_date
2626 , created_by
2627 , fm_serial_number
2628 , to_serial_number
2629 , vendor_serial_number
2630 , vendor_lot_number
2631 , parent_serial_number
2632 , origination_date
2633 , end_item_unit_number
2634 , territory_code
2635 , time_since_new
2636 , cycles_since_new
2637 , time_since_overhaul
2638 , cycles_since_overhaul
2639 , time_since_repair
2640 , cycles_since_repair
2641 , time_since_visit
2642 , cycles_since_visit
2643 , time_since_mark
2644 , cycles_since_mark
2645 , number_of_repairs
2646 , serial_attribute_category
2647 , c_attribute1
2648 , c_attribute2
2649 , c_attribute3
2650 , c_attribute4
2651 , c_attribute5
2652 , c_attribute6
2653 , c_attribute7
2654 , c_attribute8
2655 , c_attribute9
2656 , c_attribute10
2657 , c_attribute11
2658 , c_attribute12
2659 , c_attribute13
2660 , c_attribute14
2661 , c_attribute15
2662 , c_attribute16
2663 , c_attribute17
2664 , c_attribute18
2665 , c_attribute19
2666 , c_attribute20
2667 , d_attribute1
2668 , d_attribute2
2669 , d_attribute3
2670 , d_attribute4
2671 , d_attribute5
2672 , d_attribute6
2673 , d_attribute7
2674 , d_attribute8
2675 , d_attribute9
2676 , d_attribute10
2677 , n_attribute1
2678 , n_attribute2
2679 , n_attribute3
2680 , n_attribute4
2681 , n_attribute5
2682 , n_attribute6
2683 , n_attribute7
2684 , n_attribute8
2685 , n_attribute9
2686 , n_attribute10
2687 )
2688 VALUES (
2689 p_transaction_temp_id
2690 , SYSDATE
2691 , p_user_id
2692 , SYSDATE
2693 , p_user_id
2694 , p_serial_number
2695 , Nvl(p_to_serial_number,p_serial_number)
2696 , p_serial_atts.vendor_serial_number
2697 , p_serial_atts.vendor_lot_number
2698 , p_serial_atts.parent_serial_number
2699 , p_serial_atts.origination_date
2700 , p_serial_atts.end_item_unit_number
2701 , p_serial_atts.territory_code
2702 , p_serial_atts.time_since_new
2703 , p_serial_atts.cycles_since_new
2704 , p_serial_atts.time_since_overhaul
2705 , p_serial_atts.cycles_since_overhaul
2706 , p_serial_atts.time_since_repair
2707 , p_serial_atts.cycles_since_repair
2708 , p_serial_atts.time_since_visit
2709 , p_serial_atts.cycles_since_visit
2710 , p_serial_atts.time_since_mark
2711 , p_serial_atts.cycles_since_mark
2712 , p_serial_atts.number_of_repairs
2713 , p_serial_atts.serial_attribute_category
2714 , p_serial_atts.c_attribute1
2715 , p_serial_atts.c_attribute2
2716 , p_serial_atts.c_attribute3
2717 , p_serial_atts.c_attribute4
2718 , p_serial_atts.c_attribute5
2719 , p_serial_atts.c_attribute6
2720 , p_serial_atts.c_attribute7
2721 , p_serial_atts.c_attribute8
2722 , p_serial_atts.c_attribute9
2723 , p_serial_atts.c_attribute10
2724 , p_serial_atts.c_attribute11
2725 , p_serial_atts.c_attribute12
2726 , p_serial_atts.c_attribute13
2727 , p_serial_atts.c_attribute14
2728 , p_serial_atts.c_attribute15
2729 , p_serial_atts.c_attribute16
2730 , p_serial_atts.c_attribute17
2731 , p_serial_atts.c_attribute18
2732 , p_serial_atts.c_attribute19
2733 , p_serial_atts.c_attribute20
2734 , p_serial_atts.d_attribute1
2735 , p_serial_atts.d_attribute2
2736 , p_serial_atts.d_attribute3
2737 , p_serial_atts.d_attribute4
2738 , p_serial_atts.d_attribute5
2739 , p_serial_atts.d_attribute6
2740 , p_serial_atts.d_attribute7
2741 , p_serial_atts.d_attribute8
2742 , p_serial_atts.d_attribute9
2743 , p_serial_atts.d_attribute10
2744 , p_serial_atts.n_attribute1
2745 , p_serial_atts.n_attribute2
2746 , p_serial_atts.n_attribute3
2747 , p_serial_atts.n_attribute4
2748 , p_serial_atts.n_attribute5
2749 , p_serial_atts.n_attribute6
2750 , p_serial_atts.n_attribute7
2751 , p_serial_atts.n_attribute8
2752 , p_serial_atts.n_attribute9
2753 , p_serial_atts.n_attribute10
2754 );
2755 RETURN TRUE;
2756 EXCEPTION
2757 WHEN OTHERS THEN
2758 RETURN FALSE;
2759 END insert_msnt_rec;
2760
2761
2762 /* Local function to insert a record in MTL_TRANSACTION_LOTS_TEMP
2763 * from the original MTLT record. These MTLT records are needed by
2764 * the receiving transaction manager for the deliver transaction
2765 */
2766 FUNCTION insert_dup_mtlt (
2767 p_orig_temp_id IN NUMBER
2768 , p_new_temp_id IN NUMBER
2769 , p_serial_temp_id IN NUMBER
2770 , p_item_id IN NUMBER
2771 , p_organization_id IN NUMBER) RETURN BOOLEAN IS
2772 BEGIN
2773 INSERT INTO mtl_transaction_lots_temp
2774 (
2775 transaction_temp_id
2776 , last_update_date
2777 , last_updated_by
2778 , creation_date
2779 , created_by
2780 , transaction_quantity
2781 , primary_quantity
2782 , lot_number
2783 , lot_expiration_date
2784 , serial_transaction_temp_id
2785 , description
2786 , vendor_name
2787 , supplier_lot_number
2788 , origination_date
2789 , date_code
2790 , grade_code
2791 , change_date
2792 , maturity_date
2793 , retest_date
2794 , age
2795 , item_size
2796 , color
2797 , volume
2798 , volume_uom
2799 , place_of_origin
2800 , best_by_date
2801 , LENGTH
2802 , length_uom
2803 , recycled_content
2804 , thickness
2805 , thickness_uom
2806 , width
2807 , width_uom
2808 , curl_wrinkle_fold
2809 , lot_attribute_category
2810 , c_attribute1
2811 , c_attribute2
2812 , c_attribute3
2813 , c_attribute4
2814 , c_attribute5
2815 , c_attribute6
2816 , c_attribute7
2817 , c_attribute8
2818 , c_attribute9
2819 , c_attribute10
2820 , c_attribute11
2821 , c_attribute12
2822 , c_attribute13
2823 , c_attribute14
2824 , c_attribute15
2825 , c_attribute16
2826 , c_attribute17
2827 , c_attribute18
2828 , c_attribute19
2829 , c_attribute20
2830 , d_attribute1
2831 , d_attribute2
2832 , d_attribute3
2833 , d_attribute4
2834 , d_attribute5
2835 , d_attribute6
2836 , d_attribute7
2837 , d_attribute8
2838 , d_attribute9
2839 , d_attribute10
2840 , n_attribute1
2841 , n_attribute2
2842 , n_attribute3
2843 , n_attribute4
2844 , n_attribute5
2845 , n_attribute6
2846 , n_attribute7
2847 , n_attribute8
2848 , n_attribute9
2849 , n_attribute10
2850 , vendor_id
2851 , territory_code
2852 , attribute_category --Bug#7019043.Added this and following 15 columns
2853 , attribute1
2854 , attribute2
2855 , attribute3
2856 , attribute4
2857 , attribute5
2858 , attribute6
2859 , attribute7
2860 , attribute8
2861 , attribute9
2862 , attribute10
2863 , attribute11
2864 , attribute12
2865 , attribute13
2866 , attribute14
2867 , attribute15
2868 )
2869 (SELECT p_new_temp_id
2870 , mtlt.last_update_date
2871 , mtlt.last_updated_by
2872 , mtlt.creation_date
2873 , mtlt.created_by
2874 , mtlt.transaction_quantity
2875 , mtlt.primary_quantity
2876 , mtlt.lot_number
2877 , mtlt.lot_expiration_date
2878 , p_serial_temp_id
2879 , mln.description
2880 , mln.vendor_name
2881 , mln.supplier_lot_number
2882 , mln.origination_date
2883 , mln.date_code
2884 , mln.grade_code
2885 , mln.change_date
2886 , mln.maturity_date
2887 , mln.retest_date
2888 , mln.age
2889 , mln.item_size
2890 , mln.color
2891 , mln.volume
2892 , mln.volume_uom
2893 , mln.place_of_origin
2894 , mln.best_by_date
2895 , mln.LENGTH
2896 , mln.length_uom
2897 , mln.recycled_content
2898 , mln.thickness
2899 , mln.thickness_uom
2900 , mln.width
2901 , mln.width_uom
2902 , mln.curl_wrinkle_fold
2903 , mln.lot_attribute_category
2904 , mln.c_attribute1
2905 , mln.c_attribute2
2906 , mln.c_attribute3
2907 , mln.c_attribute4
2908 , mln.c_attribute5
2909 , mln.c_attribute6
2910 , mln.c_attribute7
2911 , mln.c_attribute8
2912 , mln.c_attribute9
2913 , mln.c_attribute10
2914 , mln.c_attribute11
2915 , mln.c_attribute12
2916 , mln.c_attribute13
2917 , mln.c_attribute14
2918 , mln.c_attribute15
2919 , mln.c_attribute16
2920 , mln.c_attribute17
2921 , mln.c_attribute18
2922 , mln.c_attribute19
2923 , mln.c_attribute20
2924 , mln.d_attribute1
2925 , mln.d_attribute2
2926 , mln.d_attribute3
2927 , mln.d_attribute4
2928 , mln.d_attribute5
2929 , mln.d_attribute6
2930 , mln.d_attribute7
2931 , mln.d_attribute8
2932 , mln.d_attribute9
2933 , mln.d_attribute10
2934 , mln.n_attribute1
2935 , mln.n_attribute2
2936 , mln.n_attribute3
2937 , mln.n_attribute4
2938 , mln.n_attribute5
2939 , mln.n_attribute6
2940 , mln.n_attribute7
2941 , mln.n_attribute8
2942 , mln.n_attribute9
2943 , mln.n_attribute10
2944 , mln.vendor_id
2945 , mln.territory_code
2946 , mln.attribute_category --Bug#7019043.Added this and the following 15 cols
2947 , mln.attribute1
2948 , mln.attribute2
2949 , mln.attribute3
2950 , mln.attribute4
2951 , mln.attribute5
2952 , mln.attribute6
2953 , mln.attribute7
2954 , mln.attribute8
2955 , mln.attribute9
2956 , mln.attribute10
2957 , mln.attribute11
2958 , mln.attribute12
2959 , mln.attribute13
2960 , mln.attribute14
2961 , mln.attribute15
2962 FROM mtl_transaction_lots_temp mtlt
2963 , mtl_lot_numbers mln
2964 WHERE mtlt.transaction_temp_id = p_orig_temp_id
2965 AND mln.lot_number = mtlt.lot_number
2966 AND mln.inventory_item_id = p_item_id
2967 AND mln.organization_id = p_organization_id);
2968 RETURN TRUE;
2969 EXCEPTION
2970 WHEN OTHERS THEN
2971 RETURN FALSE;
2972 END insert_dup_mtlt;
2973
2974 /* Local function to insert records in MTL_SERIAL_NUMBERS_TEMP
2975 * from the original MSNT record(s). These records are needed by
2976 * the receiving transaction manager for the deliver transaction
2977 */
2978 FUNCTION insert_dup_msnt (
2979 p_orig_temp_id IN NUMBER
2980 , p_new_temp_id IN NUMBER) RETURN BOOLEAN IS
2981 BEGIN
2982 INSERT INTO mtl_serial_numbers_temp
2983 (
2984 transaction_temp_id
2985 , last_update_date
2986 , last_updated_by
2987 , creation_date
2988 , created_by
2989 , fm_serial_number
2990 , to_serial_number
2991 , vendor_serial_number
2992 , vendor_lot_number
2993 , parent_serial_number
2994 , origination_date
2995 , end_item_unit_number
2996 , territory_code
2997 , time_since_new
2998 , cycles_since_new
2999 , time_since_overhaul
3000 , cycles_since_overhaul
3001 , time_since_repair
3002 , cycles_since_repair
3003 , time_since_visit
3004 , cycles_since_visit
3005 , time_since_mark
3006 , cycles_since_mark
3007 , number_of_repairs
3008 , serial_attribute_category
3009 , c_attribute1
3010 , c_attribute2
3011 , c_attribute3
3012 , c_attribute4
3013 , c_attribute5
3014 , c_attribute6
3015 , c_attribute7
3016 , c_attribute8
3017 , c_attribute9
3018 , c_attribute10
3019 , c_attribute11
3020 , c_attribute12
3021 , c_attribute13
3022 , c_attribute14
3023 , c_attribute15
3024 , c_attribute16
3025 , c_attribute17
3026 , c_attribute18
3027 , c_attribute19
3028 , c_attribute20
3029 , d_attribute1
3030 , d_attribute2
3031 , d_attribute3
3032 , d_attribute4
3033 , d_attribute5
3034 , d_attribute6
3035 , d_attribute7
3036 , d_attribute8
3037 , d_attribute9
3038 , d_attribute10
3039 , n_attribute1
3040 , n_attribute2
3041 , n_attribute3
3042 , n_attribute4
3043 , n_attribute5
3044 , n_attribute6
3045 , n_attribute7
3046 , n_attribute8
3047 , n_attribute9
3048 , n_attribute10
3049 )
3050 (SELECT p_new_temp_id
3051 , last_update_date
3052 , last_updated_by
3053 , creation_date
3054 , created_by
3055 , fm_serial_number
3056 , to_serial_number
3057 , vendor_serial_number
3058 , vendor_lot_number
3059 , parent_serial_number
3060 , origination_date
3061 , end_item_unit_number
3062 , territory_code
3063 , time_since_new
3064 , cycles_since_new
3065 , time_since_overhaul
3066 , cycles_since_overhaul
3067 , time_since_repair
3068 , cycles_since_repair
3069 , time_since_visit
3070 , cycles_since_visit
3071 , time_since_mark
3072 , cycles_since_mark
3073 , number_of_repairs
3074 , serial_attribute_category
3075 , c_attribute1
3076 , c_attribute2
3077 , c_attribute3
3078 , c_attribute4
3079 , c_attribute5
3080 , c_attribute6
3081 , c_attribute7
3082 , c_attribute8
3083 , c_attribute9
3084 , c_attribute10
3085 , c_attribute11
3086 , c_attribute12
3087 , c_attribute13
3088 , c_attribute14
3089 , c_attribute15
3090 , c_attribute16
3091 , c_attribute17
3092 , c_attribute18
3093 , c_attribute19
3094 , c_attribute20
3095 , d_attribute1
3096 , d_attribute2
3097 , d_attribute3
3098 , d_attribute4
3099 , d_attribute5
3100 , d_attribute6
3101 , d_attribute7
3102 , d_attribute8
3103 , d_attribute9
3104 , d_attribute10
3105 , n_attribute1
3106 , n_attribute2
3107 , n_attribute3
3108 , n_attribute4
3109 , n_attribute5
3110 , n_attribute6
3111 , n_attribute7
3112 , n_attribute8
3113 , n_attribute9
3114 , n_attribute10
3115 FROM mtl_serial_numbers_temp
3116 WHERE transaction_temp_id = p_orig_temp_id);
3117 RETURN TRUE;
3118 EXCEPTION
3119 WHEN OTHERS THEN
3120 RETURN FALSE;
3121 END insert_dup_msnt;
3122
3123 /* FP-J Lot/Serial Support Enhancement
3124 * Helper routine to create MTL_TRANSACTION_LOTS_INTERFACE records
3125 * for the lot and quantity corresponding to the drop quantity
3126 * Called for a receiving LPN when INV and PO patch levels are J or higher
3127 */
3128 FUNCTION insert_mtli_helper(
3129 p_txn_if_id IN OUT NOCOPY NUMBER
3130 , p_lot_number IN VARCHAR2
3131 , p_txn_qty IN NUMBER
3132 , p_prm_qty IN NUMBER
3133 , p_item_id IN NUMBER
3134 , p_org_id IN NUMBER
3135 , x_serial_temp_id OUT NOCOPY NUMBER
3136 , p_product_txn_id IN OUT NOCOPY NUMBER
3137 , p_temp_id IN NUMBER
3138 , p_secondary_quantity IN NUMBER --OPM Convergence
3139 , p_secondary_uom IN VARCHAR2 --OPM Convergence /* Fix for Bug#9037915. Changed NUMBER to VARCHAR2
3140 ) RETURN BOOLEAN IS
3141 --Local variables
3142 l_lot_status_id NUMBER;
3143 l_txn_if_id NUMBER := p_txn_if_id;
3144 l_product_txn_id NUMBER := p_product_txn_id;
3145 l_expiration_date DATE;
3146 l_prod_code VARCHAR2(5) := inv_rcv_integration_apis.G_PROD_CODE;
3147 l_yes VARCHAR2(1) := inv_rcv_integration_apis.G_YES;
3148 l_no VARCHAR2(1) := inv_rcv_integration_apis.G_NO;
3149 l_false VARCHAR2(1) := inv_rcv_integration_apis.G_FALSE;
3150 l_return_status VARCHAR2(1);
3151 l_msg_count NUMBER;
3152 l_msg_data VARCHAR2(10000);
3153 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3154 BEGIN
3155 --Get the required columns from MLN first
3156 SELECT expiration_date
3157 , status_id
3158 INTO l_expiration_date
3159 , l_lot_status_id
3160 FROM mtl_lot_numbers
3161 WHERE lot_number = p_lot_number
3162 AND inventory_item_id = p_item_id
3163 AND organization_id = p_org_id;
3164
3165 /*
3166 , p_secondary_quantity IN NUMBER DEFAULT NULL--OPM Convergence
3167 , p_origination_type IN NUMBER DEFAULT NULL--OPM Convergence
3168 , p_expiration_action_code IN VARCHAR2 DEFAULT NULL--OPM Convergence
3169 , p_expiration_action_date IN DATE DEFAULT NULL-- OPM Convergence
3170 , p_hold_date IN DATE DEFAULT NULL--OPM Convergence
3171 , p_parent_lot_number IN VARCHAR2 DEFAULT NULL--OPM Convergence
3172 , p_reasond_id IN NUMBER DEFAULT NULL--OPM convergence
3173 ); */
3174 --Call the insert_mtli API
3175 inv_rcv_integration_apis.insert_mtli(
3176 p_api_version => 1.0
3177 , p_init_msg_lst => l_false
3178 , x_return_status => l_return_status
3179 , x_msg_count => l_msg_count
3180 , x_msg_data => l_msg_data
3181 , p_transaction_interface_id => l_txn_if_id
3182 , p_lot_number => p_lot_number
3183 , p_transaction_quantity => p_txn_qty
3184 , p_primary_quantity => p_prm_qty
3185 , p_organization_id => p_org_id
3186 , p_inventory_item_id => p_item_id
3187 , p_expiration_date => l_expiration_date
3188 , p_status_id => l_lot_status_id
3189 , x_serial_transaction_temp_id => x_serial_temp_id
3190 , p_product_transaction_id => l_product_txn_id
3191 , p_product_code => l_prod_code
3192 , p_att_exist => l_yes
3193 , p_update_mln => l_no
3194 , p_secondary_quantity => p_secondary_quantity --OPM Convergence
3195 );
3196
3197 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3198 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
3199 IF (l_debug = 1) THEN
3200 mydebug('insert_mtli_helper: Error occurred while creating interface lots: ' || l_msg_data);
3201 END IF;
3202 RETURN FALSE;
3203 END IF;
3204
3205 RETURN TRUE;
3206
3207 EXCEPTION
3208 WHEN OTHERS THEN
3209 IF (l_debug = 1) THEN
3210 mydebug('Exception occurred in insert_mtli_helper: ');
3211 END IF;
3212 RETURN FALSE;
3213 END insert_mtli_helper;
3214
3215 /* FP-J Lot/Serial Support Enhancement
3216 * Helper routine to create MTL_SERIAL_NUMBERS_INTERFACE records
3217 * for the serials corresponding to the dropped quantity
3218 * Called for a receiving LPN when INV and PO patch levels are J or higher
3219 */
3220 FUNCTION insert_msni_helper(
3221 p_txn_if_id IN OUT NOCOPY NUMBER
3222 , p_serial_number IN VARCHAR2
3223 , p_item_id IN NUMBER
3224 , p_org_id IN NUMBER
3225 , p_product_txn_id IN OUT NOCOPY NUMBER
3226 ) RETURN BOOLEAN IS
3227 --Local variables
3228 l_serial_status_id NUMBER;
3229 l_txn_if_id NUMBER := p_txn_if_id;
3230 l_product_txn_id NUMBER := p_product_txn_id;
3231 l_prod_code VARCHAR2(5) := inv_rcv_integration_apis.G_PROD_CODE;
3232 l_yes VARCHAR2(1) := inv_rcv_integration_apis.G_YES;
3233 l_no VARCHAR2(1) := inv_rcv_integration_apis.G_NO;
3234 l_false VARCHAR2(1) := inv_rcv_integration_apis.G_FALSE;
3235 l_return_status VARCHAR2(1);
3236 l_msg_count NUMBER;
3237 l_msg_data VARCHAR2(10000);
3238 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3239 BEGIN
3240
3241 --Get the serial status
3242 SELECT status_id
3243 INTO l_serial_status_id
3244 FROM mtl_serial_numbers
3245 WHERE serial_number = p_serial_number
3246 AND inventory_item_id = p_item_id;
3247
3248 --Call the insert_msni API
3249 inv_rcv_integration_apis.insert_msni(
3250 p_api_version => 1.0
3251 , p_init_msg_lst => l_false
3252 , x_return_status => l_return_status
3253 , x_msg_count => l_msg_count
3254 , x_msg_data => l_msg_data
3255 , p_transaction_interface_id => l_txn_if_id
3256 , p_fm_serial_number => p_serial_number
3257 , p_to_serial_number => p_serial_number
3258 , p_organization_id => p_org_id
3259 , p_inventory_item_id => p_item_id
3260 , p_status_id => l_serial_status_id
3261 , p_product_transaction_id => l_product_txn_id
3262 , p_product_code => l_prod_code
3263 , p_att_exist => l_yes
3264 , p_update_msn => l_no);
3265
3266 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3267 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
3268 IF (l_debug = 1) THEN
3269 mydebug('insert_msni_helper: Error occurred while creating interface serials: ' || l_msg_data);
3270 END IF;
3271 RETURN FALSE;
3272 END IF;
3273
3274 RETURN TRUE;
3275
3276 EXCEPTION
3277 WHEN OTHERS THEN
3278 IF (l_debug = 1) THEN
3279 mydebug('Exception occurred in insert_msni_helper: ');
3280 END IF;
3281 RETURN FALSE;
3282 END insert_msni_helper;
3283
3284 --3978111 CHANGES START
3285 procedure create_snapshot(p_temp_id NUMBER, p_org_id NUMBER)
3286 IS
3287 l_errNum NUMBER;
3288 l_errCode VARCHAR2(1);
3289 l_errMsg VARCHAR2(241);
3290 l_cst_ret NUMBER(1):=0;
3291 l_primary_cost_method NUMBER;
3292 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3293 BEGIN
3294 select primary_cost_method
3295 into l_primary_cost_method
3296 from mtl_parameters
3297 where organization_id = p_org_id;
3298
3299 IF (l_debug = 1) THEN
3300 mydebug('complete_putaway: cost method of org'||p_org_id||' is '||l_primary_cost_method);
3301 END IF;
3302
3303 IF l_primary_cost_method in (2,5,6) THEN
3304 IF (l_debug = 1) THEN
3305 mydebug('complete_putaway: PRIMARY COST METHOD IS AVG OR FIFO OR LIFO CALLING CSTACOSN.op_snapshot'||p_temp_id);
3306 END IF;
3307
3308 l_cst_ret := CSTACOSN.op_snapshot(i_txn_temp_id => p_temp_id,
3309 err_num => l_errNum,
3310 err_code => l_errCode,
3311 err_msg => l_errMsg);
3312 IF(l_cst_ret <> 1) THEN
3313 fnd_message.set_name('BOM', 'CST_SNAPSHOT_FAILED');
3314 fnd_msg_pub.ADD;
3315 IF (l_debug = 1) THEN
3316 mydebug('complete_putaway: Error from CSTACOSN.op_snapshot ');
3317 END IF;
3318 raise fnd_api.g_exc_unexpected_error;
3319 ELSE
3320 mydebug('complete_putaway: CALL TO CSTACOSN.op_snapshot SUCCESSFULL');
3321 END IF;
3322
3323 END IF;
3324 END create_snapshot;
3325 --3978111 CHANGES END
3326
3327 -- Bug# 2795096
3328 -- Added an extra input parameter called p_commit
3329 -- which will default to 'Y' = Yes.
3330 -- This is needed when we are performing a consolidated drop
3331 -- where complete_putaway is called for each and every MMTT line
3332 -- within the same commit cycle. Previously it would perform a
3333 -- commit at the end of the call to complete_putaway. This doesn't
3334 -- work for consolidated drops since if one of the MMTT lines fails
3335 -- in the call to complete_putaway, we'd like to rollback all of the
3336 -- changes done. Thus we should not call a commit until complete_putaway
3337 -- has been successfully called for every MMTT line.
3338
3339 -- FP-J Lot/Serial Support Enhancement
3340 -- Added a new parameter p_product_transaction_id which stores
3341 -- the product_transaction_id column value in MTLI/MSNI for lots and serials
3342 -- that were created from the putaway drop UI. This value would be populated
3343 -- only if there were a quantity discrepancy in the UI
3344
3345 -- Nested LPN support
3346 -- Added new parameter p_lpn_mode,
3347 -- This will have the following 3 values
3348 -- 1 - Tranfer all contents, including child LPNs
3349 -- 2 - Drop into To another LPN
3350 -- 3 - Item based drop
3351
3352 PROCEDURE complete_putaway(
3353 p_lpn_id IN NUMBER
3354 , p_org_id IN NUMBER
3355 , p_temp_id IN NUMBER
3356 , p_item_id IN NUMBER
3357 , p_rev IN VARCHAR2
3358 , p_lot IN VARCHAR2
3359 , p_loc IN NUMBER
3360 , p_sub IN VARCHAR2
3361 , p_qty IN NUMBER
3362 , p_uom IN VARCHAR2
3363 , p_user_id IN NUMBER
3364 , p_disc IN VARCHAR2
3365 , x_return_status OUT NOCOPY VARCHAR2
3366 , x_msg_count OUT NOCOPY NUMBER
3367 , x_msg_data OUT NOCOPY VARCHAR2
3368 , p_entire_lpn IN VARCHAR2 := 'N'
3369 , p_to_lpn IN VARCHAR2 := fnd_api.g_miss_char
3370 , p_qty_reason_id IN NUMBER
3371 , p_loc_reason_id IN NUMBER
3372 , p_process_serial_flag IN VARCHAR2
3373 , p_commit IN VARCHAR2 := 'Y'
3374 , p_product_transaction_id IN NUMBER
3375 , p_lpn_mode IN NUMBER
3376 , p_new_txn_header_id IN NUMBER
3377 , p_secondary_quantity IN NUMBER --OPM Convergence
3378 , p_secondary_uom IN VARCHAR2 --OPM Convergence
3379 , p_primary_uom IN VARCHAR2
3380 ) IS
3381 l_exist_lpn NUMBER;
3382 l_ref VARCHAR2(240);
3383 l_ref_id NUMBER;
3384 l_ref_type NUMBER;
3385 l_qty NUMBER;
3386 l_lot_code NUMBER;
3387 l_serial_code NUMBER;
3388 l_is_msni_req NUMBER :=0;
3389 l_pr_qty NUMBER;
3390 l_serial VARCHAR2(30);
3391 l_ser_seq NUMBER;
3392 l_org_sub VARCHAR2(30);
3393 l_org_loc NUMBER;
3394 l_lpn_context NUMBER;
3395 l_txn_ret NUMBER := 0;
3396 l_orig_qty NUMBER;
3397 l_txn_header_id NUMBER;
3398 l_orig_txn_header_id NUMBER;
3399 l_to_lpn_id NUMBER;
3400 l_txn_mode NUMBER := 2;
3401 l_del_detail_id NUMBER;
3402 l_orig_txn_uom VARCHAR2(3);
3403 l_dest_loc_id NUMBER;
3404 l_dest_sub VARCHAR2(10);
3405 l_txn_action_id NUMBER;
3406 l_dup_temp_id NUMBER;
3407 l_dup_ser_temp_id NUMBER;
3408 l_dup_ser_temp_id_exist NUMBER;
3409 l_lpn_sub VARCHAR2(30);
3410 l_lpn_loc NUMBER;
3411 l_flow_code NUMBER;
3412 l_transaction_source_type_id NUMBER := 0;
3413 l_inspection_status NUMBER := 1;
3414 l_mo_lpn_id NUMBER := 0;
3415 l_wf NUMBER;
3416 l_wf_process VARCHAR2(80);
3417 l_task_id NUMBER;
3418 l_wip_supply_type NUMBER := NULL;
3419 l_crossdock_type NUMBER := NULL;
3420 cnt NUMBER := NULL;
3421 l_business_flow_code NUMBER := 30; -- default to Inventory Putaway
3422 l_wf_temp_sub VARCHAR2(255);
3423 l_wf_temp_loc NUMBER;
3424 -- following variables added for ATF_J3
3425
3426 l_atf_error_code NUMBER;
3427 l_op_plan_instance_status NUMBER;
3428 l_return_status VARCHAR2(1);
3429 l_msg_data VARCHAR2(2000);
3430 l_msg_count NUMBER;
3431 l_move_order_line_id NUMBER;
3432 l_mmtt_transaction_qty NUMBER;
3433 l_serial_transaction_temp_id NUMBER;
3434 l_txn_type_id NUMBER;--Added bug 3978111
3435 -- End variables added for ATF_J3
3436
3437 l_secondary_uom_code mtl_material_transactions_temp.secondary_uom_code%TYPE;
3438 l_secondary_qty NUMBER;
3439
3440 l_exist_msnt NUMBER:=0 ;--Added for bug 5213359
3441
3442 l_acct_period_id NUMBER:=0; --Added for bug 5403420
3443 l_open_past_period BOOLEAN; --Added for bug 5403420
3444
3445 -- Added for Bug 6356147
3446 l_flow_schedule VARCHAR2(1);
3447
3448 --Bug #2966531 - Fetch serial attributes in addition to serial number
3449 --from MTL_SERIAL_NUMBERS for the LPN item combination
3450 CURSOR ser_csr IS
3451 SELECT serial_number
3452 , serial_number to_serial_number
3453 , vendor_serial_number
3454 , vendor_lot_number
3455 , parent_serial_number
3456 , origination_date
3457 , end_item_unit_number
3458 , territory_code
3459 , time_since_new
3460 , cycles_since_new
3461 , time_since_overhaul
3462 , cycles_since_overhaul
3463 , time_since_repair
3464 , cycles_since_repair
3465 , time_since_visit
3466 , cycles_since_visit
3467 , time_since_mark
3468 , cycles_since_mark
3469 , number_of_repairs
3470 , serial_attribute_category
3471 , c_attribute1
3472 , c_attribute2
3473 , c_attribute3
3474 , c_attribute4
3475 , c_attribute5
3476 , c_attribute6
3477 , c_attribute7
3478 , c_attribute8
3479 , c_attribute9
3480 , c_attribute10
3481 , c_attribute11
3482 , c_attribute12
3483 , c_attribute13
3484 , c_attribute14
3485 , c_attribute15
3486 , c_attribute16
3487 , c_attribute17
3488 , c_attribute18
3489 , c_attribute19
3490 , c_attribute20
3491 , d_attribute1
3492 , d_attribute2
3493 , d_attribute3
3494 , d_attribute4
3495 , d_attribute5
3496 , d_attribute6
3497 , d_attribute7
3498 , d_attribute8
3499 , d_attribute9
3500 , d_attribute10
3501 , n_attribute1
3502 , n_attribute2
3503 , n_attribute3
3504 , n_attribute4
3505 , n_attribute5
3506 , n_attribute6
3507 , n_attribute7
3508 , n_attribute8
3509 , n_attribute9
3510 , n_attribute10
3511 FROM mtl_serial_numbers
3512 WHERE lpn_id = p_lpn_id
3513 AND inventory_item_id = p_item_id
3514 AND NVL(revision, '#%^') = NVL(p_rev, '#%^')
3515 AND NVL(lot_number, -999) = NVL(p_lot, -999)
3516 AND ROWNUM <= l_pr_qty
3517 AND (
3518 (p_entire_lpn = 'Y'
3519 AND(group_mark_id IS NULL
3520 OR group_mark_id = -1))
3521 OR(p_entire_lpn = 'N'
3522 AND group_mark_id = 1)
3523 OR(p_process_serial_flag = 'N'
3524 AND p_entire_lpn = 'N'
3525 AND group_mark_id IS NULL)
3526 )
3527 -- Bug# 2772676
3528 -- For WIP completions, there is a specific serial
3529 -- tied to the MOL/MMTT line which we have to use
3530 AND (
3531 (l_transaction_source_type_id = 5
3532 AND serial_number IN(SELECT fm_serial_number
3533 FROM wip_lpn_completions_serials
3534 WHERE header_id = l_ref_id))
3535 OR l_transaction_source_type_id <> 5
3536 );
3537
3538 transfer_lpn_id NUMBER;
3539 content_lpn_id NUMBER;
3540 lpn_id NUMBER;
3541 temp_count NUMBER;
3542 l_emp_id NUMBER;
3543 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3544
3545 -- ER 7307189 changes start
3546
3547 res_count NUMBER :=0;
3548
3549
3550 CURSOR ser_csr_reserved_lpn
3551 IS
3552 SELECT serial_number ,
3553 serial_number to_serial_number ,
3554 vendor_serial_number ,
3555 vendor_lot_number ,
3556 parent_serial_number ,
3557 origination_date ,
3558 end_item_unit_number ,
3559 territory_code ,
3560 time_since_new ,
3561 cycles_since_new ,
3562 time_since_overhaul ,
3563 cycles_since_overhaul ,
3564 time_since_repair ,
3565 cycles_since_repair ,
3566 time_since_visit ,
3567 cycles_since_visit ,
3568 time_since_mark ,
3569 cycles_since_mark ,
3570 number_of_repairs ,
3571 serial_attribute_category ,
3572 c_attribute1 ,
3573 c_attribute2 ,
3574 c_attribute3 ,
3575 c_attribute4 ,
3576 c_attribute5 ,
3577 c_attribute6 ,
3578 c_attribute7 ,
3579 c_attribute8 ,
3580 c_attribute9 ,
3581 c_attribute10 ,
3582 c_attribute11 ,
3583 c_attribute12 ,
3584 c_attribute13 ,
3585 c_attribute14 ,
3586 c_attribute15 ,
3587 c_attribute16 ,
3588 c_attribute17 ,
3589 c_attribute18 ,
3590 c_attribute19 ,
3591 c_attribute20 ,
3592 d_attribute1 ,
3593 d_attribute2 ,
3594 d_attribute3 ,
3595 d_attribute4 ,
3596 d_attribute5 ,
3597 d_attribute6 ,
3598 d_attribute7 ,
3599 d_attribute8 ,
3600 d_attribute9 ,
3601 d_attribute10 ,
3602 n_attribute1 ,
3603 n_attribute2 ,
3604 n_attribute3 ,
3605 n_attribute4 ,
3606 n_attribute5 ,
3607 n_attribute6 ,
3608 n_attribute7 ,
3609 n_attribute8 ,
3610 n_attribute9 ,
3611 n_attribute10
3612 FROM mtl_serial_numbers
3613 WHERE lpn_id = p_lpn_id
3614 AND inventory_item_id = p_item_id
3615 AND NVL(revision, '#%^') = NVL(p_rev, '#%^')
3616 AND NVL(lot_number, -999) = NVL(p_lot, -999)
3617 AND ROWNUM <= l_pr_qty
3618 AND
3619 (
3620 (
3621 p_entire_lpn = 'Y'
3622 AND
3623 (
3624 group_mark_id IS NULL
3625 OR group_mark_id >= -1
3626 )
3627 )
3628 OR
3629 (
3630 p_entire_lpn = 'N'
3631 AND group_mark_id = 1
3632 )
3633 OR
3634 (
3635 p_process_serial_flag = 'N'
3636 AND p_entire_lpn = 'N'
3637 AND group_mark_id IS NULL
3638 )
3639 )
3640 -- Bug# 2772676
3641 -- For WIP completions, there is a specific serial
3642 -- tied to the MOL/MMTT line which we have to use
3643 AND
3644 (
3645 (
3646 l_transaction_source_type_id = 5
3647 AND serial_number IN
3648 (
3649 SELECT fm_serial_number
3650 FROM wip_lpn_completions_serials
3651 WHERE header_id = l_ref_id
3652 )
3653 )
3654 OR l_transaction_source_type_id <> 5
3655 );
3656 -- ER 7307189 changes end
3657
3658
3659 --Cursors and Variables for FP-J Lot/Serial Support enhancement
3660 CURSOR c_rcv_ser_csr IS
3661 SELECT serial_number
3662 , serial_number to_serial_number
3663 , vendor_serial_number
3664 , vendor_lot_number
3665 , parent_serial_number
3666 , origination_date
3667 , end_item_unit_number
3668 , territory_code
3669 , time_since_new
3670 , cycles_since_new
3671 , time_since_overhaul
3672 , cycles_since_overhaul
3673 , time_since_repair
3674 , cycles_since_repair
3675 , time_since_visit
3676 , cycles_since_visit
3677 , time_since_mark
3678 , cycles_since_mark
3679 , number_of_repairs
3680 , serial_attribute_category
3681 , c_attribute1
3682 , c_attribute2
3683 , c_attribute3
3684 , c_attribute4
3685 , c_attribute5
3686 , c_attribute6
3687 , c_attribute7
3688 , c_attribute8
3689 , c_attribute9
3690 , c_attribute10
3691 , c_attribute11
3692 , c_attribute12
3693 , c_attribute13
3694 , c_attribute14
3695 , c_attribute15
3696 , c_attribute16
3697 , c_attribute17
3698 , c_attribute18
3699 , c_attribute19
3700 , c_attribute20
3701 , d_attribute1
3702 , d_attribute2
3703 , d_attribute3
3704 , d_attribute4
3705 , d_attribute5
3706 , d_attribute6
3707 , d_attribute7
3708 , d_attribute8
3709 , d_attribute9
3710 , d_attribute10
3711 , n_attribute1
3712 , n_attribute2
3713 , n_attribute3
3714 , n_attribute4
3715 , n_attribute5
3716 , n_attribute6
3717 , n_attribute7
3718 , n_attribute8
3719 , n_attribute9
3720 , n_attribute10
3721 FROM mtl_serial_numbers msn
3722 WHERE msn.lpn_id = p_lpn_id
3723 AND msn.inventory_item_id = p_item_id
3724 AND ((p_rev IS NOT NULL AND msn.revision = p_rev)
3725 OR (p_rev IS NULL AND msn.revision IS NULL))
3726 AND ((p_lot IS NOT NULL AND msn.lot_number = p_lot)
3727 OR (p_lot IS NULL AND msn.lot_number IS NULL))
3728 AND ROWNUM <= l_pr_qty
3729 AND (
3730 (p_entire_lpn = 'Y'
3731 AND(msn.group_mark_id IS NULL OR msn.group_mark_id = -1)
3732 )
3733 OR(p_entire_lpn = 'N' AND group_mark_id = 1)
3734 OR(p_process_serial_flag = 'N'
3735 AND p_entire_lpn = 'N'
3736 AND group_mark_id IS NULL)
3737 )
3738 ORDER BY msn.lot_number, msn.serial_number;
3739
3740 --Cursors and Variables for FP-J Lot/Serial Support enhancement
3741 CURSOR c_msni_ser_csr(v_prod_txn_id NUMBER) IS
3742 SELECT fm_serial_number serial_number
3743 , to_serial_number to_serial_number
3744 , vendor_serial_number
3745 , vendor_lot_number
3746 , parent_serial_number
3747 , origination_date
3748 , NULL end_item_unit_number
3749 , territory_code
3750 , time_since_new
3751 , cycles_since_new
3752 , time_since_overhaul
3753 , cycles_since_overhaul
3754 , time_since_repair
3755 , cycles_since_repair
3756 , time_since_visit
3757 , cycles_since_visit
3758 , time_since_mark
3759 , cycles_since_mark
3760 , number_of_repairs
3761 , serial_attribute_category
3762 , c_attribute1
3763 , c_attribute2
3764 , c_attribute3
3765 , c_attribute4
3766 , c_attribute5
3767 , c_attribute6
3768 , c_attribute7
3769 , c_attribute8
3770 , c_attribute9
3771 , c_attribute10
3772 , c_attribute11
3773 , c_attribute12
3774 , c_attribute13
3775 , c_attribute14
3776 , c_attribute15
3777 , c_attribute16
3778 , c_attribute17
3779 , c_attribute18
3780 , c_attribute19
3781 , c_attribute20
3782 , d_attribute1
3783 , d_attribute2
3784 , d_attribute3
3785 , d_attribute4
3786 , d_attribute5
3787 , d_attribute6
3788 , d_attribute7
3789 , d_attribute8
3790 , d_attribute9
3791 , d_attribute10
3792 , n_attribute1
3793 , n_attribute2
3794 , n_attribute3
3795 , n_attribute4
3796 , n_attribute5
3797 , n_attribute6
3798 , n_attribute7
3799 , n_attribute8
3800 , n_attribute9
3801 , n_attribute10
3802 FROM mtl_serial_numbers_interface msni
3803 -- Bug# 3281512 - Performance Fixes
3804 -- Since this cursor is only used for receiving, the product code
3805 -- will always be 'RCV'. This is needed in order to use the index.
3806 WHERE msni.product_code = 'RCV'
3807 AND msni.product_transaction_id = v_prod_txn_id;
3808
3809 l_parent_txn_id NUMBER;
3810 l_mol_lot_number mtl_lot_numbers.lot_number%TYPE;
3811 l_result BOOLEAN := TRUE;
3812 l_serial_rec msn_attribute_rec_tp;
3813 l_operation_plan_id NUMBER;
3814 l_ser_mismatch_count NUMBER;
3815 l_msnt_temp_id NUMBER;
3816 l_product_transaction_id NUMBER;
3817 l_drop_sub_type NUMBER;
3818 l_mo_line_id NUMBER;
3819 l_is_crossdocked BOOLEAN := FALSE;
3820 l_fm_serial VARCHAR2(30);
3821 l_to_serial VARCHAR2(30);
3822
3823 l_cost_group_id NUMBER; -- BUG 4134432
3824 l_mmtt_id NUMBER; -- for DBI wms_exception and wdth link fix in J
3825 l_process_flag VARCHAR2(5); -- nsinghi. Added for GME-WMS Integration
3826 l_xdock_tasks_exists VARCHAR2(1) := 'N'; --9695544
3827 BEGIN
3828 IF (l_debug = 1) THEN
3829 mydebug('complete_putaway: in complete putaway');
3830 END IF;
3831
3832 /*nsinghi GME-WMS Integration Start. Determine if Process Org*/
3833
3834 SELECT NVL(process_enabled_flag, 'N') INTO l_process_flag
3835 FROM mtl_parameters WHERE organization_id = p_org_id;
3836
3837 /*nsinghi GME-WMS Integration End. Determine if Process Org*/
3838
3839 -- Bug# 2744170
3840 -- Set the savepoint
3841 SAVEPOINT complete_putaway_sp;
3842 l_qty := p_qty;
3843 x_return_status := fnd_api.g_ret_sts_success;
3844
3845 IF l_to_lpn_id = 0 THEN
3846 l_to_lpn_id := NULL;
3847 END IF;
3848
3849
3850 IF (l_debug = 1) THEN
3851 mydebug('complete_putaway: complete_putaway API 30');
3852 END IF;
3853
3854 SELECT task_id
3855 INTO l_task_id
3856 FROM wms_dispatched_tasks
3857 WHERE transaction_temp_id = p_temp_id
3858 AND ROWNUM < 2; -- prevent exception
3859 --Bug 2127361 fix
3860
3861 IF (l_debug = 1) THEN
3862 mydebug('complete_putaway: complete_putaway API');
3863 END IF;
3864
3865 SELECT mol.REFERENCE
3866 , mol.reference_type_code
3867 , mol.reference_id
3868 , mol.backorder_delivery_detail_id
3869 , mmtt.subinventory_code
3870 , mmtt.locator_id
3871 , mmtt.transaction_action_id
3872 , mmtt.transfer_subinventory
3873 , mmtt.transfer_to_location
3874 , mmtt.transaction_header_id
3875 , mol.transaction_source_type_id
3876 , mol.inspection_status
3877 , mol.lpn_id
3878 , mmtt.transaction_uom
3879 , mmtt.transaction_quantity
3880 , mmtt.wip_supply_type
3881 , mol.crossdock_type
3882 , mol.txn_source_id
3883 , mol.lot_number
3884 , mol.line_id
3885 , mmtt.operation_plan_id
3886 , mmtt.transaction_type_id
3887 , mmtt.secondary_transaction_quantity --OPM Convergence
3888 , mol.to_cost_group_id --BUG 4134432
3889 , mmtt.secondary_uom_code --OPM Convergence
3890
3891 INTO l_ref
3892 , l_ref_type
3893 , l_ref_id
3894 , l_del_detail_id
3895 , l_org_sub
3896 , l_org_loc
3897 , l_txn_action_id
3898 , l_dest_sub
3899 , l_dest_loc_id
3900 , l_orig_txn_header_id
3901 , l_transaction_source_type_id
3902 , l_inspection_status
3903 , l_mo_lpn_id
3904 , l_orig_txn_uom
3905 , l_orig_qty
3906 , l_wip_supply_type
3907 , l_crossdock_type
3908 , l_parent_txn_id
3909 , l_mol_lot_number
3910 , l_mo_line_id
3911 , l_operation_plan_id
3912 , l_txn_type_id
3913 , l_secondary_qty --OPM Convergence
3914
3915 , l_cost_group_id -- BUG 4134432
3916 , l_secondary_uom_code --OPM Convergence
3917
3918 FROM mtl_txn_request_lines mol
3919 , mtl_material_transactions_temp mmtt
3920 WHERE mmtt.transaction_temp_id = p_temp_id
3921 AND mmtt.move_order_line_id = mol.line_id;
3922
3923 IF (l_debug = 1) THEN
3924 mydebug('complete_putaway: complete_putaway API 40');
3925 mydebug('l_org_sub ' || l_org_sub || ' l_org_loc ' || l_org_loc);
3926 mydebug('p_sub ' || p_sub || ' p_loc ' || p_loc);
3927 mydebug('l_DEST_sub ' || l_dest_sub || ' l_dest_loc ' || l_dest_loc_id);
3928 mydebug('l_crossdock_type : ' || l_crossdock_type);
3929 mydebug('l_transaction_source_type_id: ' || l_transaction_source_type_id);
3930 mydebug('l_del_detail_id: ' || l_del_detail_id);
3931 mydebug('l_wip_supply_type: ' || l_wip_supply_type);
3932 mydebug('l_parent_txn_id: ' || l_parent_txn_id);
3933 mydebug('l_mol_lot_number: ' || l_mol_lot_number);
3934 mydebug('l_operation_plan_id: ' || l_operation_plan_id);
3935 mydebug('l_secondary_qty ' || l_secondary_qty);
3936 mydebug('l_secondary_uom_code ' || l_secondary_uom_code);
3937 END IF;
3938
3939 -- Bug# 2672785: Populate the emp id instead of user id while logging an exception
3940 -- Bug# 2750060: Catch for no data found exception
3941 BEGIN
3942 SELECT employee_id
3943 INTO l_emp_id
3944 FROM fnd_user
3945 WHERE user_id = p_user_id;
3946 EXCEPTION
3947 WHEN NO_DATA_FOUND THEN
3948 IF (l_debug = 1) THEN
3949 mydebug('complete_putaway: There is no employee tied to the user');
3950 END IF;
3951 l_emp_id := NULL;
3952 END;
3953
3954 /* FP-J Lot/Serial Support Enhancement
3955 * Moved this SQL upward because based on the LPN context, we need
3956 * to open a new cursor for a receiving LPN if INV and PO patch levels
3957 * are J or higher
3958 */
3959 -- Check to see if its a receipt LPN
3960 SELECT lpn_context
3961 INTO l_lpn_context
3962 FROM wms_license_plate_numbers
3963 WHERE lpn_id = p_lpn_id;
3964
3965 IF l_lpn_context = 3 THEN
3966 IF (l_debug =1) THEN
3967 mydebug('RCV LPN: Always generate new txn header id');
3968 END IF;
3969
3970 SELECT mtl_material_transactions_s.NEXTVAL
3971 INTO l_txn_header_id
3972 FROM DUAL;
3973 ELSE
3974 IF (l_debug =1) THEN
3975 mydebug('NON RCV LPN. p_new_txn_header_id: '||p_new_txn_header_id);
3976 END IF;
3977
3978 -- IN case of Resides in Inventroy LPNs use the txn header id generated in wrapper
3979 l_txn_header_id := p_new_txn_header_id;
3980 END IF;
3981
3982 -- ATF_J3
3983 -- Before J, Customer used entering 0 quantity as a workaround to skip a task
3984 -- because they could not specify which item to putaway prior to
3985 -- patchset J.
3986 -- In patchset J, with item based putaway, user should not need to
3987 -- enter 0 quantity to skip a task.
3988
3989 IF l_qty <= 0 THEN
3990 IF (l_debug = 1) THEN
3991 mydebug('complete_putaway: user confirmed 0 qty.');
3992 END IF;
3993
3994 IF (l_debug = 1) THEN
3995 mydebug('complete_putaway: Current release is above J. Disallow 0 quantity.');
3996 END IF;
3997 fnd_message.set_name('INV', 'INV_QTY_MUST_EXCEED_ZERO');
3998 fnd_msg_pub.ADD;
3999
4000 RAISE fnd_api.g_exc_error;
4001 END IF; --IF l_qty <= 0 THEN
4002
4003 IF (l_debug = 1) THEN
4004 mydebug('complete_putaway: complete_putaway API 60');
4005 END IF;
4006
4007 -- Check to see if UOM has been changed. If yes, update MMTT
4008 IF p_uom <> l_orig_txn_uom
4009 AND l_orig_qty = l_qty THEN
4010 IF (l_debug = 1) THEN
4011 mydebug('complete_putaway: Uom has changed - need to update MMTT');
4012 mydebug('complete_putaway: complete_putaway API 70');
4013 END IF;
4014
4015 l_qty := inv_convert.inv_um_convert(
4016 item_id => p_item_id
4017 , PRECISION => NULL
4018 , from_quantity => l_qty
4019 , from_unit => p_uom
4020 , to_unit => l_orig_txn_uom
4021 , from_name => NULL
4022 , to_name => NULL
4023 );
4024
4025 UPDATE mtl_material_transactions_temp
4026 SET transaction_uom = p_uom
4027 , transaction_quantity = l_qty
4028 WHERE transaction_temp_id = p_temp_id;
4029 END IF;
4030
4031 -- Update loc and zone info, if different
4032 IF l_txn_action_id = 2 THEN
4033 -- Subtransfer , putaway of lpn already in inv
4034 l_lpn_sub := l_dest_sub;
4035 l_lpn_loc := l_dest_loc_id;
4036
4037 IF (p_loc <> l_dest_loc_id)
4038 OR(p_sub <> l_dest_sub) THEN
4039 IF (l_debug = 1) THEN
4040 mydebug('complete_putaway: Updating transfer sub and loc');
4041 END IF;
4042
4043 UPDATE mtl_material_transactions_temp
4044 SET transfer_subinventory = p_sub
4045 , transfer_to_location = p_loc
4046 WHERE transaction_temp_id = p_temp_id;
4047 END IF;
4048 ELSE
4049 -- Normal Putaway
4050 l_lpn_sub := l_org_sub;
4051 l_lpn_loc := l_org_loc;
4052
4053 IF (p_loc <> l_org_loc)
4054 OR(p_sub <> l_org_sub) THEN
4055 IF (l_debug = 1) THEN
4056 mydebug('complete_putaway: Updating sub and loc');
4057 END IF;
4058
4059 IF l_lpn_context = 3 THEN
4060
4061 IF (l_debug = 1) THEN
4062 mydebug('complete_putaway: RCV LPN, No updates of sub and loc for receving lpn');
4063 END IF;
4064 ELSE
4065
4066 UPDATE mtl_material_transactions_temp
4067 SET subinventory_code = p_sub
4068 , locator_id = p_loc
4069 WHERE transaction_temp_id = p_temp_id;
4070 END IF; -- END IF l_lpn_context = 3 THEN
4071 END IF; --END IF check txn action
4072 END IF; --END IF check sub/loc discrepancy
4073
4074 -- Check to see if to lpn exists. if not, create it
4075 IF p_to_lpn = fnd_api.g_miss_char
4076 OR p_to_lpn IS NULL
4077 OR p_to_lpn = '' THEN
4078 l_to_lpn_id := NULL;
4079 ELSE
4080 IF (l_debug = 1) THEN
4081 mydebug('complete_putaway: To LPN was passed');
4082 END IF;
4083
4084 l_exist_lpn := 0;
4085
4086 BEGIN
4087 SELECT 1
4088 INTO l_exist_lpn
4089 FROM DUAL
4090 WHERE EXISTS(SELECT 1
4091 FROM wms_license_plate_numbers
4092 WHERE license_plate_number = p_to_lpn
4093 AND organization_id = p_org_id);
4094 EXCEPTION
4095 WHEN NO_DATA_FOUND THEN
4096 l_exist_lpn := 0;
4097 END;
4098
4099 IF (l_exist_lpn = 0) THEN
4100 -- LPN does not exist, create it
4101 -- Call Suresh's Create LPN API
4102 wms_container_pub.create_lpn(
4103 p_api_version => 1.0
4104 , p_init_msg_list => fnd_api.g_false
4105 , p_commit => fnd_api.g_false
4106 , x_return_status => x_return_status
4107 , x_msg_count => x_msg_count
4108 , x_msg_data => x_msg_data
4109 , p_lpn => p_to_lpn
4110 , p_organization_id => p_org_id
4111 , p_container_item_id => NULL
4112 , p_lot_number => NULL
4113 , p_revision => NULL
4114 , p_serial_number => NULL
4115 , p_subinventory => l_lpn_sub
4116 , p_locator_id => l_lpn_loc
4117 , p_source => 1
4118 , p_cost_group_id => NULL
4119 , x_lpn_id => l_to_lpn_id
4120 );
4121 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4122
4123 IF (x_msg_count = 0) THEN
4124 IF (l_debug = 1) THEN
4125 mydebug('complete_putaway: Successful');
4126 END IF;
4127 ELSIF(x_msg_count = 1) THEN
4128 IF (l_debug = 1) THEN
4129 mydebug('complete_putaway: Not Successful');
4130 mydebug('complete_putaway: ' || REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
4131 END IF;
4132 ELSE
4133 IF (l_debug = 1) THEN
4134 mydebug('complete_putaway: Not Successful2');
4135 END IF;
4136
4137 FOR i IN 1 .. x_msg_count LOOP
4138 x_msg_data := fnd_msg_pub.get(i, 'F');
4139
4140 IF (l_debug = 1) THEN
4141 mydebug('complete_putaway: ' || REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
4142 END IF;
4143 END LOOP;
4144 END IF;
4145
4146 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4147 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
4148 fnd_msg_pub.ADD;
4149 RAISE fnd_api.g_exc_unexpected_error;
4150 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4151 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
4152 fnd_msg_pub.ADD;
4153 RAISE fnd_api.g_exc_error;
4154 END IF;
4155 ELSE
4156 -- LPN exists. Get LPN ID
4157 SELECT lpn_id
4158 INTO l_to_lpn_id
4159 FROM wms_license_plate_numbers
4160 WHERE license_plate_number = p_to_lpn
4161 AND organization_id = p_org_id;
4162 END IF;
4163 END IF;
4164
4165 IF (l_debug = 1) THEN
4166 mydebug('complete_putaway: After LPN creation');
4167 END IF;
4168
4169 SELECT lot_control_code
4170 , serial_number_control_code
4171 INTO l_lot_code
4172 , l_serial_code
4173 FROM mtl_system_items
4174 WHERE organization_id = p_org_id
4175 AND inventory_item_id = p_item_id;
4176
4177
4178 -- Bug 3405320
4179 -- If serial_code is 6 then check if serials exists for that item
4180 -- inside the LPN
4181 --4049874
4182 IF l_serial_code = 6 THEN
4183 SELECT count(1)
4184 INTO l_is_msni_req
4185 FROM mtl_serial_numbers
4186 WHERE inventory_item_id = p_item_id
4187 AND lpn_id = p_lpn_id
4188 AND current_status = 7
4189 AND current_organization_id = p_org_id;
4190 END IF;
4191
4192 --If the line is crossdocked to a sales order or WIP job, set the flag
4193 IF (l_del_detail_id IS NOT NULL) THEN
4194 l_is_crossdocked := TRUE;
4195 ELSE
4196 l_is_crossdocked := FALSE;
4197 END IF;
4198
4199 -- Do Lot and serial stuff only if there was no discrepancy
4200 IF (p_disc = 'N') THEN
4201 -- Calculate Primary Quantity
4202 l_pr_qty := wms_task_dispatch_gen.get_primary_quantity(
4203 p_item_id => p_item_id
4204 , p_organization_id => p_org_id
4205 , p_from_quantity => l_orig_qty
4206 , p_from_unit => l_orig_txn_uom); --Bug 5225012. Passing correct UOM
4207 --Earlier p_uom was being passed.
4208
4209 IF (l_debug = 1) THEN
4210 mydebug('complete_putaway: primary qty: ' || l_pr_qty);
4211 END IF;
4212
4213 IF l_lot_code > 1 THEN
4214 IF (l_debug = 1) THEN
4215 mydebug('complete_putaway: Inserting Lots');
4216 END IF;
4217
4218 l_ser_seq := NULL;
4219
4220 -- Bug 2458540
4221 -- IF l_serial_code>1 AND l_serial_code<>6 THEN
4222 --4049874
4223 IF ((l_serial_code > 1 AND l_serial_code <> 6)
4224 OR(l_serial_code = 6 AND
4225 (l_ref = 'ORDER_LINE_ID'
4226 OR l_ref = 'SHIPMENT_LINE_ID'
4227 )
4228 )
4229 ) THEN
4230 /* bug12607020 */
4231 -- Need to get the next value for serial temp id
4232 IF (l_lpn_context in (1,2)) THEN
4233 select serial_transaction_temp_id INTO l_ser_seq FROM mtl_transaction_lots_temp
4234 WHERE transaction_temp_id = p_temp_id
4235 AND lot_number = p_lot;
4236 END IF;
4237 -- Need to get the next value for serial temp id
4238 IF l_ser_seq IS NULL THEN
4239 SELECT mtl_material_transactions_s.NEXTVAL
4240 INTO l_ser_seq
4241 FROM DUAL;
4242 END IF;
4243 /* bug12607020 */
4244
4245 IF (l_debug = 1) THEN
4246 mydebug('complete_putaway: Lot and serial controlled item: ' || l_ser_seq);
4247 END IF;
4248 END IF;
4249
4250 /* FP-J Lot/Serial Support Enhancement
4251 * Do not update MTL_TRANSACTION_LOTS_TEMP from here if the LPN Resides in
4252 * Receiving and WMS and PO patch levels are J or higher
4253 * For other LPN contexts and if patch levels are lower than J,
4254 * continue with the updates
4255 */
4256 IF (l_lpn_context = 3) THEN
4257 IF (l_is_crossdocked = FALSE) THEN
4258 IF l_debug = 1 THEN
4259 mydebug('complete_putaway: LPN Resides in Receiving. No updates to MTLT from here.');
4260 END IF;
4261 ELSE
4262 UPDATE mtl_transaction_lots_temp
4263 SET serial_transaction_temp_id = l_ser_seq
4264 , last_update_date = SYSDATE
4265 , last_updated_by = p_user_id
4266 WHERE transaction_temp_id = p_temp_id
4267 AND lot_number = p_lot;
4268 END IF;
4269
4270 --INV/WIP LPN
4271 ELSE
4272 IF l_debug = 1 THEN
4273 mydebug('complete_putaway: INV/WIP LPN. Update MTLT.');
4274 END IF;
4275
4276 UPDATE mtl_transaction_lots_temp
4277 SET transaction_quantity = l_orig_qty
4278 , primary_quantity = l_pr_qty
4279 , serial_transaction_temp_id = l_ser_seq
4280 , last_update_date = SYSDATE
4281 , last_updated_by = p_user_id
4282 WHERE transaction_temp_id = p_temp_id
4283 AND lot_number = p_lot;
4284 END IF;
4285
4286 -- Capture lot info for WIP transactions
4287
4288 /* nsinghi - GME-WMS Integration. Added additional check for l_process_flag.
4289 Update Lot attrs from wip_lpn_completions_lots table only for discrete orgs. */
4290
4291 IF (l_transaction_source_type_id = 5 AND l_process_flag = 'N') THEN
4292 IF (l_debug = 1) THEN
4293 mydebug('complete_putaway: Capture lot atts from wip tables');
4294 mydebug('p_ref_id: ==> ' || l_ref_id);
4295 mydebug('p_temp_id: => ' || p_temp_id);
4296 mydebug('p_lot: =====> ' || p_lot);
4297 END IF;
4298
4299 wms_wip_integration.capture_lot_atts(
4300 p_ref_id => l_ref_id,
4301 p_temp_id => p_temp_id,
4302 p_lot => p_lot);
4303
4304 --Start Bug 6356147
4305 -- Update MMTT for WIP flow completions
4306 SELECT DECODE(wip_entity_type, 4, 'Y', 'N')
4307 INTO l_flow_schedule
4308 FROM wip_lpn_completions
4309 WHERE header_id = l_ref_id;
4310
4311 IF (l_debug = 1) THEN
4312 mydebug('l_flow_schedule => ' || l_flow_schedule);
4313 END IF;
4314
4315 UPDATE mtl_material_transactions_temp
4316 SET flow_schedule = l_flow_schedule
4317 WHERE transaction_temp_id = p_temp_id;
4318 --End Bug 6356147
4319 ELSE
4320 /*
4321 * If the item is lot controlled, we do not need temp records for
4322 * processing but the interface records MTLI. So we can create the
4323 * MTLI record here for this quantity
4324 */
4325 IF (l_lpn_context = 3) THEN
4326 --14180163
4327 l_product_transaction_id := p_product_transaction_id;
4328 IF (l_debug = 1) THEN
4329 mydebug('complete_putaway: p_product_transaction_id: inside lot_serial' || l_product_transaction_id);
4330 END IF;
4331
4332 IF l_product_transaction_id IS NULL THEN
4333 SELECT rcv_transactions_interface_s.NEXTVAL
4334 INTO l_product_transaction_id
4335 FROM sys.dual;
4336 END IF;
4337
4338 l_result := TRUE;
4339
4340 --Call the helper routine to create the MTLI record
4341 l_result := insert_mtli_helper(
4342 p_txn_if_id => l_dup_temp_id
4343 , p_lot_number => p_lot
4344 , p_txn_qty => p_qty --Bug 5225012. Earlier l_orig_qty was being passed
4345 , p_prm_qty => l_pr_qty
4346 , p_item_id => p_item_id
4347 , p_org_id => p_org_id
4348 , x_serial_temp_id => l_dup_ser_temp_id
4349 , p_product_txn_id => l_product_transaction_id
4350 , p_temp_id => p_temp_id
4351 , p_secondary_quantity => p_secondary_quantity --OPM Convergence
4352 , p_secondary_uom => p_secondary_uom); --OPM Convergence
4353 IF NOT l_result THEN
4354 IF (l_debug = 1) THEN
4355 mydebug('complete_putaway: Failure while Inserting MSNI records - lot and serial controlled item');
4356 END IF;
4357 RAISE fnd_api.g_exc_unexpected_error;
4358 END IF; --END IF check l_result
4359
4360 IF (l_debug = 1) THEN
4361 mydebug('complete_putaway: Inserted MTLI for lot and serial item. intf_txn_id: ' || l_dup_temp_id ||
4362 ', ser_temp_id : ' || l_dup_ser_temp_id || ' , prod_txn_id: ' || l_product_transaction_id);
4363 END IF;
4364 END IF; --END IF (l_lpn_context = 3) THEN
4365 END IF; --END IF l_transaction_source_type_id = 5
4366
4367 IF (l_debug = 1) THEN
4368 mydebug('complete_putaway: SNCODE:' || l_serial_code);
4369 END IF;
4370
4371 -- Bug 2458540
4372 -- IF l_serial_code>1 AND l_serial_code<>6 THEN
4373 --4049874 : removed the l_wms_po_j_or_higher check
4374 IF ((l_serial_code > 1 AND l_serial_code <> 6)
4375 OR (l_serial_code = 6 AND l_ref = 'ORDER_LINE_ID')
4376 OR (l_serial_code = 6 AND l_ref = 'SHIPMENT_LINE_ID'
4377 AND l_is_msni_req > 0
4378 )
4379 ) THEN
4380 IF (l_debug = 1) THEN
4381 mydebug('complete_putaway: Inserting Serials');
4382 END IF;
4383
4384 -- ER 7307189 changes start
4385
4386 SELECT COUNT(msn.group_mark_id)
4387 INTO res_count
4388 FROM mtl_serial_numbers msn ,
4389 mtl_reservations mr
4390 WHERE mr.lpn_id =msn.lpn_id
4391 AND msn.group_mark_id=mr.reservation_id
4392 AND msn.lpn_id = p_lpn_id;
4393
4394 mydebug(' complete_putaway : res_count value ' || res_count);
4395
4396 -- ER 7307189 changes end
4397 /*
4398 * If the MOL LPN context is "RESIDES IN RECEIVING" and INV and PO Patch
4399 * levels are J or higher, then open the cursor c_rcv_ser_csr that
4400 * fetches the serial by matches the serials in rcv_serials_supply for
4401 * the parent transaction.
4402 * If either of these is not true, then open the original cursor
4403 */
4404 IF (l_lpn_context = 3) THEN
4405 OPEN c_rcv_ser_csr;
4406 ELSE
4407 -- ER 7307189 changes start
4408 IF ( res_count > 0 ) THEN
4409 OPEN ser_csr_reserved_lpn;
4410 ELSE
4411 OPEN ser_csr;
4412 END IF;
4413 -- ER 7307189 changes end
4414 END IF;
4415
4416 LOOP
4417 IF (l_lpn_context = 3) THEN
4418 FETCH c_rcv_ser_csr INTO l_serial_rec;
4419 EXIT WHEN c_rcv_ser_csr%NOTFOUND;
4420 ELSE
4421 -- ER 7307189 changes start
4422 IF ( res_count > 0 ) THEN
4423 FETCH ser_csr_reserved_lpn INTO l_serial_rec;
4424 EXIT WHEN ser_csr_reserved_lpn%NOTFOUND;
4425 ELSE
4426 FETCH ser_csr INTO l_serial_rec;
4427 EXIT WHEN ser_csr%NOTFOUND;
4428 END IF;
4429 -- ER 7307189 changes end
4430
4431 END IF;
4432
4433 l_serial := l_serial_rec.serial_number;
4434
4435 IF (l_debug = 1) THEN
4436 mydebug('complete_putaway: SN:' || l_serial);
4437 END IF;
4438
4439 --Since we would not be exploding the content LPN in the inventory TM
4440 --we have to create the MSNT records from here for the TM to process
4441 --This is applicable for putaway of an entire INV/WIP LPN when
4442 --WMS and PO J are installed
4443 IF ( (p_entire_lpn = 'N') OR
4444 (l_txn_action_id IN(27, 12)) OR
4445 (p_entire_lpn = 'Y' AND l_lpn_context IN (1,2))
4446 ) THEN
4447 -- Capture serial info for WIP transactions
4448 /* nsinghi - GME-WMS Integration. Added additional check for l_process_flag.
4449 Update Serial attrs from wip_lpn_completions_serials table only for discrete orgs. */
4450
4451 IF (l_transaction_source_type_id = 5 AND l_process_flag = 'N') THEN
4452 IF (l_debug = 1) THEN
4453 mydebug('complete_putaway: Capture serial atts from wip tables');
4454 mydebug('p_ref_id: ===========> ' || l_ref_id);
4455 mydebug('p_temp_id: ==========> ' || p_temp_id);
4456 mydebug('p_fm_serial_number: => ' || l_serial);
4457 mydebug('p_to_serial_number: => ' || l_serial);
4458 mydebug('p_serial_temp_id: ===> ' || l_ser_seq);
4459 mydebug('p_serial_flag: ======> ' || 2);
4460 END IF;
4461
4462 wms_wip_integration.capture_serial_atts(
4463 p_ref_id => l_ref_id
4464 , p_temp_id => p_temp_id
4465 , p_last_update_date => SYSDATE
4466 , p_last_updated_by => p_user_id
4467 , p_creation_date => SYSDATE
4468 , p_created_by => p_user_id
4469 , p_fm_serial_number => l_serial
4470 , p_to_serial_number => l_serial
4471 , p_serial_temp_id => l_ser_seq
4472 , p_serial_flag => 2
4473 );
4474 ELSE
4475 l_result := TRUE;
4476 /*
4477 * If INV and PO patch levels are J or higher, we will create
4478 * create one MSNI record for each serial fetched above and
4479 * link it to the MTLI record created above. No Temp records
4480 */
4481 IF (l_lpn_context = 3) THEN
4482 IF (l_debug = 1) THEN
4483 mydebug('complete_putaway: Inserting MSNI - lot and serial item');
4484 END IF;
4485 --Call the helper routine to create the MSNI record
4486 l_result := insert_msni_helper(
4487 p_txn_if_id => l_dup_ser_temp_id
4488 , p_serial_number => l_serial
4489 , p_org_id => p_org_id
4490 , p_item_id => p_item_id
4491 , p_product_txn_id => l_product_transaction_id
4492 );
4493
4494 IF NOT l_result THEN
4495 IF (l_debug = 1) THEN
4496 mydebug('complete_putaway: Failure while Inserting MSNI records - lot and serial controlled item');
4497 END IF;
4498 RAISE fnd_api.g_exc_unexpected_error;
4499 END IF; --END IF check l_result
4500
4501 IF (l_debug = 1) THEN
4502 mydebug('complete_putaway: Inserted MSNI for lot and serial item. intf_txn_id: '
4503 || l_dup_ser_temp_id || ' , prod_txn_id: ' || l_product_transaction_id);
4504 END IF;
4505
4506 --If the line is crossdocked, create MSNT also
4507 IF (l_is_crossdocked) THEN
4508 IF (l_debug = 1) THEN
4509 mydebug('complete_putaway: Inserting MSNT for xdock - lot and serial item' || l_ser_seq);
4510 END IF;
4511 --Create one MSNT record for each serial number returned by
4512 --the cursor
4513 l_result := insert_msnt_rec(
4514 p_transaction_temp_id => l_ser_seq
4515 , p_serial_number => l_serial
4516 , p_serial_atts => l_serial_rec
4517 , p_user_id => p_user_id);
4518
4519 IF NOT l_result THEN
4520 IF (l_debug = 1) THEN
4521 mydebug('complete_putaway: Failure while creating xdock MSNT - lot and serial');
4522 END IF;
4523 RAISE fnd_api.g_exc_unexpected_error;
4524 END IF; --END IF check l_result
4525 END IF; --END IF insert MSNT for xdock
4526
4527 --LPN is not receiving LPN
4528 ELSE
4529 IF (l_debug = 1) THEN
4530 mydebug('complete_putaway: Inserting MSNT - lot and serial item' || l_ser_seq);
4531 END IF;
4532 --Create one MSNT record for each serial number returned by
4533 --the cursor
4534 l_result := insert_msnt_rec(
4535 p_transaction_temp_id => l_ser_seq
4536 , p_serial_number => l_serial
4537 , p_serial_atts => l_serial_rec
4538 , p_user_id => p_user_id);
4539
4540 IF NOT l_result THEN
4541 IF (l_debug = 1) THEN
4542 mydebug('complete_putaway: Failure while MSNT');
4543 END IF;
4544 RAISE fnd_api.g_exc_unexpected_error;
4545 END IF; --END IF check l_result
4546 END IF; --END IF (l_lpn_context = 3) THEN
4547 END IF; --END IF check transaction_source_type = 5clear scr
4548 END IF; --END IF p_entire_lpn = 'N'
4549
4550 /*
4551 * Do not update MTL_SERIAL_NUMBERS from here if the LPN Resides in
4552 * Receiving and WMS and PO patch levels are J or higher
4553 * For other LPN contexts and if patch levels are lower than J,
4554 * continue with the updates
4555 */
4556 IF (l_lpn_context = 3) THEN
4557 IF l_debug = 1 THEN
4558 mydebug('complete_putaway: The LPN resides in Receiving. No updates to MSN from here.');
4559 END IF;
4560 --INV/WIP LPN
4561 ELSE
4562 IF l_debug = 1 THEN
4563 mydebug('complete_putaway: INV/WIP LPN. Update MSN.');
4564 END IF;
4565
4566 -- Update MSN's group_mark_id
4567 UPDATE mtl_serial_numbers
4568 SET group_mark_id = p_temp_id
4569 WHERE serial_number = l_serial
4570 AND inventory_item_id = p_item_id
4571 AND lot_number = p_lot;
4572
4573 -- Bug 2458540
4574 -- Update the Serial Status to 4 before calling Receiving Transaction
4575 -- Processor for RMA serial At SALES ORDER ISSUE STANDARD RECEIPT CASE
4576 IF (l_serial_code = 6 AND l_ref = 'ORDER_LINE_ID') THEN
4577 UPDATE mtl_serial_numbers
4578 SET current_status = 4
4579 , previous_status = current_status
4580 WHERE serial_number = l_serial
4581 AND inventory_item_id = p_item_id
4582 AND lot_number = p_lot;
4583 END IF;
4584 END IF; --END IF (l_lpn_context = 3) T
4585 END LOOP; --END IF loop through serials in lot
4586
4587 IF ser_csr%ISOPEN THEN
4588 CLOSE ser_csr;
4589 END IF;
4590
4591 -- ER 7307189 changes start
4592 IF ser_csr_reserved_lpn%ISOPEN THEN
4593 CLOSE ser_csr_reserved_lpn;
4594 END IF;
4595 -- ER 7307189 changes end
4596
4597 IF c_rcv_ser_csr%ISOPEN THEN
4598 CLOSE c_rcv_ser_csr;
4599 END IF;
4600 END IF; -- End Serial Loop
4601 -- Bug 2458540
4602 -- ELSIF l_serial_code>1 AND l_serial_code<>6 THEN
4603 --not lot controlled
4604 --4049874 : removed the l_wms_po_j_or_higher check
4605 ELSIF((l_serial_code > 1 AND l_serial_code <> 6)
4606 OR ( l_serial_code = 6 AND l_ref = 'ORDER_LINE_ID')
4607 OR ( l_serial_code = 6 AND l_ref = 'SHIPMENT_LINE_ID'
4608 AND l_is_msni_req > 0
4609 )
4610 ) THEN
4611 IF (l_debug = 1) THEN
4612 mydebug('complete_putaway: serial item only');
4613 END IF;
4614
4615 -- ER 7307189 changes start
4616
4617 SELECT COUNT(msn.group_mark_id)
4618 INTO res_count
4619 FROM mtl_serial_numbers msn ,
4620 mtl_reservations mr
4621 WHERE mr.lpn_id =msn.lpn_id
4622 AND msn.group_mark_id=mr.reservation_id
4623 AND msn.lpn_id = p_lpn_id;
4624
4625 mydebug(' complete_putaway : res_count value ' || res_count);
4626
4627 -- ER 7307189 changes end
4628
4629
4630 /* FP-J Lot/Serial Support Enhancement
4631 * If the MOL LPN context is "RESIDES IN RECEIVING" and INV and PO Patch
4632 * levels are J or higher, then open the cursor c_rcv_ser_csr that
4633 * fetches the serial by matches the serials in rcv_serials_supply for
4634 * the parent transaction
4635 * If either of these is not true, then open the original cursor
4636 */
4637 IF (l_lpn_context = 3) THEN
4638 --14180163
4639 l_product_transaction_id := p_product_transaction_id;
4640 IF (l_debug = 1) THEN
4641 mydebug('complete_putaway: p_product_transaction_id: inside serila item ' || l_product_transaction_id);
4642 END IF;
4643
4644 OPEN c_rcv_ser_csr;
4645 ELSE
4646
4647 -- ER 7307189 changes start
4648 IF ( res_count > 0 ) THEN
4649 OPEN ser_csr_reserved_lpn;
4650 ELSE
4651 OPEN ser_csr;
4652 END IF;
4653 -- ER 7307189 changes end
4654
4655 END IF;
4656
4657 LOOP
4658 IF (l_lpn_context = 3) THEN
4659 FETCH c_rcv_ser_csr INTO l_serial_rec;
4660 EXIT WHEN c_rcv_ser_csr%NOTFOUND;
4661 ELSE
4662 -- ER 7307189 changes start
4663 IF ( res_count > 0 ) THEN
4664 FETCH ser_csr_reserved_lpn INTO l_serial_rec;
4665 EXIT WHEN ser_csr_reserved_lpn%NOTFOUND;
4666 ELSE
4667 FETCH ser_csr INTO l_serial_rec;
4668 EXIT WHEN ser_csr%NOTFOUND;
4669 END IF;
4670 -- ER 7307189 changes end
4671 END IF;
4672
4673 l_serial := l_serial_rec.serial_number;
4674
4675 /*IF p_entire_lpn = 'N'
4676 OR l_txn_action_id IN(27, 12) THEN*/
4677
4678 --Since we would not be exploding the content LPN in the inventory TM
4679 --we have to create the MSNT records from here for the TM to process
4680 --This is applicable for putaway of an entire INV/WIP LPN when
4681 --WMS and PO J are installed
4682 IF ( (p_entire_lpn = 'N') OR
4683 (l_txn_action_id IN(27, 12)) OR
4684 (p_entire_lpn = 'Y' AND l_lpn_context IN (1,2))
4685 ) THEN
4686 -- Capture serial info for WIP transactions
4687 IF l_transaction_source_type_id = 5 THEN
4688 IF (l_debug = 1) THEN
4689 mydebug('complete_putaway: Capture serial atts from wip tables');
4690 mydebug('p_ref_id: ===========> ' || l_ref_id);
4691 mydebug('p_temp_id: ==========> ' || p_temp_id);
4692 mydebug('p_fm_serial_number: => ' || l_serial);
4693 mydebug('p_to_serial_number: => ' || l_serial);
4694 mydebug('p_serial_temp_id: ===> ' || p_temp_id);
4695 mydebug('p_serial_flag: ======> ' || 3);
4696 END IF;
4697
4698 wms_wip_integration.capture_serial_atts(
4699 p_ref_id => l_ref_id
4700 , p_temp_id => p_temp_id
4701 , p_last_update_date => SYSDATE
4702 , p_last_updated_by => p_user_id
4703 , p_creation_date => SYSDATE
4704 , p_created_by => p_user_id
4705 , p_fm_serial_number => l_serial
4706 , p_to_serial_number => l_serial
4707 , p_serial_temp_id => p_temp_id
4708 , p_serial_flag => 3
4709 );
4710 ELSE
4711 l_result := TRUE;
4712
4713 /* FP-J Lot/Serial Support Enhancement
4714 * If the LPN Resides in Receiving and WMS and PO patch levels
4715 * are J or higher, we can create one MSNI record for each serial
4716 * fetched from the cursor. No MSNT records needed here
4717 */
4718 IF (l_lpn_context = 3) THEN
4719 IF (l_debug = 1) THEN
4720 mydebug('complete_putaway: Inserting MSNI - serial controlled only' || p_temp_id);
4721 END IF;
4722
4723 IF l_product_transaction_id IS NULL THEN
4724 SELECT rcv_transactions_interface_s.NEXTVAL
4725 INTO l_product_transaction_id
4726 FROM sys.dual;
4727 END IF;
4728
4729 --Call the helper routine to create the MSNI record
4730 l_result := insert_msni_helper(
4731 p_txn_if_id => l_dup_temp_id
4732 , p_serial_number => l_serial
4733 , p_org_id => p_org_id
4734 , p_item_id => p_item_id
4735 , p_product_txn_id => l_product_transaction_id);
4736
4737 IF NOT l_result THEN
4738 IF (l_debug = 1) THEN
4739 mydebug('complete_putaway: Failure while Inserting MSNI records - serial controlled item');
4740 END IF;
4741 RAISE fnd_api.g_exc_unexpected_error;
4742 END IF; --END IF check l_result
4743 IF (l_debug = 1) THEN
4744 mydebug('complete_putaway: Inserting MSNT for xdock - serial item' || l_ser_seq);
4745 END IF;
4746
4747 --If the line croosdocked, create one MSNT record for each serial number returned by the cursor
4748 IF (l_is_crossdocked) THEN
4749 l_result := insert_msnt_rec(
4750 p_transaction_temp_id => p_temp_id
4751 , p_serial_number => l_serial
4752 , p_serial_atts => l_serial_rec
4753 , p_user_id => p_user_id);
4754
4755 IF NOT l_result THEN
4756 IF (l_debug = 1) THEN
4757 mydebug('complete_putaway: Failure while MSNT');
4758 END IF;
4759 RAISE fnd_api.g_exc_unexpected_error;
4760 END IF; --END IF check l_result
4761 END IF; --END IF create MSNT for xdock
4762
4763 --INV/WIP LPN
4764 ELSE
4765 IF (l_debug = 1) THEN
4766 mydebug('complete_putaway: Inserting MSNT - serial controlled only' || p_temp_id);
4767 mydebug('complete_putaway p_temp_id:'|| p_temp_id);
4768 mydebug('complete_putaway l_serial:'|| l_serial);
4769 END IF;
4770
4771 /* Bug 5213359-Added the following check */
4772
4773 SELECT count(transaction_temp_id)
4774 INTO l_exist_msnt
4775 FROM mtl_serial_numbers_temp
4776 WHERE transaction_temp_id = p_temp_id
4777 AND fm_serial_number = l_serial ;
4778
4779 mydebug('complete_putaway In patchset J, checking for msnt l_exist_msnt:'|| l_exist_msnt);
4780
4781 IF l_exist_msnt = 0 THEN
4782 --Create one MSNT record for each serial number returned by the cursor
4783 l_result := insert_msnt_rec(
4784 p_transaction_temp_id => p_temp_id
4785 , p_serial_number => l_serial
4786 , p_serial_atts => l_serial_rec
4787 , p_user_id => p_user_id);
4788 END IF;
4789
4790 /* End of fix for Bug 5213359*/
4791
4792 IF NOT l_result THEN
4793 IF (l_debug = 1) THEN
4794 mydebug('complete_putaway: Failure while Inserting MSNT - serial controlled only');
4795 END IF;
4796 RAISE fnd_api.g_exc_unexpected_error;
4797 END IF; --END IF check l_result
4798 END IF; --END IF (l_lpn_context = 3) THEN
4799 END IF; --END IF l_transaction_source_type_id = 5
4800 END IF; --END IF p_entire_lpn = 'N'
4801
4802 /*
4803 * Do not update MTL_SERIAL_NUMBERS from here if the LPN Resides in
4804 * Receiving and WMS and PO patch levels are J or higher
4805 * For other LPN contexts and if patch levels are lower than J,
4806 * continue with the updates
4807 */
4808 IF (l_lpn_context = 3) THEN
4809 IF l_debug =1 THEN
4810 mydebug('complete_putaway: LPN Resides in Receiving. No updates to MSN from here.');
4811 END IF;
4812 --WMS or PO are lower than J - have to update MSN
4813 ELSE
4814 IF l_debug =1 THEN
4815 mydebug('complete_putaway: INV/WIP LPN. ');
4816 END IF;
4817
4818 -- Update MSN's group_mark_id
4819 UPDATE mtl_serial_numbers
4820 SET group_mark_id = p_temp_id
4821 WHERE serial_number = l_serial
4822 AND inventory_item_id = p_item_id;
4823
4824 -- Bug 2458540
4825 -- Update the Serial Status to 4 before calling Receiving Transaction
4826 -- Processor for RMA serial At SALES ORDER ISSUE STANDARD RECEIPT CASE
4827 IF (l_serial_code = 6 AND l_ref = 'ORDER_LINE_ID') THEN
4828 UPDATE mtl_serial_numbers
4829 SET current_status = 4
4830 , previous_status = current_status
4831 WHERE serial_number = l_serial
4832 AND inventory_item_id = p_item_id;
4833 END IF;
4834 END IF; --END IF (l_lpn_context = 3)
4835 END LOOP;
4836
4837 IF ser_csr%ISOPEN THEN
4838 CLOSE ser_csr;
4839 END IF;
4840 -- ER 7307189 changes start
4841 IF ser_csr_reserved_lpn%ISOPEN THEN
4842 CLOSE ser_csr_reserved_lpn;
4843 END IF;
4844 -- ER 7307189 changes end
4845 IF c_rcv_ser_csr%ISOPEN THEN
4846 CLOSE c_rcv_ser_csr;
4847 END IF;
4848 END IF; -- End Lot Loop
4849 --If there is a quantity discrepancy
4850 ELSIF (p_disc = 'Y') THEN
4851 /*
4852 * If the MOL LPN context is "RESIDES IN RECEIVING" and INV and PO Patch
4853 * levels are J or higher then MSNI records would have been created before
4854 * calling complete_putaway, one per serial number.
4855 * Over here we need to match the serials confirmed in the UI against the
4856 * serials in RCV_SERIALS_SUPPLY for the parent transaction
4857 * Get the parent transaction from the current MOL and check for serials
4858 * that exist in MSNI but not in RCV_SERIALS_SUPPLY. If at least one such
4859 * serial is found, then error out the transaction since match failed
4860 */
4861 IF (l_lpn_context = 3) THEN
4862
4863 --In case of quantity discrepancy, the MTLI/MSNI record would be created
4864 --in the UI itself and we get the product_transaction_id from there
4865 --So, we just need to assign this value to the local variable and subsequently
4866 --pass it the transfer/deliver API for lot/serial splits
4867 l_product_transaction_id := p_product_transaction_id;
4868 --4049874
4869 IF ((l_serial_code > 1 AND l_serial_code <> 6) OR
4870 (l_serial_code = 6 AND (l_ref = 'ORDER_LINE_ID' OR l_ref = 'SHIPMENT_LINE_ID'))) THEN
4871
4872 --If the line is crossdocked then insert the MSNT records for the serials
4873 --that were confirmed in the UI (using product_transaction_id)
4874 IF (l_is_crossdocked) THEN
4875 IF (l_lot_code > 1) THEN
4876 SELECT serial_transaction_temp_id
4877 INTO l_msnt_temp_id
4878 FROM mtl_transaction_lots_interface
4879 WHERE lot_number = p_lot
4880 AND product_transaction_id = l_product_transaction_id;
4881 ELSE
4882 l_msnt_temp_id := p_temp_id;
4883 END IF;
4884
4885 IF (l_debug = 1) THEN
4886 mydebug('complete_putaway: Case when p_disc = Y. l_msnt_temp_id:'||l_msnt_temp_id);
4887 END IF;
4888
4889 OPEN c_msni_ser_csr(l_product_transaction_id);
4890 LOOP
4891 FETCH c_msni_ser_csr INTO l_serial_rec;
4892 EXIT WHEN c_msni_ser_csr%NOTFOUND;
4893 l_fm_serial := l_serial_rec.serial_number;
4894 l_to_serial := l_serial_rec.to_serial_number;
4895 l_result := insert_msnt_rec(
4896 p_transaction_temp_id => l_msnt_temp_id
4897 , p_serial_number => l_fm_serial
4898 , p_serial_atts => l_serial_rec
4899 , p_user_id => p_user_id
4900 , p_to_serial_number => l_to_serial);
4901 IF NOT l_result THEN
4902 IF (l_debug = 1) THEN
4903 mydebug('complete_putaway: Failure while Inserting MSNT - qty disc');
4904 END IF;
4905 IF c_msni_ser_csr%ISOPEN THEN
4906 CLOSE c_msni_ser_csr;
4907 END IF;
4908 RAISE fnd_api.g_exc_unexpected_error;
4909 END IF; --END IF check l_result
4910 END LOOP;
4911 IF c_msni_ser_csr%ISOPEN THEN
4912 CLOSE c_msni_ser_csr;
4913 END IF;
4914 END IF; --END IF line is crossdocked
4915 END IF; --Item is serial controlled
4916 ELSE
4917 --If the LPN is an INV/ WIP LPN and there is a quantity discrepancy,
4918 --for an item that is lot controlled and not serial controlled, then
4919 --update the MTLT record with the user confirmed quantity
4920 --This update statement should be executed if
4921 -- a) WMS and PO Patchset levels are less than J (for LPN contexts)
4922 -- b) If the LPN is an INV/WIP LPN (if patchset levels are > j)
4923 IF ((l_lot_code > 1) AND
4924 (l_serial_code = 1 OR (l_serial_code = 6 AND l_ref <> 'ORDER_LINE_ID'))) THEN
4925 -- Calculate Primary Quantity
4926 l_pr_qty := wms_task_dispatch_gen.get_primary_quantity(
4927 p_item_id => p_item_id
4928 , p_organization_id => p_org_id
4929 , p_from_quantity => l_qty
4930 , p_from_unit => p_uom);
4931
4932 IF (l_debug = 1) THEN
4933 mydebug('complete_putaway: primary qty: ' || l_pr_qty);
4934 END IF;
4935 UPDATE mtl_transaction_lots_temp
4936 SET transaction_quantity = l_qty
4937 , primary_quantity = l_pr_qty
4938 , last_update_date = SYSDATE
4939 , last_updated_by = p_user_id
4940 WHERE transaction_temp_id = p_temp_id
4941 AND lot_number = p_lot;
4942 END IF;
4943 END IF; --END IF check patch levels and LPN context
4944 END IF; -- End disc if
4945
4946 IF (l_debug = 1) THEN
4947 mydebug(
4948 'complete_putaway: :'
4949 || p_org_id
4950 || ':'
4951 || l_ref_id
4952 || ':'
4953 || l_ref
4954 || ':'
4955 || l_ref_type
4956 || ':'
4957 || p_item_id
4958 || ':'
4959 || p_rev
4960 || ':'
4961 || p_sub
4962 || ':'
4963 || p_loc
4964 || ':'
4965 || l_qty
4966 || ':'
4967 || p_uom
4968 || ':'
4969 || p_temp_id
4970 || ':'
4971 || l_lot_code
4972 || ':'
4973 || l_serial_code
4974 );
4975 END IF;
4976
4977 --Bug 3989684 Start
4978 UPDATE mtl_material_transactions_temp
4979 SET transaction_header_id = l_txn_header_id
4980 WHERE transaction_temp_id = p_temp_id;
4981 --Bug 3989684 End
4982
4983 -- Call Amins Log exceptions
4984 IF (p_qty_reason_id > 0) THEN
4985 --Log exception
4986 IF (l_debug = 1) THEN
4987 mydebug('Logging exception for qty discrepancy');
4988 mydebug('txn_header_id: ' || l_txn_header_id);
4989 END IF;
4990
4991
4992 l_mmtt_id := p_temp_id;
4993
4994 wms_txnrsn_actions_pub.log_exception(
4995 p_api_version_number => 1.0
4996 , p_init_msg_lst => fnd_api.g_false
4997 , p_commit => fnd_api.g_false
4998 , x_return_status => x_return_status
4999 , x_msg_count => x_msg_count
5000 , x_msg_data => x_msg_data
5001 , p_organization_id => p_org_id
5002 , p_mmtt_id => l_mmtt_id
5003 , p_task_id => l_txn_header_id
5004 , p_reason_id => p_qty_reason_id
5005 , p_subinventory_code => p_sub
5006 , p_locator_id => p_loc
5007 , p_discrepancy_type => 2
5008 , p_user_id => l_emp_id --p_user_id Bug 2672785
5009 , p_item_id => p_item_id
5010 , p_revision => p_rev
5011 , p_lot_number => p_lot
5012 );
5013
5014 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5015 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5016 fnd_msg_pub.ADD;
5017 RAISE fnd_api.g_exc_unexpected_error;
5018 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5019 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5020 fnd_msg_pub.ADD;
5021 RAISE fnd_api.g_exc_error;
5022 END IF;
5023 END IF;
5024
5025 IF (p_loc_reason_id > 0) THEN
5026 --Log exception
5027 IF (l_debug = 1) THEN
5028 mydebug('Logging exception for loc discrepancy');
5029 mydebug('txn_header_id: ' || l_txn_header_id);
5030 END IF;
5031
5032 l_mmtt_id := p_temp_id;
5033
5034 wms_txnrsn_actions_pub.log_exception(
5035 p_api_version_number => 1.0
5036 , p_init_msg_lst => fnd_api.g_false
5037 , p_commit => fnd_api.g_false
5038 , x_return_status => x_return_status
5039 , x_msg_count => x_msg_count
5040 , x_msg_data => x_msg_data
5041 , p_organization_id => p_org_id
5042 , p_mmtt_id => l_mmtt_id
5043 , p_task_id => l_txn_header_id
5044 , p_reason_id => p_loc_reason_id
5045 , p_subinventory_code => p_sub
5046 , p_locator_id => p_loc
5047 , p_discrepancy_type => 2
5048 , p_user_id => l_emp_id --p_user_id Bug 2672785
5049 , p_item_id => p_item_id
5050 , p_revision => p_rev
5051 , p_lot_number => p_lot
5052 , p_is_loc_desc => TRUE --Changes for Bug 3989684
5053 );
5054
5055 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5056 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5057 fnd_msg_pub.ADD;
5058 RAISE fnd_api.g_exc_unexpected_error;
5059 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5060 fnd_message.set_name('WMS', 'WMS_LOG_EXCEPTION_FAIL');
5061 fnd_msg_pub.ADD;
5062 RAISE fnd_api.g_exc_error;
5063 END IF;
5064 END IF;
5065
5066 --If the LPN context is Resides in Receiving
5067 IF (l_lpn_context = 3) THEN
5068 IF (l_debug = 1) THEN
5069 mydebug('complete_putaway: Rcving LPN..');
5070 mydebug('complete_putaway: Updating mmtt info...');
5071 mydebug('complete_putaway: To LPN' || l_to_lpn_id);
5072 mydebug('complete_putaway: Entire LPN' || p_entire_lpn);
5073 END IF;
5074
5075 IF (p_entire_lpn = 'N') THEN
5076 --Bug 2074100 Fix
5077 IF (l_debug = 1) THEN
5078 mydebug('complete_putaway: not ent lpn');
5079 END IF;
5080
5081 IF ((l_del_detail_id IS NOT NULL)
5082 AND(l_crossdock_type = 2)
5083 AND(l_wip_supply_type = 1)) THEN
5084 IF (l_debug = 1) THEN
5085 mydebug(' This is a crossdocked line for wip issue ');
5086 mydebug(' setting transfer_lpn to null ');
5087 END IF;
5088 --This is Receiving LPN, we have to update header_id as we need
5089 -- one for each txn
5090 --We always will generate new txn header id for a receiving lpn due to the
5091 --problem in join between WDTH and MMT for the deliver transaction
5092 UPDATE mtl_material_transactions_temp
5093 SET transaction_header_id = l_txn_header_id
5094 WHERE transaction_temp_id = p_temp_id;
5095 ELSE
5096 IF (l_debug = 1) THEN
5097 mydebug(' In else for checking wip issue ');
5098 END IF;
5099
5100 IF (l_debug =1 ) THEN
5101 mydebug('Update only transfer LPN ID to NULL');
5102 END IF;
5103
5104 UPDATE mtl_material_transactions_temp
5105 SET transaction_header_id = l_txn_header_id
5106 WHERE transaction_temp_id = p_temp_id;
5107 END IF; --IF ((l_del_detail_id IS NOT NULL) AND(l_crossdock_type = 2) AND(l_wip_supply_type = 1))
5108 ELSE
5109 IF (l_debug = 1) THEN
5110 mydebug('complete_putaway: updating mmtt with content lpn');
5111 END IF;
5112
5113 -- COMMIT;
5114 IF l_debug = 1 THEN
5115 mydebug('Updating content LPN ID for inventory/WIP LPNs ');
5116 END IF;
5117
5118 UPDATE mtl_material_transactions_temp
5119 SET transaction_header_id = l_txn_header_id
5120 WHERE transaction_temp_id = p_temp_id;
5121
5122 IF (l_debug = 1) THEN
5123 mydebug('complete_putaway: after updating mmtt with content lpn');
5124 END IF;
5125 END IF;--END IF (p_entire_lpn = 'N') THEN
5126
5127 -- Have to update WMS_Exceptions so that any exceptions already
5128 -- recorded for this MMTT line will now be updated with the new txn
5129 -- header_id
5130 -- Bug# 3434940 - Performance Fixes
5131 -- Go against the org and item which are input params for
5132 -- complete_putaway since this will make use of the index in
5133 -- WMS_EXCEPTIONS
5134 UPDATE wms_exceptions
5135 SET transaction_header_id = l_txn_header_id
5136 WHERE transaction_header_id = l_orig_txn_header_id
5137 AND organization_id = p_org_id
5138 AND inventory_item_id = p_item_id;
5139
5140 IF (l_debug = 1) THEN
5141 mydebug('complete_putaway : Calling Workflow from complete_putaway');
5142 END IF;
5143
5144 -- Call the workflows
5145
5146 l_wf := 0;
5147
5148 IF (p_qty_reason_id > 0) THEN
5149 BEGIN
5150 SELECT 1
5151 INTO l_wf
5152 FROM mtl_transaction_reasons
5153 WHERE reason_id = p_qty_reason_id
5154 AND workflow_name IS NOT NULL
5155 AND workflow_name <> ' '
5156 AND workflow_process IS NOT NULL
5157 AND workflow_process <> ' ';
5158 EXCEPTION
5159 WHEN NO_DATA_FOUND THEN
5160 l_wf := 0;
5161 END;
5162
5163 IF l_wf > 0 THEN
5164 IF (l_debug = 1) THEN
5165 mydebug(' complete_putaway : WF exists for this reason code: ' || p_qty_reason_id);
5166 mydebug('complete_putaway : Calling workflow wrapper FOR qty');
5167 END IF;
5168
5169 -- Calling Workflow
5170 wms_workflow_wrappers.wf_wrapper(
5171 p_api_version => 1.0
5172 , p_init_msg_list => fnd_api.g_false
5173 , p_commit => fnd_api.g_false
5174 , x_return_status => x_return_status
5175 , x_msg_count => x_msg_count
5176 , x_msg_data => x_msg_data
5177 , p_org_id => p_org_id
5178 , p_rsn_id => p_qty_reason_id
5179 , p_calling_program => 'complete_putaway - for qty discrepancy - loose'
5180 , p_tmp_id => p_temp_id
5181 , p_quantity_picked => l_qty
5182 , p_dest_sub => l_org_sub
5183 , p_dest_loc => l_org_loc
5184 );
5185
5186 IF (l_debug = 1) THEN
5187 mydebug('complete_putaway : After Calling WF Wrapper');
5188 END IF;
5189
5190 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5191 IF (l_debug = 1) THEN
5192 mydebug('complete_putaway : Error callinf WF wrapper');
5193 END IF;
5194
5195 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5196 fnd_msg_pub.ADD;
5197 RAISE fnd_api.g_exc_unexpected_error;
5198 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5199 IF (l_debug = 1) THEN
5200 mydebug('complete_putaway : Error calling WF wrapper');
5201 END IF;
5202
5203 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5204 fnd_msg_pub.ADD;
5205 RAISE fnd_api.g_exc_error;
5206 END IF;
5207 END IF;
5208 END IF;
5209
5210 -- call workflow for location discrepancy
5211 l_wf := 0;
5212
5213 IF (p_loc_reason_id > 0) THEN
5214 -- update MMTT with reason id = p_loc_reason_id. (bugfix 4294713)
5215 update mtl_material_transactions_temp
5216 set reason_id = p_loc_reason_id
5217 where transaction_temp_id = p_temp_id;
5218
5219 BEGIN
5220 SELECT 1,
5221 workflow_process
5222 INTO l_wf,
5223 l_wf_process
5224 FROM mtl_transaction_reasons
5225 WHERE reason_id = p_loc_reason_id
5226 AND workflow_name IS NOT NULL
5227 AND workflow_name <> ' '
5228 AND workflow_process IS NOT NULL
5229 AND workflow_process <> ' ';
5230 EXCEPTION
5231 WHEN NO_DATA_FOUND THEN
5232 l_wf := 0;
5233 l_wf_process := null; --Bugfix 4294713
5234 END;
5235
5236 IF ( ( l_wf_process IS NOT NULL --Bugfix 4294713
5237 AND
5238 l_wf_process <> 'WMS_N_STEP_PUTAWAY'
5239 )
5240 OR
5241 l_operation_plan_id IS NULL
5242 ) THEN
5243 IF l_wf > 0 THEN
5244 IF (l_debug = 1) THEN
5245 mydebug(' complete_putaway : WF exists for this reason code: ' || p_loc_reason_id);
5246 mydebug('complete_putaway : Calling workflow wrapper FOR location');
5247 mydebug('dest sub: ' || p_sub);
5248 mydebug('dest loc: ' || p_loc);
5249 END IF;
5250
5251 -- Calling Workflow
5252 wms_workflow_wrappers.wf_wrapper(
5253 p_api_version => 1.0
5254 , p_init_msg_list => fnd_api.g_false
5255 , p_commit => fnd_api.g_false
5256 , x_return_status => x_return_status
5257 , x_msg_count => x_msg_count
5258 , x_msg_data => x_msg_data
5259 , p_org_id => p_org_id
5260 , p_rsn_id => p_loc_reason_id
5261 , p_calling_program => 'complete_putaway - for loc discrepancy - loose'
5262 , p_tmp_id => p_temp_id
5263 , p_quantity_picked => NULL
5264 , p_dest_sub => l_org_sub
5265 , p_dest_loc => l_org_loc
5266 );
5267
5268 IF (l_debug = 1) THEN
5269 mydebug('complete_putaway : After Calling WF Wrapper');
5270 END IF;
5271
5272 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5273 IF (l_debug = 1) THEN
5274 mydebug('complete_putaway : Error callinf WF wrapper');
5275 END IF;
5276
5277 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5278 fnd_msg_pub.ADD;
5279 RAISE fnd_api.g_exc_unexpected_error;
5280 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5281 IF (l_debug = 1) THEN
5282 mydebug('complete_putaway : Error calling WF wrapper');
5283 END IF;
5284
5285 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5286 fnd_msg_pub.ADD;
5287 RAISE fnd_api.g_exc_error;
5288 END IF;
5289 END IF;--END IF l_wf > 0 THEN
5290 END IF; -- END IF IF (( l_wf_process IS NOT NULL AND l_wf_process <> 'WMS_N_STEP_PUTAWAY') OR l_operation_plan_id IS NULL)
5291 END IF;--IF (p_loc_reason_id > 0) THEN
5292
5293 -- bug 2271470
5294 -- This MMTT record has been putaway by the user,
5295 -- therefore we don't want this record being seen
5296 -- again if user scans the same LPN.
5297 -- Therefore we update wms_task_type column to -1 as a flag
5298 -- signifying this MMTT record should not be
5299 -- shown in the putaway drop page again.
5300 -- In putaway drop page, we make sure those MMTT
5301 -- with wms_task_type of -1 not selected.
5302
5303 UPDATE mtl_material_transactions_temp
5304 SET wms_task_type = -1
5305 WHERE transaction_temp_id = p_temp_id;
5306
5307 IF (l_debug = 1) THEN
5308 mydebug('complete_putaway: Calling Karuns API');
5309 END IF;
5310
5311 /* FP-J Lot/Serial Support Enhancement
5312 * If the LPN Context is Resides in Receiving, then do the following:
5313 * IF INV J and PO J are installed Then
5314 * Check subinventory type of the drop subinventory
5315 * If destination sub is receiving subinventory Then
5316 * Call the Transfer API
5317 * Else
5318 * Set the variable p_transaction_temp_id to product_transaction_id
5319 * Call the Deliver API
5320 * End If
5321 * Else
5322 * Set the value of p_transaction_temp_id to l_dup_temp_id
5323 * Retain the old code to call deliver API by passing NULL values for
5324 * the new parameters
5325 * End If;
5326 */
5327
5328 l_drop_sub_type := wms_putaway_utils.get_subinventory_type(p_organization_id => p_org_id
5329 , p_subinventory_code => p_sub);
5330
5331 IF (l_drop_sub_type < 0) THEN
5332 fnd_message.set_name('WMS', 'WMS_TASK_ERROR');
5333 fnd_msg_pub.add;
5334 IF (l_debug = 1) THEN
5335 mydebug('complete_putaway: Error fetching drop subinventory type');
5336 END IF;
5337 RAISE fnd_api.g_exc_error;
5338 END IF;
5339
5340 --Update the wms_process_flag to 2 so that one can work with
5341 --with this move order line from elsewhere
5342 UPDATE mtl_txn_request_lines
5343 SET wms_process_flag = 2
5344 WHERE line_id = l_mo_line_id;
5345
5346 --Storage subinventory - Call Deliver API
5347 IF l_drop_sub_type = 1 THEN
5348 IF (l_debug = 1) THEN
5349 mydebug('complete_putaway: Calling the deliver API with product_transaction_id: ' || l_product_transaction_id ||
5350 ', from lpn, ' || l_mo_lpn_id || ', xfer_lpn_id: ' || l_to_lpn_id || ' lot_num: ' || l_mol_lot_number);
5351 END IF;
5352
5353 --R12
5354 inv_rcv_std_deliver_apis.Match_putaway_rcvtxn_intf_rec
5355 (p_organization_id => p_org_id
5356 , p_reference_id => l_ref_id
5357 , p_reference => l_ref
5358 , p_reference_type_code => l_ref_type
5359 , p_item_id => p_item_id
5360 , p_revision => p_rev
5361 , p_subinventory_code => p_sub
5362 , p_locator_id => p_loc
5363 , p_rcvtxn_qty => l_qty
5364 , p_rcvtxn_uom_code => p_uom
5365 , p_transaction_temp_id => l_product_transaction_id
5366 , p_lot_control_code => l_lot_code
5367 , p_serial_control_code => l_serial_code
5368 , p_original_txn_temp_id => p_temp_id
5369 , x_return_status => x_return_status
5370 , x_msg_count => x_msg_count
5371 , x_msg_data => x_msg_data
5372 , p_inspection_status_code => l_inspection_status
5373 , p_lpn_id => l_mo_lpn_id
5374 , p_transfer_lpn_id => l_to_lpn_id
5375 , p_lot_number => l_mol_lot_number
5376 , p_parent_txn_id => l_parent_txn_id
5377 , p_secondary_quantity => p_secondary_quantity --OPM Integration
5378 , p_secondary_uom => p_secondary_uom --OPM Integration
5379 , p_inspection_status => l_inspection_status
5380 , p_primary_uom_code => p_primary_uom
5381 );
5382 IF (l_debug = 1) THEN
5383 mydebug('complete_putaway: After Karuns Delivery API');
5384 END IF;
5385
5386 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5387 fnd_message.set_name('WMS', 'WMS_TD_DEL_ERROR');
5388 fnd_msg_pub.ADD;
5389 RAISE fnd_api.g_exc_unexpected_error;
5390 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5391 fnd_message.set_name('WMS', 'WMS_TD_DEL_ERROR');
5392 fnd_msg_pub.ADD;
5393 RAISE fnd_api.g_exc_error;
5394 END IF;
5395 --Receiving subinventory - Call Transfer API
5396 ELSE
5397 IF (l_debug = 1) THEN
5398 mydebug('complete_putaway: Calling the Transfer API');
5399 END IF;
5400
5401 --R12
5402 inv_rcv_std_transfer_apis.Match_transfer_rcvtxn_rec
5403 (x_return_status => x_return_status
5404 , x_msg_count => x_msg_count
5405 , x_msg_data => x_msg_data
5406 , p_organization_id => p_org_id
5407 , p_parent_txn_id => l_parent_txn_id
5408 , p_reference_id => l_ref_id
5409 , p_reference => l_ref
5410 , p_reference_type_code => l_ref_type
5411 , p_item_id => p_item_id
5412 , p_revision => p_rev
5413 , p_subinventory_code => p_sub
5414 , p_locator_id => p_loc
5415 , p_transfer_quantity => l_qty
5416 , p_transfer_uom_code => p_uom
5417 , p_lot_control_code => l_lot_code
5418 , p_serial_control_code => l_serial_code
5419 , p_original_rti_id => l_product_transaction_id
5420 , p_original_temp_id => p_temp_id
5421 , p_lot_number => l_mol_lot_number
5422 , p_lpn_id => l_mo_lpn_id
5423 , p_transfer_lpn_id => l_to_lpn_id
5424 , p_sec_transfer_quantity => p_secondary_quantity--OPM Integration
5425 , p_sec_transfer_uom_code => p_secondary_uom --OPM Integration
5426 , p_inspection_status => l_inspection_status
5427 , p_primary_uom_code => p_primary_uom
5428 );
5429 IF (l_debug = 1) THEN
5430 mydebug('complete_putaway: After Transfer API');
5431 END IF;
5432
5433 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5434 fnd_message.set_name('WMS', 'WMS_TASK_ERROR');
5435 fnd_msg_pub.ADD;
5436 RAISE fnd_api.g_exc_unexpected_error;
5437 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5438 fnd_message.set_name('WMS', 'WMS_TASK_ERROR');
5439 fnd_msg_pub.ADD;
5440 RAISE fnd_api.g_exc_error;
5441 END IF;
5442 END IF; --END IF check sub type to call the corresponding API
5443 --14487832
5444 IF l_serial_code NOT IN (1,6) THEN
5445
5446 DELETE FROM mtl_serial_numbers_interface
5447 WHERE product_transaction_id = l_product_transaction_id;
5448
5449 IF (l_debug = 1) THEN
5450 mydebug('complete_putaway: Deleted msni with l_product_transaction_id '||l_product_transaction_id);
5451 END IF;
5452
5453 IF l_lot_code = 2 THEN
5454 DELETE FROM mtl_transaction_lots_interface
5455 WHERE product_transaction_id = l_product_transaction_id;
5456
5457 IF (l_debug = 1) THEN
5458 mydebug('complete_putaway: Deleted mtli with l_product_transaction_id '||l_product_transaction_id);
5459 END IF;
5460 END IF;
5461 END IF;
5462 --14487832
5463
5464 IF (l_debug = 1) THEN
5465 mydebug(' updating WDT with the group id');
5466 END IF;
5467
5468 UPDATE wms_dispatched_tasks
5469 SET task_group_id = inv_rcv_common_apis.g_rcv_global_var.interface_group_id
5470 WHERE transaction_temp_id = p_temp_id;
5471
5472 l_txn_mode := 2;
5473
5474 -- Bug 2074100 Fix
5475
5476 IF ((l_del_detail_id IS NOT NULL)
5477 AND(l_crossdock_type = 2)
5478 AND(l_wip_supply_type = 1)) THEN
5479 IF (l_debug = 1) THEN
5480 mydebug(' This is a crossdocked line for wip issue ');
5481 mydebug(' need to update the context of the from lpn ');
5482 END IF;
5483
5484 -- Bug# 3281512 - Performance Fixes
5485 -- Match against the org too otherwise we will do a full table
5486 -- scan on MMTT which is really bad. Org is an indexed column.
5487 -- Bug# 3434940 - Performance fixes
5488 -- Use an EXISTS instead since we are just checking for existence
5489 -- of any MMTT records for the given LPN. Also use the item
5490 -- passed as an input parameter into complete_putaway too so we
5491 -- can make use of the item/org index or the index on lpn_id.
5492 -- Note that content_lpn_id currently is not an indexed column.
5493 BEGIN
5494 SELECT 1
5495 INTO cnt
5496 FROM DUAL
5497 WHERE EXISTS (SELECT 1
5498 FROM mtl_material_transactions_temp
5499 WHERE lpn_id = p_lpn_id
5500 AND organization_id = p_org_id
5501 AND inventory_item_id = p_item_id)
5502 OR EXISTS (SELECT 1
5503 FROM mtl_material_transactions_temp
5504 WHERE content_lpn_id = p_lpn_id
5505 AND organization_id = p_org_id
5506 AND inventory_item_id = p_item_id);
5507 EXCEPTION
5508 WHEN NO_DATA_FOUND THEN
5509 cnt := 0;
5510 END;
5511
5512 IF (l_debug = 1) THEN
5513 mydebug('cnt is ' || cnt);
5514 END IF;
5515
5516 ELSE
5517 IF (l_debug = 1) THEN
5518 mydebug(' In else for checking for wip issue after tm');
5519 mydebug(' to upd the lpn context ');
5520 END IF;
5521 END IF;
5522 --For other LPN contexts (Resides in Inventory, Resides in WIP)
5523 ELSE
5524 -- Set mode to normal
5525 l_txn_mode := 1;
5526
5527 IF (l_debug = 1) THEN
5528 mydebug('complete_putaway: INV or WIP LPN');
5529 mydebug('complete_putaway: Updating mmtt info...');
5530 mydebug('complete_putaway: To LPN :' || l_to_lpn_id);
5531 mydebug('complete_putaway: Entire LPN' || p_entire_lpn);
5532 mydebug('complete_putaway: lpn drop type ' || p_lpn_mode);
5533 mydebug('complete_putaway: from lpn ' || p_lpn_id );
5534 END IF;
5535
5536 --Changes for bug 5403420
5537 invttmtx.tdatechk(org_id => p_org_id,
5538 transaction_date => SYSDATE,
5539 period_id => l_acct_period_id,
5540 open_past_period => l_open_past_period);
5541
5542 IF l_acct_period_id <= 0 THEN
5543 fnd_message.set_name('INV', 'INV_NO_OPEN_PERIOD');
5544 fnd_msg_pub.ADD;
5545 RAISE fnd_api.g_exc_unexpected_error;
5546 END IF;
5547 --End of changes for bug 5403420
5548
5549 -- Nested LPN changes
5550 -- Update MMTT for drop entire LPN
5551 IF (l_debug = 1) THEN
5552 mydebug('complete_putaway: Patchset J or above , Update MMTT');
5553 -- ER 7307189 changes start
5554 mydebug(' Update MMTT l_dest_loc_id with ' || l_dest_loc_id);
5555 mydebug(' Update MMTT l_dest_sub with ' || l_dest_sub);
5556 -- ER 7307189 changes end
5557 END IF;
5558
5559 IF (p_lpn_id = l_to_lpn_id) THEN
5560
5561 IF (l_debug = 1) THEN
5562 mydebug(' Update MMTT contet LPN_ID WITH ' || p_lpn_id);
5563 mydebug(' Update MMTT cost_group_id with ' || l_cost_group_id);
5564 END IF;
5565
5566 UPDATE mtl_material_transactions_temp
5567 SET transaction_header_id = l_txn_header_id
5568 , content_lpn_id = p_lpn_id
5569 , lpn_id = NULL
5570 , transaction_status = 3
5571 , posting_flag = 'Y'
5572 , cost_group_id = Decode(l_lpn_context,1,l_cost_group_id,cost_group_id) --BUG 4134432,4475607
5573 , transfer_cost_group_id = Decode(l_lpn_context,1,l_cost_group_id,transfer_cost_group_id) --BUG 4134432, 4475607
5574 , transaction_date = sysdate --added per Karun and Saju's request 04/2006
5575 , acct_period_id = l_acct_period_id --Added for bug 5403420
5576 WHERE transaction_temp_id = p_temp_id;
5577 ELSE
5578
5579 IF (l_debug = 1) THEN
5580 mydebug(' Update MMTT from lpn_id with ' || p_lpn_id);
5581 mydebug(' Update MMTT to lpn_id with ' || l_to_lpn_id);
5582 mydebug(' Update MMTT cost_group_id with ' || l_cost_group_id);
5583 END IF;
5584
5585 UPDATE mtl_material_transactions_temp
5586 SET transaction_header_id = l_txn_header_id
5587 , lpn_id = p_lpn_id
5588 , content_lpn_id = NULL
5589 , transfer_lpn_id = l_to_lpn_id
5590 , transaction_status = 3
5591 , posting_flag = 'Y'
5592 , cost_group_id = Decode(l_lpn_context,1,l_cost_group_id,cost_group_id) --BUG 4134432, 4475607
5593 , transfer_cost_group_id = Decode(l_lpn_context,1,l_cost_group_id,transfer_cost_group_id) --BUG 4134432,4475607
5594 , transaction_date = sysdate --added per Karun and Saju's request 04/2006
5595 , acct_period_id = l_acct_period_id --Added for bug 5403420
5596 WHERE transaction_temp_id = p_temp_id;
5597
5598 END IF; --END IF (p_lpn_id = l_to_lpn_id) THEN
5599
5600
5601 -- Have to update WMS_Exceptions so that any excpetions already
5602 -- recorded for this MMTT line will now be updated with the new txn
5603 -- header_id
5604 -- Bug# 3434940 - Performance Fixes
5605 -- Go against the org and item which are input params for
5606 -- complete_putaway since this will make use of the index in
5607 -- WMS_EXCEPTIONS
5608 UPDATE wms_exceptions
5609 SET transaction_header_id = l_txn_header_id
5610 WHERE transaction_header_id = l_orig_txn_header_id
5611 AND organization_id = p_org_id
5612 AND inventory_item_id = p_item_id;
5613
5614 IF (l_debug = 1) THEN
5615 mydebug('Calling Workflow from complete_putaway');
5616 END IF;
5617
5618 -- Call the workflows
5619 l_wf := 0;
5620
5621 IF (p_qty_reason_id > 0) THEN
5622 BEGIN
5623 SELECT 1
5624 INTO l_wf
5625 FROM mtl_transaction_reasons
5626 WHERE reason_id = p_qty_reason_id
5627 AND workflow_name IS NOT NULL
5628 AND workflow_name <> ' '
5629 AND workflow_process IS NOT NULL
5630 AND workflow_process <> ' ';
5631 EXCEPTION
5632 WHEN NO_DATA_FOUND THEN
5633 l_wf := 0;
5634 END;
5635
5636 IF l_wf > 0 THEN
5637 IF (l_debug = 1) THEN
5638 mydebug('complete_putaway : WF exists for this reason code: ' || p_qty_reason_id);
5639 mydebug('complete_putaway : Calling workflow wrapper FOR qty');
5640 END IF;
5641
5642 -- Calling Workflow
5643 wms_workflow_wrappers.wf_wrapper(
5644 p_api_version => 1.0
5645 , p_init_msg_list => fnd_api.g_false
5646 , p_commit => fnd_api.g_false
5647 , x_return_status => x_return_status
5648 , x_msg_count => x_msg_count
5649 , x_msg_data => x_msg_data
5650 , p_org_id => p_org_id
5651 , p_rsn_id => p_qty_reason_id
5652 , p_calling_program => 'complete_putaway - for qty discrepancy - loose'
5653 , p_tmp_id => p_temp_id
5654 , p_quantity_picked => l_qty
5655 , p_dest_sub => l_org_sub
5656 , p_dest_loc => l_org_loc
5657 );
5658
5659 IF (l_debug = 1) THEN
5660 mydebug('complete_putaway : After Calling WF Wrapper');
5661 END IF;
5662
5663 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5664 IF (l_debug = 1) THEN
5665 mydebug('complete_putaway : Error callinf WF wrapper');
5666 END IF;
5667
5668 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5669 fnd_msg_pub.ADD;
5670 RAISE fnd_api.g_exc_unexpected_error;
5671 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5672 IF (l_debug = 1) THEN
5673 mydebug('complete_putaway : Error calling WF wrapper');
5674 END IF;
5675
5676 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5677 fnd_msg_pub.ADD;
5678 RAISE fnd_api.g_exc_error;
5679 END IF;
5680 END IF; --IF l_wf > 0 THEN
5681 END IF;--IF (p_qty_reason_id > 0) THEN
5682
5683 -- call workflow for location discrepancy
5684 l_wf := 0;
5685
5686
5687 IF (p_loc_reason_id > 0) THEN
5688 -- update MMTT with reason id = p_loc_reason_id.(bugfix 4294713)
5689 update mtl_material_transactions_temp
5690 set reason_id = p_loc_reason_id
5691 where transaction_temp_id = p_temp_id;
5692
5693 BEGIN
5694 SELECT 1,
5695 workflow_process
5696 INTO l_wf,
5697 l_wf_process
5698 FROM mtl_transaction_reasons
5699 WHERE reason_id = p_loc_reason_id
5700 AND workflow_name IS NOT NULL
5701 AND workflow_name <> ' '
5702 AND workflow_process IS NOT NULL
5703 AND workflow_process <> ' ';
5704 EXCEPTION
5705 WHEN NO_DATA_FOUND THEN
5706 l_wf := 0;
5707 l_wf_process := null; --Bugfix 4294713
5708 END;
5709
5710 IF ( ( l_wf_process IS NOT NULL --Bugfix 4294713
5711 AND
5712 l_wf_process <> 'WMS_N_STEP_PUTAWAY'
5713 )
5714 OR
5715 l_operation_plan_id IS NULL
5716 ) THEN
5717 -- Bug 3346762
5718 IF (l_lpn_context=2) AND l_dest_sub IS NULL THEN
5719 l_wf_temp_sub := l_org_sub;
5720 l_wf_temp_loc := l_org_loc;
5721 ELSE
5722 l_wf_temp_sub := l_dest_sub;
5723 l_wf_temp_loc := l_dest_loc_id;
5724 END IF;
5725
5726 IF l_wf > 0 THEN
5727 IF (l_debug = 1) THEN
5728 mydebug(' complete_putaway : WF exists for this reason code: ' || p_loc_reason_id);
5729 mydebug('complete_putaway : Calling workflow wrapper FOR location');
5730 mydebug('dest sub: ' || p_sub);
5731 mydebug('dest loc: ' || p_loc);
5732 END IF;
5733
5734
5735
5736 -- Calling Workflow
5737 wms_workflow_wrappers.wf_wrapper(
5738 p_api_version => 1.0
5739 , p_init_msg_list => fnd_api.g_false
5740 , p_commit => fnd_api.g_false
5741 , x_return_status => x_return_status
5742 , x_msg_count => x_msg_count
5743 , x_msg_data => x_msg_data
5744 , p_org_id => p_org_id
5745 , p_rsn_id => p_loc_reason_id
5746 , p_calling_program => 'complete_putaway - for loc discrepancy - loose'
5747 , p_tmp_id => p_temp_id
5748 , p_quantity_picked => NULL
5749 , p_dest_sub => l_wf_temp_sub
5750 , p_dest_loc => l_wf_temp_loc
5751 );
5752
5753 IF (l_debug = 1) THEN
5754 mydebug('complete_putaway : After Calling WF Wrapper');
5755 END IF;
5756
5757 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5758 IF (l_debug = 1) THEN
5759 mydebug('complete_putaway : Error callinf WF wrapper');
5760 END IF;
5761
5762 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5763 fnd_msg_pub.ADD;
5764 RAISE fnd_api.g_exc_unexpected_error;
5765 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5766 IF (l_debug = 1) THEN
5767 mydebug('complete_putaway : Error calling WF wrapper');
5768 END IF;
5769
5770 fnd_message.set_name('WMS', 'WMS_WORK_FLOW_FAIL');
5771 fnd_msg_pub.ADD;
5772 RAISE fnd_api.g_exc_error;
5773 END IF;
5774 END IF;--END IF l_wf > 0 THEN
5775 END IF; --IF (( l_wf_process IS NOT NULL AND l_wf_process <> 'WMS_N_STEP_PUTAWAY') OR l_operation_plan_id IS NULL) THEN
5776 END IF;--END IF (p_loc_reason_id > 0) THEN
5777
5778 IF l_transaction_source_type_id = 5 THEN
5779 IF (l_debug = 1) THEN
5780 mydebug('complete_putaway : calling wma_inv_wrappers.transferReservation');
5781 mydebug('l_ref_id: => ' || l_ref_id);
5782 mydebug('p_sub: ====> ' || p_sub);
5783 mydebug('p_loc: ====> ' || p_loc);
5784 mydebug('l_del_detail_id ====> ' || l_del_detail_id);
5785 END IF;
5786
5787 --bug 2310251 for WIP Putaway, use the new business flow code
5788 l_business_flow_code := 35;
5789
5790 IF (l_del_detail_id IS NULL ) THEN
5791
5792 /*9695544-We should not call wip api to xfer reservation in case of putaway of material from an LPN that has
5793 xdock tasks as well. The reason is that the WIP reservation for xdock will be transferred by this call
5794 while the actual xdock tasks are not yet dropped. This will create data inconsistency.
5795 On the other hand, we need to call this API is if it is a putaway of an LPN because some one can create
5796 reservation for SO and supply as WIP and we need to transfer the reservation
5797 */
5798
5799 BEGIN
5800 l_xdock_tasks_exists := 'N';
5801 SELECT 'Y' INTO l_xdock_tasks_exists
5802 FROM MTL_TXN_REQUEST_LINES mtrl
5803 WHERE lpn_id= p_lpn_id
5804 AND line_id <> l_mo_line_id
5805 AND backorder_delivery_detail_id IS NOT NULL
5806 AND line_status <> 5
5807 AND ROWNUM<2; --we need to just check if one such row exists or not
5808 EXCEPTION
5809 WHEN OTHERS THEN
5810 IF (l_debug = 1) THEN
5811 mydebug('complete_putaway : query to fetch l_xdock_tasks_exists resulte din exception, but it is fine ');
5812 END IF;
5813 l_xdock_tasks_exists := 'N';
5814 END ;
5815
5816 IF (l_debug = 1) THEN
5817 mydebug('complete_putaway : l_xdock_tasks_exists: '||l_xdock_tasks_exists);
5818 END IF;
5819
5820 IF ( l_xdock_tasks_exists = 'N' ) THEN
5821 wms_wip_integration.transfer_reservation(
5822 p_header_id => l_ref_id
5823 , p_subinventory_code => p_sub
5824 , p_locator_id => p_loc
5825 , x_return_status => x_return_status
5826 , x_msg_count => x_msg_count
5827 , x_err_msg => x_msg_data
5828 , p_temp_id => p_temp_id
5829 );
5830 END IF;
5831 ELSE
5832 IF (l_debug = 1) THEN
5833 mydebug('complete_putaway :xdock flow . So call transfer_reservation is not needed');
5834 END IF;
5835 END IF;
5836
5837 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
5838 IF (l_debug = 1) THEN
5839 mydebug('complete_putaway : wma_inv_wrappers.transferReservation - Unexpect error');
5840 END IF;
5841
5842 RAISE fnd_api.g_exc_unexpected_error;
5843 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
5844 IF (l_debug = 1) THEN
5845 mydebug('complete_putaway : wma_inv_wrappers.transferReservation - Expect error');
5846 END IF;
5847
5848 RAISE fnd_api.g_exc_error;
5849 END IF;
5850 END IF;
5851
5852 -- Added release level check for ATF_J3
5853
5854 IF (l_debug = 1) THEN
5855 mydebug('complete_putaway: Patchset J or higher. Call to Inventroy TM will be done in complete_putaway_wrapper ');
5856 END IF;
5857
5858 -- 4515887 CHANGES START
5859 IF l_txn_action_id =31 AND l_txn_type_id= 44 THEN
5860 IF (l_debug = 1) THEN
5861 mydebug('complete_putaway: Calling create_snapshot');
5862 END IF;
5863 create_snapshot(p_temp_id,p_org_id);
5864 END IF;
5865 -- 4515887 CHANGES END
5866
5867 END IF;
5868
5869 -- Bug# 2795096
5870 -- Do a commit only if the input parameter is set to 'Y' = YES
5871 IF (p_commit = 'Y') THEN
5872 COMMIT;
5873 END IF;
5874
5875 x_return_status := fnd_api.g_ret_sts_success;
5876
5877 IF (l_debug = 1) THEN
5878 mydebug('complete_putaway: done WITH API');
5879 END IF;
5880 EXCEPTION
5881 WHEN fnd_api.g_exc_error THEN
5882 -- Bug# 2744170
5883 -- Perform a rollback in the exception blocks
5884 ROLLBACK TO complete_putaway_sp;
5885 x_return_status := fnd_api.g_ret_sts_error;
5886 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5887 IF ser_csr%ISOPEN THEN
5888 CLOSE ser_csr;
5889 END IF;
5890 -- ER 7307189 changes start
5891 IF ser_csr_reserved_lpn%ISOPEN THEN
5892 CLOSE ser_csr_reserved_lpn;
5893 END IF;
5894 -- ER 7307189 changes end
5895 IF c_rcv_ser_csr%ISOPEN THEN
5896 CLOSE c_rcv_ser_csr;
5897 END IF;
5898 IF (l_debug = 1) THEN
5899 mydebug('complete_putaway: Excection error - ' || SQLERRM);
5900 END IF;
5901 WHEN OTHERS THEN
5902
5903 ROLLBACK TO complete_putaway_sp;
5904 x_return_status := fnd_api.g_ret_sts_unexp_error;
5905 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5906 IF ser_csr%ISOPEN THEN
5907 CLOSE ser_csr;
5908 END IF;
5909 -- ER 7307189 changes start
5910 IF ser_csr_reserved_lpn%ISOPEN THEN
5911 CLOSE ser_csr_reserved_lpn;
5912 END IF;
5913 -- ER 7307189 changes end
5914 IF c_rcv_ser_csr%ISOPEN THEN
5915 CLOSE c_rcv_ser_csr;
5916 END IF;
5917 IF (l_debug = 1) THEN
5918 mydebug('complete_putaway: Others exception - ' || SQLERRM);
5919 END IF;
5920 END complete_putaway;
5921
5922 /*changes for OPM are not needed in this procedure since this is not called post-patchset J */
5923 PROCEDURE discrepancy(
5924 p_lpn_id IN NUMBER
5925 , p_org_id IN NUMBER
5926 , p_temp_id IN NUMBER
5927 , p_qty IN NUMBER
5928 , p_uom IN VARCHAR2
5929 , p_user_id IN NUMBER
5930 , x_return_status OUT NOCOPY VARCHAR2
5931 ) IS
5932 l_orig_qty NUMBER;
5933 l_orig_uom VARCHAR2(3);
5934 l_mol_uom VARCHAR2(3);
5935 l_line_id NUMBER;
5936 l_item_id NUMBER;
5937 l_temp_id NUMBER;
5938 l_org_id NUMBER;
5939 l_uom VARCHAR2(3);
5940 l_qty NUMBER;
5941 l_qty_diff NUMBER;
5942 l_qty_diff_prim NUMBER;
5943 l_cnt1 NUMBER;
5944 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5945 BEGIN
5946 l_temp_id := p_temp_id;
5947 l_org_id := p_org_id;
5948 l_uom := p_uom;
5949 l_qty := p_qty;
5950
5951 SELECT transaction_quantity
5952 , transaction_uom
5953 , inventory_item_id
5954 , move_order_line_id
5955 INTO l_orig_qty
5956 , l_orig_uom
5957 , l_item_id
5958 , l_line_id
5959 FROM mtl_material_transactions_temp
5960 WHERE transaction_temp_id = l_temp_id
5961 AND organization_id = l_org_id;
5962
5963 IF (l_uom <> l_orig_uom) THEN
5964 --mydebug('Converting uom');
5965 l_qty :=
5966 inv_convert.inv_um_convert(
5967 item_id => l_item_id
5968 , PRECISION => NULL
5969 , from_quantity => l_qty
5970 , from_unit => l_uom
5971 , to_unit => l_orig_uom
5972 , from_name => NULL
5973 , to_name => NULL
5974 );
5975 END IF;
5976
5977 -- Calculate the difference
5978
5979 l_qty_diff := l_orig_qty - l_qty;
5980 -- Calculate the difference in terms of the primary uom
5981
5982 l_qty_diff_prim :=
5983 wms_task_dispatch_gen.get_primary_quantity(
5984 p_item_id => l_item_id
5985 , p_organization_id => l_org_id
5986 , p_from_quantity => l_qty_diff
5987 , p_from_unit => l_orig_uom);
5988
5989 -- Update MMTT with new values for txn and primary qty
5990
5991 UPDATE mtl_material_transactions_temp
5992 SET transaction_quantity = transaction_quantity - l_qty_diff
5993 , primary_quantity = primary_quantity - l_qty_diff_prim
5994 WHERE transaction_temp_id = l_temp_id
5995 AND organization_id = l_org_id;
5996
5997 -- Update mtl_transaction_lots_temp, if necessary
5998 --calling this procedure
5999 /* Bug #2966531
6000 * Do not update MTLT again since they would already have been done before
6001 * coming here */
6002 /*
6003 BEGIN
6004 UPDATE mtl_transaction_lots_temp
6005 SET transaction_quantity = transaction_quantity-l_qty_diff,
6006 primary_quantity = primary_quantity-l_qty_diff_prim
6007 WHERE transaction_temp_id = l_temp_id;
6008 EXCEPTION
6009 WHEN OTHERS THEN
6010 NULL;
6011 END;*/
6012
6013 --mydebug('After updating mmtt');
6014 -- Update MTL_TXN_REQUESTS_TABLE
6015 -- Since the uom code in mtl_txn_request_lines will always
6016 -- be the same as the transaction_uom in mmtt, no need to do the
6017 -- conversion again
6018 UPDATE mtl_txn_request_lines
6019 SET quantity_detailed = quantity_detailed - l_qty_diff
6020 WHERE line_id = l_line_id
6021 AND organization_id = l_org_id;
6022 --mydebug('After updating mol');
6023
6024 x_return_status := fnd_api.g_ret_sts_success;
6025 EXCEPTION
6026 WHEN fnd_api.g_exc_error THEN
6027 x_return_status := fnd_api.g_ret_sts_error;
6028 WHEN OTHERS THEN
6029 x_return_status := fnd_api.g_ret_sts_unexp_error;
6030 END discrepancy;
6031
6032 -- Important, please note that the input parameter, p_user_id
6033 -- does NOT refer to the fnd user id. Instead it refers to the employee id.
6034 -- It is used against the wms_dispatched_tasks.person_id column which
6035 -- is populated with the employee id.
6036 PROCEDURE check_lpn_validity(
6037 p_org_id IN NUMBER
6038 , p_lpn_id IN NUMBER
6039 , x_ret OUT NOCOPY NUMBER
6040 , x_return_status OUT NOCOPY VARCHAR2
6041 , x_msg_count OUT NOCOPY NUMBER
6042 , x_msg_data OUT NOCOPY VARCHAR2
6043 , x_context OUT NOCOPY NUMBER
6044 , p_user_id IN NUMBER
6045 ) IS
6046 l_ret NUMBER;
6047 l_msg_data VARCHAR2(2000);
6048 l_lpn_id NUMBER;
6049 l_dummy NUMBER;
6050 l_org_id NUMBER;
6051 l_lpn_context NUMBER;
6052 l_count NUMBER;
6053 l_insp_status NUMBER;
6054 l_process_flag_cnt NUMBER;
6055 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
6056 l_mo_cnt NUMBER;
6057 l_mo_cnt2 NUMBER;
6058 l_so_cnt NUMBER;
6059 l_nested_lpn_cnt NUMBER;
6060 l_sub VARCHAR2(10);
6061 l_locator_id NUMBER;
6062 l_emp_id NUMBER;--Bug# 3116925
6063 -- Need to trap the error returned when
6064 -- unable to lock the lpn record.
6065 record_locked EXCEPTION;
6066 PRAGMA EXCEPTION_INIT(record_locked, -54);
6067 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6068
6069 -- Following variables added in ATF_J
6070
6071 -- end variables added in ATF_J
6072
6073 l_tempid_tab num_tab;
6074 l_error_code NUMBER;
6075 l_inspection_flag NUMBER;
6076 l_load_flag NUMBER;
6077 l_drop_flag NUMBER;
6078 l_load_prim_quantity NUMBER;
6079 l_insp_prim_quantity NUMBER;
6080 l_drop_prim_quantity NUMBER;
6081 l_rti_cnt NUMBER; --Bug:13613257
6082
6083
6084 -- This cursor will get the MMTTs assoicated with the LPN passed
6085 CURSOR c_lpn_mmtt_cursor IS
6086 SELECT mmtt.transaction_temp_id
6087 FROM mtl_material_transactions_temp mmtt
6088 ,mtl_txn_request_lines mtrl
6089 WHERE mtrl.line_id = mmtt.move_order_line_id
6090 AND mtrl.line_status = 7
6091 AND mtrl.lpn_id = p_lpn_id
6092 AND mtrl.organization_id = p_org_id;
6093
6094 BEGIN
6095 l_lpn_id := p_lpn_id;
6096 l_org_id := p_org_id;
6097 x_ret := 0;
6098 l_count := 0;
6099 l_process_flag_cnt := 0;
6100
6101 IF (l_debug = 1) THEN
6102 mydebug('check_lpn_validity: In LPN Valid APi');
6103 mydebug('Org' || l_org_id);
6104 mydebug('check_lpn_validity: LPN' || l_lpn_id);
6105 END IF;
6106
6107 --get the context
6108 BEGIN
6109 SELECT lpn_context
6110 INTO l_lpn_context
6111 FROM wms_license_plate_numbers
6112 WHERE lpn_id = l_lpn_id
6113 AND organization_id = l_org_id;
6114 EXCEPTION
6115 WHEN NO_DATA_FOUND THEN
6116 IF (l_debug = 1) THEN
6117 mydebug('check_lpn_validity: LPN does not belong to ' || l_org_id || ' organization');
6118 END IF;
6119 fnd_message.set_name('INV', 'INV_NO_RESULT_FOUND');
6120 fnd_msg_pub.ADD;
6121 RAISE fnd_api.g_exc_unexpected_error;
6122 END;
6123
6124 mydebug('check_lpn_validity: LPN Context' || l_lpn_context);
6125 l_mo_cnt := 0;
6126 l_mo_cnt2 := 0;
6127 l_so_cnt := 0;
6128 l_nested_lpn_cnt := 0;
6129
6130 /*
6131 Added for the Bug:13613257
6132 */
6133
6134 mydebug('check_lpn_validity: Checking is there any non errored RTI for this LPN' || l_lpn_id);
6135
6136 IF (l_lpn_context = 3) THEN
6137
6138 BEGIN
6139 SELECT 1
6140 INTO l_rti_cnt
6141 FROM rcv_transactions_interface
6142 WHERE (transfer_lpn_id IN (SELECT lpn_id
6143 FROM wms_license_plate_numbers
6144 START WITH lpn_id = l_lpn_id
6145 CONNECT BY PRIOR lpn_id = parent_lpn_id)
6146 OR lpn_id IN (SELECT lpn_id
6147 FROM wms_license_plate_numbers
6148 START WITH lpn_id = l_lpn_id
6149 CONNECT BY PRIOR lpn_id = parent_lpn_id))
6150 AND to_organization_id = l_org_id
6151 AND TRANSACTION_STATUS_CODE <> 'ERROR'
6152 AND rownum<2;
6153 EXCEPTION
6154 WHEN NO_DATA_FOUND THEN
6155 l_rti_cnt := 0;
6156
6157 IF (l_debug = 1) THEN
6158 mydebug('check_lpn_validity: RTI not Found');
6159 mydebug('check_lpn_validity: No pending RTI exist for LPN');
6160 END IF;
6161
6162 END;
6163
6164
6165 IF (l_rti_cnt >0) THEN
6166
6167 IF (l_debug = 1) THEN
6168 mydebug('check_lpn_validity: RTI Found Henc cannt putway the LPN');
6169
6170 END IF;
6171
6172 fnd_message.set_name('INV', 'INVALID LPN');
6173 fnd_msg_pub.ADD;
6174 RAISE fnd_api.g_exc_unexpected_error;
6175 END IF ;
6176 END IF ;
6177
6178
6179 --BUG 3625990: Don't lock if the LPN is in Receiving
6180 IF (l_lpn_context <> 3) THEN
6181 -- Lock the LPN or return an error if another user
6182 -- already has a lock. This is to prevent the
6183 -- current session from hanging (bug 1724818).
6184 BEGIN
6185 SELECT lpn_id
6186 INTO l_dummy
6187 FROM wms_license_plate_numbers
6188 WHERE lpn_id = l_lpn_id
6189 AND organization_id = l_org_id
6190 FOR UPDATE NOWAIT;
6191 EXCEPTION
6192 WHEN NO_DATA_FOUND THEN
6193 IF (l_debug = 1) THEN
6194 mydebug('check_lpn_validity: LPN does not belong to ' || l_org_id || ' organization');
6195 END IF;
6196
6197 fnd_message.set_name('INV', 'INV_NO_RESULT_FOUND');
6198 fnd_msg_pub.ADD;
6199 RAISE fnd_api.g_exc_unexpected_error;
6200 WHEN record_locked THEN
6201 IF (l_debug = 1) THEN
6202 mydebug('check_lpn_validity: LPN not available. locked by someone else');
6203 END IF;
6204
6205 fnd_message.set_name('WMS', 'WMS_LPN_UNAVAIL');
6206 fnd_msg_pub.ADD;
6207 RAISE fnd_api.g_exc_unexpected_error;
6208 END;
6209 END IF;
6210
6211 IF (l_debug = 1) THEN
6212 mydebug('check_lpn_validity: nested LPN Check');
6213 END IF;
6214
6215 -- Check to see if this LPN has already been loaded by another user
6216 -- Check to see if this is a nested LPN
6217 -- Dont do this check if WMS and PO patch levels are J or higher
6218
6219 IF l_nested_lpn_cnt > 0 THEN
6220 IF (l_debug = 1) THEN
6221 mydebug('check_lpn_validity: This is a nested LPN');
6222 END IF;
6223
6224 x_ret := 3;
6225 ELSE
6226 IF (l_debug = 1) THEN
6227 mydebug('check_lpn_validity: This is NOT a nested LPN');
6228 END IF;
6229
6230 x_context := l_lpn_context;
6231
6232 IF (l_lpn_context NOT IN (1,8) ) THEN --Bug#6920388.Added '8'.
6233 IF (l_debug = 1) THEN
6234 mydebug('check_lpn_validity: Not an inv lpn, so MO has to exist');
6235 END IF;
6236
6237 BEGIN
6238 SELECT 1
6239 INTO l_mo_cnt
6240 FROM DUAL
6241 WHERE EXISTS(SELECT 1
6242 FROM mtl_txn_request_lines
6243 WHERE lpn_id = l_lpn_id
6244 AND organization_id = l_org_id
6245 );
6246 EXCEPTION
6247 WHEN NO_DATA_FOUND THEN
6248 l_mo_cnt := 0;
6249
6250 IF (l_debug = 1) THEN
6251 mydebug('check_lpn_validity: MO not Found');
6252 mydebug('check_lpn_validity: Not an inv lpn and MO does not exist, hence it is invalid');
6253 END IF;
6254
6255 x_ret := 3;
6256 END;
6257
6258 IF l_mo_cnt > 0 THEN
6259 /*Check process flag - Flag to indicate processing status for putaways.
6260 1 means Ok to process,
6261 2 means Do not Allocate,
6262 3 means Allocate but do not process.
6263 To be used by Receiving and WIP*/
6264 BEGIN
6265 SELECT 1
6266 INTO l_process_flag_cnt
6267 FROM DUAL
6268 WHERE EXISTS(SELECT 1
6269 FROM mtl_txn_request_lines
6270 WHERE lpn_id = l_lpn_id
6271 AND organization_id = l_org_id
6272 AND NVL(wms_process_flag, 1) = 2
6273 AND line_status <> 5); -- 3773255
6274 EXCEPTION
6275 WHEN NO_DATA_FOUND THEN
6276 l_process_flag_cnt := 0;
6277 END;
6278
6279 IF l_process_flag_cnt > 0 THEN
6280 x_ret := 2;
6281
6282 IF (l_debug = 1) THEN
6283 mydebug('check_lpn_validity: wms_process_flag does not allow allocations/putaway');
6284 END IF;
6285 ELSE
6286 l_count := 0;
6287
6288 IF (l_debug = 1) THEN
6289 mydebug('check_lpn_validity: wms_process_flag allows allocations/putaway');
6290 END IF;
6291
6292
6293 -- Calling the ATF API Validate to check whether inspection is required or not.
6294 -- If MMTT is available for the LPN (pre-generate or in middle of operation cases)
6295 -- call validate_operation by passing the MMTT ID
6296 -- Else call validate_operation by passing the LPN ID
6297
6298 OPEN c_lpn_mmtt_cursor;
6299
6300 FETCH c_lpn_mmtt_cursor
6301 BULK COLLECT
6302 INTO l_tempid_tab;
6303
6304 -- MMTT records exist check
6305 IF l_tempid_tab.COUNT > 0 THEN
6306 -- The LPN passed has MMTT records so call validate_operation
6307
6308 -- Validate each MMTT record
6309 FOR i IN 1 .. l_tempid_tab.COUNT LOOP
6310
6311 wms_atf_runtime_pub_apis.validate_operation (
6312 x_return_status => x_return_status
6313 ,x_msg_data => x_msg_data
6314 ,x_msg_count => x_msg_count
6315 ,x_error_code => l_error_code
6316 ,x_inspection_flag => l_inspection_flag
6317 ,x_load_flag => l_load_flag
6318 ,x_drop_flag => l_drop_flag
6319 ,x_load_prim_quantity => l_load_prim_quantity
6320 ,x_drop_prim_quantity => l_drop_prim_quantity
6321 ,x_inspect_prim_quantity => l_insp_prim_quantity
6322 ,p_source_task_id => l_tempid_tab(i)
6323 ,p_move_order_line_id => NULL
6324 ,p_inventory_item_id => NULL
6325 ,p_lpn_id => NULL
6326 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
6327 ,p_organization_id => p_org_id
6328 );
6329
6330 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6331 IF (l_debug = 1) THEN
6332 mydebug('Check LPN Validity: validate_operation failed ' || x_msg_data );
6333 END IF;
6334 RAISE fnd_api.g_exc_error;
6335 END IF;
6336
6337 -- Bug# 3349802
6338 -- The variable l_count is initialized to 0 previously. For
6339 -- each MMTT record validated, if it requires inspection, then
6340 -- add 1 to l_count. Once we are done looping through all MMTT
6341 -- records, if l_count = 0 then that means all MMTT records do
6342 -- not require inspection. If l_count = l_tempid_tab.COUNT, then
6343 -- all MMTT records require inspection. Otherwise some of the
6344 -- MMTT records require inspection. We do not want to exit the
6345 -- validation loop if one of the MMTT records require
6346 -- inspection. Otherwise there would be no way to determine if
6347 -- partial inspection or full inspection is required for the LPN.
6348 IF (l_inspection_flag <> G_NO_INSPECTION) THEN
6349 -- This MMTT requires inspection
6350 mydebug('MMTT:'||l_tempid_tab(i)||' Requires inspection');
6351
6352 -- Increment l_count by 1
6353 l_count := l_count + 1;
6354 END IF;
6355
6356 END LOOP; -- Finished validating each MMTT record for the given LPN
6357
6358 -- Check the value for l_count to determine what type of
6359 -- inspection is required for the LPN. Also set the value
6360 -- of l_count to the appropriate value as before.
6361 IF (l_count = l_tempid_tab.COUNT) THEN
6362 l_count := 1;
6363 mydebug('All of the MMTT records require inspection');
6364 ELSIF (l_count = 0) THEN
6365 l_count := 0;
6366 mydebug('None of the MMTT records require inspection');
6367 ELSE
6368 l_count := 0;
6369 x_ret := 4;
6370 mydebug('Some of the MMTT records require inspection');
6371 END IF;
6372
6373 ELSE
6374 -- The LPN passed does not have MMTTs so call validate_operation by passing LPN ID
6375
6376 wms_atf_runtime_pub_apis.validate_operation (
6377 x_return_status => x_return_status
6378 ,x_msg_data => x_msg_data
6379 ,x_msg_count => x_msg_count
6380 ,x_error_code => l_error_code
6381 ,x_inspection_flag => l_inspection_flag
6382 ,x_load_flag => l_load_flag
6383 ,x_drop_flag => l_drop_flag
6384 ,x_load_prim_quantity => l_load_prim_quantity
6385 ,x_drop_prim_quantity => l_drop_prim_quantity
6386 ,x_inspect_prim_quantity => l_insp_prim_quantity
6387 ,p_source_task_id => NULL
6388 ,p_move_order_line_id => NULL
6389 ,p_inventory_item_id => NULL
6390 ,p_lpn_id => p_lpn_id
6391 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
6392 ,p_organization_id => p_org_id
6393 );
6394
6395 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6396 IF (l_debug = 1) THEN
6397 mydebug('Check LPN Validty:validate_operation failed ' || x_msg_data );
6398 END IF;
6399 RAISE fnd_api.g_exc_error;
6400 END IF;
6401
6402 IF (l_inspection_flag = g_partial_inspection) THEN
6403 mydebug('LPN: '|| p_lpn_id||' is partially inspected');
6404 l_count := 0;
6405 x_ret := 4;
6406 ELSIF (l_inspection_flag <> G_NO_INSPECTION) THEN
6407 -- This MMTT requires inspection, hence set the inspect req flag and exit out of the loop
6408 mydebug('LPN: '|| p_lpn_id||' Requires inspection. hence set the ret status to inspect required');
6409 -- Setting the flag which will indicate inspect is req
6410 l_count := 1;
6411 END IF;
6412
6413 END IF; -- MMTTS exists check
6414
6415
6416
6417 IF l_count > 0 THEN
6418 IF (l_debug = 1) THEN
6419 mydebug('check_lpn_validity: LPN Needs inspection');
6420 END IF;
6421
6422 x_ret := 1;
6423 END IF;
6424 END IF;
6425 END IF;
6426 ELSE
6427 IF (l_debug = 1) THEN
6428 mydebug('check_lpn_validity: It is an INV LPN');
6429 mydebug('check_lpn_validity: Verifying that this LPN has not been picked for any sales order');
6430 END IF;
6431
6432 BEGIN
6433 SELECT 1
6434 INTO l_so_cnt
6435 FROM DUAL
6436 WHERE EXISTS(
6437 SELECT 1
6438 FROM wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda
6439 WHERE wdd.lpn_id = l_lpn_id
6440 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
6441 AND wdd.organization_id = l_org_id
6442 AND wdd.delivery_detail_id = wda.parent_delivery_id);
6443 EXCEPTION
6444 WHEN NO_DATA_FOUND THEN
6445 l_so_cnt := 0;
6446 END;
6447
6448 IF l_so_cnt > 0 THEN
6449 IF (l_debug = 1) THEN
6450 mydebug('check_lpn_validity: LPN has been picked for a sales order and hence cannot be putaway');
6451 END IF;
6452
6453 x_ret := 3;
6454 END IF;
6455
6456 -- Fix for Bug No. : 2374961
6457 -- Since we are now commiting after detailing for an
6458 -- INV LPN (in suggestions_pub), we have to check to see if
6459 -- move orders exist
6460 -- if they do, it implies that somebody else is attempting to
6461 -- putaway the LPN
6462
6463 IF (l_debug = 1) THEN
6464 mydebug('check_lpn_validity: Verifying that this LPN is not in use');
6465 END IF;
6466
6467 --Checking whether this LPN is being processed by somebody else.
6468
6469 --Bug# 3116925
6470 --Get the employee ID so we can use it
6471 --for checking against the person_id column in WDT
6472 --because while creating the task, employee_id is stored.
6473 BEGIN
6474 SELECT employee_id
6475 INTO l_emp_id
6476 FROM fnd_user
6477 WHERE user_id = p_user_id;
6478 EXCEPTION
6479 WHEN NO_DATA_FOUND THEN
6480 IF (l_debug = 1) THEN
6481 mydebug('Check_LPN_Validity: There is no employee tied to the user');
6482 END IF;
6483 l_emp_id := NULL;
6484 END;
6485
6486 IF (l_debug = 1) THEN
6487 mydebug('Check_LPN_Validity: Emp Id ' || l_emp_id );
6488 END IF;
6489
6490 BEGIN
6491 SELECT 1
6492 INTO l_mo_cnt2
6493 FROM DUAL
6494 WHERE EXISTS(
6495 SELECT 1
6496 FROM wms_dispatched_tasks wdt
6497 , mtl_material_transactions_temp mmtt
6498 , mtl_txn_request_lines mtrl
6499 WHERE mtrl.lpn_id = l_lpn_id
6500 AND mtrl.organization_id = l_org_id
6501 AND mtrl.line_id = mmtt.move_order_line_id
6502 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
6503 AND wdt.status <> 4
6504 AND NOT (wdt.status = 3 AND wdt.person_id = l_emp_id ));--Bug# 3116925
6505 -- AND NOT(wdt.status = 3
6506 -- AND wdt.person_id = p_user_id));
6507 /*
6508 SELECT 1 INTO l_mo_cnt2 FROM DUAL WHERE exists
6509 (SELECT 1
6510 FROM mtl_txn_request_lines mol,
6511 mtl_material_transactions_temp mmtt
6512 , wms_dispatched_tasks wdt
6513 WHERE mol.lpn_id=l_lpn_id
6514 AND mol.organization_id=l_org_id
6515 AND mol.line_id=mmtt.move_order_line_id
6516 AND wdt.transaction_temp_id=mmtt.transaction_temp_id
6517 );
6518 */
6519 EXCEPTION
6520 WHEN NO_DATA_FOUND THEN
6521 l_mo_cnt2 := 0;
6522 END;
6523
6524 IF l_mo_cnt2 > 0 THEN
6525 IF (l_debug = 1) THEN
6526 mydebug('check_lpn_validity: LPN is being processed by somebody else and hence cannot be putaway');
6527 END IF;
6528
6529 x_ret := 3;
6530 fnd_message.set_name('WMS', 'WMS_LPN_UNAVAIL');
6531 fnd_msg_pub.ADD;
6532 RAISE fnd_api.g_exc_unexpected_error;
6533 END IF;
6534 END IF;
6535 END IF;
6536
6537 IF (l_debug = 1) THEN
6538 mydebug('check_lpn_validity: Ret Status' || l_return_status);
6539 END IF;
6540
6541 x_return_status := fnd_api.g_ret_sts_success;
6542 EXCEPTION
6543 WHEN OTHERS THEN
6544 x_return_status := fnd_api.g_ret_sts_unexp_error;
6545 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6546 END check_lpn_validity;
6547
6548 PROCEDURE archive_task(
6549 p_temp_id IN NUMBER
6550 , p_org_id IN NUMBER
6551 , x_return_status OUT NOCOPY VARCHAR2
6552 , x_msg_count OUT NOCOPY NUMBER
6553 , x_msg_data OUT NOCOPY VARCHAR2
6554 ) IS
6555 l_temp_id NUMBER;
6556 l_txn_header_id NUMBER;
6557 l_org_id NUMBER;
6558 l_return_status VARCHAR2(1);
6559 l_msg_count NUMBER;
6560 l_msg_data VARCHAR2(2000);
6561 l_mmtt_line_id NUMBER;
6562 l_mmtt_qty NUMBER;
6563 l_transaction_batch_id NUMBER;
6564 l_transaction_batch_seq NUMBER;
6565 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6566 BEGIN
6567 IF (l_debug = 1) THEN
6568 mydebug('In archive task..' || p_temp_id || ':' || p_org_id);
6569 END IF;
6570
6571 l_temp_id := p_temp_id;
6572 l_org_id := p_org_id;
6573
6574 IF (l_debug = 1) THEN
6575 mydebug('Get relevant info..');
6576 END IF;
6577
6578 SELECT move_order_line_id
6579 , transaction_quantity
6580 , transaction_header_id
6581 , transaction_batch_id
6582 , transaction_batch_seq
6583 INTO l_mmtt_line_id
6584 , l_mmtt_qty
6585 , l_txn_header_id
6586 , l_transaction_batch_id
6587 , l_transaction_batch_seq
6588 FROM mtl_material_transactions_temp
6589 WHERE transaction_temp_id = l_temp_id
6590 AND organization_id = l_org_id;
6591
6592 IF (l_debug = 1) THEN
6593 mydebug('Line id' || l_mmtt_line_id);
6594 mydebug('temp id' || l_temp_id);
6595 END IF;
6596
6597 -- Insert into WMS_DISPATCHED_TASKS_HISTORY with a status of 6, 'complete'
6598
6599 l_return_status := fnd_api.g_ret_sts_success;
6600 wms_insert_wdth_pvt.insert_into_wdth
6601 ( x_return_status => l_return_status
6602 , p_txn_header_id => l_txn_header_id
6603 , p_transaction_temp_id => l_temp_id
6604 , p_transaction_batch_id => l_transaction_batch_id
6605 , p_transaction_batch_seq => l_transaction_batch_seq
6606 , p_transfer_lpn_id => NULL
6607 );
6608
6609 IF l_return_status <> fnd_api.g_ret_sts_success
6610 THEN
6611 IF l_debug = 1 THEN
6612 mydebug ('Error from wms_insert_wdth_pvt.insert_into_wdth');
6613 END IF;
6614 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6615 END IF;
6616
6617 IF (l_debug = 1) THEN
6618 mydebug('After wmsdt update');
6619 END IF;
6620
6621 -- Delete this row from wms_dispatched_tasks
6622 DELETE wms_dispatched_tasks
6623 WHERE transaction_temp_id = l_temp_id;
6624
6625 -- Delete lot and serial records
6626 BEGIN
6627 DELETE mtl_serial_numbers_temp
6628 WHERE transaction_temp_id = (SELECT serial_transaction_temp_id
6629 FROM mtl_transaction_lots_temp
6630 WHERE transaction_temp_id = l_temp_id);
6631 EXCEPTION
6632 WHEN NO_DATA_FOUND THEN
6633 NULL;
6634 END;
6635
6636 BEGIN
6637 DELETE mtl_transaction_lots_temp
6638 WHERE transaction_temp_id = l_temp_id;
6639 EXCEPTION
6640 WHEN NO_DATA_FOUND THEN
6641 NULL;
6642 END;
6643
6644 BEGIN
6645 DELETE mtl_serial_numbers_temp
6646 WHERE transaction_temp_id = l_temp_id;
6647 EXCEPTION
6648 WHEN NO_DATA_FOUND THEN
6649 NULL;
6650 END;
6651
6652 -- Delete this row from mmtt
6653 DELETE mtl_material_transactions_temp
6654 WHERE transaction_temp_id = l_temp_id;
6655
6656 x_return_status := fnd_api.g_ret_sts_success;
6657
6658 IF (l_debug = 1) THEN
6659 mydebug('done WITH API');
6660 END IF;
6661 EXCEPTION
6662 WHEN OTHERS THEN
6663 x_return_status := fnd_api.g_ret_sts_error;
6664 fnd_message.set_name('WMS', 'WMS_TD_AT_FAIL');
6665 fnd_msg_pub.ADD;
6666 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6667 END archive_task;
6668
6669 PROCEDURE archive_task(
6670 p_temp_id IN NUMBER
6671 , p_org_id IN NUMBER
6672 , x_return_status OUT NOCOPY VARCHAR2
6673 , x_msg_count OUT NOCOPY NUMBER
6674 , x_msg_data OUT NOCOPY VARCHAR2
6675 , p_delete_mmtt_flag IN VARCHAR2
6676 , p_txn_header_id IN NUMBER
6677 , p_transfer_lpn_id IN NUMBER DEFAULT NULL
6678 ) IS
6679 l_temp_id NUMBER;
6680 l_org_id NUMBER;
6681 l_return_status VARCHAR2(1);
6682 l_msg_count NUMBER;
6683 l_msg_data VARCHAR2(2000);
6684 l_transaction_batch_id NUMBER;
6685 l_transaction_batch_seq NUMBER;
6686 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6687 BEGIN
6688 IF (l_debug = 1) THEN
6689 mydebug('archive_task: In archive task..' || p_temp_id || ':' || p_org_id);
6690 END IF;
6691
6692 l_temp_id := p_temp_id;
6693 l_org_id := p_org_id;
6694 l_return_status := fnd_api.g_ret_sts_success;
6695
6696
6697 /* Bug 3961107-Modified the query to select transaction_batch_id and transaction_batch_seq
6698 as null if they have null values in the table.
6699 SELECT NVL(transaction_batch_id, -999)
6700 , NVL(transaction_batch_seq, -999)*/
6701 SELECT transaction_batch_id,
6702 transaction_batch_seq
6703 --End of fix for Bug 3961107
6704 INTO l_transaction_batch_id
6705 , l_transaction_batch_seq
6706 FROM mtl_material_transactions_temp
6707 WHERE transaction_temp_id = l_temp_id
6708 AND organization_id = l_org_id;
6709
6710 IF (l_debug = 1) THEN
6711 mydebug('Temp ID: ' || l_temp_id);
6712 mydebug('Batch ID: ' || l_transaction_batch_id);
6713 mydebug('Batch Seq: ' || l_transaction_batch_seq);
6714 END IF;
6715
6716 -- Insert into WMS_DISPATCHED_TASKS_HISTORY with a status of 6, 'complete'
6717
6718 l_return_status := fnd_api.g_ret_sts_success;
6719 wms_insert_wdth_pvt.insert_into_wdth
6720 ( x_return_status => l_return_status
6721 , p_txn_header_id => p_txn_header_id
6722 , p_transaction_temp_id => l_temp_id
6723 , p_transaction_batch_id => l_transaction_batch_id
6724 , p_transaction_batch_seq => l_transaction_batch_seq
6725 , p_transfer_lpn_id => p_transfer_lpn_id
6726 );
6727
6728 IF l_return_status <> fnd_api.g_ret_sts_success
6729 THEN
6730 IF l_debug = 1 THEN
6731 mydebug ('Error from wms_insert_wdth_pvt.insert_into_wdth');
6732 END IF;
6733 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6734 END IF;
6735
6736 -- Delete this row from wms_dispatched_tasks
6737 DELETE FROM wms_dispatched_tasks
6738 WHERE transaction_temp_id = l_temp_id;
6739
6740 IF (l_debug = 1) THEN
6741 mydebug('archive_task: After wmsdt update');
6742 END IF;
6743
6744 IF p_delete_mmtt_flag = 'Y' THEN
6745 -- Delete lot and serial records
6746 BEGIN
6747 DELETE mtl_serial_numbers_temp
6748 WHERE transaction_temp_id IN
6749 (SELECT serial_transaction_temp_id
6750 FROM mtl_transaction_lots_temp
6751 WHERE transaction_temp_id = l_temp_id);
6752 EXCEPTION
6753 WHEN OTHERS THEN
6754 mydebug('archive_task: Error deleting MSNT for MTLT: ' || sqlerrm);
6755 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6756 END;
6757
6758 BEGIN
6759 DELETE mtl_transaction_lots_temp
6760 WHERE transaction_temp_id = l_temp_id;
6761 EXCEPTION
6762 WHEN OTHERS THEN
6763 mydebug('archive_task: Error deleting MTLT: ' || sqlerrm);
6764 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6765 END;
6766
6767 BEGIN
6768 DELETE mtl_serial_numbers_temp
6769 WHERE transaction_temp_id = l_temp_id;
6770 EXCEPTION
6771 WHEN OTHERS THEN
6772 mydebug('archive_task: Error deleting MSNT: ' || sqlerrm);
6773 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6774 END;
6775
6776 BEGIN
6777 DELETE mtl_material_transactions_temp
6778 WHERE transaction_temp_id = l_temp_id;
6779 EXCEPTION
6780 WHEN OTHERS THEN
6781 mydebug('archive_task: Error deleting MMTT: ' || sqlerrm);
6782 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6783 END;
6784 END IF;
6785
6786 x_return_status := fnd_api.g_ret_sts_success;
6787
6788 IF (l_debug = 1) THEN
6789 mydebug('archive_task: done WITH API');
6790 END IF;
6791 EXCEPTION
6792 WHEN OTHERS THEN
6793 IF (l_debug = 1) THEN
6794 mydebug('Other exception occurred: ' || sqlerrm);
6795 END IF;
6796
6797 x_return_status := fnd_api.g_ret_sts_error;
6798 fnd_message.set_name('WMS', 'WMS_TD_AT_FAIL');
6799 fnd_msg_pub.ADD;
6800 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
6801 END archive_task;
6802
6803 PROCEDURE putaway_cleanup(
6804 p_temp_id IN NUMBER
6805 , p_org_id IN NUMBER
6806 , x_return_status OUT NOCOPY VARCHAR2
6807 , x_msg_count OUT NOCOPY NUMBER
6808 , x_msg_data OUT NOCOPY VARCHAR2
6809 ) IS
6810 l_temp_id NUMBER;
6811 l_txn_header_id NUMBER;
6812 l_org_id NUMBER;
6813 l_return_status VARCHAR2(1);
6814 l_msg_count NUMBER;
6815 l_msg_data VARCHAR2(2000);
6816 l_mmtt_line_id NUMBER;
6817 l_mmtt_qty NUMBER;
6818 l_item_id NUMBER;
6819 l_person_id NUMBER;
6820 l_loc_id NUMBER;
6821 l_sub VARCHAR2(10);
6822 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
6823 l_lot VARCHAR2(80);
6824 l_rev VARCHAR2(3);
6825 l_last_updated_by NUMBER;
6826 l_sequence NUMBER;
6827 cnt NUMBER := 0;
6828 l_back_id NUMBER := 0;
6829 l_crdk_type NUMBER := 0;
6830 l_demand_source_header_id NUMBER := -1;
6831 l_repetitive_line_id NUMBER := -1;
6832 l_operation_seq_num NUMBER := -1;
6833 l_primary_qty NUMBER := -1;
6834 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6835 -- Following variables added in ATF_J4
6836
6837
6838 l_secondary_quantity NUMBER; --OPM Convergence
6839 -- End variables added in ATF_J4
6840
6841 -- Bug# 3281512 - Performance Fixes
6842 -- Add cursor to get serial_transaction_temp_id values for performance.
6843 -- SQL compiler complains of a Hash Join otherwise.
6844 CURSOR c_serial_transaction_temp_id IS
6845 SELECT serial_transaction_temp_id
6846 FROM mtl_transaction_lots_temp
6847 WHERE transaction_temp_id = l_temp_id;
6848 l_serial_transaction_temp_id NUMBER;
6849 -- Bug# 3434940 - Performance Fixes
6850 -- Add cursor to get the serial number(s) for a given MSNT record.
6851 -- SQL compiler complains of a Hash Join otherwise.
6852 CURSOR c_serial_number(v_transaction_temp_id NUMBER) IS
6853 SELECT fm_serial_number
6854 FROM mtl_serial_numbers_temp
6855 WHERE transaction_temp_id = v_transaction_temp_id;
6856 l_fm_serial_number NUMBER;
6857
6858 BEGIN
6859 IF (l_debug = 1) THEN
6860 mydebug('In putaway cleanup..');
6861 END IF;
6862
6863 l_temp_id := p_temp_id;
6864 l_org_id := p_org_id;
6865 l_return_status := fnd_api.g_ret_sts_success;
6866
6867 IF (l_debug = 1) THEN
6868 mydebug('Get relevant info..');
6869 END IF;
6870
6871 SELECT t.move_order_line_id
6872 , t.transaction_quantity
6873 , t.inventory_item_id
6874 , t.primary_quantity
6875 , w.person_id
6876 , t.locator_id
6877 , t.subinventory_code
6878 , t.lot_number
6879 , t.revision
6880 , t.last_updated_by
6881 , t.demand_source_header_id
6882 , t.repetitive_line_id
6883 , t.operation_seq_num
6884 , t.secondary_transaction_quantity --OPM Convergence
6885 INTO l_mmtt_line_id
6886 , l_mmtt_qty
6887 , l_item_id
6888 , l_primary_qty
6889 , l_person_id
6890 , l_loc_id
6891 , l_sub
6892 , l_lot
6893 , l_rev
6894 , l_last_updated_by
6895 , l_demand_source_header_id
6896 , l_repetitive_line_id
6897 , l_operation_seq_num
6898 , l_secondary_quantity --OPM Convergence
6899 FROM mtl_material_transactions_temp t, wms_dispatched_tasks w
6900 WHERE t.transaction_temp_id = l_temp_id
6901 AND t.organization_id = l_org_id
6902 AND t.transaction_temp_id = w.transaction_temp_id;
6903
6904 IF (l_debug = 1) THEN
6905 mydebug('Line id' || l_mmtt_line_id);
6906 END IF;
6907
6908 -- Log exception
6909
6910 --Calculate Sequence Number
6911 SELECT wms_exceptions_s.NEXTVAL
6912 INTO l_sequence
6913 FROM DUAL;
6914
6915 IF (l_debug = 1) THEN
6916 mydebug('Inserting into exceptions');
6917 mydebug(l_sequence);
6918 END IF;
6919
6920 INSERT INTO wms_exceptions
6921 (
6922 task_id
6923 , sequence_number
6924 , organization_id
6925 , inventory_item_id
6926 , person_id
6927 , effective_start_date
6928 , effective_end_date
6929 , inventory_location_id
6930 , reason_id
6931 , discrepancy_type
6932 , subinventory_code
6933 , lot_number
6934 , revision
6935 , last_update_date
6936 , last_updated_by
6937 , creation_date
6938 , created_by
6939 )
6940 VALUES (
6941 l_temp_id
6942 , l_sequence
6943 , l_org_id
6944 , l_item_id
6945 , l_person_id
6946 , SYSDATE
6947 , SYSDATE
6948 , l_loc_id
6949 , -999
6950 , 2
6951 , l_sub
6952 , l_lot
6953 , l_rev
6954 , SYSDATE
6955 , l_last_updated_by
6956 , SYSDATE
6957 , l_last_updated_by
6958 );
6959
6960 -- ATF_J4
6961 -- If current release is J or above, do not
6962 -- update move order line, delete MMTT and revert crossdocking.
6963 -- Because cleanup can happen at an operation in the middle of
6964 -- an operation plan.
6965 -- If MMTT is not tied to an active operation plan,
6966 -- delete MMTT and update move order line will happen in suggestions_PUB;
6967 -- Not reverting crossdocking is probably not optimal, but safe.
6968
6969
6970 -- Cleanup the serials before Deleting MMTT
6971 IF (l_debug = 1) THEN
6972 mydebug('Updating Group_mark_id for Serials ');
6973 END IF;
6974
6975 -- Update for Lot/Serial controlled item
6976 -- Bug# 3281512 - Performance Fixes
6977 -- Use the c_serial_transaction_temp_id cursor to avoid the hash join.
6978 -- Also match against MSN using the item and the org to use the indexes more efficiently.
6979 -- Bug# 3434940 - Performance Fixes
6980 -- Also create and use another cursor, c_serial_number to avoid the
6981 -- hash join. This cursor will loop through the serials in MSNT for
6982 -- the given transaction temp id.
6983 OPEN c_serial_transaction_temp_id;
6984 LOOP
6985 FETCH c_serial_transaction_temp_id INTO l_serial_transaction_temp_id;
6986 EXIT WHEN c_serial_transaction_temp_id%NOTFOUND;
6987
6988 OPEN c_serial_number(l_serial_transaction_temp_id);
6989 LOOP
6990 FETCH c_serial_number INTO l_fm_serial_number;
6991 EXIT WHEN c_serial_number%NOTFOUND;
6992
6993 UPDATE mtl_serial_numbers
6994 SET group_mark_id = NULL
6995 WHERE serial_number = l_fm_serial_number
6996 AND inventory_item_id = l_item_id
6997 AND current_organization_id = l_org_id;
6998
6999 END LOOP;
7000 CLOSE c_serial_number;
7001
7002 END LOOP;
7003 CLOSE c_serial_transaction_temp_id;
7004
7005 -- Update for Serial controlled item
7006 -- Bug# 3281512 - Performance Fixes
7007 -- Match against MSN using the item and org to use the indexes more efficiently.
7008 -- Bug# 3434940 - Performance Fixes
7009 -- Also create and use another cursor, c_serial_number to avoid the
7010 -- hash join. This cursor will loop through the serials in MSNT for
7011 -- the given transaction temp id.
7012 OPEN c_serial_number(l_temp_id);
7013 LOOP
7014 FETCH c_serial_number INTO l_fm_serial_number;
7015 EXIT WHEN c_serial_number%NOTFOUND;
7016
7017 UPDATE mtl_serial_numbers
7018 SET group_mark_id = NULL
7019 WHERE serial_number = l_fm_serial_number
7020 AND inventory_item_id = l_item_id
7021 AND current_organization_id = l_org_id;
7022
7023 END LOOP;
7024 CLOSE c_serial_number;
7025
7026 -- Bug 2458540
7027 -- Reset the Status Back if putaway fails
7028 -- For cases with RMA and serial at sales order Issue
7029
7030 -- Update for Lot/Serial controlled item
7031 -- Bug# 3281512 - Performance Fixes
7032 -- Use the cursor to avoid the hash join. Also match against MSN using
7033 -- the org to use the indexes more efficiently.
7034 -- Bug# 3434940 - Performance Fixes
7035 -- Also create and use another cursor, c_serial_number to avoid the
7036 -- hash join. This cursor will loop through the serials in MSNT for
7037 -- the given transaction temp id.
7038 OPEN c_serial_transaction_temp_id;
7039 LOOP
7040 FETCH c_serial_transaction_temp_id INTO l_serial_transaction_temp_id;
7041 EXIT WHEN c_serial_transaction_temp_id%NOTFOUND;
7042
7043 OPEN c_serial_number(l_serial_transaction_temp_id);
7044 LOOP
7045 FETCH c_serial_number INTO l_fm_serial_number;
7046 EXIT WHEN c_serial_number%NOTFOUND;
7047
7048 UPDATE mtl_serial_numbers
7049 SET current_status = 5,
7050 previous_status = NULL
7051 WHERE serial_number = l_fm_serial_number
7052 AND inventory_item_id = l_item_id
7053 AND lot_number = l_lot
7054 AND current_status = 4
7055 AND current_organization_id = l_org_id
7056 AND EXISTS (SELECT 1
7057 FROM mtl_txn_request_lines mol
7058 WHERE mol.line_id = l_mmtt_line_id
7059 AND mol.REFERENCE = 'ORDER_LINE_ID');
7060 END LOOP;
7061 CLOSE c_serial_number;
7062
7063 END LOOP;
7064 CLOSE c_serial_transaction_temp_id;
7065
7066 -- Update for Serial controlled item
7067 -- Bug# 3281512 - Performance Fixes
7068 -- Match against MSN using the item and org to use the indexes more efficiently.
7069 -- Bug# 3434940 - Performance Fixes
7070 -- Also create and use another cursor, c_serial_number to avoid the
7071 -- hash join. This cursor will loop through the serials in MSNT for
7072 -- the given transaction temp id.
7073 OPEN c_serial_number(l_temp_id);
7074 LOOP
7075 FETCH c_serial_number INTO l_fm_serial_number;
7076 EXIT WHEN c_serial_number%NOTFOUND;
7077
7078 UPDATE mtl_serial_numbers
7079 SET current_status = 5,
7080 previous_status = NULL
7081 WHERE serial_number = l_fm_serial_number
7082 AND inventory_item_id = l_item_id
7083 AND current_status = 4
7084 AND current_organization_id = l_org_id
7085 AND EXISTS (SELECT 1
7086 FROM mtl_txn_request_lines mol
7087 WHERE mol.line_id = l_mmtt_line_id
7088 AND mol.REFERENCE = 'ORDER_LINE_ID');
7089 END LOOP;
7090 CLOSE c_serial_number;
7091
7092
7093 x_return_status := l_return_status;
7094
7095 --x_return_status:=FND_API.G_RET_STS_SUCCESS;
7096 IF (l_debug = 1) THEN
7097 mydebug('done WITH API');
7098 END IF;
7099 EXCEPTION
7100 WHEN OTHERS THEN
7101 x_return_status := fnd_api.g_ret_sts_error;
7102 fnd_message.set_name('WMS', 'WMS_TD_PUT_CLEAN_FAIL');
7103 fnd_msg_pub.ADD;
7104 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7105 END putaway_cleanup;
7106
7107 PROCEDURE validate_putaway_to_lpn(
7108 p_org_id IN NUMBER
7109 , p_to_lpn IN VARCHAR2
7110 , p_from_lpn IN VARCHAR2
7111 , p_sub IN VARCHAR2
7112 , p_loc_id IN NUMBER
7113 , x_return_status OUT NOCOPY VARCHAR2
7114 , x_msg_count OUT NOCOPY NUMBER
7115 , x_msg_data OUT NOCOPY VARCHAR2
7116 , x_return OUT NOCOPY NUMBER
7117 , p_crossdock IN VARCHAR2 DEFAULT NULL
7118 ) IS
7119 l_count NUMBER;
7120 l_to_lpn_id NUMBER;
7121 l_lpn_context NUMBER;
7122 l_quantity NUMBER;
7123 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7124
7125 -- Bug 4411792
7126 l_lpn_update WMS_CONTAINER_PUB.LPN;
7127 l_return_status VARCHAR2(1);
7128 l_msg_count NUMBER;
7129 l_msg_data VARCHAR2(2000);
7130
7131
7132 BEGIN
7133 IF (l_debug = 1) THEN
7134 mydebug('validate_putaway_to_lpn : validate_putaway_to_lpn Entered');
7135 END IF;
7136
7137 x_return := 0;
7138 l_count := 0;
7139 x_return_status := fnd_api.g_ret_sts_success;
7140
7141 BEGIN
7142 SELECT 1
7143 , lpn_id
7144 INTO l_count
7145 , l_to_lpn_id
7146 FROM wms_license_plate_numbers wlpn
7147 WHERE wlpn.license_plate_number = p_to_lpn
7148 AND wlpn.organization_id = p_org_id;
7149 EXCEPTION
7150 WHEN NO_DATA_FOUND THEN
7151 l_count := 0;
7152 END;
7153
7154 IF l_count = 0 THEN
7155 -- New LPN
7156 IF (l_debug = 1) THEN
7157 mydebug('validate_putaway_to_lpn : LPN does not exist. Create new LPN');
7158 END IF;
7159
7160 wms_task_dispatch_gen.create_lpn(
7161 p_organization_id => p_org_id
7162 , p_lpn => p_to_lpn
7163 , p_lpn_id => l_to_lpn_id
7164 , x_return_status => x_return_status
7165 , x_msg_count => x_msg_count
7166 , x_msg_data => x_msg_data
7167 );
7168
7169 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
7170 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
7171 fnd_msg_pub.ADD;
7172 RAISE fnd_api.g_exc_unexpected_error;
7173 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
7174 fnd_message.set_name('WMS', 'WMS_TD_CREATE_LPN_ERROR');
7175 fnd_msg_pub.ADD;
7176 RAISE fnd_api.g_exc_error;
7177 END IF;
7178
7179 x_return := 1;
7180 ELSE
7181 IF (l_debug = 1) THEN
7182 mydebug('validate_putaway_to_lpn : LPN already exists. Check to see if the LPN resides in the sub/loc');
7183 mydebug('From LPN ID: ' || p_from_lpn || ' To LPN ID: ' || p_to_lpn);
7184 END IF;
7185
7186 -- Check from LPN and to LPN match
7187 -- bug fix 2271470
7188
7189 IF p_from_lpn <> p_to_lpn THEN
7190 -- Bug Fix 2505636
7191 IF p_crossdock = 'Y' THEN
7192 IF (l_debug = 1) THEN
7193 mydebug('LPN crossdocked and from and to lpn different');
7194 END IF;
7195
7196 BEGIN
7197 -- Check the LPN Content it should be null
7198 SELECT quantity
7199 INTO l_quantity
7200 FROM wms_lpn_contents
7201 WHERE parent_lpn_id = l_to_lpn_id
7202 AND ROWNUM < 2;
7203
7204 --
7205 IF l_quantity >= 0 THEN
7206 IF (l_debug = 1) THEN
7207 mydebug('LPN has contents so can not putaway');
7208 END IF;
7209
7210 x_return := 0;
7211 RETURN;
7212 END IF;
7213 EXCEPTION
7214 WHEN NO_DATA_FOUND THEN
7215 IF (l_debug = 1) THEN
7216 mydebug('LPN has no contents so should be OK to putaway');
7217 END IF;
7218 END;
7219 END IF;
7220
7221 l_count := 0;
7222
7223 BEGIN
7224 SELECT 1
7225 INTO l_count
7226 FROM DUAL
7227 WHERE EXISTS(
7228 SELECT 1
7229 FROM mtl_material_transactions_temp mmtt
7230 WHERE (
7231 NVL(mmtt.subinventory_code, '@') <> NVL(p_sub, NVL(mmtt.subinventory_code, '@'))
7232 OR NVL(mmtt.locator_id, '0') <> NVL(p_loc_id, NVL(mmtt.locator_id, '0'))
7233 )
7234 AND mmtt.organization_id = p_org_id
7235 AND mmtt.transaction_status = 3
7236 AND mmtt.transfer_lpn_id = l_to_lpn_id);
7237 EXCEPTION
7238 WHEN NO_DATA_FOUND THEN
7239 l_count := 0;
7240 END;
7241
7242 IF l_count > 0 THEN
7243 x_return := 0;
7244
7245 IF (l_debug = 1) THEN
7246 mydebug('validate_putaway_to_lpn: LPN has a pending transaction going to different location');
7247 END IF;
7248
7249 RETURN;
7250 END IF;
7251
7252 IF (l_debug = 1) THEN
7253 mydebug('p_org_id : ' || p_org_id);
7254 mydebug('p_to_lpn : ' || p_to_lpn);
7255 mydebug('p_sub : ' || p_sub);
7256 mydebug('p_loc_id : ' || p_loc_id);
7257 mydebug('p_from_lpn : ' || p_from_lpn);
7258 END IF;
7259
7260 BEGIN
7261 SELECT 1
7262 INTO l_count
7263 FROM DUAL
7264 WHERE EXISTS(
7265 SELECT 1
7266 FROM wms_license_plate_numbers wlpn
7267 WHERE wlpn.organization_id = p_org_id
7268 AND license_plate_number = p_to_lpn
7269 AND (
7270 wlpn.lpn_context = 5
7271 OR(wlpn.lpn_context = 1
7272 AND wlpn.subinventory_code IS NULL
7273 AND wlpn.locator_id IS NULL)
7274 OR(
7275 wlpn.lpn_context = 1
7276 AND NVL(wlpn.subinventory_code, '@') = NVL(p_sub, NVL(wlpn.subinventory_code, '@'))
7277 AND NVL(wlpn.locator_id, '0') = NVL(p_loc_id, NVL(wlpn.locator_id, '0'))
7278 AND NOT wlpn.license_plate_number = NVL(p_from_lpn, -999)
7279 AND inv_material_status_grp.is_status_applicable(
7280 'TRUE'
7281 , NULL
7282 , inv_globals.g_type_container_pack
7283 , NULL
7284 , NULL
7285 , p_org_id
7286 , NULL
7287 , wlpn.subinventory_code
7288 , wlpn.locator_id
7289 , NULL
7290 , NULL
7291 , 'Z'
7292 ) = 'Y'
7293 AND inv_material_status_grp.is_status_applicable(
7294 'TRUE'
7295 , NULL
7296 , inv_globals.g_type_container_pack
7297 , NULL
7298 , NULL
7299 , p_org_id
7300 , NULL
7301 , wlpn.subinventory_code
7302 , wlpn.locator_id
7303 , NULL
7304 , NULL
7305 , 'L'
7306 ) = 'Y'
7307 )
7308 ));
7309 EXCEPTION
7310 WHEN NO_DATA_FOUND THEN
7311 l_count := 0;
7312
7313 IF (l_debug = 1) THEN
7314 mydebug('validate_putaway_to_lpn: No data found');
7315 END IF;
7316 END;
7317
7318 IF l_count > 0 THEN
7319 x_return := 1;
7320
7321 IF (l_debug = 1) THEN
7322 mydebug('validate_putaway_to_lpn: LPN exists in the sub/loc or is defined but not used');
7323 END IF;
7324 ELSE
7325 x_return := 0;
7326
7327 IF (l_debug = 1) THEN
7328 mydebug('validate_putaway_to_lpn: LPN does not exist in the sub/loc');
7329 END IF;
7330 END IF;
7331 -- bug fix 2271470
7332 ELSE -- p_from_lpn = p_to_lpn
7333 BEGIN
7334 SELECT COUNT(1)
7335 INTO l_count
7336 FROM mtl_txn_request_lines mol
7337 WHERE mol.lpn_id = l_to_lpn_id
7338 AND mol.line_status <> inv_globals.g_to_status_closed
7339 AND (
7340 (mol.quantity - NVL(mol.quantity_delivered, 0)) > (SELECT SUM(mmtt.transaction_quantity)
7341 FROM mtl_material_transactions_temp mmtt
7342 WHERE mmtt.move_order_line_id = mol.line_id)
7343 OR(mol.quantity - NVL(mol.quantity_delivered, 0) > 0
7344 AND NOT EXISTS(SELECT 1
7345 FROM mtl_material_transactions_temp mmtt
7346 WHERE mmtt.move_order_line_id = mol.line_id))
7347 );
7348
7349 IF (l_debug = 1) THEN
7350 mydebug('l_count = ' || l_count);
7351 END IF;
7352 EXCEPTION
7353 WHEN NO_DATA_FOUND THEN
7354 l_count := 0;
7355 END;
7356
7357 IF l_count > 0 THEN
7358 x_return := 0;
7359
7360 IF (l_debug = 1) THEN
7361 mydebug(
7362 'Validate_putaway_to_lpn: LPN has a pending transaction with quantity less then the difference between total quantity on MOL and quantity delivered. Cannot putaway this LPN.'
7363 );
7364 END IF;
7365
7366 RETURN;
7367 ELSE
7368 x_return := 1;
7369 RETURN;
7370 END IF;
7371 END IF;
7372 END IF;
7373
7374 SELECT wlc.lpn_context
7375 INTO l_lpn_context
7376 FROM wms_license_plate_numbers wlc
7377 WHERE wlc.license_plate_number = p_to_lpn
7378 AND wlc.organization_id = p_org_id;
7379
7380 IF (l_debug = 1) THEN
7381 mydebug('lpn_context = ' || l_lpn_context);
7382 END IF;
7383
7384 IF l_lpn_context = wms_container_pub.lpn_context_pregenerated THEN
7385 IF (l_debug = 1) THEN
7386 mydebug('update LPN context to 1');
7387 END IF;
7388
7389 -- Bug 4411792
7390 l_lpn_update.license_plate_number := p_to_lpn;
7391 l_lpn_update.organization_id := p_org_id;
7392 l_lpn_update.lpn_context := wms_container_pub.lpn_context_inv;
7393
7394 wms_container_pvt.Modify_LPN
7395 (
7396 p_api_version => 1.0
7397 , p_validation_level => fnd_api.g_valid_level_none
7398 , x_return_status => l_return_status
7399 , x_msg_count => l_msg_count
7400 , x_msg_data => l_msg_data
7401 , p_lpn => l_lpn_update
7402 ) ;
7403
7404 l_lpn_update := NULL;
7405
7406 -- 4411792 The below is replaced by the above API call
7407 --UPDATE wms_license_plate_numbers
7408 --SET lpn_context = wms_container_pub.lpn_context_inv
7409 --WHERE license_plate_number = p_to_lpn
7410 --AND organization_id = p_org_id;
7411
7412 END IF;
7413
7414 x_return_status := fnd_api.g_ret_sts_success;
7415 EXCEPTION
7416 WHEN OTHERS THEN
7417 IF (l_debug = 1) THEN
7418 mydebug('validate_putaway_to_lpn : Exception : ' || SQLERRM);
7419 END IF;
7420
7421 x_return_status := fnd_api.g_ret_sts_error;
7422 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
7423 fnd_msg_pub.ADD;
7424 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7425 END validate_putaway_to_lpn;
7426
7427 /* This API will check the status of the mmtt lines
7428 This will be called from the suggestions_api, as part of the putaway
7429 process We need to do this at the mmtt line level rather than just
7430 checking the lpn contents because the transaction type id might differ
7431 in each MOL. Returns x_mtl_stat 0 if everything is fine, 1 otherwise*/
7432 PROCEDURE check_mmtt_mtl_status(
7433 p_temp_id IN VARCHAR2
7434 , p_org_id IN NUMBER
7435 , x_mtl_status OUT NOCOPY NUMBER
7436 , x_return_status OUT NOCOPY VARCHAR2
7437 , x_msg_count OUT NOCOPY NUMBER
7438 , x_msg_data OUT NOCOPY VARCHAR2
7439 ) IS
7440 l_temp_id NUMBER;
7441 l_org_id NUMBER;
7442 l_serial_temp_id NUMBER;
7443 l_txn_type_id NUMBER;
7444 l_ser_control_code NUMBER;
7445 l_lot_control_code NUMBER;
7446 l_item_id NUMBER;
7447 l_serial_number VARCHAR2(30);
7448 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
7449 l_lot_number VARCHAR2(80);
7450 l_sub VARCHAR2(30);
7451 l_loc NUMBER;
7452 l_lpn_id NUMBER;
7453
7454 CURSOR lot_csr IS
7455 SELECT lot_number
7456 , serial_transaction_temp_id
7457 FROM mtl_transaction_lots_temp
7458 WHERE transaction_temp_id = l_temp_id;
7459
7460 CURSOR ser_csr IS
7461 SELECT serial_number
7462 FROM mtl_serial_numbers
7463 WHERE lpn_id = l_lpn_id
7464 AND inventory_item_id = l_item_id
7465 AND current_organization_id = l_org_id
7466 AND NVL(lot_number, -999) = NVL(l_lot_number, -999);
7467
7468 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7469 BEGIN
7470 IF (l_debug = 1) THEN
7471 mydebug('in check_mmtt_mtl_status api');
7472 mydebug('p_temp_id => ' || p_temp_id);
7473 mydebug('p_org_id => ' || p_org_id);
7474 END IF;
7475
7476 x_return_status := fnd_api.g_ret_sts_success;
7477 x_mtl_status := 0;
7478 l_temp_id := p_temp_id;
7479 l_org_id := p_org_id;
7480 l_lot_number := NULL;
7481
7482 SELECT msi.lot_control_code
7483 , msi.serial_number_control_code
7484 , mmtt.transaction_type_id
7485 , mmtt.inventory_item_id
7486 , DECODE(mmtt.transaction_action_id, 2, mmtt.transfer_subinventory, subinventory_code) sub
7487 , DECODE(mmtt.transaction_action_id, 2, mmtt.transfer_to_location, locator_id)
7488 , lpn_id
7489 INTO l_lot_control_code
7490 , l_ser_control_code
7491 , l_txn_type_id
7492 , l_item_id
7493 , l_sub
7494 , l_loc
7495 , l_lpn_id
7496 FROM mtl_system_items msi, mtl_material_transactions_temp mmtt
7497 WHERE mmtt.organization_id = l_org_id
7498 AND mmtt.transaction_temp_id = l_temp_id
7499 AND msi.organization_id = mmtt.organization_id
7500 AND msi.inventory_item_id = mmtt.inventory_item_id;
7501
7502 IF (l_debug = 1) THEN
7503 mydebug('check_mmtt_mtl_status: After getting relevant info..');
7504 mydebug('check_mmtt_mtl_status: Lot Code: ' || l_lot_control_code);
7505 mydebug('check_mmtt_mtl_status: Ser Code: ' || l_ser_control_code);
7506 mydebug('check_mmtt_mtl_status: Tran Type ID: ' || l_txn_type_id);
7507 mydebug('check_mmtt_mtl_status: Item: ' || l_item_id);
7508 END IF;
7509
7510 IF l_lot_control_code > 1 THEN
7511 IF (l_debug = 1) THEN
7512 mydebug('check_mmtt_mtl_status: Lot controlled');
7513 END IF;
7514
7515 -- lot controlled - CHECK lot status
7516 OPEN lot_csr;
7517
7518 LOOP
7519 FETCH lot_csr INTO l_lot_number, l_serial_temp_id;
7520 EXIT WHEN lot_csr%NOTFOUND;
7521
7522 IF l_ser_control_code > 1
7523 AND l_ser_control_code <> 6 THEN
7524 IF (l_debug = 1) THEN
7525 mydebug('check_mmtt_mtl_status: Lot and serial controlled');
7526 END IF;
7527
7528 OPEN ser_csr;
7529
7530 LOOP
7531 FETCH ser_csr INTO l_serial_number;
7532 EXIT WHEN ser_csr%NOTFOUND;
7533
7534 IF inv_material_status_grp.is_status_applicable(
7535 p_wms_installed => 'TRUE'
7536 , p_trx_status_enabled => NULL
7537 , p_trx_type_id => l_txn_type_id
7538 , p_lot_status_enabled => NULL
7539 , p_serial_status_enabled => NULL
7540 , p_organization_id => l_org_id
7541 , p_inventory_item_id => l_item_id
7542 , p_sub_code => NULL
7543 , p_locator_id => NULL
7544 , p_lot_number => l_lot_number
7545 , p_serial_number => l_serial_number
7546 , p_object_type => 'A'
7547 ) = 'N' THEN
7548 IF (l_debug = 1) THEN
7549 mydebug('check_mmtt_mtl_status: After 0');
7550 END IF;
7551
7552 x_mtl_status := 1;
7553 RETURN;
7554 END IF;
7555 END LOOP;
7556
7557 CLOSE ser_csr;
7558 ELSE
7559 IF inv_material_status_grp.is_status_applicable(
7560 p_wms_installed => 'TRUE'
7561 , p_trx_status_enabled => NULL
7562 , p_trx_type_id => l_txn_type_id
7563 , p_lot_status_enabled => NULL
7564 , p_serial_status_enabled => NULL
7565 , p_organization_id => l_org_id
7566 , p_inventory_item_id => l_item_id
7567 , p_sub_code => NULL
7568 , p_locator_id => NULL
7569 , p_lot_number => l_lot_number
7570 , p_serial_number => NULL
7571 , p_object_type => 'O'
7572 ) = 'N' THEN
7573 IF (l_debug = 1) THEN
7574 mydebug('check_mmtt_mtl_status: After 1');
7575 END IF;
7576
7577 x_mtl_status := 1;
7578 RETURN;
7579 END IF;
7580 END IF;
7581 END LOOP;
7582
7583 CLOSE lot_csr;
7584 ELSIF l_ser_control_code > 1
7585 AND l_ser_control_code <> 6 THEN
7586 IF (l_debug = 1) THEN
7587 mydebug('check_mmtt_mtl_status: Serial controlled only');
7588 END IF;
7589
7590 l_serial_temp_id := l_temp_id;
7591 -- serial controlled - CHECK serial status
7592 OPEN ser_csr;
7593
7594 LOOP
7595 FETCH ser_csr INTO l_serial_number;
7596 EXIT WHEN ser_csr%NOTFOUND;
7597
7598 IF inv_material_status_grp.is_status_applicable(
7599 p_wms_installed => 'TRUE'
7600 , p_trx_status_enabled => NULL
7601 , p_trx_type_id => l_txn_type_id
7602 , p_lot_status_enabled => NULL
7603 , p_serial_status_enabled => NULL
7604 , p_organization_id => l_org_id
7605 , p_inventory_item_id => l_item_id
7606 , p_sub_code => NULL
7607 , p_locator_id => NULL
7608 , p_lot_number => NULL
7609 , p_serial_number => l_serial_number
7610 , p_object_type => 'S'
7611 ) = 'N' THEN
7612 IF (l_debug = 1) THEN
7613 mydebug('check_mmtt_mtl_status: After 6');
7614 END IF;
7615
7616 x_mtl_status := 1;
7617 RETURN;
7618 END IF;
7619 END LOOP;
7620
7621 CLOSE ser_csr;
7622 ELSE
7623 IF (l_debug = 1) THEN
7624 mydebug('check_mmtt_mtl_status: No controls');
7625 END IF;
7626
7627 IF inv_material_status_grp.is_status_applicable(
7628 p_wms_installed => 'TRUE'
7629 , p_trx_status_enabled => NULL
7630 , p_trx_type_id => l_txn_type_id
7631 , p_lot_status_enabled => NULL
7632 , p_serial_status_enabled => NULL
7633 , p_organization_id => l_org_id
7634 , p_inventory_item_id => l_item_id
7635 , p_sub_code => l_sub
7636 , p_locator_id => l_loc
7637 , p_lot_number => l_lot_number
7638 , p_serial_number => NULL
7639 , p_object_type => 'A'
7640 ) = 'N' THEN
7641 IF (l_debug = 1) THEN
7642 mydebug('check_mmtt_mtl_status: After Check');
7643 END IF;
7644
7645 x_mtl_status := 1;
7646 RETURN;
7647 END IF;
7648
7649 IF (l_debug = 1) THEN
7650 mydebug('check_mmtt_mtl_status: After Check');
7651 END IF;
7652
7653 x_mtl_status := 0;
7654 RETURN;
7655 END IF;
7656
7657 x_mtl_status := 0;
7658 END check_mmtt_mtl_status;
7659
7660 -- added for bug 2271470
7661
7662 PROCEDURE cleanup_partial_putaway_lpn(
7663 x_return_status OUT NOCOPY VARCHAR2
7664 , x_msg_count OUT NOCOPY NUMBER
7665 , x_msg_data OUT NOCOPY VARCHAR2
7666 , p_lpn_id IN NUMBER
7667 ) IS
7668 l_lpn_context NUMBER;
7669 PRAGMA AUTONOMOUS_TRANSACTION;
7670 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7671
7672 -- Following variables added in ATF_J3
7673
7674 -- End variables added in ATF_J3
7675
7676 -- Bug# 3281512 - Performance Fixes
7677 -- Cursor added to retrieve valid MO header IDs so we can avoid
7678 -- the hash join problem.
7679 CURSOR c_header_id IS
7680 SELECT moh.header_id
7681 FROM mtl_txn_request_headers moh, mtl_txn_request_lines mol
7682 WHERE moh.move_order_type = inv_globals.g_move_order_put_away
7683 AND moh.header_id = mol.header_id
7684 AND mol.lpn_id = p_lpn_id;
7685 l_header_id NUMBER;
7686
7687 BEGIN
7688 x_return_status := fnd_api.g_ret_sts_success;
7689
7690 -- ATF_J3
7691 -- Skip cleanup_partial_putaway_lpn logic
7692 -- if current release is J or above.
7693 -- We take care of cleaning up MMTT in suggestions_PUB
7694
7695 IF (l_debug = 1) THEN
7696 mydebug('cleanup_partial_putaway_LPN: Current release is above J, return without doing anything. p_lpn_id : ' || p_lpn_id);
7697 END IF;
7698
7699 RETURN;
7700
7701 EXCEPTION
7702 WHEN OTHERS THEN
7703 x_return_status := fnd_api.g_ret_sts_unexp_error;
7704
7705 IF (l_debug = 1) THEN
7706 mydebug('cleanup_partial_putaway_LPN upexpected error: ' || SQLCODE);
7707 END IF;
7708 END cleanup_partial_putaway_lpn;
7709
7710 /**
7711 * Inbound - Nested LPN changes
7712 * Creates Move order line by exploding the given lpn
7713 */
7714
7715
7716 PROCEDURE create_mo_lpn(
7717 p_lpn_id IN NUMBER
7718 , p_org_id IN NUMBER
7719 , x_return_status OUT NOCOPY VARCHAR2
7720 , x_msg_count OUT NOCOPY NUMBER
7721 , x_msg_data OUT NOCOPY VARCHAR2
7722 ) IS
7723 l_lpn_id NUMBER;
7724 l_m_item NUMBER;
7725 l_m_qty NUMBER;
7726 l_m_uom VARCHAR2(3);
7727 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
7728 l_m_lot VARCHAR2(80);
7729 l_m_rev VARCHAR2(3);
7730 l_m_hdr NUMBER;
7731 l_m_line NUMBER;
7732 l_m_sub VARCHAR2(10);
7733 l_m_loc NUMBER;
7734 l_return_status VARCHAR2(1);
7735 l_msg_count NUMBER;
7736 l_msg_data VARCHAR2(2000);
7737 l_lpn_cg_id NUMBER;
7738 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7739 l_project_id NUMBER;
7740 l_task_id NUMBER;
7741
7742 l_m_sec_qty NUMBER; --BUG12796808
7743 l_m_sec_uom VARCHAR2(3); --BUG12796808
7744 -- Bug# 3434940 - Performance Fixes
7745 -- Create a cursor to loop through all the nested LPNs within
7746 -- the given outer LPN, p_lpn_id.
7747 CURSOR lpn_csr IS
7748 SELECT lpn_id
7749 FROM wms_license_plate_numbers
7750 START WITH lpn_id = p_lpn_id
7751 CONNECT BY PRIOR lpn_id = parent_lpn_id;
7752 l_current_lpn_id NUMBER;
7753
7754 -- Bug# 3434940 - Performance Fixes
7755 -- Rename this cursor to lpn_contents_csr. Do not loop through the
7756 -- nested LPNs here. We will open a seperate outer cursor called
7757 -- lpn_csr to do that.
7758 CURSOR lpn_contents_csr IS
7759 SELECT inventory_item_id
7760 , quantity
7761 , uom_code
7762 , lot_number
7763 , revision
7764 , cost_group_id
7765 , parent_lpn_id
7766 , secondary_quantity --BUG12796808
7767 , secondary_uom_code --BUG12796808
7768 FROM wms_lpn_contents
7769 WHERE parent_lpn_id = l_current_lpn_id;
7770 BEGIN
7771 -- Intialize out variables
7772 x_return_status := fnd_api.g_ret_sts_success;
7773
7774 OPEN lpn_csr;
7775 IF (l_debug = 1) THEN
7776 mydebug('create_mo_lpn: Opened lpn_csr');
7777 END IF;
7778 LOOP
7779 FETCH lpn_csr INTO l_current_lpn_id;
7780 EXIT WHEN lpn_csr%NOTFOUND;
7781
7782 IF (l_debug = 1) THEN
7783 mydebug('create_mo_lpn: Current LPN ID is - ' || l_current_lpn_id);
7784 END IF;
7785 OPEN lpn_contents_csr;
7786 IF (l_debug = 1) THEN
7787 mydebug('create_mo_lpn: Opened lpn_contents_csr');
7788 END IF;
7789
7790 LOOP
7791 FETCH lpn_contents_csr INTO
7792 l_m_item,
7793 l_m_qty,
7794 l_m_uom,
7795 l_m_lot,
7796 l_m_rev,
7797 l_lpn_cg_id,
7798 l_lpn_id,
7799 l_m_sec_qty, --BUG12796808
7800 l_m_sec_uom; --BUG12796808
7801
7802 EXIT WHEN lpn_contents_csr%NOTFOUND;
7803
7804 -- Close existing move orders detailed.
7805 UPDATE mtl_txn_request_lines mol
7806 SET mol.line_status = inv_globals.g_to_status_closed
7807 WHERE mol.lpn_id = l_lpn_id
7808 AND mol.organization_id = p_org_id
7809 AND mol.quantity_detailed > 0
7810 AND EXISTS
7811 (SELECT 1
7812 FROM
7813 mtl_txn_request_headers moh,
7814 wms_license_plate_numbers wlc
7815 WHERE mol.header_id = moh.header_id
7816 AND moh.move_order_type = inv_globals.g_move_order_put_away
7817 AND wlc.lpn_id = mol.lpn_id
7818 AND wlc.lpn_context = 1);
7819
7820 IF (l_debug = 1) THEN
7821 mydebug('create_mo_lpn: lpn loop');
7822 mydebug('create_mo_lpn: lot' || l_m_lot);
7823 mydebug('item ' || l_m_item);
7824 mydebug('uom ' || l_m_uom);
7825 mydebug('rev ' || l_m_rev);
7826 mydebug('cost group id ' || l_lpn_cg_id);
7827 mydebug('lpn_id ' || l_lpn_id);
7828 mydebug('l_m_sec_qty ' || l_m_sec_qty);
7829 mydebug('l_m_sec_uom ' || l_m_sec_uom);
7830 END IF;
7831
7832 SELECT subinventory_code
7833 , locator_id
7834 INTO l_m_sub
7835 , l_m_loc
7836 FROM wms_license_plate_numbers
7837 WHERE lpn_id = l_lpn_id;
7838
7839 SELECT mil.project_id
7840 , mil.task_id
7841 INTO l_project_id
7842 , l_task_id
7843 FROM mtl_item_locations mil
7844 WHERE mil.inventory_location_id = l_m_loc
7845 AND mil.organization_id = p_org_id
7846 AND mil.subinventory_code = l_m_sub;
7847
7848 -- Call create_mo
7849 IF (l_debug = 1) THEN
7850 mydebug('create_mo_lpn: Calling create_mo');
7851 END IF;
7852
7853 wms_task_dispatch_put_away.create_mo
7854 (p_org_id => p_org_id,
7855 p_inventory_item_id => l_m_item,
7856 p_qty => l_m_qty,
7857 p_uom => l_m_uom,
7858 p_lpn => l_lpn_id,
7859 p_project_id => l_project_id,
7860 p_task_id => l_task_id,
7861 p_lot_number => l_m_lot,
7862 p_revision => l_m_rev,
7863 p_header_id => l_m_hdr,
7864 p_sub => l_m_sub,
7865 p_loc => l_m_loc,
7866 x_line_id => l_m_line,
7867 p_inspection_status => NULL,
7868 p_transaction_type_id => 64,
7869 p_transaction_source_type_id => 4,
7870 p_wms_process_flag => NULL,
7871 x_return_status => l_return_status,
7872 x_msg_count => l_msg_count,
7873 x_msg_data => l_msg_data,
7874 p_from_cost_group_id => l_lpn_cg_id,
7875 p_sec_qty => l_m_sec_qty, --BUG12796808
7876 p_sec_uom => l_m_sec_uom --BUG12796808
7877 );
7878
7879 l_m_hdr := NULL;
7880 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data => l_msg_data);
7881
7882 IF (l_msg_count = 0) THEN
7883 IF (l_debug = 1) THEN
7884 mydebug('create_mo_lpn: Successful');
7885 END IF;
7886 ELSIF(l_msg_count = 1) THEN
7887 IF (l_debug = 1) THEN
7888 mydebug('create_mo_lpn: Not Successful');
7889 mydebug('create_mo_lpn: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
7890 END IF;
7891 ELSE
7892 IF (l_debug = 1) THEN
7893 mydebug('create_mo_lpn: Not Successful2');
7894 END IF;
7895
7896 FOR i IN 1 .. l_msg_count LOOP
7897 l_msg_data := fnd_msg_pub.get(i, 'F');
7898
7899 IF (l_debug = 1) THEN
7900 mydebug('create_mo_lpn: ' || REPLACE(l_msg_data, fnd_global.local_chr(0), ' '));
7901 END IF;
7902 END LOOP;
7903 END IF;
7904
7905 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7906 fnd_message.set_name('WMS', 'WMS_TD_CMO_ERROR');
7907 fnd_msg_pub.ADD;
7908 RAISE fnd_api.g_exc_error;
7909 ELSIF l_return_status = fnd_api.g_ret_sts_error THEN
7910 fnd_message.set_name('WMS', 'WMS_TD_CMO_ERROR');
7911 fnd_msg_pub.ADD;
7912 RAISE fnd_api.g_exc_error;
7913 END IF;
7914
7915 IF (l_debug = 1) THEN
7916 mydebug('create_mo: Line ID created');
7917 mydebug('create_mo: ' || l_m_line);
7918 END IF;
7919
7920 END LOOP;
7921 CLOSE lpn_contents_csr;
7922
7923 END LOOP;
7924 CLOSE lpn_csr;
7925
7926 EXCEPTION
7927 WHEN fnd_api.g_exc_error THEN
7928 x_return_status := fnd_api.g_ret_sts_error;
7929 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7930 WHEN OTHERS THEN
7931 x_return_status := fnd_api.g_ret_sts_unexp_error;
7932 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7933 END create_mo_lpn;
7934
7935
7936 PROCEDURE validate_against_rules(
7937 p_organization_id IN NUMBER
7938 , p_lpn_id IN NUMBER
7939 , p_subinventory IN VARCHAR2
7940 , p_locator_id IN NUMBER
7941 , p_user_id IN NUMBER
7942 , p_eqp_ins IN VARCHAR2
7943 , p_project_id IN NUMBER
7944 , p_task_id IN NUMBER
7945 , x_return_status OUT NOCOPY VARCHAR2
7946 , x_msg_count OUT NOCOPY NUMBER
7947 , x_msg_data OUT NOCOPY VARCHAR2
7948 , x_validation_passed OUT NOCOPY VARCHAR2
7949 ) IS
7950 l_api_name CONSTANT VARCHAR2(30) := 'validate_against_rules';
7951 l_progress VARCHAR2(10);
7952 l_mo_lines_count NUMBER;
7953 l_mmtt_lines_count NUMBER;
7954 l_number_of_rows NUMBER;
7955 l_return_status VARCHAR2(1);
7956 l_crossdock VARCHAR2(3);
7957 l_fully_allocated BOOLEAN := TRUE;
7958 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7959 l_is_content_lpn VARCHAR2(1) := 'N';
7960 l_is_mo_there VARCHAR2(1) := 'N';
7961 l_lpn_context NUMBER;
7962 l_lpn_id NUMBER;
7963 l_is_mo_created VARCHAR2(1) := 'N';
7964 l_emp_id NUMBER;
7965
7966 CURSOR qty_check_cursor IS
7967 SELECT mtrl.primary_quantity
7968 , mmtt.primary_quantity
7969 FROM mtl_txn_request_lines mtrl, mtl_material_transactions_temp mmtt
7970 WHERE mtrl.organization_id = p_organization_id
7971 AND mtrl.lpn_id = l_lpn_id
7972 AND mmtt.move_order_line_id = mtrl.line_id;
7973
7974 l_mo_primary_qty NUMBER;
7975 l_mmtt_primary_qty NUMBER;
7976
7977 CURSOR lpn_cur IS
7978 SELECT lpn_id
7979 FROM wms_license_plate_numbers
7980 START WITH lpn_id = p_lpn_id
7981 CONNECT BY parent_lpn_id = PRIOR lpn_id;
7982
7983 BEGIN
7984 IF (l_debug = 1) THEN
7985 mydebug('***Calling validate_against_rules***');
7986 END IF;
7987
7988 -- Set the savepoint
7989 SAVEPOINT validate_rules_sp;
7990 x_return_status := fnd_api.g_ret_sts_success;
7991 l_progress := '10';
7992
7993 -- Call the ATF API to abort the plan before deleting the MMTTs
7994
7995 -- Patchset level check
7996 mydebug('validate_against_rules: Current release is above J.');
7997
7998 BEGIN -- Abort op plan call
7999
8000 mydebug('validate_against_rules: Calling ATF_For_Manual_Drop to abort the plan, if any');
8001
8002 l_progress := '12';
8003 WMS_PUTAWAY_UTILS.ATF_For_Manual_Drop(
8004 x_return_status => x_return_status
8005 ,x_msg_count => x_msg_count
8006 ,x_msg_data => x_msg_data
8007 ,p_call_type => G_ATF_ABORT_PLAN
8008 ,p_org_id => p_organization_id
8009 ,p_lpn_id => p_lpn_id
8010 ,p_emp_id => NULL
8011 );
8012 l_progress := '13';
8013
8014 IF x_return_status = fnd_api.g_ret_sts_success THEN
8015 -- Abort op plan completed successfully.
8016 NULL;
8017
8018 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
8019 RAISE fnd_api.g_exc_error;
8020
8021 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
8022 RAISE fnd_api.g_exc_unexpected_error;
8023
8024 END IF;
8025 l_progress := '18';
8026
8027 EXCEPTION
8028 WHEN OTHERS THEN
8029 RAISE fnd_api.g_exc_unexpected_error;
8030 END; -- Abort op plan call
8031
8032
8033 OPEN lpn_cur;
8034 LOOP
8035 FETCH lpn_cur INTO l_lpn_id;
8036
8037 l_is_content_lpn := 'N';
8038 IF lpn_cur%notfound THEN
8039 EXIT;
8040 END IF;
8041
8042 BEGIN
8043 SELECT 'Y' INTO l_is_content_lpn
8044 FROM wms_lpn_contents
8045 WHERE parent_lpn_id = l_lpn_id;
8046 EXCEPTION
8047 WHEN no_data_found THEN
8048 l_is_content_lpn := 'N';
8049 WHEN too_many_rows THEN
8050 l_is_content_lpn := 'Y';
8051 END;
8052
8053 IF (l_is_content_lpn = 'Y') THEN
8054
8055 --BUG 3369873: We no longer need to call revert_loc_suggested_capacity
8056 --because it is done inside abort_operation_instance_already.
8057
8058 -- Clean up any old existing MMTT, MTLT, and WDT records
8059 -- which might exist if on the user directed putaway mobile page,
8060 -- you are performing a user drop and you navigate back to the loc
8061 -- to enter a different one than before.
8062 IF (l_debug = 1) THEN
8063 mydebug('Clean up old WDT, MTLT, and MMTT records first');
8064 END IF;
8065
8066 -- Before clean up call abort operations plan
8067
8068 -- After Abort Operation plan do clean up.
8069
8070 DELETE FROM wms_dispatched_tasks
8071 WHERE task_type = 2
8072 AND transaction_temp_id IN
8073 (SELECT transaction_temp_id
8074 FROM mtl_material_transactions_temp
8075 WHERE move_order_line_id IN
8076 (SELECT line_id
8077 FROM mtl_txn_request_lines
8078 WHERE organization_id = p_organization_id
8079 AND lpn_id = l_lpn_id)
8080 );
8081
8082 DELETE FROM mtl_transaction_lots_temp
8083 WHERE transaction_temp_id IN
8084 (SELECT transaction_temp_id
8085 FROM mtl_material_transactions_temp
8086 WHERE move_order_line_id IN
8087 (SELECT line_id
8088 FROM mtl_txn_request_lines
8089 WHERE organization_id = p_organization_id
8090 AND lpn_id = l_lpn_id));
8091
8092 DELETE FROM mtl_material_transactions_temp
8093 WHERE move_order_line_id IN
8094 (SELECT line_id
8095 FROM mtl_txn_request_lines
8096 WHERE organization_id = p_organization_id
8097 AND lpn_id = l_lpn_id);
8098
8099 IF (l_debug = 1) THEN
8100 mydebug('Finished cleaning up old WDT, MTLT, and MMTT records');
8101 END IF;
8102
8103 l_progress := '40';
8104
8105 -- Update the move order lines with the user inputted sub/loc.
8106 -- Also null out the quantity detailed in case the user enters
8107 -- a loc, validates it against rules, but then goes back and changes
8108 -- the sub/loc before processing it.
8109 UPDATE mtl_txn_request_lines
8110 SET to_subinventory_code = p_subinventory
8111 , to_locator_id = p_locator_id
8112 , quantity_detailed = NULL
8113 , SECONDARY_QUANTITY_DETAILED = NULL --added for bug 16527809
8114 WHERE organization_id = p_organization_id
8115 AND lpn_id = l_lpn_id
8116 AND line_status = 7;
8117
8118 l_progress := '50';
8119
8120 -- Call the rules engine and see if MMTT suggestions are returned
8121 -- This allows for rules engine validation of the user inputted sub/loc
8122 -- Bug# 2752119
8123 -- Added an extra input parameter in API call so we will not check for
8124 -- crossdocking opportunities for rules validated express drops
8125 wms_task_dispatch_put_away.suggestions_pub(
8126 p_lpn_id => l_lpn_id
8127 , p_org_id => p_organization_id
8128 , p_user_id => p_user_id
8129 , p_eqp_ins => p_eqp_ins
8130 , x_number_of_rows => l_number_of_rows
8131 , x_return_status => l_return_status
8132 , x_msg_count => x_msg_count
8133 , x_msg_data => x_msg_data
8134 , x_crossdock => l_crossdock
8135 , p_status => 4
8136 , p_check_for_crossdock => 'N'
8137 , p_drop_type => 'MD' -- Manual drop
8138 , p_subinventory => p_subinventory
8139 , p_locator_id => p_locator_id );
8140
8141 IF (l_debug = 1) THEN
8142 mydebug('Finished calling the suggestions_pub API');
8143 END IF;
8144
8145 l_progress := '60';
8146
8147 -- Check to see if the suggestions_pub returned successfully
8148 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8149 IF (l_debug = 1) THEN
8150 mydebug('Success returned from suggestions_pub API');
8151 END IF;
8152 ELSE
8153 IF (l_debug = 1) THEN
8154 mydebug('Failure returned from suggestions_pub API');
8155 END IF;
8156
8157 RAISE fnd_api.g_exc_error;
8158 END IF;
8159
8160 -- Bug# 3352224
8161 -- For Patchset J and above, we allow manual drops within
8162 -- Inventory. Therefore the call to suggestions_pub would
8163 -- create move order lines if none existed for inventory LPNs.
8164 -- The query to see how many move order lines there are for the
8165 -- LPN should be done after the call to suggestions_pub and not before.
8166
8167 -- Get the number of move order lines for this given LPN
8168 SELECT COUNT(1)
8169 INTO l_mo_lines_count
8170 FROM mtl_txn_request_lines
8171 WHERE organization_id = p_organization_id
8172 AND lpn_id = l_lpn_id
8173 AND line_status = 7;
8174
8175 IF (l_debug = 1) THEN
8176 mydebug('The number of move order lines is: ' || l_mo_lines_count);
8177 END IF;
8178
8179 l_progress := '70';
8180
8181 -- Check to see if MMTT allocations were created
8182 SELECT COUNT(mmtt.transaction_temp_id)
8183 INTO l_mmtt_lines_count
8184 FROM mtl_material_transactions_temp mmtt, mtl_txn_request_lines mtrl
8185 WHERE mtrl.lpn_id = l_lpn_id
8186 AND mtrl.organization_id = p_organization_id
8187 AND NVL(mmtt.wms_task_type, 0) <> -1
8188 AND mtrl.line_id = mmtt.move_order_line_id
8189 AND NVL(mtrl.project_id, -1) = DECODE(mtrl.project_id, NULL, -1, NVL(p_project_id, NVL(mtrl.project_id, -1)))
8190 AND NVL(mtrl.task_id, -1) = DECODE(mtrl.task_id, NULL, -1, NVL(p_task_id, NVL(mtrl.task_id, -1)));
8191
8192 IF (l_debug = 1) THEN
8193 mydebug('Checked to see how many MMTT lines were created: ' || l_mmtt_lines_count);
8194 END IF;
8195
8196 l_progress := '80';
8197
8198 -- Check that for every move order line, exactly one MMTT suggestion is created
8199 IF (l_mmtt_lines_count = 0
8200 OR l_mmtt_lines_count <> l_mo_lines_count) THEN
8201 IF (l_debug = 1) THEN
8202 mydebug('Rules engine validation failed!');
8203 END IF;
8204
8205 x_validation_passed := 'N';
8206
8207 -- Bug #2745971
8208 -- We need to explicitly revert the locator capacities since this is
8209 -- done autonomously by the rules engine. Performing a rollback
8210 -- will not revert the locator capacities.
8211 IF (l_debug = 1) THEN
8212 mydebug('Call revert_loc_suggested_capacity to clean up capacities');
8213 END IF;
8214
8215 wms_task_dispatch_put_away.revert_loc_suggested_capacity(
8216 x_return_status => l_return_status
8217 , x_msg_count => x_msg_count
8218 , x_msg_data => x_msg_data
8219 , p_organization_id => p_organization_id
8220 , p_lpn_id => p_lpn_id
8221 );
8222 l_progress := '90';
8223
8224 -- Check to see if the call to revert_loc_suggested_capacity returned successfully
8225 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8226 IF (l_debug = 1) THEN
8227 mydebug('Success returned from revert_loc_suggested_capacity API');
8228 END IF;
8229 ELSE
8230 IF (l_debug = 1) THEN
8231 mydebug('Failure returned from revert_loc_suggested_capacity API');
8232 END IF;
8233 -- Bug 5393727: do not raise an exception if revert API returns an error
8234 -- RAISE fnd_api.g_exc_error;
8235 END IF;
8236
8237 -- Perform a rollback to clean up the rest of the data
8238 BEGIN
8239 ROLLBACK TO validate_rules_sp;
8240 EXCEPTION WHEN OTHERS THEN
8241 NULL;
8242 END;
8243 EXIT;
8244 ELSE
8245 -- Bug #2745971
8246 -- Check to see if the MMTT allocations are all full allocations,
8247 -- i.e. not partially allocated suggestions
8248 IF (l_debug = 1) THEN
8249 mydebug('Check if suggestions are fully allocated');
8250 END IF;
8251
8252 OPEN qty_check_cursor;
8253
8254 LOOP
8255 FETCH qty_check_cursor INTO l_mo_primary_qty, l_mmtt_primary_qty;
8256 EXIT WHEN qty_check_cursor%NOTFOUND;
8257
8258 --IF (l_mo_primary_qty <> l_mmtt_primary_qty) THEN
8259 IF (Abs(l_mo_primary_qty - l_mmtt_primary_qty)>0.00005) THEN -- made when testing 13591755
8260 -- If any of the MOL and corresponding MMTT lines have
8261 -- different primary quantities, the line was only partially allocated
8262 l_fully_allocated := FALSE;
8263 EXIT;
8264 END IF;
8265 END LOOP;
8266
8267 CLOSE qty_check_cursor;
8268
8269 IF (l_debug = 1) THEN
8270 mydebug('Finished checking for full allocations');
8271 END IF;
8272
8273 l_progress := '100';
8274
8275 -- Rules engine validation should fail if the lines are not fully allocated
8276 IF (l_fully_allocated) THEN
8277 IF (l_debug = 1) THEN
8278 mydebug('Rules engine validation passed!');
8279 END IF;
8280
8281 x_validation_passed := 'Y';
8282 ELSE
8283 IF (l_debug = 1) THEN
8284 mydebug('Rules engine validation failed!');
8285 END IF;
8286
8287 x_validation_passed := 'N';
8288
8289 -- Bug #2745971
8290 -- We need to explicitly revert the locator capacities since this is
8291 -- done autonomously by the rules engine. Performing a rollback
8292 -- will not revert the locator capacities.
8293 IF (l_debug = 1) THEN
8294 mydebug('Call revert_loc_suggested_capacity to clean up capacities');
8295 END IF;
8296
8297 wms_task_dispatch_put_away.revert_loc_suggested_capacity(
8298 x_return_status => l_return_status
8299 , x_msg_count => x_msg_count
8300 , x_msg_data => x_msg_data
8301 , p_organization_id => p_organization_id
8302 , p_lpn_id => p_lpn_id
8303 );
8304 l_progress := '110';
8305
8306 -- Check to see if the call to revert_loc_suggested_capacity returned successfully
8307 IF (l_return_status = fnd_api.g_ret_sts_success) THEN
8308 IF (l_debug = 1) THEN
8309 mydebug('Success returned from revert_loc_suggested_capacity API');
8310 END IF;
8311 ELSE
8312 IF (l_debug = 1) THEN
8313 mydebug('Failure returned from revert_loc_suggested_capacity API');
8314 END IF;
8315 -- Bug 5393727: do not raise an exception if revert API returns an error
8316 -- RAISE fnd_api.g_exc_error;
8317 END IF;
8318
8319 -- Perform a rollback to clean up the rest of the data
8320 BEGIN
8321 ROLLBACK TO validate_rules_sp;
8322 EXCEPTION WHEN OTHERS THEN
8323 NULL;
8324 END;
8325 EXIT;
8326 END IF;
8327 END IF;
8328
8329 l_progress := '120';
8330 x_return_status := fnd_api.g_ret_sts_success;
8331
8332 END IF;
8333 END LOOP;
8334
8335 -- Call the ATF API to insert WDTs.
8336 -- Moved the ATF API calls to the complete_putaway_wrapper API instead. -etam
8337
8338 IF (l_debug = 1) THEN
8339 mydebug('***End of validate_against_rules***');
8340 END IF;
8341
8342 EXCEPTION
8343 WHEN fnd_api.g_exc_error THEN
8344 ROLLBACK TO validate_rules_sp;
8345 x_validation_passed := 'N';
8346 x_return_status := fnd_api.g_ret_sts_error;
8347 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8348
8349 IF (l_debug = 1) THEN
8350 mydebug('Exiting validate_against_rules - Execution error: ' || l_progress || ' '
8351 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
8352 END IF;
8353 WHEN fnd_api.g_exc_unexpected_error THEN
8354 ROLLBACK TO validate_rules_sp;
8355 x_validation_passed := 'N';
8356 x_return_status := fnd_api.g_ret_sts_unexp_error;
8357 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8358
8359 IF (l_debug = 1) THEN
8360 mydebug('Exiting validate_against_rules - Unexpected error: ' || l_progress || ' '
8361 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
8362 END IF;
8363 WHEN OTHERS THEN
8364 ROLLBACK TO validate_rules_sp;
8365 x_validation_passed := 'N';
8366 x_return_status := fnd_api.g_ret_sts_unexp_error;
8367
8368 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8369 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
8370 END IF;
8371
8372 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8373
8374 IF (l_debug = 1) THEN
8375 mydebug('Exiting validate_against_rules - Others exception: ' || l_progress || ' '
8376 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
8377 END IF;
8378 END validate_against_rules;
8379
8380
8381 PROCEDURE create_user_suggestions(
8382 p_organization_id IN NUMBER
8383 , p_lpn_id IN NUMBER
8384 , p_subinventory IN VARCHAR2
8385 , p_locator_id IN NUMBER
8386 , p_user_id IN NUMBER
8387 , p_eqp_ins IN VARCHAR2
8388 , x_return_status OUT NOCOPY VARCHAR2
8389 , x_msg_count OUT NOCOPY NUMBER
8390 , x_msg_data OUT NOCOPY VARCHAR2
8391 , x_number_of_rows OUT NOCOPY NUMBER
8392 ) IS
8393 l_api_name CONSTANT VARCHAR2(30) := 'create_user_suggestions';
8394 l_progress VARCHAR2(10);
8395 l_txn_header_id NUMBER;
8396 l_txn_temp_id NUMBER;
8397 l_ser_trx_id NUMBER;
8398 l_trx_action_id NUMBER;
8399 l_completion_txn_id NUMBER;
8400 l_primary_uom_code VARCHAR2(3);
8401 l_task_id NUMBER;
8402 l_return NUMBER;
8403 l_number_of_rows NUMBER := 0;
8404 l_mo_exists VARCHAR2(1) := 'N';
8405 l_lpn_context NUMBER;
8406 l_is_mo_created VARCHAR2(1) := 'N';
8407 l_subinventory mtl_secondary_inventories.secondary_inventory_name%TYPE;
8408 l_locator_id NUMBER;
8409 l_operation_seq_num NUMBER := NULL;
8410 l_repetitive_line_id NUMBER := NULL;
8411
8412 TYPE num_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
8413 TYPE var3_tab IS TABLE OF VARCHAR(3) INDEX BY BINARY_INTEGER;
8414 l_mmtt_id_tab num_tab;
8415 l_mmtt_qty_tab num_tab;
8416 l_mmtt_mol_id_tab num_tab;
8417 l_mmtt_uom_tab var3_tab;
8418 l_mmtt_sec_qty_tab num_tab; --OPM Convergence
8419 l_mmtt_sec_uom_tab var3_tab; --OPM Convergence
8420
8421 -- Bug# 3281512 - Performance Fixes
8422 -- Cursor to retrieve the nested LPNs within a given outer LPN
8423 CURSOR nested_lpn_cursor IS
8424 SELECT lpn_id
8425 FROM wms_license_plate_numbers
8426 START WITH lpn_id = p_lpn_id
8427 CONNECT BY PRIOR lpn_id = parent_lpn_id;
8428 l_current_lpn_id NUMBER;
8429
8430 -- Nested LPN changes.
8431 -- Changed MO Lines cursor to not consider closed move orders
8432 -- Bug# 3281512 - Performance Fixes
8433 --
8434 CURSOR mo_lines_cursor IS
8435 SELECT mol.lpn_id
8436 , mol.line_id
8437 , mol.inventory_item_id
8438 , mol.revision
8439 , mol.lot_number
8440 , mol.uom_code
8441 , mol.quantity
8442 , mol.primary_quantity
8443 , mol.reference_id
8444 , mol.project_id
8445 , mol.task_id
8446 , mol.txn_source_id
8447 , mol.transaction_type_id
8448 , mol.transaction_source_type_id
8449 , mol.to_cost_group_id
8450 , mol.SECONDARY_QUANTITY --BUG12796808
8451 , mol.SECONDARY_UOM_CODE --BUG12796808
8452 FROM mtl_txn_request_lines mol
8453 WHERE mol.organization_id = p_organization_id
8454 AND mol.header_id IN (SELECT moh.header_id
8455 FROM mtl_txn_request_headers moh
8456 WHERE moh.move_order_type = inv_globals.g_move_order_put_away
8457 )
8458 AND mol.line_status = 7
8459 AND mol.lpn_id = l_current_lpn_id;
8460
8461 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8462 l_emp_id NUMBER;
8463
8464
8465
8466 BEGIN
8467 IF (l_debug = 1) THEN
8468 mydebug('***Calling create_user_suggestions***');
8469 END IF;
8470
8471 -- Set the savepoint
8472 SAVEPOINT create_suggestions_sp;
8473 l_progress := '10';
8474
8475 -- Bug# 2750060
8476 -- Get the employee ID so we can populate
8477 -- the person_id column in WDT properly.
8478 IF (l_debug = 1) THEN
8479 mydebug('Get the employee ID tied to the user');
8480 END IF;
8481
8482 BEGIN
8483 SELECT employee_id
8484 INTO l_emp_id
8485 FROM fnd_user
8486 WHERE user_id = p_user_id;
8487 EXCEPTION
8488 WHEN NO_DATA_FOUND THEN
8489 IF (l_debug = 1) THEN
8490 mydebug('There is no employee tied to the user');
8491 END IF;
8492
8493 l_emp_id := NULL;
8494 END;
8495
8496 IF (l_debug = 1) THEN
8497 mydebug('Employee ID: ' || l_emp_id);
8498 END IF;
8499
8500 l_progress := '20';
8501
8502 -- Call the ATF API to abort the plan before deleting the MMTTs
8503
8504 -- Patchset level check
8505 mydebug('create_user_suggestions: Current release is above J.');
8506
8507 BEGIN -- Abort op plan call
8508
8509 mydebug('create_user_suggestions: Calling WMS_PUTAWAY_UTILS.ATF_For_Manual_Drop to abort the plan, if any');
8510
8511 l_progress := '22';
8512 WMS_PUTAWAY_UTILS.ATF_For_Manual_Drop(
8513 x_return_status => x_return_status
8514 ,x_msg_count => x_msg_count
8515 ,x_msg_data => x_msg_data
8516 ,p_call_type => G_ATF_ABORT_PLAN
8517 ,p_org_id => p_organization_id
8518 ,p_lpn_id => p_lpn_id
8519 ,p_emp_id => l_emp_id
8520 );
8521 l_progress := '23';
8522
8523 IF x_return_status = fnd_api.g_ret_sts_success THEN
8524 -- Abort op plan completed successfully.
8525 NULL;
8526
8527 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
8528 RAISE fnd_api.g_exc_error;
8529
8530 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
8531 RAISE fnd_api.g_exc_unexpected_error;
8532
8533 END IF;
8534 l_progress := '28';
8535
8536 EXCEPTION
8537 WHEN OTHERS THEN
8538 RAISE fnd_api.g_exc_unexpected_error;
8539 END; -- Abort op plan call
8540
8541
8542 -- Clean up any old existing MMTT, MTLT, and WDT records
8543 -- which might exist if on the user directed putaway mobile page,
8544 -- you are performing a user drop and you navigate back to the loc
8545 -- to enter a different one than before.
8546 IF (l_debug = 1) THEN
8547 mydebug('Clean up old WDT, MTLT, and MMTT records');
8548 END IF;
8549
8550
8551 -- Nested LPN changes
8552 -- Select the old MMTTs. Delete them at the end.
8553 -- Bug# 3434940 - Performance Fixes
8554 -- For now we will leave the hash join problem. We're not able
8555 -- to use the outer nested_lpn_cursor because of the bulk collect.
8556 SELECT mmtt.transaction_temp_id,
8557 mmtt.transaction_quantity,
8558 mmtt.transaction_uom,
8559 mmtt.move_order_line_id,
8560 mmtt.secondary_transaction_quantity, --OPM Convergence
8561 mmtt.secondary_uom_code --OPM Convergence
8562 bulk collect
8563 INTO l_mmtt_id_tab,
8564 l_mmtt_qty_tab,
8565 l_mmtt_uom_tab,
8566 l_mmtt_mol_id_tab,
8567 l_mmtt_sec_qty_tab, --OPM Convergence
8568 l_mmtt_sec_uom_tab --OPM Convergence
8569 FROM mtl_material_transactions_temp mmtt,
8570 mtl_txn_request_lines mtrl
8571 WHERE mmtt.organization_id = p_organization_id
8572 AND mmtt.move_order_line_id = mtrl.line_id
8573 AND mtrl.lpn_id IN (SELECT lpn_id
8574 FROM wms_license_plate_numbers
8575 START WITH lpn_id = p_lpn_id
8576 CONNECT BY parent_lpn_id = PRIOR lpn_id);
8577
8578
8579
8580 SELECT lpn_context,subinventory_code,locator_id
8581 INTO l_lpn_context,l_subinventory,l_locator_id
8582 FROM wms_license_plate_numbers
8583 WHERE lpn_id = p_lpn_id;
8584
8585 IF l_lpn_context = 1 THEN
8586 -- Inventory LPN so need to create MOLs first
8587 create_mo_lpn( p_lpn_id => p_lpn_id
8588 , p_org_id => p_organization_id
8589 , x_return_status => x_return_status
8590 , x_msg_count => x_msg_count
8591 , x_msg_data => x_msg_data );
8592
8593 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
8594 RAISE fnd_api.g_exc_unexpected_error;
8595 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
8596 RAISE fnd_api.g_exc_error;
8597 END IF;
8598 END IF; -- End for is Inventory lpn
8599
8600 l_progress := '30';
8601
8602 -- Loop through the move order lines cursor
8603 -- Bug# 3281512 - Performance Fixes
8604 -- Open up the nested LPN cursor first and for each LPN,
8605 -- loop through the move order lines cursor.
8606 OPEN nested_lpn_cursor;
8607 LOOP
8608 FETCH nested_lpn_cursor INTO l_current_lpn_id;
8609 EXIT WHEN nested_lpn_cursor%NOTFOUND;
8610 IF (l_debug = 1) THEN
8611 mydebug('Current LPN ID: ' || l_current_lpn_id);
8612 END IF;
8613
8614 FOR v_mo_line IN mo_lines_cursor LOOP
8615 l_number_of_rows := l_number_of_rows + 1;
8616
8617 IF (l_debug = 1) THEN
8618 mydebug('Current move order line values:');
8619 mydebug('LPN ID:==============> ' || v_mo_line.lpn_id);
8620 mydebug('Line ID: ============> ' || v_mo_line.line_id);
8621 mydebug('Inventory Item ID: ==> ' || v_mo_line.inventory_item_id);
8622 mydebug('Revision: ===========> ' || v_mo_line.revision);
8623 mydebug('Lot Number: =========> ' || v_mo_line.lot_number);
8624 mydebug('UOM Code: ===========> ' || v_mo_line.uom_code);
8625 mydebug('Qty: ================> ' || v_mo_line.quantity);
8626 mydebug('Primary Qty: ========> ' || v_mo_line.primary_quantity);
8627 mydebug('Project ID: =========> ' || v_mo_line.project_id);
8628 mydebug('Task ID: ============> ' || v_mo_line.task_id);
8629 mydebug('Txn Source ID: ======> ' || v_mo_line.txn_source_id);
8630 mydebug('Txn Type ID: ========> ' || v_mo_line.transaction_type_id);
8631 mydebug('Txn Source Type ID: => ' || v_mo_line.transaction_source_type_id);
8632 mydebug('Cost Group ID: ======> ' || v_mo_line.to_cost_group_id);
8633 mydebug('SECONDARY_QUANTITY: => ' || v_mo_line.SECONDARY_QUANTITY);
8634 mydebug('SECONDARY_UOM_CODE: => ' || v_mo_line.SECONDARY_UOM_CODE);
8635 END IF;
8636
8637 -- Get a new transaction header id from the sequence
8638 SELECT mtl_material_transactions_s.NEXTVAL
8639 INTO l_txn_header_id
8640 FROM DUAL;
8641
8642 IF (l_debug = 1) THEN
8643 mydebug('Transaction header ID: ' || l_txn_header_id);
8644 END IF;
8645
8646 l_progress := '40';
8647
8648 -- Get the value for the transaction action ID
8649 IF (v_mo_line.transaction_source_type_id = 5
8650 AND v_mo_line.transaction_type_id = 44) THEN
8651 -- WIP assembly completion
8652 l_trx_action_id := 31;
8653 ELSIF(v_mo_line.transaction_source_type_id = 1
8654 AND v_mo_line.transaction_type_id = 18) THEN
8655 -- Purchase order receipt
8656 l_trx_action_id := 27;
8657 ELSIF(v_mo_line.transaction_source_type_id = 7
8658 AND v_mo_line.transaction_type_id = 61) THEN
8659 --Internal Req/Intransit Shipment Receipt
8660 l_trx_action_id := 12;
8661 ELSIF(v_mo_line.transaction_source_type_id = 8
8662 AND v_mo_line.transaction_type_id = 62) THEN
8663 -- Internal order intransit shipment
8664 l_trx_action_id := 21;
8665 ELSIF(v_mo_line.transaction_source_type_id = 12
8666 AND v_mo_line.transaction_type_id = 15) THEN
8667 -- RMA receipt of customer return
8668 l_trx_action_id := 27;
8669 ELSIF(v_mo_line.transaction_source_type_id = 4) THEN
8670 -- Inventory lpn
8671 l_trx_action_id := 2;
8672 ELSIF(v_mo_line.transaction_source_type_id = 13
8673 AND v_mo_line.transaction_type_id = 12) THEN --bug9911977
8674 --Intransit Shipment Receipt
8675 l_trx_action_id :=12;
8676 ELSE
8677 -- This case should never come about
8678 l_trx_action_id := -999;
8679 END IF;
8680
8681 IF (l_debug = 1) THEN
8682 mydebug('Transaction action ID is: ' || l_trx_action_id);
8683 END IF;
8684
8685 l_progress := '50';
8686
8687 IF (l_debug = 1) THEN
8688 mydebug('Getting operation_seq_num and repetive_line_id for mol: ' || v_mo_line.line_id);
8689 END IF;
8690 l_progress := '52';
8691 BEGIN
8692 SELECT DISTINCT operation_seq_num, repetitive_line_id
8693 INTO l_operation_seq_num,l_repetitive_line_id
8694 FROM mtl_material_transactions_temp
8695 WHERE move_order_line_id = v_mo_line.line_id;
8696 IF (l_debug = 1) THEN
8697 mydebug(' operation_seq_num ===> '|| l_operation_seq_num);
8698 mydebug(' repetive_line_id ====> '|| l_repetitive_line_id);
8699 END IF;
8700 l_progress := '53';
8701 EXCEPTION
8702 WHEN no_data_found THEN
8703 l_operation_seq_num := NULL;
8704 l_repetitive_line_id := NULL;
8705 WHEN OTHERS THEN
8706 IF (l_debug = 1) THEN
8707 mydebug('These values are not distinct!!');
8708 END IF;
8709 RAISE fnd_api.g_exc_error;
8710 END;
8711
8712 -- Insert a record into MMTT
8713 -- Nested LPN changes,
8714 -- For Resides in Receiving LPNs insert destination sub destint loc as sub and loc
8715 -- For Resides in Inventory LPNs insert destination sub and loc as to_sub and to_loc.
8716
8717
8718 mydebug('lpn context =====>' || l_lpn_context );
8719 mydebug('l_subinventory =====>' || l_subinventory );
8720 mydebug('p_subinventory =====>' || p_subinventory );
8721 mydebug('l_locator_id =====>' || l_locator_id );
8722 mydebug('p_locator_id =====>' || p_locator_id );
8723
8724 IF l_lpn_context = 3 OR l_lpn_context = 2 THEN --added context =2 bug 4189437
8725
8726 l_return :=
8727 inv_trx_util_pub.insert_line_trx
8728 (p_trx_hdr_id => l_txn_header_id,
8729 p_item_id => v_mo_line.inventory_item_id,
8730 p_revision => v_mo_line.revision,
8731 p_org_id => p_organization_id,
8732 p_trx_action_id => l_trx_action_id,
8733 p_subinv_code => p_subinventory,
8734 p_locator_id => p_locator_id,
8735 p_trx_type_id => v_mo_line.transaction_type_id,
8736 p_trx_src_type_id => v_mo_line.transaction_source_type_id,
8737 p_trx_qty => v_mo_line.quantity,
8738 p_pri_qty => v_mo_line.primary_quantity,
8739 p_uom => v_mo_line.uom_code,
8740 p_user_id => p_user_id,
8741 p_cost_group => v_mo_line.to_cost_group_id,
8742 p_from_lpn_id => v_mo_line.lpn_id,
8743 p_trx_src_id => v_mo_line.txn_source_id,
8744 x_trx_tmp_id => l_txn_temp_id,
8745 x_proc_msg => x_msg_data,
8746 p_project_id => v_mo_line.project_id,
8747 p_task_id => v_mo_line.task_id,
8748 p_transaction_status => 2,
8749 p_secondary_trx_qty => v_mo_line.SECONDARY_QUANTITY,
8750 p_secondary_uom => v_mo_line.SECONDARY_UOM_CODE
8751 );
8752 --BUG 3356366: Insert MMTT with txn_status 2 so that it won't
8753 --invoke the DB trigger that calls update_loc_suggested_capacity
8754 ELSE
8755 l_return :=
8756 inv_trx_util_pub.insert_line_trx
8757 (p_trx_hdr_id => l_txn_header_id,
8758 p_item_id => v_mo_line.inventory_item_id,
8759 p_revision => v_mo_line.revision,
8760 p_org_id => p_organization_id,
8761 p_trx_action_id => l_trx_action_id,
8762 p_subinv_code => nvl(l_subinventory,p_subinventory), -- 4156992
8763 p_locator_id => nvl(l_locator_id,p_locator_id) , -- 4156992
8764 p_trx_type_id => v_mo_line.transaction_type_id,
8765 p_trx_src_type_id => v_mo_line.transaction_source_type_id,
8766 p_trx_qty => v_mo_line.quantity,
8767 p_pri_qty => v_mo_line.primary_quantity,
8768 p_uom => v_mo_line.uom_code,
8769 p_user_id => p_user_id,
8770 p_cost_group => v_mo_line.to_cost_group_id,
8771 p_from_lpn_id => v_mo_line.lpn_id,
8772 p_trx_src_id => v_mo_line.txn_source_id,
8773 x_trx_tmp_id => l_txn_temp_id,
8774 x_proc_msg => x_msg_data,
8775 p_project_id => v_mo_line.project_id,
8776 p_task_id => v_mo_line.task_id,
8777 p_tosubinv_code => p_subinventory,
8778 p_tolocator_id => p_locator_id,
8779 p_transaction_status => 2,
8780 p_secondary_trx_qty => v_mo_line.SECONDARY_QUANTITY,
8781 p_secondary_uom => v_mo_line.SECONDARY_UOM_CODE
8782 );
8783
8784 --BUG 3356366: Insert MMTT with txn_status 2 so that it won't
8785 --invoke the DB trigger that calls update_loc_suggested_capacity
8786 END IF;
8787
8788 IF (l_debug = 1) THEN
8789 mydebug('Successfully inserted MMTT record: ' || l_txn_temp_id);
8790 END IF;
8791
8792 l_progress := '60';
8793
8794 IF (l_return <> 0) THEN
8795 ROLLBACK TO create_suggestions_sp;
8796
8797 IF (l_debug = 1) THEN
8798 mydebug('Error occurred while calling inv_trx_util_pub.insert_line_trx');
8799 END IF;
8800
8801 RAISE fnd_api.g_exc_unexpected_error;
8802 END IF;
8803
8804 -- Get the value for the completion_transaction_id
8805 -- in the case of WIP completions
8806 IF (v_mo_line.transaction_source_type_id = 5 AND
8807 v_mo_line.transaction_type_id = 44) THEN
8808 SELECT NVL(completion_transaction_id, -999)
8809 INTO l_completion_txn_id
8810 FROM wip_lpn_completions
8811 WHERE header_id = v_mo_line.reference_id
8812 AND lpn_id = p_lpn_id;
8813 ELSE
8814 l_completion_txn_id := NULL;
8815 END IF;
8816
8817 IF (l_debug = 1) THEN
8818 mydebug('Completion transaction ID: ' || l_completion_txn_id);
8819 END IF;
8820
8821 l_progress := '70';
8822
8823 -- Get the item's primary uom code
8824 SELECT primary_uom_code
8825 INTO l_primary_uom_code
8826 FROM mtl_system_items
8827 WHERE inventory_item_id = v_mo_line.inventory_item_id
8828 AND organization_id = p_organization_id;
8829
8830 IF (l_debug = 1) THEN
8831 mydebug('Item primary UOM code: ' || l_primary_uom_code);
8832 END IF;
8833
8834 l_progress := '80';
8835
8836 --Need to update MOL.quantity_detailed
8837 --Because in WMSOPIBB.COMPLETE, it will deduct
8838 --MMTT.TRANSACTION_QUANTITY from MOL.QUANITY_DETIALED
8839 UPDATE mtl_txn_request_lines
8840 SET quantity_detailed = Nvl(quantity_detailed,0)+quantity
8841 WHERE line_id = v_mo_line.line_id;
8842
8843 -- Update the MMTT record with the move order line,
8844 -- completion transaction ID in the case of WIP completion,
8845 -- item primary UOM code, transaction status (2 for suggestions),
8846 -- and wms task type (2 for putaway).
8847 UPDATE mtl_material_transactions_temp
8848 SET move_order_line_id = v_mo_line.line_id
8849 , completion_transaction_id = l_completion_txn_id
8850 , item_primary_uom_code = l_primary_uom_code
8851 , transaction_status = 2
8852 , wms_task_type = 2
8853 , operation_seq_num = l_operation_seq_num --need these 2 columns when
8854 , repetitive_line_id = l_repetitive_line_id --reverting crossdock
8855 WHERE transaction_temp_id = l_txn_temp_id;
8856
8857 IF (l_debug = 1) THEN
8858 mydebug('Updated the MMTT record with additional info');
8859 END IF;
8860
8861 l_progress := '90';
8862
8863 IF (v_mo_line.lot_number IS NOT NULL) THEN
8864 -- Insert a record into MTLT
8865 IF (l_debug = 1) THEN
8866 mydebug('Insert a record into MTLT for lot: ' || v_mo_line.lot_number);
8867 END IF;
8868
8869 l_return :=
8870 inv_trx_util_pub.insert_lot_trx
8871 (p_trx_tmp_id => l_txn_temp_id,
8872 p_user_id => p_user_id,
8873 p_lot_number => v_mo_line.lot_number,
8874 p_trx_qty => v_mo_line.quantity,
8875 p_pri_qty => v_mo_line.primary_quantity,
8876 x_ser_trx_id => l_ser_trx_id,
8877 x_proc_msg => x_msg_data,
8878 p_secondary_qty => v_mo_line.SECONDARY_QUANTITY,
8879 p_secondary_uom => v_mo_line.SECONDARY_UOM_CODE
8880 );
8881
8882 IF (l_debug = 1) THEN
8883 mydebug('Successfully inserted MTLT record');
8884 END IF;
8885
8886 l_progress := '100';
8887
8888 IF (l_return <> 0) THEN
8889 IF (l_debug = 1) THEN
8890 mydebug('Error occurred while calling inv_trx_util_pub.insert_lot_trx');
8891 END IF;
8892
8893 RAISE fnd_api.g_exc_unexpected_error;
8894 END IF;
8895
8896 -- Update the MTLT record to clear out the serial_transaction_temp_id column
8897 -- since insert_lot_trx by default will insert a value for it.
8898 UPDATE mtl_transaction_lots_temp
8899 SET serial_transaction_temp_id = NULL
8900 WHERE transaction_temp_id = l_txn_temp_id;
8901
8902 IF (l_debug = 1) THEN
8903 mydebug('Cleared out the serial txn temp ID column in MTLT record');
8904 END IF;
8905
8906 l_progress := '110';
8907 END IF;
8908
8909
8910 l_progress := '130';
8911 END LOOP; -- End mo_lines_cursor LOOP
8912 END LOOP; -- End nested_lpn_cursor LOOP
8913 CLOSE nested_lpn_cursor;
8914
8915
8916 -- Delete WDT
8917 FORALL i in 1..l_mmtt_id_tab.COUNT
8918 DELETE FROM wms_dispatched_tasks
8919 WHERE transaction_temp_id = l_mmtt_id_tab(i)
8920 AND task_type = 2;
8921
8922
8923 -- Delete MTLT
8924 FORALL i in 1..l_mmtt_id_tab.COUNT
8925 DELETE FROM mtl_transaction_lots_temp
8926 WHERE transaction_temp_id = l_mmtt_id_tab(i);
8927
8928 FOR i IN 1..l_mmtt_id_tab.COUNT LOOP
8929 UPDATE mtl_txn_request_lines
8930 SET quantity_detailed = Nvl(quantity_detailed,0)
8931 -Decode(uom_code
8932 ,l_mmtt_uom_tab(i)
8933 ,l_mmtt_qty_tab(i)
8934 ,inv_convert.inv_um_convert
8935 (inventory_item_id
8936 ,NULL
8937 ,l_mmtt_qty_tab(i)
8938 ,l_mmtt_uom_tab(i)
8939 ,uom_code
8940 ,NULL
8941 ,NULL)
8942 )
8943 WHERE line_id = l_mmtt_mol_id_tab(i);
8944 END LOOP;
8945
8946 -- Delete MMTT.
8947 FORALL i in 1..l_mmtt_id_tab.COUNT
8948 DELETE FROM mtl_material_transactions_temp
8949 WHERE transaction_temp_id = l_mmtt_id_tab(i);
8950
8951 IF (l_debug = 1) THEN
8952 mydebug('Finished cleaning up old WDT, MTLT, and MMTT records');
8953 END IF;
8954
8955 l_progress := '135';
8956
8957 x_return_status := fnd_api.g_ret_sts_success;
8958 x_number_of_rows := l_number_of_rows;
8959
8960 IF (l_debug = 1) THEN
8961 mydebug('Finished inserting suggestion records: ' || l_number_of_rows);
8962 END IF;
8963
8964 l_progress := '140';
8965
8966
8967 -- Call the ATF API to insert WDTs
8968 -- Moved the ATF API calls to the complete_putaway_wrapper API instead. -etam
8969
8970 IF (l_debug = 1) THEN
8971 mydebug('***End of create_user_suggestions***');
8972 END IF;
8973
8974 EXCEPTION
8975 WHEN fnd_api.g_exc_error THEN
8976 ROLLBACK TO create_suggestions_sp;
8977 x_return_status := fnd_api.g_ret_sts_error;
8978 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8979
8980 IF (l_debug = 1) THEN
8981 mydebug('Exiting create_user_suggestions - Execution error: ' || l_progress || ' '
8982 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
8983 END IF;
8984 WHEN fnd_api.g_exc_unexpected_error THEN
8985 ROLLBACK TO create_suggestions_sp;
8986 x_return_status := fnd_api.g_ret_sts_unexp_error;
8987 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
8988
8989 IF (l_debug = 1) THEN
8990 mydebug('Exiting create_user_suggestions - Unexpected error: ' || l_progress || ' '
8991 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
8992 END IF;
8993 WHEN OTHERS THEN
8994 ROLLBACK TO create_suggestions_sp;
8995 x_return_status := fnd_api.g_ret_sts_unexp_error;
8996
8997 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8998 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
8999 END IF;
9000
9001 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9002
9003 IF (l_debug = 1) THEN
9004 mydebug('Exiting create_user_suggestions - Others exception: ' || l_progress || ' '
9005 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9006 END IF;
9007 END create_user_suggestions;
9008
9009
9010 PROCEDURE validate_lot_serial_status(
9011 p_organization_id IN NUMBER
9012 , p_lpn_id IN NUMBER
9013 , x_return_status OUT NOCOPY VARCHAR2
9014 , x_msg_count OUT NOCOPY NUMBER
9015 , x_msg_data OUT NOCOPY VARCHAR2
9016 , x_validation_passed OUT NOCOPY VARCHAR2
9017 , x_invalid_value OUT NOCOPY VARCHAR2
9018 ) IS
9019 l_api_name CONSTANT VARCHAR2(30) := 'validate_lot_serial_status';
9020 l_progress VARCHAR2(10);
9021 l_item_id NUMBER;
9022 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
9023 l_lot_number VARCHAR2(80);
9024 l_serial_number VARCHAR2(30);
9025 l_transaction_type NUMBER;
9026 l_lot_control_code NUMBER;
9027 l_serial_control_code NUMBER;
9028 l_return VARCHAR2(1);
9029
9030 CURSOR l_item_txn_cursor IS
9031 SELECT inventory_item_id
9032 , lot_number
9033 , transaction_type_id
9034 FROM mtl_txn_request_lines
9035 WHERE organization_id = p_organization_id
9036 AND lpn_id = p_lpn_id;
9037
9038 CURSOR l_serial_cursor IS
9039 SELECT serial_number
9040 FROM mtl_serial_numbers
9041 WHERE inventory_item_id = l_item_id
9042 AND current_organization_id = p_organization_id
9043 AND lpn_id = p_lpn_id;
9044
9045 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9046 BEGIN
9047 IF (l_debug = 1) THEN
9048 mydebug('***Calling validate_lot_serial_status***');
9049 mydebug('Org ID: => ' || p_organization_id);
9050 mydebug('LPN ID: => ' || p_lpn_id);
9051 END IF;
9052
9053 -- Set the savepoint
9054 SAVEPOINT validate_status_sp;
9055 l_progress := '10';
9056 -- Initialize the return variable
9057 l_return := 'Y';
9058 -- Loop through each move order line for the LPN
9059 OPEN l_item_txn_cursor;
9060
9061 LOOP
9062 FETCH l_item_txn_cursor INTO l_item_id, l_lot_number, l_transaction_type;
9063 EXIT WHEN l_item_txn_cursor%NOTFOUND;
9064
9065 IF (l_debug = 1) THEN
9066 mydebug('Current move order line values:');
9067 mydebug('Inventory Item ID: ==> ' || l_item_id);
9068 mydebug('Lot Number: =========> ' || l_lot_number);
9069 mydebug('Transaction type: ===> ' || l_transaction_type);
9070 END IF;
9071
9072 -- Get the item's lot and serial control code
9073 SELECT lot_control_code
9074 , serial_number_control_code
9075 INTO l_lot_control_code
9076 , l_serial_control_code
9077 FROM mtl_system_items
9078 WHERE inventory_item_id = l_item_id
9079 AND organization_id = p_organization_id;
9080
9081 IF (l_debug = 1) THEN
9082 mydebug('Lot and serial control code: ' || l_lot_control_code || ', ' || l_serial_control_code);
9083 END IF;
9084
9085 l_progress := '20';
9086
9087 -- Check lot status if lot controlled
9088 IF (l_lot_control_code = 2) THEN
9089 -- Make sure that a lot number was stamped onto the move order line
9090 IF (l_lot_number IS NULL) THEN
9091 IF (l_debug = 1) THEN
9092 mydebug('No lot number on move order line!');
9093 END IF;
9094
9095 RAISE fnd_api.g_exc_unexpected_error;
9096 END IF;
9097
9098 l_progress := '30';
9099 -- Check if the lot material status is valid
9100 -- for the current move order line's transaction type
9101 l_return :=
9102 inv_material_status_grp.is_status_applicable(
9103 p_wms_installed => 'TRUE'
9104 , p_trx_status_enabled => NULL
9105 , p_trx_type_id => l_transaction_type
9106 , p_lot_status_enabled => NULL
9107 , p_serial_status_enabled => NULL
9108 , p_organization_id => p_organization_id
9109 , p_inventory_item_id => l_item_id
9110 , p_sub_code => NULL
9111 , p_locator_id => NULL
9112 , p_lot_number => l_lot_number
9113 , p_serial_number => NULL
9114 , p_object_type => 'O'
9115 );
9116
9117 IF (l_debug = 1) THEN
9118 mydebug('Lot material status valid: ' || l_return);
9119 END IF;
9120
9121 l_progress := '40';
9122
9123 -- The function returned 'N' so the lot is not valid
9124 -- for the transaction type in the current move order line
9125 IF (l_return = 'N') THEN
9126 x_invalid_value := l_lot_number;
9127 EXIT;
9128 END IF;
9129 END IF;
9130
9131 -- Check serial status if serial controlled
9132 IF (l_serial_control_code <> 1) THEN
9133 -- Loop through each serial for the item in the LPN
9134 OPEN l_serial_cursor;
9135
9136 LOOP
9137 FETCH l_serial_cursor INTO l_serial_number;
9138 EXIT WHEN l_serial_cursor%NOTFOUND;
9139
9140 IF (l_debug = 1) THEN
9141 mydebug('Current serial: ' || l_serial_number);
9142 END IF;
9143
9144 l_progress := '50';
9145 -- Check if the serial material status is valid
9146 -- for the current move order line's transaction type
9147 l_return :=
9148 inv_material_status_grp.is_status_applicable(
9149 p_wms_installed => 'TRUE'
9150 , p_trx_status_enabled => NULL
9151 , p_trx_type_id => l_transaction_type
9152 , p_lot_status_enabled => NULL
9153 , p_serial_status_enabled => NULL
9154 , p_organization_id => p_organization_id
9155 , p_inventory_item_id => l_item_id
9156 , p_sub_code => NULL
9157 , p_locator_id => NULL
9158 , p_lot_number => NULL
9159 , p_serial_number => l_serial_number
9160 , p_object_type => 'S'
9161 );
9162
9163 IF (l_debug = 1) THEN
9164 mydebug('Serial material status valid: ' || l_return);
9165 END IF;
9166
9167 l_progress := '60';
9168
9169 -- The function returned 'N' so the serial is not valid
9170 -- for the transaction type in the current move order line
9171 IF (l_return = 'N') THEN
9172 x_invalid_value := l_serial_number;
9173 EXIT;
9174 END IF;
9175 END LOOP;
9176
9177 CLOSE l_serial_cursor;
9178
9179 -- If any one of the serials did not pass validation,
9180 -- exit the l_item_txn_cursor loop. No further validation
9181 -- is required since validation has already failed.
9182 IF (l_return = 'N') THEN
9183 EXIT;
9184 END IF;
9185 END IF;
9186 END LOOP;
9187
9188 CLOSE l_item_txn_cursor;
9189
9190 -- Finished validating lot and serial statuses
9191 IF (l_debug = 1) THEN
9192 mydebug('Validation passed: ' || l_return);
9193 mydebug('Invalid value: ' || x_invalid_value);
9194 END IF;
9195
9196 l_progress := '70';
9197 -- Set the output variable
9198 x_validation_passed := l_return;
9199 x_return_status := fnd_api.g_ret_sts_success;
9200
9201 IF (l_debug = 1) THEN
9202 mydebug('***End of validate_lot_serial_status***');
9203 END IF;
9204 EXCEPTION
9205 WHEN fnd_api.g_exc_error THEN
9206 ROLLBACK TO validate_status_sp;
9207 x_validation_passed := 'N';
9208 x_return_status := fnd_api.g_ret_sts_error;
9209 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9210
9211 IF (l_debug = 1) THEN
9212 mydebug('Exiting validate_lot_serial_status - Execution error: ' || l_progress || ' '
9213 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9214 END IF;
9215 WHEN fnd_api.g_exc_unexpected_error THEN
9216 ROLLBACK TO validate_status_sp;
9217 x_validation_passed := 'N';
9218 x_return_status := fnd_api.g_ret_sts_unexp_error;
9219 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9220
9221 IF (l_debug = 1) THEN
9222 mydebug('Exiting validate_lot_serial_status - Unexpected error: ' || l_progress || ' '
9223 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9224 END IF;
9225 WHEN OTHERS THEN
9226 ROLLBACK TO validate_status_sp;
9227 x_validation_passed := 'N';
9228 x_return_status := fnd_api.g_ret_sts_unexp_error;
9229
9230 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
9231 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
9232 END IF;
9233
9234 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9235
9236 IF (l_debug = 1) THEN
9237 mydebug('Exiting validate_lot_serial_status - Others exception: ' || l_progress || ' '
9238 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9239 END IF;
9240 END validate_lot_serial_status;
9241
9242 PROCEDURE revert_loc_suggested_capacity(
9243 x_return_status OUT NOCOPY VARCHAR2
9244 , x_msg_count OUT NOCOPY NUMBER
9245 , x_msg_data OUT NOCOPY VARCHAR2
9246 , p_organization_id IN NUMBER
9247 , p_lpn_id IN NUMBER
9248 ) IS
9249 l_api_name CONSTANT VARCHAR2(30) := 'revert_loc_suggested_capacity';
9250 l_progress VARCHAR2(10);
9251 l_item_id NUMBER;
9252 l_locator_id NUMBER;
9253 l_quantity NUMBER;
9254 l_uom_code VARCHAR2(3);
9255 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9256 l_parent_line_id NUMBER; --6962664
9257 l_txn_header_id NUMBER; --6962664
9258
9259 -- Bug# 3434940 - Performance Fixes
9260 -- Cursor to retrieve the nested LPNs within a given outer LPN
9261 CURSOR nested_lpn_cursor IS
9262 SELECT lpn_id
9263 FROM wms_license_plate_numbers
9264 START WITH lpn_id = p_lpn_id
9265 CONNECT BY PRIOR lpn_id = parent_lpn_id;
9266 l_current_lpn_id NUMBER;
9267
9268 -- Bug# 3434940 - Performance Fixes
9269 -- Take the CONNECT by clause out and use an outer cursor loop
9270 -- to get all of the nested LPNs
9271 CURSOR l_suggestions_cursor IS
9272 SELECT mmtt.inventory_item_id
9273 --BUG 3541045: For Inventory Move, suggested sub/loc will be stamped
9274 --on transfer_subinventory/transfer_to_location. So, look at that
9275 --first. Only if it is null should we use the locator_id
9276 , Nvl(mmtt.transfer_to_location,mmtt.locator_id) locator_id
9277 , mmtt.transaction_quantity
9278 , mmtt.transaction_uom
9279 , mmtt.parent_line_id --6962664
9280 , mmtt.transaction_header_id --6962664
9281 FROM mtl_material_transactions_temp mmtt,
9282 mtl_txn_request_lines mtrl
9283 WHERE mmtt.move_order_line_id = mtrl.line_id
9284 AND mmtt.organization_id = p_organization_id
9285 AND mmtt.lpn_id = l_current_lpn_id
9286 AND NVL(mmtt.wms_task_type, 0) <> -1;
9287
9288 BEGIN
9289 IF (l_debug = 1) THEN
9290 mydebug('***Calling revert_loc_suggested_capacity***');
9291 mydebug('Org ID: => ' || p_organization_id);
9292 mydebug('LPN ID: => ' || p_lpn_id);
9293 END IF;
9294
9295 -- Set the savepoint
9296 SAVEPOINT revert_capacity_sp;
9297 l_progress := '10';
9298
9299 -- Bug# 3434940 - Performance Fixes
9300 -- Loop through the nested LPNs first
9301 OPEN nested_lpn_cursor;
9302 LOOP
9303 FETCH nested_lpn_cursor INTO l_current_lpn_id;
9304 EXIT WHEN nested_lpn_cursor%NOTFOUND;
9305 IF (l_debug = 1) THEN
9306 mydebug('Current LPN ID: ' || l_current_lpn_id);
9307 END IF;
9308
9309 -- Loop through each suggested MMTT line for the current LPN
9310 OPEN l_suggestions_cursor;
9311 LOOP
9312 FETCH l_suggestions_cursor INTO l_item_id, l_locator_id, l_quantity, l_uom_code,l_parent_line_id,l_txn_header_id; --6962664 added last two variables
9313 EXIT WHEN l_suggestions_cursor%NOTFOUND;
9314 --6962664 START
9315 mydebug('Locator id value is '|| l_locator_id);
9316 IF l_locator_id IS NULL THEN
9317 BEGIN
9318 mydebug('Getting locator value using parent mmtt as locator value is null');
9319 SELECT locator_id INTO l_locator_id
9320 FROM mtl_material_transactions_temp
9321 WHERE transaction_temp_id = l_parent_line_id
9322 AND transaction_header_id = l_txn_header_id;
9323
9324 EXCEPTION
9325 WHEN No_Data_Found THEN
9326 mydebug('The locator id could not be fetched ');
9327 WHEN OTHERS THEN
9328 mydebug('Unknown Exception');
9329 END;
9330 END IF;
9331 --6962664 END
9332
9333 IF (l_debug = 1) THEN
9334 mydebug('Current MMTT suggestion values:');
9335 mydebug('Inventory Item ID: => ' || l_item_id);
9336 mydebug('Locator ID: ========> ' || l_locator_id);
9337 mydebug('Transaction qty: ===> ' || l_quantity);
9338 mydebug('Transaction UOM: ===> ' || l_uom_code);
9339 END IF;
9340
9341 l_progress := '20';
9342
9343 IF (l_debug = 1) THEN
9344 mydebug('Call INV_LOC_WMS_UTILS.revert_loc_suggested_capacity API');
9345 END IF;
9346
9347 inv_loc_wms_utils.revert_loc_suggested_capacity
9348 (x_return_status => x_return_status
9349 , x_msg_count => x_msg_count
9350 , x_msg_data => x_msg_data
9351 , p_organization_id => p_organization_id
9352 , p_inventory_location_id => l_locator_id
9353 , p_inventory_item_id => l_item_id
9354 , p_primary_uom_flag => 'N'
9355 , p_transaction_uom_code => l_uom_code
9356 , p_quantity => l_quantity
9357 );
9358 l_progress := '30';
9359
9360 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
9361 IF (l_debug = 1) THEN
9362 mydebug('Success returned from revert_loc_suggested_capacity API');
9363 END IF;
9364 ELSE
9365 IF (l_debug = 1) THEN
9366 mydebug('Failure returned from revert_loc_suggested_capacity API');
9367 END IF;
9368 -- Bug 5393727: do not raise an exception if revert API returns an error
9369 -- RAISE fnd_api.g_exc_error;
9370 END IF;
9371
9372 l_progress := '40';
9373 END LOOP;
9374 CLOSE l_suggestions_cursor;
9375
9376 END LOOP;
9377 CLOSE nested_lpn_cursor;
9378
9379 -- Set the output variable
9380 x_return_status := fnd_api.g_ret_sts_success;
9381 l_progress := '50';
9382
9383 IF (l_debug = 1) THEN
9384 mydebug('***End of revert_loc_suggested_capacity***');
9385 END IF;
9386 EXCEPTION
9387 WHEN fnd_api.g_exc_error THEN
9388 ROLLBACK TO revert_capacity_sp;
9389 x_return_status := fnd_api.g_ret_sts_error;
9390 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9391
9392 IF (l_debug = 1) THEN
9393 mydebug(
9394 'Exiting revert_loc_suggested_capacity - Execution error: ' || l_progress || ' '
9395 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
9396 );
9397 END IF;
9398 WHEN fnd_api.g_exc_unexpected_error THEN
9399 ROLLBACK TO revert_capacity_sp;
9400 x_return_status := fnd_api.g_ret_sts_unexp_error;
9401 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9402
9403 IF (l_debug = 1) THEN
9404 mydebug(
9405 'Exiting revert_loc_suggested_capacity - Unexpected error: ' || l_progress || ' '
9406 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
9407 );
9408 END IF;
9409 WHEN OTHERS THEN
9410 ROLLBACK TO revert_capacity_sp;
9411 x_return_status := fnd_api.g_ret_sts_unexp_error;
9412
9413 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
9414 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
9415 END IF;
9416
9417 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9418
9419 IF (l_debug = 1) THEN
9420 mydebug(
9421 'Exiting revert_loc_suggested_capacity - Others exception: ' || l_progress || ' '
9422 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
9423 );
9424 END IF;
9425 END revert_loc_suggested_capacity;
9426
9427 --{{
9428 -- Test the flow where check_for_crossdock is called
9429 --}}
9430 PROCEDURE check_for_crossdock(
9431 p_organization_id IN NUMBER
9432 , p_lpn_id IN NUMBER
9433 , x_return_status OUT NOCOPY VARCHAR2
9434 , x_msg_count OUT NOCOPY NUMBER
9435 , x_msg_data OUT NOCOPY VARCHAR2
9436 , x_crossdock OUT NOCOPY VARCHAR2
9437 ) IS
9438 l_api_name CONSTANT VARCHAR2(30) := 'check_for_crossdock';
9439 l_progress VARCHAR2(10);
9440 l_cross_dock_flag NUMBER;
9441 l_ret_crossdock NUMBER;
9442 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9443 BEGIN
9444 IF (l_debug = 1) THEN
9445 mydebug('***Calling check_for_crossdock***');
9446 mydebug('Org ID: => ' || p_organization_id);
9447 mydebug('LPN ID: => ' || p_lpn_id);
9448 END IF;
9449
9450 -- Set the savepoint
9451 SAVEPOINT check_crossdock_sp;
9452 l_progress := '10';
9453
9454 x_crossdock := 'N';
9455
9456 BEGIN
9457 SELECT 'Y'
9458 INTO x_crossdock
9459 FROM dual
9460 WHERE exists
9461 (SELECT 1
9462 FROM mtl_txn_request_lines
9463 WHERE lpn_id = p_lpn_id
9464 AND organization_id = p_organization_id
9465 AND backorder_delivery_detail_id IS NOT NULL);
9466 EXCEPTION
9467 WHEN OTHERS THEN
9468 x_crossdock := 'N';
9469 END ;
9470
9471 /*
9472 -- Check to see if cross dock is enabled for the org
9473 SELECT NVL(crossdock_flag, 2)
9474 INTO l_cross_dock_flag
9475 FROM mtl_parameters
9476 WHERE organization_id = p_organization_id;
9477
9478 IF (l_debug = 1) THEN
9479 mydebug('Cross Dock Flag: ' || l_cross_dock_flag);
9480 END IF;
9481
9482 l_progress := '20';
9483
9484 IF (l_cross_dock_flag = 1) THEN
9485 IF (l_debug = 1) THEN
9486 mydebug('Crossdock is enabled so check for it');
9487 END IF;
9488
9489 -- Call the cross dock API
9490 wms_cross_dock_pvt.crossdock(
9491 p_org_id => p_organization_id
9492 , p_lpn => p_lpn_id
9493 , x_ret => l_ret_crossdock
9494 , x_return_status => x_return_status
9495 , x_msg_count => x_msg_count
9496 , x_msg_data => x_msg_data
9497 );
9498
9499 IF (l_debug = 1) THEN
9500 mydebug('Finished calling WMS_Cross_Dock_Pvt.crossdock API');
9501 END IF;
9502
9503 l_progress := '30';
9504 -- See if there are any error messages returned from the API
9505 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9506
9507 IF (x_msg_count = 0) THEN
9508 IF (l_debug = 1) THEN
9509 mydebug('Successful');
9510 END IF;
9511 ELSIF(x_msg_count = 1) THEN
9512 IF (l_debug = 1) THEN
9513 mydebug('Not Successful');
9514 mydebug('Error message: ' || REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
9515 END IF;
9516 ELSE
9517 IF (l_debug = 1) THEN
9518 mydebug('Not Successful2');
9519 END IF;
9520
9521 FOR i IN 1 .. x_msg_count LOOP
9522 x_msg_data := fnd_msg_pub.get(i, 'F');
9523
9524 IF (l_debug = 1) THEN
9525 mydebug('Error messages: ' || REPLACE(x_msg_data, fnd_global.local_chr(0), ' '));
9526 END IF;
9527 END LOOP;
9528 END IF;
9529
9530 l_progress := '40';
9531
9532 -- Check the return status from the API call
9533 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
9534 IF (l_debug = 1) THEN
9535 mydebug('Success returned from WMS_Cross_Dock_Pvt.crossdock API');
9536 END IF;
9537 ELSE
9538 IF (l_debug = 1) THEN
9539 mydebug('Failure returned from WMS_Cross_Dock_Pvt.crossdock API');
9540 END IF;
9541
9542 RAISE fnd_api.g_exc_error;
9543 END IF;
9544
9545 l_progress := '50';
9546
9547 -- Check the cross dock return value
9548 IF (l_ret_crossdock = 1) THEN
9549 IF (l_debug = 1) THEN
9550 mydebug('Nothing to Cross Dock');
9551 END IF;
9552
9553 x_crossdock := 'N';
9554 ELSIF(l_ret_crossdock = 0) THEN
9555 IF (l_debug = 1) THEN
9556 mydebug('Cross Dock Succeeded');
9557 END IF;
9558
9559 x_crossdock := 'Y';
9560 ELSE
9561 IF (l_debug = 1) THEN
9562 mydebug('Cross Dock Errored');
9563 END IF;
9564
9565 x_crossdock := 'N';
9566 END IF;
9567
9568 l_progress := '60';
9569 ELSE
9570 IF (l_debug = 1) THEN
9571 mydebug('Cross Dock is not enabled');
9572 END IF;
9573
9574 x_crossdock := 'N';
9575 END IF;
9576 */
9577 -- Set the output variable
9578 x_return_status := fnd_api.g_ret_sts_success;
9579 l_progress := '70';
9580
9581 IF (l_debug = 1) THEN
9582 mydebug('***End of check_for_crossdock***');
9583 END IF;
9584 EXCEPTION
9585 WHEN fnd_api.g_exc_error THEN
9586 ROLLBACK TO check_crossdock_sp;
9587 x_crossdock := 'N';
9588 x_return_status := fnd_api.g_ret_sts_error;
9589 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9590
9591 IF (l_debug = 1) THEN
9592 mydebug('Exiting check_for_crossdock - Execution error: ' ||
9593 l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9594 END IF;
9595 WHEN fnd_api.g_exc_unexpected_error THEN
9596 ROLLBACK TO check_crossdock_sp;
9597 x_crossdock := 'N';
9598 x_return_status := fnd_api.g_ret_sts_unexp_error;
9599 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9600
9601 IF (l_debug = 1) THEN
9602 mydebug('Exiting check_for_crossdock - Unexpected error: ' ||
9603 l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9604 END IF;
9605 WHEN OTHERS THEN
9606 ROLLBACK TO check_crossdock_sp;
9607 x_crossdock := 'N';
9608 x_return_status := fnd_api.g_ret_sts_unexp_error;
9609
9610 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
9611 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
9612 END IF;
9613
9614 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
9615
9616 IF (l_debug = 1) THEN
9617 mydebug('Exiting check_for_crossdock - Others exception: ' ||
9618 l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'));
9619 END IF;
9620 END check_for_crossdock;
9621
9622
9623 END wms_task_dispatch_put_away;